GtkComboBox

GtkComboBox — Un widget utilisé pour faire un choix parmis une liste d'items.

Synopsis


#include <gtk/gtk.h>

GtkComboBox;
GtkWidget* gtk_combo_box_new (void);
GtkWidget* gtk_combo_box_new_with_model (GtkTreeModel *model);
gint gtk_combo_box_get_wrap_width (GtkComboBox *combo_box);
void gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
gint width);
gint gtk_combo_box_get_row_span_column (GtkComboBox *combo_box);
void gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
gint row_span);
gint gtk_combo_box_get_column_span_column
(GtkComboBox *combo_box);
void gtk_combo_box_set_column_span_column
(GtkComboBox *combo_box,
gint column_span);
gint gtk_combo_box_get_active (GtkComboBox *combo_box);
void gtk_combo_box_set_active (GtkComboBox *combo_box,
gint index_);
gboolean gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
GtkTreeIter *iter);
void gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
GtkTreeIter *iter);
GtkTreeModel* gtk_combo_box_get_model (GtkComboBox *combo_box);
void gtk_combo_box_set_model (GtkComboBox *combo_box,
GtkTreeModel *model);
GtkWidget* gtk_combo_box_new_text (void);
void gtk_combo_box_append_text (GtkComboBox *combo_box,
const gchar *text);
void gtk_combo_box_insert_text (GtkComboBox *combo_box,
gint position,
const gchar *text);
void gtk_combo_box_prepend_text (GtkComboBox *combo_box,
const gchar *text);
void gtk_combo_box_remove_text (GtkComboBox *combo_box,
gint position);
gchar* gtk_combo_box_get_active_text (GtkComboBox *combo_box);
void gtk_combo_box_popup (GtkComboBox *combo_box);
void gtk_combo_box_popdown (GtkComboBox *combo_box);
AtkObject* gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box);
GtkTreeViewRowSeparatorFunc gtk_combo_box_get_row_separator_func
(GtkComboBox *combo_box);
void gtk_combo_box_set_row_separator_func
(GtkComboBox *combo_box,
GtkTreeViewRowSeparatorFunc func,
gpointer data,
GtkDestroyNotify destroy);
void gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
gboolean add_tearoffs);
gboolean gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box);
void gtk_combo_box_set_title (GtkComboBox *combo_box,
const gchar *title);
const gchar* gtk_combo_box_get_title (GtkComboBox *combo_box);
void gtk_combo_box_set_focus_on_click (GtkComboBox *combo,
gboolean focus_on_click);
gboolean gtk_combo_box_get_focus_on_click (GtkComboBox *combo);

Hiérarchie des Objets

GObject
+----GInitiallyUnowned
+----GtkObject
+----GtkWidget
+----GtkContainer
+----GtkBin
+----GtkComboBox
+----GtkComboBoxEntry

Interfaces utilisées

GtkComboBox utilise AtkImplementorIface, GtkCellEditable et GtkCellLayout.

Propriétés

"active"		 gint 			: Lire / Ecrire
"add-tearoffs" gboolean : Lire / Ecrire
"column-span-column" gint : Lire / Ecrire
"focus-on-click" gboolean : Lire / Ecrire
"has-frame" gboolean : Lire / Ecrire
"model" GtkTreeModel : Lire / Ecrire
"popup-shown" gboolean : Lire
"row-span-column" gint : Lire / Ecrire
"tearoff-title" gchararray : Lire / Ecrire
"wrap-width" gint : Lire / Ecrire

Propriétés de Style

"appears-as-list"	 gboolean		: Lire
"arrow-size" gint : Lire

Signaux

"changed" 		: Run Last
"move-active" : Run Last / Action
"popup" : Run Last / Action

Description

Un GtkComboBox est un  widget qui permet à l'utilisateur de faire un choix dans une liste de choix valides. Le GtkComboBox affiche le choix sélectionné. Quand il est activé, le  GtkComboBox affiche un popup qui permet à  l'utilisateur de faire un nouveau choix. Le style dans lequel la valeur sélectionnée est affichée et le style du popup sont déterminés  par le thème courant. Il peut être semblable à un  GtkOptionMenu, ou à combobox de style Windows.

Contrairement à ses prédécesseurs GtkCombo et GtkOptionMenuGtkComboBoxutilise uses le modèle vue-controleur; la liste de choix valides est spécifiée dans une forme de modèle d'arbre, et l'affichage des choix peut être adapté aux données dans le modèle en utilisant le rendu de cellule, comme vous le feriez dans une vue en arbre. Ceci est possible depuis que GtkComboBox implémente l'interface GtkCellLayout. Le modèle en arbre contenant les choix valides n'est pas réduit à une liste plate, elle peut être un véritable arbre, et le popup reflétera dans ce cas la structure en arbre.

En plus de l'API vue-contrôleur,  GtkComboBox offre un simple API  approprié aux combobox utilisant uniquement du texte, et cache la complexité de l'organisation des données dans un modèle. Il est composé des fonctions gtk_combo_box_new_text(), gtk_combo_box_append_text(), gtk_combo_box_insert_text(), gtk_combo_box_prepend_text(), gtk_combo_box_remove_text() et gtk_combo_box_get_active_text().

Details

GtkComboBox


typedef 	struct _GtkComboBox 		GtkComboBox;

gtk_combo_box_new ()


GtkWidget* 		gtk_combo_box_new 		(void);

Créé un nouveau  GtkComboBox vide.

Retourne : Un nouveau GtkComboBox.

Depuis 2.4


gtk_combo_box_new_with_model ()


GtkWidget* 		gtk_combo_box_new_with_model		(GtkTreeModel *model);

Crée un nouveau  GtkComboBox avec le modèle initialisé à model.

model : un GtkTreeModel.
Returns : un nouveau GtkComboBox.

Depuis  2.4


gtk_combo_box_get_wrap_width ()


gint 		gtk_combo_box_get_wrap_width 		(GtkComboBox *combo_box);

Retourne la largeur de l'enveloppe qui est utilisée pour déterminer le nombre de colonnes du menu déroulant. Si la largeur de l'enveloppe est plus grand que 1, la combobox est en mode tableau.

combo_box : un GtkComboBox.
Retourne : La largeur de l'enveloppe.

Depuis 2.6


gtk_combo_box_set_wrap_width ()


void 		gtk_combo_box_set_wrap_width 		(GtkComboBox *combo_box,
gint width);

Définit ma largeur de l'enveloppe de combo_box à width. La largeur de l'enveloppe est basiquement le nombre de colonnes favorit quand vous voulez que le popup soit disposé dans un tableau.
combo_box : un GtkComboBox.
width : Nombre préféré de colonnes.

Depuis 2.4


gtk_combo_box_get_row_span_column ()


gint 		gtk_combo_box_get_row_span_column 		(GtkComboBox *combo_box);

Retourne la colonne avec l'information sur la dimension des ligne d'un colonne pour  combo_box.

combo_box : A GtkComboBox.
Retourne : the row span column. (taille de rangée pour la colonne ?)

Since 2.6


gtk_combo_box_set_row_span_column ()


void 		gtk_combo_box_set_row_span_column 		(GtkComboBox *combo_box,
gint row_span);

Définit la colonne avec la dimension de la ligne pour combo_box définie à row_span. (La dimension de  la ligne d'une colonne contient des entiers qui indiquent combien de lignes un item peut occuper.?) The row span column contains integers which indicate how many rows an item should span.

combo_box : un GtkComboBox.
row_span : une colonne dans le modèle passé pendant  la construction.

Depuis 2.4


gtk_combo_box_get_column_span_column ()


gint 			gtk_combo_box_get_column_span_column	
(GtkComboBox *combo_box);

Retourne la colonne avec l'information sur la largeur de la colonne pour combo_box.
combo_box : A GtkComboBox.
Retourne : la largeur de la colonne

Depuis 2.6


gtk_combo_box_set_column_span_column ()


void 		gtk_combo_box_set_column_span_column 		(GtkComboBox *combo_box,gint column_span);

Définit  la largeur de colonne pour combo_box  par column_span. (La largeur de la colonne contient des entiers qui indiquent  combien de colonnes un item peut occuper.) The column span column contains integers which indicate how many columns an item should span.

combo_box : Un GtkComboBox.
column_span : Une colonne dans le modèle passé pendant la construction.

Dépuis  2.4


gtk_combo_box_get_active ()


gint 		gtk_combo_box_get_active 		(GtkComboBox *combo_box);

Retourne l'index de l'item courant activé, ou -1 s'il n'y a pas d'item activé. Si le model est un model d'arbre non plat, et que l'item activé n'est pas un enfant immédiat de la racine de l'arbre, cette fonction retourne gtk_tree_path_get_indices (path)[0],  où path est le  GtkTreePath de l'item actif.

combo_box : Un GtkComboBox.
Retourne :  Un entier qui est l'index de l'item courant activé, ou -1 s'il n'y  a pas d'item activé.

Depuis 2.4


gtk_combo_box_set_active ()


void 		gtk_combo_box_set_active 		(GtkComboBox *combo_box,gint index_);

Définit l'item actif de  combo_box à l'item d'index index.

combo_box : Un GtkComboBox.
index_ : Un index dans le modèle passé pendant la construction, ou -1 pour qu'il n'y ait aucun item activé.

Depuis 2.4


gtk_combo_box_get_active_iter ()


gboolean 		gtk_combo_box_get_active_iter 		(GtkComboBox *combo_box,GtkTreeIter *iter);

Définit  iter, qui pointe sur l'item activé courant, s'il existe.

combo_box : Un GtkComboBox
iter : Le GtkTreeIter. initialisé
Returns : TRUE, si iter a été définit

Depuis 2.4


gtk_combo_box_set_active_iter ()

void 		gtk_combo_box_set_active_iter 		(GtkComboBox *combo_box,GtkTreeIter *iter);

Définit l'item courant actif  pour qu'il soit celui référencé par  iter. iter  doit correspondre à  un chemin de profondeur 1 ?(must correspond to a path of depth one.) 

Je vais traduire ce qui vient avant les combobox pour y comprendre qq chose ! :)
combo_box : Un  GtkComboBox
iter : Le GtkTreeIter.

Depuis 2.4


gtk_combo_box_get_model ()


GtkTreeModel* gtk_combo_box_get_model (GtkComboBox *combo_box);

Returns the GtkTreeModel which is acting as data source for combo_box.

combo_box : A GtkComboBox.
Returns : A GtkTreeModel which was passed during construction.

Since 2.4


gtk_combo_box_set_model ()


void gtk_combo_box_set_model (GtkComboBox *combo_box,
GtkTreeModel *model);

Sets the model used by combo_box to be model. Will unset a previously set model (if applicable). If model is NULL, then it will unset the model.

Note that this function does not clear the cell renderers, you have to call gtk_combo_box_cell_layout_clear() yourself if you need to set up different cell renderers for the new model.

combo_box : A GtkComboBox.
model : A GtkTreeModel.

Since 2.4


gtk_combo_box_new_text ()


GtkWidget* gtk_combo_box_new_text (void);

Convenience function which constructs a new text combo box, which is a GtkComboBox just displaying strings. If you use this function to create a text combo box, you should only manipulate its data source with the following convenience functions: gtk_combo_box_append_text(), gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and gtk_combo_box_remove_text().

Returns : A new text combo box.

Since 2.4


gtk_combo_box_append_text ()


void gtk_combo_box_append_text (GtkComboBox *combo_box,
const gchar *text);

Appends string to the list of strings stored in combo_box. Note that you can only use this function with combo boxes constructed with gtk_combo_box_new_text().

combo_box : A GtkComboBox constructed using gtk_combo_box_new_text().
text : A string.

Since 2.4


gtk_combo_box_insert_text ()


void gtk_combo_box_insert_text (GtkComboBox *combo_box,
gint position,
const gchar *text);

Inserts string at position in the list of strings stored in combo_box. Note that you can only use this function with combo boxes constructed with gtk_combo_box_new_text().

combo_box : A GtkComboBox constructed using gtk_combo_box_new_text().
position : An index to insert text.
text : A string.

Since 2.4


gtk_combo_box_prepend_text ()


void gtk_combo_box_prepend_text (GtkComboBox *combo_box,
const gchar *text);

Prepends string to the list of strings stored in combo_box. Note that you can only use this function with combo boxes constructed with gtk_combo_box_new_text().

combo_box : A GtkComboBox constructed with gtk_combo_box_new_text().
text : A string.

Since 2.4


gtk_combo_box_remove_text ()


void gtk_combo_box_remove_text (GtkComboBox *combo_box,
gint position);

Removes the string at position from combo_box. Note that you can only use this function with combo boxes constructed with gtk_combo_box_new_text().

combo_box : A GtkComboBox constructed with gtk_combo_box_new_text().
position : Index of the item to remove.

Since 2.4


gtk_combo_box_get_active_text ()


gchar* gtk_combo_box_get_active_text (GtkComboBox *combo_box);

Returns the currently active string in combo_box or NULL if none is selected. Note that you can only use this function with combo boxes constructed with gtk_combo_box_new_text() and with GtkComboBoxEntrys.

combo_box : A GtkComboBox constructed with gtk_combo_box_new_text().
Returns : a newly allocated string containing the currently active text.

Since 2.6


gtk_combo_box_popup ()


void gtk_combo_box_popup (GtkComboBox *combo_box);

Pops up the menu or dropdown list of combo_box.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

combo_box : a GtkComboBox

Since 2.4


gtk_combo_box_popdown ()


void gtk_combo_box_popdown (GtkComboBox *combo_box);

Hides the menu or dropdown list of combo_box.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

combo_box : a GtkComboBox

Since 2.4


gtk_combo_box_get_popup_accessible ()


AtkObject* gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box);

Gets the accessible object corresponding to the combo box's popup.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

combo_box : a GtkComboBox
Returns : the accessible object corresponding to the combo box's popup.

Since 2.6


gtk_combo_box_get_row_separator_func ()


GtkTreeViewRowSeparatorFunc gtk_combo_box_get_row_separator_func
(GtkComboBox *combo_box);

Returns the current row separator function.

combo_box : a GtkComboBox
Returns : the current row separator function.

Since 2.6


gtk_combo_box_set_row_separator_func ()


void gtk_combo_box_set_row_separator_func
(GtkComboBox *combo_box,
GtkTreeViewRowSeparatorFunc func,
gpointer data,
GtkDestroyNotify destroy);

Sets the row separator function, which is used to determine whether a row should be drawn as a separator. If the row separator function is NULL, no separators are drawn. This is the default value.

combo_box : a GtkComboBox
func : a GtkTreeViewRowSeparatorFunc
data : user data to pass to func, or NULL
destroy : destroy notifier for data, or NULL

Since 2.6


gtk_combo_box_set_add_tearoffs ()


void gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
gboolean add_tearoffs);

Sets whether the popup menu should have a tearoff menu item.

combo_box : a GtkComboBox
add_tearoffs : TRUE to add tearoff menu items

Since 2.6


gtk_combo_box_get_add_tearoffs ()


gboolean gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box);

Gets the current value of the :add-tearoffs property.

combo_box : a GtkComboBox
Returns : the current value of the :add-tearoffs property.

gtk_combo_box_set_title ()


void gtk_combo_box_set_title (GtkComboBox *combo_box,
const gchar *title);

Sets the menu's title in tearoff mode.

combo_box : a GtkComboBox
title : a title for the menu in tearoff mode.

Since 2.10


gtk_combo_box_get_title ()


const gchar* gtk_combo_box_get_title (GtkComboBox *combo_box);

Gets the current title of the menu in tearoff mode. See gtk_combo_box_set_add_tearoffs().

combo_box : a GtkComboBox
Returns : the menu's title in tearoff mode. This is an internal copy of the string which must not be freed.

Since 2.10


gtk_combo_box_set_focus_on_click ()


void gtk_combo_box_set_focus_on_click (GtkComboBox *combo,
gboolean focus_on_click);

Sets whether the combo box will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don't want the keyboard focus removed from the main area of the application.

combo : a GtkComboBox
focus_on_click : whether the combo box grabs focus when clicked with the mouse

Since 2.6


gtk_combo_box_get_focus_on_click ()


gboolean gtk_combo_box_get_focus_on_click (GtkComboBox *combo);

Returns whether the combo box grabs focus when it is clicked with the mouse. See gtk_combo_box_set_focus_on_click().

combo : a GtkComboBox
Returns : TRUE if the combo box grabs focus when it is clicked with the mouse.

Since 2.6

Property Details

The "active" property


 "active" gint : Read / Write

The item which is currently active. If the model is a non-flat treemodel, and the active item is not an immediate child of the root of the tree, this property has the value gtk_tree_path_get_indices (path)[0], where path is the GtkTreePath of the active item.

Allowed values: >= -1

Default value: -1

Since 2.4


The "add-tearoffs" property


 "add-tearoffs" gboolean : Read / Write

The add-tearoffs property controls whether generated menus have tearoff menu items.

Note that this only affects menu style combo boxes.

Default value: FALSE

Since 2.6


The "column-span-column" property


 "column-span-column" gint : Read / Write

If this is set to a non-negative value, it must be the index of a column of type G_TYPE_INT in the model.

The values of that column are used to determine how many columns a value in the list will span.

Allowed values: >= -1

Default value: -1

Since 2.4


The "focus-on-click" property


 "focus-on-click" gboolean : Read / Write

Whether the combo box grabs focus when it is clicked with the mouse.

Default value: TRUE


The "has-frame" property


 "has-frame" gboolean : Read / Write

The has-frame property controls whether a frame is drawn around the entry.

Default value: TRUE

Since 2.6


The "model" property


 "model" GtkTreeModel : Read / Write

The model from which the combo box takes the values shown in the list.

Since 2.4


The "popup-shown" property


 "popup-shown" gboolean : Read

Whether the combo boxes dropdown is popped up. Note that this property is mainly useful, because it allows you to connect to notify::popup-shown.

Default value: FALSE

Since 2.10


The "row-span-column" property


 "row-span-column" gint : Read / Write

If this is set to a non-negative value, it must be the index of a column of type G_TYPE_INT in the model.

The values of that column are used to determine how many rows a value in the list will span. Therefore, the values in the model column pointed to by this property must be greater than zero and not larger than wrap-width.

Allowed values: >= -1

Default value: -1

Since 2.4


The "tearoff-title" property


 "tearoff-title" gchararray : Read / Write

A title that may be displayed by the window manager when the popup is torn-off.

Default value: ""

Since 2.10


The "wrap-width" property


 "wrap-width" gint : Read / Write

If wrap-width is set to a positive value, the list will be displayed in multiple columns, the number of columns is determined by wrap-width.

Allowed values: >= 0

Default value: 0

Since 2.4

Style Property Details

The "appears-as-list" style property


 "appears-as-list" gboolean : Read

Whether dropdowns should look like lists rather than menus.

Default value: FALSE


The "arrow-size" style property


 "arrow-size" gint : Read

Sets the minimum size of the arrow in the combo box. Note that the arrow size is coupled to the font size, so in case a larger font is used, the arrow will be larger than set by arrow size.

Allowed values: >= 0

Default value: 15

Since 2.12

Signal Details

The "changed" signal


void user_function (GtkComboBox *widget,
gpointer user_data) : Run Last

The changed signal is emitted when the active item is changed. The can be due to the user selecting a different item from the list, or due to a call to gtk_combo_box_set_active_iter(). It will also be emitted while typing into a GtkComboBoxEntry, as well as when selecting an item from the GtkComboBoxEntry's list.

widget : the object which received the signal
user_data : user data set when the signal handler was connected.

Since 2.4


The "move-active" signal


void user_function (GtkComboBox *combobox,
GtkScrollType arg1,
gpointer user_data) : Run Last / Action

combobox : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "popup" signal


void user_function (GtkComboBox *combobox,
gpointer user_data) : Run Last / Action

combobox : the object which received the signal.
user_data : user data set when the signal handler was connected.

See Also

GtkComboBoxEntry, GtkTreeModel, GtkCellRenderer