<commit_before>/*
 * Copyright © 2011 Red Hat Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: <NAME> <<EMAIL>>
 */

#include "config.h"

#include "gtkcsscustompropertyprivate.h"

#include <string.h>

#include "gtkcssstylefuncsprivate.h"
#include "gtkthemingengine.h"

G_DEFINE_TYPE (GtkCssCustomProperty, _gtk_css_custom_property, GTK_TYPE_CSS_STYLE_PROPERTY)

static gboolean
gtk_css_custom_property_parse_value (GtkStyleProperty *property,
                                     GValue           *value,
                                     GtkCssParser     *parser,
                                     GFile            *base)
{
  GtkCssCustomProperty *custom = GTK_CSS_CUSTOM_PROPERTY (property);
  gboolean success;

  if (custom->property_parse_func)
    {
      GError *error = NULL;
      char *value_str;
      
      g_value_init (value, _gtk_style_property_get_value_type (property));

      value_str = _gtk_css_parser_read_value (parser);
      if (value_str != NULL)
        {
          success = (* custom->property_parse_func) (value_str, value, &error);
          g_free (value_str);
        }
      else
        success = FALSE;
    }
  else
    {
      GtkCssStyleProperty *style = GTK_CSS_STYLE_PROPERTY (property);
      g_value_init (value, _gtk_css_style_property_get_specified_type (style));

      success = _gtk_css_style_parse_value (value, parser, base);
    }

  if (!success)
    g_value_unset (value);

  return success;
}

static void
_gtk_css_custom_property_class_init (GtkCssCustomPropertyClass *klass)
{
  GtkStylePropertyClass *property_class = GTK_STYLE_PROPERTY_CLASS (klass);

  property_class->parse_value = gtk_css_custom_property_parse_value;
}


static void
_gtk_css_custom_property_init (GtkCssCustomProperty *custom_property)
{
}

static GtkCssValue *
gtk_css_custom_property_create_initial_value (GParamSpec *pspec)
{
  GValue value = G_VALUE_INIT;

  g_value_init (&value, pspec->value_type);

  if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
    g_value_set_object (&value, gtk_theming_engine_load (NULL));
  else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
    g_value_take_boxed (&value, pango_font_description_from_string ("Sans 10"));
  else if (pspec->value_type == GDK_TYPE_RGBA)
    {
      GdkRGBA color;
      gdk_rgba_parse (&color, "pink");
      g_value_take_boxed (&value, &color);
    }
  else if (pspec->value_type == GDK_TYPE_COLOR)
    {
      GdkColor color;
      gdk_color_parse ("pink", &color);
      g_value_take_boxed (&value, &color);
    }
  else if (pspec->value_type == GTK_TYPE_BORDER)
    {
      g_value_take_boxed (&value, gtk_border_new ());
    }
  else
    g_param_value_set_default (pspec, &value);<commit_msg>customproperty: Fix thinko<commit_after>/*
 * Copyright © 2011 Red Hat Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: <NAME> <<EMAIL>>
 */

#include "config.h"

#include "gtkcsscustompropertyprivate.h"

#include <string.h>

#include "gtkcssstylefuncsprivate.h"
#include "gtkthemingengine.h"

G_DEFINE_TYPE (GtkCssCustomProperty, _gtk_css_custom_property, GTK_TYPE_CSS_STYLE_PROPERTY)

static gboolean
gtk_css_custom_property_parse_value (GtkStyleProperty *property,
                                     GValue           *value,
                                     GtkCssParser     *parser,
                                     GFile            *base)
{
  GtkCssCustomProperty *custom = GTK_CSS_CUSTOM_PROPERTY (property);
  gboolean success;

  if (custom->property_parse_func)
    {
      GError *error = NULL;
      char *value_str;
      
      g_value_init (value, _gtk_style_property_get_value_type (property));

      value_str = _gtk_css_parser_read_value (parser);
      if (value_str != NULL)
        {
          success = (* custom->property_parse_func) (value_str, value, &error);
          g_free (value_str);
        }
      else
        success = FALSE;
    }
  else
    {
      GtkCssStyleProperty *style = GTK_CSS_STYLE_PROPERTY (property);
      g_value_init (value, _gtk_css_style_property_get_specified_type (style));

      success = _gtk_css_style_parse_value (value, parser, base);
    }

  if (!success)
    g_value_unset (value);

  return success;
}

static void
_gtk_css_custom_property_class_init (GtkCssCustomPropertyClass *klass)
{
  GtkStylePropertyClass *property_class = GTK_STYLE_PROPERTY_CLASS (klass);

  property_class->parse_value = gtk_css_custom_property_parse_value;
}


static void
_gtk_css_custom_property_init (GtkCssCustomProperty *custom_property)
{
}

static GtkCssValue *
gtk_css_custom_property_create_initial_value (GParamSpec *pspec)
{
  GValue value = G_VALUE_INIT;

  g_value_init (&value, pspec->value_type);

  if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
    g_value_set_object (&value, gtk_theming_engine_load (NULL));
  else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
    g_value_take_boxed (&value, pango_font_description_from_string ("Sans 10"));
  else if (pspec->value_type == GDK_TYPE_RGBA)
    {
      GdkRGBA color;
      gdk_rgba_parse (&color, "pink");
      g_value_set_boxed (&value, &color);
    }
  else if (pspec->value_type == GDK_TYPE_COLOR)
    {
      GdkColor color;
      gdk_color_parse ("pink", &color);
      g_value_set_boxed (&value, &color);
    }
  else if (pspec->value_type == GTK_TYPE_BORDER)
    {
      g_value_take_boxed (&value, gtk_border_new ());
    }
  else
    g_param_value_set_default (pspec, &value);
{'fraction_non_alphanumeric': 0.08719630347294678, 'fraction_numerical': 0.002384856163362647, 'mean_word_length': 3.411571334648258, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3797957', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2165, 'n_words': 537}