Sat, 11 Nov 2017 11:59:06 +0100
adds observer support for textarea and textfield (GTK)
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2014 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
31 | #include <stdarg.h> |
0 | 32 | |
33 | #include "menu.h" | |
34 | #include "button.h" | |
35 | #include "toolkit.h" | |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
36 | #include "stock.h" |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
37 | #include "container.h" |
0 | 38 | #include "../common/context.h" |
39 | #include "../ui/window.h" | |
40 | ||
41 | UcxList *menus; | |
42 | UcxList *current; | |
43 | ||
44 | void ui_menu(char *label) { | |
45 | // free current menu hierarchy | |
46 | ucx_list_free(current); | |
47 | ||
48 | // create menu | |
49 | UiMenu *menu = malloc(sizeof(UiMenu)); | |
50 | menu->item.add_to = (ui_menu_add_f)add_menu_widget; | |
51 | ||
52 | menu->label = label; | |
53 | menu->items = NULL; | |
54 | menu->parent = NULL; | |
55 | ||
56 | current = ucx_list_prepend(NULL, menu); | |
57 | menus = ucx_list_append(menus, menu); | |
58 | ||
59 | } | |
60 | ||
61 | void ui_submenu(char *label) { | |
62 | UiMenu *menu = malloc(sizeof(UiMenu)); | |
63 | menu->item.add_to = (ui_menu_add_f)add_menu_widget; | |
64 | ||
65 | menu->label = label; | |
66 | menu->items = NULL; | |
67 | menu->parent = NULL; | |
68 | ||
69 | // add submenu to current menu | |
70 | UiMenu *cm = current->data; | |
71 | cm->items = ucx_list_append(cm->items, menu); | |
72 | ||
73 | // set the submenu to current menu | |
74 | current = ucx_list_prepend(current, menu); | |
75 | } | |
76 | ||
77 | void ui_submenu_end() { | |
78 | if(ucx_list_size(current) < 2) { | |
79 | return; | |
80 | } | |
81 | current = ucx_list_remove(current, current); | |
82 | } | |
83 | ||
84 | void ui_menuitem(char *label, ui_callback f, void *userdata) { | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
85 | ui_menuitem_gr(label, f, userdata, -1); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
86 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
87 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
88 | void ui_menuitem_st(char *stockid, ui_callback f, void *userdata) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
89 | ui_menuitem_stgr(stockid, f, userdata, -1); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
90 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
91 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
92 | void ui_menuitem_gr(char *label, ui_callback f, void *userdata, ...) { |
0 | 93 | if(!current) { |
94 | return; | |
95 | } | |
96 | ||
97 | UiMenuItem *item = malloc(sizeof(UiMenuItem)); | |
98 | item->item.add_to = (ui_menu_add_f)add_menuitem_widget; | |
99 | ||
100 | item->label = label; | |
101 | item->userdata = userdata; | |
102 | item->callback = f; | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
103 | item->groups = NULL; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
104 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
105 | // add groups |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
106 | va_list ap; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
107 | va_start(ap, userdata); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
108 | int group; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
109 | while((group = va_arg(ap, int)) != -1) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
110 | item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
111 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
112 | va_end(ap); |
0 | 113 | |
114 | UiMenu *cm = current->data; | |
115 | cm->items = ucx_list_append(cm->items, item); | |
116 | } | |
117 | ||
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
118 | void ui_menuitem_stgr(char *stockid, ui_callback f, void *userdata, ...) { |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
119 | if(!current) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
120 | return; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
121 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
122 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
123 | UiStMenuItem *item = malloc(sizeof(UiStMenuItem)); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
124 | item->item.add_to = (ui_menu_add_f)add_menuitem_st_widget; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
125 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
126 | item->stockid = stockid; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
127 | item->userdata = userdata; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
128 | item->callback = f; |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
129 | item->groups = NULL; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
130 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
131 | // add groups |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
132 | va_list ap; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
133 | va_start(ap, userdata); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
134 | int group; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
135 | while((group = va_arg(ap, int)) != -1) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
136 | item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
137 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
138 | va_end(ap); |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
139 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
140 | UiMenu *cm = current->data; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
141 | cm->items = ucx_list_append(cm->items, item); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
142 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
143 | |
0 | 144 | void ui_menuseparator() { |
145 | if(!current) { | |
146 | return; | |
147 | } | |
148 | ||
149 | UiMenuItemI *item = malloc(sizeof(UiMenuItemI)); | |
150 | item->add_to = (ui_menu_add_f)add_menuseparator_widget; | |
151 | ||
152 | UiMenu *cm = current->data; | |
153 | cm->items = ucx_list_append(cm->items, item); | |
154 | } | |
155 | ||
156 | ||
157 | void ui_checkitem(char *label, ui_callback f, void *userdata) { | |
158 | if(!current) { | |
159 | return; | |
160 | } | |
161 | ||
162 | UiCheckItem *item = malloc(sizeof(UiCheckItem)); | |
163 | item->item.add_to = (ui_menu_add_f)add_checkitem_widget; | |
164 | item->label = label; | |
165 | item->callback = f; | |
166 | item->userdata = userdata; | |
167 | ||
168 | UiMenu *cm = current->data; | |
169 | cm->items = ucx_list_append(cm->items, item); | |
170 | } | |
171 | ||
172 | void ui_checkitem_nv(char *label, char *vname) { | |
173 | if(!current) { | |
174 | return; | |
175 | } | |
176 | ||
177 | UiCheckItemNV *item = malloc(sizeof(UiCheckItemNV)); | |
178 | item->item.add_to = (ui_menu_add_f)add_checkitemnv_widget; | |
179 | item->varname = vname; | |
180 | item->label = label; | |
181 | ||
182 | UiMenu *cm = current->data; | |
183 | cm->items = ucx_list_append(cm->items, item); | |
184 | } | |
185 | ||
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
186 | void ui_menuitem_list(UiList *items, ui_callback f, void *userdata) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
187 | if(!current) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
188 | return; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
189 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
190 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
191 | UiMenuItemList *item = malloc(sizeof(UiMenuItemList)); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
192 | item->item.add_to = (ui_menu_add_f)add_menuitem_list_widget; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
193 | item->callback = f; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
194 | item->userdata = userdata; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
195 | item->list = items; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
196 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
197 | UiMenu *cm = current->data; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
198 | cm->items = ucx_list_append(cm->items, item); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
199 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
200 | |
0 | 201 | |
202 | // private menu functions | |
203 | void ui_create_menubar(UiObject *obj) { | |
204 | if(!menus) { | |
205 | return; | |
206 | } | |
207 | ||
208 | Widget menubar = XmCreateMenuBar(obj->widget, "main_list", NULL, 0); | |
209 | XtManageChild(menubar); | |
210 | ||
211 | UcxList *ls = menus; | |
212 | int menu_index = 0; | |
213 | while(ls) { | |
214 | UiMenu *menu = ls->data; | |
215 | menu_index += menu->item.add_to(menubar, menu_index, &menu->item, obj); | |
216 | ||
217 | ls = ls->next; | |
218 | } | |
219 | } | |
220 | ||
221 | int add_menu_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) { | |
222 | UiMenu *menu = (UiMenu*)item; | |
223 | ||
224 | Widget menuItem = XtVaCreateManagedWidget( | |
225 | menu->label, | |
226 | xmCascadeButtonWidgetClass, | |
227 | parent, | |
228 | NULL); | |
229 | Widget m = XmVaCreateSimplePulldownMenu(parent, menu->label, i, NULL, NULL); | |
230 | ||
231 | UcxList *ls = menu->items; | |
232 | int menu_index = 0; | |
233 | while(ls) { | |
234 | UiMenuItemI *mi = ls->data; | |
235 | menu_index += mi->add_to(m, menu_index, mi, obj); | |
236 | ls = ls->next; | |
237 | } | |
238 | ||
239 | return 1; | |
240 | } | |
241 | ||
242 | int add_menuitem_widget( | |
243 | Widget parent, | |
244 | int i, | |
245 | UiMenuItemI *item, | |
246 | UiObject *obj) | |
247 | { | |
248 | UiMenuItem *mi = (UiMenuItem*)item; | |
249 | ||
250 | Arg args[1]; | |
251 | XmString label = XmStringCreateLocalized(mi->label); | |
252 | XtSetArg(args[0], XmNlabelString, label); | |
253 | ||
254 | Widget mitem = XtCreateManagedWidget( | |
255 | "menubutton", | |
256 | xmPushButtonWidgetClass, | |
257 | parent, | |
258 | args, | |
259 | 1); | |
260 | XmStringFree(label); | |
261 | ||
262 | if(mi->callback != NULL) { | |
263 | UiEventData *event = ucx_mempool_malloc( | |
264 | obj->ctx->mempool, | |
265 | sizeof(UiEventData)); | |
266 | event->obj = obj; | |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
267 | event->userdata = mi->userdata; |
0 | 268 | event->callback = mi->callback; |
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
269 | event->value = 0; |
3 | 270 | XtAddCallback( |
271 | mitem, | |
272 | XmNactivateCallback, | |
273 | (XtCallbackProc)ui_push_button_callback, | |
274 | event); | |
0 | 275 | } |
276 | ||
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
277 | if(mi->groups) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
278 | uic_add_group_widget(obj->ctx, mitem, mi->groups); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
279 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
280 | |
0 | 281 | return 1; |
282 | } | |
283 | ||
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
284 | int add_menuitem_st_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
285 | UiStMenuItem *mi = (UiStMenuItem*)item; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
286 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
287 | UiStockItem *si = ui_get_stock_item(mi->stockid); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
288 | if(!si) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
289 | fprintf(stderr, "UI Error: unknown stock id: %s\n", mi->stockid); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
290 | return 0; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
291 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
292 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
293 | int n = 0; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
294 | Arg args[4]; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
295 | XmString label = XmStringCreateLocalized(si->label); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
296 | XmString at = NULL; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
297 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
298 | XtSetArg(args[n], XmNlabelString, label); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
299 | n++; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
300 | if(si->accelerator) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
301 | XtSetArg(args[n], XmNaccelerator, si->accelerator); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
302 | n++; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
303 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
304 | if(si->accelerator_label) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
305 | at = XmStringCreateLocalized(si->accelerator_label); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
306 | XtSetArg(args[n], XmNacceleratorText, at); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
307 | n++; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
308 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
309 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
310 | Widget mitem = XtCreateManagedWidget( |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
311 | "menubutton", |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
312 | xmPushButtonWidgetClass, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
313 | parent, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
314 | args, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
315 | n); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
316 | XmStringFree(label); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
317 | if(at) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
318 | XmStringFree(at); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
319 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
320 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
321 | if(mi->callback != NULL) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
322 | UiEventData *event = ucx_mempool_malloc( |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
323 | obj->ctx->mempool, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
324 | sizeof(UiEventData)); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
325 | event->obj = obj; |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
326 | event->userdata = mi->userdata; |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
327 | event->callback = mi->callback; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
328 | event->value = 0; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
329 | XtAddCallback( |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
330 | mitem, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
331 | XmNactivateCallback, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
332 | (XtCallbackProc)ui_push_button_callback, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
333 | event); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
334 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
335 | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
336 | if(mi->groups) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
337 | uic_add_group_widget(obj->ctx, mitem, mi->groups); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
338 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
339 | |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
340 | return 1; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
341 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
342 | |
0 | 343 | int add_menuseparator_widget( |
344 | Widget parent, | |
345 | int i, | |
346 | UiMenuItemI *item, | |
347 | UiObject *obj) | |
348 | { | |
349 | Widget s = XmCreateSeparatorGadget (parent, "menu_separator", NULL, 0); | |
350 | XtManageChild(s); | |
351 | return 1; | |
352 | } | |
353 | ||
354 | int add_checkitem_widget( | |
355 | Widget parent, | |
356 | int i, | |
357 | UiMenuItemI *item, | |
358 | UiObject *obj) | |
359 | { | |
360 | UiCheckItem *ci = (UiCheckItem*)item; | |
361 | ||
362 | Arg args[3]; | |
363 | XmString label = XmStringCreateLocalized(ci->label); | |
364 | XtSetArg(args[0], XmNlabelString, label); | |
365 | XtSetArg(args[1], XmNvisibleWhenOff, 1); | |
366 | Widget checkbox = XtCreateManagedWidget( | |
367 | "menutogglebutton", | |
368 | xmToggleButtonWidgetClass, | |
369 | parent, | |
370 | args, | |
371 | 2); | |
372 | XmStringFree(label); | |
373 | ||
374 | if(ci->callback) { | |
375 | UiEventData *event = ucx_mempool_malloc( | |
376 | obj->ctx->mempool, | |
377 | sizeof(UiEventData)); | |
378 | event->obj = obj; | |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
379 | event->userdata = ci->userdata; |
0 | 380 | event->callback = ci->callback; |
381 | XtAddCallback( | |
382 | checkbox, | |
383 | XmNvalueChangedCallback, | |
384 | (XtCallbackProc)ui_toggle_button_callback, | |
385 | event); | |
386 | } | |
387 | ||
388 | return 1; | |
389 | } | |
390 | ||
391 | int add_checkitemnv_widget( | |
392 | Widget parent, | |
393 | int i, | |
394 | UiMenuItemI *item, | |
395 | UiObject *obj) | |
396 | { | |
397 | UiCheckItemNV *ci = (UiCheckItemNV*)item; | |
398 | ||
399 | Arg args[3]; | |
400 | XmString label = XmStringCreateLocalized(ci->label); | |
401 | XtSetArg(args[0], XmNlabelString, label); | |
402 | XtSetArg(args[1], XmNvisibleWhenOff, 1); | |
403 | Widget checkbox = XtCreateManagedWidget( | |
404 | "menutogglebutton", | |
405 | xmToggleButtonWidgetClass, | |
406 | parent, | |
407 | args, | |
408 | 2); | |
409 | XmStringFree(label); | |
410 | ||
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
411 | UiVar *var = uic_connect_var(obj->ctx, ci->varname, UI_VAR_INTEGER); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
412 | if(var) { |
0 | 413 | UiInteger *value = var->value; |
414 | value->obj = checkbox; | |
415 | value->get = ui_toggle_button_get; | |
416 | value->set = ui_toggle_button_set; | |
417 | value = 0; | |
418 | } else { | |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
419 | // TODO: error |
0 | 420 | } |
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
421 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
422 | return 1; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
423 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
424 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
425 | int add_menuitem_list_widget( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
426 | Widget parent, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
427 | int i, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
428 | UiMenuItemI *item, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
429 | UiObject *obj) |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
430 | { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
431 | UiMenuItemList *il = (UiMenuItemList*)item; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
432 | UcxMempool *mp = obj->ctx->mempool; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
433 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
434 | UiActiveMenuItemList *ls = ucx_mempool_malloc( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
435 | mp, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
436 | sizeof(UiActiveMenuItemList)); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
437 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
438 | ls->object = obj; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
439 | ls->menu = parent; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
440 | ls->index = i; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
441 | ls->oldcount = 0; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
442 | ls->list = il->list; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
443 | ls->callback = il->callback; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
444 | ls->userdata = il->userdata; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
445 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
446 | ls->list->observers = ui_add_observer( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
447 | ls->list->observers, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
448 | (ui_callback)ui_update_menuitem_list, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
449 | ls); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
450 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
451 | ui_update_menuitem_list(NULL, ls); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
452 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
453 | return 0; |
0 | 454 | } |
455 | ||
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
456 | void ui_update_menuitem_list(UiEvent *event, UiActiveMenuItemList *list) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
457 | Arg args[4]; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
458 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
459 | // remove old items |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
460 | if(list->oldcount > 0) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
461 | Widget *children; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
462 | int nc; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
463 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
464 | XtVaGetValues( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
465 | list->menu, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
466 | XmNchildren, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
467 | &children, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
468 | XmNnumChildren, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
469 | &nc, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
470 | NULL); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
471 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
472 | for(int i=0;i<list->oldcount;i++) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
473 | XtDestroyWidget(children[list->index + i]); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
474 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
475 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
476 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
477 | char *str = ui_list_first(list->list); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
478 | if(str) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
479 | // add separator |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
480 | XtSetArg(args[0], XmNpositionIndex, list->index); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
481 | Widget s = XmCreateSeparatorGadget (list->menu, "menu_separator", args, 1); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
482 | XtManageChild(s); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
483 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
484 | int i = 1; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
485 | while(str) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
486 | XmString label = XmStringCreateLocalized(str); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
487 | XtSetArg(args[0], XmNlabelString, label); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
488 | XtSetArg(args[1], XmNpositionIndex, list->index + i); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
489 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
490 | Widget mitem = XtCreateManagedWidget( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
491 | "menubutton", |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
492 | xmPushButtonWidgetClass, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
493 | list->menu, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
494 | args, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
495 | 2); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
496 | XmStringFree(label); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
497 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
498 | if(list->callback) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
499 | // TODO: use mempool |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
500 | UiEventData *event = malloc(sizeof(UiEventData)); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
501 | event->obj = list->object; |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
502 | event->userdata = list->userdata; |
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
503 | event->callback = list->callback; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
504 | event->value = i - 1; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
505 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
506 | XtAddCallback( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
507 | mitem, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
508 | XmNactivateCallback, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
509 | (XtCallbackProc)ui_push_button_callback, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
510 | event); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
511 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
512 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
513 | str = ui_list_next(list->list); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
514 | i++; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
515 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
516 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
517 | list->oldcount = i; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
518 | } |
0 | 519 | |
520 | void ui_menu_event_wrapper(Widget widget, XtPointer udata, XtPointer cdata) { | |
521 | UiEventData *event = udata; | |
522 | UiEvent e; | |
523 | e.obj = event->obj; | |
524 | e.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
525 | e.document = event->obj->ctx->document; |
0 | 526 | e.intval = 0; |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
527 | event->callback(&e, event->userdata); |
0 | 528 | } |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
529 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
530 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
531 | /* |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
532 | * widget menu functions |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
533 | */ |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
534 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
535 | static void ui_popup_handler(Widget widget, XtPointer data, XEvent *event, Boolean *c) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
536 | Widget menu = data; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
537 | XmMenuPosition(menu, (XButtonPressedEvent *)event); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
538 | XtManageChild(menu); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
539 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
540 | *c = FALSE; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
541 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
542 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
543 | UIMENU ui_contextmenu(UiObject *obj) { |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
544 | UiContainer *ct = uic_get_current_container(obj); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
545 | if(ct->current) { |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
546 | return ui_contextmenu_w(obj, ct->current); |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
547 | } else { |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
548 | return NULL; // TODO: warn |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
549 | } |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
550 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
551 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
552 | UIMENU ui_contextmenu_w(UiObject *obj, UIWIDGET widget) { |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
553 | UiContainer *ct = uic_get_current_container(obj); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
554 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
555 | Widget menu = XmCreatePopupMenu(widget, "popup_menu", NULL, 0); |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
556 | ct->menu = menu; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
557 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
558 | XtAddEventHandler(widget, ButtonPressMask, FALSE, ui_popup_handler, menu); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
559 | |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
560 | return menu; |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
561 | } |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
562 | |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
563 | void ui_contextmenu_popup(UIMENU menu) { |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
564 | |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
565 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
566 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
567 | void ui_widget_menuitem(UiObject *obj, char *label, ui_callback f, void *userdata) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
568 | ui_widget_menuitem_gr(obj, label, f, userdata, -1); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
569 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
570 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
571 | void ui_widget_menuitem_gr(UiObject *obj, char *label, ui_callback f, void *userdata, ...) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
572 | UiContainer *ct = uic_get_current_container(obj); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
573 | if(!ct->menu) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
574 | return; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
575 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
576 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
577 | // add groups |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
578 | UcxList *groups = NULL; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
579 | va_list ap; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
580 | va_start(ap, userdata); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
581 | int group; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
582 | while((group = va_arg(ap, int)) != -1) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
583 | ucx_list_append(groups, (void*)(intptr_t)group); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
584 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
585 | va_end(ap); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
586 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
587 | // create menuitem |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
588 | Arg args[4]; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
589 | XmString labelstr = XmStringCreateLocalized(label); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
590 | XtSetArg(args[0], XmNlabelString, labelstr); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
591 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
592 | Widget item = XmCreatePushButton(ct->menu, "menu_button", args, 1); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
593 | XtManageChild(item); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
594 | XmStringFree(labelstr); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
595 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
596 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
597 | void ui_widget_menuitem_st(UiObject *obj, char *stockid, ui_callback f, void *userdata) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
598 | ui_widget_menuitem_stgr(obj, stockid, f, userdata, -1); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
599 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
600 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
601 | void ui_widget_menuitem_stgr(UiObject *obj, char *stockid, ui_callback f, void *userdata, ...) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
602 | UiContainer *ct = uic_get_current_container(obj); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
603 | if(!ct->menu) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
604 | return; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
605 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
606 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
607 | // add groups |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
608 | UcxList *groups = NULL; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
609 | va_list ap; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
610 | va_start(ap, userdata); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
611 | int group; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
612 | while((group = va_arg(ap, int)) != -1) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
613 | ucx_list_append(groups, (void*)(intptr_t)group); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
614 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
615 | va_end(ap); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
616 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
617 | // create menuitem |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
618 | UiStockItem *stockItem = ui_get_stock_item(stockid); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
619 | Arg args[4]; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
620 | XmString labelstr = XmStringCreateLocalized(stockItem->label); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
621 | XtSetArg(args[0], XmNlabelString, labelstr); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
622 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
623 | Widget item = XmCreatePushButton(ct->menu, "menu_button", args, 1); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
624 | XtManageChild(item); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
625 | XmStringFree(labelstr); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
626 | } |