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

0001 #ifndef oxygengtktypenames_h
0002 #define oxygengtktypenames_h
0003 /*
0004 * this file is part of the oxygen gtk engine
0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 *
0007 * based on the Null Theme Engine for Gtk+.
0008 * SPDX-FileCopyrightText: 2008 Robert Staudinger <robert.staudinger@gmail.com>
0009 *
0010 * SPDX-License-Identifier: LGPL-2.0-or-later
0011 */
0012 
0013 #include <gtk/gtk.h>
0014 #include <gdk/gdk.h>
0015 #include <gio/gio.h>
0016 #include <string>
0017 #include <iostream>
0018 
0019 namespace Oxygen
0020 {
0021 
0022     namespace Gtk
0023     {
0024         //! css to gtk mapping
0025         class TypeNames
0026         {
0027 
0028             public:
0029             //@{
0030 
0031             //! widget state
0032             static const char* state( GtkStateType );
0033 
0034             //! shadow type
0035             static const char* shadow( GtkShadowType );
0036 
0037             //! arrow type
0038             static const char* arrow( GtkArrowType );
0039 
0040             //! position
0041             static const char* position( GtkPositionType );
0042 
0043             //! edge
0044             static const char* windowEdge( GdkWindowEdge );
0045 
0046             //! window type
0047             static const char* windowTypeHint( GdkWindowTypeHint );
0048 
0049             //! widget orientation
0050             static const char* orientation( GtkOrientation );
0051 
0052             //! tree expander style
0053             static const char* expanderStyle( GtkExpanderStyle );
0054 
0055             //! Gtk dialogs response IDs
0056             static const char* response( GtkResponseType );
0057 
0058             //! icon size
0059             static const char* iconSize( GtkIconSize );
0060 
0061             //! file monitor event
0062             static const char* fileMonitorEvent( GFileMonitorEvent );
0063 
0064             //@}
0065 
0066             //__________________________________________
0067             //! template class to handle css to gtk maps
0068             template< typename T> struct Entry
0069             {
0070                 public:
0071 
0072                 T gtk_value;
0073                 std::string css_value;
0074             };
0075 
0076             //__________________________________________
0077             //! template class to handle css to gtk maps
0078             template< typename T> class Finder
0079             {
0080                 public:
0081 
0082                 typedef const Entry<T>* ValueList;
0083 
0084                 //! constructor
0085                 Finder( ValueList values, unsigned int size ):
0086                     _size( size ),
0087                     _values( values )
0088                 {}
0089 
0090                 //! return gtk value matching css
0091                 T findGtk( const char* css_value, const T& default_value )
0092                 {
0093                     g_return_val_if_fail( css_value, default_value );
0094                     for( unsigned int i = 0; i < _size; i++ )
0095                     {
0096                         if( _values[i].css_value == css_value )
0097                         { return _values[i].gtk_value; }
0098                     }
0099 
0100                     return default_value;
0101                 }
0102 
0103                 //! return css value matching gtk
0104                 const char* findCss( const T& gtk_value )
0105                 {
0106                     for( unsigned int i = 0; i < _size; i++ )
0107                     {
0108                         if( _values[i].gtk_value == gtk_value )
0109                         { return _values[i].css_value.c_str(); }
0110                     }
0111 
0112                     return "";
0113 
0114                 }
0115 
0116                 private:
0117 
0118                 unsigned int _size;
0119                 ValueList _values;
0120 
0121             };
0122 
0123             protected:
0124 
0125             static GtkStateType matchState( const char* );
0126             static GtkShadowType matchShadow( const char* );
0127             static GtkArrowType matchArrow( const char* );
0128             static GtkPositionType matchPosition( const char* );
0129             static GdkWindowEdge matchWindowEdge    ( const char* );
0130             static GdkWindowTypeHint matchWindowTypeHint( const char* );
0131             static GtkOrientation matchOrientation( const char* );
0132             static GtkExpanderStyle matchExpanderStyle( const char* );
0133             static GtkResponseType matchResponse( const char* );
0134             static GtkIconSize matchIconSize( const char* );
0135             static GFileMonitorEvent matchFileMonitorEvent( const char* );
0136 
0137         };
0138     }
0139 
0140 }
0141 
0142 #endif