1 #ifndef oxygenscrollbarstateengine_h 2 #define oxygenscrollbarstateengine_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 "oxygenscrollbarstatedata.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 scrollbarstatees 38 /*! 39 ensures that the text entry and the button of editable scrollbarstatees 40 gets hovered and focus flags at the same time 41 */ 42 class ScrollBarStateEngine: public GenericEngine<ScrollBarStateData>, public AnimationEngine 43 { 44 45 public: 46 47 //! constructor ScrollBarStateEngine(Animations * widget)48 ScrollBarStateEngine( Animations* widget ): 49 GenericEngine<ScrollBarStateData>( widget ) 50 {} 51 52 //! destructor ~ScrollBarStateEngine(void)53 virtual ~ScrollBarStateEngine( 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<ScrollBarStateData>::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<ScrollBarStateData>::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,const GdkRectangle & rect,GtkArrowType type,const StyleOptions & options)81 virtual AnimationData get( GtkWidget* widget, const GdkRectangle& rect, GtkArrowType type, const StyleOptions& options ) 82 { 83 84 // check widget 85 if( !( enabled() && widget ) ) return AnimationData(); 86 87 // register 88 registerWidget( widget ); 89 90 ScrollBarStateData& data( this->data().value( widget ) ); 91 92 // update rect 93 if( options&Hover ) data.setRect( type, rect ); 94 95 // check intersection and get relevant animation data 96 if( gdk_rectangle_intersect( &rect, &data.rect( type ), 0L ) ) 97 { 98 99 data.updateState( type, (options&Hover) && !(options&Disabled) ); 100 return data.isAnimated( type ) ? AnimationData( data.opacity( type ), AnimationHover ):AnimationData(); 101 102 } else return AnimationData(); 103 104 } 105 106 //@} 107 108 protected: 109 110 //! register widget [overloaded] registerWidget(GtkWidget * widget)111 virtual bool registerWidget( GtkWidget* widget ) 112 { 113 const bool registered( GenericEngine<ScrollBarStateData>::registerWidget( widget ) ); 114 if( registered ) { 115 data().value( widget ).setEnabled( enabled() ); 116 data().value( widget ).setDuration( duration() ); 117 } 118 return registered; 119 } 120 121 }; 122 123 } 124 125 #endif 126