Sun, 13 Oct 2024 11:05:38 +0200
implement gtk3 stack tabview
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 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | static UiMenu *menus_begin; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | static UiMenu *menus_end; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | static CxList *current; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
41 | static int menu_item_counter = 0; |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
42 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | static void add_menu(UiMenu *menu) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | cx_linked_list_add( |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | (void**)&menus_begin, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | (void**)&menus_end, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | offsetof(UiMenu, item.prev), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | offsetof(UiMenu, item.next), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | menu); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | } |
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 | static void add_item(UiMenuItemI *item) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | UiMenu *menu = cxListAt(current, 0); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | cx_linked_list_add( |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | (void**)&menu->items_begin, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | (void**)&menu->items_end, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | offsetof(UiMenu, item.prev), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | offsetof(UiMenu, item.next), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
62 | 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
|
63 | 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
|
64 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
65 | |
208 | 66 | static char* nl_strdup(const char* s) { |
67 | return s ? strdup(s) : NULL; | |
68 | } | |
69 | ||
254
13997c76859b
fix some const related warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
70 | static int* copy_groups(const int* groups, size_t *ngroups) { |
208 | 71 | *ngroups = 0; |
72 | if (!groups) { | |
73 | return NULL; | |
74 | } | |
75 | ||
76 | size_t n; | |
77 | for (n = 0; groups[n] > -1; n++) { } | |
78 | ||
79 | if (ngroups > 0) { | |
80 | int* newarray = calloc(n, sizeof(int)); | |
81 | memcpy(newarray, groups, n); | |
82 | *ngroups = n; | |
83 | return newarray; | |
84 | } | |
85 | return NULL; | |
86 | } | |
87 | ||
88 | void ui_menu_create(const char *label) { | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | if(!current) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | } |
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 | // create menu |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | UiMenu *menu = malloc(sizeof(UiMenu)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
95 | mitem_set_id(&menu->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | menu->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | menu->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | menu->item.type = UI_MENU; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | menu->label = label; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | menu->items_begin = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | menu->items_end = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | menu->parent = NULL; |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
104 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
105 | menu->end = 0; |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | |
325 | 107 | if (cxListSize(current) == 0) { |
208 | 108 | add_menu(menu); |
109 | } | |
110 | else { | |
111 | add_item((UiMenuItemI*)menu); | |
112 | } | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
113 | uic_add_menu_to_stack(menu); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
116 | UIEXPORT void ui_menu_end(void) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
117 | cxListRemove(current, 0); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
118 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
119 | |
208 | 120 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
208 | 122 | void ui_menuitem_create(UiMenuItemArgs args) { |
123 | if (!current) { | |
124 | return; // error? | |
125 | } | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | |
208 | 127 | UiMenuItem* item = malloc(sizeof(UiMenuItem)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
128 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | item->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | item->item.type = UI_MENU_ITEM; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | |
208 | 133 | item->label = nl_strdup(args.label); |
134 | item->stockid = nl_strdup(args.stockid); | |
135 | item->icon = nl_strdup(args.icon); | |
136 | item->userdata = args.onclickdata; | |
137 | item->callback = args.onclick; | |
138 | item->groups = copy_groups(args.groups, &item->ngroups); | |
139 | ||
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | } |
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 | void ui_menuseparator() { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | if(!current) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | return; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | } |
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 | UiMenuItemI *item = malloc(sizeof(UiMenuItemI)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
149 | item->id[0] = 0; |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | item->prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | item->next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | item->type = UI_MENU_SEPARATOR; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
208 | 157 | void ui_menu_toggleitem_create(UiMenuToggleItemArgs args) { |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | if(!current) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | return; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | |
208 | 162 | UiMenuCheckItem *item = malloc(sizeof(UiMenuCheckItem)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
163 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | item->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | item->item.type = UI_MENU_CHECK_ITEM; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | |
208 | 168 | item->label = nl_strdup(args.label); |
169 | item->stockid = nl_strdup(args.stockid); | |
170 | item->icon = nl_strdup(args.icon); | |
171 | item->varname = nl_strdup(args.varname); | |
172 | item->userdata = args.onchangedata; | |
173 | item->callback = args.onchange; | |
174 | item->groups = copy_groups(args.groups, &item->ngroups); | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | |
208 | 179 | void ui_menu_radioitem_create(UiMenuToggleItemArgs args) { |
180 | if (!current) { | |
181 | return; | |
182 | } | |
183 | ||
184 | UiMenuCheckItem* item = malloc(sizeof(UiMenuCheckItem)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
185 | mitem_set_id(&item->item); |
208 | 186 | item->item.prev = NULL; |
187 | item->item.next = NULL; | |
188 | item->item.type = UI_MENU_CHECK_ITEM; | |
189 | ||
190 | item->label = nl_strdup(args.label); | |
191 | item->stockid = nl_strdup(args.stockid); | |
192 | item->icon = nl_strdup(args.icon); | |
193 | item->varname = nl_strdup(args.varname); | |
194 | item->userdata = args.onchangedata; | |
195 | item->callback = args.onchange; | |
196 | item->groups = copy_groups(args.groups, &item->ngroups); | |
197 | ||
198 | add_item((UiMenuItemI*)item); | |
199 | } | |
200 | ||
201 | void ui_menu_itemlist_create(UiMenuItemListArgs args) { | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | if(!current) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | return; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | |
208 | 206 | UiMenuItemList*item = malloc(sizeof(UiMenuItemList)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
207 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | item->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | 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
|
211 | item->getvalue = args.getvalue; |
208 | 212 | item->callback = args.onselect; |
213 | item->userdata = args.onselectdata; | |
214 | item->varname = nl_strdup(args.varname); | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | |
208 | 219 | void ui_menu_checkitemlist_create(UiMenuItemListArgs args) { |
220 | if (!current) { | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | return; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | } |
208 | 223 | |
224 | UiMenuItemList* item = malloc(sizeof(UiMenuItemList)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
225 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | item->item.next = NULL; |
229
a952760955b4
add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
228 | item->item.type = UI_MENU_CHECKITEM_LIST; |
208 | 229 | item->callback = args.onselect; |
230 | item->userdata = args.onselectdata; | |
231 | item->varname = nl_strdup(args.varname); | |
232 | ||
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | |
208 | 236 | void ui_menu_radioitemlist_create(UiMenuItemListArgs args) { |
237 | if (!current) { | |
238 | return; | |
239 | } | |
240 | ||
241 | UiMenuItemList* item = malloc(sizeof(UiMenuItemList)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
242 | mitem_set_id(&item->item); |
208 | 243 | item->item.prev = NULL; |
244 | item->item.next = NULL; | |
229
a952760955b4
add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
245 | item->item.type = UI_MENU_RADIOITEM_LIST; |
208 | 246 | item->callback = args.onselect; |
247 | item->userdata = args.onselectdata; | |
248 | item->varname = nl_strdup(args.varname); | |
249 | ||
250 | add_item((UiMenuItemI*)item); | |
251 | } | |
252 | ||
253 | ||
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
254 | 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
|
255 | if (!current) { |
e2b33055113f
fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
229
diff
changeset
|
256 | 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
|
257 | } |
e2b33055113f
fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
229
diff
changeset
|
258 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
259 | cxListInsert(current, 0, menu); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
260 | } |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | UiMenu* uic_get_menu_list(void) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | return menus_begin; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | } |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
265 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
266 | UIEXPORT void ui_menu_close(void) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
267 | UiMenu* menu = cxListAt(current, 0); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
268 | menu->end = 1; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
269 | } |
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 | UIEXPORT int ui_menu_is_open(void) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
272 | UiMenu* menu = cxListAt(current, 0); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
273 | if (menu->end) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
274 | ui_menu_end(); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
275 | return 0; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
276 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
277 | return 1; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
278 | } |