1 /*
2 * Calcoo: b_buttons.c
3 *
4 * Copyright (C) 2001, 2002, 2005 Alexei Kaminski
5 *
6 * functions to create and operate buttons
7 *
8 */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <gtk/gtk.h>
13 #include <gdk/gdk.h>
14
15 #include "codes.h"
16 #include "body.h"
17 #include "defaults.h"
18 #include "b_headers.h"
19 #include "gtkaux_headers.h"
20 #include "io_headers.h"
21
create_button(int button_code,int x,int y,int w,int h,char *** icon_xpm,void (* button_function)(void),char * tooltip)22 void create_button(int button_code,
23 int x, int y, int w, int h,
24 char ***icon_xpm,
25 void (*button_function)(void),
26 char *tooltip)
27 {
28 create_fg_pixmap(&(body->icon[button_code]), icon_xpm[button_code]);
29 gtk_widget_show(body->icon[button_code]);
30
31 body->button[button_code] = gtk_button_new();
32 gtk_container_add(GTK_CONTAINER(body->button[button_code]),
33 body->icon[button_code]);
34 g_signal_connect(G_OBJECT (body->button[button_code]), "clicked",
35 GTK_SIGNAL_FUNC (*button_function), NULL);
36 gtk_fixed_put(GTK_FIXED(body->fixer), body->button[button_code], x, y);
37 GTK_WIDGET_UNSET_FLAGS(body->button[button_code], GTK_CAN_FOCUS);
38 gtk_widget_set_size_request(body->button[button_code], w, h);
39 gtk_widget_show(body->button[button_code]);
40
41 if (tooltip)
42 gtk_tooltips_set_tip(GTK_TOOLTIPS (body->button_tooltips),
43 body->button[button_code], tooltip, NULL);
44 }
45
46 /* Invisible buttons are fake buttons necessary (?) to have keyboard
47 * accelerators for functions which are not (and should not be) tied to any
48 * specific real button. Exit is an example of such a function */
49 /* void create_invisible_button(int button_code, */
50 /* void (*button_function)(void)) */
51 /* { */
52 /* body->button[button_code] = gtk_button_new(); */
53 /* gtk_signal_connect(GTK_OBJECT (body->button[button_code]), "clicked", */
54 /* GTK_SIGNAL_FUNC (*button_function), NULL); */
55 /* gtk_fixed_put(GTK_FIXED(body->fixer), body->button[button_code], 0, 0); */
56 /* GTK_WIDGET_UNSET_FLAGS(body->button[button_code], GTK_CAN_FOCUS); */
57 /* gtk_widget_set_usize(body->button[button_code], 0, 0); */
58 /* } */
59
create_toggle_button(int button_code,int x,int y,int w,int h,char *** icon_xpm,void (* button_function)(void),char * tooltip)60 void create_toggle_button(int button_code,
61 int x, int y, int w, int h,
62 char ***icon_xpm,
63 void (*button_function)(void),
64 char *tooltip)
65 {
66 create_fg_pixmap(&(body->icon[button_code]), icon_xpm[button_code]);
67 gtk_widget_show(body->icon[button_code]);
68
69 body->button[button_code] = gtk_toggle_button_new();
70 gtk_container_add(GTK_CONTAINER(body->button[button_code]),
71 body->icon[button_code]);
72 g_signal_connect(G_OBJECT (body->button[button_code]), "toggled",
73 GTK_SIGNAL_FUNC (*button_function), NULL);
74 gtk_fixed_put(GTK_FIXED(body->fixer), body->button[button_code], x, y);
75 GTK_WIDGET_UNSET_FLAGS(body->button[button_code], GTK_CAN_FOCUS);
76 gtk_widget_set_size_request(body->button[button_code], w, h);
77 gtk_widget_show(body->button[button_code]);
78
79 if (tooltip)
80 gtk_tooltips_set_tip(GTK_TOOLTIPS (body->button_tooltips),
81 body->button[button_code], tooltip, NULL);
82 }
83
create_copy_button(int button_code,int x,int y,int w,int h,char *** icon_xpm,char * tooltip)84 void create_copy_button(int button_code,
85 int x, int y, int w, int h,
86 char ***icon_xpm,
87 char *tooltip)
88 /* a special function is needed to create the copy button because
89 * an additional signal connection is needed for it (see below) */
90 {
91 static int have_selection = FALSE;
92
93 body->selection_widget = gtk_invisible_new ();
94
95 create_fg_pixmap(&(body->icon[button_code]), icon_xpm[button_code]);
96 gtk_widget_show(body->icon[button_code]);
97
98 body->button[button_code] = gtk_button_new();
99 gtk_container_add(GTK_CONTAINER(body->button[button_code]),
100 body->icon[button_code]);
101
102 /* now let us create copying process */
103 g_signal_connect (G_OBJECT (body->button[button_code]),
104 "clicked",
105 G_CALLBACK (own_selection),
106 (gpointer) &have_selection
107 );
108 g_signal_connect (G_OBJECT (body->selection_widget),
109 "selection_clear_event",
110 G_CALLBACK (selection_clear),
111 (gpointer) &have_selection
112 );
113 gtk_selection_add_target (body->selection_widget,
114 GDK_SELECTION_PRIMARY,
115 GDK_SELECTION_TYPE_STRING,
116 1);
117 g_signal_connect (G_OBJECT (body->selection_widget),
118 "selection_get",
119 G_CALLBACK (set_selection),
120 (gpointer) &have_selection
121 );
122
123 gtk_fixed_put(GTK_FIXED(body->fixer), body->button[button_code], x, y);
124 GTK_WIDGET_UNSET_FLAGS(body->button[button_code], GTK_CAN_FOCUS);
125 gtk_widget_set_size_request(body->button[button_code], w, h);
126 gtk_widget_show(body->button[button_code]);
127
128 if (tooltip)
129 gtk_tooltips_set_tip(GTK_TOOLTIPS (body->button_tooltips),
130 body->button[button_code], tooltip, NULL);
131 }
132
133
create_paste_button(int button_code,int x,int y,int w,int h,char *** icon_xpm,char * tooltip)134 void create_paste_button(int button_code,
135 int x, int y, int w, int h,
136 char ***icon_xpm,
137 char *tooltip)
138 /* a special function is needed to create the paste button because
139 * an additional signal connection is needed for it (see below) */
140 {
141 create_fg_pixmap(&(body->icon[button_code]), icon_xpm[button_code]);
142 gtk_widget_show(body->icon[button_code]);
143
144 body->button[button_code] = gtk_button_new();
145 gtk_container_add(GTK_CONTAINER(body->button[button_code]),
146 body->icon[button_code]);
147
148 g_signal_connect (G_OBJECT (body->button[button_code]),
149 "clicked",
150 G_CALLBACK (request_selection),
151 (gpointer)body->main_window
152 );
153 g_signal_connect (G_OBJECT(body->main_window),
154 "selection_received",
155 G_CALLBACK (get_selection), NULL);
156
157 gtk_fixed_put(GTK_FIXED(body->fixer), body->button[button_code], x, y);
158 GTK_WIDGET_UNSET_FLAGS(body->button[button_code], GTK_CAN_FOCUS);
159 gtk_widget_set_size_request(body->button[button_code], w, h);
160 gtk_widget_show(body->button[button_code]);
161
162 if (tooltip)
163 gtk_tooltips_set_tip(GTK_TOOLTIPS (body->button_tooltips),
164 body->button[button_code], tooltip, NULL);
165 }
166
show_button_label(int button_code)167 void show_button_label(int button_code)
168 {
169 gtk_widget_show(body->icon[button_code]);
170 }
171
hide_button_label(int button_code)172 void hide_button_label(int button_code)
173 {
174 gtk_widget_hide(body->icon[button_code]);
175 }
176
toggled_arc_button(void)177 void toggled_arc_button(void)
178 {
179 /* this empty function is kept just in case,
180 * but in GTK+ 1.0 it was necessary since there were
181 * no function to determine the state of a toggle button,
182 * and this function set the corresponding auxiliary flag */
183 }
184
toggled_hyp_button(void)185 void toggled_hyp_button(void)
186 {
187 /* this empty function is kept just in case,
188 * but in GTK+ 1.0 it was necessary since there were
189 * no function to determine the state of a toggle button,
190 * and this function set the corresponding auxiliary flag */
191 }
192
raise_toggle_button(int button_code)193 void raise_toggle_button(int button_code)
194 {
195 gtk_toggle_button_set_active(
196 GTK_TOGGLE_BUTTON(body->button[button_code]), FALSE);
197 }
198
get_toggle_button_state(int button_code)199 int get_toggle_button_state(int button_code)
200 {
201 return gtk_toggle_button_get_active(
202 GTK_TOGGLE_BUTTON(body->button[button_code]));
203 }
204
raise_arc_hyp(void)205 void raise_arc_hyp(void)
206 {
207 if (body->arc_autorelease)
208 raise_toggle_button(CODE_ARC);
209 if (body->hyp_autorelease)
210 raise_toggle_button(CODE_HYP);
211 }
212
get_arc_state(void)213 int get_arc_state(void)
214 {
215 return get_toggle_button_state(CODE_ARC);
216 }
217
get_hyp_state(void)218 int get_hyp_state(void)
219 {
220 return get_toggle_button_state(CODE_HYP);
221 }
222
set_arc_autorelease(int a)223 void set_arc_autorelease(int a)
224 {
225 body->arc_autorelease = a;
226 }
227
set_hyp_autorelease(int a)228 void set_hyp_autorelease(int a)
229 {
230 body->hyp_autorelease = a;
231 }
232
get_arc_autorelease(void)233 int get_arc_autorelease(void)
234 {
235 return body->arc_autorelease;
236 }
237
get_hyp_autorelease(void)238 int get_hyp_autorelease(void)
239 {
240 return body->hyp_autorelease;
241 }
242
enable_button(int button_code)243 void enable_button(int button_code)
244 {
245 gtk_widget_set_sensitive(body->button[button_code],TRUE);
246 }
247
disable_button(int button_code)248 void disable_button(int button_code)
249 {
250 gtk_widget_set_sensitive(body->button[button_code],FALSE);
251 }
252
show_button(int button_code)253 void show_button(int button_code)
254 {
255 gtk_widget_show(body->button[button_code]);
256 }
257
hide_button(int button_code)258 void hide_button(int button_code)
259 {
260 gtk_widget_hide(body->button[button_code]);
261 }
262
disable_all_buttons(void)263 void disable_all_buttons(void)
264 {
265 int i;
266
267 for (i = 0; i < MAX_BUTTON_NUMBER; i++) {
268 if ((body->button[i] != NULL)
269 && (i != CODE_CLEAR_ALL)
270 && (i != CODE_UNDO)
271 && (i != CODE_REDO))
272 disable_button(i);
273 }
274
275 }
276
enable_all_buttons(void)277 void enable_all_buttons(void)
278 {
279 int i;
280
281 for (i = 0; i < MAX_BUTTON_NUMBER; i++) {
282 if ((body->button[i] != NULL)
283 && (i != CODE_CLEAR_ALL)
284 && (i != CODE_UNDO)
285 && (i != CODE_REDO))
286 enable_button(i);
287 }
288
289 }
290