menus.pas 87 KB

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