[gimp/gtk3-port: 76/248] app: port the overlay stuff to GTK+ 3.0



commit c05a7a2d3f8e49bca742db9021374ff4b76cb3f5
Author: Michael Natterer <mitch gimp org>
Date:   Tue Oct 19 19:28:49 2010 +0200

    app: port the overlay stuff to GTK+ 3.0

 app/widgets/gimpoverlaybox.c   |   28 +++++++---------
 app/widgets/gimpoverlaychild.c |   71 +++++++++++++++++-----------------------
 app/widgets/gimpoverlaychild.h |    4 +-
 3 files changed, 44 insertions(+), 59 deletions(-)
---
diff --git a/app/widgets/gimpoverlaybox.c b/app/widgets/gimpoverlaybox.c
index dda04c0..9674c99 100644
--- a/app/widgets/gimpoverlaybox.c
+++ b/app/widgets/gimpoverlaybox.c
@@ -45,8 +45,8 @@ static void        gimp_overlay_box_size_request        (GtkWidget      *widget,
                                                          GtkRequisition *requisition);
 static void        gimp_overlay_box_size_allocate       (GtkWidget      *widget,
                                                          GtkAllocation  *allocation);
-static gboolean    gimp_overlay_box_expose              (GtkWidget      *widget,
-                                                         GdkEventExpose *event);
+static gboolean    gimp_overlay_box_draw                (GtkWidget      *widget,
+                                                         cairo_t        *cr);
 static gboolean    gimp_overlay_box_damage              (GtkWidget      *widget,
                                                          GdkEventExpose *event);
 
@@ -85,7 +85,7 @@ gimp_overlay_box_class_init (GimpOverlayBoxClass *klass)
   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->expose_event  = gimp_overlay_box_expose;
+  widget_class->draw          = gimp_overlay_box_draw;
 
   g_signal_override_class_handler ("damage-event",
                                    GIMP_TYPE_OVERLAY_BOX,
@@ -151,10 +151,9 @@ gimp_overlay_box_realize (GtkWidget *widget)
   attributes.window_type = GDK_WINDOW_CHILD;
   attributes.wclass      = GDK_INPUT_OUTPUT;
   attributes.visual      = gtk_widget_get_visual (widget);
-  attributes.colormap    = gtk_widget_get_colormap (widget);
   attributes.event_mask  = gtk_widget_get_events (widget);
 
-  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;
 
   gtk_widget_set_window (widget,
                          gdk_window_new (gtk_widget_get_parent_window (widget),
@@ -224,19 +223,16 @@ gimp_overlay_box_size_allocate (GtkWidget     *widget,
 }
 
 static gboolean
-gimp_overlay_box_expose (GtkWidget      *widget,
-                         GdkEventExpose *event)
+gimp_overlay_box_draw (GtkWidget *widget,
+                       cairo_t   *cr)
 {
-  if (gtk_widget_is_drawable (widget))
-    {
-      GimpOverlayBox *box = GIMP_OVERLAY_BOX (widget);
-      GList          *list;
+  GimpOverlayBox *box = GIMP_OVERLAY_BOX (widget);
+  GList          *list;
 
-      for (list = box->children; list; list = g_list_next (list))
-        {
-          if (gimp_overlay_child_expose (box, list->data, event))
-            return FALSE;
-        }
+  for (list = box->children; list; list = g_list_next (list))
+    {
+      if (gimp_overlay_child_draw (box, list->data, cr))
+        return FALSE;
     }
 
   return FALSE;
diff --git a/app/widgets/gimpoverlaychild.c b/app/widgets/gimpoverlaychild.c
index d01b745..8ace94d 100644
--- a/app/widgets/gimpoverlaychild.c
+++ b/app/widgets/gimpoverlaychild.c
@@ -130,7 +130,7 @@ gimp_overlay_child_realize (GimpOverlayBox   *box,
   GtkWidget     *widget;
   GdkDisplay    *display;
   GdkScreen     *screen;
-  GdkColormap   *colormap;
+  GdkVisual     *visual;
   GtkAllocation  child_allocation;
   GdkWindowAttr  attributes;
   gint           attributes_mask;
@@ -143,9 +143,9 @@ gimp_overlay_child_realize (GimpOverlayBox   *box,
   display = gtk_widget_get_display (widget);
   screen  = gtk_widget_get_screen (widget);
 
-  colormap = gdk_screen_get_rgba_colormap (screen);
-  if (colormap)
-    gtk_widget_set_colormap (child->widget, colormap);
+  visual = gdk_screen_get_rgba_visual (screen);
+  if (visual)
+    gtk_widget_set_visual (child->widget, visual);
 
   gtk_widget_get_allocation (child->widget, &child_allocation);
 
@@ -165,14 +165,12 @@ gimp_overlay_child_realize (GimpOverlayBox   *box,
   attributes.window_type = GDK_WINDOW_OFFSCREEN;
   attributes.wclass      = GDK_INPUT_OUTPUT;
   attributes.visual      = gtk_widget_get_visual (child->widget);
-  attributes.colormap    = gtk_widget_get_colormap (child->widget);
   attributes.event_mask  = GDK_EXPOSURE_MASK;
   attributes.cursor      = gdk_cursor_new_for_display (display, GDK_LEFT_PTR);
 
   attributes_mask = (GDK_WA_X        |
                      GDK_WA_Y        |
                      GDK_WA_VISUAL   |
-                     GDK_WA_COLORMAP |
                      GDK_WA_CURSOR);
 
   child->window = gdk_window_new (gtk_widget_get_root_window (widget),
@@ -217,7 +215,7 @@ gimp_overlay_child_size_request (GimpOverlayBox   *box,
   g_return_if_fail (GIMP_IS_OVERLAY_BOX (box));
   g_return_if_fail (child != NULL);
 
-  gtk_widget_size_request (child->widget, &child_requisition);
+  gtk_widget_get_preferred_size (child->widget, &child_requisition, NULL);
 }
 
 void
@@ -238,7 +236,7 @@ gimp_overlay_child_size_allocate (GimpOverlayBox   *box,
 
   gtk_widget_get_allocation (widget, &allocation);
 
-  gtk_widget_get_child_requisition (child->widget, &child_requisition);
+  gtk_widget_get_preferred_size (child->widget, &child_requisition, NULL);
 
   child_allocation.x      = 0;
   child_allocation.y      = 0;
@@ -257,14 +255,8 @@ gimp_overlay_child_size_allocate (GimpOverlayBox   *box,
       gdk_window_get_position (child->window,
                                &old_allocation.x,
                                &old_allocation.y);
-#if GTK_CHECK_VERSION (2, 24, 0)
       old_allocation.width  = gdk_window_get_width (child->window);
       old_allocation.height = gdk_window_get_height (child->window);
-#else
-      gdk_drawable_get_size (child->window,
-                             &old_allocation.width,
-                             &old_allocation.height);
-#endif
 
       gimp_overlay_child_transform_bounds (child, &old_allocation, &old_bounds);
 
@@ -319,19 +311,19 @@ gimp_overlay_child_size_allocate (GimpOverlayBox   *box,
 }
 
 gboolean
-gimp_overlay_child_expose (GimpOverlayBox   *box,
-                           GimpOverlayChild *child,
-                           GdkEventExpose   *event)
+gimp_overlay_child_draw (GimpOverlayBox   *box,
+                         GimpOverlayChild *child,
+                         cairo_t          *cr)
 {
   GtkWidget *widget;
 
   g_return_val_if_fail (GIMP_IS_OVERLAY_BOX (box), FALSE);
   g_return_val_if_fail (child != NULL, FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
+  g_return_val_if_fail (cr != NULL, FALSE);
 
   widget = GTK_WIDGET (box);
 
-  if (event->window == gtk_widget_get_window (widget))
+  if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
     {
       GtkAllocation child_allocation;
       GdkRectangle  bounds;
@@ -340,33 +332,30 @@ gimp_overlay_child_expose (GimpOverlayBox   *box,
 
       gimp_overlay_child_transform_bounds (child, &child_allocation, &bounds);
 
-      if (gtk_widget_get_visible (child->widget) &&
-          gdk_rectangle_intersect (&event->area, &bounds, NULL))
+      if (gtk_widget_get_visible (child->widget))
         {
-          GdkPixmap *pixmap = gdk_offscreen_window_get_pixmap (child->window);
-          cairo_t   *cr     = gdk_cairo_create (gtk_widget_get_window (widget));
-
-          gdk_cairo_region (cr, event->region);
-          cairo_clip (cr);
+          cairo_surface_t *surface = gdk_offscreen_window_get_surface (child->window);
 
+          cairo_save (cr);
           cairo_transform (cr, &child->matrix);
-          gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+          cairo_set_source_surface (cr, surface, 0, 0);
           cairo_paint_with_alpha (cr, child->opacity);
-          cairo_destroy (cr);
+          cairo_restore (cr);
         }
     }
-  else if (event->window == child->window)
+
+  if (gtk_cairo_should_draw_window (cr, child->window))
     {
       if (! gtk_widget_get_app_paintable (child->widget))
         gtk_paint_flat_box (gtk_widget_get_style (child->widget),
-                            event->window,
+                            cr,
                             GTK_STATE_NORMAL, GTK_SHADOW_NONE,
-                            &event->area, widget, NULL,
+                            widget, NULL,
                             0, 0, -1, -1);
 
-      gtk_container_propagate_expose (GTK_CONTAINER (widget),
-                                      child->widget,
-                                      event);
+      gtk_container_propagate_draw (GTK_CONTAINER (widget),
+                                    child->widget,
+                                    cr);
 
       return TRUE;
     }
@@ -389,24 +378,24 @@ gimp_overlay_child_damage (GimpOverlayBox   *box,
 
   if (event->window == child->window)
     {
-      GdkRectangle *rects;
-      gint          n_rects;
-      gint          i;
+      gint n_rects;
+      gint i;
 
-      gdk_region_get_rectangles (event->region, &rects, &n_rects);
+      n_rects = cairo_region_num_rectangles (event->region);
 
       for (i = 0; i < n_rects; i++)
         {
+          GdkRectangle rect;
           GdkRectangle bounds;
 
-          gimp_overlay_child_transform_bounds (child, &rects[i], &bounds);
+          cairo_region_get_rectangle (event->region, i, &rect);
+
+          gimp_overlay_child_transform_bounds (child, &rect, &bounds);
 
           gdk_window_invalidate_rect (gtk_widget_get_window (widget),
                                       &bounds, FALSE);
         }
 
-      g_free (rects);
-
       return TRUE;
     }
 
diff --git a/app/widgets/gimpoverlaychild.h b/app/widgets/gimpoverlaychild.h
index 0e57fd3..5bb5361 100644
--- a/app/widgets/gimpoverlaychild.h
+++ b/app/widgets/gimpoverlaychild.h
@@ -64,9 +64,9 @@ void               gimp_overlay_child_size_request  (GimpOverlayBox   *box,
                                                      GimpOverlayChild *child);
 void               gimp_overlay_child_size_allocate (GimpOverlayBox   *box,
                                                      GimpOverlayChild *child);
-gboolean           gimp_overlay_child_expose        (GimpOverlayBox   *box,
+gboolean           gimp_overlay_child_draw          (GimpOverlayBox   *box,
                                                      GimpOverlayChild *child,
-                                                     GdkEventExpose   *event);
+                                                     cairo_t          *cr);
 gboolean           gimp_overlay_child_damage        (GimpOverlayBox   *box,
                                                      GimpOverlayChild *child,
                                                      GdkEventExpose   *event);



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