1 #ifndef oxygentoolbarstateengine_h 2 #define oxygentoolbarstateengine_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 "oxygentoolbarstatedata.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 ToolBarStateEngine: public GenericEngine<ToolBarStateData>, public AnimationEngine 41 { 42 43 public: 44 45 //! constructor ToolBarStateEngine(Animations * parent)46 ToolBarStateEngine( Animations* parent ): 47 GenericEngine<ToolBarStateData>( parent ), 48 _followMouse( false ), 49 _followMouseAnimationsDuration( 50 ) 50 {} 51 52 //! destructor ~ToolBarStateEngine(void)53 virtual ~ToolBarStateEngine( void ) 54 {} 55 56 //! register widget [overloaded] registerWidget(GtkWidget * widget)57 virtual bool registerWidget( GtkWidget* widget ) 58 { 59 const bool registered( GenericEngine<ToolBarStateData>::registerWidget( widget ) ); 60 if( registered ) 61 { 62 ToolBarStateData& 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 //! register child 75 virtual void registerChild( GtkWidget* widget, GtkWidget* child, bool value = true ) 76 { 77 if( !enabled() ) return; 78 data().value( widget ).registerChild( child, value ); 79 } 80 81 //! enable animations setEnabled(bool value)82 bool setEnabled( bool value ) 83 { 84 if( !BaseEngine::setEnabled( value ) ) return false; 85 86 for( DataMap<ToolBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 87 { 88 iter->second.setEnabled( value ); 89 if( enabled() && !widgetIsBlackListed( iter->first ) ) iter->second.connect( iter->first ); 90 else iter->second.disconnect( iter->first ); 91 } 92 return true; 93 } 94 95 //! transition duration setDuration(int value)96 virtual bool setDuration( int value ) 97 { 98 if( !AnimationEngine::setDuration( value ) ) return false; 99 for( DataMap<ToolBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 100 { iter->second.setDuration( value ); } 101 return false; 102 } 103 104 //! enable follow-mouse animation setFollowMouse(bool value)105 bool setFollowMouse( bool value ) 106 { 107 if( _followMouse == value ) return false; 108 _followMouse = value; 109 110 for( DataMap<ToolBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 111 { iter->second.setFollowMouse( value && !widgetIsBlackListed( iter->first ) ); } 112 return true; 113 } 114 115 //! follow-mouse animations duration setFollowMouseAnimationsDuration(int value)116 bool setFollowMouseAnimationsDuration( int value ) 117 { 118 if( _followMouseAnimationsDuration == value ) return false; 119 _followMouseAnimationsDuration = value; 120 121 for( DataMap<ToolBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 122 { iter->second.setFollowMouseAnimationsDuration( value ); } 123 return true; 124 } 125 126 //@} 127 128 //!@name accessors 129 //@{ 130 131 //! returns parent that matches a given child, and is in list findParent(GtkWidget * widget)132 GtkWidget* findParent( GtkWidget* widget ) 133 { 134 for( GtkWidget *parent = gtk_widget_get_parent( widget ); parent; parent = gtk_widget_get_parent( parent ) ) 135 { if( data().contains( parent ) ) return parent; } 136 137 return 0L; 138 } 139 140 //! true if animated isAnimated(GtkWidget * widget)141 bool isAnimated( GtkWidget* widget ) 142 { return data().value( widget ).isAnimated(); } 143 144 //! true if given animation type is animated isAnimated(GtkWidget * widget,const WidgetType & type)145 bool isAnimated( GtkWidget* widget, const WidgetType& type ) 146 { return data().value( widget ).isAnimated( type ); } 147 148 //! widget matching type widget(GtkWidget * widget,const WidgetType & type)149 GtkWidget* widget( GtkWidget* widget, const WidgetType& type ) 150 { return data().value( widget ).widget( type ); } 151 152 //! animated rect for given widget and type rectangle(GtkWidget * widget,const WidgetType & type)153 const GdkRectangle& rectangle( GtkWidget* widget, const WidgetType& type ) 154 { return data().value( widget ).rectangle( type ); } 155 156 //! animation data for given widget and type animationData(GtkWidget * widget,const WidgetType & type)157 AnimationData animationData( GtkWidget* widget, const WidgetType& type ) 158 { return data().value( widget ).animationData( type ); } 159 160 //! returns true if animated rectangle is valid animatedRectangleIsValid(GtkWidget * widget)161 bool animatedRectangleIsValid( GtkWidget* widget ) 162 { return data().value( widget ).animatedRectangleIsValid(); } 163 164 //! animated rectangle animatedRectangle(GtkWidget * widget)165 const GdkRectangle& animatedRectangle( GtkWidget* widget ) 166 { return data().value( widget ).animatedRectangle(); } 167 168 //! true when fade out animation is locked (delayed) isLocked(GtkWidget * widget)169 bool isLocked( GtkWidget* widget ) 170 { return data().value( widget ).isLocked(); } 171 172 //@} 173 174 private: 175 176 //! follow-mouse enabled 177 bool _followMouse; 178 179 //! follow-mouse animation duration 180 int _followMouseAnimationsDuration; 181 182 }; 183 184 } 185 186 #endif 187