wviews.pas 66 KB

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