[gimp/gtk3-port: 146/246] libgimpwidgets: turn GimpRuler into a no-window widget



commit 4e4bc6fef44d527b609a83d91da1f47ce49872d7
Author: Michael Natterer <mitch gimp org>
Date:   Thu Dec 16 22:58:52 2010 +0100

    libgimpwidgets: turn GimpRuler into a no-window widget
    
    and use an input-only window for events instead.

 libgimpwidgets/gimpruler.c |   43 +++++++++++++++++++++++++------------------
 1 files changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/libgimpwidgets/gimpruler.c b/libgimpwidgets/gimpruler.c
index ba3596a..72b6ea5 100644
--- a/libgimpwidgets/gimpruler.c
+++ b/libgimpwidgets/gimpruler.c
@@ -67,6 +67,7 @@ typedef struct
   gdouble          position;
   gdouble          max_size;
 
+  GdkWindow       *input_window;
   cairo_surface_t *backing_store;
   PangoLayout     *layout;
   gdouble          font_scale;
@@ -225,6 +226,8 @@ gimp_ruler_init (GimpRuler *ruler)
 {
   GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
 
+  gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE);
+
   priv->orientation   = GTK_ORIENTATION_HORIZONTAL;
   priv->unit          = GIMP_PIXELS;
   priv->lower         = 0;
@@ -725,12 +728,13 @@ gimp_ruler_get_range (GimpRuler *ruler,
 static void
 gimp_ruler_realize (GtkWidget *widget)
 {
-  GimpRuler     *ruler = GIMP_RULER (widget);
-  GtkAllocation  allocation;
-  GdkWindowAttr  attributes;
-  gint           attributes_mask;
+  GimpRuler        *ruler = GIMP_RULER (widget);
+  GimpRulerPrivate *priv  = GIMP_RULER_GET_PRIVATE (ruler);
+  GtkAllocation     allocation;
+  GdkWindowAttr     attributes;
+  gint              attributes_mask;
 
-  gtk_widget_set_realized (widget, TRUE);
+  GTK_WIDGET_CLASS (gimp_ruler_parent_class)->realize (widget);
 
   gtk_widget_get_allocation (widget, &allocation);
 
@@ -739,23 +743,17 @@ gimp_ruler_realize (GtkWidget *widget)
   attributes.y           = allocation.y;
   attributes.width       = allocation.width;
   attributes.height      = allocation.height;
-  attributes.wclass      = GDK_INPUT_OUTPUT;
-  attributes.visual      = gtk_widget_get_visual (widget);
+  attributes.wclass      = GDK_INPUT_ONLY;
   attributes.event_mask  = (gtk_widget_get_events (widget) |
                             GDK_EXPOSURE_MASK              |
                             GDK_POINTER_MOTION_MASK        |
                             GDK_POINTER_MOTION_HINT_MASK);
 
-  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),
-                                         &attributes, attributes_mask));
-  gdk_window_set_user_data (gtk_widget_get_window (widget), ruler);
+  attributes_mask = GDK_WA_X | GDK_WA_Y;
 
-  gtk_widget_style_attach (widget);
-  gtk_style_context_set_background (gtk_widget_get_style_context (widget),
-                                    gtk_widget_get_window (widget));
+  priv->input_window = gdk_window_new (gtk_widget_get_window (widget),
+                                       &attributes, attributes_mask);
+  gdk_window_set_user_data (priv->input_window, ruler);
 
   gimp_ruler_make_pixmap (ruler);
 }
@@ -778,6 +776,12 @@ gimp_ruler_unrealize (GtkWidget *widget)
       priv->layout = NULL;
     }
 
+  if (priv->input_window)
+    {
+      gdk_window_destroy (priv->input_window);
+      priv->input_window = NULL;
+    }
+
   GTK_WIDGET_CLASS (gimp_ruler_parent_class)->unrealize (widget);
 }
 
@@ -785,7 +789,8 @@ static void
 gimp_ruler_size_allocate (GtkWidget     *widget,
                           GtkAllocation *allocation)
 {
-  GimpRuler     *ruler = GIMP_RULER (widget);
+  GimpRuler        *ruler = GIMP_RULER (widget);
+  GimpRulerPrivate *priv  = GIMP_RULER_GET_PRIVATE (widget);
   GtkAllocation  widget_allocation;
   gboolean       resized;
 
@@ -798,7 +803,7 @@ gimp_ruler_size_allocate (GtkWidget     *widget,
 
   if (gtk_widget_get_realized (widget))
     {
-      gdk_window_move_resize (gtk_widget_get_window (widget),
+      gdk_window_move_resize (priv->input_window,
                               allocation->x, allocation->y,
                               allocation->width, allocation->height);
 
@@ -1159,6 +1164,8 @@ gimp_ruler_draw_pos (GimpRuler *ruler)
       gdouble  position;
       gdouble  increment;
 
+      cairo_translate (cr, allocation.x, allocation.y);
+
       /*  If a backing store exists, restore the ruler  */
       if (priv->backing_store)
         {



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