]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkthemingengine.c
Make GtkToolItemGroup use GtkStyleContext
[~andy/gtk] / gtk / gtkthemingengine.c
index 55cb6bc0e05eeb2379ae86169aefabf8e9c9e96a..4dc889c00eb1c063027c999f149257d705932c15 100644 (file)
  * must be created, alongside the CSS file that will reference it, the
  * theming engine would be created as an .so library, and installed in
  * $(gtk-modules-dir)/theming-engines/.
+ *
+ * #GtkThemingEngine<!-- -->s have limited access to the object they are
+ * rendering, the #GtkThemingEngine API has read-only accessors to the
+ * style information contained in the rendered object's #GtkStyleContext.
  */
 
 typedef struct GtkThemingEnginePrivate GtkThemingEnginePrivate;
@@ -326,7 +330,6 @@ _gtk_theming_engine_set_context (GtkThemingEngine *engine,
 
 /**
  * gtk_theming_engine_register_property:
- * @engine: a #GtkThemingEngine
  * @name_space: namespace for the property name
  * @parse_func: parsing function to use, or %NULL
  * @pspec: the #GParamSpec for the new property
@@ -539,6 +542,30 @@ gtk_theming_engine_get_style (GtkThemingEngine *engine,
   va_end (args);
 }
 
+/**
+ * gtk_theming_engine_lookup_color:
+ * @engine: a #GtkThemingEngine
+ * @color_name: color name to lookup
+ * @color: (out): Return location for the looked up color
+ *
+ * Looks up and resolves a color name in the current style's color map.
+ *
+ * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
+ **/
+gboolean
+gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
+                                 const gchar      *color_name,
+                                 GdkRGBA          *color)
+{
+  GtkThemingEnginePrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
+  g_return_val_if_fail (color_name != NULL, FALSE);
+
+  priv = engine->priv;
+  return gtk_style_context_lookup_color (priv->context, color_name, color);
+}
+
 /**
  * gtk_theming_engine_get_state:
  * @engine: a #GtkThemingEngine
@@ -709,6 +736,168 @@ gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
   return gtk_style_context_get_junction_sides (priv->context);
 }
 
+/**
+ * gtk_theming_engine_get_color:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the foreground color
+ *
+ * Gets the foreground color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_color (GtkThemingEngine *engine,
+                              GtkStateFlags     state,
+                              GdkRGBA          *color)
+{
+  GtkThemingEnginePrivate *priv;
+
+  g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+  priv = engine->priv;
+  gtk_style_context_get_color (priv->context, state, color);
+}
+
+/**
+ * gtk_theming_engine_get_background_color:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the background color
+ *
+ * Gets the background color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
+                                         GtkStateFlags     state,
+                                         GdkRGBA          *color)
+{
+  GtkThemingEnginePrivate *priv;
+
+  g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+  priv = engine->priv;
+  gtk_style_context_get_background_color (priv->context, state, color);
+}
+
+/**
+ * gtk_theming_engine_get_border_color:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the border color
+ *
+ * Gets the border color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
+                                     GtkStateFlags     state,
+                                     GdkRGBA          *color)
+{
+  GtkThemingEnginePrivate *priv;
+
+  g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+  priv = engine->priv;
+  gtk_style_context_get_border_color (priv->context, state, color);
+}
+
+/**
+ * gtk_theming_engine_get_border:
+ * @engine: a #GtkthemingEngine
+ * @state: state to retrieve the border for
+ * @border: (out): return value for the border settings
+ *
+ * Gets the border for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_border (GtkThemingEngine *engine,
+                               GtkStateFlags     state,
+                               GtkBorder        *border)
+{
+  GtkThemingEnginePrivate *priv;
+
+  g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+  priv = engine->priv;
+  gtk_style_context_get_border (priv->context, state, border);
+}
+
+/**
+ * gtk_theming_engine_get_padding:
+ * @engine: a #GtkthemingEngine
+ * @state: state to retrieve the padding for
+ * @padding: (out): return value for the padding settings
+ *
+ * Gets the padding for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_padding (GtkThemingEngine *engine,
+                                GtkStateFlags     state,
+                                GtkBorder        *padding)
+{
+  GtkThemingEnginePrivate *priv;
+
+  g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+  priv = engine->priv;
+  gtk_style_context_get_padding (priv->context, state, padding);
+}
+
+/**
+ * gtk_theming_engine_get_margin:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the border for
+ * @margin: (out): return value for the margin settings
+ *
+ * Gets the margin for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_margin (GtkThemingEngine *engine,
+                               GtkStateFlags     state,
+                               GtkBorder        *margin)
+{
+  GtkThemingEnginePrivate *priv;
+
+  g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+  priv = engine->priv;
+  gtk_style_context_get_margin (priv->context, state, margin);
+}
+
+/**
+ * gtk_theming_engine_get_font:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the font for
+ *
+ * Returns the font description for a given state.
+ *
+ * Returns: the #PangoFontDescription for the given state. This
+ *          object is owned by GTK+ and should not be freed.
+ *
+ * Since: 3.0
+ **/
+const PangoFontDescription *
+gtk_theming_engine_get_font (GtkThemingEngine *engine,
+                             GtkStateFlags     state)
+{
+  GtkThemingEnginePrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
+
+  priv = engine->priv;
+  return gtk_style_context_get_font (priv->context, state);
+}
+
 /* GtkThemingModule */
 
 static gboolean
@@ -723,19 +912,13 @@ gtk_theming_module_load (GTypeModule *type_module)
   module_path = _gtk_find_module (name, "theming-engines");
 
   if (!module_path)
-    {
-      g_warning (_("Unable to locate theme engine in module path: \"%s\","), name);
-      return FALSE;
-    }
+    return FALSE;
 
   module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
   g_free (module_path);
 
   if (!module)
-    {
-      g_warning ("%s", g_module_error ());
-      return FALSE;
-    }
+    return FALSE;
 
   if (!g_module_symbol (module, "theme_init",
                         (gpointer *) &theming_module->init) ||
@@ -744,7 +927,6 @@ gtk_theming_module_load (GTypeModule *type_module)
       !g_module_symbol (module, "create_engine",
                         (gpointer *) &theming_module->create_engine))
     {
-      g_warning ("%s", g_module_error ());
       g_module_close (module);
 
       return FALSE;
@@ -869,20 +1051,26 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
                                  gdouble           width,
                                  gdouble           height)
 {
-  GdkRGBA *fg_color, *bg_color;
-  const GtkWidgetPath *path;
+  GdkRGBA *fg_color, *bg_color, *border_color;
   GtkStateFlags flags;
   gint exterior_size, interior_size, thickness, pad;
+  GtkBorderStyle border_style;
+  GtkBorder *border;
+  gint border_width;
 
   flags = gtk_theming_engine_get_state (engine);
-  path = gtk_theming_engine_get_path (engine);
   cairo_save (cr);
 
   gtk_theming_engine_get (engine, flags,
                           "color", &fg_color,
                           "background-color", &bg_color,
+                          "border-color", &border_color,
+                          "border-style", &border_style,
+                          "border-width", &border,
                           NULL);
 
+  border_width = MIN (MIN (border->top, border->bottom),
+                      MIN (border->left, border->right));
   exterior_size = MIN (width, height);
 
   if (exterior_size % 2 == 0) /* Ensure odd */
@@ -902,15 +1090,18 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
   x -= (1 + exterior_size - (gint) width) / 2;
   y -= (1 + exterior_size - (gint) height) / 2;
 
-  if (!gtk_theming_engine_has_class (engine, "menu"))
+  if (border_style == GTK_BORDER_STYLE_SOLID)
     {
-      cairo_set_line_width (cr, 1.0);
+      cairo_set_line_width (cr, border_width);
 
       cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
       gdk_cairo_set_source_rgba (cr, bg_color);
       cairo_fill_preserve (cr);
 
-      gdk_cairo_set_source_rgba (cr, fg_color);
+      if (border_color)
+        gdk_cairo_set_source_rgba (cr, border_color);
+      else
+        gdk_cairo_set_source_rgba (cr, fg_color);
 
       cairo_stroke (cr);
     }
@@ -974,6 +1165,9 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
   cairo_restore (cr);
 
   gdk_rgba_free (fg_color);
+  gdk_rgba_free (bg_color);
+  gdk_rgba_free (border_color);
+  gtk_border_free (border);
 }
 
 static void
@@ -985,13 +1179,13 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
                                   gdouble           height)
 {
   GtkStateFlags flags;
-  GdkRGBA *fg_color, *bg_color;
-  const GtkWidgetPath *path;
-  gint exterior_size, interior_size, pad, thickness;
+  GdkRGBA *fg_color, *bg_color, *border_color;
+  gint exterior_size, interior_size, pad, thickness, border_width;
+  GtkBorderStyle border_style;
+  GtkBorder *border;
   gdouble radius;
 
   flags = gtk_theming_engine_get_state (engine);
-  path = gtk_theming_engine_get_path (engine);
   radius = MIN (width, height) / 2 - 0.5;
 
   cairo_save (cr);
@@ -999,9 +1193,14 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
   gtk_theming_engine_get (engine, flags,
                           "color", &fg_color,
                           "background-color", &bg_color,
+                          "border-color", &border_color,
+                          "border-style", &border_style,
+                          "border-width", &border,
                           NULL);
 
   exterior_size = MIN (width, height);
+  border_width = MIN (MIN (border->top, border->bottom),
+                      MIN (border->left, border->right));
 
   if (exterior_size % 2 == 0) /* Ensure odd */
     exterior_size -= 1;
@@ -1009,21 +1208,23 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
   x -= (1 + exterior_size - width) / 2;
   y -= (1 + exterior_size - height) / 2;
 
-  if (!gtk_theming_engine_has_class (engine, "menu"))
+  if (border_style == GTK_BORDER_STYLE_SOLID)
     {
-      gdk_cairo_set_source_rgba (cr, bg_color);
-
+      cairo_set_line_width (cr, border_width);
       cairo_arc (cr,
                 x + exterior_size / 2.,
                 y + exterior_size / 2.,
                 (exterior_size - 1) / 2.,
                 0, 2 * G_PI);
 
+      gdk_cairo_set_source_rgba (cr, bg_color);
       cairo_fill_preserve (cr);
 
-      gdk_cairo_set_source_rgba (cr, fg_color);
+      if (border_color)
+        gdk_cairo_set_source_rgba (cr, border_color);
+      else
+        gdk_cairo_set_source_rgba (cr, fg_color);
 
-      cairo_set_line_width (cr, 1.);
       cairo_stroke (cr);
     }
 
@@ -1077,6 +1278,8 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
 
   gdk_rgba_free (fg_color);
   gdk_rgba_free (bg_color);
+  gdk_rgba_free (border_color);
+  gtk_border_free (border);
 }
 
 static void
@@ -1189,8 +1392,7 @@ _cairo_round_rectangle_sides (cairo_t          *cr,
   if (sides & SIDE_RIGHT)
     {
       if (radius == 0 ||
-          (junction & GTK_JUNCTION_TOP) ||
-          (junction & GTK_JUNCTION_RIGHT))
+          (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
         cairo_move_to (cr, x + width, y);
       else
         {
@@ -1199,8 +1401,7 @@ _cairo_round_rectangle_sides (cairo_t          *cr,
         }
 
       if (radius == 0 ||
-          (junction & GTK_JUNCTION_BOTTOM) ||
-          (junction & GTK_JUNCTION_RIGHT))
+          (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
         cairo_line_to (cr, x + width, y + height);
       else
         cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI / 4);
@@ -1209,8 +1410,7 @@ _cairo_round_rectangle_sides (cairo_t          *cr,
   if (sides & SIDE_BOTTOM)
     {
       if (radius != 0 &&
-          ! (junction & GTK_JUNCTION_RIGHT) &&
-          ! (junction & GTK_JUNCTION_BOTTOM))
+          ! (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
         {
           if ((sides & SIDE_RIGHT) == 0)
             cairo_new_sub_path (cr);
@@ -1221,8 +1421,7 @@ _cairo_round_rectangle_sides (cairo_t          *cr,
         cairo_move_to (cr, x + width, y + height);
 
       if (radius == 0 ||
-          (junction & GTK_JUNCTION_BOTTOM) ||
-          (junction & GTK_JUNCTION_LEFT))
+          (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
         cairo_line_to (cr, x, y + height);
       else
         cairo_arc (cr, x + radius, y + height - radius, radius, G_PI / 2, 3 * (G_PI / 4));
@@ -1233,8 +1432,7 @@ _cairo_round_rectangle_sides (cairo_t          *cr,
   if (sides & SIDE_LEFT)
     {
       if (radius != 0 &&
-          ! (junction & GTK_JUNCTION_LEFT) &&
-          ! (junction & GTK_JUNCTION_BOTTOM))
+          ! (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
         {
           if ((sides & SIDE_BOTTOM) == 0)
             cairo_new_sub_path (cr);
@@ -1245,8 +1443,7 @@ _cairo_round_rectangle_sides (cairo_t          *cr,
         cairo_move_to (cr, x, y + height);
 
       if (radius == 0 ||
-          (junction & GTK_JUNCTION_TOP) ||
-          (junction & GTK_JUNCTION_LEFT))
+          (junction & GTK_JUNCTION_CORNER_TOPLEFT))
         cairo_line_to (cr, x, y);
       else
         cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI + G_PI / 4);
@@ -1255,8 +1452,7 @@ _cairo_round_rectangle_sides (cairo_t          *cr,
   if (sides & SIDE_TOP)
     {
       if (radius != 0 &&
-          ! (junction & GTK_JUNCTION_TOP) &&
-          ! (junction & GTK_JUNCTION_LEFT))
+          ! (junction & GTK_JUNCTION_CORNER_TOPLEFT))
         {
           if ((sides & SIDE_LEFT) == 0)
             cairo_new_sub_path (cr);
@@ -1267,8 +1463,7 @@ _cairo_round_rectangle_sides (cairo_t          *cr,
         cairo_move_to (cr, x, y);
 
       if (radius == 0 ||
-          (junction & GTK_JUNCTION_TOP) ||
-          (junction & GTK_JUNCTION_RIGHT))
+          (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
         cairo_line_to (cr, x + width, y);
       else
         cairo_arc (cr, x + width - radius, y + radius, radius, 3 * (G_PI / 2), - G_PI / 4);
@@ -1276,55 +1471,31 @@ _cairo_round_rectangle_sides (cairo_t          *cr,
 }
 
 static void
-gtk_theming_engine_render_background (GtkThemingEngine *engine,
-                                      cairo_t          *cr,
-                                      gdouble           x,
-                                      gdouble           y,
-                                      gdouble           width,
-                                      gdouble           height)
+render_background_internal (GtkThemingEngine *engine,
+                            cairo_t          *cr,
+                            gdouble           x,
+                            gdouble           y,
+                            gdouble           width,
+                            gdouble           height,
+                            GtkJunctionSides  junction)
 {
   GdkRGBA *bg_color;
   cairo_pattern_t *pattern;
   GtkStateFlags flags;
   gboolean running;
   gdouble progress, alpha = 1;
-  GtkJunctionSides junction;
-  gint radius, border_width;
+  gint radius;
 
   flags = gtk_theming_engine_get_state (engine);
-  junction = gtk_theming_engine_get_junction_sides (engine);
   cairo_save (cr);
 
-  if (gtk_theming_engine_has_class (engine, "spinbutton") &&
-      gtk_theming_engine_has_class (engine, "button"))
-    {
-      x += 2;
-      y += 2;
-      width -= 4;
-      height -= 4;
-    }
-
   gtk_theming_engine_get (engine, flags,
                           "background-image", &pattern,
                           "background-color", &bg_color,
-                          "border-width", &border_width,
                           "border-radius", &radius,
                           NULL);
 
   running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
-
-  if (border_width > 0)
-    {
-      x += border_width;
-      y += border_width;
-      width -= 2 * border_width;
-      height -= 2 * border_width;
-      radius -= 2 * border_width;
-
-      if (radius < 0)
-        radius = 0;
-    }
-
   _cairo_round_rectangle_sides (cr, (gdouble) radius,
                                 x, y, width, height,
                                 SIDE_ALL, junction);
@@ -1494,8 +1665,8 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
           const GdkRGBA *color, *other_color;
 
           /* Merge just colors */
-         color = bg_color;
-         other_color = other_bg;
+          color = bg_color;
+          other_color = other_bg;
 
           new_pattern = cairo_pattern_create_rgba (CLAMP (color->red + ((other_color->red - color->red) * progress), 0, 1),
                                                    CLAMP (color->green + ((other_color->green - color->green) * progress), 0, 1),
@@ -1543,6 +1714,68 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
   gdk_rgba_free (bg_color);
 }
 
+static void
+gtk_theming_engine_render_background (GtkThemingEngine *engine,
+                                      cairo_t          *cr,
+                                      gdouble           x,
+                                      gdouble           y,
+                                      gdouble           width,
+                                      gdouble           height)
+{
+  GtkJunctionSides junction;
+  GtkStateFlags flags;
+  GtkBorder *border;
+
+  junction = gtk_theming_engine_get_junction_sides (engine);
+
+  if (gtk_theming_engine_has_class (engine, "spinbutton") &&
+      gtk_theming_engine_has_class (engine, "button"))
+    {
+      x += 2;
+      y += 2;
+      width -= 4;
+      height -= 4;
+    }
+
+  flags = gtk_theming_engine_get_state (engine);
+  gtk_theming_engine_get (engine, flags,
+                          "border-width", &border,
+                          NULL);
+
+  x += border->left;
+  y += border->top;
+  width -= border->left + border->right;
+  height -= border->top + border->bottom;
+
+  render_background_internal (engine, cr,
+                              x, y, width, height,
+                              junction);
+
+  gtk_border_free (border);
+}
+
+/* Renders the small triangle on corners so
+ * frames with 0 radius have a 3D-like effect
+ */
+static void
+_cairo_corner_triangle (cairo_t *cr,
+                        gdouble  x,
+                        gdouble  y,
+                        gint     size)
+{
+  gint i;
+
+  cairo_move_to (cr, x + 0.5, y + size - 0.5);
+  cairo_line_to (cr, x + size - 0.5, y + size - 0.5);
+  cairo_line_to (cr, x + size - 0.5, y + 0.5);
+
+  for (i = 1; i < size - 1; i++)
+    {
+      cairo_move_to (cr, x + size - 0.5, y + i + 0.5);
+      cairo_line_to (cr, x + (size - i) - 0.5, y + i + 0.5);
+    }
+}
+
 static void
 render_frame_internal (GtkThemingEngine *engine,
                        cairo_t          *cr,
@@ -1558,16 +1791,47 @@ render_frame_internal (GtkThemingEngine *engine,
   GdkRGBA *border_color;
   GtkBorderStyle border_style;
   gint border_width, radius;
-  gdouble d1, d2, m;
+  gdouble progress, d1, d2, m;
+  gboolean running;
+  GtkBorder *border;
 
   state = gtk_theming_engine_get_state (engine);
   gtk_theming_engine_get (engine, state,
                           "border-color", &border_color,
                           "border-style", &border_style,
-                          "border-width", &border_width,
+                          "border-width", &border,
                           "border-radius", &radius,
                           NULL);
 
+  running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
+  border_width = MIN (MIN (border->top, border->bottom),
+                      MIN (border->left, border->right));
+
+  if (running)
+    {
+      GtkStateFlags other_state;
+      GdkRGBA *other_color;
+
+      if (state & GTK_STATE_FLAG_PRELIGHT)
+        {
+          other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
+          progress = 1 - progress;
+        }
+      else
+        other_state = state | GTK_STATE_FLAG_PRELIGHT;
+
+      gtk_theming_engine_get (engine, other_state,
+                              "border-color", &other_color,
+                              NULL);
+
+      border_color->red = CLAMP (border_color->red + ((other_color->red - border_color->red) * progress), 0, 1);
+      border_color->green = CLAMP (border_color->green + ((other_color->green - border_color->green) * progress), 0, 1);
+      border_color->blue = CLAMP (border_color->blue + ((other_color->blue - border_color->blue) * progress), 0, 1);
+      border_color->alpha = CLAMP (border_color->alpha + ((other_color->alpha - border_color->alpha) * progress), 0, 1);
+
+      gdk_rgba_free (other_color);
+    }
+
   cairo_save (cr);
 
   color_shade (border_color, 1.8, &lighter);
@@ -1606,12 +1870,16 @@ render_frame_internal (GtkThemingEngine *engine,
     case GTK_BORDER_STYLE_INSET:
     case GTK_BORDER_STYLE_OUTSET:
       cairo_set_line_width (cr, border_width);
-      cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+
+      if (radius == 0)
+        cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+      else
+        cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
 
       if (border_width > 1)
         {
           d1 = (gdouble) border_width / 2;
-          d2 = (gdouble) (border_width - (gint) d1) + 1;
+          d2 = border_width;
         }
       else
         {
@@ -1624,22 +1892,6 @@ render_frame_internal (GtkThemingEngine *engine,
       m = MIN (width, height);
       m /= 2;
 
-      /* Only needed for square frames to have a 3D-like
-       * feeling, for rounded ones, the arc will ensure
-       * the stroke is painted to end at 45°.
-       */
-      if (radius == 0)
-        {
-          cairo_move_to (cr, x, y + height);
-          cairo_line_to (cr, x + m, y + height - m);
-          cairo_line_to (cr, x + width - m, y + m);
-          cairo_line_to (cr, x + width, y);
-          cairo_line_to (cr, x + width, y + height);
-          cairo_close_path (cr);
-
-          cairo_clip (cr);
-        }
-
       if (border_style == GTK_BORDER_STYLE_INSET)
         gdk_cairo_set_source_rgba (cr, &lighter);
       else
@@ -1652,22 +1904,6 @@ render_frame_internal (GtkThemingEngine *engine,
                                     junction);
       cairo_stroke (cr);
 
-      cairo_restore (cr);
-
-      cairo_save (cr);
-
-      if (radius == 0)
-        {
-          cairo_move_to (cr, x, y + height);
-          cairo_line_to (cr, x + m, y + height - m);
-          cairo_line_to (cr, x + width - m, y + m);
-          cairo_line_to (cr, x + width, y);
-          cairo_line_to (cr, x, y);
-          cairo_close_path (cr);
-
-          cairo_clip (cr);
-        }
-
       if (border_style == GTK_BORDER_STYLE_INSET)
         gdk_cairo_set_source_rgba (cr, border_color);
       else
@@ -1680,6 +1916,36 @@ render_frame_internal (GtkThemingEngine *engine,
                                     junction);
       cairo_stroke (cr);
 
+      if (border_width > 1)
+        {
+          /* overprint top/right and bottom/left corner
+           * triangles if there are square corners there,
+           * to give the box a 3D-like appearance.
+           */
+          cairo_save (cr);
+
+          if (border_style == GTK_BORDER_STYLE_INSET)
+            gdk_cairo_set_source_rgba (cr, &lighter);
+          else
+            gdk_cairo_set_source_rgba (cr, border_color);
+
+          cairo_set_line_width (cr, 1);
+
+          if (radius == 0 ||
+              (junction & GTK_JUNCTION_CORNER_TOPRIGHT) != 0)
+            _cairo_corner_triangle (cr,
+                                    x + width - border_width, y,
+                                    border_width);
+
+          if (radius == 0 ||
+              (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) != 0)
+            _cairo_corner_triangle (cr,
+                                    x, y + height - border_width,
+                                    border_width);
+          cairo_stroke (cr);
+          cairo_restore (cr);
+        }
+
       cairo_restore (cr);
       break;
     }
@@ -1688,6 +1954,8 @@ render_frame_internal (GtkThemingEngine *engine,
 
   if (border_color)
     gdk_rgba_free (border_color);
+
+  gtk_border_free (border);
 }
 
 static void
@@ -1713,8 +1981,8 @@ gtk_theming_engine_render_frame (GtkThemingEngine *engine,
 
   if (slice)
     {
-      gtk_9slice_render (slice, cr, x, y, width, height);
-      gtk_9slice_unref (slice);
+      _gtk_9slice_render (slice, cr, x, y, width, height);
+      _gtk_9slice_unref (slice);
     }
   else if (border_style != GTK_BORDER_STYLE_NONE)
     render_frame_internal (engine, cr,
@@ -1731,7 +1999,7 @@ gtk_theming_engine_render_expander (GtkThemingEngine *engine,
                                     gdouble           height)
 {
   GtkStateFlags flags;
-  GdkRGBA *bg_color, *fg_color;
+  GdkRGBA *outline_color, *fg_color;
   double vertical_overshoot;
   int diameter;
   double radius;
@@ -1741,29 +2009,43 @@ gtk_theming_engine_render_expander (GtkThemingEngine *engine,
   double x_double, y_double;
   gdouble angle;
   gint line_width;
+  gboolean running, is_rtl;
+  gdouble progress;
 
   cairo_save (cr);
   flags = gtk_theming_engine_get_state (engine);
 
   gtk_theming_engine_get (engine, flags,
                           "color", &fg_color,
-                          "background-color", &bg_color,
+                          NULL);
+  gtk_theming_engine_get (engine, flags,
+                          "border-color", &outline_color,
                           NULL);
 
+  running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
+  is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
   line_width = 1;
 
-  /* FIXME: LTR/RTL */
-  if (flags & GTK_STATE_FLAG_ACTIVE)
+  if (!running)
+    progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
+
+  if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_VERTICAL))
     {
-      angle = G_PI / 2;
-      interp = 1.0;
+      if (is_rtl)
+        angle = (G_PI) - ((G_PI / 2) * progress);
+      else
+        angle = (G_PI / 2) * progress;
     }
   else
     {
-      angle = 0;
-      interp = 0;
+      if (is_rtl)
+        angle = (G_PI / 2) + ((G_PI / 2) * progress);
+      else
+        angle = (G_PI / 2) - ((G_PI / 2) * progress);
     }
 
+  interp = progress;
+
   /* Compute distance that the stroke extends beyonds the end
    * of the triangle we draw.
    */
@@ -1817,13 +2099,13 @@ gtk_theming_engine_render_expander (GtkThemingEngine *engine,
 
   cairo_fill_preserve (cr);
 
-  gdk_cairo_set_source_rgba (cr, fg_color);
+  gdk_cairo_set_source_rgba (cr, outline_color);
   cairo_stroke (cr);
 
   cairo_restore (cr);
 
   gdk_rgba_free (fg_color);
-  gdk_rgba_free (bg_color);
+  gdk_rgba_free (outline_color);
 }
 
 static void
@@ -1985,6 +2267,8 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine,
   GdkRGBA *fg_color;
   GtkStateFlags flags;
   GdkScreen *screen;
+  gdouble progress;
+  gboolean running;
 
   cairo_save (cr);
   flags = gtk_theming_engine_get_state (engine);
@@ -1996,6 +2280,37 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine,
   screen = gtk_theming_engine_get_screen (engine);
   matrix = pango_context_get_matrix (pango_layout_get_context (layout));
 
+  running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
+
+  if (running)
+    {
+      GtkStateFlags other_flags;
+      GdkRGBA *other_fg;
+
+      if (flags & GTK_STATE_FLAG_PRELIGHT)
+        {
+          other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
+          progress = 1 - progress;
+        }
+      else
+        other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
+
+      gtk_theming_engine_get (engine, other_flags,
+                              "color", &other_fg,
+                              NULL);
+
+      if (fg_color && other_fg)
+        {
+          fg_color->red = CLAMP (fg_color->red + ((other_fg->red - fg_color->red) * progress), 0, 1);
+          fg_color->green = CLAMP (fg_color->green + ((other_fg->green - fg_color->green) * progress), 0, 1);
+          fg_color->blue = CLAMP (fg_color->blue + ((other_fg->blue - fg_color->blue) * progress), 0, 1);
+          fg_color->alpha = CLAMP (fg_color->alpha + ((other_fg->alpha - fg_color->alpha) * progress), 0, 1);
+        }
+
+      if (other_fg)
+        gdk_rgba_free (other_fg);
+    }
+
   if (matrix)
     {
       cairo_matrix_t cairo_matrix;
@@ -2018,13 +2333,13 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine,
       cairo_set_matrix (cr, &cairo_matrix);
     }
   else
-    cairo_translate (cr, x, y);
+    cairo_move_to (cr, x, y);
 
   if (flags & GTK_STATE_FLAG_INSENSITIVE)
     {
       cairo_save (cr);
       cairo_set_source_rgb (cr, 1, 1, 1);
-      cairo_move_to (cr, 1, 1);
+      cairo_move_to (cr, x + 1, y + 1);
       _gtk_pango_fill_layout (cr, layout);
       cairo_restore (cr);
     }
@@ -2085,73 +2400,94 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
                                      gdouble           xy0_gap,
                                      gdouble           xy1_gap)
 {
-  GtkJunctionSides junction = 0;
+  GtkJunctionSides junction;
   GtkStateFlags state;
-  gint border_width;
-  GdkRGBA *bg_color;
+  gint border_width, radius;
+  gdouble x0, y0, x1, y1, xc, yc, wc, hc;
+  GtkBorder *border;
 
+  xc = yc = wc = hc = 0;
   state = gtk_theming_engine_get_state (engine);
+  junction = gtk_theming_engine_get_junction_sides (engine);
   gtk_theming_engine_get (engine, state,
-                          "border-width", &border_width,
-                          "background-color", &bg_color,
+                          "border-width", &border,
+                          "border-radius", &radius,
                           NULL);
 
+  border_width = MIN (MIN (border->top, border->bottom),
+                      MIN (border->left, border->right));
+
   cairo_save (cr);
 
   switch (gap_side)
     {
     case GTK_POS_TOP:
-      junction = GTK_JUNCTION_TOP;
+      xc = x + xy0_gap + border_width;
+      yc = y;
+      wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
+      hc = border_width;
+
+      if (xy0_gap < radius)
+        junction |= GTK_JUNCTION_CORNER_TOPLEFT;
+
+      if (xy1_gap > width - radius)
+        junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
       break;
     case GTK_POS_BOTTOM:
-      junction = GTK_JUNCTION_BOTTOM;
+      xc = x + xy0_gap + border_width;
+      yc = y + height - border_width;
+      wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
+      hc = border_width;
+
+      if (xy0_gap < radius)
+        junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
+
+      if (xy1_gap > width - radius)
+        junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
+
       break;
     case GTK_POS_LEFT:
-      junction = GTK_JUNCTION_LEFT;
+      xc = x;
+      yc = y + xy0_gap + border_width;
+      wc = border_width;
+      hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
+
+      if (xy0_gap < radius)
+        junction |= GTK_JUNCTION_CORNER_TOPLEFT;
+
+      if (xy1_gap > height - radius)
+        junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
+
       break;
     case GTK_POS_RIGHT:
-      junction = GTK_JUNCTION_RIGHT;
+      xc = x + width - border_width;
+      yc = y + xy0_gap + border_width;
+      wc = border_width;
+      hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
+
+      if (xy0_gap < radius)
+        junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
+
+      if (xy1_gap > height - radius)
+        junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
+
       break;
     }
 
+  cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
+  cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
+  cairo_rectangle (cr, x0, yc, xc - x0, hc);
+  cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
+  cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
+  cairo_clip (cr);
+
   render_frame_internal (engine, cr,
                          x, y, width, height,
                          0, junction);
-  switch (gap_side)
-    {
-    case GTK_POS_TOP:
-      cairo_rectangle (cr,
-                       x + xy0_gap + border_width, y,
-                       xy1_gap - xy0_gap - 2 * border_width,
-                       border_width);
-      break;
-    case GTK_POS_BOTTOM:
-      cairo_rectangle (cr,
-                       x + xy0_gap + border_width,
-                       y + height - border_width,
-                       xy1_gap - xy0_gap - 2 * border_width,
-                       border_width);
-      break;
-    case GTK_POS_LEFT:
-      cairo_rectangle (cr,
-                       x, y + xy0_gap + border_width, border_width,
-                       xy1_gap - xy0_gap - 2 * border_width);
-      break;
-    case GTK_POS_RIGHT:
-      cairo_rectangle (cr,
-                       x + width - border_width,
-                       y + xy0_gap + border_width, border_width,
-                       xy1_gap - xy0_gap - 2 * border_width);
-      break;
-    }
-
-  gdk_cairo_set_source_rgba (cr, bg_color);
-  cairo_fill (cr);
 
   cairo_restore (cr);
 
-  if (bg_color)
-    gdk_rgba_free (bg_color);
+  gtk_border_free (border);
 }
 
 static void
@@ -2164,10 +2500,7 @@ gtk_theming_engine_render_extension (GtkThemingEngine *engine,
                                      GtkPositionType   gap_side)
 {
   GtkJunctionSides junction = 0;
-  GtkStateFlags state;
   guint hidden_side = 0;
-  GdkRGBA *bg_color;
-  gint radius;
 
   cairo_save (cr);
 
@@ -2176,41 +2509,50 @@ gtk_theming_engine_render_extension (GtkThemingEngine *engine,
     case GTK_POS_LEFT:
       junction = GTK_JUNCTION_LEFT;
       hidden_side = SIDE_LEFT;
+
+      cairo_translate (cr, x + width, y);
+      cairo_rotate (cr, G_PI / 2);
       break;
     case GTK_POS_RIGHT:
       junction = GTK_JUNCTION_RIGHT;
       hidden_side = SIDE_RIGHT;
+
+      cairo_translate (cr, x, y + height);
+      cairo_rotate (cr, - G_PI / 2);
       break;
     case GTK_POS_TOP:
       junction = GTK_JUNCTION_TOP;
       hidden_side = SIDE_TOP;
+
+      cairo_translate (cr, x + width, y + height);
+      cairo_rotate (cr, G_PI);
       break;
     case GTK_POS_BOTTOM:
       junction = GTK_JUNCTION_BOTTOM;
       hidden_side = SIDE_BOTTOM;
+
+      cairo_translate (cr, x, y);
       break;
     }
 
-  state = gtk_theming_engine_get_state (engine);
-  gtk_theming_engine_get (engine, state,
-                          "background-color", &bg_color,
-                          "border-radius", &radius,
-                          NULL);
+  if (gap_side == GTK_POS_TOP ||
+      gap_side == GTK_POS_BOTTOM)
+    render_background_internal (engine, cr,
+                                0, 0, width, height,
+                                GTK_JUNCTION_BOTTOM);
+  else
+    render_background_internal (engine, cr,
+                                0, 0, height, width,
+                                GTK_JUNCTION_BOTTOM);
+  cairo_restore (cr);
 
-  _cairo_round_rectangle_sides (cr, radius,
-                                x, y, width, height,
-                                SIDE_ALL, junction);
-  gdk_cairo_set_source_rgba (cr, bg_color);
-  cairo_fill (cr);
+  cairo_save (cr);
 
   render_frame_internal (engine, cr,
                          x, y, width, height,
                          hidden_side, junction);
 
   cairo_restore (cr);
-
-  if (bg_color)
-    gdk_rgba_free (bg_color);
 }
 
 static void
@@ -2272,7 +2614,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
   cairo_rectangle (cr, x, y, width, height);
   cairo_fill (cr);
 
-  if (gtk_theming_engine_has_class (engine, "grip"))
+  if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
     {
       GtkJunctionSides sides;
       gint skip = -1;
@@ -2283,14 +2625,14 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
       sides = gtk_theming_engine_get_junction_sides (engine);
 
       /* reduce confusing values to a meaningful state */
-      if (sides & (GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT))
-        sides &= ~(GTK_JUNCTION_LEFT);
+      if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
+        sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
 
-      if (sides & (GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM))
-        sides &= ~(GTK_JUNCTION_TOP);
+      if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
+        sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
 
       if (sides == 0)
-        sides = (GTK_JUNCTION_BOTTOM | GTK_JUNCTION_RIGHT);
+        sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
 
       /* align drawing area to the connected side */
       if (sides == GTK_JUNCTION_LEFT)
@@ -2298,7 +2640,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
           if (height < width)
             width = height;
         }
-      else if (sides & (GTK_JUNCTION_LEFT | GTK_JUNCTION_TOP))
+      else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
         {
           if (width < height)
             height = width;
@@ -2307,7 +2649,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
 
           skip = 2;
         }
-      else if (sides & (GTK_JUNCTION_LEFT | GTK_JUNCTION_BOTTOM))
+      else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
         {
           /* make it square, aligning to bottom left */
           if (width < height)
@@ -2320,7 +2662,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
 
           skip = 1;
         }
-      if (sides == GTK_JUNCTION_RIGHT)
+      else if (sides == GTK_JUNCTION_RIGHT)
         {
           /* aligning to right */
           if (height < width)
@@ -2329,7 +2671,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
               width = height;
             }
         }
-      else if (sides & (GTK_JUNCTION_RIGHT | GTK_JUNCTION_TOP))
+      else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
         {
           if (width < height)
             height = width;
@@ -2341,7 +2683,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
 
           skip = 3;
         }
-      else if (sides & (GTK_JUNCTION_RIGHT | GTK_JUNCTION_BOTTOM))
+      else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
         {
           /* make it square, aligning to bottom right */
           if (width < height)
@@ -2414,7 +2756,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
               yi+= 2;
             }
         }
-      else if (sides == (GTK_JUNCTION_TOP | GTK_JUNCTION_LEFT))
+      else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
         {
           gint xi, yi;
 
@@ -2444,7 +2786,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
               yi -= 3;
             }
         }
-      else if (sides == (GTK_JUNCTION_TOP | GTK_JUNCTION_RIGHT))
+      else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
         {
           gint xi, yi;
 
@@ -2474,7 +2816,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
               yi -= 3;
             }
         }
-      else if (sides == (GTK_JUNCTION_BOTTOM | GTK_JUNCTION_LEFT))
+      else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
         {
           gint xi, yi;
 
@@ -2504,7 +2846,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
               yi += 3;
             }
         }
-      else if (sides == (GTK_JUNCTION_BOTTOM | GTK_JUNCTION_RIGHT))
+      else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
         {
           gint xi, yi;
 
@@ -2537,7 +2879,7 @@ gtk_theming_engine_render_handle (GtkThemingEngine *engine,
 
       cairo_restore (cr);
     }
-  else if (gtk_theming_engine_has_class (engine, "paned"))
+  else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
     {
       if (width > height)
         for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
@@ -2569,7 +2911,7 @@ gtk_theming_engine_render_activity (GtkThemingEngine *engine,
                                     gdouble           width,
                                     gdouble           height)
 {
-  if (gtk_theming_engine_has_class (engine, "spinner"))
+  if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
     {
       GtkStateFlags state;
       guint num_steps, step;
@@ -2580,16 +2922,12 @@ gtk_theming_engine_render_activity (GtkThemingEngine *engine,
       gdouble half;
       gint i;
 
-      gtk_theming_engine_get_style (engine,
-                                    "num-steps", &num_steps,
-                                    NULL);
+      num_steps = 12;
 
       state = gtk_theming_engine_get_state (engine);
       gtk_theming_engine_get (engine, state,
                               "color", &color,
                               NULL);
-      if (num_steps == 0)
-        num_steps = 12;
 
       if (gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
         step = (guint) (progress * num_steps);