1 #ifndef oxygengenericengine_h 2 #define oxygengenericengine_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 24 #include "oxygenbaseengine.h" 25 #include "oxygendatamap.h" 26 27 #include <gtk/gtk.h> 28 29 namespace Oxygen 30 { 31 //! forward declaration 32 class Animations; 33 34 //! associates widgets with some type of data 35 template< typename T> 36 class GenericEngine: public BaseEngine 37 { 38 39 public: 40 41 //! constructor GenericEngine(Animations * widget)42 GenericEngine( Animations* widget ): 43 BaseEngine( widget ) 44 {} 45 46 //! destructor ~GenericEngine(void)47 virtual ~GenericEngine( void ) 48 {} 49 50 //! register widget registerWidget(GtkWidget * widget)51 virtual bool registerWidget( GtkWidget* widget ) 52 { 53 if( _data.contains( widget ) ) return false; 54 if( enabled() ) 55 { 56 57 T& data( _data.registerWidget( widget ) ); 58 data.connect( widget ); 59 60 } else _data.registerWidget( widget ); 61 62 BaseEngine::registerWidget( widget ); 63 return true; 64 65 } 66 67 //! unregister widget unregisterWidget(GtkWidget * widget)68 virtual void unregisterWidget( GtkWidget* widget ) 69 { 70 if( !_data.contains( widget ) ) return; 71 _data.value( widget ).disconnect( widget ); 72 _data.erase( widget ); 73 } 74 75 //! enabled state 76 /*! returns true if changed */ 77 inline virtual bool setEnabled( bool value ); 78 79 //! true if widget is included contains(GtkWidget * widget)80 virtual bool contains( GtkWidget* widget ) 81 { return _data.contains( widget ); } 82 83 protected: 84 85 //! return refence to data data(void)86 virtual DataMap<T>& data( void ) 87 { return _data; } 88 89 //! return refence to data data(void)90 virtual const DataMap<T>& data( void ) const 91 { return _data; } 92 93 private: 94 95 //! map widgets to data 96 DataMap<T> _data; 97 98 }; 99 100 //________________________________________________________________________ setEnabled(bool value)101 template< typename T> bool GenericEngine<T>::setEnabled( bool value ) 102 { 103 if( enabled() == value ) return false; 104 105 BaseEngine::setEnabled( value ); 106 if( enabled() ) _data.connectAll(); 107 else _data.disconnectAll(); 108 109 return true; 110 111 } 112 113 } 114 115 #endif 116