tags:

views:

203

answers:

2

I have an application layer that I'd like to port to Gtk that has all it's own layout code and I don't really want to spend 'n' months re-writting it to work with the Gtk layout system, but rather just using the existing internal layout code and have Gtk render the resulting widgets.

I've started by writting my own widget after trying several of the built in containers. Basically I'm looking for something like the GtkFixed container that doesn't have a minimum size, i.e. Gtk will fit the first widget to the entire window, and all the child widgets will lay themselves out so that they fill the area. If I use GtkFixed for that, the window is always limited to the size of the initial layout, as thats the "requested" space. I can't resize it smaller than that using the edges of the window decor.

Maybe I need schooling in allocation vs requesting. My googling so far hasn't found the information I need to make this work. I did try.

I'm using the C api at the moment, and I'm targetting Win32 and Linux. So far I have a shell app working in Win32 that puts up an empty window. But the first child widget is limiting the resizing to it's initial size.

+2  A: 

I believe you want to use a GtkFixed and connect to the size-request signal on it, which gets called whenever the widget is asked to figure out how much space it wants. Modify the GtkRequisition struct to be however much space you want the widget to have. This will be the amount of space the GTK layout engine tries to allocate to the widget if possible, so it's essentially the minimum size you want the widget to have. The layout engine, of course, is free to allocate more (or less!) space than you request.

Paul Kuliniewicz
I tried that, and once I've returned that size to GTK I can't resize the window any smaller than that in the case where I have the GtkFixed in the GtkWindow. If I try and use 1x1, then it's not stretched to fill the window either... it just sits up in the top left corner at 0,0-1,1.
fret
A: 

The problem with my code is that I was catching the "configure-event" and returning TRUE, which stopped some of the normal GTK layout stuff from working. I need that event to update my internal size variables, but I also need to return FALSE to allow the next handler to get that signal.

Now my widget can assume the size of client area of the window correctly and I can then use GtkFixed style positioning to layout my controls where I need them to go.

fret
How are you setting the size of the first widget without it making your container stuck at that size?
pib
For the top most widget inside the window I request 10x10 pixels and Gtk expands that to fill the whole window. The rest of the child widgets request their defined size exactly.
fret