Fri, 15 Nov 2024 21:16:18 +0100
add UiObject reference counting (GTK)
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2023 Olaf Wintermann. All rights reserved. |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "menu.h" |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
175
diff
changeset
|
31 | #include <stdarg.h> |
208 | 32 | #include <string.h> |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
175
diff
changeset
|
33 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <cx/linked_list.h> |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <cx/array_list.h> |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
37 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | static UiMenu *menus_begin; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | static UiMenu *menus_end; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | static CxList *current; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
42 | static int menu_item_counter = 0; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
43 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | static void add_menu(UiMenu *menu) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | cx_linked_list_add( |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | (void**)&menus_begin, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | (void**)&menus_end, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | offsetof(UiMenu, item.prev), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | offsetof(UiMenu, item.next), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | menu); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | static void add_item(UiMenuItemI *item) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | UiMenu *menu = cxListAt(current, 0); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | cx_linked_list_add( |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | (void**)&menu->items_begin, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | (void**)&menu->items_end, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | offsetof(UiMenu, item.prev), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | offsetof(UiMenu, item.next), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
63 | static void mitem_set_id(UiMenuItemI *item) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
64 | snprintf(item->id, 8, "%x", menu_item_counter++); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
65 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
66 | |
208 | 67 | static char* nl_strdup(const char* s) { |
68 | return s ? strdup(s) : NULL; | |
69 | } | |
70 | ||
367
1c3af8e31d8e
fix toolbar item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
71 | int* uic_copy_groups(const int* groups, size_t *ngroups) { |
208 | 72 | *ngroups = 0; |
73 | if (!groups) { | |
74 | return NULL; | |
75 | } | |
76 | ||
77 | size_t n; | |
78 | for (n = 0; groups[n] > -1; n++) { } | |
79 | ||
80 | if (ngroups > 0) { | |
81 | int* newarray = calloc(n, sizeof(int)); | |
364
eaec7c62ce41
implement menu item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
325
diff
changeset
|
82 | memcpy(newarray, groups, n * sizeof(int)); |
208 | 83 | *ngroups = n; |
84 | return newarray; | |
85 | } | |
86 | return NULL; | |
87 | } | |
88 | ||
89 | void ui_menu_create(const char *label) { | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | if(!current) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | // create menu |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | UiMenu *menu = malloc(sizeof(UiMenu)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
96 | mitem_set_id(&menu->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | menu->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | menu->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | menu->item.type = UI_MENU; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | menu->label = label; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | menu->items_begin = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | menu->items_end = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | menu->parent = NULL; |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
105 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
106 | menu->end = 0; |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | |
325 | 108 | if (cxListSize(current) == 0) { |
208 | 109 | add_menu(menu); |
110 | } | |
111 | else { | |
112 | add_item((UiMenuItemI*)menu); | |
113 | } | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
114 | uic_add_menu_to_stack(menu); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
117 | UIEXPORT void ui_menu_end(void) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
118 | cxListRemove(current, 0); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
119 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
120 | |
208 | 121 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | |
208 | 123 | void ui_menuitem_create(UiMenuItemArgs args) { |
124 | if (!current) { | |
125 | return; // error? | |
126 | } | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
208 | 128 | UiMenuItem* item = malloc(sizeof(UiMenuItem)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
129 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | item->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | item->item.type = UI_MENU_ITEM; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | |
208 | 134 | item->label = nl_strdup(args.label); |
135 | item->stockid = nl_strdup(args.stockid); | |
136 | item->icon = nl_strdup(args.icon); | |
137 | item->userdata = args.onclickdata; | |
138 | item->callback = args.onclick; | |
367
1c3af8e31d8e
fix toolbar item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
139 | item->groups = uic_copy_groups(args.groups, &item->ngroups); |
208 | 140 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | void ui_menuseparator() { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | if(!current) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | return; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | UiMenuItemI *item = malloc(sizeof(UiMenuItemI)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
150 | item->id[0] = 0; |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | item->prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | item->next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | item->type = UI_MENU_SEPARATOR; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | |
208 | 158 | void ui_menu_toggleitem_create(UiMenuToggleItemArgs args) { |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | if(!current) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | return; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | |
208 | 163 | UiMenuCheckItem *item = malloc(sizeof(UiMenuCheckItem)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
164 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | item->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | item->item.type = UI_MENU_CHECK_ITEM; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | |
208 | 169 | item->label = nl_strdup(args.label); |
170 | item->stockid = nl_strdup(args.stockid); | |
171 | item->icon = nl_strdup(args.icon); | |
172 | item->varname = nl_strdup(args.varname); | |
173 | item->userdata = args.onchangedata; | |
174 | item->callback = args.onchange; | |
367
1c3af8e31d8e
fix toolbar item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
175 | item->groups = uic_copy_groups(args.groups, &item->ngroups); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | |
208 | 180 | void ui_menu_radioitem_create(UiMenuToggleItemArgs args) { |
181 | if (!current) { | |
182 | return; | |
183 | } | |
184 | ||
185 | UiMenuCheckItem* item = malloc(sizeof(UiMenuCheckItem)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
186 | mitem_set_id(&item->item); |
208 | 187 | item->item.prev = NULL; |
188 | item->item.next = NULL; | |
189 | item->item.type = UI_MENU_CHECK_ITEM; | |
190 | ||
191 | item->label = nl_strdup(args.label); | |
192 | item->stockid = nl_strdup(args.stockid); | |
193 | item->icon = nl_strdup(args.icon); | |
194 | item->varname = nl_strdup(args.varname); | |
195 | item->userdata = args.onchangedata; | |
196 | item->callback = args.onchange; | |
367
1c3af8e31d8e
fix toolbar item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
197 | item->groups = uic_copy_groups(args.groups, &item->ngroups); |
208 | 198 | |
199 | add_item((UiMenuItemI*)item); | |
200 | } | |
201 | ||
202 | void ui_menu_itemlist_create(UiMenuItemListArgs args) { | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | if(!current) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | return; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | |
208 | 207 | UiMenuItemList*item = malloc(sizeof(UiMenuItemList)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
208 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | item->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | item->item.type = UI_MENU_ITEM_LIST; |
236
ee794586f51b
add getvalue func for menu item lists (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
212 | item->getvalue = args.getvalue; |
208 | 213 | item->callback = args.onselect; |
214 | item->userdata = args.onselectdata; | |
215 | item->varname = nl_strdup(args.varname); | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | |
208 | 220 | void ui_menu_checkitemlist_create(UiMenuItemListArgs args) { |
221 | if (!current) { | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | return; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | } |
208 | 224 | |
225 | UiMenuItemList* item = malloc(sizeof(UiMenuItemList)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
226 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | item->item.next = NULL; |
229
a952760955b4
add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
229 | item->item.type = UI_MENU_CHECKITEM_LIST; |
208 | 230 | item->callback = args.onselect; |
231 | item->userdata = args.onselectdata; | |
232 | item->varname = nl_strdup(args.varname); | |
233 | ||
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | |
208 | 237 | void ui_menu_radioitemlist_create(UiMenuItemListArgs args) { |
238 | if (!current) { | |
239 | return; | |
240 | } | |
241 | ||
242 | UiMenuItemList* item = malloc(sizeof(UiMenuItemList)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
243 | mitem_set_id(&item->item); |
208 | 244 | item->item.prev = NULL; |
245 | item->item.next = NULL; | |
229
a952760955b4
add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
246 | item->item.type = UI_MENU_RADIOITEM_LIST; |
208 | 247 | item->callback = args.onselect; |
248 | item->userdata = args.onselectdata; | |
249 | item->varname = nl_strdup(args.varname); | |
250 | ||
251 | add_item((UiMenuItemI*)item); | |
252 | } | |
253 | ||
254 | ||
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
255 | void uic_add_menu_to_stack(UiMenu* menu) { |
232
e2b33055113f
fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
229
diff
changeset
|
256 | if (!current) { |
e2b33055113f
fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
229
diff
changeset
|
257 | current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); |
e2b33055113f
fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
229
diff
changeset
|
258 | } |
e2b33055113f
fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
229
diff
changeset
|
259 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
260 | cxListInsert(current, 0, menu); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
261 | } |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | UiMenu* uic_get_menu_list(void) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | return menus_begin; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | } |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
266 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
267 | UIEXPORT void ui_menu_close(void) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
268 | UiMenu* menu = cxListAt(current, 0); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
269 | menu->end = 1; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
270 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
271 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
272 | UIEXPORT int ui_menu_is_open(void) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
273 | UiMenu* menu = cxListAt(current, 0); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
274 | if (menu->end) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
275 | ui_menu_end(); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
276 | return 0; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
277 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
278 | return 1; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
279 | } |