Mercurial > hg > xemacs-beta
comparison lwlib/lwlib-Xaw.c @ 428:3ecd8885ac67 r21-2-22
Import from CVS: tag r21-2-22
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:28:15 +0200 |
parents | |
children | 9d177e8d4150 |
comparison
equal
deleted
inserted
replaced
427:0a0253eac470 | 428:3ecd8885ac67 |
---|---|
1 /* The lwlib interface to Athena widgets. | |
2 Copyright (C) 1993, 1994 Free Software Foundation, 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 XEmacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 Boston, MA 02111-1307, USA. */ | |
20 | |
21 #include <config.h> | |
22 #include <stdio.h> | |
23 | |
24 #ifdef STDC_HEADERS | |
25 #include <stdlib.h> | |
26 #endif | |
27 | |
28 #include "lwlib-Xaw.h" | |
29 | |
30 #include <X11/StringDefs.h> | |
31 #include <X11/IntrinsicP.h> | |
32 #include <X11/CoreP.h> | |
33 #include <X11/Shell.h> | |
34 | |
35 #ifdef LWLIB_SCROLLBARS_ATHENA | |
36 #include <X11/Xaw/Scrollbar.h> | |
37 #endif | |
38 #ifdef LWLIB_DIALOGS_ATHENA | |
39 #include <X11/Xaw/Dialog.h> | |
40 #include <X11/Xaw/Form.h> | |
41 #include <X11/Xaw/Command.h> | |
42 #include <X11/Xaw/Label.h> | |
43 #endif | |
44 #ifdef LWLIB_WIDGETS_ATHENA | |
45 #include <X11/Xaw/Toggle.h> | |
46 #include "xlwradio.h" | |
47 #include "xlwcheckbox.h" | |
48 #include "xlwgauge.h" | |
49 #ifndef NEED_MOTIF | |
50 #include <X11/Xaw/AsciiText.h> | |
51 #endif | |
52 #endif | |
53 #include <X11/Xatom.h> | |
54 | |
55 static void xaw_generic_callback (Widget, XtPointer, XtPointer); | |
56 | |
57 | |
58 Boolean | |
59 lw_xaw_widget_p (Widget widget) | |
60 { | |
61 return (0 | |
62 #ifdef LWLIB_SCROLLBARS_ATHENA | |
63 || XtIsSubclass (widget, scrollbarWidgetClass) | |
64 #endif | |
65 #ifdef LWLIB_DIALOGS_ATHENA | |
66 || XtIsSubclass (widget, dialogWidgetClass) | |
67 #endif | |
68 #ifdef LWLIB_WIDGETS_ATHENA | |
69 || XtIsSubclass (widget, labelWidgetClass) | |
70 || XtIsSubclass (widget, toggleWidgetClass) | |
71 || XtIsSubclass (widget, gaugeWidgetClass) | |
72 #if 0 | |
73 || XtIsSubclass (widget, textWidgetClass) | |
74 #endif | |
75 #endif | |
76 ); | |
77 } | |
78 | |
79 #ifdef LWLIB_SCROLLBARS_ATHENA | |
80 static void | |
81 xaw_update_scrollbar (widget_instance *instance, Widget widget, | |
82 widget_value *val) | |
83 { | |
84 if (val->scrollbar_data) | |
85 { | |
86 scrollbar_values *data = val->scrollbar_data; | |
87 float widget_shown, widget_topOfThumb; | |
88 float new_shown, new_topOfThumb; | |
89 Arg al [10]; | |
90 | |
91 /* First size and position the scrollbar widget. */ | |
92 XtSetArg (al [0], XtNx, data->scrollbar_x); | |
93 XtSetArg (al [1], XtNy, data->scrollbar_y); | |
94 XtSetArg (al [2], XtNwidth, data->scrollbar_width); | |
95 XtSetArg (al [3], XtNheight, data->scrollbar_height); | |
96 XtSetValues (widget, al, 4); | |
97 | |
98 /* Now size the scrollbar's slider. */ | |
99 XtSetArg (al [0], XtNtopOfThumb, &widget_topOfThumb); | |
100 XtSetArg (al [1], XtNshown, &widget_shown); | |
101 XtGetValues (widget, al, 2); | |
102 | |
103 new_shown = (double) data->slider_size / | |
104 (double) (data->maximum - data->minimum); | |
105 | |
106 new_topOfThumb = (double) (data->slider_position - data->minimum) / | |
107 (double) (data->maximum - data->minimum); | |
108 | |
109 if (new_shown > 1.0) | |
110 new_shown = 1.0; | |
111 else if (new_shown < 0) | |
112 new_shown = 0; | |
113 | |
114 if (new_topOfThumb > 1.0) | |
115 new_topOfThumb = 1.0; | |
116 else if (new_topOfThumb < 0) | |
117 new_topOfThumb = 0; | |
118 | |
119 if (new_shown != widget_shown || new_topOfThumb != widget_topOfThumb) | |
120 XawScrollbarSetThumb (widget, new_topOfThumb, new_shown); | |
121 } | |
122 } | |
123 #endif /* LWLIB_SCROLLBARS_ATHENA */ | |
124 | |
125 void | |
126 xaw_update_one_widget (widget_instance *instance, Widget widget, | |
127 widget_value *val, Boolean deep_p) | |
128 { | |
129 if (val->nargs) | |
130 XtSetValues (widget, val->args, val->nargs); | |
131 | |
132 if (0) | |
133 ; | |
134 #ifdef LWLIB_SCROLLBARS_ATHENA | |
135 else if (XtIsSubclass (widget, scrollbarWidgetClass)) | |
136 { | |
137 xaw_update_scrollbar (instance, widget, val); | |
138 } | |
139 #endif | |
140 #ifdef LWLIB_DIALOGS_ATHENA | |
141 else if (XtIsSubclass (widget, dialogWidgetClass)) | |
142 { | |
143 Arg al [1]; | |
144 XtSetArg (al [0], XtNlabel, val->contents->value); | |
145 XtSetValues (widget, al, 1); | |
146 } | |
147 #endif /* LWLIB_DIALOGS_ATHENA */ | |
148 #ifdef LWLIB_WIDGETS_ATHENA | |
149 else if (XtClass (widget) == labelWidgetClass) | |
150 { | |
151 Arg al [1]; | |
152 XtSetArg (al [0], XtNlabel, val->value); | |
153 XtSetValues (widget, al, 1); | |
154 } | |
155 #endif /* LWLIB_WIDGETS_ATHENA */ | |
156 #if defined (LWLIB_DIALOGS_ATHENA) || defined (LWLIB_WIDGETS_ATHENA) | |
157 else if (XtIsSubclass (widget, commandWidgetClass)) | |
158 { | |
159 Dimension bw = 0; | |
160 Arg al [3]; | |
161 XtSetArg (al [0], XtNborderWidth, &bw); | |
162 XtGetValues (widget, al, 1); | |
163 | |
164 #ifndef LWLIB_DIALOGS_ATHENA3D | |
165 if (bw == 0) | |
166 /* Don't let buttons end up with 0 borderwidth, that's ugly... | |
167 Yeah, all this should really be done through app-defaults files | |
168 or fallback resources, but that's a whole different can of worms | |
169 that I don't feel like opening right now. Making Athena widgets | |
170 not look like shit is just entirely too much work. | |
171 */ | |
172 { | |
173 XtSetArg (al [0], XtNborderWidth, 1); | |
174 XtSetValues (widget, al, 1); | |
175 } | |
176 #endif /* ! LWLIB_DIALOGS_ATHENA3D */ | |
177 | |
178 XtSetArg (al [0], XtNlabel, val->value); | |
179 XtSetArg (al [1], XtNsensitive, val->enabled); | |
180 /* Force centered button text. See above. */ | |
181 XtSetArg (al [2], XtNjustify, XtJustifyCenter); | |
182 XtSetValues (widget, al, 3); | |
183 | |
184 XtRemoveAllCallbacks (widget, XtNcallback); | |
185 XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance); | |
186 #ifdef LWLIB_WIDGETS_ATHENA | |
187 /* set the selected state */ | |
188 if (XtIsSubclass (widget, toggleWidgetClass)) | |
189 { | |
190 XtSetArg (al [0], XtNstate, val->selected); | |
191 XtSetValues (widget, al, 1); | |
192 } | |
193 #endif /* LWLIB_WIDGETS_ATHENA */ | |
194 } | |
195 #endif /* LWLIB_DIALOGS_ATHENA */ | |
196 } | |
197 | |
198 void | |
199 xaw_update_one_value (widget_instance *instance, Widget widget, | |
200 widget_value *val) | |
201 { | |
202 #ifdef LWLIB_WIDGETS_ATHENA | |
203 widget_value *old_wv; | |
204 | |
205 /* copy the call_data slot into the "return" widget_value */ | |
206 for (old_wv = instance->info->val->contents; old_wv; old_wv = old_wv->next) | |
207 if (!strcmp (val->name, old_wv->name)) | |
208 { | |
209 val->call_data = old_wv->call_data; | |
210 break; | |
211 } | |
212 | |
213 if (XtIsSubclass (widget, toggleWidgetClass)) | |
214 { | |
215 Arg al [1]; | |
216 XtSetArg (al [0], XtNstate, &val->selected); | |
217 XtGetValues (widget, al, 1); | |
218 val->edited = True; | |
219 } | |
220 #ifndef NEED_MOTIF | |
221 else if (XtIsSubclass (widget, asciiTextWidgetClass)) | |
222 { | |
223 Arg al [1]; | |
224 if (val->value) | |
225 free (val->value); | |
226 XtSetArg (al [0], XtNstring, &val->value); | |
227 XtGetValues (widget, al, 1); | |
228 val->edited = True; | |
229 } | |
230 #endif | |
231 #endif /* LWLIB_WIDGETS_ATHENA */ | |
232 } | |
233 | |
234 void | |
235 xaw_destroy_instance (widget_instance *instance) | |
236 { | |
237 #ifdef LWLIB_DIALOGS_ATHENA | |
238 if (XtIsSubclass (instance->widget, dialogWidgetClass)) | |
239 /* Need to destroy the Shell too. */ | |
240 XtDestroyWidget (XtParent (instance->widget)); | |
241 else | |
242 #endif | |
243 XtDestroyWidget (instance->widget); | |
244 } | |
245 | |
246 void | |
247 xaw_popup_menu (Widget widget, XEvent *event) | |
248 { | |
249 /* An Athena menubar has not been implemented. */ | |
250 return; | |
251 } | |
252 | |
253 void | |
254 xaw_pop_instance (widget_instance *instance, Boolean up) | |
255 { | |
256 Widget widget = instance->widget; | |
257 | |
258 if (up) | |
259 { | |
260 #ifdef LWLIB_DIALOGS_ATHENA | |
261 if (XtIsSubclass (widget, dialogWidgetClass)) | |
262 { | |
263 /* For dialogs, we need to call XtPopup on the parent instead | |
264 of calling XtManageChild on the widget. | |
265 Also we need to hack the shell's WM_PROTOCOLS to get it to | |
266 understand what the close box is supposed to do!! | |
267 */ | |
268 Display *dpy = XtDisplay (widget); | |
269 Widget shell = XtParent (widget); | |
270 Atom props [2]; | |
271 int i = 0; | |
272 props [i++] = XInternAtom (dpy, "WM_DELETE_WINDOW", False); | |
273 XChangeProperty (dpy, XtWindow (shell), | |
274 XInternAtom (dpy, "WM_PROTOCOLS", False), | |
275 XA_ATOM, 32, PropModeAppend, | |
276 (unsigned char *) props, i); | |
277 | |
278 /* Center the widget in its parent. Why isn't this kind of crap | |
279 done automatically? I thought toolkits were supposed to make | |
280 life easier? | |
281 */ | |
282 { | |
283 unsigned int x, y, w, h; | |
284 Widget topmost = instance->parent; | |
285 w = shell->core.width; | |
286 h = shell->core.height; | |
287 while (topmost->core.parent && | |
288 XtIsRealized (topmost->core.parent) && | |
289 /* HAVE_SESSION adds an unmapped parent widget that | |
290 we should ignore here. */ | |
291 topmost->core.parent->core.mapped_when_managed) | |
292 topmost = topmost->core.parent; | |
293 if (topmost->core.width < w) x = topmost->core.x; | |
294 else x = topmost->core.x + ((topmost->core.width - w) / 2); | |
295 if (topmost->core.height < h) y = topmost->core.y; | |
296 else y = topmost->core.y + ((topmost->core.height - h) / 2); | |
297 XtMoveWidget (shell, x, y); | |
298 } | |
299 | |
300 /* Finally, pop it up. */ | |
301 XtPopup (shell, XtGrabNonexclusive); | |
302 } | |
303 else | |
304 #endif /* LWLIB_DIALOGS_ATHENA */ | |
305 XtManageChild (widget); | |
306 } | |
307 else | |
308 { | |
309 #ifdef LWLIB_DIALOGS_ATHENA | |
310 if (XtIsSubclass (widget, dialogWidgetClass)) | |
311 XtUnmanageChild (XtParent (widget)); | |
312 else | |
313 #endif | |
314 XtUnmanageChild (widget); | |
315 } | |
316 } | |
317 | |
318 | |
319 #ifdef LWLIB_DIALOGS_ATHENA | |
320 /* Dialog boxes */ | |
321 | |
322 static char overrideTrans[] = | |
323 "<Message>WM_PROTOCOLS: lwlib_delete_dialog()"; | |
324 static XtActionProc wm_delete_window (Widget shell, XtPointer closure, | |
325 XtPointer call_data); | |
326 static XtActionsRec xaw_actions [] = { | |
327 {"lwlib_delete_dialog", (XtActionProc) wm_delete_window} | |
328 }; | |
329 static Boolean actions_initted = False; | |
330 | |
331 static Widget | |
332 make_dialog (CONST char* name, Widget parent, Boolean pop_up_p, | |
333 CONST char* shell_title, CONST char* icon_name, | |
334 Boolean text_input_slot, | |
335 Boolean radio_box, Boolean list, | |
336 int left_buttons, int right_buttons) | |
337 { | |
338 Arg av [20]; | |
339 int ac = 0; | |
340 int i, bc; | |
341 char button_name [255]; | |
342 Widget shell; | |
343 Widget dialog; | |
344 Widget button; | |
345 XtTranslations override; | |
346 | |
347 if (! pop_up_p) abort (); /* not implemented */ | |
348 if (text_input_slot) abort (); /* not implemented */ | |
349 if (radio_box) abort (); /* not implemented */ | |
350 if (list) abort (); /* not implemented */ | |
351 | |
352 if (! actions_initted) | |
353 { | |
354 XtAppContext app = XtWidgetToApplicationContext (parent); | |
355 XtAppAddActions (app, xaw_actions, | |
356 sizeof (xaw_actions) / sizeof (xaw_actions[0])); | |
357 actions_initted = True; | |
358 } | |
359 | |
360 override = XtParseTranslationTable (overrideTrans); | |
361 | |
362 ac = 0; | |
363 XtSetArg (av[ac], XtNtitle, shell_title); ac++; | |
364 XtSetArg (av[ac], XtNallowShellResize, True); ac++; | |
365 XtSetArg (av[ac], XtNtransientFor, parent); ac++; | |
366 shell = XtCreatePopupShell ("dialog", transientShellWidgetClass, | |
367 parent, av, ac); | |
368 XtOverrideTranslations (shell, override); | |
369 | |
370 ac = 0; | |
371 dialog = XtCreateManagedWidget (name, dialogWidgetClass, shell, av, ac); | |
372 | |
373 bc = 0; | |
374 button = 0; | |
375 for (i = 0; i < left_buttons; i++) | |
376 { | |
377 ac = 0; | |
378 XtSetArg (av [ac], XtNfromHoriz, button); ac++; | |
379 XtSetArg (av [ac], XtNleft, XtChainLeft); ac++; | |
380 XtSetArg (av [ac], XtNright, XtChainLeft); ac++; | |
381 XtSetArg (av [ac], XtNtop, XtChainBottom); ac++; | |
382 XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++; | |
383 XtSetArg (av [ac], XtNresizable, True); ac++; | |
384 sprintf (button_name, "button%d", ++bc); | |
385 button = XtCreateManagedWidget (button_name, commandWidgetClass, | |
386 dialog, av, ac); | |
387 } | |
388 if (right_buttons) | |
389 { | |
390 /* Create a separator | |
391 | |
392 I want the separator to take up the slack between the buttons on | |
393 the right and the buttons on the left (that is I want the buttons | |
394 after the separator to be packed against the right edge of the | |
395 window) but I can't seem to make it do it. | |
396 */ | |
397 ac = 0; | |
398 XtSetArg (av [ac], XtNfromHoriz, button); ac++; | |
399 /* XtSetArg (av [ac], XtNfromVert, XtNameToWidget (dialog, "label")); ac++; */ | |
400 XtSetArg (av [ac], XtNleft, XtChainLeft); ac++; | |
401 XtSetArg (av [ac], XtNright, XtChainRight); ac++; | |
402 XtSetArg (av [ac], XtNtop, XtChainBottom); ac++; | |
403 XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++; | |
404 XtSetArg (av [ac], XtNlabel, ""); ac++; | |
405 XtSetArg (av [ac], XtNwidth, 30); ac++; /* #### aaack!! */ | |
406 XtSetArg (av [ac], XtNborderWidth, 0); ac++; | |
407 XtSetArg (av [ac], XtNshapeStyle, XmuShapeRectangle); ac++; | |
408 XtSetArg (av [ac], XtNresizable, False); ac++; | |
409 XtSetArg (av [ac], XtNsensitive, False); ac++; | |
410 button = XtCreateManagedWidget ("separator", | |
411 /* labelWidgetClass, */ | |
412 /* This has to be Command to fake out | |
413 the Dialog widget... */ | |
414 commandWidgetClass, | |
415 dialog, av, ac); | |
416 } | |
417 for (i = 0; i < right_buttons; i++) | |
418 { | |
419 ac = 0; | |
420 XtSetArg (av [ac], XtNfromHoriz, button); ac++; | |
421 XtSetArg (av [ac], XtNleft, XtChainRight); ac++; | |
422 XtSetArg (av [ac], XtNright, XtChainRight); ac++; | |
423 XtSetArg (av [ac], XtNtop, XtChainBottom); ac++; | |
424 XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++; | |
425 XtSetArg (av [ac], XtNresizable, True); ac++; | |
426 sprintf (button_name, "button%d", ++bc); | |
427 button = XtCreateManagedWidget (button_name, commandWidgetClass, | |
428 dialog, av, ac); | |
429 } | |
430 | |
431 return dialog; | |
432 } | |
433 | |
434 Widget | |
435 xaw_create_dialog (widget_instance* instance) | |
436 { | |
437 char *name = instance->info->type; | |
438 Widget parent = instance->parent; | |
439 Widget widget; | |
440 Boolean pop_up_p = instance->pop_up_p; | |
441 CONST char *shell_name = 0; | |
442 CONST char *icon_name = 0; | |
443 Boolean text_input_slot = False; | |
444 Boolean radio_box = False; | |
445 Boolean list = False; | |
446 int total_buttons; | |
447 int left_buttons = 0; | |
448 int right_buttons = 1; | |
449 | |
450 switch (name [0]) { | |
451 case 'E': case 'e': | |
452 icon_name = "dbox-error"; | |
453 shell_name = "Error"; | |
454 break; | |
455 | |
456 case 'I': case 'i': | |
457 icon_name = "dbox-info"; | |
458 shell_name = "Information"; | |
459 break; | |
460 | |
461 case 'L': case 'l': | |
462 list = True; | |
463 icon_name = "dbox-question"; | |
464 shell_name = "Prompt"; | |
465 break; | |
466 | |
467 case 'P': case 'p': | |
468 text_input_slot = True; | |
469 icon_name = "dbox-question"; | |
470 shell_name = "Prompt"; | |
471 break; | |
472 | |
473 case 'Q': case 'q': | |
474 icon_name = "dbox-question"; | |
475 shell_name = "Question"; | |
476 break; | |
477 } | |
478 | |
479 total_buttons = name [1] - '0'; | |
480 | |
481 if (name [3] == 'T' || name [3] == 't') | |
482 { | |
483 text_input_slot = False; | |
484 radio_box = True; | |
485 } | |
486 else if (name [3]) | |
487 right_buttons = name [4] - '0'; | |
488 | |
489 left_buttons = total_buttons - right_buttons; | |
490 | |
491 widget = make_dialog (name, parent, pop_up_p, | |
492 shell_name, icon_name, text_input_slot, radio_box, | |
493 list, left_buttons, right_buttons); | |
494 | |
495 return widget; | |
496 } | |
497 #endif /* LWLIB_DIALOGS_ATHENA */ | |
498 | |
499 | |
500 static void | |
501 xaw_generic_callback (Widget widget, XtPointer closure, XtPointer call_data) | |
502 { | |
503 widget_instance *instance = (widget_instance *) closure; | |
504 Widget instance_widget; | |
505 LWLIB_ID id; | |
506 XtPointer user_data; | |
507 #ifdef LWLIB_WIDGETS_ATHENA | |
508 /* We want the selected status to change only when we decide it | |
509 should change. Yuck but correct. */ | |
510 if (XtIsSubclass (widget, toggleWidgetClass)) | |
511 { | |
512 Boolean check; | |
513 Arg al [1]; | |
514 | |
515 XtSetArg (al [0], XtNstate, &check); | |
516 XtGetValues (widget, al, 1); | |
517 | |
518 XtSetArg (al [0], XtNstate, !check); | |
519 XtSetValues (widget, al, 1); | |
520 } | |
521 #endif /* LWLIB_WIDGETS_ATHENA */ | |
522 lw_internal_update_other_instances (widget, closure, call_data); | |
523 | |
524 if (! instance) | |
525 return; | |
526 if (widget->core.being_destroyed) | |
527 return; | |
528 | |
529 instance_widget = instance->widget; | |
530 if (!instance_widget) | |
531 return; | |
532 | |
533 id = instance->info->id; | |
534 | |
535 #if 0 | |
536 user_data = NULL; | |
537 { | |
538 Arg al [1]; | |
539 XtSetArg (al [0], XtNuserData, &user_data); | |
540 XtGetValues (widget, al, 1); | |
541 } | |
542 #else | |
543 /* Damn! Athena doesn't give us a way to hang our own data on the | |
544 buttons, so we have to go find it... I guess this assumes that | |
545 all instances of a button have the same call data. | |
546 | |
547 ... Which is a totally bogus assumption --andyp */ | |
548 { | |
549 widget_value *val = instance->info->val; | |
550 /* If the widget is a buffer/gutter widget then we already have | |
551 the one we are looking for, so don't try and descend the widget | |
552 tree. */ | |
553 if (val->contents) | |
554 { | |
555 char *name = XtName (widget); | |
556 val = val->contents; | |
557 while (val) | |
558 { | |
559 if (val->name && !strcmp (val->name, name)) | |
560 break; | |
561 val = val->next; | |
562 } | |
563 if (! val) abort (); | |
564 } | |
565 user_data = val->call_data; | |
566 } | |
567 #endif | |
568 | |
569 if (instance->info->selection_cb) | |
570 instance->info->selection_cb (widget, id, user_data); | |
571 } | |
572 | |
573 #ifdef LWLIB_DIALOGS_ATHENA | |
574 | |
575 static XtActionProc | |
576 wm_delete_window (Widget shell, XtPointer closure, XtPointer call_data) | |
577 { | |
578 LWLIB_ID id; | |
579 Widget *kids = 0; | |
580 Widget widget; | |
581 Arg al [1]; | |
582 if (! XtIsSubclass (shell, shellWidgetClass)) | |
583 abort (); | |
584 XtSetArg (al [0], XtNchildren, &kids); | |
585 XtGetValues (shell, al, 1); | |
586 if (!kids || !*kids) | |
587 abort (); | |
588 widget = kids [0]; | |
589 if (! XtIsSubclass (widget, dialogWidgetClass)) | |
590 abort (); | |
591 id = lw_get_widget_id (widget); | |
592 if (! id) abort (); | |
593 | |
594 { | |
595 widget_info *info = lw_get_widget_info (id); | |
596 if (! info) abort (); | |
597 if (info->selection_cb) | |
598 info->selection_cb (widget, id, (XtPointer) -1); | |
599 } | |
600 | |
601 lw_destroy_all_widgets (id); | |
602 return NULL; | |
603 } | |
604 | |
605 #endif /* LWLIB_DIALOGS_ATHENA */ | |
606 | |
607 | |
608 /* Scrollbars */ | |
609 | |
610 #ifdef LWLIB_SCROLLBARS_ATHENA | |
611 static void | |
612 xaw_scrollbar_scroll (Widget widget, XtPointer closure, XtPointer call_data) | |
613 { | |
614 widget_instance *instance = (widget_instance *) closure; | |
615 LWLIB_ID id; | |
616 scroll_event event_data; | |
617 | |
618 if (!instance || widget->core.being_destroyed) | |
619 return; | |
620 | |
621 id = instance->info->id; | |
622 event_data.slider_value = (int) call_data; | |
623 event_data.time = 0; | |
624 | |
625 if ((int) call_data > 0) | |
626 /* event_data.action = SCROLLBAR_PAGE_DOWN;*/ | |
627 event_data.action = SCROLLBAR_LINE_DOWN; | |
628 else | |
629 /* event_data.action = SCROLLBAR_PAGE_UP;*/ | |
630 event_data.action = SCROLLBAR_LINE_UP; | |
631 | |
632 if (instance->info->pre_activate_cb) | |
633 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data); | |
634 } | |
635 | |
636 static void | |
637 xaw_scrollbar_jump (Widget widget, XtPointer closure, XtPointer call_data) | |
638 { | |
639 widget_instance *instance = (widget_instance *) closure; | |
640 LWLIB_ID id; | |
641 scroll_event event_data; | |
642 scrollbar_values *val = | |
643 (scrollbar_values *) instance->info->val->scrollbar_data; | |
644 float percent; | |
645 | |
646 if (!instance || widget->core.being_destroyed) | |
647 return; | |
648 | |
649 id = instance->info->id; | |
650 | |
651 percent = * (float *) call_data; | |
652 event_data.slider_value = | |
653 (int) (percent * (float) (val->maximum - val->minimum)) + val->minimum; | |
654 | |
655 event_data.time = 0; | |
656 event_data.action = SCROLLBAR_DRAG; | |
657 | |
658 if (instance->info->pre_activate_cb) | |
659 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data); | |
660 } | |
661 | |
662 static Widget | |
663 xaw_create_scrollbar (widget_instance *instance, int vertical) | |
664 { | |
665 Arg av[10]; | |
666 int ac = 0; | |
667 | |
668 static XtCallbackRec jumpCallbacks[2] = | |
669 { {xaw_scrollbar_jump, NULL}, {NULL, NULL} }; | |
670 | |
671 static XtCallbackRec scrollCallbacks[2] = | |
672 { {xaw_scrollbar_scroll, NULL}, {NULL, NULL} }; | |
673 | |
674 jumpCallbacks[0].closure = scrollCallbacks[0].closure = (XtPointer) instance; | |
675 | |
676 /* #### This is tacked onto the with and height and completely | |
677 screws our geometry management. We should probably make the | |
678 top-level aware of this so that people could have a border but so | |
679 few people use the Athena scrollbar now that it really isn't | |
680 worth the effort, at least not at the moment. */ | |
681 XtSetArg (av [ac], XtNborderWidth, 0); ac++; | |
682 XtSetArg (av [ac], XtNorientation, | |
683 vertical ? XtorientVertical : XtorientHorizontal); ac++; | |
684 XtSetArg (av [ac], "jumpProc", jumpCallbacks); ac++; | |
685 XtSetArg (av [ac], "scrollProc", scrollCallbacks); ac++; | |
686 | |
687 return XtCreateWidget (instance->info->name, scrollbarWidgetClass, | |
688 instance->parent, av, ac); | |
689 } | |
690 | |
691 static Widget | |
692 xaw_create_vertical_scrollbar (widget_instance *instance) | |
693 { | |
694 return xaw_create_scrollbar (instance, 1); | |
695 } | |
696 | |
697 static Widget | |
698 xaw_create_horizontal_scrollbar (widget_instance *instance) | |
699 { | |
700 return xaw_create_scrollbar (instance, 0); | |
701 } | |
702 #endif /* LWLIB_SCROLLBARS_ATHENA */ | |
703 | |
704 #ifdef LWLIB_WIDGETS_ATHENA | |
705 /* glyph widgets */ | |
706 static Widget | |
707 xaw_create_button (widget_instance *instance) | |
708 { | |
709 Arg al[20]; | |
710 int ac = 0; | |
711 Widget button = 0; | |
712 widget_value* val = instance->info->val; | |
713 | |
714 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++; | |
715 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; | |
716 XtSetArg (al [ac], XtNjustify, XtJustifyCenter); ac++; | |
717 /* The highlight doesn't appear to be dynamically set which makes it | |
718 look ugly. I think this may be a LessTif bug but for now we just | |
719 get rid of it. */ | |
720 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++; | |
721 | |
722 /* add any args the user supplied for creation time */ | |
723 lw_add_value_args_to_args (val, al, &ac); | |
724 | |
725 if (!val->call_data) | |
726 button = XtCreateManagedWidget (val->name, labelWidgetClass, | |
727 instance->parent, al, ac); | |
728 | |
729 else | |
730 { | |
731 if (val->type == TOGGLE_TYPE || val->type == RADIO_TYPE) | |
732 { | |
733 XtSetArg (al [ac], XtNstate, val->selected); ac++; | |
734 button = XtCreateManagedWidget | |
735 (val->name, | |
736 val->type == TOGGLE_TYPE ? checkboxWidgetClass : radioWidgetClass, | |
737 instance->parent, al, ac); | |
738 } | |
739 else | |
740 { | |
741 button = XtCreateManagedWidget (val->name, commandWidgetClass, | |
742 instance->parent, al, ac); | |
743 } | |
744 XtRemoveAllCallbacks (button, XtNcallback); | |
745 XtAddCallback (button, XtNcallback, xaw_generic_callback, (XtPointer)instance); | |
746 } | |
747 | |
748 XtManageChild (button); | |
749 | |
750 return button; | |
751 } | |
752 | |
753 static Widget | |
754 xaw_create_label_field (widget_instance *instance) | |
755 { | |
756 return xaw_create_label (instance->parent, instance->info->val); | |
757 } | |
758 | |
759 Widget | |
760 xaw_create_label (Widget parent, widget_value* val) | |
761 { | |
762 Arg al[20]; | |
763 int ac = 0; | |
764 Widget label = 0; | |
765 | |
766 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++; | |
767 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; | |
768 XtSetArg (al [ac], XtNjustify, XtJustifyCenter); ac++; | |
769 | |
770 /* add any args the user supplied for creation time */ | |
771 lw_add_value_args_to_args (val, al, &ac); | |
772 | |
773 label = XtCreateManagedWidget (val->name, labelWidgetClass, | |
774 parent, al, ac); | |
775 | |
776 /* Do it again for arguments that have no effect until the widget is realized. */ | |
777 ac = 0; | |
778 lw_add_value_args_to_args (val, al, &ac); | |
779 XtSetValues (label, al, ac); | |
780 | |
781 return label; | |
782 } | |
783 | |
784 static Widget | |
785 xaw_create_progress (widget_instance *instance) | |
786 { | |
787 Arg al[20]; | |
788 int ac = 0; | |
789 Widget scale = 0; | |
790 widget_value* val = instance->info->val; | |
791 | |
792 if (!val->call_data) | |
793 { | |
794 XtSetArg (al [ac], XtNsensitive, False); ac++; | |
795 } | |
796 else | |
797 { | |
798 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++; | |
799 } | |
800 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; | |
801 XtSetArg (al [ac], XtNorientation, XtorientHorizontal); ac++; | |
802 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++; | |
803 XtSetArg (al [ac], XtNntics, (Cardinal)10);ac++; | |
804 | |
805 /* add any args the user supplied for creation time */ | |
806 lw_add_value_args_to_args (val, al, &ac); | |
807 | |
808 scale = XtCreateManagedWidget (val->name, gaugeWidgetClass, | |
809 instance->parent, al, ac); | |
810 /* add the callback */ | |
811 if (val->call_data) | |
812 XtAddCallback (scale, XtNgetValue, xaw_generic_callback, (XtPointer)instance); | |
813 | |
814 XtManageChild (scale); | |
815 | |
816 return scale; | |
817 } | |
818 | |
819 #ifndef NEED_MOTIF | |
820 static Widget | |
821 xaw_create_text_field (widget_instance *instance) | |
822 { | |
823 Arg al[20]; | |
824 int ac = 0; | |
825 Widget text = 0; | |
826 widget_value* val = instance->info->val; | |
827 | |
828 XtSetArg (al [ac], XtNsensitive, val->enabled && val->call_data); ac++; | |
829 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; | |
830 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0); ac++; | |
831 XtSetArg (al [ac], XtNtype, XawAsciiString); ac++; | |
832 XtSetArg (al [ac], XtNeditType, XawtextEdit); ac++; | |
833 | |
834 /* add any args the user supplied for creation time */ | |
835 lw_add_value_args_to_args (val, al, &ac); | |
836 | |
837 text = XtCreateManagedWidget (val->name, asciiTextWidgetClass, | |
838 instance->parent, al, ac); | |
839 XtManageChild (text); | |
840 | |
841 return text; | |
842 } | |
843 #endif | |
844 #endif /* LWLIB_WIDGETS_ATHENA */ | |
845 | |
846 widget_creation_entry | |
847 xaw_creation_table [] = | |
848 { | |
849 #ifdef LWLIB_SCROLLBARS_ATHENA | |
850 {"vertical-scrollbar", xaw_create_vertical_scrollbar }, | |
851 {"horizontal-scrollbar", xaw_create_horizontal_scrollbar }, | |
852 #endif | |
853 #ifdef LWLIB_WIDGETS_ATHENA | |
854 {"button", xaw_create_button }, | |
855 { "label", xaw_create_label_field }, | |
856 #ifndef NEED_MOTIF | |
857 {"text-field", xaw_create_text_field }, | |
858 #endif | |
859 {"progress", xaw_create_progress }, | |
860 #endif | |
861 {NULL, NULL} | |
862 }; | |
863 |