[gimp/gtk3-port: 130/143] app: port GimpOverlayBox to GtkWidget::get_preferred_width/height()



commit 47fbcfbea9a168c1586b279d574f1d0f94d2480d
Author: Michael Natterer <mitch gimp org>
Date:   Fri Nov 19 13:58:10 2010 +0100

    app: port GimpOverlayBox to GtkWidget::get_preferred_width/height()

 app/widgets/gimpoverlaybox.c   |   50 ++++++++++++++++++++++----------
 app/widgets/gimpoverlaychild.c |   22 +++++++++++--
 app/widgets/gimpoverlaychild.h |   62 ++++++++++++++++++++-------------------
 3 files changed, 84 insertions(+), 50 deletions(-)
---
diff --git a/app/widgets/gimpoverlaybox.c b/app/widgets/gimpoverlaybox.c
index 9674c99..6b61d4e 100644
--- a/app/widgets/gimpoverlaybox.c
+++ b/app/widgets/gimpoverlaybox.c
@@ -41,8 +41,12 @@ static void        gimp_overlay_box_get_property        (GObject        *object,
 
 static void        gimp_overlay_box_realize             (GtkWidget      *widget);
 static void        gimp_overlay_box_unrealize           (GtkWidget      *widget);
-static void        gimp_overlay_box_size_request        (GtkWidget      *widget,
-                                                         GtkRequisition *requisition);
+static void        gimp_overlay_box_get_preferred_width (GtkWidget      *widget,
+                                                         gint           *minimum_width,
+                                                         gint           *natural_width);
+static void        gimp_overlay_box_get_preferred_height(GtkWidget      *widget,
+                                                         gint           *minimum_height,
+                                                         gint           *natural_height);
 static void        gimp_overlay_box_size_allocate       (GtkWidget      *widget,
                                                          GtkAllocation  *allocation);
 static gboolean    gimp_overlay_box_draw                (GtkWidget      *widget,
@@ -78,14 +82,15 @@ gimp_overlay_box_class_init (GimpOverlayBoxClass *klass)
   GtkWidgetClass    *widget_class    = GTK_WIDGET_CLASS (klass);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
-  object_class->set_property  = gimp_overlay_box_set_property;
-  object_class->get_property  = gimp_overlay_box_get_property;
+  object_class->set_property         = gimp_overlay_box_set_property;
+  object_class->get_property         = gimp_overlay_box_get_property;
 
-  widget_class->realize       = gimp_overlay_box_realize;
-  widget_class->unrealize     = gimp_overlay_box_unrealize;
-  widget_class->size_request  = gimp_overlay_box_size_request;
-  widget_class->size_allocate = gimp_overlay_box_size_allocate;
-  widget_class->draw          = gimp_overlay_box_draw;
+  widget_class->realize              = gimp_overlay_box_realize;
+  widget_class->unrealize            = gimp_overlay_box_unrealize;
+  widget_class->get_preferred_width  = gimp_overlay_box_get_preferred_width;
+  widget_class->get_preferred_height = gimp_overlay_box_get_preferred_height;
+  widget_class->size_allocate        = gimp_overlay_box_size_allocate;
+  widget_class->draw                 = gimp_overlay_box_draw;
 
   g_signal_override_class_handler ("damage-event",
                                    GIMP_TYPE_OVERLAY_BOX,
@@ -186,20 +191,33 @@ gimp_overlay_box_unrealize (GtkWidget *widget)
 }
 
 static void
-gimp_overlay_box_size_request (GtkWidget      *widget,
-                               GtkRequisition *requisition)
+gimp_overlay_box_get_preferred_width (GtkWidget *widget,
+                                      gint      *minimum_width,
+                                      gint      *natural_width)
 {
   GimpOverlayBox *box = GIMP_OVERLAY_BOX (widget);
   GList          *list;
-  gint            border_width;
 
-  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+  *minimum_width = *natural_width =
+    2 * gtk_container_get_border_width (GTK_CONTAINER (widget)) + 1;
 
-  requisition->width  = 1 + 2 * border_width;
-  requisition->height = 1 + 2 * border_width;
+  for (list = box->children; list; list = g_list_next (list))
+    gimp_overlay_child_get_preferred_width (box, list->data);
+}
+
+static void
+gimp_overlay_box_get_preferred_height (GtkWidget *widget,
+                                       gint      *minimum_height,
+                                       gint      *natural_height)
+{
+  GimpOverlayBox *box = GIMP_OVERLAY_BOX (widget);
+  GList          *list;
+
+  *minimum_height = *natural_height =
+    2 * gtk_container_get_border_width (GTK_CONTAINER (widget)) + 1;
 
   for (list = box->children; list; list = g_list_next (list))
-    gimp_overlay_child_size_request (box, list->data);
+    gimp_overlay_child_get_preferred_height (box, list->data);
 }
 
 static void
diff --git a/app/widgets/gimpoverlaychild.c b/app/widgets/gimpoverlaychild.c
index 8ace94d..09bc725 100644
--- a/app/widgets/gimpoverlaychild.c
+++ b/app/widgets/gimpoverlaychild.c
@@ -207,15 +207,29 @@ gimp_overlay_child_unrealize (GimpOverlayBox   *box,
 }
 
 void
-gimp_overlay_child_size_request (GimpOverlayBox   *box,
-                                 GimpOverlayChild *child)
+gimp_overlay_child_get_preferred_width (GimpOverlayBox   *box,
+                                        GimpOverlayChild *child)
 {
-  GtkRequisition child_requisition;
+  gint minimum;
+  gint natural;
 
   g_return_if_fail (GIMP_IS_OVERLAY_BOX (box));
   g_return_if_fail (child != NULL);
 
-  gtk_widget_get_preferred_size (child->widget, &child_requisition, NULL);
+  gtk_widget_get_preferred_width (child->widget, &minimum, &natural);
+}
+
+void
+gimp_overlay_child_get_preferred_height (GimpOverlayBox   *box,
+                                         GimpOverlayChild *child)
+{
+  gint minimum;
+  gint natural;
+
+  g_return_if_fail (GIMP_IS_OVERLAY_BOX (box));
+  g_return_if_fail (child != NULL);
+
+  gtk_widget_get_preferred_height (child->widget, &minimum, &natural);
 }
 
 void
diff --git a/app/widgets/gimpoverlaychild.h b/app/widgets/gimpoverlaychild.h
index 5bb5361..e4b6731 100644
--- a/app/widgets/gimpoverlaychild.h
+++ b/app/widgets/gimpoverlaychild.h
@@ -44,39 +44,41 @@ struct _GimpOverlayChild
 };
 
 
-GimpOverlayChild * gimp_overlay_child_new           (GimpOverlayBox  *box,
-                                                     GtkWidget       *widget,
-                                                     gdouble          xalign,
-                                                     gdouble          yalign,
-                                                     gdouble          angle,
-                                                     gdouble          opacity);
-void               gimp_overlay_child_free          (GimpOverlayBox   *box,
-                                                     GimpOverlayChild *child);
+GimpOverlayChild * gimp_overlay_child_new                  (GimpOverlayBox  *box,
+                                                            GtkWidget       *widget,
+                                                            gdouble          xalign,
+                                                            gdouble          yalign,
+                                                            gdouble          angle,
+                                                            gdouble          opacity);
+void               gimp_overlay_child_free                 (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child);
 
-GimpOverlayChild * gimp_overlay_child_find          (GimpOverlayBox   *box,
-                                                     GtkWidget        *widget);
+GimpOverlayChild * gimp_overlay_child_find                 (GimpOverlayBox   *box,
+                                                            GtkWidget        *widget);
 
-void               gimp_overlay_child_realize       (GimpOverlayBox   *box,
-                                                     GimpOverlayChild *child);
-void               gimp_overlay_child_unrealize     (GimpOverlayBox   *box,
-                                                     GimpOverlayChild *child);
-void               gimp_overlay_child_size_request  (GimpOverlayBox   *box,
-                                                     GimpOverlayChild *child);
-void               gimp_overlay_child_size_allocate (GimpOverlayBox   *box,
-                                                     GimpOverlayChild *child);
-gboolean           gimp_overlay_child_draw          (GimpOverlayBox   *box,
-                                                     GimpOverlayChild *child,
-                                                     cairo_t          *cr);
-gboolean           gimp_overlay_child_damage        (GimpOverlayBox   *box,
-                                                     GimpOverlayChild *child,
-                                                     GdkEventExpose   *event);
+void               gimp_overlay_child_realize              (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child);
+void               gimp_overlay_child_unrealize            (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child);
+void               gimp_overlay_child_get_preferred_width  (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child);
+void               gimp_overlay_child_get_preferred_height (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child);
+void               gimp_overlay_child_size_allocate        (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child);
+gboolean           gimp_overlay_child_draw                 (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child,
+                                                            cairo_t          *cr);
+gboolean           gimp_overlay_child_damage               (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child,
+                                                            GdkEventExpose   *event);
 
-void               gimp_overlay_child_invalidate    (GimpOverlayBox   *box,
-                                                     GimpOverlayChild *child);
-gboolean           gimp_overlay_child_pick          (GimpOverlayBox   *box,
-                                                     GimpOverlayChild *child,
-                                                     gdouble           box_x,
-                                                     gdouble           box_y);
+void               gimp_overlay_child_invalidate           (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child);
+gboolean           gimp_overlay_child_pick                 (GimpOverlayBox   *box,
+                                                            GimpOverlayChild *child,
+                                                            gdouble           box_x,
+                                                            gdouble           box_y);
 
 
 #endif /* __GIMP_OVERLAY_CHILD_H__ */



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