gadtools.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. {
  2. This file is part of the Free Pascal run time library.
  3. A file in Amiga system run time library.
  4. Copyright (c) 1998-2003 by Nils Sjoholm
  5. member of the Amiga RTL development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. History:
  14. Added autoopening of gadtools.library.
  15. 15 Jul 2000.
  16. Added MessageBox for error report.
  17. 31 Jul 2000.
  18. Added the macros GTMENUITEM_USERDATA and GTMENU_USERDATA.
  19. 19 Aug 2000.
  20. Added functions and procedures with array of const.
  21. For use with fpc 1.0. They are in systemvartags.
  22. 11 Nov 2002.
  23. Added the defines use_amiga_smartlink and
  24. use_auto_openlib.
  25. 13 Jan 2003.
  26. Update for AmigaOS 3.9.
  27. Changed startup code for the unit.
  28. 01 Feb 2003.
  29. Changed integer > smallint,
  30. cardinal > longword.
  31. 09 Feb 2003.
  32. [email protected]
  33. }
  34. {$I useamigasmartlink.inc}
  35. {$ifdef use_amiga_smartlink}
  36. {$smartlink on}
  37. {$endif use_amiga_smartlink}
  38. unit gadtools;
  39. INTERFACE
  40. uses exec, intuition, graphics, utility;
  41. {------------------------------------------------------------------------}
  42. { The kinds (almost classes) of gadgets in the toolkit. Use these
  43. identifiers when calling CreateGadgetA() }
  44. CONST
  45. GENERIC_KIND = 0;
  46. BUTTON_KIND = 1;
  47. CHECKBOX_KIND = 2;
  48. INTEGER_KIND = 3;
  49. LISTVIEW_KIND = 4;
  50. MX_KIND = 5;
  51. NUMBER_KIND = 6;
  52. CYCLE_KIND = 7;
  53. PALETTE_KIND = 8;
  54. SCROLLER_KIND = 9;
  55. { Kind number 10 is reserved }
  56. SLIDER_KIND = 11;
  57. STRING_KIND = 12;
  58. TEXT_KIND = 13;
  59. NUM_KINDS = 14;
  60. GADTOOLSNAME : PChar = 'gadtools.library';
  61. {------------------------------------------------------------------------}
  62. { 'Or' the appropriate set together for your Window IDCMPFlags: }
  63. ARROWIDCMP = (IDCMP_GADGETUP + IDCMP_GADGETDOWN +
  64. IDCMP_INTUITICKS + IDCMP_MOUSEBUTTONS);
  65. BUTTONIDCMP = (IDCMP_GADGETUP);
  66. CHECKBOXIDCMP = (IDCMP_GADGETUP);
  67. INTEGERIDCMP = (IDCMP_GADGETUP);
  68. LISTVIEWIDCMP = (IDCMP_GADGETUP + IDCMP_GADGETDOWN +
  69. IDCMP_MOUSEMOVE + ARROWIDCMP);
  70. MXIDCMP = (IDCMP_GADGETDOWN);
  71. NUMBERIDCMP = 0;
  72. CYCLEIDCMP = (IDCMP_GADGETUP);
  73. PALETTEIDCMP = (IDCMP_GADGETUP);
  74. { Use ARROWIDCMP+SCROLLERIDCMP if your scrollers have arrows: }
  75. SCROLLERIDCMP = (IDCMP_GADGETUP + IDCMP_GADGETDOWN + IDCMP_MOUSEMOVE);
  76. SLIDERIDCMP = (IDCMP_GADGETUP + IDCMP_GADGETDOWN + IDCMP_MOUSEMOVE);
  77. STRINGIDCMP = (IDCMP_GADGETUP);
  78. TEXTIDCMP = 0;
  79. {------------------------------------------------------------------------}
  80. { Generic NewGadget used by several of the gadget classes: }
  81. Type
  82. pNewGadget = ^tNewGadget;
  83. tNewGadget = record
  84. ng_LeftEdge, ng_TopEdge : smallint; { gadget position }
  85. ng_Width, ng_Height : smallint; { gadget size }
  86. ng_GadgetText : STRPTR; { gadget label }
  87. ng_TextAttr : pTextAttr; { desired font for gadget label }
  88. ng_GadgetID : Word; { gadget ID }
  89. ng_Flags : ULONG; { see below }
  90. ng_VisualInfo : Pointer; { Set to retval of GetVisualInfo() }
  91. ng_UserData : Pointer; { gadget UserData }
  92. END;
  93. { ng_Flags control certain aspects of the gadget. The first five control
  94. the placement of the descriptive text. All larger groups supply a
  95. default: }
  96. CONST
  97. PLACETEXT_LEFT = $0001; { Right-align text on left side }
  98. PLACETEXT_RIGHT = $0002; { Left-align text on right side }
  99. PLACETEXT_ABOVE = $0004; { Center text above }
  100. PLACETEXT_BELOW = $0008; { Center text below }
  101. PLACETEXT_IN = $0010; { Center text on }
  102. NG_HIGHLABEL = $0020; { Highlight the label }
  103. {------------------------------------------------------------------------}
  104. { Fill out an array of these and pass that to CreateMenus(): }
  105. Type
  106. pNewMenu = ^tNewMenu;
  107. tNewMenu = record
  108. nm_Type : Byte; { See below }
  109. nm_Label : STRPTR; { Menu's label }
  110. nm_CommKey : STRPTR; { MenuItem Command Key Equiv }
  111. nm_Flags : Word; { Menu OR MenuItem flags (see note) }
  112. nm_MutualExclude : Longint; { MenuItem MutualExclude word }
  113. nm_UserData : Pointer; { For your own use, see note }
  114. END;
  115. const
  116. { Needed only by inside IM_ definitions below }
  117. MENU_IMAGE = 128;
  118. { nm_Type determines what each NewMenu structure corresponds to.
  119. * for the NM_TITLE, NM_ITEM, and NM_SUB values, nm_Label should
  120. * be a text string to use for that menu title, item, or sub-item.
  121. * For IM_ITEM or IM_SUB, set nm_Label to point at the Image structure
  122. * you wish to use for this item or sub-item.
  123. * NOTE: At present, you may only use conventional images.
  124. * Custom images created from Intuition image-classes do not work.
  125. }
  126. NM_TITLE = 1; { Menu header }
  127. NM_ITEM = 2; { Textual menu item }
  128. NM_SUB = 3; { Textual menu sub-item }
  129. IM_ITEM = (NM_ITEM OR MENU_IMAGE); { Graphical menu item }
  130. IM_SUB = (NM_SUB OR MENU_IMAGE); { Graphical menu sub-item }
  131. { The NewMenu array should be terminated with a NewMenu whose
  132. * nm_Type equals NM_END.
  133. }
  134. NM_END = 0; { End of NewMenu array }
  135. { Starting with V39, GadTools will skip any NewMenu entries whose
  136. * nm_Type field has the NM_IGNORE bit set.
  137. }
  138. NM_IGNORE = 64;
  139. { nm_Label should be a text string for textual items, a pointer
  140. * to an Image structure for graphical menu items, or the special
  141. * constant NM_BARLABEL, to get a separator bar.
  142. }
  143. NM_BARLABEL = -1;
  144. { The nm_Flags field is used to fill out either the Menu->Flags or
  145. * MenuItem->Flags field. Note that the sense of the MENUENABLED or
  146. * ITEMENABLED bit is inverted between this use and Intuition's use,
  147. * in other words, NewMenus are enabled by default. The following
  148. * labels are provided to disable them:
  149. }
  150. NM_MENUDISABLED = MENUENABLED;
  151. NM_ITEMDISABLED = ITEMENABLED;
  152. { New for V39: NM_COMMANDSTRING. For a textual MenuItem or SubItem,
  153. * point nm_CommKey at an arbitrary string, and set the NM_COMMANDSTRING
  154. * flag.
  155. }
  156. NM_COMMANDSTRING = COMMSEQ;
  157. { The following are pre-cleared (COMMSEQ, ITEMTEXT, and HIGHxxx are set
  158. * later as appropriate):
  159. * Under V39, the COMMSEQ flag bit is not cleared, since it now has
  160. * meaning.
  161. }
  162. NM_FLAGMASK = NOT (COMMSEQ OR ITEMTEXT OR HIGHFLAGS);
  163. NM_FLAGMASK_V39 = NOT (ITEMTEXT OR HIGHFLAGS);
  164. { You may choose among CHECKIT, MENUTOGGLE, and CHECKED.
  165. * Toggle-select menuitems are of type CHECKIT|MENUTOGGLE, along
  166. * with CHECKED if currently selected. Mutually exclusive ones
  167. * are of type CHECKIT, and possibly CHECKED too. The nm_MutualExclude
  168. * is a bit-wise representation of the items excluded by this one,
  169. * so in the simplest case (choose 1 among n), these flags would be
  170. * ~1, ~2, ~4, ~8, ~16, etc. See the Intuition Menus chapter.
  171. }
  172. { A UserData pointer can be associated with each Menu and MenuItem structure.
  173. * The CreateMenus() call allocates space for a UserData after each
  174. * Menu or MenuItem (header, item or sub-item). You should use the
  175. * GTMENU_USERDATA() or GTMENUITEM_USERDATA() macro to extract it.
  176. }
  177. const
  178. { These return codes can be obtained through the GTMN_SecondaryError tag }
  179. GTMENU_TRIMMED = $00000001; { Too many menus, items, or subitems,
  180. * menu has been trimmed down
  181. }
  182. GTMENU_INVALID = $00000002; { Invalid NewMenu array }
  183. GTMENU_NOMEM = $00000003; { Out of memory }
  184. {------------------------------------------------------------------------}
  185. { Starting with V39, checkboxes and mx gadgets can be scaled to your
  186. * specified gadget width/height. Use the new GTCB_Scaled or GTMX_Scaled
  187. * tags, respectively. Under V37, and by default in V39, the imagery
  188. * is of the following fixed size:
  189. }
  190. { MX gadget default dimensions: }
  191. MX_WIDTH = 17;
  192. MX_HEIGHT = 9;
  193. { Checkbox default dimensions: }
  194. CHECKBOX_WIDTH = 26;
  195. CHECKBOX_HEIGHT = 11;
  196. {------------------------------------------------------------------------}
  197. {------------------------------------------------------------------------}
  198. { Tags for GadTools functions: }
  199. CONST
  200. GT_TagBase = TAG_USER + $80000;
  201. GTVI_NewWindow = GT_TagBase+1; { Unused }
  202. GTVI_NWTags = GT_TagBase+2; { Unused }
  203. GT_Private0 = GT_TagBase+3; { (private) }
  204. GTCB_Checked = GT_TagBase+4; { State of checkbox }
  205. GTLV_Top = GT_TagBase+5; { Top visible one in listview }
  206. GTLV_Labels = GT_TagBase+6; { List to display in listview }
  207. GTLV_ReadOnly = GT_TagBase+7; { TRUE IF listview is to be
  208. read-only }
  209. GTLV_ScrollWidth = GT_TagBase+8; { Width of scrollbar }
  210. GTMX_Labels = GT_TagBase+9; { NULL-terminated array of labels }
  211. GTMX_Active = GT_TagBase+10; { Active one in mx gadget }
  212. GTTX_Text = GT_TagBase+11; { Text to display }
  213. GTTX_CopyText = GT_TagBase+12; { Copy text label instead of
  214. referencing it }
  215. GTNM_Number = GT_TagBase+13; { Number to display }
  216. GTCY_Labels = GT_TagBase+14; { NULL-terminated array of labels }
  217. GTCY_Active = GT_TagBase+15; { The active one in the cycle gad }
  218. GTPA_Depth = GT_TagBase+16; { Number of bitplanes in palette }
  219. GTPA_Color = GT_TagBase+17; { Palette color }
  220. GTPA_ColorOffset = GT_TagBase+18; { First color to use in palette }
  221. GTPA_IndicatorWidth = GT_TagBase+19; { Width of current-color indicator }
  222. GTPA_IndicatorHeight = GT_TagBase+20; { Height of current-color indicator }
  223. GTSC_Top = GT_TagBase+21; { Top visible in scroller }
  224. GTSC_Total = GT_TagBase+22; { Total in scroller area }
  225. GTSC_Visible = GT_TagBase+23; { Number visible in scroller }
  226. GTSC_Overlap = GT_TagBase+24; { Unused }
  227. { GT_TagBase+25 through GT_TagBase+37 are reserved }
  228. GTSL_Min = GT_TagBase+38; { Slider min value }
  229. GTSL_Max = GT_TagBase+39; { Slider max value }
  230. GTSL_Level = GT_TagBase+40; { Slider level }
  231. GTSL_MaxLevelLen = GT_TagBase+41; { Max length of printed level }
  232. GTSL_LevelFormat = GT_TagBase+42; { Format string for level }
  233. GTSL_LevelPlace = GT_TagBase+43; { Where level should be placed }
  234. GTSL_DispFunc = GT_TagBase+44; { Callback for number calculation
  235. before display }
  236. GTST_String = GT_TagBase+45; { String gadget's displayed string }
  237. GTST_MaxChars = GT_TagBase+46; { Max length of string }
  238. GTIN_Number = GT_TagBase+47; { Number in integer gadget }
  239. GTIN_MaxChars = GT_TagBase+48; { Max number of digits }
  240. GTMN_TextAttr = GT_TagBase+49; { MenuItem font TextAttr }
  241. GTMN_FrontPen = GT_TagBase+50; { MenuItem text pen color }
  242. GTBB_Recessed = GT_TagBase+51; { Make BevelBox recessed }
  243. GT_VisualInfo = GT_TagBase+52; { result of VisualInfo call }
  244. GTLV_ShowSelected = GT_TagBase+53; { show selected entry beneath
  245. listview, set tag data = NULL for display-only, or pointer
  246. to a string gadget you've created }
  247. GTLV_Selected = GT_TagBase+54; { Set ordinal number of selected
  248. entry in the list }
  249. GT_Reserved0 = GT_TagBase+55; { Reserved }
  250. GT_Reserved1 = GT_TagBase+56; { Reserved for future use }
  251. GTTX_Border = GT_TagBase+57; { Put a border around
  252. Text-display gadgets }
  253. GTNM_Border = GT_TagBase+58; { Put a border around
  254. Number-display gadgets }
  255. GTSC_Arrows = GT_TagBase+59; { Specify size of arrows for
  256. scroller }
  257. GTMN_Menu = GT_TagBase+60; { Pointer to Menu for use by
  258. LayoutMenuItems() }
  259. GTMX_Spacing = GT_TagBase+61; { Added to font height to
  260. figure spacing between mx choices. Use this instead
  261. of LAYOUTA_SPACING for mx gadgets. }
  262. { New to V37 GadTools. Ignored by GadTools V36 }
  263. GTMN_FullMenu = GT_TagBase+62; { Asks CreateMenus() to
  264. validate that this is a complete menu structure }
  265. GTMN_SecondaryError = GT_TagBase+63; { ti_Data is a pointer
  266. to a ULONG to receive error reports from CreateMenus() }
  267. GT_Underscore = GT_TagBase+64; { ti_Data points to the symbol
  268. that preceeds the character you'd like to underline in a
  269. gadget label }
  270. { New to V39 GadTools. Ignored by GadTools V36 and V37 }
  271. GTMN_Checkmark = GT_TagBase+65; { ti_Data is checkmark img to use }
  272. GTMN_AmigaKey = GT_TagBase+66; { ti_Data is Amiga-key img to use }
  273. GTMN_NewLookMenus = GT_TagBase+67; { ti_Data is boolean }
  274. { New to V39 GadTools. Ignored by GadTools V36 and V37.
  275. * Set to TRUE if you want the checkbox or mx image scaled to
  276. * the gadget width/height you specify. Defaults to FALSE,
  277. * for compatibility.
  278. }
  279. GTCB_Scaled = GT_TagBase+68; { ti_Data is boolean }
  280. GTMX_Scaled = GT_TagBase+69; { ti_Data is boolean }
  281. GTPA_NumColors = GT_TagBase+70; { Number of colors in palette }
  282. GTMX_TitlePlace = GT_TagBase+71; { Where to put the title }
  283. GTTX_FrontPen = GT_TagBase+72; { Text color in TEXT_KIND gad }
  284. GTTX_BackPen = GT_TagBase+73; { Bgrnd color in TEXT_KIND gad }
  285. GTTX_Justification = GT_TagBase+74; { See GTJ_#? constants }
  286. GTNM_FrontPen = GT_TagBase+72; { Text color in NUMBER_KIND gad }
  287. GTNM_BackPen = GT_TagBase+73; { Bgrnd color in NUMBER_KIND gad }
  288. GTNM_Justification = GT_TagBase+74; { See GTJ_#? constants }
  289. GTNM_Format = GT_TagBase+75; { Formatting string for number }
  290. GTNM_MaxNumberLen = GT_TagBase+76; { Maximum length of number }
  291. GTBB_FrameType = GT_TagBase+77; { defines what kind of boxes
  292. * DrawBevelBox() renders. See
  293. * the BBFT_#? constants for
  294. * possible values
  295. }
  296. GTLV_MakeVisible = GT_TagBase+78; { Make this item visible }
  297. GTLV_ItemHeight = GT_TagBase+79; { Height of an individual item }
  298. GTSL_MaxPixelLen = GT_TagBase+80; { Max pixel size of level display }
  299. GTSL_Justification = GT_TagBase+81; { how should the level be displayed }
  300. GTPA_ColorTable = GT_TagBase+82; { colors to use in palette }
  301. GTLV_CallBack = GT_TagBase+83; { general-purpose listview call back }
  302. GTLV_MaxPen = GT_TagBase+84; { maximum pen number used by call back }
  303. GTTX_Clipped = GT_TagBase+85; { make a TEXT_KIND clip text }
  304. GTNM_Clipped = GT_TagBase+85; { make a NUMBER_KIND clip text }
  305. {------------------------------------------------------------------------}
  306. { Justification types for GTTX_Justification and GTNM_Justification tags }
  307. GTJ_LEFT = 0;
  308. GTJ_RIGHT = 1;
  309. GTJ_CENTER = 2;
  310. {------------------------------------------------------------------------}
  311. { Bevel box frame types for GTBB_FrameType tag }
  312. BBFT_BUTTON = 1; { Standard button gadget box }
  313. BBFT_RIDGE = 2; { Standard string gadget box }
  314. BBFT_ICONDROPBOX = 3; { Standard icon drop box }
  315. {------------------------------------------------------------------------}
  316. { Typical suggested spacing between "elements": }
  317. INTERWIDTH = 8;
  318. INTERHEIGHT = 4;
  319. {------------------------------------------------------------------------}
  320. { "NWay" is an old synonym for cycle gadgets }
  321. NWAY_KIND = CYCLE_KIND;
  322. NWAYIDCMP = CYCLEIDCMP;
  323. GTNW_Labels = GTCY_Labels;
  324. GTNW_Active = GTCY_Active;
  325. {------------------------------------------------------------------------}
  326. { These two definitions are obsolete, but are here for backwards
  327. * compatibility. You never need to worry about these:
  328. }
  329. GADTOOLBIT = ($8000);
  330. { Use this mask to isolate the user part: }
  331. GADTOOLMASK = NOT (GADTOOLBIT);
  332. {------------------------------------------------------------------------}
  333. { These definitions are for the GTLV_CallBack tag }
  334. { The different types of messages that a listview callback hook can see }
  335. LV_DRAW = $202; { draw yourself, with state }
  336. { Possible return values from a callback hook }
  337. LVCB_OK = 0; { callback understands this message type }
  338. LVCB_UNKNOWN = 1; { callback does not understand this message }
  339. { states for LVDrawMsg.lvdm_State }
  340. LVR_NORMAL = 0; { the usual }
  341. LVR_SELECTED = 1; { for selected gadgets }
  342. LVR_NORMALDISABLED = 2; { for disabled gadgets }
  343. LVR_SELECTEDDISABLED = 8; { disabled and selected }
  344. Type
  345. { structure of LV_DRAW messages, object is a (struct Node *) }
  346. pLVDrawMsg = ^tLVDrawMsg;
  347. tLVDrawMsg = record
  348. lvdm_MethodID : ULONG; { LV_DRAW }
  349. lvdm_RastPort : pRastPort; { where to render to }
  350. lvdm_DrawInfo : pDrawInfo; { useful to have around }
  351. lvdm_Bounds : tRectangle; { limits of where to render }
  352. lvdm_State : ULONG; { how to render }
  353. end;
  354. VAR
  355. GadToolsBase : pLibrary;
  356. FUNCTION CreateContext(glistptr : pGadget): pGadget;
  357. FUNCTION CreateGadgetA(kind : ULONG; gad : pGadget;const ng : pNewGadget;const taglist : pTagItem) : pGadget;
  358. FUNCTION CreateMenusA(const newmenu : pNewMenu;const taglist : pTagItem) : pMenu;
  359. PROCEDURE DrawBevelBoxA(rport : pRastPort; left : LONGINT; top : LONGINT; width : LONGINT; height : LONGINT;const taglist : pTagItem);
  360. PROCEDURE FreeGadgets(gad : pGadget);
  361. PROCEDURE FreeMenus(menu : pMenu);
  362. PROCEDURE FreeVisualInfo(vi : POINTER);
  363. FUNCTION GetVisualInfoA(screen : pScreen;const taglist : pTagItem) : POINTER;
  364. PROCEDURE GT_BeginRefresh(win : pWindow);
  365. PROCEDURE GT_EndRefresh(win : pWindow; complete : LONGINT);
  366. FUNCTION GT_FilterIMsg(const imsg : pIntuiMessage) : pIntuiMessage;
  367. FUNCTION GT_GetGadgetAttrsA(gad : pGadget; win : pWindow; req : pRequester;const taglist : pTagItem) : LONGINT;
  368. FUNCTION GT_GetIMsg(iport : pMsgPort) : pIntuiMessage;
  369. FUNCTION GT_PostFilterIMsg(imsg : pIntuiMessage) : pIntuiMessage;
  370. PROCEDURE GT_RefreshWindow(win : pWindow; req : pRequester);
  371. PROCEDURE GT_ReplyIMsg(imsg : pIntuiMessage);
  372. PROCEDURE GT_SetGadgetAttrsA(gad : pGadget; win : pWindow; req : pRequester;const taglist : pTagItem);
  373. FUNCTION LayoutMenuItemsA(firstitem : pMenuItem; vi : POINTER;const taglist : pTagItem) : BOOLEAN;
  374. FUNCTION LayoutMenusA(firstmenu : pMenu; vi : POINTER;const taglist : pTagItem) : BOOLEAN;
  375. function GTMENUITEM_USERDATA(menuitem : pMenuItem): pointer;
  376. function GTMENU_USERDATA(menu : pMenu): pointer;
  377. {Here we read how to compile this unit}
  378. {You can remove this include and use a define instead}
  379. {$I useautoopenlib.inc}
  380. {$ifdef use_init_openlib}
  381. procedure InitGADTOOLSLibrary;
  382. {$endif use_init_openlib}
  383. {This is a variable that knows how the unit is compiled}
  384. var
  385. GADTOOLSIsCompiledHow : longint;
  386. IMPLEMENTATION
  387. uses
  388. {$ifndef dont_use_openlib}
  389. msgbox;
  390. {$endif dont_use_openlib}
  391. function GTMENUITEM_USERDATA(menuitem : pMenuItem): pointer;
  392. begin
  393. GTMENUITEM_USERDATA := pointer((pMenuItem(menuitem)+1));
  394. end;
  395. function GTMENU_USERDATA(menu : pMenu): pointer;
  396. begin
  397. GTMENU_USERDATA := pointer((pMenu(menu)+1));
  398. end;
  399. FUNCTION CreateContext(glistptr : pGadget): pGadget;
  400. BEGIN
  401. ASM
  402. MOVE.L A6,-(A7)
  403. MOVEA.L glistptr,A0
  404. MOVEA.L GadToolsBase,A6
  405. JSR -114(A6)
  406. MOVEA.L (A7)+,A6
  407. MOVE.L D0,@RESULT
  408. END;
  409. END;
  410. FUNCTION CreateGadgetA(kind : ULONG; gad : pGadget;const ng : pNewGadget;const taglist : pTagItem) : pGadget;
  411. BEGIN
  412. ASM
  413. MOVE.L A6,-(A7)
  414. MOVE.L kind,D0
  415. MOVEA.L gad,A0
  416. MOVEA.L ng,A1
  417. MOVEA.L taglist,A2
  418. MOVEA.L GadToolsBase,A6
  419. JSR -030(A6)
  420. MOVEA.L (A7)+,A6
  421. MOVE.L D0,@RESULT
  422. END;
  423. END;
  424. FUNCTION CreateMenusA(const newmenu : pNewMenu;const taglist : pTagItem) : pMenu;
  425. BEGIN
  426. ASM
  427. MOVE.L A6,-(A7)
  428. MOVEA.L newmenu,A0
  429. MOVEA.L taglist,A1
  430. MOVEA.L GadToolsBase,A6
  431. JSR -048(A6)
  432. MOVEA.L (A7)+,A6
  433. MOVE.L D0,@RESULT
  434. END;
  435. END;
  436. PROCEDURE DrawBevelBoxA(rport : pRastPort; left : LONGINT; top : LONGINT; width : LONGINT; height : LONGINT;const taglist : pTagItem);
  437. BEGIN
  438. ASM
  439. MOVE.L A6,-(A7)
  440. MOVEA.L rport,A0
  441. MOVE.L left,D0
  442. MOVE.L top,D1
  443. MOVE.L width,D2
  444. MOVE.L height,D3
  445. MOVEA.L taglist,A1
  446. MOVEA.L GadToolsBase,A6
  447. JSR -120(A6)
  448. MOVEA.L (A7)+,A6
  449. END;
  450. END;
  451. PROCEDURE FreeGadgets(gad : pGadget);
  452. BEGIN
  453. ASM
  454. MOVE.L A6,-(A7)
  455. MOVEA.L gad,A0
  456. MOVEA.L GadToolsBase,A6
  457. JSR -036(A6)
  458. MOVEA.L (A7)+,A6
  459. END;
  460. END;
  461. PROCEDURE FreeMenus(menu : pMenu);
  462. BEGIN
  463. ASM
  464. MOVE.L A6,-(A7)
  465. MOVEA.L menu,A0
  466. MOVEA.L GadToolsBase,A6
  467. JSR -054(A6)
  468. MOVEA.L (A7)+,A6
  469. END;
  470. END;
  471. PROCEDURE FreeVisualInfo(vi : POINTER);
  472. BEGIN
  473. ASM
  474. MOVE.L A6,-(A7)
  475. MOVEA.L vi,A0
  476. MOVEA.L GadToolsBase,A6
  477. JSR -132(A6)
  478. MOVEA.L (A7)+,A6
  479. END;
  480. END;
  481. FUNCTION GetVisualInfoA(screen : pScreen;const taglist : pTagItem) : POINTER;
  482. BEGIN
  483. ASM
  484. MOVE.L A6,-(A7)
  485. MOVEA.L screen,A0
  486. MOVEA.L taglist,A1
  487. MOVEA.L GadToolsBase,A6
  488. JSR -126(A6)
  489. MOVEA.L (A7)+,A6
  490. MOVE.L D0,@RESULT
  491. END;
  492. END;
  493. PROCEDURE GT_BeginRefresh(win : pWindow);
  494. BEGIN
  495. ASM
  496. MOVE.L A6,-(A7)
  497. MOVEA.L win,A0
  498. MOVEA.L GadToolsBase,A6
  499. JSR -090(A6)
  500. MOVEA.L (A7)+,A6
  501. END;
  502. END;
  503. PROCEDURE GT_EndRefresh(win : pWindow; complete : LONGINT);
  504. BEGIN
  505. ASM
  506. MOVE.L A6,-(A7)
  507. MOVEA.L win,A0
  508. MOVE.L complete,D0
  509. MOVEA.L GadToolsBase,A6
  510. JSR -096(A6)
  511. MOVEA.L (A7)+,A6
  512. END;
  513. END;
  514. FUNCTION GT_FilterIMsg(const imsg : pIntuiMessage) : pIntuiMessage;
  515. BEGIN
  516. ASM
  517. MOVE.L A6,-(A7)
  518. MOVEA.L imsg,A1
  519. MOVEA.L GadToolsBase,A6
  520. JSR -102(A6)
  521. MOVEA.L (A7)+,A6
  522. MOVE.L D0,@RESULT
  523. END;
  524. END;
  525. FUNCTION GT_GetGadgetAttrsA(gad : pGadget; win : pWindow; req : pRequester;const taglist : pTagItem) : LONGINT;
  526. BEGIN
  527. ASM
  528. MOVE.L A6,-(A7)
  529. MOVEA.L gad,A0
  530. MOVEA.L win,A1
  531. MOVEA.L req,A2
  532. MOVEA.L taglist,A3
  533. MOVEA.L GadToolsBase,A6
  534. JSR -174(A6)
  535. MOVEA.L (A7)+,A6
  536. MOVE.L D0,@RESULT
  537. END;
  538. END;
  539. FUNCTION GT_GetIMsg(iport : pMsgPort) : pIntuiMessage;
  540. BEGIN
  541. ASM
  542. MOVE.L A6,-(A7)
  543. MOVEA.L iport,A0
  544. MOVEA.L GadToolsBase,A6
  545. JSR -072(A6)
  546. MOVEA.L (A7)+,A6
  547. MOVE.L D0,@RESULT
  548. END;
  549. END;
  550. FUNCTION GT_PostFilterIMsg(imsg : pIntuiMessage) : pIntuiMessage;
  551. BEGIN
  552. ASM
  553. MOVE.L A6,-(A7)
  554. MOVEA.L imsg,A1
  555. MOVEA.L GadToolsBase,A6
  556. JSR -108(A6)
  557. MOVEA.L (A7)+,A6
  558. MOVE.L D0,@RESULT
  559. END;
  560. END;
  561. PROCEDURE GT_RefreshWindow(win : pWindow; req : pRequester);
  562. BEGIN
  563. ASM
  564. MOVE.L A6,-(A7)
  565. MOVEA.L win,A0
  566. MOVEA.L req,A1
  567. MOVEA.L GadToolsBase,A6
  568. JSR -084(A6)
  569. MOVEA.L (A7)+,A6
  570. END;
  571. END;
  572. PROCEDURE GT_ReplyIMsg(imsg : pIntuiMessage);
  573. BEGIN
  574. ASM
  575. MOVE.L A6,-(A7)
  576. MOVEA.L imsg,A1
  577. MOVEA.L GadToolsBase,A6
  578. JSR -078(A6)
  579. MOVEA.L (A7)+,A6
  580. END;
  581. END;
  582. PROCEDURE GT_SetGadgetAttrsA(gad : pGadget; win : pWindow; req : pRequester;const taglist : pTagItem);
  583. BEGIN
  584. ASM
  585. MOVE.L A6,-(A7)
  586. MOVEA.L gad,A0
  587. MOVEA.L win,A1
  588. MOVEA.L req,A2
  589. MOVEA.L taglist,A3
  590. MOVEA.L GadToolsBase,A6
  591. JSR -042(A6)
  592. MOVEA.L (A7)+,A6
  593. END;
  594. END;
  595. FUNCTION LayoutMenuItemsA(firstitem : pMenuItem; vi : POINTER;const taglist : pTagItem) : BOOLEAN;
  596. BEGIN
  597. ASM
  598. MOVE.L A6,-(A7)
  599. MOVEA.L firstitem,A0
  600. MOVEA.L vi,A1
  601. MOVEA.L taglist,A2
  602. MOVEA.L GadToolsBase,A6
  603. JSR -060(A6)
  604. MOVEA.L (A7)+,A6
  605. TST.W D0
  606. BEQ.B @end
  607. MOVEQ #1,D0
  608. @end: MOVE.B D0,@RESULT
  609. END;
  610. END;
  611. FUNCTION LayoutMenusA(firstmenu : pMenu; vi : POINTER;const taglist : pTagItem) : BOOLEAN;
  612. BEGIN
  613. ASM
  614. MOVE.L A6,-(A7)
  615. MOVEA.L firstmenu,A0
  616. MOVEA.L vi,A1
  617. MOVEA.L taglist,A2
  618. MOVEA.L GadToolsBase,A6
  619. JSR -066(A6)
  620. MOVEA.L (A7)+,A6
  621. TST.W D0
  622. BEQ.B @end
  623. MOVEQ #1,D0
  624. @end: MOVE.B D0,@RESULT
  625. END;
  626. END;
  627. const
  628. { Change VERSION and LIBVERSION to proper values }
  629. VERSION : string[2] = '0';
  630. LIBVERSION : longword = 0;
  631. {$ifdef use_init_openlib}
  632. {$Info Compiling initopening of gadtools.library}
  633. {$Info don't forget to use InitGADTOOLSLibrary in the beginning of your program}
  634. var
  635. gadtools_exit : Pointer;
  636. procedure ClosegadtoolsLibrary;
  637. begin
  638. ExitProc := gadtools_exit;
  639. if GadToolsBase <> nil then begin
  640. CloseLibrary(GadToolsBase);
  641. GadToolsBase := nil;
  642. end;
  643. end;
  644. procedure InitGADTOOLSLibrary;
  645. begin
  646. GadToolsBase := nil;
  647. GadToolsBase := OpenLibrary(GADTOOLSNAME,LIBVERSION);
  648. if GadToolsBase <> nil then begin
  649. gadtools_exit := ExitProc;
  650. ExitProc := @ClosegadtoolsLibrary;
  651. end else begin
  652. MessageBox('FPC Pascal Error',
  653. 'Can''t open gadtools.library version ' + VERSION + #10 +
  654. 'Deallocating resources and closing down',
  655. 'Oops');
  656. halt(20);
  657. end;
  658. end;
  659. begin
  660. GADTOOLSIsCompiledHow := 2;
  661. {$endif use_init_openlib}
  662. {$ifdef use_auto_openlib}
  663. {$Info Compiling autoopening of gadtools.library}
  664. var
  665. gadtools_exit : Pointer;
  666. procedure ClosegadtoolsLibrary;
  667. begin
  668. ExitProc := gadtools_exit;
  669. if GadToolsBase <> nil then begin
  670. CloseLibrary(GadToolsBase);
  671. GadToolsBase := nil;
  672. end;
  673. end;
  674. begin
  675. GadToolsBase := nil;
  676. GadToolsBase := OpenLibrary(GADTOOLSNAME,LIBVERSION);
  677. if GadToolsBase <> nil then begin
  678. gadtools_exit := ExitProc;
  679. ExitProc := @ClosegadtoolsLibrary;
  680. GADTOOLSIsCompiledHow := 1;
  681. end else begin
  682. MessageBox('FPC Pascal Error',
  683. 'Can''t open gadtools.library version ' + VERSION + #10 +
  684. 'Deallocating resources and closing down',
  685. 'Oops');
  686. halt(20);
  687. end;
  688. {$endif use_auto_openlib}
  689. {$ifdef dont_use_openlib}
  690. begin
  691. GADTOOLSIsCompiledHow := 3;
  692. {$Warning No autoopening of gadtools.library compiled}
  693. {$Warning Make sure you open gadtools.library yourself}
  694. {$endif dont_use_openlib}
  695. END. (* UNIT GADTOOLS *)