wviews.pas 65 KB

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