1 #ifndef oxygenmenubarstateengine_h
2 #define oxygenmenubarstateengine_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 "oxygenmenubarstatedata.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 MenuBarStateEngine: public GenericEngine<MenuBarStateData>, public AnimationEngine
41     {
42 
43         public:
44 
45         //! constructor
MenuBarStateEngine(Animations * parent)46         MenuBarStateEngine( Animations* parent ):
47             GenericEngine<MenuBarStateData>( parent ),
48             _animationsEnabled( true ),
49             _followMouse( false ),
50             _followMouseAnimationsDuration( 80 )
51             {}
52 
53         //! destructor
~MenuBarStateEngine(void)54         virtual ~MenuBarStateEngine( void )
55         {}
56 
57         //! register widget [overloaded]
registerWidget(GtkWidget * widget)58         virtual bool registerWidget( GtkWidget* widget )
59         {
60             const bool registered( GenericEngine<MenuBarStateData>::registerWidget( widget ) );
61             if( registered )
62             {
63                 MenuBarStateData& data( this->data().value( widget ) );
64                 data.setDuration( duration() );
65                 data.setAnimationsEnabled( _animationsEnabled );
66                 data.setFollowMouse( _followMouse );
67                 data.setFollowMouseAnimationsDuration( _followMouseAnimationsDuration );
68             }
69             return registered;
70         }
71 
72         //!@name modifiers
73         //@{
74 
75         //! enable animations
setAnimationsEnabled(bool value)76         bool setAnimationsEnabled( bool value )
77         {
78             if( _animationsEnabled == value ) return false;
79             _animationsEnabled = value;
80 
81             for( DataMap<MenuBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ )
82             { iter->second.setAnimationsEnabled( value && !widgetIsBlackListed( iter->first ) ); }
83             return true;
84         }
85 
86         //! transition duration
setDuration(int value)87         virtual bool setDuration( int value )
88         {
89             if( !AnimationEngine::setDuration( value ) ) return false;
90             for( DataMap<MenuBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ )
91             { iter->second.setDuration( value ); }
92             return false;
93         }
94 
95         //! enable follow-mouse animation
setFollowMouse(bool value)96         bool setFollowMouse( bool value )
97         {
98             if( _followMouse == value ) return false;
99             _followMouse = value;
100 
101             for( DataMap<MenuBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ )
102             { iter->second.setFollowMouse( value && !widgetIsBlackListed( iter->first ) ); }
103             return true;
104         }
105 
106         //! follow-mouse animations duration
setFollowMouseAnimationsDuration(int value)107         bool setFollowMouseAnimationsDuration( int value )
108         {
109             if( _followMouseAnimationsDuration == value ) return false;
110             _followMouseAnimationsDuration = value;
111 
112             for( DataMap<MenuBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ )
113             { iter->second.setFollowMouseAnimationsDuration( value ); }
114             return true;
115         }
116 
117         //@}
118 
119         //!@name accessors
120         //@{
121 
122         //! true if animated
isAnimated(GtkWidget * widget)123         bool isAnimated( GtkWidget* widget )
124         { return data().value( widget ).isAnimated(); }
125 
126         //! true if given animation type is animated
isAnimated(GtkWidget * widget,const WidgetType & type)127         bool isAnimated( GtkWidget* widget, const WidgetType& type )
128         { return data().value( widget ).isAnimated( type ); }
129 
130         //! animated widget for given parent and type
widget(GtkWidget * widget,const WidgetType & type)131         GtkWidget* widget( GtkWidget* widget, const WidgetType& type )
132         { return data().value( widget ).widget( type ); }
133 
134         //! animated rect for given widget and type
rectangle(GtkWidget * widget,const WidgetType & type)135         const GdkRectangle& rectangle( GtkWidget* widget, const WidgetType& type )
136         { return data().value( widget ).rectangle( type ); }
137 
138         //! animation data for given widget and type
animationData(GtkWidget * widget,const WidgetType & type)139         AnimationData animationData( GtkWidget* widget, const WidgetType& type )
140         { return data().value( widget ).animationData( type ); }
141 
142         //! returns true if animated rectangle is valid
animatedRectangleIsValid(GtkWidget * widget)143         bool animatedRectangleIsValid( GtkWidget* widget )
144         { return data().value( widget ).animatedRectangleIsValid(); }
145 
146         //! animated rectangle
animatedRectangle(GtkWidget * widget)147         const GdkRectangle& animatedRectangle( GtkWidget* widget )
148         { return data().value( widget ).animatedRectangle(); }
149 
150         //@}
151 
152         private:
153 
154         //! enable animations
155         bool _animationsEnabled;
156 
157         //! follow-mouse enabled
158         bool _followMouse;
159 
160         //! follow-mouse animation duration
161         int _followMouseAnimationsDuration;
162 
163     };
164 
165 }
166 
167 #endif
168