menus.pas 86 KB

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