ui/gtk/toolbar.c

Wed, 21 Jan 2015 20:38:21 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 21 Jan 2015 20:38:21 +0100
changeset 77
bc0ed99e49c7
parent 49
a80ba8741be6
child 86
3c63f57a8f77
permissions
-rw-r--r--

fixed memory allocation bug

3
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
c1a75454b444 added toolbar
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "toolbar.h"
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "../../ucx/mempool.h"
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "../common/context.h"
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 static UcxMap *toolbar_items;
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 static UcxList *defaults;
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 void ui_toolbar_init() {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 toolbar_items = ucx_map_new(16);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 UiStToolItem *item = malloc(sizeof(UiStToolItem));
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 item->item.add_to = (ui_toolbar_add_f)add_toolitem_st_widget;
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 item->stockid = stockid;
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 ucx_map_cstr_put(toolbar_items, name, item);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 void ui_toolbar_add_default(char *name) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 char *s = strdup(name);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 defaults = ucx_list_append(defaults, s);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 GtkWidget* ui_create_toolbar(UiObject *obj) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 if(!defaults) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 return NULL;
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 GtkWidget *toolbar = gtk_toolbar_new();
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 #ifdef UI_GTK3
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 gtk_style_context_add_class(
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 gtk_widget_get_style_context(toolbar),
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 #endif
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 GtkToolbar *tb = GTK_TOOLBAR(toolbar);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 UCX_FOREACH(elm, defaults) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 UiToolItemI *item = ucx_map_cstr_get(toolbar_items, elm->data);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 if(item) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 item->add_to(tb, item, obj);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 } else if(!strcmp(elm->data, "@separator")) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 gtk_toolbar_insert(tb, gtk_separator_tool_item_new(), -1);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 } else {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", elm->data);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 return toolbar;
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 void add_toolitem_widget(GtkToolbar *tb, UiToolItem *item, UiObject *obj) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 GtkToolItem *button = gtk_tool_button_new(NULL, item->label);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 if(item->callback) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 UiEventData *event = ucx_mempool_malloc(
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 obj->ctx->mempool,
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 sizeof(UiEventData));
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 event->callback = item->callback;
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 g_signal_connect(
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 button,
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 "clicked",
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 G_CALLBACK(ui_button_clicked),
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 event);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 void add_toolitem_st_widget(GtkToolbar *tb, UiStToolItem *item, UiObject *obj) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 GtkToolItem *button = gtk_tool_button_new_from_stock(item->stockid);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 if(item->callback) {
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 UiEventData *event = ucx_mempool_malloc(
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 obj->ctx->mempool,
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 sizeof(UiEventData));
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 event->callback = item->callback;
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 g_signal_connect(
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 button,
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 "clicked",
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 G_CALLBACK(ui_button_clicked),
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 event);
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 }
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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 }

mercurial