2
0

wviews.pas 67 KB

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