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