Re: Build break with latest GTK+ 3



On Wed, 2010-09-29 at 10:19 +0100, Damon Chaplin wrote:
> Did you attach the patch? I didn't get it.

Here it is. Now the demo works again, but somebody should still look at
it, because I did it in a rush.

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com
>From 70f79977c29739cdc5cfabbe6b35c50772b2ed0d Mon Sep 17 00:00:00 2001
From: Murray Cumming <murrayc murrayc com>
Date: Wed, 29 Sep 2010 09:23:24 +0200
Subject: [PATCH] Rough port to lastest GTK+ 3 API.

---
 demo/demo-fifteen.c        |    4 +-
 demo/demo-grabs.c          |   26 ++++++++--------
 demo/mv-demo-fifteen.c     |    4 +-
 demo/mv-demo-grabs.c       |   22 +++++++-------
 demo/mv-scalability-demo.c |   16 ++++------
 demo/scalability-demo.c    |    8 ++--
 src/goocanvas.c            |   68 +++++++++++++++++++++++--------------------
 src/goocanvas.h            |    4 +-
 8 files changed, 77 insertions(+), 75 deletions(-)

diff --git a/demo/demo-fifteen.c b/demo/demo-fifteen.c
index 44b3768..8ab0f03 100644
--- a/demo/demo-fifteen.c
+++ b/demo/demo-fifteen.c
@@ -12,7 +12,7 @@
 
 
 static void
-free_stuff (GtkObject *obj, gpointer data)
+free_stuff (GObject *obj, gpointer data)
 {
 	g_free (data);
 }
@@ -179,7 +179,7 @@ setup_item_signals (GooCanvasItem     *item)
 #define SCRAMBLE_MOVES 256
 
 static void
-scramble (GtkObject *object, gpointer data)
+scramble (GObject *object, gpointer data)
 {
 	GooCanvas *canvas;
 	GooCanvasItem **board;
diff --git a/demo/demo-grabs.c b/demo/demo-grabs.c
index fbbb0aa..d09d23a 100644
--- a/demo/demo-grabs.c
+++ b/demo/demo-grabs.c
@@ -5,16 +5,16 @@
 
 
 static gboolean
-on_widget_expose (GtkWidget *widget,
-		  GdkEventExpose *event,
+on_widget_draw (GtkWidget *widget,
+		  cairo_t *cr,
 		  char *item_id)
 {
   GtkAllocation allocation;
-  g_print ("%s received 'expose' signal\n", item_id);
+  g_print ("%s received 'draw' signal\n", item_id);
 
   gtk_widget_get_allocation (widget, &allocation);
-  gtk_paint_box (gtk_widget_get_style (widget), gtk_widget_get_window (widget), GTK_STATE_NORMAL,
-		 GTK_SHADOW_IN, &event->area, widget, NULL, 0, 0,
+  gtk_paint_box (gtk_widget_get_style (widget), cr, GTK_STATE_NORMAL,
+		 GTK_SHADOW_IN, widget, NULL, 0, 0,
 		 allocation.width, allocation.height);
 
   return FALSE;
@@ -232,8 +232,8 @@ create_fixed (GtkTable *table, gint row, gchar *text, gchar *id)
   gtk_widget_show (fixed);
 
   view_id = g_strdup_printf ("%s-background", id);
-  g_signal_connect (fixed, "expose_event",
-		    G_CALLBACK (on_widget_expose), view_id);
+  g_signal_connect (fixed, "draw",
+		    G_CALLBACK (on_widget_draw), view_id);
 
   g_signal_connect (fixed, "enter_notify_event",
 		    G_CALLBACK (on_widget_enter_notify), view_id);
@@ -259,14 +259,14 @@ create_fixed (GtkTable *table, gint row, gchar *text, gchar *id)
 			 | GDK_ENTER_NOTIFY_MASK
 			 | GDK_LEAVE_NOTIFY_MASK
 			 | GDK_FOCUS_CHANGE_MASK);
-			 
+
   gtk_widget_set_size_request (drawing_area, 60, 60);
   gtk_fixed_put (GTK_FIXED (fixed), drawing_area, 20, 20);
   gtk_widget_show (drawing_area);
 
   view_id = g_strdup_printf ("%s-left", id);
-  g_signal_connect (drawing_area, "expose_event",
-		    G_CALLBACK (on_widget_expose), view_id);
+  g_signal_connect (drawing_area, "draw",
+		    G_CALLBACK (on_widget_draw), view_id);
 
   g_signal_connect (drawing_area, "enter_notify_event",
 		    G_CALLBACK (on_widget_enter_notify), view_id);
@@ -292,14 +292,14 @@ create_fixed (GtkTable *table, gint row, gchar *text, gchar *id)
 			 | GDK_ENTER_NOTIFY_MASK
 			 | GDK_LEAVE_NOTIFY_MASK
 			 | GDK_FOCUS_CHANGE_MASK);
-			 
+
   gtk_widget_set_size_request (drawing_area, 60, 60);
   gtk_fixed_put (GTK_FIXED (fixed), drawing_area, 120, 20);
   gtk_widget_show (drawing_area);
 
   view_id = g_strdup_printf ("%s-right", id);
-  g_signal_connect (drawing_area, "expose_event",
-		    G_CALLBACK (on_widget_expose), view_id);
+  g_signal_connect (drawing_area, "draw",
+		    G_CALLBACK (on_widget_draw), view_id);
 
   g_signal_connect (drawing_area, "enter_notify_event",
 		    G_CALLBACK (on_widget_enter_notify), view_id);
diff --git a/demo/mv-demo-fifteen.c b/demo/mv-demo-fifteen.c
index 08ff3ab..5ea6f4c 100644
--- a/demo/mv-demo-fifteen.c
+++ b/demo/mv-demo-fifteen.c
@@ -12,7 +12,7 @@
 
 
 static void
-free_stuff (GtkObject *obj, gpointer data)
+free_stuff (GObject *obj, gpointer data)
 {
 	g_free (data);
 }
@@ -190,7 +190,7 @@ on_item_created (GooCanvas          *canvas,
 #define SCRAMBLE_MOVES 256
 
 static void
-scramble (GtkObject *object, gpointer data)
+scramble (GObject *object, gpointer data)
 {
 	GooCanvas *canvas;
 	GooCanvasItemModel **board;
diff --git a/demo/mv-demo-grabs.c b/demo/mv-demo-grabs.c
index 1777cef..6b0be0a 100644
--- a/demo/mv-demo-grabs.c
+++ b/demo/mv-demo-grabs.c
@@ -5,17 +5,17 @@
 
 
 static gboolean
-on_widget_expose (GtkWidget *widget,
-		  GdkEventExpose *event,
+on_widget_draw (GtkWidget *widget,
+		  cairo_t *cr,
 		  char *item_id)
 {
   GtkAllocation allocation;
   
-  g_print ("%s received 'expose' signal\n", item_id);
+  g_print ("%s received 'draw' signal\n", item_id);
 
   gtk_widget_get_allocation (widget, &allocation);
-  gtk_paint_box (gtk_widget_get_style (widget), gtk_widget_get_window (widget), GTK_STATE_NORMAL,
-		 GTK_SHADOW_IN, &event->area, widget, NULL, 0, 0,
+  gtk_paint_box (gtk_widget_get_style (widget), cr, GTK_STATE_NORMAL,
+		 GTK_SHADOW_IN, widget, NULL, 0, 0,
 		 allocation.width, allocation.height);
 
   return FALSE;
@@ -238,8 +238,8 @@ create_fixed (GtkTable *table, gint row, gchar *text, gchar *id)
   gtk_widget_show (fixed);
 
   view_id = g_strdup_printf ("%s-background", id);
-  g_signal_connect (fixed, "expose_event",
-		    G_CALLBACK (on_widget_expose), view_id);
+  g_signal_connect (fixed, "draw",
+		    G_CALLBACK (on_widget_draw), view_id);
 
   g_signal_connect (fixed, "enter_notify_event",
 		    G_CALLBACK (on_widget_enter_notify), view_id);
@@ -271,8 +271,8 @@ create_fixed (GtkTable *table, gint row, gchar *text, gchar *id)
   gtk_widget_show (drawing_area);
 
   view_id = g_strdup_printf ("%s-left", id);
-  g_signal_connect (drawing_area, "expose_event",
-		    G_CALLBACK (on_widget_expose), view_id);
+  g_signal_connect (drawing_area, "draw",
+		    G_CALLBACK (on_widget_draw), view_id);
 
   g_signal_connect (drawing_area, "enter_notify_event",
 		    G_CALLBACK (on_widget_enter_notify), view_id);
@@ -304,8 +304,8 @@ create_fixed (GtkTable *table, gint row, gchar *text, gchar *id)
   gtk_widget_show (drawing_area);
 
   view_id = g_strdup_printf ("%s-right", id);
-  g_signal_connect (drawing_area, "expose_event",
-		    G_CALLBACK (on_widget_expose), view_id);
+  g_signal_connect (drawing_area, "draw",
+		    G_CALLBACK (on_widget_draw), view_id);
 
   g_signal_connect (drawing_area, "enter_notify_event",
 		    G_CALLBACK (on_widget_enter_notify), view_id);
diff --git a/demo/mv-scalability-demo.c b/demo/mv-scalability-demo.c
index 23c0134..bdbc438 100644
--- a/demo/mv-scalability-demo.c
+++ b/demo/mv-scalability-demo.c
@@ -41,7 +41,7 @@
 #endif
 
 #if 0
-#define USE_PIXMAP 
+#define USE_PIXMAP
 #endif
 
 #if 0
@@ -90,7 +90,7 @@ init_ids (void)
 {
   int group_i, group_j, i, j;
   int id_item_num = 0;;
-	
+
   for (group_i = 0; group_i < N_GROUP_COLS; group_i++)
     {
       for (group_j = 0; group_j < N_GROUP_ROWS; group_j++)
@@ -263,8 +263,8 @@ setup_canvas (GtkWidget *canvas)
 
 
 static gboolean
-on_expose_event (GtkWidget *canvas,
-		 GdkEvent  *event,
+on_draw (GtkWidget *canvas,
+		 cairo_t  *cr,
 		 gpointer   unused_data)
 {
   static gboolean first_time = TRUE;
@@ -295,7 +295,7 @@ create_canvas (void)
   item_width = ITEM_WIDTH;
   item_height = 19;
 #endif
-	
+
   cell_width = item_width + PADDING * 2;
   cell_height = item_height + PADDING * 2;
 
@@ -327,8 +327,8 @@ create_canvas (void)
 			 left_offset + total_width, top_offset + total_height);
   gtk_widget_show (canvas);
 
-  g_signal_connect (canvas, "expose_event",
-		    G_CALLBACK (on_expose_event), NULL);
+  g_signal_connect (canvas, "draw",
+		    G_CALLBACK (on_draw), NULL);
 
   return canvas;
 }
@@ -374,5 +374,3 @@ main (int argc, char *argv[])
 
   return 0;
 }
-
-
diff --git a/demo/scalability-demo.c b/demo/scalability-demo.c
index 408b7b9..ae4770d 100644
--- a/demo/scalability-demo.c
+++ b/demo/scalability-demo.c
@@ -256,8 +256,8 @@ setup_canvas (GtkWidget *canvas)
 
 
 static gboolean
-on_expose_event (GtkWidget *canvas,
-		 GdkEvent  *event,
+on_draw (GtkWidget *canvas,
+		 cairo_t  *cr,
 		 gpointer   unused_data)
 {
   static gboolean first_time = TRUE;
@@ -320,8 +320,8 @@ create_canvas (void)
 			 left_offset + total_width, top_offset + total_height);
   gtk_widget_show (canvas);
 
-  g_signal_connect (canvas, "expose_event",
-		    G_CALLBACK (on_expose_event), NULL);
+  g_signal_connect (canvas, "draw",
+		    G_CALLBACK (on_draw), NULL);
 
   return canvas;
 }
diff --git a/src/goocanvas.c b/src/goocanvas.c
index abdb84c..a874d29 100644
--- a/src/goocanvas.c
+++ b/src/goocanvas.c
@@ -163,8 +163,8 @@ static void     goo_canvas_size_allocate   (GtkWidget        *widget,
 static void     goo_canvas_set_adjustments (GooCanvas        *canvas,
 					    GtkAdjustment    *hadj,
 					    GtkAdjustment    *vadj);
-static gboolean goo_canvas_expose_event	   (GtkWidget        *widget,
-					    GdkEventExpose   *event);
+static gboolean goo_canvas_draw	   (GtkWidget        *widget,
+					    cairo_t          *cr);
 static gboolean goo_canvas_button_press    (GtkWidget        *widget,
 					    GdkEventButton   *event);
 static gboolean goo_canvas_button_release  (GtkWidget        *widget,
@@ -251,7 +251,7 @@ goo_canvas_class_init (GooCanvasClass *klass)
   widget_class->size_request         = goo_canvas_size_request;
   widget_class->size_allocate        = goo_canvas_size_allocate;
   widget_class->style_set            = goo_canvas_style_set;
-  widget_class->expose_event         = goo_canvas_expose_event;
+  widget_class->draw                 = goo_canvas_draw;
   widget_class->button_press_event   = goo_canvas_button_press;
   widget_class->button_release_event = goo_canvas_button_release;
   widget_class->motion_notify_event  = goo_canvas_motion;
@@ -489,7 +489,7 @@ goo_canvas_init (GooCanvas *canvas)
   canvas->anchor = GOO_CANVAS_ANCHOR_NORTH_WEST;
   canvas->clear_background = TRUE;
   canvas->redraw_when_scrolled = FALSE;
-  canvas->before_initial_expose = TRUE;
+  canvas->before_initial_draw = TRUE;
 
   /* Set the default bounds to a reasonable size. */
   canvas->bounds.x1 = 0.0;
@@ -1451,10 +1451,9 @@ goo_canvas_realize (GtkWidget *widget)
   attributes.height = allocation.height;
   attributes.wclass = GDK_INPUT_OUTPUT;
   attributes.visual = gtk_widget_get_visual (widget);
-  attributes.colormap = gtk_widget_get_colormap (widget);
   attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
 
-  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
 
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
 				   &attributes, attributes_mask);
@@ -1504,9 +1503,11 @@ goo_canvas_realize (GtkWidget *widget)
   /* Make sure the window backgrounds aren't set, to avoid flicker when
      scrolling (due to the delay between X clearing the background and
      GooCanvas painting it). */
+  /* TODO: Do this with GTK+ 3 too?
   gdk_window_set_back_pixmap (window, NULL, FALSE);
   gdk_window_set_back_pixmap (canvas->canvas_window, NULL, FALSE);
   gdk_window_set_back_pixmap (canvas->tmp_window, NULL, FALSE);
+  */
 
   /* Set the parent window of all the child widget items. */
   tmp_list = canvas->widget_items;
@@ -1587,8 +1588,10 @@ goo_canvas_style_set (GtkWidget *widget,
       /* Make sure the window backgrounds aren't set, to avoid flicker when
 	 scrolling (due to the delay between X clearing the background and
 	 GooCanvas painting it). */
+      /* TODO: Do this with GTK+ 3 too?
       gdk_window_set_back_pixmap (gtk_widget_get_window (widget), NULL, FALSE);
       gdk_window_set_back_pixmap (GOO_CANVAS (widget)->canvas_window, NULL, FALSE);
+      */
     }
 }
 
@@ -2335,8 +2338,8 @@ goo_canvas_set_scale_internal	(GooCanvas *canvas,
   canvas->freeze_count--;
   goo_canvas_adjustment_value_changed (NULL, canvas);
 
-  /* Now hide the temporary window, so the canvas window will get an expose
-     event. */
+  /* Now hide the temporary window, so the canvas window will get a draw
+     signal. */
   if (gtk_widget_get_mapped (GTK_WIDGET (canvas)))
     gdk_window_hide (canvas->tmp_window);
 }
@@ -2636,7 +2639,7 @@ goo_canvas_request_item_redraw (GooCanvas             *canvas,
 {
   /* If the canvas hasn't been painted yet, we can just return as it all needs
      a redraw. This can save a lot of time if there are lots of items. */
-  if (canvas->before_initial_expose)
+  if (canvas->before_initial_draw)
     return;
 
   if (is_static)
@@ -2648,12 +2651,16 @@ goo_canvas_request_item_redraw (GooCanvas             *canvas,
 
 static void
 paint_static_items (GooCanvas      *canvas,
-		    GdkEventExpose *event,
 		    cairo_t        *cr)
 {
   GooCanvasPrivate *priv = GOO_CANVAS_GET_PRIVATE (canvas);
   GooCanvasBounds static_bounds;
   double static_x_offset, static_y_offset;
+  GtkWidget* widget = GTK_WIDGET (canvas);
+  const int area_x = 0;
+  const int area_y = 0;
+  const int area_width = gtk_widget_get_allocated_width (widget);
+  const int area_height = gtk_widget_get_allocated_height (widget);
 
   cairo_save (cr);
   cairo_identity_matrix (cr);
@@ -2661,35 +2668,33 @@ paint_static_items (GooCanvas      *canvas,
   static_y_offset = floor (gtk_adjustment_get_value (canvas->vadjustment));
   cairo_translate (cr, static_x_offset, static_y_offset);
   /* FIXME: Uses pixels at present - use canvas units instead? */
-  static_bounds.x1 = event->area.x - static_x_offset;
-  static_bounds.y1 = event->area.y - static_y_offset;
-  static_bounds.x2 = event->area.width + static_bounds.x1;
-  static_bounds.y2 = event->area.height + static_bounds.y1;
+  static_bounds.x1 = area_x - static_x_offset;
+  static_bounds.y1 = area_y - static_y_offset;
+  static_bounds.x2 = area_width + static_bounds.x1;
+  static_bounds.y2 = area_height + static_bounds.y1;
   goo_canvas_item_paint (priv->static_root_item, cr, &static_bounds, 1.0);
   cairo_restore (cr);
 }
 
 
 static gboolean
-goo_canvas_expose_event (GtkWidget      *widget,
-			 GdkEventExpose *event)
+goo_canvas_draw (GtkWidget      *widget,
+			 cairo_t *cr)
 {
   GooCanvas *canvas = GOO_CANVAS (widget);
+  const int area_x = 0;
+  const int area_y = 0;
+  const int area_width = gtk_widget_get_allocated_width (widget);
+  const int area_height = gtk_widget_get_allocated_height (widget);
   GooCanvasBounds bounds, root_item_bounds;
-  cairo_t *cr;
   double x1, y1, x2, y2;
 
   if (!canvas->root_item)
     {
-      canvas->before_initial_expose = FALSE;
+      canvas->before_initial_draw = FALSE;
       return FALSE;
     }
 
-  if (event->window != canvas->canvas_window)
-    return FALSE;
-
-  cr = goo_canvas_create_cairo_context (canvas);
-
   /* Clear the background. */
   if (canvas->clear_background)
     {
@@ -2704,12 +2709,12 @@ goo_canvas_expose_event (GtkWidget      *widget,
   if (canvas->need_update)
     goo_canvas_update_internal (canvas, cr);
 
-  bounds.x1 = ((event->area.x - canvas->canvas_x_offset) / canvas->device_to_pixels_x)
+  bounds.x1 = ((area_x - canvas->canvas_x_offset) / canvas->device_to_pixels_x)
     + canvas->bounds.x1;
-  bounds.y1 = ((event->area.y - canvas->canvas_y_offset) / canvas->device_to_pixels_y)
+  bounds.y1 = ((area_y - canvas->canvas_y_offset) / canvas->device_to_pixels_y)
     + canvas->bounds.y1;
-  bounds.x2 = (event->area.width / canvas->device_to_pixels_x) + bounds.x1;
-  bounds.y2 = (event->area.height / canvas->device_to_pixels_y) + bounds.y1;
+  bounds.x2 = (area_width / canvas->device_to_pixels_x) + bounds.x1;
+  bounds.y2 = (area_height / canvas->device_to_pixels_y) + bounds.y1;
 
   /* Translate it to use the canvas pixel offsets (used when the canvas is
      smaller than the window and the anchor isn't set to NORTH_WEST). */
@@ -2721,6 +2726,7 @@ goo_canvas_expose_event (GtkWidget      *widget,
   /* Translate it so the top-left of the canvas becomes (0,0). */
   cairo_translate (cr, -canvas->bounds.x1, -canvas->bounds.y1);
 
+  /* TODO: clipping is apparently unnecessary in GTK+ 3 now. The cairo_t is alrady clipped when we get it. */
   /* Clip to the canvas bounds, if necessary. We only need to clip if the
      items in the canvas extend outside the canvas bounds and the canvas
      bounds is less than the area being painted. */
@@ -2754,13 +2760,11 @@ goo_canvas_expose_event (GtkWidget      *widget,
 
   cairo_restore (cr);
 
-  paint_static_items (canvas, event, cr);
-
-  cairo_destroy (cr);
+  paint_static_items (canvas, cr);
 
-  GTK_WIDGET_CLASS (goo_canvas_parent_class)->expose_event (widget, event);
+  GTK_WIDGET_CLASS (goo_canvas_parent_class)->draw (widget, cr);
 
-  canvas->before_initial_expose = FALSE;
+  canvas->before_initial_draw = FALSE;
 
   return FALSE;
 }
diff --git a/src/goocanvas.h b/src/goocanvas.h
index 91cd277..e2e41ac 100644
--- a/src/goocanvas.h
+++ b/src/goocanvas.h
@@ -88,8 +88,8 @@ struct _GooCanvas
      useful when there are sticky items to reduce flicker, but is slower. */
   guint redraw_when_scrolled : 1;
 
-  /* If the canvas hasn't received the initial expose event yet. */
-  guint before_initial_expose : 1;
+  /* If the canvas hasn't received the initial draw signal yet. */
+  guint before_initial_draw : 1;
 
   /* This is the padding around the automatic bounds. */
   gdouble bounds_padding;
-- 
1.7.0.4



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