ui/gtk/menu.c

Wed, 02 Apr 2014 13:21:11 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 02 Apr 2014 13:21:11 +0200
changeset 19
f8f22eb0b575
parent 18
06be29a56f8b
child 21
012418e7dc90
permissions
-rw-r--r--

added menu accelerators (Cocoa)

0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1f419bd32da1 added files
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
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
31 #include <inttypes.h>
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "menu.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "toolkit.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../common/context.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "../ui/window.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
38 static UcxList *menus;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
39 static UcxList *current;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 void ui_menu(char *label) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 // free current menu hierarchy
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 ucx_list_free(current);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 // create menu
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 UiMenu *menu = malloc(sizeof(UiMenu));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 menu->item.add_to = (ui_menu_add_f)add_menu_widget;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 menu->label = label;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 menu->items = NULL;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 menu->parent = NULL;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 current = ucx_list_prepend(NULL, menu);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 menus = ucx_list_append(menus, menu);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 void ui_submenu(char *label) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 UiMenu *menu = malloc(sizeof(UiMenu));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 menu->item.add_to = (ui_menu_add_f)add_menu_widget;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 menu->label = label;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 menu->items = NULL;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 menu->parent = NULL;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 // add submenu to current menu
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 UiMenu *cm = current->data;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 cm->items = ucx_list_append(cm->items, menu);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 // set the submenu to current menu
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 current = ucx_list_prepend(current, menu);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 void ui_submenu_end() {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 if(ucx_list_size(current) < 2) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 return;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 current = ucx_list_remove(current, current);
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
79 //UcxList *c = current;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 void ui_menuitem(char *label, ui_callback f, void *userdata) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 if(!current) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 return;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 UiMenuItem *item = malloc(sizeof(UiMenuItem));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 item->item.add_to = (ui_menu_add_f)add_menuitem_widget;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 item->label = label;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 item->userdata = userdata;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 item->callback = f;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 UiMenu *cm = current->data;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 cm->items = ucx_list_append(cm->items, item);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
98 void ui_menuitem_st(char *stockid, ui_callback f, void *userdata) {
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
99 if(!current) {
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
100 return;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
101 }
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
102
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
103 UiStMenuItem *item = malloc(sizeof(UiStMenuItem));
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
104 item->item.add_to = (ui_menu_add_f)add_menuitem_st_widget;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
105
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
106 item->stockid = stockid;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
107 item->userdata = userdata;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
108 item->callback = f;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
109
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
110 UiMenu *cm = current->data;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
111 cm->items = ucx_list_append(cm->items, item);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
112 }
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
113
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 void ui_menuseparator() {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 if(!current) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 return;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 UiMenuItemI *item = malloc(sizeof(UiMenuItemI));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 item->add_to = (ui_menu_add_f)add_menuseparator_widget;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 UiMenu *cm = current->data;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 cm->items = ucx_list_append(cm->items, item);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 void ui_checkitem(char *label, ui_callback f, void *userdata) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 if(!current) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 return;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 UiCheckItem *item = malloc(sizeof(UiCheckItem));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 item->item.add_to = (ui_menu_add_f)add_checkitem_widget;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 item->label = label;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 item->callback = f;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 item->userdata = userdata;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 UiMenu *cm = current->data;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 cm->items = ucx_list_append(cm->items, item);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 void ui_checkitem_nv(char *label, char *vname) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 if(!current) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 return;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 UiCheckItemNV *item = malloc(sizeof(UiCheckItemNV));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 item->item.add_to = (ui_menu_add_f)add_checkitemnv_widget;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 item->varname = vname;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 item->label = label;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 UiMenu *cm = current->data;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 cm->items = ucx_list_append(cm->items, item);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
155 void ui_menuitem_list(UiList *items, ui_callback f, void *userdata) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
156 if(!current) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
157 return;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
158 }
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
159
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
160 UiMenuItemList *item = malloc(sizeof(UiMenuItemList));
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
161 item->item.add_to = (ui_menu_add_f)add_menuitem_list_widget;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
162 item->callback = f;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
163 item->userdata = userdata;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
164 item->list = items;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
165
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
166 UiMenu *cm = current->data;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
167 cm->items = ucx_list_append(cm->items, item);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
168 }
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
169
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 // private menu functions
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 GtkWidget *ui_create_menubar(UiObject *obj) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 if(menus == NULL) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 return NULL;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 GtkWidget *mb = gtk_menu_bar_new();
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 UcxList *ls = menus;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 while(ls) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 UiMenu *menu = ls->data;
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
181 menu->item.add_to(mb, 0, &menu->item, obj);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 ls = ls->next;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 return mb;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
189 void add_menu_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj) {
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 UiMenu *menu = (UiMenu*)item;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 GtkWidget *menu_widget = gtk_menu_new();
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 GtkWidget *menu_item = gtk_menu_item_new_with_label(menu->label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu_widget);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 UcxList *ls = menu->items;
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
197 int index = 0;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 while(ls) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 UiMenuItemI *i = ls->data;
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
200 i->add_to(menu_widget, index, i, obj);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 ls = ls->next;
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
203 index++;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 gtk_menu_shell_append(GTK_MENU_SHELL(parent), menu_item);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
209 void add_menuitem_widget(GtkWidget *parent, int index, UiMenuItemI *item, UiObject *obj) {
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 UiMenuItem *i = (UiMenuItem*)item;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 //GtkWidget *widget = gtk_menu_item_new_with_label(i->title);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 GtkWidget *widget = gtk_menu_item_new_with_mnemonic(i->label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 if(i->callback != NULL) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 UiEventData *event = malloc(sizeof(UiEventData));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 event->obj = obj;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 event->user_data = i->userdata;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 event->callback = i->callback;
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
220 event->value = 0;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 g_signal_connect(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 widget,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 "activate",
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 G_CALLBACK(ui_menu_event_wrapper),
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 event);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 void add_menuitem_st_widget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 GtkWidget *parent,
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
234 int index,
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 UiMenuItemI *item,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 UiObject *obj)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 UiStMenuItem *i = (UiStMenuItem*)item;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
240 GtkWidget *widget = gtk_image_menu_item_new_from_stock(i->stockid, obj->ctx->accel_group);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 if(i->callback != NULL) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 UiEventData *event = malloc(sizeof(UiEventData));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 event->obj = obj;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 event->user_data = i->userdata;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 event->callback = i->callback;
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
247 event->value = 0;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 g_signal_connect(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 widget,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 "activate",
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 G_CALLBACK(ui_menu_event_wrapper),
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 event);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 void add_menuseparator_widget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 GtkWidget *parent,
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
261 int index,
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 UiMenuItemI *item,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 UiObject *obj)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 gtk_menu_shell_append(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 GTK_MENU_SHELL(parent),
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 gtk_separator_menu_item_new());
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
270 void add_checkitem_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) {
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 UiCheckItem *ci = (UiCheckItem*)item;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 gtk_menu_shell_append(GTK_MENU_SHELL(p), widget);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 if(ci->callback) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 UiEventData *event = malloc(sizeof(UiEventData));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 event->obj = obj;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 event->user_data = ci->userdata;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 event->callback = ci->callback;
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
280 event->value = 0;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 g_signal_connect(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 widget,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 "toggled",
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 G_CALLBACK(ui_menu_event_toggled),
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 event);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
290 void add_checkitemnv_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) {
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 UiCheckItemNV *ci = (UiCheckItemNV*)item;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 GtkWidget *widget = gtk_check_menu_item_new_with_mnemonic(ci->label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 gtk_menu_shell_append(GTK_MENU_SHELL(p), widget);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
295 UiVar *var = uic_connect_var(obj->ctx, ci->varname, UI_VAR_INTEGER);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
296 if(var) {
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 UiInteger *value = var->value;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 value->obj = widget;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 value->get = ui_checkitem_get;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 value->set = ui_checkitem_set;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 value = 0;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 } else {
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
303 // TODO: error
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
307 void add_menuitem_list_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
308 UiMenuItemList *il = (UiMenuItemList*)item;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
309 UcxMempool *mp = obj->ctx->mempool;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
310
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
311 UiActiveMenuItemList *ls = ucx_mempool_malloc(
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
312 mp,
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
313 sizeof(UiActiveMenuItemList));
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
314
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
315 ls->object = obj;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
316 ls->menu = GTK_MENU_SHELL(p);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
317 ls->index = index;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
318 ls->oldcount = 0;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
319 ls->list = il->list;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
320 ls->callback = il->callback;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
321 ls->userdata = il->userdata;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
322
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
323 ls->list->observers = ui_add_observer(
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
324 ls->list->observers,
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
325 (ui_callback)ui_update_menuitem_list,
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
326 ls);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
327
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
328 ui_update_menuitem_list(NULL, ls);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
329 }
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
332 void ui_update_menuitem_list(UiEvent *event, UiActiveMenuItemList *list) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
333 // remove old items
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
334 if(list->oldcount > 0) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
335 int i = 0;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
336 GList *mi = gtk_container_get_children(GTK_CONTAINER(list->menu));
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
337 while(mi) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
338 if(i >= list->index && i < list->index + list->oldcount) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
339 gtk_container_remove(GTK_CONTAINER(list->menu), mi->data);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
340 }
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
341 mi = mi->next;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
342 i++;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
343 }
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
344 }
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
345
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
346 char *str = ui_list_first(list->list);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
347 if(str) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
348 GtkWidget *widget = gtk_separator_menu_item_new();
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
349 gtk_menu_shell_insert(list->menu, widget, list->index);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
350 gtk_widget_show(widget);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
351 }
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
352 int i = 1;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
353 while(str) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
354 GtkWidget *widget = gtk_menu_item_new_with_label(str);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
355 gtk_menu_shell_insert(list->menu, widget, list->index + i);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
356 gtk_widget_show(widget);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
357
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
358 if(list->callback) {
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
359 // TODO: use mempool
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
360 UiEventData *event = malloc(sizeof(UiEventData));
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
361 event->obj = list->object;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
362 event->user_data = list->userdata;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
363 event->callback = list->callback;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
364 event->value = i - 1;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
365
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
366 g_signal_connect(
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
367 widget,
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
368 "activate",
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
369 G_CALLBACK(ui_menu_event_wrapper),
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
370 event);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
371 }
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
372
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
373 str = ui_list_next(list->list);
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
374 i++;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
375 }
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
376
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
377 list->oldcount = i;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
378 }
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
379
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 void ui_menu_event_wrapper(GtkMenuItem *item, UiEventData *event) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 UiEvent evt;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382 evt.obj = event->obj;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383 evt.window = event->obj->window;
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
384 evt.document = event->obj->document;
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
385 evt.eventdata = NULL;
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
386 evt.intval = event->value;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 event->callback(&evt, event->user_data);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
388 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390 void ui_menu_event_toggled(GtkCheckMenuItem *ci, UiEventData *event) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 UiEvent evt;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 evt.obj = event->obj;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393 evt.window = event->obj->window;
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
394 evt.document = event->obj->document;
16
a499c8a72c15 added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
395 evt.eventdata = NULL;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
396 evt.intval = gtk_check_menu_item_get_active(ci);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
397 event->callback(&evt, event->user_data);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400 int ui_checkitem_get(UiInteger *i) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401 int state = gtk_check_menu_item_get_active(i->obj);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402 i->value = state;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 return state;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 void ui_checkitem_set(UiInteger *i, int value) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 i->value = value;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
408 gtk_check_menu_item_set_active(i->obj, value);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409 }

mercurial