lwlib-Xaw.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /* The lwlib interface to Athena widgets.
  2. Copyright (C) 1993 Chuck Thompson <cthomp@cs.uiuc.edu>
  3. Copyright (C) 1994, 2001-2012 Free Software Foundation, Inc.
  4. This file is part of the Lucid Widget Library.
  5. The Lucid Widget Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 1, or (at your option)
  8. any later version.
  9. The Lucid Widget Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Emacs; see the file COPYING. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA. */
  17. #ifdef HAVE_CONFIG_H
  18. #include <config.h>
  19. #endif
  20. #include <stdio.h>
  21. #include <setjmp.h>
  22. #include <ctype.h>
  23. #include <lisp.h>
  24. #include "lwlib-Xaw.h"
  25. #include <X11/StringDefs.h>
  26. #include <X11/IntrinsicP.h>
  27. #include <X11/CoreP.h>
  28. #include <X11/Shell.h>
  29. #ifdef HAVE_XAW3D
  30. #include <X11/Xaw3d/Scrollbar.h>
  31. #include <X11/Xaw3d/Paned.h>
  32. #include <X11/Xaw3d/Dialog.h>
  33. #include <X11/Xaw3d/Form.h>
  34. #include <X11/Xaw3d/Command.h>
  35. #include <X11/Xaw3d/Label.h>
  36. #else /* !HAVE_XAW3D */
  37. #include <X11/Xaw/Scrollbar.h>
  38. #include <X11/Xaw/Paned.h>
  39. #include <X11/Xaw/Dialog.h>
  40. #include <X11/Xaw/Form.h>
  41. #include <X11/Xaw/Command.h>
  42. #include <X11/Xaw/Label.h>
  43. #endif /* HAVE_XAW3D */
  44. #include <X11/Xatom.h>
  45. #ifdef HAVE_XFT
  46. #include <X11/Xft/Xft.h>
  47. struct widget_xft_data
  48. {
  49. Widget widget;
  50. XftFont *xft_font;
  51. XftDraw *xft_draw;
  52. XftColor xft_fg, xft_bg;
  53. int p_width, p_height;
  54. Pixmap p;
  55. };
  56. #endif
  57. static void xaw_generic_callback (Widget widget,
  58. XtPointer closure,
  59. XtPointer call_data);
  60. Boolean
  61. lw_xaw_widget_p (Widget widget)
  62. {
  63. return (XtIsSubclass (widget, scrollbarWidgetClass) ||
  64. XtIsSubclass (widget, dialogWidgetClass));
  65. }
  66. #ifdef HAVE_XFT
  67. static void
  68. fill_xft_data (struct widget_xft_data *data, Widget widget, XftFont *font)
  69. {
  70. Pixel bg, fg;
  71. XColor colors[2];
  72. data->widget = widget;
  73. data->xft_font = font;
  74. XtVaGetValues (widget,
  75. XtNbackground, &bg,
  76. XtNforeground, &fg,
  77. NULL);
  78. colors[0].pixel = data->xft_fg.pixel = fg;
  79. colors[1].pixel = data->xft_bg.pixel = bg;
  80. XQueryColors (XtDisplay (widget),
  81. DefaultColormapOfScreen (XtScreen (widget)),
  82. colors, 2);
  83. data->xft_fg.color.alpha = 0xFFFF;
  84. data->xft_fg.color.red = colors[0].red;
  85. data->xft_fg.color.green = colors[0].green;
  86. data->xft_fg.color.blue = colors[0].blue;
  87. data->xft_bg.color.alpha = 0xFFFF;
  88. data->xft_bg.color.red = colors[1].red;
  89. data->xft_bg.color.green = colors[1].green;
  90. data->xft_bg.color.blue = colors[1].blue;
  91. data->p = None;
  92. data->xft_draw = 0;
  93. data->p_width = data->p_height = 0;
  94. }
  95. static XftFont*
  96. openFont (Widget widget, char *name)
  97. {
  98. char *fname = name;
  99. int screen = XScreenNumberOfScreen (XtScreen (widget));
  100. int len = strlen (fname), i = len-1;
  101. XftFont *fn;
  102. /* Try to convert Gtk-syntax (Sans 9) to Xft syntax Sans-9. */
  103. while (i > 0 && isdigit (fname[i]))
  104. --i;
  105. if (fname[i] == ' ')
  106. {
  107. fname = xstrdup (name);
  108. fname[i] = '-';
  109. }
  110. fn = XftFontOpenName (XtDisplay (widget), screen, fname);
  111. if (fname != name) xfree (fname);
  112. return fn;
  113. }
  114. static int
  115. get_text_width_and_height (Widget widget, char *text,
  116. XftFont *xft_font,
  117. int *height)
  118. {
  119. int w = 0, h = 0;
  120. char *bp = text;
  121. while (bp && *bp != '\0')
  122. {
  123. XGlyphInfo gi;
  124. char *cp = strchr (bp, '\n');
  125. XftTextExtentsUtf8 (XtDisplay (widget), xft_font,
  126. (FcChar8 *) bp,
  127. cp ? cp - bp : strlen (bp),
  128. &gi);
  129. bp = cp ? cp + 1 : NULL;
  130. h += xft_font->height;
  131. if (w < gi.width) w = gi.width;
  132. }
  133. *height = h;
  134. return w;
  135. }
  136. static void
  137. draw_text (struct widget_xft_data *data, char *lbl, int inverse)
  138. {
  139. Screen *sc = XtScreen (data->widget);
  140. int screen = XScreenNumberOfScreen (sc);
  141. int y = data->xft_font->ascent;
  142. int x = inverse ? 0 : 2;
  143. char *bp = lbl;
  144. data->xft_draw = XftDrawCreate (XtDisplay (data->widget),
  145. data->p,
  146. DefaultVisual (XtDisplay (data->widget),
  147. screen),
  148. DefaultColormapOfScreen (sc));
  149. XftDrawRect (data->xft_draw,
  150. inverse ? &data->xft_fg : &data->xft_bg,
  151. 0, 0, data->p_width, data->p_height);
  152. if (!inverse) y += 2;
  153. while (bp && *bp != '\0')
  154. {
  155. char *cp = strchr (bp, '\n');
  156. XftDrawStringUtf8 (data->xft_draw,
  157. inverse ? &data->xft_bg : &data->xft_fg,
  158. data->xft_font, x, y,
  159. (FcChar8 *) bp,
  160. cp ? cp - bp : strlen (bp));
  161. bp = cp ? cp + 1 : NULL;
  162. /* 1.2 gives reasonable line spacing. */
  163. y += data->xft_font->height * 1.2;
  164. }
  165. }
  166. static void
  167. set_text (struct widget_xft_data *data, Widget toplevel, char *lbl, int margin)
  168. {
  169. int width, height;
  170. width = get_text_width_and_height (data->widget, lbl, data->xft_font,
  171. &height);
  172. data->p_width = width + margin;
  173. data->p_height = height + margin;
  174. data->p = XCreatePixmap (XtDisplay (data->widget),
  175. XtWindow (toplevel),
  176. data->p_width,
  177. data->p_height,
  178. DefaultDepthOfScreen (XtScreen (data->widget)));
  179. draw_text (data, lbl, 0);
  180. XtVaSetValues (data->widget, XtNbitmap, data->p, NULL);
  181. }
  182. static struct widget_xft_data *
  183. find_xft_data (Widget widget)
  184. {
  185. widget_instance *inst = NULL;
  186. Widget parent = XtParent (widget);
  187. struct widget_xft_data *data = NULL;
  188. int nr;
  189. while (parent && !inst)
  190. {
  191. inst = lw_get_widget_instance (parent);
  192. parent = XtParent (parent);
  193. }
  194. if (!inst || !inst->xft_data || !inst->xft_data[0].xft_font) return 0;
  195. for (nr = 0; data == NULL && nr < inst->nr_xft_data; ++nr)
  196. {
  197. if (inst->xft_data[nr].widget == widget)
  198. data = &inst->xft_data[nr];
  199. }
  200. return data;
  201. }
  202. static void
  203. command_press (Widget widget,
  204. XEvent* event,
  205. String *params,
  206. Cardinal *num_params)
  207. {
  208. struct widget_xft_data *data = find_xft_data (widget);
  209. if (data)
  210. {
  211. char *lbl;
  212. /* Since this isn't used for rectangle buttons, use it to for armed. */
  213. XtVaSetValues (widget, XtNcornerRoundPercent, 1, NULL);
  214. XtVaGetValues (widget, XtNlabel, &lbl, NULL);
  215. draw_text (data, lbl, 1);
  216. }
  217. }
  218. static void
  219. command_reset (Widget widget,
  220. XEvent* event,
  221. String *params,
  222. Cardinal *num_params)
  223. {
  224. struct widget_xft_data *data = find_xft_data (widget);
  225. if (data)
  226. {
  227. Dimension cr;
  228. XtVaGetValues (widget, XtNcornerRoundPercent, &cr, NULL);
  229. if (cr == 1)
  230. {
  231. char *lbl;
  232. XtVaSetValues (widget, XtNcornerRoundPercent, 0, NULL);
  233. XtVaGetValues (widget, XtNlabel, &lbl, NULL);
  234. draw_text (data, lbl, 0);
  235. }
  236. }
  237. }
  238. #endif
  239. void
  240. xaw_update_one_widget (widget_instance *instance,
  241. Widget widget,
  242. widget_value *val,
  243. Boolean deep_p)
  244. {
  245. if (XtIsSubclass (widget, dialogWidgetClass))
  246. {
  247. #ifdef HAVE_XFT
  248. if (instance->xft_data && instance->xft_data[0].xft_font)
  249. {
  250. set_text (&instance->xft_data[0], instance->parent,
  251. val->contents->value, 10);
  252. }
  253. #endif
  254. XtVaSetValues (widget, XtNlabel, val->contents->value, NULL);
  255. }
  256. else if (XtIsSubclass (widget, commandWidgetClass))
  257. {
  258. Dimension bw = 0;
  259. Arg al[10];
  260. int ac = 0;
  261. XtVaGetValues (widget, XtNborderWidth, &bw, NULL);
  262. if (bw == 0)
  263. /* Don't let buttons end up with 0 borderwidth, that's ugly...
  264. Yeah, all this should really be done through app-defaults files
  265. or fallback resources, but that's a whole different can of worms
  266. that I don't feel like opening right now. Making Athena widgets
  267. not look like shit is just entirely too much work.
  268. */
  269. {
  270. XtSetArg (al[0], XtNborderWidth, 1);
  271. XtSetValues (widget, al, 1);
  272. }
  273. XtSetSensitive (widget, val->enabled);
  274. XtSetArg (al[ac], XtNlabel, val->value);ac++;
  275. /* Force centered button text. Se above. */
  276. XtSetArg (al[ac], XtNjustify, XtJustifyCenter);ac++;
  277. #ifdef HAVE_XFT
  278. if (instance->xft_data && instance->xft_data[0].xft_font)
  279. {
  280. int th;
  281. int nr;
  282. for (nr = 0; nr < instance->nr_xft_data; ++nr)
  283. if (instance->xft_data[nr].widget == widget)
  284. break;
  285. if (nr < instance->nr_xft_data)
  286. {
  287. set_text (&instance->xft_data[nr], instance->parent,
  288. val->value, 6);
  289. /* Must set internalHeight to twice the highlight thickness,
  290. or else it gets overwritten by our pixmap. Probably a bug. */
  291. XtVaGetValues (widget, XtNhighlightThickness, &th, NULL);
  292. XtSetArg (al[ac], XtNinternalHeight, 2*th);ac++;
  293. }
  294. }
  295. #endif
  296. XtSetValues (widget, al, ac);
  297. XtRemoveAllCallbacks (widget, XtNcallback);
  298. XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance);
  299. }
  300. }
  301. void
  302. xaw_update_one_value (widget_instance *instance,
  303. Widget widget,
  304. widget_value *val)
  305. {
  306. /* This function is not used by the scrollbars and those are the only
  307. Athena widget implemented at the moment so do nothing. */
  308. return;
  309. }
  310. void
  311. xaw_destroy_instance (widget_instance *instance)
  312. {
  313. #ifdef HAVE_XFT
  314. if (instance->xft_data)
  315. {
  316. int i;
  317. for (i = 0; i < instance->nr_xft_data; ++i)
  318. {
  319. if (instance->xft_data[i].xft_draw)
  320. XftDrawDestroy (instance->xft_data[i].xft_draw);
  321. if (instance->xft_data[i].p != None)
  322. {
  323. XtVaSetValues (instance->xft_data[i].widget, XtNbitmap, None,
  324. NULL);
  325. XFreePixmap (XtDisplay (instance->widget),
  326. instance->xft_data[i].p);
  327. }
  328. }
  329. if (instance->xft_data[0].xft_font)
  330. XftFontClose (XtDisplay (instance->widget),
  331. instance->xft_data[0].xft_font);
  332. xfree (instance->xft_data);
  333. }
  334. #endif
  335. if (XtIsSubclass (instance->widget, dialogWidgetClass))
  336. /* Need to destroy the Shell too. */
  337. XtDestroyWidget (XtParent (instance->widget));
  338. else
  339. XtDestroyWidget (instance->widget);
  340. }
  341. void
  342. xaw_popup_menu (Widget widget, XEvent *event)
  343. {
  344. /* An Athena menubar has not been implemented. */
  345. return;
  346. }
  347. void
  348. xaw_pop_instance (widget_instance *instance, Boolean up)
  349. {
  350. Widget widget = instance->widget;
  351. if (up)
  352. {
  353. if (XtIsSubclass (widget, dialogWidgetClass))
  354. {
  355. /* For dialogs, we need to call XtPopup on the parent instead
  356. of calling XtManageChild on the widget.
  357. Also we need to hack the shell's WM_PROTOCOLS to get it to
  358. understand what the close box is supposed to do!!
  359. */
  360. Display *dpy = XtDisplay (widget);
  361. Widget shell = XtParent (widget);
  362. Atom props [2];
  363. int i = 0;
  364. props [i++] = XInternAtom (dpy, "WM_DELETE_WINDOW", False);
  365. XChangeProperty (dpy, XtWindow (shell),
  366. XInternAtom (dpy, "WM_PROTOCOLS", False),
  367. XA_ATOM, 32, PropModeAppend,
  368. (unsigned char *) props, i);
  369. /* Center the widget in its parent. Why isn't this kind of crap
  370. done automatically? I thought toolkits were supposed to make
  371. life easier?
  372. */
  373. {
  374. unsigned int x, y, w, h;
  375. Widget topmost = instance->parent;
  376. Arg args[2];
  377. w = shell->core.width;
  378. h = shell->core.height;
  379. while (topmost->core.parent && XtIsRealized (topmost->core.parent))
  380. topmost = topmost->core.parent;
  381. if (topmost->core.width < w) x = topmost->core.x;
  382. else x = topmost->core.x + ((topmost->core.width - w) / 2);
  383. if (topmost->core.height < h) y = topmost->core.y;
  384. else y = topmost->core.y + ((topmost->core.height - h) / 2);
  385. /* Using XtMoveWidget caused the widget to come
  386. out in the wrong place with vtwm.
  387. Question of virtual vs real coords, perhaps. */
  388. XtSetArg (args[0], XtNx, x);
  389. XtSetArg (args[1], XtNy, y);
  390. XtSetValues (shell, args, 2);
  391. }
  392. /* Finally, pop it up. */
  393. XtPopup (shell, XtGrabNonexclusive);
  394. }
  395. else
  396. XtManageChild (widget);
  397. }
  398. else
  399. {
  400. if (XtIsSubclass (widget, dialogWidgetClass))
  401. XtUnmanageChild (XtParent (widget));
  402. else
  403. XtUnmanageChild (widget);
  404. }
  405. }
  406. /* Dialog boxes */
  407. static char overrideTrans[] =
  408. "<Message>WM_PROTOCOLS: lwlib_delete_dialog()";
  409. /* Dialogs pop down on any key press */
  410. static char dialogOverride[] =
  411. "<KeyPress>Escape: lwlib_delete_dialog()";
  412. static void wm_delete_window (Widget w,
  413. XEvent *event,
  414. String *params,
  415. Cardinal *num_params);
  416. static XtActionsRec xaw_actions [] = {
  417. {"lwlib_delete_dialog", wm_delete_window}
  418. };
  419. static Boolean actions_initted = False;
  420. #ifdef HAVE_XFT
  421. static XtActionsRec button_actions[] =
  422. {
  423. { "my_reset", command_reset },
  424. { "my_press", command_press },
  425. };
  426. char buttonTrans[] =
  427. "<Leave>: reset() my_reset()\n"
  428. "<Btn1Down>: set() my_press()\n"
  429. "<Btn1Up>: my_reset() notify() unset()\n";
  430. #endif
  431. static Widget
  432. make_dialog (char* name,
  433. Widget parent,
  434. Boolean pop_up_p,
  435. char* shell_title,
  436. char* icon_name,
  437. Boolean text_input_slot,
  438. Boolean radio_box,
  439. Boolean list,
  440. int left_buttons,
  441. int right_buttons,
  442. widget_instance *instance)
  443. {
  444. Arg av [20];
  445. int ac = 0;
  446. int i, bc;
  447. char button_name [255];
  448. Widget shell;
  449. Widget dialog;
  450. Widget button;
  451. XtTranslations override;
  452. #ifdef HAVE_XFT
  453. XftFont *xft_font = 0;
  454. XtTranslations button_override;
  455. #endif
  456. if (! pop_up_p) abort (); /* not implemented */
  457. if (text_input_slot) abort (); /* not implemented */
  458. if (radio_box) abort (); /* not implemented */
  459. if (list) abort (); /* not implemented */
  460. if (! actions_initted)
  461. {
  462. XtAppContext app = XtWidgetToApplicationContext (parent);
  463. XtAppAddActions (app, xaw_actions,
  464. sizeof (xaw_actions) / sizeof (xaw_actions[0]));
  465. #ifdef HAVE_XFT
  466. XtAppAddActions (app, button_actions,
  467. sizeof (button_actions) / sizeof (button_actions[0]));
  468. #endif
  469. actions_initted = True;
  470. }
  471. override = XtParseTranslationTable (overrideTrans);
  472. ac = 0;
  473. XtSetArg (av[ac], XtNtitle, shell_title); ac++;
  474. XtSetArg (av[ac], XtNallowShellResize, True); ac++;
  475. /* Don't allow any geometry request from the user. */
  476. XtSetArg (av[ac], XtNgeometry, 0); ac++;
  477. shell = XtCreatePopupShell ("dialog", transientShellWidgetClass,
  478. parent, av, ac);
  479. XtOverrideTranslations (shell, override);
  480. ac = 0;
  481. dialog = XtCreateManagedWidget (name, dialogWidgetClass, shell, av, ac);
  482. override = XtParseTranslationTable (dialogOverride);
  483. XtOverrideTranslations (dialog, override);
  484. #ifdef HAVE_XFT
  485. {
  486. int num;
  487. Widget *ch = NULL;
  488. Widget w = 0;
  489. XtVaGetValues (dialog,
  490. XtNnumChildren, &num,
  491. XtNchildren, &ch, NULL);
  492. for (i = 0; i < num; ++i)
  493. {
  494. if (!XtIsSubclass (ch[i], commandWidgetClass)
  495. && XtIsSubclass (ch[i], labelWidgetClass))
  496. {
  497. w = ch[i];
  498. break;
  499. }
  500. }
  501. instance->xft_data = 0;
  502. instance->nr_xft_data = 0;
  503. if (w)
  504. {
  505. XtResource rec[] =
  506. { { "font", "Font", XtRString, sizeof(String), 0, XtRString,
  507. (XtPointer)"Sans-10" }};
  508. char *fontName = NULL;
  509. XtVaGetSubresources (dialog, &fontName, "Dialog", "dialog",
  510. rec, 1, (String)NULL);
  511. if (fontName)
  512. {
  513. XFontStruct *xfn = XLoadQueryFont (XtDisplay (dialog), fontName);
  514. if (!xfn)
  515. xft_font = openFont (dialog, fontName);
  516. else
  517. XFreeFont (XtDisplay (dialog), xfn);
  518. }
  519. if (xft_font)
  520. {
  521. instance->nr_xft_data = left_buttons + right_buttons + 1;
  522. instance->xft_data = calloc (instance->nr_xft_data,
  523. sizeof(*instance->xft_data));
  524. fill_xft_data (&instance->xft_data[0], w, xft_font);
  525. }
  526. }
  527. button_override = XtParseTranslationTable (buttonTrans);
  528. }
  529. #endif
  530. bc = 0;
  531. button = 0;
  532. for (i = 0; i < left_buttons; i++)
  533. {
  534. ac = 0;
  535. XtSetArg (av [ac], XtNfromHoriz, button); ac++;
  536. XtSetArg (av [ac], XtNleft, XtChainLeft); ac++;
  537. XtSetArg (av [ac], XtNright, XtChainLeft); ac++;
  538. XtSetArg (av [ac], XtNtop, XtChainBottom); ac++;
  539. XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++;
  540. XtSetArg (av [ac], XtNresizable, True); ac++;
  541. #ifdef HAVE_XAW3D
  542. if (DefaultDepthOfScreen (XtScreen (dialog)) >= 16)
  543. {
  544. /* Turn of dithered shadow if we can. Looks bad */
  545. XtSetArg (av [ac], "beNiceToColormap", False); ac++;
  546. }
  547. #endif
  548. sprintf (button_name, "button%d", ++bc);
  549. button = XtCreateManagedWidget (button_name, commandWidgetClass,
  550. dialog, av, ac);
  551. #ifdef HAVE_XFT
  552. if (xft_font)
  553. {
  554. fill_xft_data (&instance->xft_data[bc], button, xft_font);
  555. XtOverrideTranslations (button, button_override);
  556. }
  557. #endif
  558. }
  559. for (i = 0; i < right_buttons; i++)
  560. {
  561. ac = 0;
  562. XtSetArg (av [ac], XtNfromHoriz, button); ac++;
  563. if (i == 0)
  564. {
  565. /* Separator to the other buttons. */
  566. XtSetArg (av [ac], XtNhorizDistance, 30); ac++;
  567. }
  568. XtSetArg (av [ac], XtNleft, XtChainRight); ac++;
  569. XtSetArg (av [ac], XtNright, XtChainRight); ac++;
  570. XtSetArg (av [ac], XtNtop, XtChainBottom); ac++;
  571. XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++;
  572. XtSetArg (av [ac], XtNresizable, True); ac++;
  573. #ifdef HAVE_XAW3D
  574. if (DefaultDepthOfScreen (XtScreen (dialog)) >= 16)
  575. {
  576. /* Turn of dithered shadow if we can. Looks bad */
  577. XtSetArg (av [ac], "beNiceToColormap", False); ac++;
  578. }
  579. #endif
  580. sprintf (button_name, "button%d", ++bc);
  581. button = XtCreateManagedWidget (button_name, commandWidgetClass,
  582. dialog, av, ac);
  583. #ifdef HAVE_XFT
  584. if (xft_font)
  585. {
  586. fill_xft_data (&instance->xft_data[bc], button, xft_font);
  587. XtOverrideTranslations (button, button_override);
  588. }
  589. #endif
  590. }
  591. return dialog;
  592. }
  593. Widget
  594. xaw_create_dialog (widget_instance *instance)
  595. {
  596. char *name = instance->info->type;
  597. Widget parent = instance->parent;
  598. Widget widget;
  599. Boolean pop_up_p = instance->pop_up_p;
  600. char *shell_name = 0;
  601. char *icon_name = 0;
  602. Boolean text_input_slot = False;
  603. Boolean radio_box = False;
  604. Boolean list = False;
  605. int total_buttons;
  606. int left_buttons = 0;
  607. int right_buttons = 1;
  608. switch (name [0]) {
  609. case 'E': case 'e':
  610. icon_name = "dbox-error";
  611. shell_name = "Error";
  612. break;
  613. case 'I': case 'i':
  614. icon_name = "dbox-info";
  615. shell_name = "Information";
  616. break;
  617. case 'L': case 'l':
  618. list = True;
  619. icon_name = "dbox-question";
  620. shell_name = "Prompt";
  621. break;
  622. case 'P': case 'p':
  623. text_input_slot = True;
  624. icon_name = "dbox-question";
  625. shell_name = "Prompt";
  626. break;
  627. case 'Q': case 'q':
  628. icon_name = "dbox-question";
  629. shell_name = "Question";
  630. break;
  631. }
  632. total_buttons = name [1] - '0';
  633. if (name [3] == 'T' || name [3] == 't')
  634. {
  635. text_input_slot = False;
  636. radio_box = True;
  637. }
  638. else if (name [3])
  639. right_buttons = name [4] - '0';
  640. left_buttons = total_buttons - right_buttons;
  641. widget = make_dialog (name, parent, pop_up_p,
  642. shell_name, icon_name, text_input_slot, radio_box,
  643. list, left_buttons, right_buttons, instance);
  644. return widget;
  645. }
  646. static void
  647. xaw_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
  648. {
  649. widget_instance *instance = (widget_instance *) closure;
  650. Widget instance_widget;
  651. LWLIB_ID id;
  652. XtPointer user_data;
  653. lw_internal_update_other_instances (widget, closure, call_data);
  654. if (! instance)
  655. return;
  656. if (widget->core.being_destroyed)
  657. return;
  658. instance_widget = instance->widget;
  659. if (!instance_widget)
  660. return;
  661. id = instance->info->id;
  662. /* Damn! Athena doesn't give us a way to hang our own data on the
  663. buttons, so we have to go find it... I guess this assumes that
  664. all instances of a button have the same call data. */
  665. {
  666. widget_value *val = instance->info->val->contents;
  667. char *name = XtName (widget);
  668. while (val)
  669. {
  670. if (val->name && !strcmp (val->name, name))
  671. break;
  672. val = val->next;
  673. }
  674. if (! val) abort ();
  675. user_data = val->call_data;
  676. }
  677. if (instance->info->selection_cb)
  678. instance->info->selection_cb (widget, id, user_data);
  679. }
  680. static void
  681. wm_delete_window (Widget w,
  682. XEvent *event,
  683. String *params,
  684. Cardinal *num_params)
  685. {
  686. LWLIB_ID id;
  687. Cardinal nkids;
  688. int i;
  689. Widget *kids = 0;
  690. Widget widget = 0, shell;
  691. if (XtIsSubclass (w, dialogWidgetClass))
  692. shell = XtParent (w);
  693. else
  694. shell = w;
  695. if (! XtIsSubclass (shell, shellWidgetClass))
  696. abort ();
  697. XtVaGetValues (shell, XtNnumChildren, &nkids, NULL);
  698. XtVaGetValues (shell, XtNchildren, &kids, NULL);
  699. if (!kids || !*kids)
  700. abort ();
  701. for (i = 0; i < nkids; i++)
  702. {
  703. widget = kids[i];
  704. if (XtIsSubclass (widget, dialogWidgetClass))
  705. break;
  706. }
  707. if (! widget) return;
  708. id = lw_get_widget_id (widget);
  709. if (! id) abort ();
  710. {
  711. widget_info *info = lw_get_widget_info (id);
  712. if (! info) abort ();
  713. if (info->selection_cb)
  714. info->selection_cb (widget, id, (XtPointer) -1);
  715. }
  716. lw_destroy_all_widgets (id);
  717. }
  718. static Widget
  719. xaw_create_main (widget_instance *instance)
  720. {
  721. Arg al[1];
  722. int ac;
  723. /* Create a vertical Paned to hold menubar */
  724. ac = 0;
  725. XtSetArg (al[ac], XtNborderWidth, 0); ac++;
  726. return XtCreateWidget (instance->info->name, panedWidgetClass,
  727. instance->parent, al, ac);
  728. }
  729. widget_creation_entry
  730. xaw_creation_table [] =
  731. {
  732. {"main", xaw_create_main},
  733. {NULL, NULL}
  734. };