1 #ifndef oxygenscrollbarstatedata_h
2 #define oxygenscrollbarstatedata_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 "../oxygengtkutils.h"
24 #include "oxygentimeline.h"
25 
26 #include <gtk/gtk.h>
27 
28 namespace Oxygen
29 {
30     //! track scrollbar arrow state changes events
31     class ScrollBarStateData
32     {
33 
34         public:
35 
36         //! constructor
ScrollBarStateData(void)37         explicit ScrollBarStateData( void ):
38             _target( 0L )
39         {}
40 
41         //! destructor
~ScrollBarStateData(void)42         virtual ~ScrollBarStateData( 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             data( GTK_ARROW_UP )._timeLine.setEnabled( value );
59             data( GTK_ARROW_DOWN )._timeLine.setEnabled( value );
60         }
61 
62         //! duration
setDuration(int value)63         void setDuration( int value )
64         {
65             data( GTK_ARROW_UP )._timeLine.setDuration( value );
66             data( GTK_ARROW_DOWN )._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         //! rect
rect(GtkArrowType type)78         const GdkRectangle& rect( GtkArrowType type ) const
79         { return data( type )._rect; }
80 
81         //! rect
setRect(GtkArrowType type,const GdkRectangle & rect)82         void setRect( GtkArrowType type, const GdkRectangle& rect )
83         { data( type )._rect = rect; }
84 
85         protected:
86 
87         // arrow data
88         class Data
89         {
90 
91             public:
92 
93             //! constructor
Data(void)94             explicit Data( void ):
95                 _rect( Gtk::gdk_rectangle() ),
96                 _state( false )
97             {}
98 
99             //! update state
100             bool updateState( bool );
101 
102             //! timeline
103             TimeLine _timeLine;
104 
105             //! rectangle
106             GdkRectangle _rect;
107 
108             //! state
109             bool _state;
110 
111         };
112 
113         //! get data for given arrow type
data(GtkArrowType type)114         const Data& data( GtkArrowType type ) const
115         {
116             switch( type )
117             {
118 
119                 case GTK_ARROW_UP:
120                 case GTK_ARROW_LEFT:
121                 return _upArrowData;
122 
123                 default:
124                 case GTK_ARROW_DOWN:
125                 case GTK_ARROW_RIGHT:
126                 return _downArrowData;
127 
128             }
129         }
130 
131         //! get data for given arrow type
data(GtkArrowType type)132         Data& data( GtkArrowType type )
133         {
134             switch( type )
135             {
136 
137                 case GTK_ARROW_UP:
138                 case GTK_ARROW_LEFT:
139                 return _upArrowData;
140 
141                 default:
142                 case GTK_ARROW_DOWN:
143                 case GTK_ARROW_RIGHT:
144                 return _downArrowData;
145 
146             }
147         }
148 
149         //! delayed update
150         static gboolean delayedUpdate( gpointer );
151 
152         private:
153 
154         //! target
155         GtkWidget* _target;
156 
157         // up/left arrow
158         Data _upArrowData;
159 
160         // down/right arrow
161         Data _downArrowData;
162 
163     };
164 
165 }
166 
167 #endif
168