Sun, 01 Oct 2023 12:08:09 +0200
implement toggle button (WinUI3)
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
4 | * Copyright 2017 Olaf Wintermann. All rights reserved. |
0 | 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" | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
37 | #include "../common/menu.h" |
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
38 | #include "../ui/properties.h" |
0 | 39 | #include "../ui/window.h" |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
40 | #include "container.h" |
0 | 41 | |
174 | 42 | #include <cx/linked_list.h> |
43 | #include <cx/array_list.h> | |
44 | ||
45 | ||
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
46 | static ui_menu_add_f createMenuItem[] = { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
47 | /* UI_MENU */ add_menu_widget, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
48 | /* UI_MENU_SUBMENU */ add_menu_widget, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
49 | /* UI_MENU_ITEM */ add_menuitem_widget, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
50 | /* UI_MENU_STOCK_ITEM */ add_menuitem_st_widget, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
51 | /* UI_MENU_CHECK_ITEM */ add_checkitem_widget, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
52 | /* UI_MENU_CHECK_ITEM_NV */ add_checkitemnv_widget, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
53 | /* UI_MENU_ITEM_LIST */ add_menuitem_list_widget, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
54 | /* UI_MENU_ITEM_LIST_NV */ NULL, // TODO |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
55 | /* UI_MENU_SEPARATOR */ add_menuseparator_widget |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
56 | }; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
57 | |
0 | 58 | // private menu functions |
59 | GtkWidget *ui_create_menubar(UiObject *obj) { | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
60 | UiMenu *menus_begin = uic_get_menu_list(); |
174 | 61 | if(menus_begin == NULL) { |
0 | 62 | return NULL; |
63 | } | |
64 | ||
65 | GtkWidget *mb = gtk_menu_bar_new(); | |
66 | ||
174 | 67 | UiMenu *ls = menus_begin; |
0 | 68 | while(ls) { |
174 | 69 | UiMenu *menu = ls; |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
70 | add_menu_widget(mb, 0, &menu->item, obj); |
0 | 71 | |
174 | 72 | ls = (UiMenu*)ls->item.next; |
0 | 73 | } |
74 | ||
75 | return mb; | |
76 | } | |
77 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
78 | void add_menu_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj) { |
0 | 79 | UiMenu *menu = (UiMenu*)item; |
80 | ||
81 | GtkWidget *menu_widget = gtk_menu_new(); | |
164
1d912f78fd1d
fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
82 | GtkWidget *menu_item = gtk_menu_item_new_with_mnemonic(menu->label); |
0 | 83 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu_widget); |
84 | ||
174 | 85 | UiMenuItemI *it = menu->items_begin; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
86 | int index = 0; |
174 | 87 | while(it) { |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
88 | createMenuItem[it->type](menu_widget, index, it, obj); |
0 | 89 | |
174 | 90 | it = it->next; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
91 | index++; |
0 | 92 | } |
93 | ||
94 | gtk_menu_shell_append(GTK_MENU_SHELL(parent), menu_item); | |
95 | } | |
96 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
97 | void add_menuitem_widget(GtkWidget *parent, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 98 | UiMenuItem *i = (UiMenuItem*)item; |
99 | ||
100 | //GtkWidget *widget = gtk_menu_item_new_with_label(i->title); | |
101 | GtkWidget *widget = gtk_menu_item_new_with_mnemonic(i->label); | |
102 | ||
103 | if(i->callback != NULL) { | |
104 | UiEventData *event = malloc(sizeof(UiEventData)); | |
105 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
106 | event->userdata = i->userdata; |
0 | 107 | event->callback = i->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
108 | event->value = 0; |
0 | 109 | |
110 | g_signal_connect( | |
111 | widget, | |
112 | "activate", | |
113 | G_CALLBACK(ui_menu_event_wrapper), | |
114 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
115 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
116 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
117 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
118 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
119 | event); |
0 | 120 | } |
121 | ||
122 | 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
|
123 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
124 | if(i->groups) { |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
125 | uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, i->groups); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
126 | } |
0 | 127 | } |
128 | ||
129 | void add_menuitem_st_widget( | |
130 | GtkWidget *parent, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
131 | int index, |
0 | 132 | UiMenuItemI *item, |
133 | UiObject *obj) | |
134 | { | |
135 | UiStMenuItem *i = (UiStMenuItem*)item; | |
136 | ||
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
137 | GtkWidget *widget = gtk_image_menu_item_new_from_stock(i->stockid, obj->ctx->accel_group); |
0 | 138 | |
139 | if(i->callback != NULL) { | |
140 | UiEventData *event = malloc(sizeof(UiEventData)); | |
141 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
142 | event->userdata = i->userdata; |
0 | 143 | event->callback = i->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
144 | event->value = 0; |
0 | 145 | |
146 | g_signal_connect( | |
147 | widget, | |
148 | "activate", | |
149 | G_CALLBACK(ui_menu_event_wrapper), | |
150 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
151 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
152 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
153 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
154 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
155 | event); |
0 | 156 | } |
157 | ||
158 | 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
|
159 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
160 | if(i->groups) { |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
161 | uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, i->groups); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
162 | } |
0 | 163 | } |
164 | ||
165 | void add_menuseparator_widget( | |
166 | GtkWidget *parent, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
167 | int index, |
0 | 168 | UiMenuItemI *item, |
169 | UiObject *obj) | |
170 | { | |
171 | gtk_menu_shell_append( | |
172 | GTK_MENU_SHELL(parent), | |
173 | gtk_separator_menu_item_new()); | |
174 | } | |
175 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
176 | void add_checkitem_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 177 | UiCheckItem *ci = (UiCheckItem*)item; |
178 | GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label); | |
179 | gtk_menu_shell_append(GTK_MENU_SHELL(p), widget); | |
180 | ||
181 | if(ci->callback) { | |
182 | UiEventData *event = malloc(sizeof(UiEventData)); | |
183 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
184 | event->userdata = ci->userdata; |
0 | 185 | event->callback = ci->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
186 | event->value = 0; |
0 | 187 | |
188 | g_signal_connect( | |
189 | widget, | |
190 | "toggled", | |
191 | G_CALLBACK(ui_menu_event_toggled), | |
192 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
193 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
194 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
195 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
196 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
197 | event); |
0 | 198 | } |
199 | } | |
200 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
201 | void add_checkitemnv_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 202 | UiCheckItemNV *ci = (UiCheckItemNV*)item; |
203 | GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label); | |
204 | gtk_menu_shell_append(GTK_MENU_SHELL(p), widget); | |
205 | ||
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
206 | UiVar *var = uic_create_var(obj->ctx, ci->varname, UI_VAR_INTEGER); |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
207 | if(var) { |
0 | 208 | UiInteger *value = var->value; |
209 | value->obj = widget; | |
210 | value->get = ui_checkitem_get; | |
211 | value->set = ui_checkitem_set; | |
212 | value = 0; | |
213 | } else { | |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
214 | // TODO: error |
0 | 215 | } |
216 | } | |
217 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
218 | 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
|
219 | UiMenuItemList *il = (UiMenuItemList*)item; |
174 | 220 | const CxAllocator *a = obj->ctx->allocator; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
221 | |
174 | 222 | UiActiveMenuItemList *ls = cxMalloc( |
223 | a, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
224 | sizeof(UiActiveMenuItemList)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
225 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
226 | ls->object = obj; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
227 | ls->menu = GTK_MENU_SHELL(p); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
228 | ls->index = index; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
229 | ls->oldcount = 0; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
230 | ls->list = il->list; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
231 | ls->callback = il->callback; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
232 | ls->userdata = il->userdata; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
233 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
234 | ls->list->observers = ui_add_observer( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
235 | ls->list->observers, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
236 | (ui_callback)ui_update_menuitem_list, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
237 | ls); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
238 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
239 | ui_update_menuitem_list(NULL, ls); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
240 | } |
0 | 241 | |
242 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
243 | 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
|
244 | // remove old items |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
245 | if(list->oldcount > 0) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
246 | int i = 0; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
247 | 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
|
248 | while(mi) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
249 | 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
|
250 | //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
|
251 | gtk_widget_destroy(mi->data); |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
252 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
253 | mi = mi->next; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
254 | i++; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
255 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
256 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
257 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
258 | char *str = ui_list_first(list->list); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
259 | if(str) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
260 | GtkWidget *widget = gtk_separator_menu_item_new(); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
261 | 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
|
262 | gtk_widget_show(widget); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
263 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
264 | int i = 1; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
265 | while(str) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
266 | 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
|
267 | 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
|
268 | gtk_widget_show(widget); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
269 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
270 | if(list->callback) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
271 | // TODO: use mempool |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
272 | UiEventData *event = malloc(sizeof(UiEventData)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
273 | event->obj = list->object; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
274 | event->userdata = list->userdata; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
275 | event->callback = list->callback; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
276 | event->value = i - 1; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
277 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
278 | g_signal_connect( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
279 | widget, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
280 | "activate", |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
281 | G_CALLBACK(ui_menu_event_wrapper), |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
282 | event); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
283 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
284 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
285 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
286 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
287 | event); |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
288 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
289 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
290 | str = ui_list_next(list->list); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
291 | i++; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
292 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
293 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
294 | list->oldcount = i; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
295 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
296 | |
0 | 297 | void ui_menu_event_wrapper(GtkMenuItem *item, UiEventData *event) { |
298 | UiEvent evt; | |
299 | evt.obj = event->obj; | |
300 | evt.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
301 | evt.document = event->obj->ctx->document; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
302 | evt.eventdata = NULL; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
303 | evt.intval = event->value; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
304 | event->callback(&evt, event->userdata); |
0 | 305 | } |
306 | ||
307 | void ui_menu_event_toggled(GtkCheckMenuItem *ci, UiEventData *event) { | |
308 | UiEvent evt; | |
309 | evt.obj = event->obj; | |
310 | evt.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
311 | evt.document = event->obj->ctx->document; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
312 | evt.eventdata = NULL; |
0 | 313 | 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
|
314 | event->callback(&evt, event->userdata); |
0 | 315 | } |
316 | ||
148
4e0b38bbd6c4
replaces usage of some deprecated functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
317 | int64_t ui_checkitem_get(UiInteger *i) { |
0 | 318 | int state = gtk_check_menu_item_get_active(i->obj); |
319 | i->value = state; | |
320 | return state; | |
321 | } | |
322 | ||
148
4e0b38bbd6c4
replaces usage of some deprecated functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
323 | void ui_checkitem_set(UiInteger *i, int64_t value) { |
0 | 324 | i->value = value; |
325 | gtk_check_menu_item_set_active(i->obj, value); | |
326 | } | |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
327 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
328 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
329 | /* |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
330 | * widget menu functions |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
331 | */ |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
332 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
333 | 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
|
334 | if(event->type == GDK_BUTTON_PRESS) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
335 | GdkEventButton *e = (GdkEventButton*)event; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
336 | if(e->button == 3) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
337 | gtk_widget_show_all(GTK_WIDGET(menu)); |
148
4e0b38bbd6c4
replaces usage of some deprecated functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
338 | ui_contextmenu_popup(menu); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
339 | return TRUE; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
340 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
341 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
342 | return FALSE; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
343 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
344 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
345 | UIMENU ui_contextmenu(UiObject *obj) { |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
346 | UiContainer *ct = uic_get_current_container(obj); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
347 | return ui_contextmenu_w(obj, ct->current); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
348 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
349 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
350 | UIMENU ui_contextmenu_w(UiObject *obj, UIWIDGET widget) { |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
351 | UiContainer *ct = uic_get_current_container(obj); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
352 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
353 | GtkMenu *menu = GTK_MENU(gtk_menu_new()); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
354 | 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
|
355 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
356 | ct->menu = menu; |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
357 | return menu; |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
358 | } |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
359 | |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
360 | void ui_contextmenu_popup(UIMENU menu) { |
148
4e0b38bbd6c4
replaces usage of some deprecated functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
361 | #if GTK_MAJOR_VERSION >= 3 && GTK_MINOR_VERSION >= 16 |
4e0b38bbd6c4
replaces usage of some deprecated functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
362 | gtk_menu_popup_at_pointer(menu, NULL); |
4e0b38bbd6c4
replaces usage of some deprecated functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
363 | #else |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
364 | gtk_menu_popup(menu, NULL, NULL, 0, 0, 0, gtk_get_current_event_time()); |
148
4e0b38bbd6c4
replaces usage of some deprecated functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
365 | #endif |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
366 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
367 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
368 | 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
|
369 | ui_widget_menuitem_gr(obj, label, f, userdata, -1); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
370 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
371 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
372 | 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
|
373 | UiContainer *ct = uic_get_current_container(obj); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
374 | if(!ct->menu) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
375 | return; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
376 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
377 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
378 | // add groups |
174 | 379 | CxList *groups = NULL; |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
380 | va_list ap; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
381 | va_start(ap, userdata); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
382 | int group; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
383 | while((group = va_arg(ap, int)) != -1) { |
174 | 384 | if(!groups) { |
385 | groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16); | |
386 | } | |
387 | cxListAdd(groups, &group); | |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
388 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
389 | va_end(ap); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
390 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
391 | // create menuitem |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
392 | GtkWidget *widget = gtk_menu_item_new_with_mnemonic(label); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
393 | gtk_widget_show(widget); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
394 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
395 | if(f) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
396 | UiEventData *event = malloc(sizeof(UiEventData)); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
397 | event->obj = obj; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
398 | event->userdata = userdata; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
399 | event->callback = f; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
400 | event->value = 0; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
401 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
402 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
403 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
404 | "activate", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
405 | G_CALLBACK(ui_menu_event_wrapper), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
406 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
407 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
408 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
409 | "destroy", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
410 | G_CALLBACK(ui_destroy_userdata), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
411 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
412 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
413 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
414 | 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
|
415 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
416 | if(groups) { |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
417 | uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, groups); |
174 | 418 | cxListDestroy(groups); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
419 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
420 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
421 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
422 | 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
|
423 | ui_widget_menuitem_stgr(obj, stockid, f, userdata, -1); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
424 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
425 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
426 | 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
|
427 | UiContainer *ct = uic_get_current_container(obj); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
428 | if(!ct->menu) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
429 | return; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
430 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
431 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
432 | // add groups |
174 | 433 | CxList *groups = NULL; |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
434 | va_list ap; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
435 | va_start(ap, userdata); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
436 | int group; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
437 | while((group = va_arg(ap, int)) != -1) { |
174 | 438 | if(!groups) { |
439 | groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16); | |
440 | } | |
441 | cxListAdd(groups, &group); | |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
442 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
443 | va_end(ap); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
444 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
445 | // create menuitem |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
446 | 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
|
447 | gtk_widget_show(widget); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
448 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
449 | if(f) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
450 | UiEventData *event = malloc(sizeof(UiEventData)); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
451 | event->obj = obj; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
452 | event->userdata = userdata; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
453 | event->callback = f; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
454 | event->value = 0; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
455 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
456 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
457 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
458 | "activate", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
459 | G_CALLBACK(ui_menu_event_wrapper), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
460 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
461 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
462 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
463 | "destroy", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
464 | G_CALLBACK(ui_destroy_userdata), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
465 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
466 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
467 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
468 | 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
|
469 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
470 | if(groups) { |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
471 | uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, groups); |
174 | 472 | cxListDestroy(groups); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
473 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
474 | } |