[gtk+/rendering-cleanup-next: 83/153] button: Port to draw vfunc



commit b4ade5f3246ed7a89024dea08340b762de703111
Author: Benjamin Otte <otte redhat com>
Date:   Wed Sep 8 00:23:04 2010 +0200

    button: Port to draw vfunc
    
    Also port togglebutton, they use the same paint function.

 gtk/gtkbutton.c       |   52 ++++++++++++++++++++++----------------------
 gtk/gtkbutton.h       |    4 ++-
 gtk/gtktogglebutton.c |   57 +++++++++++++++++++++++++------------------------
 3 files changed, 58 insertions(+), 55 deletions(-)
---
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 3b98a7c..2dc7f66 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -128,7 +128,7 @@ static void gtk_button_unmap (GtkWidget * widget);
 static void gtk_button_style_set (GtkWidget * widget, GtkStyle * prev_style);
 static void gtk_button_size_allocate (GtkWidget * widget,
 				      GtkAllocation * allocation);
-static gint gtk_button_expose (GtkWidget * widget, GdkEventExpose * event);
+static gint gtk_button_draw (GtkWidget * widget, cairo_t *cr, int width, int height);
 static gint gtk_button_button_press (GtkWidget * widget,
 				     GdkEventButton * event);
 static gint gtk_button_button_release (GtkWidget * widget,
@@ -215,7 +215,7 @@ gtk_button_class_init (GtkButtonClass *klass)
   widget_class->unmap = gtk_button_unmap;
   widget_class->style_set = gtk_button_style_set;
   widget_class->size_allocate = gtk_button_size_allocate;
-  widget_class->expose_event = gtk_button_expose;
+  widget_class->draw = gtk_button_draw;
   widget_class->button_press_event = gtk_button_button_press;
   widget_class->button_release_event = gtk_button_button_release;
   widget_class->grab_broken_event = gtk_button_grab_broken;
@@ -1539,14 +1539,15 @@ gtk_button_size_allocate (GtkWidget     *widget,
 
 void
 _gtk_button_paint (GtkButton          *button,
-		   const GdkRectangle *area,
+		   cairo_t            *cr,
+                   int                 width,
+                   int                 height,
 		   GtkStateType        state_type,
 		   GtkShadowType       shadow_type,
 		   const gchar        *main_detail,
 		   const gchar        *default_detail)
 {
   GtkWidget *widget;
-  gint width, height;
   gint x, y;
   gint border_width;
   GtkBorder default_border;
@@ -1571,17 +1572,17 @@ _gtk_button_paint (GtkButton          *button,
   style = gtk_widget_get_style (widget);
   window = gtk_widget_get_window (widget);
 
-  x = allocation.x + border_width;
-  y = allocation.y + border_width;
-  width = allocation.width - border_width * 2;
-  height = allocation.height - border_width * 2;
+  x = border_width;
+  y = border_width;
+  width -= border_width * 2;
+  height -= border_width * 2;
 
   if (gtk_widget_has_default (widget) &&
       GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL)
     {
-      gtk_paint_box (style, window,
+      gtk_cairo_paint_box (style, cr,
                      GTK_STATE_NORMAL, GTK_SHADOW_IN,
-                     area, widget, "buttondefault",
+                     widget, "buttondefault",
                      x, y, width, height);
 
       x += default_border.left;
@@ -1607,9 +1608,9 @@ _gtk_button_paint (GtkButton          *button,
 
   if (button->relief != GTK_RELIEF_NONE || button->depressed ||
       gtk_widget_get_state(widget) == GTK_STATE_PRELIGHT)
-    gtk_paint_box (style, window,
+    gtk_cairo_paint_box (style, cr,
                    state_type,
-                   shadow_type, area, widget, "button",
+                   shadow_type, widget, "button",
                    x, y, width, height);
    
   if (gtk_widget_has_focus (widget))
@@ -1645,28 +1646,27 @@ _gtk_button_paint (GtkButton          *button,
           y += child_displacement_y;
         }
 
-      gtk_paint_focus (style, window,
+      gtk_cairo_paint_focus (style, cr,
                        gtk_widget_get_state (widget),
-                       area, widget, "button",
+                       widget, "button",
                        x, y, width, height);
     }
 }
 
 static gboolean
-gtk_button_expose (GtkWidget      *widget,
-		   GdkEventExpose *event)
+gtk_button_draw (GtkWidget *widget,
+		 cairo_t   *cr,
+                 int        width,
+                 int        height)
 {
-  if (gtk_widget_is_drawable (widget))
-    {
-      GtkButton *button = GTK_BUTTON (widget);
-      
-      _gtk_button_paint (button, &event->area,
-			 gtk_widget_get_state (widget),
-			 button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
-			 "button", "buttondefault");
+  GtkButton *button = GTK_BUTTON (widget);
+  
+  _gtk_button_paint (button, cr, width, height,
+                     gtk_widget_get_state (widget),
+                     button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
+                     "button", "buttondefault");
 
-      GTK_WIDGET_CLASS (gtk_button_parent_class)->expose_event (widget, event);
-    }
+  GTK_WIDGET_CLASS (gtk_button_parent_class)->draw (widget, cr, width, height);
 
   return FALSE;
 }
diff --git a/gtk/gtkbutton.h b/gtk/gtkbutton.h
index ea76cd8..dabb64b 100644
--- a/gtk/gtkbutton.h
+++ b/gtk/gtkbutton.h
@@ -136,7 +136,9 @@ GdkWindow*            gtk_button_get_event_window   (GtkButton      *button);
 void _gtk_button_set_depressed             (GtkButton          *button,
 					    gboolean            depressed);
 void _gtk_button_paint                     (GtkButton          *button,
-					    const GdkRectangle *area,
+                                            cairo_t            *cr,
+                                            int                 width,
+                                            int                 height,
 					    GtkStateType        state_type,
 					    GtkShadowType       shadow_type,
 					    const gchar        *main_detail,
diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c
index 2ea40ac..774e216 100644
--- a/gtk/gtktogglebutton.c
+++ b/gtk/gtktogglebutton.c
@@ -52,8 +52,10 @@ enum {
 };
 
 
-static gint gtk_toggle_button_expose        (GtkWidget            *widget,
-					     GdkEventExpose       *event);
+static gint gtk_toggle_button_draw         (GtkWidget            *widget,
+					    cairo_t              *cr,
+                                            int                   width,
+                                            int                   height);
 static gboolean gtk_toggle_button_mnemonic_activate  (GtkWidget            *widget,
                                                       gboolean              group_cycling);
 static void gtk_toggle_button_pressed       (GtkButton            *button);
@@ -98,7 +100,7 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class)
   gobject_class->set_property = gtk_toggle_button_set_property;
   gobject_class->get_property = gtk_toggle_button_get_property;
 
-  widget_class->expose_event = gtk_toggle_button_expose;
+  widget_class->draw = gtk_toggle_button_draw;
   widget_class->mnemonic_activate = gtk_toggle_button_mnemonic_activate;
 
   button_class->pressed = gtk_toggle_button_pressed;
@@ -416,34 +418,33 @@ gtk_toggle_button_get_inconsistent (GtkToggleButton *toggle_button)
 }
 
 static gint
-gtk_toggle_button_expose (GtkWidget      *widget,
-			  GdkEventExpose *event)
+gtk_toggle_button_draw (GtkWidget *widget,
+			cairo_t   *cr,
+                        int        width,
+                        int        height)
 {
-  if (gtk_widget_is_drawable (widget))
-    {
-      GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
-      GtkButton *button = GTK_BUTTON (widget);
-      GtkStateType state_type;
-      GtkShadowType shadow_type;
+  GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
+  GtkButton *button = GTK_BUTTON (widget);
+  GtkStateType state_type;
+  GtkShadowType shadow_type;
 
-      state_type = gtk_widget_get_state (widget);
-      
-      if (GTK_TOGGLE_BUTTON (widget)->inconsistent)
-        {
-          if (state_type == GTK_STATE_ACTIVE)
-            state_type = GTK_STATE_NORMAL;
-          shadow_type = GTK_SHADOW_ETCHED_IN;
-        }
-      else
-	shadow_type = button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
-
-      _gtk_button_paint (button, &event->area, state_type, shadow_type,
-			 "togglebutton", "togglebuttondefault");
-
-      if (child)
-	gtk_container_propagate_expose (GTK_CONTAINER (widget), child, event);
-    }
+  state_type = gtk_widget_get_state (widget);
   
+  if (GTK_TOGGLE_BUTTON (widget)->inconsistent)
+    {
+      if (state_type == GTK_STATE_ACTIVE)
+        state_type = GTK_STATE_NORMAL;
+      shadow_type = GTK_SHADOW_ETCHED_IN;
+    }
+  else
+    shadow_type = button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
+
+  _gtk_button_paint (button, cr, width, height, state_type, shadow_type,
+                     "togglebutton", "togglebuttondefault");
+
+  if (child)
+    gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr);
+
   return FALSE;
 }
 



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