From a7273386adb9399ecdc7b7c8f4b041099db042ef Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Thu, 1 Oct 2009 12:41:23 +0200 Subject: Fix crash in S60 input methods after task switching When switching away from the application, the focused widget is set to null. When switching back, there are callbacks from S60 before the focus has been restored. These functions check for null widget, but the output function parameters are left uninitialised, which causes a crash inside the S60 FEP. 1) GetXYZ functions now initialise the output parameters even when the focused widget is null. 2) Return no input capability when there is no focused widget, as was already done during destruction. This stops most of the callbacks from S60. Task-number: QTBUG-4618 Reviewed-by: axis --- src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index fc55a0f..c4d17ff 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -222,7 +222,7 @@ void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event) TCoeInputCapabilities QCoeFepInputContext::inputCapabilities() { - if (m_inDestruction) { + if (m_inDestruction || !focusWidget()) { return TCoeInputCapabilities(TCoeInputCapabilities::ENone, 0, 0); } @@ -554,8 +554,10 @@ void QCoeFepInputContext::SetCursorSelectionForFepL(const TCursorSelection& aCur void QCoeFepInputContext::GetCursorSelectionForFep(TCursorSelection& aCursorSelection) const { QWidget *w = focusWidget(); - if (!w) + if (!w) { + aCursorSelection.SetSelection(0,0); return; + } int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt() + m_preeditString.size(); int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt() + m_preeditString.size(); @@ -567,8 +569,10 @@ void QCoeFepInputContext::GetEditorContentForFep(TDes& aEditorContent, TInt aDoc TInt aLengthToRetrieve) const { QWidget *w = focusWidget(); - if (!w) + if (!w) { + aEditorContent.FillZ(aLengthToRetrieve); return; + } QString text = w->inputMethodQuery(Qt::ImSurroundingText).value(); // FEP expects the preedit string to be part of the editor content, so let's mix it in. @@ -580,8 +584,10 @@ void QCoeFepInputContext::GetEditorContentForFep(TDes& aEditorContent, TInt aDoc void QCoeFepInputContext::GetFormatForFep(TCharFormat& aFormat, TInt /* aDocumentPosition */) const { QWidget *w = focusWidget(); - if (!w) + if (!w) { + aFormat = TCharFormat(); return; + } QFont font = w->inputMethodQuery(Qt::ImFont).value(); QFontMetrics metrics(font); @@ -595,8 +601,12 @@ void QCoeFepInputContext::GetScreenCoordinatesForFepL(TPoint& aLeftSideOfBaseLin TInt& aAscent, TInt /* aDocumentPosition */) const { QWidget *w = focusWidget(); - if (!w) + if (!w) { + aLeftSideOfBaseLine = TPoint(0,0); + aHeight = 0; + aAscent = 0; return; + } QRect rect = w->inputMethodQuery(Qt::ImMicroFocus).value(); aLeftSideOfBaseLine.iX = rect.left(); -- cgit v0.12