GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to find a child

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
bil
Familiar Face


Joined: 27 Mar 2007
Posts: 26

PostPosted: Tue Apr 03, 2007 10:40 am    Post subject: how to find a child Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

  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: (Plaintext)
1
2
3
4
5
6
7
8
9

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.
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 387
Location: Fairfax, Virginia

PostPosted: Tue Apr 03, 2007 11:11 am    Post subject: Reply with quote

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: (Plaintext)
1
2
3
4
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().
Back to top
bil
Familiar Face


Joined: 27 Mar 2007
Posts: 26

PostPosted: Wed Apr 04, 2007 6:42 am    Post subject: Reply with quote

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?
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 387
Location: Fairfax, Virginia

PostPosted: Wed Apr 04, 2007 11:51 am    Post subject: Reply with quote

Structures in GTK+ are pure C, so if you look into the implementation of C structures, you can find out.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP