<commit_before>/*
 * Copyright (C) 2007, Red Hat, Inc.
 * Copyright (C) 2007, <NAME>
 *
 * 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 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, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <string.h>
#include <gdk/gdkdrawable.h>

#include "sugar-style.h"
#include "sugar-rc-style.h"
#include "sugar-info.h"
#include "sugar-drawing.h"

#define SANTIZE_SIZE g_assert (width >= -1 && height >= -1);    \
    if (width == -1 && height == -1) {                          \
        gdk_drawable_get_size (GDK_DRAWABLE (window), &width, &height);          \
    } else if (width == -1) {                                   \
        gdk_drawable_get_size (GDK_DRAWABLE (window), &width, NULL);             \
    } else if (height == -1) {                                  \
        gdk_drawable_get_size (GDK_DRAWABLE (window), NULL, &height);            \
    }

#define HINT(str) (SUGAR_RC_STYLE (style->rc_style)->hint && g_str_equal (SUGAR_RC_STYLE (style->rc_style)->hint, str))
#define DETAIL(str) (detail && g_str_equal (detail, str))


static void sugar_style_init       (SugarStyle      *style);
static void sugar_style_class_init (SugarStyleClass *klass);

GType sugar_type_style = 0;

static GtkStyleClass *parent_class;

void
sugar_style_register_type (GTypeModule *module)
{
    static const GTypeInfo object_info =
    {
        sizeof (SugarStyleClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) sugar_style_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (SugarStyle),
        0,              /* n_preallocs */
        (GInstanceInitFunc) sugar_style_init,
    };
  
    sugar_type_style = g_type_module_register_type (module,
						                            GTK_TYPE_STYLE,
						                            "SugarStyle",
						                            &object_info, 0);
}

static void
sugar_style_init (SugarStyle *style)
{
}

static cairo_t*
sugar_cairo_create (GdkWindow *window, GdkRectangle *area)
{
	cairo_t *cr;
	
	cr = gdk_cairo_create (GDK_DRAWABLE (window));
	
	if (area) {
		gdk_cairo_rectangle (cr, area);
		cairo_clip (cr);
	}
	return cr;
}

static void
sugar_style_draw_focus (GtkStyle       *style,
                       GdkWindow      *window,
                       GtkStateType    state_type,
                       GdkRectangle   *area,
                       GtkWidget      *widget,
                       const gchar    *detail,
                       gint            x,
                       gint            y,
                       gint            width,
                       gint            height)
{
	SugarInfo info;
	cairo_t *cr;
	gboolean interior_focus = TRUE;

	sugar_fill_generic_info (&info, style, state_type, GTK_SHADOW_NONE, widget, detail, x, y, width, height);
	sugar_info_get_style_property (&info, "interior-focus", &interior_focus);

	if (!interior_focus) {
		cr = sugar_cairo_create (window, area);

		if (HINT ("comboboxentry")) {
			if (DETAIL ("button")) {
				sugar_info_remove_corners (&info, SIDE_LEFT);
			} else {
				sugar_info_remove_corners (&info, SIDE_RIGHT);
			}
		}
		if (DETAIL ("entry") && HINT ("spinbutton")) {
			/* We need to fake the focus on the button separately. */
			sugar_info_remove_corners (&info, SIDE_RIGHT);
			info.pos.width += info.rc_style->thick_line_width;
			if (!info.ltr)
				info.pos.x -= info.rc_style->thick_line_width;
		}
		if (DETAIL ("spinbutton_up") || DETAIL ("spinbutton_down")) {
			/* spinbutton button focus hack -- this gets called from draw_box */

			gdk_cairo_rectangle (cr, &info.pos);
			cairo_clip (cr);

			/* duplicated from draw_box */
			if (DETAIL ("spinbutton_up")) {
				info.corners = info.ltr ? CORNER_TOPRIGHT : CORNER_TOPRIGHT;
				info.pos.height += info.rc_style->thick_line_width;
			} else {
				info.corners = info.ltr ? CORNER_BOTTOMRIGHT : CORNER_BOTTOMRIGHT;
				info.pos.y -= info.rc_style->thick_line_width;
				info.pos.height += info.rc_style->thick_line_width;
			}

			info.pos.width += info.rc_style->thick_line_width;
			if (info.ltr)
				info.pos.x -= info.rc_style->thick_line_width;
		}
		if (DETAIL ("trough")) {
			/* Must be scale?!? */
			SugarRangeInfo range_info;

			/* This will decrease the size of the focus as neccessary. */
			range_info.info = info;
			sugar_fill_range_info (&range_info, TRUE);
			info = range_info.info;
		}

		sugar_draw_exterior_focus (cr, &info);
		cairo_destroy (cr);
	} else {
		parent_class->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
	}
}

static void
sugar_style_draw_slider (GtkStyle       *style,
                        GdkWindow      *window,
                        GtkStateType    state_type,
                        GtkShadowType   shadow_type,
                        GdkRectangle   *area,
                        GtkWidget      *widget,
                        const gchar    *detail,
                        gint            x,
                        gint            y,
                        gint            width,
                        gint            height,
                        GtkOrientation  orientation)
{
	cairo_t *cr;

	SANTIZE_SIZE
	<commit_msg>Force the state to be normal for the scale focus.<commit_after>/*
 * Copyright (C) 2007, Red Hat, Inc.
 * Copyright (C) 2007, <NAME>
 *
 * 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 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, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <string.h>
#include <gdk/gdkdrawable.h>

#include "sugar-style.h"
#include "sugar-rc-style.h"
#include "sugar-info.h"
#include "sugar-drawing.h"

#define SANTIZE_SIZE g_assert (width >= -1 && height >= -1);    \
    if (width == -1 && height == -1) {                          \
        gdk_drawable_get_size (GDK_DRAWABLE (window), &width, &height);          \
    } else if (width == -1) {                                   \
        gdk_drawable_get_size (GDK_DRAWABLE (window), &width, NULL);             \
    } else if (height == -1) {                                  \
        gdk_drawable_get_size (GDK_DRAWABLE (window), NULL, &height);            \
    }

#define HINT(str) (SUGAR_RC_STYLE (style->rc_style)->hint && g_str_equal (SUGAR_RC_STYLE (style->rc_style)->hint, str))
#define DETAIL(str) (detail && g_str_equal (detail, str))


static void sugar_style_init       (SugarStyle      *style);
static void sugar_style_class_init (SugarStyleClass *klass);

GType sugar_type_style = 0;

static GtkStyleClass *parent_class;

void
sugar_style_register_type (GTypeModule *module)
{
    static const GTypeInfo object_info =
    {
        sizeof (SugarStyleClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) sugar_style_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (SugarStyle),
        0,              /* n_preallocs */
        (GInstanceInitFunc) sugar_style_init,
    };
  
    sugar_type_style = g_type_module_register_type (module,
						                            GTK_TYPE_STYLE,
						                            "SugarStyle",
						                            &object_info, 0);
}

static void
sugar_style_init (SugarStyle *style)
{
}

static cairo_t*
sugar_cairo_create (GdkWindow *window, GdkRectangle *area)
{
	cairo_t *cr;
	
	cr = gdk_cairo_create (GDK_DRAWABLE (window));
	
	if (area) {
		gdk_cairo_rectangle (cr, area);
		cairo_clip (cr);
	}
	return cr;
}

static void
sugar_style_draw_focus (GtkStyle       *style,
                       GdkWindow      *window,
                       GtkStateType    state_type,
                       GdkRectangle   *area,
                       GtkWidget      *widget,
                       const gchar    *detail,
                       gint            x,
                       gint            y,
                       gint            width,
                       gint            height)
{
	SugarInfo info;
	cairo_t *cr;
	gboolean interior_focus = TRUE;

	sugar_fill_generic_info (&info, style, state_type, GTK_SHADOW_NONE, widget, detail, x, y, width, height);
	sugar_info_get_style_property (&info, "interior-focus", &interior_focus);

	if (!interior_focus) {
		cr = sugar_cairo_create (window, area);

		if (HINT ("comboboxentry")) {
			if (DETAIL ("button")) {
				sugar_info_remove_corners (&info, SIDE_LEFT);
			} else {
				sugar_info_remove_corners (&info, SIDE_RIGHT);
			}
		}
		if (DETAIL ("entry") && HINT ("spinbutton")) {
			/* We need to fake the focus on the button separately. */
			sugar_info_remove_corners (&info, SIDE_RIGHT);
			info.pos.width += info.rc_style->thick_line_width;
			if (!info.ltr)
				info.pos.x -= info.rc_style->thick_line_width;
		}
		if (DETAIL ("spinbutton_up") || DETAIL ("spinbutton_down")) {
			/* spinbutton button focus hack -- this gets called from draw_box */

			gdk_cairo_rectangle (cr, &info.pos);
			cairo_clip (cr);

			/* duplicated from draw_box */
			if (DETAIL ("spinbutton_up")) {
				info.corners = info.ltr ? CORNER_TOPRIGHT : CORNER_TOPRIGHT;
				info.pos.height += info.rc_style->thick_line_width;
			} else {
				info.corners = info.ltr ? CORNER_BOTTOMRIGHT : CORNER_BOTTOMRIGHT;
				info.pos.y -= info.rc_style->thick_line_width;
				info.pos.height += info.rc_style->thick_line_width;
			}

			info.pos.width += info.rc_style->thick_line_width;
			if (info.ltr)
				info.pos.x -= info.rc_style->thick_line_width;
		}
		if (DETAIL ("trough")) {
			/* Must be scale?!? */
			SugarRangeInfo range_info;

			/* This will decrease the size of the focus as neccessary. */
			range_info.info = info;
			sugar_fill_range_info (&range_info, TRUE);
			info = range_info.info;

			info.state = GTK_STATE_NORMAL;
		}

		sugar_draw_exterior_focus (cr, &info);
		cairo_destroy (cr);
	} else {
		parent_class->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
	}
}

static void
sugar_style_draw_slider (GtkStyle       *style,
                        GdkWindow      *window,
                        GtkStateType    state_type,
                        GtkShadowType   shadow_type,
                        GdkRectangle   *area,
                        GtkWidget      *widget,
                        const gchar    *detail,
                        gint            x,
                        gint            y,
                        gint            width,
                        gint            height,
                        GtkOrientation  orientation)
{
	cairo_t *cr;

	SANTIZE_SIZE
	
{'fraction_non_alphanumeric': 0.10016100330480468, 'fraction_numerical': 0.005423269214473349, 'mean_word_length': 2.1000788022064616, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4116837', 'n_tokens_mistral': 4072, 'n_tokens_neox': 3680, 'n_words': 955}