diff options
author | axis <qt-info@nokia.com> | 2009-05-04 07:22:47 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-05-05 06:34:11 (GMT) |
commit | ab7578d954c6b5ff496316246cab3644d6f688f1 (patch) | |
tree | b5ac0c85cd0b7d8571e200b36b8b100b5733fa80 /src | |
parent | 203b2b2c611e29ee18ee4f546b8695359710fd1b (diff) | |
download | Qt-ab7578d954c6b5ff496316246cab3644d6f688f1.zip Qt-ab7578d954c6b5ff496316246cab3644d6f688f1.tar.gz Qt-ab7578d954c6b5ff496316246cab3644d6f688f1.tar.bz2 |
Implemented support for input method hints in S60 FEP.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/inputmethod/qcoefepinputcontext_p.h | 3 | ||||
-rw-r--r-- | src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 114 |
2 files changed, 111 insertions, 6 deletions
diff --git a/src/gui/inputmethod/qcoefepinputcontext_p.h b/src/gui/inputmethod/qcoefepinputcontext_p.h index e4357c2..57f0375 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_p.h +++ b/src/gui/inputmethod/qcoefepinputcontext_p.h @@ -63,6 +63,7 @@ public: private: void commitCurrentString(); + void applyHints(Qt::InputMethodHints hints); // From MCoeFepAwareTextEditor public: @@ -98,6 +99,8 @@ private: QSymbianControl *m_parent; CAknEdwinState *m_fepState; QString m_preeditString; + Qt::InputMethodHints m_lastImHints; + TUint m_textCapabilities; bool m_isEditing; bool m_inDestruction; int m_cursorVisibility; diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index 5bf4259..643dc39 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -31,6 +31,8 @@ QT_BEGIN_NAMESPACE QCoeFepInputContext::QCoeFepInputContext(QObject *parent) : QInputContext(parent), m_fepState(new (ELeave) CAknEdwinState), + m_lastImHints(Qt::ImhNone), + m_textCapabilities(TCoeInputCapabilities::EAllText), m_isEditing(false), m_inDestruction(false), m_cursorVisibility(1), @@ -41,12 +43,10 @@ QCoeFepInputContext::QCoeFepInputContext(QObject *parent) m_fepState->SetObjectProvider(this); m_fepState->SetFlags(EAknEditorFlagDefault); m_fepState->SetDefaultInputMode( EAknEditorTextInputMode ); - m_fepState->SetCurrentInputMode( EAknEditorTextInputMode ); m_fepState->SetPermittedInputModes( EAknEditorAllInputModes ); m_fepState->SetLocalLanguage(ELangEnglish); m_fepState->SetDefaultLanguage(ELangEnglish); m_fepState->SetDefaultCase( EAknEditorLowerCase ); - m_fepState->SetCurrentCase( EAknEditorLowerCase ); m_fepState->SetPermittedCases( EAknEditorLowerCase|EAknEditorUpperCase ); m_fepState->SetSpecialCharacterTableResourceId( 0 ); m_fepState->SetNumericKeymap( EAknEditorStandardNumberModeKeymap ); @@ -74,7 +74,17 @@ void QCoeFepInputContext::reset() void QCoeFepInputContext::update() { - // For pre-5.0 SDKs, we don't do any work. + QWidget *w = focusWidget(); + if (w) { + Qt::InputMethodHints hints = w->inputMethodHints(); + if (hints != m_lastImHints) { + m_lastImHints = hints; + applyHints(hints); + CCoeEnv::Static()->InputCapabilitiesChanged(); + } + } + + // For pre-5.0 SDKs, we don't do text updates on S60 side. if (QSysInfo::s60Version() != QSysInfo::SV_S60_5_0) { return; } @@ -203,7 +213,22 @@ QString QCoeFepInputContext::language() bool QCoeFepInputContext::filterEvent(const QEvent *event) { - // For pre-5.0 SDKs, we don't do any work. + Q_ASSERT(focusWidget()); + + if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { + const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event); + Q_ASSERT(m_lastImHints == focusWidget()->inputMethodHints()); + if (keyEvent->key() == Qt::Key_F20 && m_lastImHints & Qt::ImhHiddenText) { + // Special case in Symbian. On editors with secret text, F20 is for some reason + // considered to be a backspace. + QKeyEvent modifiedEvent(keyEvent->type(), Qt::Key_Backspace, keyEvent->modifiers(), + keyEvent->text(), keyEvent->isAutoRepeat(), keyEvent->count()); + QApplication::sendEvent(focusWidget(), &modifiedEvent); + return true; + } + } + + // For pre-5.0 SDKs, we don't launch the keyboard. if (QSysInfo::s60Version() != QSysInfo::SV_S60_5_0) { return false; } @@ -211,7 +236,6 @@ bool QCoeFepInputContext::filterEvent(const QEvent *event) if (event->type() == QEvent::RequestSoftwareInputPanel) { // Notify S60 that we want the virtual keyboard to show up. QSymbianControl *sControl; - Q_ASSERT(focusWidget()); sControl = focusWidget()->effectiveWinId()->MopGetObject(sControl); Q_ASSERT(sControl); @@ -294,7 +318,7 @@ TCoeInputCapabilities QCoeFepInputContext::inputCapabilities() return TCoeInputCapabilities(TCoeInputCapabilities::ENone, 0, 0); } - return TCoeInputCapabilities(TCoeInputCapabilities::EAllText, this, 0); + return TCoeInputCapabilities(m_textCapabilities, this, 0); } static QTextCharFormat qt_TCharFormat2QTextCharFormat(const TCharFormat &cFormat) @@ -310,6 +334,84 @@ static QTextCharFormat qt_TCharFormat2QTextCharFormat(const TCharFormat &cFormat return qFormat; } +void QCoeFepInputContext::applyHints(Qt::InputMethodHints hints) +{ + using namespace Qt; + + // Some sanity checking. Just make sure that the preferred set is within + // the permitted set. + InputMethodHints prefs = ImhNumbersOnly | ImhUppercaseOnly | ImhLowercaseOnly; + prefs &= hints; + if (prefs != ImhNumbersOnly && prefs != ImhUppercaseOnly && prefs != ImhLowercaseOnly) { + hints &= ~prefs; + } + + bool noOnlys = !(hints & ImhNumbersOnly || hints & ImhUppercaseOnly + || hints & ImhLowercaseOnly); + TInt flags; + + if (hints & ImhPreferNumbers && noOnlys || hints & ImhNumbersOnly) { + m_fepState->SetDefaultInputMode(EAknEditorNumericInputMode); + } else { + m_fepState->SetDefaultInputMode(EAknEditorTextInputMode); + } + flags = 0; + if (hints & ImhNumbersOnly) { + flags |= EAknEditorNumericInputMode; + } + if (hints & ImhUppercaseOnly || hints & ImhLowercaseOnly) { + flags |= EAknEditorTextInputMode; + } + if (flags == 0) { + flags = EAknEditorAllInputModes; + } + m_fepState->SetPermittedInputModes(flags); + m_fepState->ReportAknEdStateEventL(MAknEdStateObserver::EAknEdwinStateInputModeUpdate); + + if (hints & ImhPreferLowercase && noOnlys || hints & ImhLowercaseOnly) { + m_fepState->SetDefaultCase(EAknEditorLowerCase); + } else if (hints & ImhPreferUppercase && noOnlys || hints & ImhUppercaseOnly) { + m_fepState->SetDefaultCase(EAknEditorUpperCase); + } else if (hints & ImhNoAutoUppercase) { + m_fepState->SetDefaultCase(EAknEditorLowerCase); + } else { + m_fepState->SetDefaultCase(EAknEditorTextCase); + } + flags = 0; + if (hints & ImhUppercaseOnly) { + flags |= EAknEditorUpperCase; + } + if (hints & ImhLowercaseOnly) { + flags |= EAknEditorLowerCase; + } + if (flags == 0) { + flags = EAknEditorAllCaseModes; + if (hints & ImhNoAutoUppercase) { + flags &= ~EAknEditorTextCase; + } + } + m_fepState->SetPermittedCases(flags); + m_fepState->ReportAknEdStateEventL(MAknEdStateObserver::EAknEdwinStateCaseModeUpdate); + + flags = 0; + if (hints & ImhUppercaseOnly && !(hints & ImhLowercaseOnly) + || hints & ImhLowercaseOnly && !(hints & ImhUppercaseOnly)) { + flags |= EAknEditorFlagFixedCase; + } + // Using T9 and hidden text together may actually crash the FEP, so check for hidden text too. + if (hints & ImhNoPredictiveText || hints & ImhHiddenText) { + flags |= EAknEditorFlagNoT9; + } + m_fepState->SetFlags(flags); + m_fepState->ReportAknEdStateEventL(MAknEdStateObserver::EAknEdwinStateFlagsUpdate); + + if (hints & ImhHiddenText) { + m_textCapabilities = TCoeInputCapabilities::EAllText | TCoeInputCapabilities::ESecretText; + } else { + m_textCapabilities = TCoeInputCapabilities::EAllText; + } +} + void QCoeFepInputContext::StartFepInlineEditL(const TDesC& aInitialInlineText, TInt aPositionOfInsertionPointInInlineText, TBool aCursorVisibility, const MFormCustomDraw* /*aCustomDraw*/, MFepInlineTextFormatRetriever& aInlineTextFormatRetriever, |