menus.pas 87 KB

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