1 #ifndef oxygenarrowstateengine_h 2 #define oxygenarrowstateengine_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 "oxygenarrowstatedata.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 arrowstatees 38 /*! 39 ensures that the text entry and the button of editable arrowstatees 40 gets hovered and focus flags at the same time 41 */ 42 class ArrowStateEngine: public GenericEngine<ArrowStateData>, public AnimationEngine 43 { 44 45 public: 46 47 //! constructor ArrowStateEngine(Animations * widget)48 ArrowStateEngine( Animations* widget ): 49 GenericEngine<ArrowStateData>( widget ) 50 {} 51 52 //! destructor ~ArrowStateEngine(void)53 virtual ~ArrowStateEngine( void ) 54 {} 55 56 //! enable state setEnabled(bool value)57 virtual bool setEnabled( bool value ) 58 { 59 if( !BaseEngine::setEnabled( value ) ) return false; 60 for( DataMap<ArrowStateData>::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 67 return true; 68 } 69 70 //! transition duration setDuration(int value)71 virtual bool setDuration( int value ) 72 { 73 if( !AnimationEngine::setDuration( value ) ) return false; 74 for( DataMap<ArrowStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 75 { iter->second.setDuration( value ); } 76 return true; 77 } 78 79 //! retrieve animation data matching a given widget for provided options 80 /*! note: for convenience, this method also calls ::registerWidget and ::updateState */ get(GtkWidget * widget,GtkArrowType type,const StyleOptions & options)81 virtual AnimationData get( GtkWidget* widget, GtkArrowType type, const StyleOptions& options ) 82 { 83 84 // check widget 85 if( !( enabled() && widget ) ) return AnimationData(); 86 87 // register 88 registerWidget( widget ); 89 90 ArrowStateData& data( this->data().value( widget ) ); 91 data.updateState( type, (options&Hover) && !(options&Disabled) ); 92 93 return data.isAnimated( type ) ? AnimationData( data.opacity( type ), AnimationHover ):AnimationData(); 94 95 } 96 97 //@} 98 99 protected: 100 101 //!@name protected modifiers 102 //@{ 103 104 //! register widget [overloaded] registerWidget(GtkWidget * widget)105 virtual bool registerWidget( GtkWidget* widget ) 106 { 107 const bool registered( GenericEngine<ArrowStateData>::registerWidget( widget ) ); 108 if( registered ) { 109 data().value( widget ).setEnabled( enabled() ); 110 data().value( widget ).setDuration( duration() ); 111 } 112 return registered; 113 } 114 115 //@} 116 117 }; 118 119 } 120 121 #endif 122