1 #ifndef oxygenbackgroundhintengine_h 2 #define oxygenbackgroundhintengine_h 3 /* 4 * this file is part of the oxygen gtk engine 5 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or(at your option ) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 20 * MA 02110-1301, USA. 21 */ 22 23 #include "../oxygenflags.h" 24 #include "oxygenbaseengine.h" 25 26 #include <gtk/gtk.h> 27 #include <set> 28 #include <algorithm> 29 30 #ifdef GDK_WINDOWING_X11 31 #include <gdk/gdkx.h> 32 #include <X11/Xdefs.h> 33 #endif 34 35 namespace Oxygen 36 { 37 38 //! forward declaration 39 class Animations; 40 class StyleHelper; 41 42 enum BackgroundHint 43 { 44 45 BackgroundGradient = 1<<0, 46 BackgroundPixmap = 1<<1 47 }; 48 OX_DECLARE_FLAGS(BackgroundHints,BackgroundHint)49 OX_DECLARE_FLAGS( BackgroundHints, BackgroundHint ) 50 OX_DECLARE_OPERATORS_FOR_FLAGS( BackgroundHints ) 51 52 //! associates widgets with some type of data 53 class BackgroundHintEngine: public BaseEngine 54 { 55 56 public: 57 58 //! constructor 59 BackgroundHintEngine( Animations* ); 60 61 //! destructor 62 virtual ~BackgroundHintEngine( void ) 63 {} 64 65 //! register widget 66 virtual bool registerWidget( GtkWidget* widget ) 67 { return registerWidget( widget, BackgroundGradient|BackgroundPixmap ); } 68 69 //! register widget 70 virtual bool registerWidget( GtkWidget*, BackgroundHints ); 71 72 //! unregister widget 73 virtual void unregisterWidget( GtkWidget* ); 74 75 //! returns true if widget is registered 76 bool contains( GtkWidget* widget ) const; 77 78 //! true if background gradient is used 79 void setUseBackgroundGradient( bool value ) 80 { _useBackgroundGradient = value; } 81 82 #ifdef GDK_WINDOWING_X11 83 Atom backgroundGradientAtom( void ) const 84 { return _backgroundGradientAtom; } 85 #endif 86 87 protected: 88 89 // true if background gradient is used 90 bool _useBackgroundGradient; 91 92 #ifdef GDK_WINDOWING_X11 93 94 //! argb hint atom 95 Atom _backgroundGradientAtom; 96 97 //! background gradient hint atom 98 Atom _backgroundPixmapAtom; 99 100 //! map widget and window id 101 class Data 102 { 103 104 public: 105 106 //! constructor 107 Data( GtkWidget* widget, XID id ): 108 _widget( widget ), 109 _id( id ) 110 {} 111 112 //! equal to operator 113 bool operator == (const Data& other ) const 114 { 115 return 116 other._widget == _widget && 117 other._id == _id; 118 } 119 120 //! less than operator 121 bool operator < ( const Data& other ) const 122 { 123 if( _widget != other._widget ) return _widget < other._widget; 124 else return _id < other._id; 125 } 126 127 //! widget 128 GtkWidget* _widget; 129 130 //! window id 131 XID _id; 132 133 }; 134 135 //! true if widget is included 136 virtual bool contains( const Data& data ) const 137 { return _data.find( data ) != _data.end(); } 138 139 //! used to find Data matching given widget 140 class SameWidgetFTor 141 { 142 143 public: 144 145 //! constructor 146 SameWidgetFTor( GtkWidget* widget ): 147 _widget( widget ) 148 {} 149 150 //! predicate 151 bool operator () (const Data& data ) const 152 { return data._widget == _widget; } 153 154 private: 155 156 //! prediction 157 GtkWidget* _widget; 158 159 }; 160 161 //! store registered widgets 162 std::set<Data> _data; 163 164 #endif 165 166 }; 167 168 } 169 170 #endif 171