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
|
80
|
18 along with XEmacs; 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 {
|
80
|
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
|
80
|
156 resource.resource_name = "labelString";
|
78
|
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++;
|
80
|
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;
|
80
|
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 {
|
80
|
671 XmTextSetString (widget, val->value ? val->value : "");
|
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 {
|
80
|
683 XmTextFieldSetString (widget, val->value ? val->value : "");
|
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,
|
80
|
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;
|
80
|
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, "dialog", al, ac);
|
0
|
1048
|
80
|
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;
|
80
|
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;
|
80
|
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++;
|
80
|
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, "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++;
|
80
|
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;
|
80
|
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, "", al, ac);
|
0
|
1148
|
|
1149 ac = 0;
|
80
|
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;
|
80
|
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, "", al, ac);
|
0
|
1171 DO_DND_KLUDGE (icon_separator);
|
|
1172
|
|
1173 if (text_input_slot)
|
|
1174 {
|
|
1175 ac = 0;
|
80
|
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, "value", al, ac);
|
0
|
1187 DO_DND_KLUDGE (value);
|
|
1188 }
|
|
1189 else if (radio_box)
|
|
1190 {
|
|
1191 Widget radio_butt;
|
|
1192 ac = 0;
|
80
|
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, "radiobutton1", al, ac);
|
0
|
1207 ac = 0;
|
|
1208 i = 0;
|
80
|
1209 radio_butt = XmCreateToggleButtonGadget (value, "radio1", al, ac);
|
0
|
1210 children [i++] = radio_butt;
|
80
|
1211 radio_butt = XmCreateToggleButtonGadget (value, "radio2", al, ac);
|
0
|
1212 children [i++] = radio_butt;
|
80
|
1213 radio_butt = XmCreateToggleButtonGadget (value, "radio3", al, ac);
|
0
|
1214 children [i++] = radio_butt;
|
|
1215 XtManageChildren (children, i);
|
|
1216 }
|
|
1217 else if (list)
|
|
1218 {
|
|
1219 ac = 0;
|
80
|
1220 XtSetArg(al[ac], XmNvisibleItemCount, 5); ac++;
|
|
1221 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
|
|
1222 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1223 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
|
1224 XtSetArg(al[ac], XmNbottomWidget, separator); ac++;
|
|
1225 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1226 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1227 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1228 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1229 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1230 value = XmCreateScrolledList (form, "list", al, ac);
|
0
|
1231
|
|
1232 /* this is the easiest way I found to have the dble click in the
|
|
1233 list activate the default button */
|
|
1234 XtAddCallback (value, XmNdefaultActionCallback, activate_button, button);
|
|
1235 }
|
|
1236
|
|
1237 ac = 0;
|
80
|
1238 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
1239 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
|
|
1240 XtSetArg(al[ac], XmNtopOffset, 13); ac++;
|
|
1241 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
|
|
1242 XtSetArg(al[ac], XmNbottomOffset, 13); ac++;
|
0
|
1243 XtSetArg(al[ac], XmNbottomWidget,
|
|
1244 text_input_slot || radio_box || list ? value : separator); ac++;
|
80
|
1245 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
1246 XtSetArg(al[ac], XmNleftOffset, 13); ac++;
|
|
1247 XtSetArg(al[ac], XmNleftWidget, icon); ac++;
|
|
1248 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
|
|
1249 XtSetArg(al[ac], XmNrightOffset, 13); ac++;
|
|
1250 message = XmCreateLabel (form, "message", al, ac);
|
0
|
1251 DO_DND_KLUDGE (message);
|
|
1252
|
|
1253 if (list)
|
|
1254 XtManageChild (value);
|
|
1255
|
|
1256 i = 0;
|
|
1257 children [i] = row; i++;
|
|
1258 children [i] = separator; i++;
|
|
1259 if (text_input_slot || radio_box)
|
|
1260 {
|
|
1261 children [i] = value; i++;
|
|
1262 }
|
|
1263 children [i] = message; i++;
|
|
1264 children [i] = icon; i++;
|
|
1265 children [i] = icon_separator; i++;
|
|
1266 XtManageChildren (children, i);
|
|
1267
|
|
1268 if (text_input_slot || list)
|
|
1269 {
|
|
1270 XtInstallAccelerators (value, button);
|
|
1271 XmProcessTraversal(value, XmTRAVERSE_CURRENT);
|
|
1272 }
|
|
1273 else
|
|
1274 {
|
|
1275 XtInstallAccelerators (form, button);
|
|
1276 XmProcessTraversal(value, XmTRAVERSE_CURRENT);
|
|
1277 }
|
|
1278
|
|
1279 #ifdef DND_KLUDGE
|
|
1280 XtFree ((char *) dnd_override);
|
|
1281 #endif
|
|
1282 #undef DO_DND_KLUDGE
|
|
1283
|
|
1284 return result;
|
|
1285 }
|
|
1286
|
|
1287 static destroyed_instance*
|
|
1288 find_matching_instance (widget_instance* instance)
|
|
1289 {
|
|
1290 destroyed_instance* cur;
|
|
1291 destroyed_instance* prev;
|
|
1292 char* type = instance->info->type;
|
|
1293 char* name = instance->info->name;
|
|
1294
|
|
1295 for (prev = NULL, cur = all_destroyed_instances;
|
|
1296 cur;
|
|
1297 prev = cur, cur = cur->next)
|
|
1298 {
|
|
1299 if (!strcmp (cur->name, name)
|
|
1300 && !strcmp (cur->type, type)
|
|
1301 && cur->parent == instance->parent
|
|
1302 && cur->pop_up_p == instance->pop_up_p)
|
|
1303 {
|
|
1304 if (prev)
|
|
1305 prev->next = cur->next;
|
|
1306 else
|
|
1307 all_destroyed_instances = cur->next;
|
|
1308 return cur;
|
|
1309 }
|
|
1310 /* do some cleanup */
|
|
1311 else if (!cur->widget)
|
|
1312 {
|
|
1313 if (prev)
|
|
1314 prev->next = cur->next;
|
|
1315 else
|
|
1316 all_destroyed_instances = cur->next;
|
|
1317 free_destroyed_instance (cur);
|
|
1318 cur = prev ? prev : all_destroyed_instances;
|
|
1319 }
|
|
1320 }
|
|
1321 return NULL;
|
|
1322 }
|
|
1323
|
|
1324 static void
|
|
1325 mark_dead_instance_destroyed (Widget widget, XtPointer closure,
|
|
1326 XtPointer call_data)
|
|
1327 {
|
|
1328 destroyed_instance* instance = (destroyed_instance*)closure;
|
|
1329 instance->widget = NULL;
|
|
1330 }
|
|
1331
|
|
1332 static void
|
|
1333 recenter_widget (Widget widget)
|
|
1334 {
|
|
1335 Widget parent = XtParent (widget);
|
|
1336 Screen* screen = XtScreen (widget);
|
|
1337 Dimension screen_width = WidthOfScreen (screen);
|
|
1338 Dimension screen_height = HeightOfScreen (screen);
|
|
1339 Dimension parent_width = 0;
|
|
1340 Dimension parent_height = 0;
|
|
1341 Dimension child_width = 0;
|
|
1342 Dimension child_height = 0;
|
|
1343 Position x;
|
|
1344 Position y;
|
|
1345
|
|
1346 XtVaGetValues (widget, XtNwidth, &child_width, XtNheight, &child_height, 0);
|
|
1347 XtVaGetValues (parent, XtNwidth, &parent_width, XtNheight, &parent_height,
|
|
1348 0);
|
|
1349
|
|
1350 x = (((Position)parent_width) - ((Position)child_width)) / 2;
|
|
1351 y = (((Position)parent_height) - ((Position)child_height)) / 2;
|
|
1352
|
|
1353 XtTranslateCoords (parent, x, y, &x, &y);
|
|
1354
|
|
1355 if ((Dimension) (x + child_width) > screen_width)
|
|
1356 x = screen_width - child_width;
|
|
1357 if (x < 0)
|
|
1358 x = 0;
|
|
1359
|
|
1360 if ((Dimension) (y + child_height) > screen_height)
|
|
1361 y = screen_height - child_height;
|
|
1362 if (y < 0)
|
|
1363 y = 0;
|
|
1364
|
|
1365 XtVaSetValues (widget, XtNx, x, XtNy, y, 0);
|
|
1366 }
|
|
1367
|
|
1368 static Widget
|
|
1369 recycle_instance (destroyed_instance* instance)
|
|
1370 {
|
|
1371 Widget widget = instance->widget;
|
|
1372
|
|
1373 /* widget is NULL if the parent was destroyed. */
|
|
1374 if (widget)
|
|
1375 {
|
|
1376 Widget focus;
|
|
1377 Widget separator;
|
|
1378
|
|
1379 /* Remove the destroy callback as the instance is not in the list
|
|
1380 anymore */
|
|
1381 XtRemoveCallback (instance->parent, XtNdestroyCallback,
|
|
1382 mark_dead_instance_destroyed,
|
|
1383 (XtPointer)instance);
|
|
1384
|
|
1385 /* Give the focus to the initial item */
|
|
1386 focus = XtNameToWidget (widget, "*value");
|
|
1387 if (!focus)
|
|
1388 focus = XtNameToWidget (widget, "*button1");
|
|
1389 if (focus)
|
|
1390 XmProcessTraversal(focus, XmTRAVERSE_CURRENT);
|
|
1391
|
|
1392 /* shrink the separator label back to their original size */
|
|
1393 separator = XtNameToWidget (widget, "*separator_button");
|
|
1394 if (separator)
|
|
1395 XtVaSetValues (separator, XtNwidth, 5, XtNheight, 5, 0);
|
|
1396
|
|
1397 /* Center the dialog in its parent */
|
|
1398 recenter_widget (widget);
|
|
1399 }
|
|
1400 free_destroyed_instance (instance);
|
|
1401 return widget;
|
|
1402 }
|
|
1403
|
|
1404 Widget
|
|
1405 xm_create_dialog (widget_instance* instance)
|
|
1406 {
|
|
1407 char* name = instance->info->type;
|
|
1408 Widget parent = instance->parent;
|
|
1409 Widget widget;
|
|
1410 Boolean pop_up_p = instance->pop_up_p;
|
2
|
1411 CONST char* shell_name = 0;
|
|
1412 CONST char* icon_name = 0;
|
0
|
1413 Boolean text_input_slot = False;
|
|
1414 Boolean radio_box = False;
|
|
1415 Boolean list = False;
|
|
1416 int total_buttons;
|
|
1417 int left_buttons = 0;
|
|
1418 int right_buttons = 1;
|
|
1419 destroyed_instance* dead_one;
|
|
1420
|
|
1421 /* try to find a widget to recycle */
|
|
1422 dead_one = find_matching_instance (instance);
|
|
1423 if (dead_one)
|
|
1424 {
|
|
1425 Widget recycled_widget = recycle_instance (dead_one);
|
|
1426 if (recycled_widget)
|
|
1427 return recycled_widget;
|
|
1428 }
|
|
1429
|
|
1430 switch (name [0]){
|
|
1431 case 'E': case 'e':
|
|
1432 icon_name = "dbox-error";
|
|
1433 shell_name = "Error";
|
|
1434 break;
|
|
1435
|
|
1436 case 'I': case 'i':
|
|
1437 icon_name = "dbox-info";
|
|
1438 shell_name = "Information";
|
|
1439 break;
|
|
1440
|
|
1441 case 'L': case 'l':
|
|
1442 list = True;
|
|
1443 icon_name = "dbox-question";
|
|
1444 shell_name = "Prompt";
|
|
1445 break;
|
|
1446
|
|
1447 case 'P': case 'p':
|
|
1448 text_input_slot = True;
|
|
1449 icon_name = "dbox-question";
|
|
1450 shell_name = "Prompt";
|
|
1451 break;
|
|
1452
|
|
1453 case 'Q': case 'q':
|
|
1454 icon_name = "dbox-question";
|
|
1455 shell_name = "Question";
|
|
1456 break;
|
|
1457 }
|
|
1458
|
|
1459 total_buttons = name [1] - '0';
|
|
1460
|
|
1461 if (name [3] == 'T' || name [3] == 't')
|
|
1462 {
|
|
1463 text_input_slot = False;
|
|
1464 radio_box = True;
|
|
1465 }
|
|
1466 else if (name [3])
|
|
1467 right_buttons = name [4] - '0';
|
|
1468
|
|
1469 left_buttons = total_buttons - right_buttons;
|
|
1470
|
|
1471 widget = make_dialog (name, parent, pop_up_p,
|
|
1472 shell_name, icon_name, text_input_slot, radio_box,
|
|
1473 list, left_buttons, right_buttons);
|
|
1474
|
|
1475 XtAddCallback (widget, XmNpopdownCallback, xm_nosel_callback,
|
|
1476 (XtPointer) instance);
|
|
1477 return widget;
|
|
1478 }
|
|
1479
|
|
1480 #endif /* DIALOGS_MOTIF */
|
|
1481
|
|
1482 #ifdef MENUBARS_MOTIF
|
|
1483 static Widget
|
|
1484 make_menubar (widget_instance* instance)
|
|
1485 {
|
|
1486 Arg al[10];
|
|
1487 int ac = 0;
|
|
1488
|
80
|
1489 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
|
0
|
1490 XtSetArg(al[ac], XmNshadowThickness, 3); ac++;
|
|
1491
|
|
1492 return XmCreateMenuBar (instance->parent, instance->info->name, al, ac);
|
|
1493 }
|
|
1494
|
|
1495 static void
|
|
1496 remove_grabs (Widget shell, XtPointer closure, XtPointer call_data)
|
|
1497 {
|
|
1498 Widget menu = (Widget) closure;
|
|
1499 XmRemoveFromPostFromList (menu, XtParent (XtParent ((Widget) menu)));
|
|
1500 }
|
|
1501
|
|
1502 static Widget
|
|
1503 make_popup_menu (widget_instance* instance)
|
|
1504 {
|
|
1505 Widget parent = instance->parent;
|
|
1506 Window parent_window = parent->core.window;
|
|
1507 Widget result;
|
|
1508
|
|
1509 /* sets the parent window to 0 to fool Motif into not generating a grab */
|
|
1510 parent->core.window = 0;
|
|
1511 result = XmCreatePopupMenu (parent, instance->info->name, NULL, 0);
|
|
1512 XtAddCallback (XtParent (result), XmNpopdownCallback, remove_grabs,
|
|
1513 (XtPointer)result);
|
|
1514 parent->core.window = parent_window;
|
|
1515 return result;
|
|
1516 }
|
|
1517 #endif /* MENUBARS_MOTIF */
|
|
1518
|
|
1519 #ifdef SCROLLBARS_MOTIF
|
|
1520 static Widget
|
|
1521 make_scrollbar (widget_instance *instance, int vertical)
|
|
1522 {
|
|
1523 Arg al[20];
|
|
1524 int ac = 0;
|
80
|
1525 static XtCallbackRec callbacks[2] =
|
|
1526 { {xm_scrollbar_callback, NULL}, {NULL, NULL} };
|
0
|
1527
|
80
|
1528 callbacks[0].closure = (XtPointer) instance;
|
|
1529
|
|
1530 XtSetArg (al[ac], XmNminimum, 1); ac++;
|
|
1531 XtSetArg (al[ac], XmNmaximum, INT_MAX); ac++;
|
|
1532 XtSetArg (al[ac], XmNincrement, 1); ac++;
|
|
1533 XtSetArg (al[ac], XmNpageIncrement, 1); ac++;
|
|
1534 XtSetArg (al[ac], XmNborderWidth, 0); ac++;
|
|
1535 XtSetArg (al[ac], XmNorientation, vertical ? XmVERTICAL : XmHORIZONTAL); ac++;
|
0
|
1536
|
80
|
1537 XtSetArg (al[ac], XmNdecrementCallback, callbacks); ac++;
|
|
1538 XtSetArg (al[ac], XmNdragCallback, callbacks); ac++;
|
|
1539 XtSetArg (al[ac], XmNincrementCallback, callbacks); ac++;
|
|
1540 XtSetArg (al[ac], XmNpageDecrementCallback, callbacks); ac++;
|
|
1541 XtSetArg (al[ac], XmNpageIncrementCallback, callbacks); ac++;
|
|
1542 XtSetArg (al[ac], XmNtoBottomCallback, callbacks); ac++;
|
|
1543 XtSetArg (al[ac], XmNtoTopCallback, callbacks); ac++;
|
|
1544 XtSetArg (al[ac], XmNvalueChangedCallback, callbacks); ac++;
|
70
|
1545
|
80
|
1546 return XmCreateScrollBar (instance->parent, instance->info->name, al, ac);
|
0
|
1547 }
|
|
1548
|
|
1549 static Widget
|
|
1550 make_vertical_scrollbar (widget_instance *instance)
|
|
1551 {
|
|
1552 return make_scrollbar (instance, 1);
|
|
1553 }
|
|
1554
|
|
1555 static Widget
|
|
1556 make_horizontal_scrollbar (widget_instance *instance)
|
|
1557 {
|
|
1558 return make_scrollbar (instance, 0);
|
|
1559 }
|
|
1560
|
|
1561 #endif /* SCROLLBARS_MOTIF */
|
|
1562
|
|
1563 /* Table of functions to create widgets */
|
|
1564
|
|
1565 #ifdef ENERGIZE
|
|
1566
|
|
1567 /* interface with the XDesigner generated functions */
|
|
1568 typedef Widget (*widget_maker) (Widget);
|
|
1569 extern Widget create_project_p_sheet (Widget parent);
|
|
1570 extern Widget create_debugger_p_sheet (Widget parent);
|
|
1571 extern Widget create_breaklist_p_sheet (Widget parent);
|
|
1572 extern Widget create_le_browser_p_sheet (Widget parent);
|
|
1573 extern Widget create_class_browser_p_sheet (Widget parent);
|
|
1574 extern Widget create_call_browser_p_sheet (Widget parent);
|
|
1575 extern Widget create_build_dialog (Widget parent);
|
|
1576 extern Widget create_editmode_dialog (Widget parent);
|
|
1577 extern Widget create_search_dialog (Widget parent);
|
|
1578 extern Widget create_project_display_dialog (Widget parent);
|
|
1579
|
|
1580 static Widget
|
|
1581 make_one (widget_instance* instance, widget_maker fn)
|
|
1582 {
|
|
1583 Widget result;
|
|
1584 Arg al [64];
|
|
1585 int ac = 0;
|
|
1586
|
|
1587 if (instance->pop_up_p)
|
|
1588 {
|
|
1589 XtSetArg (al [ac], XmNallowShellResize, TRUE); ac++;
|
|
1590 result = XmCreateDialogShell (instance->parent, "dialog", NULL, 0);
|
|
1591 XtAddCallback (result, XmNpopdownCallback, &xm_nosel_callback,
|
|
1592 (XtPointer) instance);
|
|
1593 (*fn) (result);
|
|
1594 }
|
|
1595 else
|
|
1596 {
|
|
1597 result = (*fn) (instance->parent);
|
|
1598 XtRealizeWidget (result);
|
|
1599 }
|
|
1600 return result;
|
|
1601 }
|
|
1602
|
|
1603 static Widget
|
|
1604 make_project_p_sheet (widget_instance* instance)
|
|
1605 {
|
|
1606 return make_one (instance, create_project_p_sheet);
|
|
1607 }
|
|
1608
|
|
1609 static Widget
|
|
1610 make_debugger_p_sheet (widget_instance* instance)
|
|
1611 {
|
|
1612 return make_one (instance, create_debugger_p_sheet);
|
|
1613 }
|
|
1614
|
|
1615 static Widget
|
|
1616 make_breaklist_p_sheet (widget_instance* instance)
|
|
1617 {
|
|
1618 return make_one (instance, create_breaklist_p_sheet);
|
|
1619 }
|
|
1620
|
|
1621 static Widget
|
|
1622 make_le_browser_p_sheet (widget_instance* instance)
|
|
1623 {
|
|
1624 return make_one (instance, create_le_browser_p_sheet);
|
|
1625 }
|
|
1626
|
|
1627 static Widget
|
|
1628 make_class_browser_p_sheet (widget_instance* instance)
|
|
1629 {
|
|
1630 return make_one (instance, create_class_browser_p_sheet);
|
|
1631 }
|
|
1632
|
|
1633 static Widget
|
|
1634 make_call_browser_p_sheet (widget_instance* instance)
|
|
1635 {
|
|
1636 return make_one (instance, create_call_browser_p_sheet);
|
|
1637 }
|
|
1638
|
|
1639 static Widget
|
|
1640 make_build_dialog (widget_instance* instance)
|
|
1641 {
|
|
1642 return make_one (instance, create_build_dialog);
|
|
1643 }
|
|
1644
|
|
1645 static Widget
|
|
1646 make_editmode_dialog (widget_instance* instance)
|
|
1647 {
|
|
1648 return make_one (instance, create_editmode_dialog);
|
|
1649 }
|
|
1650
|
|
1651 static Widget
|
|
1652 make_search_dialog (widget_instance* instance)
|
|
1653 {
|
|
1654 return make_one (instance, create_search_dialog);
|
|
1655 }
|
|
1656
|
|
1657 static Widget
|
|
1658 make_project_display_dialog (widget_instance* instance)
|
|
1659 {
|
|
1660 return make_one (instance, create_project_display_dialog);
|
|
1661 }
|
|
1662
|
|
1663 #endif /* ENERGIZE */
|
|
1664
|
|
1665 widget_creation_entry
|
|
1666 xm_creation_table [] =
|
|
1667 {
|
|
1668 #ifdef MENUBARS_MOTIF
|
|
1669 {"menubar", make_menubar},
|
|
1670 {"popup", make_popup_menu},
|
|
1671 #endif
|
|
1672 #ifdef SCROLLBARS_MOTIF
|
|
1673 {"vertical-scrollbar", make_vertical_scrollbar},
|
|
1674 {"horizontal-scrollbar", make_horizontal_scrollbar},
|
|
1675 #endif
|
|
1676 #ifdef ENERGIZE
|
|
1677 {"project_p_sheet", make_project_p_sheet},
|
|
1678 {"debugger_p_sheet", make_debugger_p_sheet},
|
|
1679 {"breaklist_psheet", make_breaklist_p_sheet},
|
|
1680 {"leb_psheet", make_le_browser_p_sheet},
|
|
1681 {"class_browser_psheet", make_class_browser_p_sheet},
|
|
1682 {"ctree_browser_psheet", make_call_browser_p_sheet},
|
|
1683 {"build", make_build_dialog},
|
|
1684 {"editmode", make_editmode_dialog},
|
|
1685 {"search", make_search_dialog},
|
|
1686 {"project_display", make_project_display_dialog},
|
|
1687 #endif /* ENERGIZE */
|
|
1688 {NULL, NULL}
|
|
1689 };
|
|
1690
|
|
1691 /* Destruction of instances */
|
|
1692 void
|
|
1693 xm_destroy_instance (widget_instance* instance)
|
|
1694 {
|
|
1695 #ifdef DIALOGS_MOTIF
|
|
1696 /* It appears that this is used only for dialog boxes. */
|
|
1697 Widget widget = instance->widget;
|
|
1698 /* recycle the dialog boxes */
|
|
1699 /* Disable the recycling until we can find a way to have the dialog box
|
|
1700 get reasonable layout after we modify its contents. */
|
|
1701 if (0
|
|
1702 && XtClass (widget) == xmDialogShellWidgetClass)
|
|
1703 {
|
|
1704 destroyed_instance* dead_instance =
|
|
1705 make_destroyed_instance (instance->info->name,
|
|
1706 instance->info->type,
|
|
1707 instance->widget,
|
|
1708 instance->parent,
|
|
1709 instance->pop_up_p);
|
|
1710 dead_instance->next = all_destroyed_instances;
|
|
1711 all_destroyed_instances = dead_instance;
|
|
1712 XtUnmanageChild (first_child (instance->widget));
|
|
1713 XFlush (XtDisplay (instance->widget));
|
|
1714 XtAddCallback (instance->parent, XtNdestroyCallback,
|
|
1715 mark_dead_instance_destroyed, (XtPointer)dead_instance);
|
|
1716 }
|
|
1717 else
|
|
1718 {
|
|
1719 /* This might not be necessary now that the nosel is attached to
|
|
1720 popdown instead of destroy, but it can't hurt. */
|
|
1721 XtRemoveCallback (instance->widget, XtNdestroyCallback,
|
|
1722 xm_nosel_callback, (XtPointer)instance);
|
|
1723
|
|
1724 XtDestroyWidget (instance->widget);
|
|
1725 }
|
|
1726 #endif /* DIALOGS_MOTIF */
|
|
1727 }
|
|
1728
|
|
1729 /* popup utility */
|
|
1730 #ifdef MENUBARS_MOTIF
|
|
1731
|
|
1732 void
|
|
1733 xm_popup_menu (Widget widget, XEvent *event)
|
|
1734 {
|
|
1735 if (event->type == ButtonPress || event->type == ButtonRelease)
|
|
1736 {
|
|
1737 /* This is so totally ridiculous: there's NO WAY to tell Motif
|
|
1738 that *any* button can select a menu item. Only one button
|
|
1739 can have that honor.
|
|
1740 */
|
|
1741 char *trans = 0;
|
|
1742 if (event->xbutton.state & Button5Mask) trans = "<Btn5Down>";
|
|
1743 else if (event->xbutton.state & Button4Mask) trans = "<Btn4Down>";
|
|
1744 else if (event->xbutton.state & Button3Mask) trans = "<Btn3Down>";
|
|
1745 else if (event->xbutton.state & Button2Mask) trans = "<Btn2Down>";
|
|
1746 else if (event->xbutton.state & Button1Mask) trans = "<Btn1Down>";
|
|
1747 if (trans) XtVaSetValues (widget, XmNmenuPost, trans, 0);
|
|
1748 XmMenuPosition (widget, (XButtonPressedEvent *) event);
|
|
1749 }
|
|
1750 XtManageChild (widget);
|
|
1751 }
|
|
1752
|
|
1753 #endif
|
|
1754
|
|
1755 #ifdef DIALOGS_MOTIF
|
|
1756
|
|
1757 static void
|
|
1758 set_min_dialog_size (Widget w)
|
|
1759 {
|
|
1760 short width;
|
|
1761 short height;
|
|
1762 XtVaGetValues (w, XmNwidth, &width, XmNheight, &height, 0);
|
|
1763 XtVaSetValues (w, XmNminWidth, width, XmNminHeight, height, 0);
|
|
1764 }
|
|
1765
|
|
1766 #endif
|
|
1767
|
|
1768 void
|
|
1769 xm_pop_instance (widget_instance* instance, Boolean up)
|
|
1770 {
|
|
1771 Widget widget = instance->widget;
|
|
1772
|
|
1773 #ifdef DIALOGS_MOTIF
|
|
1774 if (XtClass (widget) == xmDialogShellWidgetClass)
|
|
1775 {
|
|
1776 Widget widget_to_manage = first_child (widget);
|
|
1777 if (up)
|
|
1778 {
|
|
1779 XtManageChild (widget_to_manage);
|
|
1780 set_min_dialog_size (widget);
|
|
1781 XmProcessTraversal(widget, XmTRAVERSE_CURRENT);
|
|
1782 }
|
|
1783 else
|
|
1784 XtUnmanageChild (widget_to_manage);
|
|
1785 }
|
|
1786 else
|
|
1787 #endif
|
|
1788 {
|
|
1789 if (up)
|
|
1790 XtManageChild (widget);
|
|
1791 else
|
|
1792 XtUnmanageChild (widget);
|
|
1793 }
|
|
1794 }
|
|
1795
|
|
1796
|
|
1797 /* motif callback */
|
|
1798
|
|
1799 enum do_call_type { pre_activate, selection, no_selection, post_activate };
|
|
1800
|
|
1801 static void
|
|
1802 do_call (Widget widget, XtPointer closure, enum do_call_type type)
|
|
1803 {
|
|
1804 XtPointer user_data;
|
|
1805 widget_instance* instance = (widget_instance*)closure;
|
|
1806 Widget instance_widget;
|
|
1807 LWLIB_ID id;
|
|
1808
|
|
1809 if (!instance)
|
|
1810 return;
|
|
1811 if (widget->core.being_destroyed)
|
|
1812 return;
|
|
1813
|
|
1814 instance_widget = instance->widget;
|
|
1815 if (!instance_widget)
|
|
1816 return;
|
|
1817
|
|
1818 id = instance->info->id;
|
|
1819 user_data = NULL;
|
|
1820 XtVaGetValues (widget, XmNuserData, &user_data, NULL);
|
|
1821 switch (type)
|
|
1822 {
|
|
1823 case pre_activate:
|
|
1824 if (instance->info->pre_activate_cb)
|
|
1825 instance->info->pre_activate_cb (widget, id, user_data);
|
|
1826 break;
|
|
1827 case selection:
|
|
1828 if (instance->info->selection_cb)
|
|
1829 instance->info->selection_cb (widget, id, user_data);
|
|
1830 break;
|
|
1831 case no_selection:
|
|
1832 if (instance->info->selection_cb)
|
|
1833 instance->info->selection_cb (widget, id, (XtPointer) -1);
|
|
1834 break;
|
|
1835 case post_activate:
|
|
1836 if (instance->info->post_activate_cb)
|
|
1837 instance->info->post_activate_cb (widget, id, user_data);
|
|
1838 break;
|
|
1839 default:
|
|
1840 abort ();
|
|
1841 }
|
|
1842 }
|
|
1843
|
|
1844 /* Like lw_internal_update_other_instances except that it does not do
|
|
1845 anything if its shell parent is not managed. This is to protect
|
|
1846 lw_internal_update_other_instances to dereference freed memory
|
|
1847 if the widget was ``destroyed'' by caching it in the all_destroyed_instances
|
|
1848 list */
|
|
1849 static void
|
|
1850 xm_internal_update_other_instances (Widget widget, XtPointer closure,
|
|
1851 XtPointer call_data)
|
|
1852 {
|
|
1853 Widget parent;
|
|
1854 for (parent = widget; parent; parent = XtParent (parent))
|
|
1855 if (XtIsShell (parent))
|
|
1856 break;
|
|
1857 else if (!XtIsManaged (parent))
|
|
1858 return;
|
|
1859 lw_internal_update_other_instances (widget, closure, call_data);
|
|
1860 }
|
|
1861
|
|
1862 static void
|
|
1863 xm_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
1864 {
|
|
1865 #if !defined (ENERGIZE) && (defined (MENUBARS_MOTIF) || defined (DIALOGS_MOTIF))
|
|
1866 /* We want the selected status to change only when we decide it
|
|
1867 should change. Yuck but correct. */
|
|
1868 if (XtClass (widget) == xmToggleButtonWidgetClass
|
|
1869 || XtClass (widget) == xmToggleButtonGadgetClass)
|
|
1870 {
|
|
1871 Boolean check;
|
|
1872 XtVaGetValues (widget, XmNset, &check, 0);
|
|
1873 XtVaSetValues (widget, XmNset, !check, 0);
|
|
1874 }
|
|
1875 #endif
|
|
1876 lw_internal_update_other_instances (widget, closure, call_data);
|
|
1877 do_call (widget, closure, selection);
|
|
1878 }
|
|
1879
|
|
1880 #ifdef DIALOGS_MOTIF
|
|
1881
|
|
1882 static void
|
|
1883 xm_nosel_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
1884 {
|
|
1885 /* This callback is only called when a dialog box is dismissed with the wm's
|
|
1886 destroy button (WM_DELETE_WINDOW.) We want the dialog box to be destroyed
|
|
1887 in that case, not just unmapped, so that it releases its keyboard grabs.
|
|
1888 But there are problems with running our callbacks while the widget is in
|
|
1889 the process of being destroyed, so we set XmNdeleteResponse to XmUNMAP
|
|
1890 instead of XmDESTROY and then destroy it ourself after having run the
|
|
1891 callback.
|
|
1892 */
|
|
1893 do_call (widget, closure, no_selection);
|
|
1894 XtDestroyWidget (widget);
|
|
1895 }
|
|
1896
|
|
1897 #endif
|
|
1898
|
|
1899 #ifdef MENUBARS_MOTIF
|
|
1900
|
|
1901 static void
|
|
1902 xm_pull_down_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
1903 {
|
|
1904 #if 0
|
|
1905 if (call_data)
|
|
1906 {
|
|
1907 /* new behavior for incremental menu construction */
|
|
1908
|
|
1909 }
|
|
1910 else
|
|
1911 #endif
|
|
1912 do_call (widget, closure, pre_activate);
|
|
1913 }
|
|
1914
|
|
1915 #if 0
|
|
1916 static void
|
|
1917 xm_pop_down_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
1918 {
|
|
1919 do_call (widget, closure, post_activate);
|
|
1920 }
|
|
1921 #endif /* 0 */
|
|
1922
|
|
1923 #endif /* MENUBARS_MOTIF */
|
|
1924
|
|
1925 #ifdef SCROLLBARS_MOTIF
|
|
1926 static void
|
|
1927 xm_scrollbar_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
1928 {
|
|
1929 widget_instance *instance = (widget_instance *) closure;
|
|
1930 LWLIB_ID id;
|
|
1931 XmScrollBarCallbackStruct *data =
|
|
1932 (XmScrollBarCallbackStruct *) call_data;
|
|
1933 scroll_event event_data;
|
|
1934 scrollbar_values *val =
|
|
1935 (scrollbar_values *) instance->info->val->scrollbar_data;
|
|
1936 double percent;
|
|
1937
|
|
1938 if (!instance || widget->core.being_destroyed)
|
|
1939 return;
|
|
1940
|
|
1941 id = instance->info->id;
|
|
1942
|
|
1943 percent = (double) (data->value - 1) / (double) (INT_MAX - 1);
|
|
1944 event_data.slider_value =
|
|
1945 (int) (percent * (double) (val->maximum - val->minimum)) + val->minimum;
|
|
1946
|
|
1947 if (event_data.slider_value > (val->maximum - val->slider_size))
|
|
1948 event_data.slider_value = val->maximum - val->slider_size;
|
|
1949 else if (event_data.slider_value < 1)
|
|
1950 event_data.slider_value = 1;
|
|
1951
|
|
1952 if (data->event)
|
|
1953 {
|
|
1954 switch (data->event->xany.type)
|
|
1955 {
|
|
1956 case KeyPress:
|
|
1957 case KeyRelease:
|
|
1958 event_data.time = data->event->xkey.time;
|
|
1959 break;
|
|
1960 case ButtonPress:
|
|
1961 case ButtonRelease:
|
|
1962 event_data.time = data->event->xbutton.time;
|
|
1963 break;
|
|
1964 case MotionNotify:
|
|
1965 event_data.time = data->event->xmotion.time;
|
|
1966 break;
|
|
1967 case EnterNotify:
|
|
1968 case LeaveNotify:
|
|
1969 event_data.time = data->event->xcrossing.time;
|
|
1970 break;
|
|
1971 default:
|
|
1972 event_data.time = 0;
|
|
1973 break;
|
|
1974 }
|
|
1975 }
|
|
1976 else
|
|
1977 event_data.time = 0;
|
|
1978
|
|
1979 switch (data->reason)
|
|
1980 {
|
|
1981 case XmCR_DECREMENT:
|
|
1982 event_data.action = SCROLLBAR_LINE_UP;
|
|
1983 break;
|
|
1984 case XmCR_INCREMENT:
|
|
1985 event_data.action = SCROLLBAR_LINE_DOWN;
|
|
1986 break;
|
|
1987 case XmCR_PAGE_DECREMENT:
|
|
1988 event_data.action = SCROLLBAR_PAGE_UP;
|
|
1989 break;
|
|
1990 case XmCR_PAGE_INCREMENT:
|
|
1991 event_data.action = SCROLLBAR_PAGE_DOWN;
|
|
1992 break;
|
|
1993 case XmCR_TO_TOP:
|
|
1994 event_data.action = SCROLLBAR_TOP;
|
|
1995 break;
|
|
1996 case XmCR_TO_BOTTOM:
|
|
1997 event_data.action = SCROLLBAR_BOTTOM;
|
|
1998 break;
|
|
1999 case XmCR_DRAG:
|
|
2000 event_data.action = SCROLLBAR_DRAG;
|
|
2001 break;
|
|
2002 case XmCR_VALUE_CHANGED:
|
|
2003 event_data.action = SCROLLBAR_CHANGE;
|
|
2004 break;
|
|
2005 default:
|
|
2006 event_data.action = SCROLLBAR_CHANGE;
|
|
2007 break;
|
|
2008 }
|
|
2009
|
|
2010 if (instance->info->pre_activate_cb)
|
|
2011 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
|
|
2012 }
|
|
2013 #endif /* SCROLLBARS_MOTIF */
|
|
2014
|
|
2015
|
|
2016 /* set the keyboard focus */
|
|
2017 void
|
|
2018 xm_set_keyboard_focus (Widget parent, Widget w)
|
|
2019 {
|
|
2020 XmProcessTraversal (w, XmTRAVERSE_CURRENT);
|
|
2021 /* At some point we believed that it was necessary to use XtSetKeyboardFocus
|
|
2022 instead of XmProcessTraversal when using Motif >= 1.2.1, but that's bogus.
|
|
2023 Presumably the problem was elsewhere, and is now gone...
|
|
2024 */
|
|
2025 }
|