Re: Iterating through children



        Well, looking at your function I realized that it might be more helpful
then I thought. Here is what I am trying to accomplish:
        I am not sure whether you are familiar with the lookup_widget ()
function that glade/glade-2 generates as part of its gtk code but what
it does is allow the programmer to get a pointer to any widget just by
passing an arbitrary widget and the name of the variable that is used to
point to the sought widget.
        I am trying to duplicate this functionality! The reason why I am not
using lookup_widget is that it requires that the top level widget is a
window. Unfortunately, I don't have that pointer since the container
that I am working with gets passed to me.
        If would appreciate it very much if anyone can help with this.
Otherwise, I will have to resort to making all the needed widgets global
:(

        Below is the code that glade-2 generates:

#define GLADE_HOOKUP_OBJECT(component,widget,name) \
  g_object_set_data_full (G_OBJECT (component), name, \
    gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)

#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
  g_object_set_data (G_OBJECT (component), name, widget)


GtkWidget*
lookup_widget                          (GtkWidget       *widget,
                                        const gchar     *widget_name)
{
  GtkWidget *parent, *found_widget;

  for (;;)
    {
      if (GTK_IS_MENU (widget))
        parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
      else
        parent = widget->parent;
      if (!parent)
        parent = g_object_get_data (G_OBJECT (widget),
"GladeParentKey");      if (parent == NULL)
        break;
      widget = parent;
    }

  found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
                                                 widget_name);
  if (!found_widget)
    g_warning ("Widget not found: %s", widget_name);
  return found_widget;
}


On Fri, 17 Oct 2003 00:55:11 +0200
Gus Koppel <gtk spamkiller bytechase cx> wrote:

Dimitar Haralanov wrote:

    Does any one know of a good way to iterate through all the
    children of a widget? What I need is to be able to reach every
    child of a top level window notebook page

The key function for this to use is gtk_container_get_children (). You
may have a look at my widget_find_by_name () function which
demonstrates how to use it recursively. Just rename the function and
remove the name-specific string comparisons and you should have what
you were looking for.

http://www.spamkiller.bytechase.cx/democode/widget_find_by_name.c
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


-- 
Mitko Haralanov
mitko keyresearch com
http://www.keyresearch.com

==========================================
56. Sorry, we deleted that package last week...

        --Top 100 things you don't want the sysadmin to say



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