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,217 +1,216 @@
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 );