menus.pas 84 KB

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