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 #ifndef ENERGIZE
|
|
380 XtAddCallback (widget, XmNvalueChangedCallback, xm_generic_callback,
|
|
381 instance);
|
|
382 #else
|
165
|
383 XtAddCallback (widget, XmNvalueChangedCallback,
|
|
384 xm_internal_update_other_instances, instance);
|
|
385 #endif
|
|
386 XtSetArg (al [0], XmNset, val->selected);
|
|
387 XtSetArg (al [1], XmNalignment, XmALIGNMENT_BEGINNING);
|
|
388 XtSetValues (widget, al, 2);
|
0
|
389 }
|
|
390
|
|
391 static void
|
|
392 xm_update_radiobox (widget_instance* instance, Widget widget,
|
|
393 widget_value* val)
|
|
394 {
|
|
395 Widget toggle;
|
|
396 widget_value* cur;
|
|
397
|
|
398 /* update the callback */
|
|
399 XtRemoveAllCallbacks (widget, XmNentryCallback);
|
|
400 XtAddCallback (widget, XmNentryCallback, xm_generic_callback, instance);
|
|
401
|
|
402 /* first update all the toggles */
|
|
403 /* Energize kernel interface is currently bad. It sets the selected widget
|
|
404 with the selected flag but returns it by its name. So we currently
|
|
405 have to support both setting the selection with the selected slot
|
|
406 of val contents and setting it with the "value" slot of val. The latter
|
|
407 has a higher priority. This to be removed when the kernel is fixed. */
|
|
408 for (cur = val->contents; cur; cur = cur->next)
|
|
409 {
|
|
410 toggle = XtNameToWidget (widget, cur->value);
|
|
411 if (toggle)
|
|
412 {
|
165
|
413 Arg al [2];
|
|
414 XtSetArg (al [0], XmNsensitive, cur->enabled);
|
|
415 XtSetArg (al [1], XmNset, (!val->value && cur->selected ? cur->selected : False));
|
|
416 XtSetValues (toggle, al, 2);
|
0
|
417 }
|
|
418 }
|
|
419
|
|
420 /* The selected was specified by the value slot */
|
|
421 if (val->value)
|
|
422 {
|
|
423 toggle = XtNameToWidget (widget, val->value);
|
|
424 if (toggle)
|
165
|
425 {
|
|
426 Arg al [1];
|
|
427 XtSetArg (al [0], XmNset, True);
|
|
428 XtSetValues (toggle, al, 1);
|
|
429 }
|
0
|
430 }
|
|
431 }
|
|
432
|
|
433 #ifdef MENUBARS_MOTIF
|
|
434
|
|
435 /* update a popup menu, pulldown menu or a menubar */
|
|
436 static void
|
|
437 make_menu_in_widget (widget_instance* instance, Widget widget,
|
|
438 widget_value* val)
|
|
439 {
|
|
440 Widget* children = 0;
|
|
441 int num_children;
|
|
442 int child_index;
|
|
443 widget_value* cur;
|
|
444 Widget button = 0;
|
|
445 Widget menu;
|
|
446 Arg al [256];
|
|
447 int ac;
|
165
|
448 Boolean menubar_p = False;
|
0
|
449
|
|
450 /* Allocate the children array */
|
|
451 for (num_children = 0, cur = val; cur; num_children++, cur = cur->next);
|
|
452 children = (Widget*)XtMalloc (num_children * sizeof (Widget));
|
|
453
|
|
454 /* tricky way to know if this RowColumn is a menubar or a pulldown... */
|
165
|
455 XtSetArg (al [0], XmNisHomogeneous, &menubar_p);
|
|
456 XtGetValues (widget, al, 1);
|
0
|
457
|
|
458 /* add the unmap callback for popups and pulldowns */
|
|
459 /*** this sounds bogus ***/
|
|
460 /* probably because it is -- cet */
|
|
461 /*
|
|
462 if (!menubar_p)
|
|
463 XtAddCallback (XtParent (widget), XmNpopdownCallback,
|
|
464 xm_pop_down_callback, (XtPointer)instance);
|
|
465 */
|
|
466
|
|
467 num_children = 0;
|
|
468 for (child_index = 0, cur = val; cur; child_index++, cur = cur->next)
|
|
469 {
|
|
470 ac = 0;
|
|
471 button = 0;
|
80
|
472 XtSetArg (al [ac], XmNsensitive, cur->enabled); ac++;
|
|
473 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
|
|
474 XtSetArg (al [ac], XmNuserData, cur->call_data); ac++;
|
0
|
475
|
|
476 switch (cur->type)
|
|
477 {
|
|
478 case PUSHRIGHT_TYPE:
|
|
479 /* A pushright marker which is not needed for the real Motif
|
|
480 menubar. */
|
|
481 break;
|
|
482 case SEPARATOR_TYPE:
|
|
483 ac = 0;
|
|
484 if (cur->value)
|
|
485 {
|
|
486 /* #### - xlwmenu.h supports several types that motif does
|
|
487 not. Also, motif supports pixmaps w/ type NO_LINE and
|
|
488 lwlib provides no way to access that functionality. --Stig */
|
|
489 XtSetArg (al [ac], XmNseparatorType, cur->value), ac++;
|
|
490 }
|
|
491 button = XmCreateSeparator (widget, "separator", al, ac);
|
|
492 break;
|
|
493 case CASCADE_TYPE:
|
|
494 menu = XmCreatePulldownMenu (widget, "pulldown", NULL, 0);
|
|
495 make_menu_in_widget (instance, menu, cur->contents);
|
|
496 XtSetArg (al [ac], XmNsubMenuId, menu); ac++;
|
|
497 button = XmCreateCascadeButton (widget, cur->name, al, ac);
|
|
498
|
|
499 xm_update_label (instance, button, cur);
|
|
500
|
|
501 XtAddCallback (button, XmNcascadingCallback, xm_pull_down_callback,
|
|
502 (XtPointer)instance);
|
|
503 break;
|
|
504 default:
|
|
505 if (menubar_p)
|
|
506 button = XmCreateCascadeButton (widget, cur->name, al, ac);
|
|
507 else if (!cur->call_data)
|
|
508 button = XmCreateLabel (widget, cur->name, al, ac);
|
|
509 else if (cur->type == TOGGLE_TYPE || cur->type == RADIO_TYPE)
|
|
510 {
|
165
|
511 XtSetArg (al [ac], XmNindicatorType,
|
|
512 (cur->type == TOGGLE_TYPE ?
|
|
513 XmN_OF_MANY : XmONE_OF_MANY)); ac++;
|
0
|
514 XtSetArg (al [ac], XmNvisibleWhenOff, True); ac++;
|
|
515 button = XmCreateToggleButtonGadget (widget, cur->name, al, ac);
|
|
516 }
|
|
517 else
|
|
518 button = XmCreatePushButtonGadget (widget, cur->name, al, ac);
|
|
519
|
|
520 xm_update_label (instance, button, cur);
|
|
521
|
|
522 /* don't add a callback to a simple label */
|
|
523 if (cur->type == TOGGLE_TYPE || cur->type == RADIO_TYPE)
|
|
524 xm_update_toggle (instance, button, cur);
|
|
525 else if (cur->call_data)
|
|
526 XtAddCallback (button, XmNactivateCallback, xm_generic_callback,
|
|
527 (XtPointer)instance);
|
|
528 } /* switch (cur->type) */
|
|
529
|
|
530 if (button)
|
|
531 children [num_children++] = button;
|
|
532 }
|
|
533
|
|
534 /* Last entry is the help button. This used be done after managing
|
|
535 the buttons. The comment claimed that it had to be done this way
|
|
536 otherwise the menubar ended up only 4 pixels high. That must
|
|
537 have been in the Old World. In the New World it stays the proper
|
|
538 height if you don't manage them until after you set this and as a
|
|
539 bonus the Help menu ends up where it is supposed to. */
|
|
540 if (button)
|
|
541 {
|
|
542 ac = 0;
|
|
543 XtSetArg (al [ac], XmNmenuHelpWidget, button); ac++;
|
|
544 XtSetValues (widget, al, ac);
|
|
545 }
|
|
546
|
|
547 if (num_children)
|
|
548 XtManageChildren (children, num_children);
|
|
549
|
|
550 XtFree ((char *) children);
|
|
551 }
|
|
552
|
|
553 static void
|
|
554 update_one_menu_entry (widget_instance* instance, Widget widget,
|
|
555 widget_value* val, Boolean deep_p)
|
|
556 {
|
165
|
557 Arg al [2];
|
0
|
558 Widget menu;
|
|
559 widget_value* contents;
|
|
560
|
|
561 if (val->change == NO_CHANGE)
|
|
562 return;
|
|
563
|
|
564 /* update the sensitivity and userdata */
|
|
565 /* Common to all widget types */
|
165
|
566 XtSetArg (al [0], XmNsensitive, val->enabled);
|
|
567 XtSetArg (al [1], XmNuserData, val->call_data);
|
|
568 XtSetValues (widget, al, 2);
|
0
|
569
|
|
570 /* update the menu button as a label. */
|
|
571 if (val->change >= VISIBLE_CHANGE)
|
|
572 {
|
|
573 xm_update_label (instance, widget, val);
|
|
574 if (XtClass (widget) == xmToggleButtonWidgetClass
|
|
575 || XtClass (widget) == xmToggleButtonGadgetClass)
|
|
576 {
|
|
577 xm_update_toggle (instance, widget, val);
|
|
578 }
|
|
579 }
|
|
580
|
|
581
|
|
582 /* update the pulldown/pullaside as needed */
|
|
583 menu = NULL;
|
165
|
584 XtSetArg (al [0], XmNsubMenuId, &menu);
|
|
585 XtGetValues (widget, al, 1);
|
0
|
586
|
|
587 contents = val->contents;
|
|
588
|
|
589 if (!menu)
|
|
590 {
|
|
591 if (contents)
|
|
592 {
|
|
593 menu = XmCreatePulldownMenu (widget, "pulldown", NULL, 0);
|
|
594 make_menu_in_widget (instance, menu, contents);
|
|
595 ac = 0;
|
|
596 XtSetArg (al [ac], XmNsubMenuId, menu); ac++;
|
|
597 XtSetValues (widget, al, ac);
|
|
598 }
|
|
599 }
|
|
600 else if (!contents)
|
|
601 {
|
|
602 ac = 0;
|
|
603 XtSetArg (al [ac], XmNsubMenuId, NULL); ac++;
|
|
604 XtSetValues (widget, al, ac);
|
|
605 XtDestroyWidget (menu);
|
|
606 }
|
|
607 else if (deep_p && contents->change != NO_CHANGE)
|
|
608 xm_update_menu (instance, menu, val, 1);
|
|
609 }
|
|
610
|
|
611 static void
|
|
612 xm_update_menu (widget_instance* instance, Widget widget, widget_value* val,
|
|
613 Boolean deep_p)
|
|
614 {
|
|
615 /* Widget is a RowColumn widget whose contents have to be updated
|
|
616 * to reflect the list of items in val->contents */
|
|
617 if (val->contents->change == STRUCTURAL_CHANGE)
|
|
618 {
|
|
619 destroy_all_children (widget);
|
|
620 make_menu_in_widget (instance, widget, val->contents);
|
|
621 }
|
|
622 else
|
|
623 {
|
|
624 /* Update all the buttons of the RowColumn in order. */
|
|
625 Widget* children;
|
|
626 unsigned int num_children;
|
|
627 int i;
|
|
628 widget_value *cur = 0;
|
|
629
|
|
630 children = XtCompositeChildren (widget, &num_children);
|
|
631 if (children)
|
|
632 {
|
|
633 for (i = 0, cur = val->contents; i < num_children; i++)
|
|
634 {
|
|
635 if (!cur)
|
|
636 abort ();
|
|
637 /* skip if this is a pushright marker or a separator */
|
|
638 if (cur->type == PUSHRIGHT_TYPE || cur->type == SEPARATOR_TYPE)
|
|
639 {
|
|
640 cur = cur->next;
|
|
641 #if 0
|
|
642 /* #### - this could puke if you have a separator as the
|
|
643 last item on a pullright menu. */
|
|
644 if (!cur)
|
|
645 abort ();
|
|
646 #else
|
|
647 if (!cur)
|
|
648 continue;
|
|
649 #endif
|
|
650 }
|
|
651 if (children [i]->core.being_destroyed
|
|
652 || strcmp (XtName (children [i]), cur->name))
|
|
653 continue;
|
|
654 update_one_menu_entry (instance, children [i], cur, deep_p);
|
|
655 cur = cur->next;
|
|
656 }
|
|
657 XtFree ((char *) children);
|
|
658 }
|
|
659 if (cur)
|
|
660 abort ();
|
|
661 }
|
|
662 }
|
|
663
|
|
664 #endif /* MENUBARS_MOTIF */
|
|
665
|
|
666
|
|
667 #ifdef DIALOGS_MOTIF
|
|
668
|
|
669 /* update text widgets */
|
|
670
|
|
671 static void
|
|
672 xm_update_text (widget_instance* instance, Widget widget, widget_value* val)
|
|
673 {
|
80
|
674 XmTextSetString (widget, val->value ? val->value : "");
|
0
|
675 XtRemoveAllCallbacks (widget, XmNactivateCallback);
|
|
676 XtAddCallback (widget, XmNactivateCallback, xm_generic_callback, instance);
|
|
677 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback);
|
|
678 XtAddCallback (widget, XmNvalueChangedCallback,
|
|
679 xm_internal_update_other_instances, instance);
|
|
680 }
|
|
681
|
|
682 static void
|
|
683 xm_update_text_field (widget_instance* instance, Widget widget,
|
|
684 widget_value* val)
|
|
685 {
|
80
|
686 XmTextFieldSetString (widget, val->value ? val->value : "");
|
0
|
687 XtRemoveAllCallbacks (widget, XmNactivateCallback);
|
|
688 XtAddCallback (widget, XmNactivateCallback, xm_generic_callback, instance);
|
|
689 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback);
|
|
690 XtAddCallback (widget, XmNvalueChangedCallback,
|
|
691 xm_internal_update_other_instances, instance);
|
|
692 }
|
|
693
|
|
694 #endif /* DIALOGS_MOTIF */
|
|
695
|
|
696 #ifdef SCROLLBARS_MOTIF
|
|
697
|
|
698 /*
|
|
699 * If this function looks like it does a lot more work than it needs to,
|
|
700 * you're right. Blame the Motif scrollbar for not being smart about
|
|
701 * updating its appearance.
|
|
702 */
|
|
703 static void
|
|
704 xm_update_scrollbar (widget_instance *instance, Widget widget,
|
|
705 widget_value *val)
|
|
706 {
|
|
707 if (val->scrollbar_data)
|
|
708 {
|
|
709 scrollbar_values *data = val->scrollbar_data;
|
|
710 int widget_sliderSize, widget_val;
|
|
711 int new_sliderSize, new_value;
|
|
712 double percent;
|
|
713 double h_water, l_water;
|
165
|
714 Arg al [4];
|
0
|
715
|
165
|
716 /* First size and position the scrollbar widget. */
|
|
717 XtSetArg (al [0], XtNx, data->scrollbar_x);
|
|
718 XtSetArg (al [1], XtNy, data->scrollbar_y);
|
|
719 XtSetArg (al [2], XtNwidth, data->scrollbar_width);
|
|
720 XtSetArg (al [3], XtNheight, data->scrollbar_height);
|
|
721 XtSetValues (widget, al, 4);
|
0
|
722
|
165
|
723 /* Now size the scrollbar's slider. */
|
|
724 XtSetArg (al [0], XmNsliderSize, &widget_sliderSize);
|
|
725 XtSetArg (al [1], XmNvalue, &widget_val);
|
|
726 XtGetValues (widget, al, 2);
|
0
|
727
|
|
728 percent = (double) data->slider_size /
|
|
729 (double) (data->maximum - data->minimum);
|
|
730 new_sliderSize = (int) ((double) (INT_MAX - 1) * percent);
|
|
731
|
|
732 percent = (double) (data->slider_position - data->minimum) /
|
|
733 (double) (data->maximum - data->minimum);
|
|
734 new_value = (int) ((double) (INT_MAX - 1) * percent);
|
|
735
|
|
736 if (new_sliderSize > (INT_MAX - 1))
|
|
737 new_sliderSize = INT_MAX - 1;
|
165
|
738 else if (new_sliderSize < 1)
|
0
|
739 new_sliderSize = 1;
|
|
740
|
|
741 if (new_value > (INT_MAX - new_sliderSize))
|
|
742 new_value = INT_MAX - new_sliderSize;
|
|
743 else if (new_value < 1)
|
|
744 new_value = 1;
|
|
745
|
|
746 h_water = 1.05;
|
|
747 l_water = 0.95;
|
|
748 if (new_sliderSize != widget_sliderSize || new_value != widget_val)
|
|
749 {
|
|
750 int force = ((INT_MAX - widget_sliderSize - widget_val)
|
|
751 ? 0
|
|
752 : (INT_MAX - new_sliderSize - new_value));
|
|
753
|
|
754 if (force
|
|
755 || (double)new_sliderSize < (l_water * (double)widget_sliderSize)
|
|
756 || (double)new_sliderSize > (h_water * (double)widget_sliderSize)
|
|
757 || (double)new_value < (l_water * (double)widget_val)
|
|
758 || (double)new_value > (h_water * (double)widget_val))
|
|
759 {
|
|
760 XmScrollBarSetValues (widget, new_value, new_sliderSize, 1, 1,
|
|
761 False);
|
|
762 }
|
|
763 }
|
|
764 }
|
|
765 }
|
|
766
|
|
767 #endif /* SCROLLBARS_MOTIF */
|
|
768
|
|
769
|
|
770 /* update a motif widget */
|
|
771
|
|
772 void
|
|
773 xm_update_one_widget (widget_instance* instance, Widget widget,
|
|
774 widget_value* val, Boolean deep_p)
|
|
775 {
|
|
776 WidgetClass class;
|
165
|
777 Arg al [2];
|
0
|
778
|
|
779 /* Mark as not edited */
|
|
780 val->edited = False;
|
|
781
|
|
782 /* Common to all widget types */
|
165
|
783 XtSetArg (al [0], XmNsensitive, val->enabled);
|
|
784 XtSetArg (al [1], XmNuserData, val->call_data);
|
|
785 XtSetValues (widget, al, 2);
|
0
|
786
|
|
787 #if defined (DIALOGS_MOTIF) || defined (MENUBARS_MOTIF)
|
|
788 /* Common to all label like widgets */
|
|
789 if (XtIsSubclass (widget, xmLabelWidgetClass))
|
|
790 xm_update_label (instance, widget, val);
|
|
791 #endif
|
|
792
|
|
793 class = XtClass (widget);
|
|
794 /* Class specific things */
|
|
795 if (class == xmPushButtonWidgetClass ||
|
|
796 class == xmArrowButtonWidgetClass)
|
|
797 {
|
|
798 xm_update_pushbutton (instance, widget, val);
|
|
799 }
|