File indexing completed on 2024-05-12 17:05:49
0001 #ifndef oxygenmenustateengine_h 0002 #define oxygenmenustateengine_h 0003 /* 0004 * this file is part of the oxygen gtk engine 0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0006 * 0007 * SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "oxygenanimationengine.h" 0011 #include "oxygengenericengine.h" 0012 #include "oxygendatamap.h" 0013 #include "oxygenmenustatedata.h" 0014 0015 #include <gtk/gtk.h> 0016 0017 namespace Oxygen 0018 { 0019 //! forward declaration 0020 class Animations; 0021 0022 //! stores data associated to editable comboboxes 0023 /*! 0024 ensures that the text entry and the button of editable comboboxes 0025 gets hovered and focus flags at the same time 0026 */ 0027 class MenuStateEngine: public GenericEngine<MenuStateData>, public AnimationEngine 0028 { 0029 0030 public: 0031 0032 //! constructor 0033 MenuStateEngine( Animations* parent ): 0034 GenericEngine<MenuStateData>( parent ), 0035 _followMouse( false ), 0036 _followMouseAnimationsDuration( 40 ) 0037 {} 0038 0039 //! destructor 0040 virtual ~MenuStateEngine( void ) 0041 {} 0042 0043 //! register widget [overloaded] 0044 virtual bool registerWidget( GtkWidget* widget ) 0045 { 0046 const bool registered( GenericEngine<MenuStateData>::registerWidget( widget ) ); 0047 if( registered ) 0048 { 0049 MenuStateData& data( this->data().value( widget ) ); 0050 data.setDuration( duration() ); 0051 data.setEnabled( enabled() ); 0052 data.setFollowMouse( _followMouse ); 0053 data.setFollowMouseAnimationsDuration( _followMouseAnimationsDuration ); 0054 } 0055 return registered; 0056 } 0057 0058 //!@name modifiers 0059 //@{ 0060 0061 //! enable state 0062 virtual bool setEnabled( bool value ) 0063 { 0064 if( !BaseEngine::setEnabled( value ) ) return false; 0065 for( DataMap<MenuStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0066 { 0067 iter->second.setEnabled( value ); 0068 if( enabled() && !widgetIsBlackListed( iter->first ) ) iter->second.connect( iter->first ); 0069 else iter->second.disconnect( iter->first ); 0070 } 0071 0072 return true; 0073 } 0074 0075 //! transition duration 0076 virtual bool setDuration( int value ) 0077 { 0078 if( !AnimationEngine::setDuration( value ) ) return false; 0079 for( DataMap<MenuStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0080 { iter->second.setDuration( value ); } 0081 return false; 0082 } 0083 0084 //! enable follow-mouse animation 0085 bool setFollowMouse( bool value ) 0086 { 0087 if( _followMouse == value ) return false; 0088 _followMouse = value; 0089 0090 for( DataMap<MenuStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0091 { iter->second.setFollowMouse( value && !widgetIsBlackListed( iter->first ) ); } 0092 return true; 0093 } 0094 0095 //! follow-mouse animations duration 0096 bool setFollowMouseAnimationsDuration( int value ) 0097 { 0098 if( _followMouseAnimationsDuration == value ) return false; 0099 _followMouseAnimationsDuration = value; 0100 0101 for( DataMap<MenuStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0102 { iter->second.setFollowMouseAnimationsDuration( value ); } 0103 return true; 0104 } 0105 0106 //@} 0107 0108 //!@name accessors 0109 //@{ 0110 0111 //! true if animated 0112 bool isAnimated( GtkWidget* widget ) 0113 { return data().value( widget ).isAnimated(); } 0114 0115 //! true if given animation type is animated 0116 bool isAnimated( GtkWidget* widget, const WidgetType& type ) 0117 { return data().value( widget ).isAnimated( type ); } 0118 0119 //! animated widget for given parent and type 0120 GtkWidget* widget( GtkWidget* widget, const WidgetType& type ) 0121 { return data().value( widget ).widget( type ); } 0122 0123 //! animated rect for given widget and type 0124 const GdkRectangle& rectangle( GtkWidget* widget, const WidgetType& type ) 0125 { return data().value( widget ).rectangle( type ); } 0126 0127 //! animation data for given widget and type 0128 AnimationData animationData( GtkWidget* widget, const WidgetType& type ) 0129 { return data().value( widget ).animationData( type ); } 0130 0131 //! returns true if animated rectangle is valid 0132 bool animatedRectangleIsValid( GtkWidget* widget ) 0133 { return data().value( widget ).animatedRectangleIsValid(); } 0134 0135 //! animated rectangle 0136 const GdkRectangle& animatedRectangle( GtkWidget* widget ) 0137 { return data().value( widget ).animatedRectangle(); } 0138 0139 //! true when fade out animation is locked (delayed) 0140 bool isLocked( GtkWidget* widget ) 0141 { return data().value( widget ).isLocked(); } 0142 0143 //@} 0144 0145 private: 0146 0147 //! follow-mouse enabled 0148 bool _followMouse; 0149 0150 //! follow-mouse animation duration 0151 int _followMouseAnimationsDuration; 0152 0153 }; 0154 0155 } 0156 0157 #endif