fpgtkext.pp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. {$mode objfpc}{$h+}
  2. unit FPgtkExt;
  3. interface
  4. uses FPgtk, gtk, gdk, glib, sysutils, classes;
  5. { ==== Application object ==== }
  6. type
  7. TFPgtkApplication = class
  8. Private
  9. FMainwindow : TFPgtkWindow;
  10. FMainDestroysignal : guint;
  11. procedure SetMainWindow (Value:TFPgtkWindow);
  12. procedure MainDestroyed (Sender:TFPgtkObject; data:pointer);
  13. Public
  14. constructor Create;
  15. destructor Destroy; override;
  16. procedure Run;
  17. property Mainwindow : TFPgtkWindow read FMainwindow write SetMainwindow;
  18. end;
  19. var
  20. Application : TFPgtkApplication;
  21. { ==== Extra Widgets ==== }
  22. type
  23. TFPgtkFileEntry = class (TFPgtkHBox)
  24. private
  25. FEdit : TFPgtkEntry;
  26. FButton : TFPgtkButton;
  27. FImage : TFPgtkPixmap;
  28. procedure OpenFileSelection (Sender : TFPgtkObject; data : pointer);
  29. procedure CloseFileSelection (Sender:TFPgtkWindow; DialogResult:pointer;
  30. Action:integer; initiator:TFPgtkObject);
  31. procedure SetFilename (Value : string);
  32. function GetFilename : string;
  33. public
  34. constructor create;
  35. property Edit : TFPgtkEntry read FEdit;
  36. property Button : TFPgtkButton read FButton;
  37. property Image : TFPgtkPixmap read FImage;
  38. property Filename : string read GetFilename write SetFilename;
  39. end;
  40. TFPgtkCheckedButton = class (TFPgtkToggleButton)
  41. private
  42. FChecked, FUnchecked : TFPgtkPixmap;
  43. procedure ChangeCheck (Sender:TFPgtkObject; data:pointer);
  44. public
  45. constructor Create;
  46. constructor CreateWithLabel (aText:string);
  47. constructor CreateWithLabel (aText:string; AccelGroup : PGtkAccelGroup);
  48. end;
  49. { ==== Widget who needs a scrollwindow ==== }
  50. type
  51. TFPgtkScrollText = class (TFPgtkScrolledWindow)
  52. private
  53. FText : TFPgtkText;
  54. procedure SetTooltip (Value : string);
  55. function GetTooltip : string;
  56. function GetUdpatePolicy : TGtkUpdateType;
  57. procedure SetUpdatePolicy (Value : TGtkUpdateType);
  58. function GetText : string;
  59. procedure SetText (Value : string);
  60. function GetLines : TStrings;
  61. public
  62. constructor create;
  63. procedure Clear;
  64. property TheText : TFPgtkText read FText;
  65. property Tooltip : string read GetTooltip write SetTooltip;
  66. property UpdatePolicy : TGtkUpdateType read GetUdpatePolicy write SetUpdatePolicy;
  67. property Text : string read GetText write SetText;
  68. property Lines : TStrings read GetLines;
  69. end;
  70. TFPgtkScrollList = class (TFPgtkScrolledWindow)
  71. private
  72. FList : TFPgtkList;
  73. public
  74. constructor create;
  75. property List : TFPgtkList read FList;
  76. end;
  77. TFPgtkScrollCList = class (TFPgtkScrolledWindow)
  78. private
  79. FCList : TFPgtkCList;
  80. public
  81. constructor create (CountColumns : integer);
  82. property CList : TFPgtkCList read FCList;
  83. end;
  84. TFPgtkScrollTree = class (TFPgtkScrolledWindow)
  85. private
  86. FTree : TFPgtkTree;
  87. public
  88. constructor create;
  89. property Tree : TFPgtkTree read FTree;
  90. end;
  91. { ==== Message dialogs ==== }
  92. type
  93. TModalResult = Low(Integer)..High(Integer);
  94. TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
  95. TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
  96. mbAll, mbNoToAll, mbYesToAll, mbHelp);
  97. TMsgDlgButtons = set of TMsgDlgBtn;
  98. const
  99. mbYesNo = [mbYes,mbNo];
  100. mbYesNoCancel = [mbYes, mbNo, mbCancel];
  101. mbOKCancel = [mbOK, mbCancel];
  102. mbAbortRetryIgnore = [mbAbort, mbRetry, mbIgnore];
  103. mrNone = 0;
  104. mrOK = mrNone + 1;
  105. mrCancel = mrNone + 2;
  106. mrAbort = mrNone + 3;
  107. mrRetry = mrNone + 4;
  108. mrIgnore = mrNone + 5;
  109. mrYes = mrNone + 6;
  110. mrNo = mrNone + 7;
  111. mrAll = mrNone + 8;
  112. mrNoToAll = mrNone + 9;
  113. mrYesToAll = mrNone + 10;
  114. function MessageDlg(const aMsg: string; DlgType: TMsgDlgType;
  115. Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
  116. function MessageDlg(const Fmt: string; Args : Array of const; DlgType: TMsgDlgType;
  117. Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
  118. procedure ShowMessage (const aTitle, aMessage : string);
  119. { ==== Menu handling ==== }
  120. type
  121. TAccelKeyDef = record
  122. Key : guint;
  123. Mods : TGdkModifierType;
  124. AG : PGtkAccelGroup;
  125. end;
  126. PAccelKeyDef = ^TAccelKeyDef;
  127. TAccelModifier = (amShift, amLock, amControl, amMod1, amMod2, amMod3, amMod4,
  128. amMod5, amButton1, amButton2, amButton3, amButton4, amButton5,
  129. amRelease);
  130. TAccelModifiersSet = set of TAccelModifier;
  131. const
  132. amAlt = amMod1;
  133. gdk_Alt_mask = gdk_mod1_Mask;
  134. DefaultAccelFlags : TGtkAccelFlags = GTK_ACCEL_VISIBLE;
  135. function RemoveUnderscore (s : string) : string;
  136. function ConvertAccelModifier (amSet : TAccelModifiersSet) : TGdkModifierType;
  137. function ConvertModifierType (Mods : TGdkModifierType) : TAccelModifiersSet;
  138. function MakeAccelKeyDef (aWindow : TFPgtkWindow; anAG : integer; aKey : guint; aMods : TGdkModifierType) : PAccelKeyDef; overload;
  139. function MakeAccelKeyDef (aWindow : TFPgtkWindow; anAG : integer; aKey : guint; aMods : TAccelModifiersSet) : PAccelKeyDef; overload;
  140. function MakeAccelKeyDef (anAG : PGtkAccelGroup; aKey : guint; aMods : TGdkModifierType) : PAccelKeyDef; overload;
  141. function MakeAccelKeyDef (anAG : PGtkAccelGroup; aKey : guint; aMods : TAccelModifiersSet) : PAccelKeyDef; overload;
  142. function NewMenuBar (items : array of TFPgtkMenuItem) : TFPgtkMenuBar;
  143. function NewMenu (ATitle : string; items : array of TFPgtkMenuItem) : TFPgtkMenu;
  144. function NewMenuItem (ACaption, AToolTip, AprivText : string; Accelerator : PAccelKeyDef;
  145. ActivateFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkMenuItem; overload;
  146. function NewMenuItem (ACaption, AToolTip, AprivText : string;
  147. ActivateFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkMenuItem; overload;
  148. function NewMenuItem (ACaption : string; Accelerator : PAccelKeyDef;
  149. ActivateFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkMenuItem; overload;
  150. function NewMenuItem (ACaption : string; ActivateFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkMenuItem; overload;
  151. function NewMenuItem (ACaption : string) : TFPgtkMenuItem; overload;
  152. function NewLine : TFPgtkMenuItem;
  153. function NewTearOffMenu : TFPgtkTearOffMenuItem;
  154. function NewSubMenu (ACaption, ATooltip, AprivText : string; Accelerator : PAccelKeyDef;
  155. Items : array of TFPgtkMenuItem) : TFPgtkMenuItem; Overload;
  156. function NewSubMenu (ACaption, ATooltip, AprivText : string;
  157. Items : array of TFPgtkMenuItem) : TFPgtkMenuItem; Overload;
  158. function NewSubMenu (ACaption : string; Accelerator : PAccelKeyDef;
  159. Items : array of TFPgtkMenuItem) : TFPgtkMenuItem; Overload;
  160. function NewSubMenu (ACaption : string; Items : array of TFPgtkMenuItem) : TFPgtkMenuItem; Overload;
  161. function NewCheckMenuItem (ACaption, AToolTip, AprivText : string; Accelerator : PAccelKeyDef;
  162. ToggledFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkCheckMenuItem; Overload;
  163. function NewCheckMenuItem (ACaption, AToolTip, AprivText : string;
  164. ToggledFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkCheckMenuItem; Overload;
  165. function NewCheckMenuItem (ACaption : string; Accelerator : PAccelKeyDef;
  166. ToggledFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkCheckMenuItem; Overload;
  167. function NewCheckMenuItem (ACaption : string; ToggledFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkCheckMenuItem; Overload;
  168. procedure InsertMenuItemGroup (InMenu : TFPgtkMenuShell; position : integer; MenuItems : TFPgtkItemGroup); Overload;
  169. procedure InsertMenuItemGroup (InMenu : TFPgtkMenuShell; position : integer;
  170. MenuItems : TFPgtkItemGroup; ActivateProc : TFPgtkSignalFunction; ActivateData : pointer); Overload;
  171. procedure AppendMenuItemGroup (InMenu : TFPgtkmenuShell; MenuItems : TFPgtkItemGroup); Overload;
  172. procedure AppendMenuItemGroup (InMenu : TFPgtkmenuShell; MenuItems : TFPgtkItemGroup;
  173. ActivateProc : TFPgtkSignalFunction; ActivateData : pointer); Overload;
  174. procedure PrependMenuItemGroup (InMenu : TFPgtkmenuShell; MenuItems : TFPgtkItemGroup); Overload;
  175. procedure PrependMenuItemGroup (InMenu : TFPgtkmenuShell; MenuItems : TFPgtkItemGroup;
  176. ActivateProc : TFPgtkSignalFunction; ActivateData : pointer); Overload;
  177. implementation
  178. resourcestring
  179. rsNothingToRun = 'No main window defined, nothing to do...';
  180. rsErrorTitle = 'Error occured';
  181. rsMessageTitle = 'Message';
  182. sErrWrongItemType = 'Items in list are not from TFPgtkMenuItem class.';
  183. { TFPgtkApplication }
  184. constructor TFPgtkApplication.Create;
  185. begin
  186. gtk_init (@argc, @argv);
  187. inherited create;
  188. FMainWindow := nil;
  189. end;
  190. destructor TFPgtkApplication.Destroy;
  191. begin
  192. if assigned (FMainWindow) then
  193. FMainWindow.Free;
  194. gtk_Exit (0);
  195. inherited;
  196. end;
  197. procedure TFPgtkApplication.SetMainWindow (Value : TFPgtkWindow);
  198. begin
  199. if FMainWindow <> Value then
  200. begin
  201. if assigned (FMainWindow) and (FMainDestroySignal > 0) then
  202. FMainWindow.signalDisconnect (FMainDestroySignal);
  203. FMainWindow := Value;
  204. if Assigned (Value) then
  205. FMainDestroySignal := FMainWindow.ConnectDestroy (@MainDestroyed, nil);
  206. end;
  207. end;
  208. procedure TFPgtkApplication.MainDestroyed (Sender:TFPgtkObject; data:pointer);
  209. begin
  210. FMainWindow := nil;
  211. FMainDestroySignal := 0;
  212. gtk_main_quit;
  213. end;
  214. procedure TFPgtkApplication.Run;
  215. begin
  216. if assigned (FMainWindow) then
  217. while assigned (FMainWindow) do
  218. try
  219. FMainWindow.execute (nil, nil, nil);
  220. //gtk_main;
  221. FreeFPgtkObjects (nil);
  222. except
  223. on e : exception do
  224. ShowMessage (rsErrorTitle, e.message);
  225. end
  226. else
  227. ShowMessage (rsMessageTitle, rsNothingToRun);
  228. end;
  229. { TFPgtkScrollText }
  230. constructor TFPgtkScrollText.create;
  231. begin
  232. inherited create (nil,nil);
  233. FText := TFPgtkText.Create;
  234. Add (FText);
  235. HPolicy := Gtk_Policy_Never;
  236. end;
  237. function TFPgtkScrollText.GetTooltip : string;
  238. begin
  239. result := inherited Tooltip;
  240. end;
  241. procedure TFPgtkScrollText.SetTooltip (Value : string);
  242. begin
  243. TheText.Tooltip := Value;
  244. inherited Tooltip := Value;
  245. end;
  246. function TFPgtkScrollText.GetUdpatePolicy : TGtkUpdateType;
  247. begin
  248. result := VScrollbar.UpdatePolicy;
  249. end;
  250. procedure TFPgtkScrollText.Clear;
  251. begin
  252. if assigned(TheText) then
  253. TheText.Clear;
  254. end;
  255. procedure TFPgtkScrollText.SetUpdatePolicy (Value : TGtkUpdateType);
  256. begin
  257. VScrollbar.UpdatePolicy := Value;
  258. {$ifndef gtkwin}
  259. HScrollbar.UpdatePolicy := Value;
  260. {$endif}
  261. end;
  262. function TFPgtkScrollText.GetText : string;
  263. begin
  264. if assigned(TheText) then
  265. begin
  266. result := TheText.Text;
  267. end
  268. else
  269. begin
  270. result := '';
  271. end;
  272. end;
  273. procedure TFPgtkScrollText.SetText (Value : string);
  274. begin
  275. if assigned (TheText) then
  276. TheText.Text := Value;
  277. end;
  278. function TFPgtkScrollText.GetLines : TStrings;
  279. begin
  280. if assigned (TheText) then
  281. result := TheText.Lines
  282. else
  283. result := nil;
  284. end;
  285. { TFPgtkScrollList }
  286. constructor TFPgtkScrollList.create;
  287. begin
  288. inherited create (nil, nil);
  289. setusize (100, 40);
  290. FList := TFPgtkList.Create;
  291. AddWithViewport (FList);
  292. end;
  293. { TFPgtkScrollCList }
  294. constructor TFPgtkScrollCList.create (CountColumns : integer);
  295. begin
  296. inherited create (nil, nil);
  297. setusize (100, 40);
  298. FCList := TFPgtkCList.Create (CountColumns);
  299. Add (FCList);
  300. end;
  301. { TFPgtkScrollTree }
  302. constructor TFPgtkScrollTree.create;
  303. begin
  304. inherited create (nil, nil);
  305. FTree := TFPgtkTree.Create;
  306. AddWithViewport (FTree);
  307. FTree.Show;
  308. end;
  309. { Menu functions }
  310. function RemoveUnderscore (s : string) : string;
  311. begin
  312. result := stringreplace (s, '_', '', [rfReplaceAll]);
  313. end;
  314. type
  315. TFPgtkMenuItemType = class of TFPgtkMenuItem;
  316. function MakeAccelKeyDef (aWindow : TFPgtkWindow; anAG : integer; aKey : guint; aMods : TGdkModifierType) : PAccelKeyDef;
  317. begin
  318. new (result);
  319. with result^ do
  320. begin
  321. AG := aWindow.AccelGroups[anAG];
  322. Key := aKey;
  323. Mods := aMods;
  324. end;
  325. end;
  326. function MakeAccelKeyDef (aWindow : TFPgtkWindow; anAG : integer; aKey : guint; aMods : TAccelModifiersSet) : PAccelKeyDef;
  327. begin
  328. new (result);
  329. with result^ do
  330. begin
  331. AG := aWindow.AccelGroups[anAG];
  332. Key := aKey;
  333. Mods := ConvertAccelModifier (aMods);
  334. end;
  335. end;
  336. function MakeAccelKeyDef (anAG : PGtkAccelGroup; aKey : guint; aMods : TGdkModifierType) : PAccelKeyDef;
  337. begin
  338. new (result);
  339. with result^ do
  340. begin
  341. AG := anAG;
  342. Key := aKey;
  343. Mods := aMods;
  344. end;
  345. end;
  346. function MakeAccelKeyDef (anAG : PGtkAccelGroup; aKey : guint; aMods : TAccelModifiersSet) : PAccelKeyDef;
  347. begin
  348. new (result);
  349. with result^ do
  350. begin
  351. AG := anAG;
  352. Key := aKey;
  353. Mods := ConvertAccelModifier (aMods);
  354. end;
  355. end;
  356. function ConvertAccelModifier (amSet : TAccelModifiersSet) : TGdkModifierType;
  357. var am : TAccelModifier;
  358. begin
  359. result := 0;
  360. for am := low(TAccelModifier) to high (TAccelModifier) do
  361. if am in amSet then
  362. result := result + (1 shl ord(am));
  363. end;
  364. function ConvertModifierType (Mods : TGdkModifierType) : TAccelModifiersSet;
  365. var am : TAccelModifier;
  366. begin
  367. result := [];
  368. for am := low(TAccelModifier) to high (TAccelModifier) do
  369. if (Mods and (1 shl ord(am))) <> 0 then
  370. result := result + [am];
  371. end;
  372. function NewMenuBar (items : array of TFPgtkMenuItem) : TFPgtkMenuBar;
  373. var r : integer;
  374. begin
  375. result := TFPgtkMenuBar.Create;
  376. with result do
  377. for r := low(items) to high (items) do
  378. append (items[r]);
  379. end;
  380. function NewMenu (ATitle : string; items : array of TFPgtkMenuItem) : TFPgtkMenu;
  381. var r : integer;
  382. AG : PGtkAccelGroup;
  383. m : TFPgtkMenuItem;
  384. begin
  385. result := TFPgtkMenu.Create;
  386. with result do
  387. begin
  388. Title := ATitle;
  389. ag := AccelGroup;
  390. for r := low(items) to high(items) do
  391. begin
  392. m := items[r];
  393. Append (m);
  394. if m.AccelKey <> 0 then
  395. m.AcceleratorAdd (AG, sgActivateItem, m.AccelKey, 0, TGtkAccelFlags(0));
  396. end;
  397. end;
  398. end;
  399. function CreateMenuItem (Atype : TFPgtkMenuItemType; ACaption, ATooltip,
  400. APrivText : string; Accelerator : PAccelKeyDef) : TFPgtkMenuItem;
  401. begin
  402. result := AType.CreateWithLabel (ACaption);
  403. if (ATooltip <> '') or (APrivText <> '') then
  404. result.Tooltip := ComposeTooltip (ATooltip, APrivText);
  405. if assigned(accelerator) then
  406. begin
  407. with Accelerator^ do
  408. result.AcceleratorAdd (AG, sgActivateItem, Key, Mods, DefaultAccelFlags);
  409. dispose (Accelerator);
  410. end;
  411. end;
  412. function NewMenuItem (ACaption, AToolTip, AprivText : string; Accelerator : PAccelKeyDef;
  413. ActivateFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkMenuItem;
  414. begin
  415. result := CreateMenuItem (TFPgtkMenuItem, ACaption, ATooltip, APrivtext, Accelerator);
  416. if assigned (ActivateFunc) then
  417. result.ConnectActivate (ActivateFunc, AData);
  418. end;
  419. function NewMenuItem (ACaption, AToolTip, AprivText : string;
  420. ActivateFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkMenuItem;
  421. begin
  422. result := NewMenuItem (aCaption, aTooltip, aPrivText, nil, ActivateFunc, aData);
  423. end;
  424. function NewMenuItem (ACaption : string; Accelerator : PAccelKeyDef;
  425. ActivateFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkMenuItem;
  426. begin
  427. result := NewMenuItem (aCaption, '', '', Accelerator, ActivateFunc, aData);
  428. end;
  429. function NewMenuItem (ACaption : string; ActivateFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkMenuItem;
  430. begin
  431. result := NewMenuItem (aCaption, '', '', nil, ActivateFunc, aData);
  432. end;
  433. function NewMenuItem (ACaption : string) : TFPgtkMenuItem;
  434. begin
  435. result := NewMenuItem (aCaption, '', '', nil, nil, nil);
  436. end;
  437. function NewLine : TFPgtkMenuItem;
  438. begin
  439. result := TFPgtkMenuItem.Create;
  440. end;
  441. function NewTearOffMenu : TFPgtkTearOffMenuItem;
  442. begin
  443. result := TFPgtkTearOffMenuItem.create;
  444. end;
  445. function NewSubMenu (ACaption, ATooltip, AprivText : string; Accelerator : PAccelKeyDef;
  446. Items : array of TFPgtkMenuItem) : TFPgtkMenuItem;
  447. begin
  448. result := CreateMenuItem (TFPgtkMenuItem, ACaption, ATooltip, APrivText, Accelerator);
  449. result.SetSubmenu (NewMenu ('', Items));
  450. end;
  451. function NewSubMenu (ACaption, ATooltip, AprivText : string;
  452. Items : array of TFPgtkMenuItem) : TFPgtkMenuItem;
  453. begin
  454. result := NewSubMenu (aCaption, aTooltip, aPrivText, nil, Items);
  455. end;
  456. function NewSubMenu (ACaption : string; Accelerator : PAccelKeyDef;
  457. Items : array of TFPgtkMenuItem) : TFPgtkMenuItem;
  458. begin
  459. result := NewSubMenu (aCaption, '', '', Accelerator, Items);
  460. end;
  461. function NewSubMenu (ACaption : string; Items : array of TFPgtkMenuItem) : TFPgtkMenuItem;
  462. begin
  463. result := NewSubMenu (aCaption, '', '', nil, Items);
  464. end;
  465. function NewCheckMenuItem (ACaption, AToolTip, AprivText : string; Accelerator : PAccelKeyDef;
  466. ToggledFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkCheckMenuItem;
  467. begin
  468. result := TFPgtkCheckMenuItem(CreateMenuItem (TFPgtkCheckMenuItem, ACaption, ATooltip, APrivText, Accelerator));
  469. if assigned (ToggledFunc) then
  470. Result.ConnectToggled (ToggledFunc, AData);
  471. end;
  472. function NewCheckMenuItem (ACaption, AToolTip, AprivText : string;
  473. ToggledFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkCheckMenuItem;
  474. begin
  475. result := NewCheckMenuItem (aCaption, aToolTip, aPrivText, nil, ToggledFunc, AData);
  476. end;
  477. function NewCheckMenuItem (ACaption : string; Accelerator : PAccelKeyDef;
  478. ToggledFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkCheckMenuItem;
  479. begin
  480. result := NewCheckMenuItem (aCaption, '', '', Accelerator, ToggledFunc, AData);
  481. end;
  482. function NewCheckMenuItem (ACaption : string; ToggledFunc : TFPgtkSignalFunction; AData : pointer) : TFPgtkCheckMenuItem;
  483. begin
  484. result := NewCheckMenuItem (aCaption, '', '', nil, ToggledFunc, AData);
  485. end;
  486. procedure InsertMenuItemGroup (InMenu : TFPgtkMenuShell; position : integer; MenuItems : TFPgtkItemGroup);
  487. begin
  488. InsertMenuItemGroup (InMenu, position, MenuItems, nil, nil);
  489. end;
  490. procedure InsertMenuItemGroup (InMenu : TFPgtkMenuShell; position : integer;
  491. MenuItems : TFPgtkItemGroup; ActivateProc : TFPgtkSignalFunction; ActivateData : pointer);
  492. var r : integer;
  493. begin
  494. if (MenuItems.count > 0) then
  495. if (MenuItems.items[0] is TFPgtkMenuItem) then
  496. with InMenu do
  497. for r := MenuItems.count-1 downto 0 do
  498. begin
  499. if assigned(ActivateProc) then
  500. if assigned (ActivateData) then
  501. TFPgtkMenuItem(MenuItems.items[r]).ConnectActivate (ActivateProc, ActivateData)
  502. else
  503. TFPgtkMenuItem(MenuItems.items[r]).ConnectActivate (ActivateProc, inttopointer(r));
  504. Insert (TFPgtkMenuItem(MenuItems.items[r]), position);
  505. end
  506. else
  507. raise FPgtkException.Create (sErrWrongItemType);
  508. end;
  509. procedure AppendMenuItemGroup (InMenu : TFPgtkmenuShell; MenuItems : TFPgtkItemGroup);
  510. begin
  511. AppendMenuItemGroup (InMenu, MenuItems, nil, nil);
  512. end;
  513. procedure AppendMenuItemGroup (InMenu : TFPgtkmenuShell; MenuItems : TFPgtkItemGroup;
  514. ActivateProc : TFPgtkSignalFunction; ActivateData : pointer);
  515. var r : integer;
  516. begin
  517. if (MenuItems.count > 0) then
  518. if MenuItems.items[0] is TFPgtkMenuItem then
  519. with InMenu do
  520. for r := 0 to MenuItems.count-1 do
  521. begin
  522. if assigned(ActivateProc) then
  523. if assigned (ActivateData) then
  524. TFPgtkMenuItem(MenuItems.items[r]).ConnectActivate (ActivateProc, ActivateData)
  525. else
  526. TFPgtkMenuItem(MenuItems.items[r]).ConnectActivate (ActivateProc, inttopointer(r));
  527. Append (TFPgtkMenuItem(MenuItems.items[r]));
  528. end
  529. else
  530. raise FPgtkException.Create (sErrWrongItemType);
  531. end;
  532. procedure PrependMenuItemGroup (InMenu : TFPgtkmenuShell; MenuItems : TFPgtkItemGroup);
  533. begin
  534. PrependMenuItemGroup (InMenu, MenuItems, nil, nil);
  535. end;
  536. procedure PrependMenuItemGroup (InMenu : TFPgtkmenuShell; MenuItems : TFPgtkItemGroup;
  537. ActivateProc : TFPgtkSignalFunction; ActivateData : pointer);
  538. var r : integer;
  539. begin
  540. if (MenuItems.count > 0) then
  541. if MenuItems.items[0] is TFPgtkMenuItem then
  542. with InMenu do
  543. for r := MenuItems.count-1 downto 0 do
  544. begin
  545. if assigned(ActivateProc) then
  546. if assigned (ActivateData) then
  547. TFPgtkMenuItem(MenuItems.items[r]).ConnectActivate (ActivateProc, ActivateData)
  548. else
  549. TFPgtkMenuItem(MenuItems.items[r]).ConnectActivate (ActivateProc, inttopointer(r));
  550. Prepend (TFPgtkMenuItem(MenuItems.items[r]));
  551. end
  552. else
  553. raise FPgtkException.Create (sErrWrongItemType);
  554. end;
  555. { TFileEntryDialog }
  556. type
  557. TFileEntryDialog = class (TFPgtkFileSelection)
  558. public
  559. constructor create (AType:TGtkWindowType);
  560. procedure DoDialogInit (InitData : pointer); override;
  561. end;
  562. PFileEntryData = ^TFileEntryData;
  563. TFileEntryData = record
  564. aFilename : string;
  565. end;
  566. constructor TFileEntryDialog.Create (AType:TGtkWindowType);
  567. begin
  568. inherited;
  569. OKButton.ConnectClicked (@CloseWithResult, inttopointer(drOk));
  570. CancelButton.ConnectClicked (@CloseWindow, nil);
  571. end;
  572. procedure TFileEntryDialog.DoDialogInit (InitData : pointer);
  573. begin
  574. with PFileEntryData(InitData)^ do
  575. Filename := aFilename;
  576. end;
  577. { TFPgtkFileEntry }
  578. const
  579. FileEntryXPM =
  580. '16 13 4 1'#13#10+
  581. '. c None'#13#10+ // no color
  582. '# c #000000'#13#10+ // black
  583. 'y c #ffff00'#13#10+ // yellow
  584. 'g c #AFAF00'#13#10+ // grayed yellow
  585. '.......#####....'#13#10+
  586. '............#.#.'#13#10+
  587. '.............##.'#13#10+
  588. '..####......###.'#13#10+
  589. '##yyyy#####.....'#13#10+
  590. '#yyyyyyyyy#.....'#13#10+
  591. '#yyyyyyyyy#.....'#13#10+
  592. '#yyyy###########'#13#10+
  593. '#yyy#ggggggggg#.'#13#10+
  594. '#yy#ggggggggg#..'#13#10+
  595. '#y#ggggggggg#...'#13#10+
  596. '##ggggggggg#....'#13#10+
  597. '###########.....';
  598. var
  599. DefFileEntryPixmap : PGdkPixmap;
  600. DefFileEntryBitmask : PGdkBitmap;
  601. constructor TFPgtkFileEntry.create;
  602. begin
  603. inherited;
  604. FEdit := TFPgtkEntry.Create;
  605. FButton := TFPgtkButton.Create;
  606. FImage := TFPgtkPixMap.Create;
  607. with FImage do
  608. if assigned (DefFileEntryPixmap) then
  609. SetPixmap (DefFileEntryPixmap, DefFileEntryBitmask)
  610. else
  611. begin
  612. loadfromtext (FileEntryXPM);
  613. GetPixmap (DefFileEntryPixmap, DefFileEntryBitmask);
  614. end;
  615. with FButton do
  616. begin
  617. Add (FImage);
  618. ConnectClicked (@OpenFileSelection, self);
  619. end;
  620. PackStart (FEdit, true, true, 0);
  621. PackStart (FButton, false, true, 0);
  622. end;
  623. procedure TFPgtkFileEntry.SetFilename (Value : string);
  624. begin
  625. FEdit.Text := Value;
  626. end;
  627. function TFPgtkFileEntry.GetFilename : string;
  628. begin
  629. result := FEdit.Text;
  630. end;
  631. procedure TFPgtkFileEntry.OpenFileSelection (Sender : TFPgtkObject; data : pointer);
  632. var d : TFileEntryData;
  633. begin
  634. d.aFilename := Filename;
  635. with TFileEntryDialog.Create(gtk_window_dialog) do
  636. Execute (nil, @d, @CloseFileSelection);
  637. end;
  638. procedure TFPgtkFileEntry.CloseFileSelection (Sender:TFPgtkWindow; DialogResult:pointer;
  639. Action:integer; initiator:TFPgtkObject);
  640. begin
  641. if action = drOk then
  642. Filename := (Sender as TFileEntryDialog).Filename;
  643. end;
  644. { TFPgtkCheckedButton }
  645. const
  646. XPMChecked : array [0..17] of ansistring = (
  647. '15 13 4 1',
  648. '. c None', // None
  649. '# c #000000', // Black
  650. '- c #FFFFFF', // White
  651. 'o c #0000FF', // Blue
  652. '..............o',
  653. '.............o-',
  654. '............o-.',
  655. '..########.o-..',
  656. '..#......#o-...',
  657. '..#......o-....',
  658. '..o-....oo-....',
  659. '.ooo-..oo-.....',
  660. '..ooo-oo-#.....',
  661. '..#oooo-.#.....',
  662. '..##ooo-##.....',
  663. '.....o-........',
  664. '...............');
  665. XPMUnChecked : array [0..17] of ansistring = (
  666. '15 13 4 1',
  667. '. c None', // None
  668. '# c #000000', // Black
  669. '- c #FFFFFF', // White
  670. 'o c #0000FF', // Blue
  671. '...............',
  672. '...............',
  673. '...............',
  674. '..########.....',
  675. '..#......#.....',
  676. '..#......#.....',
  677. '..#......#.....',
  678. '..#......#.....',
  679. '..#......#.....',
  680. '..#......#.....',
  681. '..########.....',
  682. '...............',
  683. '...............');
  684. var
  685. DefChecked, DefUnchecked : PGdkPixmap;
  686. DefCheckedBM, DefUncheckedBM : PGdkBitmap;
  687. procedure TFPgtkCheckedButton.ChangeCheck (Sender:TFPgtkObject; data:pointer);
  688. var b : boolean;
  689. begin
  690. b := Active;
  691. FChecked.visible := b;
  692. FUnchecked.visible := not b;
  693. end;
  694. constructor TFPgtkCheckedButton.CreateWithLabel (aText:string);
  695. begin
  696. create;
  697. Text := aText;
  698. end;
  699. constructor TFPgtkCheckedButton.CreateWithLabel (aText:string; AccelGroup : PGtkAccelGroup);
  700. begin
  701. create;
  702. Text := aText;
  703. if (AccelKey <> 0) and assigned(AccelGroup) then
  704. AcceleratorAdd (AccelGroup, sgClicked, AccelKey, DefaultButtonModifiers, GTK_ACCEL_Visible);
  705. end;
  706. constructor TFPgtkCheckedButton.create;
  707. begin
  708. inherited;
  709. DrawIndicator := False;
  710. AddContainer := TFPgtkHBox.Create;
  711. Add (AddContainer);
  712. FChecked := TFPgtkPixMap.Create;
  713. with FChecked do
  714. if assigned (DefChecked) then
  715. SetPixmap (DefChecked, DefCheckedBM)
  716. else
  717. begin
  718. loadfromArray (XPMChecked);
  719. GetPixmap (DefChecked, DefCheckedBM);
  720. end;
  721. FUnchecked := TFPgtkPixMap.Create;
  722. with FUnchecked do
  723. if assigned (DefUnchecked) then
  724. SetPixmap (DefUnchecked, DefUncheckedBM)
  725. else
  726. begin
  727. loadfromArray (XPMUnchecked);
  728. GetPixmap (DefUnchecked, DefUncheckedBM);
  729. end;
  730. with TFPgtkBox(AddContainer) do
  731. begin
  732. PackStart (FChecked, false, false, 0);
  733. PackStart (FUnChecked, false, false, 0);
  734. end;
  735. ChangeCheck (self, nil);
  736. ConnectToggled (@ChangeCheck, nil);
  737. end;
  738. { ShowMessage }
  739. resourcestring
  740. rsOk = ' Ok ';
  741. function MessageWindow (aTitle, aMessage : string) : TFPgtkWindow;
  742. var b : TFPgtkBox;
  743. but : TFPgtkButton;
  744. l : TFPgtkLabel;
  745. AG : integer;
  746. bb : TFPgtkButtonBox;
  747. begin
  748. result := TFPgtkWindow.create (gtk_window_dialog);
  749. result.setDefaultSize (200,25);
  750. result.title := aTitle;
  751. AG := result.AccelGroupNew;
  752. b := TFPgtkVBox.create;
  753. b.Homogeneous := false;
  754. b.border := 15;
  755. b.spacing := 15;
  756. l := TFPgtkLabel.Create (aMessage);
  757. b.Packstart (l, true, true, 0); // Text to show
  758. bb := TFPgtkHButtonBox.create;
  759. bb.Layout := GTK_BUTTONBOX_DEFAULT_STYLE;
  760. b.PackEnd (bb, false, false, 0);
  761. but := TFPgtkButton.CreateWithLabel (rsOk); // Ok button to close
  762. but.ConnectClicked (@(result.CloseWindow), nil);
  763. result.AcceleratorAdd (AG, but, sgClicked, gdk_Cancel, 0, TGTKAccelFlags(0));
  764. result.AcceleratorAdd (AG, but, sgClicked, gdk_Return, 0, TGTKAccelFlags(0));
  765. bb.add (but);
  766. result.Add (b);
  767. end;
  768. procedure ShowMessage (const aTitle, aMessage : string);
  769. begin
  770. with MessageWindow (aTitle, aMessage) do
  771. Execute (nil, nil, nil);
  772. end;
  773. { MessageDialog }
  774. type
  775. TMessageDialogWindow = Class(TFPgtkWindow)
  776. FImage : TFPGtkPixMap;
  777. FLabel : TFPGtkLabel;
  778. FLTable : TFPgtkTable;
  779. FVBox : TFPgtkVBox;
  780. FButtonBox: TFPgtkButtonBox;
  781. Constructor Create(AMsg:String; DlgType:TMsgDlgType; Buttons: TMsgDlgButtons);
  782. Procedure CreateButtons(Buttons: TMsgDlgButtons);
  783. end;
  784. const
  785. IMGInfo : Array[1..37] of string = ('32 32 4 1',
  786. '. c None',
  787. ' c None',
  788. 'a c #ffffff', //#c3c3c3',
  789. '# c #0000ff',
  790. '............#######.............',
  791. '.........###aaaaaaa###..........',
  792. '.......##aaaaaaaaaaaaa##........',
  793. '......#aaaaaaa###aaaaaaa#.......',
  794. '.....#aaaaaaa#####aaaaaaa#......',
  795. '....#aaaaaaa#######aaaaaaa#.....',
  796. '...#aaaaaaaa#######aaaaaaaa#....',
  797. '..#aaaaaaaaa#######aaaaaaaaa#...',
  798. '..#aaaaaaaaaa#####aaaaaaaaaa#...',
  799. '.#aaaaaaaaaaaa###aaaaaaaaaaaa#..',
  800. '.#aaaaaaaaaaaaaaaaaaaaaaaaaaa#..',
  801. '.#aaaaaaaaaaa#####aaaaaaaaaaa#..',
  802. '#aaaaaaaaaaaa#####aaaaaaaaaaaa#.',
  803. '#aaaaaaaaaaaa#####aaaaaaaaaaaa#.',
  804. '#aaaaaaaaaaaa#####aaaaaaaaaaaa#.',
  805. '#aaaaaaaaaaaa#####aaaaaaaaaaaa#.',
  806. '#aaaaaaaaaaaa#####aaaaaaaaaaaa#.',
  807. '#aaaaaaaaaaaa#####aaaaaaaaaaaa#.',
  808. '#aaaaaaaaaaaa#####aaaaaaaaaaaa#.',
  809. '.#aaaaaaaaaaa#####aaaaaaaaaaa#..',
  810. '.#aaaaaaaaaaa#####aaaaaaaaaaa#..',
  811. '.#aaaaaaaaaa#######aaaaaaaaaa#..',
  812. '..#aaaaaaaaa#######aaaaaaaaa#...',
  813. '..#aaaaaaaaa#######aaaaaaaaa#...',
  814. '...#aaaaaaaaaaaaaaaaaaaaaaa#....',
  815. '....#aaaaaaaaaaaaaaaaaaaaa#.....',
  816. '.....#aaaaaaaaaaaaaaaaaaa#......',
  817. '......#aaaaaaaaaaaaaaaaa#.......',
  818. '.......##aaaaaaaaaaaaa##........',
  819. '.........###aaaaaaa###..........',
  820. '............#######.............',
  821. '................................');
  822. IMGWarning :Array[1..37] of string = ('32 32 4 1',
  823. '# c #000000',
  824. 'b c #9c999c',
  825. '. c None',
  826. 'a c #ffff00',
  827. '.............###................',
  828. '............#aaa#...............',
  829. '...........#aaaaa#b.............',
  830. '...........#aaaaa#bb............',
  831. '..........#aaaaaaa#bb...........',
  832. '..........#aaaaaaa#bb...........',
  833. '.........#aaaaaaaaa#bb..........',
  834. '.........#aaaaaaaaa#bb..........',
  835. '........#aaaaaaaaaaa#bb.........',
  836. '........#aaaa###aaaa#bb.........',
  837. '.......#aaaa#####aaaa#bb........',
  838. '.......#aaaa#####aaaa#bb........',
  839. '......#aaaaa#####aaaaa#bb.......',
  840. '......#aaaaa#####aaaaa#bb.......',
  841. '.....#aaaaaa#####aaaaaa#bb......',
  842. '.....#aaaaaa#####aaaaaa#bb......',
  843. '....#aaaaaaaa###aaaaaaaa#bb.....',
  844. '....#aaaaaaaa###aaaaaaaa#bb.....',
  845. '...#aaaaaaaaa###aaaaaaaaa#bb....',
  846. '...#aaaaaaaaaa#aaaaaaaaaa#bb....',
  847. '..#aaaaaaaaaaa#aaaaaaaaaaa#bb...',
  848. '..#aaaaaaaaaaaaaaaaaaaaaaa#bb...',
  849. '.#aaaaaaaaaaaa##aaaaaaaaaaa#bb..',
  850. '.#aaaaaaaaaaa####aaaaaaaaaa#bb..',
  851. '#aaaaaaaaaaaa####aaaaaaaaaaa#bb.',
  852. '#aaaaaaaaaaaaa##aaaaaaaaaaaa#bb.',
  853. '#aaaaaaaaaaaaaaaaaaaaaaaaaaa#bbb',
  854. '#aaaaaaaaaaaaaaaaaaaaaaaaaaa#bbb',
  855. '.#aaaaaaaaaaaaaaaaaaaaaaaaa#bbbb',
  856. '..#########################bbbbb',
  857. '....bbbbbbbbbbbbbbbbbbbbbbbbbbb.',
  858. '.....bbbbbbbbbbbbbbbbbbbbbbbbb..');
  859. IMGError : Array[1..37] of string = ('32 32 4 1',
  860. '. c None',
  861. 'b c #808080',
  862. '# c #c00000',
  863. 'a c #ffffff',
  864. '................................',
  865. '................................',
  866. '................................',
  867. '............#######.............',
  868. '...........###########..........',
  869. '........###############.........',
  870. '.......##################.......',
  871. '......####################......',
  872. '.....###aa############aa###.....',
  873. '.....###aaa##########aaa###.....',
  874. '....#####aaa########aaa#####....',
  875. '....######aaa######aaa######....',
  876. '...########aaa####aaa########...',
  877. '...#########aaa##aaa#########b..',
  878. '...##########aaaaaa##########b..',
  879. '...###########aaaa###########b..',
  880. '...###########aaaa###########b..',
  881. '...##########aaaaaa##########b..',
  882. '...#########aaa##aaa#########b..',
  883. '...########aaa####aaa#######bb..',
  884. '....######aaa######aaa######bb..',
  885. '.....####aaa########aaa#####bb..',
  886. '.....###aaa##########aaa###bbb..',
  887. '.....###aa############aa##bbb...',
  888. '......####################bb....',
  889. '.......##################bb.....',
  890. '.........###############bb......',
  891. '..........###########bbbb.......',
  892. '.............#######bbb.........',
  893. '................................',
  894. '................................',
  895. '................................');
  896. IMGConfirmation : Array[1..37] of string = ('32 32 4 1',
  897. '. c None',
  898. 'b c #808080',
  899. 'a c #c00000',
  900. '# c #ffffff',
  901. '................................',
  902. '................................',
  903. '................................',
  904. '................................',
  905. '.............######.............',
  906. '..........###########...........',
  907. '.........##############.........',
  908. '........################........',
  909. '.......##################.......',
  910. '......########aaaaa#######......',
  911. '.....########aaaaaaa#######.....',
  912. '.....#######aa#####aa######.....',
  913. '.....#######a######aa#######....',
  914. '....###############aa#######b...',
  915. '....###############aa#######bb..',
  916. '....##############aa########bb..',
  917. '....#############aa#########bb..',
  918. '....############aa##########bb..',
  919. '....###########aa###########bb..',
  920. '.....##########aa##########bbb..',
  921. '.....##########aa##########bbb..',
  922. '.....##########aa##########bb...',
  923. '......#########aa#########bb....',
  924. '.......##################bbb....',
  925. '........#######aa#######bbb.....',
  926. '.........######aa######bbb......',
  927. '...........###########bbb.......',
  928. '.............######bbbbb........',
  929. '................................',
  930. '................................',
  931. '................................',
  932. '................................');
  933. Constructor TMessageDialogWindow.Create(AMsg : String;DlgType:TMsgDlgType;Buttons: TMsgDlgButtons);
  934. const
  935. OH = GTK_FILL OR GTK_EXPAND;
  936. begin
  937. Inherited Create(GTK_WINDOW_DIALOG);
  938. FVBox:=TFPGtkVBox.Create;
  939. FVBox.Spacing:=4;
  940. FVBox.Border:=8;
  941. Add(FVBox);
  942. FLTable:=TFpgtkTable.Create(10,1);
  943. if DlgType <> mtCustom then
  944. begin
  945. FImage:=TFPGtkPixMap.Create;
  946. With FImage do
  947. Case DlgType of
  948. mtInformation : LoadFromArray(Imginfo);
  949. mtWarning : LoadFromArray(imgWarning);
  950. mtConfirmation : LoadFromArray(imgConfirmation);
  951. mtError : LoadFromArray(imgError);
  952. end;
  953. FLTable.Attach(FImage,1,2,0,1,OH,OH,0,0);
  954. end;
  955. FLabel:=TFPGtkLabel.Create(Amsg);
  956. FLTable.Attach(FLabel,4,9,0,1,OH,OH,0,0);
  957. FButtonBox:=TFPgtkHButtonBox.Create;
  958. with FButtonBox do
  959. begin
  960. Layout := GTK_BUTTONBOX_DEFAULT_STYLE;
  961. spacing := 4;
  962. end;
  963. CreateButtons(Buttons);
  964. FVBox.PackStart(FLTable,false,False,8);
  965. FVBox.PackStart(FButtonBox,false,False,8);
  966. end;
  967. Const
  968. ButtonText : Array[TMsgDlgBtn] of string =
  969. ('Yes', 'No', 'OK', 'Cancel','Abort', 'Retry', 'Ignore',
  970. 'All', 'NoToAll', 'YesToAll', 'Help');
  971. ButtonResult : array [TMsgDlgbtn] of TModalResult =
  972. (mrYes, mrNo, mrOK, mrCAncel, mrAbort, mrRetry, mrIgnore,
  973. mrAll, mrNoToAll, mrYesToAll, 0);
  974. Procedure TMessageDialogWindow.CreateButtons(Buttons: TMsgDlgButtons);
  975. Var
  976. b : TMsgDlgBtn;
  977. bw : TFPGtkButton;
  978. begin
  979. For B:=Low(TMsgDlgBtn) to high(TMsgDlgBtn) do
  980. If b in Buttons then
  981. begin
  982. BW:=TFPGtkButton.CreateWithLabel(ButtonText[b]);
  983. BW.ConnectClicked(@CloseWithResult,IntToPointer(ButtonResult[b]));
  984. BW.Setusize(50,25);
  985. FButtonBox.PackStart(BW,False,False,4);
  986. end;
  987. end;
  988. function MessageDlg(const aMsg: string; DlgType: TMsgDlgType;
  989. Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
  990. begin
  991. With TMessageDialogWindow.Create(AMsg,DlgType,Buttons) do
  992. Result:=Execute(Nil,Nil,Nil);
  993. end;
  994. function MessageDlg(const Fmt: string; Args : Array of const; DlgType: TMsgDlgType;
  995. Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
  996. begin
  997. Result:=MessageDlg(Format(Fmt,Args),Dlgtype,Buttons,HelpCtx);
  998. end;
  999. end.