[gtk+/rendering-cleanup-next: 64/203] notebook: Port to draw vfunc



commit 06a584d6393fccf4fb930a985c1b9de1a51c97dc
Author: Benjamin Otte <otte redhat com>
Date:   Tue Sep 7 02:39:44 2010 +0200

    notebook: Port to draw vfunc

 gtk/gtknotebook.c |   88 ++++++++++++++++++++++++++++------------------------
 1 files changed, 47 insertions(+), 41 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index ad2a3cd..c143a4e 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -283,8 +283,8 @@ static void gtk_notebook_size_request        (GtkWidget        *widget,
 					      GtkRequisition   *requisition);
 static void gtk_notebook_size_allocate       (GtkWidget        *widget,
 					      GtkAllocation    *allocation);
-static gint gtk_notebook_expose              (GtkWidget        *widget,
-					      GdkEventExpose   *event);
+static gint gtk_notebook_draw                (GtkWidget        *widget,
+                                              cairo_t          *cr);
 static gboolean gtk_notebook_scroll          (GtkWidget        *widget,
                                               GdkEventScroll   *event);
 static gint gtk_notebook_button_press        (GtkWidget        *widget,
@@ -403,7 +403,7 @@ static void  gtk_notebook_child_reordered    (GtkNotebook      *notebook,
 
 /*** GtkNotebook Drawing Functions ***/
 static void gtk_notebook_paint               (GtkWidget        *widget,
-					      GdkRectangle     *area);
+					      cairo_t          *cr);
 static void gtk_notebook_draw_tab            (GtkNotebook      *notebook,
 					      GtkNotebookPage  *page,
 					      cairo_t          *cr);
@@ -559,7 +559,7 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   widget_class->unrealize = gtk_notebook_unrealize;
   widget_class->size_request = gtk_notebook_size_request;
   widget_class->size_allocate = gtk_notebook_size_allocate;
-  widget_class->expose_event = gtk_notebook_expose;
+  widget_class->draw = gtk_notebook_draw;
   widget_class->scroll_event = gtk_notebook_scroll;
   widget_class->button_press_event = gtk_notebook_button_press;
   widget_class->button_release_event = gtk_notebook_button_release;
@@ -1580,7 +1580,7 @@ gtk_notebook_get_property (GObject         *object,
  * gtk_notebook_realize
  * gtk_notebook_size_request
  * gtk_notebook_size_allocate
- * gtk_notebook_expose
+ * gtk_notebook_draw
  * gtk_notebook_scroll
  * gtk_notebook_button_press
  * gtk_notebook_button_release
@@ -2251,16 +2251,27 @@ gtk_notebook_size_allocate (GtkWidget     *widget,
 }
 
 static gint
-gtk_notebook_expose (GtkWidget      *widget,
-		     GdkEventExpose *event)
+gtk_notebook_draw (GtkWidget *widget,
+                   cairo_t   *cr)
 {
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GtkNotebookPrivate *priv = notebook->priv;
+  GtkAllocation allocation;
+  GdkWindow *window;
   gint i;
 
-  if (gtk_widget_is_drawable (widget))
+  gtk_widget_get_allocation (widget, &allocation);
+
+  window = gtk_widget_get_window (widget);
+  if (gtk_cairo_should_draw_window (cr, window))
     {
-      gtk_notebook_paint (widget, &event->area);
+      cairo_save (cr);
+
+      cairo_translate (cr, -allocation.x, -allocation.y);
+      gtk_notebook_paint (widget, cr);
+
+      cairo_restore (cr);
+
       if (priv->show_tabs)
 	{
 	  GtkNotebookPage *page;
@@ -2270,32 +2281,31 @@ gtk_notebook_expose (GtkWidget      *widget,
             {
 	      page = GTK_NOTEBOOK_PAGE (pages);
 
-	      if (gtk_widget_get_window (page->tab_label) == event->window &&
-		  gtk_widget_is_drawable (page->tab_label))
-		gtk_container_propagate_expose (GTK_CONTAINER (notebook),
-						page->tab_label, event);
+              if (gtk_widget_get_parent (page->tab_label) == widget)
+                gtk_container_propagate_draw (GTK_CONTAINER (notebook),
+                                              page->tab_label, cr);
 	    }
 	}
 
-      if (priv->cur_page)
-	gtk_container_propagate_expose (GTK_CONTAINER (notebook),
-					priv->cur_page->child,
-					event);
+      if (priv->cur_page && priv->operation != DRAG_OPERATION_REORDER)
+	gtk_container_propagate_draw (GTK_CONTAINER (notebook),
+                                      priv->cur_page->child,
+                                      cr);
       if (priv->show_tabs)
       {
         for (i = 0; i < N_ACTION_WIDGETS; i++)
         {
-          if (priv->action_widget[i] &&
-              gtk_widget_is_drawable (priv->action_widget[i]))
-            gtk_container_propagate_expose (GTK_CONTAINER (notebook),
-                                            priv->action_widget[i], event);
+          if (priv->action_widget[i])
+            gtk_container_propagate_draw (GTK_CONTAINER (notebook),
+                                          priv->action_widget[i], cr);
         }
       }
     }
 
-  if (event->window == priv->drag_window)
+  if (priv->operation == DRAG_OPERATION_REORDER &&
+      gtk_cairo_should_draw_window (cr, priv->drag_window))
     {
-      cairo_t *cr;
+      int x, y;
 
       /* FIXME: This is a workaround to make tabs reordering work better
        * with engines with rounded tabs. If the drag window background
@@ -2304,16 +2314,21 @@ gtk_notebook_expose (GtkWidget      *widget,
        * Ideally, these corners should be made transparent, Either by using
        * ARGB visuals or shape windows.
        */
-      cr = gdk_cairo_create (priv->drag_window);
+      cairo_save (cr);
+      gdk_window_get_position (priv->drag_window, &x, &y);
+      cairo_translate (cr, x - allocation.x, y - allocation.y);
+
       gdk_cairo_set_source_color (cr, &gtk_widget_get_style (widget)->bg [GTK_STATE_NORMAL]);
       cairo_paint (cr);
 
       gtk_notebook_draw_tab (notebook,
 			     priv->cur_page,
 			     cr);
-      cairo_destroy (cr);
-      gtk_container_propagate_expose (GTK_CONTAINER (notebook),
-				      priv->cur_page->tab_label, event);
+
+      cairo_restore (cr);
+
+      gtk_container_propagate_draw (GTK_CONTAINER (notebook),
+				    priv->cur_page->tab_label, cr);
     }
   
   return FALSE;
@@ -4787,7 +4802,7 @@ gtk_notebook_search_page (GtkNotebook *notebook,
  */
 static void
 gtk_notebook_paint (GtkWidget    *widget,
-		    GdkRectangle *area)
+		    cairo_t      *cr)
 {
   GtkNotebook *notebook;
   GtkNotebookPrivate *priv;
@@ -4801,7 +4816,6 @@ gtk_notebook_paint (GtkWidget    *widget,
   gint gap_x = 0, gap_width = 0, step = STEP_PREV;
   gboolean is_rtl;
   gint tab_pos;
-  cairo_t *cr;
    
   notebook = GTK_NOTEBOOK (widget);
   priv = notebook->priv;
@@ -4821,10 +4835,9 @@ gtk_notebook_paint (GtkWidget    *widget,
 
   if (priv->show_border && (!priv->show_tabs || !priv->children))
     {
-      gtk_paint_box (gtk_widget_get_style (widget),
-                     gtk_widget_get_window (widget),
+      gtk_cairo_paint_box (gtk_widget_get_style (widget), cr,
 		     GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-		     area, widget, "notebook",
+		     widget, "notebook",
 		     x, y, width, height);
       return;
     }
@@ -4885,17 +4898,12 @@ gtk_notebook_paint (GtkWidget    *widget,
 	  break;
 	}
     }
-  gtk_paint_box_gap (gtk_widget_get_style (widget),
-                     gtk_widget_get_window (widget),
+  gtk_cairo_paint_box_gap (gtk_widget_get_style (widget), cr,
 		     GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-		     area, widget, "notebook",
+		     widget, "notebook",
 		     x, y, width, height,
 		     tab_pos, gap_x, gap_width);
 
-  cr = gdk_cairo_create (gtk_widget_get_window (widget));
-  gdk_cairo_rectangle (cr, area);
-  cairo_clip (cr);
-
   showarrow = FALSE;
   children = gtk_notebook_search_page (notebook, NULL, step, TRUE);
   while (children)
@@ -4925,8 +4933,6 @@ gtk_notebook_paint (GtkWidget    *widget,
 
   if (priv->operation != DRAG_OPERATION_REORDER)
     gtk_notebook_draw_tab (notebook, priv->cur_page, cr);
-
-  cairo_destroy (cr);
 }
 
 static void



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