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