Wed, 21 Jan 2015 20:38:21 +0100
fixed memory allocation bug
3 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2014 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | #include <string.h> | |
32 | ||
33 | #include "toolbar.h" | |
34 | #include "button.h" | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
35 | #include "image.h" |
3 | 36 | #include "../../ucx/mempool.h" |
37 | #include "../common/context.h" | |
38 | ||
39 | static UcxMap *toolbar_items; | |
40 | static UcxList *defaults; | |
41 | ||
42 | void ui_toolbar_init() { | |
43 | toolbar_items = ucx_map_new(16); | |
44 | } | |
45 | ||
46 | void ui_toolitem(char *name, char *label, ui_callback f, void *udata) { | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
47 | ui_toolitem_img(name, label, NULL, f, udata); |
3 | 48 | } |
49 | ||
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
50 | void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *userdata) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
51 | ui_toolitem_stgr(name, stockid, f, userdata, -1); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
52 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
53 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
54 | void ui_toolitem_sti(char *name, char *stockid, ui_callback f, void *userdata) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
55 | ui_toolitem_stgri(name, stockid, f, userdata, -1); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
56 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
57 | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
58 | void ui_toolitem_stgr(char *name, char *stockid, ui_callback f, void *userdata, ...) { |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
59 | va_list ap; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
60 | va_start(ap, userdata); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
61 | ui_toolitem_vstgr(name, stockid, 0, f, userdata, ap); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
62 | va_end(ap); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
63 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
64 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
65 | void ui_toolitem_stgri(char *name, char *stockid, ui_callback f, void *userdata, ...) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
66 | va_list ap; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
67 | va_start(ap, userdata); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
68 | ui_toolitem_vstgr(name, stockid, 1, f, userdata, ap); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
69 | va_end(ap); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
70 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
71 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
72 | void ui_toolitem_img(char *name, char *label, char *img, ui_callback f, void *udata) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
73 | UiToolItem *item = malloc(sizeof(UiToolItem)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
74 | item->item.add_to = (ui_toolbar_add_f)add_toolitem_widget; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
75 | item->label = label; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
76 | item->image = img; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
77 | item->callback = f; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
78 | item->userdata = udata; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
79 | item->isimportant = 0; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
80 | item->groups = NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
81 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
82 | ucx_map_cstr_put(toolbar_items, name, item); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
83 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
84 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
85 | void ui_toolitem_vstgr( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
86 | char *name, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
87 | char *stockid, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
88 | int isimportant, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
89 | ui_callback f, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
90 | void *userdata, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
91 | va_list ap) |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
92 | { |
3 | 93 | UiStToolItem *item = malloc(sizeof(UiStToolItem)); |
94 | item->item.add_to = (ui_toolbar_add_f)add_toolitem_st_widget; | |
95 | item->stockid = stockid; | |
96 | item->callback = f; | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
97 | item->userdata = userdata; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
98 | item->groups = NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
99 | item->isimportant = isimportant; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
100 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
101 | // add groups |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
102 | int group; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
103 | while((group = va_arg(ap, int)) != -1) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
104 | item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
105 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
106 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
107 | ucx_map_cstr_put(toolbar_items, name, item); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
108 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
109 | |
49
a80ba8741be6
added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
110 | void ui_toolitem_toggle_st(char *name, char *stockid, ui_callback f, void *udata) { |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
111 | ui_toolitem_toggle_stgr(name, stockid, f, udata, -1); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
112 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
113 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
114 | void ui_toolitem_toggle_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
115 | UiStToolItem *item = malloc(sizeof(UiStToolItem)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
116 | item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_st_widget; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
117 | item->stockid = stockid; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
118 | item->callback = f; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
119 | item->userdata = udata; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
120 | item->groups = NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
121 | item->isimportant = 0; |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
122 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
123 | // add groups |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
124 | va_list ap; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
125 | va_start(ap, udata); |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
126 | int group; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
127 | while((group = va_arg(ap, int)) != -1) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
128 | item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
129 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
130 | va_end(ap); |
3 | 131 | |
132 | ucx_map_cstr_put(toolbar_items, name, item); | |
133 | } | |
134 | ||
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
135 | void ui_toolitem_toggle_imggr(char *name, char *label, char *img, ui_callback f, void *udata, ...) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
136 | UiToolItem *item = malloc(sizeof(UiToolItem)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
137 | item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
138 | item->label = label; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
139 | item->image = img; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
140 | item->callback = f; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
141 | item->userdata = udata; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
142 | item->groups = NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
143 | item->isimportant = 0; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
144 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
145 | // add groups |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
146 | va_list ap; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
147 | va_start(ap, udata); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
148 | int group; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
149 | while((group = va_arg(ap, int)) != -1) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
150 | item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
151 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
152 | va_end(ap); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
153 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
154 | ucx_map_cstr_put(toolbar_items, name, item); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
155 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
156 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
157 | |
3 | 158 | void ui_toolbar_add_default(char *name) { |
159 | char *s = strdup(name); | |
160 | defaults = ucx_list_append(defaults, s); | |
161 | } | |
162 | ||
163 | GtkWidget* ui_create_toolbar(UiObject *obj) { | |
164 | if(!defaults) { | |
165 | return NULL; | |
166 | } | |
167 | ||
168 | GtkWidget *toolbar = gtk_toolbar_new(); | |
169 | #ifdef UI_GTK3 | |
170 | gtk_style_context_add_class( | |
171 | gtk_widget_get_style_context(toolbar), | |
172 | GTK_STYLE_CLASS_PRIMARY_TOOLBAR); | |
173 | #endif | |
174 | ||
175 | GtkToolbar *tb = GTK_TOOLBAR(toolbar); | |
176 | UCX_FOREACH(elm, defaults) { | |
177 | UiToolItemI *item = ucx_map_cstr_get(toolbar_items, elm->data); | |
178 | if(item) { | |
179 | item->add_to(tb, item, obj); | |
180 | } else if(!strcmp(elm->data, "@separator")) { | |
181 | gtk_toolbar_insert(tb, gtk_separator_tool_item_new(), -1); | |
182 | } else { | |
183 | fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", elm->data); | |
184 | } | |
185 | } | |
186 | ||
187 | return toolbar; | |
188 | } | |
189 | ||
190 | void add_toolitem_widget(GtkToolbar *tb, UiToolItem *item, UiObject *obj) { | |
191 | GtkToolItem *button = gtk_tool_button_new(NULL, item->label); | |
192 | gtk_tool_item_set_homogeneous(button, FALSE); | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
193 | if(item->image) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
194 | GdkPixbuf *pixbuf = ui_get_image(item->image); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
195 | GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
196 | gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), image); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
197 | } |
3 | 198 | |
199 | if(item->callback) { | |
200 | UiEventData *event = ucx_mempool_malloc( | |
201 | obj->ctx->mempool, | |
202 | sizeof(UiEventData)); | |
203 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
204 | event->userdata = item->userdata; |
3 | 205 | event->callback = item->callback; |
206 | ||
207 | g_signal_connect( | |
208 | button, | |
209 | "clicked", | |
210 | G_CALLBACK(ui_button_clicked), | |
211 | event); | |
212 | } | |
213 | ||
214 | gtk_toolbar_insert(tb, button, -1); | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
215 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
216 | if(item->groups) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
217 | uic_add_group_widget(obj->ctx, button, item->groups); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
218 | } |
3 | 219 | } |
220 | ||
221 | void add_toolitem_st_widget(GtkToolbar *tb, UiStToolItem *item, UiObject *obj) { | |
222 | GtkToolItem *button = gtk_tool_button_new_from_stock(item->stockid); | |
223 | gtk_tool_item_set_homogeneous(button, FALSE); | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
224 | if(item->isimportant) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
225 | gtk_tool_item_set_is_important(button, TRUE); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
226 | } |
3 | 227 | |
228 | if(item->callback) { | |
229 | UiEventData *event = ucx_mempool_malloc( | |
230 | obj->ctx->mempool, | |
231 | sizeof(UiEventData)); | |
232 | event->obj = obj; | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
233 | event->userdata = item->userdata; |
3 | 234 | event->callback = item->callback; |
235 | ||
236 | g_signal_connect( | |
237 | button, | |
238 | "clicked", | |
239 | G_CALLBACK(ui_button_clicked), | |
240 | event); | |
241 | } | |
242 | ||
243 | gtk_toolbar_insert(tb, button, -1); | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
244 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
245 | if(item->groups) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
246 | uic_add_group_widget(obj->ctx, button, item->groups); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
247 | } |
3 | 248 | } |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
249 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
250 | void add_toolitem_toggle_widget(GtkToolbar *tb, UiToolItem *item, UiObject *obj) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
251 | GtkToolItem *button = gtk_toggle_tool_button_new(); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
252 | gtk_tool_item_set_homogeneous(button, FALSE); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
253 | if(item->label) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
254 | gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), item->label); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
255 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
256 | if(item->image) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
257 | GdkPixbuf *pixbuf = ui_get_image(item->image); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
258 | GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
259 | gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), image); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
260 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
261 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
262 | if(item->callback) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
263 | UiEventData *event = ucx_mempool_malloc( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
264 | obj->ctx->mempool, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
265 | sizeof(UiEventData)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
266 | event->obj = obj; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
267 | event->userdata = item->userdata; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
268 | event->callback = item->callback; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
269 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
270 | g_signal_connect( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
271 | button, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
272 | "toggled", |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
273 | G_CALLBACK(ui_button_toggled), |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
274 | event); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
275 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
276 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
277 | gtk_toolbar_insert(tb, button, -1); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
278 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
279 | if(item->groups) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
280 | uic_add_group_widget(obj->ctx, button, item->groups); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
281 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
282 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
283 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
284 | void add_toolitem_toggle_st_widget(GtkToolbar *tb, UiStToolItem *item, UiObject *obj) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
285 | GtkToolItem *button = gtk_toggle_tool_button_new_from_stock(item->stockid); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
286 | gtk_tool_item_set_homogeneous(button, FALSE); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
287 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
288 | if(item->callback) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
289 | UiEventData *event = ucx_mempool_malloc( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
290 | obj->ctx->mempool, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
291 | sizeof(UiEventData)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
292 | event->obj = obj; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
293 | event->userdata = item->userdata; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
294 | event->callback = item->callback; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
295 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
296 | g_signal_connect( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
297 | button, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
298 | "toggled", |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
299 | G_CALLBACK(ui_button_toggled), |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
300 | event); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
301 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
302 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
303 | gtk_toolbar_insert(tb, button, -1); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
304 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
305 | if(item->groups) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
306 | uic_add_group_widget(obj->ctx, button, item->groups); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
307 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
308 | } |