Re: Gtkcombo



Sorry Carlos... Just saw I post the response to you only :)
This one is posted to the list with the previous answer

Hi Carlos,

I'm not sure this is a good idea.
combo box strings may come from a configuration file
or from user input. Moreover you may have a lot of
strings in the combo box and this should really be
a pain.

A way to achieve the same is to work on the public GtkList
in the GtkCombo.

AFAIK v1.2.x GtkList structure contains two members
called children and selection. children is a
GList of GtkListItem as well as selection. Since you
have only one selection, you can run through the
children list to find the GtkListItem which is held
in the selection list.

I just saw that my english is worse than ever so I
should better provide a small snip of code :)

gint gtk_combo_get_item_pos(GtkWidget *p_widget)
{
  GtkList *p_list = GTK_LIST(GTK_COMBO(p_widget)->list);
  GList *p_children;
  GList *p_sel;

  p_sel = p_list->selection;
  p_child = p_list->children;

  return (g_list_index(p_children, p_sel->data));
}

Hope this
a) is not too false
b) helps

I totally agree. My purpose was only to get him started on 
how to use a combo box. Go through the list is certainly a
much better option (perhaps the only possible) if the information 
comes from a configuration file, as you said. 

Anyway, the difference between a combo box and an 
option menu is that in the combo box the user
is free to write something different, so usually
you have to parse the entry, checking for errors,
which implies some string manipulation. To handle
properly a combo is a bit more than just know the
order of the selected item. What happens if the
user wrote something different in the entry? that
should NOT be an error just by itself. If the user

    I agree with this. As an addition to the former
    asnswer I made, I would like to add that when the
    combo entry is modified, the list selection is
    modified too. So the gtk_combo_get_item_pos()
    function will return -1. In this case, you can
    parse the entry in order to validate it. 

cannot choose different, unlisted, options, then the
right choice is an option menu, not a combo box.

Carlos

Yours,

Emmanuel





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]