home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / TURBOPASCAL WIN / DOC.PAK / WOBJECTS.INT < prev   
Encoding:
Text File  |  1992-06-08  |  33.6 KB  |  1,049 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal for Windows                        }
  5. {       ObjectWindows Unit                              }
  6. {                                                       }
  7. {       Copyright (c) 1992 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit WObjects;
  12.  
  13. {$S-}
  14.  
  15. interface
  16.  
  17. uses WinTypes, WinProcs, Strings;
  18.  
  19. const
  20.  
  21. { Application message constants }
  22.  
  23.   wm_First    = $0000;            { $0000-$7FFF window messages }
  24.   id_First    =    $8000;          { $8000-$8FFF child id messages }
  25.   id_Internal = $8F00;            { $8F00-$8FFF reserved for internal use }
  26.   nf_First    =    $9000;          { $9000-$9FFF notification messages }
  27.   nf_Internal = $9F00;            { $9F00-$9FFF reserved for internal use }
  28.   cm_First    =    $A000;          { $A000-$FFFF command messages }
  29.   cm_Internal =    $FF00;            { $FF00-$FFFF reserved for internal use }
  30.   wm_Count    =    $8000;            { Number of window messages }
  31.   id_Count    =    $1000;            { Number of child ID messages }
  32.   nf_Count    =    $1000;            { Number of notification messages }
  33.   cm_Count    =    $6000;            { Number of command messages }
  34.  
  35. { Standard child ID messages }
  36.  
  37.   id_Reserved      = id_Internal - id_First;
  38.   id_FirstMDIChild = id_Reserved + 1;
  39.   id_MDIClient     = id_Reserved + 2;
  40.  
  41. { Standard command messages }
  42.  
  43.   cm_Reserved        = cm_Internal - cm_First;
  44.   cm_EditCut         = cm_Reserved + 0;
  45.   cm_EditCopy        = cm_Reserved + 1;
  46.   cm_EditPaste       = cm_Reserved + 2;
  47.   cm_EditDelete      = cm_Reserved + 3;
  48.   cm_EditClear       = cm_Reserved + 4;
  49.   cm_EditUndo        = cm_Reserved + 5;
  50.   cm_EditFind        = cm_Reserved + 6;
  51.   cm_EditReplace     = cm_Reserved + 7;
  52.   cm_EditFindNext    = cm_Reserved + 8;
  53.  
  54.   cm_FileNew         = cm_Reserved + 9;
  55.   cm_FileOpen        = cm_Reserved + 10;
  56.   cm_MDIFileNew      = cm_Reserved + 11;
  57.   cm_MDIFileOpen     = cm_Reserved + 12;
  58.   cm_FileSave        = cm_Reserved + 13;
  59.   cm_FileSaveAs      = cm_Reserved + 14;
  60.   cm_ArrangeIcons    = cm_Reserved + 15;
  61.   cm_TileChildren    = cm_Reserved + 16;
  62.   cm_CascadeChildren = cm_Reserved + 17;
  63.   cm_CloseChildren   = cm_Reserved + 18;
  64.   cm_CreateChild     = cm_Reserved + 19;
  65.   cm_Exit            = cm_Reserved + 20;
  66.  
  67. { TWindowsObject Flags masks }
  68.  
  69.   wb_KBHandler    = $01;
  70.   wb_FromResource = $02;
  71.   wb_AutoCreate   = $04;
  72.   wb_MDIChild     = $08;
  73.   wb_Transfer     = $10;
  74.  
  75. { TWindowsObject Status codes }
  76.  
  77.   em_InvalidWindow     = -1;
  78.   em_OutOfMemory       = -2;
  79.   em_InvalidClient     = -3;
  80.   em_InvalidChild      = -4;
  81.   em_InvalidMainWindow = -5;
  82.  
  83. { TWindowsObject Transfer codes }
  84.  
  85.   tf_SizeData =    0;
  86.   tf_GetData  =    1;
  87.   tf_SetData  =    2;
  88.  
  89. { TCheckBox check states }
  90.  
  91.   bf_Unchecked = 0;
  92.   bf_Checked   = 1;
  93.   bf_Grayed    = 2;
  94.  
  95. { TStream access modes }
  96.  
  97.   stCreate    = $3C00;          { Create new file }
  98.   stOpenRead  = $3D00;          { Read access only }
  99.   stOpenWrite = $3D01;          { Write access only }
  100.   stOpen      = $3D02;          { Read and write access }
  101.  
  102. { TStream error codes }
  103.  
  104.   stOk         =  0;            { No error }
  105.   stError      = -1;            { Access error }
  106.   stInitError  = -2;            { Cannot initialize stream }
  107.   stReadError  = -3;            { Read beyond end of stream }
  108.   stWriteError = -4;            { Cannot expand stream }
  109.   stGetError   = -5;            { Get of unregistered object type }
  110.   stPutError   = -6;            { Put of unregistered object type }
  111.  
  112. { Maximum TCollection size }
  113.  
  114.   MaxCollectionSize = 65520 div SizeOf(Pointer);
  115.  
  116. { TCollection error codes }
  117.  
  118.   coIndexError = -1;            { Index out of range }
  119.   coOverflow   = -2;            { Overflow }
  120.  
  121. type
  122.  
  123. { String pointer }
  124.  
  125.   PString = ^String;
  126.  
  127. { Type conversion records }
  128.  
  129.   WordRec = record Lo, Hi: Byte end;
  130.   LongRec = record Lo, Hi: Word end;
  131.   PtrRec = record Ofs, Seg: Word end;
  132.  
  133. { General arrays }
  134.  
  135.   PByteArray = ^TByteArray;
  136.   TByteArray = array[0..32767] of Byte;
  137.   PWordArray = ^TWordArray;
  138.   TWordArray = array[0..16383] of Word;
  139.  
  140. { TObject base object }
  141.  
  142.   PObject = ^TObject;
  143.   TObject = object
  144.     constructor Init;
  145.     procedure Free;
  146.     destructor Done; virtual;
  147.   end;
  148.  
  149. { TStreamRec }
  150.  
  151.   PStreamRec = ^TStreamRec;
  152.   TStreamRec = record
  153.     ObjType: Word;
  154.     VmtLink: Word;
  155.     Load: Pointer;
  156.     Store: Pointer;
  157.     Next: Word;
  158.   end;
  159.  
  160. { TStream }
  161.  
  162.   PStream = ^TStream;
  163.   TStream = object(TObject)
  164.     Status: Integer;
  165.     ErrorInfo: Integer;
  166.     constructor Init;
  167.     procedure CopyFrom(var S: TStream; Count: Longint);
  168.     procedure Error(Code, Info: Integer); virtual;
  169.     procedure Flush; virtual;
  170.     function Get: PObject;
  171.     function GetPos: Longint; virtual;
  172.     function GetSize: Longint; virtual;
  173.     procedure Put(P: PObject);
  174.     procedure Read(var Buf; Count: Word); virtual;
  175.     function ReadStr: PString;
  176.     procedure Reset;
  177.     procedure Seek(Pos: Longint); virtual;
  178.     function StrRead: PChar;
  179.     procedure StrWrite(P: PChar);
  180.     procedure Truncate; virtual;
  181.     procedure Write(var Buf; Count: Word); virtual;
  182.     procedure WriteStr(P: PString);
  183.   end;
  184.  
  185. { TDosStream }
  186.  
  187.   PDosStream = ^TDosStream;
  188.   TDosStream = object(TStream)
  189.     Handle: Word;
  190.     constructor Init(FileName: PChar; Mode: Word);
  191.     destructor Done; virtual;
  192.     function GetPos: Longint; virtual;
  193.     function GetSize: Longint; virtual;
  194.     procedure Read(var Buf; Count: Word); virtual;
  195.     procedure Seek(Pos: Longint); virtual;
  196.     procedure Truncate; virtual;
  197.     procedure Write(var Buf; Count: Word); virtual;
  198.   end;
  199.  
  200. { TBufStream }
  201.  
  202.   PBufStream = ^TBufStream;
  203.   TBufStream = object(TDosStream)
  204.     Buffer: Pointer;
  205.     BufSize: Word;
  206.     BufPtr: Word;
  207.     BufEnd: Word;
  208.     constructor Init(FileName: PChar; Mode, Size: Word);
  209.     destructor Done; virtual;
  210.     procedure Flush; virtual;
  211.     function GetPos: Longint; virtual;
  212.     function GetSize: Longint; virtual;
  213.     procedure Read(var Buf; Count: Word); virtual;
  214.     procedure Seek(Pos: Longint); virtual;
  215.     procedure Truncate; virtual;
  216.     procedure Write(var Buf; Count: Word); virtual;
  217.   end;
  218.  
  219. { TEmsStream }
  220.  
  221.   PEmsStream = ^TEmsStream;
  222.   TEmsStream = object(TStream)
  223.     Handle: Word;
  224.     PageCount: Word;
  225.     Size: Longint;
  226.     Position: Longint;
  227.     constructor Init(MinSize, MaxSize: Longint);
  228.     destructor Done; virtual;
  229.     function GetPos: Longint; virtual;
  230.     function GetSize: Longint; virtual;
  231.     procedure Read(var Buf; Count: Word); virtual;
  232.     procedure Seek(Pos: Longint); virtual;
  233.     procedure Truncate; virtual;
  234.     procedure Write(var Buf; Count: Word); virtual;
  235.   end;
  236.  
  237. { TCollection types }
  238.  
  239.   PItemList = ^TItemList;
  240.   TItemList = array[0..MaxCollectionSize - 1] of Pointer;
  241.  
  242. { TCollection object }
  243.  
  244.   PCollection = ^TCollection;
  245.   TCollection = object(TObject)
  246.     Items: PItemList;
  247.     Count: Integer;
  248.     Limit: Integer;
  249.     Delta: Integer;
  250.     constructor Init(ALimit, ADelta: Integer);
  251.     constructor Load(var S: TStream);
  252.     destructor Done; virtual;
  253.     function At(Index: Integer): Pointer;
  254.     procedure AtDelete(Index: Integer);
  255.     procedure AtFree(Index: Integer);
  256.     procedure AtInsert(Index: Integer; Item: Pointer);
  257.     procedure AtPut(Index: Integer; Item: Pointer);
  258.     procedure Delete(Item: Pointer);
  259.     procedure DeleteAll;
  260.     procedure Error(Code, Info: Integer); virtual;
  261.     function FirstThat(Test: Pointer): Pointer;
  262.     procedure ForEach(Action: Pointer);
  263.     procedure Free(Item: Pointer);
  264.     procedure FreeAll;
  265.     procedure FreeItem(Item: Pointer); virtual;
  266.     function GetItem(var S: TStream): Pointer; virtual;
  267.     function IndexOf(Item: Pointer): Integer; virtual;
  268.     procedure Insert(Item: Pointer); virtual;
  269.     function LastThat(Test: Pointer): Pointer;
  270.     procedure Pack;
  271.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  272.     procedure SetLimit(ALimit: Integer); virtual;
  273.     procedure Store(var S: TStream);
  274.   end;
  275.  
  276. { TSortedCollection object }
  277.  
  278.   PSortedCollection = ^TSortedCollection;
  279.   TSortedCollection = object(TCollection)
  280.     Duplicates: Boolean;
  281.     constructor Init(ALimit, ADelta: Integer);
  282.     constructor Load(var S: TStream);
  283.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  284.     function IndexOf(Item: Pointer): Integer; virtual;
  285.     procedure Insert(Item: Pointer); virtual;
  286.     function KeyOf(Item: Pointer): Pointer; virtual;
  287.     function Search(Key: Pointer; var Index: Integer): Boolean; virtual;
  288.     procedure Store(var S: TStream);
  289.   end;
  290.  
  291. { TStringCollection object }
  292.  
  293.   PStringCollection = ^TStringCollection;
  294.   TStringCollection = object(TSortedCollection)
  295.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  296.     procedure FreeItem(Item: Pointer); virtual;
  297.     function GetItem(var S: TStream): Pointer; virtual;
  298.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  299.   end;
  300.  
  301. { TStrCollection object }
  302.  
  303.   PStrCollection = ^TStrCollection;
  304.   TStrCollection = object(TSortedCollection)
  305.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  306.     procedure FreeItem(Item: Pointer); virtual;
  307.     function GetItem(var S: TStream): Pointer; virtual;
  308.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  309.   end;
  310.  
  311. { TMessage windows message record }
  312.  
  313.   PMessage = ^TMessage;
  314.   TMessage = record
  315.     Receiver: HWnd;
  316.     Message: Word;
  317.     case Integer of
  318.       0: (
  319.         WParam: Word;
  320.         LParam: Longint;
  321.     Result: Longint);
  322.       1: (
  323.     WParamLo: Byte;
  324.         WParamHi: Byte;
  325.         LParamLo: Word;
  326.         LParamHi: Word;
  327.         ResultLo: Word;
  328.         ResultHi: Word);
  329.   end;
  330.  
  331. { ObjectWindows pointer types }
  332.  
  333.   PWindowsObject = ^TWindowsObject;
  334.   PWindow        = ^TWindow;
  335.   PDialog     = ^TDialog;
  336.   PDlgWindow     = ^TDlgWindow;
  337.   PMDIWindow     = ^TMDIWindow;
  338.   PControl     = ^TControl;
  339.   PButton      = ^TButton;
  340.   PCheckBox     = ^TCheckBox;
  341.   PRadioButton     = ^TRadioButton;
  342.   PGroupBox     = ^TGroupBox;
  343.   PStatic     = ^TStatic;
  344.   PEdit             = ^TEdit;
  345.   PListBox     = ^TListBox;
  346.   PComboBox     = ^TComboBox;
  347.   PScrollBar     = ^TScrollBar;
  348.   PMDIClient     = ^TMDIClient;
  349.   PScroller     = ^TScroller;
  350.   PApplication     = ^TApplication;
  351.  
  352. { TWindowsObject object }
  353.  
  354.   TWindowsObject = object(TObject)
  355.     Status: Integer;
  356.     HWindow: HWnd;
  357.     Parent, ChildList: PWindowsObject;
  358.     TransferBuffer: Pointer;
  359.     Instance: TFarProc;
  360.     Flags: Byte;
  361.     constructor Init(AParent: PWindowsObject);
  362.     constructor Load(var S: TStream);
  363.     destructor Done; virtual;
  364.     procedure Store(var S: TStream);
  365.     procedure DefWndProc(var Msg: TMessage); virtual {index 8};
  366.     procedure DefCommandProc(var Msg: TMessage); virtual {index 12};
  367.     procedure DefChildProc(var Msg: TMessage); virtual {index 16};
  368.     procedure DefNotificationProc(var Msg: TMessage); virtual {index 20};
  369.     procedure SetFlags(Mask: Byte; OnOff: Boolean);
  370.     function IsFlagSet(Mask: Byte): Boolean;
  371.     function FirstThat(Test: Pointer): PWindowsObject;
  372.     procedure ForEach(Action: Pointer);
  373.     function Next: PWindowsObject;
  374.     function Previous: PWindowsObject;
  375.     procedure EnableKBHandler;
  376.     procedure EnableAutoCreate;
  377.     procedure DisableAutoCreate;
  378.     procedure EnableTransfer;
  379.     procedure DisableTransfer;
  380.     function Register: Boolean; virtual;
  381.     function Create: Boolean; virtual;
  382.     procedure Destroy; virtual;
  383.     function GetId: Integer; virtual;
  384.     function ChildWithId(Id: Integer): PWindowsObject;
  385.     function GetClassName: PChar; virtual;
  386.     function GetClient: PMDIClient; virtual;
  387.     procedure GetChildPtr(var S: TStream; var P);
  388.     procedure PutChildPtr(var S: TStream; P: PWindowsObject);
  389.     procedure GetSiblingPtr(var S: TStream; var P);
  390.     procedure PutSiblingPtr(var S: TStream; P: PWindowsObject);
  391.     procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  392.     procedure SetupWindow; virtual;
  393.     procedure Show(ShowCmd: Integer);
  394.     function CanClose: Boolean;  virtual;
  395.     function Transfer(DataPtr: Pointer; TransferFlag: Word): Word; virtual;
  396.     procedure TransferData(Direction: Word); virtual;
  397.     procedure DispatchScroll(var Msg: TMessage); virtual;
  398.     procedure CloseWindow;
  399.     procedure GetChildren(var S: TStream);
  400.     procedure PutChildren(var S: TStream);
  401.     function CreateChildren: Boolean;
  402.     procedure WMVScroll(var Msg: TMessage); virtual wm_First + wm_VScroll;
  403.     procedure WMHScroll(var Msg: TMessage); virtual wm_First + wm_HScroll;
  404.     procedure WMCommand(var Msg: TMessage); virtual wm_First + wm_Command;
  405.     procedure WMClose(var Msg: TMessage); virtual wm_First + wm_Close;
  406.     procedure WMDestroy(var Msg: TMessage); virtual wm_First + wm_Destroy;
  407.     procedure WMNCDestroy(var Msg: TMessage); virtual wm_First + wm_NCDestroy;
  408.     procedure WMActivate(var Msg: TMessage); virtual wm_First + wm_Activate;
  409.     procedure WMQueryEndSession(var Msg: TMessage);
  410.       virtual wm_First + wm_QueryEndSession;
  411.     procedure CMExit(var Msg: TMessage); virtual cm_First + cm_Exit;
  412.   end;
  413.  
  414. { TWindow creation attributes }
  415.  
  416.   TWindowAttr = record
  417.     Title: PChar;
  418.     Style: LongInt;
  419.     ExStyle: LongInt;
  420.     X, Y, W, H: Integer;
  421.     Param: Pointer;
  422.     case Integer of
  423.       0: (Menu: HMenu);         { Menu handle }
  424.       1: (Id: Integer);         { Child identifier }
  425.   end;
  426.  
  427. { TWindow object }
  428.  
  429.   TWindow = object(TWindowsObject)
  430.     Attr: TWindowAttr;
  431.     DefaultProc: TFarProc;
  432.     Scroller: PScroller;
  433.     FocusChildHandle: THandle;
  434.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  435.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  436.     constructor Load(var S: TStream);
  437.     destructor Done; virtual;
  438.     procedure Store(var S: TStream);
  439.     procedure SetCaption(ATitle: PChar);
  440.     procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  441.     function GetId: Integer; virtual;
  442.     function Create: Boolean; virtual;
  443.     procedure DefWndProc(var Msg: TMessage); virtual;
  444.     procedure WMActivate(var Msg: TMessage);
  445.       virtual wm_First + wm_Activate;
  446.     procedure SetupWindow; virtual;
  447.     procedure WMCreate(var Msg: TMessage);
  448.       virtual wm_First + wm_Create;
  449.     procedure WMHScroll(var Msg: TMessage);
  450.       virtual wm_First + wm_HScroll;
  451.     procedure WMVScroll(var Msg: TMessage);
  452.       virtual wm_First + wm_VScroll;
  453.     procedure WMPaint(var Msg: TMessage);
  454.       virtual wm_First + wm_Paint;
  455.     procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
  456.     procedure WMSize(var Msg: TMessage);
  457.       virtual wm_First + wm_Size;
  458.     procedure WMMove(var Msg: TMessage);
  459.       virtual wm_First + wm_Move;
  460.     procedure WMLButtonDown(var Msg: TMessage);
  461.       virtual wm_First + wm_LButtonDown;
  462.   end;
  463.  
  464. { TDialog creation attributes }
  465.  
  466.   TDialogAttr = record
  467.     Name: PChar;
  468.     Param: LongInt;
  469.   end;
  470.  
  471. { TDialog object }
  472.  
  473.   TDialog = object(TWindowsObject)
  474.     Attr: TDialogAttr;
  475.     IsModal: Boolean;
  476.     constructor Init(AParent: PWindowsObject; AName: PChar);
  477.     constructor Load(var S: TStream);
  478.     destructor Done; virtual;
  479.     procedure Store(var S: TStream);
  480.     function Create: Boolean; virtual;
  481.     function Execute: Integer; virtual;
  482.     procedure EndDlg(ARetValue: Integer); 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 Cancel(var Msg: TMessage); virtual id_First + id_Cancel;
  488.     procedure WMInitDialog(var Msg: TMessage);
  489.       virtual wm_First + wm_InitDialog;
  490.     procedure WMQueryEndSession(var Msg: TMessage);
  491.       virtual wm_First + wm_QueryEndSession;
  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.   end;
  504.  
  505. { TMDIWindow object }
  506.  
  507.   TMDIWindow = object(TWindow)
  508.     ClientWnd:  PMDIClient;
  509.     ChildMenuPos: Integer;
  510.     constructor Init(ATitle: PChar; AMenu: HMenu);
  511.     destructor Done; virtual;
  512.     constructor Load(var S: TStream);
  513.     procedure Store(var S: TStream);
  514.     procedure SetupWindow; virtual;
  515.     procedure InitClientWindow; virtual;
  516.     function GetClassName: PChar; virtual;
  517.     function GetClient: PMDIClient; virtual;
  518.     procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  519.     procedure DefWndProc(var Msg: TMessage); virtual;
  520.     function InitChild: PWindowsObject; virtual;
  521.     function CreateChild: PWindowsObject; virtual;
  522.     procedure CMCreateChild(var Msg: TMessage);
  523.       virtual cm_First + cm_CreateChild;
  524.     procedure TileChildren; virtual;
  525.     procedure CascadeChildren; virtual;
  526.     procedure ArrangeIcons; virtual;
  527.     procedure CloseChildren; virtual;
  528.     procedure CMTileChildren(var Msg: TMessage);
  529.       virtual cm_First + cm_TileChildren;
  530.     procedure CMCascadeChildren(var Msg: TMessage);
  531.       virtual cm_First + cm_CascadeChildren;
  532.     procedure CMArrangeIcons(var Msg: TMessage);
  533.       virtual cm_First + cm_ArrangeIcons;
  534.     procedure CMCloseChildren(var Msg: TMessage);
  535.       virtual cm_First + cm_CloseChildren;
  536.   end;
  537.  
  538. { TControl object }
  539.  
  540.   TControl = object(TWindow)
  541.     constructor Init(AParent: PWindowsObject; AnId: Integer;
  542.       ATitle: PChar; X, Y, W, H: Integer);
  543.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  544.     function Register: Boolean; virtual;
  545.     function GetClassName: PChar; virtual;
  546.     procedure WMPaint(var Msg: TMessage); virtual wm_First + wm_Paint;
  547.   end;
  548.  
  549. { TButton object }
  550.  
  551.   TButton = object(TControl)
  552.     constructor Init(AParent: PWindowsObject; AnId: Integer;
  553.       AText: PChar; X, Y, W, H: Integer; IsDefault: Boolean);
  554.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  555.     function GetClassName: PChar; virtual;
  556.   end;
  557.  
  558. { TCheckBox object }
  559.  
  560.   TCheckBox = object(TButton)
  561.     Group: PGroupBox;
  562.     constructor Init(AParent: PWindowsObject; AnID: Integer;
  563.       ATitle: PChar; X, Y, W, H: Integer; AGroup: PGroupBox);
  564.     constructor InitResource(AParent: PWindowsObject; ResourceID: Word);
  565.     constructor Load(var S: TStream);
  566.     procedure Store(var S: TStream);
  567.     procedure Check;
  568.     procedure Uncheck;
  569.     procedure Toggle;
  570.     function GetClassName: PChar; virtual;
  571.     function GetCheck: Word;
  572.     procedure SetCheck(CheckFlag: Word);
  573.     function Transfer(DataPtr: Pointer; TransferFlag: Word): Word; virtual;
  574.     procedure BNClicked(var Msg: TMessage);
  575.       virtual nf_First + bn_Clicked;
  576.   end;
  577.  
  578. { TRadioButton object }
  579.  
  580.   TRadioButton = object(TCheckBox)
  581.     constructor Init(AParent: PWindowsObject; AnID: Integer;
  582.       ATitle: PChar; X, Y, W, H: Integer; AGroup: PGroupBox);
  583.     function GetClassName: PChar; virtual;
  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.     destructor Done; virtual;
  791.     procedure Store(var S: TStream);
  792.     procedure SetUnits(TheXUnit, TheYUnit: LongInt);
  793.     procedure SetPageSize; virtual;
  794.     procedure SetSBarRange; virtual; 
  795.     procedure SetRange(TheXRange, TheYRange: LongInt);
  796.     procedure BeginView(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
  797.     procedure EndView; virtual;
  798.     procedure VScroll(ScrollRequest: Word; ThumbPos: Integer); virtual;
  799.     procedure HScroll(ScrollRequest: Word; ThumbPos: Integer); virtual;
  800.     procedure ScrollTo(X, Y: LongInt);
  801.     procedure ScrollBy(Dx, Dy: LongInt);
  802.     procedure AutoScroll; virtual;
  803.     function IsVisibleRect(X, Y: LongInt; XExt, YExt: Integer): Boolean;
  804.   end;
  805.  
  806. { TApplication object }
  807.  
  808.   TApplication = object(TObject)
  809.     Status: Integer;
  810.     Name: PChar;
  811.     MainWindow: PWindowsObject;
  812.     HAccTable: THandle;
  813.     KBHandlerWnd: PWindowsObject;
  814.     constructor Init(AName: PChar);
  815.     destructor Done; virtual;
  816.     procedure InitApplication; virtual;
  817.     procedure InitInstance; virtual;
  818.     procedure InitMainWindow; virtual;
  819.     procedure Run; virtual;
  820.     procedure SetKBHandler(AWindowsObject: PWindowsObject);
  821.     procedure MessageLoop; virtual;
  822.     function ProcessAppMsg(var Message: TMsg): Boolean; virtual;
  823.     function ProcessDlgMsg(var Message: TMsg): Boolean; virtual;
  824.     function ProcessAccels(var Message: TMsg): Boolean; virtual;
  825.     function ProcessMDIAccels(var Message: TMsg): Boolean; virtual;
  826.     function MakeWindow(AWindowsObject: PWindowsObject): PWindowsObject; virtual;
  827.     function ExecDialog(ADialog: PWindowsObject): Integer; virtual;
  828.     function ValidWindow(AWindowsObject: PWindowsObject): PWindowsObject; virtual;
  829.     procedure Error(ErrorCode: Integer); virtual;
  830.     function CanClose: Boolean; virtual;
  831.   end;
  832.  
  833. { Abstract notification procedure }
  834.  
  835. procedure Abstract;
  836.  
  837. { Memory management routines }
  838.  
  839. procedure InitMemory;
  840. procedure DoneMemory;
  841. function LowMemory: Boolean;
  842. procedure RestoreMemory;
  843. function MemAlloc(Size: Word): Pointer;
  844. function GetObjectPtr(HWindow: HWnd): PWindowsObject;
  845. function NewStr(S: String): PString;
  846. procedure DisposeStr(P: PString);
  847.  
  848. { Multi-selection support routines }
  849.  
  850. function AllocMultiSel(Size: Integer): PMultiSelRec;
  851. procedure FreeMultiSel(P: PMultiSelRec);
  852.  
  853. { Stream routines }
  854.  
  855. procedure RegisterType(var S: TStreamRec);
  856. procedure RegisterWObjects;
  857.  
  858. { Longint inline routines }
  859.  
  860. function LongMul(X, Y: Integer): Longint;
  861. inline($5A/$58/$F7/$EA);
  862.  
  863. function LongDiv(X: Longint; Y: Integer): Integer;
  864. inline($59/$58/$5A/$F7/$F9);
  865.  
  866. { Application object pointer }
  867.  
  868. const
  869.   Application: PApplication = nil;
  870.  
  871. { Safety pool size }
  872.  
  873. const
  874.   SafetyPoolSize: Word = 8192;
  875.  
  876. { Stream error procedure }
  877.  
  878. const
  879.   StreamError: Pointer = nil;
  880.  
  881. { EMS stream state variables }
  882.  
  883. const
  884.   EmsCurHandle: Word = $FFFF;
  885.   EmsCurPage: Word = $FFFF;
  886.  
  887. { Stream registration records }
  888.  
  889. const
  890.   RCollection: TStreamRec = (
  891.     ObjType: 50;
  892.     VmtLink: Ofs(TypeOf(TCollection)^);
  893.     Load:    @TCollection.Load;
  894.     Store:   @TCollection.Store);
  895.  
  896. const
  897.   RStringCollection: TStreamRec = (
  898.     ObjType: 51;
  899.     VmtLink: Ofs(TypeOf(TStringCollection)^);
  900.     Load:    @TStringCollection.Load;
  901.     Store:   @TStringCollection.Store);
  902.  
  903. const
  904.   RWindowsObject: TStreamRec = (
  905.     ObjType: 52;
  906.     VmtLink: Ofs(TypeOf(TWindowsObject)^);
  907.     Load:    @TWindowsObject.Load;
  908.     Store:   @TWindowsObject.Store);
  909.  
  910. const
  911.   RWindow: TStreamRec = (
  912.     ObjType: 53;
  913.     VmtLink: Ofs(TypeOf(TWindow)^);
  914.     Load:    @TWindow.Load;
  915.     Store:   @TWindow.Store);
  916.  
  917. const
  918.   RDialog: TStreamRec = (
  919.     ObjType: 54;
  920.     VmtLink: Ofs(TypeOf(TDialog)^);
  921.     Load:    @TDialog.Load;
  922.     Store:   @TDialog.Store);
  923.  
  924. const
  925.   RDlgWindow: TStreamRec = (
  926.     ObjType: 55;
  927.     VmtLink: Ofs(TypeOf(TDlgWindow)^);
  928.     Load:    @TDlgWindow.Load;
  929.     Store:   @TDlgWindow.Store);
  930.  
  931. const
  932.   RControl: TStreamRec = (
  933.     ObjType: 56;
  934.     VmtLink: Ofs(TypeOf(TControl)^);
  935.     Load:    @TControl.Load;
  936.     Store:   @TControl.Store);
  937.  
  938. const
  939.   RMDIWindow: TStreamRec = (
  940.     ObjType: 57;
  941.     VmtLink: Ofs(TypeOf(TMDIWindow)^);
  942.     Load:    @TMDIWindow.Load;
  943.     Store:   @TMDIWindow.Store);
  944.  
  945. const
  946.   RMDIClient: TStreamRec = (
  947.     ObjType: 58;
  948.     VmtLink: Ofs(TypeOf(TMDIClient)^);
  949.     Load:    @TMDIClient.Load;
  950.     Store:   @TMDIClient.Store);
  951.  
  952. const
  953.   RButton: TStreamRec = (
  954.     ObjType: 59;
  955.     VmtLink: Ofs(TypeOf(TButton)^);
  956.     Load:    @TButton.Load;
  957.     Store:   @TButton.Store);
  958.  
  959. const
  960.   RCheckBox: TStreamRec = (
  961.     ObjType: 60;
  962.     VmtLink: Ofs(TypeOf(TCheckBox)^);
  963.     Load:    @TCheckBox.Load;
  964.     Store:   @TCheckBox.Store);
  965.  
  966. const
  967.   RRadioButton: TStreamRec = (
  968.     ObjType: 61;
  969.     VmtLink: Ofs(TypeOf(TRadioButton)^);
  970.     Load:    @TRadioButton.Load;
  971.     Store:   @TRadioButton.Store);
  972.  
  973. const
  974.   RGroupBox: TStreamRec = (
  975.     ObjType: 62;
  976.     VmtLink: Ofs(TypeOf(TGroupBox)^);
  977.     Load:    @TGroupBox.Load;
  978.     Store:   @TGroupBox.Store);
  979.  
  980. const
  981.   RListBox: TStreamRec = (
  982.     ObjType: 63;
  983.     VmtLink: Ofs(TypeOf(TListBox)^);
  984.     Load:    @TListBox.Load;
  985.     Store:   @TListBox.Store);
  986.  
  987. const
  988.   RComboBox: TStreamRec = (
  989.     ObjType: 64;
  990.     VmtLink: Ofs(TypeOf(TComboBox)^);
  991.     Load:    @TComboBox.Load;
  992.     Store:   @TComboBox.Store);
  993.  
  994. const
  995.   RScrollBar: TStreamRec = (
  996.     ObjType: 65;
  997.     VmtLink: Ofs(TypeOf(TScrollBar)^);
  998.     Load:    @TScrollBar.Load;
  999.     Store:   @TScrollBar.Store);
  1000.  
  1001. const
  1002.   RStatic: TStreamRec = (
  1003.     ObjType: 66;
  1004.     VmtLink: Ofs(TypeOf(TStatic)^);
  1005.     Load:    @TStatic.Load;
  1006.     Store:   @TStatic.Store);
  1007.  
  1008. const
  1009.   REdit: TStreamRec = (
  1010.     ObjType: 67;
  1011.     VmtLink: Ofs(TypeOf(TEdit)^);
  1012.     Load:    @TEdit.Load;
  1013.     Store:   @TEdit.Store);
  1014.  
  1015. const
  1016.   RScroller: TStreamRec = (
  1017.     ObjType: 68;
  1018.     VmtLink: Ofs(TypeOf(TScroller)^);
  1019.     Load:    @TScroller.Load;
  1020.     Store:   @TScroller.Store);
  1021.  
  1022. const
  1023.   RStrCollection: TStreamRec = (
  1024.     ObjType: 69;
  1025.     VmtLink: Ofs(TypeOf(TStrCollection)^);
  1026.     Load:    @TStrCollection.Load;
  1027.     Store:   @TStrCollection.Store);
  1028.  
  1029. type
  1030.   TCreateDialogParam = function (HInstance: THandle; TemplateName: PChar;
  1031.     WndParent: HWnd; DialogFunc: TFarProc; InitParam: LongInt): HWnd;
  1032.   TDialogBoxParam = function (HInstance: THandle; TemplateName: PChar;
  1033.     WndParent: HWnd; DialogFunc: TFarProc; InitParam: LongInt): Integer;
  1034.   TDefaultProc = function (Wnd: HWnd; Msg, wParam: Word;
  1035.     lParam: LongInt): LongInt;
  1036.   TMessageBox = function (WndParent: HWnd; Txt, Caption: PChar;
  1037.     TextType: Word): Integer;
  1038.  
  1039. const
  1040.   CreateDialogParam: TCreateDialogParam = WinProcs.CreateDialogParam;
  1041.   DialogBoxParam: TDialogBoxParam = WinProcs.DialogBoxParam;
  1042.   DefWndDlgProc: TDefaultProc = WinProcs.DefWindowProc;
  1043.   DefMDIDlgProc: TDefaultProc = WinProcs.DefMDIChildProc;
  1044.   DefDlgProc: TDefaultProc = WinProcs.DefDlgProc;
  1045.   MessageBox: TMessageBox = WinProcs.MessageBox;
  1046.  
  1047.   BWCCClassNames: Boolean = False;
  1048.  
  1049.