ui/gtk/toolbar.c

Fri, 11 Dec 2020 11:46:19 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 11 Dec 2020 11:46:19 +0100
changeset 3
c04433993fbb
parent 2
ea89bbb0c4c8
permissions
-rw-r--r--

add drawingarea and textarea group

0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
804d8803eade add existing toolkit source
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
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "toolbar.h"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "button.h"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "image.h"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "tree.h"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include <ucx/mempool.h>
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "../common/context.h"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 static UcxMap *toolbar_items;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 static UcxList *defaults;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 void ui_toolbar_init() {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 toolbar_items = ucx_map_new(16);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 void ui_toolitem(char *name, char *label, ui_callback f, void *udata) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 ui_toolitem_img(name, label, NULL, f, udata);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *userdata) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 ui_toolitem_stgr(name, stockid, f, userdata, -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 void ui_toolitem_sti(char *name, char *stockid, ui_callback f, void *userdata) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 ui_toolitem_stgri(name, stockid, f, userdata, -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 void ui_toolitem_stgr(char *name, char *stockid, ui_callback f, void *userdata, ...) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 va_list ap;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 va_start(ap, userdata);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 ui_toolitem_vstgr(name, stockid, 0, f, userdata, ap);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 va_end(ap);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 void ui_toolitem_stgri(char *name, char *stockid, ui_callback f, void *userdata, ...) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 va_list ap;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 va_start(ap, userdata);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 ui_toolitem_vstgr(name, stockid, 1, f, userdata, ap);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 va_end(ap);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 void ui_toolitem_img(char *name, char *label, char *img, ui_callback f, void *udata) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 UiToolItem *item = malloc(sizeof(UiToolItem));
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 item->item.add_to = (ui_toolbar_add_f)add_toolitem_widget;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 item->label = label;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 item->image = img;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 item->callback = f;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 item->userdata = udata;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 item->isimportant = 0;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 item->groups = NULL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 ucx_map_cstr_put(toolbar_items, name, item);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 void ui_toolitem_vstgr(
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 char *name,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 char *stockid,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 int isimportant,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 ui_callback f,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 void *userdata,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 va_list ap)
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 UiStToolItem *item = malloc(sizeof(UiStToolItem));
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 item->item.add_to = (ui_toolbar_add_f)add_toolitem_st_widget;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 item->stockid = stockid;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 item->callback = f;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 item->userdata = userdata;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 item->groups = NULL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 item->isimportant = isimportant;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 // add groups
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 int group;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 while((group = va_arg(ap, int)) != -1) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 ucx_map_cstr_put(toolbar_items, name, item);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
111 void ui_toolitem_toggle(const char *name, const char *label, const char *img, UiInteger *i) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
112 UiToggleToolItem *item = malloc(sizeof(UiToggleToolItem));
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
113 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
114 item->label = label;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
115 item->image = img;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
116 item->stockid = NULL;
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 item->groups = NULL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 item->isimportant = 0;
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
119 item->value = i;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
120 item->var = NULL;
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 ucx_map_cstr_put(toolbar_items, name, item);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
125 void ui_toolitem_toggle_st(const char *name, const char *stockid, UiInteger *i) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
126 UiToggleToolItem *item = malloc(sizeof(UiToggleToolItem));
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
127 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
128 item->label = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
129 item->image = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
130 item->stockid = stockid;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
131 item->groups = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
132 item->isimportant = 0;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
133 item->value = i;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
134 item->var = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
135
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
136 ucx_map_cstr_put(toolbar_items, name, item);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
137 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
138
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
139 void ui_toolitem_toggle_nv(const char *name, const char *label, const char *img, const char *intvar) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
140 UiToggleToolItem *item = malloc(sizeof(UiToggleToolItem));
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 item->label = label;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 item->image = img;
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
144 item->stockid = NULL;
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 item->groups = NULL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 item->isimportant = 0;
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
147 item->value = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
148 item->var = intvar;
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
150 ucx_map_cstr_put(toolbar_items, name, item);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
151 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
152
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
153 void ui_toolitem_toggle_stnv(const char *name, const char *stockid, const char *intvar) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
154 UiToggleToolItem *item = malloc(sizeof(UiToggleToolItem));
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
155 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
156 item->label = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
157 item->image = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
158 item->stockid = stockid;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
159 item->groups = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
160 item->isimportant = 0;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
161 item->value = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
162 item->var = intvar;
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 ucx_map_cstr_put(toolbar_items, name, item);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 void ui_toolbar_combobox(
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 char *name,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 UiList *list,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 ui_getvaluefunc getvalue,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 ui_callback f,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 void *udata)
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 UiToolbarComboBox *cb = malloc(sizeof(UiToolbarComboBox));
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 UiVar *var = malloc(sizeof(UiVar));
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 var->value = list;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 var->type = UI_VAR_SPECIAL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 var->from = NULL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 var->from_ctx = NULL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 cb->var = var;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 cb->getvalue = getvalue;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 cb->callback = f;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 cb->userdata = udata;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 ucx_map_cstr_put(toolbar_items, name, cb);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 void ui_toolbar_combobox_str(
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 char *name,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 UiList *list,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 ui_callback f,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 void *udata)
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 ui_toolbar_combobox(name, list, ui_strmodel_getvalue, f, udata);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 void ui_toolbar_combobox_nv(
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 char *name,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 char *listname,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 ui_getvaluefunc getvalue,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 ui_callback f,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 void *udata)
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 UiToolbarComboBoxNV *cb = malloc(sizeof(UiToolbarComboBoxNV));
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox_nv;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 cb->listname = listname;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 cb->getvalue = getvalue;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 cb->callback = f;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 cb->userdata = udata;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 ucx_map_cstr_put(toolbar_items, name, cb);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 void ui_toolbar_add_default(char *name) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 char *s = strdup(name);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 defaults = ucx_list_append(defaults, s);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 GtkWidget* ui_create_toolbar(UiObject *obj) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 if(!defaults) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 return NULL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 GtkWidget *toolbar = gtk_toolbar_new();
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 #ifdef UI_GTK3
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 gtk_style_context_add_class(
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 gtk_widget_get_style_context(toolbar),
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 #endif
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 GtkToolbar *tb = GTK_TOOLBAR(toolbar);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 UCX_FOREACH(elm, defaults) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 UiToolItemI *item = ucx_map_cstr_get(toolbar_items, elm->data);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 if(item) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 item->add_to(tb, item, obj);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 } else if(!strcmp(elm->data, "@separator")) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 gtk_toolbar_insert(tb, gtk_separator_tool_item_new(), -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 } else {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", elm->data);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 return toolbar;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 void add_toolitem_widget(GtkToolbar *tb, UiToolItem *item, UiObject *obj) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 GtkToolItem *button = gtk_tool_button_new(NULL, item->label);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 gtk_tool_item_set_homogeneous(button, FALSE);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 if(item->image) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 GdkPixbuf *pixbuf = ui_get_image(item->image);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), image);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 } else {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 gtk_tool_item_set_is_important(button, TRUE);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 if(item->callback) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 UiEventData *event = ucx_mempool_malloc(
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 obj->ctx->mempool,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 sizeof(UiEventData));
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 event->obj = obj;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 event->userdata = item->userdata;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 event->callback = item->callback;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 g_signal_connect(
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 button,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 "clicked",
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 G_CALLBACK(ui_button_clicked),
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 event);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 gtk_toolbar_insert(tb, button, -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 if(item->groups) {
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
278 uic_add_group_widget(obj->ctx, button, (ui_enablefunc)ui_set_enabled, item->groups);
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 void add_toolitem_st_widget(GtkToolbar *tb, UiStToolItem *item, UiObject *obj) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 GtkToolItem *button = gtk_tool_button_new_from_stock(item->stockid);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 gtk_tool_item_set_homogeneous(button, FALSE);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 if(item->isimportant) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 gtk_tool_item_set_is_important(button, TRUE);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 if(item->callback) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 UiEventData *event = ucx_mempool_malloc(
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 obj->ctx->mempool,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 sizeof(UiEventData));
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 event->obj = obj;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 event->userdata = item->userdata;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 event->callback = item->callback;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 g_signal_connect(
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 button,
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 "clicked",
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 G_CALLBACK(ui_button_clicked),
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 event);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 gtk_toolbar_insert(tb, button, -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 if(item->groups) {
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
307 uic_add_group_widget(obj->ctx, button, (ui_enablefunc)ui_set_enabled, item->groups);
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
311 void add_toolitem_toggle_widget(GtkToolbar *tb, UiToggleToolItem *item, UiObject *obj) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
312 GtkToolItem *button;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
313 if(item->stockid) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
314 button = gtk_toggle_tool_button_new_from_stock(item->stockid);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
315 } else {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
316 button = gtk_toggle_tool_button_new();
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
317 gtk_tool_item_set_homogeneous(button, FALSE);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
318 if(item->label) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
319 gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), item->label);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
320 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
321 if(item->image) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
322 GdkPixbuf *pixbuf = ui_get_image(item->image);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
323 GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
324 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), image);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
325 }
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
328 UiVar *var;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
329 if(item->value) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
330 var = malloc(sizeof(UiVar));
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
331 var->value = item->value;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
332 var->type = UI_VAR_SPECIAL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
333 var->from = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
334 var->from_ctx = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
335 } else {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
336 var = uic_create_var(obj->ctx, item->var, UI_VAR_INTEGER);
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
339 if(var->value) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
340 UiInteger *i = var->value;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
341 i->get = ui_tool_toggle_button_get;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
342 i->set = ui_tool_toggle_button_set;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
343 i->obj = button;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
344
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
345 if(i->value != 0) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
346 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(button), TRUE);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
347 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
348 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
349
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
350 // register event
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
351 // the event func will call the UiInteger observer callbacks
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
352 UiEventData *event = ucx_mempool_malloc(
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
353 obj->ctx->mempool,
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
354 sizeof(UiEventData));
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
355 event->obj = obj;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
356 event->userdata = var;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
357 event->callback = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
358
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
359 g_signal_connect(
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
360 button,
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
361 "toggled",
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
362 G_CALLBACK(ui_tool_button_toggled),
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
363 event);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
364
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
365 // add item to toolbar
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 gtk_toolbar_insert(tb, button, -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 if(item->groups) {
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
369 uic_add_group_widget(obj->ctx, button, (ui_enablefunc)ui_set_enabled, item->groups);
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
373 void ui_tool_button_toggled(GtkToggleToolButton *widget, UiEventData *event) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
374 UiEvent e;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
375 e.obj = event->obj;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
376 e.window = event->obj->window;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
377 e.document = event->obj->ctx->document;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
378 e.eventdata = NULL;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
379 e.intval = gtk_toggle_tool_button_get_active(widget);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
380
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
381 UiVar *var = event->userdata;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
382 UiInteger *i = var->value;
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
384 ui_notify_evt(i->observers, &e);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
385 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
386
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
387 int64_t ui_tool_toggle_button_get(UiInteger *integer) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
388 integer->value = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(integer->obj));
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
389 return integer->value;
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
390 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
391
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
392 void ui_tool_toggle_button_set(UiInteger *integer, int64_t value) {
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
393 gboolean s = value != 0 ? TRUE : FALSE;
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
394 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(integer->obj), s);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
395 integer->value = s;
0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
396 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
397
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398 void add_toolbar_combobox(GtkToolbar *tb, UiToolbarComboBox *cb, UiObject *obj) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399 UiModel *modelinfo = ui_model(obj->ctx, UI_STRING, "", -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400 modelinfo->getvalue = cb->getvalue;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401 UiListModel *model = ui_list_model_new(obj, cb->var, modelinfo);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 GtkWidget *combobox = ui_create_combobox(obj, model, cb->callback, cb->userdata);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 GtkToolItem *item = gtk_tool_item_new();
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405 gtk_container_add(GTK_CONTAINER(item), combobox);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 gtk_toolbar_insert(tb, item, -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
408
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409 void add_toolbar_combobox_nv(GtkToolbar *tb, UiToolbarComboBoxNV *cb, UiObject *obj) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
410 UiVar *var = uic_create_var(obj->ctx, cb->listname, UI_VAR_LIST);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 if(var) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
412 UiModel *modelinfo = ui_model(obj->ctx, UI_STRING, "", -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
413 modelinfo->getvalue = cb->getvalue;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
414 UiListModel *model = ui_list_model_new(obj, var, modelinfo);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
415
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
416 GtkWidget *combobox = ui_create_combobox(obj, model, cb->callback, cb->userdata);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 GtkToolItem *item = gtk_tool_item_new();
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
418 gtk_container_add(GTK_CONTAINER(item), combobox);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
419 gtk_toolbar_insert(tb, item, -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
422

mercurial