1 #ifndef oxygenmenustateengine_h 2 #define oxygenmenustateengine_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 "oxygenanimationengine.h" 24 #include "oxygengenericengine.h" 25 #include "oxygendatamap.h" 26 #include "oxygenmenustatedata.h" 27 28 #include <gtk/gtk.h> 29 30 namespace Oxygen 31 { 32 //! forward declaration 33 class Animations; 34 35 //! stores data associated to editable comboboxes 36 /*! 37 ensures that the text entry and the button of editable comboboxes 38 gets hovered and focus flags at the same time 39 */ 40 class MenuStateEngine: public GenericEngine<MenuStateData>, public AnimationEngine 41 { 42 43 public: 44 45 //! constructor MenuStateEngine(Animations * parent)46 MenuStateEngine( Animations* parent ): 47 GenericEngine<MenuStateData>( parent ), 48 _followMouse( false ), 49 _followMouseAnimationsDuration( 40 ) 50 {} 51 52 //! destructor ~MenuStateEngine(void)53 virtual ~MenuStateEngine( void ) 54 {} 55 56 //! register widget [overloaded] registerWidget(GtkWidget * widget)57 virtual bool registerWidget( GtkWidget* widget ) 58 { 59 const bool registered( GenericEngine<MenuStateData>::registerWidget( widget ) ); 60 if( registered ) 61 { 62 MenuStateData& data( this->data().value( widget ) ); 63 data.setDuration( duration() ); 64 data.setEnabled( enabled() ); 65 data.setFollowMouse( _followMouse ); 66 data.setFollowMouseAnimationsDuration( _followMouseAnimationsDuration ); 67 } 68 return registered; 69 } 70 71 //!@name modifiers 72 //@{ 73 74 //! enable state setEnabled(bool value)75 virtual bool setEnabled( bool value ) 76 { 77 if( !BaseEngine::setEnabled( value ) ) return false; 78 for( DataMap<MenuStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 79 { 80 iter->second.setEnabled( value ); 81 if( enabled() && !widgetIsBlackListed( iter->first ) ) iter->second.connect( iter->first ); 82 else iter->second.disconnect( iter->first ); 83 } 84 85 return true; 86 } 87 88 //! transition duration setDuration(int value)89 virtual bool setDuration( int value ) 90 { 91 if( !AnimationEngine::setDuration( value ) ) return false; 92 for( DataMap<MenuStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 93 { iter->second.setDuration( value ); } 94 return false; 95 } 96 97 //! enable follow-mouse animation setFollowMouse(bool value)98 bool setFollowMouse( bool value ) 99 { 100 if( _followMouse == value ) return false; 101 _followMouse = value; 102 103 for( DataMap<MenuStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 104 { iter->second.setFollowMouse( value && !widgetIsBlackListed( iter->first ) ); } 105 return true; 106 } 107 108 //! follow-mouse animations duration setFollowMouseAnimationsDuration(int value)109 bool setFollowMouseAnimationsDuration( int value ) 110 { 111 if( _followMouseAnimationsDuration == value ) return false; 112 _followMouseAnimationsDuration = value; 113 114 for( DataMap<MenuStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 115 { iter->second.setFollowMouseAnimationsDuration( value ); } 116 return true; 117 } 118 119 //@} 120 121 //!@name accessors 122 //@{ 123 124 //! true if animated isAnimated(GtkWidget * widget)125 bool isAnimated( GtkWidget* widget ) 126 { return data().value( widget ).isAnimated(); } 127 128 //! true if given animation type is animated isAnimated(GtkWidget * widget,const WidgetType & type)129 bool isAnimated( GtkWidget* widget, const WidgetType& type ) 130 { return data().value( widget ).isAnimated( type ); } 131 132 //! animated widget for given parent and type widget(GtkWidget * widget,const WidgetType & type)133 GtkWidget* widget( GtkWidget* widget, const WidgetType& type ) 134 { return data().value( widget ).widget( type ); } 135 136 //! animated rect for given widget and type rectangle(GtkWidget * widget,const WidgetType & type)137 const GdkRectangle& rectangle( GtkWidget* widget, const WidgetType& type ) 138 { return data().value( widget ).rectangle( type ); } 139 140 //! animation data for given widget and type animationData(GtkWidget * widget,const WidgetType & type)141 AnimationData animationData( GtkWidget* widget, const WidgetType& type ) 142 { return data().value( widget ).animationData( type ); } 143 144 //! returns true if animated rectangle is valid animatedRectangleIsValid(GtkWidget * widget)145 bool animatedRectangleIsValid( GtkWidget* widget ) 146 { return data().value( widget ).animatedRectangleIsValid(); } 147 148 //! animated rectangle animatedRectangle(GtkWidget * widget)149 const GdkRectangle& animatedRectangle( GtkWidget* widget ) 150 { return data().value( widget ).animatedRectangle(); } 151 152 //! true when fade out animation is locked (delayed) isLocked(GtkWidget * widget)153 bool isLocked( GtkWidget* widget ) 154 { return data().value( widget ).isLocked(); } 155 156 //@} 157 158 private: 159 160 //! follow-mouse enabled 161 bool _followMouse; 162 163 //! follow-mouse animation duration 164 int _followMouseAnimationsDuration; 165 166 }; 167 168 } 169 170 #endif 171