gtk: Implement gtk_widget_get_preferred_width/height.
authorMatt Birkholz <matt@birkholz.chandler.az.us>
Sun, 12 Aug 2012 22:47:50 +0000 (15:47 -0700)
committerMatt Birkholz <matt@birkholz.chandler.az.us>
Sun, 12 Aug 2012 22:47:50 +0000 (15:47 -0700)
Also, use gtk_widget_set_allocation and gtk_cairo_transform_to_window.

src/gtk/Includes/gtkwidget.cdecl
src/gtk/fix-layout.scm
src/gtk/gtk.cdecl
src/gtk/gtk.pkg
src/gtk/scm-widget.scm
src/gtk/scmwidget.c.stay
src/gtk/scmwidget.h

index df51b1428727c8f1f216f603f58284c6b28cdaed..7092e8a5ff5e90b024fcbdb82635d68d80646eb8 100644 (file)
@@ -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
index 487875d269b222f1f80dec75634e9bdfbef4ce31..0af05068f3b01340bdac80f838598885df896702 100644 (file)
@@ -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 <box-ink>) dx dy)
index 0c731a089db2857308bbe1b2a7a9d94429016013..6375ee94b6d12580d7c55adb91cb34f9dff4a54e 100644 (file)
@@ -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)
index 13ccbcd43b257a5d801cace3ed7ec7420b4b9106..779d11d663d311ed01dc24521c7aa9a93ea3ffe2 100644 (file)
@@ -212,7 +212,8 @@ USA.
          set-gtk-widget-destroy-callback!)
   (export (gtk)
          <scm-widget>
-         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))
index 683961d0fcce01383c336c8e002ba3c71492860e..acdeff2380f457713cc832845977ef03278478d5 100644 (file)
@@ -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
index 96d9c567602223b52654c9969525ce4623a842c2..ccefbaec776cec7a4a715b616f5a6896ea606a67 100644 (file)
@@ -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;
+}
index ad84b032608a402330b4400f98b8aa27ae553d84..8d3dfef4833c5b93953b6d1dcccf5974ace33307 100644 (file)
@@ -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;