Wed, 04 Dec 2024 08:55:49 +0100
add first working cocoa code
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> |
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
33 | #include <stdio.h> |
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
175
diff
changeset
|
34 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <cx/linked_list.h> |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include <cx/array_list.h> |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
38 | |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
39 | static UiMenuBuilder *current_builder; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
40 | static UiMenuBuilder global_builder; |
175
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 | |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
44 | void uic_menu_init(void) { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
45 | global_builder.current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
46 | current_builder = &global_builder; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
47 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
48 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | static void add_menu(UiMenu *menu) { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | cx_linked_list_add( |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
51 | (void**)¤t_builder->menus_begin, |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
52 | (void**)¤t_builder->menus_end, |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | offsetof(UiMenu, item.prev), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | offsetof(UiMenu, item.next), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | menu); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | static void add_item(UiMenuItemI *item) { |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
59 | UiMenu *menu = cxListAt(current_builder->current, 0); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | cx_linked_list_add( |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | (void**)&menu->items_begin, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | (void**)&menu->items_end, |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | offsetof(UiMenu, item.prev), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | offsetof(UiMenu, item.next), |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
68 | 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
|
69 | 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
|
70 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
71 | |
208 | 72 | static char* nl_strdup(const char* s) { |
73 | return s ? strdup(s) : NULL; | |
74 | } | |
75 | ||
367
1c3af8e31d8e
fix toolbar item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
76 | int* uic_copy_groups(const int* groups, size_t *ngroups) { |
208 | 77 | *ngroups = 0; |
78 | if (!groups) { | |
79 | return NULL; | |
80 | } | |
81 | ||
82 | size_t n; | |
83 | for (n = 0; groups[n] > -1; n++) { } | |
84 | ||
85 | if (ngroups > 0) { | |
393
3099bf907e21
fix missing terminator in uic_copy_groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
86 | int* newarray = calloc(n+1, sizeof(int)); |
364
eaec7c62ce41
implement menu item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
325
diff
changeset
|
87 | memcpy(newarray, groups, n * sizeof(int)); |
393
3099bf907e21
fix missing terminator in uic_copy_groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
88 | newarray[n] = -1; |
208 | 89 | *ngroups = n; |
90 | return newarray; | |
91 | } | |
92 | return NULL; | |
93 | } | |
94 | ||
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
95 | void ui_menu_create(const char *label) { |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | // create menu |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | UiMenu *menu = malloc(sizeof(UiMenu)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
98 | mitem_set_id(&menu->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | menu->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | menu->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | menu->item.type = UI_MENU; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | menu->label = label; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | menu->items_begin = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | menu->items_end = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | menu->parent = NULL; |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
107 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
108 | menu->end = 0; |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
110 | if (cxListSize(current_builder->current) == 0) { |
208 | 111 | add_menu(menu); |
112 | } | |
113 | else { | |
114 | add_item((UiMenuItemI*)menu); | |
115 | } | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
116 | uic_add_menu_to_stack(menu); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
119 | UIEXPORT void ui_menu_end(void) { |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
120 | cxListRemove(current_builder->current, 0); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
121 | if(cxListSize(current_builder->current) == 0) { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
122 | current_builder = &global_builder; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
123 | } |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
124 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
125 | |
208 | 126 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
208 | 128 | void ui_menuitem_create(UiMenuItemArgs args) { |
129 | UiMenuItem* item = malloc(sizeof(UiMenuItem)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
130 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | item->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | item->item.type = UI_MENU_ITEM; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | |
208 | 135 | item->label = nl_strdup(args.label); |
136 | item->stockid = nl_strdup(args.stockid); | |
137 | item->icon = nl_strdup(args.icon); | |
138 | item->userdata = args.onclickdata; | |
139 | item->callback = args.onclick; | |
367
1c3af8e31d8e
fix toolbar item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
140 | item->groups = uic_copy_groups(args.groups, &item->ngroups); |
208 | 141 | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | add_item((UiMenuItemI*)item); |
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 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | void ui_menuseparator() { |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | UiMenuItemI *item = malloc(sizeof(UiMenuItemI)); |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
147 | item->id[0] = 0; |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | item->prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | item->next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | item->type = UI_MENU_SEPARATOR; |
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 | add_item((UiMenuItemI*)item); |
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 | |
208 | 155 | void ui_menu_toggleitem_create(UiMenuToggleItemArgs args) { |
156 | UiMenuCheckItem *item = malloc(sizeof(UiMenuCheckItem)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
157 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | item->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | item->item.type = UI_MENU_CHECK_ITEM; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | |
208 | 162 | item->label = nl_strdup(args.label); |
163 | item->stockid = nl_strdup(args.stockid); | |
164 | item->icon = nl_strdup(args.icon); | |
165 | item->varname = nl_strdup(args.varname); | |
166 | item->userdata = args.onchangedata; | |
167 | item->callback = args.onchange; | |
367
1c3af8e31d8e
fix toolbar item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
168 | 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
|
169 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | add_item((UiMenuItemI*)item); |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | } |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | |
208 | 173 | void ui_menu_radioitem_create(UiMenuToggleItemArgs args) { |
174 | UiMenuCheckItem* item = malloc(sizeof(UiMenuCheckItem)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
175 | mitem_set_id(&item->item); |
208 | 176 | item->item.prev = NULL; |
177 | item->item.next = NULL; | |
178 | item->item.type = UI_MENU_CHECK_ITEM; | |
179 | ||
180 | item->label = nl_strdup(args.label); | |
181 | item->stockid = nl_strdup(args.stockid); | |
182 | item->icon = nl_strdup(args.icon); | |
183 | item->varname = nl_strdup(args.varname); | |
184 | item->userdata = args.onchangedata; | |
185 | item->callback = args.onchange; | |
367
1c3af8e31d8e
fix toolbar item groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
186 | item->groups = uic_copy_groups(args.groups, &item->ngroups); |
208 | 187 | |
188 | add_item((UiMenuItemI*)item); | |
189 | } | |
190 | ||
191 | void ui_menu_itemlist_create(UiMenuItemListArgs args) { | |
192 | UiMenuItemList*item = malloc(sizeof(UiMenuItemList)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
193 | mitem_set_id(&item->item); |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | item->item.prev = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | item->item.next = NULL; |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | 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
|
197 | item->getvalue = args.getvalue; |
208 | 198 | item->callback = args.onselect; |
199 | item->userdata = args.onselectdata; | |
200 | item->varname = nl_strdup(args.varname); | |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | |
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | add_item((UiMenuItemI*)item); |
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 | |
208 | 205 | void ui_menu_checkitemlist_create(UiMenuItemListArgs args) { |
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; |
229
a952760955b4
add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
210 | item->item.type = UI_MENU_CHECKITEM_LIST; |
208 | 211 | item->callback = args.onselect; |
212 | item->userdata = args.onselectdata; | |
213 | item->varname = nl_strdup(args.varname); | |
214 | ||
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | add_item((UiMenuItemI*)item); |
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 | |
208 | 218 | void ui_menu_radioitemlist_create(UiMenuItemListArgs args) { |
219 | UiMenuItemList* item = malloc(sizeof(UiMenuItemList)); | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
220 | mitem_set_id(&item->item); |
208 | 221 | item->item.prev = NULL; |
222 | item->item.next = NULL; | |
229
a952760955b4
add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
223 | item->item.type = UI_MENU_RADIOITEM_LIST; |
208 | 224 | item->callback = args.onselect; |
225 | item->userdata = args.onselectdata; | |
226 | item->varname = nl_strdup(args.varname); | |
227 | ||
228 | add_item((UiMenuItemI*)item); | |
229 | } | |
230 | ||
231 | ||
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
232 | void uic_add_menu_to_stack(UiMenu* menu) { |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
233 | cxListInsert(current_builder->current, 0, menu); |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
234 | } |
175
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 | UiMenu* uic_get_menu_list(void) { |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
237 | return current_builder->menus_begin; |
175
2cb06c231057
move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | } |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
239 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
240 | UIEXPORT void ui_menu_close(void) { |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
241 | UiMenu* menu = cxListAt(current_builder->current, 0); |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
242 | menu->end = 1; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
243 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
244 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
245 | UIEXPORT int ui_menu_is_open(void) { |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
246 | UiMenu* menu = cxListAt(current_builder->current, 0); |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
247 | if (menu->end) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
248 | ui_menu_end(); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
249 | return 0; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
250 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
251 | return 1; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
252 | } |
388
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
253 | |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
254 | |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
255 | void ui_contextmenu_builder(UiMenuBuilder **out_builder) { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
256 | UiMenuBuilder *builder = malloc(sizeof(UiMenuBuilder)); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
257 | builder->menus_begin = NULL; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
258 | builder->menus_end = NULL; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
259 | builder->current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
260 | current_builder = builder; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
261 | *out_builder = builder; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
262 | |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
263 | ui_menu_create(NULL); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
264 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
265 | |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
266 | |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
267 | |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
268 | static void free_menuitem(UiMenuItemI *item) { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
269 | switch(item->type) { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
270 | default: break; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
271 | case UI_MENU: { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
272 | UiMenu *menu = (UiMenu*)item; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
273 | UiMenuItemI *m = menu->items_begin; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
274 | while(m) { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
275 | UiMenuItemI *next = m->next; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
276 | free_menuitem(m); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
277 | m = next; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
278 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
279 | break; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
280 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
281 | case UI_MENU_ITEM: { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
282 | UiMenuItem *i = (UiMenuItem*)item; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
283 | free(i->groups); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
284 | free(i->label); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
285 | free(i->stockid); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
286 | free(i->icon); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
287 | break; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
288 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
289 | case UI_MENU_CHECK_ITEM: { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
290 | UiMenuCheckItem *i = (UiMenuCheckItem*)item; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
291 | free(i->groups); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
292 | free(i->label); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
293 | free(i->stockid); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
294 | free(i->icon); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
295 | free(i->varname); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
296 | break; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
297 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
298 | case UI_MENU_RADIO_ITEM: { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
299 | UiMenuRadioItem *i = (UiMenuRadioItem*)item; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
300 | free(i->groups); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
301 | free(i->label); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
302 | free(i->stockid); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
303 | free(i->icon); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
304 | //free(i->varname); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
305 | break; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
306 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
307 | case UI_MENU_ITEM_LIST: { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
308 | break; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
309 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
310 | case UI_MENU_CHECKITEM_LIST: { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
311 | break; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
312 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
313 | case UI_MENU_RADIOITEM_LIST: { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
314 | break; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
315 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
316 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
317 | |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
318 | free(item); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
319 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
320 | |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
321 | void ui_menubuilder_free(UiMenuBuilder *builder) { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
322 | UiMenuItemI *m = &builder->menus_begin->item; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
323 | while(m) { |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
324 | UiMenuItemI *next = m->next; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
325 | free_menuitem(m); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
326 | m = next; |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
327 | } |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
328 | cxListDestroy(builder->current); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
329 | free(builder); |
473c03f85197
add menu builder API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
330 | } |