summaryrefslogtreecommitdiff
path: root/library/qpemenubar.cpp
Unidiff
Diffstat (limited to 'library/qpemenubar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpemenubar.cpp1
1 files changed, 0 insertions, 1 deletions
diff --git a/library/qpemenubar.cpp b/library/qpemenubar.cpp
index 3e5bad5..1d8eff4 100644
--- a/library/qpemenubar.cpp
+++ b/library/qpemenubar.cpp
@@ -1,330 +1,329 @@
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>
26#include <qtimer.h> 25#include <qtimer.h>
27 26
28 27
29class QMenuBarHack : public QMenuBar 28class QMenuBarHack : public QMenuBar
30{ 29{
31public: 30public:
32 int activeItem() const { return actItem; } 31 int activeItem() const { return actItem; }
33 32
34 void goodbye() 33 void goodbye()
35 { 34 {
36 activateItemAt(-1); 35 activateItemAt(-1);
37 for ( unsigned int i = 0; i < count(); i++ ) { 36 for ( unsigned int i = 0; i < count(); i++ ) {
38 QMenuItem *mi = findItem( idAt(i) ); 37 QMenuItem *mi = findItem( idAt(i) );
39 if ( mi->popup() ) { 38 if ( mi->popup() ) {
40 mi->popup()->hide(); 39 mi->popup()->hide();
41 } 40 }
42 } 41 }
43 } 42 }
44}; 43};
45 44
46 45
47// Sharp ROM compatibility 46// Sharp ROM compatibility
48void QPEMenuToolFocusManager::setMenukeyEnabled ( bool ) 47void QPEMenuToolFocusManager::setMenukeyEnabled ( bool )
49{ 48{
50} 49}
51int QPEMenuBar::getOldFocus ( ) 50int QPEMenuBar::getOldFocus ( )
52{ 51{
53 return 0; 52 return 0;
54} 53}
55 54
56QPEMenuToolFocusManager *QPEMenuToolFocusManager::me = 0; 55QPEMenuToolFocusManager *QPEMenuToolFocusManager::me = 0;
57 56
58QPEMenuToolFocusManager::QPEMenuToolFocusManager() : QObject() 57QPEMenuToolFocusManager::QPEMenuToolFocusManager() : QObject()
59{ 58{
60 qApp->installEventFilter( this ); 59 qApp->installEventFilter( this );
61} 60}
62 61
63void QPEMenuToolFocusManager::addWidget( QWidget *w ) 62void QPEMenuToolFocusManager::addWidget( QWidget *w )
64{ 63{
65 list.append( GuardedWidget(w) ); 64 list.append( GuardedWidget(w) );
66} 65}
67 66
68void QPEMenuToolFocusManager::removeWidget( QWidget *w ) 67void QPEMenuToolFocusManager::removeWidget( QWidget *w )
69{ 68{
70 list.remove( GuardedWidget(w) ); 69 list.remove( GuardedWidget(w) );
71} 70}
72 71
73void QPEMenuToolFocusManager::setActive( bool a ) 72void QPEMenuToolFocusManager::setActive( bool a )
74{ 73{
75 if ( a ) { 74 if ( a ) {
76 oldFocus = qApp->focusWidget(); 75 oldFocus = qApp->focusWidget();
77 QValueList<GuardedWidget>::Iterator it; 76 QValueList<GuardedWidget>::Iterator it;
78 it = list.begin(); 77 it = list.begin();
79 while ( it != list.end() ) { 78 while ( it != list.end() ) {
80 QWidget *w = (*it); 79 QWidget *w = (*it);
81 if ( w && w->isEnabled() && w->isVisible() && 80 if ( w && w->isEnabled() && w->isVisible() &&
82 w->topLevelWidget() == qApp->activeWindow() ) { 81 w->topLevelWidget() == qApp->activeWindow() ) {
83 setFocus( w ); 82 setFocus( w );
84 return; 83 return;
85 } 84 }
86 ++it; 85 ++it;
87 } 86 }
88 } else { 87 } else {
89 if ( inFocus ) { 88 if ( inFocus ) {
90 if ( inFocus->inherits( "QMenuBar" ) ) 89 if ( inFocus->inherits( "QMenuBar" ) )
91 ((QMenuBarHack *)(QWidget *)inFocus)->goodbye(); 90 ((QMenuBarHack *)(QWidget *)inFocus)->goodbye();
92 if ( inFocus->hasFocus() ) { 91 if ( inFocus->hasFocus() ) {
93 if ( oldFocus && oldFocus->isVisible() && oldFocus->isEnabled() ) { 92 if ( oldFocus && oldFocus->isVisible() && oldFocus->isEnabled() ) {
94 oldFocus->setFocus(); 93 oldFocus->setFocus();
95 } else { 94 } else {
96 inFocus->clearFocus(); 95 inFocus->clearFocus();
97 } 96 }
98 } 97 }
99 } 98 }
100 inFocus = 0; 99 inFocus = 0;
101 oldFocus = 0; 100 oldFocus = 0;
102 } 101 }
103} 102}
104 103
105bool QPEMenuToolFocusManager::isActive() const 104bool QPEMenuToolFocusManager::isActive() const
106{ 105{
107 return !inFocus.isNull(); 106 return !inFocus.isNull();
108} 107}
109 108
110void QPEMenuToolFocusManager::moveFocus( bool next ) 109void QPEMenuToolFocusManager::moveFocus( bool next )
111{ 110{
112 if ( !isActive() ) 111 if ( !isActive() )
113 return; 112 return;
114 113
115 int n = list.count(); 114 int n = list.count();
116 QValueList<GuardedWidget>::Iterator it; 115 QValueList<GuardedWidget>::Iterator it;
117 it = list.find( inFocus ); 116 it = list.find( inFocus );
118 if ( it == list.end() ) 117 if ( it == list.end() )
119 it = list.begin(); 118 it = list.begin();
120 while ( --n ) { 119 while ( --n ) {
121 if ( next ) { 120 if ( next ) {
122 ++it; 121 ++it;
123 if ( it == list.end() ) 122 if ( it == list.end() )
124 it = list.begin(); 123 it = list.begin();
125 } else { 124 } else {
126 if ( it == list.begin() ) 125 if ( it == list.begin() )
127 it = list.end(); 126 it = list.end();
128 --it; 127 --it;
129 } 128 }
130 QWidget *w = (*it); 129 QWidget *w = (*it);
131 if ( w && w->isEnabled() && w->isVisible() && !w->inherits("QToolBarSeparator") && 130 if ( w && w->isEnabled() && w->isVisible() && !w->inherits("QToolBarSeparator") &&
132 w->topLevelWidget() == qApp->activeWindow() ) { 131 w->topLevelWidget() == qApp->activeWindow() ) {
133 setFocus( w, next ); 132 setFocus( w, next );
134 return; 133 return;
135 } 134 }
136 } 135 }
137} 136}
138 137
139void QPEMenuToolFocusManager::initialize() 138void QPEMenuToolFocusManager::initialize()
140{ 139{
141 if ( !me ) 140 if ( !me )
142 me = new QPEMenuToolFocusManager; 141 me = new QPEMenuToolFocusManager;
143} 142}
144 143
145QPEMenuToolFocusManager *QPEMenuToolFocusManager::manager() 144QPEMenuToolFocusManager *QPEMenuToolFocusManager::manager()
146{ 145{
147 if ( !me ) 146 if ( !me )
148 me = new QPEMenuToolFocusManager; 147 me = new QPEMenuToolFocusManager;
149 148
150 return me; 149 return me;
151} 150}
152 151
153void QPEMenuToolFocusManager::setFocus( QWidget *w, bool next ) 152void QPEMenuToolFocusManager::setFocus( QWidget *w, bool next )
154{ 153{
155 inFocus = w; 154 inFocus = w;
156// qDebug( "Set focus on %s", w->className() ); 155// qDebug( "Set focus on %s", w->className() );
157 if ( inFocus->inherits( "QMenuBar" ) ) { 156 if ( inFocus->inherits( "QMenuBar" ) ) {
158 QMenuBar *mb = (QMenuBar *)(QWidget *)inFocus; 157 QMenuBar *mb = (QMenuBar *)(QWidget *)inFocus;
159 if ( next ) 158 if ( next )
160 mb->activateItemAt( 0 ); 159 mb->activateItemAt( 0 );
161 else 160 else
162 mb->activateItemAt( mb->count()-1 ); 161 mb->activateItemAt( mb->count()-1 );
163 } 162 }
164 inFocus->setFocus(); 163 inFocus->setFocus();
165} 164}
166 165
167bool QPEMenuToolFocusManager::eventFilter( QObject *object, QEvent *event ) 166bool QPEMenuToolFocusManager::eventFilter( QObject *object, QEvent *event )
168{ 167{
169 if ( event->type() == QEvent::KeyPress ) { 168 if ( event->type() == QEvent::KeyPress ) {
170 QKeyEvent *ke = (QKeyEvent *)event; 169 QKeyEvent *ke = (QKeyEvent *)event;
171 if ( isActive() ) { 170 if ( isActive() ) {
172 if ( object->inherits( "QButton" ) ) { 171 if ( object->inherits( "QButton" ) ) {
173 switch ( ke->key() ) { 172 switch ( ke->key() ) {
174 case Key_Left: 173 case Key_Left:
175 moveFocus( FALSE ); 174 moveFocus( FALSE );
176 return TRUE; 175 return TRUE;
177 176
178 case Key_Right: 177 case Key_Right:
179 moveFocus( TRUE ); 178 moveFocus( TRUE );
180 return TRUE; 179 return TRUE;
181 180
182 case Key_Up: 181 case Key_Up:
183 case Key_Down: 182 case Key_Down:
184 return TRUE; 183 return TRUE;
185 } 184 }
186 } else if ( object->inherits( "QPopupMenu" ) ) { 185 } else if ( object->inherits( "QPopupMenu" ) ) {
187 // Deactivate when a menu item is selected 186 // Deactivate when a menu item is selected
188 if ( ke->key() == Key_Enter || ke->key() == Key_Return || 187 if ( ke->key() == Key_Enter || ke->key() == Key_Return ||
189 ke->key() == Key_Escape ) { 188 ke->key() == Key_Escape ) {
190 QTimer::singleShot( 0, this, SLOT(deactivate()) ); 189 QTimer::singleShot( 0, this, SLOT(deactivate()) );
191 } 190 }
192 } else if ( object->inherits( "QMenuBar" ) ) { 191 } else if ( object->inherits( "QMenuBar" ) ) {
193 int dx = 0; 192 int dx = 0;
194 switch ( ke->key() ) { 193 switch ( ke->key() ) {
195 case Key_Left: 194 case Key_Left:
196 dx = -1; 195 dx = -1;
197 break; 196 break;
198 197
199 case Key_Right: 198 case Key_Right:
200 dx = 1; 199 dx = 1;
201 break; 200 break;
202 } 201 }
203 202
204 QMenuBarHack *mb = (QMenuBarHack *)object; 203 QMenuBarHack *mb = (QMenuBarHack *)object;
205 if ( dx && mb->activeItem() >= 0 ) { 204 if ( dx && mb->activeItem() >= 0 ) {
206 int i = mb->activeItem(); 205 int i = mb->activeItem();
207 int c = mb->count(); 206 int c = mb->count();
208 int n = c; 207 int n = c;
209 while ( n-- ) { 208 while ( n-- ) {
210 i = i + dx; 209 i = i + dx;
211 if ( i == c ) { 210 if ( i == c ) {
212 mb->goodbye(); 211 mb->goodbye();
213 moveFocus( TRUE ); 212 moveFocus( TRUE );
214 return TRUE; 213 return TRUE;
215 } else if ( i < 0 ) { 214 } else if ( i < 0 ) {
216 mb->goodbye(); 215 mb->goodbye();
217 moveFocus( FALSE ); 216 moveFocus( FALSE );
218 return TRUE; 217 return TRUE;
219 } 218 }
220 QMenuItem *mi = mb->findItem( mb->idAt(i) ); 219 QMenuItem *mi = mb->findItem( mb->idAt(i) );
221 if ( mi->isEnabled() && !mi->isSeparator() ) { 220 if ( mi->isEnabled() && !mi->isSeparator() ) {
222 break; 221 break;
223 } 222 }
224 } 223 }
225 } 224 }
226 } 225 }
227 } 226 }
228 } else if ( event->type() == QEvent::KeyRelease ) { 227 } else if ( event->type() == QEvent::KeyRelease ) {
229 QKeyEvent *ke = (QKeyEvent *)event; 228 QKeyEvent *ke = (QKeyEvent *)event;
230 if ( isActive() ) { 229 if ( isActive() ) {
231 if ( object->inherits( "QButton" ) ) { 230 if ( object->inherits( "QButton" ) ) {
232 // Deactivate when a button is selected 231 // Deactivate when a button is selected
233 if ( ke->key() == Key_Space ) 232 if ( ke->key() == Key_Space )
234 QTimer::singleShot( 0, this, SLOT(deactivate()) ); 233 QTimer::singleShot( 0, this, SLOT(deactivate()) );
235 } 234 }
236 } 235 }
237 } else if ( event->type() == QEvent::FocusIn ) { 236 } else if ( event->type() == QEvent::FocusIn ) {
238 if ( isActive() ) { 237 if ( isActive() ) {
239 // A non-menu/tool widget has been selected - we're deactivated 238 // A non-menu/tool widget has been selected - we're deactivated
240 QWidget *w = (QWidget *)object; 239 QWidget *w = (QWidget *)object;
241 if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) { 240 if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) {
242 inFocus = 0; 241 inFocus = 0;
243 } 242 }
244 } 243 }
245 } else if ( event->type() == QEvent::Hide ) { 244 } else if ( event->type() == QEvent::Hide ) {
246 if ( isActive() ) { 245 if ( isActive() ) {
247 // Deaticvate if a menu/tool has been hidden 246 // Deaticvate if a menu/tool has been hidden
248 QWidget *w = (QWidget *)object; 247 QWidget *w = (QWidget *)object;
249 if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) { 248 if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) {
250 setActive( FALSE ); 249 setActive( FALSE );
251 } 250 }
252 } 251 }
253 } else if ( event->type() == QEvent::ChildInserted ) { 252 } else if ( event->type() == QEvent::ChildInserted ) {
254 QChildEvent *ce = (QChildEvent *)event; 253 QChildEvent *ce = (QChildEvent *)event;
255 if ( ce->child()->isWidgetType() ) { 254 if ( ce->child()->isWidgetType() ) {
256 if ( ce->child()->inherits( "QMenuBar" ) ) { 255 if ( ce->child()->inherits( "QMenuBar" ) ) {
257 addWidget( (QWidget *)ce->child() ); 256 addWidget( (QWidget *)ce->child() );
258 ce->child()->installEventFilter( this ); 257 ce->child()->installEventFilter( this );
259 } else if ( object->inherits( "QToolBar" ) ) { 258 } else if ( object->inherits( "QToolBar" ) ) {
260 addWidget( (QWidget *)ce->child() ); 259 addWidget( (QWidget *)ce->child() );
261 } 260 }
262 } 261 }
263 } else if ( event->type() == QEvent::ChildRemoved ) { 262 } else if ( event->type() == QEvent::ChildRemoved ) {
264 QChildEvent *ce = (QChildEvent *)event; 263 QChildEvent *ce = (QChildEvent *)event;
265 if ( ce->child()->isWidgetType() ) { 264 if ( ce->child()->isWidgetType() ) {
266 if ( ce->child()->inherits( "QMenuBar" ) ) { 265 if ( ce->child()->inherits( "QMenuBar" ) ) {
267 removeWidget( (QWidget *)ce->child() ); 266 removeWidget( (QWidget *)ce->child() );
268 ce->child()->removeEventFilter( this ); 267 ce->child()->removeEventFilter( this );
269 } else if ( object->inherits( "QToolBar" ) ) { 268 } else if ( object->inherits( "QToolBar" ) ) {
270 removeWidget( (QWidget *)ce->child() ); 269 removeWidget( (QWidget *)ce->child() );
271 } 270 }
272 } 271 }
273 } 272 }
274 273
275 return FALSE; 274 return FALSE;
276} 275}
277 276
278void QPEMenuToolFocusManager::deactivate() 277void QPEMenuToolFocusManager::deactivate()
279{ 278{
280 setActive( FALSE ); 279 setActive( FALSE );
281} 280}
282 281
283/*! 282/*!
284 \class QPEMenuBar qpemenubar.h 283 \class QPEMenuBar qpemenubar.h
285 \brief The QPEMenuBar class is obsolete. Use QMenuBar instead. 284 \brief The QPEMenuBar class is obsolete. Use QMenuBar instead.
286 285
287 \obsolete 286 \obsolete
288 287
289 This class is obsolete. Use QMenuBar instead. 288 This class is obsolete. Use QMenuBar instead.
290 289
291*/ 290*/
292 291
293/*! 292/*!
294 Constructs a QPEMenuBar just as you would construct 293 Constructs a QPEMenuBar just as you would construct
295 a QMenuBar, passing \a parent and \a name. 294 a QMenuBar, passing \a parent and \a name.
296*/ 295*/
297QPEMenuBar::QPEMenuBar( QWidget *parent, const char *name ) 296QPEMenuBar::QPEMenuBar( QWidget *parent, const char *name )
298 : QMenuBar( parent, name ) 297 : QMenuBar( parent, name )
299{ 298{
300} 299}
301 300
302/*! 301/*!
303 \reimp 302 \reimp
304*/ 303*/
305QPEMenuBar::~QPEMenuBar() 304QPEMenuBar::~QPEMenuBar()
306{ 305{
307} 306}
308 307
309/*! 308/*!
310 \internal 309 \internal
311*/ 310*/
312void QPEMenuBar::keyPressEvent( QKeyEvent *e ) 311void QPEMenuBar::keyPressEvent( QKeyEvent *e )
313{ 312{
314 QMenuBar::keyPressEvent( e ); 313 QMenuBar::keyPressEvent( e );
315} 314}
316 315
317/*! 316/*!
318 \internal 317 \internal
319*/ 318*/
320void QPEMenuBar::activateItem( int index ) { 319void QPEMenuBar::activateItem( int index ) {
321 activateItemAt( index ); 320 activateItemAt( index );
322} 321}
323void QPEMenuBar::goodbye() { 322void QPEMenuBar::goodbye() {
324 activateItemAt(-1); 323 activateItemAt(-1);
325 for ( uint i = 0; i < count(); i++ ) { 324 for ( uint i = 0; i < count(); i++ ) {
326 QMenuItem* mi = findItem( idAt(i) ); 325 QMenuItem* mi = findItem( idAt(i) );
327 if (mi->popup() ) 326 if (mi->popup() )
328 mi->popup()->hide(); 327 mi->popup()->hide();
329 } 328 }
330} 329}