<commit_before>/*
* this file is part of the oxygen gtk engine
* Copyright (c) 2010 <NAME> <<EMAIL>>
* Copyright (c) 2010 <NAME> <<EMAIL>>
*
* based on the Null Theme Engine for Gtk+.
* Copyright (c) 2008 <NAME> <<EMAIL>>
*
* Icon rendering code from Walmis
* <http://gnome-look.org/content/show.php?content=77783&forumpage=3>
*
* 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., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/

#include "oxygenstylewrapper.h"

#include "config.h"

#include "oxygen.h"
#include "oxygenanimations.h"
#include "oxygencairoutils.h"
#include "oxygengtkcellinfo.h"
#include "oxygengtkdetails.h"
#include "oxygengtktypenames.h"
#include "oxygengtkutils.h"
#include "oxygenrcstyle.h"
#include "oxygenstyle.h"

#include <iostream>

//_______________________________________________________________________________________________________________
struct _OxygenStyle
{ GtkStyle parent; };

//_______________________________________________________________________________________________________________
struct _OxygenStyleClass
{  GtkStyleClass parent; };

//_______________________________________________________________________________________________________________
static GtkStyleClass* oxygen_style_parent_class = 0L;

namespace Oxygen
{

    //___________________________________________________________________________________________________________
    static void draw_flat_box(
        GtkStyle* style,
        GdkWindow* window,
        GtkStateType state,
        GtkShadowType shadow,
        GdkRectangle* clipRect,
        GtkWidget* widget,
        const char* detail,
        gint x,
        gint y,
        gint w,
        gint h )
    {
        g_return_if_fail( style && window );
        Style::instance().sanitizeSize( window, w, h );

        #if OXYGEN_DEBUG
        g_log( OXYGEN_LOG_DOMAIN, G_LOG_LEVEL_INFO,
            "widget=%s, primitive=flat_box, state=%s, shadow=%s, detail=%s",
            G_OBJECT_TYPE_NAME( widget ),
            Gtk::TypeNames::state( state ),
            Gtk::TypeNames::shadow( shadow ),
            detail );
        #endif

        const Gtk::Detail d( detail );
        bool accepted( false );
        if( d.isBase() || d.isEventBox())
        {

            if( GTK_IS_WINDOW( widget ) )
            {

                Style::instance().animations().mainWindowEngine().registerWidget( widget );

            } else if( GtkWidget* parent = Gtk::gtk_parent_scrolled_window( widget ) ) {

                Style::instance().animations().scrollBarEngine().registerScrolledWindow( parent );

            }

            Style::instance().renderWindowBackground( window, clipRect, x, y, w, h );
            return;

        } else if( d.isViewportBin() ) {

            GdkColor bg=style->bg[state];
            GdkColor defbg=gtk_widget_get_default_style()->bg[state];

            // This dirty hack with 10000 makes GIMP bottom element viewportbin have correct window color
            // while ccsm options list will remain white. Hope this will work as intended for other apps
            // FIXME: why default style bg isn't the same as unchanged(?) bg in GIMP? If it were, no hack would be needed
            if(
                bg.red/10000==defbg.red/10000 &&
                bg.green/10000==defbg.green/10000 &&
                bg.blue/10000==defbg.blue/10000)
            {

                // make sure that widget is registered to scrolledBarEngine,
                // so that background gets updated properly
                if( GtkWidget* parent = Gtk::gtk_parent_scrolled_window( widget ) )
                { Style::instance().animations().scrollBarEngine().registerScrolledWindow( parent ); }

                Style::instance().renderWindowBackground( window, clipRect, x, y, w, h );
                accepted = true;
            }

        } else if( d.isTrough() ) {

            if( GTK_IS_PROGRESS_BAR( widget ) )
            { return; }

        } else if( d.isTooltip() && Style::instance().settings().tooltipDrawStyledFrames() ) {

            StyleOptions options;
            if( Gtk::gtk_widget_has_rgba( widget ) ) options |= Alpha;
            if( !( (options&Alpha) || Style::instance().settings().applicationName().isMozilla() )  )
            {

                // make tooltips appear rounded using XShape extension if screen isn't composited
                Style::instance().animations().widgetSizeEngine().registerWidget( widget );
                const GtkAllocation& allocation( widget->allocation );
                if( Style::instance().animations().widgetSizeEngine().updateSize( widget, allocation.width, allocation.height ) )
                {
                    GdkPixmap* mask( Style::instance().helper().roundMask( allocation.width, allocation.height ) );
                    gdk_window_shape_combine_mask( window, mask, 0, 0 );
                    gdk_pixmap_unref( mask );

                }

            }

            Style::instance().renderTooltipBackground( window, clipRect, x, y, w, h, options );
            return;

        } else if(
            d.isCheckButton() ||
            d.isRadioButton() ||
            d.isExpander() ) {

            return;

        } else if( d.isCell() ) {

            StyleOptions options( widget, state );

            // select palete colorgroup for cell background
            Palette::Group group( Palette::Active );
            if( options & Disabled ) group = Palette::Disabled;
            else if( !(options&Focus) ) group = Palette::Inactive;

            // render background
            ColorUtils::Rgba background;
            if( d.isCellEven() ) background = Style::instance().settings().palette().color( group, Palette::Base );
            else if( d.isCellOdd() ) background = Style::instance().settings().palette().color( group, Palette::BaseAlternate );

            if( background.isValid() ) Style::instance().fill( window, clipRect, x, y, w, h, background );
            if( Gtk::gtk_combobox_is_tree_view( widget ) )
            {

                // draw flat selection in combobox list
                if(state==GTK_STATE_SELECTED)
                {
                    ColorUtils::Rgba selection( Style::instance().settings().palette().color( Palette::Active, Palette::Selected ) );
                    Style::instance().fill( window, clipRect, x, y, w, h, selection );
                }

            } else {

                // draw rounded selection in normal list,
                // and detect hover
                bool forceCellStart( false );
                if( GTK_IS_TREE_VIEW( widget ) )
                {

                    Style::instance().animations().treeViewEngine().registerWidget( widget );
                    if(  Style::instance().animations().treeViewEngine().isCellHovered( widget, x, y, w, h ) )
                    { options |= Hover; }

                    GtkTreeView* treeView( GTK_TREE_VIEW( widget ) );
                    Gtk::CellInfo cellInfo( treeView, x, y, w, h );

                    if( cellInfo.isExpanderColumn( treeView ) )
                    {

                        // tree lines
                        forceCellStart = true;
                        if( Style::instance().settings().viewDrawTreeBranchLines() )
                        {
                            StyleOptions options( widget, state, shadow );
                            Style::instance().renderTreeLines( window, clipRect, x, y, w, h, Gtk::CellInfoFlags( treeView, cellInfo ), options );
                        }

                        // change selection rect so that it does not overlap with expander
                        if( options & (Selected|Hover) )
                        {

                            // get expander size from widget
                            int depth( cellInfo.depth() );
                            int expanderSize(0);
                            gtk_widget_style_get( widget, "expander-size", &expanderSize, NULL );

                            int offset( 3 + expanderSize * depth + ( 4 + gtk_tree_view_get_level_indentation( treeView ) )*(depth-1) );

                            x += offset;<commit_msg>added check on cell validity<commit_after>/*
* this file is part of the oxygen gtk engine
* Copyright (c) 2010 <NAME> <<EMAIL>>
* Copyright (c) 2010 <NAME> <<EMAIL>>
*
* based on the Null Theme Engine for Gtk+.
* Copyright (c) 2008 <NAME> <<EMAIL>>
*
* Icon rendering code from Walmis
* <http://gnome-look.org/content/show.php?content=77783&forumpage=3>
*
* 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., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/

#include "oxygenstylewrapper.h"

#include "config.h"

#include "oxygen.h"
#include "oxygenanimations.h"
#include "oxygencairoutils.h"
#include "oxygengtkcellinfo.h"
#include "oxygengtkdetails.h"
#include "oxygengtktypenames.h"
#include "oxygengtkutils.h"
#include "oxygenrcstyle.h"
#include "oxygenstyle.h"

#include <iostream>

//_______________________________________________________________________________________________________________
struct _OxygenStyle
{ GtkStyle parent; };

//_______________________________________________________________________________________________________________
struct _OxygenStyleClass
{  GtkStyleClass parent; };

//_______________________________________________________________________________________________________________
static GtkStyleClass* oxygen_style_parent_class = 0L;

namespace Oxygen
{

    //___________________________________________________________________________________________________________
    static void draw_flat_box(
        GtkStyle* style,
        GdkWindow* window,
        GtkStateType state,
        GtkShadowType shadow,
        GdkRectangle* clipRect,
        GtkWidget* widget,
        const char* detail,
        gint x,
        gint y,
        gint w,
        gint h )
    {
        g_return_if_fail( style && window );
        Style::instance().sanitizeSize( window, w, h );

        #if OXYGEN_DEBUG
        g_log( OXYGEN_LOG_DOMAIN, G_LOG_LEVEL_INFO,
            "widget=%s, primitive=flat_box, state=%s, shadow=%s, detail=%s",
            G_OBJECT_TYPE_NAME( widget ),
            Gtk::TypeNames::state( state ),
            Gtk::TypeNames::shadow( shadow ),
            detail );
        #endif

        const Gtk::Detail d( detail );
        bool accepted( false );
        if( d.isBase() || d.isEventBox())
        {

            if( GTK_IS_WINDOW( widget ) )
            {

                Style::instance().animations().mainWindowEngine().registerWidget( widget );

            } else if( GtkWidget* parent = Gtk::gtk_parent_scrolled_window( widget ) ) {

                Style::instance().animations().scrollBarEngine().registerScrolledWindow( parent );

            }

            Style::instance().renderWindowBackground( window, clipRect, x, y, w, h );
            return;

        } else if( d.isViewportBin() ) {

            GdkColor bg=style->bg[state];
            GdkColor defbg=gtk_widget_get_default_style()->bg[state];

            // This dirty hack with 10000 makes GIMP bottom element viewportbin have correct window color
            // while ccsm options list will remain white. Hope this will work as intended for other apps
            // FIXME: why default style bg isn't the same as unchanged(?) bg in GIMP? If it were, no hack would be needed
            if(
                bg.red/10000==defbg.red/10000 &&
                bg.green/10000==defbg.green/10000 &&
                bg.blue/10000==defbg.blue/10000)
            {

                // make sure that widget is registered to scrolledBarEngine,
                // so that background gets updated properly
                if( GtkWidget* parent = Gtk::gtk_parent_scrolled_window( widget ) )
                { Style::instance().animations().scrollBarEngine().registerScrolledWindow( parent ); }

                Style::instance().renderWindowBackground( window, clipRect, x, y, w, h );
                accepted = true;
            }

        } else if( d.isTrough() ) {

            if( GTK_IS_PROGRESS_BAR( widget ) )
            { return; }

        } else if( d.isTooltip() && Style::instance().settings().tooltipDrawStyledFrames() ) {

            StyleOptions options;
            if( Gtk::gtk_widget_has_rgba( widget ) ) options |= Alpha;
            if( !( (options&Alpha) || Style::instance().settings().applicationName().isMozilla() )  )
            {

                // make tooltips appear rounded using XShape extension if screen isn't composited
                Style::instance().animations().widgetSizeEngine().registerWidget( widget );
                const GtkAllocation& allocation( widget->allocation );
                if( Style::instance().animations().widgetSizeEngine().updateSize( widget, allocation.width, allocation.height ) )
                {
                    GdkPixmap* mask( Style::instance().helper().roundMask( allocation.width, allocation.height ) );
                    gdk_window_shape_combine_mask( window, mask, 0, 0 );
                    gdk_pixmap_unref( mask );

                }

            }

            Style::instance().renderTooltipBackground( window, clipRect, x, y, w, h, options );
            return;

        } else if(
            d.isCheckButton() ||
            d.isRadioButton() ||
            d.isExpander() ) {

            return;

        } else if( d.isCell() ) {

            StyleOptions options( widget, state );

            // select palete colorgroup for cell background
            Palette::Group group( Palette::Active );
            if( options & Disabled ) group = Palette::Disabled;
            else if( !(options&Focus) ) group = Palette::Inactive;

            // render background
            ColorUtils::Rgba background;
            if( d.isCellEven() ) background = Style::instance().settings().palette().color( group, Palette::Base );
            else if( d.isCellOdd() ) background = Style::instance().settings().palette().color( group, Palette::BaseAlternate );

            if( background.isValid() ) Style::instance().fill( window, clipRect, x, y, w, h, background );
            if( Gtk::gtk_combobox_is_tree_view( widget ) )
            {

                // draw flat selection in combobox list
                if(state==GTK_STATE_SELECTED)
                {
                    ColorUtils::Rgba selection( Style::instance().settings().palette().color( Palette::Active, Palette::Selected ) );
                    Style::instance().fill( window, clipRect, x, y, w, h, selection );
                }

            } else {

                // draw rounded selection in normal list,
                // and detect hover
                bool forceCellStart( false );
                if( GTK_IS_TREE_VIEW( widget ) )
                {

                    Style::instance().animations().treeViewEngine().registerWidget( widget );
                    if(  Style::instance().animations().treeViewEngine().isCellHovered( widget, x, y, w, h ) )
                    { options |= Hover; }

                    GtkTreeView* treeView( GTK_TREE_VIEW( widget ) );
                    Gtk::CellInfo cellInfo( treeView, x, y, w, h );

                    if( cellInfo.isValid() && cellInfo.isExpanderColumn( treeView ) )
                    {

                        // tree lines
                        forceCellStart = true;
                        if( Style::instance().settings().viewDrawTreeBranchLines() )
                        {
                            StyleOptions options( widget, state, shadow );
                            Style::instance().renderTreeLines( window, clipRect, x, y, w, h, Gtk::CellInfoFlags( treeView, cellInfo ), options );
                        }

                        // change selection rect so that it does not overlap with expander
                        if( options & (Selected|Hover) )
                        {

                            // get expander size from widget
                            int depth( cellInfo.depth() );
                            int expanderSize(0);
                            gtk_widget_style_get( widget, "expander-size", &expanderSize, NULL );

                            int offset( 3 + expanderSize * depth + ( 4 + gtk_tree_view_get_level_indentation( treeView ) )*(depth-1) );

                            x += offset;
{'fraction_non_alphanumeric': 0.10355785053623107, 'fraction_numerical': 0.008171139987516314, 'mean_word_length': 2.1137809187279153, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5494899', 'n_tokens_mistral': 4712, 'n_tokens_neox': 4388, 'n_words': 1236}