menus.pas 84 KB

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