Esempio n. 1
0
void
gtk_css_computed_values_print (GtkCssComputedValues *values,
                               GString              *string)
{
  guint i;

  g_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
  g_return_if_fail (string != NULL);

  for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
    {
      GtkCssSection *section = _gtk_css_computed_values_get_section (values, i);
      g_string_append (string, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (i))));
      g_string_append (string, ": ");
      _gtk_css_value_print (_gtk_css_computed_values_get_value (values, i), string);
      g_string_append (string, ";");
      if (section)
        {
          g_string_append (string, " /* ");
          _gtk_css_section_print (section, string);
          g_string_append (string, " */");
        }
      g_string_append (string, "\n");
    }
}
Esempio n. 2
0
void
gtk_css_style_print (GtkCssStyle *style,
                     GString     *string)
{
  guint i;

  g_return_if_fail (GTK_IS_CSS_STYLE (style));
  g_return_if_fail (string != NULL);

  for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
    {
      GtkCssSection *section = gtk_css_style_get_section (style, i);
      g_string_append (string, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (i))));
      g_string_append (string, ": ");
      _gtk_css_value_print (gtk_css_style_get_value (style, i), string);
      g_string_append (string, ";");
      if (section)
        {
          g_string_append (string, " /* ");
          _gtk_css_section_print (section, string);
          g_string_append (string, " */");
        }
      g_string_append (string, "\n");
    }
}
Esempio n. 3
0
static GtkCssValue *
gtk_css_value_initial_compute (GtkCssValue             *value,
                               guint                    property_id,
                               GtkStyleProviderPrivate *provider,
                               GtkCssStyle             *style,
                               GtkCssStyle             *parent_style)
{
  GtkSettings *settings;

  switch (property_id)
    {
    case GTK_CSS_PROPERTY_DPI:
      settings = _gtk_style_provider_private_get_settings (provider);
      if (settings)
        {
          GdkScreen *screen = _gtk_settings_get_screen (settings);
          double resolution = gdk_screen_get_resolution (screen);

          if (resolution > 0.0)
            return _gtk_css_number_value_new (resolution, GTK_CSS_NUMBER);
        }
      break;

    case GTK_CSS_PROPERTY_FONT_FAMILY:
      settings = _gtk_style_provider_private_get_settings (provider);
      if (settings)
        {
          PangoFontDescription *description;
          char *font_name;
          GtkCssValue *value;

          g_object_get (settings, "gtk-font-name", &font_name, NULL);
          description = pango_font_description_from_string (font_name);
          g_free (font_name);
          if (description == NULL)
            break;

          if (pango_font_description_get_set_fields (description) & PANGO_FONT_MASK_FAMILY)
            {
              value = _gtk_css_array_value_new (_gtk_css_string_value_new (pango_font_description_get_family (description)));
              pango_font_description_free (description);
              return value;
            }
 
          pango_font_description_free (description);
        }
      break;

    default:
      break;
    }

  return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
                                 property_id,
                                 provider,
                                 style,
                                 parent_style);
}
Esempio n. 4
0
static void
transition_info_add (TransitionInfo    infos[GTK_CSS_PROPERTY_N_PROPERTIES],
                     GtkStyleProperty *property,
                     guint             index)
{
    if (property == NULL)
    {
        guint i;

        for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
        {
            GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (i);

            transition_info_add (infos, GTK_STYLE_PROPERTY (prop), index);
        }
    }
    else if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
    {
        GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
        guint i;

        for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
        {
            GtkCssStyleProperty *prop = _gtk_css_shorthand_property_get_subproperty (shorthand, i);

            transition_info_add (infos, GTK_STYLE_PROPERTY (prop), index);
        }
    }
    else if (GTK_IS_CSS_STYLE_PROPERTY (property))
    {
        guint id;

        if (!_gtk_css_style_property_is_animated (GTK_CSS_STYLE_PROPERTY (property)))
            return;

        id = _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (property));
        g_assert (id < GTK_CSS_PROPERTY_N_PROPERTIES);
        infos[id].index = index;
        infos[id].pending = TRUE;
    }
    else
    {
        g_assert_not_reached ();
    }
}
Esempio n. 5
0
/*
 * gtk_css_style_print:
 * @style: a #GtkCssStyle
 * @string: the #GString to print to
 * @indent: level of indentation to use
 * @skip_initial: %TRUE to skip properties that have their initial value
 *
 * Print the @style to @string, in CSS format. Every property is printed
 * on a line by itself, indented by @indent spaces. If @skip_initial is
 * %TRUE, properties are only printed if their value in @style is different
 * from the initial value of the property.
 *
 * Returns: %TRUE is any properties have been printed
 */
gboolean
gtk_css_style_print (GtkCssStyle *style,
                     GString     *string,
                     guint        indent,
                     gboolean     skip_initial)
{
    guint i;
    gboolean retval = FALSE;

    g_return_val_if_fail (GTK_IS_CSS_STYLE (style), FALSE);
    g_return_val_if_fail (string != NULL, FALSE);

    for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
    {
        GtkCssSection *section;
        GtkCssStyleProperty *prop;
        GtkCssValue *value;
        const char *name;

        section = gtk_css_style_get_section (style, i);
        if (!section && skip_initial)
            continue;

        prop = _gtk_css_style_property_lookup_by_id (i);
        name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
        value = gtk_css_style_get_value (style, i);

        g_string_append_printf (string, "%*s%s: ", indent, "", name);
        _gtk_css_value_print (value, string);
        g_string_append_c (string, ';');

        if (section)
        {
            g_string_append (string, " /* ");
            _gtk_css_section_print (section, string);
            g_string_append (string, " */");
        }

        g_string_append_c (string, '\n');

        retval = TRUE;
    }

    return retval;
}
Esempio n. 6
0
/**
 * _gtk_css_style_property_get_mask_affecting:
 * @flags: the flags that are affected
 *
 * Computes a bitmask for all properties that have at least one of @flags
 * set.
 *
 * Returns: (transfer full): A #GtkBitmask with the bit set for every
 *          property that has at least one of @flags set.
 */
GtkBitmask *
_gtk_css_style_property_get_mask_affecting (GtkCssAffects affects)
{
  GtkBitmask *result;
  guint i;

  result = _gtk_bitmask_new ();

  for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
    {
      GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (i);

      if (_gtk_css_style_property_get_affects (prop) & affects)
        result = _gtk_bitmask_set (result, i, TRUE);
    }

  return result;
}
Esempio n. 7
0
void
_gtk_css_computed_values_compute_value (GtkCssComputedValues    *values,
                                        GtkStyleProviderPrivate *provider,
                                        GtkCssComputedValues    *parent_values,
                                        guint                    id,
                                        GtkCssValue             *specified,
                                        GtkCssSection           *section)
{
    GtkCssDependencies dependencies;
    GtkCssValue *value;

    gtk_internal_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
    gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
    gtk_internal_return_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values));

    /* http://www.w3.org/TR/css3-cascade/#cascade
     * Then, for every element, the value for each property can be found
     * by following this pseudo-algorithm:
     * 1) Identify all declarations that apply to the element
     */
    if (specified == NULL)
    {
        GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (id);

        if (_gtk_css_style_property_is_inherit (prop))
            specified = _gtk_css_inherit_value_new ();
        else
            specified = _gtk_css_initial_value_new ();
    }
    else
        _gtk_css_value_ref (specified);

    value = _gtk_css_value_compute (specified, id, provider, values, parent_values, &dependencies);

    _gtk_css_computed_values_set_value (values, id, value, dependencies, section);

    _gtk_css_value_unref (value);
    _gtk_css_value_unref (specified);
}
Esempio n. 8
0
static GtkCssValue *
gtk_css_value_unset_compute (GtkCssValue             *value,
                             guint                    property_id,
                             GtkStyleProviderPrivate *provider,
                             GtkCssStyle             *style,
                             GtkCssStyle             *parent_style)
{
    GtkCssStyleProperty *property;
    GtkCssValue *unset_value;

    property = _gtk_css_style_property_lookup_by_id (property_id);

    if (_gtk_css_style_property_is_inherit (property))
        unset_value = _gtk_css_inherit_value_get ();
    else
        unset_value = _gtk_css_initial_value_get ();

    return _gtk_css_value_compute (unset_value,
                                   property_id,
                                   provider,
                                   style,
                                   parent_style);
}
Esempio n. 9
0
void
_gtk_css_computed_values_compute_value (GtkCssComputedValues    *values,
                                        GtkStyleProviderPrivate *provider,
					int                      scale,
                                        GtkCssComputedValues    *parent_values,
                                        guint                    id,
                                        GtkCssValue             *specified,
                                        GtkCssSection           *section)
{
  GtkCssDependencies dependencies;
  GtkCssValue *value;

  gtk_internal_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
  gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
  gtk_internal_return_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values));

  /* http://www.w3.org/TR/css3-cascade/#cascade
   * Then, for every element, the value for each property can be found
   * by following this pseudo-algorithm:
   * 1) Identify all declarations that apply to the element
   */
  if (specified == NULL)
    {
      GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (id);

      if (_gtk_css_style_property_is_inherit (prop))
        specified = _gtk_css_inherit_value_new ();
      else
        specified = _gtk_css_initial_value_new ();
    }
  else
    _gtk_css_value_ref (specified);

  value = _gtk_css_value_compute (specified, id, provider, scale, values, parent_values, &dependencies);

  if (values->values == NULL)
    values->values = g_ptr_array_new_full (_gtk_css_style_property_get_n_properties (),
					   (GDestroyNotify)_gtk_css_value_unref);
  if (id >= values->values->len)
   g_ptr_array_set_size (values->values, id + 1);

  if (g_ptr_array_index (values->values, id))
    _gtk_css_value_unref (g_ptr_array_index (values->values, id));
  g_ptr_array_index (values->values, id) = _gtk_css_value_ref (value);

  if (dependencies & (GTK_CSS_DEPENDS_ON_PARENT | GTK_CSS_EQUALS_PARENT))
    values->depends_on_parent = _gtk_bitmask_set (values->depends_on_parent, id, TRUE);
  if (dependencies & (GTK_CSS_EQUALS_PARENT))
    values->equals_parent = _gtk_bitmask_set (values->equals_parent, id, TRUE);
  if (dependencies & (GTK_CSS_DEPENDS_ON_COLOR))
    values->depends_on_color = _gtk_bitmask_set (values->depends_on_color, id, TRUE);
  if (dependencies & (GTK_CSS_DEPENDS_ON_FONT_SIZE))
    values->depends_on_font_size = _gtk_bitmask_set (values->depends_on_font_size, id, TRUE);

  if (values->sections && values->sections->len > id && g_ptr_array_index (values->sections, id))
    {
      gtk_css_section_unref (g_ptr_array_index (values->sections, id));
      g_ptr_array_index (values->sections, id) = NULL;
    }

  if (section)
    {
      if (values->sections == NULL)
        values->sections = g_ptr_array_new_with_free_func (maybe_unref_section);
      if (values->sections->len <= id)
        g_ptr_array_set_size (values->sections, id + 1);

      g_ptr_array_index (values->sections, id) = gtk_css_section_ref (section);
    }

  _gtk_css_value_unref (value);
  _gtk_css_value_unref (specified);
}