/************************************************************************
*																								*
*		PPrint																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Endlich ein vernünftiges Utility, für den User, der einfach nur	*
*		seine Texte vernünftig ausdrucken will.									*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		V 1.10	©1991 by Marc Jackisch												*
*																								*
************************************************************************/

#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <libraries/reqbase.h>
#include <devices/printer.h>
#include <private/help.h>
#include <private/deva.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/reqproto.h>

#include	"settings.h"
#include "PPrintX.h"

/***************************************

					Definitions

***************************************/

#define	RP			( FirstWindow->RPort )
#define	PRTLEN	sizeof( struct IODRPReq )

/***************************************

						Globals

***************************************/

LONG __far		_stack = 4000;
char __far	  *_procname = "PPrint-procedure";
LONG __far 		_priority = 0;
LONG __far 		_BackGroundIO = 0;

struct IntuitionBase		  *IntuitionBase;
struct GfxBase				  *GfxBase;
struct ReqBase				  *ReqBase;
struct IODRPReq			  *GPrtReq;
struct IOStdReq			  *PrtReq;
struct IOPrtCmdReq		  *CmdReq;
struct Window				  *FirstWindow;
struct Screen				  *FirstScreen;
struct Process				  *MyProcess;
APTR								window_save		=	NULL;
BOOL								gRun;

LONG								Memsize			=	0L;
UBYTE							  *ActFile			=	NULL;

struct Settings				Sets[ 10 ];
SHORT								ActSet			=	1;

SHORT								CurLay			=	1;		/* Current Layout */
USHORT							OTSize;
SHORT								Topline			=	0;
UBYTE								LineBuf[ 128 ];

SHORT								LAYOUT_TOP,
									NUM_LINES,
									NUMTOP,
									SECTOP,
									STRINGTOP,
									ACTIONTOP,
									PT1TOP,
									PT2TOP,
									SWITCHTOP;

UBYTE							  *HashTab[ 5120 ];
SHORT								NumLines;

/***************************************

					Constants

***************************************/

UBYTE								ScTitle[]	=
"PPrint V1.10  File: < none >                                              ";

struct NewScreen				FirstNewScreen	=
{
	0,	0,
	640,	STDSCREENHEIGHT,
	3,	0,	1,
	HIRES,
	CUSTOMSCREEN,
	NULL,
	ScTitle,
	NULL,
	NULL
};

struct NewWindow				FirstNewWindow =
{
	0, 0,
	640, 0,
	0, 1,
	RAWKEY | GADGETUP | MENUPICK | MOUSEBUTTONS,
	SMART_REFRESH | ACTIVATE | BORDERLESS | BACKDROP,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	0,0,0,0,
	CUSTOMSCREEN
};

UBYTE								LoadString[]		=	"Open a file";
struct FileInfoBlock		  *FIB;
UBYTE								Dir[ DSIZE + 1 ],
									File[ FCHARS + 1 ],
									Path[ DSIZE + FCHARS + 2 ];
struct FileRequester			FReq	=
{
	0,
	LoadString,
	Dir,
	File,
	Path,
	NULL,
	0,
	24,
	30,
	13,
	FRQCACHINGM | FRQCACHEPURGEM,
	2,1,2,0,0,0,0,1,1,3,3,3,3
};

/***************************************

					Declarations

***************************************/

VOID			RawkeyA( USHORT, USHORT );
VOID			MenuA( USHORT );
VOID			GadgetA( struct Gadget * );
BOOL			Open_All( VOID );
VOID			Close_All( VOID );
VOID			NewSet( SHORT );
VOID			NewStyle( SHORT );
VOID			NewCond( BOOL );
VOID			NewLetter( BOOL );
VOID			NewLsp( BOOL );
VOID			NewNuming( SHORT );
VOID			Layout1( VOID );
VOID			Layout2( VOID );
VOID			RefreshTSize( VOID );
VOID			RefreshRMarg( VOID );
VOID			RefreshLMarg( VOID );
VOID			RefreshPLength( VOID );
VOID			RefreshPWidth( VOID );
VOID			DoRefresh( VOID );
VOID			DoInits( SHORT );

IMPORT	VOID			About( VOID );
IMPORT	VOID			Load( VOID );
IMPORT	VOID			AskTSize( VOID );
IMPORT	VOID			AskRMarg( VOID );
IMPORT	VOID			AskLMarg( VOID );
IMPORT	VOID			AskPLength( VOID );
IMPORT	VOID			AskPWidth( VOID );
IMPORT	VOID			LoadDefSets( VOID );
IMPORT	VOID			SaveSettings( VOID );
IMPORT	VOID			LoadSettings( VOID );

IMPORT	VOID			PreInit( VOID );
IMPORT	VOID			PrintPageWise( VOID );
IMPORT	VOID			PrintAll( VOID );

IMPORT	VOID			ShowText( SHORT );

/************************************************************************
*																								*
*		main																					*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		No CLI - parameters this time, so we set ourselves to VOID			*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		main( VOID )
{
	struct BackMsg		  *BM;

	/***/

	gRun	=	Open_All();

	while( gRun )
	{
		BM	=	FetchMsg( FirstWindow );
		switch( BM->Class )
		{
			case	RAWKEY	:	RawkeyA( BM->Code, BM->Qual );
									break;
			case	MENUPICK	:	MenuA( BM->Code );
									break;
			case	GADGETUP	:	GadgetA(( struct Gadget * )BM->Adr );
									break;
			default			:	break;
		}
	}
	if( ActFile )
		free( ActFile );

	PurgeFiles( &FReq );
	Close_All();
}

/************************************************************************
*																								*
*		RawkeyA																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Deals with Rawkey - messges.													*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			cd				:	RAWKEY - code												*
*			qu				:	Qualifier													*
*																								*
************************************************************************/

VOID		RawkeyA( USHORT cd, USHORT qu )
{
	qu	&=	~( IEQUALIFIER_RELATIVEMOUSE | IEQUALIFIER_REPEAT );

	/***************************************
					Copy of the menus
	***************************************/

	if( qu == IEQUALIFIER_LCOMMAND )
	{
		switch( cd )
		{
			case	0x20	:	About();							/*	About */
								break;
			case	0x18	:	Load();							/*	Load	*/
								break;
			case	0x19	:	PrintPageWise();				/*	Print	*/
								break;
			case	0x10	:	if( TwoGadRequest( "Do you really\nwant to quit ?" ))
									gRun	=	FALSE;			/*	Quit	*/
								break;
			case	0x28	:	LoadSettings();				/*	Load Sets	*/
								break;
			case	0x21	:	SaveSettings();				/*	Save Sets	*/
								break;
			case	0x13	:	AskRMarg();						/* Right Margin */
								break;
			case	0x37	:	AskLMarg();						/* Left Margin */
								break;
			case	0x14	:	AskTSize();						/*	Tab size */
								break;
			case	0x11	:	AskPWidth();					/*	PWidth */
								break;
			case	0x25	:	AskPLength();					/*	PLen */
								break;
			default		:	break;
		}
		return;
	}

	/***************************************
					Other Commands
	***************************************/

	if( qu == IEQUALIFIER_NUMERICPAD )
	{
		switch( cd )
		{
			case	0x1e	:	ShowText(( SHORT )( Topline + 1 ));
								break;
			case	0x3e	:	ShowText(( SHORT )( Topline - 1 ));
								break;
			case	0x1f	:	ShowText(( SHORT )( Topline + 12 ));
								break;
			case	0x3f	:	ShowText(( SHORT )( Topline - 12 ));
								break;
			case	0x1d	:	ShowText( NumLines );
								break;
			case	0x3d	:	ShowText( 0 );
								break;
			default		:	break;
		}
	}

	if( qu == 0 )
	{
		switch( cd )
		{
			case	0x01	:
			case	0x02	:
			case	0x03	:
			case	0x04	:
			case	0x05	:
			case	0x06	:
			case	0x07	:
			case	0x08	:
			case	0x09	:
			case	0x0a	:	cd	%=	10;
								if( CurLay == 2 )
									Layout1();
								NewSet(( SHORT )cd );
								break;
			case	0x44	:	if( CurLay == 1 )
									Layout2();
								else
									Layout1();
								break;
			case	0x4c	:	ShowText(( SHORT )( Topline - 1 ));
								break;
			case	0x4d	:	ShowText(( SHORT )( Topline + 1 ));
								break;
			case	0x5d	:	PrintAll();
								break;
			case	0x40	:	NewStyle(( SHORT )(( Sets[ ActSet ].Style + 1 ) % 3 ));
								break;
			case	0x33	:	NewCond(( BOOL )( Sets[ ActSet ].Cond ^ TRUE ));
								break;
			case	0x28	:	NewLetter(( BOOL )( Sets[ ActSet ].LetterQ ^ TRUE ));
								break;
			case	0x20	:	NewLsp(( BOOL )( Sets[ ActSet ].LSpace6 ^ TRUE ));
								break;
			case	0x36	:	NewNuming(( SHORT )(( Sets[ ActSet ].Numb + 1 ) % 4 ));
								break;
			default		:	break;
		}
		return;
	}
}

/************************************************************************
*																								*
*												MenuA											*
*																								*
*								Na klar, die Menüauswertung ...						*
*																								*
*		Parameter	:																		*
*			cd				:	Code in der empfangenen Message						*
*																								*
*		Rückgabe		:																		*
*			keine																				*
*																								*
************************************************************************/

VOID MenuA( USHORT cd )
{
	USHORT				Menu, Item;
	struct MenuItem	*NxMen;

	/***/

	Menu = MENUNUM( cd );
	Item = ITEMNUM( cd );
	NxMen = ItemAddress( FirstWindow->MenuStrip, cd );

	switch( Menu )
	{
		case	0:
			switch( Item )
			{
				case	0:	if( TwoGadRequest( "Do you really\nwant to quit ?" ))
								gRun	=	FALSE;	/*	Quit	*/
							break;
				case	1:	PrintPageWise();		/* Print */
							break;
				case	2:	Load();					/* Load */
							break;
				case	3:	About();					/* About */
							break;
				default:	break;
			}
			break;

		case	1:
			switch( Item )
			{
				case	0:	SaveSettings();		/* Save Sets */
							break;
				case	1:	LoadSettings();		/* Load Sets */
							break;
				case	2:	AskRMarg();				/* Right Margin */
							break;
				case	3:	AskLMarg();				/* Left Margin */
							break;
				case	4:	AskTSize();				/*	Tab size */
							break;
				case	5:	AskPWidth();			/*	PWidth */
							break;
				case	6:	AskPLength();			/*	PLen */
							break;
				default:	break;
			}
			break;

		default:
			break;
	}

	if( NxMen )		MenuA( NxMen->NextSelect );
}

/************************************************************************
*																								*
*		GadgetA																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Deals with Gadgets ...															*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			gad			:	Pointer to the gadget triggering the message		*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		GadgetA( struct Gadget *gad )
{
	switch( gad->GadgetID )
	{
		case	0	:
		case	1	:
		case	2	:
		case	3	:
		case	4	:
		case	5	:
		case	6	:
		case	7	:
		case	8	:
		case	9	:	NewSet( gad->GadgetID );
						break;
		case	10	:	NewStyle(( SHORT )(( Sets[ ActSet ].Style + 1 ) % 3 ));
						break;
		case	11	:	NewCond(( BOOL )( Sets[ ActSet ].Cond ^ TRUE ));
						break;
		case	12	:	NewLetter(( BOOL )( Sets[ ActSet ].LetterQ ^ TRUE ));
						break;
		case	13	:	NewLsp(( BOOL )( Sets[ ActSet ].LSpace6 ^ TRUE ));
						break;
		case	14	:	if(( RMarg_info.LongInt >= 0 )&&( RMarg_info.LongInt > Sets[ ActSet ].LMarg ))
							Sets[ ActSet ].RMarg		=	RMarg_info.LongInt;
						else
							RefreshRMarg();
						break;
		case	15	:	if(( LMarg_info.LongInt >= 0 )&&( LMarg_info.LongInt < Sets[ ActSet ].RMarg ))
							Sets[ ActSet ].LMarg		=	LMarg_info.LongInt;
						else
							RefreshLMarg();
						break;
		case	16	:	if(( TSize_info.LongInt >= 0 )&&( TSize_info.LongInt <= 12 ))
						{
							Sets[ ActSet ].Tabsize	=	TSize_info.LongInt;
							if( OTSize != Sets[ ActSet ].Tabsize )
							{
								ShowText( Topline );
								OTSize	=	Sets[ ActSet ].Tabsize;
							}
						}
						else
							RefreshTSize();
						break;
		case	100:	NewNuming(( SHORT )(( Sets[ ActSet ].Numb + 1 ) % 4 ));
						break;
		case	101:	if( PLength_info.LongInt > 0 )
							Sets[ ActSet ].PageLen	=	PLength_info.LongInt;
						else
							RefreshPLength();
						break;
		case	102:	if( PWidth_info.LongInt > 0 )
							Sets[ ActSet ].PageWidth	=	PWidth_info.LongInt;
						else
							RefreshPWidth();
						break;
		case	1000:	Layout2();
						break;
		case	1001:	Layout1();
						break;
		case	2000:	PreInit();
						break;
		case	2001:	PrintPageWise();
						break;
		case	2002:	PrintAll();
						break;
		default	:	break;
	}
}

/************************************************************************
*																								*
*		Open_All																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		This time we open	:	intuition.library										*
*									graphics.library										*
*									req.library												*
*									FirstScreen												*
*									FirstWindow												*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			Boolean value : TRUE, if everything is OK; FALSE, if an error	*
*			occured.																			*
*																								*
************************************************************************/

BOOL	Open_All( VOID )
{
	if(!( FIB = ( struct FileInfoBlock * )AllocMem( sizeof( struct FileInfoBlock ), MEMF_CHIP )))
		return FALSE;

	if(!( IntuitionBase = ( struct IntuitionBase * )OpenLibrary( "intuition.library", 0L )))
		return FALSE;

	if(!( GfxBase	=	( struct GfxBase * )OpenLibrary( "graphics.library", 0L )))
		return FALSE;

	if(!( ReqBase	=	( struct ReqBase * )OpenLibrary( "req.library", 0L )))
		return FALSE;

	if( Open_Device( "printer.device", 0L, ( CPTR * )&GPrtReq, 0, PRTLEN ) == FALSE )
		return FALSE;
	else
	{
		PrtReq	=	( struct IOStdReq * )GPrtReq;
		CmdReq	=	( struct IOPrtCmdReq * )GPrtReq;
	}

	if(!( FirstScreen = ( struct Screen * )OpenScreen( &FirstNewScreen )))
		return FALSE;

	DoInits( FirstScreen->Height );

	SetRGB4( &FirstScreen->ViewPort, 4, 0x00, 0x00, 0x00 );
	SetRGB4( &FirstScreen->ViewPort, 5, 0x00, 0x00, 0x00 );
	SetRGB4( &FirstScreen->ViewPort, 6, 0x00, 0x00, 0x00 );
	SetRGB4( &FirstScreen->ViewPort, 7, 0x00, 0x00, 0x00 );

	FirstNewWindow.Screen		=	FirstScreen;
	FirstNewWindow.FirstGadget	=	&Switch1;

	if(!( FirstWindow = ( struct Window * )OpenWindow( &FirstNewWindow )))
		return FALSE;

	SetMenuStrip( FirstWindow, &Project );

	MyProcess						=	( struct Process * )FindTask( NULL );
	window_save						=	MyProcess->pr_WindowPtr;
	MyProcess->pr_WindowPtr		=	( APTR )FirstWindow;

	SetAPen( RP, 1 );
	LoadDefSets();
	DrawImage( RP, &Layout_image, 0, LAYOUT_TOP );
	NewSet( 0 );

	getcd( 0, Dir );				/* Current directory path to "Dir" */

	SetRGB4( &FirstScreen->ViewPort, 4, 0x0f, 0x0f, 0x0f );
	SetRGB4( &FirstScreen->ViewPort, 5, 0x0c, 0x0c, 0x0d );
	SetRGB4( &FirstScreen->ViewPort, 6, 0x08, 0x08, 0x09 );
	SetRGB4( &FirstScreen->ViewPort, 7, 0x05, 0x05, 0x06 );

	return TRUE;
}

/************************************************************************
*																								*
*		Close_All																			*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		As ususal : closed everything, that Open_All opened.					*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID	Close_All( VOID )
{
	if( window_save )		MyProcess->pr_WindowPtr	=	window_save;
	if( FirstWindow )
	{
		ClearMenuStrip( FirstWindow );
		CloseWindow( FirstWindow );
	}
	if( FirstScreen )		CloseScreen( FirstScreen );
	if( GPrtReq )			Close_Device( GPrtReq );
	if( ReqBase )			CloseLibrary( ReqBase );
	if( GfxBase )			CloseLibrary( GfxBase );
	if( IntuitionBase )	CloseLibrary( IntuitionBase );
	if( FIB )				FreeMem( FIB, sizeof( struct FileInfoBlock ));
}

/************************************************************************
*																								*
*		NewSet																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Displays a new setting															*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			new			:	New setting number										*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		NewSet( SHORT new )
{
	static struct Image	  *Del[] =
	{
		&D0_1_image, &D1_1_image, &D2_1_image, &D3_1_image, &D4_1_image,
		&D5_1_image, &D6_1_image, &D7_1_image, &D8_1_image, &D9_1_image
	};
	static struct Image	  *Put[]	=
	{
		&D0_2_image, &D1_2_image, &D2_2_image, &D3_2_image, &D4_2_image,
		&D5_2_image, &D6_2_image, &D7_2_image, &D8_2_image, &D9_2_image
	};

	/***/

	if( CurLay	==	1 )
	{
		DrawImage( RP, Del[ ActSet ], ( 10 + ( SHORT )( 21 * ActSet )), NUMTOP );
		DrawImage( RP, Put[ new ], ( SHORT )( 10 + ( 21 * new )), NUMTOP );
		ActSet	=	new;
		NewStyle( Sets[ ActSet ].Style );
		NewCond( Sets[ ActSet ].Cond );
		NewLsp( Sets[ ActSet ].LSpace6 );
		NewLetter( Sets[ ActSet ].LetterQ );
		RefreshTSize();
		RefreshLMarg();
		RefreshRMarg();
	}
	ActSet	=	new;
	if( OTSize != Sets[ ActSet ].Tabsize )
	{
		ShowText( Topline );
		OTSize	=	Sets[ ActSet ].Tabsize;
	}
}

/************************************************************************
*																								*
*		NewStyle																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Set a new style																	*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			st				:	Number of the new style									*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		NewStyle( SHORT st )
{
	static struct Image	  *Put[]	=
	{
		&Elite_image,
		&Pica_image,
		&Prop_image
	};

	/***/

	if( CurLay == 1 )
		if(( st >= 0 )&&( st < 3 ))
			DrawImage( RP, Put[ st ], 231, NUMTOP );
	Sets[ ActSet ].Style	=	st;
}

/************************************************************************
*																								*
*		NewCond																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Set the Cond-Flag to a new boolen value									*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			on				:	New value													*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		NewCond( BOOL on )
{
	static struct Image	  *Put[] =
	{
		&CondOff_image,
		&CondOn_image
	};

	/***/

	Sets[ ActSet ].Cond	=	on;
	if( CurLay == 1 )
		DrawImage( RP, Put[ on ], 332, NUMTOP );
}

/************************************************************************
*																								*
*		NewLetter																			*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Set LQ to on or off																*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			on				:	New boolean value											*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		NewLetter( BOOL on )
{
	static struct Image	  *Put[] =
	{
		&Draft_image,
		&LQ_image
	};

	/***/

	Sets[ ActSet ].LetterQ	=	on;
	if( CurLay == 1 )
		DrawImage( RP, Put[ on ], 439, NUMTOP );
}

/************************************************************************
*																								*
*		NewLsp																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Sets line - space to new boolean value i.e. TRUE means 1/6",		*
*		FALSE means 1/8".																	*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			six			:	New boolean value											*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		NewLsp( BOOL six )
{
	static struct Image	  *Put[] =
	{
		&LS8_image,
		&LS6_image
	};

	/***/

	Sets[ ActSet ].LSpace6	=	six;
	if( CurLay == 1 )
		DrawImage( RP, Put[ six ], 11, SECTOP );
}

/************************************************************************
*																								*
*		NewNuming																			*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Sets a new Numing - type.														*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			ty				:	New type														*
*																								*
************************************************************************/

VOID		NewNuming( SHORT ty )
{
	static struct Image	  *Put[]	=
	{
		&Num_No_image,
		&Num_Top_image,
		&Num_Bot_image,
		&Num_Line_image
	};

	/***/

	Sets[ ActSet ].Numb	=	ty;
	if( CurLay == 2 )
		DrawImage( RP, Put[ty], 151, NUMTOP );
}

/************************************************************************
*																								*
*		Layout1																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Draws the first layout - image, and sets the appropriate gadgets	*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		Layout1( VOID )
{
	RemoveGList( FirstWindow, &Switch2, -1 );
	DrawImage( RP, &Layout_image, 0, LAYOUT_TOP );
	AddGList( FirstWindow, &Switch1, 0, -1, NULL );
	CurLay	=	1;
	DoRefresh();
}

/************************************************************************
*																								*
*		Layout2																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Draws the second layout - image, and sets the appropriate gadgets	*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		Layout2( VOID )
{
	RemoveGList( FirstWindow, &Switch1, -1 );
	DrawImage( RP, &Layout2_image, 0, LAYOUT_TOP );
	AddGList( FirstWindow, &Switch2, 0, -1, NULL );
	CurLay	=	2;
	DoRefresh();
}

/************************************************************************
*																								*
*		RefreshTSize																		*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Puts the current number into the container of the TSize - gadget.	*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		RefreshTSize( VOID )
{
	if( CurLay == 1 )
	{
		strcpy( TSize_info.Buffer, ltoa( Sets[ ActSet ].Tabsize ));
		TSize_info.LongInt	=	Sets[ ActSet ].Tabsize;
		RefreshGList( &TSize, FirstWindow, NULL, 1 );
	}
}

/************************************************************************
*																								*
*		RefreshRMarg																		*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Refreshes the RMarg - container.												*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		RefreshRMarg( VOID )
{
	if( CurLay == 1 )
	{
		strcpy( RMarg_info.Buffer, ltoa( Sets[ ActSet ].RMarg ));
		RMarg_info.LongInt	=	Sets[ ActSet ].RMarg;
		RefreshGList( &RMarg, FirstWindow, NULL, 1 );
	}
}

/************************************************************************
*																								*
*		RefreshLMarg																		*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Refreshes the LMarg - container.												*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		RefreshLMarg( VOID )
{
	if( CurLay == 1 )
	{
		strcpy( LMarg_info.Buffer, ltoa( Sets[ ActSet ].LMarg ));
		LMarg_info.LongInt	=	Sets[ ActSet ].LMarg;
		RefreshGList( &LMarg, FirstWindow, NULL, 1 );
	}
}

/************************************************************************
*																								*
*		RefreshPLength																		*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Refreshes the PLength - container.											*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		RefreshPLength( VOID )
{
	if( CurLay == 2 )
	{
		strcpy( PLength_info.Buffer, ltoa( Sets[ ActSet ].PageLen ));
		PLength_info.LongInt	=	Sets[ ActSet ].PageLen;
		RefreshGList( &PLength, FirstWindow, NULL, 1 );
	}
}

/************************************************************************
*																								*
*		RefreshPWidth																		*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Refreshes the PWidth - container.											*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		RefreshPWidth( VOID )
{
	if( CurLay == 2 )
	{
		strcpy( PWidth_info.Buffer, ltoa( Sets[ ActSet ].PageWidth ));
		PWidth_info.LongInt	=	Sets[ ActSet ].PageWidth;
		RefreshGList( &PWidth, FirstWindow, NULL, 1 );
	}
}

/************************************************************************
*																								*
*		DoRefresh																			*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Does a complete refresh															*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			none																				*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		DoRefresh( VOID )
{
	if( CurLay == 1 )
		NewSet( ActSet );
	else
	{
		NewNuming( Sets[ ActSet ].Numb );
		RefreshPLength();
		RefreshPWidth();
	}
}

/************************************************************************
*																								*
*		DoInits																				*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Initializes all predefined structures for PAL or NTSC					*
*																								*
*-----------------------------------------------------------------------*
*																								*
*		Parameters		:																	*
*			SH				:	Screen height												*
*																								*
*		Returns			:																	*
*			none																				*
*																								*
************************************************************************/

VOID		DoInits( SHORT SH )
{
	LAYOUT_TOP					=	SH - 56;
	NUM_LINES					=	( LAYOUT_TOP / 8 ) - 2;
	NUMTOP						=	LAYOUT_TOP + 5;
	SECTOP						=	NUMTOP + 15;
	STRINGTOP					=	SECTOP + 3;
	ACTIONTOP					=	SECTOP + 16;
	PT1TOP						=	NUMTOP + 3;
	PT2TOP						=	PT1TOP + 11;
	SWITCHTOP					=	NUMTOP + 35;

	Num9.TopEdge				=	NUMTOP;
	Num8.TopEdge				=	NUMTOP;
	Num7.TopEdge				=	NUMTOP;
	Num6.TopEdge				=	NUMTOP;
	Num5.TopEdge				=	NUMTOP;
	Num4.TopEdge				=	NUMTOP;
	Num3.TopEdge				=	NUMTOP;
	Num2.TopEdge				=	NUMTOP;
	Num1.TopEdge				=	NUMTOP;
	Num0.TopEdge				=	NUMTOP;
	TSize.TopEdge				=	STRINGTOP;
	LMarg.TopEdge				=	STRINGTOP;
	RMarg.TopEdge				=	STRINGTOP;
	LineSP.TopEdge				=	SECTOP;
	Letter.TopEdge				=	NUMTOP;
	Cond.TopEdge				=	NUMTOP;
	Style.TopEdge				=	NUMTOP;
	PrAll.TopEdge				=	ACTIONTOP;
	PPW.TopEdge					=	ACTIONTOP;
	Pre.TopEdge					=	ACTIONTOP;
	Switch1.TopEdge			=	SWITCHTOP;
	PWidth.TopEdge				=	PT1TOP;
	PLength.TopEdge			=	PT2TOP;
	Numing.TopEdge				=	NUMTOP;
	Switch2.TopEdge			=	SWITCHTOP;

	FirstNewWindow.Height	=	SH;
}
