Sat, 17 Sep 2016 19:32:44 +0200
fixes var binding and motif tableview
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" |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
39 | #include "container.h" |
0 | 40 | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
41 | static UcxList *menus; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
42 | static UcxList *current; |
0 | 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); | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
82 | //UcxList *c = current; |
0 | 83 | } |
84 | ||
85 | 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
|
86 | 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
|
87 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
88 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
89 | 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
|
90 | 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
|
91 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
92 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
93 | void ui_menuitem_gr(char *label, ui_callback f, void *userdata, ...) { |
0 | 94 | if(!current) { |
95 | return; | |
96 | } | |
97 | ||
98 | UiMenuItem *item = malloc(sizeof(UiMenuItem)); | |
99 | item->item.add_to = (ui_menu_add_f)add_menuitem_widget; | |
100 | ||
101 | item->label = label; | |
102 | item->userdata = userdata; | |
103 | item->callback = f; | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
104 | item->groups = NULL; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
105 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
106 | // add groups |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
107 | va_list ap; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
108 | va_start(ap, userdata); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
109 | int group; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
110 | 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
|
111 | 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
|
112 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
113 | va_end(ap); |
0 | 114 | |
115 | UiMenu *cm = current->data; | |
116 | cm->items = ucx_list_append(cm->items, item); | |
117 | } | |
118 | ||
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
119 | 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
|
120 | if(!current) { |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
121 | return; |
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 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
124 | UiStMenuItem *item = malloc(sizeof(UiStMenuItem)); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
125 | 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
|
126 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
127 | item->stockid = stockid; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
128 | item->userdata = userdata; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
129 | item->callback = f; |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
130 | item->groups = NULL; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
131 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
132 | // add groups |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
133 | va_list ap; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
134 | va_start(ap, userdata); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
135 | int group; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
136 | 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
|
137 | 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
|
138 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
139 | va_end(ap); |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
140 | |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
141 | UiMenu *cm = current->data; |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
142 | cm->items = ucx_list_append(cm->items, item); |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
143 | } |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
144 | |
0 | 145 | void ui_menuseparator() { |
146 | if(!current) { | |
147 | return; | |
148 | } | |
149 | ||
150 | UiMenuItemI *item = malloc(sizeof(UiMenuItemI)); | |
151 | item->add_to = (ui_menu_add_f)add_menuseparator_widget; | |
152 | ||
153 | UiMenu *cm = current->data; | |
154 | cm->items = ucx_list_append(cm->items, item); | |
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 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
186 | 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
|
187 | if(!current) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
188 | return; |
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 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
191 | UiMenuItemList *item = malloc(sizeof(UiMenuItemList)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
192 | 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
|
193 | item->callback = f; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
194 | item->userdata = userdata; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
195 | item->list = items; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
196 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
197 | UiMenu *cm = current->data; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
198 | cm->items = ucx_list_append(cm->items, item); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
199 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
200 | |
0 | 201 | // private menu functions |
202 | GtkWidget *ui_create_menubar(UiObject *obj) { | |
203 | if(menus == NULL) { | |
204 | return NULL; | |
205 | } | |
206 | ||
207 | GtkWidget *mb = gtk_menu_bar_new(); | |
208 | ||
209 | UcxList *ls = menus; | |
210 | while(ls) { | |
211 | UiMenu *menu = ls->data; | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
212 | menu->item.add_to(mb, 0, &menu->item, obj); |
0 | 213 | |
214 | ls = ls->next; | |
215 | } | |
216 | ||
217 | return mb; | |
218 | } | |
219 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
220 | void add_menu_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj) { |
0 | 221 | UiMenu *menu = (UiMenu*)item; |
222 | ||
223 | GtkWidget *menu_widget = gtk_menu_new(); | |
224 | GtkWidget *menu_item = gtk_menu_item_new_with_label(menu->label); | |
225 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu_widget); | |
226 | ||
227 | UcxList *ls = menu->items; | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
228 | int index = 0; |
0 | 229 | while(ls) { |
230 | UiMenuItemI *i = ls->data; | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
231 | i->add_to(menu_widget, index, i, obj); |
0 | 232 | |
233 | ls = ls->next; | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
234 | index++; |
0 | 235 | } |
236 | ||
237 | gtk_menu_shell_append(GTK_MENU_SHELL(parent), menu_item); | |
238 | } | |
239 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
240 | void add_menuitem_widget(GtkWidget *parent, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 241 | UiMenuItem *i = (UiMenuItem*)item; |
242 | ||
243 | //GtkWidget *widget = gtk_menu_item_new_with_label(i->title); | |
244 | GtkWidget *widget = gtk_menu_item_new_with_mnemonic(i->label); | |
245 | ||
246 | if(i->callback != NULL) { | |
247 | UiEventData *event = malloc(sizeof(UiEventData)); | |
248 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
249 | event->userdata = i->userdata; |
0 | 250 | event->callback = i->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
251 | event->value = 0; |
0 | 252 | |
253 | g_signal_connect( | |
254 | widget, | |
255 | "activate", | |
256 | G_CALLBACK(ui_menu_event_wrapper), | |
257 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
258 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
259 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
260 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
261 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
262 | event); |
0 | 263 | } |
264 | ||
265 | 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
|
266 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
267 | if(i->groups) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
268 | 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
|
269 | } |
0 | 270 | } |
271 | ||
272 | void add_menuitem_st_widget( | |
273 | GtkWidget *parent, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
274 | int index, |
0 | 275 | UiMenuItemI *item, |
276 | UiObject *obj) | |
277 | { | |
278 | UiStMenuItem *i = (UiStMenuItem*)item; | |
279 | ||
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
280 | GtkWidget *widget = gtk_image_menu_item_new_from_stock(i->stockid, obj->ctx->accel_group); |
0 | 281 | |
282 | if(i->callback != NULL) { | |
283 | UiEventData *event = malloc(sizeof(UiEventData)); | |
284 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
285 | event->userdata = i->userdata; |
0 | 286 | event->callback = i->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
287 | event->value = 0; |
0 | 288 | |
289 | g_signal_connect( | |
290 | widget, | |
291 | "activate", | |
292 | G_CALLBACK(ui_menu_event_wrapper), | |
293 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
294 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
295 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
296 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
297 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
298 | event); |
0 | 299 | } |
300 | ||
301 | 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
|
302 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
303 | if(i->groups) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
304 | 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
|
305 | } |
0 | 306 | } |
307 | ||
308 | void add_menuseparator_widget( | |
309 | GtkWidget *parent, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
310 | int index, |
0 | 311 | UiMenuItemI *item, |
312 | UiObject *obj) | |
313 | { | |
314 | gtk_menu_shell_append( | |
315 | GTK_MENU_SHELL(parent), | |
316 | gtk_separator_menu_item_new()); | |
317 | } | |
318 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
319 | void add_checkitem_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 320 | UiCheckItem *ci = (UiCheckItem*)item; |
321 | GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label); | |
322 | gtk_menu_shell_append(GTK_MENU_SHELL(p), widget); | |
323 | ||
324 | if(ci->callback) { | |
325 | UiEventData *event = malloc(sizeof(UiEventData)); | |
326 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
327 | event->userdata = ci->userdata; |
0 | 328 | event->callback = ci->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
329 | event->value = 0; |
0 | 330 | |
331 | g_signal_connect( | |
332 | widget, | |
333 | "toggled", | |
334 | G_CALLBACK(ui_menu_event_toggled), | |
335 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
336 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
337 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
338 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
339 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
340 | event); |
0 | 341 | } |
342 | } | |
343 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
344 | void add_checkitemnv_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 345 | UiCheckItemNV *ci = (UiCheckItemNV*)item; |
346 | GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label); | |
347 | gtk_menu_shell_append(GTK_MENU_SHELL(p), widget); | |
348 | ||
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
349 | 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
|
350 | if(var) { |
0 | 351 | UiInteger *value = var->value; |
352 | value->obj = widget; | |
353 | value->get = ui_checkitem_get; | |
354 | value->set = ui_checkitem_set; | |
355 | value = 0; | |
356 | } else { | |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
357 | // TODO: error |
0 | 358 | } |
359 | } | |
360 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
361 | 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
|
362 | UiMenuItemList *il = (UiMenuItemList*)item; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
363 | UcxMempool *mp = obj->ctx->mempool; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
364 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
365 | UiActiveMenuItemList *ls = ucx_mempool_malloc( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
366 | mp, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
367 | sizeof(UiActiveMenuItemList)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
368 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
369 | ls->object = obj; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
370 | ls->menu = GTK_MENU_SHELL(p); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
371 | ls->index = index; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
372 | ls->oldcount = 0; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
373 | ls->list = il->list; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
374 | ls->callback = il->callback; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
375 | ls->userdata = il->userdata; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
376 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
377 | ls->list->observers = ui_add_observer( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
378 | ls->list->observers, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
379 | (ui_callback)ui_update_menuitem_list, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
380 | ls); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
381 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
382 | ui_update_menuitem_list(NULL, ls); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
383 | } |
0 | 384 | |
385 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
386 | 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
|
387 | // remove old items |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
388 | if(list->oldcount > 0) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
389 | int i = 0; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
390 | 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
|
391 | while(mi) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
392 | 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
|
393 | //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
|
394 | gtk_widget_destroy(mi->data); |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
395 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
396 | mi = mi->next; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
397 | i++; |
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 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
401 | char *str = ui_list_first(list->list); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
402 | if(str) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
403 | GtkWidget *widget = gtk_separator_menu_item_new(); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
404 | 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
|
405 | gtk_widget_show(widget); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
406 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
407 | int i = 1; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
408 | while(str) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
409 | 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
|
410 | 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
|
411 | gtk_widget_show(widget); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
412 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
413 | if(list->callback) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
414 | // TODO: use mempool |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
415 | UiEventData *event = malloc(sizeof(UiEventData)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
416 | event->obj = list->object; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
417 | event->userdata = list->userdata; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
418 | event->callback = list->callback; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
419 | event->value = i - 1; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
420 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
421 | g_signal_connect( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
422 | widget, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
423 | "activate", |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
424 | G_CALLBACK(ui_menu_event_wrapper), |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
425 | event); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
426 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
427 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
428 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
429 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
430 | event); |
16
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 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
433 | str = ui_list_next(list->list); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
434 | i++; |
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 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
437 | list->oldcount = i; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
438 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
439 | |
0 | 440 | void ui_menu_event_wrapper(GtkMenuItem *item, UiEventData *event) { |
441 | UiEvent evt; | |
442 | evt.obj = event->obj; | |
443 | evt.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
444 | evt.document = event->obj->ctx->document; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
445 | evt.eventdata = NULL; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
446 | evt.intval = event->value; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
447 | event->callback(&evt, event->userdata); |
0 | 448 | } |
449 | ||
450 | void ui_menu_event_toggled(GtkCheckMenuItem *ci, UiEventData *event) { | |
451 | UiEvent evt; | |
452 | evt.obj = event->obj; | |
453 | evt.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
454 | evt.document = event->obj->ctx->document; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
455 | evt.eventdata = NULL; |
0 | 456 | 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
|
457 | event->callback(&evt, event->userdata); |
0 | 458 | } |
459 | ||
460 | int ui_checkitem_get(UiInteger *i) { | |
461 | int state = gtk_check_menu_item_get_active(i->obj); | |
462 | i->value = state; | |
463 | return state; | |
464 | } | |
465 | ||
466 | void ui_checkitem_set(UiInteger *i, int value) { | |
467 | i->value = value; | |
468 | gtk_check_menu_item_set_active(i->obj, value); | |
469 | } | |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
470 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
471 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
472 | /* |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
473 | * widget menu functions |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
474 | */ |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
475 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
476 | static gboolean ui_button_press_event(GtkWidget *widget, GdkEvent *event, GtkMenu *menu) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
477 | if(event->type == GDK_BUTTON_PRESS) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
478 | GdkEventButton *e = (GdkEventButton*)event; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
479 | if(e->button == 3) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
480 | gtk_widget_show_all(GTK_WIDGET(menu)); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
481 | gtk_menu_popup(menu, NULL, NULL, NULL, NULL, e->button, e->time); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
482 | return TRUE; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
483 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
484 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
485 | return FALSE; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
486 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
487 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
488 | UIMENU ui_contextmenu(UiObject *obj) { |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
489 | UiContainer *ct = uic_get_current_container(obj); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
490 | return ui_contextmenu_w(obj, ct->current); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
491 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
492 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
493 | UIMENU ui_contextmenu_w(UiObject *obj, UIWIDGET widget) { |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
494 | UiContainer *ct = uic_get_current_container(obj); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
495 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
496 | GtkMenu *menu = GTK_MENU(gtk_menu_new()); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
497 | g_signal_connect(widget, "button-press-event", (GCallback) ui_button_press_event, menu); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
498 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
499 | ct->menu = menu; |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
500 | return menu; |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
501 | } |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
502 | |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
503 | void ui_contextmenu_popup(UIMENU menu) { |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
504 | gtk_menu_popup(menu, NULL, NULL, 0, 0, 0, gtk_get_current_event_time()); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
505 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
506 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
507 | void ui_widget_menuitem(UiObject *obj, char *label, ui_callback f, void *userdata) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
508 | ui_widget_menuitem_gr(obj, label, f, userdata, -1); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
509 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
510 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
511 | void ui_widget_menuitem_gr(UiObject *obj, char *label, ui_callback f, void *userdata, ...) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
512 | UiContainer *ct = uic_get_current_container(obj); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
513 | if(!ct->menu) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
514 | return; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
515 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
516 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
517 | // add groups |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
518 | UcxList *groups = NULL; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
519 | va_list ap; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
520 | va_start(ap, userdata); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
521 | int group; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
522 | while((group = va_arg(ap, int)) != -1) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
523 | ucx_list_append(groups, (void*)(intptr_t)group); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
524 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
525 | va_end(ap); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
526 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
527 | // create menuitem |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
528 | GtkWidget *widget = gtk_menu_item_new_with_mnemonic(label); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
529 | gtk_widget_show(widget); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
530 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
531 | if(f) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
532 | UiEventData *event = malloc(sizeof(UiEventData)); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
533 | event->obj = obj; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
534 | event->userdata = userdata; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
535 | event->callback = f; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
536 | event->value = 0; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
537 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
538 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
539 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
540 | "activate", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
541 | G_CALLBACK(ui_menu_event_wrapper), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
542 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
543 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
544 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
545 | "destroy", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
546 | G_CALLBACK(ui_destroy_userdata), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
547 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
548 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
549 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
550 | gtk_menu_shell_append(GTK_MENU_SHELL(ct->menu), widget); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
551 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
552 | if(groups) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
553 | uic_add_group_widget(obj->ctx, widget, groups); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
554 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
555 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
556 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
557 | void ui_widget_menuitem_st(UiObject *obj, char *stockid, ui_callback f, void *userdata) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
558 | ui_widget_menuitem_stgr(obj, stockid, f, userdata, -1); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
559 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
560 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
561 | void ui_widget_menuitem_stgr(UiObject *obj, char *stockid, ui_callback f, void *userdata, ...) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
562 | UiContainer *ct = uic_get_current_container(obj); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
563 | if(!ct->menu) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
564 | return; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
565 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
566 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
567 | // add groups |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
568 | UcxList *groups = NULL; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
569 | va_list ap; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
570 | va_start(ap, userdata); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
571 | int group; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
572 | while((group = va_arg(ap, int)) != -1) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
573 | ucx_list_append(groups, (void*)(intptr_t)group); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
574 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
575 | va_end(ap); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
576 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
577 | // create menuitem |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
578 | GtkWidget *widget = gtk_image_menu_item_new_from_stock(stockid, obj->ctx->accel_group); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
579 | gtk_widget_show(widget); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
580 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
581 | if(f) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
582 | UiEventData *event = malloc(sizeof(UiEventData)); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
583 | event->obj = obj; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
584 | event->userdata = userdata; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
585 | event->callback = f; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
586 | event->value = 0; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
587 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
588 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
589 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
590 | "activate", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
591 | G_CALLBACK(ui_menu_event_wrapper), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
592 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
593 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
594 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
595 | "destroy", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
596 | G_CALLBACK(ui_destroy_userdata), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
597 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
598 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
599 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
600 | gtk_menu_shell_append(GTK_MENU_SHELL(ct->menu), widget); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
601 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
602 | if(groups) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
603 | uic_add_group_widget(obj->ctx, widget, groups); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
604 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
605 | } |