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