From: Matt Birkholz Date: Sun, 12 Aug 2012 22:47:50 +0000 (-0700) Subject: gtk: Implement gtk_widget_get_preferred_width/height. X-Git-Tag: mit-scheme-pucked-9.2.12~564 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=bb92498155812b56af124d2a1ac1b315ba924958;p=mit-scheme.git gtk: Implement gtk_widget_get_preferred_width/height. Also, use gtk_widget_set_allocation and gtk_cairo_transform_to_window. --- diff --git a/src/gtk/Includes/gtkwidget.cdecl b/src/gtk/Includes/gtkwidget.cdecl index df51b1428..7092e8a5f 100644 --- a/src/gtk/Includes/gtkwidget.cdecl +++ b/src/gtk/Includes/gtkwidget.cdecl @@ -84,6 +84,10 @@ gtk/gtkwidget.h |# (widget (* GtkWidget)) (allocation (* GtkAllocation))) +(extern void gtk_widget_set_allocation + (widget (* GtkWidget)) + (allocation (* GtkAllocation))) + (extern void gtk_widget_error_bell (widget (* GtkWidget))) @@ -121,6 +125,11 @@ gtk/gtkwidget.h |# (widget (* GtkWidget)) (text (* (const gchar)))) +(extern void gtk_cairo_transform_to_window + (cr (* cairo_t)) + (widget (* GtkWidget)) + (window (* GdkWindow))) + (extern (* GtkStyleContext) gtk_widget_get_style_context (width (* GtkWidget))) \ No newline at end of file diff --git a/src/gtk/fix-layout.scm b/src/gtk/fix-layout.scm index 487875d26..0af05068f 100644 --- a/src/gtk/fix-layout.scm +++ b/src/gtk/fix-layout.scm @@ -59,10 +59,10 @@ USA. (let ((alien (gobject-alien widget))) (let ((w (->requisition-fixnum width)) (h (->requisition-fixnum height))) - (C-call "gtk_widget_set_size_request" alien w h) + (set-scm-widget-size-request! widget 0 0 w h) ;; Init. size, for a realize signal arriving before an allocation. (set-fix-rect-size! (fix-widget-geometry widget) w h)) - (C-call "gtk_widget_set_has_window" alien 1)) ; WILL have when realized + (C-call "gtk_widget_set_has_window" alien 1)) (set-gtk-widget-realize-callback! widget fix-widget-realize-callback) (set-gtk-widget-size-allocate-callback! widget allocate-callback) @@ -109,6 +109,7 @@ USA. (height (C-> GtkAllocation "GtkAllocation height")) (rect (fix-widget-geometry widget))) (%trace "; allocated "width"x"height" at "x","y" for "widget"\n") + (C-call "gtk_widget_set_allocation" (gobject-alien widget) GtkAllocation) (set-fix-rect! rect x y width height) (if (fix-widget-realized? widget) (C-call "gdk_window_move_resize" @@ -408,6 +409,7 @@ USA. (view (fix-layout-view layout))) (let ((offx (fix-rect-x view)) (offy (fix-rect-y view))) + (C-call "gtk_cairo_transform_to_window" cr (gobject-alien layout) window) (fix:clip-region cr (lambda (x y w h) (if drawing @@ -699,6 +701,8 @@ USA. (define (resizer-draw-callback resizer cr) (let ((geom (fix-widget-geometry resizer)) (style (gtk-widget-style-context resizer))) + (C-call "gtk_cairo_transform_to_window" cr (gobject-alien resizer) + (fix-widget-window resizer)) (C-call "gtk_render_handle" style cr (->flonum (fix-rect-x geom)) (->flonum (fix-rect-y geom)) @@ -756,11 +760,12 @@ USA. (let ((w (fix:+ (car w.h-before) dx)) (h (fix:+ (cdr w.h-before) dy))) (%trace "; resizing "before" to "w"x"h"\n") - (gtk-widget-set-size-request before w h)) + (set-scm-widget-size-request! (gtk-bin-child before) + 0 0 w h)) (let ((w (fix:- (car w.h-after) dx)) (h (fix:- (cdr w.h-after) dy))) (%trace "; resizing "after" to "w"x"h"\n") - (gtk-widget-set-size-request after w h)))))) + (set-scm-widget-size-request! after 0 0 w h)))))) (if (fix-resizer-stack-vertical? resizer) @@ -1789,7 +1794,6 @@ USA. (y (->flonum (fix:- (fix-rect-y extent) (fix-rect-y view)))) (width (->flonum (fix-rect-width extent))) (height (->flonum (fix-rect-height extent)))) - (C-call "gtk_render_background" style cr x y width height) (C-call "gtk_render_focus" style cr x y width height)))) (define-method fix-ink-move! ((ink ) dx dy) diff --git a/src/gtk/gtk.cdecl b/src/gtk/gtk.cdecl index 0c731a089..6375ee94b 100644 --- a/src/gtk/gtk.cdecl +++ b/src/gtk/gtk.cdecl @@ -86,6 +86,10 @@ USA. (typedef ScmWidget (struct _ScmWidget (widget GtkWidget) + (minimum_width gint) + (minimum_height gint) + (natural_width gint) + (natural_height gint) (hadjustment (* GtkAdjustment)) (vadjustment (* GtkAdjustment)) (hscroll_policy guint) diff --git a/src/gtk/gtk.pkg b/src/gtk/gtk.pkg index 13ccbcd43..779d11d66 100644 --- a/src/gtk/gtk.pkg +++ b/src/gtk/gtk.pkg @@ -212,7 +212,8 @@ USA. set-gtk-widget-destroy-callback!) (export (gtk) - set-scm-widget-set-scroll-adjustments-callback!)) + set-scm-widget-set-scroll-adjustments-callback! + set-scm-widget-size-request!)) (define-package (gtk fix-layout) (parent (gtk)) diff --git a/src/gtk/scm-widget.scm b/src/gtk/scm-widget.scm index 683961d0f..acdeff238 100644 --- a/src/gtk/scm-widget.scm +++ b/src/gtk/scm-widget.scm @@ -40,4 +40,18 @@ USA. (define (set-scm-widget-set-scroll-adjustments-callback! widget callback) (guarantee-scm-widget widget 'set-scm-widget-set-scroll-adjustments-callback!) (guarantee-procedure-of-arity callback 3 'set-scm-widget-set-scroll-adjustments-callback!) - (g-signal-connect widget (C-callback "set_scroll_adjustments") callback)) \ No newline at end of file + (g-signal-connect widget (C-callback "set_scroll_adjustments") callback)) + +(define (set-scm-widget-size-request! widget + minimum-width minimum-height + natural-width natural-height) + (guarantee-scm-widget widget 'set-scm-widget-size-request!) + (guarantee-non-negative-fixnum minimum-width 'set-scm-widget-size-request!) + (guarantee-non-negative-fixnum minimum-height 'set-scm-widget-size-request!) + (guarantee-non-negative-fixnum natural-width 'set-scm-widget-size-request!) + (guarantee-non-negative-fixnum natural-height 'set-scm-widget-size-request!) + (let ((a (gobject-alien widget))) + (C->= a "ScmWidget minimum_width" minimum-width) + (C->= a "ScmWidget minimum_height" minimum-height) + (C->= a "ScmWidget natural_width" natural-width) + (C->= a "ScmWidget natural_height" natural-height))) \ No newline at end of file diff --git a/src/gtk/scmwidget.c.stay b/src/gtk/scmwidget.c.stay index 96d9c5676..ccefbaec7 100644 --- a/src/gtk/scmwidget.c.stay +++ b/src/gtk/scmwidget.c.stay @@ -41,6 +41,12 @@ static void scm_widget_set_property (GObject *object, guint prop_id, static void scm_widget_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static void scm_widget_realize (GtkWidget *widget); +static void scm_widget_get_preferred_width (GtkWidget *widget, + gint *minimum_size, + gint *natural_size); +static void scm_widget_get_preferred_height (GtkWidget *widget, + gint *minimum_size, + gint *natural_size); static guint set_scroll_adjustments_signal_id; @@ -86,6 +92,10 @@ G_DEFINE_TYPE_WITH_CODE (ScmWidget, scm_widget, GTK_TYPE_WIDGET, static void scm_widget_init (ScmWidget *widget) { + widget->minimum_width = 0; + widget->minimum_height = 0; + widget->natural_width = 0; + widget->natural_height = 0; widget->hadjustment = NULL; widget->vadjustment = NULL; widget->hscroll_policy = GTK_SCROLL_NATURAL; @@ -105,6 +115,8 @@ scm_widget_class_init (ScmWidgetClass *klass) gobject_class->get_property = scm_widget_get_property; widget_class->realize = scm_widget_realize; + widget_class->get_preferred_width = scm_widget_get_preferred_width; + widget_class->get_preferred_height = scm_widget_get_preferred_height; gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_VIEWPORT); @@ -228,3 +240,31 @@ scm_widget_realize (GtkWidget* widget) gtk_widget_set_realized (widget, TRUE); } + +static void +scm_widget_get_preferred_width (GtkWidget *widget, + gint *minimum_size, + gint *natural_size) +{ + ScmWidget *scm_widget = SCM_WIDGET (widget); + + if (minimum_size) + *minimum_size = scm_widget->minimum_width; + + if (natural_size) + *natural_size = scm_widget->natural_width; +} + +static void +scm_widget_get_preferred_height (GtkWidget *widget, + gint *minimum_size, + gint *natural_size) +{ + ScmWidget *scm_widget = SCM_WIDGET (widget); + + if (minimum_size) + *minimum_size = scm_widget->minimum_height; + + if (natural_size) + *natural_size = scm_widget->natural_height; +} diff --git a/src/gtk/scmwidget.h b/src/gtk/scmwidget.h index ad84b0326..8d3dfef48 100644 --- a/src/gtk/scmwidget.h +++ b/src/gtk/scmwidget.h @@ -38,6 +38,10 @@ struct _ScmWidgetClass struct _ScmWidget { GtkWidget widget; + gint minimum_width; + gint minimum_height; + gint natural_width; + gint natural_height; GtkAdjustment *hadjustment; GtkAdjustment *vadjustment; guint hscroll_policy;