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
|
|
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,
|
2286
|
342 widget_value* UNUSED (val))
|
428
|
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,
|
2286
|
831 widget_value* val,
|
|
832 #ifdef LWLIB_MENUBARS_MOTIF
|
|
833 Boolean deep_p
|
|
834 #else
|
|
835 Boolean UNUSED (deep_p)
|
|
836 #endif
|
|
837 )
|
428
|
838 {
|
1201
|
839 WidgetClass class_;
|
428
|
840 Arg al [20];
|
|
841 int ac = 0;
|
|
842
|
|
843 /* Mark as not edited */
|
|
844 val->edited = False;
|
|
845
|
|
846 /* Common to all widget types */
|
|
847 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
|
848 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
849 XtSetValues (widget, al, ac);
|
|
850
|
|
851 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
|
852 /* Common to all label like widgets */
|
903
|
853 xm_safe_update_label (instance, widget, val);
|
428
|
854 #endif
|
1201
|
855 class_ = XtClass (widget);
|
428
|
856 /* Class specific things */
|
1201
|
857 if (class_ == xmPushButtonWidgetClass ||
|
|
858 class_ == xmArrowButtonWidgetClass)
|
428
|
859 {
|
|
860 xm_update_pushbutton (instance, widget, val);
|
|
861 }
|
|
862 #ifdef LWLIB_MENUBARS_MOTIF
|
1201
|
863 else if (class_ == xmCascadeButtonWidgetClass)
|
428
|
864 {
|
|
865 xm_update_cascadebutton (instance, widget, val);
|
|
866 }
|
|
867 #endif
|
1201
|
868 else if (class_ == xmToggleButtonWidgetClass
|
|
869 || class_ == xmToggleButtonGadgetClass)
|
428
|
870 {
|
|
871 xm_update_toggle (instance, widget, val);
|
|
872 }
|
1201
|
873 else if (class_ == xmRowColumnWidgetClass)
|
428
|
874 {
|
|
875 Boolean radiobox = 0;
|
|
876
|
|
877 XtSetArg (al [0], XmNradioBehavior, &radiobox);
|
|
878 XtGetValues (widget, al, 1);
|
|
879
|
|
880 if (radiobox)
|
|
881 xm_update_radiobox (instance, widget, val);
|
|
882 #ifdef LWLIB_MENUBARS_MOTIF
|
|
883 else
|
|
884 xm_update_menu (instance, widget, val, deep_p);
|
|
885 #endif
|
|
886 }
|
1201
|
887 else if (class_ == xmTextWidgetClass)
|
428
|
888 {
|
|
889 xm_update_text (instance, widget, val);
|
|
890 }
|
1201
|
891 else if (class_ == xmTextFieldWidgetClass)
|
428
|
892 {
|
|
893 xm_update_text_field (instance, widget, val);
|
|
894 }
|
1201
|
895 else if (class_ == xmListWidgetClass)
|
428
|
896 {
|
|
897 xm_update_list (instance, widget, val);
|
|
898 }
|
|
899 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
1201
|
900 else if (class_ == xmComboBoxWidgetClass)
|
428
|
901 {
|
|
902 xm_update_combo_box (instance, widget, val);
|
|
903 }
|
|
904 #endif
|
|
905 #ifdef LWLIB_SCROLLBARS_MOTIF
|
1201
|
906 else if (class_ == xmScrollBarWidgetClass)
|
428
|
907 {
|
|
908 xm_update_scrollbar (instance, widget, val);
|
|
909 }
|
|
910 #endif
|
1458
|
911 #ifdef LWLIB_WIDGETS_MOTIF
|
1201
|
912 else if (class_ == xmScaleWidgetClass)
|
639
|
913 {
|
|
914 xm_update_progress (instance, widget, val);
|
|
915 }
|
1458
|
916 #endif
|
442
|
917 /* Lastly update our global arg values. */
|
|
918 if (val->args && val->args->nargs)
|
|
919 XtSetValues (widget, val->args->args, val->args->nargs);
|
428
|
920 }
|
|
921
|
|
922 /* getting the value back */
|
|
923 void
|
|
924 xm_update_one_value (widget_instance* instance, Widget widget,
|
|
925 widget_value* val)
|
|
926 {
|
1201
|
927 WidgetClass class_ = XtClass (widget);
|
428
|
928 widget_value *old_wv;
|
|
929
|
|
930 /* copy the call_data slot into the "return" widget_value */
|
|
931 for (old_wv = instance->info->val->contents; old_wv; old_wv = old_wv->next)
|
|
932 if (!strcmp (val->name, old_wv->name))
|
|
933 {
|
|
934 val->call_data = old_wv->call_data;
|
|
935 break;
|
|
936 }
|
|
937
|
1201
|
938 if (class_ == xmToggleButtonWidgetClass || class_ == xmToggleButtonGadgetClass)
|
428
|
939 {
|
|
940 Arg al [1];
|
|
941 XtSetArg (al [0], XmNset, &val->selected);
|
|
942 XtGetValues (widget, al, 1);
|
|
943 val->edited = True;
|
|
944 }
|
1201
|
945 else if (class_ == xmTextWidgetClass)
|
428
|
946 {
|
|
947 if (val->value)
|
458
|
948 XtFree (val->value);
|
428
|
949 val->value = XmTextGetString (widget);
|
|
950 val->edited = True;
|
|
951 }
|
1201
|
952 else if (class_ == xmTextFieldWidgetClass)
|
428
|
953 {
|
|
954 if (val->value)
|
458
|
955 XtFree (val->value);
|
428
|
956 val->value = XmTextFieldGetString (widget);
|
|
957 val->edited = True;
|
|
958 }
|
1201
|
959 else if (class_ == xmRowColumnWidgetClass)
|
428
|
960 {
|
|
961 Boolean radiobox = 0;
|
|
962 {
|
|
963 Arg al [1];
|
|
964 XtSetArg (al [0], XmNradioBehavior, &radiobox);
|
|
965 XtGetValues (widget, al, 1);
|
|
966 }
|
|
967
|
|
968 if (radiobox)
|
|
969 {
|
|
970 CompositeWidget radio = (CompositeWidget)widget;
|
639
|
971 unsigned int i;
|
428
|
972 for (i = 0; i < radio->composite.num_children; i++)
|
|
973 {
|
|
974 int set = False;
|
|
975 Widget toggle = radio->composite.children [i];
|
|
976 Arg al [1];
|
|
977
|
|
978 XtSetArg (al [0], XmNset, &set);
|
|
979 XtGetValues (toggle, al, 1);
|
|
980 if (set)
|
|
981 {
|
|
982 if (val->value)
|
|
983 free (val->value);
|
|
984 val->value = safe_strdup (XtName (toggle));
|
|
985 }
|
|
986 }
|
|
987 val->edited = True;
|
|
988 }
|
|
989 }
|
1201
|
990 else if (class_ == xmListWidgetClass
|
428
|
991 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
1201
|
992 || class_ == xmComboBoxWidgetClass
|
428
|
993 #endif
|
|
994 )
|
|
995 {
|
|
996 int pos_cnt;
|
|
997 int* pos_list;
|
|
998 Widget list = widget;
|
|
999 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
1201
|
1000 if (class_ == xmComboBoxWidgetClass)
|
428
|
1001 list = CB_List (widget);
|
|
1002 #endif
|
|
1003 if (XmListGetSelectedPos (list, &pos_list, &pos_cnt))
|
|
1004 {
|
|
1005 int i;
|
|
1006 widget_value* cur;
|
|
1007 for (cur = val->contents, i = 0; cur; cur = cur->next)
|
|
1008 if (cur->value)
|
|
1009 {
|
|
1010 int j;
|
|
1011 cur->selected = False;
|
|
1012 i += 1;
|
|
1013 for (j = 0; j < pos_cnt; j++)
|
|
1014 if (pos_list [j] == i)
|
|
1015 {
|
|
1016 cur->selected = True;
|
|
1017 val->value = safe_strdup (cur->name);
|
|
1018 }
|
|
1019 }
|
|
1020 val->edited = 1;
|
|
1021 XtFree ((char *) pos_list);
|
|
1022 }
|
|
1023 }
|
|
1024 #ifdef LWLIB_SCROLLBARS_MOTIF
|
1201
|
1025 else if (class_ == xmScrollBarWidgetClass)
|
428
|
1026 {
|
|
1027 /* This function is not used by the scrollbar. */
|
|
1028 return;
|
|
1029 }
|
|
1030 #endif
|
|
1031 }
|
|
1032
|
|
1033
|
1330
|
1034 #ifdef LWLIB_DIALOGS_MOTIF
|
|
1035
|
428
|
1036 /* This function is for activating a button from a program. It's wrong because
|
|
1037 we pass a NULL argument in the call_data which is not Motif compatible.
|
|
1038 This is used from the XmNdefaultAction callback of the List widgets to
|
|
1039 have a double-click put down a dialog box like the button would do.
|
|
1040 I could not find a way to do that with accelerators.
|
|
1041 */
|
|
1042 static void
|
|
1043 activate_button (Widget widget, XtPointer closure, XtPointer call_data)
|
|
1044 {
|
|
1045 Widget button = (Widget)closure;
|
|
1046 XtCallCallbacks (button, XmNactivateCallback, NULL);
|
|
1047 }
|
|
1048
|
|
1049 /* creation functions */
|
|
1050
|
|
1051 /* dialogs */
|
|
1052
|
|
1053 #if (XmVersion >= 1002)
|
|
1054 # define ARMANDACTIVATE_KLUDGE
|
|
1055 # define DND_KLUDGE
|
|
1056 #endif
|
|
1057
|
|
1058 #ifdef ARMANDACTIVATE_KLUDGE
|
|
1059 /* We want typing Return at a dialog box to select the default button; but
|
|
1060 we're satisfied with having it select the leftmost button instead.
|
|
1061
|
|
1062 In Motif 1.1.5 we could do this by putting this resource in the
|
|
1063 app-defaults file:
|
|
1064
|
|
1065 *dialog*button1.accelerators:#override\
|
|
1066 <KeyPress>Return: ArmAndActivate()\n\
|
|
1067 <KeyPress>KP_Enter: ArmAndActivate()\n\
|
|
1068 Ctrl<KeyPress>m: ArmAndActivate()\n
|
|
1069
|
|
1070 but that doesn't work with 1.2.1 and I don't understand why. However,
|
|
1071 doing the equivalent C code does work, with the notable disadvantage that
|
|
1072 the user can't override it. So that's what we do until we figure out
|
|
1073 something better....
|
|
1074 */
|
|
1075 static char button_trans[] = "\
|
|
1076 <KeyPress>Return: ArmAndActivate()\n\
|
|
1077 <KeyPress>KP_Enter: ArmAndActivate()\n\
|
|
1078 Ctrl<KeyPress>m: ArmAndActivate()\n";
|
|
1079
|
|
1080 #endif /* ARMANDACTIVATE_KLUDGE */
|
|
1081
|
|
1082
|
|
1083 #ifdef DND_KLUDGE
|
|
1084 /* This is a kludge to disable drag-and-drop in dialog boxes. The symptom
|
|
1085 was a segv down in libXm somewhere if you used the middle button on a
|
|
1086 dialog box to begin a drag; when you released the button to make a drop
|
|
1087 things would lose if you were not over the button where you started the
|
|
1088 drag (canceling the operation). This was probably due to the fact that
|
|
1089 the dialog boxes were not set up to handle a drag but were trying to do
|
|
1090 so anyway for some reason.
|
|
1091
|
|
1092 So we disable drag-and-drop in dialog boxes by turning off the binding for
|
|
1093 Btn2Down which, by default, initiates a drag. Clearly this is a shitty
|
|
1094 solution as it only works in default configurations, but...
|
|
1095 */
|
|
1096 static char disable_dnd_trans[] = "<Btn2Down>: ";
|
|
1097 #endif /* DND_KLUDGE */
|
|
1098
|
|
1099
|
|
1100 static Widget
|
|
1101 make_dialog (char* name, Widget parent, Boolean pop_up_p,
|
442
|
1102 const char* shell_title, const char* icon_name,
|
428
|
1103 Boolean text_input_slot, Boolean radio_box, Boolean list,
|
|
1104 int left_buttons, int right_buttons)
|
|
1105 {
|
|
1106 Widget result;
|
|
1107 Widget form;
|
|
1108 Widget row;
|
|
1109 Widget icon;
|
|
1110 Widget icon_separator;
|
|
1111 Widget message;
|
|
1112 Widget value = 0;
|
|
1113 Widget separator;
|
|
1114 Widget button = 0;
|
|
1115 Widget children [16]; /* for the final XtManageChildren */
|
|
1116 int n_children;
|
|
1117 Arg al[64]; /* Arg List */
|
|
1118 int ac; /* Arg Count */
|
|
1119 int i;
|
|
1120
|
|
1121 #ifdef DND_KLUDGE
|
|
1122 XtTranslations dnd_override = XtParseTranslationTable (disable_dnd_trans);
|
|
1123 # define DO_DND_KLUDGE(widget) XtOverrideTranslations ((widget), dnd_override)
|
|
1124 #else /* ! DND_KLUDGE */
|
|
1125 # define DO_DND_KLUDGE(widget)
|
|
1126 #endif /* ! DND_KLUDGE */
|
|
1127
|
|
1128 if (pop_up_p)
|
|
1129 {
|
|
1130 ac = 0;
|
|
1131 XtSetArg(al[ac], XmNtitle, shell_title); ac++;
|
|
1132 XtSetArg(al[ac], XtNallowShellResize, True); ac++;
|
|
1133 XtSetArg(al[ac], XmNdeleteResponse, XmUNMAP); ac++;
|
|
1134 result = XmCreateDialogShell (parent, "dialog", al, ac);
|
|
1135
|
|
1136 XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
|
|
1137 /* XtSetArg(al[ac], XmNautoUnmanage, TRUE); ac++; */ /* ####is this ok? */
|
|
1138 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
|
|
1139 form = XmCreateForm (result, (char *) shell_title, al, ac);
|
|
1140 }
|
|
1141 else
|
|
1142 {
|
|
1143 ac = 0;
|
|
1144 XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
|
|
1145 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
|
|
1146 form = XmCreateForm (parent, (char *) shell_title, al, ac);
|
|
1147 result = form;
|
|
1148 }
|
|
1149
|
|
1150 ac = 0;
|
|
1151 XtSetArg(al[ac], XmNpacking, XmPACK_COLUMN); ac++;
|
|
1152 XtSetArg(al[ac], XmNorientation, XmVERTICAL); ac++;
|
|
1153 XtSetArg(al[ac], XmNnumColumns, left_buttons + right_buttons + 1); ac++;
|
|
1154 XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
|
|
1155 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
|
|
1156 XtSetArg(al[ac], XmNspacing, 13); ac++;
|
|
1157 XtSetArg(al[ac], XmNadjustLast, False); ac++;
|
|
1158 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
|
|
1159 XtSetArg(al[ac], XmNisAligned, True); ac++;
|
|
1160 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
|
|
1161 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
|
|
1162 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1163 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
|
|
1164 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1165 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1166 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1167 row = XmCreateRowColumn (form, "row", al, ac);
|
|
1168
|
|
1169 n_children = 0;
|
|
1170 for (i = 0; i < left_buttons; i++)
|
|
1171 {
|
|
1172 char button_name [16];
|
|
1173 sprintf (button_name, "button%d", i + 1);
|
|
1174 ac = 0;
|
|
1175 if (i == 0)
|
|
1176 {
|
|
1177 XtSetArg(al[ac], XmNhighlightThickness, 1); ac++;
|
|
1178 XtSetArg(al[ac], XmNshowAsDefault, TRUE); ac++;
|
|
1179 }
|
|
1180 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
|
|
1181 children [n_children] = XmCreatePushButton (row, button_name, al, ac);
|
|
1182 DO_DND_KLUDGE (children [n_children]);
|
|
1183
|
|
1184 if (i == 0)
|
|
1185 {
|
|
1186 button = children [n_children];
|
|
1187 ac = 0;
|
|
1188 XtSetArg(al[ac], XmNdefaultButton, button); ac++;
|
|
1189 XtSetValues (row, al, ac);
|
|
1190
|
|
1191 #ifdef ARMANDACTIVATE_KLUDGE /* See comment above */
|
|
1192 {
|
|
1193 XtTranslations losers = XtParseTranslationTable (button_trans);
|
|
1194 XtOverrideTranslations (button, losers);
|
|
1195 XtFree ((char *) losers);
|
|
1196 }
|
|
1197 #endif /* ARMANDACTIVATE_KLUDGE */
|
|
1198 }
|
|
1199
|
|
1200 n_children++;
|
|
1201 }
|
|
1202
|
442
|
1203 /* invisible separator button */
|
428
|
1204 ac = 0;
|
|
1205 XtSetArg (al[ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1206 children [n_children] = XmCreateLabel (row, "separator_button",
|
|
1207 al, ac);
|
|
1208 DO_DND_KLUDGE (children [n_children]);
|
|
1209 n_children++;
|
|
1210
|
|
1211 for (i = 0; i < right_buttons; i++)
|
|
1212 {
|
|
1213 char button_name [16];
|
|
1214 sprintf (button_name, "button%d", left_buttons + i + 1);
|
|
1215 ac = 0;
|
|
1216 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
|
|
1217 children [n_children] = XmCreatePushButton (row, button_name, al, ac);
|
|
1218 DO_DND_KLUDGE (children [n_children]);
|
|
1219 if (! button) button = children [n_children];
|
|
1220 n_children++;
|
|
1221 }
|
|
1222
|
|
1223 XtManageChildren (children, n_children);
|
|
1224
|
|
1225 ac = 0;
|
|
1226 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
|
|
1227 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1228 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1229 XtSetArg(al[ac], XmNbottomWidget, row); ac++;
|
|
1230 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
|
|
1231 XtSetArg(al[ac], XmNleftOffset, 0); ac++;
|
|
1232 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1233 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
|
|
1234 separator = XmCreateSeparator (form, "", al, ac);
|
|
1235
|
|
1236 ac = 0;
|
|
1237 XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++;
|
|
1238 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
|
|
1239 XtSetArg(al[ac], XmNtopOffset, 13); ac++;
|
|
1240 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
|
|
1241 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
|
|
1242 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1243 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_NONE); ac++;
|
|
1244 icon = XmCreateLabel (form, (char *) icon_name, al, ac);
|
|
1245 DO_DND_KLUDGE (icon);
|
|
1246
|
|
1247 ac = 0;
|
|
1248 XtSetArg(al[ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1249 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
|
|
1250 XtSetArg(al[ac], XmNtopOffset, 6); ac++;
|
|
1251 XtSetArg(al[ac], XmNtopWidget, icon); ac++;
|
|
1252 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1253 XtSetArg(al[ac], XmNbottomOffset, 6); ac++;
|
|
1254 XtSetArg(al[ac], XmNbottomWidget, separator); ac++;
|
|
1255 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_NONE); ac++;
|
|
1256 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_NONE); ac++;
|
|
1257 icon_separator = XmCreateLabel (form, "", al, ac);
|
|
1258 DO_DND_KLUDGE (icon_separator);
|
|
1259
|
|
1260 if (text_input_slot)
|
|
1261 {
|
|
1262 ac = 0;
|
|
1263 XtSetArg(al[ac], XmNcolumns, 50); ac++;
|
|
1264 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
|
|
1265 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1266 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1267 XtSetArg(al[ac], XmNbottomWidget, separator); ac++;
|
|
1268 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1269 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1270 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1271 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1272 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1273 value = XmCreateTextField (form, "value", al, ac);
|
|
1274 DO_DND_KLUDGE (value);
|
|
1275 }
|
|
1276 else if (radio_box)
|
|
1277 {
|
|
1278 Widget radio_butt;
|
|
1279 ac = 0;
|
|
1280 XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
|
|
1281 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
|
|
1282 XtSetArg(al[ac], XmNspacing, 13); ac++;
|
|
1283 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
|
|
1284 XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
|
|
1285 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1286 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1287 XtSetArg(al[ac], XmNbottomWidget, separator); ac++;
|
|
1288 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1289 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1290 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1291 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1292 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1293 value = XmCreateRadioBox (form, "radiobutton1", al, ac);
|
|
1294 ac = 0;
|
|
1295 i = 0;
|
|
1296 radio_butt = XmCreateToggleButtonGadget (value, "radio1", al, ac);
|
|
1297 children [i++] = radio_butt;
|
|
1298 radio_butt = XmCreateToggleButtonGadget (value, "radio2", al, ac);
|
|
1299 children [i++] = radio_butt;
|
|
1300 radio_butt = XmCreateToggleButtonGadget (value, "radio3", al, ac);
|
|
1301 children [i++] = radio_butt;
|
|
1302 XtManageChildren (children, i);
|
|
1303 }
|
|
1304 else if (list)
|
|
1305 {
|
|
1306 ac = 0;
|
|
1307 XtSetArg(al[ac], XmNvisibleItemCount, 5); ac++;
|
|
1308 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
|
|
1309 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1310 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1311 XtSetArg(al[ac], XmNbottomWidget, separator); ac++;
|
|
1312 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1313 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1314 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1315 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1316 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1317 value = XmCreateScrolledList (form, "list", al, ac);
|
|
1318
|
442
|
1319 /* this is the easiest way I found to have the double click in the
|
428
|
1320 list activate the default button */
|
|
1321 XtAddCallback (value, XmNdefaultActionCallback, activate_button, button);
|
|
1322 }
|
805
|
1323 /* else add nothing; it's a separator */
|
428
|
1324
|
|
1325 ac = 0;
|
|
1326 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1327 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
|
|
1328 XtSetArg(al[ac], XmNtopOffset, 13); ac++;
|
|
1329 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1330 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1331 XtSetArg(al[ac], XmNbottomWidget,
|
|
1332 text_input_slot || radio_box || list ? value : separator); ac++;
|
|
1333 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1334 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1335 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1336 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1337 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1338 message = XmCreateLabel (form, "message", al, ac);
|
|
1339 DO_DND_KLUDGE (message);
|
|
1340
|
|
1341 if (list)
|
|
1342 XtManageChild (value);
|
|
1343
|
|
1344 i = 0;
|
|
1345 children [i] = row; i++;
|
|
1346 children [i] = separator; i++;
|
|
1347 if (text_input_slot || radio_box)
|
|
1348 {
|
|
1349 children [i] = value; i++;
|
|
1350 }
|
|
1351 children [i] = message; i++;
|
|
1352 children [i] = icon; i++;
|
|
1353 children [i] = icon_separator; i++;
|
|
1354 XtManageChildren (children, i);
|
|
1355
|
|
1356 if (text_input_slot || list)
|
|
1357 {
|
|
1358 XtInstallAccelerators (value, button);
|
|
1359 XmProcessTraversal(value, XmTRAVERSE_CURRENT);
|
|
1360 }
|
805
|
1361 else if (radio_box)
|
428
|
1362 {
|
|
1363 XtInstallAccelerators (form, button);
|
|
1364 XmProcessTraversal(value, XmTRAVERSE_CURRENT);
|
|
1365 }
|
805
|
1366 /* else we don' need no STEENKIN' assellerators. */
|
428
|
1367
|
|
1368 #ifdef DND_KLUDGE
|
|
1369 XtFree ((char *) dnd_override);
|
|
1370 #endif
|
|
1371 #undef DO_DND_KLUDGE
|
|
1372
|
|
1373 return result;
|
|
1374 }
|
|
1375
|
|
1376 static destroyed_instance*
|
|
1377 find_matching_instance (widget_instance* instance)
|
|
1378 {
|
|
1379 destroyed_instance* cur;
|
|
1380 destroyed_instance* prev;
|
|
1381 char* type = instance->info->type;
|
|
1382 char* name = instance->info->name;
|
|
1383
|
|
1384 for (prev = NULL, cur = all_destroyed_instances;
|
|
1385 cur;
|
|
1386 prev = cur, cur = cur->next)
|
|
1387 {
|
|
1388 if (!strcmp (cur->name, name)
|
|
1389 && !strcmp (cur->type, type)
|
|
1390 && cur->parent == instance->parent
|
|
1391 && cur->pop_up_p == instance->pop_up_p)
|
|
1392 {
|
|
1393 if (prev)
|
|
1394 prev->next = cur->next;
|
|
1395 else
|
|
1396 all_destroyed_instances = cur->next;
|
|
1397 return cur;
|
|
1398 }
|
|
1399 /* do some cleanup */
|
|
1400 else if (!cur->widget)
|
|
1401 {
|
|
1402 if (prev)
|
|
1403 prev->next = cur->next;
|
|
1404 else
|
|
1405 all_destroyed_instances = cur->next;
|
|
1406 free_destroyed_instance (cur);
|
|
1407 cur = prev ? prev : all_destroyed_instances;
|
|
1408 }
|
|
1409 }
|
|
1410 return NULL;
|
|
1411 }
|
|
1412
|
|
1413 static void
|
|
1414 recenter_widget (Widget widget)
|
|
1415 {
|
|
1416 Widget parent = XtParent (widget);
|
|
1417 Screen* screen = XtScreen (widget);
|
|
1418 Dimension screen_width = WidthOfScreen (screen);
|
|
1419 Dimension screen_height = HeightOfScreen (screen);
|
|
1420 Dimension parent_width = 0;
|
|
1421 Dimension parent_height = 0;
|
|
1422 Dimension child_width = 0;
|
|
1423 Dimension child_height = 0;
|
|
1424 Position x;
|
|
1425 Position y;
|
|
1426 Arg al [2];
|
|
1427
|
|
1428 XtSetArg (al [0], XtNwidth, &child_width);
|
|
1429 XtSetArg (al [1], XtNheight, &child_height);
|
|
1430 XtGetValues (widget, al, 2);
|
|
1431
|
|
1432 XtSetArg (al [0], XtNwidth, &parent_width);
|
|
1433 XtSetArg (al [1], XtNheight, &parent_height);
|
|
1434 XtGetValues (parent, al, 2);
|
|
1435
|
|
1436 x = (Position) ((parent_width - child_width) / 2);
|
|
1437 y = (Position) ((parent_height - child_height) / 2);
|
|
1438
|
|
1439 XtTranslateCoords (parent, x, y, &x, &y);
|
|
1440
|
|
1441 if ((Dimension) (x + child_width) > screen_width)
|
|
1442 x = screen_width - child_width;
|
|
1443 if (x < 0)
|
|
1444 x = 0;
|
|
1445
|
|
1446 if ((Dimension) (y + child_height) > screen_height)
|
|
1447 y = screen_height - child_height;
|
|
1448 if (y < 0)
|
|
1449 y = 0;
|
|
1450
|
|
1451 XtSetArg (al [0], XtNx, x);
|
|
1452 XtSetArg (al [1], XtNy, y);
|
|
1453 XtSetValues (widget, al, 2);
|
|
1454 }
|
|
1455
|
|
1456 static Widget
|
|
1457 recycle_instance (destroyed_instance* instance)
|
|
1458 {
|
|
1459 Widget widget = instance->widget;
|
|
1460
|
|
1461 /* widget is NULL if the parent was destroyed. */
|
|
1462 if (widget)
|
|
1463 {
|
|
1464 Widget focus;
|
|
1465 Widget separator;
|
|
1466
|
|
1467 /* Remove the destroy callback as the instance is not in the list
|
|
1468 anymore */
|
|
1469 XtRemoveCallback (instance->parent, XtNdestroyCallback,
|
|
1470 mark_dead_instance_destroyed,
|
|
1471 (XtPointer)instance);
|
|
1472
|
|
1473 /* Give the focus to the initial item */
|
|
1474 focus = XtNameToWidget (widget, "*value");
|
|
1475 if (!focus)
|
|
1476 focus = XtNameToWidget (widget, "*button1");
|
|
1477 if (focus)
|
|
1478 XmProcessTraversal(focus, XmTRAVERSE_CURRENT);
|
|
1479
|
|
1480 /* shrink the separator label back to their original size */
|
|
1481 separator = XtNameToWidget (widget, "*separator_button");
|
|
1482 if (separator)
|
|
1483 {
|
|
1484 Arg al [2];
|
|
1485 XtSetArg (al [0], XtNwidth, 5);
|
|
1486 XtSetArg (al [1], XtNheight, 5);
|
|
1487 XtSetValues (separator, al, 2);
|
|
1488 }
|
|
1489
|
|
1490 /* Center the dialog in its parent */
|
|
1491 recenter_widget (widget);
|
|
1492 }
|
|
1493 free_destroyed_instance (instance);
|
|
1494 return widget;
|
|
1495 }
|
|
1496
|
|
1497 Widget
|
|
1498 xm_create_dialog (widget_instance* instance)
|
|
1499 {
|
|
1500 char* name = instance->info->type;
|
|
1501 Widget parent = instance->parent;
|
|
1502 Widget widget;
|
|
1503 Boolean pop_up_p = instance->pop_up_p;
|
442
|
1504 const char* shell_name = 0;
|
|
1505 const char* icon_name = 0;
|
428
|
1506 Boolean text_input_slot = False;
|
|
1507 Boolean radio_box = False;
|
|
1508 Boolean list = False;
|
|
1509 int total_buttons;
|
|
1510 int left_buttons = 0;
|
|
1511 int right_buttons = 1;
|
|
1512 destroyed_instance* dead_one;
|
|
1513
|
|
1514 /* try to find a widget to recycle */
|
|
1515 dead_one = find_matching_instance (instance);
|
|
1516 if (dead_one)
|
|
1517 {
|
|
1518 Widget recycled_widget = recycle_instance (dead_one);
|
|
1519 if (recycled_widget)
|
|
1520 return recycled_widget;
|
|
1521 }
|
|
1522
|
|
1523 switch (name [0]){
|
|
1524 case 'E': case 'e':
|
|
1525 icon_name = "dbox-error";
|
|
1526 shell_name = "Error";
|
|
1527 break;
|
|
1528
|
|
1529 case 'I': case 'i':
|
|
1530 icon_name = "dbox-info";
|
|
1531 shell_name = "Information";
|
|
1532 break;
|
|
1533
|
|
1534 case 'L': case 'l':
|
|
1535 list = True;
|
|
1536 icon_name = "dbox-question";
|
|
1537 shell_name = "Prompt";
|
|
1538 break;
|
|
1539
|
|
1540 case 'P': case 'p':
|
|
1541 text_input_slot = True;
|
|
1542 icon_name = "dbox-question";
|
|
1543 shell_name = "Prompt";
|
|
1544 break;
|
|
1545
|
|
1546 case 'Q': case 'q':
|
|
1547 icon_name = "dbox-question";
|
|
1548 shell_name = "Question";
|
|
1549 break;
|
|
1550 }
|
|
1551
|
|
1552 total_buttons = name [1] - '0';
|
|
1553
|
|
1554 if (name [3] == 'T' || name [3] == 't')
|
|
1555 {
|
|
1556 text_input_slot = False;
|
|
1557 radio_box = True;
|
|
1558 }
|
|
1559 else if (name [3])
|
|
1560 right_buttons = name [4] - '0';
|
|
1561
|
|
1562 left_buttons = total_buttons - right_buttons;
|
|
1563
|
|
1564 widget = make_dialog (name, parent, pop_up_p,
|
|
1565 shell_name, icon_name, text_input_slot, radio_box,
|
|
1566 list, left_buttons, right_buttons);
|
|
1567
|
|
1568 XtAddCallback (widget, XmNpopdownCallback, xm_nosel_callback,
|
|
1569 (XtPointer) instance);
|
|
1570 return widget;
|
|
1571 }
|
|
1572
|
|
1573 #endif /* LWLIB_DIALOGS_MOTIF */
|
|
1574
|
|
1575 #ifdef LWLIB_MENUBARS_MOTIF
|
|
1576 static Widget
|
|
1577 make_menubar (widget_instance* instance)
|
|
1578 {
|
|
1579 Arg al[10];
|
|
1580 int ac = 0;
|
|
1581
|
|
1582 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
|
|
1583 XtSetArg(al[ac], XmNshadowThickness, 3); ac++;
|
|
1584
|
|
1585 return XmCreateMenuBar (instance->parent, instance->info->name, al, ac);
|
|
1586 }
|
|
1587
|
|
1588 static void
|
|
1589 remove_grabs (Widget shell, XtPointer closure, XtPointer call_data)
|
|
1590 {
|
|
1591 Widget menu = (Widget) closure;
|
|
1592 XmRemoveFromPostFromList (menu, XtParent (XtParent ((Widget) menu)));
|
|
1593 }
|
|
1594
|
|
1595 static Widget
|
|
1596 make_popup_menu (widget_instance* instance)
|
|
1597 {
|
|
1598 Widget parent = instance->parent;
|
|
1599 Window parent_window = parent->core.window;
|
|
1600 Widget result;
|
|
1601
|
|
1602 /* sets the parent window to 0 to fool Motif into not generating a grab */
|
|
1603 parent->core.window = 0;
|
|
1604 result = XmCreatePopupMenu (parent, instance->info->name, NULL, 0);
|
|
1605 XtAddCallback (XtParent (result), XmNpopdownCallback, remove_grabs,
|
|
1606 (XtPointer)result);
|
|
1607 parent->core.window = parent_window;
|
|
1608 return result;
|
|
1609 }
|
|
1610 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
1611
|
|
1612 #ifdef LWLIB_SCROLLBARS_MOTIF
|
|
1613 static Widget
|
|
1614 make_scrollbar (widget_instance *instance, int vertical)
|
|
1615 {
|
|
1616 Arg al[20];
|
|
1617 int ac = 0;
|
|
1618 static XtCallbackRec callbacks[2] =
|
|
1619 { {xm_scrollbar_callback, NULL}, {NULL, NULL} };
|
|
1620
|
|
1621 callbacks[0].closure = (XtPointer) instance;
|
|
1622
|
|
1623 XtSetArg (al[ac], XmNminimum, 1); ac++;
|
|
1624 XtSetArg (al[ac], XmNmaximum, INT_MAX); ac++;
|
|
1625 XtSetArg (al[ac], XmNincrement, 1); ac++;
|
|
1626 XtSetArg (al[ac], XmNpageIncrement, 1); ac++;
|
|
1627 XtSetArg (al[ac], XmNborderWidth, 0); ac++;
|
|
1628 XtSetArg (al[ac], XmNorientation, vertical ? XmVERTICAL : XmHORIZONTAL); ac++;
|
|
1629
|
|
1630 XtSetArg (al[ac], XmNdecrementCallback, callbacks); ac++;
|
|
1631 XtSetArg (al[ac], XmNdragCallback, callbacks); ac++;
|
|
1632 XtSetArg (al[ac], XmNincrementCallback, callbacks); ac++;
|
|
1633 XtSetArg (al[ac], XmNpageDecrementCallback, callbacks); ac++;
|
|
1634 XtSetArg (al[ac], XmNpageIncrementCallback, callbacks); ac++;
|
|
1635 XtSetArg (al[ac], XmNtoBottomCallback, callbacks); ac++;
|
|
1636 XtSetArg (al[ac], XmNtoTopCallback, callbacks); ac++;
|
|
1637 XtSetArg (al[ac], XmNvalueChangedCallback, callbacks); ac++;
|
|
1638
|
|
1639 return XmCreateScrollBar (instance->parent, instance->info->name, al, ac);
|
|
1640 }
|
|
1641
|
|
1642 static Widget
|
|
1643 make_vertical_scrollbar (widget_instance *instance)
|
|
1644 {
|
|
1645 return make_scrollbar (instance, 1);
|
|
1646 }
|
|
1647
|
|
1648 static Widget
|
|
1649 make_horizontal_scrollbar (widget_instance *instance)
|
|
1650 {
|
|
1651 return make_scrollbar (instance, 0);
|
|
1652 }
|
|
1653
|
|
1654 #endif /* LWLIB_SCROLLBARS_MOTIF */
|
|
1655
|
|
1656 #ifdef LWLIB_WIDGETS_MOTIF
|
|
1657 /* glyph widgets */
|
|
1658 static Widget
|
|
1659 xm_create_button (widget_instance *instance)
|
|
1660 {
|
|
1661 Arg al[20];
|
|
1662 int ac = 0;
|
|
1663 Widget button = 0;
|
|
1664 widget_value* val = instance->info->val;
|
|
1665
|
|
1666 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
|
1667 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1668 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
1669 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1670 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1671 look ugly. I think this may be a LessTif bug but for now we just
|
|
1672 get rid of it. */
|
|
1673 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
|
1674
|
|
1675 /* add any args the user supplied for creation time */
|
|
1676 lw_add_value_args_to_args (val, al, &ac);
|
|
1677
|
|
1678 if (!val->call_data)
|
|
1679 button = XmCreateLabel (instance->parent, val->name, al, ac);
|
|
1680
|
|
1681 else if (val->type == TOGGLE_TYPE || val->type == RADIO_TYPE)
|
|
1682 {
|
|
1683 XtSetArg (al [ac], XmNset, val->selected); ac++;
|
|
1684 XtSetArg (al [ac], XmNindicatorType,
|
|
1685 (val->type == TOGGLE_TYPE ?
|
|
1686 XmN_OF_MANY : XmONE_OF_MANY)); ac++;
|
|
1687 XtSetArg (al [ac], XmNvisibleWhenOff, True); ac++;
|
|
1688 button = XmCreateToggleButton (instance->parent, val->name, al, ac);
|
|
1689 XtRemoveAllCallbacks (button, XmNvalueChangedCallback);
|
|
1690 XtAddCallback (button, XmNvalueChangedCallback, xm_generic_callback,
|
|
1691 (XtPointer)instance);
|
|
1692 }
|
|
1693 else
|
|
1694 {
|
|
1695 button = XmCreatePushButton (instance->parent, val->name, al, ac);
|
|
1696 XtAddCallback (button, XmNactivateCallback, xm_generic_callback,
|
|
1697 (XtPointer)instance);
|
|
1698 }
|
|
1699
|
|
1700 XtManageChild (button);
|
|
1701
|
|
1702 return button;
|
|
1703 }
|
|
1704
|
|
1705 static Widget
|
|
1706 xm_create_progress (widget_instance *instance)
|
|
1707 {
|
|
1708 Arg al[20];
|
|
1709 int ac = 0;
|
639
|
1710 Dimension height = 0;
|
|
1711 Dimension width = 0;
|
428
|
1712 Widget scale = 0;
|
|
1713 widget_value* val = instance->info->val;
|
|
1714 if (!val->call_data)
|
|
1715 {
|
639
|
1716 XtSetArg (al [ac], XmNeditable, False); ac++;
|
428
|
1717 }
|
|
1718 else
|
|
1719 {
|
639
|
1720 XtSetArg (al [ac], XmNeditable, val->enabled); ac++;
|
428
|
1721 }
|
|
1722 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1723 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
1724 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1725 XtSetArg (al [ac], XmNorientation, XmHORIZONTAL); ac++;
|
|
1726 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1727 look ugly. I think this may be a LessTif bug but for now we just
|
|
1728 get rid of it. */
|
|
1729 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
639
|
1730
|
|
1731 height = (Dimension)lw_get_value_arg (val, XtNheight);
|
|
1732 width = (Dimension)lw_get_value_arg (val, XtNwidth);
|
|
1733 if (height > 0)
|
|
1734 {
|
|
1735 XtSetArg (al [ac], XmNscaleHeight, height); ac++;
|
|
1736 }
|
|
1737 if (width > 0)
|
|
1738 {
|
|
1739 XtSetArg (al [ac], XmNscaleWidth, width); ac++;
|
|
1740 }
|
|
1741
|
428
|
1742 /* add any args the user supplied for creation time */
|
|
1743 lw_add_value_args_to_args (val, al, &ac);
|
|
1744
|
|
1745 scale = XmCreateScale (instance->parent, val->name, al, ac);
|
|
1746 if (val->call_data)
|
|
1747 XtAddCallback (scale, XmNvalueChangedCallback, xm_generic_callback,
|
|
1748 (XtPointer)instance);
|
|
1749
|
|
1750 XtManageChild (scale);
|
|
1751
|
|
1752 return scale;
|
|
1753 }
|
|
1754
|
|
1755 static Widget
|
|
1756 xm_create_text_field (widget_instance *instance)
|
|
1757 {
|
|
1758 Arg al[20];
|
|
1759 int ac = 0;
|
|
1760 Widget text = 0;
|
|
1761 widget_value* val = instance->info->val;
|
|
1762
|
442
|
1763 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
428
|
1764 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1765 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
1766 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1767 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1768 look ugly. I think this may be a LessTif bug but for now we just
|
|
1769 get rid of it. */
|
|
1770 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
|
1771
|
|
1772 /* add any args the user supplied for creation time */
|
|
1773 lw_add_value_args_to_args (val, al, &ac);
|
|
1774
|
|
1775 text = XmCreateTextField (instance->parent, val->name, al, ac);
|
|
1776 if (val->call_data)
|
|
1777 XtAddCallback (text, XmNvalueChangedCallback, xm_generic_callback,
|
|
1778 (XtPointer)instance);
|
|
1779
|
|
1780 XtManageChild (text);
|
|
1781
|
|
1782 return text;
|
|
1783 }
|
|
1784
|
|
1785 static Widget
|
|
1786 xm_create_label_field (widget_instance *instance)
|
|
1787 {
|
|
1788 return xm_create_label (instance->parent, instance->info->val);
|
|
1789 }
|
|
1790
|
|
1791 Widget
|
|
1792 xm_create_label (Widget parent, widget_value* val)
|
|
1793 {
|
|
1794 Arg al[20];
|
|
1795 int ac = 0;
|
|
1796 Widget label = 0;
|
|
1797
|
|
1798 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
|
1799 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1800 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1801 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1802 look ugly. I think this may be a LessTif bug but for now we just
|
|
1803 get rid of it. */
|
|
1804 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
|
1805
|
|
1806 /* add any args the user supplied for creation time */
|
|
1807 lw_add_value_args_to_args (val, al, &ac);
|
|
1808
|
|
1809 label = XmCreateLabel (parent, val->name, al, ac);
|
|
1810
|
|
1811 XtManageChild (label);
|
|
1812
|
|
1813 /* Do it again for arguments that have no effect until the widget is realized. */
|
|
1814 ac = 0;
|
|
1815 lw_add_value_args_to_args (val, al, &ac);
|
|
1816 XtSetValues (label, al, ac);
|
|
1817
|
|
1818 return label;
|
|
1819 }
|
|
1820
|
|
1821 #if XmVERSION > 1
|
|
1822 static Widget
|
|
1823 xm_create_combo_box (widget_instance *instance)
|
|
1824 {
|
|
1825 Arg al[20];
|
|
1826 int ac = 0;
|
|
1827 Widget combo = 0;
|
|
1828 widget_value* val = instance->info->val;
|
|
1829
|
|
1830 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
|
|
1831 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1832 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
|
|
1833 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
|
|
1834 /* The highlight doesn't appear to be dynamically set which makes it
|
|
1835 look ugly. I think this may be a LessTif bug but for now we just
|
|
1836 get rid of it. */
|
|
1837 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
|
|
1838
|
|
1839 /* add any args the user supplied for creation time */
|
|
1840 lw_add_value_args_to_args (val, al, &ac);
|
|
1841
|
|
1842 combo = XmCreateDropDownComboBox (instance->parent, val->name, al, ac);
|
|
1843 if (val->call_data)
|
|
1844 XtAddCallback (combo, XmNselectionCallback, xm_generic_callback,
|
|
1845 (XtPointer)instance);
|
|
1846
|
|
1847 XtManageChild (combo);
|
|
1848
|
|
1849 return combo;
|
|
1850 }
|
|
1851 #endif
|
|
1852 #endif /* LWLIB_WIDGETS_MOTIF */
|
|
1853
|
|
1854
|
|
1855 /* Table of functions to create widgets */
|
|
1856
|
450
|
1857 const widget_creation_entry
|
428
|
1858 xm_creation_table [] =
|
|
1859 {
|
|
1860 #ifdef LWLIB_MENUBARS_MOTIF
|
|
1861 {"menubar", make_menubar},
|
|
1862 {"popup", make_popup_menu},
|
|
1863 #endif
|
|
1864 #ifdef LWLIB_SCROLLBARS_MOTIF
|
|
1865 {"vertical-scrollbar", make_vertical_scrollbar},
|
|
1866 {"horizontal-scrollbar", make_horizontal_scrollbar},
|
|
1867 #endif
|
|
1868 #ifdef LWLIB_WIDGETS_MOTIF
|
|
1869 {"button", xm_create_button},
|
|
1870 {"progress", xm_create_progress},
|
|
1871 {"text-field", xm_create_text_field},
|
|
1872 {"label", xm_create_label_field},
|
|
1873 #if XmVERSION > 1
|
|
1874 {"combo-box", xm_create_combo_box},
|
|
1875 #endif
|
|
1876 #endif
|
|
1877 {NULL, NULL}
|
|
1878 };
|
|
1879
|
|
1880 /* Destruction of instances */
|
|
1881 void
|
2286
|
1882 xm_destroy_instance (
|
|
1883 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
|
1884 widget_instance* instance
|
|
1885 #else
|
|
1886 widget_instance* UNUSED (instance)
|
|
1887 #endif
|
|
1888 )
|
428
|
1889 {
|
|
1890 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
|
1891 /* It appears that this is used only for dialog boxes. */
|
|
1892 Widget widget = instance->widget;
|
|
1893 /* recycle the dialog boxes */
|
|
1894 /* Disable the recycling until we can find a way to have the dialog box
|
|
1895 get reasonable layout after we modify its contents. */
|
|
1896 if (0
|
|
1897 && XtClass (widget) == xmDialogShellWidgetClass)
|
|
1898 {
|
|
1899 destroyed_instance* dead_instance =
|
|
1900 make_destroyed_instance (instance->info->name,
|
|
1901 instance->info->type,
|
|
1902 instance->widget,
|
|
1903 instance->parent,
|
|
1904 instance->pop_up_p);
|
|
1905 dead_instance->next = all_destroyed_instances;
|
|
1906 all_destroyed_instances = dead_instance;
|
|
1907 XtUnmanageChild (first_child (instance->widget));
|
|
1908 XFlush (XtDisplay (instance->widget));
|
|
1909 XtAddCallback (instance->parent, XtNdestroyCallback,
|
|
1910 mark_dead_instance_destroyed, (XtPointer)dead_instance);
|
|
1911 }
|
|
1912 else
|
|
1913 {
|
|
1914 /* This might not be necessary now that the nosel is attached to
|
|
1915 popdown instead of destroy, but it can't hurt. */
|
|
1916 XtRemoveCallback (instance->widget, XtNdestroyCallback,
|
|
1917 xm_nosel_callback, (XtPointer)instance);
|
|
1918
|
|
1919 XtDestroyWidget (instance->widget);
|
|
1920 }
|
|
1921 #endif /* LWLIB_DIALOGS_MOTIF || LWLIB_WIDGETS_MOTIF */
|
|
1922 }
|
|
1923
|
|
1924 /* popup utility */
|
|
1925 #ifdef LWLIB_MENUBARS_MOTIF
|
|
1926
|
|
1927 void
|
|
1928 xm_popup_menu (Widget widget, XEvent *event)
|
|
1929 {
|
|
1930 if (event->type == ButtonPress || event->type == ButtonRelease)
|
|
1931 {
|
|
1932 /* This is so totally ridiculous: there's NO WAY to tell Motif
|
|
1933 that *any* button can select a menu item. Only one button
|
|
1934 can have that honor.
|
|
1935 */
|
|
1936 char *trans = 0;
|
|
1937 if (event->xbutton.state & Button5Mask) trans = "<Btn5Down>";
|
|
1938 else if (event->xbutton.state & Button4Mask) trans = "<Btn4Down>";
|
|
1939 else if (event->xbutton.state & Button3Mask) trans = "<Btn3Down>";
|
|
1940 else if (event->xbutton.state & Button2Mask) trans = "<Btn2Down>";
|
|
1941 else if (event->xbutton.state & Button1Mask) trans = "<Btn1Down>";
|
|
1942 if (trans)
|
|
1943 {
|
|
1944 Arg al [1];
|
|
1945 XtSetArg (al [0], XmNmenuPost, trans);
|
|
1946 XtSetValues (widget, al, 1);
|
|
1947 }
|
|
1948 XmMenuPosition (widget, (XButtonPressedEvent *) event);
|
|
1949 }
|
|
1950 XtManageChild (widget);
|
|
1951 }
|
|
1952
|
|
1953 #endif
|
|
1954
|
|
1955 #ifdef LWLIB_DIALOGS_MOTIF
|
|
1956
|
|
1957 static void
|
|
1958 set_min_dialog_size (Widget w)
|
|
1959 {
|
|
1960 short width;
|
|
1961 short height;
|
|
1962 Arg al [2];
|
|
1963
|
|
1964 XtSetArg (al [0], XmNwidth, &width);
|
|
1965 XtSetArg (al [1], XmNheight, &height);
|
|
1966 XtGetValues (w, al, 2);
|
|
1967
|
|
1968 XtSetArg (al [0], XmNminWidth, width);
|
|
1969 XtSetArg (al [1], XmNminHeight, height);
|
|
1970 XtSetValues (w, al, 2);
|
|
1971 }
|
|
1972
|
|
1973 #endif
|
|
1974
|
|
1975 void
|
|
1976 xm_pop_instance (widget_instance* instance, Boolean up)
|
|
1977 {
|
|
1978 Widget widget = instance->widget;
|
|
1979
|
|
1980 #ifdef LWLIB_DIALOGS_MOTIF
|
|
1981 if (XtClass (widget) == xmDialogShellWidgetClass)
|
|
1982 {
|
|
1983 Widget widget_to_manage = first_child (widget);
|
|
1984 if (up)
|
|
1985 {
|
|
1986 XtManageChild (widget_to_manage);
|
|
1987 set_min_dialog_size (widget);
|
|
1988 XmProcessTraversal(widget, XmTRAVERSE_CURRENT);
|
|
1989 }
|
|
1990 else
|
|
1991 XtUnmanageChild (widget_to_manage);
|
|
1992 }
|
|
1993 else
|
|
1994 #endif
|
|
1995 {
|
|
1996 if (up)
|
|
1997 XtManageChild (widget);
|
|
1998 else
|
|
1999 XtUnmanageChild (widget);
|
|
2000 }
|
|
2001 }
|
|
2002
|
|
2003
|
|
2004 /* motif callback */
|
|
2005
|
|
2006 enum do_call_type { pre_activate, selection, no_selection, post_activate };
|
|
2007
|
|
2008 static void
|
|
2009 do_call (Widget widget, XtPointer closure, enum do_call_type type)
|
|
2010 {
|
|
2011 XtPointer user_data;
|
|
2012 widget_instance* instance = (widget_instance*)closure;
|
|
2013 Widget instance_widget;
|
|
2014 LWLIB_ID id;
|
|
2015 Arg al [1];
|
|
2016
|
|
2017 if (!instance)
|
|
2018 return;
|
|
2019 if (widget->core.being_destroyed)
|
|
2020 return;
|
|
2021
|
|
2022 instance_widget = instance->widget;
|
|
2023 if (!instance_widget)
|
|
2024 return;
|
|
2025
|
|
2026 id = instance->info->id;
|
|
2027 user_data = NULL;
|
|
2028 XtSetArg(al [0], XmNuserData, &user_data);
|
|
2029 XtGetValues (widget, al, 1);
|
|
2030 switch (type)
|
|
2031 {
|
|
2032 case pre_activate:
|
|
2033 if (instance->info->pre_activate_cb)
|
|
2034 instance->info->pre_activate_cb (widget, id, user_data);
|
|
2035 break;
|
|
2036 case selection:
|
|
2037 if (instance->info->selection_cb)
|
|
2038 instance->info->selection_cb (widget, id, user_data);
|
|
2039 break;
|
|
2040 case no_selection:
|
|
2041 if (instance->info->selection_cb)
|
|
2042 instance->info->selection_cb (widget, id, (XtPointer) -1);
|
|
2043 break;
|
|
2044 case post_activate:
|
|
2045 if (instance->info->post_activate_cb)
|
|
2046 instance->info->post_activate_cb (widget, id, user_data);
|
|
2047 break;
|
|
2048 default:
|
|
2049 abort ();
|
|
2050 }
|
|
2051 }
|
|
2052
|
|
2053 /* Like lw_internal_update_other_instances except that it does not do
|
|
2054 anything if its shell parent is not managed. This is to protect
|
|
2055 lw_internal_update_other_instances to dereference freed memory
|
|
2056 if the widget was ``destroyed'' by caching it in the all_destroyed_instances
|
|
2057 list */
|
|
2058 static void
|
|
2059 xm_internal_update_other_instances (Widget widget, XtPointer closure,
|
|
2060 XtPointer call_data)
|
|
2061 {
|
|
2062 Widget parent;
|
|
2063 for (parent = widget; parent; parent = XtParent (parent))
|
|
2064 if (XtIsShell (parent))
|
|
2065 break;
|
|
2066 else if (!XtIsManaged (parent))
|
|
2067 return;
|
|
2068 lw_internal_update_other_instances (widget, closure, call_data);
|
|
2069 }
|
|
2070
|
|
2071 static void
|
|
2072 xm_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
2073 {
|
|
2074 #if (defined (LWLIB_MENUBARS_MOTIF) || defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF))
|
|
2075 /* We want the selected status to change only when we decide it
|
|
2076 should change. Yuck but correct. */
|
|
2077 if (XtClass (widget) == xmToggleButtonWidgetClass
|
|
2078 || XtClass (widget) == xmToggleButtonGadgetClass)
|
|
2079 {
|
|
2080 Boolean check;
|
|
2081 Arg al [1];
|
|
2082
|
|
2083 XtSetArg (al [0], XmNset, &check);
|
|
2084 XtGetValues (widget, al, 1);
|
|
2085
|
|
2086 XtSetArg (al [0], XmNset, !check);
|
|
2087 XtSetValues (widget, al, 1);
|
|
2088 }
|
|
2089 #endif
|
|
2090 lw_internal_update_other_instances (widget, closure, call_data);
|
|
2091 do_call (widget, closure, selection);
|
|
2092 }
|
|
2093
|
1261
|
2094 #if 0 /* Caller above is commented out */
|
428
|
2095 static void
|
|
2096 xm_pop_down_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
2097 {
|
|
2098 do_call (widget, closure, post_activate);
|
|
2099 }
|
1261
|
2100 #endif /* 0 */
|
428
|
2101
|
|
2102 #ifdef LWLIB_MENUBARS_MOTIF
|
|
2103
|
|
2104 static void
|
|
2105 xm_pull_down_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
2106 {
|
|
2107 #if 0
|
|
2108 if (call_data)
|
|
2109 {
|
|
2110 /* new behavior for incremental menu construction */
|
|
2111
|
|
2112 }
|
|
2113 else
|
|
2114 #endif
|
|
2115 do_call (widget, closure, pre_activate);
|
|
2116 }
|
|
2117
|
|
2118 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
2119
|
|
2120 #ifdef LWLIB_SCROLLBARS_MOTIF
|
|
2121 static void
|
|
2122 xm_scrollbar_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
2123 {
|
|
2124 widget_instance *instance = (widget_instance *) closure;
|
|
2125 LWLIB_ID id;
|
|
2126 XmScrollBarCallbackStruct *data =
|
|
2127 (XmScrollBarCallbackStruct *) call_data;
|
|
2128 scroll_event event_data;
|
|
2129 scrollbar_values *val =
|
|
2130 (scrollbar_values *) instance->info->val->scrollbar_data;
|
|
2131 double percent;
|
|
2132
|
|
2133 if (!instance || widget->core.being_destroyed)
|
|
2134 return;
|
|
2135
|
|
2136 id = instance->info->id;
|
|
2137
|
|
2138 percent = (double) (data->value - 1) / (double) (INT_MAX - 1);
|
|
2139 event_data.slider_value =
|
|
2140 (int) (percent * (double) (val->maximum - val->minimum)) + val->minimum;
|
|
2141
|
|
2142 if (event_data.slider_value > (val->maximum - val->slider_size))
|
|
2143 event_data.slider_value = val->maximum - val->slider_size;
|
|
2144 else if (event_data.slider_value < 1)
|
|
2145 event_data.slider_value = 1;
|
|
2146
|
|
2147 if (data->event)
|
|
2148 {
|
|
2149 switch (data->event->xany.type)
|
|
2150 {
|
|
2151 case KeyPress:
|
|
2152 case KeyRelease:
|
|
2153 event_data.time = data->event->xkey.time;
|
|
2154 break;
|
|
2155 case ButtonPress:
|
|
2156 case ButtonRelease:
|
|
2157 event_data.time = data->event->xbutton.time;
|
|
2158 break;
|
|
2159 case MotionNotify:
|
|
2160 event_data.time = data->event->xmotion.time;
|
|
2161 break;
|
|
2162 case EnterNotify:
|
|
2163 case LeaveNotify:
|
|
2164 event_data.time = data->event->xcrossing.time;
|
|
2165 break;
|
|
2166 default:
|
|
2167 event_data.time = 0;
|
|
2168 break;
|
|
2169 }
|
|
2170 }
|
|
2171 else
|
|
2172 event_data.time = 0;
|
|
2173
|
|
2174 switch (data->reason)
|
|
2175 {
|
|
2176 case XmCR_DECREMENT:
|
|
2177 event_data.action = SCROLLBAR_LINE_UP;
|
|
2178 break;
|
|
2179 case XmCR_INCREMENT:
|
|
2180 event_data.action = SCROLLBAR_LINE_DOWN;
|
|
2181 break;
|
|
2182 case XmCR_PAGE_DECREMENT:
|
|
2183 event_data.action = SCROLLBAR_PAGE_UP;
|
|
2184 break;
|
|
2185 case XmCR_PAGE_INCREMENT:
|
|
2186 event_data.action = SCROLLBAR_PAGE_DOWN;
|
|
2187 break;
|
|
2188 case XmCR_TO_TOP:
|
|
2189 event_data.action = SCROLLBAR_TOP;
|
|
2190 break;
|
|
2191 case XmCR_TO_BOTTOM:
|
|
2192 event_data.action = SCROLLBAR_BOTTOM;
|
|
2193 break;
|
|
2194 case XmCR_DRAG:
|
|
2195 event_data.action = SCROLLBAR_DRAG;
|
|
2196 break;
|
|
2197 case XmCR_VALUE_CHANGED:
|
|
2198 event_data.action = SCROLLBAR_CHANGE;
|
|
2199 break;
|
|
2200 default:
|
|
2201 event_data.action = SCROLLBAR_CHANGE;
|
|
2202 break;
|
|
2203 }
|
|
2204
|
|
2205 if (instance->info->pre_activate_cb)
|
|
2206 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
|
|
2207 }
|
|
2208 #endif /* LWLIB_SCROLLBARS_MOTIF */
|
|
2209
|
|
2210 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
|
|
2211 static void
|
|
2212 mark_dead_instance_destroyed (Widget widget, XtPointer closure,
|
|
2213 XtPointer call_data)
|
|
2214 {
|
|
2215 destroyed_instance* instance = (destroyed_instance*)closure;
|
|
2216 instance->widget = NULL;
|
|
2217 }
|
|
2218
|
|
2219 static void
|
|
2220 xm_nosel_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
2221 {
|
|
2222 /* This callback is only called when a dialog box is dismissed with the wm's
|
|
2223 destroy button (WM_DELETE_WINDOW.) We want the dialog box to be destroyed
|
|
2224 in that case, not just unmapped, so that it releases its keyboard grabs.
|
|
2225 But there are problems with running our callbacks while the widget is in
|
|
2226 the process of being destroyed, so we set XmNdeleteResponse to XmUNMAP
|
|
2227 instead of XmDESTROY and then destroy it ourself after having run the
|
|
2228 callback.
|
|
2229 */
|
|
2230 do_call (widget, closure, no_selection);
|
|
2231 XtDestroyWidget (widget);
|
|
2232 }
|
|
2233 #endif
|
|
2234
|
|
2235
|
|
2236 /* set the keyboard focus */
|
|
2237 void
|
2286
|
2238 xm_set_keyboard_focus (Widget UNUSED (parent), Widget w)
|
428
|
2239 {
|
|
2240 XmProcessTraversal (w, XmTRAVERSE_CURRENT);
|
|
2241 /* At some point we believed that it was necessary to use XtSetKeyboardFocus
|
|
2242 instead of XmProcessTraversal when using Motif >= 1.2.1, but that's bogus.
|
|
2243 Presumably the problem was elsewhere, and is now gone...
|
|
2244 */
|
|
2245 }
|