ui/common/menu.c

Mon, 22 May 2023 19:44:27 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 22 May 2023 19:44:27 +0200
branch
newapi
changeset 175
2cb06c231057
child 176
bc63cb601f6d
permissions
-rw-r--r--

move some menu code to common

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
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <cx/linked_list.h>
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <cx/array_list.h>
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 static UiMenu *menus_begin;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 static UiMenu *menus_end;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 static CxList *current;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 static void add_menu(UiMenu *menu) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 cx_linked_list_add(
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 (void**)&menus_begin,
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 (void**)&menus_end,
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 offsetof(UiMenu, item.prev),
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 offsetof(UiMenu, item.next),
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 menu);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 static void add_item(UiMenuItemI *item) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 UiMenu *menu = cxListAt(current, 0);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 cx_linked_list_add(
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 (void**)&menu->items_begin,
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 (void**)&menu->items_end,
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 offsetof(UiMenu, item.prev),
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 offsetof(UiMenu, item.next),
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 item);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 }
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 void ui_menu(char *label) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 if(!current) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 } else {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 // free current menu hierarchy
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 cxListClear(current);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 // create menu
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 UiMenu *menu = malloc(sizeof(UiMenu));
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 menu->item.prev = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 menu->item.next = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 menu->item.type = UI_MENU;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 menu->label = label;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 menu->items_begin = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 menu->items_end = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 menu->parent = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 add_menu(menu);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 cxListAdd(current, menu);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 void ui_submenu(char *label) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 UiMenu *menu = malloc(sizeof(UiMenu));
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 menu->item.prev = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 menu->item.next = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 menu->item.type = UI_MENU_SUBMENU;
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 menu->label = label;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 menu->items_begin = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 menu->items_end = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 menu->parent = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 // add submenu to current menu
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 add_item((UiMenuItemI*)menu);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 // set the submenu to current menu
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 cxListInsert(current, 0, menu);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 void ui_submenu_end() {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 if(current->size < 2) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 return;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 cxListRemove(current, 0);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 void ui_menuitem(char *label, ui_callback f, void *userdata) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 ui_menuitem_gr(label, f, userdata, -1);
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
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 void ui_menuitem_st(char *stockid, ui_callback f, void *userdata) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 ui_menuitem_stgr(stockid, f, userdata, -1);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 void ui_menuitem_gr(char *label, ui_callback f, void *userdata, ...) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 if(!current) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 return;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
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 UiMenuItem *item = malloc(sizeof(UiMenuItem));
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 item->item.prev = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 item->item.next = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 item->item.type = UI_MENU_ITEM;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 item->label = label;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 item->userdata = userdata;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 item->callback = f;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 item->groups = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 // add groups
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 va_list ap;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 va_start(ap, userdata);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 int group;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 while((group = va_arg(ap, int)) != -1) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 if(!item->groups) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 item->groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 8);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 cxListAdd(item->groups, &group);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 va_end(ap);
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 add_item((UiMenuItemI*)item);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 void ui_menuitem_stgr(char *stockid, ui_callback f, void *userdata, ...) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 if(!current) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 return;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 UiStMenuItem *item = malloc(sizeof(UiStMenuItem));
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 item->item.prev = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 item->item.next = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 item->item.type = UI_MENU_STOCK_ITEM;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 item->stockid = stockid;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 item->userdata = userdata;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 item->callback = f;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 item->groups = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 // add groups
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 va_list ap;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 va_start(ap, userdata);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 int group;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 while((group = va_arg(ap, int)) != -1) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 if(!item->groups) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 item->groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 8);
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 cxListAdd(item->groups, &group);
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 va_end(ap);
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
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 void ui_menuseparator() {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 if(!current) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 return;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 UiMenuItemI *item = malloc(sizeof(UiMenuItemI));
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 item->prev = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 item->next = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 item->type = UI_MENU_SEPARATOR;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 add_item((UiMenuItemI*)item);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 void ui_checkitem(char *label, ui_callback f, void *userdata) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 if(!current) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 return;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 UiCheckItem *item = malloc(sizeof(UiCheckItem));
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 item->item.prev = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 item->item.next = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 item->item.type = UI_MENU_CHECK_ITEM;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 item->label = label;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 item->callback = f;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 item->userdata = userdata;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 add_item((UiMenuItemI*)item);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 }
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 void ui_checkitem_nv(char *label, char *vname) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 if(!current) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 return;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 UiCheckItemNV *item = malloc(sizeof(UiCheckItemNV));
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 item->item.prev = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 item->item.next = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 item->item.type = UI_MENU_CHECK_ITEM_NV;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 item->varname = vname;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 item->label = label;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 add_item((UiMenuItemI*)item);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 void ui_menuitem_list(UiList *items, ui_callback f, void *userdata) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 if(!current) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 return;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 }
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 UiMenuItemList *item = malloc(sizeof(UiMenuItemList));
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 item->item.prev = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 item->item.next = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 item->item.type = UI_MENU_ITEM_LIST;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 item->callback = f;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 item->userdata = userdata;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 item->list = items;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 add_item((UiMenuItemI*)item);
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 void ui_menuitem_list_nv(const char *varname, ui_callback f, void *userdata) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 if(!current) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 return;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 }
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 UiMenuItemListNV *item = malloc(sizeof(UiMenuItemListNV));
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 item->item.prev = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 item->item.next = NULL;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 item->item.type = UI_MENU_ITEM_LIST;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 item->callback = f;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 item->userdata = userdata;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 item->varname = varname;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 add_item((UiMenuItemI*)item);
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
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 UiMenu* uic_get_menu_list(void) {
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 return menus_begin;
2cb06c231057 move some menu code to common
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 }

mercurial