I miss the bindings for 'GtkWidget::allocation' in widgets in the pike bindings for GTK2. In the GTK(1)-module there is an allocation() method plus that there are the methods xsize(), ysize(), xoffset() and yoffset() on the GTK.Widget object. I need these for knowing the size of an widget.
Anybody knows the reason for this?
On Sat, 2006-02-04 at 15:25 +0000, davve (David Vest) @ Pike (-) developers forum wrote:
I miss the bindings for 'GtkWidget::allocation' in widgets in the pike bindings for GTK2. In the GTK(1)-module there is an allocation() method plus that there are the methods xsize(), ysize(), xoffset() and yoffset() on the GTK.Widget object. I need these for knowing the size of an widget.
Anybody knows the reason for this?
The closest that GTK2 has is gtk_widget_size_request(), which returns a structure. I apparently missed that function; I'll add it right now...
The closest that GTK2 has is gtk_widget_size_request(), which returns a structure. I apparently missed that function; I'll add it right now...
Um, what do you mean? An GtkWidget in GTK2 also has an allocation member of type GtkAllocation (which is a GdkRectangle in GTK2), just like in GTK 1.2.
On Sat, 2006-02-04 at 15:25 +0000, davve (David Vest) @ Pike (-) developers forum wrote:
I miss the bindings for 'GtkWidget::allocation' in widgets in the pike bindings for GTK2. In the GTK(1)-module there is an allocation() method plus that there are the methods xsize(), ysize(), xoffset() and yoffset() on the GTK.Widget object. I need these for knowing the size of an widget.
Anybody knows the reason for this?
Okay, I added size_request() and size_allocate(). I hope that does what you need. If not, let me know, and I will find something more appropriate.
When I went on trying to test your check-ins I noticed that gtktreedragsource.inc seems to be missing from src/post_modules/GTK2/source/
Parsing input files... /home/davve/extern/cvs/Pike/7.7/src/post_modules/GTK2/source/gtktreestore.pre:364: Error: Failed to read /home/davve/extern/cvs/Pike/7.7/src/post_modules/GTK2/source/gtktreedragsource.inc make[3]: *** [compile1] Error 1 make[3]: Leaving directory `/home/davve/extern/cvs/Pike/7.7/build/post_modules/GTK2' make[2]: *** [GTK2] Error 1 make[2]: Leaving directory `/home/davve/extern/cvs/Pike/7.7/build/post_modules' make[1]: *** [post_module_objects] Error 1 make[1]: Leaving directory `/home/davve/extern/cvs/Pike/7.7/build' make: *** [all] Error 2
Okay, I added size_request()
I can't say exactly what 'gtk_widget_size_request' is supposed to do[1], but I don't think it really related to what I was asking about, the current size of a widget.
and size_allocate().
The docs for 'gtk_widget_size_allocate'[2] are a bit more clear:
"This function is only used by GtkContainer subclasses, to assign a size and position to their child widgets."
I was thinking more in the line of what is implemented in the (old) GTK module, adding a allocation() method in gtkwidget.pre:
mapping(string:int) allocation() //! Returns ([ "x":xoffset, "y":yoffset, "width":xsize, "height":ysize ]) { pgtk_verify_inited(); push_text( "x" ); push_int( GTK_WIDGET( THIS->obj )->allocation.x ); push_text( "y" ); push_int( GTK_WIDGET( THIS->obj )->allocation.y ); push_text( "width" ); push_int( GTK_WIDGET( THIS->obj )->allocation.width ); push_text( "height" ); push_int( GTK_WIDGET( THIS->obj )->allocation.height ); f_aggregate_mapping( 8 ); }
But as marcus points out, it is not strictly necessary.
[1] URL:http://developer.gimp.org/api/2.0/gtk/GtkWidget.html#gtk-widget-size-request [2] URL:http://developer.gimp.org/api/2.0/gtk/GtkWidget.html#gtk-widget-size-allocate
mapping(string:int) allocation() //! Returns ([ "x":xoffset, "y":yoffset, "width":xsize, "height":ysize ]) { pgtk_verify_inited(); push_text( "x" ); push_int( GTK_WIDGET( THIS->obj )->allocation.x ); push_text( "y" ); push_int( GTK_WIDGET( THIS->obj )->allocation.y ); push_text( "width" ); push_int( GTK_WIDGET( THIS->obj )->allocation.width ); push_text( "height" ); push_int( GTK_WIDGET( THIS->obj )->allocation.height ); f_aggregate_mapping( 8 ); }
Okay, I added this convenience function. We'll see if this does it...
You can connect a handler to the signal "size_allocate". The handler will be called with the allocation in the second argument, whenever the widget is allocated a (new) size.
One could do that, but it means manual tracking of the sizes of all relevant widgets. I would prefer a binding to the allocation rect directly, since those structures already are updated on the C-level.
pike-devel@lists.lysator.liu.se