2 * Copyright (C) 2006 Nokia Corporation.
3 * Author: Xan Lopez <xan.lopez@nokia.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * version 2.1 as published by the Free Software Foundation.
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
23 GtkWidget *bbox = NULL;
24 GtkWidget *hbbox = NULL, *vbbox = NULL;
26 static const char* styles[] = { "GTK_BUTTONBOX_DEFAULT_STYLE",
27 "GTK_BUTTONBOX_SPREAD",
29 "GTK_BUTTONBOX_START",
31 "GTK_BUTTONBOX_CENTER",
34 static const char* types[] = { "GtkHButtonBox",
39 populate_combo_with (GtkComboBoxText *combo, const char** elements)
43 for (i = 0; elements[i] != NULL; i++) {
44 gtk_combo_box_text_append_text (combo, elements[i]);
47 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
51 combo_changed_cb (GtkComboBoxText *combo,
57 text = gtk_combo_box_text_get_active_text (combo);
59 for (i = 0; styles[i]; i++) {
60 if (g_str_equal (text, styles[i])) {
61 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), (GtkButtonBoxStyle)i);
67 reparent_widget (GtkWidget *widget,
68 GtkWidget *old_parent,
69 GtkWidget *new_parent)
71 g_object_ref (widget);
72 gtk_container_remove (GTK_CONTAINER (old_parent), widget);
73 gtk_container_add (GTK_CONTAINER (new_parent), widget);
74 g_object_unref (widget);
78 combo_types_changed_cb (GtkComboBoxText *combo,
83 GtkWidget *old_parent, *new_parent;
84 GtkButtonBoxStyle style;
86 text = gtk_combo_box_text_get_active_text (combo);
88 if (g_str_equal (text, "GtkHButtonBox")) {
98 for (i = 0; i < N_BUTTONS; i++) {
99 reparent_widget (buttons[i], old_parent, new_parent);
102 gtk_widget_hide (old_parent);
103 style = gtk_button_box_get_layout (GTK_BUTTON_BOX (old_parent));
104 gtk_button_box_set_layout (GTK_BUTTON_BOX (new_parent), style);
105 gtk_widget_show (new_parent);
109 option_cb (GtkToggleButton *option,
112 gboolean active = gtk_toggle_button_get_active (option);
114 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (bbox),
118 static const char* strings[] = { "Ok", "Cancel", "Help" };
124 GtkWidget *window, *buttons[N_BUTTONS];
125 GtkWidget *vbox, *hbox, *combo_styles, *combo_types, *option;
128 gtk_init (&argc, &argv);
130 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
131 g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL);
133 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
134 gtk_container_add (GTK_CONTAINER (window), vbox);
138 hbbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
139 gtk_box_pack_start (GTK_BOX (vbox), hbbox, TRUE, TRUE, 5);
141 for (i = 0; i < N_BUTTONS; i++) {
142 buttons[i] = gtk_button_new_with_label (strings[i]);
143 gtk_container_add (GTK_CONTAINER (hbbox), buttons[i]);
149 vbbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
150 gtk_box_pack_start (GTK_BOX (vbox), vbbox, TRUE, TRUE, 5);
154 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
155 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
157 combo_types = gtk_combo_box_text_new ();
158 populate_combo_with (GTK_COMBO_BOX_TEXT (combo_types), types);
159 g_signal_connect (G_OBJECT (combo_types), "changed", G_CALLBACK (combo_types_changed_cb), buttons);
160 gtk_box_pack_start (GTK_BOX (hbox), combo_types, TRUE, TRUE, 0);
162 combo_styles = gtk_combo_box_text_new ();
163 populate_combo_with (GTK_COMBO_BOX_TEXT (combo_styles), styles);
164 g_signal_connect (G_OBJECT (combo_styles), "changed", G_CALLBACK (combo_changed_cb), NULL);
165 gtk_box_pack_start (GTK_BOX (hbox), combo_styles, TRUE, TRUE, 0);
167 option = gtk_check_button_new_with_label ("Help is secondary");
168 g_signal_connect (G_OBJECT (option), "toggled", G_CALLBACK (option_cb), buttons[N_BUTTONS - 1]);
170 gtk_box_pack_start (GTK_BOX (hbox), option, FALSE, FALSE, 0);
172 gtk_widget_show_all (window);
173 gtk_widget_hide (vbbox);