<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
<!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY version SYSTEM "version.xml">
<!ENTITY pi "&#960;">
<!ENTITY solidus "&#8260;">
]>
<refentry id="GtkToggleButton">
<refmeta>
<refentrytitle role="top_of_page" id="GtkToggleButton.top_of_page">GtkToggleButton</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GTK4 Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>GtkToggleButton</refname>
<refpurpose>Create buttons which retain their state</refpurpose>
</refnamediv>

<refsect1 id="GtkToggleButton.functions" role="functions_proto">
<title role="functions_proto.title">Functions</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="functions_proto_type" colwidth="150px"/>
<colspec colname="functions_proto_name"/>
<tbody>
<row><entry role="function_type"><link linkend="GtkWidget"><returnvalue>GtkWidget</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="gtk-toggle-button-new">gtk_toggle_button_new</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GtkWidget"><returnvalue>GtkWidget</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="gtk-toggle-button-new-with-label">gtk_toggle_button_new_with_label</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GtkWidget"><returnvalue>GtkWidget</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="gtk-toggle-button-new-with-mnemonic">gtk_toggle_button_new_with_mnemonic</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="gtk-toggle-button-toggled">gtk_toggle_button_toggled</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="gtk-toggle-button-get-active">gtk_toggle_button_get_active</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="gtk-toggle-button-set-active">gtk_toggle_button_set_active</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="GtkToggleButton.properties" role="properties">
<title role="properties.title">Properties</title>
<informaltable frame="none">
<tgroup cols="3">
<colspec colname="properties_type" colwidth="150px"/>
<colspec colname="properties_name" colwidth="300px"/>
<colspec colname="properties_flags" colwidth="200px"/>
<tbody>
<row><entry role="property_type"><link linkend="gboolean"><type>gboolean</type></link></entry><entry role="property_name"><link linkend="GtkToggleButton--active">active</link></entry><entry role="property_flags">Read / Write</entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="GtkToggleButton.signals" role="signal_proto">
<title role="signal_proto.title">Signals</title>
<informaltable frame="none">
<tgroup cols="3">
<colspec colname="signal_proto_type" colwidth="150px"/>
<colspec colname="signal_proto_name" colwidth="300px"/>
<colspec colname="signal_proto_flags" colwidth="200px"/>
<tbody>
<row><entry role="signal_type"><link linkend="void"><returnvalue>void</returnvalue></link></entry><entry role="signal_name"><link linkend="GtkToggleButton-toggled">toggled</link></entry><entry role="signal_flags"><link linkend="G-SIGNAL-RUN-FIRST:CAPS">Run First</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="GtkToggleButton.other" role="other_proto">
<title role="other_proto.title">Types and Values</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="other_proto_type" colwidth="150px"/>
<colspec colname="other_proto_name"/>
<tbody>
<row><entry role="datatype_keyword">struct</entry><entry role="function_name"><link linkend="GtkToggleButton-struct">GtkToggleButton</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="GtkToggleButton.object-hierarchy" role="object_hierarchy">
<title role="object_hierarchy.title">Object Hierarchy</title>
<screen>    <link linkend="GObject">GObject</link>
    <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> <link linkend="GInitiallyUnowned">GInitiallyUnowned</link>
        <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> <link linkend="GtkWidget">GtkWidget</link>
            <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> <link linkend="GtkButton">GtkButton</link>
                <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> GtkToggleButton
                    <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> <link linkend="GtkCheckButton">GtkCheckButton</link>
</screen>
</refsect1>
<refsect1 id="GtkToggleButton.implemented-interfaces" role="impl_interfaces">
<title role="impl_interfaces.title">Implemented Interfaces</title>
<para>
GtkToggleButton implements
 <link linkend="AtkImplementorIface">AtkImplementorIface</link>,  <link linkend="GtkBuildable">GtkBuildable</link>,  <link linkend="GtkConstraintTarget">GtkConstraintTarget</link> and  <link linkend="GtkActionable">GtkActionable</link>.</para>

</refsect1>

<refsect1 id="GtkToggleButton.includes"><title>Includes</title><synopsis>#include &lt;gtk/gtk.h&gt;
</synopsis></refsect1>

<refsect1 id="GtkToggleButton.description" role="desc">
<title role="desc.title">Description</title>
<para>A <link linkend="GtkToggleButton"><type>GtkToggleButton</type></link> is a <link linkend="GtkButton"><type>GtkButton</type></link> which will remain “pressed-in” when
clicked. Clicking again will cause the toggle button to return to its
normal state.</para>
<para>A toggle button is created by calling either <link linkend="gtk-toggle-button-new"><function>gtk_toggle_button_new()</function></link> or
<link linkend="gtk-toggle-button-new-with-label"><function>gtk_toggle_button_new_with_label()</function></link>. If using the former, it is advisable to
pack a widget, (such as a <link linkend="GtkLabel"><type>GtkLabel</type></link> and/or a <link linkend="GtkImage"><type>GtkImage</type></link>), into the toggle
button’s container. (See <link linkend="GtkButton"><type>GtkButton</type></link> for more information).</para>
<para>The state of a <link linkend="GtkToggleButton"><type>GtkToggleButton</type></link> can be set specifically using
<link linkend="gtk-toggle-button-set-active"><function>gtk_toggle_button_set_active()</function></link>, and retrieved using
<link linkend="gtk-toggle-button-get-active"><function>gtk_toggle_button_get_active()</function></link>.</para>
<para>To simply switch the state of a toggle button, use <link linkend="gtk-toggle-button-toggled"><function>gtk_toggle_button_toggled()</function></link>.</para>
<refsect2><title>CSS nodes</title><para>GtkToggleButton has a single CSS node with name button. To differentiate
it from a plain <link linkend="GtkButton"><type>GtkButton</type></link>, it gets the .toggle style class.</para>
<refsect3><title>Creating two <link linkend="GtkToggleButton"><type>GtkToggleButton</type></link> widgets.</title><informalexample><programlisting role="example"><![CDATA[
static void output_state (GtkToggleButton *source, gpointer user_data) {
  printf ("Active: %d\n", gtk_toggle_button_get_active (source));
}

void make_toggles (void) {
  GtkWidget *window, *toggle1, *toggle2;
  GtkWidget *box;
  const char *text;

  window = gtk_window_new ();
  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);

  text = "Hi, I’m a toggle button.";
  toggle1 = gtk_toggle_button_new_with_label (text);

  g_signal_connect (toggle1, "toggled",
                    G_CALLBACK (output_state),
                    NULL);
  gtk_box_append (GTK_BOX (box), toggle1);

  text = "Hi, I’m a toggle button.";
  toggle2 = gtk_toggle_button_new_with_label (text);
  g_signal_connect (toggle2, "toggled",
                    G_CALLBACK (output_state),
                    NULL);
  gtk_box_append (GTK_BOX (box), toggle2);

  gtk_window_set_child (GTK_WINDOW (window), box);
  gtk_widget_show (window);
}
]]></programlisting></informalexample>
<para></para>
</refsect3>
</refsect2>

</refsect1>
<refsect1 id="GtkToggleButton.functions_details" role="details">
<title role="details.title">Functions</title>
<refsect2 id="gtk-toggle-button-new" role="function">
<title>gtk_toggle_button_new&#160;()</title>
<indexterm zone="gtk-toggle-button-new"><primary>gtk_toggle_button_new</primary></indexterm>
<programlisting language="C"><link linkend="GtkWidget"><returnvalue>GtkWidget</returnvalue></link>&#160;*
gtk_toggle_button_new (<parameter><type>void</type></parameter>);</programlisting>
<para>Creates a new toggle button. A widget should be packed into the button, as in <link linkend="gtk-button-new"><function>gtk_button_new()</function></link>.</para>
<refsect3 id="gtk-toggle-button-new.returns" role="returns">
<title>Returns</title>
<para> a new toggle button.</para>
</refsect3></refsect2>
<refsect2 id="gtk-toggle-button-new-with-label" role="function">
<title>gtk_toggle_button_new_with_label&#160;()</title>
<indexterm zone="gtk-toggle-button-new-with-label"><primary>gtk_toggle_button_new_with_label</primary></indexterm>
<programlisting language="C"><link linkend="GtkWidget"><returnvalue>GtkWidget</returnvalue></link>&#160;*
gtk_toggle_button_new_with_label (<parameter>const <link linkend="gchar"><type>gchar</type></link> *label</parameter>);</programlisting>
<para>Creates a new toggle button with a text label.</para>
<refsect3 id="gtk-toggle-button-new-with-label.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>label</para></entry>
<entry role="parameter_description"><para>a string containing the message to be placed in the toggle button.</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="gtk-toggle-button-new-with-label.returns" role="returns">
<title>Returns</title>
<para> a new toggle button.</para>
</refsect3></refsect2>
<refsect2 id="gtk-toggle-button-new-with-mnemonic" role="function">
<title>gtk_toggle_button_new_with_mnemonic&#160;()</title>
<indexterm zone="gtk-toggle-button-new-with-mnemonic"><primary>gtk_toggle_button_new_with_mnemonic</primary></indexterm>
<programlisting language="C"><link linkend="GtkWidget"><returnvalue>GtkWidget</returnvalue></link>&#160;*
gtk_toggle_button_new_with_mnemonic (<parameter>const <link linkend="gchar"><type>gchar</type></link> *label</parameter>);</programlisting>
<para>Creates a new <link linkend="GtkToggleButton"><type>GtkToggleButton</type></link> containing a label. The label
will be created using <link linkend="gtk-label-new-with-mnemonic"><function>gtk_label_new_with_mnemonic()</function></link>, so underscores
in <parameter>label</parameter>
 indicate the mnemonic for the button.</para>
<refsect3 id="gtk-toggle-button-new-with-mnemonic.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>label</para></entry>
<entry role="parameter_description"><para>the text of the button, with an underscore in front of the
mnemonic character</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="gtk-toggle-button-new-with-mnemonic.returns" role="returns">
<title>Returns</title>
<para> a new <link linkend="GtkToggleButton"><type>GtkToggleButton</type></link></para>
</refsect3></refsect2>
<refsect2 id="gtk-toggle-button-toggled" role="function">
<title>gtk_toggle_button_toggled&#160;()</title>
<indexterm zone="gtk-toggle-button-toggled"><primary>gtk_toggle_button_toggled</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
gtk_toggle_button_toggled (<parameter><link linkend="GtkToggleButton"><type>GtkToggleButton</type></link> *toggle_button</parameter>);</programlisting>
<para>Emits the <link linkend="GtkToggleButton-toggled"><type>“toggled”</type></link> signal on the
<link linkend="GtkToggleButton"><type>GtkToggleButton</type></link>. There is no good reason for an
application ever to call this function.</para>
<refsect3 id="gtk-toggle-button-toggled.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>toggle_button</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkToggleButton"><type>GtkToggleButton</type></link>.</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="gtk-toggle-button-get-active" role="function">
<title>gtk_toggle_button_get_active&#160;()</title>
<indexterm zone="gtk-toggle-button-get-active"><primary>gtk_toggle_button_get_active</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
gtk_toggle_button_get_active (<parameter><link linkend="GtkToggleButton"><type>GtkToggleButton</type></link> *toggle_button</parameter>);</programlisting>
<para>Queries a <link linkend="GtkToggleButton"><type>GtkToggleButton</type></link> and returns its current state. Returns <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> if
the toggle button is pressed in and <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if it is raised.</para>
<refsect3 id="gtk-toggle-button-get-active.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>toggle_button</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkToggleButton"><type>GtkToggleButton</type></link>.</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="gtk-toggle-button-get-active.returns" role="returns">
<title>Returns</title>
<para> a <link linkend="gboolean"><type>gboolean</type></link> value.</para>
</refsect3></refsect2>
<refsect2 id="gtk-toggle-button-set-active" role="function">
<title>gtk_toggle_button_set_active&#160;()</title>
<indexterm zone="gtk-toggle-button-set-active"><primary>gtk_toggle_button_set_active</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
gtk_toggle_button_set_active (<parameter><link linkend="GtkToggleButton"><type>GtkToggleButton</type></link> *toggle_button</parameter>,
                              <parameter><link linkend="gboolean"><type>gboolean</type></link> is_active</parameter>);</programlisting>
<para>Sets the status of the toggle button. Set to <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> if you want the
GtkToggleButton to be “pressed in”, and <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> to raise it.</para>
<para>If the status of the button changes, this action causes the
<link linkend="GtkToggleButton-toggled"><type>“toggled”</type></link> signal to be emitted.</para>
<refsect3 id="gtk-toggle-button-set-active.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>toggle_button</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkToggleButton"><type>GtkToggleButton</type></link>.</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>is_active</para></entry>
<entry role="parameter_description"><para><link linkend="TRUE:CAPS"><literal>TRUE</literal></link> or <link linkend="FALSE:CAPS"><literal>FALSE</literal></link>.</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>

</refsect1>
<refsect1 id="GtkToggleButton.other_details" role="details">
<title role="details.title">Types and Values</title>
<refsect2 id="GtkToggleButton-struct" role="struct">
<title>struct GtkToggleButton</title>
<indexterm zone="GtkToggleButton-struct"><primary>GtkToggleButton</primary></indexterm>
<programlisting language="C">struct GtkToggleButton;</programlisting>
</refsect2>

</refsect1>
<refsect1 id="GtkToggleButton.property-details" role="property_details">
<title role="property_details.title">Property Details</title>
<refsect2 id="GtkToggleButton--active" role="property"><title>The <literal>“active”</literal> property</title>
<indexterm zone="GtkToggleButton--active"><primary>GtkToggleButton:active</primary></indexterm>
<programlisting>  “active”                   <link linkend="gboolean"><type>gboolean</type></link></programlisting>
<para>If the toggle button should be pressed in.</para><para>Owner: GtkToggleButton</para>
<para>Flags: Read / Write</para>
<para>Default value: FALSE</para>
</refsect2>

</refsect1>
<refsect1 id="GtkToggleButton.signal-details" role="signals">
<title role="signals.title">Signal Details</title>
<refsect2 id="GtkToggleButton-toggled" role="signal"><title>The <literal>“toggled”</literal> signal</title>
<indexterm zone="GtkToggleButton-toggled"><primary>GtkToggleButton::toggled</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
user_function (<link linkend="GtkToggleButton"><type>GtkToggleButton</type></link> *togglebutton,
               <link linkend="gpointer"><type>gpointer</type></link>         user_data)</programlisting>
<para>Should be connected if you wish to perform an action whenever the
<link linkend="GtkToggleButton"><type>GtkToggleButton</type></link>'s state is changed.</para>
<refsect3 id="GtkToggleButton-toggled.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>togglebutton</para></entry>
<entry role="parameter_description"><para>the object which received the signal.</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><simpara>user_data</simpara></entry>
<entry role="parameter_description"><simpara>user data set when the signal handler was connected.</simpara></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para>Flags: <link linkend="G-SIGNAL-RUN-FIRST:CAPS">Run First</link></para>
</refsect2>
</refsect1>
<refsect1 id="GtkToggleButton.see-also">
<title>See Also</title>
<para><link linkend="GtkButton"><type>GtkButton</type></link>, <link linkend="GtkCheckButton"><type>GtkCheckButton</type></link>, <link linkend="GtkCheckMenuItem"><type>GtkCheckMenuItem</type></link></para>

</refsect1>

</refentry>
