Mercurial > emacs
annotate lwlib/lwlib-Xm.c @ 11723:a812bce4aef0
Make sure CDPATH doesn't mess up PWD check.
Check whether X bitmaps are in X11/bitmaps instead of bitmaps.
Use fmod instead of logb in -lm check.
author | David J. MacKenzie <djm@gnu.org> |
---|---|
date | Sat, 06 May 1995 21:27:16 +0000 |
parents | efaaecd960ae |
children | 10a973a88e87 |
rev | line source |
---|---|
5626 | 1 /* The lwlib interface to Motif widgets. |
2 Copyright (C) 1992 Lucid, Inc. | |
3 | |
4 This file is part of the Lucid Widget Library. | |
5 | |
6 The Lucid Widget Library is free software; you can redistribute it and/or | |
7 modify it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 The Lucid Widget Library is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 #include <stdlib.h> | |
21 #include <unistd.h> | |
22 #include <string.h> | |
23 #include <stdio.h> | |
24 | |
25 #include <X11/StringDefs.h> | |
26 #include <X11/IntrinsicP.h> | |
27 #include <X11/ObjectP.h> | |
28 #include <X11/CoreP.h> | |
29 #include <X11/CompositeP.h> | |
30 | |
31 #include "lwlib-Xm.h" | |
32 #include "lwlib-utils.h" | |
33 | |
34 #include <Xm/BulletinB.h> | |
35 #include <Xm/CascadeB.h> | |
36 #include <Xm/DrawingA.h> | |
37 #include <Xm/FileSB.h> | |
38 #include <Xm/Label.h> | |
39 #include <Xm/List.h> | |
8784 | 40 #include <Xm/MainW.h> |
5626 | 41 #include <Xm/MenuShell.h> |
42 #include <Xm/MessageB.h> | |
8784 | 43 #include <Xm/PanedW.h> |
5626 | 44 #include <Xm/PushB.h> |
45 #include <Xm/PushBG.h> | |
46 #include <Xm/ArrowB.h> | |
47 #include <Xm/SelectioB.h> | |
48 #include <Xm/Text.h> | |
49 #include <Xm/TextF.h> | |
50 #include <Xm/ToggleB.h> | |
51 #include <Xm/ToggleBG.h> | |
52 #include <Xm/RowColumn.h> | |
53 #include <Xm/ScrolledW.h> | |
54 #include <Xm/Separator.h> | |
55 #include <Xm/DialogS.h> | |
56 #include <Xm/Form.h> | |
57 | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
58 static void xm_pull_down_callback (/* Widget, XtPointer, XtPointer */); |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
59 static void xm_internal_update_other_instances (/* Widget, XtPointer, |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
60 XtPointer */); |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
61 static void xm_generic_callback (/* Widget, XtPointer, XtPointer */); |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
62 static void xm_nosel_callback (/* Widget, XtPointer, XtPointer */); |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
63 static void xm_pop_down_callback (/* Widget, XtPointer, XtPointer */); |
5626 | 64 |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
65 static void xm_update_menu (/* widget_instance*, Widget, widget_value*, |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
66 Boolean) */); |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
67 |
5626 | 68 |
69 /* Structures to keep destroyed instances */ | |
70 typedef struct _destroyed_instance | |
71 { | |
72 char* name; | |
73 char* type; | |
74 Widget widget; | |
75 Widget parent; | |
76 Boolean pop_up_p; | |
77 struct _destroyed_instance* next; | |
78 } destroyed_instance; | |
79 | |
80 static destroyed_instance* | |
81 all_destroyed_instances = NULL; | |
82 | |
83 static destroyed_instance* | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
84 make_destroyed_instance (name, type, widget, parent, pop_up_p) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
85 char* name; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
86 char* type; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
87 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
88 Widget parent; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
89 Boolean pop_up_p; |
5626 | 90 { |
91 destroyed_instance* instance = | |
92 (destroyed_instance*)malloc (sizeof (destroyed_instance)); | |
8784 | 93 instance->name = safe_strdup (name); |
94 instance->type = safe_strdup (type); | |
5626 | 95 instance->widget = widget; |
96 instance->parent = parent; | |
97 instance->pop_up_p = pop_up_p; | |
98 instance->next = NULL; | |
99 return instance; | |
100 } | |
101 | |
102 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
103 free_destroyed_instance (instance) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
104 destroyed_instance* instance; |
5626 | 105 { |
106 free (instance->name); | |
107 free (instance->type); | |
108 free (instance); | |
109 } | |
110 | |
111 /* motif utility functions */ | |
112 Widget | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
113 first_child (widget) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
114 Widget widget; |
5626 | 115 { |
116 return ((CompositeWidget)widget)->composite.children [0]; | |
117 } | |
118 | |
119 Boolean | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
120 lw_motif_widget_p (widget) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
121 Widget widget; |
5626 | 122 { |
123 return | |
124 XtClass (widget) == xmDialogShellWidgetClass | |
125 || XmIsPrimitive (widget) || XmIsManager (widget) || XmIsGadget (widget); | |
126 } | |
127 | |
128 static XmString | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
129 resource_motif_string (widget, name) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
130 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
131 char* name; |
5626 | 132 { |
133 XtResource resource; | |
134 XmString result = 0; | |
135 | |
136 resource.resource_name = name; | |
137 resource.resource_class = XmCXmString; | |
138 resource.resource_type = XmRXmString; | |
139 resource.resource_size = sizeof (XmString); | |
140 resource.resource_offset = 0; | |
141 resource.default_type = XtRImmediate; | |
142 resource.default_addr = 0; | |
143 | |
144 XtGetSubresources (widget, (XtPointer)&result, "dialogString", | |
145 "DialogString", &resource, 1, NULL, 0); | |
146 return result; | |
147 } | |
148 | |
149 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
150 destroy_all_children (widget) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
151 Widget widget; |
5626 | 152 { |
153 Widget* children; | |
154 unsigned int number; | |
155 int i; | |
156 | |
157 children = XtCompositeChildren (widget, &number); | |
158 if (children) | |
159 { | |
160 /* Unmanage all children and destroy them. They will only be | |
161 * really destroyed when we get out of DispatchEvent. */ | |
162 for (i = 0; i < number; i++) | |
163 { | |
164 Widget child = children [i]; | |
165 if (!child->core.being_destroyed) | |
166 { | |
167 XtUnmanageChild (child); | |
168 XtDestroyWidget (child); | |
169 } | |
170 } | |
171 XtFree ((char *) children); | |
172 } | |
173 } | |
174 | |
175 /* update the label of anything subclass of a label */ | |
176 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
177 xm_update_label (instance, widget, val) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
178 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
179 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
180 widget_value* val; |
5626 | 181 { |
182 XmString res_string = 0; | |
183 XmString built_string = 0; | |
184 XmString key_string = 0; | |
185 Arg al [256]; | |
186 int ac; | |
187 | |
188 ac = 0; | |
189 | |
190 if (val->value) | |
191 { | |
192 res_string = resource_motif_string (widget, val->value); | |
193 | |
194 if (res_string) | |
195 { | |
196 XtSetArg (al [ac], XmNlabelString, res_string); ac++; | |
197 } | |
198 else | |
199 { | |
200 built_string = | |
201 XmStringCreateLtoR (val->value, XmSTRING_DEFAULT_CHARSET); | |
202 XtSetArg (al [ac], XmNlabelString, built_string); ac++; | |
203 } | |
204 XtSetArg (al [ac], XmNlabelType, XmSTRING); ac++; | |
205 } | |
206 | |
207 if (val->key) | |
208 { | |
209 key_string = XmStringCreateLtoR (val->key, XmSTRING_DEFAULT_CHARSET); | |
210 XtSetArg (al [ac], XmNacceleratorText, key_string); ac++; | |
211 } | |
212 | |
213 if (ac) | |
214 XtSetValues (widget, al, ac); | |
215 | |
216 if (built_string) | |
217 XmStringFree (built_string); | |
218 | |
219 if (key_string) | |
220 XmStringFree (key_string); | |
221 } | |
222 | |
223 /* update of list */ | |
224 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
225 xm_update_list (instance, widget, val) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
226 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
227 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
228 widget_value* val; |
5626 | 229 { |
230 widget_value* cur; | |
231 int i; | |
232 XtRemoveAllCallbacks (widget, XmNsingleSelectionCallback); | |
233 XtAddCallback (widget, XmNsingleSelectionCallback, xm_generic_callback, | |
234 instance); | |
235 for (cur = val->contents, i = 0; cur; cur = cur->next) | |
236 if (cur->value) | |
237 { | |
238 XmString xmstr = XmStringCreate (cur->value, XmSTRING_DEFAULT_CHARSET); | |
239 i += 1; | |
240 XmListAddItem (widget, xmstr, 0); | |
241 if (cur->selected) | |
242 XmListSelectPos (widget, i, False); | |
243 XmStringFree (xmstr); | |
244 } | |
245 } | |
246 | |
247 /* update of buttons */ | |
248 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
249 xm_update_pushbutton (instance, widget, val) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
250 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
251 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
252 widget_value* val; |
5626 | 253 { |
254 XtVaSetValues (widget, XmNalignment, XmALIGNMENT_CENTER, 0); | |
255 XtRemoveAllCallbacks (widget, XmNactivateCallback); | |
256 XtAddCallback (widget, XmNactivateCallback, xm_generic_callback, instance); | |
257 } | |
258 | |
259 static void | |
260 xm_update_cascadebutton (widget_instance* instance, Widget widget, | |
261 widget_value* val) | |
262 { | |
263 /* Should also rebuild the menu by calling ...update_menu... */ | |
264 XtRemoveAllCallbacks (widget, XmNcascadingCallback); | |
265 XtAddCallback (widget, XmNcascadingCallback, xm_pull_down_callback, | |
266 instance); | |
267 } | |
268 | |
269 /* update toggle and radiobox */ | |
270 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
271 xm_update_toggle (instance, widget, val) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
272 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
273 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
274 widget_value* val; |
5626 | 275 { |
276 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback); | |
277 XtAddCallback (widget, XmNvalueChangedCallback, | |
278 xm_internal_update_other_instances, instance); | |
279 XtVaSetValues (widget, XmNset, val->selected, | |
280 XmNalignment, XmALIGNMENT_BEGINNING, 0); | |
281 } | |
282 | |
283 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
284 xm_update_radiobox (instance, widget, val) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
285 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
286 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
287 widget_value* val; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
288 |
5626 | 289 { |
290 Widget toggle; | |
291 widget_value* cur; | |
292 | |
293 /* update the callback */ | |
294 XtRemoveAllCallbacks (widget, XmNentryCallback); | |
295 XtAddCallback (widget, XmNentryCallback, xm_generic_callback, instance); | |
296 | |
297 /* first update all the toggles */ | |
298 /* Energize kernel interface is currently bad. It sets the selected widget | |
299 with the selected flag but returns it by its name. So we currently | |
300 have to support both setting the selection with the selected slot | |
301 of val contents and setting it with the "value" slot of val. The latter | |
302 has a higher priority. This to be removed when the kernel is fixed. */ | |
303 for (cur = val->contents; cur; cur = cur->next) | |
304 { | |
305 toggle = XtNameToWidget (widget, cur->value); | |
306 if (toggle) | |
307 { | |
308 XtVaSetValues (toggle, XmNsensitive, cur->enabled, 0); | |
309 if (!val->value && cur->selected) | |
310 XtVaSetValues (toggle, XmNset, cur->selected, 0); | |
311 if (val->value && strcmp (val->value, cur->value)) | |
312 XtVaSetValues (toggle, XmNset, False, 0); | |
313 } | |
314 } | |
315 | |
316 /* The selected was specified by the value slot */ | |
317 if (val->value) | |
318 { | |
319 toggle = XtNameToWidget (widget, val->value); | |
320 if (toggle) | |
321 XtVaSetValues (toggle, XmNset, True, 0); | |
322 } | |
323 } | |
324 | |
325 /* update a popup menu, pulldown menu or a menubar */ | |
326 static Boolean | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
327 all_dashes_p (s) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
328 char* s; |
5626 | 329 { |
330 char* t; | |
331 for (t = s; *t; t++) | |
332 if (*t != '-') | |
333 return False; | |
334 return True; | |
335 } | |
336 | |
337 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
338 make_menu_in_widget (instance, widget, val) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
339 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
340 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
341 widget_value* val; |
5626 | 342 { |
343 Widget* children = 0; | |
344 int num_children; | |
345 int child_index; | |
346 widget_value* cur; | |
347 Widget button = 0; | |
348 Widget menu; | |
349 Arg al [256]; | |
350 int ac; | |
351 Boolean menubar_p; | |
352 | |
353 /* Allocate the children array */ | |
354 for (num_children = 0, cur = val; cur; num_children++, cur = cur->next); | |
355 children = (Widget*)XtMalloc (num_children * sizeof (Widget)); | |
356 | |
357 /* tricky way to know if this RowColumn is a menubar or a pulldown... */ | |
358 menubar_p = False; | |
359 XtSetArg (al[0], XmNisHomogeneous, &menubar_p); | |
360 XtGetValues (widget, al, 1); | |
361 | |
362 /* add the unmap callback for popups and pulldowns */ | |
363 /*** this sounds bogus ***/ | |
364 if (!menubar_p) | |
365 XtAddCallback (XtParent (widget), XmNpopdownCallback, | |
366 xm_pop_down_callback, (XtPointer)instance); | |
367 | |
368 for (child_index = 0, cur = val; cur; child_index++, cur = cur->next) | |
369 { | |
370 ac = 0; | |
371 XtSetArg (al [ac], XmNsensitive, cur->enabled); ac++; | |
372 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++; | |
373 XtSetArg (al [ac], XmNuserData, cur->call_data); ac++; | |
374 | |
9835
d2250d1b0f48
(make_menu_in_widget): Differentiate a separator entry ("--") from a
Paul Reilly <pmr@pajato.com>
parents:
9825
diff
changeset
|
375 if (instance->pop_up_p && !cur->contents && !cur->call_data |
d2250d1b0f48
(make_menu_in_widget): Differentiate a separator entry ("--") from a
Paul Reilly <pmr@pajato.com>
parents:
9825
diff
changeset
|
376 && !all_dashes_p (cur->name)) |
9224
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
377 { |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
378 ac = 0; |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
379 XtSetArg (al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++; |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
380 button = XmCreateLabel (widget, cur->name, al, ac); |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
381 } |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
382 else if (all_dashes_p (cur->name)) |
5626 | 383 { |
384 button = XmCreateSeparator (widget, cur->name, NULL, 0); | |
385 } | |
386 else if (!cur->contents) | |
387 { | |
388 if (menubar_p) | |
389 button = XmCreateCascadeButton (widget, cur->name, al, ac); | |
390 else if (!cur->call_data) | |
391 button = XmCreateLabel (widget, cur->name, al, ac); | |
392 else | |
393 button = XmCreatePushButtonGadget (widget, cur->name, al, ac); | |
394 | |
395 xm_update_label (instance, button, cur); | |
396 | |
397 /* don't add a callback to a simple label */ | |
398 if (cur->call_data) | |
399 XtAddCallback (button, XmNactivateCallback, xm_generic_callback, | |
400 (XtPointer)instance); | |
401 } | |
402 else | |
403 { | |
11435
efaaecd960ae
(update_one_menu_entry, make_menu_in_widget):
Richard M. Stallman <rms@gnu.org>
parents:
11299
diff
changeset
|
404 menu = XmCreatePulldownMenu (widget, cur->name, NULL, 0); |
5626 | 405 make_menu_in_widget (instance, menu, cur->contents); |
406 XtSetArg (al [ac], XmNsubMenuId, menu); ac++; | |
407 button = XmCreateCascadeButton (widget, cur->name, al, ac); | |
408 | |
409 xm_update_label (instance, button, cur); | |
410 | |
411 XtAddCallback (button, XmNcascadingCallback, xm_pull_down_callback, | |
412 (XtPointer)instance); | |
413 } | |
414 | |
415 children [child_index] = button; | |
416 } | |
417 | |
418 XtManageChildren (children, num_children); | |
419 | |
420 /* Last entry is the help button. Has to be done after managing | |
421 * the buttons otherwise the menubar is only 4 pixels high... */ | |
422 if (button) | |
423 { | |
424 ac = 0; | |
425 XtSetArg (al [ac], XmNmenuHelpWidget, button); ac++; | |
426 XtSetValues (widget, al, ac); | |
427 } | |
428 | |
429 XtFree ((char *) children); | |
430 } | |
431 | |
432 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
433 update_one_menu_entry (instance, widget, val, deep_p) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
434 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
435 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
436 widget_value* val; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
437 Boolean deep_p; |
5626 | 438 { |
439 Arg al [256]; | |
440 int ac; | |
441 Widget menu; | |
442 widget_value* contents; | |
443 | |
444 if (val->change == NO_CHANGE) | |
445 return; | |
446 | |
447 /* update the sensitivity and userdata */ | |
448 /* Common to all widget types */ | |
449 XtVaSetValues (widget, | |
450 XmNsensitive, val->enabled, | |
451 XmNuserData, val->call_data, | |
452 0); | |
453 | |
454 /* update the menu button as a label. */ | |
455 if (val->change >= VISIBLE_CHANGE) | |
456 xm_update_label (instance, widget, val); | |
457 | |
458 /* update the pulldown/pullaside as needed */ | |
459 ac = 0; | |
460 menu = NULL; | |
461 XtSetArg (al [ac], XmNsubMenuId, &menu); ac++; | |
462 XtGetValues (widget, al, ac); | |
463 | |
464 contents = val->contents; | |
465 | |
466 if (!menu) | |
467 { | |
468 if (contents) | |
469 { | |
11435
efaaecd960ae
(update_one_menu_entry, make_menu_in_widget):
Richard M. Stallman <rms@gnu.org>
parents:
11299
diff
changeset
|
470 menu = XmCreatePulldownMenu (XtParent (widget), XtName (widget), NULL, 0); |
5626 | 471 make_menu_in_widget (instance, menu, contents); |
472 ac = 0; | |
473 XtSetArg (al [ac], XmNsubMenuId, menu); ac++; | |
474 XtSetValues (widget, al, ac); | |
475 } | |
476 } | |
477 else if (!contents) | |
478 { | |
479 ac = 0; | |
480 XtSetArg (al [ac], XmNsubMenuId, NULL); ac++; | |
481 XtSetValues (widget, al, ac); | |
482 XtDestroyWidget (menu); | |
483 } | |
484 else if (deep_p && contents->change != NO_CHANGE) | |
485 xm_update_menu (instance, menu, val, 1); | |
486 } | |
487 | |
488 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
489 xm_update_menu (instance, widget, val, deep_p) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
490 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
491 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
492 widget_value* val; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
493 Boolean deep_p; |
5626 | 494 { |
495 /* Widget is a RowColumn widget whose contents have to be updated | |
496 * to reflect the list of items in val->contents */ | |
497 if (val->contents->change == STRUCTURAL_CHANGE) | |
498 { | |
499 destroy_all_children (widget); | |
500 make_menu_in_widget (instance, widget, val->contents); | |
501 } | |
502 else | |
503 { | |
504 /* Update all the buttons of the RowColumn in order. */ | |
505 Widget* children; | |
506 unsigned int num_children; | |
507 int i; | |
508 widget_value* cur; | |
509 | |
510 children = XtCompositeChildren (widget, &num_children); | |
511 if (children) | |
512 { | |
513 for (i = 0, cur = val->contents; i < num_children; i++) | |
514 { | |
515 if (!cur) | |
516 abort (); | |
517 if (children [i]->core.being_destroyed | |
518 || strcmp (XtName (children [i]), cur->name)) | |
519 continue; | |
520 update_one_menu_entry (instance, children [i], cur, deep_p); | |
521 cur = cur->next; | |
522 } | |
523 XtFree ((char *) children); | |
524 } | |
525 if (cur) | |
526 abort (); | |
527 } | |
528 } | |
529 | |
530 | |
531 /* update text widgets */ | |
532 | |
533 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
534 xm_update_text (instance, widget, val) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
535 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
536 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
537 widget_value* val; |
5626 | 538 { |
539 XmTextSetString (widget, val->value ? val->value : ""); | |
540 XtRemoveAllCallbacks (widget, XmNactivateCallback); | |
541 XtAddCallback (widget, XmNactivateCallback, xm_generic_callback, instance); | |
542 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback); | |
543 XtAddCallback (widget, XmNvalueChangedCallback, | |
544 xm_internal_update_other_instances, instance); | |
545 } | |
546 | |
547 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
548 xm_update_text_field (instance, widget, val) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
549 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
550 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
551 widget_value* val; |
5626 | 552 { |
553 XmTextFieldSetString (widget, val->value ? val->value : ""); | |
554 XtRemoveAllCallbacks (widget, XmNactivateCallback); | |
555 XtAddCallback (widget, XmNactivateCallback, xm_generic_callback, instance); | |
556 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback); | |
557 XtAddCallback (widget, XmNvalueChangedCallback, | |
558 xm_internal_update_other_instances, instance); | |
559 } | |
560 | |
561 | |
562 /* update a motif widget */ | |
563 | |
564 void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
565 xm_update_one_widget (instance, widget, val, deep_p) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
566 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
567 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
568 widget_value* val; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
569 Boolean deep_p; |
5626 | 570 { |
571 WidgetClass class; | |
572 | |
573 /* Mark as not edited */ | |
574 val->edited = False; | |
575 | |
576 /* Common to all widget types */ | |
577 XtVaSetValues (widget, | |
578 XmNsensitive, val->enabled, | |
579 XmNuserData, val->call_data, | |
580 0); | |
581 | |
582 /* Common to all label like widgets */ | |
583 if (XtIsSubclass (widget, xmLabelWidgetClass)) | |
584 xm_update_label (instance, widget, val); | |
585 | |
586 class = XtClass (widget); | |
587 /* Class specific things */ | |
588 if (class == xmPushButtonWidgetClass || | |
589 class == xmArrowButtonWidgetClass) | |
590 { | |
591 xm_update_pushbutton (instance, widget, val); | |
592 } | |
593 else if (class == xmCascadeButtonWidgetClass) | |
594 { | |
595 xm_update_cascadebutton (instance, widget, val); | |
596 } | |
597 else if (class == xmToggleButtonWidgetClass | |
598 || class == xmToggleButtonGadgetClass) | |
599 { | |
600 xm_update_toggle (instance, widget, val); | |
601 } | |
602 else if (class == xmRowColumnWidgetClass) | |
603 { | |
604 Boolean radiobox = 0; | |
605 int ac = 0; | |
606 Arg al [1]; | |
607 | |
608 XtSetArg (al [ac], XmNradioBehavior, &radiobox); ac++; | |
609 XtGetValues (widget, al, ac); | |
610 | |
611 if (radiobox) | |
612 xm_update_radiobox (instance, widget, val); | |
613 else | |
614 xm_update_menu (instance, widget, val, deep_p); | |
615 } | |
616 else if (class == xmTextWidgetClass) | |
617 { | |
618 xm_update_text (instance, widget, val); | |
619 } | |
620 else if (class == xmTextFieldWidgetClass) | |
621 { | |
622 xm_update_text_field (instance, widget, val); | |
623 } | |
624 else if (class == xmListWidgetClass) | |
625 { | |
626 xm_update_list (instance, widget, val); | |
627 } | |
628 } | |
629 | |
630 /* getting the value back */ | |
631 void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
632 xm_update_one_value (instance, widget, val) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
633 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
634 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
635 widget_value* val; |
5626 | 636 { |
637 WidgetClass class = XtClass (widget); | |
638 widget_value *old_wv; | |
639 | |
640 /* copy the call_data slot into the "return" widget_value */ | |
641 for (old_wv = instance->info->val->contents; old_wv; old_wv = old_wv->next) | |
642 if (!strcmp (val->name, old_wv->name)) | |
643 { | |
644 val->call_data = old_wv->call_data; | |
645 break; | |
646 } | |
647 | |
648 if (class == xmToggleButtonWidgetClass || class == xmToggleButtonGadgetClass) | |
649 { | |
650 XtVaGetValues (widget, XmNset, &val->selected, 0); | |
651 val->edited = True; | |
652 } | |
653 else if (class == xmTextWidgetClass) | |
654 { | |
655 if (val->value) | |
656 free (val->value); | |
657 val->value = XmTextGetString (widget); | |
658 val->edited = True; | |
659 } | |
660 else if (class == xmTextFieldWidgetClass) | |
661 { | |
662 if (val->value) | |
663 free (val->value); | |
664 val->value = XmTextFieldGetString (widget); | |
665 val->edited = True; | |
666 } | |
667 else if (class == xmRowColumnWidgetClass) | |
668 { | |
669 Boolean radiobox = 0; | |
670 int ac = 0; | |
671 Arg al [1]; | |
672 | |
673 XtSetArg (al [ac], XmNradioBehavior, &radiobox); ac++; | |
674 XtGetValues (widget, al, ac); | |
675 | |
676 if (radiobox) | |
677 { | |
678 CompositeWidget radio = (CompositeWidget)widget; | |
679 int i; | |
680 for (i = 0; i < radio->composite.num_children; i++) | |
681 { | |
682 int set = False; | |
683 Widget toggle = radio->composite.children [i]; | |
684 | |
685 XtVaGetValues (toggle, XmNset, &set, 0); | |
686 if (set) | |
687 { | |
688 if (val->value) | |
689 free (val->value); | |
8784 | 690 val->value = safe_strdup (XtName (toggle)); |
5626 | 691 } |
692 } | |
693 val->edited = True; | |
694 } | |
695 } | |
696 else if (class == xmListWidgetClass) | |
697 { | |
698 int pos_cnt; | |
699 int* pos_list; | |
700 if (XmListGetSelectedPos (widget, &pos_list, &pos_cnt)) | |
701 { | |
702 int i; | |
703 widget_value* cur; | |
704 for (cur = val->contents, i = 0; cur; cur = cur->next) | |
705 if (cur->value) | |
706 { | |
707 int j; | |
708 cur->selected = False; | |
709 i += 1; | |
710 for (j = 0; j < pos_cnt; j++) | |
711 if (pos_list [j] == i) | |
712 { | |
713 cur->selected = True; | |
8784 | 714 val->value = safe_strdup (cur->name); |
5626 | 715 } |
716 } | |
717 val->edited = 1; | |
718 XtFree ((char *) pos_list); | |
719 } | |
720 } | |
721 } | |
722 | |
723 | |
724 /* This function is for activating a button from a program. It's wrong because | |
725 we pass a NULL argument in the call_data which is not Motif compatible. | |
726 This is used from the XmNdefaultAction callback of the List widgets to | |
727 have a dble-click put down a dialog box like the button woudl do. | |
728 I could not find a way to do that with accelerators. | |
729 */ | |
730 static void | |
731 activate_button (Widget widget, XtPointer closure, XtPointer call_data) | |
732 { | |
733 Widget button = (Widget)closure; | |
734 XtCallCallbacks (button, XmNactivateCallback, NULL); | |
735 } | |
736 | |
737 /* creation functions */ | |
738 | |
739 /* dialogs */ | |
740 static Widget | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
741 make_dialog (name, parent, pop_up_p, shell_title, icon_name, text_input_slot, |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
742 radio_box, list, left_buttons, right_buttons) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
743 char* name; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
744 Widget parent; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
745 Boolean pop_up_p; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
746 char* shell_title; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
747 char* icon_name; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
748 Boolean text_input_slot; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
749 Boolean radio_box; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
750 Boolean list; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
751 int left_buttons; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
752 int right_buttons; |
5626 | 753 { |
754 Widget result; | |
755 Widget form; | |
756 Widget row; | |
757 Widget icon; | |
758 Widget icon_separator; | |
759 Widget message; | |
760 Widget value = 0; | |
761 Widget separator; | |
762 Widget button = 0; | |
763 Widget children [16]; /* for the final XtManageChildren */ | |
764 int n_children; | |
765 Arg al[64]; /* Arg List */ | |
766 int ac; /* Arg Count */ | |
767 int i; | |
768 | |
769 if (pop_up_p) | |
770 { | |
771 ac = 0; | |
772 XtSetArg(al[ac], XmNtitle, shell_title); ac++; | |
773 XtSetArg(al[ac], XtNallowShellResize, True); ac++; | |
774 XtSetArg(al[ac], XmNdeleteResponse, XmUNMAP); ac++; | |
775 result = XmCreateDialogShell (parent, "dialog", al, ac); | |
776 ac = 0; | |
777 XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++; | |
778 /* XtSetArg(al[ac], XmNautoUnmanage, TRUE); ac++; */ /* ####is this ok? */ | |
779 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++; | |
780 form = XmCreateForm (result, shell_title, al, ac); | |
781 } | |
782 else | |
783 { | |
784 ac = 0; | |
785 XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++; | |
786 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++; | |
787 form = XmCreateForm (parent, shell_title, al, ac); | |
788 result = form; | |
789 } | |
790 | |
8884 | 791 n_children = left_buttons + right_buttons + 1; |
5626 | 792 ac = 0; |
8884 | 793 XtSetArg(al[ac], XmNpacking, n_children == 3? |
794 XmPACK_COLUMN: XmPACK_TIGHT); ac++; | |
795 XtSetArg(al[ac], XmNorientation, n_children == 3? | |
796 XmVERTICAL: XmHORIZONTAL); ac++; | |
5626 | 797 XtSetArg(al[ac], XmNnumColumns, left_buttons + right_buttons + 1); ac++; |
798 XtSetArg(al[ac], XmNmarginWidth, 0); ac++; | |
799 XtSetArg(al[ac], XmNmarginHeight, 0); ac++; | |
800 XtSetArg(al[ac], XmNspacing, 13); ac++; | |
801 XtSetArg(al[ac], XmNadjustLast, False); ac++; | |
802 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++; | |
803 XtSetArg(al[ac], XmNisAligned, True); ac++; | |
804 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++; | |
805 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++; | |
806 XtSetArg(al[ac], XmNbottomOffset, 13); ac++; | |
807 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++; | |
808 XtSetArg(al[ac], XmNleftOffset, 13); ac++; | |
809 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; | |
810 XtSetArg(al[ac], XmNrightOffset, 13); ac++; | |
811 row = XmCreateRowColumn (form, "row", al, ac); | |
812 | |
813 n_children = 0; | |
814 for (i = 0; i < left_buttons; i++) | |
815 { | |
816 char button_name [16]; | |
817 sprintf (button_name, "button%d", i + 1); | |
818 ac = 0; | |
819 if (i == 0) | |
820 { | |
821 XtSetArg(al[ac], XmNhighlightThickness, 1); ac++; | |
822 XtSetArg(al[ac], XmNshowAsDefault, TRUE); ac++; | |
823 } | |
8884 | 824 XtSetArg(al[ac], XmNmarginWidth, 10); ac++; |
5626 | 825 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++; |
826 children [n_children] = XmCreatePushButton (row, button_name, al, ac); | |
827 | |
828 if (i == 0) | |
829 { | |
830 button = children [n_children]; | |
831 ac = 0; | |
832 XtSetArg(al[ac], XmNdefaultButton, button); ac++; | |
833 XtSetValues (row, al, ac); | |
834 } | |
835 | |
836 n_children++; | |
837 } | |
838 | |
839 /* invisible seperator button */ | |
840 ac = 0; | |
841 XtSetArg (al[ac], XmNmappedWhenManaged, FALSE); ac++; | |
842 children [n_children] = XmCreateLabel (row, "separator_button", al, ac); | |
843 n_children++; | |
844 | |
845 for (i = 0; i < right_buttons; i++) | |
846 { | |
847 char button_name [16]; | |
848 sprintf (button_name, "button%d", left_buttons + i + 1); | |
849 ac = 0; | |
8884 | 850 XtSetArg(al[ac], XmNmarginWidth, 10); ac++; |
5626 | 851 XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++; |
852 children [n_children] = XmCreatePushButton (row, button_name, al, ac); | |
853 if (! button) button = children [n_children]; | |
854 n_children++; | |
855 } | |
856 | |
857 XtManageChildren (children, n_children); | |
858 | |
859 ac = 0; | |
860 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++; | |
861 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++; | |
862 XtSetArg(al[ac], XmNbottomOffset, 13); ac++; | |
863 XtSetArg(al[ac], XmNbottomWidget, row); ac++; | |
864 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++; | |
865 XtSetArg(al[ac], XmNleftOffset, 0); ac++; | |
866 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; | |
867 XtSetArg(al[ac], XmNrightOffset, 0); ac++; | |
868 separator = XmCreateSeparator (form, "", al, ac); | |
869 | |
870 ac = 0; | |
871 XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++; | |
872 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++; | |
873 XtSetArg(al[ac], XmNtopOffset, 13); ac++; | |
874 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_NONE); ac++; | |
875 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++; | |
876 XtSetArg(al[ac], XmNleftOffset, 13); ac++; | |
877 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_NONE); ac++; | |
878 icon = XmCreateLabel (form, icon_name, al, ac); | |
879 | |
880 ac = 0; | |
881 XtSetArg(al[ac], XmNmappedWhenManaged, FALSE); ac++; | |
882 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++; | |
883 XtSetArg(al[ac], XmNtopOffset, 6); ac++; | |
884 XtSetArg(al[ac], XmNtopWidget, icon); ac++; | |
885 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++; | |
886 XtSetArg(al[ac], XmNbottomOffset, 6); ac++; | |
887 XtSetArg(al[ac], XmNbottomWidget, separator); ac++; | |
888 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_NONE); ac++; | |
889 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_NONE); ac++; | |
890 icon_separator = XmCreateLabel (form, "", al, ac); | |
891 | |
892 if (text_input_slot) | |
893 { | |
894 ac = 0; | |
895 XtSetArg(al[ac], XmNcolumns, 50); ac++; | |
896 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++; | |
897 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++; | |
898 XtSetArg(al[ac], XmNbottomOffset, 13); ac++; | |
899 XtSetArg(al[ac], XmNbottomWidget, separator); ac++; | |
900 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++; | |
901 XtSetArg(al[ac], XmNleftOffset, 13); ac++; | |
902 XtSetArg(al[ac], XmNleftWidget, icon); ac++; | |
903 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; | |
904 XtSetArg(al[ac], XmNrightOffset, 13); ac++; | |
905 value = XmCreateTextField (form, "value", al, ac); | |
906 } | |
907 else if (radio_box) | |
908 { | |
909 Widget radio_butt; | |
910 ac = 0; | |
911 XtSetArg(al[ac], XmNmarginWidth, 0); ac++; | |
912 XtSetArg(al[ac], XmNmarginHeight, 0); ac++; | |
913 XtSetArg(al[ac], XmNspacing, 13); ac++; | |
914 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++; | |
915 XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++; | |
916 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++; | |
917 XtSetArg(al[ac], XmNbottomOffset, 13); ac++; | |
918 XtSetArg(al[ac], XmNbottomWidget, separator); ac++; | |
919 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++; | |
920 XtSetArg(al[ac], XmNleftOffset, 13); ac++; | |
921 XtSetArg(al[ac], XmNleftWidget, icon); ac++; | |
922 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; | |
923 XtSetArg(al[ac], XmNrightOffset, 13); ac++; | |
924 value = XmCreateRadioBox (form, "radiobutton1", al, ac); | |
925 ac = 0; | |
926 i = 0; | |
927 radio_butt = XmCreateToggleButtonGadget (value, "radio1", al, ac); | |
928 children [i++] = radio_butt; | |
929 radio_butt = XmCreateToggleButtonGadget (value, "radio2", al, ac); | |
930 children [i++] = radio_butt; | |
931 radio_butt = XmCreateToggleButtonGadget (value, "radio3", al, ac); | |
932 children [i++] = radio_butt; | |
933 XtManageChildren (children, i); | |
934 } | |
935 else if (list) | |
936 { | |
937 ac = 0; | |
938 XtSetArg(al[ac], XmNvisibleItemCount, 5); ac++; | |
939 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++; | |
940 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++; | |
941 XtSetArg(al[ac], XmNbottomOffset, 13); ac++; | |
942 XtSetArg(al[ac], XmNbottomWidget, separator); ac++; | |
943 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++; | |
944 XtSetArg(al[ac], XmNleftOffset, 13); ac++; | |
945 XtSetArg(al[ac], XmNleftWidget, icon); ac++; | |
946 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; | |
947 XtSetArg(al[ac], XmNrightOffset, 13); ac++; | |
948 value = XmCreateScrolledList (form, "list", al, ac); | |
949 | |
950 /* this is the easiest way I found to have the dble click in the | |
951 list activate the default button */ | |
952 XtAddCallback (value, XmNdefaultActionCallback, activate_button, button); | |
953 } | |
954 | |
955 ac = 0; | |
956 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++; | |
957 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++; | |
958 XtSetArg(al[ac], XmNtopOffset, 13); ac++; | |
959 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++; | |
960 XtSetArg(al[ac], XmNbottomOffset, 13); ac++; | |
961 XtSetArg(al[ac], XmNbottomWidget, | |
962 text_input_slot || radio_box || list ? value : separator); ac++; | |
963 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++; | |
964 XtSetArg(al[ac], XmNleftOffset, 13); ac++; | |
965 XtSetArg(al[ac], XmNleftWidget, icon); ac++; | |
966 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; | |
967 XtSetArg(al[ac], XmNrightOffset, 13); ac++; | |
968 message = XmCreateLabel (form, "message", al, ac); | |
969 | |
970 if (list) | |
971 XtManageChild (value); | |
972 | |
973 i = 0; | |
974 children [i] = row; i++; | |
975 children [i] = separator; i++; | |
976 if (text_input_slot || radio_box) | |
977 { | |
978 children [i] = value; i++; | |
979 } | |
980 children [i] = message; i++; | |
981 children [i] = icon; i++; | |
982 children [i] = icon_separator; i++; | |
983 XtManageChildren (children, i); | |
984 | |
985 if (text_input_slot || list) | |
986 { | |
987 XtInstallAccelerators (value, button); | |
988 XtSetKeyboardFocus (result, value); | |
989 } | |
990 else | |
991 { | |
992 XtInstallAccelerators (form, button); | |
993 XtSetKeyboardFocus (result, button); | |
994 } | |
995 | |
996 return result; | |
997 } | |
998 | |
999 static destroyed_instance* | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1000 find_matching_instance (instance) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1001 widget_instance* instance; |
5626 | 1002 { |
1003 destroyed_instance* cur; | |
1004 destroyed_instance* prev; | |
1005 char* type = instance->info->type; | |
1006 char* name = instance->info->name; | |
1007 | |
1008 for (prev = NULL, cur = all_destroyed_instances; | |
1009 cur; | |
1010 prev = cur, cur = cur->next) | |
1011 { | |
1012 if (!strcmp (cur->name, name) | |
1013 && !strcmp (cur->type, type) | |
1014 && cur->parent == instance->parent | |
1015 && cur->pop_up_p == instance->pop_up_p) | |
1016 { | |
1017 if (prev) | |
1018 prev->next = cur->next; | |
1019 else | |
1020 all_destroyed_instances = cur->next; | |
1021 return cur; | |
1022 } | |
1023 /* do some cleanup */ | |
1024 else if (!cur->widget) | |
1025 { | |
1026 if (prev) | |
1027 prev->next = cur->next; | |
1028 else | |
1029 all_destroyed_instances = cur->next; | |
1030 free_destroyed_instance (cur); | |
1031 cur = prev ? prev : all_destroyed_instances; | |
1032 } | |
1033 } | |
1034 return NULL; | |
1035 } | |
1036 | |
1037 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1038 mark_dead_instance_destroyed (widget, closure, call_data) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1039 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1040 XtPointer closure; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1041 XtPointer call_data; |
5626 | 1042 { |
1043 destroyed_instance* instance = (destroyed_instance*)closure; | |
1044 instance->widget = NULL; | |
1045 } | |
1046 | |
1047 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1048 recenter_widget (widget) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1049 Widget widget; |
5626 | 1050 { |
1051 Widget parent = XtParent (widget); | |
1052 Screen* screen = XtScreen (widget); | |
1053 Dimension screen_width = WidthOfScreen (screen); | |
1054 Dimension screen_height = HeightOfScreen (screen); | |
1055 Dimension parent_width = 0; | |
1056 Dimension parent_height = 0; | |
1057 Dimension child_width = 0; | |
1058 Dimension child_height = 0; | |
1059 Position x; | |
1060 Position y; | |
1061 | |
1062 XtVaGetValues (widget, XtNwidth, &child_width, XtNheight, &child_height, 0); | |
1063 XtVaGetValues (parent, XtNwidth, &parent_width, XtNheight, &parent_height, | |
1064 0); | |
1065 | |
1066 x = (((Position)parent_width) - ((Position)child_width)) / 2; | |
1067 y = (((Position)parent_height) - ((Position)child_height)) / 2; | |
1068 | |
1069 XtTranslateCoords (parent, x, y, &x, &y); | |
1070 | |
1071 if (x + child_width > screen_width) | |
1072 x = screen_width - child_width; | |
1073 if (x < 0) | |
1074 x = 0; | |
1075 | |
1076 if (y + child_height > screen_height) | |
1077 y = screen_height - child_height; | |
1078 if (y < 0) | |
1079 y = 0; | |
1080 | |
1081 XtVaSetValues (widget, XtNx, x, XtNy, y, 0); | |
1082 } | |
1083 | |
1084 static Widget | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1085 recycle_instance (instance) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1086 destroyed_instance* instance; |
5626 | 1087 { |
1088 Widget widget = instance->widget; | |
1089 | |
1090 /* widget is NULL if the parent was destroyed. */ | |
1091 if (widget) | |
1092 { | |
1093 Widget focus; | |
1094 Widget separator; | |
1095 | |
1096 /* Remove the destroy callback as the instance is not in the list | |
1097 anymore */ | |
1098 XtRemoveCallback (instance->parent, XtNdestroyCallback, | |
1099 mark_dead_instance_destroyed, | |
1100 (XtPointer)instance); | |
1101 | |
1102 /* Give the focus to the initial item */ | |
1103 focus = XtNameToWidget (widget, "*value"); | |
1104 if (!focus) | |
1105 focus = XtNameToWidget (widget, "*button1"); | |
1106 if (focus) | |
1107 XtSetKeyboardFocus (widget, focus); | |
1108 | |
1109 /* shrink the separator label back to their original size */ | |
1110 separator = XtNameToWidget (widget, "*separator_button"); | |
1111 if (separator) | |
1112 XtVaSetValues (separator, XtNwidth, 5, XtNheight, 5, 0); | |
1113 | |
1114 /* Center the dialog in its parent */ | |
1115 recenter_widget (widget); | |
1116 } | |
1117 free_destroyed_instance (instance); | |
1118 return widget; | |
1119 } | |
1120 | |
1121 Widget | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1122 xm_create_dialog (instance) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1123 widget_instance* instance; |
5626 | 1124 { |
1125 char* name = instance->info->type; | |
1126 Widget parent = instance->parent; | |
1127 Widget widget; | |
1128 Boolean pop_up_p = instance->pop_up_p; | |
1129 char* shell_name = 0; | |
1130 char* icon_name; | |
1131 Boolean text_input_slot = False; | |
1132 Boolean radio_box = False; | |
1133 Boolean list = False; | |
1134 int total_buttons; | |
1135 int left_buttons = 0; | |
1136 int right_buttons = 1; | |
1137 destroyed_instance* dead_one; | |
1138 | |
1139 /* try to find a widget to recycle */ | |
1140 dead_one = find_matching_instance (instance); | |
1141 if (dead_one) | |
1142 { | |
1143 Widget recycled_widget = recycle_instance (dead_one); | |
1144 if (recycled_widget) | |
1145 return recycled_widget; | |
1146 } | |
1147 | |
1148 switch (name [0]){ | |
1149 case 'E': case 'e': | |
1150 icon_name = "dbox-error"; | |
1151 shell_name = "Error"; | |
1152 break; | |
1153 | |
1154 case 'I': case 'i': | |
1155 icon_name = "dbox-info"; | |
1156 shell_name = "Information"; | |
1157 break; | |
1158 | |
1159 case 'L': case 'l': | |
1160 list = True; | |
1161 icon_name = "dbox-question"; | |
1162 shell_name = "Prompt"; | |
1163 break; | |
1164 | |
1165 case 'P': case 'p': | |
1166 text_input_slot = True; | |
1167 icon_name = "dbox-question"; | |
1168 shell_name = "Prompt"; | |
1169 break; | |
1170 | |
1171 case 'Q': case 'q': | |
1172 icon_name = "dbox-question"; | |
1173 shell_name = "Question"; | |
1174 break; | |
1175 } | |
1176 | |
1177 total_buttons = name [1] - '0'; | |
1178 | |
1179 if (name [3] == 'T' || name [3] == 't') | |
1180 { | |
1181 text_input_slot = False; | |
1182 radio_box = True; | |
1183 } | |
1184 else if (name [3]) | |
1185 right_buttons = name [4] - '0'; | |
1186 | |
1187 left_buttons = total_buttons - right_buttons; | |
1188 | |
1189 widget = make_dialog (name, parent, pop_up_p, | |
1190 shell_name, icon_name, text_input_slot, radio_box, | |
1191 list, left_buttons, right_buttons); | |
1192 | |
1193 XtAddCallback (widget, XmNpopdownCallback, xm_nosel_callback, | |
1194 (XtPointer) instance); | |
1195 return widget; | |
1196 } | |
1197 | |
1198 static Widget | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1199 make_menubar (instance) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1200 widget_instance* instance; |
5626 | 1201 { |
1202 return XmCreateMenuBar (instance->parent, instance->info->name, NULL, 0); | |
1203 } | |
1204 | |
1205 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1206 remove_grabs (shell, closure, call_data) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1207 Widget shell; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1208 XtPointer closure; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1209 XtPointer call_data; |
5626 | 1210 { |
11245
5fdf816307c6
(remove_grabs): Use type Widget for `menu'.
Richard M. Stallman <rms@gnu.org>
parents:
9835
diff
changeset
|
1211 Widget menu = (Widget) closure; |
5fdf816307c6
(remove_grabs): Use type Widget for `menu'.
Richard M. Stallman <rms@gnu.org>
parents:
9835
diff
changeset
|
1212 XmRemoveFromPostFromList (menu, XtParent (XtParent (menu))); |
5626 | 1213 } |
1214 | |
1215 static Widget | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1216 make_popup_menu (instance) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1217 widget_instance* instance; |
5626 | 1218 { |
1219 Widget parent = instance->parent; | |
1220 Window parent_window = parent->core.window; | |
1221 Widget result; | |
1222 | |
1223 /* sets the parent window to 0 to fool Motif into not generating a grab */ | |
1224 parent->core.window = 0; | |
1225 result = XmCreatePopupMenu (parent, instance->info->name, NULL, 0); | |
1226 XtAddCallback (XtParent (result), XmNpopdownCallback, remove_grabs, | |
1227 (XtPointer)result); | |
1228 parent->core.window = parent_window; | |
1229 return result; | |
1230 } | |
8784 | 1231 static Widget |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1232 make_main (instance) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1233 widget_instance* instance; |
8784 | 1234 { |
1235 Widget parent = instance->parent; | |
1236 Widget result; | |
1237 Arg al[2]; | |
1238 int ac; | |
1239 | |
1240 ac = 0; | |
1241 XtSetArg (al[ac], XtNborderWidth, 0); ac++; | |
1242 XtSetArg (al[ac], XmNspacing, 0); ac++; | |
1243 result = XmCreateMainWindow (parent, instance->info->name, al, ac); | |
1244 return result; | |
1245 } | |
5626 | 1246 |
1247 /* Table of functions to create widgets */ | |
1248 | |
1249 #ifdef ENERGIZE | |
1250 | |
1251 /* interface with the XDesigner generated functions */ | |
1252 typedef Widget (*widget_maker) (Widget); | |
1253 extern Widget create_project_p_sheet (Widget parent); | |
1254 extern Widget create_debugger_p_sheet (Widget parent); | |
1255 extern Widget create_breaklist_p_sheet (Widget parent); | |
1256 extern Widget create_le_browser_p_sheet (Widget parent); | |
1257 extern Widget create_class_browser_p_sheet (Widget parent); | |
1258 extern Widget create_call_browser_p_sheet (Widget parent); | |
1259 extern Widget create_build_dialog (Widget parent); | |
1260 extern Widget create_editmode_dialog (Widget parent); | |
1261 extern Widget create_search_dialog (Widget parent); | |
1262 extern Widget create_project_display_dialog (Widget parent); | |
1263 | |
1264 static Widget | |
1265 make_one (widget_instance* instance, widget_maker fn) | |
1266 { | |
1267 Widget result; | |
1268 Arg al [64]; | |
1269 int ac = 0; | |
1270 | |
1271 if (instance->pop_up_p) | |
1272 { | |
1273 XtSetArg (al [ac], XmNallowShellResize, TRUE); ac++; | |
1274 result = XmCreateDialogShell (instance->parent, "dialog", NULL, 0); | |
1275 XtAddCallback (result, XmNpopdownCallback, &xm_nosel_callback, | |
1276 (XtPointer) instance); | |
1277 (*fn) (result); | |
1278 } | |
1279 else | |
1280 { | |
1281 result = (*fn) (instance->parent); | |
1282 XtRealizeWidget (result); | |
1283 } | |
1284 return result; | |
1285 } | |
1286 | |
1287 static Widget | |
1288 make_project_p_sheet (widget_instance* instance) | |
1289 { | |
1290 return make_one (instance, create_project_p_sheet); | |
1291 } | |
1292 | |
1293 static Widget | |
1294 make_debugger_p_sheet (widget_instance* instance) | |
1295 { | |
1296 return make_one (instance, create_debugger_p_sheet); | |
1297 } | |
1298 | |
1299 static Widget | |
1300 make_breaklist_p_sheet (widget_instance* instance) | |
1301 { | |
1302 return make_one (instance, create_breaklist_p_sheet); | |
1303 } | |
1304 | |
1305 static Widget | |
1306 make_le_browser_p_sheet (widget_instance* instance) | |
1307 { | |
1308 return make_one (instance, create_le_browser_p_sheet); | |
1309 } | |
1310 | |
1311 static Widget | |
1312 make_class_browser_p_sheet (widget_instance* instance) | |
1313 { | |
1314 return make_one (instance, create_class_browser_p_sheet); | |
1315 } | |
1316 | |
1317 static Widget | |
1318 make_call_browser_p_sheet (widget_instance* instance) | |
1319 { | |
1320 return make_one (instance, create_call_browser_p_sheet); | |
1321 } | |
1322 | |
1323 static Widget | |
1324 make_build_dialog (widget_instance* instance) | |
1325 { | |
1326 return make_one (instance, create_build_dialog); | |
1327 } | |
1328 | |
1329 static Widget | |
1330 make_editmode_dialog (widget_instance* instance) | |
1331 { | |
1332 return make_one (instance, create_editmode_dialog); | |
1333 } | |
1334 | |
1335 static Widget | |
1336 make_search_dialog (widget_instance* instance) | |
1337 { | |
1338 return make_one (instance, create_search_dialog); | |
1339 } | |
1340 | |
1341 static Widget | |
1342 make_project_display_dialog (widget_instance* instance) | |
1343 { | |
1344 return make_one (instance, create_project_display_dialog); | |
1345 } | |
1346 | |
1347 #endif /* ENERGIZE */ | |
1348 | |
1349 widget_creation_entry | |
1350 xm_creation_table [] = | |
1351 { | |
1352 {"menubar", make_menubar}, | |
1353 {"popup", make_popup_menu}, | |
8784 | 1354 {"main", make_main}, |
5626 | 1355 #ifdef ENERGIZE |
1356 {"project_p_sheet", make_project_p_sheet}, | |
1357 {"debugger_p_sheet", make_debugger_p_sheet}, | |
1358 {"breaklist_psheet", make_breaklist_p_sheet}, | |
1359 {"leb_psheet", make_le_browser_p_sheet}, | |
1360 {"class_browser_psheet", make_class_browser_p_sheet}, | |
1361 {"ctree_browser_psheet", make_call_browser_p_sheet}, | |
1362 {"build", make_build_dialog}, | |
1363 {"editmode", make_editmode_dialog}, | |
1364 {"search", make_search_dialog}, | |
1365 {"project_display", make_project_display_dialog}, | |
1366 #endif /* ENERGIZE */ | |
1367 {NULL, NULL} | |
1368 }; | |
1369 | |
1370 /* Destruction of instances */ | |
1371 void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1372 xm_destroy_instance (instance) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1373 widget_instance* instance; |
5626 | 1374 { |
1375 Widget widget = instance->widget; | |
1376 /* recycle the dialog boxes */ | |
1377 /* Disable the recycling until we can find a way to have the dialog box | |
1378 get reasonable layout after we modify its contents. */ | |
1379 if (0 | |
1380 && XtClass (widget) == xmDialogShellWidgetClass) | |
1381 { | |
1382 destroyed_instance* dead_instance = | |
1383 make_destroyed_instance (instance->info->name, | |
1384 instance->info->type, | |
1385 instance->widget, | |
1386 instance->parent, | |
1387 instance->pop_up_p); | |
1388 dead_instance->next = all_destroyed_instances; | |
1389 all_destroyed_instances = dead_instance; | |
1390 XtUnmanageChild (first_child (instance->widget)); | |
1391 XFlush (XtDisplay (instance->widget)); | |
1392 XtAddCallback (instance->parent, XtNdestroyCallback, | |
1393 mark_dead_instance_destroyed, (XtPointer)dead_instance); | |
1394 } | |
1395 else | |
1396 { | |
1397 /* This might not be necessary now that the nosel is attached to | |
1398 popdown instead of destroy, but it can't hurt. */ | |
1399 XtRemoveCallback (instance->widget, XtNdestroyCallback, | |
1400 xm_nosel_callback, (XtPointer)instance); | |
1401 XtDestroyWidget (instance->widget); | |
1402 } | |
1403 } | |
1404 | |
1405 /* popup utility */ | |
1406 void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1407 xm_popup_menu (widget) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1408 Widget widget; |
5626 | 1409 { |
1410 XButtonPressedEvent dummy; | |
1411 XEvent* event; | |
1412 | |
1413 dummy.type = ButtonPress; | |
1414 dummy.serial = 0; | |
1415 dummy.send_event = 0; | |
1416 dummy.display = XtDisplay (widget); | |
1417 dummy.window = XtWindow (XtParent (widget)); | |
1418 dummy.time = 0; | |
1419 dummy.button = 0; | |
1420 XQueryPointer (dummy.display, dummy.window, &dummy.root, | |
1421 &dummy.subwindow, &dummy.x_root, &dummy.y_root, | |
1422 &dummy.x, &dummy.y, &dummy.state); | |
1423 event = (XEvent *) &dummy; | |
1424 | |
1425 if (event->type == ButtonPress || event->type == ButtonRelease) | |
1426 { | |
1427 /* This is so totally ridiculous: there's NO WAY to tell Motif | |
1428 that *any* button can select a menu item. Only one button | |
1429 can have that honor. | |
1430 */ | |
1431 char *trans = 0; | |
1432 if (event->xbutton.state & Button5Mask) trans = "<Btn5Down>"; | |
1433 else if (event->xbutton.state & Button4Mask) trans = "<Btn4Down>"; | |
1434 else if (event->xbutton.state & Button3Mask) trans = "<Btn3Down>"; | |
1435 else if (event->xbutton.state & Button2Mask) trans = "<Btn2Down>"; | |
1436 else if (event->xbutton.state & Button1Mask) trans = "<Btn1Down>"; | |
1437 if (trans) XtVaSetValues (widget, XmNmenuPost, trans, 0); | |
1438 XmMenuPosition (widget, (XButtonPressedEvent *) event); | |
1439 } | |
1440 XtManageChild (widget); | |
1441 } | |
1442 | |
1443 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1444 set_min_dialog_size (w) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1445 Widget w; |
5626 | 1446 { |
1447 short width; | |
1448 short height; | |
1449 XtVaGetValues (w, XmNwidth, &width, XmNheight, &height, 0); | |
1450 XtVaSetValues (w, XmNminWidth, width, XmNminHeight, height, 0); | |
1451 } | |
1452 | |
1453 void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1454 xm_pop_instance (instance, up) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1455 widget_instance* instance; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1456 Boolean up; |
5626 | 1457 { |
1458 Widget widget = instance->widget; | |
1459 | |
1460 if (XtClass (widget) == xmDialogShellWidgetClass) | |
1461 { | |
1462 Widget widget_to_manage = first_child (widget); | |
1463 if (up) | |
1464 { | |
1465 XtManageChild (widget_to_manage); | |
1466 set_min_dialog_size (widget); | |
1467 XtSetKeyboardFocus (instance->parent, widget); | |
1468 } | |
1469 else | |
1470 XtUnmanageChild (widget_to_manage); | |
1471 } | |
1472 else | |
1473 { | |
1474 if (up) | |
1475 XtManageChild (widget); | |
1476 else | |
1477 XtUnmanageChild (widget); | |
1478 } | |
1479 } | |
1480 | |
1481 | |
1482 /* motif callback */ | |
1483 | |
1484 enum do_call_type { pre_activate, selection, no_selection, post_activate }; | |
1485 | |
1486 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1487 do_call (widget, closure, type) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1488 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1489 XtPointer closure; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1490 enum do_call_type type; |
5626 | 1491 { |
1492 Arg al [256]; | |
1493 int ac; | |
1494 XtPointer user_data; | |
1495 widget_instance* instance = (widget_instance*)closure; | |
1496 Widget instance_widget; | |
1497 LWLIB_ID id; | |
1498 | |
1499 if (!instance) | |
1500 return; | |
1501 if (widget->core.being_destroyed) | |
1502 return; | |
1503 | |
1504 instance_widget = instance->widget; | |
1505 if (!instance_widget) | |
1506 return; | |
1507 | |
1508 id = instance->info->id; | |
1509 ac = 0; | |
1510 user_data = NULL; | |
1511 XtSetArg (al [ac], XmNuserData, &user_data); ac++; | |
1512 XtGetValues (widget, al, ac); | |
1513 switch (type) | |
1514 { | |
1515 case pre_activate: | |
1516 if (instance->info->pre_activate_cb) | |
1517 instance->info->pre_activate_cb (widget, id, user_data); | |
1518 break; | |
1519 case selection: | |
1520 if (instance->info->selection_cb) | |
1521 instance->info->selection_cb (widget, id, user_data); | |
1522 break; | |
1523 case no_selection: | |
1524 if (instance->info->selection_cb) | |
1525 instance->info->selection_cb (widget, id, (XtPointer) -1); | |
1526 break; | |
1527 case post_activate: | |
1528 if (instance->info->post_activate_cb) | |
1529 instance->info->post_activate_cb (widget, id, user_data); | |
1530 break; | |
1531 default: | |
1532 abort (); | |
1533 } | |
1534 } | |
1535 | |
1536 /* Like lw_internal_update_other_instances except that it does not do | |
1537 anything if its shell parent is not managed. This is to protect | |
1538 lw_internal_update_other_instances to dereference freed memory | |
1539 if the widget was ``destroyed'' by caching it in the all_destroyed_instances | |
1540 list */ | |
1541 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1542 xm_internal_update_other_instances (widget, closure, call_data) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1543 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1544 XtPointer closure; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1545 XtPointer call_data; |
5626 | 1546 { |
1547 Widget parent; | |
1548 for (parent = widget; parent; parent = XtParent (parent)) | |
1549 if (XtIsShell (parent)) | |
1550 break; | |
1551 else if (!XtIsManaged (parent)) | |
1552 return; | |
1553 lw_internal_update_other_instances (widget, closure, call_data); | |
1554 } | |
1555 | |
1556 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1557 xm_generic_callback (widget, closure, call_data) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1558 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1559 XtPointer closure; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1560 XtPointer call_data; |
5626 | 1561 { |
1562 lw_internal_update_other_instances (widget, closure, call_data); | |
1563 do_call (widget, closure, selection); | |
1564 } | |
1565 | |
1566 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1567 xm_nosel_callback (widget, closure, call_data) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1568 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1569 XtPointer closure; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1570 XtPointer call_data; |
5626 | 1571 { |
1572 /* This callback is only called when a dialog box is dismissed with the wm's | |
1573 destroy button (WM_DELETE_WINDOW.) We want the dialog box to be destroyed | |
1574 in that case, not just unmapped, so that it releases its keyboard grabs. | |
1575 But there are problems with running our callbacks while the widget is in | |
1576 the process of being destroyed, so we set XmNdeleteResponse to XmUNMAP | |
1577 instead of XmDESTROY and then destroy it ourself after having run the | |
1578 callback. | |
1579 */ | |
1580 do_call (widget, closure, no_selection); | |
1581 XtDestroyWidget (widget); | |
1582 } | |
1583 | |
1584 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1585 xm_pull_down_callback (widget, closure, call_data) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1586 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1587 XtPointer closure; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1588 XtPointer call_data; |
5626 | 1589 { |
1590 do_call (widget, closure, pre_activate); | |
1591 } | |
1592 | |
1593 static void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1594 xm_pop_down_callback (widget, closure, call_data) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1595 Widget widget; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1596 XtPointer closure; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1597 XtPointer call_data; |
5626 | 1598 { |
9835
d2250d1b0f48
(make_menu_in_widget): Differentiate a separator entry ("--") from a
Paul Reilly <pmr@pajato.com>
parents:
9825
diff
changeset
|
1599 widget_instance *instance = (widget_instance *) closure; |
d2250d1b0f48
(make_menu_in_widget): Differentiate a separator entry ("--") from a
Paul Reilly <pmr@pajato.com>
parents:
9825
diff
changeset
|
1600 |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1601 if ((!instance->pop_up_p && (XtParent (widget) == instance->widget)) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1602 || (XtParent (widget) == instance->parent)) |
9835
d2250d1b0f48
(make_menu_in_widget): Differentiate a separator entry ("--") from a
Paul Reilly <pmr@pajato.com>
parents:
9825
diff
changeset
|
1603 do_call (widget, closure, post_activate); |
5626 | 1604 } |
1605 | |
1606 | |
1607 /* set the keyboard focus */ | |
1608 void | |
11299
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1609 xm_set_keyboard_focus (parent, w) |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1610 Widget parent; |
f82f4e93e523
(*): remove function prototypes.
Paul Reilly <pmr@pajato.com>
parents:
11245
diff
changeset
|
1611 Widget w; |
5626 | 1612 { |
1613 XmProcessTraversal (w, 0); | |
1614 XtSetKeyboardFocus (parent, w); | |
1615 } | |
9224
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1616 |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1617 /* Motif hack to set the main window areas. */ |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1618 void |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1619 xm_set_main_areas (parent, menubar, work_area) |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1620 Widget parent; |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1621 Widget menubar; |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1622 Widget work_area; |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1623 { |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1624 XmMainWindowSetAreas (parent, |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1625 menubar, /* menubar (maybe 0) */ |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1626 0, /* command area (psheets) */ |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1627 0, /* horizontal scroll */ |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1628 0, /* vertical scroll */ |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1629 work_area); /* work area */ |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1630 } |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1631 |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1632 /* Motif hack to control resizing on the menubar. */ |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1633 void |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1634 xm_manage_resizing (w, flag) |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1635 Widget w; |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1636 Boolean flag; |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1637 { |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1638 if (flag) |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1639 { |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1640 /* Enable the edit widget for resizing. */ |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1641 Arg al[1]; |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1642 |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1643 XtSetArg (al[0], XtNallowShellResize, 0); |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1644 XtSetValues (w, al, 1); |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1645 } |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1646 else |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1647 { |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1648 /* Disable the edit widget from resizing. */ |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1649 Arg al[1]; |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1650 |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1651 XtSetArg (al[0], XtNallowShellResize, 0); |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1652 XtSetValues (w, al, 1); |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1653 } |
b4563001d783
(make_menu_in_widget): Add support for displaying a title in pop up
Paul Reilly <pmr@pajato.com>
parents:
8884
diff
changeset
|
1654 } |