📄 gtkcombo.html
字号:
<HTML><HEAD><TITLE>GtkCombo</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.61"><LINKREL="HOME"TITLE="GTK+ Reference Manual"HREF="index.html"><LINKREL="UP"TITLE="GTK+ Widgets and Objects"HREF="gtkobjects.html"><LINKREL="PREVIOUS"TITLE="GtkColorSelectionDialog"HREF="gtkcolorselectiondialog.html"><LINKREL="NEXT"TITLE="GtkContainer"HREF="gtkcontainer.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"BGCOLOR="#000000"CELLPADDING="1"CELLSPACING="0"><TR><THCOLSPAN="4"ALIGN="center"><FONTCOLOR="#FFFFFF"SIZE="5">GTK+ Reference Manual</FONT></TH></TR><TR><TDWIDTH="25%"BGCOLOR="#C00000"ALIGN="left"><AHREF="gtkcolorselectiondialog.html"><FONTCOLOR="#FFFFFF"SIZE="3"><B><<< Previous Page</B></FONT></A></TD><TDWIDTH="25%"BGCOLOR="#0000C0"ALIGN="center"><FONTCOLOR="#FFFFFF"SIZE="3"><B><AHREF="index.html"><FONTCOLOR="#FFFFFF"SIZE="3"><B>Home</B></FONT></A></B></FONT></TD><TDWIDTH="25%"BGCOLOR="#00C000"ALIGN="center"><FONTCOLOR="#FFFFFF"SIZE="3"><B><AHREF="gtkobjects.html"><FONTCOLOR="#FFFFFF"SIZE="3"><B>Up</B></FONT></A></B></FONT></TD><TDWIDTH="25%"BGCOLOR="#C00000"ALIGN="right"><AHREF="gtkcontainer.html"><FONTCOLOR="#FFFFFF"SIZE="3"><B>Next Page >>></B></FONT></A></TD></TR></TABLE></DIV><H1><ANAME="GTKCOMBO">GtkCombo</A></H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN19445"></A><H2>Name</H2>GtkCombo -- a text entry field with a dropdown list.</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN19448"></A><H2>Synopsis</H2><TABLEBORDER="0"BGCOLOR="#D6E8FF"WIDTH="100%"CELLPADDING="6"><TR><TD><PRECLASS="SYNOPSIS"> #include <gtk/gtk.h>struct <AHREF="gtkcombo.html#GTKCOMBO-STRUCT">GtkCombo</A>;<AHREF="gtkwidget.html">GtkWidget</A>* <AHREF="gtkcombo.html#GTK-COMBO-NEW">gtk_combo_new</A> (void);void <AHREF="gtkcombo.html#GTK-COMBO-SET-POPDOWN-STRINGS">gtk_combo_set_popdown_strings</A> (<AHREF="gtkcombo.html">GtkCombo</A> *combo, <AHREF=../glib/glib-doubly-linked-lists.html#GLIST>GList</A> *strings);void <AHREF="gtkcombo.html#GTK-COMBO-SET-VALUE-IN-LIST">gtk_combo_set_value_in_list</A> (<AHREF="gtkcombo.html">GtkCombo</A> *combo, <AHREF=../glib/glib-basic-types.html#GINT>gint</A> val, <AHREF=../glib/glib-basic-types.html#GINT>gint</A> ok_if_empty);void <AHREF="gtkcombo.html#GTK-COMBO-SET-USE-ARROWS">gtk_combo_set_use_arrows</A> (<AHREF="gtkcombo.html">GtkCombo</A> *combo, <AHREF=../glib/glib-basic-types.html#GINT>gint</A> val);void <AHREF="gtkcombo.html#GTK-COMBO-SET-USE-ARROWS-ALWAYS">gtk_combo_set_use_arrows_always</A> (<AHREF="gtkcombo.html">GtkCombo</A> *combo, <AHREF=../glib/glib-basic-types.html#GINT>gint</A> val);void <AHREF="gtkcombo.html#GTK-COMBO-SET-CASE-SENSITIVE">gtk_combo_set_case_sensitive</A> (<AHREF="gtkcombo.html">GtkCombo</A> *combo, <AHREF=../glib/glib-basic-types.html#GINT>gint</A> val);void <AHREF="gtkcombo.html#GTK-COMBO-SET-ITEM-STRING">gtk_combo_set_item_string</A> (<AHREF="gtkcombo.html">GtkCombo</A> *combo, <AHREF="gtkitem.html">GtkItem</A> *item, const <AHREF=../glib/glib-basic-types.html#GCHAR>gchar</A> *item_value);void <AHREF="gtkcombo.html#GTK-COMBO-DISABLE-ACTIVATE">gtk_combo_disable_activate</A> (<AHREF="gtkcombo.html">GtkCombo</A> *combo); </PRE></TD></TR></TABLE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN19476"></A><H2>Object Hierarchy</H2><TABLEBORDER="0"BGCOLOR="#D6E8FF"WIDTH="100%"CELLPADDING="6"><TR><TD><PRECLASS="SYNOPSIS"> <AHREF="gtkobject.html">GtkObject</A> +----<AHREF="gtkwidget.html">GtkWidget</A> +----<AHREF="gtkcontainer.html">GtkContainer</A> +----<AHREF="gtkbox.html">GtkBox</A> +----<AHREF="gtkhbox.html">GtkHBox</A> +----GtkCombo</PRE></TD></TR></TABLE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN19484"></A><H2>Description</H2><P>The <AHREF="gtkcombo.html">GtkCombo</A> widget consists of a single-line text entry field and a drop-downlist. The drop-down list is displayed when the user clicks on a small arrowbutton to the right of the entry field.</P><P>The drop-down list is a <AHREF="gtklist.html">GtkList</A> widget and can be accessed using the<TTCLASS="STRUCTFIELD"><I>list</I></TT> member of the <AHREF="gtkcombo.html#GTKCOMBO-STRUCT">GtkCombo</A>.List elements can contain arbitrary widgets, but if an element is not aplain label, then you must use the gtk_list_set_item_string() function.This sets the string which will be placed in the text entry field when theitem is selected.</P><P>By default, the user can step through the items in the list using thearrow (cursor) keys, though this behaviour can be turned off with<AHREF="gtkcombo.html#GTK-COMBO-SET-USE-ARROWS">gtk_combo_set_use_arrows</A>().</P><P>Normally the arrow keys are only active when the contents of the text entryfield matches one of the items in the list. If the contents of the entry fielddo not match any of the list items, then pressing the arrow keys does nothing.However, by calling <AHREF="gtkcombo.html#GTK-COMBO-SET-USE-ARROWS-ALWAYS">gtk_combo_set_use_arrows_always</A>() you can specify that thearrow keys are always active. If the contents of the entry field does not matchany of the items in the list, then pressing the up or down arrow key will setthe entry field to the last or first item in the list, respectively.</P><DIVCLASS="EXAMPLE"><ANAME="GTKCOMBO-SIMPLE-EXAMPLE"></A><P><B>Example 1. Creating a <AHREF="gtkcombo.html">GtkCombo</A> widget with simple text items.</B></P><TABLEBORDER="0"BGCOLOR="#D8F8D8"WIDTH="100%"CELLPADDING="6"><TR><TD><PRECLASS="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 = <AHREF="gtkcombo.html#GTK-COMBO-NEW">gtk_combo_new</A>(); gtk_combo_set_popdown_strings (GTK_COMBO (combo), items);</PRE></TD></TR></TABLE></DIV><DIVCLASS="EXAMPLE"><ANAME="AEN19502"></A><P><B>Example 2. Creating a <AHREF="gtkcombo.html">GtkCombo</A> widget with a complex item.</B></P><TABLEBORDER="0"BGCOLOR="#D8F8D8"WIDTH="100%"CELLPADDING="6"><TR><TD><PRECLASS="PROGRAMLISTING"> GtkWidget *combo, *item, *hbox, *arrow, *label; combo = <AHREF="gtkcombo.html#GTK-COMBO-NEW">gtk_combo_new</A>(); item = <AHREF="gtklistitem.html#GTK-LIST-ITEM-NEW">gtk_list_item_new</A>(); 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);</PRE></TD></TR></TABLE></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN19508"></A><H2>Details</H2><DIVCLASS="REFSECT2"><ANAME="AEN19510"></A><H3><ANAME="GTKCOMBO-STRUCT"></A>struct GtkCombo</H3><TABLEBORDER="0"BGCOLOR="#D6E8FF"WIDTH="100%"CELLPADDING="6"><TR><TD><PRECLASS="PROGRAMLISTING">struct GtkCombo;</PRE></TD></TR></TABLE><P>The GtkFixedChild struct contains the following fields.(These fields should be considered read-only. They should never be set byan application.)<DIVCLASS="INFORMALTABLE"><ANAME="AEN19516"></A><P></P><TABLEBORDER="0"WIDTH="100%"BGCOLOR="#FFF0D0"CELLSPACING="0"CELLPADDING="4"CLASS="CALSTABLE"><TBODY><TR><TDWIDTH="20%"ALIGN="LEFT"VALIGN="TOP"><AHREF="gtkwidget.html">GtkWidget</A> *entry;</TD><TDWIDTH="80%"ALIGN="LEFT"VALIGN="TOP">the text entry field.</TD></TR><TR><TDWIDTH="20%"ALIGN="LEFT"VALIGN="TOP"><AHREF="gtkwidget.html">GtkWidget</A> *list;</TD><TDWIDTH="80%"ALIGN="LEFT"VALIGN="TOP">the list shown in the drop-down window.</TD></TR></TBODY></TABLE><P></P></DIV></P></DIV><HR><DIVCLASS="REFSECT2"><ANAME="AEN19529"></A><H3><ANAME="GTK-COMBO-NEW"></A>gtk_combo_new ()</H3><TABLEBORDER="0"BGCOLOR="#D6E8FF"WIDTH="100%"CELLPADDING="6"><TR><TD><PRECLASS="PROGRAMLISTING"><AHREF="gtkwidget.html">GtkWidget</A>* gtk_combo_new (void);</PRE></TD></TR></TABLE><P>Creates a new <AHREF="gtkcombo.html">GtkCombo</A>.</P><DIVCLASS="INFORMALTABLE"><ANAME="AEN19536"></A><P></P><TABLEBORDER="0"WIDTH="100%"BGCOLOR="#FFD0D0"CELLSPACING="0"CELLPADDING="4"CLASS="CALSTABLE"><TBODY><TR><TDWIDTH="20%"ALIGN="RIGHT"VALIGN="TOP"><ICLASS="EMPHASIS">Returns</I> :</TD><TDWIDTH="80%"ALIGN="LEFT"VALIGN="TOP">a new <AHREF="gtkcombo.html">GtkCombo</A>. </TD></TR></TBODY></TABLE><P></P></DIV></DIV><HR><DIVCLASS="REFSECT2"><ANAME="AEN19546"></A><H3><ANAME="GTK-COMBO-SET-POPDOWN-STRINGS"></A>gtk_combo_set_popdown_strings ()</H3><TABLEBORDER="0"BGCOLOR="#D6E8FF"WIDTH="100%"CELLPADDING="6"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_combo_set_popdown_strings (<AHREF="gtkcombo.html">GtkCombo</A> *combo, <AHREF=../glib/glib-doubly-linked-lists.html#GLIST>GList</A> *strings);</PRE></TD></TR></TABLE><P>Convenience function to set all of the items in the popup list.(See the <AHREF="gtkcombo.html#GTKCOMBO-SIMPLE-EXAMPLE">example</A> above.)</P><DIVCLASS="INFORMALTABLE"><ANAME="AEN19554"></A><P></P><TABLEBORDER="0"WIDTH="100%"BGCOLOR="#FFD0D0"CELLSPACING="0"CELLPADDING="4"CLASS="CALSTABLE"><TBODY><TR><TDWIDTH="20%"ALIGN="RIGHT"VALIGN="TOP"><TTCLASS="PARAMETER"><I>combo</I></TT> :</TD><TDWIDTH="80%"ALIGN="LEFT"VALIGN="TOP">a <AHREF="gtkcombo.html">GtkCombo</A>.</TD></TR><TR><TDWIDTH="20%"ALIGN="RIGHT"VALIGN="TOP"><TTCLASS="PARAMETER"><I>strings</I></TT> :</TD><TDWIDTH="80%"ALIGN="LEFT"VALIGN="TOP">a list of strings. </TD></TR></TBODY></TABLE><P></P></DIV></DIV><HR><DIVCLASS="REFSECT2"><ANAME="AEN19568"></A><H3><ANAME="GTK-COMBO-SET-VALUE-IN-LIST"></A>gtk_combo_set_value_in_list ()</H3><TABLEBORDER="0"BGCOLOR="#D6E8FF"WIDTH="100%"CELLPADDING="6"><TR><TD><PRE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -