Re: gtk_widget_get_child_requisition always returns (0,0)



On Wed, 2007-06-27 at 21:51 -0700, ext Spencer, Bob wrote:
> 
> I'm using version (0.0.18) of hildon-desktop from svn.  I'm adding a
> button to a panel.  The widget has called "gtk_widget_set_size_request
> (button, 48, 48);"  but in the panel it doesn't recognize this
> request.  Looking into it I found:
> 
>         hildon-desktop-panel.c,  
>                 hildon_desktop_panel_real_add_button (…) { 
>                         ... 
>         ~ln 352:        gtk_widget_get_child_requisition (widget,
> &req);        //always returns (0,0) 
>                         ... 
>                 } 
> gtk_widget_get_child_requisition(...) is always returning (0,0) for
> the req. width and height.  This causes the default values to be used
> (80,80).

That looks like a bug in the panel. It should be calling
gtk_widget_size_request() instead.


gtk_widget_get_child_requisition() is an optimization which you can
safely call only if you *know* that the widget in question has had its
size requisition correctly calculated already. As a container you can
call gtk_widget_size_request() on your child widgets in size-request and
be sure the gtk_widget_get_child_requisition() is valid in
size-allocate, but not necessarily elsewhere.

Since it's an optimization, unless the size requisition calculation is
terribly expensive you'd be safer to use gtk_widget_size_request()
instead.


> If I replace the call with gtk_widget_size_request (widget, &req);
> then I always get the requested width/height.   
> From the docs:
> http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#gtk-widget-get-child-requisition it seems that the panel should get the right values with the current code. 

Only if you have called gtk_widget_set_size_request() for exactly the
same widget the panel will call gtk_widget_get_child_requisition() on.


-- 
Tommi Komulainen                            <tommi komulainen nokia com>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]