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