File indexing completed on 2024-05-12 05:34:36
0001 #ifndef oxygentoolbarstateengine_h 0002 #define oxygentoolbarstateengine_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 "oxygentoolbarstatedata.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 ToolBarStateEngine: public GenericEngine<ToolBarStateData>, public AnimationEngine 0028 { 0029 0030 public: 0031 0032 //! constructor 0033 ToolBarStateEngine( Animations* parent ): 0034 GenericEngine<ToolBarStateData>( parent ), 0035 _followMouse( false ), 0036 _followMouseAnimationsDuration( 50 ) 0037 {} 0038 0039 //! destructor 0040 virtual ~ToolBarStateEngine( void ) 0041 {} 0042 0043 //! register widget [overloaded] 0044 virtual bool registerWidget( GtkWidget* widget ) 0045 { 0046 const bool registered( GenericEngine<ToolBarStateData>::registerWidget( widget ) ); 0047 if( registered ) 0048 { 0049 ToolBarStateData& 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 //! register child 0062 virtual void registerChild( GtkWidget* widget, GtkWidget* child, bool value = true ) 0063 { 0064 if( !enabled() ) return; 0065 data().value( widget ).registerChild( child, value ); 0066 } 0067 0068 //! enable animations 0069 bool setEnabled( bool value ) 0070 { 0071 if( !BaseEngine::setEnabled( value ) ) return false; 0072 0073 for( DataMap<ToolBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0074 { 0075 iter->second.setEnabled( value ); 0076 if( enabled() && !widgetIsBlackListed( iter->first ) ) iter->second.connect( iter->first ); 0077 else iter->second.disconnect( iter->first ); 0078 } 0079 return true; 0080 } 0081 0082 //! transition duration 0083 virtual bool setDuration( int value ) 0084 { 0085 if( !AnimationEngine::setDuration( value ) ) return false; 0086 for( DataMap<ToolBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0087 { iter->second.setDuration( value ); } 0088 return false; 0089 } 0090 0091 //! enable follow-mouse animation 0092 bool setFollowMouse( bool value ) 0093 { 0094 if( _followMouse == value ) return false; 0095 _followMouse = value; 0096 0097 for( DataMap<ToolBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0098 { iter->second.setFollowMouse( value && !widgetIsBlackListed( iter->first ) ); } 0099 return true; 0100 } 0101 0102 //! follow-mouse animations duration 0103 bool setFollowMouseAnimationsDuration( int value ) 0104 { 0105 if( _followMouseAnimationsDuration == value ) return false; 0106 _followMouseAnimationsDuration = value; 0107 0108 for( DataMap<ToolBarStateData>::Map::iterator iter = data().map().begin(); iter != data().map().end(); iter++ ) 0109 { iter->second.setFollowMouseAnimationsDuration( value ); } 0110 return true; 0111 } 0112 0113 //@} 0114 0115 //!@name accessors 0116 //@{ 0117 0118 //! returns parent that matches a given child, and is in list 0119 GtkWidget* findParent( GtkWidget* widget ) 0120 { 0121 for( GtkWidget *parent = gtk_widget_get_parent( widget ); parent; parent = gtk_widget_get_parent( parent ) ) 0122 { if( data().contains( parent ) ) return parent; } 0123 0124 return 0L; 0125 } 0126 0127 //! true if animated 0128 bool isAnimated( GtkWidget* widget ) 0129 { return data().value( widget ).isAnimated(); } 0130 0131 //! true if given animation type is animated 0132 bool isAnimated( GtkWidget* widget, const WidgetType& type ) 0133 { return data().value( widget ).isAnimated( type ); } 0134 0135 //! widget matching type 0136 GtkWidget* widget( GtkWidget* widget, const WidgetType& type ) 0137 { return data().value( widget ).widget( type ); } 0138 0139 //! animated rect for given widget and type 0140 const GdkRectangle& rectangle( GtkWidget* widget, const WidgetType& type ) 0141 { return data().value( widget ).rectangle( type ); } 0142 0143 //! animation data for given widget and type 0144 AnimationData animationData( GtkWidget* widget, const WidgetType& type ) 0145 { return data().value( widget ).animationData( type ); } 0146 0147 //! returns true if animated rectangle is valid 0148 bool animatedRectangleIsValid( GtkWidget* widget ) 0149 { return data().value( widget ).animatedRectangleIsValid(); } 0150 0151 //! animated rectangle 0152 const GdkRectangle& animatedRectangle( GtkWidget* widget ) 0153 { return data().value( widget ).animatedRectangle(); } 0154 0155 //! true when fade out animation is locked (delayed) 0156 bool isLocked( GtkWidget* widget ) 0157 { return data().value( widget ).isLocked(); } 0158 0159 //@} 0160 0161 private: 0162 0163 //! follow-mouse enabled 0164 bool _followMouse; 0165 0166 //! follow-mouse animation duration 0167 int _followMouseAnimationsDuration; 0168 0169 }; 0170 0171 } 0172 0173 #endif