{**************************************
 *  O b j e c t G E M   Version 1.03  *
 *  Copyright 1992/93 by Thomas Much  *
 **************************************
 *    Softdesign Computer Software    *
 *    Thomas Much, Gerwigstraže 46,   *
 *  76131 Karlsruhe, (0721) 61 61 28  *
 *  UK48@ibm3090.rz.uni-karlsruhe.de  *
 **************************************
 *    erstellt am:        13.07.1992  *
 *    letztes Update am:  25.07.1993  *
 **************************************}

{$B+,D-,G-,I-,L-,N-,P+,Q-,R-,S-,T-,V-,X+,Z+}

unit GObjects;

interface

  uses Dos,Tos,Gem,Strings;

	const	GOVersion             = $0103;
				GODate                = $07251993;

				em_OK                 =   0;
				em_OutOfMemory        =  -1;
				em_InvalidWindow      =  -4;
				em_InvalidMainWindow  =  -5;
				em_AccInitFailure     = -10;
				em_GEMInitFailure     = -11;
				em_AESNotActive       = -12;
				em_WOpenFailure       = -20;
				em_WCloseFailure      = -21;
				em_WDestroyFailure    = -22;
				em_RscNotFound        = -30;
				em_InvalidMenu        = -31;
				em_InvalidDialog      = -32;
				em_Terminate          = -98;
				em_Quit               = -99;

				as_LoadFonts          =   1;
				as_GrowShrink         =   2;
				as_MenuSeparator      =   4;
				as_MoveDials          =   8;
				as_MoveTransparent    =  16 or as_MoveDials;
				as_Rubbox             =  32;
				as_HandleShutdown     =  64;
				as_3DFlags            = 128;

				ws_NoWindow           =   1;
				ws_Created            =   2;
				ws_Open               =   3;

				ws_ex_Modeless        =   1;
				ws_ex_TryModeless     =   2 or ws_ex_Modeless;
				ws_ex_AppModal        =   4;
				ws_ex_Popup           =   8;
				ws_ex_Center          =  16;
				ws_ex_CenterOnce      =  32 or ws_ex_Center;
				ws_ex_Center2Parent   =  64 or ws_ex_Center;
				ws_ex_MoveDial        = 128;
				ws_ex_MoveTransparent = 256 or ws_ex_MoveDial;
				ws_ex_Disabled        = 512;

				cs_ByteAlignClient    =    1;
				cs_ByteAlignWindow    =    2;
				cs_VerAlignClient     =    4;
				cs_VerAlignWindow     =    8;
				cs_FullRedraw         =   16;
				cs_SaveBits           =   32;
				cs_Rubbox             =   64;
				cs_WorkBackground     =  128;
				cs_DblClks            =  256;
				cs_CreateOnAccOpen    =  512;
				cs_CancelOnClose      = 1024;
				cs_HRedraw            =  cs_FullRedraw;
				cs_VRedraw            =  cs_FullRedraw;

				tf_GetData            =    0;
				tf_SetData            =    1;
				tf_SizeData           =    2;

				wb_Transfer           =    1;

				cs_CheckBox           =    1;
				cs_AutoCheckBox       =    cs_CheckBox;
				cs_3State             =    2 or cs_CheckBox;
				cs_Auto3State         =    cs_3State;
				cs_RadioButton        =    4;
				cs_AutoRadioButton    =    cs_RadioButton;
				cs_PushButton         =    8;
				cs_GroupBox           =   16;
				cs_Static             =   32;
				cs_Edit               =   64;
				cs_ScrollBar          =  128;

				es_ASCIIOnly          = 2048;

				bs_DefPushButton      = 2048;

				sbs_Horz              = 2048;
				sbs_Vert              = 4096;

				sts_Fill              = 2048;

				bf_Unchecked          =  1;
				bf_Checked            =  2;
				bf_Grayed             =  3;
				bf_Enabled            =  4;
				bf_Disabled           =  5;

				id_No                 = -1;
				id_OK                 =  0;
				id_Cancel             =  1;
				id_Help               =  2;
				id_Undo               =  3;
				id_Esc                =  4;
				id_NoExit             = 42;

				S_Esc                 = gem.Esc;
				S_Undo                = gem.Undo;
				S_Help                = gem.Help;

				coIndexError          = -1;
				coOverflow            = -2;
				MaxCollectionSize     = maxlongint div sizeof(pointer);

				vsOK                  =  0;
				vsSyntax              =  1;

				voFill                = $0001;
				voNotEmpty            = $0002;
				voOnEdit              = $0004;
				voReserved            = $00f8;

				KbSCAN    = $8000;  KsCAPS    = $0010;
				KbNUM     = $4000;  KsALT     = $0008;
				KbALT     = $0800;  KsCONTROL = $0004;
				KbCONTROL = $0400;  KsSHIFT   = $0003;
				KbLSHIFT  = $0200;  KsLSHIFT  = $0002;
				KbRSHIFT  = $0100;  KsRSHIFT  = $0001;
				KbISO     = $0037;
				KbF1      = $003b;  KbF11     = $0054;
				KbF2      = $003c;  KbF12     = $0055;
				KbF3      = $003d;  KbF13     = $0056;
				KbF4      = $003e;  KbF14     = $0057;
				KbF5      = $003f;  KbF15     = $0058;
				KbF6      = $0040;  KbF16     = $0059;
				KbF7      = $0041;  KbF17     = $005a;
				KbF8      = $0042;  KbF18     = $005b;
				KbF9      = $0043;  KbF19     = $005c;
				KbF10     = $0044;  KbF20     = $005d;
				KbAlt1    = $0078;  KbUNDO    = $0061;
				KbAlt2    = $0079;  KbHELP    = $0062;
				KbAlt3    = $007a;  KbINSERT  = $0052;
				KbAlt4    = $007b;  KbHOME    = $0047;
				KbAlt5    = $007c;  KbUP      = $0048;
				KbAlt6    = $007d;  KbDOWN    = $0050;
				KbAlt7    = $007e;  KbLEFT    = $004b;
				KbAlt8    = $007f;  KbRIGHT   = $004d;
				KbAlt9    = $0080;
				KbAlt0    = $0081;

				USA =  0;           FRG =  1;
				FRA =  2;           UK  =  3;
				SPA =  4;           ITA =  5;
				SWE =  6;           SWF =  7;
				SWG =  8;           TUR =  9;
				FIN = 10;           NOR = 11;
        DEN = 12;           SAU = 13;
        HOL = 14;

				SIGNULL =  0;       SIGHUP   =  1;
				SIGINT  =  2;       SIGQUIT  =  3;
				SIGILL  =  4;       SIGTRAP  =  5;
				SIGABRT =  6;       SIGPRIV  =  7;
				SIGFPE  =  8;       SIGKILL  =  9;
				SIGBUS  = 10;       SIGSEGV  = 11;
				SIGSYS  = 12;       SIGPIPE  = 13;
				SIGALRM = 14;       SIGTERM  = 15;
				SIGSTOP = 17;       SIGTSTP  = 18;
				SIGCONT = 19;       SIGCHLD  = 20;
				SIGTTIN = 21;       SIGTTOU  = 22;
				SIGXCPU = 24;       SIGWINCH = 28;
				SIGUSR1 = 29;       SIGUSR2  = 30;
				SIG_DFL = pointer(0);
				SIG_IGN = pointer(1);

				NUL =   0;          SOH =  1;
				STX =   2;          ETX =  3;
				EOT =   4;          ENQ =  5;
				ACK =   6;          BEL =  7;
				BS  =   8;          HT  =  9;
				LF  =  10;          VT  = 11;
				FF  =  12;          CR  = 13;
				SO  =  14;          SI  = 15;
				DLE =  16;          DC1 = 17;
				DC2 =  18;          DC3 = 19;
				DC4 =  20;          NAK = 21;
				SYN =  22;          ETB = 23;
				CAN =  24;          EM  = 25;
				SUB =  26;          ESC = 27;
				FS  =  28;          GS  = 29;
				RS  =  30;          US  = 31;
				SP  =  32;          EOS =  0;
				DEL = 127;

				DESK             =  0;
        CLIP_ON          =  1;
        CLIP_OFF         =  0;
        PER_ON           =  1;
        PER_OFF          =  0;
        ME_DRAW          =  1;
        ME_ERASE         =  0;
        ME_INQUIRE       = -1;
        ME_CHECK         =  1;
        ME_UNCHECK       =  0;
        ME_DISABLE       =  0;
        ME_ENABLE        =  1;
        ME_NORMAL        =  1;
        ME_INVERT        =  0;
        FF_STAND         =  1;
        FF_DEVSPEC       =  0;
        POP_LEFTOP       =  0;
        POP_CENTER       =  1;
        AT_TIMER         =  0;
        AT_BUTTON        =  1;
        AT_MOUSE         =  2;
        AT_KEYBD         =  3;
        NO_ICON          =  0;
        NOTE             =  1;
        WAIT             =  2;
        STOP             =  3;
        NDC              =  0;
        RC               =  2;

				{ ACHTUNG: Die Konstanten im folgenden Block sind fr
				           MultiTOS wichtig; sie werden aus ObjectGEM
				           verschwunden sein, sobald sie von den
				           Standard-PP-Units untersttzt werden! }
				WF_OWNER         =    20;
				WF_BEVENT        =    24;
				WF_BOTTOM        =    25;
				CT_KEY           =    53;
				RESCH_COMPLETED  =    61;
				AP_DRAGDROP      =    63;
				SH_WDRAW         =    72;
				DD_OK            =     0;
				DD_NAK           =     1;
				DD_EXT           =     2;
				DD_LEN           =     3;
				DD_TIMEOUT       =  4000;
				DD_NUMEXTS       =     8;
				DD_EXTSIZE       =    32;
				DD_NAMEMAX       =   128;
				DD_HDRMAX        =     8+DD_NAMEMAX;
				G_CICON          =    33;
				FL3DMASK         = $0600;
				FL3DNONE         = $0000;
				FL3DIND          = $0200;
				FL3DBAK          = $0400;
				FL3DACT          = $0600;
				LK3DIND          =     1;
				LK3DAKT          =     2;
				INDBUTCOL        =     3;
				ACTBUTCOL        =     4;
				BACKGRCOL        =     5;
				AD3DVAL          =     6;

        IDC_ARROW        = ARROW;
        IDC_IBEAM        = TEXT_CRSR;
        IDC_WAIT         = 100;
        IDC_CROSS        = THIN_CROSS;
        IDC_SIZE         = 101;
        IDC_LOAD         = 102;
        IDC_NOTICE       = 103;
        HOURGLASS        = IDC_WAIT;
        IDC_UPARROW      = 104;
        IDC_ICON         = 105;
        IDC_SIZENWSE     = 106;
        IDC_SIZENESW     = 107;
        IDC_SIZEWE       = 108;
        IDC_SIZENS       = 109;
        IDC_HELP         = 110;
        IDC_PENCIL       = 111;
        IDC_RUBBER       = 112;
        IDC_SCISSORS     = 113;

        ACC_ID           =  $400;
        ACC_OPEN         =  $401;
        ACC_CLOSE        =  $402;
        ACC_ACC          =  $403;
        ACC_EXIT         =  $404;
        ACC_ACK          =  $500;
        ACC_TEXT         =  $501;
        ACC_KEY          =  $502;
        ACC_META         =  $503;
        ACC_IMG          =  $504;
        ACC_SPECIAL      =  $800;

        AV_PROTOKOLL     = $4700;
        VA_PROTOSTATUS   = $4701;
        AV_GETSTATUS     = $4703;
        AV_STATUS        = $4704;
        VA_SETSTATUS     = $4705;
        AV_SENDKEY       = $4710;
        VA_START         = $4711;
        AV_ASKFILEFONT   = $4712;
        VA_FILEFONT      = $4713;
        AV_ASKCONFONT    = $4714;
        VA_CONFONT       = $4715;
        AV_ASKOBJECT     = $4716;
        VA_OBJECT        = $4717;
        AV_OPENCONSOLE   = $4718;
        VA_CONSOLEOPEN   = $4719;
        AV_OPENWIND      = $4720;
        VA_WINDOPEN      = $4721;
        AV_STARTPROG     = $4722;
        VA_PROGSTART     = $4723;
        AV_ACCWINDOPEN   = $4724;
        VA_DRAGACCWIND   = $4725;
        AV_ACCWINDCLOSED = $4726;

				HexArray: array [0..15] of char = ('0','1','2','3','4','5','6','7',
				                                   '8','9','a','b','c','d','e','f');


  type THandle                = longint;
	     HWnd                   = THandle;
	     HCursor                = THandle;
	     HBrush                 = THandle;
	     Bool                   = word;
	     PByte                  = ^byte;
       PStr                   = PChar;
       PWord                  = ^word;
       PBool                  = ^Bool;
       PInteger               = ^integer;
       PShort                 = ^shortint;
       PLongint               = ^longint;
       PString                = ^string;
       PBoolean               = ^boolean;
       PPointer               = ^pointer;
       Pipearray              = ARRAY_8;
       PPipearray             = ^Pipearray;
       PTree                  = AESTreePtr;
       PObj                   = AESOBJECTPtr;
       PGRECT                 = ^GRECT;
       PAPPLRECORD            = ^APPLRECORD;
       PWordRec               = ^WordRec;
       PLongRec               = ^LongRec;
			 PIterationProc         = ^IterationProc;
			 PIterationFunc         = ^IterationFunc;
       PItemList              = ^TItemList;
       PWndClass              = ^TWndClass;
       PPaintStruct           = ^TPaintStruct;
       PScrollBarTransferRec  = ^TScrollBarTransferRec;
       PWindowAttr            = ^TWindowAttr;
       PGEMAttr               = ^TGEMAttr;
       PEventData             = ^TEventData;
       PCookieID              = ^TCookieID;
       PCookie                = ^TCookie;
       PRsFile                = ^TRsFile;
       PCharSet               = ^TCharSet;
       PByteArray             = ^TByteArray;
       PWordArray             = ^TWordArray;

			 PObject                = ^TObject;
			 PEventObject           = ^TEventObject;
			 PCollection            = ^TCollection;
			 PSortedCollection      = ^TSortedCollection;
			 PStringCollection      = ^TStringCollection;
			 PStrCollection         = ^TStrCollection;
			 PEvent                 = ^TEvent;
			 PControl               = ^TControl;
			 PScrollBar             = ^TScrollBar;
			 PGroupBox              = ^TGroupBox;
			 PStatic                = ^TStatic;
			 PButton                = ^TButton;
			 PCheckBox              = ^TCheckBox;
			 PTriState              = ^TTriState;
			 PRadioButton           = ^TRadioButton;
			 PEdit                  = ^TEdit;
			 PValidator             = ^TValidator;
			 PFilterValidator       = ^TFilterValidator;
			 PRangeValidator        = ^TRangeValidator;
			 PLookupValidator       = ^TLookupValidator;
			 PStringLookupValidator = ^TStringLookupValidator;
			 PScroller              = ^TScroller;
			 PWindow                = ^TWindow;
			 PApplication           = ^TApplication;
       PDialog                = ^TDialog;
       PPopup                 = ^TPopup;
       PKeyMenu               = ^TKeyMenu;
			 PKey                   = ^TKey;
			 PMenu                  = ^TMenu;


       GRECT = record
       					 case integer of
       						 0: (g_x,g_y,g_w,g_h    : integer);
       						 1: (X,Y,W,H,X1,Y1,X2,Y2: integer);
       						 2: (A1,A2              : ARRAY_4)
       				 end;
			 APPLRECORD = record
											Typ: longint;
											What: record
															case boolean of
																false: (Long: longint);
																true:  (Hi,Lo: word)
														end
										end;
			 WordRec = record
									 Hi,Lo: byte
								 end;
			 LongRec = record
									 Hi,Lo: word
								 end;
			 IterationProc = procedure(p: pointer);
			 IterationFunc = function(p: pointer): boolean;
			 TItemList = array [0..pred(MaxCollectionSize)] of pointer;
			 TWndClass = record
										 Style        : word;
										 hCursor      : HCursor;
										 hbrBackground: HBrush;
										 MenuTree     : PTree;
										 lpszClassName: PString
									 end;
			 TPaintStruct = record
												fErase : boolean;
												feColor: HBrush;
												rcPaint: GRECT
											end;
			 TScrollBarTransferRec = record
																 LowValue,HighValue,Position: longint
															 end;
       TWindowAttr = record
                       Title,SubTitle  : PString;
                       RBox            : GRECT;
                       Handle          : HWnd;
                       gemHandle,Status: integer;
                       Style           : integer;
                       ExStyle         : longint
                     end;
       TGEMAttr = record
       							EventMask,Instance     : integer;
       							Style                  : longint;
       							Country                : word;
       							rpTail,rpCmd           : PString;
       							sysFonts,addFonts      : integer;
	                  charSWidth,charSHeight : integer;
	                  boxSWidth,boxSHeight   : integer;
	                  MaxPX,MaxPY,PixW,PixH  : integer;
	                  Colors,MaxColors,Planes: integer
                  end;
			 TEventData = record
			 							  Pipe       : Pipearray;
			 							  mX,mY      : integer;
			 							  BStat,KStat: integer;
			 							  Key,Clicks : integer
										end;
       TCookieID = array [0..3] of char;
       TCookie = record
                   ID:  TCookieID;
                   Val: longint
                 end;
			 TRsFile = record
									 case boolean of
										 false: (rsh: RSHDR);
										 true:  (rsd: array [0..65535] of byte)
								 end;
			 TCharSet   = set of char;
			 TByteArray = array [0..maxlongint] of byte;
			 TWordArray = array [0..1073741822] of word;
			 TPicResult = (prComplete,prIncomplete,prEmpty,prError,prSyntax,prAmbiguous,prIncompNoFill);


			 TObject = object
									 public
  							   constructor Init;
  							   procedure Free;
  							   destructor Done; virtual;
  				       end;

			 TEventObject = object(TObject)
												public
												EventList: PEvent;
  							  			constructor Init;
  							  			destructor Done; virtual;
											end;

			 TCollection = object(TObject)
											 public
											 Items            : PItemList;
											 Count,Limit,Delta: longint;
											 constructor Init(ALimit,ADelta: longint);
											 destructor Done; virtual;
											 function At(Index: longint): pointer; virtual;
											 procedure AtDelete(Index: longint); virtual;
											 procedure AtFree(Index: longint); virtual;
											 procedure AtInsert(Index: longint; Item: pointer); virtual;
											 procedure AtPut(Index: longint; Item: pointer); virtual;
											 procedure Delete(Item: pointer); virtual;
											 procedure Error(Code,Info: longint); virtual;
											 procedure DeleteAll; virtual;
											 function FirstThat(Test: PIterationFunc): pointer; virtual;
											 procedure ForEach(Action: PIterationProc); virtual;
											 procedure Free(Item: pointer);
											 procedure FreeAll; virtual;
											 procedure FreeItem(Item: pointer); virtual;
											 function IndexOf(Item: pointer): longint; virtual;
											 procedure Insert(Item: pointer); virtual;
											 function LastThat(Test: PIterationFunc): pointer; virtual;
											 procedure Pack; virtual;
											 procedure SetLimit(ALimit: longint); virtual;
										 end;

			 TSortedCollection = object(TCollection)
														 public
														 Duplicates: boolean;
														 constructor Init(ALimit,ADelta: longint);
														 function IndexOf(Item: pointer): longint; virtual;
														 procedure Insert(Item: pointer); virtual;
														 function Compare(Key1,Key2: pointer): integer; virtual;
														 function KeyOf(Item: pointer): pointer; virtual;
														 function Search(Key: pointer; var Index: longint): boolean; virtual;
													 end;

			 TStringCollection = object(TSortedCollection)
														 public
														 constructor Init(ALimit,ADelta: longint);
														 procedure FreeItem(Item: pointer); virtual;
														 function Compare(Key1,Key2: pointer): integer; virtual;
													 end;

			 TStrCollection = object(TStringCollection)
													public
													procedure FreeItem(Item: pointer); virtual;
													function Compare(Key1,Key2: pointer): integer; virtual;
												end;

			 TEvent = object(TObject)
									public
									Parent: PEventObject;
									constructor Init(AParent: PEventObject);
									destructor Done; virtual;
									function TestKey(Stat,Key: integer): boolean; virtual;
									function TestButton(mX,mY,BStat,KStat,Clicks: integer): boolean; virtual;
									function TestMouse(M,mX,mY,BStat,KStat: integer): boolean; virtual;
									function TestMessage(Pipe: Pipearray): boolean; virtual;
									function TestMenu(mNum: integer): boolean; virtual;
									procedure Work; virtual;
									function Previous: PEvent; virtual;
									function Next: PEvent; virtual;
								end;

			 TControl = object(TObject)
										public
										Parent    : PDialog;
										Style     : word;
										Flags     : byte;
										ObjIndx,ID: integer;
										ObjAddr   : PObj;
										constructor Init(AParent: PDialog; AnIndx: integer; Hlp: string);
										destructor Done; virtual;
										function TestIndex(AnIndx: integer): boolean; virtual;
										function TestID(AnID: integer): boolean; virtual;
										function TestShortCut(Key: integer): boolean; virtual;
										procedure SetFlags(Mask: byte; OnOff: boolean); virtual;
										function IsFlagSet(Mask: byte): boolean; virtual;
									  procedure SetState(StateFlag: integer); virtual;
									  function GetState: integer; virtual;
									  procedure Disable; virtual;
									  procedure Enable; virtual;
									  procedure DisableTransfer; virtual;
									  procedure EnableTransfer; virtual;
									  function Transfer(DataPtr: pointer; TransferFlag: word): word; virtual;
									  procedure Changed(AnIndx: integer; DblClick: boolean); virtual;
									  procedure Paint; virtual;
									  function IsHelpAvailable: boolean; virtual;
									  function GetHelp: string; virtual;
									  procedure SetHelp(Hlp: string); virtual;
									  function Previous: PControl; virtual;
									  function Next: PControl; virtual;
									end;

			 TScrollBar = object(TControl)
											public
											LineMagnitude,PageMagnitude,Size: longint;
											IsHorizontal                    : boolean;
											constructor Init(AParent: PDialog; SIndx,DIndx,IIndx: integer; TheSize,TheRange: longint; Hlp: string);
											function TestIndex(AnIndx: integer): boolean; virtual;
											function Transfer(DataPtr: pointer; TransferFlag: word): word; virtual;
											procedure Changed(AnIndx: integer; DblClick: boolean); virtual;
											procedure Work; virtual;
											procedure SetPosition(ThumbPos: longint); virtual;
											function GetPosition: longint; virtual;
											function DeltaPos(Delta: longint): longint; virtual;
											procedure SetRange(LoVal,HiVal: longint); virtual;
											function GetRange(var LoVal,HiVal: longint): longint; virtual;
											function GetSBoxMin: integer; virtual;
										end;

			 TGroupBox = object(TControl)
										 public
										 constructor Init(AParent: PDialog; AnIndx: integer; ATitle,Hlp: string);
										 destructor Done; virtual;
										 procedure SetText(ATextString: string); virtual;
										 function GetText: string; virtual;
									 end;

			 TStatic = object(TControl)
									 public
									 UsrDef : boolean;
									 TextLen: integer;
									 constructor Init(AParent: PDialog; AnIndx,ATextLen: integer; UserDef: boolean; Hlp: string);
									 destructor Done; virtual;
									 function Transfer(DataPtr: pointer; TransferFlag: word): word; virtual;
									 procedure SetText(ATextString: string); virtual;
									 function GetText: string; virtual;
									 function GetTextLen: integer; virtual;
									 procedure Clear; virtual;
								 end;

			 TButton = object(TControl)
									 public
									 UsrDef: boolean;
									 constructor Init(AParent: PDialog; AnIndx,AnID: integer; UserDef: boolean; Hlp: string);
									 destructor Done; virtual;
									 function Install: boolean; virtual;
									 procedure SetText(ATextString: string); virtual;
									 function GetText: string; virtual;
								 end;

			 TCheckBox = object(TButton)
										 public
										 constructor Init(AParent: PDialog; AnIndx: integer; UserDef: boolean; Hlp: string);
										 function Install: boolean; virtual;
										 function Transfer(DataPtr: pointer; TransferFlag: word): word; virtual;
										 procedure SetCheck(CheckFlag: integer); virtual;
										 function GetCheck: integer; virtual;
										 procedure Check; virtual;
										 procedure Uncheck; virtual;
										 procedure Toggle; virtual;
									 end;

			 TTriState = object(TCheckBox)
										 public
										 constructor Init(AParent: PDialog; AnIndx: integer; Hlp: string);
										 procedure Gray; virtual;
									 end;

			 TRadioButton = object(TCheckBox)
												public
												constructor Init(AParent: PDialog; AnIndx: integer; UserDef: boolean; Hlp: string);
												procedure SetState(StateFlag: integer); virtual;
												function Install: boolean; virtual;
											end;

			 TEdit = object(TStatic)
								 public
								 Validator: PValidator;
								 constructor Init(AParent: PDialog; AnIndx,ATextLen: integer; Hlp: string);
								 destructor Done; virtual;
								 procedure SetText(ATextString: string); virtual;
								 procedure Edit; virtual;
								 function IsValid(ReportError: boolean): boolean; virtual;
								 function CanClose: boolean; virtual;
								 function CanUndo: boolean; virtual;
								 procedure Undo; virtual;
								 procedure Paste; virtual;
								 procedure Copy; virtual;
								 procedure Cut; virtual;
								 procedure Focus; virtual;
								 function IsModified: boolean; virtual;
								 procedure ClearModify; virtual;
								 procedure SetValidator(AValid: PValidator); virtual;
								 procedure SetCursor(CPos: integer); virtual;
								 function GetCursor: integer; virtual;
							 end;

			 TValidator = object(TObject)
											public
											Status,Options: Word;
											Window        : PDialog;
											constructor Init;
											procedure Error; virtual;
											function IsValid(s: string): boolean; virtual;
											function IsValidInput(var s: string; SuppressFill: boolean): boolean; virtual;
											function Valid(s: string): boolean; virtual;
										end;

			 TFilterValidator = object(TValidator)
														public
														ValidChars: TCharSet;
														constructor Init(ValidCharSet: TCharSet);
														procedure Error; virtual;
														function IsValid(s: string): boolean; virtual;
														function IsValidInput(var s: string; SuppressFill: boolean): boolean; virtual;
													end;

			 TRangeValidator = object(TFilterValidator)
													 public
													 Min,Max: longint;
													 constructor Init(AMin,AMax: longint);
													 procedure Error; virtual;
													 function IsValid(s: string): boolean; virtual;
													 function IsValidInput(var s: string; SuppressFill: boolean): boolean; virtual;
												 end;

			 TLookupValidator = object(TValidator)
														 public
														 function IsValid(s: string): boolean; virtual;
														 function Lookup(s: string): boolean; virtual;
													end;

			 TStringLookupValidator = object(TLookupValidator)
																	public
																	Strings: PStringCollection;
																	constructor Init(AString: PStringCollection);
																	destructor Done; virtual;
																	procedure Error; virtual;
																	function Lookup(s: string): boolean; virtual;
																	procedure NewStringList(AString: PStringCollection); virtual;
																end;

			 TPopup = object(TEvent)
									public
									PopTree         : PTree;
									pX,pY,pIndex    : integer;
									pRows,pMax,pFlag: integer;
									constructor Init(AParent: PEventObject; tIndx,oIndx: integer);
									function Execute: integer; virtual;
									procedure SetText(nr: integer; ATextString: string); virtual;
									function GetText(nr: integer): string; virtual;
								  procedure SetState(nr,StateFlag: integer); virtual;
								  function GetState(nr: integer): integer; virtual;
								  procedure Disable(nr: integer); virtual;
								  procedure Enable(nr: integer); virtual;
									procedure SetCheck(nr,CheckFlag: integer); virtual;
									function GetCheck(nr: integer): integer; virtual;
									procedure Check(nr: integer); virtual;
									procedure Uncheck(nr: integer); virtual;
									procedure Toggle(nr: integer); virtual;
								end;

			 TScroller = object(TObject)
										 public
										 Window                     : PWindow;
										 XUnit,YUnit                : integer;
										 XPos,Ypos,XRange,YRange    : longint;
										 XLine,YLine,XPage,YPage    : longint;
										 TrackMode                  : boolean;
										 HasHScrollBar,HasVScrollBar: boolean;
										 constructor Init(TheWindow: PWindow; TheXUnit,TheYUnit: integer; TheXRange,TheYRange: longint);
										 destructor Done; virtual;
										 procedure HScroll; virtual;
										 procedure VScroll; virtual;
										 function IsVisibleRect(X,Y,XExt,YExt: longint): boolean; virtual;
										 procedure ScrollBy(dX,dY: longint); virtual;
										 procedure ScrollTo(X,Y: longint); virtual;
										 procedure SetPageSize; virtual;
										 procedure SetSBarRange; virtual;
										 procedure SetRange(TheXRange,TheYRange: longint); virtual;
										 procedure SetUnits(TheXUnit,TheYUnit: integer); virtual;
										 function GetXOrg: longint; virtual;
										 function GetYOrg: longint; virtual;
									 end;

       TWindow = object(TEventObject)
    							 public
                   Attr            : TWindowAttr;
                   Class           : TWndClass;
                   Parent,ChildList: PWindow;
                   Scroller        : PScroller;
									 DlgTree         : PTree;
									 Full,Curr,Work  : GRECT;
									 vdiHandle       : integer;
									 constructor Init(AParent: PWindow; ATitle: string);
                   destructor Done; virtual;
                   function GetStyle: integer; virtual;
                   procedure GetWindowClass(var AWndClass: TWndClass); virtual;
                   function GetClassName: string; virtual;
                   function CanClose: boolean; virtual;
                   function IsModeless: boolean; virtual;
                   function IsDialog: boolean; virtual;
                   function IsTop: boolean; virtual;
									 procedure GetFull; virtual;
									 procedure GetCurr; virtual;
                   procedure GetWork; virtual;
                   procedure SetCurr(r: GRECT); virtual;
                   procedure SetWork(r: GRECT); virtual;
                   procedure LoadDialog(Indx: integer); virtual;
                   procedure FreeDialog; virtual;
									 procedure SetDlgTree(tree: PTree); virtual;
                   procedure UpdateDialog; virtual;
                   procedure SetupWindow; virtual;
                   procedure MakeWindow; virtual;
                   procedure Create; virtual;
                   procedure OpenWindow; virtual;
                   procedure CloseWindow; virtual;
                   procedure Destroy; virtual;
                   procedure RawDestroy; virtual;
                   procedure Top; virtual;
                   procedure FullSize; virtual;
                   procedure Size(r: GRECT); virtual;
                   procedure Move(r: GRECT); virtual;
                   procedure Paint(var PaintInfo: TPaintStruct); virtual;
                   procedure ForceRedraw; virtual;
                   procedure SetTitle(ATitle: string); virtual;
                   procedure SetSubTitle(AnInfo: string); virtual;
                   procedure Calc(ctype: integer; ri: GRECT; var ro: GRECT); virtual;
                   procedure ChkAlign(var r: GRECT); virtual;
                   procedure ChkMin(var r: GRECT); virtual;
                   procedure ChkMax(var r: GRECT); virtual;
									 procedure GetWorkMin(var minX,minY: integer); virtual;
									 procedure GetWorkMax(var maxX,maxY: integer); virtual;
									 function GetDC: integer; virtual;
									 procedure ReleaseDC; virtual;
                   procedure WMRedraw(X,Y,W,H: integer); virtual;
                   procedure WMTopped; virtual;
                   procedure WMClosed; virtual;
                   procedure WMFulled; virtual;
                   procedure WMArrowed(wA: integer); virtual;
                   procedure WMHSlid(Value: integer); virtual;
                   procedure WMVSlid(Value: integer); virtual;
                   procedure WMSized(X,Y,W,H: integer); virtual;
                   procedure WMMoved(X,Y,W,H: integer); virtual;
									 procedure WMButton(mX,mY,BStat,KStat,Clicks: integer); virtual;
									 procedure WMClick(mX,mY,KStat: integer); virtual;
									 procedure WMDblClick(mX,mY,KStat: integer); virtual;
									 procedure WMRubbox(r: GRECT); virtual;
									 procedure WMRBoxChanged(r: GRECT); virtual;
                   procedure WMNewTop; virtual;
                   procedure WMUntopped; virtual;
                   procedure WMOnTop; virtual;
                   function WMKeyDown(Stat,Key: integer): boolean; virtual;
									 procedure WMDragDrop(PipeID,OrgID,mX,mY,KStat: integer); virtual;
                   procedure WAUpPage; virtual;
                   procedure WADnPage; virtual;
                   procedure WAUpLine; virtual;
                   procedure WADnLine; virtual;
                   procedure WALfPage; virtual;
                   procedure WARtPage; virtual;
                   procedure WALfLine; virtual;
                   procedure WARtLine; virtual;
                   function Previous: PWindow; virtual;
                   function Next: PWindow; virtual;
									 function FirstWndThat(Test: PIterationFunc): PWindow; virtual;
									 procedure ForEachWnd(Action: PIterationProc); virtual;
                 end;

  		 TApplication = object(TEventObject)
  											public
  		                  Name,apName,apPath   : PString;
  		                  ID                   : TCookieID;
  		                  Status,vdiHandle     : integer;
                        aesHandle,apID       : integer;
                        menuID               : integer;
	                      workIn               : workin_ARRAY;
	                      workOut              : workout_ARRAY;
	                      Attr                 : TGEMAttr;
  		                  MainWindow           : PWindow;
  		                  RscPtr               : PRsFile;
  		                  MenuTree             : PTree;
  		                  MessageBuffer        : pointer;
  		                  MessageBLen          : integer;
  		                  apDTA                : DTA;
  		                  FirstInstance        : boolean;
			                  SpeedoActive,MultiTOS: boolean;
			                  GDOSActive,MiNTActive: boolean;
			                  IsQSBUsed            : boolean;
  		                  constructor Init(AnID: TCookieID; AName: string);
  		                  destructor Done; virtual;
  		                  function CanClose: boolean; virtual;
												procedure LoadResource(FileHiRes,FileLoRes: string); virtual;
												procedure InitResource(AddrHiRes,AddrLoRes: pointer); virtual;
												function GetAddr(Indx: integer): PTree; virtual;
												function GetFImagePtr(Indx: integer): pointer; virtual;
												function GetFStringPtr(Indx: integer): PChar; virtual;
												function GetFString(Indx: integer): string; virtual;
												procedure FreeResource; virtual;
												procedure InstallDesktop(tIndx,oIndx: integer); virtual;
												procedure RemoveDesktop; virtual;
												procedure LoadMenu(Indx: integer); virtual;
												procedure DrawMenu; virtual;
												procedure FreeMenu; virtual;
  		                  procedure InitGEM; virtual;
  		                  procedure ExitGEM; virtual;
  		                  procedure SetupVDI; virtual;
  		                  procedure InitApplication; virtual;
  		                  procedure InitInstance; virtual;
  		                  procedure InitMainWindow; virtual;
  		                  function GetCurrInstance: integer; virtual;
												function GetGPWindow(gHnd: integer): PWindow; virtual;
												function GetPWindow(Hnd: HWnd): PWindow; virtual;
												function GetPTopWindow: PWindow; virtual;
												function GetMsTimer: longint; virtual;
												procedure GetCrsRect(var crect: GRECT); virtual;
  		                  function GetEvent(var data: TEventData): integer; virtual;
  		                  procedure MessageLoop; virtual;
  		                  procedure MUKeybd(data: TEventData); virtual;
  		                  procedure MUButton(data: TEventData); virtual;
												procedure MURubbox(r: GRECT); virtual;
												procedure MURBoxChanged(r: GRECT); virtual;
  		                  procedure MUM1(data: TEventData); virtual;
  		                  procedure MUM2(data: TEventData); virtual;
  		                  procedure MUMesag(data: TEventData); virtual;
  		                  procedure MUTimer(data: TEventData); virtual;
												procedure MNSelected(meNum,mtNum: integer; Tree: PTree; PrIndx: integer); virtual;
												procedure ACOpen(mID: integer); virtual;
												function ACClose(mID,Why: integer): integer; virtual;
												function APTerm(Why: integer): integer; virtual;
												procedure APDragDrop(PipeID,OrgID,WindID,mX,mY,KStat: integer); virtual;
												procedure ShutCompleted(Stat,ErrID,ErrCode: integer); virtual;
												procedure ResChCompleted(Stat: integer); virtual;
												procedure CHExit(ChID,ChRet: integer); virtual;
												procedure HandleDragDrop(PipeID,OrgID,WindID,mX,mY,KStat: integer); virtual;
												procedure HandleKeybd(Stat,Key: integer); virtual;
												procedure HandleButton(mX,mY,BStat,KStat,Clicks: integer); virtual;
												procedure HandleM1(mX,mY,BStat,KStat: integer); virtual;
												procedure HandleM2(mX,mY,BStat,KStat: integer); virtual;
												procedure HandleMesag(Pipe: Pipearray); virtual;
												procedure HandleAV(Pipe: Pipearray); virtual;
												procedure HandleXAcc(Pipe: Pipearray); virtual;
												procedure HandleTimer; virtual;
												procedure HandleMenu(meNum: integer); virtual;
												procedure HandleError; virtual;
												procedure Terminate; virtual;
  		                  procedure Run; virtual;
  		                  procedure Quit; virtual;
												function FirstWndThat(Test: PIterationFunc): PWindow; virtual;
												procedure ForEachWnd(Action: PIterationProc); virtual;
  		                  function ExecDialog(ADialog: PDialog): integer; virtual;
  		                  function Alert(AParent: PWindow; DefBtn: integer; Sign: longint; Txt,Btn: string): integer; virtual;
  		                  function Popup(APopup: PPopup; x,y,Flag: integer): integer; virtual;
												function Rubbox(WHnd,x,y,xmin,ymin,xmax,ymax: integer; var r: GRECT): boolean; virtual;
												procedure InvalidateRect(Wnd: HWnd; Rect: PGRECT); virtual;
												procedure RestoreModalDialog(p: PWindow); virtual;
												procedure DeskRedraw; virtual;
												procedure SetQuit(mNum,tNum: integer); virtual;
  		                  function ChkError: integer; virtual;
  		                  function ChkSpeedoError: integer; virtual;
  		                  procedure Error(ErrorCode: integer); virtual;
  		 			          end;

       TDialog = object(TWindow)
    							 public
     							 CtrlList      : PControl;
     							 TransferBuffer: pointer;
									 IsModal,Cont  : boolean;
									 Result        : integer;
									 constructor Init(AParent: PWindow; ATitle: string; Indx: integer);
                   destructor Done; virtual;
                   function GetStyle: integer; virtual;
                   procedure GetWindowClass(var AWndClass: TWndClass); virtual;
                   function GetClassName: string; virtual;
                   function GetKBHandler: PEvent; virtual;
                   function IsDialog: boolean; virtual;
                   procedure LoadDialog(Indx: integer); virtual;
                   procedure UpdateDialog; virtual;
                   procedure SetupWindow; virtual;
                   procedure MakeWindow; virtual;
                   procedure Create; virtual;
                   procedure OpenWindow; virtual;
                   procedure CloseWindow; virtual;
                   procedure Destroy; virtual;
                   procedure Paint(var PaintInfo: TPaintStruct); virtual;
                   procedure ObjcPaint(Indx: integer); virtual;
									 procedure GetWorkMax(var maxX,maxY: integer); virtual;
                   procedure WMClosed; virtual;
									 procedure WMButton(mX,mY,BStat,KStat,Clicks: integer); virtual;
									 procedure Execute; virtual;
                   procedure EndDlg(Indx: integer; DblClick: boolean); virtual;
                   procedure TransferData(Direction: word); virtual;
                   function ExitDlg(AnIndx: integer): boolean; virtual;
                   function OK: boolean; virtual;
                   function Cancel: boolean; virtual;
                   function Help: boolean; virtual;
                   function Undo: boolean; virtual;
                   function Esc: boolean; virtual;
									 function FirstThat(Test: PIterationFunc): PControl; virtual;
									 procedure ForEach(Action: PIterationProc); virtual;
									 procedure InitFocus; virtual;
									 procedure SetFocus(Obj: integer); virtual;
									 function GetFocus: integer; virtual;
									 procedure CallChanged(Indx: integer; dclk,edt: boolean); virtual;
                 end;

			 TKeyMenu = object(TEvent)
										public
										ADialog               : PDialog;
										VStat,VKey,VMNum,VTNum: integer;
										VPipe                 : PPipearray;
										VGHnd                 : boolean;
										constructor Init(AParent: PEventObject; Stat,Key,mNum,tNum: integer);
										destructor Done; virtual;
										function TestKey(Stat,Key: integer): boolean; virtual;
										function TestMenu(mNum: integer): boolean; virtual;
										function GetState: integer; virtual;
										procedure SetState(StateFlag: integer); virtual;
										procedure Disable; virtual;
										procedure Enable; virtual;
										function GetText: string; virtual;
										procedure SetText(ATextString: string); virtual;
										function GetCheck: integer; virtual;
										procedure SetCheck(CheckFlag: integer); virtual;
										procedure Check; virtual;
										procedure Uncheck; virtual;
										procedure Toggle; virtual;
								 end;

			 TKey = object(TKeyMenu)
								public
			 					constructor Init(AParent: PEventObject; Stat,Key: integer; Msg: pointer; GetHnd: boolean);
			 					function TestMenu(mNum: integer): boolean; virtual;
							end;

			 TMenu = object(TKeyMenu)
								 public
			 					 constructor Init(AParent: PEventObject; mNum: integer; Msg: pointer; GetHnd: boolean);
			 					 function TestKey(Stat,Key: integer): boolean; virtual;
							 end;


  var Application: PApplication;
      GP         : record
										 charWidth,charHeight : integer;
										 boxWidth,boxHeight   : integer;
										 horAlign,verAlign    : integer;
										 wrmode,ltype,lwidth  : integer;
										 lcolor,mtype,mheight : integer;
										 mcolor,tpoint,theight: integer;
										 trotation,teffects   : integer;
										 tcolor,fstyle,fcolor : integer;
										 finterior,fperimeter : integer;
										 lendsb,lendse,ludsty : integer;
										 font                 : integer;
										 mnr                  : HCursor;
										 mform                : MFORM;
										 clip                 : ARRAY_4
                  end;


	procedure Abstract;
	procedure UpdateGPValues;
	function StrPLeft(s: string; c: integer): string;
	function StrPRight(s: string; c: integer): string;
	function StrPTrimF(s: string): string;
	procedure StrPTrim(var s: string);
	function StrPSpace(anz: integer): string;
	function StrPUpper(s: string): string;
  function NewStr(s: string): PString;
  procedure DisposeStr(var p: PString);
	function ChrNew(s: string): PChar;
	procedure ChrDispose(var p: PChar);
	function RPos(subStr,Str: string): byte;
	function ltoa(l: longint): string;
	function atol(s: string): longint;
	function ftoa(f: real): string;
	function atof(s: string): real;
	function Ptr(hi,lo: word): pointer;
	function NewCookie(cookie: TCookieID; value: longint): boolean;
	function RemoveCookie(cookie: TCookieID): boolean;
  function GetCookie(cookie: TCookieID; var value: longint): boolean;
  function ChangeCookie(cookie: TCookieID; newval: longint): boolean;
  function GetOSHeaderPtr: pointer;
  function MapKey(key: integer): integer;
	function BootDevice: string;
  function GEMVersion: word;
  function MiNTVersion: word;
  function GEMDOSVersion: word;
  function TOSVersion: word;
  function TOSDate: longint;
  function IsDesktopActive: boolean;
  function Max(a,b: longint): longint;
  function Min(a,b: longint): longint;
  function Between(x,min,max: longint): boolean;
  function Sgn(x: longint): integer;
  function HiWord(p: pointer): word;
  function LoWord(p: pointer): word;
	function bTst(value,mask: longint): boolean;
	procedure GRtoA2(var r: GRECT);
	procedure A2toGR(var r: GRECT);
  function rc_intersect(r1: GRECT; var r2: GRECT): boolean;
	procedure form_box(flag: integer; r: GRECT);
	function StrLPas(p: PChar; maxc: integer): string;
	function VtoS(w: word): string;
	function DtoS(l: longint): string;
	procedure GetQSB(var p: pointer; var len: longint);
	procedure GetDesk(var r: GRECT);
	function Exist(FileName: string): boolean;
	function FileSelect(AParent: PWindow; ATitle,AMask: string; var APath,AFile: string; ForceExist: boolean): boolean;
	function WritePrivateProfileString(AppName,KeyName,Value,FileName: string): boolean;
	function WritePrivateProfileInt(AppName,KeyName: string; Value: longint; FileName: string): boolean;
	function GetPrivateProfileString(AppName,KeyName,Default,FileName: string): string;
	function GetPrivateProfileInt(AppName,KeyName: string; Default: longint; FileName: string): longint;
	procedure appl_yield;
	procedure vr_trnfm(handle: integer; psrcMFDB,pdesMFDB: MFDB);
	procedure vr_convert(handle: integer; psrcMFDB: MFDB; format: integer);
	procedure vdi_fix(var pfd: MFDB; theAddr: pointer; wb,h: integer);
	function IsMouseVisible: boolean;
	function IsMouseBusy: boolean;
	procedure ShowMouse;
	procedure HideMouse;
	procedure ArrowMouse;
	procedure BusyMouse;
	procedure LastMouse;

