Add powerbox hook
[gtk-with-powerbox.git] / tests / testbbox.c
blobe9a5de60028d41235c82ce4420ef2ced2ca6a32f
1 /*
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, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 * 02110-1301 USA
21 #include <gtk/gtk.h>
23 #define N_BUTTONS 3
25 GtkWidget *bbox = NULL;
26 GtkWidget *hbbox = NULL, *vbbox = NULL;
28 static const char* styles[] = { "GTK_BUTTONBOX_DEFAULT_STYLE",
29 "GTK_BUTTONBOX_SPREAD",
30 "GTK_BUTTONBOX_EDGE",
31 "GTK_BUTTONBOX_START",
32 "GTK_BUTTONBOX_END",
33 "GTK_BUTTONBOX_CENTER",
34 NULL};
36 static const char* types[] = { "GtkHButtonBox",
37 "GtkVButtonBox",
38 NULL};
40 static void
41 populate_combo_with (GtkComboBox *combo, const char** elements)
43 int i;
45 for (i = 0; elements[i] != NULL; i++) {
46 gtk_combo_box_append_text (combo, elements[i]);
49 gtk_combo_box_set_active (combo, 0);
52 static void
53 combo_changed_cb (GtkComboBox *combo,
54 gpointer user_data)
56 char *text;
57 int i;
59 text = gtk_combo_box_get_active_text (combo);
61 for (i = 0; styles[i]; i++) {
62 if (g_str_equal (text, styles[i])) {
63 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), (GtkButtonBoxStyle)i);
68 static void
69 reparent_widget (GtkWidget *widget,
70 GtkWidget *old_parent,
71 GtkWidget *new_parent)
73 g_object_ref (widget);
74 gtk_container_remove (GTK_CONTAINER (old_parent), widget);
75 gtk_container_add (GTK_CONTAINER (new_parent), widget);
76 g_object_unref (widget);
79 static void
80 combo_types_changed_cb (GtkComboBox *combo,
81 GtkWidget **buttons)
83 int i;
84 char *text;
85 GtkWidget *old_parent, *new_parent;
86 GtkButtonBoxStyle style;
88 text = gtk_combo_box_get_active_text (combo);
90 if (g_str_equal (text, "GtkHButtonBox")) {
91 old_parent = vbbox;
92 new_parent = hbbox;
93 } else {
94 old_parent = hbbox;
95 new_parent = vbbox;
98 bbox = new_parent;
100 for (i = 0; i < N_BUTTONS; i++) {
101 reparent_widget (buttons[i], old_parent, new_parent);
104 gtk_widget_hide (old_parent);
105 style = gtk_button_box_get_layout (GTK_BUTTON_BOX (old_parent));
106 gtk_button_box_set_layout (GTK_BUTTON_BOX (new_parent), style);
107 gtk_widget_show (new_parent);
110 static void
111 option_cb (GtkToggleButton *option,
112 GtkWidget *button)
114 gboolean active = gtk_toggle_button_get_active (option);
116 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (bbox),
117 button, active);
120 static const char* strings[] = { "Ok", "Cancel", "Help" };
123 main (int argc,
124 char **argv)
126 GtkWidget *window, *buttons[N_BUTTONS];
127 GtkWidget *vbox, *hbox, *combo_styles, *combo_types, *option;
128 int i;
130 gtk_init (&argc, &argv);
132 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
133 g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL);
135 vbox = gtk_vbox_new (FALSE, 0);
136 gtk_container_add (GTK_CONTAINER (window), vbox);
138 /* GtkHButtonBox */
140 hbbox = gtk_hbutton_box_new ();
141 gtk_box_pack_start (GTK_BOX (vbox), hbbox, TRUE, TRUE, 5);
143 for (i = 0; i < N_BUTTONS; i++) {
144 buttons[i] = gtk_button_new_with_label (strings[i]);
145 gtk_container_add (GTK_CONTAINER (hbbox), buttons[i]);
148 bbox = hbbox;
150 /* GtkVButtonBox */
151 vbbox = gtk_vbutton_box_new ();
152 gtk_box_pack_start (GTK_BOX (vbox), vbbox, TRUE, TRUE, 5);
154 /* Options */
156 hbox = gtk_hbox_new (FALSE, 0);
157 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
159 combo_types = gtk_combo_box_new_text ();
160 populate_combo_with (GTK_COMBO_BOX (combo_types), types);
161 g_signal_connect (G_OBJECT (combo_types), "changed", G_CALLBACK (combo_types_changed_cb), buttons);
162 gtk_box_pack_start (GTK_BOX (hbox), combo_types, TRUE, TRUE, 0);
164 combo_styles = gtk_combo_box_new_text ();
165 populate_combo_with (GTK_COMBO_BOX (combo_styles), styles);
166 g_signal_connect (G_OBJECT (combo_styles), "changed", G_CALLBACK (combo_changed_cb), NULL);
167 gtk_box_pack_start (GTK_BOX (hbox), combo_styles, TRUE, TRUE, 0);
169 option = gtk_check_button_new_with_label ("Help is secondary");
170 g_signal_connect (G_OBJECT (option), "toggled", G_CALLBACK (option_cb), buttons[N_BUTTONS - 1]);
172 gtk_box_pack_start (GTK_BOX (hbox), option, FALSE, FALSE, 0);
174 gtk_widget_show_all (window);
175 gtk_widget_hide (vbbox);
177 gtk_main ();
179 return 0;