1 /* The lwlib interface to Athena widgets.
2 Copyright (C) 1993 Chuck Thompson <cthomp@cs.uiuc.edu>
3 Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 This file is part of the Lucid Widget Library.
8 The Lucid Widget Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 1, or (at your option)
13 The Lucid Widget Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
30 #include "../src/lisp.h"
32 #include "lwlib-Xaw.h"
34 #include <X11/StringDefs.h>
35 #include <X11/IntrinsicP.h>
36 #include <X11/CoreP.h>
37 #include <X11/Shell.h>
40 #include <X11/Xaw3d/Scrollbar.h>
41 #include <X11/Xaw3d/Paned.h>
42 #include <X11/Xaw3d/Dialog.h>
43 #include <X11/Xaw3d/Form.h>
44 #include <X11/Xaw3d/Command.h>
45 #include <X11/Xaw3d/Label.h>
46 #else /* !HAVE_XAW3D */
47 #include <X11/Xaw/Scrollbar.h>
48 #include <X11/Xaw/Paned.h>
49 #include <X11/Xaw/Dialog.h>
50 #include <X11/Xaw/Form.h>
51 #include <X11/Xaw/Command.h>
52 #include <X11/Xaw/Label.h>
53 #endif /* HAVE_XAW3D */
55 #include <X11/Xatom.h>
58 #include <X11/Xft/Xft.h>
60 struct widget_xft_data
65 XftColor xft_fg
, xft_bg
;
66 int p_width
, p_height
;
73 static void xaw_generic_callback (Widget widget
, XtPointer closure
, XtPointer call_data
);
77 lw_xaw_widget_p (Widget widget
)
79 return (XtIsSubclass (widget
, scrollbarWidgetClass
) ||
80 XtIsSubclass (widget
, dialogWidgetClass
));
85 xaw_update_scrollbar (instance
, widget
, val
)
86 widget_instance
*instance
;
90 if (val
->scrollbar_data
)
92 scrollbar_values
*data
= val
->scrollbar_data
;
93 Dimension height
, width
;
94 Dimension pos_x
, pos_y
;
95 int widget_shown
, widget_topOfThumb
;
96 float new_shown
, new_topOfThumb
;
98 XtVaGetValues (widget
,
103 XtNtopOfThumb
, &widget_topOfThumb
,
104 XtNshown
, &widget_shown
,
108 * First size and position the scrollbar widget.
109 * We need to position it to second-guess the Paned widget's notion
110 * of what should happen when the WMShell gets resized.
112 if (height
!= data
->scrollbar_height
|| pos_y
!= data
->scrollbar_pos
)
114 XtConfigureWidget (widget
, pos_x
, data
->scrollbar_pos
,
115 width
, data
->scrollbar_height
, 0);
117 XtVaSetValues (widget
,
118 XtNlength
, data
->scrollbar_height
,
124 * Now the size the scrollbar's slider.
126 new_shown
= (float) data
->slider_size
/
127 (float) (data
->maximum
- data
->minimum
);
129 new_topOfThumb
= (float) (data
->slider_position
- data
->minimum
) /
130 (float) (data
->maximum
- data
->minimum
);
137 if (new_topOfThumb
> 1.0)
138 new_topOfThumb
= 1.0;
139 if (new_topOfThumb
< 0)
142 if (new_shown
!= widget_shown
|| new_topOfThumb
!= widget_topOfThumb
)
143 XawScrollbarSetThumb (widget
, new_topOfThumb
, new_shown
);
150 fill_xft_data (struct widget_xft_data
*data
, Widget widget
, XftFont
*font
)
154 int screen
= XScreenNumberOfScreen (XtScreen (widget
));
156 data
->widget
= widget
;
157 data
->xft_font
= font
;
158 XtVaGetValues (widget
,
163 colors
[0].pixel
= data
->xft_fg
.pixel
= fg
;
164 colors
[1].pixel
= data
->xft_bg
.pixel
= bg
;
165 XQueryColors (XtDisplay (widget
),
166 DefaultColormapOfScreen (XtScreen (widget
)),
169 data
->xft_fg
.color
.alpha
= 0xFFFF;
170 data
->xft_fg
.color
.red
= colors
[0].red
;
171 data
->xft_fg
.color
.green
= colors
[0].green
;
172 data
->xft_fg
.color
.blue
= colors
[0].blue
;
173 data
->xft_bg
.color
.alpha
= 0xFFFF;
174 data
->xft_bg
.color
.red
= colors
[1].red
;
175 data
->xft_bg
.color
.green
= colors
[1].green
;
176 data
->xft_bg
.color
.blue
= colors
[1].blue
;
180 data
->p_width
= data
->p_height
= 0;
184 openFont (Widget widget
, char *name
)
187 int screen
= XScreenNumberOfScreen (XtScreen (widget
));
188 int len
= strlen (fname
), i
= len
-1;
191 /* Try to convert Gtk-syntax (Sans 9) to Xft syntax Sans-9. */
192 while (i
> 0 && isdigit (fname
[i
]))
196 fname
= xstrdup (name
);
200 fn
= XftFontOpenName (XtDisplay (widget
), screen
, fname
);
201 if (fname
!= name
) free (fname
);
207 get_text_width_and_height (Widget widget
, char *text
,
214 while (bp
&& *bp
!= '\0')
217 char *cp
= strchr (bp
, '\n');
218 XftTextExtentsUtf8 (XtDisplay (widget
), xft_font
,
220 cp
? cp
- bp
: strlen (bp
),
222 bp
= cp
? cp
+ 1 : NULL
;
223 h
+= xft_font
->height
;
224 if (w
< gi
.width
) w
= gi
.width
;
232 draw_text (struct widget_xft_data
*data
, char *lbl
, int inverse
)
234 Screen
*sc
= XtScreen (data
->widget
);
235 int screen
= XScreenNumberOfScreen (sc
);
236 int y
= data
->xft_font
->ascent
;
237 int x
= inverse
? 0 : 2;
240 data
->xft_draw
= XftDrawCreate (XtDisplay (data
->widget
),
242 DefaultVisual (XtDisplay (data
->widget
),
244 DefaultColormapOfScreen (sc
));
245 XftDrawRect (data
->xft_draw
,
246 inverse
? &data
->xft_fg
: &data
->xft_bg
,
247 0, 0, data
->p_width
, data
->p_height
);
249 if (!inverse
) y
+= 2;
250 while (bp
&& *bp
!= '\0')
252 char *cp
= strchr (bp
, '\n');
253 XftDrawStringUtf8 (data
->xft_draw
,
254 inverse
? &data
->xft_bg
: &data
->xft_fg
,
255 data
->xft_font
, x
, y
, bp
, cp
? cp
- bp
: strlen (bp
));
256 bp
= cp
? cp
+ 1 : NULL
;
257 /* 1.2 gives reasonable line spacing. */
258 y
+= data
->xft_font
->height
* 1.2;
265 set_text (struct widget_xft_data
*data
, Widget toplevel
, char *lbl
, int margin
)
267 int screen
= XScreenNumberOfScreen (XtScreen (data
->widget
));
270 width
= get_text_width_and_height (data
->widget
, lbl
, data
->xft_font
,
272 data
->p_width
= width
+ margin
;
273 data
->p_height
= height
+ margin
;
275 data
->p
= XCreatePixmap (XtDisplay (data
->widget
),
279 DefaultDepthOfScreen (XtScreen (data
->widget
)));
280 draw_text (data
, lbl
, 0);
281 XtVaSetValues (data
->widget
, XtNbitmap
, data
->p
, NULL
);
284 static struct widget_xft_data
*
285 find_xft_data (Widget widget
)
287 widget_instance
*inst
= NULL
;
288 Widget parent
= XtParent (widget
);
289 struct widget_xft_data
*data
= NULL
;
291 while (parent
&& !inst
)
293 inst
= lw_get_widget_instance (parent
);
294 parent
= XtParent (parent
);
296 if (!inst
|| !inst
->xft_data
|| !inst
->xft_data
[0].xft_font
) return;
298 for (nr
= 0; data
== NULL
&& nr
< inst
->nr_xft_data
; ++nr
)
300 if (inst
->xft_data
[nr
].widget
== widget
)
301 data
= &inst
->xft_data
[nr
];
308 command_press (Widget widget
,
311 Cardinal
*num_params
)
313 struct widget_xft_data
*data
= find_xft_data (widget
);
317 /* Since this isn't used for rectangle buttons, use it to for armed. */
318 XtVaSetValues (widget
, XtNcornerRoundPercent
, 1, NULL
);
320 XtVaGetValues (widget
, XtNlabel
, &lbl
, NULL
);
321 draw_text (data
, lbl
, 1);
326 command_reset (Widget widget
,
329 Cardinal
*num_params
)
331 struct widget_xft_data
*data
= find_xft_data (widget
);
335 XtVaGetValues (widget
, XtNcornerRoundPercent
, &cr
, NULL
);
339 XtVaSetValues (widget
, XtNcornerRoundPercent
, 0, NULL
);
340 XtVaGetValues (widget
, XtNlabel
, &lbl
, NULL
);
341 draw_text (data
, lbl
, 0);
351 xaw_update_one_widget (widget_instance
*instance
, Widget widget
,
352 widget_value
*val
, Boolean deep_p
)
354 xaw_update_one_widget (instance
, widget
, val
, deep_p
)
355 widget_instance
*instance
;
362 if (XtIsSubclass (widget
, scrollbarWidgetClass
))
364 xaw_update_scrollbar (instance
, widget
, val
);
367 if (XtIsSubclass (widget
, dialogWidgetClass
))
371 if (instance
->xft_data
&& instance
->xft_data
[0].xft_font
)
373 set_text (&instance
->xft_data
[0], instance
->parent
,
374 val
->contents
->value
, 10);
377 XtVaSetValues (widget
, XtNlabel
, val
->contents
->value
, NULL
);
379 else if (XtIsSubclass (widget
, commandWidgetClass
))
385 XtVaGetValues (widget
, XtNborderWidth
, &bw
, NULL
);
387 /* Don't let buttons end up with 0 borderwidth, that's ugly...
388 Yeah, all this should really be done through app-defaults files
389 or fallback resources, but that's a whole different can of worms
390 that I don't feel like opening right now. Making Athena widgets
391 not look like shit is just entirely too much work.
394 XtSetArg (al
[0], XtNborderWidth
, 1);
395 XtSetValues (widget
, al
, 1);
398 XtSetSensitive (widget
, val
->enabled
);
399 XtSetArg (al
[ac
], XtNlabel
, val
->value
);ac
++;
400 /* Force centered button text. Se above. */
401 XtSetArg (al
[ac
], XtNjustify
, XtJustifyCenter
);ac
++;
403 if (instance
->xft_data
&& instance
->xft_data
[0].xft_font
)
407 for (nr
= 0; nr
< instance
->nr_xft_data
; ++nr
)
408 if (instance
->xft_data
[nr
].widget
== widget
)
410 if (nr
< instance
->nr_xft_data
)
412 set_text (&instance
->xft_data
[nr
], instance
->parent
,
415 /* Must set internalHeight to twice the highlight thickness,
416 or else it gets overwritten by our pixmap. Probably a bug. */
417 XtVaGetValues (widget
, XtNhighlightThickness
, &th
, NULL
);
418 XtSetArg (al
[ac
], XtNinternalHeight
, 2*th
);ac
++;
422 XtSetValues (widget
, al
, ac
);
423 XtRemoveAllCallbacks (widget
, XtNcallback
);
424 XtAddCallback (widget
, XtNcallback
, xaw_generic_callback
, instance
);
429 xaw_update_one_value (widget_instance
*instance
, Widget widget
, widget_value
*val
)
431 /* This function is not used by the scrollbars and those are the only
432 Athena widget implemented at the moment so do nothing. */
437 xaw_destroy_instance (widget_instance
*instance
)
440 if (instance
->xft_data
)
443 for (i
= 0; i
< instance
->nr_xft_data
; ++i
)
445 if (instance
->xft_data
[i
].xft_draw
)
446 XftDrawDestroy (instance
->xft_data
[i
].xft_draw
);
447 if (instance
->xft_data
[i
].p
!= None
)
449 XtVaSetValues (instance
->xft_data
[i
].widget
, XtNbitmap
, None
,
451 XFreePixmap (XtDisplay (instance
->widget
),
452 instance
->xft_data
[i
].p
);
455 if (instance
->xft_data
[0].xft_font
)
456 XftFontClose (XtDisplay (instance
->widget
),
457 instance
->xft_data
[0].xft_font
);
458 free (instance
->xft_data
);
461 if (XtIsSubclass (instance
->widget
, dialogWidgetClass
))
462 /* Need to destroy the Shell too. */
463 XtDestroyWidget (XtParent (instance
->widget
));
465 XtDestroyWidget (instance
->widget
);
469 xaw_popup_menu (Widget widget
, XEvent
*event
)
471 /* An Athena menubar has not been implemented. */
477 xaw_pop_instance (widget_instance
*instance
, Boolean up
)
479 xaw_pop_instance (instance
, up
)
480 widget_instance
*instance
;
484 Widget widget
= instance
->widget
;
488 if (XtIsSubclass (widget
, dialogWidgetClass
))
490 /* For dialogs, we need to call XtPopup on the parent instead
491 of calling XtManageChild on the widget.
492 Also we need to hack the shell's WM_PROTOCOLS to get it to
493 understand what the close box is supposed to do!!
495 Display
*dpy
= XtDisplay (widget
);
496 Widget shell
= XtParent (widget
);
499 props
[i
++] = XInternAtom (dpy
, "WM_DELETE_WINDOW", False
);
500 XChangeProperty (dpy
, XtWindow (shell
),
501 XInternAtom (dpy
, "WM_PROTOCOLS", False
),
502 XA_ATOM
, 32, PropModeAppend
,
503 (unsigned char *) props
, i
);
505 /* Center the widget in its parent. Why isn't this kind of crap
506 done automatically? I thought toolkits were supposed to make
510 unsigned int x
, y
, w
, h
;
511 Widget topmost
= instance
->parent
;
514 w
= shell
->core
.width
;
515 h
= shell
->core
.height
;
516 while (topmost
->core
.parent
&& XtIsRealized (topmost
->core
.parent
))
517 topmost
= topmost
->core
.parent
;
518 if (topmost
->core
.width
< w
) x
= topmost
->core
.x
;
519 else x
= topmost
->core
.x
+ ((topmost
->core
.width
- w
) / 2);
520 if (topmost
->core
.height
< h
) y
= topmost
->core
.y
;
521 else y
= topmost
->core
.y
+ ((topmost
->core
.height
- h
) / 2);
522 /* Using XtMoveWidget caused the widget to come
523 out in the wrong place with vtwm.
524 Question of virtual vs real coords, perhaps. */
525 XtSetArg (args
[0], XtNx
, x
);
526 XtSetArg (args
[1], XtNy
, y
);
527 XtSetValues (shell
, args
, 2);
530 /* Finally, pop it up. */
531 XtPopup (shell
, XtGrabNonexclusive
);
534 XtManageChild (widget
);
538 if (XtIsSubclass (widget
, dialogWidgetClass
))
539 XtUnmanageChild (XtParent (widget
));
541 XtUnmanageChild (widget
);
548 static char overrideTrans
[] =
549 "<Message>WM_PROTOCOLS: lwlib_delete_dialog()";
550 /* Dialogs pop down on any key press */
551 static char dialogOverride
[] =
552 "<KeyPress>Escape: lwlib_delete_dialog()";
553 static void wm_delete_window(Widget w
, XtPointer closure
, XtPointer call_data
);
554 static XtActionsRec xaw_actions
[] = {
555 {"lwlib_delete_dialog", wm_delete_window
}
557 static Boolean actions_initted
= False
;
560 static XtActionsRec button_actions
[] =
562 { "my_reset", command_reset
},
563 { "my_press", command_press
},
566 "<Leave>: reset() my_reset()\n"
567 "<Btn1Down>: set() my_press()\n"
568 "<Btn1Up>: my_reset() notify() unset()\n";
572 make_dialog (name
, parent
, pop_up_p
, shell_title
, icon_name
, text_input_slot
,
573 radio_box
, list
, left_buttons
, right_buttons
, instance
)
579 Boolean text_input_slot
;
584 widget_instance
*instance
;
589 char button_name
[255];
593 XtTranslations override
;
595 XftFont
*xft_font
= 0;
596 XtTranslations button_override
;
599 if (! pop_up_p
) abort (); /* not implemented */
600 if (text_input_slot
) abort (); /* not implemented */
601 if (radio_box
) abort (); /* not implemented */
602 if (list
) abort (); /* not implemented */
604 if (! actions_initted
)
606 XtAppContext app
= XtWidgetToApplicationContext (parent
);
607 XtAppAddActions (app
, xaw_actions
,
608 sizeof (xaw_actions
) / sizeof (xaw_actions
[0]));
610 XtAppAddActions (app
, button_actions
,
611 sizeof (button_actions
) / sizeof (button_actions
[0]));
613 actions_initted
= True
;
616 override
= XtParseTranslationTable (overrideTrans
);
619 XtSetArg (av
[ac
], XtNtitle
, shell_title
); ac
++;
620 XtSetArg (av
[ac
], XtNallowShellResize
, True
); ac
++;
622 /* Don't allow any geometry request from the user. */
623 XtSetArg (av
[ac
], XtNgeometry
, 0); ac
++;
625 shell
= XtCreatePopupShell ("dialog", transientShellWidgetClass
,
627 XtOverrideTranslations (shell
, override
);
630 dialog
= XtCreateManagedWidget (name
, dialogWidgetClass
, shell
, av
, ac
);
631 override
= XtParseTranslationTable (dialogOverride
);
632 XtOverrideTranslations (dialog
, override
);
639 XtVaGetValues (dialog
,
640 XtNnumChildren
, &num
,
641 XtNchildren
, &ch
, NULL
);
642 for (i
= 0; i
< num
; ++i
)
644 if (!XtIsSubclass (ch
[i
], commandWidgetClass
)
645 && XtIsSubclass (ch
[i
], labelWidgetClass
))
651 instance
->xft_data
= 0;
652 instance
->nr_xft_data
= 0;
656 { { "faceName", "FaceName", XtRString
, sizeof(String
), 0, XtRString
,
657 (XtPointer
)"Sans-14" }};
659 XtVaGetSubresources (dialog
, &faceName
, "Dialog", "dialog",
660 rec
, 1, (String
)NULL
);
661 if (strcmp ("none", faceName
) != 0)
662 xft_font
= openFont (dialog
, faceName
);
665 instance
->nr_xft_data
= left_buttons
+ right_buttons
+ 1;
666 instance
->xft_data
= calloc (instance
->nr_xft_data
,
667 sizeof(*instance
->xft_data
));
669 fill_xft_data (&instance
->xft_data
[0], w
, xft_font
);
673 button_override
= XtParseTranslationTable (buttonTrans
);
679 for (i
= 0; i
< left_buttons
; i
++)
682 XtSetArg (av
[ac
], XtNfromHoriz
, button
); ac
++;
683 XtSetArg (av
[ac
], XtNleft
, XtChainLeft
); ac
++;
684 XtSetArg (av
[ac
], XtNright
, XtChainLeft
); ac
++;
685 XtSetArg (av
[ac
], XtNtop
, XtChainBottom
); ac
++;
686 XtSetArg (av
[ac
], XtNbottom
, XtChainBottom
); ac
++;
687 XtSetArg (av
[ac
], XtNresizable
, True
); ac
++;
689 if (DefaultDepthOfScreen (XtScreen (dialog
)) >= 16)
691 /* Turn of dithered shadow if we can. Looks bad */
692 XtSetArg (av
[ac
], "beNiceToColormap", False
); ac
++;
695 sprintf (button_name
, "button%d", ++bc
);
696 button
= XtCreateManagedWidget (button_name
, commandWidgetClass
,
701 fill_xft_data (&instance
->xft_data
[bc
], button
, xft_font
);
702 XtOverrideTranslations (button
, button_override
);
707 for (i
= 0; i
< right_buttons
; i
++)
710 XtSetArg (av
[ac
], XtNfromHoriz
, button
); ac
++;
713 /* Separator to the other buttons. */
714 XtSetArg (av
[ac
], XtNhorizDistance
, 30); ac
++;
716 XtSetArg (av
[ac
], XtNleft
, XtChainRight
); ac
++;
717 XtSetArg (av
[ac
], XtNright
, XtChainRight
); ac
++;
718 XtSetArg (av
[ac
], XtNtop
, XtChainBottom
); ac
++;
719 XtSetArg (av
[ac
], XtNbottom
, XtChainBottom
); ac
++;
720 XtSetArg (av
[ac
], XtNresizable
, True
); ac
++;
722 if (DefaultDepthOfScreen (XtScreen (dialog
)) >= 16)
724 /* Turn of dithered shadow if we can. Looks bad */
725 XtSetArg (av
[ac
], "beNiceToColormap", False
); ac
++;
728 sprintf (button_name
, "button%d", ++bc
);
729 button
= XtCreateManagedWidget (button_name
, commandWidgetClass
,
734 fill_xft_data (&instance
->xft_data
[bc
], button
, xft_font
);
735 XtOverrideTranslations (button
, button_override
);
744 xaw_create_dialog (widget_instance
*instance
)
746 char *name
= instance
->info
->type
;
747 Widget parent
= instance
->parent
;
749 Boolean pop_up_p
= instance
->pop_up_p
;
750 char *shell_name
= 0;
752 Boolean text_input_slot
= False
;
753 Boolean radio_box
= False
;
754 Boolean list
= False
;
756 int left_buttons
= 0;
757 int right_buttons
= 1;
761 icon_name
= "dbox-error";
762 shell_name
= "Error";
766 icon_name
= "dbox-info";
767 shell_name
= "Information";
772 icon_name
= "dbox-question";
773 shell_name
= "Prompt";
777 text_input_slot
= True
;
778 icon_name
= "dbox-question";
779 shell_name
= "Prompt";
783 icon_name
= "dbox-question";
784 shell_name
= "Question";
788 total_buttons
= name
[1] - '0';
790 if (name
[3] == 'T' || name
[3] == 't')
792 text_input_slot
= False
;
796 right_buttons
= name
[4] - '0';
798 left_buttons
= total_buttons
- right_buttons
;
800 widget
= make_dialog (name
, parent
, pop_up_p
,
801 shell_name
, icon_name
, text_input_slot
, radio_box
,
802 list
, left_buttons
, right_buttons
, instance
);
808 xaw_generic_callback (Widget widget
, XtPointer closure
, XtPointer call_data
)
810 widget_instance
*instance
= (widget_instance
*) closure
;
811 Widget instance_widget
;
815 lw_internal_update_other_instances (widget
, closure
, call_data
);
819 if (widget
->core
.being_destroyed
)
822 instance_widget
= instance
->widget
;
823 if (!instance_widget
)
826 id
= instance
->info
->id
;
830 XtVaGetValues (widget
, XtNuserData
, &user_data
, NULL
);
832 /* Damn! Athena doesn't give us a way to hang our own data on the
833 buttons, so we have to go find it... I guess this assumes that
834 all instances of a button have the same call data. */
836 widget_value
*val
= instance
->info
->val
->contents
;
837 char *name
= XtName (widget
);
840 if (val
->name
&& !strcmp (val
->name
, name
))
845 user_data
= val
->call_data
;
849 if (instance
->info
->selection_cb
)
850 instance
->info
->selection_cb (widget
, id
, user_data
);
854 wm_delete_window (Widget w
, XtPointer closure
, XtPointer call_data
)
860 Widget widget
, shell
;
862 if (XtIsSubclass (w
, dialogWidgetClass
))
863 shell
= XtParent (w
);
867 if (! XtIsSubclass (shell
, shellWidgetClass
))
869 XtVaGetValues (shell
, XtNnumChildren
, &nkids
, NULL
);
870 XtVaGetValues (shell
, XtNchildren
, &kids
, NULL
);
873 for (i
= 0; i
< nkids
; i
++)
876 if (XtIsSubclass (widget
, dialogWidgetClass
))
879 id
= lw_get_widget_id (widget
);
883 widget_info
*info
= lw_get_widget_info (id
);
884 if (! info
) abort ();
885 if (info
->selection_cb
)
886 info
->selection_cb (widget
, id
, (XtPointer
) -1);
889 lw_destroy_all_widgets (id
);
897 xaw_scrollbar_scroll (widget
, closure
, call_data
)
902 widget_instance
*instance
= (widget_instance
*) closure
;
904 scroll_event event_data
;
906 if (!instance
|| widget
->core
.being_destroyed
)
909 id
= instance
->info
->id
;
910 event_data
.slider_value
= 0;
913 if ((int) call_data
> 0)
914 event_data
.action
= SCROLLBAR_PAGE_DOWN
;
916 event_data
.action
= SCROLLBAR_PAGE_UP
;
918 if (instance
->info
->pre_activate_cb
)
919 instance
->info
->pre_activate_cb (widget
, id
, (XtPointer
) &event_data
);
925 xaw_scrollbar_jump (widget
, closure
, call_data
)
930 widget_instance
*instance
= (widget_instance
*) closure
;
932 scroll_event event_data
;
933 scrollbar_values
*val
=
934 (scrollbar_values
*) instance
->info
->val
->scrollbar_data
;
937 if (!instance
|| widget
->core
.being_destroyed
)
940 id
= instance
->info
->id
;
942 percent
= * (float *) call_data
;
943 event_data
.slider_value
=
944 (int) (percent
* (float) (val
->maximum
- val
->minimum
)) + val
->minimum
;
947 event_data
.action
= SCROLLBAR_DRAG
;
949 if (instance
->info
->pre_activate_cb
)
950 instance
->info
->pre_activate_cb (widget
, id
, (XtPointer
) &event_data
);
955 xaw_create_scrollbar (widget_instance
*instance
)
963 XtVaGetValues (instance
->parent
, XtNwidth
, &width
, NULL
);
965 XtSetArg (av
[ac
], XtNshowGrip
, 0); ac
++;
966 XtSetArg (av
[ac
], XtNresizeToPreferred
, 1); ac
++;
967 XtSetArg (av
[ac
], XtNallowResize
, True
); ac
++;
968 XtSetArg (av
[ac
], XtNskipAdjust
, True
); ac
++;
969 XtSetArg (av
[ac
], XtNwidth
, width
); ac
++;
970 XtSetArg (av
[ac
], XtNmappedWhenManaged
, True
); ac
++;
973 XtCreateWidget (instance
->info
->name
, scrollbarWidgetClass
,
974 instance
->parent
, av
, ac
);
976 /* We have to force the border width to be 0 otherwise the
977 geometry manager likes to start looping for awhile... */
978 XtVaSetValues (scrollbar
, XtNborderWidth
, 0, NULL
);
980 XtRemoveAllCallbacks (scrollbar
, "jumpProc");
981 XtRemoveAllCallbacks (scrollbar
, "scrollProc");
983 XtAddCallback (scrollbar
, "jumpProc", xaw_scrollbar_jump
,
984 (XtPointer
) instance
);
985 XtAddCallback (scrollbar
, "scrollProc", xaw_scrollbar_scroll
,
986 (XtPointer
) instance
);
995 xaw_create_main (widget_instance
*instance
)
1000 /* Create a vertical Paned to hold menubar */
1002 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
1003 return XtCreateWidget (instance
->info
->name
, panedWidgetClass
,
1004 instance
->parent
, al
, ac
);
1007 widget_creation_entry
1008 xaw_creation_table
[] =
1010 {"scrollbar", xaw_create_scrollbar
},
1011 {"main", xaw_create_main
},
1015 /* arch-tag: fbbd3589-ae1c-41a0-9142-f628cfee6564
1016 (do not change this comment) */