Sun, 29 Sep 2024 20:24:46 +0200
implement progressbar min/max args (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 | ||
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
41 | #include <cx/linked_list.h> |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
42 | #include <cx/array_list.h> |
0 | 43 | |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
44 | static ui_menu_add_f createMenuItem[] = { |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
45 | /* UI_MENU */ add_menu_widget, |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
46 | /* UI_MENU_SUBMENU */ add_menu_widget, |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
47 | /* UI_MENU_ITEM */ add_menuitem_widget, |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
48 | /* UI_MENU_STOCK_ITEM */ add_menuitem_st_widget, |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
49 | /* UI_MENU_CHECK_ITEM */ add_checkitem_widget, |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
50 | /* UI_MENU_CHECK_ITEM_NV */ add_checkitemnv_widget, |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
51 | /* UI_MENU_ITEM_LIST */ add_menuitem_list_widget, |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
52 | /* UI_MENU_ITEM_LIST_NV */ NULL, // TODO |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
53 | /* UI_MENU_SEPARATOR */ add_menuseparator_widget |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
54 | }; |
0 | 55 | |
56 | // private menu functions | |
57 | void ui_create_menubar(UiObject *obj) { | |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
58 | UiMenu *menus = uic_get_menu_list(); |
0 | 59 | if(!menus) { |
60 | return; | |
61 | } | |
62 | ||
63 | Widget menubar = XmCreateMenuBar(obj->widget, "main_list", NULL, 0); | |
64 | XtManageChild(menubar); | |
65 | ||
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
66 | UiMenu *menu = menus; |
0 | 67 | int menu_index = 0; |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
68 | while(menu) { |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
69 | menu_index += add_menu_widget(menubar, menu_index, &menu->item, obj); |
0 | 70 | |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
71 | menu = (UiMenu*)menu->item.next; |
0 | 72 | } |
73 | } | |
74 | ||
75 | int add_menu_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) { | |
76 | UiMenu *menu = (UiMenu*)item; | |
77 | ||
78 | Widget menuItem = XtVaCreateManagedWidget( | |
79 | menu->label, | |
80 | xmCascadeButtonWidgetClass, | |
81 | parent, | |
82 | NULL); | |
83 | Widget m = XmVaCreateSimplePulldownMenu(parent, menu->label, i, NULL, NULL); | |
84 | ||
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
85 | UiMenuItemI *mi = menu->items_begin; |
0 | 86 | int menu_index = 0; |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
87 | while(mi) { |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
88 | menu_index += createMenuItem[mi->type](m, menu_index, mi, obj); |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
89 | mi = mi->next; |
0 | 90 | } |
91 | ||
92 | return 1; | |
93 | } | |
94 | ||
95 | int add_menuitem_widget( | |
96 | Widget parent, | |
97 | int i, | |
98 | UiMenuItemI *item, | |
99 | UiObject *obj) | |
100 | { | |
101 | UiMenuItem *mi = (UiMenuItem*)item; | |
102 | ||
103 | Arg args[1]; | |
104 | XmString label = XmStringCreateLocalized(mi->label); | |
105 | XtSetArg(args[0], XmNlabelString, label); | |
106 | ||
107 | Widget mitem = XtCreateManagedWidget( | |
108 | "menubutton", | |
109 | xmPushButtonWidgetClass, | |
110 | parent, | |
111 | args, | |
112 | 1); | |
113 | XmStringFree(label); | |
114 | ||
115 | if(mi->callback != NULL) { | |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
116 | UiEventData *event = cxMalloc( |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
117 | obj->ctx->allocator, |
0 | 118 | sizeof(UiEventData)); |
119 | event->obj = obj; | |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
120 | event->userdata = mi->userdata; |
0 | 121 | event->callback = mi->callback; |
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
122 | event->value = 0; |
3 | 123 | XtAddCallback( |
124 | mitem, | |
125 | XmNactivateCallback, | |
126 | (XtCallbackProc)ui_push_button_callback, | |
127 | event); | |
0 | 128 | } |
129 | ||
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
130 | if(mi->groups) { |
169
fe49cff3c571
refactor widget groups/document tree (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
153
diff
changeset
|
131 | uic_add_group_widget(obj->ctx, mitem, (ui_enablefunc)XtSetSensitive, mi->groups); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
132 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
133 | |
0 | 134 | return 1; |
135 | } | |
136 | ||
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
137 | 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
|
138 | UiStMenuItem *mi = (UiStMenuItem*)item; |
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 | UiStockItem *si = ui_get_stock_item(mi->stockid); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
141 | if(!si) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
142 | 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
|
143 | return 0; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
144 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
145 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
146 | int n = 0; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
147 | Arg args[4]; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
148 | XmString label = XmStringCreateLocalized(si->label); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
149 | XmString at = NULL; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
150 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
151 | XtSetArg(args[n], XmNlabelString, label); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
152 | n++; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
153 | if(si->accelerator) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
154 | XtSetArg(args[n], XmNaccelerator, si->accelerator); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
155 | n++; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
156 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
157 | if(si->accelerator_label) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
158 | at = XmStringCreateLocalized(si->accelerator_label); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
159 | XtSetArg(args[n], XmNacceleratorText, at); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
160 | n++; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
161 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
162 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
163 | Widget mitem = XtCreateManagedWidget( |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
164 | "menubutton", |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
165 | xmPushButtonWidgetClass, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
166 | parent, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
167 | args, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
168 | n); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
169 | XmStringFree(label); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
170 | if(at) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
171 | XmStringFree(at); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
172 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
173 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
174 | if(mi->callback != NULL) { |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
175 | UiEventData *event = cxMalloc( |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
176 | obj->ctx->allocator, |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
177 | sizeof(UiEventData)); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
178 | event->obj = obj; |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
179 | event->userdata = mi->userdata; |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
180 | event->callback = mi->callback; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
181 | event->value = 0; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
182 | XtAddCallback( |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
183 | mitem, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
184 | XmNactivateCallback, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
185 | (XtCallbackProc)ui_push_button_callback, |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
186 | event); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
187 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
188 | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
189 | if(mi->groups) { |
169
fe49cff3c571
refactor widget groups/document tree (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
153
diff
changeset
|
190 | uic_add_group_widget(obj->ctx, mitem, (ui_enablefunc)XtSetSensitive, mi->groups); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
191 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
192 | |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
193 | return 1; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
194 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
195 | |
0 | 196 | int add_menuseparator_widget( |
197 | Widget parent, | |
198 | int i, | |
199 | UiMenuItemI *item, | |
200 | UiObject *obj) | |
201 | { | |
202 | Widget s = XmCreateSeparatorGadget (parent, "menu_separator", NULL, 0); | |
203 | XtManageChild(s); | |
204 | return 1; | |
205 | } | |
206 | ||
207 | int add_checkitem_widget( | |
208 | Widget parent, | |
209 | int i, | |
210 | UiMenuItemI *item, | |
211 | UiObject *obj) | |
212 | { | |
213 | UiCheckItem *ci = (UiCheckItem*)item; | |
214 | ||
215 | Arg args[3]; | |
216 | XmString label = XmStringCreateLocalized(ci->label); | |
217 | XtSetArg(args[0], XmNlabelString, label); | |
218 | XtSetArg(args[1], XmNvisibleWhenOff, 1); | |
219 | Widget checkbox = XtCreateManagedWidget( | |
220 | "menutogglebutton", | |
221 | xmToggleButtonWidgetClass, | |
222 | parent, | |
223 | args, | |
224 | 2); | |
225 | XmStringFree(label); | |
226 | ||
227 | if(ci->callback) { | |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
228 | UiEventData *event = cxMalloc( |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
229 | obj->ctx->allocator, |
0 | 230 | sizeof(UiEventData)); |
231 | event->obj = obj; | |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
232 | event->userdata = ci->userdata; |
0 | 233 | event->callback = ci->callback; |
234 | XtAddCallback( | |
235 | checkbox, | |
236 | XmNvalueChangedCallback, | |
237 | (XtCallbackProc)ui_toggle_button_callback, | |
238 | event); | |
239 | } | |
240 | ||
241 | return 1; | |
242 | } | |
243 | ||
244 | int add_checkitemnv_widget( | |
245 | Widget parent, | |
246 | int i, | |
247 | UiMenuItemI *item, | |
248 | UiObject *obj) | |
249 | { | |
250 | UiCheckItemNV *ci = (UiCheckItemNV*)item; | |
251 | ||
252 | Arg args[3]; | |
253 | XmString label = XmStringCreateLocalized(ci->label); | |
254 | XtSetArg(args[0], XmNlabelString, label); | |
255 | XtSetArg(args[1], XmNvisibleWhenOff, 1); | |
256 | Widget checkbox = XtCreateManagedWidget( | |
257 | "menutogglebutton", | |
258 | xmToggleButtonWidgetClass, | |
259 | parent, | |
260 | args, | |
261 | 2); | |
262 | XmStringFree(label); | |
263 | ||
153
ee49d1852a5f
applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
264 | UiVar *var = uic_create_var(obj->ctx, ci->varname, UI_VAR_INTEGER); |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
265 | if(var) { |
0 | 266 | UiInteger *value = var->value; |
267 | value->obj = checkbox; | |
268 | value->get = ui_toggle_button_get; | |
269 | value->set = ui_toggle_button_set; | |
270 | value = 0; | |
271 | } else { | |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
272 | // TODO: error |
0 | 273 | } |
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
274 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
275 | return 1; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
276 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
277 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
278 | int add_menuitem_list_widget( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
279 | Widget parent, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
280 | int i, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
281 | UiMenuItemI *item, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
282 | UiObject *obj) |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
283 | { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
284 | UiMenuItemList *il = (UiMenuItemList*)item; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
285 | |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
286 | UiActiveMenuItemList *ls = cxMalloc( |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
287 | obj->ctx->allocator, |
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
288 | sizeof(UiActiveMenuItemList)); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
289 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
290 | ls->object = obj; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
291 | ls->menu = parent; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
292 | ls->index = i; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
293 | ls->oldcount = 0; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
294 | ls->list = il->list; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
295 | ls->callback = il->callback; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
296 | ls->userdata = il->userdata; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
297 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
298 | ls->list->observers = ui_add_observer( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
299 | ls->list->observers, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
300 | (ui_callback)ui_update_menuitem_list, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
301 | ls); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
302 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
303 | ui_update_menuitem_list(NULL, ls); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
304 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
305 | return 0; |
0 | 306 | } |
307 | ||
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
308 | 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
|
309 | Arg args[4]; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
310 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
311 | // remove old items |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
312 | if(list->oldcount > 0) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
313 | Widget *children; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
314 | int nc; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
315 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
316 | XtVaGetValues( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
317 | list->menu, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
318 | XmNchildren, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
319 | &children, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
320 | XmNnumChildren, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
321 | &nc, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
322 | NULL); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
323 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
324 | for(int i=0;i<list->oldcount;i++) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
325 | XtDestroyWidget(children[list->index + i]); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
326 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
327 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
328 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
329 | char *str = ui_list_first(list->list); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
330 | if(str) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
331 | // add separator |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
332 | XtSetArg(args[0], XmNpositionIndex, list->index); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
333 | 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
|
334 | XtManageChild(s); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
335 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
336 | int i = 1; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
337 | while(str) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
338 | XmString label = XmStringCreateLocalized(str); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
339 | XtSetArg(args[0], XmNlabelString, label); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
340 | XtSetArg(args[1], XmNpositionIndex, list->index + i); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
341 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
342 | Widget mitem = XtCreateManagedWidget( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
343 | "menubutton", |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
344 | xmPushButtonWidgetClass, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
345 | list->menu, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
346 | args, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
347 | 2); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
348 | XmStringFree(label); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
349 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
350 | if(list->callback) { |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
351 | // TODO: use mempool |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
352 | UiEventData *event = malloc(sizeof(UiEventData)); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
353 | event->obj = list->object; |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
354 | event->userdata = list->userdata; |
17
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
355 | event->callback = list->callback; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
356 | event->value = i - 1; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
357 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
358 | XtAddCallback( |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
359 | mitem, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
360 | XmNactivateCallback, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
361 | (XtCallbackProc)ui_push_button_callback, |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
362 | event); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
363 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
364 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
365 | str = ui_list_next(list->list); |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
366 | i++; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
367 | } |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
368 | |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
369 | list->oldcount = i; |
db95c0104937
added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
370 | } |
0 | 371 | |
372 | void ui_menu_event_wrapper(Widget widget, XtPointer udata, XtPointer cdata) { | |
373 | UiEventData *event = udata; | |
374 | UiEvent e; | |
375 | e.obj = event->obj; | |
376 | e.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
377 | e.document = event->obj->ctx->document; |
0 | 378 | e.intval = 0; |
98
efaae97bd95b
added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
379 | event->callback(&e, event->userdata); |
0 | 380 | } |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
381 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
382 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
383 | /* |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
384 | * widget menu functions |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
385 | */ |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
386 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
387 | 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
|
388 | Widget menu = data; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
389 | XmMenuPosition(menu, (XButtonPressedEvent *)event); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
390 | XtManageChild(menu); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
391 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
392 | *c = FALSE; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
393 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
394 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
395 | UIMENU ui_contextmenu(UiObject *obj) { |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
396 | UiContainer *ct = uic_get_current_container(obj); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
397 | if(ct->current) { |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
398 | return ui_contextmenu_w(obj, ct->current); |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
399 | } else { |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
400 | return NULL; // TODO: warn |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
401 | } |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
402 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
403 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
404 | UIMENU ui_contextmenu_w(UiObject *obj, UIWIDGET widget) { |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
405 | UiContainer *ct = uic_get_current_container(obj); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
406 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
407 | Widget menu = XmCreatePopupMenu(widget, "popup_menu", NULL, 0); |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
408 | ct->menu = menu; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
409 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
410 | XtAddEventHandler(widget, ButtonPressMask, FALSE, ui_popup_handler, menu); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
411 | |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
412 | return menu; |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
413 | } |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
414 | |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
415 | void ui_contextmenu_popup(UIMENU menu) { |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
98
diff
changeset
|
416 | |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
417 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
418 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
419 | 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
|
420 | ui_widget_menuitem_gr(obj, label, f, userdata, -1); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
421 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
422 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
423 | 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
|
424 | UiContainer *ct = uic_get_current_container(obj); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
425 | if(!ct->menu) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
426 | return; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
427 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
428 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
429 | // add groups |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
430 | CxList *groups = NULL; |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
431 | va_list ap; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
432 | va_start(ap, userdata); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
433 | int group; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
434 | while((group = va_arg(ap, int)) != -1) { |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
435 | if(!groups) { |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
436 | groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16); |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
437 | } |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
438 | cxListAdd(groups, &group); |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
439 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
440 | va_end(ap); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
441 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
442 | // create menuitem |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
443 | Arg args[4]; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
444 | XmString labelstr = XmStringCreateLocalized(label); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
445 | XtSetArg(args[0], XmNlabelString, labelstr); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
446 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
447 | Widget item = XmCreatePushButton(ct->menu, "menu_button", args, 1); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
448 | XtManageChild(item); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
449 | XmStringFree(labelstr); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
450 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
451 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
452 | 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
|
453 | ui_widget_menuitem_stgr(obj, stockid, f, userdata, -1); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
454 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
455 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
456 | 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
|
457 | UiContainer *ct = uic_get_current_container(obj); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
458 | if(!ct->menu) { |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
459 | return; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
460 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
461 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
462 | // add groups |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
463 | CxList *groups = NULL; |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
464 | va_list ap; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
465 | va_start(ap, userdata); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
466 | int group; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
467 | while((group = va_arg(ap, int)) != -1) { |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
468 | if(!groups) { |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
469 | groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16); |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
470 | } |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
471 | cxListAdd(groups, &group); |
76
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
472 | } |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
473 | va_end(ap); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
474 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
475 | // create menuitem |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
476 | UiStockItem *stockItem = ui_get_stock_item(stockid); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
477 | Arg args[4]; |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
478 | XmString labelstr = XmStringCreateLocalized(stockItem->label); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
479 | XtSetArg(args[0], XmNlabelString, labelstr); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
480 | |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
481 | Widget item = XmCreatePushButton(ct->menu, "menu_button", args, 1); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
482 | XtManageChild(item); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
483 | XmStringFree(labelstr); |
3782827378ab
added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
484 | } |