[goffice] GocCanvas: Introduce goc_canvas_get_realized



commit e099df42ca9b05ed205883998e9bc1b3fc6e1e0b
Author: Morten Welinder <terra gnome org>
Date:   Fri Mar 22 15:29:22 2013 -0400

    GocCanvas: Introduce goc_canvas_get_realized

 goffice/canvas/goc-canvas.c |   25 +++++++++++++++++++++----
 goffice/canvas/goc-canvas.h |    1 +
 goffice/canvas/goc-item.c   |   16 ++++------------
 3 files changed, 26 insertions(+), 16 deletions(-)
---
diff --git a/goffice/canvas/goc-canvas.c b/goffice/canvas/goc-canvas.c
index 6590709..94d20bd 100644
--- a/goffice/canvas/goc-canvas.c
+++ b/goffice/canvas/goc-canvas.c
@@ -1,5 +1,5 @@
 /*
- * goc-canvas.c :
+ * goc-canvas.c:
  *
  * Copyright (C) 2008-2009 Jean Brefort (jean brefort normalesup org)
  *
@@ -451,7 +451,7 @@ goc_canvas_get_pixels_per_unit (GocCanvas *canvas)
 }
 
 /**
- * goc_canvas_invalidate :
+ * goc_canvas_invalidate:
  * @canvas: #GocCanvas
  * @x0: minimum x coordinate of the invalidated region in canvas coordinates
  * @y0: minimum y coordinate of the invalidated region in canvas coordinates
@@ -464,9 +464,9 @@ goc_canvas_get_pixels_per_unit (GocCanvas *canvas)
 void
 goc_canvas_invalidate (GocCanvas *canvas, double x0, double y0, double x1, double y1)
 {
-#ifdef GOFFICE_WITH_GTK
-       if (!gtk_widget_get_realized (GTK_WIDGET (canvas)))
+       if (!goc_canvas_get_realized (canvas))
                return;
+#ifdef GOFFICE_WITH_GTK
        x0 = (x0 - canvas->scroll_x1) * canvas->pixels_per_unit;
        y0 = (y0 - canvas->scroll_y1) * canvas->pixels_per_unit;
        x1 = (x1 - canvas->scroll_x1) * canvas->pixels_per_unit;
@@ -493,6 +493,23 @@ goc_canvas_invalidate (GocCanvas *canvas, double x0, double y0, double x1, doubl
 }
 
 /**
+ * goc_canvas_get_realized:
+ * @canvas: #GocCanvas
+ *
+ * Returns: %TRUE if the canvas has been realized as a #GtkWidget.
+ **/
+gboolean
+goc_canvas_get_realized (GocCanvas *canvas)
+{
+#ifdef GOFFICE_WITH_GTK
+       return gtk_widget_get_realized (GTK_WIDGET (canvas));
+#else
+       return FALSE;
+#endif
+}
+
+
+/**
  * goc_canvas_get_item_at:
  * @canvas: #GocCanvas
  * @x: horizontal position
diff --git a/goffice/canvas/goc-canvas.h b/goffice/canvas/goc-canvas.h
index b14c296..86ce4cd 100644
--- a/goffice/canvas/goc-canvas.h
+++ b/goffice/canvas/goc-canvas.h
@@ -75,6 +75,7 @@ void           goc_canvas_get_scroll_position (GocCanvas *canvas, double *x, double *y);
 void            goc_canvas_set_pixels_per_unit (GocCanvas *canvas, double pixels_per_unit);
 double          goc_canvas_get_pixels_per_unit (GocCanvas *canvas);
 void            goc_canvas_invalidate (GocCanvas *canvas, double x0, double y0, double x1, double y1);
+gboolean         goc_canvas_get_realized (GocCanvas *canvas);
 GocItem                *goc_canvas_get_item_at (GocCanvas *canvas, double x, double y);
 void            goc_canvas_grab_item (GocCanvas *canvas, GocItem *item);
 void            goc_canvas_ungrab_item (GocCanvas *canvas);
diff --git a/goffice/canvas/goc-item.c b/goffice/canvas/goc-item.c
index 64beaf7..ab33fcf 100644
--- a/goffice/canvas/goc-item.c
+++ b/goffice/canvas/goc-item.c
@@ -21,9 +21,6 @@
 
 #include <goffice/goffice-config.h>
 #include <goffice/goffice.h>
-#ifdef GOFFICE_WITH_GTK
-#       include <gtk/gtk.h>
-#endif
 #include <gsf/gsf-impl-utils.h>
 #include <glib/gi18n-lib.h>
 
@@ -217,12 +214,8 @@ goc_item_dispose (GObject *object)
                        item->canvas->last_item = NULL;
                if (item->canvas->grabbed_item == item)
                        item->canvas->grabbed_item = NULL;
-#ifdef GOFFICE_WITH_GTK
-               if (gtk_widget_get_realized (GTK_WIDGET (item->canvas))) {
-                       item->cached_bounds = TRUE; /* avoids a call to update_bounds */
-                       goc_item_invalidate (item);
-               }
-#endif
+               item->cached_bounds = TRUE; /* avoids a call to update_bounds */
+               goc_item_invalidate (item);
        }
 
        if (item->parent != NULL)
@@ -463,10 +456,9 @@ goc_item_maybe_invalidate (GocItem *item, gboolean ignore_visibility)
        if (!parent)
                return;
 
-#ifdef GOFFICE_WITH_GTK
-       if (!gtk_widget_get_realized (GTK_WIDGET (item->canvas)))
+       if (!goc_canvas_get_realized (item->canvas))
                return;
-#endif
+
        if (!ignore_visibility && !item->visible)
                return;
 


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