ui/win32/menu.c

Thu, 08 Jan 2026 18:06:04 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 08 Jan 2026 18:06:04 +0100
changeset 118
6d0da97105d8
parent 115
e57ca2747782
permissions
-rw-r--r--

update to ucx version 4.0

115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
e57ca2747782 fix build with newest toolkit version
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
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "menu.h"
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
118
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
31 #include <cx/array_list.h>
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
32
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 static ui_menu_add_f createMenuItem[] = {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 /* UI_MENU */ ui_add_menu,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 /* UI_MENU_ITEM */ ui_add_menu_item,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 /* UI_MENU_CHECK_ITEM */ ui_add_menu_checkitem,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 /* UI_MENU_RADIO_ITEM */ ui_add_menu_radioitem,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 /* UI_MENU_ITEM_LIST */ ui_add_menu_list,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 /* UI_MENU_CHECKITEM_LIST */ ui_add_menu_checklist,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 /* UI_MENU_RADIOITEM_LIST */ ui_add_menu_radiolist,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 /* UI_MENU_SEPARATOR */ ui_add_menu_separator
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 };
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 HMENU ui_create_main_menu(UiObject *obj) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 UiMenu *menu = uic_get_menu_list();
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 if (!menu) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 return NULL;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 HMENU hMenu = CreateMenu();
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 ui_add_menu(hMenu, 0, &menu->item, obj);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 return hMenu;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 void ui_add_menu(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 UiMenu *menu = (UiMenu*)item;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 HMENU hMenu = CreatePopupMenu();
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 AppendMenu(parent, MF_POPUP, (UINT_PTR)hMenu, menu->label);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 int i = 0;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 UiMenuItemI *child = menu->items_begin;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 while (child) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 createMenuItem[child->type](hMenu, i++, child, obj);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 child = child->next;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
118
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
71 static void menu_item_clicked(UiObject *obj, uint64_t id, UiMenuItem *item) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
72 UiEvent event;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
73 event.obj = obj;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
74 event.window = obj->window;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
75 event.document = obj->ctx->document;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
76 event.eventdata = NULL;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
77 event.eventdatatype = 0;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
78 event.intval = 0;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
79 event.set = 0;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
80 if (item->callback) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
81 item->callback(&event, item->userdata);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
82 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
83 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
84
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 void ui_add_menu_item(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) {
118
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
86 uint64_t id = ++obj->ctx->command_id_counter;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
87
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 UiMenuItem *i = (UiMenuItem*)item;
118
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
89 AppendMenu(parent, MF_STRING, id, i->label);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
90
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
91 UiCommand cmd;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
92 cmd.callback = (ui_command_func)menu_item_clicked;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
93 cmd.userdata = i;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
94 cxMapPut(obj->ctx->command_map, id, &cmd);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
95 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
96
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
97 static void menu_stateitem_update(UiStateMenuItem *item) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
98 MENUITEMINFO mi = { 0 };
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
99 mi.cbSize = sizeof(mi);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
100 mi.fMask = MIIM_STATE;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
101 mi.fState = item->state ? MFS_CHECKED : MFS_UNCHECKED;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
102 SetMenuItemInfo(item->menu, item->id, FALSE, &mi);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
103 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
104
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
105 static void menu_checkitem_clicked(UiObject *obj, uint64_t id, UiStateMenuItem *item) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
106 item->state = !item->state;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
107 menu_stateitem_update(item);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
108
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
109 UiEvent event;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
110 event.obj = obj;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
111 event.window = obj->window;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
112 event.document = obj->ctx->document;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
113 event.eventdata = NULL;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
114 event.eventdatatype = 0;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
115 event.intval = 0;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
116 event.set = 0;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
117 if (item->onchange) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
118 item->onchange(&event, item->userdata);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
119 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
120
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
121 if (item->var) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
122 UiInteger *i = item->var->value;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
123 ui_notify_evt(i->observers, &event);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
124 }
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 void ui_add_menu_checkitem(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) {
118
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
128 uint64_t id = ++obj->ctx->command_id_counter;
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129
118
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
130 UiMenuCheckItem *i = (UiMenuCheckItem*)item;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
131 AppendMenu(parent, MF_STRING, id, i->label);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
132
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
133 // create an UiStateMenuItem with the same lifetime as the UiObject
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
134 UiStateMenuItem *sitem = ui_malloc(obj->ctx, sizeof(UiStateMenuItem));
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
135 memset(sitem, 0, sizeof(UiStateMenuItem));
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
136 sitem->obj = obj;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
137 sitem->menu = parent;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
138 sitem->id = id;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
139 sitem->onchange = i->callback;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
140 sitem->userdata = i->userdata;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
141 sitem->var = uic_widget_var(obj->ctx, obj->ctx, NULL, i->varname, UI_VAR_INTEGER);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
142 // bind to var
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
143 if (sitem->var) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
144 UiInteger *v = sitem->var->value;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
145 sitem->state = v->value != 0;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
146 v->obj = sitem;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
147 v->get = ui_checkitem_get;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
148 v->set = ui_checkitem_set;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
149 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
150
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
151 // register command id
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
152 UiCommand cmd;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
153 cmd.callback = (ui_command_func)menu_checkitem_clicked;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
154 cmd.userdata = sitem;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
155 cxMapPut(obj->ctx->command_map, id, &cmd);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
156
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
157 menu_stateitem_update(sitem);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
158 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
159
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
160 int64_t ui_checkitem_get(UiInteger *i) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
161 return i->value;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
162 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
163
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
164 void ui_checkitem_set(UiInteger *i, int64_t value) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
165 i->value = value;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
166 menu_stateitem_update(i->obj);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
167 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
168
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
169 static void menu_radioitem_clicked(UiObject *obj, uint64_t id, UiStateMenuItem *item) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
170 UiInteger *i = item->var->value; // UiVar is always not NULL for radio items
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
171 ui_set(i, item->index+1);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
172
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
173 UiEvent event;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
174 event.obj = obj;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
175 event.window = obj->window;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
176 event.document = obj->ctx->document;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
177 event.eventdata = i;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
178 event.eventdatatype = UI_EVENT_DATA_INTEGER_VALUE;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
179 event.intval = item->state;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
180 event.set = ui_get_setop();
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
181
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
182 if (item->onchange) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
183 item->onchange(&event, item->userdata);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
184 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
185
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
186 event.intval = (int)ui_get(i);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
187 ui_notify_evt(i->observers, &event);
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 void ui_add_menu_radioitem(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) {
118
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
191 uint64_t id = ++obj->ctx->command_id_counter;
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192
118
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
193 UiMenuRadioItem *i = (UiMenuRadioItem*)item;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
194 AppendMenu(parent, MF_STRING, id, i->label);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
195
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
196 UiVar *var = uic_widget_var(obj->ctx, obj->ctx, NULL, i->varname, UI_VAR_INTEGER);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
197 if (!var) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
198 return; // radio item without var is useless
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
199 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
200
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
201 UiInteger *v = var->value;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
202 CxList *group = v->obj;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
203 if (!group) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
204 // first radio button in this group
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
205 group = cxArrayListCreate(obj->ctx->allocator, sizeof(UiStateMenuItem), 4);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
206 v->obj = group;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
207 v->get = ui_radioitem_get;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
208 v->set = ui_radioitem_set;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
209 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
210
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
211 UiStateMenuItem sitem = { 0 };
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
212 sitem.obj = obj;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
213 sitem.menu = parent;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
214 sitem.id = id;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
215 sitem.onchange = i->callback;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
216 sitem.userdata = i->userdata;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
217 sitem.var = var;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
218 sitem.index = (int)cxListSize(group);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
219 cxListAdd(group, &sitem);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
220
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
221 if (v->value == sitem.index+1) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
222 sitem.state = 1;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
223 menu_stateitem_update(&sitem);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
224 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
225
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
226
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
227 UiStateMenuItem *sitem_ptr = cxListAt(group, sitem.index);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
228 // register command id
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
229 UiCommand cmd;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
230 cmd.callback = (ui_command_func)menu_radioitem_clicked;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
231 cmd.userdata = sitem_ptr;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
232 cxMapPut(obj->ctx->command_map, id, &cmd);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
233 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
234
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
235 int64_t ui_radioitem_get(UiInteger *i) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
236 return i->value;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
237 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
238
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
239 void ui_radioitem_set(UiInteger *i, int64_t value) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
240 CxList *group = i->obj;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
241 // de-select all items
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
242 CxIterator it = cxListIterator(group);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
243 cx_foreach(UiStateMenuItem *, item, it) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
244 if (item->state) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
245 item->state = FALSE;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
246 menu_stateitem_update(item);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
247 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
248 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
249
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
250 if (value > 0) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
251 UiStateMenuItem *item = cxListAt(group, value-1);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
252 if (item) {
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
253 item->state = TRUE;
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
254 menu_stateitem_update(item);
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
255 }
6d0da97105d8 update to ucx version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
256 }
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 void ui_add_menu_list(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 void ui_add_menu_checklist(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 void ui_add_menu_radiolist(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 void ui_add_menu_separator(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 }

mercurial