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
25 GtkWidget
*bbox
= NULL
;
26 GtkWidget
*hbbox
= NULL
, *vbbox
= NULL
;
28 static const char* styles
[] = { "GTK_BUTTONBOX_DEFAULT_STYLE",
29 "GTK_BUTTONBOX_SPREAD",
31 "GTK_BUTTONBOX_START",
33 "GTK_BUTTONBOX_CENTER",
36 static const char* types
[] = { "GtkHButtonBox",
41 populate_combo_with (GtkComboBox
*combo
, const char** elements
)
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);
53 combo_changed_cb (GtkComboBox
*combo
,
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
);
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
);
80 combo_types_changed_cb (GtkComboBox
*combo
,
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")) {
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
);
111 option_cb (GtkToggleButton
*option
,
114 gboolean active
= gtk_toggle_button_get_active (option
);
116 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (bbox
),
120 static const char* strings
[] = { "Ok", "Cancel", "Help" };
126 GtkWidget
*window
, *buttons
[N_BUTTONS
];
127 GtkWidget
*vbox
, *hbox
, *combo_styles
, *combo_types
, *option
;
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
);
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
]);
151 vbbox
= gtk_vbutton_box_new ();
152 gtk_box_pack_start (GTK_BOX (vbox
), vbbox
, TRUE
, TRUE
, 5);
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
);