-rw-r--r-- | library/qpemenubar.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/library/qpemenubar.cpp b/library/qpemenubar.cpp index c658d10..4aa0bf3 100644 --- a/library/qpemenubar.cpp +++ b/library/qpemenubar.cpp | |||
@@ -1,302 +1,311 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define INCLUDE_MENUITEM_DEF | 21 | #define INCLUDE_MENUITEM_DEF |
22 | 22 | ||
23 | #include "qpemenubar.h" | 23 | #include "qpemenubar.h" |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qguardedptr.h> | 25 | #include <qguardedptr.h> |
26 | #include <qtimer.h> | 26 | #include <qtimer.h> |
27 | 27 | ||
28 | 28 | ||
29 | class QMenuBarHack : public QMenuBar | 29 | class QMenuBarHack : public QMenuBar |
30 | { | 30 | { |
31 | public: | 31 | public: |
32 | int activeItem() const { return actItem; } | 32 | int activeItem() const { return actItem; } |
33 | 33 | ||
34 | void goodbye() | 34 | void goodbye() |
35 | { | 35 | { |
36 | activateItemAt(-1); | 36 | activateItemAt(-1); |
37 | for ( unsigned int i = 0; i < count(); i++ ) { | 37 | for ( unsigned int i = 0; i < count(); i++ ) { |
38 | QMenuItem *mi = findItem( idAt(i) ); | 38 | QMenuItem *mi = findItem( idAt(i) ); |
39 | if ( mi->popup() ) { | 39 | if ( mi->popup() ) { |
40 | mi->popup()->hide(); | 40 | mi->popup()->hide(); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | } | 43 | } |
44 | }; | 44 | }; |
45 | 45 | ||
46 | 46 | ||
47 | // Sharp ROM compatibility | ||
48 | void QPEMenuToolFocusManager::setMenukeyEnabled ( bool ) | ||
49 | { | ||
50 | } | ||
51 | int QPEMenuBar::getOldFocus ( ) | ||
52 | { | ||
53 | return 0; | ||
54 | } | ||
55 | |||
47 | QPEMenuToolFocusManager *QPEMenuToolFocusManager::me = 0; | 56 | QPEMenuToolFocusManager *QPEMenuToolFocusManager::me = 0; |
48 | 57 | ||
49 | QPEMenuToolFocusManager::QPEMenuToolFocusManager() : QObject() | 58 | QPEMenuToolFocusManager::QPEMenuToolFocusManager() : QObject() |
50 | { | 59 | { |
51 | qApp->installEventFilter( this ); | 60 | qApp->installEventFilter( this ); |
52 | } | 61 | } |
53 | 62 | ||
54 | void QPEMenuToolFocusManager::addWidget( QWidget *w ) | 63 | void QPEMenuToolFocusManager::addWidget( QWidget *w ) |
55 | { | 64 | { |
56 | list.append( GuardedWidget(w) ); | 65 | list.append( GuardedWidget(w) ); |
57 | } | 66 | } |
58 | 67 | ||
59 | void QPEMenuToolFocusManager::removeWidget( QWidget *w ) | 68 | void QPEMenuToolFocusManager::removeWidget( QWidget *w ) |
60 | { | 69 | { |
61 | list.remove( GuardedWidget(w) ); | 70 | list.remove( GuardedWidget(w) ); |
62 | } | 71 | } |
63 | 72 | ||
64 | void QPEMenuToolFocusManager::setActive( bool a ) | 73 | void QPEMenuToolFocusManager::setActive( bool a ) |
65 | { | 74 | { |
66 | if ( a ) { | 75 | if ( a ) { |
67 | oldFocus = qApp->focusWidget(); | 76 | oldFocus = qApp->focusWidget(); |
68 | QValueList<GuardedWidget>::Iterator it; | 77 | QValueList<GuardedWidget>::Iterator it; |
69 | it = list.begin(); | 78 | it = list.begin(); |
70 | while ( it != list.end() ) { | 79 | while ( it != list.end() ) { |
71 | QWidget *w = (*it); | 80 | QWidget *w = (*it); |
72 | if ( w && w->isEnabled() && w->isVisible() && | 81 | if ( w && w->isEnabled() && w->isVisible() && |
73 | w->topLevelWidget() == qApp->activeWindow() ) { | 82 | w->topLevelWidget() == qApp->activeWindow() ) { |
74 | setFocus( w ); | 83 | setFocus( w ); |
75 | return; | 84 | return; |
76 | } | 85 | } |
77 | ++it; | 86 | ++it; |
78 | } | 87 | } |
79 | } else { | 88 | } else { |
80 | if ( inFocus ) { | 89 | if ( inFocus ) { |
81 | if ( inFocus->inherits( "QMenuBar" ) ) | 90 | if ( inFocus->inherits( "QMenuBar" ) ) |
82 | ((QMenuBarHack *)(QWidget *)inFocus)->goodbye(); | 91 | ((QMenuBarHack *)(QWidget *)inFocus)->goodbye(); |
83 | if ( inFocus->hasFocus() ) { | 92 | if ( inFocus->hasFocus() ) { |
84 | if ( oldFocus && oldFocus->isVisible() && oldFocus->isEnabled() ) { | 93 | if ( oldFocus && oldFocus->isVisible() && oldFocus->isEnabled() ) { |
85 | oldFocus->setFocus(); | 94 | oldFocus->setFocus(); |
86 | } else { | 95 | } else { |
87 | inFocus->clearFocus(); | 96 | inFocus->clearFocus(); |
88 | } | 97 | } |
89 | } | 98 | } |
90 | } | 99 | } |
91 | inFocus = 0; | 100 | inFocus = 0; |
92 | oldFocus = 0; | 101 | oldFocus = 0; |
93 | } | 102 | } |
94 | } | 103 | } |
95 | 104 | ||
96 | bool QPEMenuToolFocusManager::isActive() const | 105 | bool QPEMenuToolFocusManager::isActive() const |
97 | { | 106 | { |
98 | return !inFocus.isNull(); | 107 | return !inFocus.isNull(); |
99 | } | 108 | } |
100 | 109 | ||
101 | void QPEMenuToolFocusManager::moveFocus( bool next ) | 110 | void QPEMenuToolFocusManager::moveFocus( bool next ) |
102 | { | 111 | { |
103 | if ( !isActive() ) | 112 | if ( !isActive() ) |
104 | return; | 113 | return; |
105 | 114 | ||
106 | int n = list.count(); | 115 | int n = list.count(); |
107 | QValueList<GuardedWidget>::Iterator it; | 116 | QValueList<GuardedWidget>::Iterator it; |
108 | it = list.find( inFocus ); | 117 | it = list.find( inFocus ); |
109 | if ( it == list.end() ) | 118 | if ( it == list.end() ) |
110 | it = list.begin(); | 119 | it = list.begin(); |
111 | while ( --n ) { | 120 | while ( --n ) { |
112 | if ( next ) { | 121 | if ( next ) { |
113 | ++it; | 122 | ++it; |
114 | if ( it == list.end() ) | 123 | if ( it == list.end() ) |
115 | it = list.begin(); | 124 | it = list.begin(); |
116 | } else { | 125 | } else { |
117 | if ( it == list.begin() ) | 126 | if ( it == list.begin() ) |
118 | it = list.end(); | 127 | it = list.end(); |
119 | --it; | 128 | --it; |
120 | } | 129 | } |
121 | QWidget *w = (*it); | 130 | QWidget *w = (*it); |
122 | if ( w && w->isEnabled() && w->isVisible() && !w->inherits("QToolBarSeparator") && | 131 | if ( w && w->isEnabled() && w->isVisible() && !w->inherits("QToolBarSeparator") && |
123 | w->topLevelWidget() == qApp->activeWindow() ) { | 132 | w->topLevelWidget() == qApp->activeWindow() ) { |
124 | setFocus( w, next ); | 133 | setFocus( w, next ); |
125 | return; | 134 | return; |
126 | } | 135 | } |
127 | } | 136 | } |
128 | } | 137 | } |
129 | 138 | ||
130 | void QPEMenuToolFocusManager::initialize() | 139 | void QPEMenuToolFocusManager::initialize() |
131 | { | 140 | { |
132 | if ( !me ) | 141 | if ( !me ) |
133 | me = new QPEMenuToolFocusManager; | 142 | me = new QPEMenuToolFocusManager; |
134 | } | 143 | } |
135 | 144 | ||
136 | QPEMenuToolFocusManager *QPEMenuToolFocusManager::manager() | 145 | QPEMenuToolFocusManager *QPEMenuToolFocusManager::manager() |
137 | { | 146 | { |
138 | if ( !me ) | 147 | if ( !me ) |
139 | me = new QPEMenuToolFocusManager; | 148 | me = new QPEMenuToolFocusManager; |
140 | 149 | ||
141 | return me; | 150 | return me; |
142 | } | 151 | } |
143 | 152 | ||
144 | void QPEMenuToolFocusManager::setFocus( QWidget *w, bool next ) | 153 | void QPEMenuToolFocusManager::setFocus( QWidget *w, bool next ) |
145 | { | 154 | { |
146 | inFocus = w; | 155 | inFocus = w; |
147 | // qDebug( "Set focus on %s", w->className() ); | 156 | // qDebug( "Set focus on %s", w->className() ); |
148 | if ( inFocus->inherits( "QMenuBar" ) ) { | 157 | if ( inFocus->inherits( "QMenuBar" ) ) { |
149 | QMenuBar *mb = (QMenuBar *)(QWidget *)inFocus; | 158 | QMenuBar *mb = (QMenuBar *)(QWidget *)inFocus; |
150 | if ( next ) | 159 | if ( next ) |
151 | mb->activateItemAt( 0 ); | 160 | mb->activateItemAt( 0 ); |
152 | else | 161 | else |
153 | mb->activateItemAt( mb->count()-1 ); | 162 | mb->activateItemAt( mb->count()-1 ); |
154 | } | 163 | } |
155 | inFocus->setFocus(); | 164 | inFocus->setFocus(); |
156 | } | 165 | } |
157 | 166 | ||
158 | bool QPEMenuToolFocusManager::eventFilter( QObject *object, QEvent *event ) | 167 | bool QPEMenuToolFocusManager::eventFilter( QObject *object, QEvent *event ) |
159 | { | 168 | { |
160 | if ( event->type() == QEvent::KeyPress ) { | 169 | if ( event->type() == QEvent::KeyPress ) { |
161 | QKeyEvent *ke = (QKeyEvent *)event; | 170 | QKeyEvent *ke = (QKeyEvent *)event; |
162 | if ( isActive() ) { | 171 | if ( isActive() ) { |
163 | if ( object->inherits( "QButton" ) ) { | 172 | if ( object->inherits( "QButton" ) ) { |
164 | switch ( ke->key() ) { | 173 | switch ( ke->key() ) { |
165 | case Key_Left: | 174 | case Key_Left: |
166 | moveFocus( FALSE ); | 175 | moveFocus( FALSE ); |
167 | return TRUE; | 176 | return TRUE; |
168 | 177 | ||
169 | case Key_Right: | 178 | case Key_Right: |
170 | moveFocus( TRUE ); | 179 | moveFocus( TRUE ); |
171 | return TRUE; | 180 | return TRUE; |
172 | 181 | ||
173 | case Key_Up: | 182 | case Key_Up: |
174 | case Key_Down: | 183 | case Key_Down: |
175 | return TRUE; | 184 | return TRUE; |
176 | } | 185 | } |
177 | } else if ( object->inherits( "QPopupMenu" ) ) { | 186 | } else if ( object->inherits( "QPopupMenu" ) ) { |
178 | // Deactivate when a menu item is selected | 187 | // Deactivate when a menu item is selected |
179 | if ( ke->key() == Key_Enter || ke->key() == Key_Return || | 188 | if ( ke->key() == Key_Enter || ke->key() == Key_Return || |
180 | ke->key() == Key_Escape ) { | 189 | ke->key() == Key_Escape ) { |
181 | QTimer::singleShot( 0, this, SLOT(deactivate()) ); | 190 | QTimer::singleShot( 0, this, SLOT(deactivate()) ); |
182 | } | 191 | } |
183 | } else if ( object->inherits( "QMenuBar" ) ) { | 192 | } else if ( object->inherits( "QMenuBar" ) ) { |
184 | int dx = 0; | 193 | int dx = 0; |
185 | switch ( ke->key() ) { | 194 | switch ( ke->key() ) { |
186 | case Key_Left: | 195 | case Key_Left: |
187 | dx = -1; | 196 | dx = -1; |
188 | break; | 197 | break; |
189 | 198 | ||
190 | case Key_Right: | 199 | case Key_Right: |
191 | dx = 1; | 200 | dx = 1; |
192 | break; | 201 | break; |
193 | } | 202 | } |
194 | 203 | ||
195 | QMenuBarHack *mb = (QMenuBarHack *)object; | 204 | QMenuBarHack *mb = (QMenuBarHack *)object; |
196 | if ( dx && mb->activeItem() >= 0 ) { | 205 | if ( dx && mb->activeItem() >= 0 ) { |
197 | int i = mb->activeItem(); | 206 | int i = mb->activeItem(); |
198 | int c = mb->count(); | 207 | int c = mb->count(); |
199 | int n = c; | 208 | int n = c; |
200 | while ( n-- ) { | 209 | while ( n-- ) { |
201 | i = i + dx; | 210 | i = i + dx; |
202 | if ( i == c ) { | 211 | if ( i == c ) { |
203 | mb->goodbye(); | 212 | mb->goodbye(); |
204 | moveFocus( TRUE ); | 213 | moveFocus( TRUE ); |
205 | return TRUE; | 214 | return TRUE; |
206 | } else if ( i < 0 ) { | 215 | } else if ( i < 0 ) { |
207 | mb->goodbye(); | 216 | mb->goodbye(); |
208 | moveFocus( FALSE ); | 217 | moveFocus( FALSE ); |
209 | return TRUE; | 218 | return TRUE; |
210 | } | 219 | } |
211 | QMenuItem *mi = mb->findItem( mb->idAt(i) ); | 220 | QMenuItem *mi = mb->findItem( mb->idAt(i) ); |
212 | if ( mi->isEnabled() && !mi->isSeparator() ) { | 221 | if ( mi->isEnabled() && !mi->isSeparator() ) { |
213 | break; | 222 | break; |
214 | } | 223 | } |
215 | } | 224 | } |
216 | } | 225 | } |
217 | } | 226 | } |
218 | } | 227 | } |
219 | if ( ke->key() == Key_F11 ) { | 228 | if ( ke->key() == Key_F11 ) { |
220 | setActive( !isActive() ); | 229 | setActive( !isActive() ); |
221 | return TRUE; | 230 | return TRUE; |
222 | } | 231 | } |
223 | } else if ( event->type() == QEvent::KeyRelease ) { | 232 | } else if ( event->type() == QEvent::KeyRelease ) { |
224 | QKeyEvent *ke = (QKeyEvent *)event; | 233 | QKeyEvent *ke = (QKeyEvent *)event; |
225 | if ( isActive() ) { | 234 | if ( isActive() ) { |
226 | if ( object->inherits( "QButton" ) ) { | 235 | if ( object->inherits( "QButton" ) ) { |
227 | // Deactivate when a button is selected | 236 | // Deactivate when a button is selected |
228 | if ( ke->key() == Key_Space ) | 237 | if ( ke->key() == Key_Space ) |
229 | QTimer::singleShot( 0, this, SLOT(deactivate()) ); | 238 | QTimer::singleShot( 0, this, SLOT(deactivate()) ); |
230 | } | 239 | } |
231 | } | 240 | } |
232 | } else if ( event->type() == QEvent::FocusIn ) { | 241 | } else if ( event->type() == QEvent::FocusIn ) { |
233 | if ( isActive() ) { | 242 | if ( isActive() ) { |
234 | // A non-menu/tool widget has been selected - we're deactivated | 243 | // A non-menu/tool widget has been selected - we're deactivated |
235 | QWidget *w = (QWidget *)object; | 244 | QWidget *w = (QWidget *)object; |
236 | if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) { | 245 | if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) { |
237 | inFocus = 0; | 246 | inFocus = 0; |
238 | } | 247 | } |
239 | } | 248 | } |
240 | } else if ( event->type() == QEvent::Hide ) { | 249 | } else if ( event->type() == QEvent::Hide ) { |
241 | if ( isActive() ) { | 250 | if ( isActive() ) { |
242 | // Deaticvate if a menu/tool has been hidden | 251 | // Deaticvate if a menu/tool has been hidden |
243 | QWidget *w = (QWidget *)object; | 252 | QWidget *w = (QWidget *)object; |
244 | if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) { | 253 | if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) { |
245 | setActive( FALSE ); | 254 | setActive( FALSE ); |
246 | } | 255 | } |
247 | } | 256 | } |
248 | } else if ( event->type() == QEvent::ChildInserted ) { | 257 | } else if ( event->type() == QEvent::ChildInserted ) { |
249 | QChildEvent *ce = (QChildEvent *)event; | 258 | QChildEvent *ce = (QChildEvent *)event; |
250 | if ( ce->child()->isWidgetType() ) { | 259 | if ( ce->child()->isWidgetType() ) { |
251 | if ( ce->child()->inherits( "QMenuBar" ) ) { | 260 | if ( ce->child()->inherits( "QMenuBar" ) ) { |
252 | addWidget( (QWidget *)ce->child() ); | 261 | addWidget( (QWidget *)ce->child() ); |
253 | ce->child()->installEventFilter( this ); | 262 | ce->child()->installEventFilter( this ); |
254 | } else if ( object->inherits( "QToolBar" ) ) { | 263 | } else if ( object->inherits( "QToolBar" ) ) { |
255 | addWidget( (QWidget *)ce->child() ); | 264 | addWidget( (QWidget *)ce->child() ); |
256 | } | 265 | } |
257 | } | 266 | } |
258 | } else if ( event->type() == QEvent::ChildRemoved ) { | 267 | } else if ( event->type() == QEvent::ChildRemoved ) { |
259 | QChildEvent *ce = (QChildEvent *)event; | 268 | QChildEvent *ce = (QChildEvent *)event; |
260 | if ( ce->child()->isWidgetType() ) { | 269 | if ( ce->child()->isWidgetType() ) { |
261 | if ( ce->child()->inherits( "QMenuBar" ) ) { | 270 | if ( ce->child()->inherits( "QMenuBar" ) ) { |
262 | removeWidget( (QWidget *)ce->child() ); | 271 | removeWidget( (QWidget *)ce->child() ); |
263 | ce->child()->removeEventFilter( this ); | 272 | ce->child()->removeEventFilter( this ); |
264 | } else if ( object->inherits( "QToolBar" ) ) { | 273 | } else if ( object->inherits( "QToolBar" ) ) { |
265 | removeWidget( (QWidget *)ce->child() ); | 274 | removeWidget( (QWidget *)ce->child() ); |
266 | } | 275 | } |
267 | } | 276 | } |
268 | } | 277 | } |
269 | 278 | ||
270 | return FALSE; | 279 | return FALSE; |
271 | } | 280 | } |
272 | 281 | ||
273 | void QPEMenuToolFocusManager::deactivate() | 282 | void QPEMenuToolFocusManager::deactivate() |
274 | { | 283 | { |
275 | setActive( FALSE ); | 284 | setActive( FALSE ); |
276 | } | 285 | } |
277 | 286 | ||
278 | /*! | 287 | /*! |
279 | \class QPEMenuBar qpemenubar.h | 288 | \class QPEMenuBar qpemenubar.h |
280 | \brief The QPEMenuBar class is obsolete. Use QMenuBar instead. | 289 | \brief The QPEMenuBar class is obsolete. Use QMenuBar instead. |
281 | 290 | ||
282 | \obsolete | 291 | \obsolete |
283 | 292 | ||
284 | This class is obsolete. Use QMenuBar instead. | 293 | This class is obsolete. Use QMenuBar instead. |
285 | 294 | ||
286 | */ | 295 | */ |
287 | 296 | ||
288 | /*! | 297 | /*! |
289 | Constructs a QPEMenuBar just as you would construct | 298 | Constructs a QPEMenuBar just as you would construct |
290 | a QMenuBar, passing \a parent and \a name. | 299 | a QMenuBar, passing \a parent and \a name. |
291 | */ | 300 | */ |
292 | QPEMenuBar::QPEMenuBar( QWidget *parent, const char *name ) | 301 | QPEMenuBar::QPEMenuBar( QWidget *parent, const char *name ) |
293 | : QMenuBar( parent, name ) | 302 | : QMenuBar( parent, name ) |
294 | { | 303 | { |
295 | } | 304 | } |
296 | 305 | ||
297 | /*! | 306 | /*! |
298 | \reimp | 307 | \reimp |
299 | */ | 308 | */ |
300 | QPEMenuBar::~QPEMenuBar() | 309 | QPEMenuBar::~QPEMenuBar() |
301 | { | 310 | { |
302 | } | 311 | } |