diff options
author | axis <qt-info@nokia.com> | 2009-09-30 09:41:09 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-09-30 13:31:26 (GMT) |
commit | 5dadf715a40189c94235e8445dc79f0270b0a87e (patch) | |
tree | 5577577134b817147772b3209f844e947c51e3a8 /src/gui/kernel/qapplication_s60.cpp | |
parent | 8c4b3937511c8e960f9c03f1c711005aef49d982 (diff) | |
download | Qt-5dadf715a40189c94235e8445dc79f0270b0a87e.zip Qt-5dadf715a40189c94235e8445dc79f0270b0a87e.tar.gz Qt-5dadf715a40189c94235e8445dc79f0270b0a87e.tar.bz2 |
Fixed some focus issues on Symbian.
There are really two bugs that are fixed in this commit:
- SetFocus() in Symbian does not automatically clear focus on the
previously focused control, so we have to remember that control and
clear it ourselves.
- Symbian assumes that it is always the control at the top of the
control stack that should have focus, and if this isn't the case,
focus may or may not work depending on whether Symbian has had a
chance to reset the focus or not. Therefore, whenever we change
focus on a control, we have to also readd that control to the top
of the stack, to ensure that it stays focused.
RevBy: Janne Anttila
Diffstat (limited to 'src/gui/kernel/qapplication_s60.cpp')
-rw-r--r-- | src/gui/kernel/qapplication_s60.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 498b1e7..1e78079 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -91,6 +91,8 @@ extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp QWidget *qt_button_down = 0; // widget got last button-down +QSymbianControl *QSymbianControl::lastFocusedControl = 0; + QS60Data* qGlobalS60Data() { return qt_s60Data(); @@ -337,6 +339,7 @@ QSymbianControl::~QSymbianControl() { if (S60->curWin == this) S60->curWin = 0; + setFocusSafely(false); S60->appUi()->RemoveFromStack(this); delete m_longTapDetector; } @@ -845,8 +848,8 @@ void QSymbianControl::FocusChanged(TDrawNow /* aDrawNow */) || (qwidget->windowType() & Qt::Popup) == Qt::Popup) return; - if (IsFocused()) { - QApplication::setActiveWindow(qwidget); + if (IsFocused() && IsVisible()) { + QApplication::setActiveWindow(qwidget->window()); #ifdef Q_WS_S60 // If widget is fullscreen, hide status pane and button container // otherwise show them. @@ -858,9 +861,10 @@ void QSymbianControl::FocusChanged(TDrawNow /* aDrawNow */) if (buttonGroup && (buttonGroup->IsVisible() == isFullscreen)) buttonGroup->MakeVisible(!isFullscreen); #endif - } else { + } else if (QApplication::activeWindow() == qwidget->window()) { QApplication::setActiveWindow(0); } + // else { We don't touch the active window unless we were explicitly activated or deactivated } } void QSymbianControl::HandleResourceChange(int resourceType) @@ -904,6 +908,31 @@ TTypeUid::Ptr QSymbianControl::MopSupplyObject(TTypeUid id) return CCoeControl::MopSupplyObject(id); } +void QSymbianControl::setFocusSafely(bool focus) +{ + // The stack hack in here is very unfortunate, but it is the only way to ensure proper + // focus in Symbian. If this is not executed, the control which happens to be on + // the top of the stack may randomly be assigned focus by Symbian, for example + // when creating new windows (specifically in CCoeAppUi::HandleStackChanged()). + if (focus) { + S60->appUi()->RemoveFromStack(this); + // Symbian doesn't automatically remove focus from the last focused control, so we need to + // remember it and clear focus ourselves. + if (lastFocusedControl && lastFocusedControl != this) + lastFocusedControl->SetFocus(false); + QT_TRAP_THROWING(S60->appUi()->AddToStackL(this, + ECoeStackPriorityDefault + 1, ECoeStackFlagStandard)); // Note the + 1 + lastFocusedControl = this; + this->SetFocus(true); + } else { + S60->appUi()->RemoveFromStack(this); + QT_TRAP_THROWING(S60->appUi()->AddToStackL(this, + ECoeStackPriorityDefault, ECoeStackFlagStandard)); + lastFocusedControl = 0; + this->SetFocus(false); + } +} + /*! \typedef QApplication::QS60MainApplicationFactory |