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