[Xfce4-commits] <libxfce4ui:stephan/gtk3> Some improvements in heading rendering.

Nick Schermer noreply at xfce.org
Fri May 4 22:48:01 CEST 2012


Updating branch refs/heads/stephan/gtk3
         to 34573fe70a99aed23ef2f830fca28b232f16cb82 (commit)
       from 1cc5ff252449165ba3f3cbcc9d78feb6943ca137 (commit)

commit 34573fe70a99aed23ef2f830fca28b232f16cb82
Author: Nick Schermer <nick at xfce.org>
Date:   Fri May 4 22:47:13 2012 +0200

    Some improvements in heading rendering.

 libxfce4ui/xfce-heading.c       |  133 +++++++++++++--------------------------
 libxfce4ui/xfce-titled-dialog.c |    6 --
 2 files changed, 45 insertions(+), 94 deletions(-)

diff --git a/libxfce4ui/xfce-heading.c b/libxfce4ui/xfce-heading.c
index 42f7d70..f09527d 100644
--- a/libxfce4ui/xfce-heading.c
+++ b/libxfce4ui/xfce-heading.c
@@ -43,7 +43,6 @@ static void         _xfce_heading_finalize       (GObject          *object);
 static void         _xfce_heading_realize        (GtkWidget        *widget);
 static void         _xfce_heading_size_request   (GtkWidget        *widget,
                                                   GtkRequisition   *requisition);
-static void         _xfce_heading_style_updated  (GtkWidget        *widget);
 static gboolean     _xfce_heading_draw           (GtkWidget        *widget,
                                                   cairo_t *ctx);
 static AtkObject   *_xfce_heading_get_accessible (GtkWidget        *widget);
@@ -70,7 +69,6 @@ struct _XfceHeading
   /*< private >*/
   GtkWidget       __parent__;
 
-  GtkStyleContext *context;
   GdkPixbuf       *icon;
   gchar           *icon_name;
   gchar           *subtitle;
@@ -96,7 +94,6 @@ _xfce_heading_class_init (XfceHeadingClass *klass)
   gtkwidget_class->realize = _xfce_heading_realize;
   gtkwidget_class->get_preferred_width = _xfce_heading_get_preferred_width;
   gtkwidget_class->get_preferred_height = _xfce_heading_get_preferred_height;
-  gtkwidget_class->style_updated = _xfce_heading_style_updated;
   gtkwidget_class->draw = _xfce_heading_draw;
   gtkwidget_class->get_accessible = _xfce_heading_get_accessible;
 }
@@ -106,14 +103,8 @@ _xfce_heading_class_init (XfceHeadingClass *klass)
 static void
 _xfce_heading_init (XfceHeading *heading)
 {
-  GtkStyleContext  *style_context = NULL;
-
   /* setup the widget parameters */
   gtk_widget_set_has_window (GTK_WIDGET (heading), TRUE);
-
-  style_context = gtk_widget_get_style_context (GTK_WIDGET (heading));
-
-  gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_HEADER);
 }
 
 
@@ -139,10 +130,9 @@ _xfce_heading_finalize (GObject *object)
 static void
 _xfce_heading_realize (GtkWidget *widget)
 {
-  GdkWindowAttr     attributes;
-  GtkAllocation     allocation;
-  GdkWindow        *window;
-  XfceHeading      *heading = XFCE_HEADING (widget);
+  GdkWindowAttr  attributes;
+  GtkAllocation  allocation;
+  GdkWindow     *window;
 
   /* mark the widget as realized */
   gtk_widget_set_realized (widget, TRUE);
@@ -161,42 +151,42 @@ _xfce_heading_realize (GtkWidget *widget)
 
   /* allocate the widget window */
   window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
-                                   GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL);
+                           GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL);
   gtk_widget_set_window (widget, window);
   gdk_window_set_user_data (window, widget);
-
-  heading->context = gtk_widget_get_style_context (widget);
 }
 
 
 
 static void
-_xfce_heading_get_preferred_width (
-        GtkWidget *widget,
-        gint *min,
-        gint *natural)
+_xfce_heading_get_preferred_width (GtkWidget *widget,
+                                   gint *min,
+                                   gint *natural)
 {
   GtkRequisition requisition;
-  
+
   _xfce_heading_size_request (widget, &requisition);
 
   *min = *natural = requisition.width;
 }
 
+
+
 static void
-_xfce_heading_get_preferred_height (
-        GtkWidget *widget,
-        gint *min,
-        gint *natural)
+_xfce_heading_get_preferred_height (GtkWidget *widget,
+                                    gint *min,
+                                    gint *natural)
 {
 
   GtkRequisition requisition;
-  
+
   _xfce_heading_size_request (widget, &requisition);
 
   *min = *natural = requisition.height;
 }
 
+
+
 static void
 _xfce_heading_size_request (GtkWidget      *widget,
                             GtkRequisition *requisition)
@@ -234,62 +224,38 @@ _xfce_heading_size_request (GtkWidget      *widget,
 
 
 
-static void
-_xfce_heading_style_updated (GtkWidget *widget)
-{
-  GtkStyleContext  *style_context = NULL;
-
-  /* check if we're already realized */
-  if (gtk_widget_get_realized (widget))
-    {
-      style_context = gtk_widget_get_style_context (widget);
-
-
-      gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_HEADER);
-    }
-}
-
-
-
 static gboolean
 _xfce_heading_draw (GtkWidget      *widget,
                     cairo_t *ctx)
 {
-  XfceHeading *heading = XFCE_HEADING (widget);
-  PangoLayout *layout;
-  GdkRGBA      bg_color;
-  GdkRGBA      text_color;
-  GdkPixbuf   *pixbuf;
-  gboolean     rtl;
-  gint         width;
-  gint         height;
-  gint         x;
-  gint         y;
-  GtkAllocation allocation;
-
-  gtk_style_context_get_background_color (heading->context,
-                                          GTK_STATE_FLAG_NORMAL,
-                                          &bg_color);
-  gtk_style_context_get_color (heading->context,
-                               GTK_STATE_FLAG_NORMAL,
-                               &text_color);
-  
+  XfceHeading     *heading = XFCE_HEADING (widget);
+  PangoLayout     *layout;
+  GdkPixbuf       *pixbuf;
+  gboolean         rtl;
+  gint             width;
+  gint             height;
+  gint             x;
+  gint             y;
+  GtkAllocation    allocation;
+  GtkStyleContext *context;
+
   gtk_widget_get_allocation (widget, &allocation);
 
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
+
   /* check if we should render from right to left */
   rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
 
   /* determine the initial horizontal position */
   x = (rtl ? allocation.width - XFCE_HEADING_BORDER : XFCE_HEADING_BORDER);
 
-  gdk_cairo_set_source_rgba (ctx, &bg_color);
-
-  cairo_rectangle ( ctx,
-                    0.0, 0.0,
-                    allocation.width, allocation.height);
-  cairo_paint (ctx);
-
-  cairo_save (ctx);
+  gtk_render_background (context, ctx,
+                         allocation.x, allocation.y,
+                         allocation.x + allocation.width,
+                         allocation.y + allocation.height);
 
   /* check if we have a pixbuf to render */
   pixbuf = _xfce_heading_make_pixbuf (heading);
@@ -302,16 +268,11 @@ _xfce_heading_draw (GtkWidget      *widget,
       /* determine the vertical position */
       y = (allocation.height - height) / 2;
 
-      cairo_translate (ctx,
+      gtk_render_icon (context, ctx,
+                       pixbuf,
                        rtl ? x - width : x,
                        y);
 
-      gdk_cairo_set_source_pixbuf (ctx,
-                                   pixbuf,
-                                   0.0,
-                                   0.0);
-      cairo_paint ( ctx );
-
       /* release the pixbuf */
       g_object_unref (G_OBJECT (pixbuf));
 
@@ -319,8 +280,6 @@ _xfce_heading_draw (GtkWidget      *widget,
       x += (rtl ? -1 : 1) * (width + XFCE_HEADING_SPACING);
     }
 
-  cairo_restore (ctx);
-
   /* generate the title layout */
   layout = _xfce_heading_make_layout (heading);
   pango_layout_get_pixel_size (layout, &width, &height);
@@ -328,17 +287,15 @@ _xfce_heading_draw (GtkWidget      *widget,
   /* determine the vertical position */
   y = (allocation.height - height) / 2;
 
-  /* render the title */
-  cairo_move_to (ctx,
-                 rtl ? x - width : x,
-                 y);
-
-  pango_cairo_update_layout (ctx, layout);
-  gdk_cairo_set_source_rgba (ctx, &text_color);
-  pango_cairo_show_layout (ctx, layout);
+  gtk_render_layout (context, ctx,
+                     rtl ? x - width : x, y,
+                     layout);
 
   /* release the layout */
   g_object_unref (G_OBJECT (layout));
+
+  gtk_style_context_restore (context);
+
   return FALSE;
 }
 
@@ -386,7 +343,7 @@ _xfce_heading_make_layout (XfceHeading *heading)
 
   /* allocate and setup a new layout from the widget's context */
   layout = gtk_widget_create_pango_layout (GTK_WIDGET (heading), text->str);
-  
+
 
   /* allocate an attribute list (large bold title) */
   attr_list = pango_attr_list_new ();
diff --git a/libxfce4ui/xfce-titled-dialog.c b/libxfce4ui/xfce-titled-dialog.c
index 2572774..4a865fa 100644
--- a/libxfce4ui/xfce-titled-dialog.c
+++ b/libxfce4ui/xfce-titled-dialog.c
@@ -117,15 +117,9 @@ xfce_titled_dialog_init (XfceTitledDialog *titled_dialog)
 {
   GtkWidget *line;
   GtkWidget *vbox;
-  GtkStyleContext  *style_context = NULL;
-
-  style_context = gtk_widget_get_style_context (GTK_WIDGET (titled_dialog));
-
-  gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_DEFAULT);
 
   gtk_widget_set_has_window (GTK_WIDGET (titled_dialog), FALSE);
 
-
   /* connect the private data */
   titled_dialog->priv = XFCE_TITLED_DIALOG_GET_PRIVATE (titled_dialog);
 


More information about the Xfce4-commits mailing list