menus.pas 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  1. { $Id$ }
  2. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  3. { }
  4. { System independent GRAPHICAL clone of MENUS.PAS }
  5. { }
  6. { Interface Copyright (c) 1992 Borland International }
  7. { }
  8. { Copyright (c) 1996, 1997, 1998, 1999 by Leon de Boer }
  9. { [email protected] - primary e-mail addr }
  10. { [email protected] - backup e-mail addr }
  11. { }
  12. {****************[ THIS CODE IS FREEWARE ]*****************}
  13. { }
  14. { This sourcecode is released for the purpose to }
  15. { promote the pascal language on all platforms. You may }
  16. { redistribute it and/or modify with the following }
  17. { DISCLAIMER. }
  18. { }
  19. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  20. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  21. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  22. { }
  23. {*****************[ SUPPORTED PLATFORMS ]******************}
  24. { 16 and 32 Bit compilers }
  25. { DOS - Turbo Pascal 7.0 + (16 Bit) }
  26. { DPMI - Turbo Pascal 7.0 + (16 Bit) }
  27. { - FPC 0.9912+ (GO32V2) (32 Bit) }
  28. { WINDOWS - Turbo Pascal 7.0 + (16 Bit) }
  29. { - Delphi 1.0+ (16 Bit) }
  30. { WIN95/NT - Delphi 2.0+ (32 Bit) }
  31. { - Virtual Pascal 2.0+ (32 Bit) }
  32. { - Speedsoft Sybil 2.0+ (32 Bit) }
  33. { - FPC 0.9912+ (32 Bit) }
  34. { OS2 - Virtual Pascal 1.0+ (32 Bit) }
  35. { - Speed pascal 1.0+ (32 Bit) }
  36. { }
  37. {******************[ REVISION HISTORY ]********************}
  38. { Version Date Fix }
  39. { ------- --------- --------------------------------- }
  40. { 1.00 12 Jun 96 Initial DOS/DPMI code released. }
  41. { 1.10 18 Oct 97 Code converted to GUI & TEXT mode. }
  42. { 1.20 18 Jul 97 Windows conversion added. }
  43. { 1.30 29 Aug 97 Platform.inc sort added. }
  44. { 1.40 22 Oct 97 Delphi3 32 bit code added. }
  45. { 1.50 05 May 98 Virtual pascal 2.0 code added. }
  46. { 1.60 11 May 98 Clean up and ensure error checks. }
  47. { 1.70 15 May 98 Documentation & format completed. }
  48. { 1.80 30 Sep 99 Complete recheck preformed }
  49. { 1.81 03 Nov 99 FPC windows support added }
  50. { 1.90 26 Nov 99 Graphics stuff moved to GFVGraph }
  51. {**********************************************************}
  52. UNIT Menus;
  53. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  54. INTERFACE
  55. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  56. {====Include file to sort compiler platform out =====================}
  57. {$I Platform.inc}
  58. {====================================================================}
  59. {==== Compiler directives ===========================================}
  60. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  61. {$F-} { Near calls are okay }
  62. {$A+} { Word Align Data }
  63. {$B-} { Allow short circuit boolean evaluations }
  64. {$O+} { This unit may be overlaid }
  65. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  66. {$P-} { Normal string variables }
  67. {$N-} { No 80x87 code generation }
  68. {$E+} { Emulation is on }
  69. {$ENDIF}
  70. {$X+} { Extended syntax is ok }
  71. {$R-} { Disable range checking }
  72. {$S-} { Disable Stack Checking }
  73. {$I-} { Disable IO Checking }
  74. {$Q-} { Disable Overflow Checking }
  75. {$V-} { Turn off strict VAR strings }
  76. {====================================================================}
  77. USES
  78. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  79. {$IFNDEF PPC_SPEED} { NON SPEED COMPILER }
  80. {$IFDEF PPC_FPC} { FPC WINDOWS COMPILER }
  81. Windows, { Standard unit }
  82. {$ELSE} { OTHER COMPILERS }
  83. WinTypes,WinProcs, { Standard units }
  84. {$ENDIF}
  85. {$ELSE} { SPEEDSOFT COMPILER }
  86. WinBase, WinDef, { Standard units }
  87. {$ENDIF}
  88. {$ENDIF}
  89. GFVGraph, { GFV standard unit }
  90. Objects, Drivers, Views; { GFV standard units }
  91. {***************************************************************************}
  92. { PUBLIC CONSTANTS }
  93. {***************************************************************************}
  94. {---------------------------------------------------------------------------}
  95. { COLOUR PALETTES }
  96. {---------------------------------------------------------------------------}
  97. CONST
  98. CMenuView = #2#3#4#5#6#7; { Menu colours }
  99. CStatusLine = #2#3#4#5#6#7; { Statusline colours }
  100. {***************************************************************************}
  101. { RECORD DEFINITIONS }
  102. {***************************************************************************}
  103. TYPE
  104. TMenuStr = String[31]; { Menu string }
  105. PMenu = ^TMenu; { Pointer to menu }
  106. {---------------------------------------------------------------------------}
  107. { TMenuItem RECORD }
  108. {---------------------------------------------------------------------------}
  109. PMenuItem = ^TMenuItem;
  110. TMenuItem = PACKED RECORD
  111. Next: PMenuItem; { Next menu item }
  112. Name: PString; { Menu item name }
  113. Command: Word; { Menu item command }
  114. Disabled: Boolean; { Menu item state }
  115. KeyCode: Word; { Menu item keycode }
  116. HelpCtx: Word; { Menu item help ctx }
  117. Case Integer Of
  118. 0: (Param: PString);
  119. 1: (SubMenu: PMenu);
  120. END;
  121. {---------------------------------------------------------------------------}
  122. { TMenu RECORD }
  123. {---------------------------------------------------------------------------}
  124. TMenu = PACKED RECORD
  125. Items: PMenuItem; { Menu item list }
  126. Default: PMenuItem; { Default menu }
  127. END;
  128. {---------------------------------------------------------------------------}
  129. { TStatusItem RECORD }
  130. {---------------------------------------------------------------------------}
  131. TYPE
  132. PStatusItem = ^TStatusItem;
  133. TStatusItem = PACKED RECORD
  134. Next: PStatusItem; { Next status item }
  135. Text: PString; { Text of status item }
  136. KeyCode: Word; { Keycode of item }
  137. Command: Word; { Command of item }
  138. END;
  139. {---------------------------------------------------------------------------}
  140. { TStatusDef RECORD }
  141. {---------------------------------------------------------------------------}
  142. TYPE
  143. PStatusDef = ^TStatusDef;
  144. TStatusDef = PACKED RECORD
  145. Next: PStatusDef; { Next status defined }
  146. Min, Max: Word; { Range of item }
  147. Items: PStatusItem; { Item list }
  148. END;
  149. {***************************************************************************}
  150. { OBJECT DEFINITIONS }
  151. {***************************************************************************}
  152. {---------------------------------------------------------------------------}
  153. { TMenuView OBJECT - MENU VIEW ANCESTOR OBJECT }
  154. {---------------------------------------------------------------------------}
  155. TYPE
  156. PMenuView = ^TMenuView;
  157. TMenuView = OBJECT (TView)
  158. ParentMenu: PMenuView; { Parent menu }
  159. Menu : PMenu; { Menu item list }
  160. Current : PMenuItem; { Current menu item }
  161. OldItem : PMenuItem; { Old item for draws }
  162. CONSTRUCTOR Init (Var Bounds: TRect);
  163. CONSTRUCTOR Load (Var S: TStream);
  164. FUNCTION Execute: Word; Virtual;
  165. FUNCTION GetHelpCtx: Word; Virtual;
  166. FUNCTION GetPalette: PPalette; Virtual;
  167. FUNCTION FindItem (Ch: Char): PMenuItem;
  168. FUNCTION HotKey (KeyCode: Word): PMenuItem;
  169. FUNCTION NewSubView (Var Bounds: TRect; AMenu: PMenu;
  170. AParentMenu: PMenuView): PMenuView; Virtual;
  171. PROCEDURE Store (Var S: TStream);
  172. PROCEDURE HandleEvent (Var Event: TEvent); Virtual;
  173. PROCEDURE GetItemRect (Item: PMenuItem; Var R: TRect); Virtual;
  174. END;
  175. {---------------------------------------------------------------------------}
  176. { TMenuBar OBJECT - MENU BAR OBJECT }
  177. {---------------------------------------------------------------------------}
  178. TYPE
  179. TMenuBar = OBJECT (TMenuView)
  180. CONSTRUCTOR Init (Var Bounds: TRect; AMenu: PMenu);
  181. DESTRUCTOR Done; Virtual;
  182. PROCEDURE Draw; Virtual;
  183. PROCEDURE DrawBackGround; Virtual;
  184. PROCEDURE GetItemRect (Item: PMenuItem; Var R: TRect); Virtual;
  185. END;
  186. PMenuBar = ^TMenuBar;
  187. {---------------------------------------------------------------------------}
  188. { TMenuBox OBJECT - BOXED MENU OBJECT }
  189. {---------------------------------------------------------------------------}
  190. TYPE
  191. TMenuBox = OBJECT (TMenuView)
  192. CONSTRUCTOR Init (Var Bounds: TRect; AMenu: PMenu;
  193. AParentMenu: PMenuView);
  194. PROCEDURE Draw; Virtual;
  195. PROCEDURE DrawBackGround; Virtual;
  196. PROCEDURE GetItemRect (Item: PMenuItem; Var R: TRect); Virtual;
  197. END;
  198. PMenuBox = ^TMenuBox;
  199. {---------------------------------------------------------------------------}
  200. { TMenuPopUp OBJECT - POPUP MENU OBJECT }
  201. {---------------------------------------------------------------------------}
  202. TYPE
  203. TMenuPopup = OBJECT (TMenuBox)
  204. CONSTRUCTOR Init (Var Bounds: TRect; AMenu: PMenu);
  205. DESTRUCTOR Done; Virtual;
  206. PROCEDURE HandleEvent (Var Event: TEvent); Virtual;
  207. END;
  208. PMenuPopup = ^TMenuPopup;
  209. {---------------------------------------------------------------------------}
  210. { TStatusLine OBJECT - STATUS LINE OBJECT }
  211. {---------------------------------------------------------------------------}
  212. TYPE
  213. TStatusLine = OBJECT (TView)
  214. Items: PStatusItem; { Status line items }
  215. Defs : PStatusDef; { Status line default }
  216. CONSTRUCTOR Init (Var Bounds: TRect; ADefs: PStatusDef);
  217. CONSTRUCTOR Load (Var S: TStream);
  218. DESTRUCTOR Done; Virtual;
  219. FUNCTION GetPalette: PPalette; Virtual;
  220. FUNCTION Hint (AHelpCtx: Word): String; Virtual;
  221. PROCEDURE Draw; Virtual;
  222. PROCEDURE Update; Virtual;
  223. PROCEDURE Store (Var S: TStream);
  224. PROCEDURE HandleEvent (Var Event: TEvent); Virtual;
  225. PRIVATE
  226. PROCEDURE FindItems;
  227. PROCEDURE DrawSelect (Selected: PStatusItem);
  228. END;
  229. PStatusLine = ^TStatusLine;
  230. {***************************************************************************}
  231. { INTERFACE ROUTINES }
  232. {***************************************************************************}
  233. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  234. { MENU INTERFACE ROUTINES }
  235. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  236. {-NewMenu------------------------------------------------------------
  237. Allocates and returns a pointer to a new TMenu record. Sets the Items
  238. and Default fields of the record to the value given by the parameter.
  239. An error creating will return a nil pointer.
  240. 14May98 LdB
  241. ---------------------------------------------------------------------}
  242. FUNCTION NewMenu (Items: PMenuItem): PMenu;
  243. {-DisposeMenu--------------------------------------------------------
  244. Disposes of all the elements of the specified menu (and all submenus).
  245. 14May98 LdB
  246. ---------------------------------------------------------------------}
  247. PROCEDURE DisposeMenu (Menu: PMenu);
  248. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  249. { MENU ITEM ROUTINES }
  250. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  251. {-NewLine------------------------------------------------------------
  252. Allocates and returns a pointer to a new TMenuItem record that
  253. represents a separator line in a menu box.
  254. An error creating will return a nil pointer.
  255. 14May98 LdB
  256. ---------------------------------------------------------------------}
  257. FUNCTION NewLine (Next: PMenuItem): PMenuItem;
  258. {-NewItem------------------------------------------------------------
  259. Allocates and returns a pointer to a new TMenuItem record that
  260. represents a menu item (using NewStr to allocate the Name and Param).
  261. An error creating will return a nil pointer.
  262. 14May98 LdB
  263. ---------------------------------------------------------------------}
  264. FUNCTION NewItem (Name, Param: TMenuStr; KeyCode: Word; Command: Word;
  265. AHelpCtx: Word; Next: PMenuItem): PMenuItem;
  266. {-NewSubMenu---------------------------------------------------------
  267. Allocates and returns a pointer to a new TMenuItem record, which
  268. represents a submenu (using NewStr to allocate the Name).
  269. An error creating will return a nil pointer.
  270. 14May98 LdB
  271. ---------------------------------------------------------------------}
  272. FUNCTION NewSubMenu (Name: TMenuStr; AHelpCtx: Word; SubMenu: PMenu;
  273. Next: PMenuItem): PMenuItem;
  274. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  275. { STATUS INTERFACE ROUTINES }
  276. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  277. {-NewStatusDef-------------------------------------------------------
  278. Allocates and returns a pointer to a new TStatusDef record initialized
  279. with the given parameter values. Calls to NewStatusDef can be nested.
  280. An error creating will return a nil pointer.
  281. 15May98 LdB
  282. ---------------------------------------------------------------------}
  283. FUNCTION NewStatusDef (AMin, AMax: Word; AItems: PStatusItem;
  284. ANext: PStatusDef): PStatusDef;
  285. {-NewStatusKey-------------------------------------------------------
  286. Allocates and returns a pointer to a new TStatusItem record initialized
  287. with the given parameter values (using NewStr to allocate the Text).
  288. An error in creating will return a nil pointer.
  289. 15May98 LdB
  290. ---------------------------------------------------------------------}
  291. FUNCTION NewStatusKey (AText: String; AKeyCode: Word; ACommand: Word;
  292. ANext: PStatusItem): PStatusItem;
  293. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  294. { OBJECT REGISTER ROUTINES }
  295. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  296. {-RegisterMenus-------------------------------------------------------
  297. Calls RegisterType for each of the object types defined in this unit.
  298. 15May98 LdB
  299. ---------------------------------------------------------------------}
  300. PROCEDURE RegisterMenus;
  301. {***************************************************************************}
  302. { OBJECT REGISTRATION }
  303. {***************************************************************************}
  304. {---------------------------------------------------------------------------}
  305. { TMenuBar STREAM REGISTRATION }
  306. {---------------------------------------------------------------------------}
  307. CONST
  308. RMenuBar: TStreamRec = (
  309. ObjType: 40; { Register id = 40 }
  310. {$IFDEF BP_VMTLink} { BP style VMT link }
  311. VmtLink: Ofs(TypeOf(TMenuBar)^);
  312. {$ELSE} { Alt style VMT link }
  313. VmtLink: TypeOf(TMenuBar);
  314. {$ENDIF}
  315. Load: @TMenuBar.Load; { Object load method }
  316. Store: @TMenuBar.Store { Object store method }
  317. );
  318. {---------------------------------------------------------------------------}
  319. { TMenuBox STREAM REGISTRATION }
  320. {---------------------------------------------------------------------------}
  321. CONST
  322. RMenuBox: TStreamRec = (
  323. ObjType: 41; { Register id = 41 }
  324. {$IFDEF BP_VMTLink} { BP style VMT link }
  325. VmtLink: Ofs(TypeOf(TMenuBox)^);
  326. {$ELSE} { Alt style VMT link }
  327. VmtLink: TypeOf(TMenuBox);
  328. {$ENDIF}
  329. Load: @TMenuBox.Load; { Object load method }
  330. Store: @TMenuBox.Store { Object store method }
  331. );
  332. {---------------------------------------------------------------------------}
  333. { TStatusLine STREAM REGISTRATION }
  334. {---------------------------------------------------------------------------}
  335. CONST
  336. RStatusLine: TStreamRec = (
  337. ObjType: 42; { Register id = 42 }
  338. {$IFDEF BP_VMTLink} { BP style VMT link }
  339. VmtLink: Ofs(TypeOf(TStatusLine)^);
  340. {$ELSE} { Alt style VMT link }
  341. VmtLink: TypeOf(TStatusLine);
  342. {$ENDIF}
  343. Load: @TStatusLine.Load; { Object load method }
  344. Store: @TStatusLine.Store { Object store method }
  345. );
  346. {---------------------------------------------------------------------------}
  347. { TMenuPopup STREAM REGISTRATION }
  348. {---------------------------------------------------------------------------}
  349. CONST
  350. RMenuPopup: TStreamRec = (
  351. ObjType: 43; { Register id = 43 }
  352. {$IFDEF BP_VMTLink} { BP style VMT link }
  353. VmtLink: Ofs(TypeOf(TMenuPopup)^);
  354. {$ELSE} { Alt style VMT link }
  355. VmtLink: TypeOf(TMenuPopup);
  356. {$ENDIF}
  357. Load: @TMenuPopup.Load; { Object load method }
  358. Store: @TMenuPopup.Store { Object store method }
  359. );
  360. {***************************************************************************}
  361. { INITIALIZED PUBLIC VARIABLES }
  362. {***************************************************************************}
  363. {---------------------------------------------------------------------------}
  364. { INITIALIZED PUBLIC VARIABLES }
  365. {---------------------------------------------------------------------------}
  366. CONST
  367. AdvancedMenus: Boolean = False; { Advanced menus }
  368. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  369. IMPLEMENTATION
  370. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  371. {***************************************************************************}
  372. { OBJECT METHODS }
  373. {***************************************************************************}
  374. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  375. { TMenuView OBJECT METHODS }
  376. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  377. {--TMenuView----------------------------------------------------------------}
  378. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  379. {---------------------------------------------------------------------------}
  380. CONSTRUCTOR TMenuView.Init (Var Bounds: TRect);
  381. BEGIN
  382. Inherited Init(Bounds); { Call ancestor }
  383. EventMask := EventMask OR evBroadcast; { See broadcast events }
  384. END;
  385. {--TMenuView----------------------------------------------------------------}
  386. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  387. {---------------------------------------------------------------------------}
  388. CONSTRUCTOR TMenuView.Load (Var S: TStream);
  389. FUNCTION DoLoadMenu: PMenu;
  390. VAR Tok: Byte; Item: PMenuItem; Last: ^PMenuItem; Menu: PMenu;
  391. BEGIN
  392. New(Menu); { Create new menu }
  393. Last := @Menu^.Items; { Start on first item }
  394. Item := Nil; { Clear pointer }
  395. S.Read(Tok, 1); { Read token }
  396. While (Tok <> 0) Do Begin
  397. New(Item); { Create new item }
  398. Last^ := Item; { First part of chain }
  399. If (Item <> Nil) Then Begin { Check item valid }
  400. Last := @Item^.Next; { Complete chain }
  401. With Item^ Do Begin
  402. Name := S.ReadStr; { Read menu name }
  403. S.Read(Command, 2); { Menu item command }
  404. S.Read(Disabled, 1); { Menu item state }
  405. S.Read(KeyCode, 2); { Menu item keycode }
  406. S.Read(HelpCtx, 2); { Menu item help ctx }
  407. If (Name <> Nil) Then
  408. If Command = 0 Then
  409. {$ifdef PPC_FPC}
  410. SubMenu := DoLoadMenu() { Load submenu }
  411. {$else not PPC_FPC}
  412. SubMenu := DoLoadMenu { Load submenu }
  413. {$endif not PPC_FPC}
  414. Else Param := S.ReadStr; { Read param string }
  415. End;
  416. End;
  417. S.Read(Tok, 1); { Read token }
  418. End;
  419. Last^ := Nil; { List complete }
  420. Menu^.Default := Menu^.Items; { Set menu default }
  421. DoLoadMenu := Menu; { Return menu }
  422. End;
  423. BEGIN
  424. Inherited Load(S); { Call ancestor }
  425. Menu := DoLoadMenu; { Load menu items }
  426. END;
  427. {--TMenuView----------------------------------------------------------------}
  428. { Execute -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  429. {---------------------------------------------------------------------------}
  430. FUNCTION TMenuView.Execute: Word;
  431. TYPE MenuAction = (DoNothing, DoSelect, DoReturn);
  432. VAR AutoSelect: Boolean; Action: MenuAction; Ch: Char; Res: Word; R: TRect;
  433. ItemShown, P: PMenuItem; Target: PMenuView; E: TEvent; MouseActive: Boolean;
  434. PROCEDURE TrackMouse;
  435. VAR Mouse: TPoint; R: TRect;
  436. BEGIN
  437. Mouse.X := E.Where.X - RawOrigin.X; { Local x position }
  438. Mouse.Y := E.Where.Y - RawoRigin.Y; { Local y position }
  439. Current := Menu^.Items; { Start with current }
  440. While (Current <> Nil) Do Begin
  441. GetItemRect(Current, R); { Get item rectangle }
  442. If R.Contains(Mouse) Then Begin { Contains mouse }
  443. MouseActive := True; { Return true }
  444. Exit; { Then exit }
  445. End;
  446. Current := Current^.Next; { Try next item }
  447. End;
  448. END;
  449. PROCEDURE TrackKey (FindNext: Boolean);
  450. PROCEDURE NextItem;
  451. BEGIN
  452. Current := Current^.Next; { Move to next item }
  453. If (Current = Nil) Then
  454. Current := Menu^.Items; { Return first menu }
  455. END;
  456. PROCEDURE PrevItem;
  457. VAR P: PMenuItem;
  458. BEGIN
  459. P := Current; { Start on current }
  460. If (P = Menu^.Items) Then P := Nil; { Check if at start }
  461. Repeat NextItem Until Current^.Next = P; { Prev item found }
  462. END;
  463. BEGIN
  464. If (Current <> Nil) Then { Current view valid }
  465. Repeat
  466. If FindNext Then NextItem Else PrevItem; { Find next/prev item }
  467. Until (Current^.Name <> Nil); { Until we have name }
  468. END;
  469. FUNCTION MouseInOwner: Boolean;
  470. VAR Mouse: TPoint; R: TRect;
  471. BEGIN
  472. MouseInOwner := False; { Preset false }
  473. If (ParentMenu <> Nil) AND (ParentMenu^.Size.Y = 1)
  474. Then Begin { Valid parent menu }
  475. Mouse.X := E.Where.X - ParentMenu^.RawOrigin.X;{ Local x position }
  476. Mouse.Y := E.Where.Y - ParentMenu^.RawOrigin.Y;{ Local y position }
  477. ParentMenu^.GetItemRect(ParentMenu^.Current,R);{ Get item rect }
  478. MouseInOwner := R.Contains(Mouse); { Return result }
  479. End;
  480. END;
  481. FUNCTION MouseInMenus: Boolean;
  482. VAR P: PMenuView;
  483. BEGIN
  484. P := ParentMenu; { Parent menu }
  485. While (P <> Nil) AND NOT P^.MouseInView(E.Where)
  486. Do P := P^.ParentMenu; { Check next menu }
  487. MouseInMenus := (P <> Nil); { Return result }
  488. END;
  489. FUNCTION TopMenu: PMenuView;
  490. VAR P: PMenuView;
  491. BEGIN
  492. P := @Self; { Start with self }
  493. While (P^.ParentMenu <> Nil) Do
  494. P := P^.ParentMenu; { Check next menu }
  495. TopMenu := P; { Top menu }
  496. END;
  497. BEGIN
  498. AutoSelect := False; { Clear select flag }
  499. MouseActive := False; { Clear mouse flag }
  500. Res := 0; { Clear result }
  501. ItemShown := Nil; { Clear item pointer }
  502. If (Menu <> Nil) Then Current := Menu^.Default { Set current item }
  503. Else Current := Nil; { No menu = no current }
  504. Repeat
  505. Action := DoNothing; { Clear action flag }
  506. GetEvent(E); { Get next event }
  507. Case E.What Of
  508. evMouseDown: If MouseInView(E.Where) { Mouse in us }
  509. OR MouseInOwner Then Begin { Mouse in owner area }
  510. TrackMouse; { Track the mouse }
  511. If (Size.Y = 1) Then AutoSelect := True; { Set select flag }
  512. End Else Action := DoReturn; { Set return action }
  513. evMouseUp: Begin
  514. TrackMouse; { Track the mouse }
  515. If MouseInOwner Then { Mouse in owner }
  516. Current := Menu^.Default { Set as current }
  517. Else If (Current <> Nil) AND
  518. (Current^.Name <> Nil) Then
  519. Action := DoSelect { Set select action }
  520. Else If MouseActive OR MouseInView(E.Where)
  521. Then Action := DoReturn { Set return action }
  522. Else Begin
  523. Current := Menu^.Default; { Set current item }
  524. If (Current = Nil) Then
  525. Current := Menu^.Items; { Select first item }
  526. Action := DoNothing; { Do nothing action }
  527. End;
  528. End;
  529. evMouseMove: If (E.Buttons <> 0) Then Begin { Mouse moved }
  530. TrackMouse; { Track the mouse }
  531. If NOT (MouseInView(E.Where) OR MouseInOwner)
  532. AND MouseInMenus Then Action := DoReturn; { Set return action }
  533. End;
  534. evKeyDown:
  535. Case CtrlToArrow(E.KeyCode) Of { Check arrow keys }
  536. kbUp, kbDown: If (Size.Y <> 1) Then
  537. TrackKey(CtrlToArrow(E.KeyCode) = kbDown){ Track keyboard }
  538. Else If (E.KeyCode = kbDown) Then { Down arrow }
  539. AutoSelect := True; { Select item }
  540. kbLeft, kbRight: If (ParentMenu = Nil) Then
  541. TrackKey(CtrlToArrow(E.KeyCode)=kbRight) { Track keyboard }
  542. Else Action := DoReturn; { Set return action }
  543. kbHome, kbEnd: If (Size.Y <> 1) Then Begin
  544. Current := Menu^.Items; { Set to first item }
  545. If (E.KeyCode = kbEnd) Then { If the 'end' key }
  546. TrackKey(False); { Move to last item }
  547. End;
  548. kbEnter: Begin
  549. If Size.Y = 1 Then AutoSelect := True; { Select item }
  550. Action := DoSelect; { Return the item }
  551. End;
  552. kbEsc: Begin
  553. Action := DoReturn; { Set return action }
  554. If (ParentMenu = Nil) OR
  555. (ParentMenu^.Size.Y <> 1) Then { Check parent }
  556. ClearEvent(E); { Kill the event }
  557. End;
  558. Else Target := @Self; { Set target as self }
  559. Ch := GetAltChar(E.KeyCode);
  560. If (Ch = #0) Then Ch := E.CharCode Else
  561. Target := TopMenu; { Target is top menu }
  562. P := Target^.FindItem(Ch); { Check for item }
  563. If (P = Nil) Then Begin
  564. P := TopMenu^.HotKey(E.KeyCode); { Check for hot key }
  565. If (P <> Nil) AND { Item valid }
  566. CommandEnabled(P^.Command) Then Begin { Command enabled }
  567. Res := P^.Command; { Set return command }
  568. Action := DoReturn; { Set return action }
  569. End
  570. End Else If Target = @Self Then Begin
  571. If Size.Y = 1 Then AutoSelect := True; { Set auto select }
  572. Action := DoSelect; { Select item }
  573. Current := P; { Set current item }
  574. End Else If (ParentMenu <> Target) OR
  575. (ParentMenu^.Current <> P) Then { Item different }
  576. Action := DoReturn; { Set return action }
  577. End;
  578. evCommand: If (E.Command = cmMenu) Then Begin { Menu command }
  579. AutoSelect := False; { Dont select item }
  580. If (ParentMenu <> Nil) Then
  581. Action := DoReturn; { Set return action }
  582. End Else Action := DoReturn; { Set return action }
  583. End;
  584. If (ItemShown <> Current) Then Begin { New current item }
  585. OldItem := ItemShown; { Hold old item }
  586. ItemShown := Current; { Hold new item }
  587. SetDrawMask(vdFocus OR vdInner); { Set the draw mask }
  588. DrawView; { Redraw the items }
  589. OldItem := Nil; { Clear old item }
  590. End;
  591. If (Action = DoSelect) OR ((Action = DoNothing)
  592. AND AutoSelect) Then { Item is selecting }
  593. If (Current <> Nil) Then With Current^ Do { Current item valid }
  594. If (Name <> Nil) Then { Item has a name }
  595. If (Command = 0) Then Begin { Has no command }
  596. If (E.What AND (evMouseDown+evMouseMove) <> 0)
  597. Then PutEvent(E); { Put event on queue }
  598. GetItemRect(Current, R); { Get area of item }
  599. R.A.X := R.A.X DIV FontWidth + Origin.X; { Left start point }
  600. R.A.Y := R.B.Y DIV FontHeight + Origin.Y;{ Top start point }
  601. R.B.X := Owner^.Size.X; { X screen area left }
  602. R.B.Y := Owner^.Size.Y; { Y screen area left }
  603. Target := TopMenu^.NewSubView(R, SubMenu,
  604. @Self); { Create drop menu }
  605. Res := Owner^.ExecView(Target); { Execute dropped view }
  606. Dispose(Target, Done); { Dispose drop view }
  607. End Else If Action = DoSelect Then
  608. Res := Command; { Return result }
  609. If (Res <> 0) AND CommandEnabled(Res) { Check command }
  610. Then Begin
  611. Action := DoReturn; { Return command }
  612. ClearEvent(E); { Clear the event }
  613. End Else Res := 0; { Clear result }
  614. Until (Action = DoReturn);
  615. If (E.What <> evNothing) Then
  616. If (ParentMenu <> Nil) OR (E.What = evCommand) { Check event type }
  617. Then PutEvent(E); { Put event on queue }
  618. If (Current <> Nil) Then Begin
  619. Menu^.Default := Current; { Set new default }
  620. Current := Nil; { Clear current }
  621. DrawView; { Redraw the view }
  622. End;
  623. Execute := Res; { Return result }
  624. END;
  625. {--TMenuView----------------------------------------------------------------}
  626. { GetHelpCtx -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  627. {---------------------------------------------------------------------------}
  628. FUNCTION TMenuView.GetHelpCtx: Word;
  629. VAR C: PMenuView;
  630. BEGIN
  631. C := @Self; { Start at self }
  632. While (C <> Nil) AND ((C^.Current = Nil) OR
  633. (C^.Current^.HelpCtx = hcNoContext) OR { Has no context }
  634. (C^.Current^.Name = Nil)) Do C := C^.ParentMenu; { Parent menu context }
  635. If (C<>Nil) Then GetHelpCtx := C^.Current^.HelpCtx { Current context }
  636. Else GetHelpCtx := hcNoContext; { No help context }
  637. END;
  638. {--TMenuView----------------------------------------------------------------}
  639. { GetPalette -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 15May98 LdB }
  640. {---------------------------------------------------------------------------}
  641. FUNCTION TMenuView.GetPalette: PPalette;
  642. {$IFDEF PPC_DELPHI3} { DELPHI3+ COMPILER }
  643. CONST P: String = CMenuView; { Possible huge string }
  644. {$ELSE} { OTHER COMPILERS }
  645. CONST P: String[Length(CMenuView)] = CMenuView; { Always normal string }
  646. {$ENDIF}
  647. BEGIN
  648. GetPalette := @P; { Return palette }
  649. END;
  650. {--TMenuView----------------------------------------------------------------}
  651. { FindItem -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  652. {---------------------------------------------------------------------------}
  653. FUNCTION TMenuView.FindItem (Ch: Char): PMenuItem;
  654. VAR I: Integer; P: PMenuItem;
  655. BEGIN
  656. Ch := UpCase(Ch); { Upper case of char }
  657. P := Menu^.Items; { First menu item }
  658. While (P <> Nil) Do Begin { While item valid }
  659. If (P^.Name <> Nil) AND (NOT P^.Disabled) { Valid enabled cmd }
  660. Then Begin
  661. I := Pos('~', P^.Name^); { Scan for highlight }
  662. If (I <> 0) AND (Ch = UpCase(P^.Name^[I+1])) { Hotkey char found }
  663. Then Begin
  664. FindItem := P; { Return item }
  665. Exit; { Now exit }
  666. End;
  667. End;
  668. P := P^.Next; { Next item }
  669. End;
  670. FindItem := Nil; { No item found }
  671. END;
  672. {--TMenuView----------------------------------------------------------------}
  673. { HotKey -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  674. {---------------------------------------------------------------------------}
  675. FUNCTION TMenuView.HotKey (KeyCode: Word): PMenuItem;
  676. FUNCTION FindHotKey (P: PMenuItem): PMenuItem;
  677. VAR T: PMenuItem;
  678. BEGIN
  679. While (P <> Nil) Do Begin { While item valid }
  680. If (P^.Name <> Nil) Then { If valid name }
  681. If (P^.Command = 0) Then Begin { Valid command }
  682. T := FindHotKey(P^.SubMenu^.Items); { Search for hot key }
  683. If (T <> Nil) Then Begin
  684. FindHotKey := T; { Return hotkey }
  685. Exit; { Now exit }
  686. End;
  687. End Else If NOT P^.Disabled AND { Hotkey is enabled }
  688. (P^.KeyCode <> kbNoKey) AND { Valid keycode }
  689. (P^.KeyCode = KeyCode) Then Begin { Key matches request }
  690. FindHotKey := P; { Return hotkey code }
  691. Exit; { Exit }
  692. End;
  693. P := P^.Next; { Next item }
  694. End;
  695. FindHotKey := Nil; { No item found }
  696. END;
  697. BEGIN
  698. HotKey := FindHotKey(Menu^.Items); { Hot key function }
  699. END;
  700. {--TMenuView----------------------------------------------------------------}
  701. { NewSubView -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  702. {---------------------------------------------------------------------------}
  703. FUNCTION TMenuView.NewSubView (Var Bounds: TRect; AMenu: PMenu;
  704. AParentMenu: PMenuView): PMenuView;
  705. BEGIN
  706. NewSubView := New(PMenuBox, Init(Bounds, AMenu,
  707. AParentMenu)); { Create a menu box }
  708. END;
  709. {--TMenuView----------------------------------------------------------------}
  710. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  711. {---------------------------------------------------------------------------}
  712. PROCEDURE TMenuView.Store (Var S: TStream);
  713. PROCEDURE DoStoreMenu (Menu: PMenu);
  714. VAR Item: PMenuItem; Tok: Byte;
  715. BEGIN
  716. Tok := $FF; { Preset max count }
  717. Item := Menu^.Items; { Start first item }
  718. While (Item <> Nil) Do Begin
  719. With Item^ Do Begin
  720. S.Write(Tok, 1); { Write tok value }
  721. S.WriteStr(Name); { Write item name }
  722. S.Write(Command, 2); { Menu item command }
  723. S.Write(Disabled, 1); { Menu item state }
  724. S.Write(KeyCode, 2); { Menu item keycode }
  725. S.Write(HelpCtx, 2); { Menu item help ctx }
  726. If (Name <> Nil) Then
  727. If Command = 0 Then DoStoreMenu(SubMenu)
  728. Else S.WriteStr(Param); { Write parameter }
  729. End;
  730. Item := Item^.Next; { Next item }
  731. End;
  732. Tok := 0; { Clear tok count }
  733. S.Write(Tok, 1); { Write tok value }
  734. END;
  735. BEGIN
  736. TView.Store(S); { TView.Store called }
  737. DoStoreMenu(Menu); { Store menu items }
  738. END;
  739. {--TMenuView----------------------------------------------------------------}
  740. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  741. {---------------------------------------------------------------------------}
  742. PROCEDURE TMenuView.HandleEvent (Var Event: TEvent);
  743. VAR CallDraw: Boolean; P: PMenuItem;
  744. PROCEDURE UpdateMenu (Menu: PMenu);
  745. VAR P: PMenuItem; CommandState: Boolean;
  746. BEGIN
  747. P := Menu^.Items; { Start on first item }
  748. While (P <> Nil) Do Begin
  749. If (P^.Name <> Nil) Then { Valid name }
  750. If (P^.Command = 0) Then UpdateMenu(P^.SubMenu){ Update menu }
  751. Else Begin
  752. CommandState := CommandEnabled(P^.Command); { Menu item state }
  753. If (P^.Disabled = CommandState) Then Begin
  754. P^.Disabled := NOT CommandState; { Disable item }
  755. CallDraw := True; { Must draw }
  756. End;
  757. End;
  758. P := P^.Next; { Next item }
  759. End;
  760. END;
  761. PROCEDURE DoSelect;
  762. BEGIN
  763. PutEvent(Event); { Put event on queue }
  764. Event.Command := Owner^.ExecView(@Self); { Execute view }
  765. If (Event.Command <> 0) AND
  766. CommandEnabled(Event.Command) Then Begin
  767. Event.What := evCommand; { Command event }
  768. Event.InfoPtr := Nil; { Clear info ptr }
  769. PutEvent(Event); { Put event on queue }
  770. End;
  771. ClearEvent(Event); { Clear the event }
  772. END;
  773. BEGIN
  774. If (Menu <> Nil) Then
  775. Case Event.What Of
  776. evMouseDown: DoSelect; { Select menu item }
  777. evKeyDown:
  778. If (FindItem(GetAltChar(Event.KeyCode)) <> Nil)
  779. Then DoSelect Else Begin { Select menu item }
  780. P := HotKey(Event.KeyCode); { Check for hotkey }
  781. If (P <> Nil) AND
  782. (CommandEnabled(P^.Command)) Then Begin
  783. Event.What := evCommand; { Command event }
  784. Event.Command := P^.Command; { Set command event }
  785. Event.InfoPtr := Nil; { Clear info ptr }
  786. PutEvent(Event); { Put event on queue }
  787. ClearEvent(Event); { Clear the event }
  788. End;
  789. End;
  790. evCommand:
  791. If Event.Command = cmMenu Then DoSelect; { Select menu item }
  792. evBroadcast:
  793. If (Event.Command = cmCommandSetChanged) { Commands changed }
  794. Then Begin
  795. CallDraw := False; { Preset no redraw }
  796. UpdateMenu(Menu); { Update menu }
  797. If CallDraw Then DrawView; { Redraw if needed }
  798. End;
  799. End;
  800. END;
  801. {--TMenuView----------------------------------------------------------------}
  802. { GetItemRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  803. {---------------------------------------------------------------------------}
  804. PROCEDURE TMenuView.GetItemRect (Item: PMenuItem; Var R: TRect);
  805. BEGIN { Abstract method }
  806. END;
  807. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  808. { TMenuBar OBJECT METHODS }
  809. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  810. {--TMenuBar-----------------------------------------------------------------}
  811. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  812. {---------------------------------------------------------------------------}
  813. CONSTRUCTOR TMenuBar.Init (Var Bounds: TRect; AMenu: PMenu);
  814. BEGIN
  815. Inherited Init(Bounds); { Call ancestor }
  816. GrowMode := gfGrowHiX; { Set grow mode }
  817. Menu := AMenu; { Hold menu item }
  818. Options := Options OR ofPreProcess; { Preprocessing view }
  819. END;
  820. {--TMenuBar-----------------------------------------------------------------}
  821. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  822. {---------------------------------------------------------------------------}
  823. DESTRUCTOR TMenuBar.Done;
  824. BEGIN
  825. If (Menu <> Nil) Then DisposeMenu(Menu); { Dispose menu items }
  826. Inherited Done; { Call ancestor }
  827. END;
  828. {--TMenuBar-----------------------------------------------------------------}
  829. { Draw -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  830. {---------------------------------------------------------------------------}
  831. PROCEDURE TMenuBar.Draw;
  832. VAR I, J, K, L, CNormal, CSelect, CNormDisabled, CSelDisabled, Color: Word;
  833. P: PMenuItem; B: TDrawBuffer;
  834. BEGIN
  835. CNormal := GetColor($0301); { Normal colour }
  836. CSelect := GetColor($0604); { Select colour }
  837. CNormDisabled := GetColor($0202); { Disabled colour }
  838. CSelDisabled := GetColor($0505); { Select disabled }
  839. If (Menu <> Nil) Then Begin { Valid menu }
  840. I := 0; { Set start position }
  841. P := Menu^.Items; { First item }
  842. While (P <> Nil) Do Begin
  843. If (P^.Name <> Nil) Then Begin { Name valid }
  844. J := CStrLen(P^.Name^) + 2; { Name string length }
  845. If (P = OldItem) OR (P = Current) Then Begin { Matches a state }
  846. If P^.Disabled Then Begin
  847. If (P = Current) Then
  848. Color := CSelDisabled { Select disabled }
  849. Else Color := CNormDisabled { Normal disabled }
  850. End Else Begin
  851. If (P = Current) Then Color := CSelect { Select colour }
  852. Else Color := CNormal; { Normal colour }
  853. End;
  854. MoveCStr(B, ' '+P^.Name^+' ', Color); { Name to buffer }
  855. WriteBuf(I, 0, J, 1, B); { Write the string }
  856. K := I*FontWidth; { X start position }
  857. L := K + TextWidth(' '+P^.Name^+' '); { X end position }
  858. If AdvancedMenus Then Begin
  859. GraphLine(K, 0, L, 0, White); { Redraw top line }
  860. GraphLine(K, FontHeight-1, L,
  861. FontHeight-1, DarkGray); { Redraw lower line }
  862. End;
  863. End;
  864. Inc(I, J); { Advance position }
  865. End;
  866. P := P^.Next; { Next item }
  867. End;
  868. End;
  869. END;
  870. {--TMenuBar-----------------------------------------------------------------}
  871. { DrawBackGround -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  872. {---------------------------------------------------------------------------}
  873. PROCEDURE TMenuBar.DrawBackGround;
  874. VAR I, J, CNormal, CSelect, CNormDisabled, CSelDisabled, Color: Word;
  875. P: PMenuItem; B: TDrawBuffer;
  876. BEGIN
  877. Inherited DrawBackGround; { Call ancestor }
  878. CNormal := GetColor($0301); { Normal colour }
  879. CSelect := GetColor($0604); { Select colour }
  880. CNormDisabled := GetColor($0202); { Disabled colour }
  881. CSelDisabled := GetColor($0505); { Select disabled }
  882. If (Menu <> Nil) Then Begin { Valid menu }
  883. I := 0; { Set start position }
  884. P := Menu^.Items; { First item }
  885. While (P <> Nil) Do Begin
  886. If (P^.Name <> Nil) Then Begin { Name valid }
  887. If P^.Disabled Then Begin
  888. If (P = Current) Then Color := CSelDisabled{ Select disabled }
  889. Else Color := CNormDisabled { Normal disabled }
  890. End Else Begin
  891. If (P = Current) Then Color := CSelect { Select colour }
  892. Else Color := CNormal; { Normal colour }
  893. End;
  894. J := CStrLen(P^.Name^) + 2; { Length of string }
  895. MoveCStr(B, ' '+P^.Name^+' ', Color); { Name to buffer }
  896. WriteBuf(I, 0, J, 1, B); { Write the string }
  897. Inc(I, J); { Advance position }
  898. End;
  899. P := P^.Next; { Next item }
  900. End;
  901. End;
  902. If AdvancedMenus Then BiColorRectangle(0, 0,
  903. RawSize.X, RawSize.Y, White, DarkGray, False); { Draw 3d effect }
  904. END;
  905. {--TMenuBar-----------------------------------------------------------------}
  906. { GetItemRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  907. {---------------------------------------------------------------------------}
  908. PROCEDURE TMenuBar.GetItemRect (Item: PMenuItem; Var R: TRect);
  909. VAR I: Integer; P: PMenuItem;
  910. BEGIN
  911. I := 0; { Preset to zero }
  912. R.Assign(0, 0, 0, FontHeight); { Initial rect size }
  913. P := Menu^.Items; { First item }
  914. While (P <> Nil) Do Begin { While valid item }
  915. R.A.X := I*FontWidth; { Move area along }
  916. If (P^.Name <> Nil) Then Begin { Valid name }
  917. R.B.X := R.A.X+TextWidth(' ' + P^.Name^ + ' ');{ Add text width }
  918. I := I + CStrLen(P^.Name^) + 2; { Add item length }
  919. End Else R.B.X := R.A.X;
  920. If (P = Item) Then Exit; { Requested item found }
  921. P := P^.Next; { Next item }
  922. End;
  923. END;
  924. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  925. { TMenuBox OBJECT METHODS }
  926. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  927. {--TMenuBox-----------------------------------------------------------------}
  928. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  929. {---------------------------------------------------------------------------}
  930. CONSTRUCTOR TMenuBox.Init (Var Bounds: TRect; AMenu: PMenu;
  931. AParentMenu: PMenuView);
  932. VAR W, H, L: Integer; S: String; P: PMenuItem; R: TRect;
  933. BEGIN
  934. W := 0; { Clear initial width }
  935. H := 2; { Set initial height }
  936. If (AMenu <> Nil) Then Begin { Valid menu }
  937. P := AMenu^.Items; { Start on first item }
  938. While (P <> Nil) Do Begin { If item valid }
  939. If (P^.Name <> Nil) Then Begin { Check for name }
  940. S := ' ' + P^.Name^ + ' '; { Transfer string }
  941. If (P^.Command <> 0) AND (P^.Param <> Nil)
  942. Then S := S + ' - ' + P^.Param^; { Add any parameter }
  943. End;
  944. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  945. HWindow := 0; { Must zero handle }
  946. Dc := 0; { Must zero context }
  947. {$ENDIF}
  948. {$IFDEF OS_OS2} { OS2 CODE }
  949. HWindow := 0; { Must zero handle }
  950. Ps := 0; { Must zero pres space }
  951. {$ENDIF}
  952. L := TextWidth(S); { Width of string }
  953. If (L > W) Then W := L; { Hold maximum }
  954. Inc(H); { Inc count of items }
  955. P := P^.Next; { Move to next item }
  956. End;
  957. End;
  958. W := 5 + (W DIV FontWidth); { Longest text width }
  959. R.Copy(Bounds); { Copy the bounds }
  960. If (R.A.X + W < R.B.X) Then R.B.X := R.A.X + W { Shorten if possible }
  961. Else R.A.X := R.B.X - W; { Insufficent space }
  962. R.B.X := R.A.X + W;
  963. If (R.A.Y + H < R.B.Y) Then R.B.Y := R.A.Y + H { Shorten if possible }
  964. Else R.A.Y := R.B.Y - H; { Insufficent height }
  965. Inherited Init(R); { Call ancestor }
  966. State := State OR sfShadow; { Set shadow state }
  967. Options := Options OR ofPreProcess; { View pre processes }
  968. Menu := AMenu; { Hold menu }
  969. ParentMenu := AParentMenu; { Hold parent }
  970. END;
  971. {--TMenuBox-----------------------------------------------------------------}
  972. { Draw -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  973. {---------------------------------------------------------------------------}
  974. PROCEDURE TMenuBox.Draw;
  975. VAR CNormal, CSelect, CDisabled, Color: Word; Tx, Ty, Y: Integer;
  976. S: String; P: PMenuItem; B: TDrawBuffer;
  977. BEGIN
  978. CNormal := GetColor($0301); { Normal colour }
  979. CSelect := GetColor($0604); { Selected colour }
  980. CDisabled := GetColor($0202); { Disabled colour }
  981. Y := 1;
  982. If (Menu <> Nil) Then Begin { We have a menu }
  983. P := Menu^.Items; { Start on first }
  984. While (P <> Nil) Do Begin { Valid menu item }
  985. Color := CNormal; { Normal colour }
  986. If (P^.Name <> Nil) Then Begin { Item has text }
  987. If P^.Disabled Then Color := CDisabled { Is item disabled }
  988. Else If (P = Current) Then Color := CSelect; { Select colour }
  989. MoveChar(B, ' ', Color, Size.X-4); { Clear buffer }
  990. S := ' ' + P^.Name^ + ' '; { Menu string }
  991. MoveCStr(B[0], S, Color); { Transfer string }
  992. If (P^.Command <> 0) AND(P^.Param <> Nil)
  993. Then Begin
  994. MoveCStr(B[CStrLen(S)], ' - ' + P^.Param^,
  995. Color); { Add param chars }
  996. S := S + ' - ' + P^.Param^; { Add to string }
  997. End;
  998. If (OldItem = Nil) OR (OldItem = P) OR
  999. (Current = P) Then Begin { We need to fix draw }
  1000. WriteBuf(2, Y, CStrLen(S), 1, B); { Write the line }
  1001. If (P = Current) Then Begin { Selected item }
  1002. Tx := 2 * FontWidth; { X offset }
  1003. Ty := Y * FontHeight; { Y offset }
  1004. BicolorRectangle(Tx, Ty, Tx + TextWidth(S)
  1005. - 1, Ty + FontHeight - 1, White,
  1006. DarkGray, False); { Draw higlight box }
  1007. End;
  1008. End;
  1009. End;
  1010. Inc(Y); { Next line down }
  1011. P := P^.Next; { fetch next item }
  1012. End;
  1013. End;
  1014. END;
  1015. {--TMenuBox-----------------------------------------------------------------}
  1016. { DrawBackGround -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1017. {---------------------------------------------------------------------------}
  1018. PROCEDURE TMenuBox.DrawBackGround;
  1019. VAR X, Y, Y2: Integer; P : PMenuItem;
  1020. BEGIN
  1021. Y2 := FontHeight DIV 2; { Intra offset }
  1022. Y := FontHeight; { Initial position }
  1023. X := 3*FontWidth; { 2 offset }
  1024. Inherited DrawBackGround; { Call ancestor }
  1025. If (Menu <> Nil) Then Begin { We have a menu }
  1026. P := Menu^.Items; { Start on first }
  1027. While (P <> Nil) Do Begin
  1028. If (P^.Name = Nil) Then { Item has no string }
  1029. BiColorRectangle(X, Y+Y2, RawSize.X-X,
  1030. Y+Y2+1, White, DarkGray, True); { Draw 3d line effect }
  1031. Inc(Y, FontHeight); { Down one line }
  1032. P := P^.Next; { Next item now }
  1033. End;
  1034. End;
  1035. BiColorRectangle(3, 3, RawSize.X-3, RawSize.Y-3,
  1036. White, DarkGray, False); { Draw 3d effect }
  1037. BiColorRectangle(5, 5, RawSize.X-5, RawSize.Y-5,
  1038. White, DarkGray, True); { Draw 3d effect }
  1039. BiColorRectangle(0, 0, RawSize.X, RawSize.Y,
  1040. White, DarkGray, False); { Draw 3d effect }
  1041. END;
  1042. {--TMenuBox-----------------------------------------------------------------}
  1043. { GetItemRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1044. {---------------------------------------------------------------------------}
  1045. PROCEDURE TMenuBox.GetItemRect (Item: PMenuItem; Var R: TRect);
  1046. VAR X, Y: Integer; P: PMenuItem;
  1047. BEGIN
  1048. Y := FontHeight; { Initial y position }
  1049. P := Menu^.Items; { Initial item }
  1050. While (P <> Item) Do Begin { Valid item }
  1051. Inc(Y, FontHeight); { Inc position }
  1052. P := P^.Next; { Next item }
  1053. End;
  1054. X := 2 * FontWidth; { Left/Right margin }
  1055. R.Assign(X, Y, RawSize.X - X, Y + FontHeight); { Assign area }
  1056. END;
  1057. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1058. { TMenuPopUp OBJECT METHODS }
  1059. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1060. {--TMenuPopUp---------------------------------------------------------------}
  1061. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 15May98 LdB }
  1062. {---------------------------------------------------------------------------}
  1063. CONSTRUCTOR TMenuPopup.Init (Var Bounds: TRect; AMenu: PMenu);
  1064. BEGIN
  1065. Inherited Init(Bounds, AMenu, Nil); { Call ancestor }
  1066. END;
  1067. {--TMenuPopUp---------------------------------------------------------------}
  1068. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 15May98 LdB }
  1069. {---------------------------------------------------------------------------}
  1070. DESTRUCTOR TMenuPopup.Done;
  1071. BEGIN
  1072. If (Menu <> Nil) Then DisposeMenu(Menu); { Dispose menu items }
  1073. Inherited Done; { Call ancestor }
  1074. END;
  1075. {--TMenuPopUp---------------------------------------------------------------}
  1076. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 15May98 LdB }
  1077. {---------------------------------------------------------------------------}
  1078. PROCEDURE TMenuPopup.HandleEvent (Var Event: TEvent);
  1079. VAR P: PMenuItem;
  1080. BEGIN
  1081. Case Event.What Of
  1082. evKeyDown: Begin
  1083. P := FindItem(GetCtrlChar(Event.KeyCode)); { Find the item }
  1084. If (P = Nil) Then P := HotKey(Event.KeyCode);{ Try hot key }
  1085. If (P <> Nil) AND (CommandEnabled(P^.Command))
  1086. Then Begin { Command valid }
  1087. Event.What := evCommand; { Command event }
  1088. Event.Command := P^.Command; { Set command value }
  1089. Event.InfoPtr := Nil; { Clear info ptr }
  1090. PutEvent(Event); { Put event on queue }
  1091. ClearEvent(Event); { Clear the event }
  1092. End Else If (GetAltChar(Event.KeyCode) <> #0)
  1093. Then ClearEvent(Event); { Clear the event }
  1094. End;
  1095. End;
  1096. Inherited HandleEvent(Event); { Call ancestor }
  1097. END;
  1098. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1099. { TStatusLine OBJECT METHODS }
  1100. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1101. {--TStatusLine--------------------------------------------------------------}
  1102. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1103. {---------------------------------------------------------------------------}
  1104. CONSTRUCTOR TStatusLine.Init (Var Bounds: TRect; ADefs: PStatusDef);
  1105. BEGIN
  1106. Inherited Init(Bounds); { Call ancestor }
  1107. Options := Options OR ofPreProcess; { Pre processing view }
  1108. EventMask := EventMask OR evBroadcast; { See broadcasts }
  1109. GrowMode := gfGrowLoY + gfGrowHiX + gfGrowHiY; { Set grow modes }
  1110. Defs := ADefs; { Set default items }
  1111. FindItems; { Find the items }
  1112. END;
  1113. {--TStatusLine--------------------------------------------------------------}
  1114. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1115. {---------------------------------------------------------------------------}
  1116. CONSTRUCTOR TStatusLine.Load (Var S: TStream);
  1117. FUNCTION DoLoadStatusItems: PStatusItem;
  1118. VAR Count: Integer; Cur, First: PStatusItem; Last: ^PStatusItem;
  1119. BEGIN
  1120. Cur := Nil; { Preset nil }
  1121. Last := @First; { Start on first item }
  1122. S.Read(Count, 2); { Read count }
  1123. While (Count > 0) Do Begin
  1124. New(Cur); { New status item }
  1125. Last^ := Cur; { First chain part }
  1126. If (Cur <> Nil) Then Begin { Check pointer valid }
  1127. Last := @Cur^.Next; { Chain complete }
  1128. Cur^.Text := S.ReadStr; { Read item text }
  1129. S.Read(Cur^.KeyCode, 2); { Keycode of item }
  1130. S.Read(Cur^.Command, 2); { Command of item }
  1131. End;
  1132. Dec(Count); { One item loaded }
  1133. End;
  1134. Last^ := Nil; { Now chain end }
  1135. DoLoadStatusItems := First; { Return the list }
  1136. END;
  1137. FUNCTION DoLoadStatusDefs: PStatusDef;
  1138. VAR Count: Integer; Cur, First: PStatusDef; Last: ^PStatusDef;
  1139. BEGIN
  1140. Last := @First; { Start on first }
  1141. S.Read(Count, 2); { Read item count }
  1142. While (Count > 0) Do Begin
  1143. New(Cur); { New status def }
  1144. Last^ := Cur; { First part of chain }
  1145. If (Cur <> Nil) Then Begin { Check pointer valid }
  1146. Last := @Cur^.Next; { Chain complete }
  1147. S.Read(Cur^.Min, 2); { Read min data }
  1148. S.Read(Cur^.Max, 2); { Read max data }
  1149. Cur^.Items := DoLoadStatusItems; { Set pointer }
  1150. End;
  1151. Dec(Count); { One item loaded }
  1152. End;
  1153. Last^ := Nil; { Now chain ends }
  1154. DoLoadStatusDefs := First; { Return item list }
  1155. END;
  1156. BEGIN
  1157. Inherited Load(S); { Call ancestor }
  1158. Defs := DoLoadStatusDefs; { Retreive items }
  1159. FindItems; { Find the items }
  1160. END;
  1161. {--TStatusLine--------------------------------------------------------------}
  1162. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1163. {---------------------------------------------------------------------------}
  1164. DESTRUCTOR TStatusLine.Done;
  1165. VAR T: PStatusDef;
  1166. PROCEDURE DisposeItems (Item: PStatusItem);
  1167. VAR T: PStatusItem;
  1168. BEGIN
  1169. While (Item <> Nil) Do Begin { Item to dispose }
  1170. T := Item; { Hold pointer }
  1171. Item := Item^.Next; { Move down chain }
  1172. DisposeStr(T^.Text); { Dispose string }
  1173. Dispose(T); { Dispose item }
  1174. End;
  1175. END;
  1176. BEGIN
  1177. While (Defs <> Nil) Do Begin
  1178. T := Defs; { Hold pointer }
  1179. Defs := Defs^.Next; { Move down chain }
  1180. DisposeItems(T^.Items); { Dispose the item }
  1181. Dispose(T); { Dispose status item }
  1182. End;
  1183. Inherited Done; { Call ancestor }
  1184. END;
  1185. {--TStatusLine--------------------------------------------------------------}
  1186. { GetPalette -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1187. {---------------------------------------------------------------------------}
  1188. FUNCTION TStatusLine.GetPalette: PPalette;
  1189. {$IFDEF PPC_DELPHI3} { DELPHI3+ COMPILER }
  1190. CONST P: String = CStatusLine; { Possible huge string }
  1191. {$ELSE} { OTHER COMPILERS }
  1192. CONST P: String[Length(CStatusLine)] = CStatusLine; { Always normal string }
  1193. {$ENDIF}
  1194. BEGIN
  1195. GetPalette := @P; { Return palette }
  1196. END;
  1197. {--TStatusLine--------------------------------------------------------------}
  1198. { Hint -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1199. {---------------------------------------------------------------------------}
  1200. FUNCTION TStatusLine.Hint (AHelpCtx: Word): String;
  1201. BEGIN
  1202. Hint := ''; { Return nothing }
  1203. END;
  1204. {--TStatusLine--------------------------------------------------------------}
  1205. { Draw -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1206. {---------------------------------------------------------------------------}
  1207. PROCEDURE TStatusLine.Draw;
  1208. BEGIN
  1209. DrawSelect(Nil); { Call draw select }
  1210. END;
  1211. {--TStatusLine--------------------------------------------------------------}
  1212. { Update -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 15May98 LdB }
  1213. {---------------------------------------------------------------------------}
  1214. PROCEDURE TStatusLine.Update;
  1215. VAR H: Word; P: PView;
  1216. BEGIN
  1217. P := TopView; { Get topmost view }
  1218. If (P <> Nil) Then H := P^.GetHelpCtx Else { Top views context }
  1219. H := hcNoContext; { No context }
  1220. If (HelpCtx <> H) Then Begin { Differs from last }
  1221. HelpCtx := H; { Hold new context }
  1222. FindItems; { Find the item }
  1223. DrawView; { Redraw the view }
  1224. End;
  1225. END;
  1226. {--TStatusLine--------------------------------------------------------------}
  1227. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1228. {---------------------------------------------------------------------------}
  1229. PROCEDURE TStatusLine.Store (Var S: TStream);
  1230. PROCEDURE DoStoreStatusItems (Cur: PStatusItem);
  1231. VAR Count: Integer; T: PStatusItem;
  1232. BEGIN
  1233. Count := 0; { Clear count }
  1234. T := Cur; { Start on current }
  1235. While (T <> Nil) Do Begin
  1236. Inc(Count); { Count items }
  1237. T := T^.Next; { Next item }
  1238. End;
  1239. S.Write(Count, 2); { Write item count }
  1240. While (Cur <> Nil) Do Begin
  1241. S.WriteStr(Cur^.Text); { Store item text }
  1242. S.Write(Cur^.KeyCode, 2); { Keycode of item }
  1243. S.Write(Cur^.Command, 2); { Command of item }
  1244. Cur := Cur^.Next; { Move to next item }
  1245. End;
  1246. END;
  1247. PROCEDURE DoStoreStatusDefs (Cur: PStatusDef);
  1248. VAR Count: Integer; T: PStatusDef;
  1249. BEGIN
  1250. Count := 0; { Clear count }
  1251. T := Cur; { Current status item }
  1252. While (T <> Nil) Do Begin
  1253. Inc(Count); { Count items }
  1254. T := T^.Next { Next item }
  1255. End;
  1256. S.Write(Count, 2); { Write item count }
  1257. While (Cur <> Nil) Do Begin
  1258. With Cur^ Do Begin
  1259. S.Write(Cur^.Min, 2); { Write min data }
  1260. S.Write(Cur^.Max, 2); { Write max data }
  1261. DoStoreStatusItems(Items); { Store the items }
  1262. End;
  1263. Cur := Cur^.Next; { Next status item }
  1264. End;
  1265. END;
  1266. BEGIN
  1267. TView.Store(S); { TView.Store called }
  1268. DoStoreStatusDefs(Defs); { Store status items }
  1269. END;
  1270. {--TStatusLine--------------------------------------------------------------}
  1271. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1272. {---------------------------------------------------------------------------}
  1273. PROCEDURE TStatusLine.HandleEvent (Var Event: TEvent);
  1274. VAR Mouse: TPoint; T, Tt: PStatusItem;
  1275. FUNCTION ItemMouseIsIn: PStatusItem;
  1276. VAR X, Xi: Word; T: PStatusItem;
  1277. BEGIN
  1278. ItemMouseIsIn := Nil; { Preset fail }
  1279. If (Mouse.Y < 0) OR (Mouse.Y > FontHeight) { Outside view height }
  1280. Then Exit; { Not in view exit }
  1281. X := 0; { Zero x position }
  1282. T := Items; { Start at first item }
  1283. While (T <> Nil) Do Begin { While item valid }
  1284. If (T^.Text <> Nil) Then Begin { Check valid text }
  1285. Xi := X; { Hold initial x value }
  1286. X := Xi + TextWidth(' ' + T^.Text^ + ' '); { Add text width }
  1287. If (Mouse.X >= Xi) AND (Mouse.X < X)
  1288. Then Begin
  1289. ItemMouseIsIn := T; { Selected item }
  1290. Exit; { Now exit }
  1291. End;
  1292. End;
  1293. T := T^.Next; { Next item }
  1294. End;
  1295. END;
  1296. BEGIN
  1297. Inherited HandleEvent(Event); { Call ancestor }
  1298. Case Event.What Of
  1299. evMouseDown: Begin
  1300. T := Nil; { Preset ptr to nil }
  1301. Repeat
  1302. Mouse.X := Event.Where.X - RawOrigin.X; { Local x position }
  1303. Mouse.Y := Event.Where.Y - RawOrigin.Y; { Local y position }
  1304. Tt := ItemMouseIsIn; { Find selected item }
  1305. If (T <> Tt) Then { Item has changed }
  1306. DrawSelect(Tt); { Draw new item }
  1307. T := Tt { Transfer item }
  1308. Until NOT MouseEvent(Event, evMouseMove); { Mouse stopped moving }
  1309. If (T <> Nil) AND CommandEnabled(T^.Command) { Check cmd enabled }
  1310. Then Begin
  1311. Event.What := evCommand; { Command event }
  1312. Event.Command := T^.Command; { Set command value }
  1313. Event.InfoPtr := Nil; { No info ptr }
  1314. PutEvent(Event); { Put event on queue }
  1315. End;
  1316. ClearEvent(Event); { Clear the event }
  1317. DrawSelect(Nil); { Clear the highlight }
  1318. End;
  1319. evKeyDown: Begin { Key down event }
  1320. T := Items; { Start on first item }
  1321. While (T <> Nil) Do Begin { For each valid item }
  1322. If (Event.KeyCode = T^.KeyCode) AND { Check for hot key }
  1323. CommandEnabled(T^.Command) Then Begin { Check cmd enabled }
  1324. Event.What := evCommand; { Change to command }
  1325. Event.Command := T^.Command; { Set command value }
  1326. Event.InfoPtr := Nil; { Clear info ptr }
  1327. Exit; { Now exit }
  1328. End;
  1329. T := T^.Next; { Next item }
  1330. End;
  1331. End;
  1332. evBroadcast:
  1333. If (Event.Command = cmCommandSetChanged) Then { Command set change }
  1334. DrawView; { Redraw view }
  1335. End;
  1336. END;
  1337. {***************************************************************************}
  1338. { TStatusLine OBJECT PRIVATE METHODS }
  1339. {***************************************************************************}
  1340. {--TStatusLine--------------------------------------------------------------}
  1341. { FindItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1342. {---------------------------------------------------------------------------}
  1343. PROCEDURE TStatusLine.FindItems;
  1344. VAR P: PStatusDef;
  1345. BEGIN
  1346. P := Defs; { First status item }
  1347. While (P <> Nil) AND ((HelpCtx < P^.Min) OR
  1348. (HelpCtx > P^.Max)) Do P := P^.Next; { Find status item }
  1349. If (P = Nil) Then Items := Nil Else
  1350. Items := P^.Items; { Return found item }
  1351. END;
  1352. {--TStatusLine--------------------------------------------------------------}
  1353. { DrawSelect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  1354. {---------------------------------------------------------------------------}
  1355. PROCEDURE TStatusLine.DrawSelect (Selected: PStatusItem);
  1356. VAR I, L: Integer; Color, CSelect, CNormal, CSelDisabled, CNormDisabled: Word;
  1357. HintBuf: String; B: TDrawBuffer; T: PStatusItem;
  1358. BEGIN
  1359. CNormal := GetColor($0301); { Normal colour }
  1360. CSelect := GetColor($0604); { Select colour }
  1361. CNormDisabled := GetColor($0202); { Disabled colour }
  1362. CSelDisabled := GetColor($0505); { Select disabled }
  1363. MoveChar(B, ' ', Byte(CNormal), 80); { Clear the buffer }
  1364. T := Items; { First item }
  1365. I := 0; { Clear the count }
  1366. L := 0;
  1367. While (T <> Nil) Do Begin { While valid item }
  1368. If (T^.Text <> Nil) Then Begin { While valid text }
  1369. L := CStrLen(' '+T^.Text^+' '); { Text length }
  1370. If CommandEnabled(T^.Command) Then Begin { Command enabled }
  1371. If T = Selected Then Color := CSelect { Selected colour }
  1372. Else Color := CNormal { Normal colour }
  1373. End Else
  1374. If T = Selected Then Color := CSelDisabled { Selected disabled }
  1375. Else Color := CNormDisabled; { Disabled colour }
  1376. MoveCStr(B[I], ' '+T^.Text^+' ', Color); { Move text to buf }
  1377. Inc(I, L); { Advance position }
  1378. End;
  1379. T := T^.Next; { Next item }
  1380. End;
  1381. HintBuf := Hint(HelpCtx); { Get hint string }
  1382. If (HintBuf <> '') Then Begin { Hint present }
  1383. {$IFNDEF OS_WINDOWS}
  1384. MoveChar(B[I], #179, Byte(CNormal), 1); { '|' char to buffer }
  1385. {$ELSE}
  1386. MoveChar(B[I], #166, Byte(CNormal), 1); { '|' char to buffer }
  1387. {$ENDIF}
  1388. Inc(I, 2); { Move along }
  1389. MoveStr(B[I], HintBuf, Byte(CNormal)); { Move hint to buffer }
  1390. I := I + Length(HintBuf); { Hint length }
  1391. End;
  1392. WriteLine(0, 0, I, 1, B); { Write the buffer }
  1393. If AdvancedMenus Then BicolorRectangle(0, 0,
  1394. RawSize.X, RawSize.Y, White, DarkGray, False); { Add 3d effect }
  1395. END;
  1396. {***************************************************************************}
  1397. { INTERFACE ROUTINES }
  1398. {***************************************************************************}
  1399. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1400. { MENU INTERFACE ROUTINES }
  1401. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1402. {---------------------------------------------------------------------------}
  1403. { NewMenu -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 14May98 LdB }
  1404. {---------------------------------------------------------------------------}
  1405. FUNCTION NewMenu (Items: PMenuItem): PMenu;
  1406. VAR P: PMenu;
  1407. BEGIN
  1408. New(P); { Create new menu }
  1409. If (P <> Nil) Then Begin { Check valid pointer }
  1410. P^.Items := Items; { Hold item list }
  1411. P^.Default := Items; { Set default item }
  1412. End;
  1413. NewMenu := P; { Return menu }
  1414. END;
  1415. {---------------------------------------------------------------------------}
  1416. { DisposeMenu -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 14May98 LdB }
  1417. {---------------------------------------------------------------------------}
  1418. PROCEDURE DisposeMenu (Menu: PMenu);
  1419. VAR P, Q: PMenuItem;
  1420. BEGIN
  1421. If (Menu <> Nil) Then Begin { Valid menu item }
  1422. P := Menu^.Items; { First item in list }
  1423. While (P <> Nil) Do Begin { Item is valid }
  1424. If (P^.Name <> Nil) Then Begin { Valid name pointer }
  1425. DisposeStr(P^.Name); { Dispose of name }
  1426. If (P^.Command <> 0) Then
  1427. DisposeStr(P^.Param) Else { Dispose parameter }
  1428. DisposeMenu(P^.SubMenu); { Dispose submenu }
  1429. End;
  1430. Q := P; { Hold pointer }
  1431. P := P^.Next; { Move to next item }
  1432. Dispose(Q); { Dispose of item }
  1433. End;
  1434. Dispose(Menu); { Dispose of menu }
  1435. End;
  1436. END;
  1437. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1438. { MENU ITEM ROUTINES }
  1439. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1440. {---------------------------------------------------------------------------}
  1441. { NewLine -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 14May98 LdB }
  1442. {---------------------------------------------------------------------------}
  1443. FUNCTION NewLine (Next: PMenuItem): PMenuItem;
  1444. VAR P: PMenuItem;
  1445. BEGIN
  1446. New(P); { Allocate memory }
  1447. If (P <> Nil) Then Begin { Check valid pointer }
  1448. P^.Next := Next; { Hold next menu item }
  1449. P^.Name := Nil; { Clear name ptr }
  1450. P^.HelpCtx := hcNoContext; { Clear help context }
  1451. End;
  1452. NewLine := P; { Return new line }
  1453. END;
  1454. {---------------------------------------------------------------------------}
  1455. { NewItem -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 14May98 LdB }
  1456. {---------------------------------------------------------------------------}
  1457. FUNCTION NewItem (Name, Param: TMenuStr; KeyCode: Word; Command: Word;
  1458. AHelpCtx: Word; Next: PMenuItem): PMenuItem;
  1459. VAR P: PMenuItem; R: TRect; T: PView;
  1460. BEGIN
  1461. If (Name <> '') AND (Command <> 0) Then Begin
  1462. New(P); { Allocate memory }
  1463. If (P <> Nil) Then Begin { Check valid pointer }
  1464. P^.Next := Next; { Hold next item }
  1465. P^.Name := NewStr(Name); { Hold item name }
  1466. P^.Command := Command; { Hold item command }
  1467. R.Assign(1, 1, 10, 10); { Random assignment }
  1468. T := New(PView, Init(R)); { Create a view }
  1469. If (T <> Nil) Then Begin
  1470. P^.Disabled := NOT T^.CommandEnabled(Command);
  1471. Dispose(T, Done); { Dispose of view }
  1472. End Else P^.Disabled := True;
  1473. P^.KeyCode := KeyCode; { Hold item keycode }
  1474. P^.HelpCtx := AHelpCtx; { Hold help context }
  1475. P^.Param := NewStr(Param); { Hold parameter }
  1476. End;
  1477. NewItem := P; { Return item }
  1478. End Else NewItem := Next; { Move forward }
  1479. END;
  1480. {---------------------------------------------------------------------------}
  1481. { NewSubMenu -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 14May98 LdB }
  1482. {---------------------------------------------------------------------------}
  1483. FUNCTION NewSubMenu (Name: TMenuStr; AHelpCtx: Word; SubMenu: PMenu;
  1484. Next: PMenuItem): PMenuItem;
  1485. VAR P: PMenuItem;
  1486. BEGIN
  1487. If (Name <> '') AND (SubMenu <> Nil) Then Begin
  1488. New(P); { Allocate memory }
  1489. If (P <> Nil) Then Begin { Check valid pointer }
  1490. P^.Next := Next; { Hold next item }
  1491. P^.Name := NewStr(Name); { Hold submenu name }
  1492. P^.Command := 0; { Clear item command }
  1493. P^.Disabled := False; { Item not disabled }
  1494. P^.HelpCtx := AHelpCtx; { Set help context }
  1495. P^.SubMenu := SubMenu; { Hold next submenu }
  1496. End;
  1497. NewSubMenu := P; { Return submenu }
  1498. End Else NewSubMenu := Next; { Return next item }
  1499. END;
  1500. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1501. { STATUS INTERFACE ROUTINES }
  1502. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1503. {---------------------------------------------------------------------------}
  1504. { NewStatusDef -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 15May98 LdB }
  1505. {---------------------------------------------------------------------------}
  1506. FUNCTION NewStatusDef (AMin, AMax: Word; AItems: PStatusItem;
  1507. ANext:PStatusDef): PStatusDef;
  1508. VAR T: PStatusDef;
  1509. BEGIN
  1510. New(T); { Allocate memory }
  1511. If (T <> Nil) Then Begin { Check valid pointer }
  1512. T^.Next := ANext; { Set next item }
  1513. T^.Min := AMin; { Hold min value }
  1514. T^.Max := AMax; { Hold max value }
  1515. T^.Items := AItems; { Hold item list }
  1516. End;
  1517. NewStatusDef := T; { Return status }
  1518. END;
  1519. {---------------------------------------------------------------------------}
  1520. { NewStatusKey -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 15May98 LdB }
  1521. {---------------------------------------------------------------------------}
  1522. FUNCTION NewStatusKey (AText: String; AKeyCode: Word; ACommand: Word;
  1523. ANext: PStatusItem): PStatusItem;
  1524. VAR T: PStatusItem;
  1525. BEGIN
  1526. New(T); { Allocate memory }
  1527. If (T <> Nil) Then Begin { Check valid pointer }
  1528. T^.Text := NewStr(AText); { Hold text string }
  1529. T^.KeyCode := AKeyCode; { Hold keycode }
  1530. T^.Command := ACommand; { Hold command }
  1531. T^.Next := ANext; { Pointer to next }
  1532. End;
  1533. NewStatusKey := T; { Return status item }
  1534. END;
  1535. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1536. { OBJECT REGISTER ROUTINES }
  1537. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1538. {---------------------------------------------------------------------------}
  1539. { RegisterMenus -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 15May98 LdB }
  1540. {---------------------------------------------------------------------------}
  1541. PROCEDURE RegisterMenus;
  1542. BEGIN
  1543. RegisterType(RMenuBar); { Register bar menu }
  1544. RegisterType(RMenuBox); { Register menu box }
  1545. RegisterType(RStatusLine); { Register status line }
  1546. RegisterType(RMenuPopup); { Register popup menu }
  1547. END;
  1548. END.
  1549. {
  1550. $Log$
  1551. Revision 1.4 2001-04-10 21:57:55 pierre
  1552. + first adds for Use_API define
  1553. }