1 #ifndef oxygenarrowstatedata_h
2 #define oxygenarrowstatedata_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 "oxygentimeline.h"
24 
25 #include <gtk/gtk.h>
26 
27 namespace Oxygen
28 {
29     //! track arrow state changes events,
30     /*! used to deal with spinbox and Notebook arrows */
31     class ArrowStateData
32     {
33 
34         public:
35 
36         //! constructor
ArrowStateData(void)37         explicit ArrowStateData( void ):
38             _target( 0L )
39         {}
40 
41         //! destructor
~ArrowStateData(void)42         virtual ~ArrowStateData( void )
43         {}
44 
45         //! setup connections
46         void connect( GtkWidget* );
47 
48         //! disconnect
49         void disconnect( GtkWidget* );
50 
51         //! update state
updateState(GtkArrowType type,bool value)52         bool updateState( GtkArrowType type, bool value )
53         { return data( type ).updateState( value ); }
54 
55         //! enable state
setEnabled(bool value)56         void setEnabled( bool value )
57         {
58             _upArrowData._timeLine.setEnabled( value );
59             _downArrowData._timeLine.setEnabled( value );
60         }
61 
62         //! duration
setDuration(int value)63         void setDuration( int value )
64         {
65             _upArrowData._timeLine.setDuration( value );
66             _downArrowData._timeLine.setDuration( value );
67         }
68 
69         //! true if timeline for give arrow type is running
isAnimated(GtkArrowType type)70         bool isAnimated( GtkArrowType type ) const
71         { return data( type )._timeLine.isRunning(); }
72 
73         //! opacity
opacity(GtkArrowType type)74         double opacity( GtkArrowType type ) const
75         { return data( type )._timeLine.value(); }
76 
77         protected:
78 
79         // arrow data
80         class Data
81         {
82 
83             public:
84 
85             //! constructor
Data(void)86             explicit Data( void ):
87                 _state( false )
88             {}
89 
90             //! update state
91             bool updateState( bool );
92 
93             //! timeline
94             TimeLine _timeLine;
95 
96             //! state
97             bool _state;
98 
99         };
100 
101         //! get data for given arrow type
data(GtkArrowType type)102         const Data& data( GtkArrowType type ) const
103         {
104             switch( type )
105             {
106 
107                 case GTK_ARROW_UP:
108                 case GTK_ARROW_LEFT:
109                 return _upArrowData;
110 
111                 default:
112                 case GTK_ARROW_DOWN:
113                 case GTK_ARROW_RIGHT:
114                 return _downArrowData;
115 
116             }
117         }
118 
119         //! get data for given arrow type
data(GtkArrowType type)120         Data& data( GtkArrowType type )
121         {
122             switch( type )
123             {
124 
125                 case GTK_ARROW_UP:
126                 case GTK_ARROW_LEFT:
127                 return _upArrowData;
128 
129                 default:
130                 case GTK_ARROW_DOWN:
131                 case GTK_ARROW_RIGHT:
132                 return _downArrowData;
133 
134             }
135         }
136 
137         //! delayed update
138         static gboolean delayedUpdate( gpointer );
139 
140         private:
141 
142         //! target
143         GtkWidget* _target;
144 
145         // up/left arrow
146         Data _upArrowData;
147 
148         // down/right arrow
149         Data _downArrowData;
150 
151     };
152 
153 }
154 
155 #endif
156