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         //! argb hint atom
94         Atom _backgroundGradientAtom;
95 
96         //! background gradient hint atom
97         Atom _backgroundPixmapAtom;
98 
99         //! map widget and window id
100         class Data
101         {
102 
103             public:
104 
105             //! constructor
106             Data( GtkWidget* widget, XID id ):
107                 _widget( widget ),
108                 _id( id )
109             {}
110 
111             //! equal to operator
112             bool operator == (const Data& other ) const
113             {
114                 return
115                     other._widget == _widget &&
116                     other._id == _id;
117             }
118 
119             //! less than operator
120             bool operator < ( const Data& other ) const
121             {
122                 if( _widget != other._widget ) return _widget < other._widget;
123                 else return _id < other._id;
124             }
125 
126             //! widget
127             GtkWidget* _widget;
128 
129             //! window id
130             XID _id;
131 
132         };
133 
134         //! true if widget is included
135         virtual bool contains( const Data& data ) const
136         { return _data.find( data ) != _data.end(); }
137 
138         //! used to find Data matching given widget
139         class SameWidgetFTor
140         {
141 
142             public:
143 
144             //! constructor
145             SameWidgetFTor( GtkWidget* widget ):
146                 _widget( widget )
147                 {}
148 
149             //! predicate
150             bool operator () (const Data& data ) const
151             { return data._widget == _widget; }
152 
153             private:
154 
155             //! prediction
156             GtkWidget* _widget;
157 
158         };
159 
160         //! store registered widgets
161         std::set<Data> _data;
162 
163         #endif
164 
165     };
166 
167 }
168 
169 #endif
170