GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 28, 2014 9:40 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: how to find a child
PostPosted: Tue Apr 03, 2007 10:40 am 
Offline
Familiar Face

Joined: Tue Mar 27, 2007 8:56 am
Posts: 26
I'm new to gtk+ and want to ask a newbie question, apologise if it has been asked before.

Suppose I create a toplevel gtkwindow, and add a gtkvbox to it. Then I add a menu, a toolbar, a gtkfixed, and a statusbar to the gtkvbox.

Code:
  window=. 0{:: gtk_window_new <GTK_WINDOW_TOPLEVEL
  gtk_window_set_title window ;< id
  vbox1=. 0{:: gtk_vbox_new 0 ;< 0
  gtk_widget_show <vbox1
  gtk_container_add window ;< vbox1
NB. menubar
  menubar1=. 0{:: gtk_menu_bar_new ''
  gtk_box_pack_start vbox1 ; menubar1 ; 0 ; 0 ;< 0
NB. toolbar
  toolbar1=. 0{:: gtk_toolbar_new ''
  gtk_box_pack_start vbox1 ; toolbar1 ; 0 ; 0 ;< 0
NB. fixed
  fixed1=. 0{:: gtk_fixed_new ''
  gtk_widget_show <fixed1
  gtk_box_pack_start vbox1 ; fixed1 ; 0 ; 0 ;< 0
NB. statusbar
  statusbar1=. 0{:: gtk_statusbar_new ''
  gtk_widget_show <statusbar1
  gtk_statusbar_set_has_resize_grip statusbar1 ;< 0
  gtk_box_pack_start vbox1 ; statusbar1 ; 0 ; 0 ;< 0


Then I want to get the pointer of each child using code
Code:
NB. get handle of child gtkfixed
  g1=. 0{:: gtk_container_get_children <window
  vbox1=. 0{:: g_list_nth_data g1 ;< 0
  g2=. 0{:: gtk_container_get_children <vbox1
  fixed1=. 0{:: g_list_nth_data g2 ;< 2  NB. menu toolbar fxied  statusbar
  g_list_free <g2
  g_list_free <g1


Here fixed1 for g_list_nth_data is the 2 (index-0) child, but I might not create menu or toolbar so that the index method does not always work. What is the better way of finding fixed1?

PS. the programming language I used is not c/c++ but it directly call gtk+ api. Please interpret it as pseudo code for discussion.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 11:11 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Well, what you _should_ do is create a structure that holds all of the children and pass that to your function. If you want to use gtk_container_get_children(), use:

Code:
GList *list;
for (list = g1; list != NULL; list = list->next)
  if (GTK_IS_FIXED (list->data))
    /* Use the fixed widget. */


This is in C, but can easily be converted to any other language. By looping like this, you avoid traversing the list on every call to g_list_nth_data().

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 6:42 am 
Offline
Familiar Face

Joined: Tue Mar 27, 2007 8:56 am
Posts: 26
openldev wrote:
Well, what you _should_ do is create a structure that holds all of the children and pass that to your function. If you want to use gtk_container_get_children(), use:

Thank you for suggestion. I use a scripting language that creates gui dynamically so it is more convinient to discover children using gtk_container_get_children.
Another question, does structures in gtk+ always use 4-bytes alignment in 32-bit os? And will it be 8-bytes on 64-bit os?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 11:51 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Structures in GTK+ are pure C, so if you look into the implementation of C structures, you can find out.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group