wviews.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  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. unit WViews;
  12. interface
  13. uses Objects,Drivers,Views,Menus,Dialogs;
  14. const
  15. evIdle = $8000;
  16. cmLocalMenu = 54100;
  17. cmUpdate = 54101;
  18. cmListFocusChanged = 54102;
  19. type
  20. PCenterDialog = ^TCenterDialog;
  21. TCenterDialog = object(TDialog)
  22. constructor Init(var Bounds: TRect; ATitle: TTitleStr);
  23. end;
  24. PAdvancedMenuBox = ^TAdvancedMenuBox;
  25. TAdvancedMenuBox = object(TMenuBox)
  26. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  27. AParentMenu: PMenuView): PMenuView; virtual;
  28. function Execute: Word; virtual;
  29. end;
  30. PAdvancedMenuPopUp = ^TAdvancedMenuPopup;
  31. TAdvancedMenuPopUp = object(TMenuPopup)
  32. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  33. AParentMenu: PMenuView): PMenuView; virtual;
  34. function Execute: Word; virtual;
  35. end;
  36. PAdvancedMenuBar = ^TAdvancedMenuBar;
  37. TAdvancedMenuBar = object(TMenuBar)
  38. constructor Init(var Bounds: TRect; AMenu: PMenu);
  39. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  40. AParentMenu: PMenuView): PMenuView; virtual;
  41. procedure Update; virtual;
  42. procedure HandleEvent(var Event: TEvent); virtual;
  43. function Execute: Word; virtual;
  44. end;
  45. PAdvancedStaticText = ^TAdvancedStaticText;
  46. TAdvancedStaticText = object(TStaticText)
  47. procedure SetText(S: string); virtual;
  48. end;
  49. PAdvancedListBox = ^TAdvancedListBox;
  50. TAdvancedListBox = object(TListBox)
  51. Default: boolean;
  52. procedure FocusItem(Item: sw_integer); virtual;
  53. procedure HandleEvent(var Event: TEvent); virtual;
  54. end;
  55. TLocalMenuListBox = object(TAdvancedListBox)
  56. procedure HandleEvent(var Event: TEvent); virtual;
  57. procedure LocalMenu(P: TPoint); virtual;
  58. function GetLocalMenu: PMenu; virtual;
  59. function GetCommandTarget: PView; virtual;
  60. private
  61. LastLocalCmd: word;
  62. end;
  63. PColorStaticText = ^TColorStaticText;
  64. TColorStaticText = object(TAdvancedStaticText)
  65. Color: word;
  66. DontWrap: boolean;
  67. Delta: TPoint;
  68. constructor Init(var Bounds: TRect; AText: String; AColor: word);
  69. procedure Draw; virtual;
  70. end;
  71. PHSListBox = ^THSListBox;
  72. THSListBox = object(TLocalMenuListBox)
  73. constructor Init(var Bounds: TRect; ANumCols: Word; AHScrollBar, AVScrollBar: PScrollBar);
  74. end;
  75. PDlgWindow = ^TDlgWindow;
  76. TDlgWindow = object(TDialog)
  77. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  78. end;
  79. PAdvancedStatusLine = ^TAdvancedStatusLine;
  80. TAdvancedStatusLine = object(TStatusLine)
  81. StatusText: PString;
  82. function GetStatusText: string; virtual;
  83. procedure SetStatusText(const S: string); virtual;
  84. procedure ClearStatusText; virtual;
  85. procedure Draw; virtual;
  86. end;
  87. procedure InsertOK(ADialog: PDialog);
  88. procedure InsertButtons(ADialog: PDialog);
  89. procedure ErrorBox(const S: string; Params: pointer);
  90. procedure WarningBox(const S: string; Params: pointer);
  91. procedure InformationBox(const S: string; Params: pointer);
  92. function ConfirmBox(const S: string; Params: pointer; CanCancel: boolean): word;
  93. procedure ShowMessage(Msg: string);
  94. procedure HideMessage;
  95. function SearchMenuItem(Menu: PMenu; Cmd: word): PMenuItem;
  96. procedure SetMenuItemParam(Menu: PMenuItem; Param: string);
  97. function IsSubMenu(P: PMenuItem): boolean;
  98. function IsSeparator(P: PMenuItem): boolean;
  99. function UpdateMenu(M: PMenu): boolean;
  100. function SearchSubMenu(M: PMenu; Index: integer): PMenuItem;
  101. procedure AppendMenuItem(M: PMenu; I: PMenuItem);
  102. procedure RemoveMenuItem(Menu: PMenu; I: PMenuItem);
  103. function GetMenuItemBefore(Menu:PMenu; BeforeOf: PMenuItem): PMenuItem;
  104. procedure NotImplemented;
  105. implementation
  106. uses Commands,App,MsgBox;
  107. const
  108. MessageDialog : PCenterDialog = nil;
  109. {*****************************************************************************
  110. TCenterDialog
  111. *****************************************************************************}
  112. constructor TCenterDialog.Init(var Bounds: TRect; ATitle: TTitleStr);
  113. begin
  114. inherited Init(Bounds,ATitle);
  115. Options:=Options or ofCentered;
  116. end;
  117. function TAdvancedMenuBox.NewSubView(var Bounds: TRect; AMenu: PMenu;
  118. AParentMenu: PMenuView): PMenuView;
  119. begin
  120. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  121. end;
  122. function TAdvancedMenuBox.Execute: word;
  123. type
  124. MenuAction = (DoNothing, DoSelect, DoReturn);
  125. var
  126. AutoSelect: Boolean;
  127. Action: MenuAction;
  128. Ch: Char;
  129. Result: Word;
  130. ItemShown, P: PMenuItem;
  131. Target: PMenuView;
  132. R: TRect;
  133. E: TEvent;
  134. MouseActive: Boolean;
  135. function IsDisabled(Item: PMenuItem): boolean;
  136. var Found: boolean;
  137. begin
  138. Found:=Item^.Disabled or IsSeparator(Item);
  139. if (Found=false) and (IsSubMenu(Item)=false) then
  140. Found:=CommandEnabled(Item^.Command)=false;
  141. IsDisabled:=Found;
  142. end;
  143. procedure TrackMouse;
  144. var
  145. Mouse: TPoint;
  146. R: TRect;
  147. OldC: PMenuItem;
  148. begin
  149. MakeLocal(E.Where, Mouse);
  150. OldC:=Current;
  151. Current := Menu^.Items;
  152. while Current <> nil do
  153. begin
  154. GetItemRect(Current, R);
  155. if R.Contains(Mouse) then
  156. begin
  157. MouseActive := True;
  158. Break;
  159. end;
  160. Current := Current^.Next;
  161. end;
  162. if (Current<>nil) and IsDisabled(Current) then
  163. begin
  164. Current:={OldC}nil;
  165. MouseActive:=false;
  166. end;
  167. end;
  168. procedure TrackKey(FindNext: Boolean);
  169. procedure NextItem;
  170. begin
  171. Current := Current^.Next;
  172. if Current = nil then Current := Menu^.Items;
  173. end;
  174. procedure PrevItem;
  175. var
  176. P: PMenuItem;
  177. begin
  178. P := Current;
  179. if P = Menu^.Items then P := nil;
  180. repeat NextItem until Current^.Next = P;
  181. end;
  182. begin
  183. if Current <> nil then
  184. repeat
  185. if FindNext then NextItem else PrevItem;
  186. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  187. end;
  188. function MouseInOwner: Boolean;
  189. var
  190. Mouse: TPoint;
  191. R: TRect;
  192. begin
  193. MouseInOwner := False;
  194. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  195. begin
  196. ParentMenu^.MakeLocal(E.Where, Mouse);
  197. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  198. MouseInOwner := R.Contains(Mouse);
  199. end;
  200. end;
  201. function MouseInMenus: Boolean;
  202. var
  203. P: PMenuView;
  204. begin
  205. P := ParentMenu;
  206. while (P <> nil) and (P^.MouseInView(E.Where)=false) do
  207. P := P^.ParentMenu;
  208. MouseInMenus := P <> nil;
  209. end;
  210. function TopMenu: PMenuView;
  211. var
  212. P: PMenuView;
  213. begin
  214. P := @Self;
  215. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  216. TopMenu := P;
  217. end;
  218. begin
  219. AutoSelect := False; E.What:=evNothing;
  220. Result := 0;
  221. ItemShown := nil;
  222. Current := Menu^.Default;
  223. MouseActive := False;
  224. if UpdateMenu(Menu) then
  225. begin
  226. if Current<>nil then
  227. if Current^.Disabled then
  228. TrackKey(true);
  229. repeat
  230. Action := DoNothing;
  231. GetEvent(E);
  232. case E.What of
  233. evMouseDown:
  234. if MouseInView(E.Where) or MouseInOwner then
  235. begin
  236. TrackMouse;
  237. if Size.Y = 1 then AutoSelect := True;
  238. end else Action := DoReturn;
  239. evMouseUp:
  240. begin
  241. TrackMouse;
  242. if MouseInOwner then
  243. Current := Menu^.Default
  244. else
  245. if (Current <> nil) and (Current^.Name <> nil) then
  246. Action := DoSelect
  247. else
  248. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  249. else
  250. begin
  251. Current := Menu^.Default;
  252. if Current = nil then Current := Menu^.Items;
  253. Action := DoNothing;
  254. end;
  255. end;
  256. evMouseMove:
  257. if E.Buttons <> 0 then
  258. begin
  259. TrackMouse;
  260. if not (MouseInView(E.Where) or MouseInOwner) and
  261. MouseInMenus then Action := DoReturn;
  262. end;
  263. evKeyDown:
  264. case CtrlToArrow(E.KeyCode) of
  265. kbUp, kbDown:
  266. if Size.Y <> 1 then
  267. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  268. if E.KeyCode = kbDown then AutoSelect := True;
  269. kbLeft, kbRight:
  270. if ParentMenu = nil then
  271. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  272. Action := DoReturn;
  273. kbHome, kbEnd:
  274. if Size.Y <> 1 then
  275. begin
  276. Current := Menu^.Items;
  277. if E.KeyCode = kbEnd then TrackKey(False);
  278. end;
  279. kbEnter:
  280. begin
  281. if Size.Y = 1 then AutoSelect := True;
  282. Action := DoSelect;
  283. end;
  284. kbEsc:
  285. begin
  286. Action := DoReturn;
  287. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  288. ClearEvent(E);
  289. end;
  290. else
  291. Target := @Self;
  292. Ch := GetAltChar(E.KeyCode);
  293. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  294. P := Target^.FindItem(Ch);
  295. if P = nil then
  296. begin
  297. P := TopMenu^.HotKey(E.KeyCode);
  298. if (P <> nil) and CommandEnabled(P^.Command) then
  299. begin
  300. Result := P^.Command;
  301. Action := DoReturn;
  302. end
  303. end else
  304. if Target = @Self then
  305. begin
  306. if Size.Y = 1 then AutoSelect := True;
  307. Action := DoSelect;
  308. Current := P;
  309. end else
  310. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  311. Action := DoReturn;
  312. end;
  313. evCommand:
  314. if E.Command = cmMenu then
  315. begin
  316. AutoSelect := False;
  317. if ParentMenu <> nil then Action := DoReturn;
  318. end else Action := DoReturn;
  319. end;
  320. if ItemShown <> Current then
  321. begin
  322. ItemShown := Current;
  323. DrawView;
  324. end;
  325. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  326. if Current <> nil then with Current^ do if Name <> nil then
  327. if Command = 0 then
  328. begin
  329. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  330. GetItemRect(Current, R);
  331. R.A.X := R.A.X + Origin.X;
  332. R.A.Y := R.B.Y + Origin.Y;
  333. R.B := Owner^.Size;
  334. if Size.Y = 1 then Dec(R.A.X);
  335. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  336. Result := Owner^.ExecView(Target);
  337. Dispose(Target, Done);
  338. end else if Action = DoSelect then Result := Command;
  339. if (Result <> 0) and CommandEnabled(Result) then
  340. begin
  341. Action := DoReturn;
  342. ClearEvent(E);
  343. end
  344. else
  345. Result := 0;
  346. until Action = DoReturn;
  347. end;
  348. if E.What <> evNothing then
  349. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  350. if Current <> nil then
  351. begin
  352. Menu^.Default := Current;
  353. Current := nil;
  354. DrawView;
  355. end;
  356. Execute := Result;
  357. end;
  358. function TAdvancedMenuPopup.NewSubView(var Bounds: TRect; AMenu: PMenu;
  359. AParentMenu: PMenuView): PMenuView;
  360. begin
  361. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  362. end;
  363. function TAdvancedMenuPopup.Execute: word;
  364. type
  365. MenuAction = (DoNothing, DoSelect, DoReturn);
  366. var
  367. AutoSelect: Boolean;
  368. Action: MenuAction;
  369. Ch: Char;
  370. Result: Word;
  371. ItemShown, P: PMenuItem;
  372. Target: PMenuView;
  373. R: TRect;
  374. E: TEvent;
  375. MouseActive: Boolean;
  376. function IsDisabled(Item: PMenuItem): boolean;
  377. var Found: boolean;
  378. begin
  379. Found:=Item^.Disabled or IsSeparator(Item);
  380. if (Found=false) and (IsSubMenu(Item)=false) then
  381. Found:=CommandEnabled(Item^.Command)=false;
  382. IsDisabled:=Found;
  383. end;
  384. procedure TrackMouse;
  385. var
  386. Mouse: TPoint;
  387. R: TRect;
  388. OldC: PMenuItem;
  389. begin
  390. MakeLocal(E.Where, Mouse);
  391. OldC:=Current;
  392. Current := Menu^.Items;
  393. while Current <> nil do
  394. begin
  395. GetItemRect(Current, R);
  396. if R.Contains(Mouse) then
  397. begin
  398. MouseActive := True;
  399. Break;
  400. end;
  401. Current := Current^.Next;
  402. end;
  403. if (Current<>nil) and IsDisabled(Current) then
  404. begin
  405. Current:={OldC}nil;
  406. MouseActive:=false;
  407. end;
  408. end;
  409. procedure TrackKey(FindNext: Boolean);
  410. procedure NextItem;
  411. begin
  412. Current := Current^.Next;
  413. if Current = nil then Current := Menu^.Items;
  414. end;
  415. procedure PrevItem;
  416. var
  417. P: PMenuItem;
  418. begin
  419. P := Current;
  420. if P = Menu^.Items then P := nil;
  421. repeat NextItem until Current^.Next = P;
  422. end;
  423. begin
  424. if Current <> nil then
  425. repeat
  426. if FindNext then NextItem else PrevItem;
  427. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  428. end;
  429. function MouseInOwner: Boolean;
  430. var
  431. Mouse: TPoint;
  432. R: TRect;
  433. begin
  434. MouseInOwner := False;
  435. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  436. begin
  437. ParentMenu^.MakeLocal(E.Where, Mouse);
  438. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  439. MouseInOwner := R.Contains(Mouse);
  440. end;
  441. end;
  442. function MouseInMenus: Boolean;
  443. var
  444. P: PMenuView;
  445. begin
  446. P := ParentMenu;
  447. while (P <> nil) and (P^.MouseInView(E.Where)=false) do
  448. P := P^.ParentMenu;
  449. MouseInMenus := P <> nil;
  450. end;
  451. function TopMenu: PMenuView;
  452. var
  453. P: PMenuView;
  454. begin
  455. P := @Self;
  456. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  457. TopMenu := P;
  458. end;
  459. begin
  460. AutoSelect := False; E.What:=evNothing;
  461. Result := 0;
  462. ItemShown := nil;
  463. Current := Menu^.Default;
  464. MouseActive := False;
  465. if UpdateMenu(Menu) then
  466. begin
  467. if Current<>nil then
  468. if Current^.Disabled then
  469. TrackKey(true);
  470. repeat
  471. Action := DoNothing;
  472. GetEvent(E);
  473. case E.What of
  474. evMouseDown:
  475. if MouseInView(E.Where) or MouseInOwner then
  476. begin
  477. TrackMouse;
  478. if Size.Y = 1 then AutoSelect := True;
  479. end else Action := DoReturn;
  480. evMouseUp:
  481. begin
  482. TrackMouse;
  483. if MouseInOwner then
  484. Current := Menu^.Default
  485. else
  486. if (Current <> nil) and (Current^.Name <> nil) then
  487. Action := DoSelect
  488. else
  489. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  490. else
  491. begin
  492. Current := Menu^.Default;
  493. if Current = nil then Current := Menu^.Items;
  494. Action := DoNothing;
  495. end;
  496. end;
  497. evMouseMove:
  498. if E.Buttons <> 0 then
  499. begin
  500. TrackMouse;
  501. if not (MouseInView(E.Where) or MouseInOwner) and
  502. MouseInMenus then Action := DoReturn;
  503. end;
  504. evKeyDown:
  505. case CtrlToArrow(E.KeyCode) of
  506. kbUp, kbDown:
  507. if Size.Y <> 1 then
  508. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  509. if E.KeyCode = kbDown then AutoSelect := True;
  510. kbLeft, kbRight:
  511. if ParentMenu = nil then
  512. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  513. Action := DoReturn;
  514. kbHome, kbEnd:
  515. if Size.Y <> 1 then
  516. begin
  517. Current := Menu^.Items;
  518. if E.KeyCode = kbEnd then TrackKey(False);
  519. end;
  520. kbEnter:
  521. begin
  522. if Size.Y = 1 then AutoSelect := True;
  523. Action := DoSelect;
  524. end;
  525. kbEsc:
  526. begin
  527. Action := DoReturn;
  528. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  529. ClearEvent(E);
  530. end;
  531. else
  532. Target := @Self;
  533. Ch := GetAltChar(E.KeyCode);
  534. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  535. P := Target^.FindItem(Ch);
  536. if P = nil then
  537. begin
  538. P := TopMenu^.HotKey(E.KeyCode);
  539. if (P <> nil) and CommandEnabled(P^.Command) then
  540. begin
  541. Result := P^.Command;
  542. Action := DoReturn;
  543. end
  544. end else
  545. if Target = @Self then
  546. begin
  547. if Size.Y = 1 then AutoSelect := True;
  548. Action := DoSelect;
  549. Current := P;
  550. end else
  551. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  552. Action := DoReturn;
  553. end;
  554. evCommand:
  555. if E.Command = cmMenu then
  556. begin
  557. AutoSelect := False;
  558. if ParentMenu <> nil then Action := DoReturn;
  559. end else Action := DoReturn;
  560. end;
  561. if ItemShown <> Current then
  562. begin
  563. ItemShown := Current;
  564. DrawView;
  565. end;
  566. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  567. if Current <> nil then with Current^ do if Name <> nil then
  568. if Command = 0 then
  569. begin
  570. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  571. GetItemRect(Current, R);
  572. R.A.X := R.A.X + Origin.X;
  573. R.A.Y := R.B.Y + Origin.Y;
  574. R.B := Owner^.Size;
  575. if Size.Y = 1 then Dec(R.A.X);
  576. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  577. Result := Owner^.ExecView(Target);
  578. Dispose(Target, Done);
  579. end else if Action = DoSelect then Result := Command;
  580. if (Result <> 0) and CommandEnabled(Result) then
  581. begin
  582. Action := DoReturn;
  583. ClearEvent(E);
  584. end
  585. else
  586. Result := 0;
  587. until Action = DoReturn;
  588. end;
  589. if E.What <> evNothing then
  590. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  591. if Current <> nil then
  592. begin
  593. Menu^.Default := Current;
  594. Current := nil;
  595. DrawView;
  596. end;
  597. Execute := Result;
  598. end;
  599. constructor TAdvancedMenuBar.Init(var Bounds: TRect; AMenu: PMenu);
  600. begin
  601. inherited Init(Bounds, AMenu);
  602. EventMask:=EventMask or evBroadcast;
  603. end;
  604. function TAdvancedMenuBar.NewSubView(var Bounds: TRect; AMenu: PMenu;
  605. AParentMenu: PMenuView): PMenuView;
  606. begin
  607. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  608. end;
  609. procedure TAdvancedMenuBar.Update;
  610. begin
  611. UpdateMenu(Menu);
  612. DrawView;
  613. end;
  614. procedure TAdvancedMenuBar.HandleEvent(var Event: TEvent);
  615. begin
  616. case Event.What of
  617. evBroadcast :
  618. case Event.Command of
  619. cmCommandSetChanged : Update;
  620. cmUpdate : Update;
  621. end;
  622. end;
  623. inherited HandleEvent(Event);
  624. end;
  625. function TAdvancedMenuBar.Execute: word;
  626. type
  627. MenuAction = (DoNothing, DoSelect, DoReturn);
  628. var
  629. AutoSelect: Boolean;
  630. Action: MenuAction;
  631. Ch: Char;
  632. Result: Word;
  633. ItemShown, P: PMenuItem;
  634. Target: PMenuView;
  635. R: TRect;
  636. E: TEvent;
  637. MouseActive: Boolean;
  638. function IsDisabled(Item: PMenuItem): boolean;
  639. var Dis : boolean;
  640. begin
  641. Dis:=Item^.Disabled or IsSeparator(Item);
  642. if (Dis=false) and (IsSubMenu(Item)=false) then
  643. Dis:=CommandEnabled(Item^.Command)=false;
  644. IsDisabled:=Dis;
  645. end;
  646. procedure TrackMouse;
  647. var
  648. Mouse: TPoint;
  649. R: TRect;
  650. OldC: PMenuItem;
  651. begin
  652. MakeLocal(E.Where, Mouse);
  653. OldC:=Current;
  654. Current := Menu^.Items;
  655. while Current <> nil do
  656. begin
  657. GetItemRect(Current, R);
  658. if R.Contains(Mouse) then
  659. begin
  660. MouseActive := True;
  661. Break;
  662. end;
  663. Current := Current^.Next;
  664. end;
  665. if (Current<>nil) and IsDisabled(Current) then
  666. Current:=nil;
  667. end;
  668. procedure TrackKey(FindNext: Boolean);
  669. procedure NextItem;
  670. begin
  671. Current := Current^.Next;
  672. if Current = nil then Current := Menu^.Items;
  673. end;
  674. procedure PrevItem;
  675. var
  676. P: PMenuItem;
  677. begin
  678. P := Current;
  679. if P = Menu^.Items then P := nil;
  680. repeat NextItem until Current^.Next = P;
  681. end;
  682. begin
  683. if Current <> nil then
  684. repeat
  685. if FindNext then NextItem else PrevItem;
  686. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  687. end;
  688. function MouseInOwner: Boolean;
  689. var
  690. Mouse: TPoint;
  691. R: TRect;
  692. begin
  693. MouseInOwner := False;
  694. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  695. begin
  696. ParentMenu^.MakeLocal(E.Where, Mouse);
  697. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  698. MouseInOwner := R.Contains(Mouse);
  699. end;
  700. end;
  701. function MouseInMenus: Boolean;
  702. var
  703. P: PMenuView;
  704. begin
  705. P := ParentMenu;
  706. while (P <> nil) and not P^.MouseInView(E.Where) do P := P^.ParentMenu;
  707. MouseInMenus := P <> nil;
  708. end;
  709. function TopMenu: PMenuView;
  710. var
  711. P: PMenuView;
  712. begin
  713. P := @Self;
  714. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  715. TopMenu := P;
  716. end;
  717. begin
  718. AutoSelect := False; E.What:=evNothing;
  719. Result := 0;
  720. ItemShown := nil;
  721. Current := Menu^.Default;
  722. MouseActive := False;
  723. if UpdateMenu(Menu) then
  724. begin
  725. if Current<>nil then
  726. if Current^.Disabled then
  727. TrackKey(true);
  728. repeat
  729. Action := DoNothing;
  730. GetEvent(E);
  731. case E.What of
  732. evMouseDown:
  733. if MouseInView(E.Where) or MouseInOwner then
  734. begin
  735. TrackMouse;
  736. if Size.Y = 1 then AutoSelect := True;
  737. end else Action := DoReturn;
  738. evMouseUp:
  739. begin
  740. TrackMouse;
  741. if MouseInOwner then
  742. Current := Menu^.Default
  743. else
  744. if (Current <> nil) and (Current^.Name <> nil) then
  745. Action := DoSelect
  746. else
  747. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  748. else
  749. begin
  750. Current := Menu^.Default;
  751. if Current = nil then Current := Menu^.Items;
  752. Action := DoNothing;
  753. end;
  754. end;
  755. evMouseMove:
  756. if E.Buttons <> 0 then
  757. begin
  758. TrackMouse;
  759. if not (MouseInView(E.Where) or MouseInOwner) and
  760. MouseInMenus then Action := DoReturn;
  761. end;
  762. evKeyDown:
  763. case CtrlToArrow(E.KeyCode) of
  764. kbUp, kbDown:
  765. if Size.Y <> 1 then
  766. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  767. if E.KeyCode = kbDown then AutoSelect := True;
  768. kbLeft, kbRight:
  769. if ParentMenu = nil then
  770. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  771. Action := DoReturn;
  772. kbHome, kbEnd:
  773. if Size.Y <> 1 then
  774. begin
  775. Current := Menu^.Items;
  776. if E.KeyCode = kbEnd then TrackKey(False);
  777. end;
  778. kbEnter:
  779. begin
  780. if Size.Y = 1 then AutoSelect := True;
  781. Action := DoSelect;
  782. end;
  783. kbEsc:
  784. begin
  785. Action := DoReturn;
  786. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  787. ClearEvent(E);
  788. end;
  789. else
  790. Target := @Self;
  791. Ch := GetAltChar(E.KeyCode);
  792. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  793. P := Target^.FindItem(Ch);
  794. if P = nil then
  795. begin
  796. P := TopMenu^.HotKey(E.KeyCode);
  797. if (P <> nil) and CommandEnabled(P^.Command) then
  798. begin
  799. Result := P^.Command;
  800. Action := DoReturn;
  801. end
  802. end else
  803. if Target = @Self then
  804. begin
  805. if Size.Y = 1 then AutoSelect := True;
  806. Action := DoSelect;
  807. Current := P;
  808. end else
  809. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  810. Action := DoReturn;
  811. end;
  812. evCommand:
  813. if E.Command = cmMenu then
  814. begin
  815. AutoSelect := False;
  816. if ParentMenu <> nil then Action := DoReturn;
  817. end else Action := DoReturn;
  818. end;
  819. if ItemShown <> Current then
  820. begin
  821. ItemShown := Current;
  822. DrawView;
  823. end;
  824. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  825. if Current <> nil then with Current^ do if Name <> nil then
  826. if Command = 0 then
  827. begin
  828. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  829. GetItemRect(Current, R);
  830. R.A.X := R.A.X + Origin.X;
  831. R.A.Y := R.B.Y + Origin.Y;
  832. R.B := Owner^.Size;
  833. if Size.Y = 1 then Dec(R.A.X);
  834. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  835. Result := Owner^.ExecView(Target);
  836. Dispose(Target, Done);
  837. end else if Action = DoSelect then Result := Command;
  838. if (Result <> 0) and CommandEnabled(Result) then
  839. begin
  840. Action := DoReturn;
  841. ClearEvent(E);
  842. end
  843. else
  844. Result := 0;
  845. until Action = DoReturn;
  846. end;
  847. if E.What <> evNothing then
  848. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  849. if Current <> nil then
  850. begin
  851. Menu^.Default := Current;
  852. Current := nil;
  853. DrawView;
  854. end;
  855. Execute := Result;
  856. end;
  857. procedure TAdvancedStaticText.SetText(S: string);
  858. begin
  859. if Text<>nil then DisposeStr(Text);
  860. Text:=NewStr(S);
  861. DrawView;
  862. end;
  863. procedure TAdvancedListBox.FocusItem(Item: sw_integer);
  864. begin
  865. inherited FocusItem(Item);
  866. Message(Owner,evBroadcast,cmListFocusChanged,@Self);
  867. end;
  868. procedure TAdvancedListBox.HandleEvent(var Event: TEvent);
  869. begin
  870. case Event.What of
  871. evMouseDown :
  872. if MouseInView(Event.Where) and (Event.Double) then
  873. begin
  874. inherited HandleEvent(Event);
  875. if Range>Focused then SelectItem(Focused);
  876. end;
  877. evBroadcast :
  878. case Event.Command of
  879. cmListItemSelected :
  880. Message(Owner,evBroadcast,cmDefault,nil);
  881. end;
  882. end;
  883. inherited HandleEvent(Event);
  884. end;
  885. constructor TColorStaticText.Init(var Bounds: TRect; AText: String; AColor: word);
  886. begin
  887. inherited Init(Bounds,AText);
  888. Color:=AColor;
  889. end;
  890. procedure TColorStaticText.Draw;
  891. var
  892. C: word;
  893. Center: Boolean;
  894. I, J, L, P, Y: Integer;
  895. B: TDrawBuffer;
  896. S: String;
  897. T: string;
  898. CurS: string;
  899. TildeCount,Po: integer;
  900. TempS: string;
  901. begin
  902. if Size.X=0 then Exit;
  903. if DontWrap=false then
  904. begin
  905. C:=Color;
  906. GetText(S);
  907. L := Length(S);
  908. P := 1;
  909. Y := 0;
  910. Center := False;
  911. while Y < Size.Y do
  912. begin
  913. MoveChar(B, ' ', Lo(C), Size.X);
  914. if P <= L then
  915. begin
  916. if S[P] = #3 then
  917. begin
  918. Center := True;
  919. Inc(P);
  920. end;
  921. I := P;
  922. repeat
  923. J := P;
  924. while (P <= L) and (S[P] = ' ') do Inc(P);
  925. while (P <= L) and (S[P] <> ' ') and (S[P] <> #13) do Inc(P);
  926. until (P > L) or (P >= I + Size.X) or (S[P] = #13);
  927. TildeCount:=0; TempS:=copy(S,I,P-I);
  928. repeat
  929. Po:=Pos('~',TempS);
  930. if Po>0 then begin Inc(TildeCount); Delete(TempS,1,Po); end;
  931. until Po=0;
  932. if P > I + Size.X + TildeCount then
  933. if J > I then P := J else P := I + Size.X;
  934. T:=copy(S,I,P-I);
  935. if Center then J := (Size.X - {P + I}CStrLen(T)) div 2 else J := 0;
  936. MoveCStr(B[J],T,C);
  937. while (P <= L) and (S[P] = ' ') do Inc(P);
  938. if (P <= L) and (S[P] = #13) then
  939. begin
  940. Center := False;
  941. Inc(P);
  942. if (P <= L) and (S[P] = #10) then Inc(P);
  943. end;
  944. end;
  945. WriteLine(0, Y, Size.X, 1, B);
  946. Inc(Y);
  947. end;
  948. end { Wrap=false } else
  949. begin
  950. C := Color;
  951. GetText(S);
  952. I:=1;
  953. for Y:=0 to Size.Y-1 do
  954. begin
  955. MoveChar(B, ' ', Lo(C), Size.X);
  956. CurS:='';
  957. if S<>'' then
  958. begin
  959. P:=Pos(#13,S);
  960. if P=0 then P:=length(S)+1;
  961. CurS:=copy(S,1,P-1);
  962. CurS:=copy(CurS,Delta.X+1,255);
  963. CurS:=copy(CurS,1,MaxViewWidth);
  964. Delete(S,1,P);
  965. end;
  966. if CurS<>'' then MoveCStr(B,CurS,C);
  967. WriteLine(0,Y,Size.X,1,B);
  968. end;
  969. end;
  970. end;
  971. constructor THSListBox.Init(var Bounds: TRect; ANumCols: Word; AHScrollBar, AVScrollBar: PScrollBar);
  972. begin
  973. inherited Init(Bounds,ANumCols,AVScrollBar);
  974. HScrollBar:=AHScrollBar;
  975. end;
  976. constructor TDlgWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  977. begin
  978. inherited Init(Bounds,ATitle);
  979. Number:=ANumber;
  980. Flags:=Flags or (wfMove + wfGrow + wfClose + wfZoom);
  981. end;
  982. procedure TLocalMenuListBox.LocalMenu(P: TPoint);
  983. var M: PMenu;
  984. MV: PAdvancedMenuPopUp;
  985. R: TRect;
  986. Re: word;
  987. begin
  988. M:=GetLocalMenu;
  989. if M=nil then Exit;
  990. if LastLocalCmd<>0 then
  991. M^.Default:=SearchMenuItem(M,LastLocalCmd);
  992. Desktop^.GetExtent(R);
  993. MakeGlobal(P,R.A); {Desktop^.MakeLocal(R.A,R.A);}
  994. New(MV, Init(R, M));
  995. Re:=Application^.ExecView(MV);
  996. if M^.Default=nil then LastLocalCmd:=0
  997. else LastLocalCmd:=M^.Default^.Command;
  998. Dispose(MV, Done);
  999. if Re<>0 then
  1000. Message(GetCommandTarget,evCommand,Re,@Self);
  1001. end;
  1002. function TLocalMenuListBox.GetLocalMenu: PMenu;
  1003. begin
  1004. GetLocalMenu:=nil;
  1005. Abstract;
  1006. end;
  1007. function TLocalMenuListBox.GetCommandTarget: PView;
  1008. begin
  1009. GetCommandTarget:=@Self;
  1010. end;
  1011. procedure TLocalMenuListBox.HandleEvent(var Event: TEvent);
  1012. var DontClear: boolean;
  1013. P: TPoint;
  1014. begin
  1015. case Event.What of
  1016. evMouseDown :
  1017. if MouseInView(Event.Where) and (Event.Buttons=mbRightButton) then
  1018. begin
  1019. MakeLocal(Event.Where,P); Inc(P.X); Inc(P.Y);
  1020. LocalMenu(P);
  1021. ClearEvent(Event);
  1022. end;
  1023. evKeyDown :
  1024. begin
  1025. DontClear:=false;
  1026. case Event.KeyCode of
  1027. kbAltF10 : Message(@Self,evCommand,cmLocalMenu,@Self);
  1028. else DontClear:=true;
  1029. end;
  1030. if DontClear=false then ClearEvent(Event);
  1031. end;
  1032. evCommand :
  1033. begin
  1034. DontClear:=false;
  1035. case Event.Command of
  1036. cmLocalMenu :
  1037. begin
  1038. P:=Cursor; Inc(P.X); Inc(P.Y);
  1039. LocalMenu(P);
  1040. end;
  1041. else DontClear:=true;
  1042. end;
  1043. if not DontClear then ClearEvent(Event);
  1044. end;
  1045. end;
  1046. inherited HandleEvent(Event);
  1047. end;
  1048. function TAdvancedStatusLine.GetStatusText: string;
  1049. var S: string;
  1050. begin
  1051. if StatusText=nil then S:='' else S:=StatusText^;
  1052. GetStatusText:=S;
  1053. end;
  1054. procedure TAdvancedStatusLine.SetStatusText(const S: string);
  1055. begin
  1056. if StatusText<>nil then DisposeStr(StatusText);
  1057. StatusText:=NewStr(S);
  1058. DrawView;
  1059. end;
  1060. procedure TAdvancedStatusLine.ClearStatusText;
  1061. begin
  1062. SetStatusText('');
  1063. end;
  1064. procedure TAdvancedStatusLine.Draw;
  1065. var B: TDrawBuffer;
  1066. C: word;
  1067. S: string;
  1068. begin
  1069. S:=GetStatusText;
  1070. if S='' then inherited Draw else
  1071. begin
  1072. C:=GetColor(1);
  1073. MoveChar(B,' ',C,Size.X);
  1074. MoveStr(B[1],S,C);
  1075. WriteLine(0,0,Size.X,Size.Y,B);
  1076. end;
  1077. end;
  1078. procedure ErrorBox(const S: string; Params: pointer);
  1079. begin
  1080. MessageBox(S,Params,mfError+mfInsertInApp+mfOKButton);
  1081. end;
  1082. procedure WarningBox(const S: string; Params: pointer);
  1083. begin
  1084. MessageBox(S,Params,mfWarning+mfInsertInApp+mfOKButton);
  1085. end;
  1086. procedure InformationBox(const S: string; Params: pointer);
  1087. begin
  1088. MessageBox(S,Params,mfInformation+mfInsertInApp+mfOKButton);
  1089. end;
  1090. function ConfirmBox(const S: string; Params: pointer; CanCancel: boolean): word;
  1091. begin
  1092. ConfirmBox:=MessageBox(S,Params,mfConfirmation+mfInsertInApp+mfYesButton+mfNoButton+integer(CanCancel)*mfCancelButton);
  1093. end;
  1094. function IsSeparator(P: PMenuItem): boolean;
  1095. begin
  1096. IsSeparator:=(P<>nil) and (P^.Name=nil) and (P^.HelpCtx=hcNoContext);
  1097. end;
  1098. function IsSubMenu(P: PMenuItem): boolean;
  1099. begin
  1100. IsSubMenu:=(P<>nil) and (P^.Name<>nil) and (P^.Command=0) and (P^.SubMenu<>nil);
  1101. end;
  1102. function SearchMenuItem(Menu: PMenu; Cmd: word): PMenuItem;
  1103. var P,I: PMenuItem;
  1104. begin
  1105. I:=nil;
  1106. if Menu=nil then P:=nil else P:=Menu^.Items;
  1107. while (P<>nil) and (I=nil) do
  1108. begin
  1109. if IsSubMenu(P) then
  1110. I:=SearchMenuItem(P^.SubMenu,Cmd);
  1111. if I=nil then
  1112. if P^.Command=Cmd then I:=P else
  1113. P:=P^.Next;
  1114. end;
  1115. SearchMenuItem:=I;
  1116. end;
  1117. procedure SetMenuItemParam(Menu: PMenuItem; Param: string);
  1118. begin
  1119. if Menu=nil then Exit;
  1120. if Menu^.Param<>nil then DisposeStr(Menu^.Param);
  1121. Menu^.Param:=NewStr(Param);
  1122. end;
  1123. function UpdateMenu(M: PMenu): boolean;
  1124. var P: PMenuItem;
  1125. IsEnabled: boolean;
  1126. begin
  1127. if M=nil then begin UpdateMenu:=false; Exit; end;
  1128. P:=M^.Items; IsEnabled:=false;
  1129. while (P<>nil) do
  1130. begin
  1131. if IsSubMenu(P) then
  1132. P^.Disabled:=not UpdateMenu(P^.SubMenu);
  1133. if (IsSeparator(P)=false) and (P^.Disabled=false) and (Application^.CommandEnabled(P^.Command)=true) then
  1134. IsEnabled:=true;
  1135. P:=P^.Next;
  1136. end;
  1137. UpdateMenu:=IsEnabled;
  1138. end;
  1139. function SearchSubMenu(M: PMenu; Index: integer): PMenuItem;
  1140. var P,C: PMenuItem;
  1141. Count: integer;
  1142. begin
  1143. P:=nil; Count:=-1;
  1144. if M<>nil then C:=M^.Items else C:=nil;
  1145. while (C<>nil) and (P=nil) do
  1146. begin
  1147. if IsSubMenu(C) then
  1148. begin
  1149. Inc(Count);
  1150. if Count=Index then P:=C;
  1151. end;
  1152. C:=C^.Next;
  1153. end;
  1154. SearchSubMenu:=P;
  1155. end;
  1156. procedure AppendMenuItem(M: PMenu; I: PMenuItem);
  1157. var P: PMenuItem;
  1158. begin
  1159. if (M=nil) or (I=nil) then Exit;
  1160. I^.Next:=nil;
  1161. if M^.Items=nil then M^.Items:=I else
  1162. begin
  1163. P:=M^.Items;
  1164. while (P^.Next<>nil) do P:=P^.Next;
  1165. P^.Next:=I;
  1166. end;
  1167. end;
  1168. procedure DisposeMenuItem(P: PMenuItem);
  1169. begin
  1170. if P<>nil then
  1171. begin
  1172. if IsSubMenu(P) then DisposeMenu(P^.SubMenu) else
  1173. if IsSeparator(P)=false then
  1174. if P^.Param<>nil then DisposeStr(P^.Param);
  1175. if P^.Name<>nil then DisposeStr(P^.Name);
  1176. Dispose(P);
  1177. end;
  1178. end;
  1179. procedure RemoveMenuItem(Menu: PMenu; I: PMenuItem);
  1180. var P,PrevP: PMenuItem;
  1181. begin
  1182. if (Menu=nil) or (I=nil) then Exit;
  1183. P:=Menu^.Items; PrevP:=nil;
  1184. while (P<>nil) do
  1185. begin
  1186. if P=I then
  1187. begin
  1188. if Menu^.Items<>I then PrevP^.Next:=P^.Next
  1189. else Menu^.Items:=P^.Next;
  1190. DisposeMenuItem(P);
  1191. Break;
  1192. end;
  1193. PrevP:=P; P:=P^.Next;
  1194. end;
  1195. end;
  1196. function GetMenuItemBefore(Menu: PMenu; BeforeOf: PMenuItem): PMenuItem;
  1197. var P,C: PMenuItem;
  1198. begin
  1199. P:=nil;
  1200. if Menu<>nil then C:=Menu^.Items else C:=nil;
  1201. while (C<>nil) do
  1202. begin
  1203. if C^.Next=BeforeOf then begin P:=C; Break; end;
  1204. C:=C^.Next;
  1205. end;
  1206. GetMenuItemBefore:=P;
  1207. end;
  1208. procedure NotImplemented;
  1209. begin
  1210. InformationBox('This function is not yet implemented...',nil);
  1211. end;
  1212. procedure InsertButtons(ADialog: PDialog);
  1213. var R : TRect;
  1214. W,H : integer;
  1215. X : integer;
  1216. X1,X2: Sw_integer;
  1217. begin
  1218. with ADialog^ do
  1219. begin
  1220. GetExtent(R);
  1221. W:=R.B.X-R.A.X; H:=(R.B.Y-R.A.Y);
  1222. R.Assign(0,0,W,H+3); ChangeBounds(R);
  1223. X:=W div 2; X1:=X div 2+1; X2:=X+X1-1;
  1224. R.Assign(X1-3,H,X1+7,H+2);
  1225. Insert(New(PButton, Init(R, 'O~K~', cmOK, bfDefault)));
  1226. R.Assign(X2-7,H,X2+3,H+2);
  1227. Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  1228. SelectNext(true);
  1229. end;
  1230. end;
  1231. procedure InsertOK(ADialog: PDialog);
  1232. var BW: Sw_integer;
  1233. R: TRect;
  1234. begin
  1235. with ADialog^ do
  1236. begin
  1237. GetBounds(R); R.Grow(0,1); Inc(R.B.Y);
  1238. ChangeBounds(R);
  1239. BW:=10;
  1240. R.A.Y:=R.B.Y-2; R.B.Y:=R.A.Y+2;
  1241. R.A.X:=R.A.X+(R.B.X-R.A.X-BW) div 2; R.B.X:=R.A.X+BW;
  1242. Insert(New(PButton, Init(R, 'O~K~', cmOK, bfDefault)));
  1243. SelectNext(true);
  1244. end;
  1245. end;
  1246. procedure ShowMessage(Msg: string);
  1247. var R: TRect;
  1248. Width: integer;
  1249. begin
  1250. Width:=length(Msg)+4*2;
  1251. if Width<(Desktop^.Size.X div 2) then Width:=(Desktop^.Size.X div 2);
  1252. R.Assign(0,0,Width,5);
  1253. New(MessageDialog, Init(R, ''));
  1254. with MessageDialog^ do
  1255. begin
  1256. Flags:=0;
  1257. GetExtent(R); R.Grow(-4,-2);
  1258. if copy(Msg,1,1)<>^C then Msg:=^C+Msg;
  1259. Insert(New(PStaticText, Init(R, Msg)));
  1260. end;
  1261. Application^.Insert(MessageDialog);
  1262. end;
  1263. procedure HideMessage;
  1264. begin
  1265. if MessageDialog<>nil then
  1266. begin
  1267. Application^.Delete(MessageDialog);
  1268. Dispose(MessageDialog, Done);
  1269. MessageDialog:=nil;
  1270. end;
  1271. end;
  1272. END.
  1273. {
  1274. $Log$
  1275. Revision 1.1 1999-03-01 15:51:43 peter
  1276. + Log
  1277. }