wviews.pas 66 KB

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