Blame docs/tutorial/html/x518.html

Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>Toggle Buttons
Packit 98cdb6
>
Packit 98cdb6
NAME="GENERATOR"
Packit 98cdb6
CONTENT="Modular DocBook HTML Stylesheet Version 1.79">
Packit 98cdb6
REL="HOME"
Packit 98cdb6
TITLE="GTK+ 2.0 Tutorial"
Packit 98cdb6
HREF="book1.html">
Packit 98cdb6
REL="UP"
Packit 98cdb6
TITLE="The Button Widget"
Packit 98cdb6
HREF="c489.html">
Packit 98cdb6
REL="PREVIOUS"
Packit 98cdb6
TITLE="The Button Widget"
Packit 98cdb6
HREF="c489.html">
Packit 98cdb6
REL="NEXT"
Packit 98cdb6
TITLE="Check Buttons"
Packit 98cdb6
HREF="x535.html">
Packit 98cdb6
>
Packit 98cdb6
CLASS="SECT1"
Packit 98cdb6
BGCOLOR="#FFFFFF"
Packit 98cdb6
TEXT="#000000"
Packit 98cdb6
LINK="#0000FF"
Packit 98cdb6
VLINK="#840084"
Packit 98cdb6
ALINK="#0000FF"
Packit 98cdb6
>
Packit 98cdb6
CLASS="NAVHEADER"
Packit 98cdb6
>
Packit 98cdb6
SUMMARY="Header navigation table"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
BORDER="0"
Packit 98cdb6
CELLPADDING="0"
Packit 98cdb6
CELLSPACING="0"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
COLSPAN="3"
Packit 98cdb6
ALIGN="center"
Packit 98cdb6
>GTK+ 2.0 Tutorial
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="10%"
Packit 98cdb6
ALIGN="left"
Packit 98cdb6
VALIGN="bottom"
Packit 98cdb6
>
Packit 98cdb6
HREF="c489.html"
Packit 98cdb6
ACCESSKEY="P"
Packit 98cdb6
><<< Previous
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="80%"
Packit 98cdb6
ALIGN="center"
Packit 98cdb6
VALIGN="bottom"
Packit 98cdb6
>The Button Widget
Packit 98cdb6
>
Packit 98cdb6
WIDTH="10%"
Packit 98cdb6
ALIGN="right"
Packit 98cdb6
VALIGN="bottom"
Packit 98cdb6
>
Packit 98cdb6
HREF="x535.html"
Packit 98cdb6
ACCESSKEY="N"
Packit 98cdb6
>Next >>>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
ALIGN="LEFT"
Packit 98cdb6
WIDTH="100%">
Packit 98cdb6
>
Packit 98cdb6
CLASS="SECT1"
Packit 98cdb6
>
Packit 98cdb6
CLASS="SECT1"
Packit 98cdb6
>
Packit 98cdb6
NAME="SEC-TOGGLEBUTTONS"
Packit 98cdb6
>Toggle Buttons
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>Toggle buttons are derived from normal buttons and are very similar,
Packit 98cdb6
except they will always be in one of two states, alternated by a
Packit 98cdb6
click. They may be depressed, and when you click again, they will pop
Packit 98cdb6
back up. Click again, and they will pop back down.
Packit 98cdb6
>
Packit 98cdb6
>Toggle buttons are the basis for check buttons and radio buttons, as
Packit 98cdb6
such, many of the calls used for toggle buttons are inherited by radio
Packit 98cdb6
and check buttons. I will point these out when we come to them.
Packit 98cdb6
>
Packit 98cdb6
>Creating a new toggle button:
Packit 98cdb6
>
Packit 98cdb6
BORDER="0"
Packit 98cdb6
BGCOLOR="#E0E0E0"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="PROGRAMLISTING"
Packit 98cdb6
>GtkWidget *gtk_toggle_button_new( void );
Packit 98cdb6
Packit 98cdb6
GtkWidget *gtk_toggle_button_new_with_label( const gchar *label );
Packit 98cdb6
Packit 98cdb6
GtkWidget *gtk_toggle_button_new_with_mnemonic( const gchar *label );
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>As you can imagine, these work identically to the normal button widget
Packit 98cdb6
calls. The first creates a blank toggle button, and the last two, a
Packit 98cdb6
button with a label widget already packed into it. The _mnemonic() variant
Packit 98cdb6
additionally parses the label for '_'-prefixed mnemonic characters.
Packit 98cdb6
>
Packit 98cdb6
>To retrieve the state of the toggle widget, including radio and check
Packit 98cdb6
buttons, we use a construct as shown in our example below. This tests
Packit 98cdb6
the state of the toggle button, by accessing the 
Packit 98cdb6
CLASS="LITERAL"
Packit 98cdb6
>active
Packit 98cdb6
> field of the
Packit 98cdb6
toggle widget's structure, after first using the
Packit 98cdb6
Packit 98cdb6
CLASS="LITERAL"
Packit 98cdb6
>GTK_TOGGLE_BUTTON
Packit 98cdb6
> macro to cast the widget pointer into a toggle
Packit 98cdb6
widget pointer. The signal of interest to us emitted by toggle
Packit 98cdb6
buttons (the toggle button, check button, and radio button widgets) is
Packit 98cdb6
the "toggled" signal. To check the state of these buttons, set up a
Packit 98cdb6
signal handler to catch the toggled signal, and access the structure
Packit 98cdb6
to determine its state. The callback will look something like:
Packit 98cdb6
>
Packit 98cdb6
BORDER="0"
Packit 98cdb6
BGCOLOR="#E0E0E0"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="PROGRAMLISTING"
Packit 98cdb6
>void toggle_button_callback (GtkWidget *widget, gpointer data)
Packit 98cdb6
{
Packit 98cdb6
    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) 
Packit 98cdb6
    {
Packit 98cdb6
        /* If control reaches here, the toggle button is down */
Packit 98cdb6
    
Packit 98cdb6
    } else {
Packit 98cdb6
    
Packit 98cdb6
        /* If control reaches here, the toggle button is up */
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>To force the state of a toggle button, and its children, the radio and
Packit 98cdb6
check buttons, use this function:
Packit 98cdb6
>
Packit 98cdb6
BORDER="0"
Packit 98cdb6
BGCOLOR="#E0E0E0"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="PROGRAMLISTING"
Packit 98cdb6
>void gtk_toggle_button_set_active( GtkToggleButton *toggle_button,
Packit 98cdb6
                                   gboolean        is_active );
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>The above call can be used to set the state of the toggle button, and
Packit 98cdb6
its children the radio and check buttons. Passing in your created
Packit 98cdb6
button as the first argument, and a TRUE or FALSE for the second state
Packit 98cdb6
argument to specify whether it should be down (depressed) or up
Packit 98cdb6
(released). Default is up, or FALSE.
Packit 98cdb6
>
Packit 98cdb6
>Note that when you use the gtk_toggle_button_set_active() function, and
Packit 98cdb6
the state is actually changed, it causes the "clicked" and "toggled"
Packit 98cdb6
signals to be emitted from the button.
Packit 98cdb6
>
Packit 98cdb6
BORDER="0"
Packit 98cdb6
BGCOLOR="#E0E0E0"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="PROGRAMLISTING"
Packit 98cdb6
>gboolean gtk_toggle_button_get_active	(GtkToggleButton *toggle_button);
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>This returns the current state of the toggle button as a boolean
Packit 98cdb6
TRUE/FALSE value.
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="NAVFOOTER"
Packit 98cdb6
>
Packit 98cdb6
ALIGN="LEFT"
Packit 98cdb6
WIDTH="100%">
Packit 98cdb6
SUMMARY="Footer navigation table"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
BORDER="0"
Packit 98cdb6
CELLPADDING="0"
Packit 98cdb6
CELLSPACING="0"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="33%"
Packit 98cdb6
ALIGN="left"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>
Packit 98cdb6
HREF="c489.html"
Packit 98cdb6
ACCESSKEY="P"
Packit 98cdb6
><<< Previous
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="34%"
Packit 98cdb6
ALIGN="center"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>
Packit 98cdb6
HREF="book1.html"
Packit 98cdb6
ACCESSKEY="H"
Packit 98cdb6
>Home
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="33%"
Packit 98cdb6
ALIGN="right"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>
Packit 98cdb6
HREF="x535.html"
Packit 98cdb6
ACCESSKEY="N"
Packit 98cdb6
>Next >>>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="33%"
Packit 98cdb6
ALIGN="left"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>The Button Widget
Packit 98cdb6
>
Packit 98cdb6
WIDTH="34%"
Packit 98cdb6
ALIGN="center"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>
Packit 98cdb6
HREF="c489.html"
Packit 98cdb6
ACCESSKEY="U"
Packit 98cdb6
>Up
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="33%"
Packit 98cdb6
ALIGN="right"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>Check Buttons
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>