File indexing completed on 2024-04-28 05:32:13

0001 /*
0002     this file is part of the oxygen gtk engine
0003     SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0004 
0005     based on the 0L Theme Engine for Gtk+.
0006     SPDX-FileCopyrightText: 2008 Robert Staudinger <robert.staudinger@gmail.com>
0007 
0008     SPDX-License-Identifier: LGPL-2.0-or-later
0009 */
0010 
0011 #include "oxygenrcstyle.h"
0012 #include "oxygenstyle.h"
0013 #include "oxygenstylewrapper.h"
0014 
0015 #include "config.h"
0016 
0017 namespace Oxygen
0018 {
0019 
0020     //______________________________________________________________________
0021     GType RCStyle::_type = 0L;
0022     GTypeInfo RCStyle::_typeInfo;
0023     GtkRcStyleClass* RCStyle::_parentClass = 0L;
0024 
0025     //______________________________________________________________________
0026     GtkStyle* RCStyle::createStyle( GtkRcStyle* rc_style )
0027     { return GTK_STYLE( g_object_new( StyleWrapper::type(), 0L ) ); }
0028 
0029     //______________________________________________________________________
0030     guint RCStyle::parse(
0031         GtkRcStyle* rc_style,
0032         GtkSettings* settings,
0033         GScanner* scanner )
0034     {
0035         static GQuark scope_id = 0;
0036         guint old_scope;
0037         guint token;
0038 
0039         if( !scope_id )
0040         { scope_id = g_quark_from_string( "oxygen_engine" ); }
0041 
0042         old_scope = g_scanner_set_scope( scanner, scope_id );
0043 
0044         token = g_scanner_peek_next_token( scanner );
0045         while( token != G_TOKEN_RIGHT_CURLY )
0046         {
0047             token = g_scanner_peek_next_token( scanner );
0048             if( token != G_TOKEN_NONE ) return token;
0049         }
0050 
0051         g_scanner_get_next_token( scanner );
0052         g_scanner_set_scope( scanner, old_scope );
0053 
0054         return G_TOKEN_NONE;
0055     }
0056 
0057     //______________________________________________________________________
0058     void RCStyle::merge( GtkRcStyle *dst, GtkRcStyle *src )
0059     {
0060         if( RCStyle::_parentClass )
0061         { RCStyle::_parentClass->merge( dst, src ); }
0062     }
0063 
0064     //______________________________________________________________________
0065     void RCStyle::classInit( OxygenRcStyleClass *klass )
0066     {
0067 
0068         GtkRcStyleClass *rcStyleClass( GTK_RC_STYLE_CLASS( klass ) );
0069 
0070         _parentClass = static_cast<GtkRcStyleClass*>(g_type_class_peek_parent( klass ) );
0071 
0072         rcStyleClass->create_style = createStyle;
0073         rcStyleClass->parse = parse;
0074         rcStyleClass->merge = merge;
0075     }
0076 
0077     //______________________________________________________________________
0078     void RCStyle::registerType( GTypeModule *module )
0079     {
0080 
0081         #if OXYGEN_DEBUG
0082         std::cerr << "Oxygen::RCStyle::registerType" << std::endl;
0083         #endif
0084 
0085         const GTypeInfo info =
0086         {
0087             (guint16)sizeof(OxygenRcStyleClass ),
0088             (GBaseInitFunc) NULL,
0089             (GBaseFinalizeFunc) NULL,
0090             (GClassInitFunc) classInit,
0091             (GClassFinalizeFunc) NULL,
0092             NULL,
0093             (guint16)sizeof( OxygenRcStyle ),
0094             0,
0095             (GInstanceInitFunc) NULL,
0096             NULL
0097         };
0098 
0099         _typeInfo = info;
0100         _type = g_type_module_register_type( module, GTK_TYPE_RC_STYLE, "OxygenRcStyle", &_typeInfo, GTypeFlags(0 ) );
0101 
0102     }
0103 
0104     //______________________________________________________________________
0105     GType RCStyle::type( void )
0106     { return _type; }
0107 
0108 }