Thu, 01 Jan 2015 17:22:55 +0100
improved box (Motif)
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> | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
31 | #include <inttypes.h> |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
32 | #include <stdarg.h> |
0 | 33 | |
34 | #include "menu.h" | |
35 | #include "toolkit.h" | |
36 | #include "../common/context.h" | |
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
37 | #include "../ui/properties.h" |
0 | 38 | #include "../ui/window.h" |
39 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
40 | static UcxList *menus; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
41 | static UcxList *current; |
0 | 42 | |
43 | void ui_menu(char *label) { | |
44 | // free current menu hierarchy | |
45 | ucx_list_free(current); | |
46 | ||
47 | // create menu | |
48 | UiMenu *menu = malloc(sizeof(UiMenu)); | |
49 | menu->item.add_to = (ui_menu_add_f)add_menu_widget; | |
50 | ||
51 | menu->label = label; | |
52 | menu->items = NULL; | |
53 | menu->parent = NULL; | |
54 | ||
55 | current = ucx_list_prepend(NULL, menu); | |
56 | menus = ucx_list_append(menus, menu); | |
57 | ||
58 | } | |
59 | ||
60 | void ui_submenu(char *label) { | |
61 | UiMenu *menu = malloc(sizeof(UiMenu)); | |
62 | menu->item.add_to = (ui_menu_add_f)add_menu_widget; | |
63 | ||
64 | menu->label = label; | |
65 | menu->items = NULL; | |
66 | menu->parent = NULL; | |
67 | ||
68 | // add submenu to current menu | |
69 | UiMenu *cm = current->data; | |
70 | cm->items = ucx_list_append(cm->items, menu); | |
71 | ||
72 | // set the submenu to current menu | |
73 | current = ucx_list_prepend(current, menu); | |
74 | } | |
75 | ||
76 | void ui_submenu_end() { | |
77 | if(ucx_list_size(current) < 2) { | |
78 | return; | |
79 | } | |
80 | current = ucx_list_remove(current, current); | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
81 | //UcxList *c = current; |
0 | 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:
16
diff
changeset
|
119 | if(!current) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
120 | return; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
121 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
122 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
123 | UiStMenuItem *item = malloc(sizeof(UiStMenuItem)); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
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:
16
diff
changeset
|
125 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
126 | item->stockid = stockid; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
127 | item->userdata = userdata; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
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:
16
diff
changeset
|
139 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
140 | UiMenu *cm = current->data; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
141 | cm->items = ucx_list_append(cm->items, item); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
142 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
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 | void ui_checkitem(char *label, ui_callback f, void *userdata) { | |
157 | if(!current) { | |
158 | return; | |
159 | } | |
160 | ||
161 | UiCheckItem *item = malloc(sizeof(UiCheckItem)); | |
162 | item->item.add_to = (ui_menu_add_f)add_checkitem_widget; | |
163 | item->label = label; | |
164 | item->callback = f; | |
165 | item->userdata = userdata; | |
166 | ||
167 | UiMenu *cm = current->data; | |
168 | cm->items = ucx_list_append(cm->items, item); | |
169 | } | |
170 | ||
171 | void ui_checkitem_nv(char *label, char *vname) { | |
172 | if(!current) { | |
173 | return; | |
174 | } | |
175 | ||
176 | UiCheckItemNV *item = malloc(sizeof(UiCheckItemNV)); | |
177 | item->item.add_to = (ui_menu_add_f)add_checkitemnv_widget; | |
178 | item->varname = vname; | |
179 | item->label = label; | |
180 | ||
181 | UiMenu *cm = current->data; | |
182 | cm->items = ucx_list_append(cm->items, item); | |
183 | } | |
184 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
185 | void ui_menuitem_list(UiList *items, ui_callback f, void *userdata) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
186 | if(!current) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
187 | return; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
188 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
189 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
190 | UiMenuItemList *item = malloc(sizeof(UiMenuItemList)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
191 | item->item.add_to = (ui_menu_add_f)add_menuitem_list_widget; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
192 | item->callback = f; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
193 | item->userdata = userdata; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
194 | item->list = items; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
195 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
196 | UiMenu *cm = current->data; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
197 | cm->items = ucx_list_append(cm->items, item); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
198 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
199 | |
0 | 200 | // private menu functions |
201 | GtkWidget *ui_create_menubar(UiObject *obj) { | |
202 | if(menus == NULL) { | |
203 | return NULL; | |
204 | } | |
205 | ||
206 | GtkWidget *mb = gtk_menu_bar_new(); | |
207 | ||
208 | UcxList *ls = menus; | |
209 | while(ls) { | |
210 | UiMenu *menu = ls->data; | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
211 | menu->item.add_to(mb, 0, &menu->item, obj); |
0 | 212 | |
213 | ls = ls->next; | |
214 | } | |
215 | ||
216 | return mb; | |
217 | } | |
218 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
219 | void add_menu_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj) { |
0 | 220 | UiMenu *menu = (UiMenu*)item; |
221 | ||
222 | GtkWidget *menu_widget = gtk_menu_new(); | |
223 | GtkWidget *menu_item = gtk_menu_item_new_with_label(menu->label); | |
224 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu_widget); | |
225 | ||
226 | UcxList *ls = menu->items; | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
227 | int index = 0; |
0 | 228 | while(ls) { |
229 | UiMenuItemI *i = ls->data; | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
230 | i->add_to(menu_widget, index, i, obj); |
0 | 231 | |
232 | ls = ls->next; | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
233 | index++; |
0 | 234 | } |
235 | ||
236 | gtk_menu_shell_append(GTK_MENU_SHELL(parent), menu_item); | |
237 | } | |
238 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
239 | void add_menuitem_widget(GtkWidget *parent, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 240 | UiMenuItem *i = (UiMenuItem*)item; |
241 | ||
242 | //GtkWidget *widget = gtk_menu_item_new_with_label(i->title); | |
243 | GtkWidget *widget = gtk_menu_item_new_with_mnemonic(i->label); | |
244 | ||
245 | if(i->callback != NULL) { | |
246 | UiEventData *event = malloc(sizeof(UiEventData)); | |
247 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
248 | event->userdata = i->userdata; |
0 | 249 | event->callback = i->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
250 | event->value = 0; |
0 | 251 | |
252 | g_signal_connect( | |
253 | widget, | |
254 | "activate", | |
255 | G_CALLBACK(ui_menu_event_wrapper), | |
256 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
257 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
258 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
259 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
260 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
261 | event); |
0 | 262 | } |
263 | ||
264 | gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
265 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
266 | if(i->groups) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
267 | uic_add_group_widget(obj->ctx, widget, i->groups); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
268 | } |
0 | 269 | } |
270 | ||
271 | void add_menuitem_st_widget( | |
272 | GtkWidget *parent, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
273 | int index, |
0 | 274 | UiMenuItemI *item, |
275 | UiObject *obj) | |
276 | { | |
277 | UiStMenuItem *i = (UiStMenuItem*)item; | |
278 | ||
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
279 | GtkWidget *widget = gtk_image_menu_item_new_from_stock(i->stockid, obj->ctx->accel_group); |
0 | 280 | |
281 | if(i->callback != NULL) { | |
282 | UiEventData *event = malloc(sizeof(UiEventData)); | |
283 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
284 | event->userdata = i->userdata; |
0 | 285 | event->callback = i->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
286 | event->value = 0; |
0 | 287 | |
288 | g_signal_connect( | |
289 | widget, | |
290 | "activate", | |
291 | G_CALLBACK(ui_menu_event_wrapper), | |
292 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
293 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
294 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
295 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
296 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
297 | event); |
0 | 298 | } |
299 | ||
300 | gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
301 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
302 | if(i->groups) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
303 | uic_add_group_widget(obj->ctx, widget, i->groups); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
304 | } |
0 | 305 | } |
306 | ||
307 | void add_menuseparator_widget( | |
308 | GtkWidget *parent, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
309 | int index, |
0 | 310 | UiMenuItemI *item, |
311 | UiObject *obj) | |
312 | { | |
313 | gtk_menu_shell_append( | |
314 | GTK_MENU_SHELL(parent), | |
315 | gtk_separator_menu_item_new()); | |
316 | } | |
317 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
318 | void add_checkitem_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 319 | UiCheckItem *ci = (UiCheckItem*)item; |
320 | GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label); | |
321 | gtk_menu_shell_append(GTK_MENU_SHELL(p), widget); | |
322 | ||
323 | if(ci->callback) { | |
324 | UiEventData *event = malloc(sizeof(UiEventData)); | |
325 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
326 | event->userdata = ci->userdata; |
0 | 327 | event->callback = ci->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
328 | event->value = 0; |
0 | 329 | |
330 | g_signal_connect( | |
331 | widget, | |
332 | "toggled", | |
333 | G_CALLBACK(ui_menu_event_toggled), | |
334 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
335 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
336 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
337 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
338 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
339 | event); |
0 | 340 | } |
341 | } | |
342 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
343 | void add_checkitemnv_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 344 | UiCheckItemNV *ci = (UiCheckItemNV*)item; |
345 | GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label); | |
346 | gtk_menu_shell_append(GTK_MENU_SHELL(p), widget); | |
347 | ||
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
348 | 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
|
349 | if(var) { |
0 | 350 | UiInteger *value = var->value; |
351 | value->obj = widget; | |
352 | value->get = ui_checkitem_get; | |
353 | value->set = ui_checkitem_set; | |
354 | value = 0; | |
355 | } else { | |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
356 | // TODO: error |
0 | 357 | } |
358 | } | |
359 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
360 | void add_menuitem_list_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
361 | UiMenuItemList *il = (UiMenuItemList*)item; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
362 | UcxMempool *mp = obj->ctx->mempool; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
363 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
364 | UiActiveMenuItemList *ls = ucx_mempool_malloc( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
365 | mp, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
366 | sizeof(UiActiveMenuItemList)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
367 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
368 | ls->object = obj; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
369 | ls->menu = GTK_MENU_SHELL(p); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
370 | ls->index = index; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
371 | ls->oldcount = 0; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
372 | ls->list = il->list; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
373 | ls->callback = il->callback; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
374 | ls->userdata = il->userdata; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
375 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
376 | ls->list->observers = ui_add_observer( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
377 | ls->list->observers, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
378 | (ui_callback)ui_update_menuitem_list, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
379 | ls); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
380 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
381 | ui_update_menuitem_list(NULL, ls); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
382 | } |
0 | 383 | |
384 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
385 | void ui_update_menuitem_list(UiEvent *event, UiActiveMenuItemList *list) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
386 | // remove old items |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
387 | if(list->oldcount > 0) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
388 | int i = 0; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
389 | GList *mi = gtk_container_get_children(GTK_CONTAINER(list->menu)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
390 | while(mi) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
391 | if(i >= list->index && i < list->index + list->oldcount) { |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
392 | //gtk_container_remove(GTK_CONTAINER(list->menu), mi->data); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
393 | gtk_widget_destroy(mi->data); |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
394 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
395 | mi = mi->next; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
396 | i++; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
397 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
398 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
399 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
400 | char *str = ui_list_first(list->list); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
401 | if(str) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
402 | GtkWidget *widget = gtk_separator_menu_item_new(); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
403 | gtk_menu_shell_insert(list->menu, widget, list->index); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
404 | gtk_widget_show(widget); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
405 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
406 | int i = 1; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
407 | while(str) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
408 | GtkWidget *widget = gtk_menu_item_new_with_label(str); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
409 | gtk_menu_shell_insert(list->menu, widget, list->index + i); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
410 | gtk_widget_show(widget); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
411 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
412 | if(list->callback) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
413 | // TODO: use mempool |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
414 | UiEventData *event = malloc(sizeof(UiEventData)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
415 | event->obj = list->object; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
416 | event->userdata = list->userdata; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
417 | event->callback = list->callback; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
418 | event->value = i - 1; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
419 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
420 | g_signal_connect( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
421 | widget, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
422 | "activate", |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
423 | G_CALLBACK(ui_menu_event_wrapper), |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
424 | event); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
425 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
426 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
427 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
428 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
429 | event); |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
430 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
431 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
432 | str = ui_list_next(list->list); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
433 | i++; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
434 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
435 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
436 | list->oldcount = i; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
437 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
438 | |
0 | 439 | void ui_menu_event_wrapper(GtkMenuItem *item, UiEventData *event) { |
440 | UiEvent evt; | |
441 | evt.obj = event->obj; | |
442 | evt.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
443 | evt.document = event->obj->ctx->document; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
444 | evt.eventdata = NULL; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
445 | evt.intval = event->value; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
446 | event->callback(&evt, event->userdata); |
0 | 447 | } |
448 | ||
449 | void ui_menu_event_toggled(GtkCheckMenuItem *ci, UiEventData *event) { | |
450 | UiEvent evt; | |
451 | evt.obj = event->obj; | |
452 | evt.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
453 | evt.document = event->obj->ctx->document; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
454 | evt.eventdata = NULL; |
0 | 455 | evt.intval = gtk_check_menu_item_get_active(ci); |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
456 | event->callback(&evt, event->userdata); |
0 | 457 | } |
458 | ||
459 | int ui_checkitem_get(UiInteger *i) { | |
460 | int state = gtk_check_menu_item_get_active(i->obj); | |
461 | i->value = state; | |
462 | return state; | |
463 | } | |
464 | ||
465 | void ui_checkitem_set(UiInteger *i, int value) { | |
466 | i->value = value; | |
467 | gtk_check_menu_item_set_active(i->obj, value); | |
468 | } |