GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Nov 01, 2014 6:40 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: apparent bug: gtk layout within gtk_box
PostPosted: Tue Oct 09, 2012 8:18 am 
Offline
Familiar Face

Joined: Tue Jan 03, 2012 11:28 am
Posts: 6
I went through an old GTK application to replace deprecated GTK3 functions.
I ran into an apparent GTK3 bug, unless there is something I am missing.

The program:
main window with vertical packing box.
The packing box contains a toolbar and a layout.
When I replaced
"gtk_vbox_new(0,0)" with
"gtk_box_new(GTK_ORIENTATION_VERTICAL,0)"
The layout no longer worked.
Using cairo to write text and pixbufs into the layout produced only a blank window.
No diagnostics were produced.

This old code works OK:
Code:
   mWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   vBox = gtk_vbox_new(0,0);                           //  deprecated function
   layout = gtk_layout_new(0,0);
   gtk_container_add(GTK_CONTAINER(mWin),vBox);
   gtk_container_add(GTK_CONTAINER(vBox),layout);


This new code does not work:
Code:
   mWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   vBox = gtk_box_new(GTK_ORIENTATION_VERTICAL,0);   //  replacement function
   layout = gtk_layout_new(0,0);
   gtk_container_add(GTK_CONTAINER(mWin),vBox);
   gtk_container_add(GTK_CONTAINER(vBox),layout);


Is this a bug or must I do something different?
I could not find anything relevant in the GTK docs or in this forum.


Top
 Profile  
 
 Post subject: Re: apparent bug: gtk layout within gtk_box
PostPosted: Tue Oct 09, 2012 11:29 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
There's so many things that could go wrong and though you've provided a fair amount of information, more would always be better.

#1 stab in the dark at what could go wrong is that I discovered when switching to gtk3 is that widgets no loger naturally expanded to fill up my boxes and tables like i was used to and I needed to set gtk_widget_set_hexpand etc. on the child widgets. Without this my GtkDrawingCanvas based widget was all scrunched up to no size at all even after I manually resized it.

Beyond that I only have questions. Do you compile with -Wall etc? Do you run the program from the command line so you can see any debug output? (is this what you mean by no diagnostics produced?) Try querying your layout for information (e.g. is it NULL, is it not realised, what are its height and width, etc.). Unless you can actually see and show that the bug is from a gtk function then it is not likely a gtk bug. But yes things could be documented a bit better, as saying that it is a simple switch is a bit misleading; as the whole is more than the parts there is always a complex interaction going on that will foil a reductionist approach.

Incidently you should really be using GtkGrid as they are making moves to remove GtkBox entirely in which case going through one transition is better than 2. Also if your packing more than the one widget in the box why are you using container_add?


Top
 Profile  
 
 Post subject: Re: apparent bug: gtk layout within gtk_box
PostPosted: Tue Oct 09, 2012 12:13 pm 
Offline
Familiar Face

Joined: Tue Jan 03, 2012 11:28 am
Posts: 6
I just realised that using gtk_box_pack_xxxx() is the correct way to add items to a box container, not gtk_container_add().
When this change is made, the non-working version does work.

The question remains about why changing
gtk_vbox_new(0,0) to
gtk_box_new(GTK_ORIENTATION_VERTICAL,0)
caused working code to fail.

I think Paul Childs may have the answer: child widgets can default to zero size unless this is changed, and that may be a difference between GTK2 and GTK3.

Thanks, Paul.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


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