428
|
1 /* The lwlib interface to Motif widgets.
|
|
2 Copyright (C) 1992, 1993, 1994 Lucid, Inc.
|
|
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
4
|
|
5 This file is part of the Lucid Widget Library.
|
|
6
|
|
7 The Lucid Widget Library is free software; you can redistribute it and/or
|
|
8 modify it under the terms of the GNU General Public License as published by
|
|
9 the Free Software Foundation; either version 2, or (at your option)
|
|
10 any later version.
|
|
11
|
|
12 The Lucid Widget Library is distributed in the hope that it will be useful,
|
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 GNU General Public License for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 #include <config.h>
|
|
23 #include <stdlib.h>
|
|
24 #include <string.h>
|
|
25 #include <stdio.h>
|
|
26 #include <limits.h>
|
|
27 #ifdef HAVE_UNISTD_H
|
|
28 #include <unistd.h>
|
|
29 #endif
|
|
30
|
|
31 #include <X11/StringDefs.h>
|
|
32 #include <X11/IntrinsicP.h>
|
|
33 #include <X11/ObjectP.h>
|
|
34 #include <X11/CoreP.h>
|
|
35 #include <X11/CompositeP.h>
|
|
36
|
|
37 #include "lwlib-Xm.h"
|
|
38 #include "lwlib-utils.h"
|
|
39
|
|
40 #include <Xm/Xm.h>
|
|
41 #include <Xm/BulletinB.h>
|
|
42 #include <Xm/CascadeB.h>
|
|
43 #include <Xm/DrawingA.h>
|
|
44 #include <Xm/FileSB.h>
|
|
45 #include <Xm/Label.h>
|
|
46 #include <Xm/List.h>
|
|
47 #include <Xm/MenuShell.h>
|
|
48 #include <Xm/MessageB.h>
|
|
49 #include <Xm/PushB.h>
|
|
50 #include <Xm/PushBG.h>
|
|
51 #include <Xm/ArrowB.h>
|
|
52 #include <Xm/ScrollBar.h>
|
|
53 #include <Xm/SelectioB.h>
|
|
54 #include <Xm/Text.h>
|
|
55 #include <Xm/TextF.h>
|
|
56 #include <Xm/ToggleB.h>
|
|
57 #include <Xm/ToggleBG.h>
|
|
58 #include <Xm/RowColumn.h>
|
|
59 #include <Xm/ScrolledW.h>
|
|
60 #include <Xm/Separator.h>
|
|
61 #include <Xm/DialogS.h>
|
|
62 #include <Xm/Form.h>
|
|
63 #ifdef LWLIB_WIDGETS_MOTIF
|
|
64 #include <Xm/Scale.h>
|
|
65 #if XmVERSION > 1
|
|
66 #include <Xm/ComboBoxP.h>
|
|
67 #endif
|
|
68 #endif
|
|
69
|
|
70 #ifdef LWLIB_MENUBARS_MOTIF
|
|
71 static void xm_pull_down_callback (Widget, XtPointer, XtPointer);
|
|
72 #endif
|
|
73 static void xm_internal_update_other_instances (Widget, XtPointer,
|
|
74 XtPointer);
|
1261
|
75 /* static void xm_pop_down_callback (Widget, XtPointer, XtPointer); */
|
428
|
76 static void xm_generic_callback (Widget, XtPointer, XtPointer);
|
2286
|
77 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
428
|
78 static void mark_dead_instance_destroyed (Widget widget, XtPointer closure,
|
|
79 XtPointer call_data);
|
|
80 static void xm_nosel_callback (Widget, XtPointer, XtPointer);
|
|
81 #endif
|
|
82 #ifdef LWLIB_SCROLLBARS_MOTIF
|
|
83 static void xm_scrollbar_callback (Widget, XtPointer, XtPointer);
|
|
84 #endif
|
|
85
|
|
86 #ifdef LWLIB_MENUBARS_MOTIF
|
|
87 static void
|
|
88 xm_update_menu (widget_instance* instance, Widget widget, widget_value* val,
|
|
89 Boolean deep_p);
|
|
90 #endif
|
|
91
|
|
92 /* Structures to keep destroyed instances */
|
|
93 typedef struct _destroyed_instance
|
|
94 {
|
|
95 char* name;
|
|
96 char* type;
|
|
97 Widget widget;
|
|
98 Widget parent;
|
|
99 Boolean pop_up_p;
|
|
100 struct _destroyed_instance* next;
|
|
101 } destroyed_instance;
|
|
102
|
|
103 static destroyed_instance*
|
|
104 all_destroyed_instances = NULL;
|
|
105
|
|
106 /* Utility function. */
|
|
107 static char *
|
|
108 safe_strdup (char* s)
|
|
109 {
|
|
110 char *result;
|
|
111 if (! s) return 0;
|
|
112 result = (char *) malloc (strlen (s) + 1);
|
|
113 if (! result)
|
|
114 return 0;
|
|
115 strcpy (result, s);
|
|
116 return result;
|
|
117 }
|
|
118
|
|
119 static destroyed_instance*
|
|
120 make_destroyed_instance (char* name, char* type, Widget widget, Widget parent,
|
|
121 Boolean pop_up_p)
|
|
122 {
|
|
123 destroyed_instance* instance =
|
|
124 (destroyed_instance*) malloc (sizeof (destroyed_instance));
|
|
125 instance->name = safe_strdup (name);
|
|
126 instance->type = safe_strdup (type);
|
|
127 instance->widget = widget;
|
|
128 instance->parent = parent;
|
|
129 instance->pop_up_p = pop_up_p;
|
|
130 instance->next = NULL;
|
|
131 return instance;
|
|
132 }
|
|
133
|
1330
|
134 #ifdef LWLIB_DIALOGS_MOTIF
|
|
135
|
428
|
136 static void
|
|
137 free_destroyed_instance (destroyed_instance* instance)
|
|
138 {
|
|
139 free (instance->name);
|
|
140 free (instance->type);
|
|
141 free (instance);
|
|
142 }
|
|
143
|
1330
|
144 #endif /* LWLIB_DIALOGS_MOTIF */
|
|
145
|
428
|
146 /* motif utility functions */
|
|
147 Widget
|
|
148 first_child (Widget widget)
|
|
149 {
|
|
150 return ((CompositeWidget)widget)->composite.children [0];
|
|
151 }
|
|
152
|
|
153 Boolean
|
|
154 lw_motif_widget_p (Widget widget)
|
|
155 {
|
|
156 return
|
|
157 #ifdef LWLIB_DIALOGS_MOTIF
|
|
158 XtClass (widget) == xmDialogShellWidgetClass ||
|
|
159 #endif
|
|
160 XmIsPrimitive (widget) || XmIsManager (widget) || XmIsGadget (widget);
|
|
161 }
|
|
162
|
|
163 static char *
|
|
164 resource_string (Widget widget, char *name)
|
|
165 {
|
|
166 XtResource resource;
|
|
167 char *result = NULL;
|
|
168
|
|
169 resource.resource_name = "labelString";
|
|
170 resource.resource_class = "LabelString"; /* #### should be Xmsomething... */
|
|
171 resource.resource_type = XtRString;
|
|
172 resource.resource_size = sizeof (String);
|
|
173 resource.resource_offset = 0;
|
|
174 resource.default_type = XtRImmediate;
|
|
175 resource.default_addr = 0;
|
|
176
|
|
177 XtGetSubresources (widget, (XtPointer)&result, name,
|
|
178 name, &resource, 1, NULL, 0);
|
|
179 return result;
|
|
180 }
|
|
181
|
|
182
|
|
183
|
|
184 #ifdef LWLIB_DIALOGS_MOTIF
|
|
185
|
|
186 static Boolean
|
|
187 is_in_dialog_box (Widget w)
|
|
188 {
|
|
189 Widget wmshell;
|
|
190
|
|
191 wmshell = XtParent (w);
|
|
192 while (wmshell && (XtClass (wmshell) != xmDialogShellWidgetClass))
|
|
193 wmshell = XtParent (wmshell);
|
|
194
|
|
195 if (wmshell && XtClass (wmshell) == xmDialogShellWidgetClass)
|
|
196 return True;
|
|
197 else
|
|
198 return False;
|
|
199 }
|
|
200
|
|
201 #endif /* LWLIB_DIALOGS_MOTIF */
|
|
202
|
|
203 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
|
204
|
|
205 /* update the label of anything subclass of a label */
|
|
206 static void
|
2311
|
207 xm_update_label (widget_instance* UNUSED (instance), Widget widget,
|
|
208 widget_value* val)
|
428
|
209 {
|
|
210 XmString built_string = NULL;
|
|
211 XmString key_string = NULL;
|
|
212 XmString val_string = NULL;
|
|
213 XmString name_string = NULL;
|
|
214 Arg al [20];
|
|
215 int ac = 0;
|
|
216 int type;
|
|
217
|
|
218 /* Don't clobber pixmap types. */
|
|
219 XtSetArg (al [0], XmNlabelType, &type);
|
|
220 XtGetValues (widget, al, 1);
|
|
221
|
|
222 if (type == XmPIXMAP)
|
|
223 return;
|
|
224
|
|
225 if (val->value)
|
|
226 {
|
446
|
227 /* #### Temporary fix. I though Motif was supposed to grok %_
|
|
228 type things. */
|
|
229 lw_remove_accelerator_spec (val->value);
|
|
230
|
428
|
231 #ifdef LWLIB_DIALOGS_MOTIF
|
|
232 /*
|
|
233 * Sigh. The main text of a label is the name field for menubar
|
|
234 * entries. The value field is a possible additional field to be
|
|
235 * concatenated on to the name field. HOWEVER, with dialog boxes
|
|
236 * the value field is the complete text which is supposed to be
|
|
237 * displayed as the label. Yuck.
|
|
238 */
|
|
239 if (is_in_dialog_box (widget))
|
|
240 {
|
|
241 char *value_name = NULL;
|
|
242
|
|
243 value_name = resource_string (widget, val->value);
|
|
244 if (!value_name)
|
|
245 value_name = val->value;
|
|
246
|
|
247 built_string =
|
|
248 XmStringCreateLtoR (value_name, XmSTRING_DEFAULT_CHARSET);
|
|
249 }
|
|
250 else
|
|
251 #endif /* LWLIB_DIALOGS_MOTIF */
|
|
252 {
|
|
253 char *value_name = NULL;
|
|
254 char *res_name = NULL;
|
|
255
|
|
256 res_name = resource_string (widget, val->name);
|
|
257 /* Concatenating the value with itself seems just plain daft. */
|
|
258 if (!res_name)
|
|
259 {
|
|
260 built_string =
|
|
261 XmStringCreateLtoR (val->value, XmSTRING_DEFAULT_CHARSET);
|
|
262 }
|
|
263 else
|
|
264 {
|
|
265 name_string =
|
|
266 XmStringCreateLtoR (res_name, XmSTRING_DEFAULT_CHARSET);
|
442
|
267
|
428
|
268 value_name = XtMalloc (strlen (val->value) + 2);
|
|
269 *value_name = 0;
|
|
270 strcat (value_name, " ");
|
|
271 strcat (value_name, val->value);
|
442
|
272
|
428
|
273 val_string =
|
|
274 XmStringCreateLtoR (value_name, XmSTRING_DEFAULT_CHARSET);
|
442
|
275
|
428
|
276 built_string =
|
|
277 XmStringConcat (name_string, val_string);
|
442
|
278
|
428
|
279 XtFree (value_name);
|
|
280 }
|
|
281 }
|
|
282
|
|
283 XtSetArg (al [ac], XmNlabelString, built_string); ac++;
|
|
284 XtSetArg (al [ac], XmNlabelType, XmSTRING); ac++;
|
|
285 }
|
|
286
|
|
287 if (val->key)
|
|
288 {
|
|
289 key_string = XmStringCreateLtoR (val->key, XmSTRING_DEFAULT_CHARSET);
|
|
290 XtSetArg (al [ac], XmNacceleratorText, key_string); ac++;
|
|
291 }
|
|
292
|
|
293 if (ac)
|
|
294 XtSetValues (widget, al, ac);
|
|
295
|
|
296 if (built_string)
|
|
297 XmStringFree (built_string);
|
|
298
|
|
299 if (key_string)
|
|
300 XmStringFree (key_string);
|
|
301
|
|
302 if (name_string)
|
|
303 XmStringFree (name_string);
|
|
304
|
|
305 if (val_string)
|
|
306 XmStringFree (val_string);
|
|
307 }
|
|
308
|
903
|
309 static void
|
|
310 xm_safe_update_label (widget_instance* instance, Widget widget, widget_value* val)
|
|
311 {
|
|
312 /* Don't clobber non-labels. */
|
|
313 if (XtIsSubclass (widget, xmLabelWidgetClass))
|
|
314 xm_update_label (instance, widget, val);
|
|
315 }
|
|
316
|
428
|
317 #endif /* defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) */
|
|
318
|
|
319 /* update of list */
|
|
320 static void
|
|
321 xm_update_list (widget_instance* instance, Widget widget, widget_value* val)
|
|
322 {
|
|
323 widget_value* cur;
|
|
324 int i;
|
|
325 XtRemoveAllCallbacks (widget, XmNsingleSelectionCallback);
|
|
326 XtAddCallback (widget, XmNsingleSelectionCallback, xm_generic_callback,
|
|
327 instance);
|
|
328 for (cur = val->contents, i = 0; cur; cur = cur->next)
|
|
329 if (cur->value)
|
|
330 {
|
|
331 XmString xmstr = XmStringCreate (cur->value, XmSTRING_DEFAULT_CHARSET);
|
|
332 i += 1;
|
|
333 XmListAddItem (widget, xmstr, 0);
|
|
334 if (cur->selected)
|
|
335 XmListSelectPos (widget, i, False);
|
|
336 XmStringFree (xmstr);
|
|
337 }
|
|
338 }
|
|
339
|
|
340 /* update of buttons */
|
|
341 static void
|
|
342 xm_update_pushbutton (widget_instance* instance, Widget widget,
|
2286
|
343 widget_value* UNUSED (val))
|
428
|
344 {
|
|
345 Arg al [1];
|
|
346 XtSetArg (al [0], XmNalignment, XmALIGNMENT_CENTER);
|
|
347 XtSetValues (widget, al, 1);
|
|
348 XtRemoveAllCallbacks (widget, XmNactivateCallback);
|
|
349 XtAddCallback (widget, XmNactivateCallback, xm_generic_callback, instance);
|
|
350 }
|
|
351
|
1281
|
352 #ifdef LWLIB_WIDGETS_MOTIF
|
639
|
353 static void
|
2311
|
354 xm_update_progress (widget_instance* UNUSED (instance), Widget scale,
|
|
355 widget_value* val)
|
639
|
356 {
|
|
357 Arg al[20];
|
|
358 int ac = 0;
|
|
359 Dimension height = 0;
|
|
360 Dimension width = 0;
|
|
361 if (!val->call_data)
|
|
362 {
|
|
363 XtSetArg (al [ac], XmNeditable, False); ac++;
|
|
364 }
|
|
365 else
|
|
366 {
|
|
367 XtSetArg (al [ac], XmNeditable, val->enabled); ac++;
|
|
368 }
|
|
369 height = (Dimension)lw_get_value_arg (val, XtNheight);
|
|
370 width = (Dimension)lw_get_value_arg (val, XtNwidth);
|
|
371 if (height > 0)
|
|
372 {
|
|
373 XtSetArg (al [ac], XmNscaleHeight, height); ac++;
|
|
374 }
|
|
375 if (width > 0)
|
|
376 {
|
|
377 XtSetArg (al [ac], XmNscaleWidth, width); ac++;
|
|
378 }
|
|
379
|
|
380 XtSetValues (scale, al, 1);
|
|
381 }
|
1281
|
382 #endif /* LWLIB_WIDGETS_MOTIF */
|
639
|
383
|
428
|
384 #ifdef LWLIB_MENUBARS_MOTIF
|
|
385
|
|
386 static void
|
|
387 xm_update_cascadebutton (widget_instance* instance, Widget widget,
|
|
388 widget_value* val)
|
|
389 {
|
|
390 /* Should also rebuild the menu by calling ...update_menu... */
|
|
391 if (val
|
|
392 && val->type == CASCADE_TYPE
|
|
393 && val->contents
|
|
394 && val->contents->type == INCREMENTAL_TYPE)
|
|
395 {
|
|
396 /* okay, we're now doing a lisp callback to incrementally generate
|
|
397 more of the menu. */
|
|
398 XtRemoveAllCallbacks (widget, XmNcascadingCallback);
|
|
399 XtAddCallback (widget, XmNcascadingCallback, xm_pull_down_callback,
|
|
400 instance);
|
|
401 XtCallCallbacks ((Widget)widget,
|
|
402 XmNcascadingCallback,
|
|
403 (XtPointer)val->contents);
|
|
404
|
|
405 } else {
|
|
406 XtRemoveAllCallbacks (widget, XmNcascadingCallback);
|
|
407 XtAddCallback (widget, XmNcascadingCallback, xm_pull_down_callback,
|
|
408 instance);
|
|
409 }
|
|
410 }
|
|
411
|
|
412 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
413
|
|
414 /* update toggle and radiobox */
|
|
415 static void
|
|
416 xm_update_toggle (widget_instance* instance, Widget widget, widget_value* val)
|
|
417 {
|
|
418 Arg al [2];
|
|
419 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback);
|
|
420 XtAddCallback (widget, XmNvalueChangedCallback, xm_generic_callback,
|
|
421 instance);
|
|
422 XtSetArg (al [0], XmNset, val->selected);
|
|
423 XtSetArg (al [1], XmNalignment, XmALIGNMENT_BEGINNING);
|
|
424 XtSetValues (widget, al, 1);
|
|
425 }
|
|
426
|
|
427 static void
|
|
428 xm_update_radiobox (widget_instance* instance, Widget widget,
|
|
429 widget_value* val)
|
|
430 {
|
|
431 Widget toggle;
|
|
432 widget_value* cur;
|
|
433
|
|
434 /* update the callback */
|
|
435 XtRemoveAllCallbacks (widget, XmNentryCallback);
|
|
436 XtAddCallback (widget, XmNentryCallback, xm_generic_callback, instance);
|
|
437
|
|
438 /* first update all the toggles */
|
|
439 /* Energize kernel interface is currently bad. It sets the selected widget
|
|
440 with the selected flag but returns it by its name. So we currently
|
|
441 have to support both setting the selection with the selected slot
|
|
442 of val contents and setting it with the "value" slot of val. The latter
|
|
443 has a higher priority. This to be removed when the kernel is fixed. */
|
|
444 for (cur = val->contents; cur; cur = cur->next)
|
|
445 {
|
|
446 toggle = XtNameToWidget (widget, cur->value);
|
|
447 if (toggle)
|
|
448 {
|
|
449 Arg al [2];
|
|
450 XtSetArg (al [0], XmNsensitive, cur->enabled);
|
|
451 XtSetArg (al [1], XmNset, (!val->value && cur->selected ? cur->selected : False));
|
|
452 XtSetValues (toggle, al, 2);
|
|
453 }
|
|
454 }
|
|
455
|
|
456 /* The selected was specified by the value slot */
|
|
457 if (val->value)
|
|
458 {
|
|
459 toggle = XtNameToWidget (widget, val->value);
|
|
460 if (toggle)
|
|
461 {
|
|
462 Arg al [1];
|
|
463 XtSetArg (al [0], XmNset, True);
|
|
464 XtSetValues (toggle, al, 1);
|
|
465 }
|
|
466 }
|
|
467 }
|
|
468
|
|
469 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
|
470 /* update of combo box */
|
|
471 static void
|
|
472 xm_update_combo_box (widget_instance* instance, Widget widget, widget_value* val)
|
|
473 {
|
|
474 widget_value* cur;
|
|
475 int i;
|
|
476 XtRemoveAllCallbacks (widget, XmNselectionCallback);
|
|
477 XtAddCallback (widget, XmNselectionCallback, xm_generic_callback,
|
|
478 instance);
|
|
479 for (cur = val->contents, i = 0; cur; cur = cur->next)
|
|
480 if (cur->value)
|
|
481 {
|
|
482 XmString xmstr = XmStringCreate (cur->value, XmSTRING_DEFAULT_CHARSET);
|
|
483 i += 1;
|
|
484 XmListAddItem (CB_List (widget), xmstr, 0);
|
|
485 if (cur->selected)
|
|
486 XmListSelectPos (CB_List (widget), i, False);
|
|
487 XmStringFree (xmstr);
|
|
488 }
|
|
489 }
|
|
490 #endif
|
|
491
|
|
492 #ifdef LWLIB_MENUBARS_MOTIF
|
|
493
|
|
494 /* update a popup menu, pulldown menu or a menubar */
|
|
495 static void
|
|
496 make_menu_in_widget (widget_instance* instance, Widget widget,
|
|
497 widget_value* val)
|
|
498 {
|
|
499 Widget* children = 0;
|
|
500 int num_children;
|
|
501 int child_index;
|
|
502 widget_value* cur;
|
|
503 Widget button = 0;
|
|
504 Widget menu;
|
|
505 Arg al [256];
|
|
506 int ac;
|
|
507 Boolean menubar_p = False;
|
|
508
|
|
509 /* Allocate the children array */
|
|
510 for (num_children = 0, cur = val; cur; num_children++, cur = cur->next);
|
|
511 children = (Widget*)XtMalloc (num_children * sizeof (Widget));
|
|
512
|
|
513 /* tricky way to know if this RowColumn is a menubar or a pulldown... */
|
|
514 XtSetArg (al [0], XmNisHomogeneous, &menubar_p);
|
|
515 XtGetValues (widget, al, 1);
|
|
516
|
|
517 /* add the unmap callback for popups and pulldowns */
|
|
518 /*** this sounds bogus ***/
|
|
519 /* probably because it is -- cet */
|
|
520 /*
|
|
521 if (!menubar_p)
|
|
522 XtAddCallback (XtParent (widget), XmNpopdownCallback,
|
|
523 xm_pop_down_callback, (XtPointer)instance);
|
|
524 */
|
|
525
|
|
526 num_children = 0;
|
|
527 for (child_index = 0, cur = val; cur; child_index++, cur = cur->next)
|
|
528 {
|
|
529 ac = 0;
|
|
530 button = 0;
|
|
531 XtSetArg (al [ac], XmNsensitive, cur->enabled); ac++;
|
|
532 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
533 XtSetArg (al [ac], XmNuserData, cur->call_data); ac++;
|
|
534
|
|
535 switch (cur->type)
|
|
536 {
|
|
537 case PUSHRIGHT_TYPE:
|
|
538 /* A pushright marker which is not needed for the real Motif
|
|
539 menubar. */
|
|
540 break;
|
|
541 case SEPARATOR_TYPE:
|
|
542 ac = 0;
|
|
543 if (cur->value)
|
|
544 {
|
|
545 /* #### - xlwmenu.h supports several types that motif does
|
|
546 not. Also, motif supports pixmaps w/ type NO_LINE and
|
|
547 lwlib provides no way to access that functionality. --Stig */
|
|
548 XtSetArg (al [ac], XmNseparatorType, cur->value), ac++;
|
|
549 }
|
|
550 button = XmCreateSeparator (widget, "separator", al, ac);
|
|
551 break;
|
|
552 case CASCADE_TYPE:
|
|
553 menu = XmCreatePulldownMenu (widget, "pulldown", NULL, 0);
|
|
554 make_menu_in_widget (instance, menu, cur->contents);
|
|
555 XtSetArg (al [ac], XmNsubMenuId, menu); ac++;
|
|
556 button = XmCreateCascadeButton (widget, cur->name, al, ac);
|
|
557
|
903
|
558 xm_safe_update_label (instance, button, cur);
|
428
|
559
|
|
560 XtAddCallback (button, XmNcascadingCallback, xm_pull_down_callback,
|
|
561 (XtPointer)instance);
|
|
562 break;
|
|
563 default:
|
|
564 if (menubar_p)
|
|
565 button = XmCreateCascadeButton (widget, cur->name, al, ac);
|
|
566 else if (!cur->call_data)
|
|
567 button = XmCreateLabel (widget, cur->name, al, ac);
|
|
568 else if (cur->type == TOGGLE_TYPE || cur->type == RADIO_TYPE)
|
|
569 {
|
|
570 XtSetArg (al [ac], XmNindicatorType,
|
|
571 (cur->type == TOGGLE_TYPE ?
|
|
572 XmN_OF_MANY : XmONE_OF_MANY)); ac++;
|
|
573 XtSetArg (al [ac], XmNvisibleWhenOff, True); ac++;
|
|
574 button = XmCreateToggleButtonGadget (widget, cur->name, al, ac);
|
|
575 }
|
|
576 else
|
|
577 button = XmCreatePushButtonGadget (widget, cur->name, al, ac);
|
|
578
|
903
|
579 xm_safe_update_label (instance, button, cur);
|
428
|
580
|
|
581 /* don't add a callback to a simple label */
|
|
582 if (cur->type == TOGGLE_TYPE || cur->type == RADIO_TYPE)
|
|
583 xm_update_toggle (instance, button, cur);
|
|
584 else if (cur->call_data)
|
|
585 XtAddCallback (button, XmNactivateCallback, xm_generic_callback,
|
|
586 (XtPointer)instance);
|
|
587 } /* switch (cur->type) */
|
|
588
|
|
589 if (button)
|
|
590 children [num_children++] = button;
|
|
591 }
|
|
592
|
|
593 /* Last entry is the help button. This used be done after managing
|
|
594 the buttons. The comment claimed that it had to be done this way
|
|
595 otherwise the menubar ended up only 4 pixels high. That must
|
|
596 have been in the Old World. In the New World it stays the proper
|
|
597 height if you don't manage them until after you set this and as a
|
|
598 bonus the Help menu ends up where it is supposed to. */
|
|
599 if (button)
|
|
600 {
|
|
601 ac = 0;
|
|
602 XtSetArg (al [ac], XmNmenuHelpWidget, button); ac++;
|
|
603 XtSetValues (widget, al, ac);
|
|
604 }
|
|
605
|
|
606 if (num_children)
|
|
607 XtManageChildren (children, num_children);
|
|
608
|
|
609 XtFree ((char *) children);
|
|
610 }
|
|
611
|
|
612 static void
|
|
613 update_one_menu_entry (widget_instance* instance, Widget widget,
|
|
614 widget_value* val, Boolean deep_p)
|
|
615 {
|
|
616 Arg al [2];
|
|
617 int ac;
|
|
618 Widget menu;
|
|
619 widget_value* contents;
|
|
620
|
|
621 if (val->change == NO_CHANGE)
|
|
622 return;
|
|
623
|
|
624 /* update the sensitivity and userdata */
|
|
625 /* Common to all widget types */
|
|
626 XtSetArg (al [0], XmNsensitive, val->enabled);
|
|
627 XtSetArg (al [1], XmNuserData, val->call_data);
|
|
628 XtSetValues (widget, al, 2);
|
|
629
|
|
630 /* update the menu button as a label. */
|
|
631 if (val->change >= VISIBLE_CHANGE)
|
|
632 {
|
903
|
633 xm_safe_update_label (instance, widget, val);
|
|
634
|
428
|
635 if (XtClass (widget) == xmToggleButtonWidgetClass
|
|
636 || XtClass (widget) == xmToggleButtonGadgetClass)
|
|
637 {
|
|
638 xm_update_toggle (instance, widget, val);
|
|
639 }
|
|
640 }
|
|
641
|
|
642
|
|
643 /* update the pulldown/pullaside as needed */
|
|
644 menu = NULL;
|
|
645 XtSetArg (al [0], XmNsubMenuId, &menu);
|
|
646 XtGetValues (widget, al, 1);
|
|
647
|
|
648 contents = val->contents;
|
|
649
|
|
650 if (!menu)
|
|
651 {
|
|
652 if (contents)
|
|
653 {
|
|
654 menu = XmCreatePulldownMenu (widget, "pulldown", NULL, 0);
|
|
655 make_menu_in_widget (instance, menu, contents);
|
|
656 ac = 0;
|
|
657 XtSetArg (al [ac], XmNsubMenuId, menu); ac++;
|
|
658 XtSetValues (widget, al, ac);
|
|
659 }
|
|
660 }
|
|
661 else if (!contents)
|
|
662 {
|
|
663 ac = 0;
|
|
664 XtSetArg (al [ac], XmNsubMenuId, NULL); ac++;
|
|
665 XtSetValues (widget, al, ac);
|
|
666 XtDestroyWidget (menu);
|
|
667 }
|
|
668 else if (deep_p && contents->change != NO_CHANGE)
|
|
669 xm_update_menu (instance, menu, val, 1);
|
|
670 }
|
|
671
|
|
672 static void
|
|
673 xm_update_menu (widget_instance* instance, Widget widget, widget_value* val,
|
|
674 Boolean deep_p)
|
|
675 {
|
|
676 /* Widget is a RowColumn widget whose contents have to be updated
|
|
677 * to reflect the list of items in val->contents */
|
|
678 if (val->contents->change == STRUCTURAL_CHANGE)
|
|
679 {
|
|
680 destroy_all_children (widget);
|
|
681 make_menu_in_widget (instance, widget, val->contents);
|
|
682 }
|
|
683 else
|
|
684 {
|
|
685 /* Update all the buttons of the RowColumn in order. */
|
|
686 Widget* children;
|
|
687 unsigned int num_children;
|
|
688 int i;
|
|
689 widget_value *cur = 0;
|
|
690
|
|
691 children = XtCompositeChildren (widget, &num_children);
|
|
692 if (children)
|
|
693 {
|
|
694 for (i = 0, cur = val->contents; i < num_children; i++)
|
|
695 {
|
|
696 if (!cur)
|
|
697 abort ();
|
|
698 /* skip if this is a pushright marker or a separator */
|
|
699 if (cur->type == PUSHRIGHT_TYPE || cur->type == SEPARATOR_TYPE)
|
|
700 {
|
|
701 cur = cur->next;
|
|
702 #if 0
|
|
703 /* #### - this could puke if you have a separator as the
|
|
704 last item on a pullright menu. */
|
|
705 if (!cur)
|
|
706 abort ();
|
|
707 #else
|
|
708 if (!cur)
|
|
709 continue;
|
|
710 #endif
|
|
711 }
|
|
712 if (children [i]->core.being_destroyed
|
|
713 || strcmp (XtName (children [i]), cur->name))
|
|
714 continue;
|
|
715 update_one_menu_entry (instance, children [i], cur, deep_p);
|
|
716 cur = cur->next;
|
|
717 }
|
|
718 XtFree ((char *) children);
|
|
719 }
|
|
720 if (cur)
|
|
721 abort ();
|
|
722 }
|
|
723 }
|
|
724
|
|
725 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
726
|
|
727
|
|
728 /* update text widgets */
|
|
729
|
|
730 static void
|
|
731 xm_update_text (widget_instance* instance, Widget widget, widget_value* val)
|
|
732 {
|
438
|
733 XmTextSetString (widget, val->value ? val->value : (char *) "");
|
428
|
734 XtRemoveAllCallbacks (widget, XmNactivateCallback);
|
|
735 XtAddCallback (widget, XmNactivateCallback, xm_generic_callback, instance);
|
|
736 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback);
|
|
737 XtAddCallback (widget, XmNvalueChangedCallback,
|
|
738 xm_internal_update_other_instances, instance);
|
|
739 }
|
|
740
|
|
741 static void
|
|
742 xm_update_text_field (widget_instance* instance, Widget widget,
|
|
743 widget_value* val)
|
|
744 {
|
438
|
745 XmTextFieldSetString (widget, val->value ? val->value : (char *) "");
|
428
|
746 XtRemoveAllCallbacks (widget, XmNactivateCallback);
|
|
747 XtAddCallback (widget, XmNactivateCallback, xm_generic_callback, instance);
|
|
748 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback);
|
|
749 XtAddCallback (widget, XmNvalueChangedCallback,
|
|
750 xm_internal_update_other_instances, instance);
|
|
751 }
|
|
752
|
|
753
|
|
754 #ifdef LWLIB_SCROLLBARS_MOTIF
|
|
755
|
|
756 /*
|
|
757 * If this function looks like it does a lot more work than it needs to,
|
|
758 * you're right. Blame the Motif scrollbar for not being smart about
|
|
759 * updating its appearance.
|
|
760 */
|
|
761 static void
|
|
762 xm_update_scrollbar (widget_instance *instance, Widget widget,
|
|
763 widget_value *val)
|
|
764 {
|
|
765 if (val->scrollbar_data)
|
|
766 {
|
|
767 scrollbar_values *data = val->scrollbar_data;
|
|
768 int widget_sliderSize, widget_val;
|
|
769 int new_sliderSize, new_value;
|
|
770 double percent;
|
|
771 double h_water, l_water;
|
|
772 Arg al [4];
|
|
773
|
|
774 /* First size and position the scrollbar widget. */
|
|
775 XtSetArg (al [0], XtNx, data->scrollbar_x);
|
|
776 XtSetArg (al [1], XtNy, data->scrollbar_y);
|
|
777 XtSetArg (al [2], XtNwidth, data->scrollbar_width);
|
|
778 XtSetArg (al [3], XtNheight, data->scrollbar_height);
|
|
779 XtSetValues (widget, al, 4);
|
|
780
|
|
781 /* Now size the scrollbar's slider. */
|
|
782 XtSetArg (al [0], XmNsliderSize, &widget_sliderSize);
|
|
783 XtSetArg (al [1], XmNvalue, &widget_val);
|
|
784 XtGetValues (widget, al, 2);
|
|
785
|
|
786 percent = (double) data->slider_size /
|
|
787 (double) (data->maximum - data->minimum);
|
|
788 new_sliderSize = (int) ((double) (INT_MAX - 1) * percent);
|
|
789
|
|
790 percent = (double) (data->slider_position - data->minimum) /
|
|
791 (double) (data->maximum - data->minimum);
|
|
792 new_value = (int) ((double) (INT_MAX - 1) * percent);
|
|
793
|
|
794 if (new_sliderSize > (INT_MAX - 1))
|
|
795 new_sliderSize = INT_MAX - 1;
|
|
796 else if (new_sliderSize < 1)
|
|
797 new_sliderSize = 1;
|
|
798
|
|
799 if (new_value > (INT_MAX - new_sliderSize))
|
|
800 new_value = INT_MAX - new_sliderSize;
|
|
801 else if (new_value < 1)
|
|
802 new_value = 1;
|
|
803
|
|
804 h_water = 1.05;
|
|
805 l_water = 0.95;
|
|
806 if (new_sliderSize != widget_sliderSize || new_value != widget_val)
|
|
807 {
|
|
808 int force = ((INT_MAX - widget_sliderSize - widget_val)
|
|
809 ? 0
|
|
810 : (INT_MAX - new_sliderSize - new_value));
|
|
811
|
|
812 if (force
|
|
813 || (double)new_sliderSize < (l_water * (double)widget_sliderSize)
|
|
814 || (double)new_sliderSize > (h_water * (double)widget_sliderSize)
|
|
815 || (double)new_value < (l_water * (double)widget_val)
|
|
816 || (double)new_value > (h_water * (double)widget_val))
|
|
817 {
|
|
818 XmScrollBarSetValues (widget, new_value, new_sliderSize, 1, 1,
|
|
819 False);
|
|
820 }
|
|
821 }
|
|
822 }
|
|
823 }
|
|
824
|
|
825 #endif /* LWLIB_SCROLLBARS_MOTIF */
|
|
826
|
|
827
|
|
828 /* update a motif widget */
|
|
829
|
|
830 void
|
|
831 xm_update_one_widget (widget_instance* instance, Widget widget,
|
2286
|
832 widget_value* val,
|
|
833 #ifdef LWLIB_MENUBARS_MOTIF
|
|
834 Boolean deep_p
|
|
835 #else
|
|
836 Boolean UNUSED (deep_p)
|
|
837 #endif
|
|
838 )
|
428
|
839 {
|
1201
|
840 WidgetClass class_;
|
428
|
841 Arg al [20];
|
|
842 int ac = 0;
|
|
843
|
|
844 /* Mark as not edited */
|
|
845 val->edited = False;
|
|
846
|
|
847 /* Common to all widget types */
|
|
848 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
|
849 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
850 XtSetValues (widget, al, ac);
|
|
851
|
|
852 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
|
853 /* Common to all label like widgets */
|
903
|
854 xm_safe_update_label (instance, widget, val);
|
428
|
855 #endif
|
1201
|
856 class_ = XtClass (widget);
|
428
|
857 /* Class specific things */
|
1201
|
858 if (class_ == xmPushButtonWidgetClass ||
|
|
859 class_ == xmArrowButtonWidgetClass)
|
428
|
860 {
|
|
861 xm_update_pushbutton (instance, widget, val);
|
|
862 }
|
|
863 #ifdef LWLIB_MENUBARS_MOTIF
|
1201
|
864 else if (class_ == xmCascadeButtonWidgetClass)
|
428
|
865 {
|
|
866 xm_update_cascadebutton (instance, widget, val);
|
|
867 }
|
|
868 #endif
|
1201
|
869 else if (class_ == xmToggleButtonWidgetClass
|
|
870 || class_ == xmToggleButtonGadgetClass)
|
428
|
871 {
|
|
872 xm_update_toggle (instance, widget, val);
|
|
873 }
|
1201
|
874 else if (class_ == xmRowColumnWidgetClass)
|
428
|
875 {
|
|
876 Boolean radiobox = 0;
|
|
877
|
|
878 XtSetArg (al [0], XmNradioBehavior, &radiobox);
|
|
879 XtGetValues (widget, al, 1);
|
|
880
|
|
881 if (radiobox)
|
|
882 xm_update_radiobox (instance, widget, val);
|
|
883 #ifdef LWLIB_MENUBARS_MOTIF
|
|
884 else
|
|
885 xm_update_menu (instance, widget, val, deep_p);
|
|
886 #endif
|
|
887 }
|
1201
|
888 else if (class_ == xmTextWidgetClass)
|
428
|
889 {
|
|
890 xm_update_text (instance, widget, val);
|
|
891 }
|
1201
|
892 else if (class_ == xmTextFieldWidgetClass)
|
428
|
893 {
|
|
894 xm_update_text_field (instance, widget, val);
|
|
895 }
|
1201
|
896 else if (class_ == xmListWidgetClass)
|
428
|
897 {
|
|
898 xm_update_list (instance, widget, val);
|
|
899 }
|
|
900 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
1201
|
901 else if (class_ == xmComboBoxWidgetClass)
|
428
|
902 {
|
|
903 xm_update_combo_box (instance, widget, val);
|
|
904 }
|
|
905 #endif
|
|
906 #ifdef LWLIB_SCROLLBARS_MOTIF
|
1201
|
907 else if (class_ == xmScrollBarWidgetClass)
|
428
|
908 {
|
|
909 xm_update_scrollbar (instance, widget, val);
|
|
910 }
|
|
911 #endif
|
1458
|
912 #ifdef LWLIB_WIDGETS_MOTIF
|
1201
|
913 else if (class_ == xmScaleWidgetClass)
|
639
|
914 {
|
|
915 xm_update_progress (instance, widget, val);
|
|
916 }
|
1458
|
917 #endif
|
442
|
918 /* Lastly update our global arg values. */
|
|
919 if (val->args && val->args->nargs)
|
|
920 XtSetValues (widget, val->args->args, val->args->nargs);
|
428
|
921 }
|
|
922
|
|
923 /* getting the value back */
|
|
924 void
|
|
925 xm_update_one_value (widget_instance* instance, Widget widget,
|
|
926 widget_value* val)
|
|
927 {
|
1201
|
928 WidgetClass class_ = XtClass (widget);
|
428
|
929 widget_value *old_wv;
|
|
930
|
|
931 /* copy the call_data slot into the "return" widget_value */
|
|
932 for (old_wv = instance->info->val->contents; old_wv; old_wv = old_wv->next)
|
|
933 if (!strcmp (val->name, old_wv->name))
|
|
934 {
|
|
935 val->call_data = old_wv->call_data;
|
|
936 break;
|
|
937 }
|
|
938
|
1201
|
939 if (class_ == xmToggleButtonWidgetClass || class_ == xmToggleButtonGadgetClass)
|
428
|
940 {
|
|
941 Arg al [1];
|
|
942 XtSetArg (al [0], XmNset, &val->selected);
|
|
943 XtGetValues (widget, al, 1);
|
|
944 val->edited = True;
|
|
945 }
|
1201
|
946 else if (class_ == xmTextWidgetClass)
|
428
|
947 {
|
|
948 if (val->value)
|
458
|
949 XtFree (val->value);
|
428
|
950 val->value = XmTextGetString (widget);
|
|
951 val->edited = True;
|
|
952 }
|
1201
|
953 else if (class_ == xmTextFieldWidgetClass)
|
428
|
954 {
|
|
955 if (val->value)
|
458
|
956 XtFree (val->value);
|
428
|
957 val->value = XmTextFieldGetString (widget);
|
|
958 val->edited = True;
|
|
959 }
|
1201
|
960 else if (class_ == xmRowColumnWidgetClass)
|
428
|
961 {
|
|
962 Boolean radiobox = 0;
|
|
963 {
|
|
964 Arg al [1];
|
|
965 XtSetArg (al [0], XmNradioBehavior, &radiobox);
|
|
966 XtGetValues (widget, al, 1);
|
|
967 }
|
|
968
|
|
969 if (radiobox)
|
|
970 {
|
|
971 CompositeWidget radio = (CompositeWidget)widget;
|
639
|
972 unsigned int i;
|
428
|
973 for (i = 0; i < radio->composite.num_children; i++)
|
|
974 {
|
|
975 int set = False;
|
|
976 Widget toggle = radio->composite.children [i];
|
|
977 Arg al [1];
|
|
978
|
|
979 XtSetArg (al [0], XmNset, &set);
|
|
980 XtGetValues (toggle, al, 1);
|
|
981 if (set)
|
|
982 {
|
|
983 if (val->value)
|
|
984 free (val->value);
|
|
985 val->value = safe_strdup (XtName (toggle));
|
|
986 }
|
|
987 }
|
|
988 val->edited = True;
|
|
989 }
|
|
990 }
|
1201
|
991 else if (class_ == xmListWidgetClass
|
428
|
992 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
1201
|
993 || class_ == xmComboBoxWidgetClass
|
428
|
994 #endif
|
|
995 )
|
|
996 {
|
|
997 int pos_cnt;
|
|
998 int* pos_list;
|
|
999 Widget list = widget;
|
|
1000 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
1201
|
1001 if (class_ == xmComboBoxWidgetClass)
|
428
|
1002 list = CB_List (widget);
|
|
1003 #endif
|
|
1004 if (XmListGetSelectedPos (list, &pos_list, &pos_cnt))
|
|
1005 {
|
|
1006 int i;
|
|
1007 widget_value* cur;
|
|
1008 for (cur = val->contents, i = 0; cur; cur = cur->next)
|
|
1009 if (cur->value)
|
|
1010 {
|
|
1011 int j;
|
|
1012 cur->selected = False;
|
|
1013 i += 1;
|
|
1014 for (j = 0; j < pos_cnt; j++)
|
|
1015 if (pos_list [j] == i)
|
|
1016 {
|
|
1017 cur->selected = True;
|
|
1018 val->value = safe_strdup (cur->name);
|
|
1019 }
|
|
1020 }
|
|
1021 val->edited = 1;
|
|
1022 XtFree ((char *) pos_list);
|
|
1023 }
|
|
1024 }
|
|
1025 #ifdef LWLIB_SCROLLBARS_MOTIF
|
1201
|
1026 else if (class_ == xmScrollBarWidgetClass)
|
428
|
1027 {
|
|
1028 /* This function is not used by the scrollbar. */
|
|
1029 return;
|
|
1030 }
|
|
1031 #endif
|
|
1032 }
|
|
1033
|
|
1034
|
1330
|
1035 #ifdef LWLIB_DIALOGS_MOTIF
|
|
1036
|
428
|
1037 /* This function is for activating a button from a program. It's wrong because
|
|
1038 we pass a NULL argument in the call_data which is not Motif compatible.
|
|
1039 This is used from the XmNdefaultAction callback of the List widgets to
|
|
1040 have a double-click put down a dialog box like the button would do.
|
|
1041 I could not find a way to do that with accelerators.
|
|
1042 */
|
|
1043 static void
|
2311
|
1044 activate_button (Widget UNUSED (widget), XtPointer closure,
|
|
1045 XtPointer UNUSED (call_data))
|
428
|
1046 {
|
|
1047 Widget button = (Widget)closure;
|
|
1048 XtCallCallbacks (button, XmNactivateCallback, NULL);
|
|
1049 }
|
|
1050
|
|
1051 /* creation functions */
|
|
1052
|
|
1053 /* dialogs */
|
|
1054
|
|
1055 #if (XmVersion >= 1002)
|
|
1056 # define ARMANDACTIVATE_KLUDGE
|
|
1057 # define DND_KLUDGE
|
|
1058 #endif
|
|
1059
|
|
1060 #ifdef ARMANDACTIVATE_KLUDGE
|
|
1061 /* We want typing Return at a dialog box to select the default button; but
|
|
1062 we're satisfied with having it select the leftmost button instead.
|
|
1063
|
|
1064 In Motif 1.1.5 we could do this by putting this resource in the
|
|
1065 app-defaults file:
|
|
1066
|
|
1067 *dialog*button1.accelerators:#override\
|
|
1068 <KeyPress>Return: ArmAndActivate()\n\
|
|
1069 <KeyPress>KP_Enter: ArmAndActivate()\n\
|
|
1070 Ctrl<KeyPress>m: ArmAndActivate()\n
|
|
1071
|
|
1072 but that doesn't work with 1.2.1 and I don't understand why. However,
|
|
1073 doing the equivalent C code does work, with the notable disadvantage that
|
|
1074 the user can't override it. So that's what we do until we figure out
|
|
1075 something better....
|
|
1076 */
|
|
1077 static char button_trans[] = "\
|
|
1078 <KeyPress>Return: ArmAndActivate()\n\
|
|
1079 <KeyPress>KP_Enter: ArmAndActivate()\n\
|
|
1080 Ctrl<KeyPress>m: ArmAndActivate()\n";
|
|
1081
|
|
1082 #endif /* ARMANDACTIVATE_KLUDGE */
|
|
1083
|
|
1084
|
|
1085 #ifdef DND_KLUDGE
|
|
1086 /* This is a kludge to disable drag-and-drop in dialog boxes. The symptom
|
|
1087 was a segv down in libXm somewhere if you used the middle button on a
|
|
1088 dialog box to begin a drag; when you released the button to make a drop
|
|
1089 things would lose if you were not over the button where you started the
|
|
1090 drag (canceling the operation). This was probably due to the fact that
|
|
1091 the dialog boxes were not set up to handle a drag but were trying to do
|
|
1092 so anyway for some reason.
|
|
1093
|
|
1094 So we disable drag-and-drop in dialog boxes by turning off the binding for
|
|
1095 Btn2Down which, by default, initiates a drag. Clearly this is a shitty
|
|
1096 solution as it only works in default configurations, but...
|
|
1097 */
|
|
1098 static char disable_dnd_trans[] = "<Btn2Down>: ";
|
|
1099 #endif /* DND_KLUDGE */
|
|
1100
|
|
1101
|
|
1102 static Widget
|
2311
|
1103 make_dialog (char* UNUSED (name), Widget parent, Boolean pop_up_p,
|
442
|
1104 const char* shell_title, const char* icon_name,
|
428
|
1105 Boolean text_input_slot, Boolean radio_box, Boolean list,
|
|
1106 int left_buttons, int right_buttons)
|
|
1107 {
|
|
1108 Widget result;
|
|
1109 Widget form;
|
|
1110 Widget row;
|
|
1111 Widget icon;
|
|
1112 Widget icon_separator;
|
|
1113 Widget message;
|
|
1114 Widget value = 0;
|
|
1115 Widget separator;
|
|
1116 Widget button = 0;
|
|
1117 Widget children [16]; /* for the final XtManageChildren */
|
|
1118 int n_children;
|
|
1119 Arg al[64]; /* Arg List */
|
|
1120 int ac; /* Arg Count */
|
|
1121 int i;
|
|
1122
|
|
1123 #ifdef DND_KLUDGE
|
|
1124 XtTranslations dnd_override = XtParseTranslationTable (disable_dnd_trans);
|
|
1125 # define DO_DND_KLUDGE(widget) XtOverrideTranslations ((widget), dnd_override)
|
|
1126 #else /* ! DND_KLUDGE */
|
|
1127 # define DO_DND_KLUDGE(widget)
|
|
1128 #endif /* ! DND_KLUDGE */
|
|
1129
|
|
1130 if (pop_up_p)
|
|
1131 {
|
|
1132 ac = 0;
|
|
1133 XtSetArg(al[ac], XmNtitle, shell_title); ac++;
|
|
1134 XtSetArg(al[ac], XtNallowShellResize, True); ac++;
|
|
1135 XtSetArg(al[ac], XmNdeleteResponse, XmUNMAP); ac++;
|
|
1136 result = XmCreateDialogShell (parent, "dialog", al, ac);
|
|
1137
|
|
1138 XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
|
|
1139 /* XtSetArg(al[ac], XmNautoUnmanage, TRUE); ac++; */ /* ####is this ok? */
|
|
1140 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
|
|
1141 form = XmCreateForm (result, (char *) shell_title, al, ac);
|
|
1142 }
|
|
1143 else
|
|
1144 {
|
|
1145 ac = 0;
|
|
1146 XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
|
|
1147 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
|
|
1148 form = XmCreateForm (parent, (char *) shell_title, al, ac);
|
|
1149 result = form;
|
|
1150 }
|
|
1151
|
|
1152 ac = 0;
|
|
1153 XtSetArg(al[ac], XmNpacking, XmPACK_COLUMN); ac++;
|
|
1154 XtSetArg(al[ac], XmNorientation, XmVERTICAL); ac++;
|
|
1155 XtSetArg(al[ac], XmNnumColumns, left_buttons + right_buttons + 1); ac++;
|
|
1156 XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
|
|
1157 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
|
|
1158 XtSetArg(al[ac], XmNspacing, 13); ac++;
|
|
1159 XtSetArg(al[ac], XmNadjustLast, False); ac++;
|
|
1160 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
|
|
1161 XtSetArg(al[ac], XmNisAligned, True); ac++;
|
|
1162 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
|
|
1163 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
|
|
1164 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1165 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
|
|
1166 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1167 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1168 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1169 row = XmCreateRowColumn (form, "row", al, ac);
|
|
1170
|
|
1171 n_children = 0;
|
|
1172 for (i = 0; i < left_buttons; i++)
|
|
1173 {
|
|
1174 char button_name [16];
|
|
1175 sprintf (button_name, "button%d", i + 1);
|
|
1176 ac = 0;
|
|
1177 if (i == 0)
|
|
1178 {
|
|
1179 XtSetArg(al[ac], XmNhighlightThickness, 1); ac++;
|
|
1180 XtSetArg(al[ac], XmNshowAsDefault, TRUE); ac++;
|
|
1181 }
|
|
1182 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
|
|
1183 children [n_children] = XmCreatePushButton (row, button_name, al, ac);
|
|
1184 DO_DND_KLUDGE (children [n_children]);
|
|
1185
|
|
1186 if (i == 0)
|
|
1187 {
|
|
1188 button = children [n_children];
|
|
1189 ac = 0;
|
|
1190 XtSetArg(al[ac], XmNdefaultButton, button); ac++;
|
|
1191 XtSetValues (row, al, ac);
|
|
1192
|
|
1193 #ifdef ARMANDACTIVATE_KLUDGE /* See comment above */
|
|
1194 {
|
|
1195 XtTranslations losers = XtParseTranslationTable (button_trans);
|
|
1196 XtOverrideTranslations (button, losers);
|
|
1197 XtFree ((char *) losers);
|
|
1198 }
|
|
1199 #endif /* ARMANDACTIVATE_KLUDGE */
|
|
1200 }
|
|
1201
|
|
1202 n_children++;
|
|
1203 }
|
|
1204
|
442
|
1205 /* invisible separator button */
|
428
|
1206 ac = 0;
|
|
1207 XtSetArg (al[ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1208 children [n_children] = XmCreateLabel (row, "separator_button",
|
|
1209 al, ac);
|
|
1210 DO_DND_KLUDGE (children [n_children]);
|
|
1211 n_children++;
|
|
1212
|
|
1213 for (i = 0; i < right_buttons; i++)
|
|
1214 {
|
|
1215 char button_name [16];
|
|
1216 sprintf (button_name, "button%d", left_buttons + i + 1);
|
|
1217 ac = 0;
|
|
1218 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
|
|
1219 children [n_children] = XmCreatePushButton (row, button_name, al, ac);
|
|
1220 DO_DND_KLUDGE (children [n_children]);
|
|
1221 if (! button) button = children [n_children];
|
|
1222 n_children++;
|
|
1223 }
|
|
1224
|
|
1225 XtManageChildren (children, n_children);
|
|
1226
|
|
1227 ac = 0;
|
|
1228 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
|
|
1229 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1230 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1231 XtSetArg(al[ac], XmNbottomWidget, row); ac++;
|
|
1232 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
|
|
1233 XtSetArg(al[ac], XmNleftOffset, 0); ac++;
|
|
1234 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1235 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
|
|
1236 separator = XmCreateSeparator (form, "", al, ac);
|
|
1237
|
|
1238 ac = 0;
|
|
1239 XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++;
|
|
1240 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
|
|
1241 XtSetArg(al[ac], XmNtopOffset, 13); ac++;
|
|
1242 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
|
|
1243 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
|
|
1244 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1245 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_NONE); ac++;
|
|
1246 icon = XmCreateLabel (form, (char *) icon_name, al, ac);
|
|
1247 DO_DND_KLUDGE (icon);
|
|
1248
|
|
1249 ac = 0;
|
|
1250 XtSetArg(al[ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1251 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
|
|
1252 XtSetArg(al[ac], XmNtopOffset, 6); ac++;
|
|
1253 XtSetArg(al[ac], XmNtopWidget, icon); ac++;
|
|
1254 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1255 XtSetArg(al[ac], XmNbottomOffset, 6); ac++;
|
|
1256 XtSetArg(al[ac], XmNbottomWidget, separator); ac++;
|
|
1257 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_NONE); ac++;
|
|
1258 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_NONE); ac++;
|
|
1259 icon_separator = XmCreateLabel (form, "", al, ac);
|
|
1260 DO_DND_KLUDGE (icon_separator);
|
|
1261
|
|
1262 if (text_input_slot)
|
|
1263 {
|
|
1264 ac = 0;
|
|
1265 XtSetArg(al[ac], XmNcolumns, 50); ac++;
|
|
1266 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
|
|
1267 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1268 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1269 XtSetArg(al[ac], XmNbottomWidget, separator); ac++;
|
|
1270 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1271 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1272 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1273 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1274 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1275 value = XmCreateTextField (form, "value", al, ac);
|
|
1276 DO_DND_KLUDGE (value);
|
|
1277 }
|
|
1278 else if (radio_box)
|
|
1279 {
|
|
1280 Widget radio_butt;
|
|
1281 ac = 0;
|
|
1282 XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
|
|
1283 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
|
|
1284 XtSetArg(al[ac], XmNspacing, 13); ac++;
|
|
1285 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
|
|
1286 XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
|
|
1287 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1288 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1289 XtSetArg(al[ac], XmNbottomWidget, separator); ac++;
|
|
1290 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1291 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1292 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1293 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1294 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1295 value = XmCreateRadioBox (form, "radiobutton1", al, ac);
|
|
1296 ac = 0;
|
|
1297 i = 0;
|
|
1298 radio_butt = XmCreateToggleButtonGadget (value, "radio1", al, ac);
|
|
1299 children [i++] = radio_butt;
|
|
1300 radio_butt = XmCreateToggleButtonGadget (value, "radio2", al, ac);
|
|
1301 children [i++] = radio_butt;
|
|
1302 radio_butt = XmCreateToggleButtonGadget (value, "radio3", al, ac);
|
|
1303 children [i++] = radio_butt;
|
|
1304 XtManageChildren (children, i);
|
|
1305 }
|
|
1306 else if (list)
|
|
1307 {
|
|
1308 ac = 0;
|
|
1309 XtSetArg(al[ac], XmNvisibleItemCount, 5); ac++;
|
|
1310 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
|
|
1311 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1312 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1313 XtSetArg(al[ac], XmNbottomWidget, separator); ac++;
|
|
1314 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1315 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1316 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1317 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1318 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1319 value = XmCreateScrolledList (form, "list", al, ac);
|
|
1320
|
442
|
1321 /* this is the easiest way I found to have the double click in the
|
428
|
1322 list activate the default button */
|
|
1323 XtAddCallback (value, XmNdefaultActionCallback, activate_button, button);
|
|
1324 }
|
805
|
1325 /* else add nothing; it's a separator */
|
428
|
1326
|
|
1327 ac = 0;
|
|
1328 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1329 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
|
|
1330 XtSetArg(al[ac], XmNtopOffset, 13); ac++;
|
|
1331 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1332 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1333 XtSetArg(al[ac], XmNbottomWidget,
|
|
1334 text_input_slot || radio_box || list ? value : separator); ac++;
|
|
1335 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1336 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1337 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1338 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1339 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1340 message = XmCreateLabel (form, "message", al, ac);
|
|
1341 DO_DND_KLUDGE (message);
|
|
1342
|
|
1343 if (list)
|
|
1344 XtManageChild (value);
|
|
1345
|
|
1346 i = 0;
|
|
1347 children [i] = row; i++;
|
|
1348 children [i] = separator; i++;
|
|
1349 if (text_input_slot || radio_box)
|
|
1350 {
|
|
1351 children [i] = value; i++;
|
|
1352 }
|
|
1353 children [i] = message; i++;
|
|
1354 children [i] = icon; i++;
|
|
1355 children [i] = icon_separator; i++;
|
|
1356 XtManageChildren (children, i);
|
|
1357
|
|
1358 if (text_input_slot || list)
|
|
1359 {
|
|
1360 XtInstallAccelerators (value, button);
|
|
1361 XmProcessTraversal(value, XmTRAVERSE_CURRENT);
|
|
1362 }
|
805
|
1363 else if (radio_box)
|
428
|
1364 {
|
|
1365 XtInstallAccelerators (form, button);
|
|
1366 XmProcessTraversal(value, XmTRAVERSE_CURRENT);
|
|
1367 }
|
805
|
1368 /* else we don' need no STEENKIN' assellerators. */
|
428
|
1369
|
|
1370 #ifdef DND_KLUDGE
|
|
1371 XtFree ((char *) dnd_override);
|
|
1372 #endif
|
|
1373 #undef DO_DND_KLUDGE
|
|
1374
|
|
1375 return result;
|
|
1376 }
|
|
1377
|
|
1378 static destroyed_instance*
|
|
1379 find_matching_instance (widget_instance* instance)
|
|
1380 {
|
|
1381 destroyed_instance* cur;
|
|
1382 destroyed_instance* prev;
|
|
1383 char* type = instance->info->type;
|
|
1384 char* name = instance->info->name;
|
|
1385
|
|
1386 for (prev = NULL, cur = all_destroyed_instances;
|
|
1387 cur;
|
|
1388 prev = cur, cur = cur->next)
|
|
1389 {
|
|
1390 if (!strcmp (cur->name, name)
|
|
1391 && !strcmp (cur->type, type)
|
|
1392 && cur->parent == instance->parent
|
|
1393 && cur->pop_up_p == instance->pop_up_p)
|
|
1394 {
|
|
1395 if (prev)
|
|
1396 prev->next = cur->next;
|
|
1397 else
|
|
1398 all_destroyed_instances = cur->next;
|
|
1399 return cur;
|
|
1400 }
|
|
1401 /* do some cleanup */
|
|
1402 else if (!cur->widget)
|
|
1403 {
|
|
1404 if (prev)
|
|
1405 prev->next = cur->next;
|
|
1406 else
|
|
1407 all_destroyed_instances = cur->next;
|
|
1408 free_destroyed_instance (cur);
|
|
1409 cur = prev ? prev : all_destroyed_instances;
|
|
1410 }
|
|
1411 }
|
|
1412 return NULL;
|
|
1413 }
|
|
1414
|
|
1415 static void
|
|
1416 recenter_widget (Widget widget)
|
|
1417 {
|
|
1418 Widget parent = XtParent (widget);
|
|
1419 Screen* screen = XtScreen (widget);
|
|
1420 Dimension screen_width = WidthOfScreen (screen);
|
|
1421 Dimension screen_height = HeightOfScreen (screen);
|
|
1422 Dimension parent_width = 0;
|
|
1423 Dimension parent_height = 0;
|
|
1424 Dimension child_width = 0;
|
|
1425 Dimension child_height = 0;
|
|
1426 Position x;
|
|
1427 Position y;
|
|
1428 Arg al [2];
|
|
1429
|
|
1430 XtSetArg (al [0], XtNwidth, &child_width);
|
|
1431 XtSetArg (al [1], XtNheight, &child_height);
|
|
1432 XtGetValues (widget, al, 2);
|
|
1433
|
|
1434 XtSetArg (al [0], XtNwidth, &parent_width);
|
|
1435 XtSetArg (al [1], XtNheight, &parent_height);
|
|
1436 XtGetValues (parent, al, 2);
|
|
1437
|
|
1438 x = (Position) ((parent_width - child_width) / 2);
|
|
1439 y = (Position) ((parent_height - child_height) / 2);
|
|
1440
|
|
1441 XtTranslateCoords (parent, x, y, &x, &y);
|
|
1442
|
|
1443 if ((Dimension) (x + child_width) > screen_width)
|
|
1444 x = screen_width - child_width;
|
|
1445 if (x < 0)
|
|
1446 x = 0;
|
|
1447
|
|
1448 if ((Dimension) (y + child_height) > screen_height)
|
|
1449 y = screen_height - child_height;
|
|
1450 if (y < 0)
|
|
1451 y = 0;
|
|
1452
|
|
1453 XtSetArg (al [0], XtNx, x);
|
|
1454 XtSetArg (al [1], XtNy, y);
|
|
1455 XtSetValues (widget, al, 2);
|
|
1456 }
|
|
1457
|
|
1458 static Widget
|
|
1459 recycle_instance (destroyed_instance* instance)
|
|
1460 {
|
|
1461 Widget widget = instance->widget;
|
|
1462
|
|
1463 /* widget is NULL if the parent was destroyed. */
|
|
1464 if (widget)
|
|
1465 {
|
|
1466 Widget focus;
|
|
1467 Widget separator;
|
|
1468
|
|
1469 /* Remove the destroy callback as the instance is not in the list
|
|
1470 anymore */
|
|
1471 XtRemoveCallback (instance->parent, XtNdestroyCallback,
|
|
1472 mark_dead_instance_destroyed,
|
|
1473 (XtPointer)instance);
|
|
1474
|
|
1475 /* Give the focus to the initial item */
|
|
1476 focus = XtNameToWidget (widget, "*value");
|
|
1477 if (!focus)
|
|
1478 focus = XtNameToWidget (widget, "*button1");
|
|
1479 if (focus)
|
|
1480 XmProcessTraversal(focus, XmTRAVERSE_CURRENT);
|
|
1481
|
|
1482 /* shrink the separator label back to their original size */
|
|
1483 separator = XtNameToWidget (widget, "*separator_button");
|
|
1484 if (separator)
|
|
1485 {
|
|
1486 Arg al [2];
|
|
1487 XtSetArg (al [0], XtNwidth, 5);
|
|
1488 XtSetArg (al [1], XtNheight, 5);
|
|
1489 XtSetValues (separator, al, 2);
|
|
1490 }
|
|
1491
|
|
1492 /* Center the dialog in its parent */
|
|
1493 recenter_widget (widget);
|
|
1494 }
|
|
1495 free_destroyed_instance (instance);
|
|
1496 return widget;
|
|
1497 }
|
|
1498
|
|
1499 Widget
|
|
1500 xm_create_dialog (widget_instance* instance)
|
|
1501 {
|
|
1502 char* name = instance->info->type;
|
|
1503 Widget parent = instance->parent;
|
|
1504 Widget widget;
|
|
1505 Boolean pop_up_p = instance->pop_up_p;
|
442
|
1506 const char* shell_name = 0;
|
|
1507 const char* icon_name = 0;
|
428
|
1508 Boolean text_input_slot = False;
|
|
1509 Boolean radio_box = False;
|
|
1510 Boolean list = False;
|
|
1511 int total_buttons;
|
|
1512 int left_buttons = 0;
|
|
1513 int right_buttons = 1;
|
|
1514 destroyed_instance* dead_one;
|
|
1515
|
|
1516 /* try to find a widget to recycle */
|
|
1517 dead_one = find_matching_instance (instance);
|
|
1518 if (dead_one)
|
|
1519 {
|
|
1520 Widget recycled_widget = recycle_instance (dead_one);
|
|
1521 if (recycled_widget)
|
|
1522 return recycled_widget;
|
|
1523 }
|
|
1524
|
|
1525 switch (name [0]){
|
|
1526 case 'E': case 'e':
|
|
1527 icon_name = "dbox-error";
|
|
1528 shell_name = "Error";
|
|
1529 break;
|
|
1530
|
|
1531 case 'I': case 'i':
|
|
1532 icon_name = "dbox-info";
|
|
1533 shell_name = "Information";
|
|
1534 break;
|
|
1535
|
|
1536 case 'L': case 'l':
|
|
1537 list = True;
|
|
1538 icon_name = "dbox-question";
|
|
1539 shell_name = "Prompt";
|
|
1540 break;
|
|
1541
|
|
1542 case 'P': case 'p':
|
|
1543 text_input_slot = True;
|
|
1544 icon_name = "dbox-question";
|
|
1545 shell_name = "Prompt";
|
|
1546 break;
|
|
1547
|
|
1548 case 'Q': case 'q':
|
|
1549 icon_name = "dbox-question";
|
|
1550 shell_name = "Question";
|
|
1551 break;
|
|
1552 }
|
|
1553
|
|
1554 total_buttons = name [1] - '0';
|
|
1555
|
|
1556 if (name [3] == 'T' || name [3] == 't')
|
|
1557 {
|
|
1558 text_input_slot = False;
|
|
1559 radio_box = True;
|
|
1560 }
|
|
1561 else if (name [3])
|
|
1562 right_buttons = name [4] - '0';
|
|
1563
|
|
1564 left_buttons = total_buttons - right_buttons;
|
|
1565
|
|
1566 widget = make_dialog (name, parent, pop_up_p,
|
|
1567 shell_name, icon_name, text_input_slot, radio_box,
|
|
1568 list, left_buttons, right_buttons);
|
|
1569
|
|
1570 XtAddCallback (widget, XmNpopdownCallback, xm_nosel_callback,
|
|
1571 (XtPointer) instance);
|
|
1572 return widget;
|
|
1573 }
|
|
1574
|
|
1575 #endif /* LWLIB_DIALOGS_MOTIF */
|
|
1576
|
|
1577 #ifdef LWLIB_MENUBARS_MOTIF
|
|
1578 static Widget
|
|
1579 make_menubar (widget_instance* instance)
|
|
1580 {
|
|
1581 Arg al[10];
|
|
1582 int ac = 0;
|
|
1583
|
|
1584 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
|
|
1585 XtSetArg(al[ac], XmNshadowThickness, 3); ac++;
|
|
1586
|
|
1587 return XmCreateMenuBar (instance->parent, instance->info->name, al, ac);
|
|
1588 }
|
|
1589
|
|
1590 static void
|
|
1591 remove_grabs (Widget shell, XtPointer closure, XtPointer call_data)
|
|
1592 {
|
|
1593 Widget menu = (Widget) closure;
|
|
1594 XmRemoveFromPostFromList (menu, XtParent (XtParent ((Widget) menu)));
|
|
1595 }
|
|
1596
|
|
1597 static Widget
|
|
1598 make_popup_menu (widget_instance* instance)
|
|
1599 {
|
|
1600 Widget parent = instance->parent;
|
|
1601 Window parent_window = parent->core.window;
|
|
1602 Widget result;
|
|
1603
|
|
1604 /* sets the parent window to 0 to fool Motif into not generating a grab */
|
|
1605 parent->core.window = 0;
|
|
1606 result = XmCreatePopupMenu (parent, instance->info->name, NULL, 0);
|
|
1607 XtAddCallback (XtParent (result), XmNpopdownCallback, remove_grabs,
|
|
1608 (XtPointer)result);
|
|
1609 parent->core.window = parent_window;
|
|
1610 return result;
|
|
1611 }
|
|
1612 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
1613
|
|
1614 #ifdef LWLIB_SCROLLBARS_MOTIF
|
|
1615 static Widget
|
|
1616 make_scrollbar (widget_instance *instance, int vertical)
|
|
1617 {
|
|
1618 Arg al[20];
|
|
1619 int ac = 0;
|
|
1620 static XtCallbackRec callbacks[2] =
|
|
1621 { {xm_scrollbar_callback, NULL}, {NULL, NULL} };
|
|
1622
|
|
1623 callbacks[0].closure = (XtPointer) instance;
|
|
1624
|
|
1625 XtSetArg (al[ac], XmNminimum, 1); ac++;
|
|
1626 XtSetArg (al[ac], XmNmaximum, INT_MAX); ac++;
|
|
1627 XtSetArg (al[ac], XmNincrement, 1); ac++;
|
|
1628 XtSetArg (al[ac], XmNpageIncrement, 1); ac++;
|
|
1629 XtSetArg (al[ac], XmNborderWidth, 0); ac++;
|
|
1630 XtSetArg (al[ac], XmNorientation, vertical ? XmVERTICAL : XmHORIZONTAL); ac++;
|
|
1631
|
|
1632 XtSetArg (al[ac], XmNdecrementCallback, callbacks); ac++;
|
|
1633 XtSetArg (al[ac], XmNdragCallback, callbacks); ac++;
|
|
1634 XtSetArg (al[ac], XmNincrementCallback, callbacks); ac++;
|
|
1635 XtSetArg (al[ac], XmNpageDecrementCallback, callbacks); ac++;
|
|
1636 XtSetArg (al[ac], XmNpageIncrementCallback, callbacks); ac++;
|
|
1637 XtSetArg (al[ac], XmNtoBottomCallback, callbacks); ac++;
|
|
1638 XtSetArg (al[ac], XmNtoTopCallback, callbacks); ac++;
|
|
1639 XtSetArg (al[ac], XmNvalueChangedCallback, callbacks); ac++;
|
|
1640
|
|
1641 return XmCreateScrollBar (instance->parent, instance->info->name, al, ac);
|
|
1642 }
|
|
1643
|
|
1644 static Widget
|
|
1645 make_vertical_scrollbar (widget_instance *instance)
|
|
1646 {
|
|
1647 return make_scrollbar (instance, 1);
|
|
1648 }
|
|
1649
|
|
1650 static Widget
|
|
1651 make_horizontal_scrollbar (widget_instance *instance)
|
|
1652 {
|
|
1653 return make_scrollbar (instance, 0);
|
|
1654 }
|
|
1655
|
|
1656 #endif /* LWLIB_SCROLLBARS_MOTIF */
|
|
1657
|
|
1658 #ifdef LWLIB_WIDGETS_MOTIF
|
|
1659 /* glyph widgets */
|
|
1660 static Widget
|
|
1661 xm_create_button (widget_instance *instance)
|
|
1662 {
|
|
1663 Arg al[20];
|
|
1664 int ac = 0;
|
|
1665 Widget button = 0;
|
|
1666 widget_value* val = instance->info->val;
|
|
1667
|
|
1668 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
|
1669 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1670 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
1671 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1672 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1673 look ugly. I think this may be a LessTif bug but for now we just
|
|
1674 get rid of it. */
|
|
1675 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
|
1676
|
|
1677 /* add any args the user supplied for creation time */
|
|
1678 lw_add_value_args_to_args (val, al, &ac);
|
|
1679
|
|
1680 if (!val->call_data)
|
|
1681 button = XmCreateLabel (instance->parent, val->name, al, ac);
|
|
1682
|
|
1683 else if (val->type == TOGGLE_TYPE || val->type == RADIO_TYPE)
|
|
1684 {
|
|
1685 XtSetArg (al [ac], XmNset, val->selected); ac++;
|
|
1686 XtSetArg (al [ac], XmNindicatorType,
|
|
1687 (val->type == TOGGLE_TYPE ?
|
|
1688 XmN_OF_MANY : XmONE_OF_MANY)); ac++;
|
|
1689 XtSetArg (al [ac], XmNvisibleWhenOff, True); ac++;
|
|
1690 button = XmCreateToggleButton (instance->parent, val->name, al, ac);
|
|
1691 XtRemoveAllCallbacks (button, XmNvalueChangedCallback);
|
|
1692 XtAddCallback (button, XmNvalueChangedCallback, xm_generic_callback,
|
|
1693 (XtPointer)instance);
|
|
1694 }
|
|
1695 else
|
|
1696 {
|
|
1697 button = XmCreatePushButton (instance->parent, val->name, al, ac);
|
|
1698 XtAddCallback (button, XmNactivateCallback, xm_generic_callback,
|
|
1699 (XtPointer)instance);
|
|
1700 }
|
|
1701
|
|
1702 XtManageChild (button);
|
|
1703
|
|
1704 return button;
|
|
1705 }
|
|
1706
|
|
1707 static Widget
|
|
1708 xm_create_progress (widget_instance *instance)
|
|
1709 {
|
|
1710 Arg al[20];
|
|
1711 int ac = 0;
|
639
|
1712 Dimension height = 0;
|
|
1713 Dimension width = 0;
|
428
|
1714 Widget scale = 0;
|
|
1715 widget_value* val = instance->info->val;
|
|
1716 if (!val->call_data)
|
|
1717 {
|
639
|
1718 XtSetArg (al [ac], XmNeditable, False); ac++;
|
428
|
1719 }
|
|
1720 else
|
|
1721 {
|
639
|
1722 XtSetArg (al [ac], XmNeditable, val->enabled); ac++;
|
428
|
1723 }
|
|
1724 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1725 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
1726 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1727 XtSetArg (al [ac], XmNorientation, XmHORIZONTAL); ac++;
|
|
1728 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1729 look ugly. I think this may be a LessTif bug but for now we just
|
|
1730 get rid of it. */
|
|
1731 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
639
|
1732
|
|
1733 height = (Dimension)lw_get_value_arg (val, XtNheight);
|
|
1734 width = (Dimension)lw_get_value_arg (val, XtNwidth);
|
|
1735 if (height > 0)
|
|
1736 {
|
|
1737 XtSetArg (al [ac], XmNscaleHeight, height); ac++;
|
|
1738 }
|
|
1739 if (width > 0)
|
|
1740 {
|
|
1741 XtSetArg (al [ac], XmNscaleWidth, width); ac++;
|
|
1742 }
|
|
1743
|
428
|
1744 /* add any args the user supplied for creation time */
|
|
1745 lw_add_value_args_to_args (val, al, &ac);
|
|
1746
|
|
1747 scale = XmCreateScale (instance->parent, val->name, al, ac);
|
|
1748 if (val->call_data)
|
|
1749 XtAddCallback (scale, XmNvalueChangedCallback, xm_generic_callback,
|
|
1750 (XtPointer)instance);
|
|
1751
|
|
1752 XtManageChild (scale);
|
|
1753
|
|
1754 return scale;
|
|
1755 }
|
|
1756
|
|
1757 static Widget
|
|
1758 xm_create_text_field (widget_instance *instance)
|
|
1759 {
|
|
1760 Arg al[20];
|
|
1761 int ac = 0;
|
|
1762 Widget text = 0;
|
|
1763 widget_value* val = instance->info->val;
|
|
1764
|
442
|
1765 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
428
|
1766 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1767 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
1768 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1769 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1770 look ugly. I think this may be a LessTif bug but for now we just
|
|
1771 get rid of it. */
|
|
1772 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
|
1773
|
|
1774 /* add any args the user supplied for creation time */
|
|
1775 lw_add_value_args_to_args (val, al, &ac);
|
|
1776
|
|
1777 text = XmCreateTextField (instance->parent, val->name, al, ac);
|
|
1778 if (val->call_data)
|
|
1779 XtAddCallback (text, XmNvalueChangedCallback, xm_generic_callback,
|
|
1780 (XtPointer)instance);
|
|
1781
|
|
1782 XtManageChild (text);
|
|
1783
|
|
1784 return text;
|
|
1785 }
|
|
1786
|
|
1787 static Widget
|
|
1788 xm_create_label_field (widget_instance *instance)
|
|
1789 {
|
|
1790 return xm_create_label (instance->parent, instance->info->val);
|
|
1791 }
|
|
1792
|
|
1793 Widget
|
|
1794 xm_create_label (Widget parent, widget_value* val)
|
|
1795 {
|
|
1796 Arg al[20];
|
|
1797 int ac = 0;
|
|
1798 Widget label = 0;
|
|
1799
|
|
1800 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
|
1801 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1802 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1803 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1804 look ugly. I think this may be a LessTif bug but for now we just
|
|
1805 get rid of it. */
|
|
1806 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
|
1807
|
|
1808 /* add any args the user supplied for creation time */
|
|
1809 lw_add_value_args_to_args (val, al, &ac);
|
|
1810
|
|
1811 label = XmCreateLabel (parent, val->name, al, ac);
|
|
1812
|
|
1813 XtManageChild (label);
|
|
1814
|
|
1815 /* Do it again for arguments that have no effect until the widget is realized. */
|
|
1816 ac = 0;
|
|
1817 lw_add_value_args_to_args (val, al, &ac);
|
|
1818 XtSetValues (label, al, ac);
|
|
1819
|
|
1820 return label;
|
|
1821 }
|
|
1822
|
|
1823 #if XmVERSION > 1
|
|
1824 static Widget
|
|
1825 xm_create_combo_box (widget_instance *instance)
|
|
1826 {
|
|
1827 Arg al[20];
|
|
1828 int ac = 0;
|
|
1829 Widget combo = 0;
|
|
1830 widget_value* val = instance->info->val;
|
|
1831
|
|
1832 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
|
1833 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1834 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
1835 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1836 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1837 look ugly. I think this may be a LessTif bug but for now we just
|
|
1838 get rid of it. */
|
|
1839 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
|
1840
|
|
1841 /* add any args the user supplied for creation time */
|
|
1842 lw_add_value_args_to_args (val, al, &ac);
|
|
1843
|
|
1844 combo = XmCreateDropDownComboBox (instance->parent, val->name, al, ac);
|
|
1845 if (val->call_data)
|
|
1846 XtAddCallback (combo, XmNselectionCallback, xm_generic_callback,
|
|
1847 (XtPointer)instance);
|
|
1848
|
|
1849 XtManageChild (combo);
|
|
1850
|
|
1851 return combo;
|
|
1852 }
|
|
1853 #endif
|
|
1854 #endif /* LWLIB_WIDGETS_MOTIF */
|
|
1855
|
|
1856
|
|
1857 /* Table of functions to create widgets */
|
|
1858
|
450
|
1859 const widget_creation_entry
|
428
|
1860 xm_creation_table [] =
|
|
1861 {
|
|
1862 #ifdef LWLIB_MENUBARS_MOTIF
|
|
1863 {"menubar", make_menubar},
|
|
1864 {"popup", make_popup_menu},
|
|
1865 #endif
|
|
1866 #ifdef LWLIB_SCROLLBARS_MOTIF
|
|
1867 {"vertical-scrollbar", make_vertical_scrollbar},
|
|
1868 {"horizontal-scrollbar", make_horizontal_scrollbar},
|
|
1869 #endif
|
|
1870 #ifdef LWLIB_WIDGETS_MOTIF
|
|
1871 {"button", xm_create_button},
|
|
1872 {"progress", xm_create_progress},
|
|
1873 {"text-field", xm_create_text_field},
|
|
1874 {"label", xm_create_label_field},
|
|
1875 #if XmVERSION > 1
|
|
1876 {"combo-box", xm_create_combo_box},
|
|
1877 #endif
|
|
1878 #endif
|
|
1879 {NULL, NULL}
|
|
1880 };
|
|
1881
|
|
1882 /* Destruction of instances */
|
|
1883 void
|
2286
|
1884 xm_destroy_instance (
|
|
1885 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
|
1886 widget_instance* instance
|
|
1887 #else
|
|
1888 widget_instance* UNUSED (instance)
|
|
1889 #endif
|
|
1890 )
|
428
|
1891 {
|
|
1892 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
|
1893 /* It appears that this is used only for dialog boxes. */
|
|
1894 Widget widget = instance->widget;
|
|
1895 /* recycle the dialog boxes */
|
|
1896 /* Disable the recycling until we can find a way to have the dialog box
|
|
1897 get reasonable layout after we modify its contents. */
|
|
1898 if (0
|
|
1899 && XtClass (widget) == xmDialogShellWidgetClass)
|
|
1900 {
|
|
1901 destroyed_instance* dead_instance =
|
|
1902 make_destroyed_instance (instance->info->name,
|
|
1903 instance->info->type,
|
|
1904 instance->widget,
|
|
1905 instance->parent,
|
|
1906 instance->pop_up_p);
|
|
1907 dead_instance->next = all_destroyed_instances;
|
|
1908 all_destroyed_instances = dead_instance;
|
|
1909 XtUnmanageChild (first_child (instance->widget));
|
|
1910 XFlush (XtDisplay (instance->widget));
|
|
1911 XtAddCallback (instance->parent, XtNdestroyCallback,
|
|
1912 mark_dead_instance_destroyed, (XtPointer)dead_instance);
|
|
1913 }
|
|
1914 else
|
|
1915 {
|
|
1916 /* This might not be necessary now that the nosel is attached to
|
|
1917 popdown instead of destroy, but it can't hurt. */
|
|
1918 XtRemoveCallback (instance->widget, XtNdestroyCallback,
|
|
1919 xm_nosel_callback, (XtPointer)instance);
|
|
1920
|
|
1921 XtDestroyWidget (instance->widget);
|
|
1922 }
|
|
1923 #endif /* LWLIB_DIALOGS_MOTIF || LWLIB_WIDGETS_MOTIF */
|
|
1924 }
|
|
1925
|
|
1926 /* popup utility */
|
|
1927 #ifdef LWLIB_MENUBARS_MOTIF
|
|
1928
|
|
1929 void
|
|
1930 xm_popup_menu (Widget widget, XEvent *event)
|
|
1931 {
|
|
1932 if (event->type == ButtonPress || event->type == ButtonRelease)
|
|
1933 {
|
|
1934 /* This is so totally ridiculous: there's NO WAY to tell Motif
|
|
1935 that *any* button can select a menu item. Only one button
|
|
1936 can have that honor.
|
|
1937 */
|
|
1938 char *trans = 0;
|
|
1939 if (event->xbutton.state & Button5Mask) trans = "<Btn5Down>";
|
|
1940 else if (event->xbutton.state & Button4Mask) trans = "<Btn4Down>";
|
|
1941 else if (event->xbutton.state & Button3Mask) trans = "<Btn3Down>";
|
|
1942 else if (event->xbutton.state & Button2Mask) trans = "<Btn2Down>";
|
|
1943 else if (event->xbutton.state & Button1Mask) trans = "<Btn1Down>";
|
|
1944 if (trans)
|
|
1945 {
|
|
1946 Arg al [1];
|
|
1947 XtSetArg (al [0], XmNmenuPost, trans);
|
|
1948 XtSetValues (widget, al, 1);
|
|
1949 }
|
|
1950 XmMenuPosition (widget, (XButtonPressedEvent *) event);
|
|
1951 }
|
|
1952 XtManageChild (widget);
|
|
1953 }
|
|
1954
|
|
1955 #endif
|
|
1956
|
|
1957 #ifdef LWLIB_DIALOGS_MOTIF
|
|
1958
|
|
1959 static void
|
|
1960 set_min_dialog_size (Widget w)
|
|
1961 {
|
|
1962 short width;
|
|
1963 short height;
|
|
1964 Arg al [2];
|
|
1965
|
|
1966 XtSetArg (al [0], XmNwidth, &width);
|
|
1967 XtSetArg (al [1], XmNheight, &height);
|
|
1968 XtGetValues (w, al, 2);
|
|
1969
|
|
1970 XtSetArg (al [0], XmNminWidth, width);
|
|
1971 XtSetArg (al [1], XmNminHeight, height);
|
|
1972 XtSetValues (w, al, 2);
|
|
1973 }
|
|
1974
|
|
1975 #endif
|
|
1976
|
|
1977 void
|
|
1978 xm_pop_instance (widget_instance* instance, Boolean up)
|
|
1979 {
|
|
1980 Widget widget = instance->widget;
|
|
1981
|
|
1982 #ifdef LWLIB_DIALOGS_MOTIF
|
|
1983 if (XtClass (widget) == xmDialogShellWidgetClass)
|
|
1984 {
|
|
1985 Widget widget_to_manage = first_child (widget);
|
|
1986 if (up)
|
|
1987 {
|
|
1988 XtManageChild (widget_to_manage);
|
|
1989 set_min_dialog_size (widget);
|
|
1990 XmProcessTraversal(widget, XmTRAVERSE_CURRENT);
|
|
1991 }
|
|
1992 else
|
|
1993 XtUnmanageChild (widget_to_manage);
|
|
1994 }
|
|
1995 else
|
|
1996 #endif
|
|
1997 {
|
|
1998 if (up)
|
|
1999 XtManageChild (widget);
|
|
2000 else
|
|
2001 XtUnmanageChild (widget);
|
|
2002 }
|
|
2003 }
|
|
2004
|
|
2005
|
|
2006 /* motif callback */
|
|
2007
|
|
2008 enum do_call_type { pre_activate, selection, no_selection, post_activate };
|
|
2009
|
|
2010 static void
|
|
2011 do_call (Widget widget, XtPointer closure, enum do_call_type type)
|
|
2012 {
|
|
2013 XtPointer user_data;
|
|
2014 widget_instance* instance = (widget_instance*)closure;
|
|
2015 Widget instance_widget;
|
|
2016 LWLIB_ID id;
|
|
2017 Arg al [1];
|
|
2018
|
|
2019 if (!instance)
|
|
2020 return;
|
|
2021 if (widget->core.being_destroyed)
|
|
2022 return;
|
|
2023
|
|
2024 instance_widget = instance->widget;
|
|
2025 if (!instance_widget)
|
|
2026 return;
|
|
2027
|
|
2028 id = instance->info->id;
|
|
2029 user_data = NULL;
|
|
2030 XtSetArg(al [0], XmNuserData, &user_data);
|
|
2031 XtGetValues (widget, al, 1);
|
|
2032 switch (type)
|
|
2033 {
|
|
2034 case pre_activate:
|
|
2035 if (instance->info->pre_activate_cb)
|
|
2036 instance->info->pre_activate_cb (widget, id, user_data);
|
|
2037 break;
|
|
2038 case selection:
|
|
2039 if (instance->info->selection_cb)
|
|
2040 instance->info->selection_cb (widget, id, user_data);
|
|
2041 break;
|
|
2042 case no_selection:
|
|
2043 if (instance->info->selection_cb)
|
|
2044 instance->info->selection_cb (widget, id, (XtPointer) -1);
|
|
2045 break;
|
|
2046 case post_activate:
|
|
2047 if (instance->info->post_activate_cb)
|
|
2048 instance->info->post_activate_cb (widget, id, user_data);
|
|
2049 break;
|
|
2050 default:
|
|
2051 abort ();
|
|
2052 }
|
|
2053 }
|
|
2054
|
|
2055 /* Like lw_internal_update_other_instances except that it does not do
|
|
2056 anything if its shell parent is not managed. This is to protect
|
|
2057 lw_internal_update_other_instances to dereference freed memory
|
|
2058 if the widget was ``destroyed'' by caching it in the all_destroyed_instances
|
|
2059 list */
|
|
2060 static void
|
|
2061 xm_internal_update_other_instances (Widget widget, XtPointer closure,
|
|
2062 XtPointer call_data)
|
|
2063 {
|
|
2064 Widget parent;
|
|
2065 for (parent = widget; parent; parent = XtParent (parent))
|
|
2066 if (XtIsShell (parent))
|
|
2067 break;
|
|
2068 else if (!XtIsManaged (parent))
|
|
2069 return;
|
|
2070 lw_internal_update_other_instances (widget, closure, call_data);
|
|
2071 }
|
|
2072
|
|
2073 static void
|
|
2074 xm_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
2075 {
|
|
2076 #if (defined (LWLIB_MENUBARS_MOTIF) || defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF))
|
|
2077 /* We want the selected status to change only when we decide it
|
|
2078 should change. Yuck but correct. */
|
|
2079 if (XtClass (widget) == xmToggleButtonWidgetClass
|
|
2080 || XtClass (widget) == xmToggleButtonGadgetClass)
|
|
2081 {
|
|
2082 Boolean check;
|
|
2083 Arg al [1];
|
|
2084
|
|
2085 XtSetArg (al [0], XmNset, &check);
|
|
2086 XtGetValues (widget, al, 1);
|
|
2087
|
|
2088 XtSetArg (al [0], XmNset, !check);
|
|
2089 XtSetValues (widget, al, 1);
|
|
2090 }
|
|
2091 #endif
|
|
2092 lw_internal_update_other_instances (widget, closure, call_data);
|
|
2093 do_call (widget, closure, selection);
|
|
2094 }
|
|
2095
|
1261
|
2096 #if 0 /* Caller above is commented out */
|
428
|
2097 static void
|
|
2098 xm_pop_down_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
2099 {
|
|
2100 do_call (widget, closure, post_activate);
|
|
2101 }
|
1261
|
2102 #endif /* 0 */
|
428
|
2103
|
|
2104 #ifdef LWLIB_MENUBARS_MOTIF
|
|
2105
|
|
2106 static void
|
|
2107 xm_pull_down_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
2108 {
|
|
2109 #if 0
|
|
2110 if (call_data)
|
|
2111 {
|
|
2112 /* new behavior for incremental menu construction */
|
|
2113
|
|
2114 }
|
|
2115 else
|
|
2116 #endif
|
|
2117 do_call (widget, closure, pre_activate);
|
|
2118 }
|
|
2119
|
|
2120 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
2121
|
|
2122 #ifdef LWLIB_SCROLLBARS_MOTIF
|
|
2123 static void
|
|
2124 xm_scrollbar_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
2125 {
|
|
2126 widget_instance *instance = (widget_instance *) closure;
|
|
2127 LWLIB_ID id;
|
|
2128 XmScrollBarCallbackStruct *data =
|
|
2129 (XmScrollBarCallbackStruct *) call_data;
|
|
2130 scroll_event event_data;
|
|
2131 scrollbar_values *val =
|
|
2132 (scrollbar_values *) instance->info->val->scrollbar_data;
|
|
2133 double percent;
|
|
2134
|
|
2135 if (!instance || widget->core.being_destroyed)
|
|
2136 return;
|
|
2137
|
|
2138 id = instance->info->id;
|
|
2139
|
|
2140 percent = (double) (data->value - 1) / (double) (INT_MAX - 1);
|
|
2141 event_data.slider_value =
|
|
2142 (int) (percent * (double) (val->maximum - val->minimum)) + val->minimum;
|
|
2143
|
|
2144 if (event_data.slider_value > (val->maximum - val->slider_size))
|
|
2145 event_data.slider_value = val->maximum - val->slider_size;
|
|
2146 else if (event_data.slider_value < 1)
|
|
2147 event_data.slider_value = 1;
|
|
2148
|
|
2149 if (data->event)
|
|
2150 {
|
|
2151 switch (data->event->xany.type)
|
|
2152 {
|
|
2153 case KeyPress:
|
|
2154 case KeyRelease:
|
|
2155 event_data.time = data->event->xkey.time;
|
|
2156 break;
|
|
2157 case ButtonPress:
|
|
2158 case ButtonRelease:
|
|
2159 event_data.time = data->event->xbutton.time;
|
|
2160 break;
|
|
2161 case MotionNotify:
|
|
2162 event_data.time = data->event->xmotion.time;
|
|
2163 break;
|
|
2164 case EnterNotify:
|
|
2165 case LeaveNotify:
|
|
2166 event_data.time = data->event->xcrossing.time;
|
|
2167 break;
|
|
2168 default:
|
|
2169 event_data.time = 0;
|
|
2170 break;
|
|
2171 }
|
|
2172 }
|
|
2173 else
|
|
2174 event_data.time = 0;
|
|
2175
|
|
2176 switch (data->reason)
|
|
2177 {
|
|
2178 case XmCR_DECREMENT:
|
|
2179 event_data.action = SCROLLBAR_LINE_UP;
|
|
2180 break;
|
|
2181 case XmCR_INCREMENT:
|
|
2182 event_data.action = SCROLLBAR_LINE_DOWN;
|
|
2183 break;
|
|
2184 case XmCR_PAGE_DECREMENT:
|
|
2185 event_data.action = SCROLLBAR_PAGE_UP;
|
|
2186 break;
|
|
2187 case XmCR_PAGE_INCREMENT:
|
|
2188 event_data.action = SCROLLBAR_PAGE_DOWN;
|
|
2189 break;
|
|
2190 case XmCR_TO_TOP:
|
|
2191 event_data.action = SCROLLBAR_TOP;
|
|
2192 break;
|
|
2193 case XmCR_TO_BOTTOM:
|
|
2194 event_data.action = SCROLLBAR_BOTTOM;
|
|
2195 break;
|
|
2196 case XmCR_DRAG:
|
|
2197 event_data.action = SCROLLBAR_DRAG;
|
|
2198 break;
|
|
2199 case XmCR_VALUE_CHANGED:
|
|
2200 event_data.action = SCROLLBAR_CHANGE;
|
|
2201 break;
|
|
2202 default:
|
|
2203 event_data.action = SCROLLBAR_CHANGE;
|
|
2204 break;
|
|
2205 }
|
|
2206
|
|
2207 if (instance->info->pre_activate_cb)
|
|
2208 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
|
|
2209 }
|
|
2210 #endif /* LWLIB_SCROLLBARS_MOTIF */
|
|
2211
|
|
2212 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
|
2213 static void
|
2311
|
2214 mark_dead_instance_destroyed (Widget UNUSED (widget), XtPointer closure,
|
|
2215 XtPointer UNUSED (call_data))
|
428
|
2216 {
|
|
2217 destroyed_instance* instance = (destroyed_instance*)closure;
|
|
2218 instance->widget = NULL;
|
|
2219 }
|
|
2220
|
|
2221 static void
|
2311
|
2222 xm_nosel_callback (Widget widget, XtPointer closure,
|
|
2223 XtPointer UNUSED (call_data))
|
428
|
2224 {
|
|
2225 /* This callback is only called when a dialog box is dismissed with the wm's
|
|
2226 destroy button (WM_DELETE_WINDOW.) We want the dialog box to be destroyed
|
|
2227 in that case, not just unmapped, so that it releases its keyboard grabs.
|
|
2228 But there are problems with running our callbacks while the widget is in
|
|
2229 the process of being destroyed, so we set XmNdeleteResponse to XmUNMAP
|
|
2230 instead of XmDESTROY and then destroy it ourself after having run the
|
|
2231 callback.
|
|
2232 */
|
|
2233 do_call (widget, closure, no_selection);
|
|
2234 XtDestroyWidget (widget);
|
|
2235 }
|
|
2236 #endif
|
|
2237
|
|
2238
|
|
2239 /* set the keyboard focus */
|
|
2240 void
|
2286
|
2241 xm_set_keyboard_focus (Widget UNUSED (parent), Widget w)
|
428
|
2242 {
|
|
2243 XmProcessTraversal (w, XmTRAVERSE_CURRENT);
|
|
2244 /* At some point we believed that it was necessary to use XtSetKeyboardFocus
|
|
2245 instead of XmProcessTraversal when using Motif >= 1.2.1, but that's bogus.
|
|
2246 Presumably the problem was elsewhere, and is now gone...
|
|
2247 */
|
|
2248 }
|