GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 30, 2014 7:54 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to recursively count GtkLabels?
PostPosted: Mon May 05, 2014 6:33 pm 
Offline

Joined: Fri Feb 08, 2013 1:55 am
Posts: 1
Starting with a GtkWindow, I want a function that returns the total number of GtkLabels that appear in the window at all levels. I tried this:

Code:
   static void recursive_label_count(void *widget, unsigned int *cptr)
   {     
      if (GTK_IS_LABEL(widget))
         *cptr += 1 ;
      else if (GTK_IS_CONTAINER(widget))
         gtk_container_foreach(widget, (GtkCallback)recursive_label_count, cptr) ;
   }

   unsigned int container_label_count(void *container)
   {
      unsigned int count = 0 ;
      recursive_label_count(container, &count) ;
      return count ;
   }


I created a window and added a GtkMenuBar. The menu bar has three menus, each with multiple items.

If I use "container_label_count" on the window, it return 3.
If I use the function on the menu bar itself, it returns 3.
If I use the function on the individual menus, it return the number of GtkLabels inside each menu.

Why doesn't the function return the recursive total when applied to the window itself or to the menu bar?

Aren't the menus children (at some level) of the menu bar?
I also tried using gtk_container_forall, but it made no different.

Thanks for any insight.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group