<refentry id="GtkCombo">
<refmeta>
<refentrytitle>GtkCombo</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GTK Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>GtkCombo</refname><refpurpose>a text entry field with a dropdown list.</refpurpose>
</refnamediv>

<refsynopsisdiv><title>Synopsis</title>
<synopsis>

#include &lt;gtk/gtk.h&gt;


struct      <link linkend="GtkCombo-struct">GtkCombo</link>;
<link linkend="GtkWidget">GtkWidget</link>*  <link linkend="gtk-combo-new">gtk_combo_new</link>                   (void);
void        <link linkend="gtk-combo-set-popdown-strings">gtk_combo_set_popdown_strings</link>   (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="GList">GList</link> *strings);
void        <link linkend="gtk-combo-set-value-in-list">gtk_combo_set_value_in_list</link>     (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="gboolean">gboolean</link> val,
                                             <link linkend="gboolean">gboolean</link> ok_if_empty);
void        <link linkend="gtk-combo-set-use-arrows">gtk_combo_set_use_arrows</link>        (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="gboolean">gboolean</link> val);
void        <link linkend="gtk-combo-set-use-arrows-always">gtk_combo_set_use_arrows_always</link> (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="gboolean">gboolean</link> val);
void        <link linkend="gtk-combo-set-case-sensitive">gtk_combo_set_case_sensitive</link>    (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="gboolean">gboolean</link> val);
void        <link linkend="gtk-combo-set-item-string">gtk_combo_set_item_string</link>       (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="GtkItem">GtkItem</link> *item,
                                             const <link linkend="gchar">gchar</link> *item_value);
void        <link linkend="gtk-combo-disable-activate">gtk_combo_disable_activate</link>      (<link linkend="GtkCombo">GtkCombo</link> *combo);


</synopsis>
</refsynopsisdiv>

<refsect1>
<title>Object Hierarchy</title>
<synopsis>

  <link linkend="GObject">GObject</link>
   +----<link linkend="GtkObject">GtkObject</link>
         +----<link linkend="GtkWidget">GtkWidget</link>
               +----<link linkend="GtkContainer">GtkContainer</link>
                     +----<link linkend="GtkBox">GtkBox</link>
                           +----<link linkend="GtkHBox">GtkHBox</link>
                                 +----GtkCombo
</synopsis>

</refsect1>

<refsect1>
<title>Properties</title>
<synopsis>

  &quot;<link linkend="GtkCombo--enable-arrow-keys">enable-arrow-keys</link>&quot;    <link linkend="gboolean">gboolean</link>             : Read / Write
  &quot;<link linkend="GtkCombo--enable-arrows-always">enable-arrows-always</link>&quot; <link linkend="gboolean">gboolean</link>             : Read / Write
  &quot;<link linkend="GtkCombo--case-sensitive">case-sensitive</link>&quot;       <link linkend="gboolean">gboolean</link>             : Read / Write
  &quot;<link linkend="GtkCombo--allow-empty">allow-empty</link>&quot;          <link linkend="gboolean">gboolean</link>             : Read / Write
  &quot;<link linkend="GtkCombo--value-in-list">value-in-list</link>&quot;        <link linkend="gboolean">gboolean</link>             : Read / Write
</synopsis>
</refsect1>



<refsect1>
<title>Description</title>
<para>
The <link linkend="GtkCombo">GtkCombo</link> widget consists of a single-line text entry field and a drop-down
list. The drop-down list is displayed when the user clicks on a small arrow
button to the right of the entry field.
</para>
<para>
The drop-down list is a <link linkend="GtkList">GtkList</link> widget and can be accessed using the
<structfield>list</structfield> member of the <link linkend="GtkCombo-struct">GtkCombo</link>.
List elements can contain arbitrary widgets, but if an element is not a
plain label, then you must use the <link linkend="gtk-list-set-item-string">gtk_list_set_item_string</link>() function.
This sets the string which will be placed in the text entry field when the
item is selected.
</para>
<para>
By default, the user can step through the items in the list using the
arrow (cursor) keys, though this behaviour can be turned off with
<link linkend="gtk-combo-set-use-arrows">gtk_combo_set_use_arrows</link>().
</para>
<para>
Normally the arrow keys are only active when the contents of the text entry
field matches one of the items in the list. If the contents of the entry field
do not match any of the list items, then pressing the arrow keys does nothing.
However, by calling <link linkend="gtk-combo-set-use-arrows-always">gtk_combo_set_use_arrows_always</link>() you can specify that the
arrow keys are always active. If the contents of the entry field does not match
any of the items in the list, then pressing the up or down arrow key will set
the entry field to the last or first item in the list, respectively.
</para>

<example id="gtkcombo-simple-example">
<title>Creating a <structname>GtkCombo</structname> widget with simple text 
items.</title>
<programlisting>
  GtkWidget *combo;
  GList *items = NULL;

  items = g_list_append (items, "First Item");
  items = g_list_append (items, "Second Item");
  items = g_list_append (items, "Third Item");
  items = g_list_append (items, "Fourth Item");
  items = g_list_append (items, "Fifth Item");

  combo = gtk_combo_new (<!>);
  gtk_combo_set_popdown_strings (GTK_COMBO (combo), items);
</programlisting>
</example>

<example>
<title>Creating a <structname>GtkCombo</structname> widget with a complex item.</title>
<programlisting>
  GtkWidget *combo, *item, *hbox, *arrow, *label;

  combo = gtk_combo_new (<!>);

  item = gtk_list_item_new (<!>);
  gtk_widget_show (item);

  /* You can put almost anything into the GtkListItem widget. Here we will use
     a horizontal box with an arrow and a label in it. */
  hbox = gtk_hbox_new (FALSE, 3);
  gtk_container_add (GTK_CONTAINER (item), hbox);
  gtk_widget_show (hbox);

  arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
  gtk_widget_show (arrow);
  gtk_box_pack_start (GTK_BOX (hbox), pixmap, FALSE, FALSE, 0);

  label = gtk_label_new ("First Item");
  gtk_widget_show (label);
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);

  /* You must set the string to display in the entry field when the item is
     selected. */
  gtk_combo_set_item_string (GTK_COMBO (combo), GTK_ITEM (item), "1st Item");

  /* Now we simply add the item to the combo's list. */
  gtk_container_add (GTK_CONTAINER (GTK_COMBO (combo)->list), item);
</programlisting>
</example>
</refsect1>

<refsect1>
<title>Details</title>
<refsect2>
<title><anchor id="GtkCombo-struct">struct GtkCombo</title>
<programlisting>struct GtkCombo;</programlisting>
<para>
The <link linkend="GtkFixedChild-struct">GtkFixedChild</link> struct contains the following fields.
(These fields should be considered read-only. They should never be set by
an application.)

<informaltable pgwide=1 frame="none" role="struct">
<tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
<tbody>

<row>
<entry><link linkend="GtkWidget">GtkWidget</link> *entry;</entry>
<entry>the text entry field.</entry>
</row>

<row>
<entry><link linkend="GtkWidget">GtkWidget</link> *list;</entry>
<entry>the list shown in the drop-down window.</entry>
</row>

</tbody></tgroup></informaltable>
</para></refsect2>
<refsect2>
<title><anchor id="gtk-combo-new">gtk_combo_new ()</title>
<programlisting><link linkend="GtkWidget">GtkWidget</link>*  gtk_combo_new                   (void);</programlisting>
<para>
Creates a new <link linkend="GtkCombo">GtkCombo</link>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>a new <link linkend="GtkCombo">GtkCombo</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-combo-set-popdown-strings">gtk_combo_set_popdown_strings ()</title>
<programlisting>void        gtk_combo_set_popdown_strings   (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="GList">GList</link> *strings);</programlisting>
<para>
Convenience function to set all of the items in the popup list.
(See the <link linkend="gtkcombo-simple-example">example</link> above.)
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>combo</parameter>&nbsp;:</entry>
<entry>a <link linkend="GtkCombo">GtkCombo</link>.
</entry></row>
<row><entry align="right"><parameter>strings</parameter>&nbsp;:</entry>
<entry>a list of strings.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-combo-set-value-in-list">gtk_combo_set_value_in_list ()</title>
<programlisting>void        gtk_combo_set_value_in_list     (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="gboolean">gboolean</link> val,
                                             <link linkend="gboolean">gboolean</link> ok_if_empty);</programlisting>
<para>
Specifies whether the value entered in the text entry field must match one of
the values in the list. If this is set then the user will not be able to
perform any other action until a valid value has been entered.
</para>
<para>
If an empty field is acceptable, the <parameter>ok_if_empty</parameter> parameter should be <literal>TRUE</literal>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>combo</parameter>&nbsp;:</entry>
<entry>a <link linkend="GtkCombo">GtkCombo</link>.
</entry></row>
<row><entry align="right"><parameter>val</parameter>&nbsp;:</entry>
<entry><literal>TRUE</literal> if the value entered must match one of the values in the list.
</entry></row>
<row><entry align="right"><parameter>ok_if_empty</parameter>&nbsp;:</entry>
<entry><literal>TRUE</literal> if an empty value is considered valid.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-combo-set-use-arrows">gtk_combo_set_use_arrows ()</title>
<programlisting>void        gtk_combo_set_use_arrows        (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="gboolean">gboolean</link> val);</programlisting>
<para>
Specifies if the arrow (cursor) keys can be used to step through the items in
the list. This is on by default.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>combo</parameter>&nbsp;:</entry>
<entry>a <link linkend="GtkCombo">GtkCombo</link>.
</entry></row>
<row><entry align="right"><parameter>val</parameter>&nbsp;:</entry>
<entry><literal>TRUE</literal> if the arrow keys can be used to step through the items in the list.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-combo-set-use-arrows-always">gtk_combo_set_use_arrows_always ()</title>
<programlisting>void        gtk_combo_set_use_arrows_always (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="gboolean">gboolean</link> val);</programlisting>
<para>
Specifies if the arrow keys will still work even if the current contents of the
<link linkend="GtkEntry">GtkEntry</link> field do not match any of the list items. 
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>combo</parameter>&nbsp;:</entry>
<entry>a <link linkend="GtkCombo">GtkCombo</link>.
</entry></row>
<row><entry align="right"><parameter>val</parameter>&nbsp;:</entry>
<entry><literal>TRUE</literal> if the arrow keys will still work even if the current contents of
the <link linkend="GtkEntry">GtkEntry</link> field do not match any of the list items.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-combo-set-case-sensitive">gtk_combo_set_case_sensitive ()</title>
<programlisting>void        gtk_combo_set_case_sensitive    (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="gboolean">gboolean</link> val);</programlisting>
<para>
Specifies whether the text entered into the <link linkend="GtkEntry">GtkEntry</link> field and the text in
the list items is case sensitive.
</para>
<para>
This may be useful, for example, when you have called
<link linkend="gtk-combo-set-value-in-list">gtk_combo_set_value_in_list</link>() to limit the values entered, but you are not
worried about differences in case.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>combo</parameter>&nbsp;:</entry>
<entry>a <link linkend="GtkCombo">GtkCombo</link>.
</entry></row>
<row><entry align="right"><parameter>val</parameter>&nbsp;:</entry>
<entry><literal>TRUE</literal> if the text in the list items is case sensitive.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-combo-set-item-string">gtk_combo_set_item_string ()</title>
<programlisting>void        gtk_combo_set_item_string       (<link linkend="GtkCombo">GtkCombo</link> *combo,
                                             <link linkend="GtkItem">GtkItem</link> *item,
                                             const <link linkend="gchar">gchar</link> *item_value);</programlisting>
<para>
Sets the string to place in the <link linkend="GtkEntry">GtkEntry</link> field when a particular list item is
selected. This is needed if the list item is not a simple label.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>combo</parameter>&nbsp;:</entry>
<entry>a <link linkend="GtkCombo">GtkCombo</link>.
</entry></row>
<row><entry align="right"><parameter>item</parameter>&nbsp;:</entry>
<entry>a <link linkend="GtkItem">GtkItem</link>.
</entry></row>
<row><entry align="right"><parameter>item_value</parameter>&nbsp;:</entry>
<entry>the string to place in the <link linkend="GtkEntry">GtkEntry</link> when <parameter>item</parameter> is selected.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-combo-disable-activate">gtk_combo_disable_activate ()</title>
<programlisting>void        gtk_combo_disable_activate      (<link linkend="GtkCombo">GtkCombo</link> *combo);</programlisting>
<para>
Stops the <link linkend="GtkCombo">GtkCombo</link> widget from showing the popup list when the <link linkend="GtkEntry">GtkEntry</link>
emits the "activate" signal, i.e. when the Return key is pressed.
This may be useful if, for example, you want the Return key to close a dialog
instead.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>combo</parameter>&nbsp;:</entry>
<entry>a <link linkend="GtkCombo">GtkCombo</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>

</refsect1>
<refsect1>
<title>Properties</title>
<variablelist>
<varlistentry><term><anchor id="GtkCombo--enable-arrow-keys">&quot;<literal>enable-arrow-keys</literal>&quot; (<link linkend="gboolean">gboolean</link> : Read / Write)</term>
<listitem>
<para>

</para></listitem></varlistentry>
<varlistentry><term><anchor id="GtkCombo--enable-arrows-always">&quot;<literal>enable-arrows-always</literal>&quot; (<link linkend="gboolean">gboolean</link> : Read / Write)</term>
<listitem>
<para>

</para></listitem></varlistentry>
<varlistentry><term><anchor id="GtkCombo--case-sensitive">&quot;<literal>case-sensitive</literal>&quot; (<link linkend="gboolean">gboolean</link> : Read / Write)</term>
<listitem>
<para>

</para></listitem></varlistentry>
<varlistentry><term><anchor id="GtkCombo--allow-empty">&quot;<literal>allow-empty</literal>&quot; (<link linkend="gboolean">gboolean</link> : Read / Write)</term>
<listitem>
<para>

</para></listitem></varlistentry>
<varlistentry><term><anchor id="GtkCombo--value-in-list">&quot;<literal>value-in-list</literal>&quot; (<link linkend="gboolean">gboolean</link> : Read / Write)</term>
<listitem>
<para>

</para></listitem></varlistentry>

</variablelist>
</refsect1>




</refentry>
