1 #ifndef oxygentabwidgetstateengine_h 2 #define oxygentabwidgetstateengine_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 "../oxygenanimationdata.h" 24 #include "../oxygenstyleoptions.h" 25 #include "oxygenanimationengine.h" 26 #include "oxygengenericengine.h" 27 #include "oxygendatamap.h" 28 #include "oxygentabwidgetstatedata.h" 29 30 #include <gtk/gtk.h> 31 32 namespace Oxygen 33 { 34 //! forward declaration 35 class Animations; 36 37 //! stores data associated to editable tabwidgetstatees 38 /*! 39 ensures that the text entry and the button of editable tabwidgetstatees 40 gets hovered and focus flags at the same time 41 */ 42 class TabWidgetStateEngine: public GenericEngine<TabWidgetStateData>, public AnimationEngine 43 { 44 45 public: 46 47 //! constructor TabWidgetStateEngine(Animations * widget)48 TabWidgetStateEngine( Animations* widget ): 49 GenericEngine<TabWidgetStateData>( widget ) 50 {} 51 52 //! destructor ~TabWidgetStateEngine(void)53 virtual ~TabWidgetStateEngine( void ) 54 {} 55 56 //! enabled state setEnabled(bool value)57 virtual bool setEnabled( bool value ) 58 { 59 if( !BaseEngine::setEnabled( value ) ) return false; 60 for( DataMap<TabWidgetStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 61 { 62 iter->second.setEnabled( value ); 63 if( enabled() && !widgetIsBlackListed( iter->first ) ) iter->second.connect( iter->first ); 64 else iter->second.disconnect( iter->first ); 65 } 66 return true; 67 } 68 69 //! transition duration setDuration(int value)70 virtual bool setDuration( int value ) 71 { 72 if( !AnimationEngine::setDuration( value ) ) return false; 73 for( DataMap<TabWidgetStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 74 { iter->second.setDuration( value ); } 75 return false; 76 } 77 78 //! retrieve animation data matching a given widget for provided options 79 /*! note: for convenience, this method also calls ::registerWidget and ::updateState */ get(GtkWidget * widget,int index,const StyleOptions & options)80 virtual AnimationData get( GtkWidget* widget, int index, const StyleOptions& options ) 81 { 82 83 // check widget 84 if( !( enabled() && widget ) ) return AnimationData(); 85 86 // register 87 registerWidget( widget ); 88 89 TabWidgetStateData& data( this->data().value( widget ) ); 90 data.updateState( index, (options&Hover) && !(options&Disabled) ); 91 92 return data.isAnimated( index ) ? AnimationData( data.opacity( index ), AnimationHover ):AnimationData(); 93 94 } 95 96 //@} 97 98 protected: 99 100 //!@name protected modifiers 101 //@{ 102 103 //! register widget [overloaded] registerWidget(GtkWidget * widget)104 virtual bool registerWidget( GtkWidget* widget ) 105 { 106 const bool registered( GenericEngine<TabWidgetStateData>::registerWidget( widget ) ); 107 if( registered ) { 108 data().value( widget ).setEnabled( enabled() ); 109 data().value( widget ).setDuration( duration() ); 110 } 111 return registered; 112 } 113 114 //@} 115 116 }; 117 118 } 119 120 #endif 121