menus.pas 80 KB

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