GtkCombo: retrieving the index of the selection
- From: Fabian Bastin <bastin fabian freebel be>
- To: gtk-list gnome org
- Subject: GtkCombo: retrieving the index of the selection
- Date: Wed, 17 May 2000 09:11:23 +0200
I use a GtkCombo widget in my program, and I would to know the index of the
selection when the user press a button (the callback has the combo as data).
Unfornulately, I haven't found any function that performs this. I can get the
text of the selection, but not the position in the list.
I have wrotten this code to perform this, but I think that is not clean and I
would like to know if there is no better way to do what I want.
int gtk_combo_index(GtkCombo *combo)
{
if (combo) {
int idx = 0;
GList *clist;
GtkListItem *li;
GtkWidget *label;
char *text = gtk_entry_get_text(GTK_ENTRY(combo->entry));
char *text2;
clist = GTK_LIST(combo->list)->children;
while (clist) {
li = GTK_LIST_ITEM(clist->data);
/* the constant "gtk-combo-string-value is defined in gtkcombo.c, but
* an usage like this one is certainly bad */
text2 = (char *)gtk_object_get_data(GTK_OBJECT((GtkListItem *)
(clist->data)),
"gtk-combo-string-value");
if (!text2) {
label = GTK_BIN(li)->child;
if (label)
if (GTK_IS_LABEL(label)) gtk_label_get(GTK_LABEL(label), &text2);
}
if (text2) {
if (!strcmp(text2, text))
return idx;
}
idx++;
clist = clist->next;
}
}
return -1;
}
Thank you for your help.
Fabian Bastin
--
Fabian Bastin
FUNDP, Dipartement de mathimatiques
GRT (Groupe de Recherche sur les Transports)
Rempart de la Vierge 8
B-5000 Namur
Tel: +32 (0)81 724923
Fax: +32 (0)81 724914
email: fbas@math.fundp.ac.be
fabian.bastin@fundp.ac.be
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]