[gtk+] GtkPopover:pointing-to: GdkRectangle instead of cairo_rectangle_int_t



commit 2495edc9fdd604fa9f052b4003a492d2b7230d37
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Tue Apr 21 09:05:26 2015 +0200

    GtkPopover:pointing-to: GdkRectangle instead of cairo_rectangle_int_t
    
    cairo_rectangle_int_t was replaced by GdkRectangle in commit
    552c29b488ecd7bcc3303dd5514ce6dbfff04437, but the type of the pointing-to
    property was not changed.
    
    To avoid breaking old code that sets or gets the property with a GValue
    of type CAIRO_GOBJECT_TYPE_RECTANGLE_INT, transformation functions between
    CAIRO_GOBJECT_TYPE_RECTANGLE_INT and GDK_TYPE_RECTANGLE are registered on
    the first call to gdk_rectangle_get_type().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723394

 gdk/gdkrectangle.c |   37 ++++++++++++++++++++++++++++++++++---
 gtk/gtkpopover.c   |    3 +--
 2 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/gdk/gdkrectangle.c b/gdk/gdkrectangle.c
index 919c3a2..404ffca 100644
--- a/gdk/gdkrectangle.c
+++ b/gdk/gdkrectangle.c
@@ -25,6 +25,7 @@
 #include "config.h"
 
 #include "gdkrectangle.h"
+#include <cairo-gobject.h>
 
 
 /**
@@ -141,6 +142,36 @@ gdk_rectangle_copy (const GdkRectangle *rectangle)
   return result;
 }
 
-G_DEFINE_BOXED_TYPE (GdkRectangle, gdk_rectangle,
-                     gdk_rectangle_copy,
-                     g_free)
+/* Transforms between identical boxed types.
+ */
+static void
+gdk_rectangle_value_transform_rect (const GValue *src_value, GValue *dest_value)
+{
+  g_value_set_boxed (dest_value, g_value_get_boxed (src_value));
+}
+
+/* Allow GValue transformation between the identical structs
+ * cairo_rectangle_int_t and GdkRectangle.
+ */
+static void
+gdk_rectangle_register_value_transform_funcs (GType gtype_gdk_rectangle)
+{
+  /* This function is called from the first call to gdk_rectangle_get_type(),
+   * before g_once_init_leave() has been called.
+   * If gdk_rectangle_get_type() is called from here (e.g. via
+   * GDK_TYPE_RECTANGLE), the program will wait indefinitely at
+   * g_once_init_enter() in gdk_rectangle_get_type().
+   */
+  g_value_register_transform_func (CAIRO_GOBJECT_TYPE_RECTANGLE_INT,
+                                   gtype_gdk_rectangle,
+                                   gdk_rectangle_value_transform_rect);
+  g_value_register_transform_func (gtype_gdk_rectangle,
+                                   CAIRO_GOBJECT_TYPE_RECTANGLE_INT,
+                                   gdk_rectangle_value_transform_rect);
+}
+
+G_DEFINE_BOXED_TYPE_WITH_CODE (GdkRectangle, gdk_rectangle,
+                               gdk_rectangle_copy,
+                               g_free,
+                               gdk_rectangle_register_value_transform_funcs (g_define_type_id))
+
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index 37064c8..88a083d 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -76,7 +76,6 @@
 
 #include "config.h"
 #include <gdk/gdk.h>
-#include <cairo-gobject.h>
 #include "gtkpopover.h"
 #include "gtkpopoverprivate.h"
 #include "gtktypebuiltins.h"
@@ -1582,7 +1581,7 @@ gtk_popover_class_init (GtkPopoverClass *klass)
                                    g_param_spec_boxed ("pointing-to",
                                                        P_("Pointing to"),
                                                        P_("Rectangle the bubble window points to"),
-                                                       CAIRO_GOBJECT_TYPE_RECTANGLE_INT,
+                                                       GDK_TYPE_RECTANGLE,
                                                        GTK_PARAM_READWRITE));
   /**
    * GtkPopover:position


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