menus.pas 80 KB

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