File indexing completed on 2024-05-12 17:05:47
0001 #ifndef oxygenbackgroundhintengine_h 0002 #define oxygenbackgroundhintengine_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 * SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "../oxygenflags.h" 0011 #include "oxygenbaseengine.h" 0012 0013 #include <gtk/gtk.h> 0014 #include <set> 0015 #include <algorithm> 0016 0017 #ifdef GDK_WINDOWING_X11 0018 #include <gdk/gdkx.h> 0019 #include <X11/Xdefs.h> 0020 #endif 0021 0022 namespace Oxygen 0023 { 0024 0025 //! forward declaration 0026 class Animations; 0027 class StyleHelper; 0028 0029 enum BackgroundHint 0030 { 0031 0032 BackgroundGradient = 1<<0, 0033 BackgroundPixmap = 1<<1 0034 }; 0035 0036 OX_DECLARE_FLAGS( BackgroundHints, BackgroundHint ) 0037 OX_DECLARE_OPERATORS_FOR_FLAGS( BackgroundHints ) 0038 0039 //! associates widgets with some type of data 0040 class BackgroundHintEngine: public BaseEngine 0041 { 0042 0043 public: 0044 0045 //! constructor 0046 BackgroundHintEngine( Animations* ); 0047 0048 //! destructor 0049 virtual ~BackgroundHintEngine( void ) 0050 {} 0051 0052 //! register widget 0053 virtual bool registerWidget( GtkWidget* widget ) 0054 { return registerWidget( widget, BackgroundGradient|BackgroundPixmap ); } 0055 0056 //! register widget 0057 virtual bool registerWidget( GtkWidget*, BackgroundHints ); 0058 0059 //! unregister widget 0060 virtual void unregisterWidget( GtkWidget* ); 0061 0062 //! returns true if widget is registered 0063 bool contains( GtkWidget* widget ) const; 0064 0065 //! true if background gradient is used 0066 void setUseBackgroundGradient( bool value ) 0067 { _useBackgroundGradient = value; } 0068 0069 #ifdef GDK_WINDOWING_X11 0070 Atom backgroundGradientAtom( void ) const 0071 { return _backgroundGradientAtom; } 0072 #endif 0073 0074 protected: 0075 0076 // true if background gradient is used 0077 bool _useBackgroundGradient; 0078 0079 #ifdef GDK_WINDOWING_X11 0080 //! argb hint atom 0081 Atom _backgroundGradientAtom; 0082 0083 //! background gradient hint atom 0084 Atom _backgroundPixmapAtom; 0085 0086 //! map widget and window id 0087 class Data 0088 { 0089 0090 public: 0091 0092 //! constructor 0093 Data( GtkWidget* widget, XID id ): 0094 _widget( widget ), 0095 _id( id ) 0096 {} 0097 0098 //! equal to operator 0099 bool operator == (const Data& other ) const 0100 { 0101 return 0102 other._widget == _widget && 0103 other._id == _id; 0104 } 0105 0106 //! less than operator 0107 bool operator < ( const Data& other ) const 0108 { 0109 if( _widget != other._widget ) return _widget < other._widget; 0110 else return _id < other._id; 0111 } 0112 0113 //! widget 0114 GtkWidget* _widget; 0115 0116 //! window id 0117 XID _id; 0118 0119 }; 0120 0121 //! true if widget is included 0122 virtual bool contains( const Data& data ) const 0123 { return _data.find( data ) != _data.end(); } 0124 0125 //! used to find Data matching given widget 0126 class SameWidgetFTor 0127 { 0128 0129 public: 0130 0131 //! constructor 0132 SameWidgetFTor( GtkWidget* widget ): 0133 _widget( widget ) 0134 {} 0135 0136 //! predicate 0137 bool operator () (const Data& data ) const 0138 { return data._widget == _widget; } 0139 0140 private: 0141 0142 //! prediction 0143 GtkWidget* _widget; 0144 0145 }; 0146 0147 //! store registered widgets 0148 std::set<Data> _data; 0149 0150 #endif 0151 0152 }; 0153 0154 } 0155 0156 #endif