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