Is there a better way?  [code sample incl.]
- From: Eric Harlow <linuxgeek yahoo com>
- To: gtk-list redhat com
- Subject: Is there a better way?  [code sample incl.]
- Date: Sat, 11 Jul 1998 06:16:24 -0700 (PDT)
I wanted to write a piece of code that would display all the items in
a listbox that were "selected" by calling this DisplaySelectedItems
function.  Turns out to require a few steps - The DisplaySelectedItems
has to call the "foreach" function for the children to get each of
them to print.  At this point, although I have the GtkListItem widget,
I cannot use this directly to figure out what the text is, but instead
have to make another "foreach" call looking for a label in there and
returning it.  Listbox->children->children->text
Is there a "better" way of doing this?
 -Eric
void DisplaySelectedItems (GtkWidget *widget)
{
    // --- Check all children
    gtk_container_foreach (GTK_CONTAINER (widget),
                           (GtkCallback) ShowSelected,
                           NULL);
}
void ShowSelected (GtkWidget *widget, gpointer data)
{
    printf ("state = %d, label = %s\n", (int) GTK_WIDGET_STATE (widget),
            GetItemLabel (widget));
}
char *GetItemLabel (GtkWidget *widget)
{
    GtkWidget *label = NULL;
    char *str;
    gtk_container_foreach (GTK_CONTAINER (widget),
                           (GtkCallback) FindLabel,
                           &label);
    gtk_label_get (GTK_LABEL (label), &str);
    return (str);
}
void FindLabel (GtkWidget *widget, gpointer data)
{
    GtkWidget **label;
    if (GTK_IS_LABEL (widget)) {
        label = (GtkWidget **) data;
        *label = widget;
    }
}
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]