Fri, 15 Nov 2024 21:16:18 +0100
add UiObject reference counting (GTK)
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 | ||
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
45 | #if GTK_MAJOR_VERSION <= 3 |
174 | 46 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
47 | static ui_menu_add_f createMenuItem[] = { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
48 | /* UI_MENU */ 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_CHECK_ITEM */ add_checkitem_widget, |
255
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
51 | /* UI_MENU_RADIO_ITEM */ add_radioitem_widget, |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
52 | /* UI_MENU_ITEM_LIST */ add_menuitem_list_widget, |
255
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
53 | /* UI_MENU_CHECKITEM_LIST */ add_menuitem_list_widget, |
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
54 | /* UI_MENU_RADIOITEM_LIST */ add_menuitem_list_widget, |
175
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 | ||
275
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
78 | void ui_add_menu_items(GtkWidget *parent, int i, UiMenu *menu, UiObject *obj) { |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
79 | UiMenuItemI *it = menu->items_begin; |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
80 | int index = 0; |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
81 | while(it) { |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
82 | createMenuItem[it->type](parent, index, it, obj); |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
83 | it = it->next; |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
84 | index++; |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
85 | } |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
86 | } |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
87 | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
88 | void add_menu_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj) { |
0 | 89 | UiMenu *menu = (UiMenu*)item; |
90 | ||
91 | GtkWidget *menu_widget = gtk_menu_new(); | |
164
1d912f78fd1d
fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
92 | GtkWidget *menu_item = gtk_menu_item_new_with_mnemonic(menu->label); |
0 | 93 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu_widget); |
94 | ||
275
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
95 | ui_add_menu_items(menu_widget, i, menu, obj); |
132c7bcc6997
implement new toolbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
96 | |
0 | 97 | |
98 | gtk_menu_shell_append(GTK_MENU_SHELL(parent), menu_item); | |
99 | } | |
100 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
101 | void add_menuitem_widget(GtkWidget *parent, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 102 | UiMenuItem *i = (UiMenuItem*)item; |
103 | ||
104 | //GtkWidget *widget = gtk_menu_item_new_with_label(i->title); | |
105 | GtkWidget *widget = gtk_menu_item_new_with_mnemonic(i->label); | |
106 | ||
107 | if(i->callback != NULL) { | |
108 | UiEventData *event = malloc(sizeof(UiEventData)); | |
109 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
110 | event->userdata = i->userdata; |
0 | 111 | event->callback = i->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
112 | event->value = 0; |
278
a8faf8757450
implement ui_dialog_create (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
113 | event->customdata = NULL; |
0 | 114 | |
115 | g_signal_connect( | |
116 | widget, | |
117 | "activate", | |
118 | G_CALLBACK(ui_menu_event_wrapper), | |
119 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
120 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
121 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
122 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
123 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
124 | event); |
0 | 125 | } |
126 | ||
127 | 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
|
128 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
129 | if(i->groups) { |
263
a0ea718ab1d8
fix add_menuitem_widget passing wrong list type to uic_add_group_widget
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
130 | CxList *groups = cxArrayListCreateSimple(sizeof(int), i->ngroups); |
a0ea718ab1d8
fix add_menuitem_widget passing wrong list type to uic_add_group_widget
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
131 | cxListAddArray(groups, i->groups, i->ngroups); |
a0ea718ab1d8
fix add_menuitem_widget passing wrong list type to uic_add_group_widget
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
132 | uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, groups); |
a0ea718ab1d8
fix add_menuitem_widget passing wrong list type to uic_add_group_widget
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
133 | cxListDestroy(groups); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
134 | } |
0 | 135 | } |
136 | ||
255
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
137 | /* |
0 | 138 | void add_menuitem_st_widget( |
139 | GtkWidget *parent, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
140 | int index, |
0 | 141 | UiMenuItemI *item, |
142 | UiObject *obj) | |
143 | { | |
144 | UiStMenuItem *i = (UiStMenuItem*)item; | |
145 | ||
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
146 | GtkWidget *widget = gtk_image_menu_item_new_from_stock(i->stockid, obj->ctx->accel_group); |
0 | 147 | |
148 | if(i->callback != NULL) { | |
149 | UiEventData *event = malloc(sizeof(UiEventData)); | |
150 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
151 | event->userdata = i->userdata; |
0 | 152 | event->callback = i->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
153 | event->value = 0; |
0 | 154 | |
155 | g_signal_connect( | |
156 | widget, | |
157 | "activate", | |
158 | G_CALLBACK(ui_menu_event_wrapper), | |
159 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
160 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
161 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
162 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
163 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
164 | event); |
0 | 165 | } |
166 | ||
167 | 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
|
168 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
169 | if(i->groups) { |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
170 | 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
|
171 | } |
0 | 172 | } |
255
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
173 | */ |
0 | 174 | |
175 | void add_menuseparator_widget( | |
176 | GtkWidget *parent, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
177 | int index, |
0 | 178 | UiMenuItemI *item, |
179 | UiObject *obj) | |
180 | { | |
181 | gtk_menu_shell_append( | |
182 | GTK_MENU_SHELL(parent), | |
183 | gtk_separator_menu_item_new()); | |
184 | } | |
185 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
186 | void add_checkitem_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
255
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
187 | UiMenuCheckItem *ci = (UiMenuCheckItem*)item; |
0 | 188 | GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label); |
189 | gtk_menu_shell_append(GTK_MENU_SHELL(p), widget); | |
190 | ||
191 | if(ci->callback) { | |
192 | UiEventData *event = malloc(sizeof(UiEventData)); | |
193 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
194 | event->userdata = ci->userdata; |
0 | 195 | event->callback = ci->callback; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
196 | event->value = 0; |
278
a8faf8757450
implement ui_dialog_create (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
197 | event->customdata = NULL; |
a8faf8757450
implement ui_dialog_create (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
198 | |
0 | 199 | g_signal_connect( |
200 | widget, | |
201 | "toggled", | |
202 | G_CALLBACK(ui_menu_event_toggled), | |
203 | event); | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
204 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
205 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
206 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
207 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
208 | event); |
0 | 209 | } |
210 | } | |
211 | ||
255
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
212 | void add_radioitem_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
213 | // TODO |
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
214 | } |
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
215 | |
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
216 | /* |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
217 | void add_checkitemnv_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) { |
0 | 218 | UiCheckItemNV *ci = (UiCheckItemNV*)item; |
219 | GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label); | |
220 | gtk_menu_shell_append(GTK_MENU_SHELL(p), widget); | |
221 | ||
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
222 | 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
|
223 | if(var) { |
0 | 224 | UiInteger *value = var->value; |
225 | value->obj = widget; | |
226 | value->get = ui_checkitem_get; | |
227 | value->set = ui_checkitem_set; | |
228 | value = 0; | |
229 | } else { | |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
230 | // TODO: error |
0 | 231 | } |
232 | } | |
255
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
233 | */ |
0 | 234 | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
235 | 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
|
236 | UiMenuItemList *il = (UiMenuItemList*)item; |
174 | 237 | const CxAllocator *a = obj->ctx->allocator; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
238 | |
174 | 239 | UiActiveMenuItemList *ls = cxMalloc( |
240 | a, | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
241 | sizeof(UiActiveMenuItemList)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
242 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
243 | ls->object = obj; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
244 | ls->menu = GTK_MENU_SHELL(p); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
245 | ls->index = index; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
246 | ls->oldcount = 0; |
286
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
247 | ls->getvalue = il->getvalue; |
255
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
248 | |
284
f93c368518c0
fix menu lists (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
249 | UiVar* var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST); |
f93c368518c0
fix menu lists (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
250 | ls->list = var->value; |
255
ebdce2bb62be
minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
251 | |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
252 | ls->callback = il->callback; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
253 | ls->userdata = il->userdata; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
254 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
255 | ls->list->observers = ui_add_observer( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
256 | ls->list->observers, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
257 | (ui_callback)ui_update_menuitem_list, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
258 | ls); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
259 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
260 | ui_update_menuitem_list(NULL, ls); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
261 | } |
0 | 262 | |
263 | ||
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
264 | 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
|
265 | // remove old items |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
266 | if(list->oldcount > 0) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
267 | int i = 0; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
268 | 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
|
269 | while(mi) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
270 | 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
|
271 | //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
|
272 | gtk_widget_destroy(mi->data); |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
273 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
274 | mi = mi->next; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
275 | i++; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
276 | } |
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 | |
286
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
279 | void* elm = ui_list_first(list->list); |
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
280 | if(elm) { |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
281 | GtkWidget *widget = gtk_separator_menu_item_new(); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
282 | 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
|
283 | gtk_widget_show(widget); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
284 | } |
286
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
285 | |
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
286 | ui_getvaluefunc getvalue = list->getvalue; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
287 | int i = 1; |
286
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
288 | while(elm) { |
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
289 | char *label = (char*) (getvalue ? getvalue(elm, 0) : elm); |
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
290 | |
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
291 | GtkWidget *widget = gtk_menu_item_new_with_label(label); |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
292 | 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
|
293 | gtk_widget_show(widget); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
294 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
295 | if(list->callback) { |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
296 | UiEventData *event = malloc(sizeof(UiEventData)); |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
297 | event->obj = list->object; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
298 | event->userdata = list->userdata; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
299 | event->callback = list->callback; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
300 | event->value = i - 1; |
287
5370ea7e45a2
fix eventdata not set by menu list events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
286
diff
changeset
|
301 | event->customdata = elm; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
302 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
303 | g_signal_connect( |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
304 | widget, |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
305 | "activate", |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
306 | G_CALLBACK(ui_menu_event_wrapper), |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
307 | event); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
308 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
309 | widget, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
310 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
311 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
312 | event); |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
313 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
314 | |
286
f6ca4bbbe2a6
fix getvaluefunc not used by menu lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
284
diff
changeset
|
315 | elm = ui_list_next(list->list); |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
316 | i++; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
317 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
318 | |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
319 | list->oldcount = i; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
320 | } |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
321 | |
0 | 322 | void ui_menu_event_wrapper(GtkMenuItem *item, UiEventData *event) { |
323 | UiEvent evt; | |
324 | evt.obj = event->obj; | |
325 | evt.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
326 | evt.document = event->obj->ctx->document; |
287
5370ea7e45a2
fix eventdata not set by menu list events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
286
diff
changeset
|
327 | evt.eventdata = event->customdata; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
328 | evt.intval = event->value; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
329 | event->callback(&evt, event->userdata); |
0 | 330 | } |
331 | ||
332 | void ui_menu_event_toggled(GtkCheckMenuItem *ci, UiEventData *event) { | |
333 | UiEvent evt; | |
334 | evt.obj = event->obj; | |
335 | evt.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
336 | evt.document = event->obj->ctx->document; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
337 | evt.eventdata = NULL; |
0 | 338 | 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
|
339 | event->callback(&evt, event->userdata); |
0 | 340 | } |
341 | ||
148
4e0b38bbd6c4
replaces usage of some deprecated functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
342 | int64_t ui_checkitem_get(UiInteger *i) { |
0 | 343 | int state = gtk_check_menu_item_get_active(i->obj); |
344 | i->value = state; | |
345 | return state; | |
346 | } | |
347 | ||
148
4e0b38bbd6c4
replaces usage of some deprecated functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
348 | void ui_checkitem_set(UiInteger *i, int64_t value) { |
0 | 349 | i->value = value; |
350 | gtk_check_menu_item_set_active(i->obj, value); | |
351 | } | |
75
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 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
354 | /* |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
355 | * widget menu functions |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
356 | */ |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
357 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
358 | 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
|
359 | if(event->type == GDK_BUTTON_PRESS) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
360 | GdkEventButton *e = (GdkEventButton*)event; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
361 | if(e->button == 3) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
362 | 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
|
363 | ui_contextmenu_popup(menu); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
364 | return TRUE; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
365 | } |
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 | return FALSE; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
368 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
369 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
370 | UIMENU ui_contextmenu(UiObject *obj) { |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
371 | UiContainer *ct = uic_get_current_container(obj); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
372 | return ui_contextmenu_w(obj, ct->current); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
373 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
374 | |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
375 | UIMENU ui_contextmenu_w(UiObject *obj, UIWIDGET widget) { |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
376 | UiContainer *ct = uic_get_current_container(obj); |
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 | GtkMenu *menu = GTK_MENU(gtk_menu_new()); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
379 | 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
|
380 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
381 | ct->menu = menu; |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
382 | return menu; |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
383 | } |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
384 | |
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
385 | 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
|
386 | #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
|
387 | 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
|
388 | #else |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
389 | 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
|
390 | #endif |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
391 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
392 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
393 | 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
|
394 | ui_widget_menuitem_gr(obj, label, f, userdata, -1); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
395 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
396 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
397 | 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
|
398 | UiContainer *ct = uic_get_current_container(obj); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
399 | if(!ct->menu) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
400 | return; |
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 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
403 | // add groups |
174 | 404 | CxList *groups = NULL; |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
405 | va_list ap; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
406 | va_start(ap, userdata); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
407 | int group; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
408 | while((group = va_arg(ap, int)) != -1) { |
174 | 409 | if(!groups) { |
410 | groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16); | |
411 | } | |
412 | cxListAdd(groups, &group); | |
75
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 | va_end(ap); |
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 | // create menuitem |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
417 | GtkWidget *widget = gtk_menu_item_new_with_mnemonic(label); |
115
102fc0b8fe3e
improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
418 | gtk_widget_show(widget); |
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 | if(f) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
421 | UiEventData *event = malloc(sizeof(UiEventData)); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
422 | event->obj = obj; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
423 | event->userdata = userdata; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
424 | event->callback = f; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
425 | event->value = 0; |
278
a8faf8757450
implement ui_dialog_create (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
426 | event->customdata = NULL; |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
427 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
428 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
429 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
430 | "activate", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
431 | G_CALLBACK(ui_menu_event_wrapper), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
432 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
433 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
434 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
435 | "destroy", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
436 | G_CALLBACK(ui_destroy_userdata), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
437 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
438 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
439 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
440 | 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
|
441 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
442 | if(groups) { |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
443 | uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, groups); |
174 | 444 | cxListDestroy(groups); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
445 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
446 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
447 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
448 | 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
|
449 | ui_widget_menuitem_stgr(obj, stockid, f, userdata, -1); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
450 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
451 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
452 | 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
|
453 | UiContainer *ct = uic_get_current_container(obj); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
454 | if(!ct->menu) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
455 | return; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
456 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
457 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
458 | // add groups |
174 | 459 | CxList *groups = NULL; |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
460 | va_list ap; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
461 | va_start(ap, userdata); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
462 | int group; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
463 | while((group = va_arg(ap, int)) != -1) { |
174 | 464 | if(!groups) { |
465 | groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16); | |
466 | } | |
467 | cxListAdd(groups, &group); | |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
468 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
469 | va_end(ap); |
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 | // create menuitem |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
472 | 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
|
473 | gtk_widget_show(widget); |
75
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 | if(f) { |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
476 | UiEventData *event = malloc(sizeof(UiEventData)); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
477 | event->obj = obj; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
478 | event->userdata = userdata; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
479 | event->callback = f; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
480 | event->value = 0; |
278
a8faf8757450
implement ui_dialog_create (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
275
diff
changeset
|
481 | event->customdata = NULL; |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
482 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
483 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
484 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
485 | "activate", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
486 | G_CALLBACK(ui_menu_event_wrapper), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
487 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
488 | g_signal_connect( |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
489 | widget, |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
490 | "destroy", |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
491 | G_CALLBACK(ui_destroy_userdata), |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
492 | event); |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
493 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
494 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
495 | 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
|
496 | |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
497 | if(groups) { |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
498 | uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, groups); |
174 | 499 | cxListDestroy(groups); |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
500 | } |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
501 | } |
293
736c962f1011
initial gtk4 porting, incomplete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
502 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
503 | #endif /* GTK_MAJOR_VERSION <= 3 */ |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
504 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
505 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
506 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
507 | #if GTK_MAJOR_VERSION >= 4 |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
508 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
509 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
510 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
511 | static ui_gmenu_add_f createMenuItem[] = { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
512 | /* UI_MENU */ ui_gmenu_add_menu, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
513 | /* UI_MENU_ITEM */ ui_gmenu_add_menuitem, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
514 | /* UI_MENU_CHECK_ITEM */ ui_gmenu_add_checkitem, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
515 | /* UI_MENU_RADIO_ITEM */ ui_gmenu_add_radioitem, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
516 | /* UI_MENU_ITEM_LIST */ ui_gmenu_add_menuitem_list, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
517 | /* UI_MENU_CHECKITEM_LIST */ ui_gmenu_add_menuitem_list, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
518 | /* UI_MENU_RADIOITEM_LIST */ ui_gmenu_add_menuitem_list, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
519 | /* UI_MENU_SEPARATOR */ ui_gmenu_add_menuseparator |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
520 | }; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
521 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
522 | void ui_gmenu_add_menu_items(GMenu *parent, int i, UiMenu *menu, UiObject *obj) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
523 | UiMenuItemI *it = menu->items_begin; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
524 | int index = 0; |
322
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
525 | int index_section = 0; |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
526 | GMenu *section = NULL; |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
527 | while(it) { |
322
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
528 | if(it->type == UI_MENU_SEPARATOR) { |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
529 | section = g_menu_new(); |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
530 | g_menu_append_section(parent, NULL, G_MENU_MODEL(section)); |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
531 | index++; |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
532 | index_section = 0; |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
533 | } else { |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
534 | if(section) { |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
535 | createMenuItem[it->type](section, index_section++, it, obj); |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
536 | } else { |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
537 | createMenuItem[it->type](parent, index++, it, obj); |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
538 | } |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
539 | } |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
540 | it = it->next; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
541 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
542 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
543 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
544 | void ui_gmenu_add_menu(GMenu *parent, int index, UiMenuItemI *item, UiObject *obj) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
545 | UiMenu *mi = (UiMenu*)item; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
546 | GMenu *menu = g_menu_new(); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
547 | ui_gmenu_add_menu_items(menu, 0, mi, obj); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
548 | g_menu_append_submenu(parent, mi->label, G_MENU_MODEL(menu)); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
549 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
550 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
551 | void ui_gmenu_add_menuitem(GMenu *parent, int index, UiMenuItemI *item, UiObject *obj) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
552 | UiMenuItem *i = (UiMenuItem*)item; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
553 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
554 | GSimpleAction *action = g_simple_action_new(item->id, NULL); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
555 | g_action_map_add_action(obj->ctx->action_map, G_ACTION(action)); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
556 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
557 | if(i->callback != NULL) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
558 | UiEventData *event = malloc(sizeof(UiEventData)); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
559 | event->obj = obj; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
560 | event->userdata = i->userdata; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
561 | event->callback = i->callback; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
562 | event->value = 0; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
563 | event->customdata = NULL; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
564 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
565 | g_signal_connect( |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
566 | action, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
567 | "activate", |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
568 | G_CALLBACK(ui_activate_event_wrapper), |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
569 | event); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
570 | g_signal_connect( |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
571 | obj->widget, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
572 | "destroy", |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
573 | G_CALLBACK(ui_destroy_userdata), |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
574 | event); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
575 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
576 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
577 | char action_name[32]; |
322
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
578 | snprintf(action_name, 32, "win.%s", item->id); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
579 | g_menu_append(parent, i->label, action_name); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
580 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
581 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
582 | void ui_gmenu_add_menuseparator(GMenu *p, int index, UiMenuItemI *item, UiObject *obj) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
583 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
584 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
585 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
586 | void ui_gmenu_add_checkitem(GMenu *p, int index, UiMenuItemI *item, UiObject *obj) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
587 | UiMenuCheckItem *checkitem = (UiMenuCheckItem*)item; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
588 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
589 | // TODO |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
590 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
591 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
592 | void ui_gmenu_add_radioitem(GMenu *p, int index, UiMenuItemI *item, UiObject *obj) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
593 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
594 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
595 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
596 | void ui_gmenu_add_menuitem_list(GMenu *p, int index, UiMenuItemI *item, UiObject *obj) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
597 | UiMenuItemList *il = (UiMenuItemList*)item; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
598 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
599 | const CxAllocator *a = obj->ctx->allocator; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
600 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
601 | UiActiveGMenuItemList *ls = cxMalloc( |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
602 | a, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
603 | sizeof(UiActiveGMenuItemList)); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
604 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
605 | ls->object = obj; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
606 | ls->menu = p; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
607 | ls->index = index; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
608 | ls->oldcount = 0; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
609 | ls->getvalue = il->getvalue; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
610 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
611 | UiVar* var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST); |
312
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
612 | ls->var = var; |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
613 | UiList *list = var->value; |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
614 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
615 | ls->callback = il->callback; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
616 | ls->userdata = il->userdata; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
617 | |
312
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
618 | list->observers = ui_add_observer( |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
619 | list->observers, |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
620 | (ui_callback)ui_update_gmenu_item_list, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
621 | ls); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
622 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
623 | GSimpleAction *action = g_simple_action_new(item->id, g_variant_type_new("i")); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
624 | g_action_map_add_action(obj->ctx->action_map, G_ACTION(action)); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
625 | snprintf(ls->action, 32, "win.%s", item->id); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
626 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
627 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
628 | UiEventData *event = malloc(sizeof(UiEventData)); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
629 | event->obj = obj; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
630 | event->userdata = il->userdata; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
631 | event->callback = il->callback; |
312
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
632 | event->customdata = var; |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
633 | event->value = 0; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
634 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
635 | g_signal_connect( |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
636 | action, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
637 | "activate", |
312
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
638 | G_CALLBACK(ui_menu_list_item_activate_event_wrapper), |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
639 | event); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
640 | g_signal_connect( |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
641 | obj->widget, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
642 | "destroy", |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
643 | G_CALLBACK(ui_destroy_userdata), |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
644 | event); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
645 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
646 | ui_update_gmenu_item_list(NULL, ls); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
647 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
648 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
649 | void ui_activate_event_wrapper(GSimpleAction* self, GVariant* parameter, UiEventData *event) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
650 | int intval = event->value; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
651 | if(parameter && g_variant_is_of_type(parameter, G_VARIANT_TYPE_INT32)) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
652 | intval = g_variant_get_int32(parameter); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
653 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
654 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
655 | UiEvent evt; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
656 | evt.obj = event->obj; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
657 | evt.window = event->obj->window; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
658 | evt.document = event->obj->ctx->document; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
659 | evt.eventdata = event->customdata; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
660 | evt.intval = intval; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
661 | event->callback(&evt, event->userdata); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
662 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
663 | |
312
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
664 | void ui_menu_list_item_activate_event_wrapper(GSimpleAction* self, GVariant* parameter, UiEventData *event) { |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
665 | int index = g_variant_get_int32(parameter); |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
666 | UiVar *var = event->customdata; |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
667 | UiList *list = var->value; |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
668 | |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
669 | UiEvent evt; |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
670 | evt.obj = event->obj; |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
671 | evt.window = event->obj->window; |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
672 | evt.document = event->obj->ctx->document; |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
673 | evt.eventdata = ui_list_get(list, index); |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
674 | evt.intval = index; |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
675 | event->callback(&evt, event->userdata); |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
676 | |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
677 | } |
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
678 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
679 | void ui_update_gmenu_item_list(UiEvent *event, UiActiveGMenuItemList *list) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
680 | // remove old items |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
681 | for(int i=0;i<list->oldcount;i++) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
682 | g_menu_remove(list->menu, list->index); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
683 | } |
312
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
684 | UiList *ls = list->var->value; |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
685 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
686 | // add list items |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
687 | ui_getvaluefunc getvalue = list->getvalue; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
688 | int i = 0; |
312
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
689 | void* elm = ui_list_first(ls); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
690 | while(elm) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
691 | char *label = (char*) (getvalue ? getvalue(elm, 0) : elm); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
692 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
693 | GMenuItem *item = g_menu_item_new(label, NULL); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
694 | GVariant *v = g_variant_new("i", i); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
695 | g_menu_item_set_action_and_target_value(item, list->action, v); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
696 | g_menu_insert_item(list->menu, list->index+i, item); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
697 | |
312
3f2b3d15668b
fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
698 | elm = ui_list_next(ls); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
699 | i++; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
700 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
701 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
702 | list->oldcount = i; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
703 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
704 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
705 | #endif |