File indexing completed on 2024-05-12 17:05:49
0001 #ifndef oxygenmenubarstateengine_h 0002 #define oxygenmenubarstateengine_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 "oxygenmenubarstatedata.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 MenuBarStateEngine: public GenericEngine<MenuBarStateData>, public AnimationEngine 0028 { 0029 0030 public: 0031 0032 //! constructor 0033 MenuBarStateEngine( Animations* parent ): 0034 GenericEngine<MenuBarStateData>( parent ), 0035 _animationsEnabled( true ), 0036 _followMouse( false ), 0037 _followMouseAnimationsDuration( 80 ) 0038 {} 0039 0040 //! destructor 0041 virtual ~MenuBarStateEngine( void ) 0042 {} 0043 0044 //! register widget [overloaded] 0045 virtual bool registerWidget( GtkWidget* widget ) 0046 { 0047 const bool registered( GenericEngine<MenuBarStateData>::registerWidget( widget ) ); 0048 if( registered ) 0049 { 0050 MenuBarStateData& data( this->data().value( widget ) ); 0051 data.setDuration( duration() ); 0052 data.setAnimationsEnabled( _animationsEnabled ); 0053 data.setFollowMouse( _followMouse ); 0054 data.setFollowMouseAnimationsDuration( _followMouseAnimationsDuration ); 0055 } 0056 return registered; 0057 } 0058 0059 //!@name modifiers 0060 //@{ 0061 0062 //! enable animations 0063 bool setAnimationsEnabled( bool value ) 0064 { 0065 if( _animationsEnabled == value ) return false; 0066 _animationsEnabled = value; 0067 0068 for( DataMap<MenuBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0069 { iter->second.setAnimationsEnabled( value && !widgetIsBlackListed( iter->first ) ); } 0070 return true; 0071 } 0072 0073 //! transition duration 0074 virtual bool setDuration( int value ) 0075 { 0076 if( !AnimationEngine::setDuration( value ) ) return false; 0077 for( DataMap<MenuBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0078 { iter->second.setDuration( value ); } 0079 return false; 0080 } 0081 0082 //! enable follow-mouse animation 0083 bool setFollowMouse( bool value ) 0084 { 0085 if( _followMouse == value ) return false; 0086 _followMouse = value; 0087 0088 for( DataMap<MenuBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0089 { iter->second.setFollowMouse( value && !widgetIsBlackListed( iter->first ) ); } 0090 return true; 0091 } 0092 0093 //! follow-mouse animations duration 0094 bool setFollowMouseAnimationsDuration( int value ) 0095 { 0096 if( _followMouseAnimationsDuration == value ) return false; 0097 _followMouseAnimationsDuration = value; 0098 0099 for( DataMap<MenuBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0100 { iter->second.setFollowMouseAnimationsDuration( value ); } 0101 return true; 0102 } 0103 0104 //@} 0105 0106 //!@name accessors 0107 //@{ 0108 0109 //! true if animated 0110 bool isAnimated( GtkWidget* widget ) 0111 { return data().value( widget ).isAnimated(); } 0112 0113 //! true if given animation type is animated 0114 bool isAnimated( GtkWidget* widget, const WidgetType& type ) 0115 { return data().value( widget ).isAnimated( type ); } 0116 0117 //! animated widget for given parent and type 0118 GtkWidget* widget( GtkWidget* widget, const WidgetType& type ) 0119 { return data().value( widget ).widget( type ); } 0120 0121 //! animated rect for given widget and type 0122 const GdkRectangle& rectangle( GtkWidget* widget, const WidgetType& type ) 0123 { return data().value( widget ).rectangle( type ); } 0124 0125 //! animation data for given widget and type 0126 AnimationData animationData( GtkWidget* widget, const WidgetType& type ) 0127 { return data().value( widget ).animationData( type ); } 0128 0129 //! returns true if animated rectangle is valid 0130 bool animatedRectangleIsValid( GtkWidget* widget ) 0131 { return data().value( widget ).animatedRectangleIsValid(); } 0132 0133 //! animated rectangle 0134 const GdkRectangle& animatedRectangle( GtkWidget* widget ) 0135 { return data().value( widget ).animatedRectangle(); } 0136 0137 //@} 0138 0139 private: 0140 0141 //! enable animations 0142 bool _animationsEnabled; 0143 0144 //! follow-mouse enabled 0145 bool _followMouse; 0146 0147 //! follow-mouse animation duration 0148 int _followMouseAnimationsDuration; 0149 0150 }; 0151 0152 } 0153 0154 #endif