Clean code and added a few amendments (if()).
[irreco.git] / irreco / src / core / irreco_cmd_dlg.c
blob39ee727cbf7d688c7277b88793393d9dea2546fb
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_cmd_dlg.h"
21 #include "irreco_backend_dlg.h"
22 #include "irreco_backend_instance.h"
24 /**
25 * @addtogroup IrrecoCmdDlg
26 * @ingroup Irreco
28 * Show a dialog where the user can select one command from a list of all
29 * possible commands
31 * @{
34 /**
35 * @file
36 * Source file of @ref IrrecoCmdDlg.
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 /* Types and definitions. */
42 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
45 #define IRRECO_SELECT_CMD_DLG_BUTTON_ROW_WIDTH 600
46 #define IRRECO_SELECT_CMD_DLG_BUTTON_PAD 5
47 #define IRRECO_SELECT_CMD_DLG_EXPAND_BUTTONS FALSE
49 enum
51 IRRECO_RESPONCE_EDIT = 1,
52 IRRECO_RESPONCE_REFRESH,
53 IRRECO_RESPONCE_COMMAND_SET
56 typedef struct _IrrecoButtonAppend IrrecoButtonAppend;
57 struct _IrrecoButtonAppend {
58 GtkWidget *vbox;
59 GtkWidget *hbox;
60 uint width;
61 uint count;
64 typedef struct _IrrecoSelectCmdDlg IrrecoSelectCmdDlg;
65 struct _IrrecoSelectCmdDlg {
66 IrrecoData *irreco_data;
67 IrrecoCmd *command;
68 GtkWidget *dialog;
69 GtkWidget *scrolled;
70 GtkWidget *vbox;
75 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
76 /* Prototypes. */
77 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
80 void irreco_cmd_dlg_create_command_list(IrrecoSelectCmdDlg * cmd_dlg);
81 void irreco_cmd_dlg_setup_scrollbars(GtkWidget * widget);
82 void irreco_cmd_dlg_append_device(IrrecoSelectCmdDlg * cmd_dlg,
83 IrrecoBackendDevice * device);
84 void irreco_cmd_dlg_append_special(IrrecoSelectCmdDlg * cmd_dlg);
85 void irreco_cmd_dlg_append_wait_button(IrrecoSelectCmdDlg * cmd_dlg,
86 IrrecoButtonAppend * button_append,
87 uint delay);
88 GtkWidget *irreco_cmd_dlg_append_hbox(GtkWidget *vbox,
89 guint padding_between,
90 guint padding_top,
91 guint padding_bottom,
92 guint padding_left,
93 guint padding_right,
94 gfloat x_expand_scale,
95 gfloat y_expand_scale);
96 GtkWidget *irreco_cmd_dlg_append_title_hbox(GtkWidget *vbox);
97 GtkWidget *irreco_cmd_dlg_append_command_hbox(GtkWidget *vbox);
98 void irreco_cmd_dlg_append_button_init(IrrecoButtonAppend * data,
99 GtkWidget *vbox);
100 GtkWidget *irreco_cmd_dlg_append_button(IrrecoButtonAppend * data,
101 const gchar *tite);
105 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
106 /* Run. */
107 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
110 * @name Run
111 * @{
115 gboolean irreco_cmd_dlg_run(IrrecoData *irreco_data, IrrecoCmd * command,
116 GtkWindow *parent)
118 IrrecoSelectCmdDlg cmd_dlg;
119 gint rvalue = -1;
120 IRRECO_ENTER
122 memset(&cmd_dlg, '\0', sizeof(cmd_dlg));
123 cmd_dlg.irreco_data = irreco_data;
124 cmd_dlg.command = command;
126 /* Create objects. */
127 cmd_dlg.dialog = gtk_dialog_new_with_buttons(
128 _("Select command"), parent,
129 /*irreco_window_manager_get_gtk_window(
130 irreco_data->window_manager),*/
131 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT /* |
132 GTK_DIALOG_NO_SEPARATOR*/,
133 _("Refresh"), IRRECO_RESPONCE_REFRESH,
134 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
135 /*_("Device controllers"), IRRECO_RESPONCE_EDIT,*/
136 NULL);
137 cmd_dlg.scrolled = gtk_scrolled_window_new(0, 0);
139 /* Construct dialog. */
140 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(cmd_dlg.scrolled),
141 GTK_POLICY_NEVER,
142 GTK_POLICY_AUTOMATIC);
143 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(cmd_dlg.dialog)->vbox),
144 cmd_dlg.scrolled);
145 irreco_cmd_dlg_create_command_list(&cmd_dlg);
147 /* Scrollbar setup signal. */
148 g_signal_connect(G_OBJECT(cmd_dlg.scrolled), "size-allocate",
149 G_CALLBACK(irreco_cmd_dlg_setup_scrollbars),
150 NULL);
152 /* Min width, max height. */
153 gtk_window_resize(GTK_WINDOW(cmd_dlg.dialog), 1, 999);
154 gtk_widget_show_all(cmd_dlg.dialog);
156 while (rvalue == -1) {
157 switch (gtk_dialog_run(GTK_DIALOG(cmd_dlg.dialog))) {
158 case GTK_RESPONSE_REJECT:
159 rvalue = FALSE;
160 break;
162 case IRRECO_RESPONCE_COMMAND_SET:
163 rvalue = TRUE;
164 break;
166 case IRRECO_RESPONCE_EDIT:
167 irreco_show_backend_dlg(irreco_data,
168 GTK_WINDOW(cmd_dlg.dialog));
169 irreco_cmd_dlg_create_command_list(&cmd_dlg);
170 break;
172 case IRRECO_RESPONCE_REFRESH:
173 irreco_backend_manager_get_devcmd_lists(
174 irreco_data->irreco_backend_manager);
175 irreco_cmd_dlg_create_command_list(&cmd_dlg);
176 break;
180 gtk_widget_destroy(cmd_dlg.dialog);
181 IRRECO_RETURN_INT(rvalue);
184 void irreco_cmd_dlg_create_command_list(IrrecoSelectCmdDlg * cmd_dlg)
186 IRRECO_ENTER
187 if (cmd_dlg->vbox != NULL) {
188 gtk_widget_destroy(cmd_dlg->vbox);
190 cmd_dlg->vbox = gtk_vbox_new(FALSE, 0);
191 gtk_scrolled_window_add_with_viewport(
192 GTK_SCROLLED_WINDOW(cmd_dlg->scrolled), cmd_dlg->vbox);
194 /* Iterate trough instance, device and command arrays. */
195 IRRECO_DEBUG("Generating command list\n");
196 IRRECO_BACKEND_MANAGER_FOREACH_INSTANCE(
197 cmd_dlg->irreco_data->irreco_backend_manager, instance)
198 IRRECO_DEBUG("Instance: \"%s\"\n", instance->name);
199 IRRECO_BACKEND_INSTANCE_FOREACH(instance, device)
200 IRRECO_DEBUG("Device: \"%s\"\n", device->name);
201 irreco_cmd_dlg_append_device(cmd_dlg, device);
202 IRRECO_BACKEND_INSTANCE_FOREACH_END
203 IRRECO_STRING_TABLE_FOREACH_END
205 IRRECO_DEBUG("Special commands.\n");
206 irreco_cmd_dlg_append_special(cmd_dlg);
207 gtk_widget_show_all(cmd_dlg->dialog);
209 IRRECO_RETURN
212 /** @} */
216 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
217 /* Signal handlers. */
218 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
221 * @name Signal handlers
222 * @{
226 void irreco_cmd_dlg_set_built_in(GtkButton * button,
227 IrrecoSelectCmdDlg * cmd_dlg)
229 gpointer type;
230 IRRECO_ENTER
232 type = g_object_get_data(G_OBJECT(button), "IrrecoCmdType");
233 irreco_cmd_set_builtin(cmd_dlg->command, (IrrecoCmdType) type);
234 gtk_dialog_response(GTK_DIALOG(cmd_dlg->dialog),
235 IRRECO_RESPONCE_COMMAND_SET);
237 IRRECO_RETURN
240 void irreco_cmd_dlg_set_layout(GtkButton * button,
241 IrrecoSelectCmdDlg * cmd_dlg)
243 gpointer name;
244 IRRECO_ENTER
246 name = g_object_get_data(G_OBJECT(button), "IrrecoCmdLayout");
247 irreco_cmd_set_layout(cmd_dlg->command, (const gchar *) name);
248 gtk_dialog_response(GTK_DIALOG(cmd_dlg->dialog),
249 IRRECO_RESPONCE_COMMAND_SET);
251 IRRECO_RETURN
254 void irreco_cmd_dlg_set_backend(GtkButton * button,
255 IrrecoSelectCmdDlg * cmd_dlg)
257 IrrecoBackendDevice *device;
258 const gchar *command;
259 IRRECO_ENTER
261 device = (IrrecoBackendDevice *) g_object_get_data(
262 G_OBJECT(button), "IrrecoCmdBackendDevice");
263 command = (const gchar *) g_object_get_data(
264 G_OBJECT(button), "IrrecoCmdBackendCommand");
265 irreco_cmd_set_backend(cmd_dlg->command,
266 device->backend_instance,
267 device->name,
268 command);
269 gtk_dialog_response(GTK_DIALOG(cmd_dlg->dialog),
270 IRRECO_RESPONCE_COMMAND_SET);
272 IRRECO_RETURN
275 void irreco_cmd_dlg_set_wait(GtkButton * button, IrrecoSelectCmdDlg * cmd_dlg)
277 gpointer delay;
278 IRRECO_ENTER
280 delay = g_object_get_data(G_OBJECT(button), "IrrecoCmdWaitDelay");
281 irreco_cmd_set_wait(cmd_dlg->command, (gulong) delay);
282 gtk_dialog_response(GTK_DIALOG(cmd_dlg->dialog),
283 IRRECO_RESPONCE_COMMAND_SET);
285 IRRECO_RETURN
289 * Set up scrollbars so that a tap on the scrollbar will scroll almost one
290 * screen worth of space.
292 void irreco_cmd_dlg_setup_scrollbars(GtkWidget * widget)
294 GtkAdjustment *adjustment;
295 IRRECO_ENTER
297 adjustment = gtk_scrolled_window_get_vadjustment(
298 GTK_SCROLLED_WINDOW(widget));
299 adjustment->step_increment = adjustment->page_size * 0.65;
300 adjustment->page_increment = adjustment->page_size * 0.65;
302 IRRECO_DEBUG("value %f\n", adjustment->value);
303 IRRECO_DEBUG("lower %f\n", adjustment->lower);
304 IRRECO_DEBUG("upper %f\n", adjustment->upper);
305 IRRECO_DEBUG("step_increment %f\n", adjustment->step_increment);
306 IRRECO_DEBUG("page_increment %f\n", adjustment->page_increment);
307 IRRECO_DEBUG("page_size %f\n", adjustment->page_size);
309 IRRECO_RETURN
312 /** @} */
316 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
317 /* Dialog construction. */
318 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
321 * @name Dialog construction
322 * @{
326 void irreco_cmd_dlg_append_commands(IrrecoSelectCmdDlg * cmd_dlg,
327 IrrecoBackendDevice * device)
329 IrrecoButtonAppend button_append;
330 GtkWidget *button;
331 IRRECO_ENTER
333 irreco_cmd_dlg_append_button_init(&button_append, cmd_dlg->vbox);
334 IRRECO_BACKEND_DEVICE_FOREACH(device, command)
335 button = irreco_cmd_dlg_append_button(&button_append,
336 command);
337 g_object_set_data(G_OBJECT(button),
338 "IrrecoCmdBackendDevice",
339 (gpointer) device);
340 g_object_set_data(G_OBJECT(button),
341 "IrrecoCmdBackendCommand",
342 (gpointer) command);
343 g_signal_connect(G_OBJECT(button), "clicked",
344 G_CALLBACK(irreco_cmd_dlg_set_backend),
345 cmd_dlg);
346 IRRECO_BACKEND_DEVICE_FOREACH_END
347 IRRECO_RETURN
350 void irreco_cmd_dlg_append_device(IrrecoSelectCmdDlg * cmd_dlg,
351 IrrecoBackendDevice * device)
353 GtkWidget *hbox;
354 GtkWidget *arrow;
355 GtkWidget *arrow_align;
356 GtkWidget *device_label;
357 GtkWidget *instance_label;
358 IRRECO_ENTER
360 hbox = irreco_cmd_dlg_append_title_hbox(cmd_dlg->vbox);
361 arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
362 arrow_align = gtk_alignment_new(0.5, 0.5, 1, 1);
363 device_label = gtk_label_new(device->name);
364 instance_label = gtk_label_new(device->backend_instance->name);
367 instance_label = gtk_label_new(
368 irreco_backend_instance_get_name_and_description(
369 device->backend_instance));
372 /* Arrow: 25px width, auto height, 5px padding left and right.*/
373 gtk_widget_set_size_request(arrow, 25, 0);
374 gtk_misc_set_alignment(GTK_MISC(arrow), 0.5, 0.5);
375 gtk_alignment_set_padding(GTK_ALIGNMENT(arrow_align), 0, 0, 8, 8);
377 gtk_misc_set_alignment(GTK_MISC(device_label), 0, 0.5);
378 gtk_misc_set_alignment(GTK_MISC(instance_label), 0, 0.5);
380 gtk_container_add(GTK_CONTAINER(arrow_align), arrow);
381 gtk_box_pack_start(GTK_BOX(hbox), instance_label, 0, 0, 0);
382 gtk_box_pack_start(GTK_BOX(hbox), arrow_align, 0, 0, 0);
383 gtk_box_pack_start(GTK_BOX(hbox), device_label, 0, 0, 0);
385 if (irreco_backend_device_is_empty(device)) {
386 GtkWidget *label = gtk_label_new(_("This device does not "
387 "have any commands."));
388 hbox = irreco_cmd_dlg_append_command_hbox(cmd_dlg->vbox);
389 gtk_box_pack_start_defaults(GTK_BOX(hbox), label);
390 } else {
391 /*GtkWidget *command_vbox = gtk_vbox_new(FALSE, 10);*/
392 irreco_cmd_dlg_append_commands(cmd_dlg, device);
395 IRRECO_RETURN
400 void irreco_cmd_dlg_append_special(IrrecoSelectCmdDlg * cmd_dlg)
402 GtkWidget *hbox;
403 GtkWidget *label;
404 GtkWidget *button;
405 IrrecoButtonAppend button_append;
406 GString *string;
407 IRRECO_ENTER
409 hbox = irreco_cmd_dlg_append_title_hbox(cmd_dlg->vbox);
410 label = gtk_label_new(_("Special commands"));
411 gtk_box_pack_start(GTK_BOX(hbox), label, 0, 0, 0);
413 /* Create next remote button. */
414 irreco_cmd_dlg_append_button_init(&button_append, cmd_dlg->vbox);
415 button = irreco_cmd_dlg_append_button(
416 &button_append, _(IRRECO_COMMAND_NEXT_REMOTE_TITLE));
417 g_object_set_data(G_OBJECT(button), "IrrecoCmdType",
418 (gpointer) IRRECO_COMMAND_NEXT_REMOTE);
419 g_signal_connect(G_OBJECT(button), "clicked",
420 G_CALLBACK(irreco_cmd_dlg_set_built_in),
421 cmd_dlg);
423 /* Create previous remote button. */
424 button = irreco_cmd_dlg_append_button(
425 &button_append, _(IRRECO_COMMAND_PREVIOUS_REMOTE_TITLE));
426 g_object_set_data(G_OBJECT(button), "IrrecoCmdType",
427 (gpointer) IRRECO_COMMAND_PREVIOUS_REMOTE);
428 g_signal_connect(G_OBJECT(button), "clicked",
429 G_CALLBACK(irreco_cmd_dlg_set_built_in),
430 cmd_dlg);
432 /* Fullscreen toggle button. */
433 button = irreco_cmd_dlg_append_button(
434 &button_append, _(IRRECO_COMMAND_FULLSCREEN_TOGGLE_TITLE));
435 g_object_set_data(G_OBJECT(button), "IrrecoCmdType",
436 (gpointer) IRRECO_COMMAND_FULLSCREEN_TOGGLE);
437 g_signal_connect(G_OBJECT(button), "clicked",
438 G_CALLBACK(irreco_cmd_dlg_set_built_in),
439 cmd_dlg);
441 /* Create show remote buttons. */
442 string = g_string_new("");
443 IRRECO_STRING_TABLE_FOREACH_KEY(
444 cmd_dlg->irreco_data->irreco_layout_array, layout_name)
445 g_string_append(g_string_set_size(string, 0),
446 _(IRRECO_COMMAND_SHOW_LAYOUT_TITLE_PREFIX));
447 g_string_append(string, layout_name);
448 button = irreco_cmd_dlg_append_button(&button_append,
449 string->str);
450 g_object_set_data(G_OBJECT(button), "IrrecoCmdLayout",
451 (gpointer) layout_name);
452 g_signal_connect(G_OBJECT(button), "clicked",
453 G_CALLBACK(irreco_cmd_dlg_set_layout),
454 cmd_dlg);
455 IRRECO_STRING_TABLE_FOREACH_END
456 g_string_free(string, TRUE);
458 /* Append wait buttons. */
459 irreco_cmd_dlg_append_wait_button(cmd_dlg, &button_append,
460 IRRECO_SECONDS_TO_USEC(0.3));
461 irreco_cmd_dlg_append_wait_button(cmd_dlg, &button_append,
462 IRRECO_SECONDS_TO_USEC(0.6));
463 irreco_cmd_dlg_append_wait_button(cmd_dlg, &button_append,
464 IRRECO_SECONDS_TO_USEC(1));
465 irreco_cmd_dlg_append_wait_button(cmd_dlg, &button_append,
466 IRRECO_SECONDS_TO_USEC(1.5));
467 irreco_cmd_dlg_append_wait_button(cmd_dlg, &button_append,
468 IRRECO_SECONDS_TO_USEC(2));
469 irreco_cmd_dlg_append_wait_button(cmd_dlg, &button_append,
470 IRRECO_SECONDS_TO_USEC(3));
471 irreco_cmd_dlg_append_wait_button(cmd_dlg, &button_append,
472 IRRECO_SECONDS_TO_USEC(5));
473 irreco_cmd_dlg_append_wait_button(cmd_dlg, &button_append,
474 IRRECO_SECONDS_TO_USEC(7));
475 irreco_cmd_dlg_append_wait_button(cmd_dlg, &button_append,
476 IRRECO_SECONDS_TO_USEC(10));
477 IRRECO_RETURN
480 void irreco_cmd_dlg_append_wait_button(IrrecoSelectCmdDlg * cmd_dlg,
481 IrrecoButtonAppend * button_append,
482 uint delay)
484 GtkWidget *button;
485 IrrecoCmd *command;
486 IRRECO_ENTER
488 /* Set title. */
489 command = irreco_cmd_create();
490 irreco_cmd_set_wait(command, delay);
491 button = irreco_cmd_dlg_append_button(
492 button_append, irreco_cmd_get_short_name(command));
493 irreco_cmd_destroy(command);
495 /* Set title.
496 string = g_string_new(NULL);
497 g_string_printf(string, _(IRRECO_COMMAND_WAIT_TITLE_FORMAT),
498 (float)(delay) / 1000);
500 g_string_free(string, TRUE);
503 /* Set callback. */
504 g_object_set_data(G_OBJECT(button), "IrrecoCmdWaitDelay",
505 (gpointer) delay);
506 g_signal_connect(G_OBJECT(button), "clicked",
507 G_CALLBACK(irreco_cmd_dlg_set_wait),
508 cmd_dlg);
509 IRRECO_RETURN
512 /** @} */
516 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
517 /* GtkHBox utility functions. */
518 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
521 * @name GtkHBox utility functions
522 * @{
526 GtkWidget *irreco_cmd_dlg_append_hbox(GtkWidget * vbox,
527 guint padding_between,
528 guint padding_top,
529 guint padding_bottom,
530 guint padding_left,
531 guint padding_right,
532 gfloat x_expand_scale,
533 gfloat y_expand_scale)
535 GtkWidget *hbox;
536 GtkWidget *align;
537 IRRECO_ENTER
539 hbox = gtk_hbox_new(FALSE, padding_between);
540 align = irreco_gtk_align(hbox, 0, 0, x_expand_scale, y_expand_scale,
541 padding_top, padding_bottom, padding_left,
542 padding_right);
543 gtk_box_pack_start(GTK_BOX(vbox), align, 0, 0, 0);
544 IRRECO_RETURN_PTR(hbox);
547 void irreco_cmd_dlg_append_separator(GtkWidget * vbox,
548 guint padding_top,
549 guint padding_bottom)
551 GtkWidget *align;
552 IRRECO_ENTER
554 align = irreco_gtk_align(gtk_hseparator_new(), 0, 0, 1, 1,
555 padding_top, padding_bottom, 20, 0);
556 gtk_box_pack_start(GTK_BOX(vbox), align, 0, 0, 0);
557 IRRECO_RETURN
560 GtkWidget *irreco_cmd_dlg_append_title_hbox(GtkWidget * vbox)
562 GtkWidget* hbox;
563 IRRECO_ENTER
565 hbox = irreco_cmd_dlg_append_hbox(vbox,
566 0, /*padding_between */
567 15, /*padding_top */
568 0, /*padding_bottom */
569 25, /*padding_left */
570 20, /*padding_right */
571 0, /* x_expand_scale */
572 0 /* y_expand_scale */
574 irreco_cmd_dlg_append_separator(vbox, 2, 6);
575 IRRECO_RETURN_PTR(hbox);
578 GtkWidget *irreco_cmd_dlg_append_command_hbox(GtkWidget * vbox)
580 return irreco_cmd_dlg_append_hbox(vbox,
581 IRRECO_SELECT_CMD_DLG_BUTTON_PAD, /* padding_between */
582 0, /* padding_top */
583 IRRECO_SELECT_CMD_DLG_BUTTON_PAD, /* padding_bottom */
584 25, /* padding_left */
585 20, /* padding_right */
586 IRRECO_SELECT_CMD_DLG_EXPAND_BUTTONS, /* x_expand_scale */
587 0 /* y_expand_scale */
591 /** @} */
595 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
596 /* Button adding to button rows. */
597 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
600 * @name Button adding to button rows
601 * @{
606 * Initialize IrrecoButtonAppend structure.
608 * There is no need to clean IrrecoButtonAppend structure because all
609 * created widgets will be attached to the vbox.
611 void irreco_cmd_dlg_append_button_init(IrrecoButtonAppend * data,
612 GtkWidget *vbox)
614 IRRECO_ENTER
615 data->vbox = vbox;
616 data->hbox = irreco_cmd_dlg_append_command_hbox(vbox);
617 data->width = 0;
618 data->count = 0;
619 IRRECO_RETURN
623 * Add a button to button row. Creates a new button row if current is full.
625 * Returns: a new GtkButton.
627 GtkWidget *irreco_cmd_dlg_append_button(IrrecoButtonAppend * data,
628 const gchar * title)
630 GtkWidget *button;
631 GtkRequisition requisition;
632 IRRECO_ENTER
634 /* Because you cant get widget data->width without adding it to a
635 container, this code does thing a bit backwards. */
636 button = gtk_button_new_with_label(title);
637 gtk_box_pack_start_defaults(GTK_BOX(data->hbox), button);
638 gtk_widget_size_request(GTK_WIDGET(button), &requisition);
639 data->width += requisition.width + IRRECO_SELECT_CMD_DLG_BUTTON_PAD;
641 /* If we have too much buttons on one row, destroy button,
642 and create another button on a new row. */
643 if (data->width > IRRECO_SELECT_CMD_DLG_BUTTON_ROW_WIDTH
644 && data->count > 0) {
645 gtk_widget_destroy(button);
646 data->count = 0;
647 data->width = requisition.width +
648 IRRECO_SELECT_CMD_DLG_BUTTON_PAD;
649 data->hbox = irreco_cmd_dlg_append_command_hbox(data->vbox);
650 button = gtk_button_new_with_label(title);
651 gtk_box_pack_start_defaults(GTK_BOX(data->hbox), button);
654 data->count += 1;
655 IRRECO_RETURN_PTR(button);
658 /** @} */
659 /** @} */