wviews.pas 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {$I globdir.inc}
  11. unit WViews;
  12. interface
  13. uses Objects,Drivers,Views,Menus,Dialogs;
  14. const
  15. evIdle = $8000;
  16. cmCopyWin = 240;
  17. cmPasteWin = 241;
  18. cmSelectAll = 246;
  19. cmUnselect = 247;
  20. cmLocalMenu = 54100;
  21. cmUpdate = 54101;
  22. cmListFocusChanged = 54102;
  23. mfUserBtn1 = $00010000;
  24. mfUserBtn2 = $00020000;
  25. mfUserBtn3 = $00040000;
  26. mfUserBtn4 = $00080000;
  27. mfCantCancel = $00100000;
  28. cmUserBtn1 = $fee0;
  29. cmUserBtn2 = $fee1;
  30. cmUserBtn3 = $fee2;
  31. cmUserBtn4 = $fee3;
  32. CPlainCluster = #7#8#9#9;
  33. type
  34. longstring = ansistring;
  35. PCenterDialog = ^TCenterDialog;
  36. TCenterDialog = object(TDialog)
  37. constructor Init(var Bounds: TRect; ATitle: TTitleStr);
  38. end;
  39. PAdvancedMenuBox = ^TAdvancedMenuBox;
  40. TAdvancedMenuBox = object(TMenuBox)
  41. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  42. AParentMenu: PMenuView): PMenuView; virtual;
  43. function Execute: Word; virtual;
  44. end;
  45. PAdvancedMenuPopUp = ^TAdvancedMenuPopup;
  46. TAdvancedMenuPopUp = object(TMenuPopup)
  47. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  48. AParentMenu: PMenuView): PMenuView; virtual;
  49. function Execute: Word; virtual;
  50. end;
  51. PAdvancedMenuBar = ^TAdvancedMenuBar;
  52. TAdvancedMenuBar = object(TMenuBar)
  53. constructor Init(var Bounds: TRect; AMenu: PMenu);
  54. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  55. AParentMenu: PMenuView): PMenuView; virtual;
  56. procedure Update; virtual;
  57. function GetMenuItem(cm : word) : PMenuItem;
  58. procedure HandleEvent(var Event: TEvent); virtual;
  59. function Execute: Word; virtual;
  60. end;
  61. PAdvancedStaticText = ^TAdvancedStaticText;
  62. TAdvancedStaticText = object(TStaticText)
  63. procedure SetText(S: string); virtual;
  64. end;
  65. PAdvancedListBox = ^TAdvancedListBox;
  66. TAdvancedListBox = object(TListBox)
  67. Default: boolean;
  68. procedure FocusItem(Item: sw_integer); virtual;
  69. procedure HandleEvent(var Event: TEvent); virtual;
  70. constructor Load(var S: TStream);
  71. procedure Store(var S: TStream);
  72. end;
  73. PNoUpdateButton = ^TNoUpdateButton;
  74. TNoUpdateButton = object(TButton)
  75. procedure HandleEvent(var Event: TEvent); virtual;
  76. end;
  77. TLocalMenuListBox = object(TAdvancedListBox)
  78. procedure HandleEvent(var Event: TEvent); virtual;
  79. procedure LocalMenu(P: TPoint); virtual;
  80. function GetLocalMenu: PMenu; virtual;
  81. function GetCommandTarget: PView; virtual;
  82. private
  83. LastLocalCmd: word;
  84. end;
  85. PColorStaticText = ^TColorStaticText;
  86. TColorStaticText = object(TAdvancedStaticText)
  87. Color: word;
  88. DontWrap: boolean;
  89. Delta: TPoint;
  90. constructor Init(var Bounds: TRect; AText: String; AColor: word; AWrap: boolean);
  91. function GetPalette: PPalette; virtual;
  92. procedure Draw; virtual;
  93. constructor Load(var S: TStream);
  94. procedure Store(var S: TStream);
  95. end;
  96. PHSListBox = ^THSListBox;
  97. THSListBox = object(TLocalMenuListBox)
  98. constructor Init(var Bounds: TRect; ANumCols: Word; AHScrollBar, AVScrollBar: PScrollBar);
  99. function SaveToFile(const AFileName: string): boolean; virtual;
  100. function SaveAs: Boolean; virtual;
  101. end;
  102. PDlgWindow = ^TDlgWindow;
  103. TDlgWindow = object(TDialog)
  104. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer);
  105. procedure HandleEvent(var Event: TEvent); virtual;
  106. procedure Update; virtual;
  107. end;
  108. PAdvancedStatusLine = ^TAdvancedStatusLine;
  109. TAdvancedStatusLine = object(TStatusLine)
  110. StatusText: PString;
  111. function GetStatusText: string; virtual;
  112. procedure SetStatusText(const S: string); virtual;
  113. procedure ClearStatusText; virtual;
  114. procedure Draw; virtual;
  115. end;
  116. PDropDownListBox = ^TDropDownListBox;
  117. PDDHelperLB = ^TDDHelperLB;
  118. TDDHelperLB = object(TLocalMenuListBox)
  119. constructor Init(ALink: PDropDownListBox; var Bounds: TRect; ANumCols: Word; AScrollBar: PScrollBar);
  120. procedure HandleEvent(var Event: TEvent); virtual;
  121. procedure SetState(AState: Word; Enable: Boolean); virtual;
  122. procedure SelectItem(Item: Sw_Integer); virtual;
  123. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  124. function GetLocalMenu: PMenu; virtual;
  125. function GetCommandTarget: PView; virtual;
  126. private
  127. Link : PDropDownListBox;
  128. LastTT: longint;
  129. InClose: boolean;
  130. end;
  131. TDropDownListBox = object(TView)
  132. Text: string;
  133. Focused: sw_integer;
  134. List: PCollection;
  135. constructor Init(var Bounds: TRect; ADropLineCount: Sw_integer; AList: PCollection);
  136. procedure HandleEvent(var Event: TEvent); virtual;
  137. function GetText(Item: pointer; MaxLen: sw_integer): string; virtual;
  138. procedure NewList(AList: PCollection); virtual;
  139. procedure CreateListBox(var R: TRect);
  140. procedure DropList(Drop: boolean); virtual;
  141. function GetItemCount: sw_integer; virtual;
  142. procedure FocusItem(Item: sw_integer); virtual;
  143. function LBGetLocalMenu: PMenu; virtual;
  144. function LBGetCommandTarget: PView; virtual;
  145. procedure SetState(AState: Word; Enable: Boolean); virtual;
  146. procedure Draw; virtual;
  147. function GetPalette: PPalette; virtual;
  148. destructor Done; virtual;
  149. private
  150. DropLineCount: Sw_integer;
  151. ListDropped : boolean;
  152. ListBox : PDDHelperLB;
  153. SB : PScrollBar;
  154. end;
  155. PGroupView = ^TGroupView;
  156. TGroupView = object(TLabel)
  157. constructor Init(var Bounds: TRect; AText: String; ALink: PView);
  158. procedure Draw; virtual;
  159. end;
  160. PPlainCheckBoxes = ^TPlainCheckBoxes;
  161. TPlainCheckBoxes = object(TCheckBoxes)
  162. function GetPalette: PPalette; virtual;
  163. end;
  164. PPlainRadioButtons = ^TPlainRadioButtons;
  165. TPlainRadioButtons = object(TRadioButtons)
  166. function GetPalette: PPalette; virtual;
  167. end;
  168. PPanel = ^TPanel;
  169. TPanel = object(TGroup)
  170. constructor Init(var Bounds: TRect);
  171. end;
  172. PAdvMessageBox = ^TAdvMessageBox;
  173. TAdvMessageBox = object(TDialog)
  174. CanCancel: boolean;
  175. procedure HandleEvent(var Event: TEvent); virtual;
  176. end;
  177. procedure InsertOK(ADialog: PDialog);
  178. procedure InsertButtons(ADialog: PDialog);
  179. procedure Bug(const S: string; Params: pointer);
  180. procedure ErrorBox(const S: string; Params: pointer);
  181. procedure WarningBox(const S: string; Params: pointer);
  182. procedure InformationBox(const S: string; Params: pointer);
  183. function OKCancelBox(const S: string; Params: pointer): word;
  184. function ConfirmBox(const S: string; Params: pointer; CanCancel: boolean): word;
  185. function ChoiceBox(const S: string; Params: pointer; Buttons: array of string; CanCancel: boolean): word;
  186. procedure ShowMessage(Msg: string);
  187. procedure HideMessage;
  188. function SearchMenuItem(Menu: PMenu; Cmd: word): PMenuItem;
  189. procedure SetMenuItemParam(Menu: PMenuItem; Param: string);
  190. function IsSubMenu(P: PMenuItem): boolean;
  191. function IsSeparator(P: PMenuItem): boolean;
  192. function UpdateMenu(M: PMenu): boolean;
  193. function SearchSubMenu(M: PMenu; Index: Sw_integer): PMenuItem;
  194. procedure AppendMenuItem(M: PMenu; I: PMenuItem);
  195. procedure RemoveMenuItem(Menu: PMenu; I: PMenuItem);
  196. function GetMenuItemBefore(Menu:PMenu; BeforeOf: PMenuItem): PMenuItem;
  197. procedure NotImplemented;
  198. function ColorIndex(Color: byte): word;
  199. var FormatParams : array[1..20] of ptrint;
  200. FormatParamCount : integer;
  201. FormatParamStrs : array[1..10] of string;
  202. FormatParamStrCount: integer;
  203. procedure ClearFormatParams;
  204. procedure AddFormatParam(P: pointer);
  205. procedure AddFormatParamInt(L: longint);
  206. procedure AddFormatParamChar(C: char);
  207. procedure AddFormatParamStr(const S: string);
  208. function FormatStrF(const Format: string; var Params): string;
  209. function FormatStrStr(const Format, Param: string): string;
  210. function FormatStrStr2(const Format, Param1,Param2: string): string;
  211. function FormatStrStr3(const Format, Param1,Param2,Param3: string): string;
  212. function FormatStrInt(const Format: string; L: longint): string;
  213. const UserButtonName : array[1..4] of string[40] = ('User~1~','User~2~','User~3~','User~4~');
  214. procedure InitAdvMsgBox;
  215. function AdvMessageBox(const Msg: String; Params: Pointer; AOptions: longint): Word;
  216. function AdvMessageBoxRect(var R: TRect; const Msg: String; Params: Pointer; AOptions: longint): Word;
  217. procedure DoneAdvMsgBox;
  218. procedure RegisterWViews;
  219. implementation
  220. uses Mouse,
  221. { Resource,}
  222. {$ifdef WinClipSupported}
  223. WinClip,
  224. FpConst,
  225. {$endif WinClipSupported}
  226. FVConsts,
  227. App,MsgBox,StdDlg,
  228. WConsts,WUtils;
  229. {$ifndef NOOBJREG}
  230. const
  231. RAdvancedListBox: TStreamRec = (
  232. ObjType: 1120;
  233. VmtLink: Ofs(TypeOf(TAdvancedListBox)^);
  234. Load: @TAdvancedListBox.Load;
  235. Store: @TAdvancedListBox.Store
  236. );
  237. RColorStaticText: TStreamRec = (
  238. ObjType: 1121;
  239. VmtLink: Ofs(TypeOf(TColorStaticText)^);
  240. Load: @TColorStaticText.Load;
  241. Store: @TColorStaticText.Store
  242. );
  243. RHSListBox: TStreamRec = (
  244. ObjType: 1122;
  245. VmtLink: Ofs(TypeOf(THSListBox)^);
  246. Load: @THSListBox.Load;
  247. Store: @THSListBox.Store
  248. );
  249. RDlgWindow: TStreamRec = (
  250. ObjType: 1123;
  251. VmtLink: Ofs(TypeOf(TDlgWindow)^);
  252. Load: @TDlgWindow.Load;
  253. Store: @TDlgWindow.Store
  254. );
  255. {$endif}
  256. {$ifdef USERESSTRINGS}
  257. resourcestring
  258. {$else}
  259. const
  260. {$endif}
  261. sConfirm='Confirm';
  262. sError='Error';
  263. sInformation='Information';
  264. sWarning='Warning';
  265. const
  266. MessageDialog : PCenterDialog = nil;
  267. UserButtonCmd : array[Low(UserButtonName)..High(UserButtonName)] of word = (cmUserBtn1,cmUserBtn2,cmUserBtn3,cmUserBtn4);
  268. {$ifdef WinClipSupported}
  269. FromWinClipCmds : TCommandSet = ([cmPasteWin]);
  270. {$endif WinClipSupported}
  271. function ColorIndex(Color: byte): word;
  272. begin
  273. ColorIndex:=(Color and $0f)+(Color and $0f) shl 4;
  274. end;
  275. {*****************************************************************************
  276. TCenterDialog
  277. *****************************************************************************}
  278. constructor TCenterDialog.Init(var Bounds: TRect; ATitle: TTitleStr);
  279. begin
  280. inherited Init(Bounds,ATitle);
  281. Options:=Options or ofCentered;
  282. end;
  283. function TAdvancedMenuBox.NewSubView(var Bounds: TRect; AMenu: PMenu;
  284. AParentMenu: PMenuView): PMenuView;
  285. begin
  286. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  287. end;
  288. function TAdvancedMenuBox.Execute: word;
  289. type
  290. MenuAction = (DoNothing, DoSelect, DoReturn);
  291. var
  292. AutoSelect: Boolean;
  293. Action: MenuAction;
  294. Ch: Char;
  295. Res: Word;
  296. ItemShown, P: PMenuItem;
  297. {$ifdef WinClipSupported}
  298. PPW: PMenuItem;
  299. WinClipEmpty: boolean;
  300. {$endif WinClipSupported}
  301. Target: PMenuView;
  302. R: TRect;
  303. E: TEvent;
  304. MouseActive: Boolean;
  305. function IsDisabled(Item: PMenuItem): boolean;
  306. var Found: boolean;
  307. begin
  308. Found:=Item^.Disabled or IsSeparator(Item);
  309. if (Found=false) and (IsSubMenu(Item)=false) then
  310. Found:=CommandEnabled(Item^.Command)=false;
  311. IsDisabled:=Found;
  312. end;
  313. procedure TrackMouse;
  314. var
  315. Mouse: TPoint;
  316. R: TRect;
  317. begin
  318. MakeLocal(E.Where, Mouse);
  319. Current := Menu^.Items;
  320. while Current <> nil do
  321. begin
  322. GetItemRect(Current, R);
  323. if R.Contains(Mouse) then
  324. begin
  325. MouseActive := True;
  326. Break;
  327. end;
  328. Current := Current^.Next;
  329. end;
  330. if (Current<>nil) and IsDisabled(Current) then
  331. begin
  332. Current:=nil;
  333. MouseActive:=false;
  334. end;
  335. end;
  336. procedure TrackKey(FindNext: Boolean);
  337. procedure NextItem;
  338. begin
  339. Current := Current^.Next;
  340. if Current = nil then Current := Menu^.Items;
  341. end;
  342. procedure PrevItem;
  343. var
  344. P: PMenuItem;
  345. begin
  346. P := Current;
  347. if P = Menu^.Items then P := nil;
  348. repeat NextItem until Current^.Next = P;
  349. end;
  350. begin
  351. if Current <> nil then
  352. repeat
  353. if FindNext then NextItem else PrevItem;
  354. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  355. end;
  356. function MouseInOwner: Boolean;
  357. var
  358. Mouse: TPoint;
  359. R: TRect;
  360. begin
  361. MouseInOwner := False;
  362. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  363. begin
  364. ParentMenu^.MakeLocal(E.Where, Mouse);
  365. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  366. MouseInOwner := R.Contains(Mouse);
  367. end;
  368. end;
  369. function MouseInMenus: Boolean;
  370. var
  371. P: PMenuView;
  372. begin
  373. P := ParentMenu;
  374. while (P <> nil) and (P^.MouseInView(E.Where)=false) do
  375. P := P^.ParentMenu;
  376. MouseInMenus := P <> nil;
  377. end;
  378. function TopMenu: PMenuView;
  379. var
  380. P: PMenuView;
  381. begin
  382. P := @Self;
  383. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  384. TopMenu := P;
  385. end;
  386. begin
  387. AutoSelect := False; E.What:=evNothing;
  388. Res := 0;
  389. ItemShown := nil;
  390. {$ifdef WinClipSupported}
  391. PPW:=SearchMenuItem(Menu,cmPasteWin);
  392. if Assigned(PPW) then
  393. begin
  394. WinClipEmpty:=GetTextWinClipboardSize=0;
  395. SetCmdState(FromWinClipCmds,Not WinClipEmpty);
  396. PPW^.disabled:=WinClipEmpty;
  397. end;
  398. {$endif WinClipSupported}
  399. Current := Menu^.Default;
  400. MouseActive := False;
  401. if UpdateMenu(Menu) then
  402. begin
  403. if Current<>nil then
  404. if Current^.Disabled then
  405. TrackKey(true);
  406. repeat
  407. Action := DoNothing;
  408. {$ifdef WinClipSupported}
  409. If Assigned(PPW) then
  410. begin
  411. If WinClipEmpty and (GetTextWinClipboardSize>0) then
  412. begin
  413. WinClipEmpty:=false;
  414. SetCmdState(FromWinClipCmds,true);
  415. PPW^.disabled:=WinClipEmpty;
  416. DrawView;
  417. end
  418. else if Not WinClipEmpty and (GetTextWinClipboardSize=0) then
  419. begin
  420. WinClipEmpty:=true;
  421. SetCmdState(FromWinClipCmds,false);
  422. PPW^.disabled:=WinClipEmpty;
  423. DrawView;
  424. end;
  425. end;
  426. {$endif WinClipSupported}
  427. GetEvent(E);
  428. case E.What of
  429. evMouseDown:
  430. if MouseInView(E.Where) or MouseInOwner then
  431. begin
  432. TrackMouse;
  433. if Size.Y = 1 then AutoSelect := True;
  434. end else Action := DoReturn;
  435. evMouseUp:
  436. begin
  437. TrackMouse;
  438. if MouseInOwner then
  439. Current := Menu^.Default
  440. else
  441. if (Current <> nil) and (Current^.Name <> nil) then
  442. Action := DoSelect
  443. else
  444. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  445. else
  446. begin
  447. Current := Menu^.Default;
  448. if Current = nil then Current := Menu^.Items;
  449. Action := DoNothing;
  450. end;
  451. end;
  452. evMouseMove:
  453. if E.Buttons <> 0 then
  454. begin
  455. TrackMouse;
  456. if not (MouseInView(E.Where) or MouseInOwner) and
  457. MouseInMenus then Action := DoReturn;
  458. end;
  459. evKeyDown:
  460. case CtrlToArrow(E.KeyCode) of
  461. kbUp, kbDown:
  462. if Size.Y <> 1 then
  463. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  464. if E.KeyCode = kbDown then AutoSelect := True;
  465. kbLeft, kbRight:
  466. if ParentMenu = nil then
  467. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  468. Action := DoReturn;
  469. kbHome, kbEnd:
  470. if Size.Y <> 1 then
  471. begin
  472. Current := Menu^.Items;
  473. if E.KeyCode = kbEnd then TrackKey(False);
  474. end;
  475. kbEnter:
  476. begin
  477. if Size.Y = 1 then AutoSelect := True;
  478. Action := DoSelect;
  479. end;
  480. kbEsc:
  481. begin
  482. Action := DoReturn;
  483. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  484. ClearEvent(E);
  485. end;
  486. else
  487. Target := @Self;
  488. Ch := GetAltChar(E.KeyCode);
  489. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  490. P := Target^.FindItem(Ch);
  491. if P = nil then
  492. begin
  493. P := TopMenu^.HotKey(E.KeyCode);
  494. if (P <> nil) and CommandEnabled(P^.Command) then
  495. begin
  496. Res := P^.Command;
  497. Action := DoReturn;
  498. end
  499. end else
  500. if Target = @Self then
  501. begin
  502. if Size.Y = 1 then AutoSelect := True;
  503. Action := DoSelect;
  504. Current := P;
  505. end else
  506. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  507. Action := DoReturn;
  508. end;
  509. evCommand:
  510. if E.Command = cmMenu then
  511. begin
  512. AutoSelect := False;
  513. if ParentMenu <> nil then Action := DoReturn;
  514. end else Action := DoReturn;
  515. end;
  516. if ItemShown <> Current then
  517. begin
  518. ItemShown := Current;
  519. DrawView;
  520. end;
  521. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  522. if Current <> nil then with Current^ do if Name <> nil then
  523. if Command = 0 then
  524. begin
  525. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  526. GetItemRect(Current, R);
  527. R.A.X := R.A.X + Origin.X;
  528. R.A.Y := R.B.Y + Origin.Y;
  529. R.B := Owner^.Size;
  530. if Size.Y = 1 then Dec(R.A.X);
  531. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  532. Res := Owner^.ExecView(Target);
  533. Dispose(Target, Done);
  534. end else if Action = DoSelect then Res := Command;
  535. if (Res <> 0) and CommandEnabled(Res) then
  536. begin
  537. Action := DoReturn;
  538. ClearEvent(E);
  539. end
  540. else
  541. Res := 0;
  542. until Action = DoReturn;
  543. end;
  544. if E.What <> evNothing then
  545. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  546. if Current <> nil then
  547. begin
  548. Menu^.Default := Current;
  549. Current := nil;
  550. DrawView;
  551. end;
  552. Execute := Res;
  553. end;
  554. function TAdvancedMenuPopup.NewSubView(var Bounds: TRect; AMenu: PMenu;
  555. AParentMenu: PMenuView): PMenuView;
  556. begin
  557. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  558. end;
  559. function TAdvancedMenuPopup.Execute: word;
  560. type
  561. MenuAction = (DoNothing, DoSelect, DoReturn);
  562. var
  563. AutoSelect: Boolean;
  564. Action: MenuAction;
  565. Ch: Char;
  566. Res: Word;
  567. ItemShown, P: PMenuItem;
  568. Target: PMenuView;
  569. R: TRect;
  570. E: TEvent;
  571. MouseActive: Boolean;
  572. function IsDisabled(Item: PMenuItem): boolean;
  573. var Found: boolean;
  574. begin
  575. Found:=Item^.Disabled or IsSeparator(Item);
  576. if (Found=false) and (IsSubMenu(Item)=false) then
  577. Found:=CommandEnabled(Item^.Command)=false;
  578. IsDisabled:=Found;
  579. end;
  580. procedure TrackMouse;
  581. var
  582. Mouse: TPoint;
  583. R: TRect;
  584. begin
  585. MakeLocal(E.Where, Mouse);
  586. Current := Menu^.Items;
  587. while Current <> nil do
  588. begin
  589. GetItemRect(Current, R);
  590. if R.Contains(Mouse) then
  591. begin
  592. MouseActive := True;
  593. Break;
  594. end;
  595. Current := Current^.Next;
  596. end;
  597. if (Current<>nil) and IsDisabled(Current) then
  598. begin
  599. Current:=nil;
  600. MouseActive:=false;
  601. end;
  602. end;
  603. procedure TrackKey(FindNext: Boolean);
  604. procedure NextItem;
  605. begin
  606. Current := Current^.Next;
  607. if Current = nil then Current := Menu^.Items;
  608. end;
  609. procedure PrevItem;
  610. var
  611. P: PMenuItem;
  612. begin
  613. P := Current;
  614. if P = Menu^.Items then P := nil;
  615. repeat NextItem until Current^.Next = P;
  616. end;
  617. begin
  618. if Current <> nil then
  619. repeat
  620. if FindNext then NextItem else PrevItem;
  621. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  622. end;
  623. function MouseInOwner: Boolean;
  624. var
  625. Mouse: TPoint;
  626. R: TRect;
  627. begin
  628. MouseInOwner := False;
  629. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  630. begin
  631. ParentMenu^.MakeLocal(E.Where, Mouse);
  632. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  633. MouseInOwner := R.Contains(Mouse);
  634. end;
  635. end;
  636. function MouseInMenus: Boolean;
  637. var
  638. P: PMenuView;
  639. begin
  640. P := ParentMenu;
  641. while (P <> nil) and (P^.MouseInView(E.Where)=false) do
  642. P := P^.ParentMenu;
  643. MouseInMenus := P <> nil;
  644. end;
  645. function TopMenu: PMenuView;
  646. var
  647. P: PMenuView;
  648. begin
  649. P := @Self;
  650. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  651. TopMenu := P;
  652. end;
  653. begin
  654. AutoSelect := False; E.What:=evNothing;
  655. Res := 0;
  656. ItemShown := nil;
  657. Current := Menu^.Default;
  658. MouseActive := False;
  659. if UpdateMenu(Menu) then
  660. begin
  661. if Current<>nil then
  662. if Current^.Disabled then
  663. TrackKey(true);
  664. repeat
  665. Action := DoNothing;
  666. GetEvent(E);
  667. case E.What of
  668. evMouseDown:
  669. if MouseInView(E.Where) or MouseInOwner then
  670. begin
  671. TrackMouse;
  672. if Size.Y = 1 then AutoSelect := True;
  673. end else Action := DoReturn;
  674. evMouseUp:
  675. begin
  676. TrackMouse;
  677. if MouseInOwner then
  678. Current := Menu^.Default
  679. else
  680. if (Current <> nil) and (Current^.Name <> nil) then
  681. Action := DoSelect
  682. else
  683. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  684. else
  685. begin
  686. Current := Menu^.Default;
  687. if Current = nil then Current := Menu^.Items;
  688. Action := DoNothing;
  689. end;
  690. end;
  691. evMouseMove:
  692. if E.Buttons <> 0 then
  693. begin
  694. TrackMouse;
  695. if not (MouseInView(E.Where) or MouseInOwner) and
  696. MouseInMenus then Action := DoReturn;
  697. end;
  698. evKeyDown:
  699. case CtrlToArrow(E.KeyCode) of
  700. kbUp, kbDown:
  701. if Size.Y <> 1 then
  702. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  703. if E.KeyCode = kbDown then AutoSelect := True;
  704. kbLeft, kbRight:
  705. if ParentMenu = nil then
  706. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  707. Action := DoReturn;
  708. kbHome, kbEnd:
  709. if Size.Y <> 1 then
  710. begin
  711. Current := Menu^.Items;
  712. if E.KeyCode = kbEnd then TrackKey(False);
  713. end;
  714. kbEnter:
  715. begin
  716. if Size.Y = 1 then AutoSelect := True;
  717. Action := DoSelect;
  718. end;
  719. kbEsc:
  720. begin
  721. Action := DoReturn;
  722. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  723. ClearEvent(E);
  724. end;
  725. else
  726. Target := @Self;
  727. Ch := GetAltChar(E.KeyCode);
  728. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  729. P := Target^.FindItem(Ch);
  730. if P = nil then
  731. begin
  732. P := TopMenu^.HotKey(E.KeyCode);
  733. if (P <> nil) and CommandEnabled(P^.Command) then
  734. begin
  735. Res := P^.Command;
  736. Action := DoReturn;
  737. end
  738. end else
  739. if Target = @Self then
  740. begin
  741. if Size.Y = 1 then AutoSelect := True;
  742. Action := DoSelect;
  743. Current := P;
  744. end else
  745. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  746. Action := DoReturn;
  747. end;
  748. evCommand:
  749. if E.Command = cmMenu then
  750. begin
  751. AutoSelect := False;
  752. if ParentMenu <> nil then Action := DoReturn;
  753. end else Action := DoReturn;
  754. end;
  755. if ItemShown <> Current then
  756. begin
  757. ItemShown := Current;
  758. DrawView;
  759. end;
  760. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  761. if Current <> nil then with Current^ do if Name <> nil then
  762. if Command = 0 then
  763. begin
  764. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  765. GetItemRect(Current, R);
  766. R.A.X := R.A.X + Origin.X;
  767. R.A.Y := R.B.Y + Origin.Y;
  768. R.B := Owner^.Size;
  769. if Size.Y = 1 then Dec(R.A.X);
  770. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  771. Res := Owner^.ExecView(Target);
  772. Dispose(Target, Done);
  773. end else if Action = DoSelect then Res := Command;
  774. if (Res <> 0) and CommandEnabled(Res) then
  775. begin
  776. Action := DoReturn;
  777. ClearEvent(E);
  778. end
  779. else
  780. Res := 0;
  781. until Action = DoReturn;
  782. end;
  783. if E.What <> evNothing then
  784. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  785. if Current <> nil then
  786. begin
  787. Menu^.Default := Current;
  788. Current := nil;
  789. DrawView;
  790. end;
  791. Execute := Res;
  792. end;
  793. constructor TAdvancedMenuBar.Init(var Bounds: TRect; AMenu: PMenu);
  794. begin
  795. inherited Init(Bounds, AMenu);
  796. EventMask:=EventMask or evBroadcast;
  797. GrowMode:=gfGrowHiX;
  798. end;
  799. function TAdvancedMenuBar.NewSubView(var Bounds: TRect; AMenu: PMenu;
  800. AParentMenu: PMenuView): PMenuView;
  801. begin
  802. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  803. end;
  804. procedure TAdvancedMenuBar.Update;
  805. begin
  806. UpdateMenu(Menu);
  807. DrawView;
  808. end;
  809. function TAdvancedMenuBar.GetMenuItem(cm : word) : PMenuItem;
  810. type
  811. PItemChain = ^TItemChain;
  812. TItemChain = record
  813. Next : PMenuItem;
  814. Up : PItemChain;
  815. end;
  816. var Cur : PMenuItem;
  817. Up,NUp : PItemChain;
  818. begin
  819. Cur:=Menu^.Items;
  820. Up:=nil;
  821. if cm=0 then
  822. begin
  823. GetMenuItem:=nil;
  824. exit;
  825. end;
  826. while assigned(Cur) and (Cur^.Command<>cm) do
  827. begin
  828. if (Cur^.Command=0) and assigned(Cur^.SubMenu) and
  829. assigned(Cur^.Name) and
  830. assigned(Cur^.SubMenu^.Items) then
  831. {subMenu}
  832. begin
  833. If assigned(Cur^.Next) then
  834. begin
  835. New(Nup);
  836. Nup^.Up:=Up;
  837. Nup^.next:=Cur^.Next;
  838. Up:=Nup;
  839. end;
  840. Cur:=Cur^.SubMenu^.Items;
  841. end
  842. else
  843. { normal item }
  844. begin
  845. if assigned(Cur^.Next) then
  846. Cur:=Cur^.Next
  847. else if assigned(Up) then
  848. begin
  849. Cur:=Up^.next;
  850. NUp:=Up;
  851. Up:=Up^.Up;
  852. Dispose(NUp);
  853. end
  854. else
  855. Cur:=Nil;
  856. end;
  857. end;
  858. GetMenuItem:=Cur;
  859. While assigned(Up) do
  860. begin
  861. NUp:=Up;
  862. Up:=Up^.up;
  863. Dispose(NUp);
  864. end;
  865. end;
  866. procedure TAdvancedMenuBar.HandleEvent(var Event: TEvent);
  867. begin
  868. case Event.What of
  869. evBroadcast :
  870. case Event.Command of
  871. cmCommandSetChanged : Update;
  872. cmUpdate : Update;
  873. end;
  874. end;
  875. inherited HandleEvent(Event);
  876. end;
  877. function TAdvancedMenuBar.Execute: word;
  878. type
  879. MenuAction = (DoNothing, DoSelect, DoReturn);
  880. var
  881. AutoSelect: Boolean;
  882. Action: MenuAction;
  883. Ch: Char;
  884. Res: Word;
  885. ItemShown, P: PMenuItem;
  886. Target: PMenuView;
  887. R: TRect;
  888. E: TEvent;
  889. MouseActive: Boolean;
  890. function IsDisabled(Item: PMenuItem): boolean;
  891. var Dis : boolean;
  892. begin
  893. Dis:=Item^.Disabled or IsSeparator(Item);
  894. if (Dis=false) and (IsSubMenu(Item)=false) then
  895. Dis:=CommandEnabled(Item^.Command)=false;
  896. IsDisabled:=Dis;
  897. end;
  898. procedure TrackMouse;
  899. var
  900. Mouse: TPoint;
  901. R: TRect;
  902. begin
  903. MakeLocal(E.Where, Mouse);
  904. Current := Menu^.Items;
  905. while Current <> nil do
  906. begin
  907. GetItemRect(Current, R);
  908. if R.Contains(Mouse) then
  909. begin
  910. MouseActive := True;
  911. Break;
  912. end;
  913. Current := Current^.Next;
  914. end;
  915. if (Current<>nil) and IsDisabled(Current) then
  916. Current:=nil;
  917. end;
  918. procedure TrackKey(FindNext: Boolean);
  919. procedure NextItem;
  920. begin
  921. Current := Current^.Next;
  922. if Current = nil then Current := Menu^.Items;
  923. end;
  924. procedure PrevItem;
  925. var
  926. P: PMenuItem;
  927. begin
  928. P := Current;
  929. if P = Menu^.Items then P := nil;
  930. repeat NextItem until Current^.Next = P;
  931. end;
  932. begin
  933. if Current <> nil then
  934. repeat
  935. if FindNext then NextItem else PrevItem;
  936. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  937. end;
  938. function MouseInOwner: Boolean;
  939. var
  940. Mouse: TPoint;
  941. R: TRect;
  942. begin
  943. MouseInOwner := False;
  944. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  945. begin
  946. ParentMenu^.MakeLocal(E.Where, Mouse);
  947. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  948. MouseInOwner := R.Contains(Mouse);
  949. end;
  950. end;
  951. function MouseInMenus: Boolean;
  952. var
  953. P: PMenuView;
  954. begin
  955. P := ParentMenu;
  956. while (P <> nil) and not P^.MouseInView(E.Where) do P := P^.ParentMenu;
  957. MouseInMenus := P <> nil;
  958. end;
  959. function TopMenu: PMenuView;
  960. var
  961. P: PMenuView;
  962. begin
  963. P := @Self;
  964. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  965. TopMenu := P;
  966. end;
  967. begin
  968. AutoSelect := False; E.What:=evNothing;
  969. Res := 0;
  970. ItemShown := nil;
  971. Current := Menu^.Default;
  972. MouseActive := False;
  973. if UpdateMenu(Menu) then
  974. begin
  975. if Current<>nil then
  976. if Current^.Disabled then
  977. TrackKey(true);
  978. repeat
  979. Action := DoNothing;
  980. GetEvent(E);
  981. case E.What of
  982. evMouseDown:
  983. if MouseInView(E.Where) or MouseInOwner then
  984. begin
  985. TrackMouse;
  986. if Size.Y = 1 then AutoSelect := True;
  987. end else Action := DoReturn;
  988. evMouseUp:
  989. begin
  990. TrackMouse;
  991. if MouseInOwner then
  992. Current := Menu^.Default
  993. else
  994. if (Current <> nil) and (Current^.Name <> nil) then
  995. Action := DoSelect
  996. else
  997. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  998. else
  999. begin
  1000. Current := Menu^.Default;
  1001. if Current = nil then Current := Menu^.Items;
  1002. Action := DoNothing;
  1003. end;
  1004. end;
  1005. evMouseMove:
  1006. if E.Buttons <> 0 then
  1007. begin
  1008. TrackMouse;
  1009. if not (MouseInView(E.Where) or MouseInOwner) and
  1010. MouseInMenus then Action := DoReturn;
  1011. end;
  1012. evKeyDown:
  1013. case CtrlToArrow(E.KeyCode) of
  1014. kbUp, kbDown:
  1015. if Size.Y <> 1 then
  1016. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  1017. if E.KeyCode = kbDown then AutoSelect := True;
  1018. kbLeft, kbRight:
  1019. if ParentMenu = nil then
  1020. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  1021. Action := DoReturn;
  1022. kbHome, kbEnd:
  1023. if Size.Y <> 1 then
  1024. begin
  1025. Current := Menu^.Items;
  1026. if E.KeyCode = kbEnd then TrackKey(False);
  1027. end;
  1028. kbEnter:
  1029. begin
  1030. if Size.Y = 1 then AutoSelect := True;
  1031. Action := DoSelect;
  1032. end;
  1033. kbEsc:
  1034. begin
  1035. Action := DoReturn;
  1036. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  1037. ClearEvent(E);
  1038. end;
  1039. else
  1040. Target := @Self;
  1041. Ch := GetAltChar(E.KeyCode);
  1042. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  1043. P := Target^.FindItem(Ch);
  1044. if P = nil then
  1045. begin
  1046. P := TopMenu^.HotKey(E.KeyCode);
  1047. if (P <> nil) and CommandEnabled(P^.Command) then
  1048. begin
  1049. Res := P^.Command;
  1050. Action := DoReturn;
  1051. end
  1052. end else
  1053. if Target = @Self then
  1054. begin
  1055. if Size.Y = 1 then AutoSelect := True;
  1056. Action := DoSelect;
  1057. Current := P;
  1058. end else
  1059. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  1060. Action := DoReturn;
  1061. end;
  1062. evCommand:
  1063. if E.Command = cmMenu then
  1064. begin
  1065. AutoSelect := False;
  1066. if ParentMenu <> nil then Action := DoReturn;
  1067. end else Action := DoReturn;
  1068. end;
  1069. if ItemShown <> Current then
  1070. begin
  1071. ItemShown := Current;
  1072. DrawView;
  1073. end;
  1074. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  1075. if Current <> nil then with Current^ do if Name <> nil then
  1076. if Command = 0 then
  1077. begin
  1078. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  1079. GetItemRect(Current, R);
  1080. R.A.X := R.A.X + Origin.X;
  1081. R.A.Y := R.B.Y + Origin.Y;
  1082. R.B := Owner^.Size;
  1083. if Size.Y = 1 then Dec(R.A.X);
  1084. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  1085. Res := Owner^.ExecView(Target);
  1086. Dispose(Target, Done);
  1087. end else if Action = DoSelect then Res := Command;
  1088. if (Res <> 0) and CommandEnabled(Res) then
  1089. begin
  1090. Action := DoReturn;
  1091. ClearEvent(E);
  1092. end
  1093. else
  1094. Res := 0;
  1095. until Action = DoReturn;
  1096. end;
  1097. if E.What <> evNothing then
  1098. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  1099. if Current <> nil then
  1100. begin
  1101. Menu^.Default := Current;
  1102. Current := nil;
  1103. DrawView;
  1104. end;
  1105. Execute := Res;
  1106. end;
  1107. procedure TAdvancedStaticText.SetText(S: string);
  1108. begin
  1109. if Text<>nil then DisposeStr(Text);
  1110. Text:=NewStr(S);
  1111. DrawView;
  1112. end;
  1113. procedure TAdvancedListBox.FocusItem(Item: sw_integer);
  1114. var OFocused: sw_integer;
  1115. begin
  1116. OFocused:=Focused;
  1117. inherited FocusItem(Item);
  1118. if Focused<>OFocused then
  1119. Message(Owner,evBroadcast,cmListFocusChanged,@Self);
  1120. end;
  1121. procedure TAdvancedListBox.HandleEvent(var Event: TEvent);
  1122. begin
  1123. case Event.What of
  1124. evMouseDown :
  1125. if MouseInView(Event.Where) {and (Event.Double)} then
  1126. begin
  1127. inherited HandleEvent(Event);
  1128. if Event.Double then
  1129. if Range>Focused then
  1130. SelectItem(Focused);
  1131. end;
  1132. evBroadcast :
  1133. case Event.Command of
  1134. cmListItemSelected :
  1135. Message(Owner,evBroadcast,cmDefault,nil);
  1136. end;
  1137. end;
  1138. if assigned(VScrollBar) then
  1139. VScrollBar^.HandleEvent(Event);
  1140. if assigned(HScrollBar) then
  1141. HScrollBar^.HandleEvent(Event);
  1142. inherited HandleEvent(Event);
  1143. end;
  1144. constructor TColorStaticText.Init(var Bounds: TRect; AText: String; AColor: word; AWrap: boolean);
  1145. begin
  1146. inherited Init(Bounds,AText);
  1147. DontWrap:=not AWrap;
  1148. Color:=AColor;
  1149. end;
  1150. function TColorStaticText.GetPalette: PPalette;
  1151. begin
  1152. GetPalette:=nil;
  1153. end;
  1154. procedure TColorStaticText.Draw;
  1155. procedure MoveColorTxt(var b;const curs:string;c:word);
  1156. var
  1157. p : ^word;
  1158. i : sw_integer;
  1159. col : byte;
  1160. tilde : boolean;
  1161. begin
  1162. tilde:=false;
  1163. col:=lo(c);
  1164. p:=@b;
  1165. i:=0;
  1166. while (i<length(Curs)) do
  1167. begin
  1168. Inc(i);
  1169. case CurS[i] of
  1170. #1 :
  1171. begin
  1172. Inc(i);
  1173. Col:=ord(curS[i]);
  1174. end;
  1175. #2 :
  1176. begin
  1177. if tilde then
  1178. col:=hi(Color)
  1179. else
  1180. col:=lo(Color)
  1181. end;
  1182. '~' :
  1183. begin
  1184. tilde:=not tilde;
  1185. if tilde then
  1186. col:=hi(Color)
  1187. else
  1188. col:=lo(Color)
  1189. end;
  1190. else
  1191. begin
  1192. p^:=(col shl 8) or ord(curs[i]);
  1193. inc(p);
  1194. end;
  1195. end;
  1196. end;
  1197. end;
  1198. var
  1199. C: word;
  1200. Center: Boolean;
  1201. I, J, L, P, Y: Sw_Integer;
  1202. B: TDrawBuffer;
  1203. S: String;
  1204. T: string;
  1205. CurS: string;
  1206. TildeCount,Po: Sw_integer;
  1207. TempS: string;
  1208. begin
  1209. if Size.X=0 then Exit;
  1210. C:=Color;
  1211. if (C and $0f)=((C and $f0) shr 4) then
  1212. C:=GetColor(C and $0f);
  1213. if DontWrap=false then
  1214. begin
  1215. GetText(S);
  1216. L := Length(S);
  1217. P := 1;
  1218. Y := 0;
  1219. Center := False;
  1220. while Y < Size.Y do
  1221. begin
  1222. MoveChar(B, ' ', Lo(C), Size.X);
  1223. if P <= L then
  1224. begin
  1225. if S[P] = #3 then
  1226. begin
  1227. Center := True;
  1228. Inc(P);
  1229. end;
  1230. I := P;
  1231. repeat
  1232. J := P;
  1233. while (P <= L) and (S[P] = ' ') do Inc(P);
  1234. while (P <= L) and (S[P] <> ' ') and (S[P] <> #13) do Inc(P);
  1235. until (P > L) or (P >= I + Size.X) or (S[P] = #13);
  1236. TildeCount:=0; TempS:=copy(S,I,P-I);
  1237. repeat
  1238. Po:=Pos('~',TempS);
  1239. if Po>0 then begin Inc(TildeCount); Delete(TempS,1,Po); end;
  1240. until Po=0;
  1241. if P > I + Size.X + TildeCount then
  1242. if J > I then P := J else P := I + Size.X;
  1243. T:=copy(S,I,P-I);
  1244. if Center then J := (Size.X - {P + I}CStrLen(T)) div 2 else J := 0;
  1245. MoveColorTxt(B[J],T,C);
  1246. while (P <= L) and (S[P] = ' ') do Inc(P);
  1247. if (P <= L) and (S[P] = #13) then
  1248. begin
  1249. Center := False;
  1250. Inc(P);
  1251. if (P <= L) and (S[P] = #10) then Inc(P);
  1252. end;
  1253. end;
  1254. WriteLine(0, Y, Size.X, 1, B);
  1255. Inc(Y);
  1256. end;
  1257. end { Wrap=false } else
  1258. begin
  1259. GetText(S);
  1260. I:=1;
  1261. for Y:=0 to Size.Y-1 do
  1262. begin
  1263. MoveChar(B, ' ', Lo(C), Size.X);
  1264. CurS:='';
  1265. if S<>'' then
  1266. begin
  1267. P:=Pos(#13,S);
  1268. if P=0 then P:=length(S)+1;
  1269. CurS:=copy(S,1,P-1);
  1270. CurS:=copy(CurS,Delta.X+1,High(CurS));
  1271. CurS:=copy(CurS,1,MaxViewWidth);
  1272. Delete(S,1,P);
  1273. end;
  1274. if CurS<>'' then
  1275. MoveColorTxt(B,CurS,C);
  1276. WriteLine(0,Y,Size.X,1,B);
  1277. end;
  1278. end;
  1279. end;
  1280. constructor TColorStaticText.Load(var S: TStream);
  1281. begin
  1282. inherited Load(S);
  1283. S.Read(Color,SizeOf(Color));
  1284. S.Read(DontWrap,SizeOf(DontWrap));
  1285. S.Read(Delta,SizeOf(Delta));
  1286. end;
  1287. procedure TColorStaticText.Store(var S: TStream);
  1288. begin
  1289. inherited Store(S);
  1290. S.Write(Color,SizeOf(Color));
  1291. S.Write(DontWrap,SizeOf(DontWrap));
  1292. S.Write(Delta,SizeOf(Delta));
  1293. end;
  1294. constructor THSListBox.Init(var Bounds: TRect; ANumCols: Word; AHScrollBar, AVScrollBar: PScrollBar);
  1295. begin
  1296. inherited Init(Bounds,ANumCols,AVScrollBar);
  1297. HScrollBar:=AHScrollBar;
  1298. if assigned(VScrollBar) then
  1299. VScrollBar^.SetStep(Bounds.B.Y-Bounds.A.Y-2,1);
  1300. if assigned(HScrollBar) then
  1301. HScrollBar^.SetStep(Bounds.B.X-Bounds.A.X-2,1);
  1302. end;
  1303. function THSListBox.SaveToFile(const AFileName: string): boolean;
  1304. var OK: boolean;
  1305. S: PBufStream;
  1306. i, count : sw_integer;
  1307. st : string;
  1308. begin
  1309. New(S, Init(AFileName,stCreate,4096));
  1310. OK:=Assigned(S) and (S^.Status=stOK);
  1311. if OK then
  1312. begin
  1313. if assigned(List) then
  1314. Count:=List^.Count
  1315. else
  1316. Count:=0;
  1317. for i:=0 to Count-1 do
  1318. begin
  1319. st:=GetText(i,High(st));
  1320. S^.Write(St[1],length(St));
  1321. if i<Count then
  1322. S^.Write(EOL[1],length(EOL));
  1323. OK:=(S^.Status=stOK);
  1324. if not OK then
  1325. break;
  1326. end;
  1327. end;
  1328. if Assigned(S) then Dispose(S, Done);
  1329. SaveToFile:=OK;
  1330. end;
  1331. function THSListBox.SaveAs: Boolean;
  1332. var
  1333. DefExt,Title,Filename : string;
  1334. Re : word;
  1335. begin
  1336. SaveAs := False;
  1337. Filename:='listbox.txt';
  1338. DefExt:='*.txt';
  1339. Title:='Save list box content';
  1340. Re:=Application^.ExecuteDialog(New(PFileDialog, Init(DefExt,
  1341. Title, label_name, fdOkButton, FileId)), @FileName);
  1342. if Re <> cmCancel then
  1343. SaveAs := SaveToFile(FileName);
  1344. end;
  1345. constructor TDlgWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer);
  1346. begin
  1347. inherited Init(Bounds,ATitle);
  1348. Number:=ANumber;
  1349. Flags:=Flags or (wfMove + wfGrow + wfClose + wfZoom);
  1350. end;
  1351. procedure TDlgWindow.Update;
  1352. begin
  1353. DrawView;
  1354. end;
  1355. procedure TDlgWindow.HandleEvent(var Event: TEvent);
  1356. begin
  1357. case Event.What of
  1358. evBroadcast :
  1359. case Event.Command of
  1360. cmUpdate : Update;
  1361. end;
  1362. end;
  1363. inherited HandleEvent(Event);
  1364. end;
  1365. procedure TLocalMenuListBox.LocalMenu(P: TPoint);
  1366. var M: PMenu;
  1367. MV: PAdvancedMenuPopUp;
  1368. R: TRect;
  1369. Re: word;
  1370. begin
  1371. M:=GetLocalMenu;
  1372. if M=nil then Exit;
  1373. if LastLocalCmd<>0 then
  1374. M^.Default:=SearchMenuItem(M,LastLocalCmd);
  1375. Desktop^.GetExtent(R);
  1376. MakeGlobal(P,R.A); {Desktop^.MakeLocal(R.A,R.A);}
  1377. New(MV, Init(R, M));
  1378. Re:=Application^.ExecView(MV);
  1379. if M^.Default=nil then LastLocalCmd:=0
  1380. else LastLocalCmd:=M^.Default^.Command;
  1381. Dispose(MV, Done);
  1382. if Re<>0 then
  1383. Message(GetCommandTarget,evCommand,Re,@Self);
  1384. end;
  1385. function TLocalMenuListBox.GetLocalMenu: PMenu;
  1386. begin
  1387. GetLocalMenu:=nil;
  1388. { Abstract;}
  1389. end;
  1390. function TLocalMenuListBox.GetCommandTarget: PView;
  1391. begin
  1392. GetCommandTarget:=@Self;
  1393. end;
  1394. procedure TLocalMenuListBox.HandleEvent(var Event: TEvent);
  1395. var DontClear: boolean;
  1396. P: TPoint;
  1397. begin
  1398. case Event.What of
  1399. evMouseDown :
  1400. if MouseInView(Event.Where) and (Event.Buttons=mbRightButton) then
  1401. begin
  1402. MakeLocal(Event.Where,P); Inc(P.X); Inc(P.Y);
  1403. LocalMenu(P);
  1404. ClearEvent(Event);
  1405. end;
  1406. evKeyDown :
  1407. begin
  1408. DontClear:=false;
  1409. case Event.KeyCode of
  1410. kbAltF10 : Message(@Self,evCommand,cmLocalMenu,@Self);
  1411. else DontClear:=true;
  1412. end;
  1413. if DontClear=false then ClearEvent(Event);
  1414. end;
  1415. evCommand :
  1416. begin
  1417. DontClear:=false;
  1418. case Event.Command of
  1419. cmLocalMenu :
  1420. begin
  1421. P:=Cursor; Inc(P.X); Inc(P.Y);
  1422. LocalMenu(P);
  1423. end;
  1424. else DontClear:=true;
  1425. end;
  1426. if not DontClear then ClearEvent(Event);
  1427. end;
  1428. end;
  1429. inherited HandleEvent(Event);
  1430. end;
  1431. function TAdvancedStatusLine.GetStatusText: string;
  1432. var S: string;
  1433. begin
  1434. if StatusText=nil then S:='' else S:=StatusText^;
  1435. GetStatusText:=S;
  1436. end;
  1437. procedure TAdvancedStatusLine.SetStatusText(const S: string);
  1438. begin
  1439. if StatusText<>nil then DisposeStr(StatusText);
  1440. StatusText:=NewStr(S);
  1441. DrawView;
  1442. end;
  1443. procedure TAdvancedStatusLine.ClearStatusText;
  1444. begin
  1445. SetStatusText('');
  1446. end;
  1447. procedure TAdvancedStatusLine.Draw;
  1448. var B: TDrawBuffer;
  1449. C: word;
  1450. S: string;
  1451. begin
  1452. S:=GetStatusText;
  1453. if S='' then inherited Draw else
  1454. begin
  1455. C:=GetColor(1);
  1456. MoveChar(B,' ',C,Size.X);
  1457. MoveStr(B[1],S,C);
  1458. WriteLine(0,0,Size.X,Size.Y,B);
  1459. end;
  1460. end;
  1461. procedure Bug(const S: string; Params: pointer);
  1462. begin
  1463. ErrorBox(FormatStrStr(msg_bugcheckfailed,S),Params);
  1464. end;
  1465. procedure ErrorBox(const S: string; Params: pointer);
  1466. begin
  1467. AdvMessageBox(S,Params,mfError+mfInsertInApp+mfOKButton);
  1468. end;
  1469. procedure WarningBox(const S: string; Params: pointer);
  1470. begin
  1471. AdvMessageBox(S,Params,mfWarning+mfInsertInApp+mfOKButton);
  1472. end;
  1473. procedure InformationBox(const S: string; Params: pointer);
  1474. begin
  1475. AdvMessageBox(S,Params,mfInformation+mfInsertInApp+mfOKButton);
  1476. end;
  1477. function OKCancelBox(const S: string; Params: pointer): word;
  1478. begin
  1479. OKCancelBox:=AdvMessageBox(S,Params,mfInformation+mfInsertInApp+mfOKButton+mfCancelButton);
  1480. end;
  1481. function b2i(B: boolean): longint;
  1482. begin
  1483. if b then b2i:=1 else b2i:=0;
  1484. end;
  1485. function ConfirmBox(const S: string; Params: pointer; CanCancel: boolean): word;
  1486. begin
  1487. ConfirmBox:=AdvMessageBox(S,Params,mfConfirmation+mfInsertInApp+mfYesButton+mfNoButton+
  1488. b2i(CanCancel)*mfCancelButton+b2i(not CanCancel)*mfCantCancel);
  1489. end;
  1490. function ChoiceBox(const S: string; Params: pointer; Buttons: array of string; CanCancel: boolean): word;
  1491. var BtnMask,M: longint;
  1492. I,BtnCount: integer;
  1493. begin
  1494. BtnCount:=Min(High(Buttons)-Low(Buttons)+1,High(UserButtonName)-Low(UserButtonName)+1);
  1495. BtnMask:=0; M:=mfUserBtn1;
  1496. for I:=Low(Buttons) to Low(Buttons)+BtnCount-1 do
  1497. begin
  1498. UserButtonName[Low(UserButtonName)+I-Low(Buttons)]:=Buttons[I];
  1499. BtnMask:=BtnMask or M; M:=M shl 1;
  1500. end;
  1501. ChoiceBox:=AdvMessageBox(S,Params,mfConfirmation+BtnMask+
  1502. b2i(CanCancel)*mfCancelButton+b2i(not CanCancel)*mfCantCancel);
  1503. end;
  1504. function IsSeparator(P: PMenuItem): boolean;
  1505. begin
  1506. IsSeparator:=(P<>nil) and (P^.Name=nil) and (P^.HelpCtx=hcNoContext);
  1507. end;
  1508. function IsSubMenu(P: PMenuItem): boolean;
  1509. begin
  1510. IsSubMenu:=(P<>nil) and (P^.Name<>nil) and (P^.Command=0) and (P^.SubMenu<>nil);
  1511. end;
  1512. function SearchMenuItem(Menu: PMenu; Cmd: word): PMenuItem;
  1513. var P,I: PMenuItem;
  1514. begin
  1515. I:=nil;
  1516. if Menu=nil then P:=nil else P:=Menu^.Items;
  1517. while (P<>nil) and (I=nil) do
  1518. begin
  1519. if IsSubMenu(P) then
  1520. I:=SearchMenuItem(P^.SubMenu,Cmd);
  1521. if I=nil then
  1522. if P^.Command=Cmd then I:=P else
  1523. P:=P^.Next;
  1524. end;
  1525. SearchMenuItem:=I;
  1526. end;
  1527. procedure SetMenuItemParam(Menu: PMenuItem; Param: string);
  1528. begin
  1529. if Menu=nil then Exit;
  1530. if Menu^.Param<>nil then DisposeStr(Menu^.Param);
  1531. Menu^.Param:=NewStr(Param);
  1532. end;
  1533. function UpdateMenu(M: PMenu): boolean;
  1534. var P: PMenuItem;
  1535. IsEnabled: boolean;
  1536. begin
  1537. if M=nil then begin UpdateMenu:=false; Exit; end;
  1538. P:=M^.Items; IsEnabled:=false;
  1539. while (P<>nil) do
  1540. begin
  1541. if IsSubMenu(P) then
  1542. begin
  1543. P^.Disabled:=not UpdateMenu(P^.SubMenu);
  1544. if not P^.Disabled then
  1545. IsEnabled:=true;
  1546. end
  1547. else
  1548. begin
  1549. if not IsSeparator(P) and
  1550. Application^.CommandEnabled(P^.Command) then
  1551. begin
  1552. p^.disabled:=false;
  1553. IsEnabled:=true;
  1554. end;
  1555. end;
  1556. P:=P^.Next;
  1557. end;
  1558. UpdateMenu:=IsEnabled;
  1559. end;
  1560. function SearchSubMenu(M: PMenu; Index: Sw_integer): PMenuItem;
  1561. var P,C: PMenuItem;
  1562. Count: Sw_integer;
  1563. begin
  1564. P:=nil; Count:=-1;
  1565. if M<>nil then C:=M^.Items else C:=nil;
  1566. while (C<>nil) and (P=nil) do
  1567. begin
  1568. if IsSubMenu(C) then
  1569. begin
  1570. Inc(Count);
  1571. if Count=Index then P:=C;
  1572. end;
  1573. C:=C^.Next;
  1574. end;
  1575. SearchSubMenu:=P;
  1576. end;
  1577. procedure AppendMenuItem(M: PMenu; I: PMenuItem);
  1578. var P: PMenuItem;
  1579. begin
  1580. if (M=nil) or (I=nil) then Exit;
  1581. I^.Next:=nil;
  1582. if M^.Items=nil then M^.Items:=I else
  1583. begin
  1584. P:=M^.Items;
  1585. while (P^.Next<>nil) do P:=P^.Next;
  1586. P^.Next:=I;
  1587. end;
  1588. end;
  1589. procedure DisposeMenuItem(P: PMenuItem);
  1590. begin
  1591. if P<>nil then
  1592. begin
  1593. if IsSubMenu(P) then DisposeMenu(P^.SubMenu) else
  1594. if IsSeparator(P)=false then
  1595. if P^.Param<>nil then DisposeStr(P^.Param);
  1596. if P^.Name<>nil then DisposeStr(P^.Name);
  1597. Dispose(P);
  1598. end;
  1599. end;
  1600. procedure RemoveMenuItem(Menu: PMenu; I: PMenuItem);
  1601. var P,PrevP: PMenuItem;
  1602. begin
  1603. if (Menu=nil) or (I=nil) then Exit;
  1604. P:=Menu^.Items; PrevP:=nil;
  1605. while (P<>nil) do
  1606. begin
  1607. if P=I then
  1608. begin
  1609. if Menu^.Items<>I then PrevP^.Next:=P^.Next
  1610. else Menu^.Items:=P^.Next;
  1611. DisposeMenuItem(P);
  1612. Break;
  1613. end;
  1614. PrevP:=P; P:=P^.Next;
  1615. end;
  1616. end;
  1617. function GetMenuItemBefore(Menu: PMenu; BeforeOf: PMenuItem): PMenuItem;
  1618. var P,C: PMenuItem;
  1619. begin
  1620. P:=nil;
  1621. if Menu<>nil then C:=Menu^.Items else C:=nil;
  1622. while (C<>nil) do
  1623. begin
  1624. if C^.Next=BeforeOf then begin P:=C; Break; end;
  1625. C:=C^.Next;
  1626. end;
  1627. GetMenuItemBefore:=P;
  1628. end;
  1629. procedure NotImplemented;
  1630. begin
  1631. InformationBox(msg_functionnotimplemented,nil);
  1632. end;
  1633. procedure InsertButtons(ADialog: PDialog);
  1634. var R : TRect;
  1635. W,H : Sw_integer;
  1636. X : Sw_integer;
  1637. X1,X2: Sw_integer;
  1638. begin
  1639. with ADialog^ do
  1640. begin
  1641. GetExtent(R);
  1642. W:=R.B.X-R.A.X; H:=(R.B.Y-R.A.Y);
  1643. R.Assign(0,0,W,H+3); ChangeBounds(R);
  1644. X:=W div 2; X1:=X div 2+1; X2:=X+X1-1;
  1645. R.Assign(X1-3,H,X1+7,H+2);
  1646. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  1647. R.Assign(X2-7,H,X2+3,H+2);
  1648. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  1649. SelectNext(true);
  1650. end;
  1651. end;
  1652. procedure InsertOK(ADialog: PDialog);
  1653. var BW: Sw_integer;
  1654. R: TRect;
  1655. begin
  1656. with ADialog^ do
  1657. begin
  1658. GetBounds(R); R.Grow(0,1); Inc(R.B.Y);
  1659. ChangeBounds(R);
  1660. BW:=10;
  1661. R.A.Y:=R.B.Y-2; R.B.Y:=R.A.Y+2;
  1662. R.A.X:=R.A.X+(R.B.X-R.A.X-BW) div 2; R.B.X:=R.A.X+BW;
  1663. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  1664. SelectNext(true);
  1665. end;
  1666. end;
  1667. procedure ShowMessage(Msg: string);
  1668. var R: TRect;
  1669. Width: Sw_integer;
  1670. begin
  1671. Width:=length(Msg)+4*2;
  1672. if Width<(Desktop^.Size.X div 2) then Width:=(Desktop^.Size.X div 2);
  1673. R.Assign(0,0,Width,5);
  1674. New(MessageDialog, Init(R, ''));
  1675. with MessageDialog^ do
  1676. begin
  1677. Flags:=0;
  1678. GetExtent(R); R.Grow(-4,-2);
  1679. if copy(Msg,1,1)<>^C then Msg:=^C+Msg;
  1680. Insert(New(PStaticText, Init(R, Msg)));
  1681. end;
  1682. Application^.Insert(MessageDialog);
  1683. end;
  1684. procedure HideMessage;
  1685. begin
  1686. if MessageDialog<>nil then
  1687. begin
  1688. Application^.Delete(MessageDialog);
  1689. Dispose(MessageDialog, Done);
  1690. MessageDialog:=nil;
  1691. end;
  1692. end;
  1693. constructor TDDHelperLB.Init(ALink: PDropDownListBox; var Bounds: TRect; ANumCols: Word; AScrollBar: PScrollBar);
  1694. begin
  1695. inherited Init(Bounds,ANumCols,AScrollBar);
  1696. EventMask:=EventMask or (evMouseMove+evIdle);
  1697. { Options:=Options or ofPreProcess;}
  1698. Link:=ALink;
  1699. end;
  1700. procedure TDDHelperLB.SetState(AState: Word; Enable: Boolean);
  1701. {var OState: longint;}
  1702. begin
  1703. { OState:=State;}
  1704. inherited SetState(AState,Enable);
  1705. { if (((State xor OState) and sfFocused)<>0) and (GetState(sfFocused)=false) then
  1706. Link^.DropList(false);}
  1707. end;
  1708. function TDDHelperLB.GetText(Item,MaxLen: Sw_Integer): String;
  1709. var P: pointer;
  1710. S: string;
  1711. begin
  1712. P:=List^.At(Item);
  1713. if Link=nil then S:='' else
  1714. S:=Link^.GetText(P,MaxLen);
  1715. GetText:=S;
  1716. end;
  1717. function TDDHelperLB.GetLocalMenu: PMenu;
  1718. begin
  1719. GetLocalMenu:=Link^.LBGetLocalMenu;
  1720. end;
  1721. function TDDHelperLB.GetCommandTarget: PView;
  1722. begin
  1723. GetCommandTarget:=Link^.LBGetCommandTarget;
  1724. end;
  1725. procedure TDDHelperLB.HandleEvent(var Event: TEvent);
  1726. const
  1727. MouseAutosToSkip = 4;
  1728. var
  1729. Mouse : TPoint;
  1730. OldItem, NewItem : Sw_Integer;
  1731. ColWidth : sw_integer;
  1732. Count : Sw_Word;
  1733. GoSelectItem: sw_integer;
  1734. MouseWhere: TPoint;
  1735. begin
  1736. GoSelectItem:=-1;
  1737. TView.HandleEvent(Event);
  1738. case Event.What of
  1739. evMouseDown :
  1740. if MouseInView(Event.Where)=false then
  1741. GoSelectItem:=-2
  1742. else
  1743. begin
  1744. ColWidth := Size.X div NumCols + 1;
  1745. OldItem := Focused;
  1746. MakeLocal(Event.Where, Mouse);
  1747. if MouseInView(Event.Where) then
  1748. NewItem := Mouse.Y + (Size.Y * (Mouse.X div ColWidth)) + TopItem
  1749. else
  1750. NewItem := OldItem;
  1751. Count := 0;
  1752. repeat
  1753. if NewItem <> OldItem then
  1754. begin
  1755. FocusItemNum(NewItem);
  1756. DrawView;
  1757. end;
  1758. OldItem := NewItem;
  1759. MakeLocal(Event.Where, Mouse);
  1760. if MouseInView(Event.Where) then
  1761. NewItem := Mouse.Y + (Size.Y * (Mouse.X div ColWidth)) + TopItem
  1762. else
  1763. begin
  1764. if NumCols = 1 then
  1765. begin
  1766. if Event.What = evMouseAuto then Inc(Count);
  1767. if Count = MouseAutosToSkip then
  1768. begin
  1769. Count := 0;
  1770. if Mouse.Y < 0 then NewItem := Focused-1
  1771. else if Mouse.Y >= Size.Y then NewItem := Focused+1;
  1772. end;
  1773. end
  1774. else
  1775. begin
  1776. if Event.What = evMouseAuto then Inc(Count);
  1777. if Count = MouseAutosToSkip then
  1778. begin
  1779. Count := 0;
  1780. if Mouse.X < 0 then NewItem := Focused-Size.Y
  1781. else if Mouse.X >= Size.X then NewItem := Focused+Size.Y
  1782. else if Mouse.Y < 0 then
  1783. NewItem := Focused - Focused mod Size.Y
  1784. else if Mouse.Y > Size.Y then
  1785. NewItem := Focused - Focused mod Size.Y + Size.Y - 1;
  1786. end
  1787. end;
  1788. end;
  1789. until not MouseEvent(Event, evMouseMove + evMouseAuto);
  1790. FocusItemNum(NewItem);
  1791. DrawView;
  1792. if Event.Double and (Range > Focused) then SelectItem(Focused);
  1793. ClearEvent(Event);
  1794. GoSelectItem:=Focused;
  1795. end;
  1796. evMouseMove,evMouseAuto:
  1797. if GetState(sfFocused) then
  1798. if MouseInView(Event.Where) then
  1799. begin
  1800. MakeLocal(Event.Where,Mouse);
  1801. FocusItemNum(TopItem+Mouse.Y);
  1802. ClearEvent(Event);
  1803. end;
  1804. evKeyDown :
  1805. begin
  1806. if (Event.KeyCode=kbEsc) then
  1807. begin
  1808. GoSelectItem:=-2;
  1809. ClearEvent(Event);
  1810. end else
  1811. if ((Event.KeyCode=kbEnter) or (Event.CharCode = ' ')) and
  1812. (Focused < Range) then
  1813. begin
  1814. GoSelectItem:=Focused;
  1815. NewItem := Focused;
  1816. end
  1817. else
  1818. case CtrlToArrow(Event.KeyCode) of
  1819. kbUp : NewItem := Focused - 1;
  1820. kbDown : NewItem := Focused + 1;
  1821. kbRight: if NumCols > 1 then NewItem := Focused + Size.Y else Exit;
  1822. kbLeft : if NumCols > 1 then NewItem := Focused - Size.Y else Exit;
  1823. kbPgDn : NewItem := Focused + Size.Y * NumCols;
  1824. kbPgUp : NewItem := Focused - Size.Y * NumCols;
  1825. kbHome : NewItem := TopItem;
  1826. kbEnd : NewItem := TopItem + (Size.Y * NumCols) - 1;
  1827. kbCtrlPgDn: NewItem := Range - 1;
  1828. kbCtrlPgUp: NewItem := 0;
  1829. else
  1830. Exit;
  1831. end;
  1832. FocusItemNum(NewItem);
  1833. DrawView;
  1834. ClearEvent(Event);
  1835. end;
  1836. evBroadcast :
  1837. case Event.Command of
  1838. cmReceivedFocus :
  1839. if (Event.InfoPtr<>@Self) and (InClose=false) then
  1840. begin
  1841. GoSelectItem:=-2;
  1842. end;
  1843. else
  1844. if Options and ofSelectable <> 0 then
  1845. if (Event.Command = cmScrollBarClicked) and
  1846. ((Event.InfoPtr = HScrollBar) or (Event.InfoPtr = VScrollBar)) then
  1847. Select
  1848. else
  1849. if (Event.Command = cmScrollBarChanged) then
  1850. begin
  1851. if (VScrollBar = Event.InfoPtr) then
  1852. begin
  1853. FocusItemNum(VScrollBar^.Value);
  1854. DrawView;
  1855. end
  1856. else
  1857. if (HScrollBar = Event.InfoPtr) then
  1858. DrawView;
  1859. end;
  1860. end;
  1861. evIdle :
  1862. begin
  1863. MouseWhere.X:=MouseWhereX shr 3; MouseWhere.Y:=MouseWhereY shr 3;
  1864. if MouseInView(MouseWhere)=false then
  1865. if abs(GetDosTicks-LastTT)>=1 then
  1866. begin
  1867. LastTT:=GetDosTicks;
  1868. MakeLocal(MouseWhere,Mouse);
  1869. if ((Mouse.Y<-1) or (Mouse.Y>=Size.Y)) and
  1870. ((0<=Mouse.X) and (Mouse.X<Size.X)) then
  1871. if Range>0 then
  1872. if Mouse.Y<0 then
  1873. FocusItemNum(Focused-(0-Mouse.Y))
  1874. else
  1875. FocusItemNum(Focused+(Mouse.Y-(Size.Y-1)));
  1876. end;
  1877. end;
  1878. end;
  1879. if (Range>0) and (GoSelectItem<>-1) then
  1880. begin
  1881. InClose:=true;
  1882. if GoSelectItem=-2 then
  1883. Link^.DropList(false)
  1884. else
  1885. SelectItem(GoSelectItem);
  1886. end;
  1887. end;
  1888. procedure TDDHelperLB.SelectItem(Item: Sw_Integer);
  1889. begin
  1890. inherited SelectItem(Item);
  1891. Link^.FocusItem(Focused);
  1892. Link^.DropList(false);
  1893. end;
  1894. constructor TDropDownListBox.Init(var Bounds: TRect; ADropLineCount: Sw_integer; AList: PCollection);
  1895. begin
  1896. inherited Init(Bounds);
  1897. Options:=Options or (ofSelectable);
  1898. EventMask:=EventMask or (evBroadcast);
  1899. DropLineCount:=ADropLineCount;
  1900. NewList(AList);
  1901. end;
  1902. procedure TDropDownListBox.HandleEvent(var Event: TEvent);
  1903. var DontClear: boolean;
  1904. Count: sw_integer;
  1905. begin
  1906. case Event.What of
  1907. evKeyDown :
  1908. if GetState(sfFocused) then
  1909. begin
  1910. DontClear:=false;
  1911. Count:=GetItemCount;
  1912. if Count>0 then
  1913. case Event.KeyCode of
  1914. kbUp :
  1915. if Focused>0 then
  1916. FocusItem(Focused-1);
  1917. kbDown :
  1918. if Focused<Count-1 then
  1919. FocusItem(Focused+1);
  1920. kbHome :
  1921. FocusItem(0);
  1922. kbEnd :
  1923. FocusItem(Count-1);
  1924. kbEnter,
  1925. kbPgDn :
  1926. DropList(true);
  1927. else DontClear:=true;
  1928. end;
  1929. if DontClear=false then ClearEvent(Event);
  1930. end;
  1931. evBroadcast :
  1932. case Event.Command of
  1933. cmReleasedFocus :
  1934. if (ListBox<>nil) and (Event.InfoPtr=ListBox) then
  1935. DropList(false);
  1936. cmListItemSelected :
  1937. if (ListBox<>nil) and (Event.InfoPtr=ListBox) then
  1938. begin
  1939. FocusItem(ListBox^.Focused);
  1940. Text:=GetText(List^.At(Focused),High(Text));
  1941. DrawView;
  1942. DropList(false);
  1943. end;
  1944. end;
  1945. evMouseDown :
  1946. if MouseInView(Event.Where) then
  1947. begin
  1948. DropList(not ListDropped);
  1949. ClearEvent(Event);
  1950. end;
  1951. end;
  1952. inherited HandleEvent(Event);
  1953. end;
  1954. function TDropDownListBox.GetText(Item: pointer; MaxLen: Sw_integer): string;
  1955. var S: string;
  1956. begin
  1957. S:=GetStr(Item);
  1958. GetText:=copy(S,1,MaxLen);
  1959. end;
  1960. procedure TDropDownListBox.NewList(AList: PCollection);
  1961. begin
  1962. if List<>nil then Dispose(List, Done); List:=nil;
  1963. List:=AList; FocusItem(0);
  1964. end;
  1965. procedure TDropDownListBox.CreateListBox(var R: TRect);
  1966. var R2: TRect;
  1967. begin
  1968. R2.Copy(R); R2.A.X:=R2.B.X-1;
  1969. New(SB, Init(R2));
  1970. Dec(R.B.X);
  1971. New(ListBox, Init(@Self,R,1,SB));
  1972. end;
  1973. procedure TDropDownListBox.DropList(Drop: boolean);
  1974. var R: TRect;
  1975. LB: PListBox;
  1976. begin
  1977. if (ListDropped=Drop) then Exit;
  1978. if Drop then
  1979. begin
  1980. R.Assign(Origin.X+1,Origin.Y+Size.Y,Origin.X+Size.X,Origin.Y+Size.Y+DropLineCount);
  1981. if Owner<>nil then Owner^.Lock;
  1982. CreateListBox(R);
  1983. if SB<>nil then
  1984. Owner^.Insert(SB);
  1985. if ListBox<>nil then
  1986. begin
  1987. ListBox^.NewList(List);
  1988. ListBox^.FocusItem(Focused);
  1989. Owner^.Insert(ListBox);
  1990. end;
  1991. if Owner<>nil then Owner^.UnLock;
  1992. end
  1993. else
  1994. begin
  1995. if Owner<>nil then Owner^.Lock;
  1996. if ListBox<>nil then
  1997. begin
  1998. { ListBox^.List:=nil;}
  1999. LB:=ListBox; ListBox:=nil; { this prevents GPFs while deleting }
  2000. Dispose(LB, Done);
  2001. end;
  2002. if SB<>nil then
  2003. begin
  2004. Dispose(SB, Done);
  2005. SB:=nil;
  2006. end;
  2007. Select;
  2008. if Owner<>nil then Owner^.UnLock;
  2009. end;
  2010. ListDropped:=Drop;
  2011. DrawView;
  2012. end;
  2013. function TDropDownListBox.GetItemCount: sw_integer;
  2014. var Count: sw_integer;
  2015. begin
  2016. if assigned(List)=false then Count:=0 else
  2017. Count:=List^.Count;
  2018. GetItemCount:=Count;
  2019. end;
  2020. procedure TDropDownListBox.FocusItem(Item: sw_integer);
  2021. var P: pointer;
  2022. begin
  2023. Focused:=Item;
  2024. if assigned(ListBox) and (Item>=0) then
  2025. ListBox^.FocusItem(Item);
  2026. if (GetItemCount>0) and (Focused>=0) then
  2027. begin
  2028. P:=List^.At(Focused);
  2029. Text:=GetText(P,Size.X-4);
  2030. end;
  2031. DrawView;
  2032. end;
  2033. function TDropDownListBox.LBGetLocalMenu: PMenu;
  2034. begin
  2035. LBGetLocalMenu:=nil;
  2036. end;
  2037. function TDropDownListBox.LBGetCommandTarget: PView;
  2038. begin
  2039. LBGetCommandTarget:=@Self;
  2040. end;
  2041. procedure TDropDownListBox.SetState(AState: Word; Enable: Boolean);
  2042. begin
  2043. inherited SetState(AState,Enable);
  2044. if (AState and (sfSelected + sfActive + sfFocused)) <> 0 then DrawView;
  2045. end;
  2046. procedure TDropDownListBox.Draw;
  2047. var B: TDrawBuffer;
  2048. C,TextC: word;
  2049. LC: char;
  2050. begin
  2051. if GetState(sfFocused)=false then
  2052. begin
  2053. C:=GetColor(2);
  2054. TextC:=GetColor(2);
  2055. end
  2056. else
  2057. begin
  2058. C:=GetColor(3);
  2059. TextC:=GetColor(3);
  2060. end;
  2061. MoveChar(B,' ',C,Size.X);
  2062. MoveStr(B[1],copy(Text,1,Size.X-2),TextC);
  2063. if ListDropped then LC:='^' else LC:='v';
  2064. MoveChar(B[Size.X-2],LC,C,1);
  2065. WriteLine(0,0,Size.X,Size.Y,B);
  2066. end;
  2067. function TDropDownListBox.GetPalette: PPalette;
  2068. const P: string[length(CListViewer)] = CListViewer;
  2069. begin
  2070. GetPalette:=@P;
  2071. end;
  2072. destructor TDropDownListBox.Done;
  2073. begin
  2074. if ListDropped then DropList(false);
  2075. inherited Done;
  2076. end;
  2077. constructor TGroupView.Init(var Bounds: TRect; AText: String; ALink: PView);
  2078. begin
  2079. inherited Init(Bounds,AText,ALink);
  2080. end;
  2081. procedure TGroupView.Draw;
  2082. var B: TDrawBuffer;
  2083. FrameC,LabelC: word;
  2084. begin
  2085. FrameC:=GetColor(1);
  2086. if Light then
  2087. LabelC:=GetColor(2)+GetColor(4) shl 8
  2088. else
  2089. LabelC:=GetColor(1)+GetColor(3) shl 8;
  2090. { First Line }
  2091. MoveChar(B[0],'Ú',FrameC,1);
  2092. MoveChar(B[1],'Ä',FrameC,Size.X-2);
  2093. MoveChar(B[Size.X-1],'¿',FrameC,1);
  2094. if Text<>nil then
  2095. begin
  2096. MoveCStr(B[1],' '+Text^+' ',LabelC);
  2097. end;
  2098. WriteLine(0,0,Size.X,1,B);
  2099. { Mid Lines }
  2100. MoveChar(B[0],'³',FrameC,1);
  2101. MoveChar(B[1],' ',FrameC,Size.X-2);
  2102. MoveChar(B[Size.X-1],'³',FrameC,1);
  2103. WriteLine(0,1,Size.X,Size.Y-2,B);
  2104. { Last Line }
  2105. MoveChar(B[0],'À',FrameC,1);
  2106. MoveChar(B[1],'Ä',FrameC,Size.X-2);
  2107. MoveChar(B[Size.X-1],'Ù',FrameC,1);
  2108. WriteLine(0,Size.Y-1,Size.X,1,B);
  2109. end;
  2110. function TPlainCheckBoxes.GetPalette: PPalette;
  2111. const P: string[length(CPlainCluster)] = CPlainCluster;
  2112. begin
  2113. GetPalette:=@P;
  2114. end;
  2115. function TPlainRadioButtons.GetPalette: PPalette;
  2116. const P: string[length(CPlainCluster)] = CPlainCluster;
  2117. begin
  2118. GetPalette:=@P;
  2119. end;
  2120. constructor TAdvancedListBox.Load(var S: TStream);
  2121. begin
  2122. inherited Load(S);
  2123. S.Read(Default,SizeOf(Default));
  2124. end;
  2125. procedure TAdvancedListBox.Store(var S: TStream);
  2126. begin
  2127. inherited Store(S);
  2128. S.Write(Default,SizeOf(Default));
  2129. end;
  2130. procedure TNoUpdateButton.HandleEvent(var Event: TEvent);
  2131. begin
  2132. if (Event.What<>evBroadcast) or (Event.Command<>cmCommandSetChanged) then
  2133. inherited HandleEvent(Event);
  2134. end;
  2135. constructor TPanel.Init(var Bounds: TRect);
  2136. begin
  2137. inherited Init(Bounds);
  2138. Options:=Options or (ofSelectable+ofTopSelect);
  2139. GrowMode:=gfGrowHiX+gfGrowHiY;
  2140. end;
  2141. procedure TAdvMessageBox.HandleEvent(var Event: TEvent);
  2142. var I: integer;
  2143. begin
  2144. if (not CanCancel) and (Event.What=evCommand) and (Event.Command=cmCancel) then
  2145. ClearEvent(Event);
  2146. inherited HandleEvent(Event);
  2147. case Event.What of
  2148. evCommand:
  2149. begin
  2150. for I:=Low(UserButtonCmd) to High(UserButtonCmd) do
  2151. if Event.Command=UserButtonCmd[I] then
  2152. if State and sfModal <> 0 then
  2153. begin
  2154. EndModal(Event.Command);
  2155. ClearEvent(Event);
  2156. end;
  2157. end;
  2158. end;
  2159. end;
  2160. procedure ClearFormatParams;
  2161. begin
  2162. FormatParamCount:=0; FillChar(FormatParams,sizeof(FormatParams),0);
  2163. FormatParamStrCount:=0;
  2164. end;
  2165. procedure AddFormatParam(P: pointer);
  2166. begin
  2167. AddFormatParamInt(ptrint(P));
  2168. end;
  2169. procedure AddFormatParamInt(L: longint);
  2170. begin
  2171. Inc(FormatParamCount);
  2172. FormatParams[FormatParamCount]:=L;
  2173. end;
  2174. procedure AddFormatParamChar(C: char);
  2175. begin
  2176. AddFormatParamInt(ord(C));
  2177. end;
  2178. procedure AddFormatParamStr(const S: string);
  2179. begin
  2180. Inc(FormatParamStrCount);
  2181. FormatParamStrs[FormatParamStrCount]:=S;
  2182. AddFormatParam(@FormatParamStrs[FormatParamStrCount]);
  2183. end;
  2184. function FormatStrF(const Format: string; var Params): string;
  2185. var S: string;
  2186. begin
  2187. S:='';
  2188. FormatStr(S,Format,Params);
  2189. FormatStrF:=S;
  2190. end;
  2191. function FormatStrStr(const Format, Param: string): string;
  2192. var S: string;
  2193. P: pointer;
  2194. begin
  2195. P:=@Param;
  2196. FormatStr(S,Format,P);
  2197. FormatStrStr:=S;
  2198. end;
  2199. function FormatStrStr2(const Format, Param1,Param2: string): string;
  2200. var S: string;
  2201. P: array[1..2] of pointer;
  2202. begin
  2203. P[1]:=@Param1; P[2]:=@Param2;
  2204. FormatStr(S,Format,P);
  2205. FormatStrStr2:=S;
  2206. end;
  2207. function FormatStrStr3(const Format, Param1,Param2,Param3: string): string;
  2208. var S: string;
  2209. P: array[1..3] of pointer;
  2210. begin
  2211. P[1]:=@Param1;
  2212. P[2]:=@Param2;
  2213. P[3]:=@Param3;
  2214. FormatStr(S,Format,P);
  2215. FormatStrStr3:=S;
  2216. end;
  2217. function FormatStrInt(const Format: string; L: longint): string;
  2218. var S: string;
  2219. begin
  2220. FormatStr(S,Format,L);
  2221. FormatStrInt:=S;
  2222. end;
  2223. const
  2224. Cmds: array[0..3] of word =
  2225. (cmYes, cmNo, cmOK, cmCancel);
  2226. var
  2227. ButtonName: array[0..3] of string;
  2228. Titles: array[0..3] of string;
  2229. function AdvMessageBox(const Msg: String; Params: Pointer; AOptions: longint): Word;
  2230. var
  2231. R: TRect;
  2232. begin
  2233. R.Assign(0, 0, 0, 0);
  2234. AdvMessageBox := AdvMessageBoxRect(R, Msg, Params, AOptions);
  2235. end;
  2236. procedure GetStaticTextDimensions(const S: string; ViewWidth: integer; var MaxCols, Rows: integer);
  2237. var
  2238. Center: Boolean;
  2239. I, J, L, P, Y: Sw_Integer;
  2240. CurLine: string;
  2241. begin
  2242. MaxCols:=0;
  2243. L := Length(S);
  2244. P := 1;
  2245. Y := 0;
  2246. Center := False;
  2247. while (Y < 32767) and (P<=length(S)) do
  2248. begin
  2249. CurLine:='';
  2250. if P <= L then
  2251. begin
  2252. if S[P] = #3 then
  2253. begin
  2254. Center := True;
  2255. Inc(P);
  2256. end;
  2257. I := P;
  2258. repeat
  2259. J := P;
  2260. while (P <= L) and (S[P] = ' ') do Inc(P);
  2261. while (P <= L) and (S[P] <> ' ') and (S[P] <> #13) do Inc(P);
  2262. until (P > L) or (P >= I + ViewWidth) or (S[P] = #13);
  2263. if P > I + ViewWidth then
  2264. if J > I then P := J else P := I + ViewWidth;
  2265. if Center then J := (ViewWidth - P + I) div 2 else J := 0;
  2266. CurLine:=CurLine+copy(S,I,P-I);
  2267. { MoveBuf(B[J], S[I], Color, P - I);}
  2268. while (P <= L) and (S[P] = ' ') do Inc(P);
  2269. if (P <= L) and (S[P] = #13) then
  2270. begin
  2271. Center := False;
  2272. Inc(P);
  2273. if (P <= L) and (S[P] = #10) then Inc(P);
  2274. end;
  2275. end;
  2276. if length(CurLine)>MaxCols then
  2277. MaxCols:=length(CurLine);
  2278. { WriteLine(0, Y, Size.X, 1, B);}
  2279. Inc(Y);
  2280. end;
  2281. Rows:=Y;
  2282. end;
  2283. function AdvMessageBoxRect(var R: TRect; const Msg: String; Params: Pointer; AOptions: longint): Word;
  2284. var
  2285. I, X, ButtonCount: Sw_Integer;
  2286. Dialog: PAdvMessageBox;
  2287. Control: PView;
  2288. ButtonList: array[0..4] of PView;
  2289. S,BtnName: String;
  2290. Cols,Rows: integer;
  2291. begin
  2292. FormatStr(S, Msg, Params^);
  2293. if R.Empty then
  2294. begin
  2295. GetStaticTextDimensions(S,40,Cols,Rows);
  2296. if Cols<32 then Cols:=32; if Rows=0 then Rows:=1;
  2297. R.Assign(0,0,3+Cols+3,Rows+6);
  2298. if (AOptions and mfInsertInApp)= 0 then
  2299. R.Move((Desktop^.Size.X-(R.B.X-R.A.X)) div 2,(Desktop^.Size.Y-(R.B.Y-R.A.Y)) div 2)
  2300. else
  2301. R.Move((Application^.Size.X-(R.B.X-R.A.X)) div 2,(Application^.Size.Y-(R.B.Y-R.A.Y)) div 2);
  2302. end;
  2303. New(Dialog,Init(R, Titles[AOptions and $3]));
  2304. with Dialog^ do
  2305. begin
  2306. CanCancel:=(Options and mfCantCancel)=0;
  2307. R.Assign(3,2, Size.X-2,Size.Y-3);
  2308. Control := New(PStaticText, Init(R, S));
  2309. Insert(Control);
  2310. X := -2;
  2311. ButtonCount := 0;
  2312. for I := 0 to 3 do
  2313. if AOptions and ($10000 shl I) <> 0 then
  2314. begin
  2315. BtnName:=UserButtonName[I+1];
  2316. R.Assign(0, 0, Max(10,length(BtnName)+2), 2);
  2317. Control := New(PButton, Init(R, BtnName, UserButtonCmd[I+1], bfNormal));
  2318. Inc(X, Control^.Size.X + 2);
  2319. ButtonList[ButtonCount] := Control;
  2320. Inc(ButtonCount);
  2321. end;
  2322. for I := 0 to 3 do
  2323. if AOptions and ($0100 shl I) <> 0 then
  2324. begin
  2325. R.Assign(0, 0, 10, 2);
  2326. Control := New(PButton, Init(R, ButtonName[I], Cmds[i], bfNormal));
  2327. Inc(X, Control^.Size.X + 2);
  2328. ButtonList[ButtonCount] := Control;
  2329. Inc(ButtonCount);
  2330. end;
  2331. X := (Size.X - X) div 2;
  2332. for I := 0 to ButtonCount - 1 do
  2333. begin
  2334. Control := ButtonList[I];
  2335. Insert(Control);
  2336. Control^.MoveTo(X, Size.Y - 3);
  2337. Inc(X, Control^.Size.X + 2);
  2338. end;
  2339. SelectNext(False);
  2340. end;
  2341. if AOptions and mfInsertInApp = 0 then
  2342. AdvMessageBoxRect := DeskTop^.ExecView(Dialog)
  2343. else
  2344. AdvMessageBoxRect := Application^.ExecView(Dialog);
  2345. Dispose(Dialog, Done);
  2346. end;
  2347. procedure InitAdvMsgBox;
  2348. begin
  2349. ButtonName[0] := slYes;
  2350. ButtonName[1] := slNo;
  2351. ButtonName[2] := slOk;
  2352. ButtonName[3] := slCancel;
  2353. Titles[0] := sWarning;
  2354. Titles[1] := sError;
  2355. Titles[2] := sInformation;
  2356. Titles[3] := sConfirm;
  2357. end;
  2358. procedure DoneAdvMsgBox;
  2359. begin
  2360. end;
  2361. procedure RegisterWViews;
  2362. begin
  2363. {$ifndef NOOBJREG}
  2364. RegisterType(RAdvancedListBox);
  2365. RegisterType(RColorStaticText);
  2366. RegisterType(RHSListBox);
  2367. RegisterType(RDlgWindow);
  2368. {$endif}
  2369. end;
  2370. END.