[gtk+/rendering-cleanup-next: 103/153] colorsel: Connect to draw signal



commit 7bd01ea04b0c44b63eab25e0ad279dbd4385f1ab
Author: Benjamin Otte <otte redhat com>
Date:   Wed Sep 8 21:07:31 2010 +0200

    colorsel: Connect to draw signal

 gtk/gtkcolorsel.c |  106 +++++++++++++++++++++++-----------------------------
 1 files changed, 47 insertions(+), 59 deletions(-)
---
diff --git a/gtk/gtkcolorsel.c b/gtk/gtkcolorsel.c
index 38789eb..13be38f 100644
--- a/gtk/gtkcolorsel.c
+++ b/gtk/gtkcolorsel.c
@@ -674,7 +674,11 @@ gtk_color_selection_grab_broken (GtkWidget          *widget,
  *
  */
 
-static void color_sample_draw_sample (GtkColorSelection *colorsel, int which);
+static void color_sample_draw_sample (GtkColorSelection *colorsel,
+                                      int                which,
+                                      cairo_t *          cr,
+                                      int                width,
+                                      int                height);
 static void color_sample_update_samples (GtkColorSelection *colorsel);
 
 static void
@@ -833,13 +837,15 @@ color_sample_drag_handle (GtkWidget        *widget,
 
 /* which = 0 means draw old sample, which = 1 means draw new */
 static void
-color_sample_draw_sample (GtkColorSelection *colorsel, int which)
+color_sample_draw_sample (GtkColorSelection *colorsel,
+                          int                which,
+                          cairo_t           *cr,
+                          int                width,
+                          int                height)
 {
-  GtkAllocation allocation;
   GtkWidget *da;
-  gint x, y, wid, heig, goff;
+  gint x, y, goff;
   GtkColorSelectionPrivate *priv;
-  cairo_t *cr;
   
   g_return_if_fail (colorsel != NULL);
   priv = colorsel->private_data;
@@ -862,12 +868,6 @@ color_sample_draw_sample (GtkColorSelection *colorsel, int which)
       goff =  old_sample_allocation.width % 32;
     }
 
-  cr = gdk_cairo_create (gtk_widget_get_window (da));
-
-  gtk_widget_get_allocation (da, &allocation);
-  wid = allocation.width;
-  heig = allocation.height;
-
   /* Below needs tweaking for non-power-of-two */  
   
   if (priv->has_opacity)
@@ -875,12 +875,12 @@ color_sample_draw_sample (GtkColorSelection *colorsel, int which)
       /* Draw checks in background */
 
       cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
-      cairo_rectangle (cr, 0, 0, wid, heig);
+      cairo_rectangle (cr, 0, 0, width, height);
       cairo_fill (cr);
 
       cairo_set_source_rgb (cr, 0.75, 0.75, 0.75);
-      for (x = goff & -CHECK_SIZE; x < goff + wid; x += CHECK_SIZE)
-	for (y = 0; y < heig; y += CHECK_SIZE)
+      for (x = goff & -CHECK_SIZE; x < goff + width; x += CHECK_SIZE)
+	for (y = 0; y < height; y += CHECK_SIZE)
 	  if ((x / CHECK_SIZE + y / CHECK_SIZE) % 2 == 0)
 	    cairo_rectangle (cr, x - goff, y, CHECK_SIZE, CHECK_SIZE);
       cairo_fill (cr);
@@ -905,10 +905,8 @@ color_sample_draw_sample (GtkColorSelection *colorsel, int which)
 			       priv->color[COLORSEL_OPACITY] : 1.0);
     }
 
-  cairo_rectangle (cr, 0, 0, wid, heig);
+  cairo_rectangle (cr, 0, 0, width, height);
   cairo_fill (cr);
-
-  cairo_destroy (cr);
 }
 
 
@@ -921,21 +919,25 @@ color_sample_update_samples (GtkColorSelection *colorsel)
 }
 
 static gboolean
-color_old_sample_expose (GtkWidget         *da,
-			 GdkEventExpose    *event,
-			 GtkColorSelection *colorsel)
+color_old_sample_draw (GtkWidget         *da,
+                       cairo_t           *cr,
+                       int                width,
+                       int                height,
+                       GtkColorSelection *colorsel)
 {
-  color_sample_draw_sample (colorsel, 0);
+  color_sample_draw_sample (colorsel, 0, cr, width, height);
   return FALSE;
 }
 
 
 static gboolean
-color_cur_sample_expose (GtkWidget         *da,
-			 GdkEventExpose    *event,
-			 GtkColorSelection *colorsel)
+color_cur_sample_draw (GtkWidget         *da,
+                       cairo_t           *cr,
+                       int                width,
+                       int                height,
+                       GtkColorSelection *colorsel)
 {
-  color_sample_draw_sample (colorsel, 1);
+  color_sample_draw_sample (colorsel, 1, cr, width, height);
   return FALSE;
 }
 
@@ -1021,11 +1023,11 @@ color_sample_new (GtkColorSelection *colorsel)
   gtk_box_pack_start (GTK_BOX (priv->sample_area), priv->cur_sample,
 		      TRUE, TRUE, 0);
   
-  g_signal_connect (priv->old_sample, "expose-event",
-		    G_CALLBACK (color_old_sample_expose),
+  g_signal_connect (priv->old_sample, "draw",
+		    G_CALLBACK (color_old_sample_draw),
 		    colorsel);
-  g_signal_connect (priv->cur_sample, "expose-event",
-		    G_CALLBACK (color_cur_sample_expose),
+  g_signal_connect (priv->cur_sample, "draw",
+		    G_CALLBACK (color_cur_sample_draw),
 		    colorsel);
   
   color_sample_setup_dnd (colorsel, priv->old_sample);
@@ -1068,40 +1070,27 @@ palette_get_color (GtkWidget *drawing_area, gdouble *color)
 }
 
 static void
-palette_paint (GtkWidget    *drawing_area,
-	       GdkRectangle *area,
-	       gpointer      data)
+palette_paint (GtkWidget *drawing_area,
+               cairo_t   *cr,
+               int        width,
+               int        height,
+	       gpointer   data)
 {
-  GdkWindow *window;
-  cairo_t *cr;
   gint focus_width;
 
-  window = gtk_widget_get_window (drawing_area);
-
-  if (window == NULL)
-    return;
-
-  cr = gdk_cairo_create (window);
-
   gdk_cairo_set_source_color (cr, &gtk_widget_get_style (drawing_area)->bg[GTK_STATE_NORMAL]);
-  gdk_cairo_rectangle (cr, area);
-  cairo_fill (cr);
+  cairo_paint (cr);
   
   if (gtk_widget_has_focus (drawing_area))
     {
-      GtkAllocation allocation;
-
       set_focus_line_attributes (drawing_area, cr, &focus_width);
 
-      gtk_widget_get_allocation (drawing_area, &allocation);
       cairo_rectangle (cr,
                        focus_width / 2., focus_width / 2.,
-                       allocation.width - focus_width,
-                       allocation.height - focus_width);
+                       width - focus_width,
+                       height - focus_width);
       cairo_stroke (cr);
     }
-
-  cairo_destroy (cr);
 }
 
 static void
@@ -1346,14 +1335,13 @@ palette_set_color (GtkWidget         *drawing_area,
 }
 
 static gboolean
-palette_expose (GtkWidget      *drawing_area,
-		GdkEventExpose *event,
-		gpointer        data)
+palette_draw (GtkWidget *drawing_area,
+              cairo_t   *cr,
+              int        width,
+              int        height,
+              gpointer  data)
 {
-  if (gtk_widget_get_window (drawing_area) == NULL)
-    return FALSE;
-  
-  palette_paint (drawing_area, &(event->area), data);
+  palette_paint (drawing_area, cr, width, height, data);
   
   return FALSE;
 }
@@ -1600,8 +1588,8 @@ palette_new (GtkColorSelection *colorsel)
                          | GDK_ENTER_NOTIFY_MASK
                          | GDK_LEAVE_NOTIFY_MASK);
   
-  g_signal_connect (retval, "expose-event",
-		    G_CALLBACK (palette_expose), colorsel);
+  g_signal_connect (retval, "draw",
+		    G_CALLBACK (palette_draw), colorsel);
   g_signal_connect (retval, "button-press-event",
 		    G_CALLBACK (palette_press), colorsel);
   g_signal_connect (retval, "button-release-event",



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