************************************************ ** Fowl - the Free/Open Widget Library ** ** Copyright (C) 2016-2020 Kostas Michalopoulos ** ************************************************ About ===== Fowl is a tiny GUI toolkit that loosely reimplements the OWL toolkit from Turbo Pascal for Windows in Free Pascal, though it is not 100% the same. It only implements a subset of it but it can be used as an alternative to Lazarus/LCL for when you want to create a small Windows-only executable. The entirety of the API is exposed by the FObjects unit which is briefly documented below. Please note that i wrote this library years ago and i haven't touched it much since then. Quick Start =========== To use Fowl simply include the FObjects unit, create an instance of the TApplication class and run it, as shown below (also in Simplest.pas): { Simplest Fowl Demo} program Simplest; uses FObjects; var App: TApplication; begin App.Init('Simplest Demo'); App.Run; App.Done; end. Usually however you want to define your own application class, main window type, with its own controls and event handling. Here is a simple example of a custom window with a button that causes the window to close (and thus terminate the application since by default when the main window is closed, it also terminates the application - the code is in Hello.pas too): { Hello Demo} program Hello; {$MODE OBJFPC}{$H+} uses FObjects; type { Custom window } PHelloWindow = ^THelloWindow; THelloWindow = object(TWindow) constructor Init; function ProcessNotification(Child: PWindowsObject; NotifyCode: Integer): Boolean; virtual; end; { Application class } TMyApp = object(TApplication) procedure InitMainWindow; virtual; end; { THelloWindow } constructor THelloWindow.Init; var Button: PButton; begin inherited Init(nil, 'Hello'); New(Button, Init(@Self, 100, 'Hello, world!', 10, 10, 100, 25, False)); end; function THelloWindow.ProcessNotification(Child: PWindowsObject; NotifyCode: Integer): Boolean; begin if (NotifyCode=cn_Clicked) and (Child^.GetId=100) then begin CloseWindow; Exit(True); end; Result:=inherited ProcessNotification(Child, NotifyCode); end; { TMyApp } procedure TMyApp.InitMainWindow; begin MainWindow:=New(PHelloWindow, Init); end; { Main } var App: TMyApp; begin App.Init('Hello Demo'); App.Run; App.Done; end. For a more elaborate example which includes object and UI streaming (aka serialization) check FowlDemo.pas. Note on streaming ================= While Fowl can stream window objects, thus enabling applications to save their UIs to files, it does not stream the state of the UI controls - for example the checked state of a checkbox. I am not sure if OWL actually did that since i never really used it (Fowl was written by reading some API reference of OWL i found), there are valid applications for each approach but i think that not storing the UI state is more useful and since Fowl isn't an 100% reimplementation of OWL anyway, i decided to do just that. There is one exception in that the text for controls *can* be serialized since this is part of the UI itself (e.g. the text in TStatic controls and buttons). Since the text can be either part of the UI or part of the state there is a method called StoreText which, if returns True, will cause the text to be stored. Constants ========= The constants exposed by Fowl are: -- Fowl information -- * FowlVersion - the version of the unit in HIWORD.LOWORD format * FowlVersionString - the version of the unit in string format * FowlWindowClassName - the Windows class name of custom Fowl windows -- Stream modes -- * stCreate - Create a new file (or whatever the stream represents) * stOpenRead - Open a stream in read-only mode * stOpenWrite - Open a stream in write-only mode * stOpen - Open a stream in read/write mode -- Stream status -- * stOk - No error * stError - Access error * stInitError - Initialization error * stReadError - Data reading error * stWriteError - Data writing error * stGetError - Object reading error * stPutError - Object writing error -- Object types -- * ot_First - First available object type ID for custom types (make sure all your types are equal or greater to this) -- Collection errors - * coIndexError - Invalid index in a collection -- Menu item types -- * it_Normal - Normal menu * it_SubMenu - Menu with a submenu * it_Separator - Menu separator * it_Check - Checkable menu * it_Radio - Radiobutton menu -- Window object flags -- wb_NoFlags - No flags wb_KeyboardHandler - Window handles keyboard events wb_FromResource - The window was created from a resource (not supported) wb_AutoCreate - Causes the object's Create method to be called by its parent when the parent is itself being created (needed mainly for loading UIs from streams) wb_MDIChild - MDI child window (not supported yet) wb_Transfer - Enable data transfer wb_HasMenu - The window object has its own menu (set via SetMenu) -- Window error conditions -- em_Ok - No error condition em_InvalidWindow - The window is invalid (see CheckHandle) em_OutOfMemory - Ran out of memory (not supported) em_InvalidClient - Invalid client (not supported yet) em_InvalidChild - Create for a child with wb_AutoCreate flag failed em_InvalidMainWindow - InitMainWindow didn't set a valid MainWindow value -- Window show commands -- sw_Hide - Hide the window sw_Show - Show the window and bring it to front sw_ShowMaximized - Show the window in a maximized sw_ShowMinimized - Show the window in a minimized state sw_ShowNormal - Show and restore the window from minimized/maximized state -- Data transfer flags -- tf_SizeData - Get the size of the data to transfer tf_GetData - Get data out of the object, data depends on the object type tf_SetData - Set data to the object -- Control notifications -- cn_Clicked - The control (e.g. button) was clicked cn_Changed - The control's contents (e.g. edit text) was changed -- Id numbers -- id_None - No id Records ======= Records that contain additional data and transfer data are shown below: TStreamRec ---------- Used as a registry entry for streamable objects, should be used in a 'const' region and registered via RegisterType. TStreamRec = packed record ObjType: Cardinal; - The object type id (must be >= ot_First) VmtLink: Pointer; - Pointer to object Vmt, ie. Ofs(TypeOf(type)^) Load: Pointer; - Pointer to Load method, ie. @type.Load Store: Pointer; - Pointer to Store method, ie. @type.Store Next: PStreamRec; - Must be nil, will be set via RegisterType end; Example (from FowlDemo.pas): RDemoMainWin: TStreamRec = ( ObjType: ot_First; VmtLink: Ofs(TypeOf(TDemoMainWin)^); Load: @TWindow.Load; Store: @TWindow.Store; Next: nil); TPaintStruct ------------ Contains information about a paint event, passed via the Paint method TPaintStruct = record DC: PDC; - Target device context Erase: Boolean; - If true, the application should erase the background X, Y, W, H: Integer; - Damaged area that needs to be painted end; TMessage -------- Window system message TMessage = record Receiver: THandle; - Message receiver handle Message: Integer; - The message itself WParam: Int64; - Generic parameter LParam: Int64; - Generic parameter Result: Int64; - Message result end; TWindowAttr ----------- Window attributes TWindowAttr = record Title: string; - The window's title or text content Style: Longint; - Style flags (WS_xxx, etc) ExStyle: Longint; - Extended style flags (WS_EX_xxx, etc) X, Y, W, H: Integer; - Position and dimensions Param: Pointer; - Generic parameter case Integer of 0: (Menu: PMenu); - Window menu (when wb_HasMenu flag is set) 1: (Id: Integer); - Control id (when wb_HasMenu flag is not set) end; TScrollBarTransferRec --------------------- Data transfer record for TScrollBar TScrollBarTransferRec = packed record LowValue: Integer; - Minimum value (scroll bar at left/top) HighValue: Integer; - Maximum value (scroll bar at right/bottom) Position: Integer; - Current position end; TListBoxTransferRec ------------------- Data transfer record for TListBox TListBoxTransferRec = packed record Strings: array of string; - Strings in the listbox Selected: array of Boolean; - Selected state for each of the strings SelIndex: Integer; - Index of the primary selected strain end; TComboBoxTransferRec -------------------- Data transfer record for TComboBox TComboBoxTransferRec = packed record Strings: array of string; - Strings in the combo box SelIndex: Integer; - Selected string index Text: string; - Text in the edit part of the combo box end; Enums and Sets ============== Below are the enum and set types exposed by Fowl: - Edit options - Used by TEdit TEditOption = ( eoMultiline, - Use a multiline editor (as in, e.g. Notepad) eoNoBorder, - Do not put a border around the editor eoWordWrap, - Enable word wrapping eoReadOnly, - Read only editor eoPassword - Do not display the typed characters (for passwords) ); TEditOptions = set of TEditOption; - List box options - Used by TListBox TListBoxOption = ( loMultiSelect, - Allow selecting multiple items in the listbox loNoBorder, - Do not put a border around the list box loSortItems - Show the items as sorted ); TListBoxOptions = set of TListBoxOption; - Combo box options - Used by TComboBox TComboBoxOption = ( coNoBorder, - Do not put a border around the combo box coSortItems, - Show the items as sorted coDropDownList - Disallow custom text, act only as a drop down list ); TComboBoxOptions = set of TComboBoxOption; - Check box state and options - TCheckBoxState = ( csUnchecked, - The check box is checked csChecked, - The check box is not checked csGrayed - The check box is grayed (ie. intermediate state) ); TCheckBoxOption = ( coAutoCheck, - Check/uncheck the check box automatically co3State - Allow a third (grayed) state ); TCheckBoxOptions = set of TCheckBoxOption; Callback Types ============== Callbacks used by Fowl: TStreamError = procedure(var S: TStream); Called whenever a stream error occurs, should be assigned to StreamError TCollectionTest = function(Item: Pointer): Boolean; Called by TCollection.FirstThat and LastThat to test and return an item TCollectionAction = procedure(Item: Pointer); Called by TCollection.ForEach for each item in the collection TCollectionError = procedure(var C: TCollection; Error, Info: Integer); Not supported yet, would be called whenever an error in a collection occured TWindowsObjectTest = function(P: PWindowsObject): Boolean; Called by TWindowsObject.FirstThat to test and return a child window TWindowsObjectAction = procedure(P: PWindowsObject); Called by TWindowsObject.ForEach for each child window in the window Object Pointers =============== All the object and record pointer types are shown below: PObject = ^TObject; PStream = ^TStream; PMemStream = ^TMemStream; PFileStream = ^TFileStream; PStreamRec = ^TStreamRec; PCollection = ^TCollection; PDC = ^TDC; PPaintStruct = ^TPaintStruct; PMenuItem = ^TMenuItem; PMenu = ^TMenu; PWindowsObject = ^TWindowsObject; PWindow = ^TWindow; PControl = ^TControl; PButton = ^TButton; PScrollBarTransferRec = ^TScrollBarTransferRec; PScrollBar = ^TScrollBar; PStatic = ^TStatic; PEdit = ^TEdit; PListBoxTransferRec = ^TListBoxTransferRec; PListBox = ^TListBox; PComboBoxTransferRec = ^TComboBoxTransferRec; PComboBox = ^TComboBox; PGroupBox = ^TGroupBox; PCheckBoxState = ^TCheckBoxState; PCheckBox = ^TCheckBox; PRadioButton = ^TRadioButton; PMDIClient = PWindowsObject; PApplication = ^TApplication; Globals ======= Below are the global variables exposed by Fowl: StreamError: TStreamError; - Stream error handler StreamVersion: Cardinal; - Library version to use for streaming CollectionError: TCollectionError; - Collection error handler Application: PApplication; - Application singleton Functions ========= Below are the functions exposed by Fowl: procedure Abstract; Raised Runtime Error 211, used to indicate an abstract method procedure RegisterType(var S: TStreamRec); Register an object type for use with the streaming system Objects ======= Below are the object types exposed by Fowl. Note that inherited methods are omitted for brevity: TObject ------- Base object for the rest of Fowl's objects TObject = object constructor Init; - Default constructor procedure Free; - Free the object destructor Done; virtual; - Default destructor end; TStream ------- Base object for streams TStream = object(TObject) ErrorInfo: Int64; Extra error info, for stGetError it is the unknown object type ID Status: Integer; Stream status, one of stXXX values constructor Init; Stream constructor procedure CopyFrom(var S: TStream; Count: Int64); Copy Count bytes from the given stream procedure Error(Code: Integer; Info: Int64); virtual; Raise a stream error with the given code and info function HasError: Boolean; Return true if there is an error procedure Flush; virtual; Flush any buffered data function Get: PObject; Read an object from the stream. The object type must be registered with Fowl using RegisterType function GetPos: Int64; virtual; Return the current stream position function GetSize: Int64; virtual; Return the whole stream data size (e.g. file size) procedure Put(P: PObject); Write an object to the stream. The object type must be registered with Fowl using RegisterType procedure Read(out Buf; Count: Int64); virtual; Read data from the stream function ReadStr: string; Read a string stored as a 32bit integer for its length followed by text procedure Reset; Reset the stream procedure Seek(Pos: Int64); virtual; Set the stream's position to the given value procedure Truncate; virtual; Truncate the stream so that its size is the current position procedure Write(const Buf; Count: Int64); virtual; Write data to the stream procedure WriteStr(S: string); Write a string stored as a 32bit integer for its length followed by text end; TMemStream ---------- Memory backed stream TMemStream = object(TStream) Buffer: Pointer; The memory buffer to read/write from/to Size: Int64; Allocated size of the buffer Position: Int64; Current stream position FreeBuffer: Boolean; If true, the buffer will be freed by the destructor constructor Init(InitialSize: Int64=0); Constructor for a stream with new buffer of the given initial size (the buffer can be resized later if needed). This sets FreeBuffer to True constructor Wrap(DataBuffer: Pointer; DataSize: Int64); Constructor for wrapping an existing buffer (the buffer can still be resized later). This sets FreeBuffer to False destructor Done; virtual; Stream destructor, will free the buffer if FreeBuffer is True procedure SetSize(NewSize: Int64); Resize the stream's buffer end; TFileStream ----------- File access stream TFileStream = object(TStream) Handle: THandle; File handle constructor Init(FileName: string; Mode: Integer); Constructor for accessing the given file. Mode is one of the stream mode values (stCreate, stOpenRead, stOpenWrite, stOpen). end; TCollection ----------- A collection of items represented by pointers. By default these pointers are assumed to be objects (PObject), however any pointer type can be supported by subclassing this class and overriding the FreeItem, GetItem and PutItem methods. TCollection = object(TObject) Count: Integer; Number of items in the collection Delta: Integer; How much to grow the collection when trying to add a new item and there is not enough memory allocated Items: array of Pointer; The items in the collection (warning: the length of this dynamic array is the allocated size which can be greater than the actual number of items stored in the collection!) constructor Init(ALimit: Integer=0; ADelta: Integer=16); Constructor for a new collection with the given initial allocation (ALimit) and allocation delta constructor Load(var S: TStream); Constructor for a collection that will be read from the given stream (calls GetItem for all items in the stored stream) destructor Done; virtual; Collection destructor procedure AtDelete(Index: Integer); Remove the item at the given index procedure AtFree(Index: Integer); Remove and free the item at the given index (this will call FreeItem) procedure AtInsert(Index: Integer; Item: Pointer); Insert an item at the given index procedure AtPut(Index: Integer; Item: Pointer); Set the item at the given index function At(Index: Integer): Pointer; Return the item at the given index procedure Delete(Item: Pointer); Remove the given item from the collection procedure DeleteAll; Remove all items in the collection procedure Error(Code, Info: Integer); virtual; Raise a collection error function FirstThat(Test: TCollectionTest): Pointer; Test all items with the given function from the first to the last and return the first item for which Test returns True, or nil if no item returned true procedure ForEach(Action: TCollectionAction); Call Action for each item in the collection, from the first to the last procedure FreeAll; Remove and free all items in the collection (calls FreeItem) procedure FreeItem(Item: Pointer); virtual; Free the given item, by default this treats Item as a PObject and calls the Dispose(PObject(Item), Done) on it. Note that this will *not* remove the item from the collection, it is meant to be called by other methods - if you want to free and remove an item from the collection use the Free method instead. procedure Free(Item: Pointer); Remove and free the given item function GetItem(var S: TStream): Pointer; virtual; Read an item from the given stream and put it in the collection. By default this assumes the item is an object (PObject) and calls S.Get to read the object from the stream. function IndexOf(Item: Pointer): Integer; virtual; Return the index of the given item or -1 if the item was not found procedure Insert(Item: Pointer); virtual; Insert the given item at the end of the collection function LastThat(Test: TCollectionTest): Pointer; Test all items with the given function from the first to the last and return the first item for which Test returns True, or nil if no item returned true procedure Pack; Remove any nil items from the collection procedure PutItem(var S: TStream; Item: Pointer); virtual; Store the given item (which is assumed to be part of the collection) to the given stream. By default this assumed that the item is an object (PObject) and calls S.Put to write it to the stream. procedure SetLimit(ALimit: Integer); virtual; Set the allocation limit procedure Store(var S: TStream); Store this collection to the given stream end; TMenuItem --------- A single menu item TMenuItem = object(TObject) Title: string; The item's title Id: Integer; The item's id Flag: Integer; Item flag (really, item type), one of the it_xxx values SubMenu: PMenu; The item's submenu, if any constructor Init(ATitle: string; AnId: Integer; ItemFlag: Integer; ASubMenu: PMenu); Construct a menu item with the given title, id, flag and submenu constructor Load(var S: TStream); Constructor for a menu item stored in the given stream destructor Done; virtual; Menu item destructor procedure SetEnabled(Enabled: Boolean); Set the enabled state of the menu function GetEnabled: Boolean; Return the enabled state of the menu procedure Store(var S: TStream); Store the menu item to the given stream end; TMenu ----- Window system menu, describes an entire menu (e.g. menu bar) TMenu = object(TObject) Items: PCollection; The menu items in this menu constructor Init; Empty menu constructor constructor Load(var S: TStream); Constructor for a menu stored in the given stream destructor Done; virtual; Menu destructor function AppendMenu(ATitle: string; AnId: Integer; ItemFlag: Integer; ASubMenu: PMenu): PMenuItem; virtual; Append a new menu item with the given title, id, flag and submenu, returns the newly created menu item object procedure AppendSeparator; virtual; Append a new separator procedure Store(var S: TStream); Store the menu to the given stream end; TWindowsObject -------------- Base type for all window system objects (toplevel windows, buttons, etc) TWindowsObject = object(TObject) ChildList: PWindowsObject; First child of the window, forming a linked list for all the children SiblingList: PWindowsObject; Next sibling of this window in its parent's linked list Flags: Byte; Window flags, a combination of wb_xxx values HWindow: THandle; Window handle Parent: PWindowsObject; Window parent Status: Integer; Window status, one of the em_xxx values TransferBuffer: Pointer; The buffer to use for data transfers constructor Init(AParent: PWindowsObject); Construct a new window object for the given parent constructor Load(var S: TStream); Constructor for loading a window object from the given stream destructor Done; virtual; Window object destructor function CanClose: Boolean; virtual; Return true if the window can be closed function ChildWithId(Id: Integer): PWindowsObject; virtual; Return the child with the given id or nil if no such child exists function ChildWithHandle(Handle: THandle): PWindowsObject; Return the child with the given handle or nil if no such child exists procedure CloseWindow; If CanClose returns true then this will call Destroy function Create: Boolean; virtual; Creates the underlying window system window for this window object - the Handle field is not valid until this method is called. Returns False if the creation failed. This is an abstract method. function CreateChildren: Boolean; Calls Create on all children - this is usually called when loading a window object from a stream procedure DefChildProc(var Msg: TMessage); virtual; Called to handle the notification message (wm_Command) for a child (note that children can block this if they handle the message themselves via ProcessParentNotificationMessage) procedure DefCommandProc(var Msg: TMessage); virtual; Process a command notification message (wm_Command from menus and accelerators) procedure DefWndProc(var Msg: TMessage); virtual; Process messages that weren't handled by Fowl (usually just calls DefWindowProc) procedure Destroy; virtual; Request to destroy the underlying native window object. In addition this will set all children's autocreate flag to true procedure DisableAutoCreate; Disable the autocreate flag on this window object procedure DisableTransfer; Disable the data transfer flag on this window object procedure DispatchScroll(var Msg: TMessage); virtual; Dispatch a scroll message to the appropriate scroll bar child procedure EnableAutoCreate; Enable the autocreate flag on this window object procedure EnableKBHandler; Enable the keyboard handler flag on this window object procedure EnableTransfer; Enable the data transfer flag on this window object function FirstThat(Test: TWindowsObjectTest): PWindowsObject; Call the Test function on all of this window object's children and return the first for which Test returns True procedure ForEach(Action: TWindowsObjectAction); Call the Action function on all of this window object's children procedure GetChildPtr(var S: TStream; out P: PWindowsObject); Read a child window from the given stream and store it in the given object pointer procedure GetChildren(var S: TStream); Read all the children of this window object from the given stream function GetClassName: string; virtual; Return the Windows class name for the native window this object represents (e.g. BUTTON, EDIT, etc) function GetClient: PMDIClient; virtual; Return the MDI client for this window (not implemented yet) function GetId: Integer; virtual; Return the id of this window procedure GetSiblingPtr(var S: TStream; out P: PWindowsObject); Read the next sibling window object from the given stream and stores it in the given object pointer procedure GetWindowClass(var AWndClass); virtual; Called to fill information for custom window classes (AWndClass is pointing to a WNDCLASS structure) function IsFlagSet(Mask: Byte): Boolean; Return true if the given flag(s) is set function Next: PWindowsObject; Return the next window object sibling function Previous: PWindowsObject; Return the previous window object sibling procedure PutChildPtr(var S: TStream; P: PWindowsObject); Store the given child window object to the given stream procedure PutChildren(var S: TStream); Store all children window objects to the given stream procedure PutSiblingPtr(var S: TStream; P: PWindowsObject); Store the given sibling window object ot the given stream function Register: Boolean; virtual; Registers the window class of this window object if needed and returns True if the registration succeeded procedure SetFlags(Mask: Byte; OnOff: Boolean); Set/unset the given flags procedure UpdateMenu; virtual; Update the native menu for this window based on the associated menu object. By default this does nothing but it is overridden by TWindow to (re)create the native menu. procedure SetupWindow; virtual; Setup the window state after it has been created function CheckHandle: Boolean; Return True if this window has a handle set procedure Show(ShowCmd: Integer); virtual; Show or hide the window object (one of the sw_xx values) procedure Move(X, Y: Integer); virtual; Move the window object to the given position. For TWindow based objects if the window handle has not been created yet, this will update the window attributes so that once the window is created, it will be placed at the given position procedure Resize(W, H: Integer); virtual; Resize the window object to the given dimensions. For TWindow based objects if the window handle has not been created yet, this will update the window attributes so that once the window is created, it will get the given size procedure Place(X, Y, W, H: Integer); virtual; Move and resize the window object to be inside the given area. For TWindow based objects if the window handle has not been created yet, this will update the window attributes so that once the window is created, it will be placed at the given area procedure GetRectArea(out X, Y, W, H: Integer); virtual; Return the window object's area in its parent space. For TWindow based objects if the window handle has not been created yet, this returns the area stored in the window attributes procedure GetClientArea(out X, Y, W, H: Integer); virtual; Return the window object's client area (as this is in client space, the X and Y values are always 0). Note that unlike Move, Resize, Place and GetRectArea, this requires the window handle to be valid procedure SetText(Text: string); virtual; Set the window object's text (title for toplevel windows) function GetText: string; virtual; Return the window object's text procedure Invalidate; virtual; Invalidate (damage) the window object to make it paint itself later procedure InvalidateArea(X, Y, W, H: Integer); virtual; Invalidate (damage) a part of the window object to make it paint itself later procedure Repaint; virtual; Force a full repaint of the window object procedure Enable(Flag: Boolean); virtual; Enable or disable the window object function IsEnabled: Boolean; virtual; Return the current setting of the enabled flag procedure Store(var S: TStream); Store this window object to the given stream function Transfer(DataPtr: Pointer; TransferFlag: Integer): Integer; virtual; Perform a data transfer operation, returns the size of the data transferred procedure TransferData(Direction: Integer); virtual; Perform a data transfer operation but only for windows that have the wb_Transfer flag set. Direction must be either tf_GetData or tf_SetData procedure ProcessMessage(var Msg: TMessage); virtual; Process a window message, this will call the other methods in this object function ProcessParentNotificationMessage(var Msg: TMessage): Boolean; virtual; Called on a child to process a notification message posted to its parent function ProcessNotification(Child: PWindowsObject; NotifyCode: Integer): Boolean; virtual; Called to process a notification event from the given child. The NotifyCode parameter can be one of the cn_xxx values function ProcessCommand(Command: Integer): Boolean; virtual; Called to process a menu/accelerator command end; TWindow ------- Base type for all windows and controls TWindow = object(TWindowsObject) Attr: TWindowAttr; Stores the window's attributes FocusChildHandle: PWindowsObject; Contains the child that had the handle of the focused window the last time the window was activated constructor Init(AParent: PWindowsObject; ATitle: string); Window constructor for the given parent and with the given title constructor Load(var S: TStream); Constructor for loading a window from the given stream procedure MoveToCenter; Move the window so that it is placed at the center of its parent or to the center of the desktop, for windows without a parent. This method works even before a handle has been allocated. procedure Paint(var PaintDC: TDC; const PaintInfo: TPaintStruct); virtual; Called to paint the window in the given device context a procedure SetMenu(AMenu: PMenu); virtual; Called to set the window menu (also sets the wb_HasMenu flag). The menu will be automatically disposed when this window gets destroyed function GetMenu: PMenu; virtual; Return the current window menu procedure RemoveMenu; virtual; Remove the menu from this window (removes the wb_HasMenu flag) function StoreText: Boolean; virtual; If StoreText returns true then the window's text will be stored during streaming so that when the UI is loaded it will already contain it. This is by default True, however controls that allow the user to edit text will set this to False as to avoid storing the control state together with the UI. end; TControl -------- Base type for controls TControl = object(TWindow) constructor Init(AParent: PWindowsObject; AnId: Integer; ATitle: string; X, Y, W, H: Integer); Contructs a control inside the given parent with the given id, title, position and dimensions end; TButton ------- Push button control TButton = object(TControl) constructor Init(AParent: PWindowsObject; AnId: Integer; AText: string; X, Y, W, H: Integer; IsDefault: Boolean); Like TControl.Init but with the additional flag IsDefault which if True will make the button to be the window's default button end; TScrollBar ---------- Horizontal or vertical scroll bar control TScrollBar = object(TControl) LineMagnitude: Integer; Amount of units to scroll for line scrolling (e.g. clicking the arrows) PageMagnitude: Integer; Amount of units to scroll for page scrolling (e.g. clcking the track) constructor Init(AParent: PWindowsObject; AnId, X, Y, W, H: Integer; IsHScrollBar: Boolean); Like TControl.Init but with a IsHScrollBar that if True will create a horizontal scroll bar and if False will create a vertical scroll bar function DeltaPos(Delta: Integer): Integer; virtual; Scroll by the given delta function GetPosition: Integer; virtual; Return the scroll bar's position procedure GetRange(out LoVal, HiVal: Integer); virtual; Return the scroll bar's range procedure SetPosition(ThumbPos: Integer); virtual; Set the scroll bar's position procedure SetRange(LoVal, HiVal: Integer); virtual; Set the scroll bar's range procedure ProcessSBMessage(var Msg: TMessage); Called to process a scroll message end; TStatic ------- Static text control { TStatic - static text control } TStatic = object(TControl) procedure Clear; virtual; Clear the text in the control end; TEdit ----- Text editor control TEdit = object(TStatic) constructor Init(AParent: PWindowsObject; AnId: Integer; AText: string; X, Y, W, H: Integer; Options: TEditOptions); Like TControl.Init but with additional edit options parameter (see the TEditOptions set above) function CanUndo: Boolean; virtual; Returns true if there is an Undo step available procedure ClearModify; virtual; Clear the modified flag procedure Copy; virtual; Copy the selected text to the clipboard procedure Cut; virtual; Cut the selected text to the clipboard function DeleteLine(LineNumber: Integer): Boolean; virtual; Delete the line at the given line number, returns false if failed function DeleteSelection: Boolean; virtual; Delete the selected text, returns false if failed function DeleteSubText(StartPos, EndPos: Integer): Boolean; virtual; Return the given text range, returns false if failed function GetLine(LineNumber: Integer): string; virtual; Return the text at the given line number function GetLineFromPos(CharPos: Integer): Integer; virtual; Return the line at the given character position function GetLineIndex(LineNumber: Integer): Integer; virtual; Return the position of the first character of the given line function GetLineLength(LineNumber: Integer): Integer; virtual; Return the length of the given line function GetNumLines: Integer; virtual; Return the number of lines in the editor function GetSelection(out StartPos, EndPos: Integer): Boolean; virtual; Return the range of the current selection, returns false if failed function GetSubText(StartPos, EndPos: Integer): string; virtual; Return the given text range procedure Insert(ATextString: string); virtual; Insert text as if it was typed function IsModified: Boolean; virtual; Returns True if the text was modified (the modified flag is set) procedure Paste; virtual; Paste text from the clipboard procedure Scroll(HorizontalUnit, VerticalUnit: Integer); virtual; Scroll the text by the given horizontal and vertical units function Search(StartPos: Integer; AText: string; CaseSensitive: Boolean): Integer; virtual; Perform a text search from the given starting position for the given text and the given case sensitivity setting function SetSelection(StartPos, EndPos: Integer): Boolean; virtual; Set the selected text range procedure Undo; virtual; Undo last edit operation end; TListBox -------- List box control TListBox = object(TControl) constructor Init(AParent: PWindowsObject; AnId, X, Y, W, H: Integer; Options: TListBoxOptions); Like TControl.Init but with additional list box options parameter (see the TListBoxOptions set above) function AddString(AString: string): Integer; virtual; Add a string to the list box, returns the new string's index procedure ClearList; virtual; Clear the list (remove all strings in it) function DeleteString(Index: Integer): Integer; virtual; Remove string at the given index from the list box, returns the remaining number of strings or -1 if the given index is invalid function GetCount: Integer; virtual; Return the number of strings in the list box function GetSelIndex: Integer; virtual; Return the primary selection index function IsSelected(Index: Integer): Boolean; virtual; Return True if the string at the given index is selected function GetSelString: string; virtual; Return the selected string function GetString(Index: Integer): string; virtual; Return the string at the given index function InsertString(AString: string; Index: Integer): Integer; virtual; Insert a string at the given index, returns -1 if the index is invalid function SetSelIndex(Index: Integer): Integer; virtual; Set the selection to the string at the given index, returns -1 if an error happens (note: do not use this for multiple selection list boxes) function SetSelected(Index: Integer; Selected: Boolean): Boolean; virtual; Set the selected state for the string at the given index, returns False if an error happens function SetSelString(AString: string; Index: Integer): Integer; virtual; Set the selected string to the first string that matches the given string end; TComboBox --------- Combo box control TComboBox = object(TControl) constructor Init(AParent: PWindowsObject; AnId, X, Y, W, H: Integer; Options: TComboBoxOptions); Like TControl.Init but with additional combo box options parameter (see the TComboBoxOptions set) function AddString(AString: string): Integer; virtual; Add a new string in the combo box procedure ClearList; virtual; Clear the strings in the combo box function DeleteString(Index: Integer): Integer; virtual; Remove the string at the given index from the combo box, returns the remaining number of strings or -1 if an invalid index was given function GetCount: Integer; virtual; Return the number of strings in the combo box function GetSelIndex: Integer; virtual; Return the index of the selected string in the combo box function GetSelString: string; virtual; Return the selected string in the combo box's list function GetString(Index: Integer): string; virtual; Return the string at the given index in the combo box function InsertString(AString: string; Index: Integer): Integer; virtual; Insert a string at the given index, returns -1 if the index is invalid function SetSelIndex(Index: Integer): Integer; virtual; Set the selection to the string at the given index, returns -1 if an error happens (note: do not use this for multiple selection list boxes) function SetSelString(AString: string; Index: Integer): Integer; virtual; Set the selected string to the first string that matches the given string procedure HideList; virtual; Hide the combo box drop down list procedure ShowList; virtual; Show the combo box drop down list end; TGroupBox --------- Group box control, used to visually group together items TGroupBox = object(TControl) NotifyParent: Boolean; If this is True, any notification inside this group box will be passed to the group box's own parent (by default the constructor sets this to True) procedure SelectionChanged(ControlId: Integer); virtual; Call the group's parent's ProcessNotification method with the control that has the given id and the cn_Changed notification code to simulate a notification message. Note that this is not used by Fowl itself and instead notifications and passed automatically via a custom BUTTON subclass end; TCheckBox --------- Check box control TCheckBox = object(TControl) constructor Init(AParent: PWindowsObject; AnId: Integer; ATitle: string; X, Y, W, H: Integer; Options: TCheckBoxOptions); Like TControl.Init but with additional check box options parameter (see the TCheckBoxOptions set above) procedure Check; virtual; Check the check box function GetCheck: TCheckBoxState; virtual; Return the check box state procedure SetCheck(CheckFlag: TCheckBoxState); virtual; Set the check box state procedure Toggle; virtual; Toggle the check box procedure Uncheck; virtual; Uncheck the check box end; TRadioButton ------------ Radio button control TRadioButton = object(TCheckBox) end; TApplication ------------ Base type for the application singleton TApplication = object(TObject) KBHandlerWnd: PWindowsObject; Current keyboard handler (this is set to the last activated window with the wb_KeyboardHandler flag) MainWindow: PWindowsObject; The main window, must be set via InitMainWindow Name: string; The application's name Status: Integer; Current status constructor Init(AName: string); Construct the application with the given name destructor Done; virtual; Application destructor function CanClose: Boolean; virtual; Returns true if the application can close procedure Error(ErrorCode: Integer); virtual; Raise an error function ExecDialog(ADialog: PWindowsObject): Integer; virtual; Execute a dialog (not implemented yet) procedure ShowMessage(Text: string); virtual; Show the given message procedure InitApplication; virtual; Called to initialize the application *before* the main window is created procedure InitInstance; virtual; Called to initialize the application, by default calls InitMainWindow, validates the MainWindow field and shows the window procedure InitMainWindow; virtual; Called to initialize the main window. This must set the MainWindow field to an instance of a TWindow derived type function MakeWindow(AWindowsObject: PWindowsObject): PWindowsObject; virtual; Attempts to create a not-created-yet window by validating and then calling its Create method. If the passed object is nil or it is not a valid window or the Create method returns False, this returns nil after disposing the object (if it is not already nil) procedure MessageLoop; virtual; Run the main message loop function ProcessAccels(var Message: TMessage): Boolean; virtual; Process accelerator messages, returns False if no message was handled function ProcessAppMsg(var Message: TMessage): Boolean; virtual; Process application messages - this calls ProcessDlgMsg, ProcessMDIAccels and ProcessAccels in that order and returns True if any of those returns True, otherwise it returns False to indicate that the message wasn't handled. This can be overridden to perform custom application-level message handling function ProcessDlgMsg(var Message: TMessage): Boolean; virtual; Handles modeless dialog messages (not implemented yet) function ProcessMDIAccels(var Message: TMessage): Boolean; virtual; Handles MDI messages (not implemented yet) procedure Run; virtual; Run the application's main message loop if there is no error status procedure Terminate; virtual; Request the application to terminate by posting a quit message in the message queue procedure SetKBHandler(AWindowsObject: PWindowsObject); Set the keyboard handler windows object (called automatically by Fowl when windows are activated) function ValidWindow(AWindowsObject: PWindowsObject): PWindowsObject; Checks if the given window is a valid window object and returns it or nil if it is not valid end;