DialogBox.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: DialogBox.c /main/9 1996/05/14 15:26:42 drk $
  24. *
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 1990,1996 Hewlett-Packard Company.
  27. * (c) Copyright 1996 International Business Machines Corp.
  28. * (c) Copyright 1996 Sun Microsystems, Inc.
  29. * (c) Copyright 1996 Novell, Inc.
  30. * (c) Copyright 1996 FUJITSU LIMITED.
  31. * (c) Copyright 1996 Hitachi.
  32. */
  33. /**---------------------------------------------------------------------
  34. ***
  35. *** file: DialogBox.c
  36. ***
  37. *** project: Motif Widgets
  38. ***
  39. *** description: Source code for DtDialogBox class.
  40. ***
  41. ***-------------------------------------------------------------------*/
  42. /*-------------------------------------------------------------
  43. ** Include Files
  44. */
  45. #include <stdio.h>
  46. #include <Xm/DialogS.h>
  47. #include <Xm/PushBG.h>
  48. #include <Xm/SeparatoG.h>
  49. #include <Dt/DialogBoxP.h>
  50. #include <Dt/MacrosP.h>
  51. #include <Dt/DtMsgsP.h>
  52. #include "DtWidgetI.h"
  53. /*
  54. * Private functions borrowed from Motif.
  55. */
  56. extern void _XmSetThickness(Widget widget, int offset, XrmValue *value);
  57. /*-------------------------------------------------------------
  58. ** Public Interface
  59. **-------------------------------------------------------------
  60. */
  61. extern Widget _DtCreateDialogBox(
  62. Widget parent,
  63. char *name,
  64. ArgList arglist,
  65. Cardinal argcount) ;
  66. extern Widget __DtCreateDialogBoxDialog(
  67. Widget ds_p,
  68. String name,
  69. ArgList db_args,
  70. Cardinal db_n) ;
  71. extern Widget _DtDialogBoxGetButton(
  72. Widget w,
  73. Cardinal pos) ;
  74. extern Widget _DtDialogBoxGetWorkArea(
  75. Widget w) ;
  76. #define Max(x, y) (((x) > (y)) ? (x) : (y))
  77. /******** Static Function Declarations ********/
  78. static void ClassInitialize( void ) ;
  79. static void ClassPartInitialize(
  80. WidgetClass wc) ;
  81. static void Initialize(
  82. Widget request_w,
  83. Widget new_w) ;
  84. static void Destroy(
  85. Widget w) ;
  86. static Boolean SetValues(
  87. Widget current_w,
  88. Widget request_w,
  89. Widget new_w) ;
  90. static void ChangeManaged(
  91. Widget manager) ;
  92. static void InsertChild(
  93. Widget child) ;
  94. static void DeleteChild(
  95. Widget child) ;
  96. static void ConstraintInitialize(
  97. Widget request,
  98. Widget new) ;
  99. static void GetSize(
  100. Widget manager,
  101. Dimension wa_w,
  102. Dimension wa_h,
  103. Dimension bp_w,
  104. Dimension bp_h,
  105. Dimension *w,
  106. Dimension *h) ;
  107. static void CreateChildren(
  108. DtDialogBoxWidget new,
  109. Widget top_widget,
  110. Widget bottom_widget) ;
  111. static void ButtonCallback(
  112. Widget g,
  113. XtPointer client_data,
  114. XtPointer call_data) ;
  115. /******** End Static Function Declarations ********/
  116. /*-------------------------------------------------------------
  117. ** Forward Declarations
  118. */
  119. #define OFFSET 6
  120. #define CENTER_POS 50
  121. #define LEFT_POS 50
  122. #define WARN_CHILD_TYPE _DtMsgDialogBox_0000
  123. #define WARN_BUTTON_CHILD _DtMsgDialogBox_0001
  124. extern void _DtRegisterNewConverters ();
  125. /*-------------------------------------------------------------
  126. ** Translations and Actions
  127. */
  128. /*-------------------------------------------------------------
  129. ** Resource List
  130. */
  131. /* Define offset macros.
  132. */
  133. #define DB_Offset(field) \
  134. XtOffset (DtDialogBoxWidget, dialog_box.field)
  135. #define DBC_Offset(field) \
  136. XtOffset (DtDialogBoxConstraintPtr, dialog_box_constraint.field)
  137. /* Core Resources.
  138. */
  139. static XtResource resources[] =
  140. {
  141. {
  142. XmNminimizeButtons,
  143. XmCMinimizeButtons, XmRBoolean, sizeof (Boolean),
  144. DB_Offset (minimize_buttons), XmRImmediate, (XtPointer) False
  145. },
  146. {
  147. XmNbuttonCount,
  148. XmCButtonCount, XmRCardinal, sizeof (Cardinal),
  149. DB_Offset (button_count), XmRImmediate, (XtPointer) 4
  150. },
  151. {
  152. XmNbuttonLabelStrings,
  153. XmCButtonLabelStrings, XmRXmStringTable, sizeof (XtPointer),
  154. DB_Offset (button_label_strings), XmRStringTable, NULL
  155. },
  156. {
  157. XmNcallback,
  158. XmCCallback, XmRCallback, sizeof (XtCallbackList),
  159. DB_Offset (callback), XmRImmediate, (XtPointer) NULL
  160. },
  161. {
  162. XmNshadowThickness,
  163. XmCShadowThickness, XmRHorizontalDimension, sizeof(Dimension),
  164. XtOffsetOf (struct _XmManagerRec, manager.shadow_thickness),
  165. XmRCallProc, (XtPointer) _XmSetThickness
  166. }
  167. };
  168. /* Constraint Resources
  169. */
  170. static XtResource constraints[] =
  171. {
  172. {
  173. XmNchildType,
  174. XmCChildType, XmRChildType, sizeof (unsigned char),
  175. DBC_Offset (child_type), XmRImmediate, (XtPointer) XmWORK_AREA
  176. }
  177. };
  178. #undef DB_Offset
  179. #undef DBC_Offset
  180. /*-------------------------------------------------------------
  181. ** Class Record
  182. */
  183. DtDialogBoxClassRec dtDialogBoxClassRec =
  184. {
  185. /* Core Part
  186. */
  187. {
  188. (WidgetClass) &xmFormClassRec, /* superclass */
  189. "DtDialogBox", /* class_name */
  190. sizeof (DtDialogBoxRec), /* widget_size */
  191. ClassInitialize, /* class_initialize */
  192. ClassPartInitialize, /* class_part_initialize*/
  193. False, /* class_inited */
  194. (XtInitProc) Initialize, /* initialize */
  195. NULL, /* initialize_hook */
  196. XtInheritRealize, /* realize */
  197. NULL, /* actions */
  198. 0, /* num_actions */
  199. resources, /* resources */
  200. XtNumber (resources), /* num_resources */
  201. NULLQUARK, /* xrm_class */
  202. True, /* compress_motion */
  203. False, /* compress_exposure */
  204. True, /* compress_enterleave */
  205. False, /* visible_interest */
  206. Destroy, /* destroy */
  207. XtInheritResize, /* resize */
  208. XtInheritExpose, /* expose */
  209. (XtSetValuesFunc) SetValues, /* set_values */
  210. NULL, /* set_values_hook */
  211. XtInheritSetValuesAlmost, /* set_values_almost */
  212. NULL, /* get_values_hook */
  213. NULL, /* accept_focus */
  214. XtVersion, /* version */
  215. NULL, /* callback private */
  216. XtInheritTranslations, /* tm_table */
  217. XtInheritQueryGeometry, /* query_geometry */
  218. NULL, /* display_accelerator */
  219. NULL, /* extension */
  220. },
  221. /* Composite Part
  222. */
  223. {
  224. XtInheritGeometryManager, /* geometry_manager */
  225. XtInheritChangeManaged, /* change_managed */
  226. InsertChild, /* insert_child */
  227. DeleteChild, /* delete_child */
  228. NULL, /* extension */
  229. },
  230. /* Constraint Part
  231. */
  232. {
  233. constraints, /* constraint_resources */
  234. XtNumber (constraints), /* num_constraint_resources */
  235. sizeof (DtDialogBoxConstraintRec),/* constraint_record */
  236. (XtInitProc) ConstraintInitialize,/* constraint_initialize */
  237. NULL, /* constraint_destroy */
  238. NULL, /* constraint_set_values */
  239. NULL, /* extension */
  240. },
  241. /* XmManager Part
  242. */
  243. {
  244. XtInheritTranslations, /* default_translations */
  245. NULL, /* get_resources */
  246. 0, /* num_get_resources */
  247. NULL, /* get_cont_resources */
  248. 0, /* num_get_cont_resources */
  249. XmInheritParentProcess, /* parent_process */
  250. NULL, /* extension */
  251. },
  252. /* XmBulletinBoard Part
  253. */
  254. {
  255. True, /* always_install_accelerators*/
  256. NULL, /* geo_matrix_create */
  257. XmInheritFocusMovedProc, /* focus_moved_proc */
  258. NULL, /* extension */
  259. },
  260. /* XmForm Part
  261. */
  262. {
  263. NULL, /* extension */
  264. },
  265. /* DtDialogBox Part
  266. */
  267. {
  268. (XtWidgetProc) CreateChildren, /* create_children */
  269. NULL, /* configure_children */
  270. GetSize, /* get_size */
  271. NULL, /* button_callback */
  272. NULL, /* extension */
  273. }
  274. };
  275. WidgetClass dtDialogBoxWidgetClass = (WidgetClass) &dtDialogBoxClassRec;
  276. /*-------------------------------------------------------------
  277. ** Private Procs
  278. **-------------------------------------------------------------
  279. */
  280. /*-------------------------------------------------------------
  281. ** Action Procs
  282. **-------------------------------------------------------------
  283. */
  284. /*-------------------------------------------------------------
  285. ** Core Procs
  286. **-------------------------------------------------------------
  287. */
  288. /*-------------------------------------------------------------
  289. ** ClassInitialize
  290. ** Initialize widget class.
  291. */
  292. static void
  293. ClassInitialize( void )
  294. {
  295. _DtRegisterNewConverters ();
  296. }
  297. /*-------------------------------------------------------------
  298. ** ClassPartInitialize
  299. ** Initialize widget class part.
  300. */
  301. static void
  302. ClassPartInitialize(
  303. WidgetClass wc )
  304. {
  305. DtDialogBoxWidgetClass mc = (DtDialogBoxWidgetClass) wc;
  306. DtDialogBoxWidgetClass super = (DtDialogBoxWidgetClass)
  307. C_Superclass (wc);
  308. mc->bulletin_board_class.always_install_accelerators = True;
  309. /* Propagate class procs for subclasses.
  310. */
  311. if (C_CreateChildren (mc) == (XtWidgetProc) _XtInherit)
  312. C_CreateChildren (mc) = C_CreateChildren (super);
  313. if (C_ConfigureChildren (mc) == (XtWidgetProc) _XtInherit)
  314. C_ConfigureChildren (mc) = C_ConfigureChildren (super);
  315. if (C_GetSize (mc) == (DlgGetSizeProc) _XtInherit)
  316. C_GetSize (mc) = C_GetSize (super);
  317. if (C_ButtonCallback (mc) == (XtCallbackProc) _XtInherit)
  318. C_ButtonCallback (mc) = C_ButtonCallback (super);
  319. }
  320. /*-------------------------------------------------------------
  321. ** Initialize
  322. ** Initialize a new widget instance.
  323. */
  324. static void
  325. Initialize(
  326. Widget request_w,
  327. Widget new_w )
  328. {
  329. DtDialogBoxWidget new = (DtDialogBoxWidget) new_w;
  330. XtWidgetProc create_children;
  331. if (M_ButtonCount (new) > 0)
  332. M_Button (new) = (Widget *)
  333. XtMalloc (sizeof (Widget) * M_ButtonCount (new));
  334. else
  335. M_Button (new) = NULL;
  336. M_WorkArea (new) = NULL;
  337. _DtProcessLock();
  338. create_children = C_CreateChildren((DtDialogBoxWidgetClass) XtClass(new));
  339. _DtProcessUnlock();
  340. (*create_children) ((Widget)new);
  341. M_ButtonLabelStrings (new) = NULL;
  342. M_MarginWidth (new) = M_ShadowThickness (new);
  343. M_MarginHeight (new) = M_ShadowThickness (new);
  344. }
  345. /*-------------------------------------------------------------
  346. ** Destroy
  347. ** Release resources allocated for widget instance.
  348. */
  349. static void
  350. Destroy(
  351. Widget w )
  352. {
  353. DtDialogBoxWidget mgr = (DtDialogBoxWidget) w;
  354. /* Free button pointers.
  355. */
  356. if (M_Button (mgr) != NULL)
  357. XtFree ((char *)M_Button (mgr));
  358. }
  359. /*-------------------------------------------------------------
  360. ** SetValues
  361. ** Handle changes in resource data.
  362. */
  363. static Boolean
  364. SetValues(
  365. Widget current_w,
  366. Widget request_w,
  367. Widget new_w )
  368. {
  369. Boolean redraw_flag = False;
  370. /* Superclass does all the work so far; checks for redisplay, etc.
  371. */
  372. return (redraw_flag);
  373. }
  374. /*-------------------------------------------------------------
  375. ** Composite Procs
  376. **-------------------------------------------------------------
  377. */
  378. /*-------------------------------------------------------------
  379. ** ChangeManaged
  380. ** Handle change in set of managed children.
  381. */
  382. static void
  383. ChangeManaged(
  384. Widget manager )
  385. {
  386. DtDialogBoxWidget mgr = (DtDialogBoxWidget) manager;
  387. Dimension w = M_Width (mgr),
  388. h = M_Height (mgr);
  389. DlgGetSizeProc get_size;
  390. XtWidgetProc resize;
  391. /* Compute desired size.
  392. */
  393. _DtProcessLock();
  394. get_size = C_GetSize((DtDialogBoxWidgetClass) XtClass(mgr));
  395. resize = XtCoreProc(manager, resize);
  396. _DtProcessUnlock();
  397. (*get_size) ((Widget)mgr, 0, 0, 0, 0, &w, &h);
  398. /* check for resize policy if not first time ?? */
  399. /* Try to change size to fit children
  400. */
  401. if (w != M_Width (mgr) || h != M_Height (mgr))
  402. {
  403. switch (XtMakeResizeRequest ((Widget) mgr, w, h, &w, &h))
  404. {
  405. case XtGeometryAlmost:
  406. XtMakeResizeRequest ((Widget) mgr, w, h,
  407. NULL, NULL);
  408. case XtGeometryYes:
  409. case XtGeometryNo:
  410. default:
  411. break;
  412. }
  413. }
  414. /* Set positions and sizes of children.
  415. */
  416. (*resize) (manager);
  417. }
  418. /*-------------------------------------------------------------
  419. ** InsertChild
  420. ** Add a child.
  421. */
  422. static void
  423. InsertChild(
  424. Widget child )
  425. {
  426. DtDialogBoxConstraint constraint = (DtDialogBoxConstraint)
  427. M_DialogBoxConstraint (child);
  428. DtDialogBoxWidget w = (DtDialogBoxWidget) XtParent (child);
  429. XmManagerWidgetClass mc = (XmManagerWidgetClass)xmManagerWidgetClass;
  430. Dimension s_t = M_ShadowThickness (w);
  431. Arg al[20]; /* arg list */
  432. register int ac; /* arg count */
  433. XtWidgetProc insert_child;
  434. _DtProcessLock();
  435. insert_child = mc->composite_class.insert_child;
  436. _DtProcessUnlock();
  437. (*insert_child) (child);
  438. if (constraint->child_type == XmWORK_AREA)
  439. {
  440. if (! M_WorkArea (w))
  441. {
  442. M_WorkArea (w) = child;
  443. ac = 0;
  444. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  445. XtSetArg (al[ac], XmNtopOffset, s_t); ac++;
  446. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  447. XtSetArg (al[ac], XmNleftOffset, s_t); ac++;
  448. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  449. XtSetArg (al[ac], XmNrightOffset, s_t); ac++;
  450. XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
  451. XtSetArg (al[ac], XmNbottomWidget, M_Separator (w)); ac++;
  452. XtSetArg (al[ac], XmNbottomOffset, 0); ac++;
  453. XtSetValues (child, al, ac);
  454. }
  455. }
  456. }
  457. /*-------------------------------------------------------------
  458. ** DeleteChild
  459. ** Delete a child.
  460. */
  461. static void
  462. DeleteChild(
  463. Widget child )
  464. {
  465. DtDialogBoxWidget w = (DtDialogBoxWidget) XtParent (child);
  466. XmManagerWidgetClass mc = (XmManagerWidgetClass)xmManagerWidgetClass;
  467. XtWidgetProc delete_child;
  468. _DtProcessLock();
  469. delete_child = mc->composite_class.delete_child;
  470. _DtProcessUnlock();
  471. (*delete_child) (child);
  472. if (child == M_Separator (w))
  473. M_Separator (w) = NULL;
  474. else if (child == M_WorkArea (w))
  475. M_WorkArea (w) = NULL;
  476. /* button children ?? */
  477. }
  478. /*-------------------------------------------------------------
  479. ** Constraint Procs
  480. **-------------------------------------------------------------
  481. */
  482. /*-------------------------------------------------------------
  483. ** ConstraintInitialize
  484. ** Add a child.
  485. */
  486. static void
  487. ConstraintInitialize(
  488. Widget request,
  489. Widget new )
  490. {
  491. DtDialogBoxWidget mgr = (DtDialogBoxWidget) XtParent (new);
  492. DtDialogBoxConstraint constraint = M_DialogBoxConstraint (new);
  493. /* Validate child type.
  494. */
  495. if (constraint->child_type != XmWORK_AREA &&
  496. constraint->child_type != XmSEPARATOR &&
  497. constraint->child_type != XmBUTTON)
  498. {
  499. XmeWarning (new, WARN_CHILD_TYPE);
  500. if (! M_WorkArea (mgr))
  501. {
  502. constraint->child_type = XmWORK_AREA;
  503. }
  504. }
  505. }
  506. /*-------------------------------------------------------------
  507. ** XmManager Procs
  508. **-------------------------------------------------------------
  509. */
  510. /* All inherited from superclass.
  511. */
  512. /*-------------------------------------------------------------
  513. ** DtDialogBox Procs
  514. **-------------------------------------------------------------
  515. */
  516. /*-------------------------------------------------------------------------
  517. ** GetSize
  518. ** Calculate desired size based on children.
  519. */
  520. static void
  521. GetSize(
  522. Widget manager,
  523. Dimension wa_w,
  524. Dimension wa_h,
  525. Dimension bp_w,
  526. Dimension bp_h,
  527. Dimension *w,
  528. Dimension *h )
  529. {
  530. DtDialogBoxWidget mgr = (DtDialogBoxWidget) manager;
  531. Widget work_area = M_WorkArea (mgr),
  532. separator = M_Separator (mgr);
  533. Widget * button = M_Button (mgr);
  534. register int button_count = M_ButtonCount (mgr),
  535. i;
  536. Boolean min_btns = M_MinimizeButtons (mgr);
  537. Dimension sep_h = 0,
  538. offset = OFFSET, pad,
  539. max_w = 0, max_h = 0,
  540. s_t = M_ShadowThickness (mgr);
  541. XtWidgetGeometry request, reply;
  542. /* Query work area.
  543. */
  544. if (work_area && !wa_w && !wa_h)
  545. {
  546. request.request_mode = CWWidth | CWHeight;
  547. XtQueryGeometry (work_area, &request, &reply);
  548. wa_w = reply.width;
  549. wa_h = reply.height;
  550. }
  551. sep_h = (separator) ? P_Height (separator) : 0;
  552. /* Get button panel size.
  553. */
  554. s_t = Max (2, s_t);
  555. if ((bp_w == 0) && (bp_h == 0) && !min_btns)
  556. {
  557. request.request_mode = CWWidth | CWHeight;
  558. for (i = 0; i < button_count; i++)
  559. {
  560. pad = (i == 0) ? 0 : 4 * s_t;
  561. XtQueryGeometry (button[i], &request, &reply);
  562. max_w = Max ((unsigned)max_w, reply.width + pad);
  563. max_h = Max ((unsigned)max_h, reply.height + pad);
  564. }
  565. if (button_count)
  566. {
  567. max_w += 4;
  568. max_h += 1;
  569. }
  570. bp_w = (button_count * max_w) + ((button_count + 1) * offset);
  571. bp_h = sep_h + max_h + (2 * offset);
  572. }
  573. else if ((bp_w == 0) && (bp_h == 0) && min_btns)
  574. {
  575. request.request_mode = CWWidth | CWHeight;
  576. for (i = 0; i < button_count; i++)
  577. {
  578. XtQueryGeometry (button[i], &request, &reply);
  579. bp_w += reply.width;
  580. max_h = Max (max_h, reply.height);
  581. }
  582. bp_w += (button_count + 1) * offset;
  583. bp_h = sep_h + max_h + (2 * offset);
  584. }
  585. /* Set width and height.
  586. */
  587. *w = Max (wa_w, bp_w);
  588. *h = wa_h + sep_h + bp_h;
  589. }
  590. /*-------------------------------------------------------------
  591. ** CreateChildren
  592. ** Create resource and value labels and text.
  593. */
  594. static void
  595. CreateChildren(
  596. DtDialogBoxWidget new,
  597. Widget top_widget,
  598. Widget bottom_widget )
  599. {
  600. Widget ref_widget,
  601. sep, btn;
  602. Widget * button = M_Button (new);
  603. int count = M_ButtonCount (new),
  604. i, l_p, r_p, off_p, b_delta, offset = 0;
  605. XmStringTable string = M_ButtonLabelStrings (new);
  606. Boolean min_btns = M_MinimizeButtons (new);
  607. Dimension s_t = M_ShadowThickness (new);
  608. char button_name[100];
  609. Arg al[20]; /* arg list */
  610. register int ac; /* arg count */
  611. /* Compute position factors.
  612. */
  613. off_p = 2;
  614. b_delta = (100 - off_p) / count;
  615. l_p = (100 - (count * b_delta) + off_p) / 2;
  616. r_p = l_p + b_delta - off_p;
  617. /* s_t = Max (2, s_t); */
  618. /* Create buttons.
  619. */
  620. for (i = 0; i < count; i++)
  621. {
  622. ac = 0;
  623. XtSetArg (al[ac], XmNdefaultButtonShadowThickness,Max(2U,s_t)/2U);
  624. ac++;
  625. XtSetArg (al[ac], XmNshadowThickness, s_t); ac++;
  626. XtSetArg (al[ac], XmNhighlightThickness, s_t); ac++;
  627. if (!min_btns)
  628. {
  629. XtSetArg (al[ac], XmNleftAttachment,
  630. XmATTACH_POSITION); ac++;
  631. XtSetArg (al[ac], XmNleftPosition, l_p); ac++;
  632. XtSetArg (al[ac], XmNleftOffset, offset); ac++;
  633. XtSetArg (al[ac], XmNrightAttachment,
  634. XmATTACH_POSITION); ac++;
  635. XtSetArg (al[ac], XmNrightPosition, r_p); ac++;
  636. XtSetArg (al[ac], XmNrightOffset, offset); ac++;
  637. }
  638. else
  639. {
  640. if (i == 0)
  641. {
  642. XtSetArg (al[ac], XmNleftAttachment,
  643. XmATTACH_FORM); ac++;
  644. XtSetArg (al[ac], XmNleftOffset, OFFSET); ac++;
  645. }
  646. else if (i == count -1)
  647. {
  648. XtSetArg (al[ac], XmNrightAttachment,
  649. XmATTACH_FORM); ac++;
  650. XtSetArg (al[ac], XmNrightOffset, OFFSET); ac++;
  651. }
  652. else
  653. {
  654. XtSetArg (al[ac], XmNleftAttachment,
  655. XmATTACH_WIDGET); ac++;
  656. XtSetArg (al[ac], XmNleftWidget, button[i-1]);
  657. ac++;
  658. XtSetArg (al[ac], XmNleftOffset, OFFSET);
  659. ac++;
  660. }
  661. }
  662. XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  663. XtSetArg (al[ac], XmNbottomOffset, OFFSET + offset); ac++;
  664. if (string)
  665. {
  666. XtSetArg (al[ac], XmNlabelString, string[i]); ac++;
  667. }
  668. XtSetArg (al[ac], XmNchildType, XmBUTTON); ac++;
  669. sprintf (button_name, "%s_%d", M_Name (new), i+1);
  670. btn = XmCreatePushButtonGadget ((Widget)new, button_name, al, ac);
  671. XtManageChild (btn);
  672. XtAddCallback (btn, XmNactivateCallback,
  673. (XtCallbackProc)ButtonCallback,
  674. (XtPointer)(i+1));
  675. button[i] = btn;
  676. l_p += b_delta;
  677. r_p += b_delta;
  678. }
  679. ref_widget = button[0];
  680. new->bulletin_board.default_button = button[0];
  681. /* Create Separator
  682. */
  683. ac = 0;
  684. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  685. XtSetArg (al[ac], XmNleftOffset, 0); ac++;
  686. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  687. XtSetArg (al[ac], XmNrightOffset, 0); ac++;
  688. XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
  689. XtSetArg (al[ac], XmNbottomWidget, ref_widget); ac++;
  690. XtSetArg (al[ac], XmNbottomOffset, OFFSET); ac++;
  691. XtSetArg (al[ac], XmNhighlightThickness, 0); ac++;
  692. XtSetArg (al[ac], XmNchildType, XmSEPARATOR); ac++;
  693. sep = XmCreateSeparatorGadget ((Widget)new, "separator", al, ac);
  694. XtManageChild (sep);
  695. M_Separator (new) = sep;
  696. }
  697. /*-------------------------------------------------------------
  698. ** ButtonCallback
  699. */
  700. static void
  701. ButtonCallback(
  702. Widget g,
  703. XtPointer client_data,
  704. XtPointer call_data )
  705. {
  706. DtDialogBoxWidget mgr = (DtDialogBoxWidget) XtParent (g);
  707. XtCallbackList cb_list = M_Callback (mgr);
  708. XmAnyCallbackStruct * b_cb_data =
  709. (XmAnyCallbackStruct *) call_data;
  710. DtDialogBoxCallbackStruct cb_data;
  711. if (cb_list != NULL)
  712. {
  713. cb_data.reason = XmCR_DIALOG_BUTTON;
  714. cb_data.event = b_cb_data->event;
  715. cb_data.button_position = (int) client_data;
  716. cb_data.button = g;
  717. XtCallCallbackList ((Widget) mgr, cb_list, &cb_data);
  718. }
  719. }
  720. /*-------------------------------------------------------------
  721. ** Public Entry Points
  722. **-------------------------------------------------------------
  723. */
  724. /*-------------------------------------------------------------
  725. ** _DtCreateDialogBox
  726. ** Create a new DtDialogBox instance.
  727. **-------------------------------------------------------------
  728. */
  729. Widget
  730. _DtCreateDialogBox(
  731. Widget parent,
  732. char *name,
  733. ArgList arglist,
  734. Cardinal argcount )
  735. {
  736. return (XtCreateWidget (name, dtDialogBoxWidgetClass,
  737. parent, arglist, argcount));
  738. }
  739. /*-------------------------------------------------------------
  740. ** __DtCreateDialogBoxDialog
  741. ** Create a DialogShell and a new DialogBox instance;
  742. ** return the DialogBox widget;
  743. **-------------------------------------------------------------
  744. */
  745. Widget
  746. __DtCreateDialogBoxDialog(
  747. Widget ds_p,
  748. String name,
  749. ArgList db_args,
  750. Cardinal db_n )
  751. {
  752. Widget ds; /* DialogShell */
  753. Arg ds_args[10]; /* arglist for shell */
  754. Cardinal ds_n; /* argcount for shell */
  755. Widget db; /* new sb widget */
  756. /* create DialogShell parent
  757. */
  758. ds_n = 0;
  759. XtSetArg (ds_args[ds_n], XmNallowShellResize, True); ds_n++;
  760. ds = XtCreatePopupShell (name, xmDialogShellWidgetClass,
  761. ds_p, ds_args, ds_n);
  762. /* create DialogBox, free args, return
  763. */
  764. db = XtCreateWidget (name, dtDialogBoxWidgetClass,
  765. ds, db_args, db_n);
  766. return (db);
  767. }
  768. /*-------------------------------------------------------------
  769. ** _DtDialogBoxGetButton
  770. ** Return DialogBox button.
  771. **-------------------------------------------------------------
  772. */
  773. Widget
  774. _DtDialogBoxGetButton(
  775. Widget w,
  776. Cardinal pos )
  777. {
  778. DtDialogBoxWidget mgr = (DtDialogBoxWidget) w;
  779. int index = pos - 1;
  780. Widget * button = M_Button (mgr);
  781. Widget rtn_w = NULL;
  782. if (index >= M_ButtonCount (mgr))
  783. XmeWarning ((Widget)mgr, WARN_BUTTON_CHILD);
  784. else
  785. rtn_w = button[index];
  786. return (rtn_w);
  787. }
  788. /*-------------------------------------------------------------
  789. ** _DtDialogBoxGetWorkArea
  790. ** Return DialogBox work area;
  791. **-------------------------------------------------------------
  792. */
  793. Widget
  794. _DtDialogBoxGetWorkArea(
  795. Widget w )
  796. {
  797. DtDialogBoxWidget mgr = (DtDialogBoxWidget) w;
  798. Widget rtn_w = M_WorkArea (mgr);
  799. return (rtn_w);
  800. }