home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / tpwinst / doc.pak / WOBJECTS.INT < prev   
Text File  |  1991-05-21  |  34KB  |  1,024 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Turbo Pascal for Windows                        }
  4. {       ObjectWindows Unit                              }
  5. {                                                       }
  6. {       Copyright (c) 1991 Borland International        }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit WObjects;
  11.  
  12. {$S-}
  13.  
  14. interface
  15.  
  16. uses WinTypes, WinProcs, Strings;
  17.  
  18. const
  19.  
  20. { Application message constants }
  21.  
  22.   wm_First    = $0000;          { $0000-$7FFF window messages }
  23.   id_First    = $8000;          { $8000-$8FFF child id messages }
  24.   id_Internal = $8F00;          { $8F00-$8FFF reserved for internal use }
  25.   nf_First    = $9000;          { $9000-$9FFF notification messages }
  26.   nf_Internal = $9F00;          { $9F00-$9FFF reserved for internal use }
  27.   cm_First    = $A000;          { $A000-$FFFF command messages }
  28.   cm_Internal = $FF00;          { $FF00-$FFFF reserved for internal use }
  29.   wm_Count    = $8000;          { Number of window messages }
  30.   id_Count    = $1000;          { Number of child ID messages }
  31.   nf_Count    = $1000;          { Number of notification messages }
  32.   cm_Count    = $6000;          { Number of command messages }
  33.  
  34. { Standard child ID messages }
  35.  
  36.   id_Reserved      = id_Internal - id_First;
  37.   id_FirstMDIChild = id_Reserved + 1;
  38.   id_MDIClient     = id_Reserved + 2;
  39.  
  40. { Standard command messages }
  41.  
  42.   cm_Reserved        = cm_Internal - cm_First;
  43.   cm_EditCut         = cm_Reserved + 0;
  44.   cm_EditCopy        = cm_Reserved + 1;
  45.   cm_EditPaste       = cm_Reserved + 2;
  46.   cm_EditDelete      = cm_Reserved + 3;
  47.   cm_EditClear       = cm_Reserved + 4;
  48.   cm_EditUndo        = cm_Reserved + 5;
  49.   cm_EditFind        = cm_Reserved + 6;
  50.   cm_EditReplace     = cm_Reserved + 7;
  51.   cm_EditFindNext    = cm_Reserved + 8;
  52.  
  53.   cm_FileNew         = cm_Reserved + 9;
  54.   cm_FileOpen        = cm_Reserved + 10;
  55.   cm_MDIFileNew      = cm_Reserved + 11;
  56.   cm_MDIFileOpen     = cm_Reserved + 12;
  57.   cm_FileSave        = cm_Reserved + 13;
  58.   cm_FileSaveAs      = cm_Reserved + 14;
  59.   cm_ArrangeIcons    = cm_Reserved + 15;
  60.   cm_TileChildren    = cm_Reserved + 16;
  61.   cm_CascadeChildren = cm_Reserved + 17;
  62.   cm_CloseChildren   = cm_Reserved + 18;
  63.   cm_CreateChild     = cm_Reserved + 19;
  64.   cm_Exit            = cm_Reserved + 20;
  65.  
  66. { TWindowsObject Flags masks }
  67.  
  68.   wb_KBHandler    = $01;
  69.   wb_FromResource = $02;
  70.   wb_AutoCreate   = $04;
  71.   wb_MDIChild     = $08;
  72.   wb_Transfer     = $10;
  73.  
  74. { TWindowsObject Status codes }
  75.  
  76.   em_InvalidWindow     = -1;
  77.   em_OutOfMemory       = -2;
  78.   em_InvalidClient     = -3;
  79.   em_InvalidChild      = -4;
  80.   em_InvalidMainWindow = -5;
  81.  
  82. { TWindowsObject Transfer codes }
  83.  
  84.   tf_SizeData = 0;
  85.   tf_GetData  = 1;
  86.   tf_SetData  = 2;
  87.  
  88. { TCheckBox check states }
  89.  
  90.   bf_Unchecked = 0;
  91.   bf_Checked   = 1;
  92.   bf_Grayed    = 2;
  93.  
  94. { TStream access modes }
  95.  
  96.   stCreate    = $3C00;          { Create new file }
  97.   stOpenRead  = $3D00;          { Read access only }
  98.   stOpenWrite = $3D01;          { Write access only }
  99.   stOpen      = $3D02;          { Read and write access }
  100.  
  101. { TStream error codes }
  102.  
  103.   stOk         =  0;            { No error }
  104.   stError      = -1;            { Access error }
  105.   stInitError  = -2;            { Cannot initialize stream }
  106.   stReadError  = -3;            { Read beyond end of stream }
  107.   stWriteError = -4;            { Cannot expand stream }
  108.   stGetError   = -5;            { Get of unregistered object type }
  109.   stPutError   = -6;            { Put of unregistered object type }
  110.  
  111. { Maximum TCollection size }
  112.  
  113.   MaxCollectionSize = 65520 div SizeOf(Pointer);
  114.  
  115. { TCollection error codes }
  116.  
  117.   coIndexError = -1;            { Index out of range }
  118.   coOverflow   = -2;            { Overflow }
  119.  
  120. type
  121.  
  122. { String pointer }
  123.  
  124.   PString = ^String;
  125.  
  126. { Type conversion records }
  127.  
  128.   WordRec = record Lo, Hi: Byte end;
  129.   LongRec = record Lo, Hi: Word end;
  130.   PtrRec = record Ofs, Seg: Word end;
  131.  
  132. { General arrays }
  133.  
  134.   PByteArray = ^TByteArray;
  135.   TByteArray = array[0..32767] of Byte;
  136.   PWordArray = ^TWordArray;
  137.   TWordArray = array[0..16383] of Word;
  138.  
  139. { TObject base object }
  140.  
  141.   PObject = ^TObject;
  142.   TObject = object
  143.     constructor Init;
  144.     procedure Free;
  145.     destructor Done; virtual;
  146.   end;
  147.  
  148. { TStreamRec }
  149.  
  150.   PStreamRec = ^TStreamRec;
  151.   TStreamRec = record
  152.     ObjType: Word;
  153.     VmtLink: Word;
  154.     Load: Pointer;
  155.     Store: Pointer;
  156.     Next: Word;
  157.   end;
  158.  
  159. { TStream }
  160.  
  161.   PStream = ^TStream;
  162.   TStream = object(TObject)
  163.     Status: Integer;
  164.     ErrorInfo: Integer;
  165.     constructor Init;
  166.     procedure CopyFrom(var S: TStream; Count: Longint);
  167.     procedure Error(Code, Info: Integer); virtual;
  168.     procedure Flush; virtual;
  169.     function Get: PObject;
  170.     function GetPos: Longint; virtual;
  171.     function GetSize: Longint; virtual;
  172.     procedure Put(P: PObject);
  173.     procedure Read(var Buf; Count: Word); virtual;
  174.     function ReadStr: PString;
  175.     procedure Reset;
  176.     procedure Seek(Pos: Longint); virtual;
  177.     function StrRead: PChar;
  178.     procedure StrWrite(P: PChar);
  179.     procedure Truncate; virtual;
  180.     procedure Write(var Buf; Count: Word); virtual;
  181.     procedure WriteStr(P: PString);
  182.   end;
  183.  
  184. { TDosStream }
  185.  
  186.   PDosStream = ^TDosStream;
  187.   TDosStream = object(TStream)
  188.     Handle: Word;
  189.     constructor Init(FileName: PChar; Mode: Word);
  190.     destructor Done; virtual;
  191.     function GetPos: Longint; virtual;
  192.     function GetSize: Longint; virtual;
  193.     procedure Read(var Buf; Count: Word); virtual;
  194.     procedure Seek(Pos: Longint); virtual;
  195.     procedure Truncate; virtual;
  196.     procedure Write(var Buf; Count: Word); virtual;
  197.   end;
  198.  
  199. { TBufStream }
  200.  
  201.   PBufStream = ^TBufStream;
  202.   TBufStream = object(TDosStream)
  203.     Buffer: Pointer;
  204.     BufSize: Word;
  205.     BufPtr: Word;
  206.     BufEnd: Word;
  207.     constructor Init(FileName: PChar; Mode, Size: Word);
  208.     destructor Done; virtual;
  209.     procedure Flush; virtual;
  210.     function GetPos: Longint; virtual;
  211.     function GetSize: Longint; virtual;
  212.     procedure Read(var Buf; Count: Word); virtual;
  213.     procedure Seek(Pos: Longint); virtual;
  214.     procedure Truncate; virtual;
  215.     procedure Write(var Buf; Count: Word); virtual;
  216.   end;
  217.  
  218. { TEmsStream }
  219.  
  220.   PEmsStream = ^TEmsStream;
  221.   TEmsStream = object(TStream)
  222.     Handle: Word;
  223.     PageCount: Word;
  224.     Size: Longint;
  225.     Position: Longint;
  226.     constructor Init(MinSize, MaxSize: Longint);
  227.     destructor Done; virtual;
  228.     function GetPos: Longint; virtual;
  229.     function GetSize: Longint; virtual;
  230.     procedure Read(var Buf; Count: Word); virtual;
  231.     procedure Seek(Pos: Longint); virtual;
  232.     procedure Truncate; virtual;
  233.     procedure Write(var Buf; Count: Word); virtual;
  234.   end;
  235.  
  236. { TCollection types }
  237.  
  238.   PItemList = ^TItemList;
  239.   TItemList = array[0..MaxCollectionSize - 1] of Pointer;
  240.  
  241. { TCollection object }
  242.  
  243.   PCollection = ^TCollection;
  244.   TCollection = object(TObject)
  245.     Items: PItemList;
  246.     Count: Integer;
  247.     Limit: Integer;
  248.     Delta: Integer;
  249.     constructor Init(ALimit, ADelta: Integer);
  250.     constructor Load(var S: TStream);
  251.     destructor Done; virtual;
  252.     function At(Index: Integer): Pointer;
  253.     procedure AtDelete(Index: Integer);
  254.     procedure AtFree(Index: Integer);
  255.     procedure AtInsert(Index: Integer; Item: Pointer);
  256.     procedure AtPut(Index: Integer; Item: Pointer);
  257.     procedure Delete(Item: Pointer);
  258.     procedure DeleteAll;
  259.     procedure Error(Code, Info: Integer); virtual;
  260.     function FirstThat(Test: Pointer): Pointer;
  261.     procedure ForEach(Action: Pointer);
  262.     procedure Free(Item: Pointer);
  263.     procedure FreeAll;
  264.     procedure FreeItem(Item: Pointer); virtual;
  265.     function GetItem(var S: TStream): Pointer; virtual;
  266.     function IndexOf(Item: Pointer): Integer; virtual;
  267.     procedure Insert(Item: Pointer); virtual;
  268.     function LastThat(Test: Pointer): Pointer;
  269.     procedure Pack;
  270.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  271.     procedure SetLimit(ALimit: Integer); virtual;
  272.     procedure Store(var S: TStream);
  273.   end;
  274.  
  275. { TSortedCollection object }
  276.  
  277.   PSortedCollection = ^TSortedCollection;
  278.   TSortedCollection = object(TCollection)
  279.     Duplicates: Boolean;
  280.     constructor Init(ALimit, ADelta: Integer);
  281.     constructor Load(var S: TStream);
  282.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  283.     function IndexOf(Item: Pointer): Integer; virtual;
  284.     procedure Insert(Item: Pointer); virtual;
  285.     function KeyOf(Item: Pointer): Pointer; virtual;
  286.     function Search(Key: Pointer; var Index: Integer): Boolean; virtual;
  287.     procedure Store(var S: TStream);
  288.   end;
  289.  
  290. { TStringCollection object }
  291.  
  292.   PStringCollection = ^TStringCollection;
  293.   TStringCollection = object(TSortedCollection)
  294.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  295.     procedure FreeItem(Item: Pointer); virtual;
  296.     function GetItem(var S: TStream): Pointer; virtual;
  297.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  298.   end;
  299.  
  300. { TStrCollection object }
  301.  
  302.   PStrCollection = ^TStrCollection;
  303.   TStrCollection = object(TSortedCollection)
  304.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  305.     procedure FreeItem(Item: Pointer); virtual;
  306.     function GetItem(var S: TStream): Pointer; virtual;
  307.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  308.   end;
  309.  
  310. { TMessage windows message record }
  311.  
  312.   PMessage = ^TMessage;
  313.   TMessage = record
  314.     Receiver: HWnd;
  315.     Message: Word;
  316.     case Integer of
  317.       0: (
  318.         WParam: Word;
  319.         LParam: Longint;
  320.         Result: Longint);
  321.       1: (
  322.         WParamLo: Byte;
  323.         WParamHi: Byte;
  324.         LParamLo: Word;
  325.         LParamHi: Word;
  326.         ResultLo: Word;
  327.         ResultHi: Word);
  328.   end;
  329.  
  330. { ObjectWindows pointer types }
  331.  
  332.   PWindowsObject = ^TWindowsObject;
  333.   PWindow        = ^TWindow;
  334.   PDialog        = ^TDialog;
  335.   PDlgWindow     = ^TDlgWindow;
  336.   PMDIWindow     = ^TMDIWindow;
  337.   PControl       = ^TControl;
  338.   PButton        = ^TButton;
  339.   PCheckBox      = ^TCheckBox;
  340.   PRadioButton   = ^TRadioButton;
  341.   PGroupBox      = ^TGroupBox;
  342.   PStatic        = ^TStatic;
  343.   PEdit          = ^TEdit;
  344.   PListBox       = ^TListBox;
  345.   PComboBox      = ^TComboBox;
  346.   PScrollBar     = ^TScrollBar;
  347.   PMDIClient     = ^TMDIClient;
  348.   PScroller      = ^TScroller;
  349.   PApplication   = ^TApplication;
  350.  
  351. { TWindowsObject object }
  352.  
  353.   TWindowsObject = object(TObject)
  354.     Status: Integer;
  355.     HWindow: HWnd;
  356.     Parent, ChildList: PWindowsObject;
  357.     TransferBuffer: Pointer;
  358.     Instance: TFarProc;
  359.     Flags: Byte;
  360.     constructor Init(AParent: PWindowsObject);
  361.     constructor Load(var S: TStream);
  362.     destructor Done; virtual;
  363.     procedure Store(var S: TStream);
  364.     procedure DefWndProc(var Msg: TMessage); virtual {index 8};
  365.     procedure DefCommandProc(var Msg: TMessage); virtual {index 12};
  366.     procedure DefChildProc(var Msg: TMessage); virtual {index 16};
  367.     procedure DefNotificationProc(var Msg: TMessage); virtual {index 20};
  368.     procedure SetFlags(Mask: Byte; OnOff: Boolean);
  369.     function IsFlagSet(Mask: Byte): Boolean;
  370.     function FirstThat(Test: Pointer): PWindowsObject;
  371.     procedure ForEach(Action: Pointer);
  372.     function Next: PWindowsObject;
  373.     function Previous: PWindowsObject;
  374.     procedure EnableKBHandler;
  375.     procedure EnableAutoCreate;
  376.     procedure DisableAutoCreate;
  377.     procedure EnableTransfer;
  378.     procedure DisableTransfer;
  379.     function Register: Boolean; virtual;
  380.     function Create: Boolean; virtual;
  381.     procedure Destroy; virtual;
  382.     function GetId: Integer; virtual;
  383.     function ChildWithId(Id: Integer): PWindowsObject;
  384.     function GetClassName: PChar; virtual;
  385.     function GetClient: PMDIClient; virtual;
  386.     procedure GetChildPtr(var S: TStream; var P);
  387.     procedure PutChildPtr(var S: TStream; P: PWindowsObject);
  388.     procedure GetSiblingPtr(var S: TStream; var P);
  389.     procedure PutSiblingPtr(var S: TStream; P: PWindowsObject);
  390.     procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  391.     procedure SetupWindow; virtual;
  392.     procedure Show(ShowCmd: Integer);
  393.     function CanClose: Boolean;  virtual;
  394.     function Transfer(DataPtr: Pointer; TransferFlag: Word): Word; virtual;
  395.     procedure TransferData(Direction: Word); virtual;
  396.     procedure DispatchScroll(var Msg: TMessage); virtual;
  397.     procedure CloseWindow;
  398.     procedure GetChildren(var S: TStream);
  399.     procedure PutChildren(var S: TStream);
  400.     function CreateChildren: Boolean;
  401.     procedure WMVScroll(var Msg: TMessage); virtual wm_First + wm_VScroll;
  402.     procedure WMHScroll(var Msg: TMessage); virtual wm_First + wm_HScroll;
  403.     procedure WMCommand(var Msg: TMessage); virtual wm_First + wm_Command;
  404.     procedure WMClose(var Msg: TMessage); virtual wm_First + wm_Close;
  405.     procedure WMDestroy(var Msg: TMessage); virtual wm_First + wm_Destroy;
  406.     procedure WMNCDestroy(var Msg: TMessage); virtual wm_First + wm_NCDestroy;
  407.     procedure WMActivate(var Msg: TMessage); virtual wm_First + wm_Activate;
  408.     procedure WMQueryEndSession(var Msg: TMessage);
  409.       virtual wm_First + wm_QueryEndSession;
  410.     procedure CMExit(var Msg: TMessage); virtual cm_First + cm_Exit;
  411.   end;
  412.  
  413. { TWindow creation attributes }
  414.  
  415.   TWindowAttr = record
  416.     Title: PChar;
  417.     Style: LongInt;
  418.     ExStyle: LongInt;
  419.     X, Y, W, H: Integer;
  420.     Param: Pointer;
  421.     case Integer of
  422.       0: (Menu: HMenu);         { Menu handle }
  423.       1: (Id: Integer);         { Child identifier }
  424.   end;
  425.  
  426. { TWindow object }
  427.  
  428.   TWindow = object(TWindowsObject)
  429.     Attr: TWindowAttr;
  430.     DefaultProc: TFarProc;
  431.     Scroller: PScroller;
  432.     FocusChildHandle: THandle;
  433.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  434.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  435.     constructor Load(var S: TStream);
  436.     destructor Done; virtual;
  437.     procedure Store(var S: TStream);
  438.     procedure SetCaption(ATitle: PChar);
  439.     procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  440.     function GetId: Integer; virtual;
  441.     function Create: Boolean; virtual;
  442.     procedure DefWndProc(var Msg: TMessage); virtual;
  443.     procedure WMActivate(var Msg: TMessage);
  444.       virtual wm_First + wm_Activate;
  445.     procedure SetupWindow; virtual;
  446.     procedure WMCreate(var Msg: TMessage);
  447.       virtual wm_First + wm_Create;
  448.     procedure WMHScroll(var Msg: TMessage);
  449.       virtual wm_First + wm_HScroll;
  450.     procedure WMVScroll(var Msg: TMessage);
  451.       virtual wm_First + wm_VScroll;
  452.     procedure WMPaint(var Msg: TMessage);
  453.       virtual wm_First + wm_Paint;
  454.     procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
  455.     procedure WMSize(var Msg: TMessage);
  456.       virtual wm_First + wm_Size;
  457.     procedure WMMove(var Msg: TMessage);
  458.       virtual wm_First + wm_Move;
  459.     procedure WMLButtonDown(var Msg: TMessage);
  460.       virtual wm_First + wm_LButtonDown;
  461.   end;
  462.  
  463. { TDialog creation attributes }
  464.  
  465.   TDialogAttr = record
  466.     Name: PChar;
  467.     Param: LongInt;
  468.   end;
  469.  
  470. { TDialog object }
  471.  
  472.   TDialog = object(TWindowsObject)
  473.     Attr: TDialogAttr;
  474.     IsModal: Boolean;
  475.     constructor Init(AParent: PWindowsObject; AName: PChar);
  476.     constructor Load(var S: TStream);
  477.     destructor Done; virtual;
  478.     procedure Store(var S: TStream);
  479.     function Create: Boolean; virtual;
  480.     function Execute: Integer; virtual;
  481.     procedure EndDlg(ARetValue: Integer); virtual;
  482.     procedure Destroy; virtual;
  483.     function GetItemHandle(DlgItemID: Integer): HWnd;
  484.     function SendDlgItemMsg(DlgItemID: Integer; AMsg, WParam: Word;
  485.       LParam: LongInt): LongInt;
  486.     procedure Ok(var Msg: TMessage); virtual id_First + id_Ok;
  487.     procedure EnterOk(var Msg: TMessage); virtual cm_First + id_Ok;
  488.     procedure Cancel(var Msg: TMessage); virtual id_First + id_Cancel;
  489.     procedure EnterCancel(var Msg: TMessage); virtual cm_First + id_Cancel;
  490.     procedure WMInitDialog(var Msg: TMessage);
  491.       virtual wm_First + wm_InitDialog;
  492.     procedure WMClose(var Msg: TMessage);
  493.       virtual wm_First + wm_Close;
  494.     procedure DefWndProc(var Msg: TMessage); virtual;
  495.   end;
  496.  
  497. { TDlgWindow object }
  498.  
  499.   TDlgWindow = object(TDialog)
  500.     constructor Init(AParent: PWindowsObject; AName: PChar);
  501.     procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  502.     function Create: Boolean; virtual;
  503.     procedure Ok(var Msg: TMessage); virtual id_First + id_OK;
  504.     procedure Cancel(var Msg: TMessage); virtual id_First + id_Cancel;
  505.   end;
  506.  
  507. { TMDIWindow object }
  508.  
  509.   TMDIWindow = object(TWindow)
  510.     ClientWnd:  PMDIClient;
  511.     ChildMenuPos: Integer;
  512.     constructor Init(ATitle: PChar; AMenu: HMenu);
  513.     destructor Done; virtual;
  514.     constructor Load(var S: TStream);
  515.     procedure Store(var S: TStream);
  516.     procedure SetupWindow; virtual;
  517.     procedure InitClientWindow; virtual;
  518.     function GetClassName: PChar; virtual;
  519.     function GetClient: PMDIClient; virtual;
  520.     procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  521.     procedure DefWndProc(var Msg: TMessage); virtual;
  522.     function InitChild: PWindowsObject; virtual;
  523.     function CreateChild: PWindowsObject; virtual;
  524.     procedure CMCreateChild(var Msg: TMessage);
  525.       virtual cm_First + cm_CreateChild;
  526.     procedure TileChildren; virtual;
  527.     procedure CascadeChildren; virtual;
  528.     procedure ArrangeIcons; virtual;
  529.     procedure CloseChildren; virtual;
  530.     procedure CMTileChildren(var Msg: TMessage);
  531.       virtual cm_First + cm_TileChildren;
  532.     procedure CMCascadeChildren(var Msg: TMessage);
  533.       virtual cm_First + cm_CascadeChildren;
  534.     procedure CMArrangeIcons(var Msg: TMessage);
  535.       virtual cm_First + cm_ArrangeIcons;
  536.     procedure CMCloseChildren(var Msg: TMessage);
  537.       virtual cm_First + cm_CloseChildren;
  538.   end;
  539.  
  540. { TControl object }
  541.  
  542.   TControl = object(TWindow)
  543.     constructor Init(AParent: PWindowsObject; AnId: Integer;
  544.       ATitle: PChar; X, Y, W, H: Integer);
  545.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  546.     function Register: Boolean; virtual;
  547.     function GetClassName: PChar; virtual;
  548.     procedure WMPaint(var Msg: TMessage); virtual wm_First + wm_Paint;
  549.   end;
  550.  
  551. { TButton object }
  552.  
  553.   TButton = object(TControl)
  554.     constructor Init(AParent: PWindowsObject; AnId: Integer;
  555.       AText: PChar; X, Y, W, H: Integer; IsDefault: Boolean);
  556.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  557.     function GetClassName: PChar; virtual;
  558.   end;
  559.  
  560. { TCheckBox object }
  561.  
  562.   TCheckBox = object(TButton)
  563.     Group: PGroupBox;
  564.     constructor Init(AParent: PWindowsObject; AnID: Integer;
  565.       ATitle: PChar; X, Y, W, H: Integer; AGroup: PGroupBox);
  566.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  567.     constructor Load(var S: TStream);
  568.     procedure Store(var S: TStream);
  569.     procedure Check;
  570.     procedure Uncheck;
  571.     procedure Toggle;
  572.     function GetCheck: Word;
  573.     procedure SetCheck(CheckFlag: Word);
  574.     function Transfer(DataPtr: Pointer; TransferFlag: Word): Word; virtual;
  575.     procedure BNClicked(var Msg: TMessage);
  576.       virtual nf_First + bn_Clicked;
  577.   end;
  578.  
  579. { TRadioButton object }
  580.  
  581.   TRadioButton = object(TCheckBox)
  582.     constructor Init(AParent: PWindowsObject; AnID: Integer;
  583.       ATitle: PChar; X, Y, W, H: Integer; AGroup: PGroupBox);
  584.   end;
  585.  
  586. { TGroupBox object }
  587.  
  588.   TGroupBox = object(TControl)
  589.     NotifyParent: Boolean;
  590.     constructor Init(AParent: PWindowsObject; AnID: Integer;
  591.       AText: PChar; X, Y, W, H: Integer);
  592.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  593.     constructor Load(var S: TStream);
  594.     procedure Store(var S: TStream);
  595.     function GetClassName: PChar; virtual;
  596.     procedure SelectionChanged(ControlId: Integer); virtual;
  597.   end;
  598.  
  599. { TStatic object }
  600.  
  601.   TStatic = object(TControl)
  602.     TextLen: Word;
  603.     constructor Init(AParent: PWindowsObject; AnId: Integer;
  604.       ATitle: PChar; X, Y, W, H: Integer; ATextLen: Word);
  605.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word;
  606.       ATextLen: Word);
  607.     constructor Load(var S: TStream);
  608.     procedure Store(var S: TStream);
  609.     function GetClassName: PChar; virtual;
  610.     function GetText(ATextString: PChar; MaxChars: Integer): Integer;
  611.     procedure SetText(ATextString: PChar);
  612.     procedure Clear;
  613.     function Transfer(DataPtr: Pointer; TransferFlag: Word): Word; virtual;
  614.   end;
  615.  
  616. { TEdit object }
  617.  
  618.   TEdit = object(TStatic)
  619.     constructor Init(AParent: PWindowsObject; AnId: Integer; ATitle: PChar;
  620.        X, Y, W, H: Integer; ATextLen: Word; Multiline: Boolean);
  621.     function GetClassName: PChar; virtual;
  622.     procedure Undo;
  623.     function CanUndo: Boolean;
  624.     procedure Paste;
  625.     procedure Copy;
  626.     procedure Cut;
  627.     function GetNumLines: Integer;
  628.     function GetLineLength(LineNumber: Integer): Integer;
  629.     function GetLine(ATextString: PChar;
  630.       StrSize, LineNumber: Integer): Boolean;
  631.     procedure GetSubText(ATextString: PChar; StartPos, EndPos: Integer);
  632.     function DeleteSubText(StartPos, EndPos: Integer): Boolean;
  633.     function DeleteLine(LineNumber: Integer): Boolean;
  634.     procedure GetSelection(var StartPos, EndPos: Integer);
  635.     function DeleteSelection: Boolean;
  636.     function IsModified: Boolean;
  637.     procedure ClearModify;
  638.     function GetLineFromPos(CharPos: Integer): Integer;
  639.     function GetLineIndex(LineNumber: Integer): Integer;
  640.     procedure Scroll(HorizontalUnit, VerticalUnit: Integer);
  641.     function SetSelection(StartPos, EndPos: Integer): Boolean;
  642.     procedure Insert(ATextString: PChar);
  643.     function Search(StartPos: Integer; AText: PChar; CaseSensitive: Boolean): Integer;
  644.     procedure SetupWindow; virtual;
  645.     procedure CMEditCut(var Msg: TMessage);
  646.       virtual  cm_First + cm_EditCut;
  647.     procedure CMEditCopy(var Msg: TMessage);
  648.       virtual  cm_First + cm_EditCopy;
  649.     procedure CMEditPaste(var Msg: TMessage);
  650.       virtual  cm_First + cm_EditPaste;
  651.     procedure CMEditDelete(var Msg: TMessage);
  652.       virtual  cm_First + cm_EditDelete;
  653.     procedure CMEditClear(var Msg: TMessage);
  654.       virtual  cm_First + cm_EditClear;
  655.     procedure CMEditUndo(var Msg: TMessage);
  656.       virtual  cm_First + cm_EditUndo;
  657.   end;
  658.  
  659. { TListBox message name type }
  660.  
  661.   TMsgName = (
  662.     mn_AddString, mn_InsertString, mn_DeleteString,
  663.     mn_ResetContent, mn_GetCount, mn_GetText,
  664.     mn_GetTextLen, mn_SelectString, mn_SetCurSel,
  665.     mn_GetCurSel);
  666.  
  667. { Multiple selction transfer record }
  668.  
  669.   PMultiSelRec = ^TMultiSelRec;
  670.   TMultiSelRec = record
  671.     Count: Integer;
  672.     Selections: array[0..32760] of Integer;
  673.   end;
  674.  
  675. { TListBox object }
  676.  
  677.   TListBox = object(TControl)
  678.     constructor Init(AParent: PWindowsObject; AnId: Integer;
  679.       X, Y, W, H: Integer);
  680.     function GetClassName: PChar; virtual;
  681.     function AddString(AString: PChar): Integer;
  682.     function InsertString(AString: PChar; Index: Integer): Integer;
  683.     function DeleteString(Index: Integer): Integer;
  684.     procedure ClearList;
  685.     function Transfer(DataPtr: Pointer; TransferFlag: Word): Word; virtual;
  686.     function GetCount: Integer;
  687.     function GetString(AString: PChar; Index: Integer): Integer;
  688.     function GetStringLen(Index: Integer): Integer;
  689.     function GetSelString(AString: PChar; MaxChars: Integer): Integer;
  690.     function SetSelString(AString: PChar; Index: Integer): Integer;
  691.     function GetSelIndex: Integer;
  692.     function SetSelIndex(Index: Integer): Integer;
  693.   end;
  694.  
  695. { TComboBox object }
  696.  
  697.   TComboBox = object(TListBox)
  698.     TextLen: Word;
  699.     constructor Init(AParent: PWindowsObject; AnID: Integer;
  700.       X, Y, W, H: Integer; AStyle: Word; ATextLen: Word);
  701.     constructor InitResource(AParent: PWindowsObject; ResourceID: Integer;
  702.       ATextLen: Word);
  703.     constructor Load(var S: TStream);
  704.     procedure Store(var S: TStream);
  705.     function GetClassName: PChar; virtual;
  706.     procedure ShowList;
  707.     procedure HideList;
  708.     function Transfer(DataPtr: Pointer; TransferFlag: Word): Word; virtual;
  709.     procedure SetupWindow; virtual;
  710.   end;
  711.  
  712. { TScrollBar transfer record }
  713.  
  714.   TScrollBarTransferRec = record
  715.     LowValue: Integer;
  716.     HighValue: Integer;
  717.     Position: Integer;
  718.   end;
  719.  
  720. { TScrollBar object }
  721.  
  722.   TScrollBar = object(TControl)
  723.     LineMagnitude, PageMagnitude: Integer;
  724.     constructor Init(AParent: PWindowsObject; AnID: Integer;
  725.       X, Y, W, H: Integer; IsHScrollBar: Boolean);
  726.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  727.     constructor Load(var S: TStream);
  728.     procedure Store(var S: TStream);
  729.     function GetClassName: PChar; virtual;
  730.     procedure SetupWindow; virtual;
  731.     procedure GetRange(var LoVal, HiVal: Integer);
  732.     function GetPosition: Integer;
  733.     procedure SetRange(LoVal, HiVal: Integer);
  734.     procedure SetPosition(ThumbPos: Integer);
  735.     function DeltaPos(Delta: Integer): Integer;
  736.     function Transfer(DataPtr: Pointer; TransferFlag: Word): Word; virtual;
  737.     procedure SBLineUp(var Msg: TMessage);
  738.       virtual nf_First + sb_LineUp;
  739.     procedure SBLineDown(var Msg: TMessage);
  740.       virtual nf_First + sb_LineDown;
  741.     procedure SBPageUp(var Msg: TMessage);
  742.       virtual nf_First + sb_PageUp;
  743.     procedure SBPageDown(var Msg: TMessage);
  744.       virtual nf_First + sb_PageDown;
  745.     procedure SBThumbPosition(var Msg: TMessage);
  746.       virtual nf_First + sb_ThumbPosition;
  747.     procedure SBThumbTrack(var Msg: TMessage);
  748.       virtual nf_First + sb_ThumbTrack;
  749.     procedure SBTop(var Msg: TMessage);
  750.       virtual nf_First + sb_Top;
  751.     procedure SBBottom(var Msg: TMessage);
  752.       virtual nf_First + sb_Bottom;
  753.   end;
  754.  
  755. { TMDIClient object }
  756.  
  757.   TMDIClient = object(TControl)
  758.     ClientAttr: TClientCreateStruct;
  759.     constructor Init(AParent: PMDIWindow);
  760.     constructor Load(var S: TStream);
  761.     procedure Store(var S: TStream);
  762.     function GetClassName: PChar; virtual;
  763.     procedure TileChildren; virtual;
  764.     procedure CascadeChildren; virtual;
  765.     procedure ArrangeIcons; virtual;
  766.   end;
  767.  
  768. { TScroller object }
  769.  
  770.   TScroller = object(TObject)
  771.     Window: PWindow;
  772.     XPos: LongInt;      { current horizontal pos in horz scroll units }
  773.     YPos: LongInt;      { current vertical pos in vert scroll units }
  774.     XUnit: Integer;     { logical device units per horz scroll unit }
  775.     YUnit: Integer;     { logical device units per vert scroll unit }
  776.     XRange: LongInt;    { # of scrollable horz scroll units }
  777.     YRange: LongInt;    { # of scrollable vert scroll units }
  778.     XLine: Integer;     { # of horz scroll units per line }
  779.     YLine: Integer;     { # of vert scroll units per line }
  780.     XPage: Integer;     { # of horz scroll units per page }
  781.     YPage: Integer;     { # of vert scroll units per page }
  782.     AutoMode: Boolean;  { auto scrolling mode  }
  783.     TrackMode: Boolean; { track scroll mode    }
  784.     AutoOrg: Boolean;   { AutoOrg indicates Scroller offsets origin }
  785.     HasHScrollBar: Boolean;
  786.     HasVScrollBar: Boolean;
  787.     constructor Init(TheWindow: PWindow; TheXUnit, TheYUnit: Integer;
  788.       TheXRange, TheYRange: LongInt);
  789.     constructor Load(var S: TStream);
  790.     procedure Store(var S: TStream);
  791.     procedure SetUnits(TheXUnit, TheYUnit: LongInt);
  792.     procedure SetPageSize; virtual;
  793.     procedure SetSBarRange; virtual;
  794.     procedure SetRange(TheXRange, TheYRange: LongInt);
  795.     procedure BeginView(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
  796.     procedure EndView; virtual;
  797.     procedure VScroll(ScrollRequest: Word; ThumbPos: Integer); virtual;
  798.     procedure HScroll(ScrollRequest: Word; ThumbPos: Integer); virtual;
  799.     procedure ScrollTo(X, Y: LongInt);
  800.     procedure ScrollBy(Dx, Dy: LongInt);
  801.     procedure AutoScroll; virtual;
  802.     function IsVisibleRect(X, Y: LongInt; XExt, YExt: Integer): Boolean;
  803.   end;
  804.  
  805. { TApplication object }
  806.  
  807.   TApplication = object(TObject)
  808.     Status: Integer;
  809.     Name: PChar;
  810.     MainWindow: PWindowsObject;
  811.     HAccTable: THandle;
  812.     KBHandlerWnd: PWindowsObject;
  813.     constructor Init(AName: PChar);
  814.     procedure InitApplication; virtual;
  815.     procedure InitInstance; virtual;
  816.     procedure InitMainWindow; virtual;
  817.     procedure Run; virtual;
  818.     procedure SetKBHandler(AWindowsObject: PWindowsObject);
  819.     procedure MessageLoop; virtual;
  820.     function ProcessAppMsg(var Message: TMsg): Boolean; virtual;
  821.     function ProcessDlgMsg(var Message: TMsg): Boolean; virtual;
  822.     function ProcessAccels(var Message: TMsg): Boolean; virtual;
  823.     function ProcessMDIAccels(var Message: TMsg): Boolean; virtual;
  824.     function MakeWindow(AWindowsObject: PWindowsObject): PWindowsObject; virtual;
  825.     function ExecDialog(ADialog: PWindowsObject): Integer; virtual;
  826.     function ValidWindow(AWindowsObject: PWindowsObject): PWindowsObject; virtual;
  827.     procedure Error(ErrorCode: Integer); virtual;
  828.     function CanClose: Boolean; virtual;
  829.   end;
  830.  
  831. { Abstract notification procedure }
  832.  
  833. procedure Abstract;
  834.  
  835. { Memory management routines }
  836.  
  837. function LowMemory: Boolean;
  838. procedure RestoreMemory;
  839. function MemAlloc(Size: Word): Pointer;
  840. function GetObjectPtr(HWindow: HWnd): PWindowsObject;
  841. function NewStr(S: String): PString;
  842. procedure DisposeStr(P: PString);
  843.  
  844. { Multi-selection support routines }
  845.  
  846. function AllocMultiSel(Size: Integer): PMultiSelRec;
  847. procedure FreeMultiSel(P: PMultiSelRec);
  848.  
  849. { Stream routines }
  850.  
  851. procedure RegisterType(var S: TStreamRec);
  852. procedure RegisterWObjects;
  853.  
  854. { Longint inline routines }
  855.  
  856. function LongMul(X, Y: Integer): Longint;
  857. inline($5A/$58/$F7/$EA);
  858.  
  859. function LongDiv(X: Longint; Y: Integer): Integer;
  860. inline($59/$58/$5A/$F7/$F9);
  861.  
  862. { Application object pointer }
  863.  
  864. const
  865.   Application: PApplication = nil;
  866.  
  867. { Safety pool size }
  868.  
  869. const
  870.   SafetyPoolSize: Word = 8192;
  871.  
  872. { Stream error procedure }
  873.  
  874. const
  875.   StreamError: Pointer = nil;
  876.  
  877. { EMS stream state variables }
  878.  
  879. const
  880.   EmsCurHandle: Word = $FFFF;
  881.   EmsCurPage: Word = $FFFF;
  882.  
  883. { Stream registration records }
  884.  
  885. const
  886.   RCollection: TStreamRec = (
  887.     ObjType: 50;
  888.     VmtLink: Ofs(TypeOf(TCollection)^);
  889.     Load:    @TCollection.Load;
  890.     Store:   @TCollection.Store);
  891.  
  892. const
  893.   RStringCollection: TStreamRec = (
  894.     ObjType: 51;
  895.     VmtLink: Ofs(TypeOf(TStringCollection)^);
  896.     Load:    @TStringCollection.Load;
  897.     Store:   @TStringCollection.Store);
  898.  
  899. const
  900.   RWindowsObject: TStreamRec = (
  901.     ObjType: 52;
  902.     VmtLink: Ofs(TypeOf(TWindowsObject)^);
  903.     Load:    @TWindowsObject.Load;
  904.     Store:   @TWindowsObject.Store);
  905.  
  906. const
  907.   RWindow: TStreamRec = (
  908.     ObjType: 53;
  909.     VmtLink: Ofs(TypeOf(TWindow)^);
  910.     Load:    @TWindow.Load;
  911.     Store:   @TWindow.Store);
  912.  
  913. const
  914.   RDialog: TStreamRec = (
  915.     ObjType: 54;
  916.     VmtLink: Ofs(TypeOf(TDialog)^);
  917.     Load:    @TDialog.Load;
  918.     Store:   @TDialog.Store);
  919.  
  920. const
  921.   RDlgWindow: TStreamRec = (
  922.     ObjType: 55;
  923.     VmtLink: Ofs(TypeOf(TDlgWindow)^);
  924.     Load:    @TDlgWindow.Load;
  925.     Store:   @TDlgWindow.Store);
  926.  
  927. const
  928.   RControl: TStreamRec = (
  929.     ObjType: 56;
  930.     VmtLink: Ofs(TypeOf(TControl)^);
  931.     Load:    @TControl.Load;
  932.     Store:   @TControl.Store);
  933.  
  934. const
  935.   RMDIWindow: TStreamRec = (
  936.     ObjType: 57;
  937.     VmtLink: Ofs(TypeOf(TMDIWindow)^);
  938.     Load:    @TMDIWindow.Load;
  939.     Store:   @TMDIWindow.Store);
  940.  
  941. const
  942.   RMDIClient: TStreamRec = (
  943.     ObjType: 58;
  944.     VmtLink: Ofs(TypeOf(TMDIClient)^);
  945.     Load:    @TMDIClient.Load;
  946.     Store:   @TMDIClient.Store);
  947.  
  948. const
  949.   RButton: TStreamRec = (
  950.     ObjType: 59;
  951.     VmtLink: Ofs(TypeOf(TButton)^);
  952.     Load:    @TButton.Load;
  953.     Store:   @TButton.Store);
  954.  
  955. const
  956.   RCheckBox: TStreamRec = (
  957.     ObjType: 60;
  958.     VmtLink: Ofs(TypeOf(TCheckBox)^);
  959.     Load:    @TCheckBox.Load;
  960.     Store:   @TCheckBox.Store);
  961.  
  962. const
  963.   RRadioButton: TStreamRec = (
  964.     ObjType: 61;
  965.     VmtLink: Ofs(TypeOf(TRadioButton)^);
  966.     Load:    @TRadioButton.Load;
  967.     Store:   @TRadioButton.Store);
  968.  
  969. const
  970.   RGroupBox: TStreamRec = (
  971.     ObjType: 62;
  972.     VmtLink: Ofs(TypeOf(TGroupBox)^);
  973.     Load:    @TGroupBox.Load;
  974.     Store:   @TGroupBox.Store);
  975.  
  976. const
  977.   RListBox: TStreamRec = (
  978.     ObjType: 63;
  979.     VmtLink: Ofs(TypeOf(TListBox)^);
  980.     Load:    @TListBox.Load;
  981.     Store:   @TListBox.Store);
  982.  
  983. const
  984.   RComboBox: TStreamRec = (
  985.     ObjType: 64;
  986.     VmtLink: Ofs(TypeOf(TComboBox)^);
  987.     Load:    @TComboBox.Load;
  988.     Store:   @TComboBox.Store);
  989.  
  990. const
  991.   RScrollBar: TStreamRec = (
  992.     ObjType: 65;
  993.     VmtLink: Ofs(TypeOf(TScrollBar)^);
  994.     Load:    @TScrollBar.Load;
  995.     Store:   @TScrollBar.Store);
  996.  
  997. const
  998.   RStatic: TStreamRec = (
  999.     ObjType: 66;
  1000.     VmtLink: Ofs(TypeOf(TStatic)^);
  1001.     Load:    @TStatic.Load;
  1002.     Store:   @TStatic.Store);
  1003.  
  1004. const
  1005.   REdit: TStreamRec = (
  1006.     ObjType: 67;
  1007.     VmtLink: Ofs(TypeOf(TEdit)^);
  1008.     Load:    @TEdit.Load;
  1009.     Store:   @TEdit.Store);
  1010.  
  1011. const
  1012.   RScroller: TStreamRec = (
  1013.     ObjType: 68;
  1014.     VmtLink: Ofs(TypeOf(TScroller)^);
  1015.     Load:    @TScroller.Load;
  1016.     Store:   @TScroller.Store);
  1017.  
  1018. const
  1019.   RStrCollection: TStreamRec = (
  1020.     ObjType: 69;
  1021.     VmtLink: Ofs(TypeOf(TStrCollection)^);
  1022.     Load:    @TStrCollection.Load;
  1023.     Store:   @TStrCollection.Store);
  1024.