1
2@c %start of fragment
3
4@node GtkToggleButton
5@chapter GtkToggleButton
6Create buttons which retain their state
7
8@section Overview
9A @code{<gtk-toggle-button>} is a @code{<gtk-button>} which will remain
10'pressed-in' when clicked. Clicking again will cause the toggle button to return
11to its normal state.
12
13A toggle button is created by calling either @code{gtk-toggle-button-new} or
14@code{gtk-toggle-button-new-with-label}. If using the former, it is advisable to
15pack a widget, (such as a @code{<gtk-label>} and/or a @code{<gtk-pixmap>}), into
16the toggle button's container. (See @code{<gtk-button>} for more information).
17
18The state of a @code{<gtk-toggle-button>} can be set specifically using
19@code{gtk-toggle-button-set-active}, and retrieved using
20@code{gtk-toggle-button-get-active}.
21
22To simply switch the state of a toggle button, use gtk_toggle_button_toggled.
23
24@example
25
26
27void make_toggles (void) @{
28   GtkWidget *dialog, *toggle1, *toggle2;
29
30   dialog = gtk_dialog_new ();
31   toggle1 = gtk_toggle_button_new_with_label ("Hi, i'm a toggle button.");
32
33   /* Makes this toggle button invisible */
34   gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle1), TRUE);
35
36   g_signal_connect (toggle1, "toggled",
37                     G_CALLBACK (output_state), NULL);
38   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
39                       toggle1, FALSE, FALSE, 2);
40
41   toggle2 = gtk_toggle_button_new_with_label ("Hi, i'm another toggle button.");
42   gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle2), FALSE);
43   g_signal_connect (toggle2, "toggled",
44                     G_CALLBACK (output_state), NULL);
45   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
46                       toggle2, FALSE, FALSE, 2);
47
48   gtk_widget_show_all (dialog);
49@}
50
51@end example
52
53@section Usage
54@include defuns-gtktogglebutton.xml.texi
55
56@c %end of fragment
57