Example #1
0
void
_gtk_style_cascade_add_provider (GtkStyleCascade  *cascade,
                                 GtkStyleProvider *provider,
                                 guint             priority)
{
  GtkStyleProviderData data;
  guint i;

  g_return_if_fail (GTK_IS_STYLE_CASCADE (cascade));
  g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
  g_return_if_fail (GTK_STYLE_PROVIDER (cascade) != provider);

  data.provider = g_object_ref (provider);
  data.priority = priority;
  data.changed_signal_id = g_signal_connect_swapped (provider,
                                                     "-gtk-private-changed",
                                                     G_CALLBACK (_gtk_style_provider_private_changed),
                                                     cascade);

  /* ensure it gets removed first */
  _gtk_style_cascade_remove_provider (cascade, provider);

  for (i = 0; i < cascade->providers->len; i++)
    {
      if (g_array_index (cascade->providers, GtkStyleProviderData, i).priority > priority)
        break;
    }
  g_array_insert_val (cascade->providers, i, data);

  _gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (cascade));
}
Example #2
0
cairo_pattern_t *
_gtk_gradient_resolve_full (GtkGradient             *gradient,
                            GtkStyleProviderPrivate *provider,
                            GtkCssComputedValues    *values,
                            GtkCssComputedValues    *parent_values,
                            GtkCssDependencies      *dependencies)
{
  cairo_pattern_t *pattern;
  guint i;

  g_return_val_if_fail (gradient != NULL, NULL);
  g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
  g_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);
  g_return_val_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values), NULL);
  g_return_val_if_fail (*dependencies == 0, NULL);

  if (gradient->radius0 == 0 && gradient->radius1 == 0)
    pattern = cairo_pattern_create_linear (gradient->x0, gradient->y0,
                                           gradient->x1, gradient->y1);
  else
    pattern = cairo_pattern_create_radial (gradient->x0, gradient->y0,
                                           gradient->radius0,
                                           gradient->x1, gradient->y1,
                                           gradient->radius1);

  for (i = 0; i < gradient->stops->len; i++)
    {
      ColorStop *stop;
      GtkCssValue *val;
      GdkRGBA rgba;
      GtkCssDependencies stop_deps;

      stop = &g_array_index (gradient->stops, ColorStop, i);

      /* if color resolving fails, assume transparency */
      val = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (stop->color),
                                          provider,
                                          _gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_COLOR),
                                          GTK_CSS_DEPENDS_ON_COLOR,
                                          &stop_deps,
                                          NULL);
      if (val)
        {
          rgba = *_gtk_css_rgba_value_get_rgba (val);
          *dependencies = _gtk_css_dependencies_union (*dependencies, stop_deps);
          _gtk_css_value_unref (val);
        }
      else
        {
          rgba.red = rgba.green = rgba.blue = rgba.alpha = 0.0;
        }

      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
                                         rgba.red, rgba.green,
                                         rgba.blue, rgba.alpha);
    }

  return pattern;
}
Example #3
0
/**
 * gtk_style_provider_get_style:
 * @provider: a #GtkStyleProvider
 * @path: #GtkWidgetPath to query
 *
 * Returns the style settings affecting a widget defined by @path, or %NULL if
 * @provider doesn't contemplate styling @path.
 *
 * Returns: (transfer full): a #GtkStyleProperties containing the
 * style settings affecting @path
 *
 * Since: 3.0
 *
 * Deprecated: 3.8: Will always return %NULL for all GTK-provided style providers
 *     as the interface cannot correctly work the way CSS is specified.
 **/
GtkStyleProperties *
gtk_style_provider_get_style (GtkStyleProvider *provider,
                              GtkWidgetPath    *path)
{
  GtkStyleProviderIface *iface;

  g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);

  iface = GTK_STYLE_PROVIDER_GET_IFACE (provider);

  if (!iface->get_style)
    return NULL;

  return iface->get_style (provider, path);
}
Example #4
0
/**
 * gtk_style_provider_get_icon_factory:
 * @provider: a #GtkStyleProvider
 * @path: #GtkWidgetPath to query
 *
 * Returns the #GtkIconFactory defined to be in use for @path, or %NULL if none
 * is defined.
 *
 * Returns: (transfer none): The icon factory to use for @path, or %NULL
 *
 * Since: 3.0
 *
 * Deprecated: 3.8: Will always return %NULL for all GTK-provided style providers.
 **/
GtkIconFactory *
gtk_style_provider_get_icon_factory (GtkStyleProvider *provider,
				     GtkWidgetPath    *path)
{
  GtkStyleProviderIface *iface;

  g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
  g_return_val_if_fail (path != NULL, NULL);

  iface = GTK_STYLE_PROVIDER_GET_IFACE (provider);

  if (!iface->get_icon_factory)
    return NULL;

  return iface->get_icon_factory (provider, path);
}
Example #5
0
void
_gtk_style_cascade_remove_provider (GtkStyleCascade  *cascade,
                                    GtkStyleProvider *provider)
{
  guint i;

  g_return_if_fail (GTK_IS_STYLE_CASCADE (cascade));
  g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));

  for (i = 0; i < cascade->providers->len; i++)
    {
      GtkStyleProviderData *data = &g_array_index (cascade->providers, GtkStyleProviderData, i);

      if (data->provider == provider)
        {
          g_array_remove_index (cascade->providers, i);
  
          _gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (cascade));
          break;
        }
    }
}
Example #6
0
/**
 * gtk_style_provider_get_style_property:
 * @provider: a #GtkStyleProvider
 * @path: #GtkWidgetPath to query
 * @state: state to query the style property for
 * @pspec: The #GParamSpec to query
 * @value: (out): return location for the property value
 *
 * Looks up a widget style property as defined by @provider for
 * the widget represented by @path.
 *
 * Returns: %TRUE if the property was found and has a value, %FALSE otherwise
 *
 * Since: 3.0
 **/
gboolean
gtk_style_provider_get_style_property (GtkStyleProvider *provider,
                                       GtkWidgetPath    *path,
                                       GtkStateFlags     state,
                                       GParamSpec       *pspec,
                                       GValue           *value)
{
  GtkStyleProviderIface *iface;

  g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), FALSE);
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
  g_return_val_if_fail (path != NULL, FALSE);
  g_return_val_if_fail (g_type_is_a (gtk_widget_path_get_object_type (path), pspec->owner_type), FALSE);
  g_return_val_if_fail (value != NULL, FALSE);

  iface = GTK_STYLE_PROVIDER_GET_IFACE (provider);

  if (!iface->get_style_property)
    return FALSE;

  return iface->get_style_property (provider, path, state, pspec, value);
}
Example #7
0
GtkCssStyle *
gtk_css_animated_style_new (GtkCssStyle             *base_style,
                            GtkCssStyle             *parent_style,
                            gint64                   timestamp,
                            GtkStyleProviderPrivate *provider,
                            GtkCssStyle             *previous_style)
{
  GtkCssAnimatedStyle *result;
  GSList *animations;
  
  gtk_internal_return_val_if_fail (GTK_IS_CSS_STYLE (base_style), NULL);
  gtk_internal_return_val_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style), NULL);
  gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
  gtk_internal_return_val_if_fail (previous_style == NULL || GTK_IS_CSS_STYLE (previous_style), NULL);

  if (timestamp == 0)
    return g_object_ref (base_style);

  animations = NULL;

  if (previous_style != NULL)
    animations = gtk_css_animated_style_create_css_transitions (animations, base_style, timestamp, previous_style);
  animations = gtk_css_animated_style_create_css_animations (animations, base_style, parent_style, timestamp, provider, previous_style);

  if (animations == NULL)
    return g_object_ref (base_style);

  result = g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL);

  result->style = g_object_ref (base_style);
  result->current_time = timestamp;
  result->animations = animations;

  gtk_css_animated_style_apply_animations (result);

  return GTK_CSS_STYLE (result);
}