form.pp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. (******************************************************************************
  2. *
  3. * Copyright (c) 1994-2000 Palm, Inc. or its subsidiaries.
  4. * All rights reserved.
  5. *
  6. * File: Form.h
  7. *
  8. * Release: Palm OS SDK 4.0 (63220)
  9. *
  10. * Description:
  11. * This file defines form structures and routines.
  12. *
  13. * History:
  14. * 09/06/94 art Created by Art Lamb.
  15. * 08/28/00 kwk Added FrmGetActiveField (4.0)
  16. *
  17. *****************************************************************************)
  18. unit form;
  19. interface
  20. uses palmos, coretraps, rect, font, window, control, field, list, scrollbar, table, event_;
  21. const
  22. noFocus = $ffff;
  23. frmInvalidObjectId = $ffff;
  24. frmNoSelectedControl = $ff;
  25. // Update code send as part of a frmUpdate event.
  26. frmRedrawUpdateCode = $8000;
  27. // Magic button IDs used by FrmCustomResponseAlert callbacks
  28. frmResponseCreate = 1974;
  29. frmResponseQuit = $BEEF;
  30. // Alert constants and structures
  31. type
  32. alertTypes = Enum;
  33. const
  34. informationAlert = 0;
  35. confirmationAlert = Succ(informationAlert);
  36. warningAlert = Succ(confirmationAlert);
  37. errorAlert = Succ(warningAlert);
  38. type
  39. AlertType = alertTypes;
  40. AlertTemplateType = record
  41. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  42. alertType: UInt16;
  43. helpRscID: UInt16;
  44. numButtons: UInt16;
  45. defaultButton: UInt16;
  46. {$endif}
  47. end;
  48. AlertTemplateTag = AlertTemplateType;
  49. // Types of object in a dialog box
  50. formObjects = Enum;
  51. const
  52. frmFieldObj = 0;
  53. frmControlObj = Succ(frmFieldObj);
  54. frmListObj = Succ(frmControlObj);
  55. frmTableObj = Succ(frmListObj);
  56. frmBitmapObj = Succ(frmTableObj);
  57. frmLineObj = Succ(frmBitmapObj);
  58. frmFrameObj = Succ(frmLineObj);
  59. frmRectangleObj = Succ(frmFrameObj);
  60. frmLabelObj = Succ(frmRectangleObj);
  61. frmTitleObj = Succ(frmLabelObj);
  62. frmPopupObj = Succ(frmTitleObj);
  63. frmGraffitiStateObj = Succ(frmPopupObj);
  64. frmGadgetObj = Succ(frmGraffitiStateObj);
  65. frmScrollBarObj = Succ(frmGadgetObj);
  66. type
  67. FormObjectKind = formObjects;
  68. FormObjAttrType = record
  69. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  70. Bits: UInt16;
  71. {
  72. UInt16 usable :1; // Set if part of ui
  73. UInt16 reserved :15; // pad it out
  74. }
  75. {$endif}
  76. end;
  77. FormObjAttrTag = FormObjAttrType;
  78. // Gadget support:
  79. const
  80. formGadgetDrawCmd = 0; // paramP is unspecified
  81. formGadgetEraseCmd = 1; // paramP is unspecified
  82. formGadgetHandleEventCmd = 2; // paramP is an EventType *for the relevant event.
  83. formGadgetDeleteCmd = 3; // paramP is unspecified.
  84. type
  85. FormGadgetAttrType = record
  86. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  87. Bits: UInt16;
  88. {
  89. UInt16 usable :1; // Set if part of ui - "should be drawn"
  90. UInt16 extended :1; // Set if the structure is an "Extended" gadget (i.e., the 'handler' field is present)
  91. UInt16 visible :1; // Set if drawn - "has been drawn" or "must do work to erase"
  92. UInt16 reserved :13; // pad it out
  93. }
  94. {$endif}
  95. end;
  96. FormGadgetAttrTag = FormGadgetAttrType;
  97. FormGadgetPtr = ^FormGadgetType;
  98. FormGadgetHandlerType = function(gadgetP: FormGadgetPtr; cmd: UInt16; paramP: Pointer): Boolean;
  99. FormGadgetType = record
  100. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  101. id: UInt16;
  102. attr: FormGadgetAttrType;
  103. rect: RectangleType;
  104. data: Pointer;
  105. handler: FormGadgetHandlerType;
  106. {$endif}
  107. end;
  108. // All of the smaller form objects:
  109. FormBitmapType = record
  110. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  111. attr: FormObjAttrType;
  112. pos: PointType;
  113. rscID: UInt16;
  114. {$endif}
  115. end;
  116. FormBitmapTag = FormBitmapType;
  117. FormBitmapPtr = ^FormBitmapType;
  118. FormLineType = record
  119. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  120. attr: FormObjAttrType;
  121. point1: PointType;
  122. point2: PointType;
  123. {$endif}
  124. end;
  125. FormLineTag = FormLineType;
  126. FormFrameType = record
  127. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  128. id: UInt16;
  129. attr: FormObjAttrType;
  130. rect: RectangleType;
  131. frameType: UInt16;
  132. {$endif}
  133. end;
  134. FormFrameTag = FormFrameType;
  135. FormRectangleType = record
  136. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  137. attr: FormObjAttrType;
  138. rect: RectangleType;
  139. {$endif}
  140. end;
  141. FormRectangleTag = FormRectangleType;
  142. FormLabelType = record
  143. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  144. id: UInt16;
  145. pos: PointType;
  146. attr: FormObjAttrType;
  147. fontID: FontID;
  148. reserved: UInt8;
  149. text: PChar;
  150. {$endif}
  151. end;
  152. FormLabelTag = FormLabelType;
  153. FormLabelPtr = ^FormLabelType;
  154. FormTitleType = record
  155. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  156. rect: RectangleType;
  157. text: PChar;
  158. {$endif}
  159. end;
  160. FormTitleTag = FormTitleType;
  161. FormPopupType = record
  162. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  163. controlID: UInt16;
  164. listID: UInt16;
  165. {$endif}
  166. end;
  167. FormPopupTag = FormPopupType;
  168. FrmGraffitiStateType = record
  169. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  170. pos: PointType;
  171. {$endif}
  172. end;
  173. FormGraffitiStateTag = FrmGraffitiStateType;
  174. FrmGraffitiStatePtr = ^FrmGraffitiStateType;
  175. FormObjectType = record
  176. case Integer of
  177. 1: (ptr: Pointer);
  178. 2: (field: ^FieldType);
  179. 3: (control: ^ControlType);
  180. 4: (graphicControl: ^GraphicControlType);
  181. 5: (sliderControl: ^SliderControlType);
  182. 6: (list: ^ListType);
  183. 7: (table: ^TableType);
  184. 8: (bitmap: ^FormBitmapType);
  185. // FormLineType * line;
  186. // FormFrameType * frame;
  187. // FormRectangleType * rectangle;
  188. 9: (label_: ^FormLabelType);
  189. 10: (title: ^FormTitleType);
  190. 11: (popup: ^FormPopupType);
  191. 12: (grfState: ^FrmGraffitiStateType);
  192. 13: (gadget: ^FormGadgetType);
  193. 14: (scrollBar: ^ScrollBarType);
  194. end;
  195. FormObjectTag = FormObjectType;
  196. // typedef FormObjectType *FormObjectPtr;
  197. FormObjListType = record
  198. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  199. objectType: FormObjectKind;
  200. reserved: UInt8;
  201. object_: FormObjectType;
  202. {$endif}
  203. end;
  204. FormObjListTag = FormObjListType;
  205. FormAttrType = record
  206. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  207. Bits: UInt16;
  208. {
  209. UInt16 usable :1; // Set if part of ui
  210. UInt16 enabled :1; // Set if interactable (not grayed out)
  211. UInt16 visible :1; // Set if drawn, used internally
  212. UInt16 dirty :1; // Set if dialog has been modified
  213. UInt16 saveBehind :1; // Set if bits behind form are save when form ids drawn
  214. UInt16 graffitiShift :1; // Set if graffiti shift indicator is supported
  215. UInt16 globalsAvailable:1; // Set by Palm OS if globals are available for the
  216. // form event handler
  217. UInt16 doingDialog :1; // FrmDoDialog is using for nested event loop
  218. UInt16 exitDialog :1; // tells FrmDoDialog to bail out and stop using this form
  219. UInt16 attnIndicator :1; // Set if attention indicator is supported
  220. UInt16 reserved :6; // pad to 16
  221. }
  222. reserved2: UInt16; // FormAttrType now explicitly 32-bits wide.
  223. {$endif}
  224. end;
  225. FormAttrTag = FormAttrType;
  226. FormEventHandlerType = function(var eventP: EventType): Boolean;
  227. FormEventHandlerPtr = FormEventHandlerType;
  228. FormType = record
  229. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_FORMS} // These fields will not be available in the next OS release!
  230. window: WindowType;
  231. formId: UInt16;
  232. attr: FormAttrType;
  233. bitsBehindForm: WinHandle;
  234. handler: FormEventHandlerType;
  235. focus: UInt16;
  236. defaultButton: UInt16;
  237. helpRscId: UInt16;
  238. menuRscId: UInt16;
  239. numObjects: UInt16;
  240. objects: ^FormObjListType;
  241. {$endif}
  242. end;
  243. FormPtr = ^FormType;
  244. FieldPtr = ^FieldType;
  245. // FormActiveStateType: this structure is passed to FrmActiveState for
  246. // saving and restoring active form/window state; this structure's
  247. // contents are abstracted because the contents will differ significantly
  248. // as PalmOS evolves
  249. // Added for PalmOS 3.0
  250. FormActiveStateType = record
  251. data: array [0..10] of UInt16;
  252. end;
  253. // FrmCustomResponseAlert callback routine prototype
  254. FormCheckResponseFuncType = function(button: Int16; attempt: PChar): Boolean;
  255. FormCheckResponseFuncPtr = FormCheckResponseFuncType;
  256. //--------------------------------------------------------------------
  257. //
  258. // Form Function
  259. //
  260. //--------------------------------------------------------------------
  261. function FrmInitForm(rscID: UInt16): FormPtr; syscall sysTrapFrmInitForm;
  262. procedure FrmDeleteForm(formP: FormPtr); syscall sysTrapFrmDeleteForm;
  263. procedure FrmDrawForm(formP: FormPtr); syscall sysTrapFrmDrawForm;
  264. procedure FrmEraseForm(formP: FormPtr); syscall sysTrapFrmEraseForm;
  265. function FrmGetActiveForm: FormPtr; syscall sysTrapFrmGetActiveForm;
  266. procedure FrmSetActiveForm(formP: FormPtr); syscall sysTrapFrmSetActiveForm;
  267. function FrmGetActiveFormID: UInt16; syscall sysTrapFrmGetActiveFormID;
  268. function FrmGetActiveField(const formP: FormPtr): FieldPtr; syscall sysTrapFrmGetActiveField;
  269. function FrmGetUserModifiedState(const formP: FormPtr): Boolean; syscall sysTrapFrmGetUserModifiedState;
  270. procedure FrmSetNotUserModified(formP: FormPtr); syscall sysTrapFrmSetNotUserModified;
  271. function FrmGetFocus(const formP: FormPtr): UInt16; syscall sysTrapFrmGetFocus;
  272. procedure FrmSetFocus(formP: FormPtr; fieldIndex: UInt16); syscall sysTrapFrmSetFocus;
  273. function FrmHandleEvent(formP: FormPtr; eventP: EventPtr): Boolean; syscall sysTrapFrmHandleEvent;
  274. procedure FrmGetFormBounds(const formP: FormPtr; var rP: RectangleType); syscall sysTrapFrmGetFormBounds;
  275. function FrmGetWindowHandle(const formP: FormPtr): WinHandle; syscall sysTrapFrmGetWindowHandle;
  276. function FrmGetFormId(const formP: FormPtr): UInt16; syscall sysTrapFrmGetFormId;
  277. function FrmGetFormPtr(formId: UInt16): FormPtr; syscall sysTrapFrmGetFormPtr;
  278. function FrmGetFirstForm: FormPtr; syscall sysTrapFrmGetFirstForm;
  279. function FrmGetNumberOfObjects(const formP: FormPtr): UInt16; syscall sysTrapFrmGetNumberOfObjects;
  280. function FrmGetObjectIndex(const formP: FormPtr; objID: UInt16): UInt16; syscall sysTrapFrmGetObjectIndex;
  281. function FrmGetObjectIndexFromPtr(const formP: FormPtr; objP: Pointer): UInt16; syscall sysTrapFrmGetObjectIndexFromPtr;
  282. function FrmGetObjectId(const formP: FormPtr; objIndex: UInt16): UInt16; syscall sysTrapFrmGetObjectId;
  283. function FrmGetObjectType(const formP: FormPtr; objIndex: UInt16): FormObjectKind; syscall sysTrapFrmGetObjectType;
  284. function FrmGetObjectPtr(const formP: FormPtr; objIndex: UInt16): Pointer; syscall sysTrapFrmGetObjectPtr;
  285. procedure FrmGetObjectBounds(const formP: FormPtr; objIndex: UInt16; var rP: RectangleType); syscall sysTrapFrmGetObjectBounds;
  286. procedure FrmHideObject(formP: FormPtr; objIndex: UInt16); syscall sysTrapFrmHideObject;
  287. procedure FrmShowObject(formP: FormPtr; objIndex: UInt16); syscall sysTrapFrmShowObject;
  288. procedure FrmGetObjectPosition(const formP: FormPtr; objIndex: UInt16; var x, y: Coord); syscall sysTrapFrmGetObjectPosition;
  289. procedure FrmSetObjectPosition(formP: FormPtr; objIndex: UInt16; x, y: Coord); syscall sysTrapFrmSetObjectPosition;
  290. procedure FrmSetObjectBounds(formP: FormPtr; objIndex: UInt16; {const} var bounds: RectangleType); syscall sysTrapFrmSetObjectBounds;
  291. function FrmGetControlValue(const formP: FormPtr; objIndex: UInt16): Int16; syscall sysTrapFrmGetControlValue;
  292. procedure FrmSetControlValue(const formP: FormPtr; objIndex, newValue: Int16); syscall sysTrapFrmSetControlValue;
  293. function FrmGetControlGroupSelection(const formP: FormPtr; groupNum: UInt8): UInt16; syscall sysTrapFrmGetControlGroupSelection;
  294. procedure FrmSetControlGroupSelection(const formP: FormPtr; groupNum: UInt8; controlID: UInt16); syscall sysTrapFrmSetControlGroupSelection;
  295. procedure FrmCopyLabel(formP: FormPtr; labelID: UInt16; const newLabel: PChar); syscall sysTrapFrmCopyLabel;
  296. function FrmGetLabel(const formP: FormPtr; labelID: UInt16): {const} PChar; syscall sysTrapFrmGetLabel;
  297. procedure FrmSetCategoryLabel(const formP: FormPtr; objIndex: UInt16; newLabel: PChar); syscall sysTrapFrmSetCategoryLabel;
  298. function FrmGetTitle(const formP: FormPtr): {const} PChar; syscall sysTrapFrmGetTitle;
  299. procedure FrmSetTitle(formP: FormPtr; newTitle: PChar); syscall sysTrapFrmSetTitle;
  300. procedure FrmCopyTitle(formP: FormPtr; const newTitle: PChar); syscall sysTrapFrmCopyTitle;
  301. function FrmGetGadgetData(const formP: FormPtr; objIndex: UInt16): Pointer; syscall sysTrapFrmGetGadgetData;
  302. procedure FrmSetGadgetData(formP: FormPtr; objIndex: UInt16; const data: Pointer); syscall sysTrapFrmSetGadgetData;
  303. procedure FrmSetGadgetHandler(formP: FormPtr; objIndex: UInt16; attrP: FormGadgetHandlerType); syscall sysTrapFrmSetGadgetHandler;
  304. function FrmDoDialog(formP: FormPtr): UInt16; syscall sysTrapFrmDoDialog;
  305. function FrmAlert(alertId: UInt16): UInt16; syscall sysTrapFrmAlert;
  306. function FrmCustomAlert(alertId: UInt16; const s1, s2, s3: PChar): UInt16; syscall sysTrapFrmCustomAlert;
  307. procedure FrmHelp(helpMsgId: UInt16); syscall sysTrapFrmHelp;
  308. procedure FrmUpdateScrollers(formP: FormPtr; upIndex, downIndex: UInt16; scrollableUp, scrollableDown: Boolean); syscall sysTrapFrmUpdateScrollers;
  309. function FrmVisible(const formP: FormPtr): Boolean; syscall sysTrapFrmVisible;
  310. procedure FrmSetEventHandler(formP: FormPtr; handler: FormEventHandlerType); syscall sysTrapFrmSetEventHandler;
  311. function FrmDispatchEvent(var eventP: EventType): Boolean; syscall sysTrapFrmDispatchEvent;
  312. procedure FrmPopupForm(formId: UInt16); syscall sysTrapFrmPopupForm;
  313. procedure FrmGotoForm(formId: UInt16); syscall sysTrapFrmGotoForm;
  314. procedure FrmUpdateForm(formId, updateCode: UInt16); syscall sysTrapFrmUpdateForm;
  315. procedure FrmReturnToForm(formId: UInt16); syscall sysTrapFrmReturnToForm;
  316. procedure FrmCloseAllForms; syscall sysTrapFrmCloseAllForms;
  317. procedure FrmSaveAllForms; syscall sysTrapFrmSaveAllForms;
  318. function FrmPointInTitle(const formP: FormPtr; x, y: Coord): Boolean; syscall sysTrapFrmPointInTitle;
  319. procedure FrmSetMenu(formP: FormPtr; menuRscID: UInt16); syscall sysTrapFrmSetMenu;
  320. function FrmValidatePtr(const formP: FormPtr): Boolean; syscall sysTrapFrmValidatePtr;
  321. function FrmAddSpaceForObject(var formPP: FormPtr; var objectPP: MemPtr; objectKind: FormObjectKind; objectSize: UInt16): Err; syscall sysTrapFrmAddSpaceForObject;
  322. function FrmRemoveObject(var formPP: FormPtr; objIndex: UInt16): Err; syscall sysTrapFrmRemoveObject;
  323. function FrmNewForm(formID: UInt16; const titleStrP: PChar; x, y, width, height: Coord; modal: Boolean;
  324. defaultButton, helpRscID, menuRscID: UInt16): FormPtr; syscall sysTrapFrmNewForm;
  325. function FrmNewLabel(var formPP: FormPtr; ID: UInt16; const textP: PChar; x, y: Coord; font: FontID): FormLabelPtr; syscall sysTrapFrmNewLabel;
  326. function FrmNewBitmap(var formPP: FormPtr; ID, rscID: UInt16; x, y: Coord): FormBitmapPtr; syscall sysTrapFrmNewBitmap;
  327. function FrmNewGadget(var formPP: FormPtr; id: UInt16; x, y, width, height: Coord): FormGadgetPtr; syscall sysTrapFrmNewGadget;
  328. function FrmActiveState(var stateP: FormActiveStateType; save: Boolean): Err; syscall sysTrapFrmActiveState;
  329. function FrmCustomResponseAlert(alertId: UInt16; const s1, s2, s3: PChar; entryStringBuf: PChar;
  330. entryStringBufLength: Int16; callback: FormCheckResponseFuncType): UInt16; syscall sysTrapFrmCustomResponseAlert;
  331. function FrmNewGsi(var formPP: FormPtr; x, y: Coord): FrmGraffitiStatePtr; syscall sysTrapFrmNewGsi;
  332. function FrmSaveActiveState(var stateP: FormActiveStateType): Err;
  333. function FrmRestoreActiveState(var stateP: FormActiveStateType): Err;
  334. implementation
  335. function FrmSaveActiveState(var stateP: FormActiveStateType): Err;
  336. begin
  337. FrmSaveActiveState := FrmActiveState(stateP, True);
  338. end;
  339. function FrmRestoreActiveState(var stateP: FormActiveStateType): Err;
  340. begin
  341. FrmRestoreActiveState := FrmActiveState(stateP, False);
  342. end;
  343. end.