menus.pas 84 KB

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