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