]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkthemingengine.c
Make GtkToolItemGroup use GtkStyleContext
[~andy/gtk] / gtk / gtkthemingengine.c
index 124ee51d860797abe95cad38f895089cda532b31..4dc889c00eb1c063027c999f149257d705932c15 100644 (file)
@@ -542,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
@@ -712,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
@@ -726,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) ||
@@ -747,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;
@@ -1305,8 +1484,7 @@ render_background_internal (GtkThemingEngine *engine,
   GtkStateFlags flags;
   gboolean running;
   gdouble progress, alpha = 1;
-  gint radius, border_width;
-  GtkBorder *border;
+  gint radius;
 
   flags = gtk_theming_engine_get_state (engine);
   cairo_save (cr);
@@ -1314,14 +1492,10 @@ render_background_internal (GtkThemingEngine *engine,
   gtk_theming_engine_get (engine, flags,
                           "background-image", &pattern,
                           "background-color", &bg_color,
-                          "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));
-
   _cairo_round_rectangle_sides (cr, (gdouble) radius,
                                 x, y, width, height,
                                 SIDE_ALL, junction);
@@ -1538,7 +1712,6 @@ render_background_internal (GtkThemingEngine *engine,
   cairo_restore (cr);
 
   gdk_rgba_free (bg_color);
-  gtk_border_free (border);
 }
 
 static void
@@ -1808,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,
@@ -1836,6 +2009,8 @@ 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);
@@ -1843,24 +2018,34 @@ gtk_theming_engine_render_expander (GtkThemingEngine *engine,
   gtk_theming_engine_get (engine, flags,
                           "color", &fg_color,
                           NULL);
-  gtk_theming_engine_get (engine, 0,
-                          "color", &outline_color,
+  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.
    */
@@ -2114,12 +2299,16 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine,
                               "color", &other_fg,
                               NULL);
 
-      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 (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);
+        }
 
-      gdk_rgba_free (other_fg);
+      if (other_fg)
+        gdk_rgba_free (other_fg);
     }
 
   if (matrix)
@@ -2144,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);
     }
@@ -2350,12 +2539,11 @@ gtk_theming_engine_render_extension (GtkThemingEngine *engine,
       gap_side == GTK_POS_BOTTOM)
     render_background_internal (engine, cr,
                                 0, 0, width, height,
-                                junction);
+                                GTK_JUNCTION_BOTTOM);
   else
     render_background_internal (engine, cr,
                                 0, 0, height, width,
-                                junction);
-
+                                GTK_JUNCTION_BOTTOM);
   cairo_restore (cr);
 
   cairo_save (cr);
@@ -2426,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;
@@ -2691,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)
@@ -2734,18 +2922,12 @@ gtk_theming_engine_render_activity (GtkThemingEngine *engine,
       gdouble half;
       gint i;
 
-      num_steps = 0;
-
-      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);