comparison src/rootvis/config_frontend_widgets.c @ 900:d985f0dcdeb0 trunk

[svn] - add a starting point for xmms-rootvis port. giacomo will need to finish this up, as my XLib skills are not enough at this time.
author nenolod
date Mon, 26 Mar 2007 01:19:26 -0700
parents
children 30e515b6e651
comparison
equal deleted inserted replaced
899:68508f8cdf25 900:d985f0dcdeb0
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include <gtk/gtk.h>
6 #include <config_frontend.h>
7
8 extern void print_status(char msg[]);
9
10 void frontend_set_signal(GtkWidget *widget, char* signal, void* func, int data)
11 {
12 gtk_signal_connect(GTK_OBJECT(widget), signal, GTK_SIGNAL_FUNC(func), GINT_TO_POINTER(data));
13 }
14
15 GtkWidget *frontend_create_window(int type, const char *name)
16 {
17 GtkWidget *window;
18
19 print_status("creating window");
20 print_status(name);
21 window = gtk_window_new(type);
22 gtk_signal_connect(GTK_OBJECT(window),
23 "delete-event",
24 GTK_SIGNAL_FUNC(signal_window_close),
25 NULL);
26
27 print_status("setting title");
28 gtk_window_set_title(window, name);
29 print_status("done");
30 gtk_widget_show(window);
31 return window;
32 }
33
34 GtkWidget *frontend_create_box(int box_type, GtkWidget *container, char *label,
35 int attach)
36 {
37 GtkWidget *box;
38
39 print_status("creating box");
40 print_status(label);
41
42
43
44 switch (box_type) {
45 case VBOX:
46 box = gtk_vbox_new(FALSE, 5);
47 gtk_container_set_border_width(GTK_CONTAINER(box), 5);
48 break;
49
50 case HBOX:
51 box = gtk_hbox_new(FALSE, 5);
52 gtk_container_set_border_width(GTK_CONTAINER(box), 5);
53 break;
54 case HBBOX:
55 box = gtk_hbutton_box_new();
56 gtk_button_box_set_layout(GTK_BUTTON_BOX(box),
57 GTK_BUTTONBOX_END);
58 gtk_button_box_set_spacing(GTK_BUTTON_BOX(box), 5);
59 break;
60 case HBBOX2:
61 box = gtk_hbutton_box_new();
62 gtk_button_box_set_layout(GTK_BUTTON_BOX(box),
63 GTK_BUTTONBOX_EDGE);
64 gtk_button_box_set_spacing(GTK_BUTTON_BOX(box), 4);
65 break;
66 case FRAME:
67 box = gtk_frame_new(label);
68 gtk_container_set_border_width(GTK_CONTAINER(box), 5);
69 break;
70 default:
71 print_status("error");
72 print_status("trying to create vbox");
73 box = gtk_vbox_new(FALSE, 5);
74 gtk_container_set_border_width(GTK_CONTAINER(box), 5);
75 }
76
77 print_status("attaching");
78 switch (attach) {
79 case ATTACH_TO_NOTEBOOK:
80 gtk_notebook_append_page(GTK_NOTEBOOK(container),
81 box, gtk_label_new(label));
82 break;
83
84 case ATTACH_TO_CONTAINER:
85 gtk_container_add(GTK_CONTAINER(container), box);
86 break;
87 case ATTACH_TO_BOX:
88 gtk_box_pack_start(GTK_BOX(container), box, TRUE, TRUE, 0);
89 break;
90 default:
91 print_status("error");
92 print_status("trying to attach to container");
93 gtk_container_add(GTK_CONTAINER(container), box);
94 }
95 gtk_widget_show(box);
96 print_status("done");
97 return box;
98 }
99
100 GtkWidget *frontend_create_notebook(GtkWidget *box)
101 {
102 GtkWidget *notebook;
103
104 print_status("creating notebook");
105 notebook = gtk_notebook_new();
106 gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0);
107 gtk_widget_show(notebook);
108 return notebook;
109 }
110
111 GtkWidget *frontend_create_button(GtkWidget *container, char *label)
112 {
113 GtkWidget *button;
114
115 print_status("adding button");
116 print_status(label);
117
118 button = gtk_button_new_with_label(label);
119 gtk_widget_show(button);
120
121 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
122 gtk_box_pack_start(GTK_BOX(container), button, TRUE, TRUE, 0);
123
124 return button;
125 }
126
127 GtkWidget *frontend_create_check(GtkWidget *container, char *label)
128 {
129 GtkWidget *check;
130
131 print_status("creating check");
132 print_status(label);
133
134 check = gtk_check_button_new_with_label(label);
135 gtk_widget_show(check);
136
137 gtk_container_add(GTK_CONTAINER(container), check);
138
139 print_status("done");
140 return check;
141 }
142
143 GtkWidget *frontend_create_label(GtkWidget *container, char *text)
144 {
145 GtkWidget *label;
146
147 print_status("creating label");
148 print_status(text);
149
150 label = gtk_label_new(text);
151 gtk_label_set_justify(label, GTK_JUSTIFY_CENTER);
152 gtk_label_set_line_wrap(label, TRUE);
153 gtk_widget_show(label);
154
155 gtk_container_add(GTK_CONTAINER(container), label);
156
157 print_status("done");
158 return label;
159 }
160
161 /*
162 GtkWidget *rootvis_create_frame_and_attach(char *name, GtkWidget *box)
163 {
164 GtkWidget *frame;
165
166 frame = gtk_frame_new(name);
167 gtk_container_set_border_width(GTK_CONTAINER(frame), 5);
168 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
169 gtk_widget_show(frame);
170 return frame;
171 }
172 */
173
174 GtkWidget *frontend_create_entry(int type, GtkWidget *container,
175 char *entry_changed,
176 char *label, ...)
177 {
178 va_list ap;
179 char *list_element;
180 char *signal;
181
182 GtkWidget *entry;
183 GList *list = NULL;
184
185 print_status("creating entry");
186 print_status(label);
187
188 va_start(ap, label);
189 switch (type) {
190 case COMBO:
191 entry = gtk_combo_new();
192 while ((list_element = va_arg(ap, char *))) {
193 print_status("adding element to list");
194 print_status(list_element);
195 list = g_list_append(list, list_element);
196 }
197 print_status("attaching string list to combo");
198 gtk_combo_set_popdown_strings(GTK_COMBO(entry), list);
199 break;
200 case ENTRY:
201 entry = gtk_entry_new();
202 gtk_entry_set_max_length(GTK_ENTRY(entry), 6);
203 while ((signal = va_arg(ap, char *))) {
204 print_status("adding signal to entry");
205 print_status(signal);
206 gtk_signal_connect(GTK_OBJECT(entry),
207 /* signal */
208 signal,
209 /* function */
210 GTK_SIGNAL_FUNC(va_arg(ap,
211 void *)),
212 /* data */
213 va_arg(ap, char *));
214 }
215 break;
216 default:
217 return NULL;
218 }
219 va_end(ap);
220
221 print_status("attaching entry to container");
222 gtk_container_add(GTK_CONTAINER(container), entry);
223 gtk_widget_show(entry);
224
225 print_status("done");
226
227 return entry;
228 }
229
230 void frontend_create_colorpicker(struct config_value *cvar)
231 {
232 struct rootvis_colorsel* colorsel = cvar->valc.frontend;
233 GtkWidget *vbox;
234 GtkWidget *options_frame, *options_vbox;
235
236 static GtkWidget *bbox, *ok, *cancel;
237
238 print_status("pressing button ... ");
239 gtk_button_set_relief(GTK_BUTTON(colorsel->button), GTK_RELIEF_HALF);
240
241
242 print_status("casting window ...");
243
244 colorsel->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
245 gtk_window_set_title(GTK_WINDOW(colorsel->window), colorsel->complete_name);
246
247 gtk_container_set_border_width(GTK_CONTAINER(colorsel->window), 10);
248 gtk_window_set_policy(GTK_WINDOW(colorsel->window), FALSE, FALSE, FALSE);
249 gtk_window_set_position(GTK_WINDOW(colorsel->window),
250 GTK_WIN_POS_MOUSE);
251 gtk_signal_connect(GTK_OBJECT(colorsel->window), "destroy",
252 GTK_SIGNAL_FUNC(gtk_widget_destroyed),
253 &(colorsel->window));
254
255 vbox = gtk_vbox_new(FALSE, 5);
256
257 printf("setting name ...");
258 options_frame = gtk_frame_new(colorsel->complete_name);
259 printf("done. \n");
260 gtk_container_set_border_width(GTK_CONTAINER(options_frame), 5);
261
262 options_vbox = gtk_vbox_new(FALSE, 5);
263 gtk_container_set_border_width(GTK_CONTAINER(options_vbox), 5);
264
265 colorsel->color_picker = gtk_color_selection_new();
266 gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(colorsel->color_picker), TRUE);
267 gtk_color_selection_set_color(GTK_COLOR_SELECTION(colorsel->color_picker), colorsel->color);
268 gtk_signal_connect(GTK_OBJECT(colorsel->color_picker), "color_changed", GTK_SIGNAL_FUNC(signal_colorselector_update), cvar);
269
270 gtk_box_pack_start(GTK_BOX(options_vbox), colorsel->color_picker,
271 FALSE, FALSE, 0);
272 gtk_widget_show(colorsel->color_picker);
273 printf("raising the curtain \n");
274
275 gtk_container_add(GTK_CONTAINER(options_frame), options_vbox);
276 gtk_widget_show(options_vbox);
277
278 gtk_box_pack_start(GTK_BOX(vbox), options_frame, TRUE, TRUE, 0);
279 gtk_widget_show(options_frame);
280
281 bbox = gtk_hbutton_box_new();
282 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
283 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
284 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
285
286 ok = gtk_button_new_with_label("Ok");
287 gtk_signal_connect(GTK_OBJECT(ok), "clicked", GTK_SIGNAL_FUNC(signal_colorselector_ok), cvar);
288 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT);
289 gtk_box_pack_start(GTK_BOX(bbox), ok, TRUE, TRUE, 0);
290 gtk_widget_show(ok);
291
292
293 cancel = gtk_button_new_with_label("Cancel");
294 gtk_signal_connect(GTK_OBJECT(cancel), "clicked", GTK_SIGNAL_FUNC(signal_colorselector_cancel), cvar);
295 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT);
296 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0);
297 gtk_widget_show(cancel);
298 gtk_widget_show(bbox);
299
300 gtk_container_add(GTK_CONTAINER(colorsel->window), vbox);
301 gtk_widget_show(vbox);
302 gtk_widget_grab_default(ok);
303 }
304
305 void frontend_create_color_button(struct config_value* cvar, GtkWidget *container, char *name,
306 char *channel_name)
307 {
308 struct rootvis_colorsel *color_struct;
309
310 print_status("Allocating memory for color struct");
311 color_struct = malloc(sizeof(struct rootvis_colorsel));
312 cvar->valc.frontend = color_struct;
313
314 frontend_set_color(cvar);
315 color_struct->window = NULL;
316 color_struct->name = name; //complete_name;
317
318 print_status("reallocating name");
319 color_struct->complete_name =
320 malloc((sizeof(name) + sizeof(channel_name) + 10)*sizeof(char));
321 print_status("done");
322 sprintf(color_struct->complete_name, "%s - %s", channel_name, name);
323 print_status("done");
324
325
326 char* labeltext = (char*)malloc(strlen(name) + 2);
327 sprintf(labeltext, "%s:", name);
328 color_struct->label = gtk_label_new(labeltext);
329 gtk_container_add(GTK_CONTAINER(container), GTK_WIDGET(color_struct->label));
330
331 color_struct->button = gtk_button_new();
332 print_status("adding container ... ");
333 gtk_container_add(GTK_CONTAINER(container), GTK_WIDGET(color_struct->button));
334 print_status("done.\nraising ... ");
335
336 print_status("done.\nmaking preview ... ");
337
338 color_struct->preview = gtk_preview_new(GTK_PREVIEW_COLOR);
339 print_status("done.\nsetting size ... ");
340 gtk_preview_size(GTK_PREVIEW(color_struct->preview), 30, 28);
341 print_status("done.\nraising ... ");
342 print_status("done.\n");
343 gtk_container_add(GTK_CONTAINER(color_struct->button), color_struct->preview);
344
345 gtk_widget_set_usize(color_struct->button, 32, 26);
346
347 gtk_signal_connect(GTK_OBJECT(color_struct->button), "clicked",
348 GTK_SIGNAL_FUNC(signal_toggle_colorselector), cvar);
349
350 frontend_update_color(cvar, 0);
351 gtk_widget_show(GTK_WIDGET(color_struct->label));
352 gtk_widget_show(GTK_WIDGET(color_struct->button));
353 gtk_widget_show(color_struct->preview);
354 }
355
356 GtkWidget *frontend_create_channel(int channel)
357 {
358 GtkWidget *window;
359 char name[12];
360
361 print_status("creating gtk window ... ");
362
363 sprintf(name, "Channel %d", channel+1);
364 print_status(name);
365
366 print_status("debug 2");
367
368 window = frontend_create_window(GTK_WINDOW_TOPLEVEL, &name);
369
370 print_status("done.");
371
372 {
373 GtkWidget *vbox_0, *notebook_1, *button_box_1,
374 *vbox_2[4], *frame_3[4], *vbox_3[1], *hbox_4[5],
375 *check_debug, *check_stereo,
376 *close_button, *revert_button;
377
378 vbox_0 = frontend_create_box(VBOX, window, "rootvis_config_vbox", ATTACH_TO_CONTAINER);
379 {
380
381 notebook_1 = frontend_create_notebook(vbox_0);
382 {
383 /* vbox_2[0] = frontend_create_box(VBOX, notebook_1, "General", ATTACH_TO_NOTEBOOK);
384 {
385 }
386 vbox_2[1] = frontend_create_box(VBOX, notebook_1, "Geometry", ATTACH_TO_NOTEBOOK);
387 {
388 }
389 vbox_2[2] = frontend_create_box(VBOX, notebook_1, "Look & Feel", ATTACH_TO_NOTEBOOK);
390 {
391 }*/
392 vbox_2[3] = frontend_create_box(VBOX, notebook_1, "Colors", ATTACH_TO_NOTEBOOK);
393 {
394 frame_3[0] = frontend_create_box(FRAME, vbox_2[3], "Gradient", ATTACH_TO_BOX);
395 hbox_4[0] = frontend_create_box(HBOX, frame_3[0], "Bar", ATTACH_TO_CONTAINER);
396 {
397 frontend_create_color_button(&Cchannel[channel].def[11], hbox_4[0], "Begin", name);
398 frontend_create_color_button(&Cchannel[channel].def[12], hbox_4[0], "2/5", name);
399 frontend_create_color_button(&Cchannel[channel].def[13], hbox_4[0], "4/5", name);
400 frontend_create_color_button(&Cchannel[channel].def[14], hbox_4[0], "End", name);
401 }
402 frame_3[1] = frontend_create_box(FRAME, vbox_2[3], "Bevel, Peaks & Shadow", ATTACH_TO_BOX);
403 hbox_4[1] = frontend_create_box(HBOX, frame_3[1], "etc", ATTACH_TO_CONTAINER);
404 {
405 frontend_create_color_button(&Cchannel[channel].def[15], hbox_4[1], "Bevel", name);
406 frontend_create_color_button(&Cchannel[channel].def[20], hbox_4[1], "Peaks", name);
407 frontend_create_color_button(&Cchannel[channel].def[16], hbox_4[1], "Shadow", name);
408 }
409 }
410 }
411
412
413 button_box_1 = frontend_create_box(HBBOX2, vbox_0, "Button Box", ATTACH_TO_BOX);
414 {
415 revert_button = frontend_create_button(button_box_1, "Revert");
416 frontend_set_signal(revert_button, "clicked", signal_revert, channel);
417 close_button = frontend_create_button(button_box_1, "Close");
418 frontend_set_signal(close_button, "clicked", signal_hide, channel);
419 }
420 }
421 }
422 config_set_widgets(channel);
423 return window;
424 }
425
426 GtkWidget *frontend_create_main(void)
427 {
428 GtkWidget *window, *channel_button[2],
429 *button_box[2], *channels_frame, *main_frame, *vbox,
430 *main_vbox, *channels_hbox, *channel_vbox[2],
431 *save_button, *revert_button, *close_button;
432
433 window = frontend_create_window(GTK_WINDOW_TOPLEVEL, "Main");
434 {
435 vbox = frontend_create_box(VBOX, window, "vbox", ATTACH_TO_CONTAINER);
436 {
437 main_frame = frontend_create_box(FRAME, vbox, "Global Settings", ATTACH_TO_BOX);
438 {
439 main_vbox = frontend_create_box(VBOX, main_frame, "main_hbox",
440 ATTACH_TO_CONTAINER);
441
442 widgets.stereo_check = frontend_create_check(main_vbox, "stereo support");
443 frontend_set_signal(widgets.stereo_check, "toggled", signal_stereo_toggled, 0);
444 widgets.debug_check = frontend_create_check(main_vbox, "debug messages (stdout)");
445 frontend_set_signal(widgets.debug_check, "toggled", signal_check_toggled, 0);
446
447 }
448 channels_frame = frontend_create_box(FRAME, vbox, "Channel-specific",
449 ATTACH_TO_BOX);
450 {
451 button_box[0] = frontend_create_box(HBOX, channels_frame, "Main Button Box",
452 ATTACH_TO_CONTAINER);
453 {
454 channel_vbox[0] = frontend_create_box(VBOX, button_box[0], "channel_vbox_0",
455 ATTACH_TO_CONTAINER);
456 {
457 channel_button[0] = frontend_create_button(channel_vbox[0], "First Channel");
458 frontend_set_signal(channel_button[0], "clicked", signal_show, 0);
459 widgets.stereo_status[0] = frontend_create_label(channel_vbox[0], "renders both channels");
460 }
461 channel_vbox[1] = frontend_create_box(VBOX, button_box[0], "channel_vbox_0",
462 ATTACH_TO_CONTAINER);
463 {
464
465 channel_button[1] = frontend_create_button(channel_vbox[1], "Second Channel");
466 frontend_set_signal(channel_button[1], "clicked", signal_show, 1);
467 widgets.stereo_status[1] = frontend_create_label(channel_vbox[1], "unused / inactive");
468 }
469 }
470 }
471 button_box[1] = frontend_create_box(HBBOX, vbox, "Button Box", ATTACH_TO_BOX);
472 {
473
474 revert_button = frontend_create_button(button_box[1], "Revert All");
475 frontend_set_signal(revert_button, "clicked", signal_revert, 2);
476 save_button = frontend_create_button(button_box[1], "Save Settings");
477 frontend_set_signal(save_button, "clicked", signal_save, 2);
478 close_button = frontend_create_button(button_box[1], "Close Windows");
479 frontend_set_signal(close_button, "clicked", signal_hide, 2);
480
481 }
482 }
483 }
484 config_set_widgets(2);
485 return window;
486 }