1 #ifndef oxygencomboboxentrydata_h
2 #define oxygencomboboxentrydata_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 "oxygenhoverdata.h"
24 #include "oxygensignal.h"
25 
26 #include <gtk/gtk.h>
27 
28 namespace Oxygen
29 {
30 
31     // handles focus and hover for editable comboboxes
32     class ComboBoxEntryData: public HoverData
33     {
34 
35         public:
36 
37         //! constructor
ComboBoxEntryData(void)38         ComboBoxEntryData( void ):
39             _list( 0L )
40         {}
41 
42         //! destructor
~ComboBoxEntryData(void)43         virtual ~ComboBoxEntryData( void )
44         { disconnect( _list ); }
45 
46         //! disconnect
47         virtual void disconnect( GtkWidget* );
48 
49         //!@name modifiers
50         //@{
51 
52         //! list
setList(GtkWidget * widget)53         void setList( GtkWidget* widget )
54         { _list = widget; }
55 
56         //! assign button
57         void setButton( GtkWidget* value );
58 
59         //! assign entry
60         void setEntry( GtkWidget* value );
61 
62         //! button focus
setButtonFocus(bool value)63         void setButtonFocus( bool value )
64         {
65             if( _button._focus == value ) return;
66             _button._focus = value;
67 
68             // trigger entry update
69             if( _entry._widget )
70             { gtk_widget_queue_draw( _entry._widget ); }
71 
72             return;
73         }
74 
75         //! button focus
setButtonHovered(bool value)76         void setButtonHovered( bool value )
77         {
78             if( _button._hovered == value ) return;
79             if( _button._widget )
80             { setHovered( _button._widget, value ); }
81             return;
82         }
83 
84         //! entry focus
setEntryFocus(bool value)85         void setEntryFocus( bool value )
86         {
87 
88             if( _entry._focus == value ) return;
89             _entry._focus = value;
90 
91             // trigger button update
92             if( _button._widget )
93             { gtk_widget_queue_draw( _button._widget ); }
94 
95         }
96 
97         //@}
98 
99         //!@name accessors
100         //@{
101 
102         //! list
list(void)103         GtkWidget* list( void ) const
104         { return _list; }
105 
106         //! true if either button or entry has focus
hasFocus(void)107         bool hasFocus( void ) const
108         { return _button._focus || _entry._focus; }
109 
110         //! true if either button or entry has hover
hovered(void)111         bool hovered( void ) const
112         { return HoverData::hovered() || _button._hovered || _entry._hovered; }
113 
114         //! pressed
pressed(void)115         bool pressed( void ) const
116         { return _button._pressed; }
117 
118         //@}
119 
120         protected:
121 
122         //! set hover flag for given widget
123         void setPressed( GtkWidget*, bool );
124 
125         //! set hover flag for given widget
126         virtual bool setHovered( GtkWidget*, bool );
127 
128         //! disconnect child
129         void unregisterChild( GtkWidget* );
130 
131         //!@name callbacks
132         //@{
133 
134         static gboolean childDestroyNotifyEvent( GtkWidget*, gpointer );
135         static void childToggledEvent( GtkWidget*, gpointer );
136 
137         //@}
138 
139         private:
140 
141         //! drop-down list, if set
142         GtkWidget* _list;
143 
144         class Data
145         {
146 
147             public:
148 
149             //! constructor
Data(void)150             Data( void ):
151                 _widget( 0L ),
152                 _focus( false ),
153                 _hovered( false ),
154                 _pressed( false )
155             {}
156 
157             //! disconnect
158             void disconnect( void );
159 
160             GtkWidget* _widget;
161             bool _focus;
162             bool _hovered;
163             bool _pressed;
164 
165             //!@name callback ids
166             //@{
167             Signal _destroyId;
168             Signal _enterId;
169             Signal _leaveId;
170             Signal _toggledId;
171             //@}
172 
173         };
174 
175         //! button data
176         Data _button;
177 
178         //! entry data
179         Data _entry;
180 
181     };
182 
183 }
184 
185 #endif
186