[gtk+/rendering-cleanup-next: 45/153] textview: Port to draw vfunc



commit 26f507d926acecf56d2bc0ccf19a34de14979ba1
Author: Benjamin Otte <otte redhat com>
Date:   Mon Sep 6 16:38:08 2010 +0200

    textview: Port to draw vfunc

 gtk/gtktextview.c |   96 ++++++++++++++++++++++++++--------------------------
 1 files changed, 48 insertions(+), 48 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 86156d0..48278fe 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -302,9 +302,14 @@ static gint gtk_text_view_focus_out_event      (GtkWidget        *widget,
                                                 GdkEventFocus    *event);
 static gint gtk_text_view_motion_event         (GtkWidget        *widget,
                                                 GdkEventMotion   *event);
-static gint gtk_text_view_expose_event         (GtkWidget        *widget,
-                                                GdkEventExpose   *expose);
-static void gtk_text_view_draw_focus           (GtkWidget        *widget);
+static gint gtk_text_view_draw                 (GtkWidget        *widget,
+                                                cairo_t          *cr,
+                                                int               width,
+                                                int               height);
+static void gtk_text_view_draw_focus           (GtkWidget        *widget,
+                                                cairo_t          *cr,
+                                                int               width,
+                                                int               height);
 static gboolean gtk_text_view_focus            (GtkWidget        *widget,
                                                 GtkDirectionType  direction);
 static void gtk_text_view_move_focus           (GtkWidget        *widget,
@@ -592,7 +597,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   widget_class->focus_in_event = gtk_text_view_focus_in_event;
   widget_class->focus_out_event = gtk_text_view_focus_out_event;
   widget_class->motion_notify_event = gtk_text_view_motion_event;
-  widget_class->expose_event = gtk_text_view_expose_event;
+  widget_class->draw = gtk_text_view_draw;
   widget_class->focus = gtk_text_view_focus;
 
   /* need to override the base class function via override_class_handler,
@@ -4778,14 +4783,12 @@ gtk_text_view_motion_event (GtkWidget *widget, GdkEventMotion *event)
 
 static void
 gtk_text_view_paint (GtkWidget      *widget,
-                     GdkRectangle   *area,
-                     GdkEventExpose *event)
+                     cairo_t        *cr)
 {
   GtkTextView *text_view;
   GtkTextViewPrivate *priv;
   GList *child_exposes;
   GList *tmp_list;
-  cairo_t *cr;
   
   text_view = GTK_TEXT_VIEW (widget);
   priv = text_view->priv;
@@ -4815,11 +4818,7 @@ gtk_text_view_paint (GtkWidget      *widget,
 
   child_exposes = NULL;
 
-  cr = gdk_cairo_create (priv->text_window->bin_window);
-
-  gdk_cairo_region (cr, event->region);
-  cairo_clip (cr);
-
+  cairo_save (cr);
   cairo_translate (cr, -priv->xoffset, -priv->yoffset);
 
   gtk_text_layout_draw (priv->layout,
@@ -4827,16 +4826,16 @@ gtk_text_view_paint (GtkWidget      *widget,
                         cr,
                         &child_exposes);
 
-  cairo_destroy (cr);
+  cairo_restore (cr);
 
   tmp_list = child_exposes;
   while (tmp_list != NULL)
     {
       GtkWidget *child = tmp_list->data;
   
-      gtk_container_propagate_expose (GTK_CONTAINER (text_view),
-                                      child,
-                                      event);
+      gtk_container_propagate_draw (GTK_CONTAINER (text_view),
+                                    child,
+                                    cr);
 
       g_object_unref (child);
       
@@ -4846,21 +4845,32 @@ gtk_text_view_paint (GtkWidget      *widget,
   g_list_free (child_exposes);
 }
 
-static gint
-gtk_text_view_expose_event (GtkWidget *widget, GdkEventExpose *event)
+static gboolean
+gtk_text_view_draw (GtkWidget *widget,
+                    cairo_t   *cr,
+                    int        width,
+                    int        height)
 {
   GSList *tmp_list;
+  GdkWindow *window;
   
-  if (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW (widget),
-                                                 GTK_TEXT_WINDOW_TEXT))
+  if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
+    gtk_text_view_draw_focus (widget, cr, width, height);
+
+  window = gtk_text_view_get_window (GTK_TEXT_VIEW (widget),
+                                     GTK_TEXT_WINDOW_TEXT);
+  if (gtk_cairo_should_draw_window (cr, window))
     {
+      int x, y;
+
       DV(g_print (">Exposed ("G_STRLOC")\n"));
-      gtk_text_view_paint (widget, &event->area, event);
+      cairo_save (cr);
+      gdk_window_get_position (window, &x, &y);
+      cairo_translate (cr, x, y);
+      gtk_text_view_paint (widget, cr);
+      cairo_restore (cr);
     }
 
-  if (event->window == gtk_widget_get_window (widget))
-    gtk_text_view_draw_focus (widget);
-
   /* Propagate exposes to all unanchored children. 
    * Anchored children are handled in gtk_text_view_paint(). 
    */
@@ -4873,9 +4883,9 @@ gtk_text_view_expose_event (GtkWidget *widget, GdkEventExpose *event)
        * child->window
        */
       if (!vc->anchor)
-        gtk_container_propagate_expose (GTK_CONTAINER (widget),
-                                        vc->widget,
-                                        event);
+        gtk_container_propagate_draw (GTK_CONTAINER (widget),
+                                      vc->widget,
+                                      cr);
       
       tmp_list = tmp_list->next;
     }
@@ -4884,10 +4894,11 @@ gtk_text_view_expose_event (GtkWidget *widget, GdkEventExpose *event)
 }
 
 static void
-gtk_text_view_draw_focus (GtkWidget *widget)
+gtk_text_view_draw_focus (GtkWidget *widget,
+                          cairo_t   *cr,
+                          int        width,
+                          int        height)
 {
-  GtkAllocation allocation;
-  GdkWindow *window;
   gboolean interior_focus;
 
   /* We clear the focus if we are in interior focus mode. */
@@ -4895,24 +4906,13 @@ gtk_text_view_draw_focus (GtkWidget *widget)
 			"interior-focus", &interior_focus,
 			NULL);
   
-  if (gtk_widget_is_drawable (widget))
-    {
-      window = gtk_widget_get_window (widget);
-
-      if (gtk_widget_has_focus (widget) && !interior_focus)
-        {
-          gtk_widget_get_allocation (widget, &allocation);
-          gtk_paint_focus (gtk_widget_get_style (widget),
-                           window,
-                           gtk_widget_get_state (widget),
-                           NULL, widget, "textview",
-                           0, 0,
-                           allocation.width, allocation.height);
-        }
-      else
-        {
-          gdk_window_clear (window);
-        }
+  if (gtk_widget_has_focus (widget) && !interior_focus)
+    {          
+      gtk_cairo_paint_focus (gtk_widget_get_style (widget), cr,
+                       gtk_widget_get_state (widget),
+                       widget, "textview",
+                       0, 0,
+                       width, height);
     }
 }
 



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