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