5626
|
1 /* The lwlib interface to "xlwmenu" menus.
|
|
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 "lwlib-Xlw.h"
|
|
21 #include <X11/StringDefs.h>
|
|
22 #include <X11/IntrinsicP.h>
|
|
23 #include <X11/ObjectP.h>
|
|
24 #include <X11/CompositeP.h>
|
|
25 #include <X11/Shell.h>
|
|
26 #include "xlwmenu.h"
|
|
27
|
|
28 /* Menu callbacks */
|
|
29 static void
|
|
30 pre_hook (Widget w, XtPointer client_data, XtPointer call_data)
|
|
31 {
|
|
32 widget_instance* instance = (widget_instance*)client_data;
|
|
33 widget_value* val;
|
|
34
|
|
35 if (w->core.being_destroyed)
|
|
36 return;
|
|
37
|
|
38 val = lw_get_widget_value_for_widget (instance, w);
|
|
39 if (instance->info->pre_activate_cb)
|
|
40 instance->info->pre_activate_cb (w, instance->info->id,
|
|
41 val ? val->call_data : NULL);
|
|
42 }
|
|
43
|
|
44 static void
|
|
45 pick_hook (Widget w, XtPointer client_data, XtPointer call_data)
|
|
46 {
|
|
47 widget_instance* instance = (widget_instance*)client_data;
|
|
48 widget_value* contents_val = (widget_value*)call_data;
|
|
49 widget_value* widget_val;
|
|
50 XtPointer widget_arg;
|
|
51
|
|
52 if (w->core.being_destroyed)
|
|
53 return;
|
|
54
|
|
55 if (instance->info->selection_cb && contents_val && contents_val->enabled
|
|
56 && !contents_val->contents)
|
|
57 instance->info->selection_cb (w, instance->info->id,
|
|
58 contents_val->call_data);
|
|
59
|
|
60 widget_val = lw_get_widget_value_for_widget (instance, w);
|
|
61 widget_arg = widget_val ? widget_val->call_data : NULL;
|
|
62 if (instance->info->post_activate_cb)
|
|
63 instance->info->post_activate_cb (w, instance->info->id, widget_arg);
|
|
64
|
|
65 }
|
|
66
|
|
67 /* creation functions */
|
|
68 static Widget
|
|
69 xlw_create_menubar (widget_instance* instance)
|
|
70 {
|
|
71 Widget widget =
|
|
72 XtVaCreateWidget (instance->info->name, xlwMenuWidgetClass,
|
|
73 instance->parent,
|
|
74 XtNmenu, instance->info->val,
|
|
75 0);
|
|
76 XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
|
|
77 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
|
|
78 return widget;
|
|
79 }
|
|
80
|
|
81 static Widget
|
|
82 xlw_create_popup_menu (widget_instance* instance)
|
|
83 {
|
|
84 Widget popup_shell =
|
|
85 XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
|
|
86 instance->parent, NULL, 0);
|
|
87
|
|
88 Widget widget =
|
|
89 XtVaCreateManagedWidget ("popup", xlwMenuWidgetClass,
|
|
90 popup_shell,
|
|
91 XtNmenu, instance->info->val,
|
|
92 XtNhorizontal, False,
|
|
93 0);
|
|
94
|
|
95 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
|
|
96
|
|
97 return popup_shell;
|
|
98 }
|
|
99
|
|
100 widget_creation_entry
|
|
101 xlw_creation_table [] =
|
|
102 {
|
|
103 {"menubar", xlw_create_menubar},
|
|
104 {"popup", xlw_create_popup_menu},
|
|
105 {NULL, NULL}
|
|
106 };
|
|
107
|
|
108 Boolean
|
|
109 lw_lucid_widget_p (Widget widget)
|
|
110 {
|
|
111 WidgetClass the_class = XtClass (widget);
|
|
112 if (the_class == xlwMenuWidgetClass)
|
|
113 return True;
|
|
114 if (the_class == overrideShellWidgetClass)
|
|
115 return
|
|
116 XtClass (((CompositeWidget)widget)->composite.children [0])
|
|
117 == xlwMenuWidgetClass;
|
|
118 return False;
|
|
119 }
|
|
120
|
|
121 void
|
|
122 xlw_update_one_widget (widget_instance* instance, Widget widget,
|
|
123 widget_value* val, Boolean deep_p)
|
|
124 {
|
|
125 XlwMenuWidget mw;
|
|
126
|
|
127 if (XtIsShell (widget))
|
|
128 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
|
|
129 else
|
|
130 mw = (XlwMenuWidget)widget;
|
|
131 XtVaSetValues (widget, XtNmenu, val, 0);
|
|
132 }
|
|
133
|
|
134 void
|
|
135 xlw_update_one_value (widget_instance* instance, Widget widget,
|
|
136 widget_value* val)
|
|
137 {
|
|
138 return;
|
|
139 }
|
|
140
|
|
141 void
|
|
142 xlw_pop_instance (widget_instance* instance, Boolean up)
|
|
143 {
|
|
144 }
|
|
145
|
|
146 void
|
|
147 xlw_popup_menu (Widget widget)
|
|
148 {
|
|
149 XButtonPressedEvent dummy;
|
|
150 XlwMenuWidget mw;
|
|
151
|
|
152 if (!XtIsShell (widget))
|
|
153 return;
|
|
154
|
|
155 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
|
|
156
|
|
157 dummy.type = ButtonPress;
|
|
158 dummy.serial = 0;
|
|
159 dummy.send_event = 0;
|
|
160 dummy.display = XtDisplay (widget);
|
|
161 dummy.window = XtWindow (XtParent (widget));
|
|
162 dummy.time = CurrentTime;
|
|
163 dummy.button = 0;
|
|
164 XQueryPointer (dummy.display, dummy.window, &dummy.root,
|
|
165 &dummy.subwindow, &dummy.x_root, &dummy.y_root,
|
|
166 &dummy.x, &dummy.y, &dummy.state);
|
|
167
|
|
168 pop_up_menu (mw, &dummy);
|
|
169 }
|
|
170
|
|
171 /* Destruction of instances */
|
|
172 void
|
|
173 xlw_destroy_instance (widget_instance* instance)
|
|
174 {
|
|
175 if (instance->widget)
|
|
176 XtDestroyWidget (instance->widget);
|
|
177 }
|
|
178
|