1 // bfe2 - gtk wrapper functions
2 // Copyright (c) 2003 Brand Huntsman
3 //
4
5
6 #include "common.h"
7 #include "functions.h"
8
9
10 //////////////////////////////////////////////////////////////////////////
11
12 // global
13
14 // local
15 uint toggle_group_button_hack;
16
17 //////////////////////////////////////////////////////////////////////////
18
19
window_delete_event(GtkWidget * widget,GdkEvent * event,gpointer data)20 gint window_delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ){
21 return(FALSE);
22 }
23
24
toggle_group_button(GtkWidget * widget,gpointer data)25 static void toggle_group_button( GtkWidget *widget, gpointer data ){
26 s_bgroup *group = (s_bgroup *)data;
27 GtkWidget *button;
28 uint x;
29
30 if(toggle_group_button_hack){
31 toggle_group_button_hack = 0;
32 return;
33 }
34
35 for(x = 0; x < group->nr_buttons; x++)
36 if(group->button[x].widget == widget) break;
37
38 if(group->current == x){
39 gtk_signal_disconnect(GTK_OBJECT(widget), group->button[x].id);
40 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
41 toggle_group_button_hack = 1;
42 group->button[x].id = gtk_signal_connect(GTK_OBJECT(widget), "clicked",
43 GTK_SIGNAL_FUNC(toggle_group_button), (gpointer)group);
44 } else {
45 button = group->button[group->current].widget;
46 gtk_signal_disconnect(GTK_OBJECT(button), group->button[group->current].id);
47 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
48 group->button[group->current].id = gtk_signal_connect(GTK_OBJECT(button), "clicked",
49 GTK_SIGNAL_FUNC(toggle_group_button), (gpointer)group);
50 group->current = x;
51 if(group->callback) (group->callback)(group);
52 }
53 }
54
55
56 //////////////////////////////////////////////////////////////////////////
57
58
new_hbox(GtkWidget * box,gboolean pack)59 GtkWidget *new_hbox( GtkWidget *box, gboolean pack ){
60 GtkWidget *hbox;
61
62 hbox = gtk_hbox_new(FALSE, 5);
63 gtk_box_pack_start(GTK_BOX(box), hbox, pack, pack, 0);
64 gtk_widget_show(hbox);
65
66 return(hbox);
67 }
68
69
new_vbox(GtkWidget * box,gboolean pack)70 GtkWidget *new_vbox( GtkWidget *box, gboolean pack ){
71 GtkWidget *vbox;
72
73 vbox = gtk_vbox_new(FALSE, 5);
74 gtk_box_pack_start(GTK_BOX(box), vbox, pack, pack, 0);
75 gtk_widget_show(vbox);
76
77 return(vbox);
78 }
79
80
new_gap(GtkWidget * box)81 void new_gap( GtkWidget *box ){
82 GtkWidget *sep;
83
84 sep = gtk_label_new("");
85 gtk_box_pack_start(GTK_BOX(box), sep, TRUE, TRUE, 0);
86 gtk_widget_show(sep);
87 }
88
89
new_list(GtkWidget * box,uint columns,gchar * titles[])90 GtkCList *new_list( GtkWidget *box, uint columns, gchar *titles[] ){
91 GtkWidget *scrolled_window;
92 GtkCList *list;
93 uint x;
94
95 // create scrolled window
96 scrolled_window = gtk_scrolled_window_new(NULL, NULL);
97 gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 0);
98 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
99 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
100 gtk_box_pack_start(GTK_BOX(box), scrolled_window, TRUE, TRUE, 0);
101 gtk_widget_show(scrolled_window);
102
103 // create list
104 list = (GtkCList *)gtk_clist_new_with_titles(columns, titles);
105 for(x = 0; x < columns; x++)
106 gtk_clist_set_column_auto_resize(list, x, TRUE);
107 gtk_clist_set_selection_mode(list, GTK_SELECTION_SINGLE);
108 gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(list));
109 gtk_widget_show(GTK_WIDGET(list));
110
111 gtk_clist_column_titles_hide(list);
112
113 return(list);
114 }
115
116
new_label(GtkWidget * box,gboolean pack,char * message,gboolean wrap)117 GtkWidget *new_label( GtkWidget *box, gboolean pack, char *message, gboolean wrap ){
118 GtkWidget *label;
119
120 label = gtk_label_new(message);
121 if(wrap == TRUE) gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
122 gtk_box_pack_start(GTK_BOX(box), label, pack, pack, 0);
123 gtk_widget_show(label);
124
125 return(label);
126 }
127
128
new_text_entry(GtkWidget * box,gboolean pack,uint width)129 GtkWidget *new_text_entry( GtkWidget *box, gboolean pack, uint width ){
130 GtkWidget *text;
131
132 text = gtk_entry_new();
133 gtk_widget_set_usize(text, width, WIDGET_HEIGHT);
134 gtk_box_pack_start(GTK_BOX(box), text, pack, pack, 0);
135 gtk_widget_show(text);
136
137 return(text);
138 }
139
140
new_button(GtkWidget * box,gboolean pack,char * name)141 GtkWidget *new_button( GtkWidget *box, gboolean pack, char *name ){
142 GtkWidget *button;
143
144 button = gtk_button_new_with_label(name);
145 gtk_widget_set_usize(button, 0, WIDGET_HEIGHT);
146 gtk_box_pack_start(GTK_BOX(box), button, pack, pack, 0);
147 gtk_widget_show(button);
148
149 return(button);
150 }
151
152
new_check_button(GtkWidget * box,gboolean pack,char * name,gboolean state)153 GtkWidget *new_check_button( GtkWidget *box, gboolean pack, char *name, gboolean state ){
154 GtkWidget *button;
155
156 button = gtk_check_button_new_with_label(name);
157 gtk_widget_set_usize(button, 0, WIDGET_HEIGHT);
158 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), state);
159 gtk_box_pack_start(GTK_BOX(box), button, pack, pack, 0);
160 gtk_widget_show(button);
161
162 return(button);
163 }
164
165
new_toggle_button(GtkWidget * box,gboolean pack,char * name)166 GtkWidget *new_toggle_button( GtkWidget *box, gboolean pack, char *name ){
167 GtkWidget *button;
168
169 button = gtk_toggle_button_new_with_label(name);
170 gtk_widget_set_usize(button, 0, WIDGET_HEIGHT);
171 gtk_box_pack_start(GTK_BOX(box), button, pack, pack, 0);
172 gtk_widget_show(button);
173
174 return(button);
175 }
176
177
new_button_group(GtkWidget * box,gboolean pack,e_orientation orientation,uint nr_buttons,char * titles[])178 s_bgroup *new_button_group( GtkWidget *box, gboolean pack, e_orientation orientation, uint nr_buttons, char *titles[] ){
179 GtkWidget *bbox, *button;
180 s_bgroup *group;
181 uint x;
182
183 group = (s_bgroup *)malloc(sizeof(s_bgroup) + sizeof(struct s_bgroup_button) * (nr_buttons - 1));
184 if(group == NULL){
185 g_print("BFE: Couldn't allocate button group.\n");
186 exit(1);
187 }
188
189 // create vbox or hbox
190 if(orientation == VERTICAL) bbox = gtk_vbox_new(FALSE, 0);
191 else bbox = gtk_hbox_new(FALSE, 0);
192 gtk_box_pack_start(GTK_BOX(box), bbox, pack, pack, 0);
193 gtk_widget_show(bbox);
194
195 // create togle buttons
196 for(x = 0; x < nr_buttons; x++){
197 button = new_toggle_button(bbox, TRUE, titles[x]);
198 if(x == 0) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
199 group->button[x].id = gtk_signal_connect(GTK_OBJECT(button), "clicked",
200 GTK_SIGNAL_FUNC(toggle_group_button), (gpointer)group);
201 group->button[x].widget = button;
202 }
203 group->callback = NULL;
204 group->current = 0;
205 group->nr_buttons = nr_buttons;
206
207 toggle_group_button_hack = 0;
208 return(group);
209 }
set_bgroup(s_bgroup * group,uint button)210 void set_bgroup( s_bgroup *group, uint button ){
211 if(button != group->current && button < group->nr_buttons)
212 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(group->button[button].widget), TRUE);
213 }
214
215
new_separator(GtkWidget * box,gboolean pack,e_orientation orientation)216 void new_separator( GtkWidget *box, gboolean pack, e_orientation orientation ){
217 GtkWidget *sep;
218
219 if(orientation == VERTICAL)
220 sep = gtk_vseparator_new();
221 else sep = gtk_hseparator_new();
222 gtk_box_pack_start(GTK_BOX(box), sep, pack, pack, 0);
223 gtk_widget_show(sep);
224 }
225
226
new_window(GtkWindowType type,char * title,uint width,uint height)227 GtkWidget *new_window( GtkWindowType type, char *title, uint width, uint height ){
228 GtkWidget *window;
229
230 // create window
231 window = gtk_window_new(type);
232 gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(window_delete_event), NULL);
233 gtk_container_set_border_width(GTK_CONTAINER(window), 5);
234 gtk_widget_set_usize(GTK_WIDGET(window), width, height);
235 gtk_window_set_title(GTK_WINDOW(window), title);
236 gtk_widget_show(window);
237
238 return(window);
239 }
240
241
new_window_vbox(GtkWidget * window)242 GtkWidget *new_window_vbox( GtkWidget *window ){
243 GtkWidget *vbox;
244
245 // create window vbox
246 vbox = gtk_vbox_new(FALSE, 5);
247 gtk_container_add(GTK_CONTAINER(window), vbox);
248 gtk_widget_show(vbox);
249
250 return(vbox);
251 }
252