| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QT_NO_IM
|
|---|
| 43 |
|
|---|
| 44 | #include "qcoefepinputcontext_p.h"
|
|---|
| 45 | #include <qapplication.h>
|
|---|
| 46 | #include <qtextformat.h>
|
|---|
| 47 | #include <private/qcore_symbian_p.h>
|
|---|
| 48 |
|
|---|
| 49 | #include <fepitfr.h>
|
|---|
| 50 | #include <hal.h>
|
|---|
| 51 |
|
|---|
| 52 | #include <limits.h>
|
|---|
| 53 | // You only find these enumerations on SDK 5 onwards, so we need to provide our own
|
|---|
| 54 | // to remain compatible with older releases. They won't be called by pre-5.0 SDKs.
|
|---|
| 55 |
|
|---|
| 56 | // MAknEdStateObserver::EAknCursorPositionChanged
|
|---|
| 57 | #define QT_EAknCursorPositionChanged MAknEdStateObserver::EAknEdwinStateEvent(6)
|
|---|
| 58 | // MAknEdStateObserver::EAknActivatePenInputRequest
|
|---|
| 59 | #define QT_EAknActivatePenInputRequest MAknEdStateObserver::EAknEdwinStateEvent(7)
|
|---|
| 60 |
|
|---|
| 61 | QT_BEGIN_NAMESPACE
|
|---|
| 62 |
|
|---|
| 63 | QCoeFepInputContext::QCoeFepInputContext(QObject *parent)
|
|---|
| 64 | : QInputContext(parent),
|
|---|
| 65 | m_fepState(q_check_ptr(new CAknEdwinState)), // CBase derived object needs check on new
|
|---|
| 66 | m_lastImHints(Qt::ImhNone),
|
|---|
| 67 | m_textCapabilities(TCoeInputCapabilities::EAllText),
|
|---|
| 68 | m_inDestruction(false),
|
|---|
| 69 | m_pendingInputCapabilitiesChanged(false),
|
|---|
| 70 | m_cursorVisibility(1),
|
|---|
| 71 | m_inlinePosition(0),
|
|---|
| 72 | m_formatRetriever(0),
|
|---|
| 73 | m_pointerHandler(0),
|
|---|
| 74 | m_longPress(0),
|
|---|
| 75 | m_cursorPos(0)
|
|---|
| 76 | {
|
|---|
| 77 | m_fepState->SetObjectProvider(this);
|
|---|
| 78 | m_fepState->SetFlags(EAknEditorFlagDefault);
|
|---|
| 79 | m_fepState->SetDefaultInputMode( EAknEditorTextInputMode );
|
|---|
| 80 | m_fepState->SetPermittedInputModes( EAknEditorAllInputModes );
|
|---|
| 81 | m_fepState->SetDefaultCase( EAknEditorLowerCase );
|
|---|
| 82 | m_fepState->SetPermittedCases( EAknEditorLowerCase|EAknEditorUpperCase );
|
|---|
| 83 | m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG);
|
|---|
| 84 | m_fepState->SetNumericKeymap( EAknEditorStandardNumberModeKeymap );
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | QCoeFepInputContext::~QCoeFepInputContext()
|
|---|
| 88 | {
|
|---|
| 89 | m_inDestruction = true;
|
|---|
| 90 |
|
|---|
| 91 | // This is to make sure that the FEP manager "forgets" about us,
|
|---|
| 92 | // otherwise we may get callbacks even after we're destroyed.
|
|---|
| 93 | // The call below is essentially equivalent to InputCapabilitiesChanged(),
|
|---|
| 94 | // but is synchronous, rather than asynchronous.
|
|---|
| 95 | CCoeEnv::Static()->SyncNotifyFocusObserversOfChangeInFocus();
|
|---|
| 96 |
|
|---|
| 97 | if (m_fepState)
|
|---|
| 98 | delete m_fepState;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | void QCoeFepInputContext::reset()
|
|---|
| 102 | {
|
|---|
| 103 | CCoeFep* fep = CCoeEnv::Static()->Fep();
|
|---|
| 104 | if (fep)
|
|---|
| 105 | fep->CancelTransaction();
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | void QCoeFepInputContext::ReportAknEdStateEvent(MAknEdStateObserver::EAknEdwinStateEvent aEventType)
|
|---|
| 109 | {
|
|---|
| 110 | QT_TRAP_THROWING(m_fepState->ReportAknEdStateEventL(aEventType));
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | void QCoeFepInputContext::update()
|
|---|
| 114 | {
|
|---|
| 115 | updateHints(false);
|
|---|
| 116 |
|
|---|
| 117 | // For pre-5.0 SDKs, we don't do text updates on S60 side.
|
|---|
| 118 | if (QSysInfo::s60Version() != QSysInfo::SV_S60_5_0) {
|
|---|
| 119 | return;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | // Don't be fooled (as I was) by the name of this enumeration.
|
|---|
| 123 | // What it really does is tell the virtual keyboard UI that the text has been
|
|---|
| 124 | // updated and it should be reflected in the internal display of the VK.
|
|---|
| 125 | ReportAknEdStateEvent(QT_EAknCursorPositionChanged);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | void QCoeFepInputContext::setFocusWidget(QWidget *w)
|
|---|
| 129 | {
|
|---|
| 130 | commitCurrentString(false);
|
|---|
| 131 |
|
|---|
| 132 | QInputContext::setFocusWidget(w);
|
|---|
| 133 |
|
|---|
| 134 | updateHints(true);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | void QCoeFepInputContext::widgetDestroyed(QWidget *w)
|
|---|
| 138 | {
|
|---|
| 139 | // Make sure that the input capabilities of whatever new widget got focused are queried.
|
|---|
| 140 | CCoeControl *ctrl = w->effectiveWinId();
|
|---|
| 141 | if (ctrl->IsFocused()) {
|
|---|
| 142 | queueInputCapabilitiesChanged();
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | QString QCoeFepInputContext::language()
|
|---|
| 147 | {
|
|---|
| 148 | TLanguage lang = m_fepState->LocalLanguage();
|
|---|
| 149 | const QByteArray localeName = qt_symbianLocaleName(lang);
|
|---|
| 150 | if (!localeName.isEmpty()) {
|
|---|
| 151 | return QString::fromLatin1(localeName);
|
|---|
| 152 | } else {
|
|---|
| 153 | return QString::fromLatin1("C");
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | bool QCoeFepInputContext::needsInputPanel()
|
|---|
| 158 | {
|
|---|
| 159 | switch (QSysInfo::s60Version()) {
|
|---|
| 160 | case QSysInfo::SV_S60_3_1:
|
|---|
| 161 | case QSysInfo::SV_S60_3_2:
|
|---|
| 162 | // There are no touch phones for pre-5.0 SDKs.
|
|---|
| 163 | return false;
|
|---|
| 164 | #ifdef Q_CC_NOKIAX86
|
|---|
| 165 | default:
|
|---|
| 166 | // For emulator we assume that we need an input panel, since we can't
|
|---|
| 167 | // separate between phone types.
|
|---|
| 168 | return true;
|
|---|
| 169 | #else
|
|---|
| 170 | case QSysInfo::SV_S60_5_0: {
|
|---|
| 171 | // For SDK == 5.0, we need phone specific detection, since the HAL API
|
|---|
| 172 | // is no good on most phones. However, all phones at the time of writing use the
|
|---|
| 173 | // input panel, except N97 in landscape mode, but in this mode it refuses to bring
|
|---|
| 174 | // up the panel anyway, so we don't have to care.
|
|---|
| 175 | return true;
|
|---|
| 176 | }
|
|---|
| 177 | default:
|
|---|
| 178 | // For unknown/newer types, we try to use the HAL API.
|
|---|
| 179 | int keyboardEnabled;
|
|---|
| 180 | int keyboardType;
|
|---|
| 181 | int err[2];
|
|---|
| 182 | err[0] = HAL::Get(HAL::EKeyboard, keyboardType);
|
|---|
| 183 | err[1] = HAL::Get(HAL::EKeyboardState, keyboardEnabled);
|
|---|
| 184 | if (err[0] == KErrNone && err[1] == KErrNone
|
|---|
| 185 | && keyboardType != 0 && keyboardEnabled)
|
|---|
| 186 | // Means that we have some sort of keyboard.
|
|---|
| 187 | return false;
|
|---|
| 188 |
|
|---|
| 189 | // Fall back to using the input panel.
|
|---|
| 190 | return true;
|
|---|
| 191 | #endif // !Q_CC_NOKIAX86
|
|---|
| 192 | }
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | bool QCoeFepInputContext::filterEvent(const QEvent *event)
|
|---|
| 196 | {
|
|---|
| 197 | // The CloseSoftwareInputPanel event is not handled here, because the VK will automatically
|
|---|
| 198 | // close when it discovers that the underlying widget does not have input capabilities.
|
|---|
| 199 |
|
|---|
| 200 | if (!focusWidget())
|
|---|
| 201 | return false;
|
|---|
| 202 |
|
|---|
| 203 | if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
|
|---|
| 204 | const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event);
|
|---|
| 205 | switch (keyEvent->key()) {
|
|---|
| 206 | case Qt::Key_F20:
|
|---|
| 207 | Q_ASSERT(m_lastImHints == focusWidget()->inputMethodHints());
|
|---|
| 208 | if (m_lastImHints & Qt::ImhHiddenText) {
|
|---|
| 209 | // Special case in Symbian. On editors with secret text, F20 is for some reason
|
|---|
| 210 | // considered to be a backspace.
|
|---|
| 211 | QKeyEvent modifiedEvent(keyEvent->type(), Qt::Key_Backspace, keyEvent->modifiers(),
|
|---|
| 212 | keyEvent->text(), keyEvent->isAutoRepeat(), keyEvent->count());
|
|---|
| 213 | QApplication::sendEvent(focusWidget(), &modifiedEvent);
|
|---|
| 214 | return true;
|
|---|
| 215 | }
|
|---|
| 216 | break;
|
|---|
| 217 | case Qt::Key_Select:
|
|---|
| 218 | if (!m_preeditString.isEmpty()) {
|
|---|
| 219 | commitCurrentString(false);
|
|---|
| 220 | return true;
|
|---|
| 221 | }
|
|---|
| 222 | break;
|
|---|
| 223 | default:
|
|---|
| 224 | break;
|
|---|
| 225 | }
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | if (!needsInputPanel())
|
|---|
| 229 | return false;
|
|---|
| 230 |
|
|---|
| 231 | if (event->type() == QEvent::RequestSoftwareInputPanel) {
|
|---|
| 232 | // Notify S60 that we want the virtual keyboard to show up.
|
|---|
| 233 | QSymbianControl *sControl;
|
|---|
| 234 | sControl = focusWidget()->effectiveWinId()->MopGetObject(sControl);
|
|---|
| 235 | Q_ASSERT(sControl);
|
|---|
| 236 |
|
|---|
| 237 | // The FEP UI temporarily steals focus when it shows up the first time, causing
|
|---|
| 238 | // all sorts of weird effects on the focused widgets. Since it will immediately give
|
|---|
| 239 | // back focus to us, we temporarily disable focus handling until the job's done.
|
|---|
| 240 | if (sControl) {
|
|---|
| 241 | sControl->setIgnoreFocusChanged(true);
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | ensureInputCapabilitiesChanged();
|
|---|
| 245 | m_fepState->ReportAknEdStateEventL(MAknEdStateObserver::QT_EAknActivatePenInputRequest);
|
|---|
| 246 |
|
|---|
| 247 | if (sControl) {
|
|---|
| 248 | sControl->setIgnoreFocusChanged(false);
|
|---|
| 249 | }
|
|---|
| 250 | return true;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | return false;
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event)
|
|---|
| 257 | {
|
|---|
| 258 | Q_ASSERT(focusWidget());
|
|---|
| 259 |
|
|---|
| 260 | if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::LeftButton) {
|
|---|
| 261 | commitCurrentString(false);
|
|---|
| 262 | int pos = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt();
|
|---|
| 263 |
|
|---|
| 264 | QList<QInputMethodEvent::Attribute> attributes;
|
|---|
| 265 | attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, pos + x, 0, QVariant());
|
|---|
| 266 | QInputMethodEvent event(QLatin1String(""), attributes);
|
|---|
| 267 | sendEvent(event);
|
|---|
| 268 | }
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | TCoeInputCapabilities QCoeFepInputContext::inputCapabilities()
|
|---|
| 272 | {
|
|---|
| 273 | if (m_inDestruction || !focusWidget()) {
|
|---|
| 274 | return TCoeInputCapabilities(TCoeInputCapabilities::ENone, 0, 0);
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | return TCoeInputCapabilities(m_textCapabilities, this, 0);
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | static QTextCharFormat qt_TCharFormat2QTextCharFormat(const TCharFormat &cFormat)
|
|---|
| 281 | {
|
|---|
| 282 | QTextCharFormat qFormat;
|
|---|
| 283 |
|
|---|
| 284 | QBrush foreground(QColor(cFormat.iFontPresentation.iTextColor.Internal()));
|
|---|
| 285 | qFormat.setForeground(foreground);
|
|---|
| 286 |
|
|---|
| 287 | qFormat.setFontStrikeOut(cFormat.iFontPresentation.iStrikethrough == EStrikethroughOn);
|
|---|
| 288 | qFormat.setFontUnderline(cFormat.iFontPresentation.iUnderline == EUnderlineOn);
|
|---|
| 289 |
|
|---|
| 290 | return qFormat;
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | void QCoeFepInputContext::updateHints(bool mustUpdateInputCapabilities)
|
|---|
| 294 | {
|
|---|
| 295 | QWidget *w = focusWidget();
|
|---|
| 296 | if (w) {
|
|---|
| 297 | Qt::InputMethodHints hints = w->inputMethodHints();
|
|---|
| 298 | if (hints != m_lastImHints) {
|
|---|
| 299 | m_lastImHints = hints;
|
|---|
| 300 | applyHints(hints);
|
|---|
| 301 | } else if (!mustUpdateInputCapabilities) {
|
|---|
| 302 | // Optimization. Return immediately if there was no change.
|
|---|
| 303 | return;
|
|---|
| 304 | }
|
|---|
| 305 | }
|
|---|
| 306 | queueInputCapabilitiesChanged();
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | void QCoeFepInputContext::applyHints(Qt::InputMethodHints hints)
|
|---|
| 310 | {
|
|---|
| 311 | using namespace Qt;
|
|---|
| 312 |
|
|---|
| 313 | bool numbersOnly = hints & ImhDigitsOnly || hints & ImhFormattedNumbersOnly
|
|---|
| 314 | || hints & ImhDialableCharactersOnly;
|
|---|
| 315 | bool noOnlys = !(numbersOnly || hints & ImhUppercaseOnly
|
|---|
| 316 | || hints & ImhLowercaseOnly);
|
|---|
| 317 | TInt flags;
|
|---|
| 318 | Qt::InputMethodHints oldHints = hints;
|
|---|
| 319 |
|
|---|
| 320 | // Some sanity checking. Make sure that only one preference is set.
|
|---|
| 321 | InputMethodHints prefs = ImhPreferNumbers | ImhPreferUppercase | ImhPreferLowercase;
|
|---|
| 322 | prefs &= hints;
|
|---|
| 323 | if (prefs != ImhPreferNumbers && prefs != ImhPreferUppercase && prefs != ImhPreferLowercase) {
|
|---|
| 324 | hints &= ~prefs;
|
|---|
| 325 | }
|
|---|
| 326 | if (!noOnlys) {
|
|---|
| 327 | // Make sure that the preference is within the permitted set.
|
|---|
| 328 | if (hints & ImhPreferNumbers && !(hints & ImhDigitsOnly || hints & ImhFormattedNumbersOnly
|
|---|
| 329 | || hints & ImhDialableCharactersOnly)) {
|
|---|
| 330 | hints &= ~ImhPreferNumbers;
|
|---|
| 331 | } else if (hints & ImhPreferUppercase && !(hints & ImhUppercaseOnly)) {
|
|---|
| 332 | hints &= ~ImhPreferUppercase;
|
|---|
| 333 | } else if (hints & ImhPreferLowercase && !(hints & ImhLowercaseOnly)) {
|
|---|
| 334 | hints &= ~ImhPreferLowercase;
|
|---|
| 335 | }
|
|---|
| 336 | // If there is no preference, set it to something within the permitted set.
|
|---|
| 337 | if (!(hints & ImhPreferNumbers || hints & ImhPreferUppercase || hints & ImhPreferLowercase)) {
|
|---|
| 338 | if (hints & ImhLowercaseOnly) {
|
|---|
| 339 | hints |= ImhPreferLowercase;
|
|---|
| 340 | } else if (hints & ImhUppercaseOnly) {
|
|---|
| 341 | hints |= ImhPreferUppercase;
|
|---|
| 342 | } else if (hints & ImhDigitsOnly || hints & ImhFormattedNumbersOnly
|
|---|
| 343 | || hints & ImhDialableCharactersOnly) {
|
|---|
| 344 | hints |= ImhPreferNumbers;
|
|---|
| 345 | }
|
|---|
| 346 | }
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | if (hints & ImhPreferNumbers) {
|
|---|
| 350 | m_fepState->SetDefaultInputMode(EAknEditorNumericInputMode);
|
|---|
| 351 | m_fepState->SetCurrentInputMode(EAknEditorNumericInputMode);
|
|---|
| 352 | } else {
|
|---|
| 353 | m_fepState->SetDefaultInputMode(EAknEditorTextInputMode);
|
|---|
| 354 | m_fepState->SetCurrentInputMode(EAknEditorTextInputMode);
|
|---|
| 355 | }
|
|---|
| 356 | flags = 0;
|
|---|
| 357 | if (numbersOnly) {
|
|---|
| 358 | flags |= EAknEditorNumericInputMode;
|
|---|
| 359 | }
|
|---|
| 360 | if (hints & ImhUppercaseOnly || hints & ImhLowercaseOnly) {
|
|---|
| 361 | flags |= EAknEditorTextInputMode;
|
|---|
| 362 | }
|
|---|
| 363 | if (flags == 0) {
|
|---|
| 364 | flags = EAknEditorAllInputModes;
|
|---|
| 365 | }
|
|---|
| 366 | m_fepState->SetPermittedInputModes(flags);
|
|---|
| 367 | ReportAknEdStateEvent(MAknEdStateObserver::EAknEdwinStateInputModeUpdate);
|
|---|
| 368 |
|
|---|
| 369 | if (hints & ImhPreferLowercase) {
|
|---|
| 370 | m_fepState->SetDefaultCase(EAknEditorLowerCase);
|
|---|
| 371 | m_fepState->SetCurrentCase(EAknEditorLowerCase);
|
|---|
| 372 | } else if (hints & ImhPreferUppercase) {
|
|---|
| 373 | m_fepState->SetDefaultCase(EAknEditorUpperCase);
|
|---|
| 374 | m_fepState->SetCurrentCase(EAknEditorUpperCase);
|
|---|
| 375 | } else if (hints & ImhNoAutoUppercase) {
|
|---|
| 376 | m_fepState->SetDefaultCase(EAknEditorLowerCase);
|
|---|
| 377 | m_fepState->SetCurrentCase(EAknEditorLowerCase);
|
|---|
| 378 | } else {
|
|---|
| 379 | m_fepState->SetDefaultCase(EAknEditorTextCase);
|
|---|
| 380 | m_fepState->SetCurrentCase(EAknEditorTextCase);
|
|---|
| 381 | }
|
|---|
| 382 | flags = 0;
|
|---|
| 383 | if (hints & ImhUppercaseOnly) {
|
|---|
| 384 | flags |= EAknEditorUpperCase;
|
|---|
| 385 | }
|
|---|
| 386 | if (hints & ImhLowercaseOnly) {
|
|---|
| 387 | flags |= EAknEditorLowerCase;
|
|---|
| 388 | }
|
|---|
| 389 | if (flags == 0) {
|
|---|
| 390 | flags = EAknEditorAllCaseModes;
|
|---|
| 391 | if (hints & ImhNoAutoUppercase) {
|
|---|
| 392 | flags &= ~EAknEditorTextCase;
|
|---|
| 393 | }
|
|---|
| 394 | }
|
|---|
| 395 | m_fepState->SetPermittedCases(flags);
|
|---|
| 396 | ReportAknEdStateEvent(MAknEdStateObserver::EAknEdwinStateCaseModeUpdate);
|
|---|
| 397 |
|
|---|
| 398 | flags = 0;
|
|---|
| 399 | if (hints & ImhUppercaseOnly && !(hints & ImhLowercaseOnly)
|
|---|
| 400 | || hints & ImhLowercaseOnly && !(hints & ImhUppercaseOnly)) {
|
|---|
| 401 | flags |= EAknEditorFlagFixedCase;
|
|---|
| 402 | }
|
|---|
| 403 | // Using T9 and hidden text together may actually crash the FEP, so check for hidden text too.
|
|---|
| 404 | if (hints & ImhNoPredictiveText || hints & ImhHiddenText) {
|
|---|
| 405 | flags |= EAknEditorFlagNoT9;
|
|---|
| 406 | }
|
|---|
| 407 | m_fepState->SetFlags(flags);
|
|---|
| 408 | ReportAknEdStateEvent(MAknEdStateObserver::EAknEdwinStateFlagsUpdate);
|
|---|
| 409 |
|
|---|
| 410 | if (hints & ImhFormattedNumbersOnly) {
|
|---|
| 411 | flags = EAknEditorCalculatorNumberModeKeymap;
|
|---|
| 412 | } else if (hints & ImhDigitsOnly) {
|
|---|
| 413 | flags = EAknEditorPlainNumberModeKeymap;
|
|---|
| 414 | } else {
|
|---|
| 415 | // ImhDialableCharactersOnly is the fallback as well, so we don't need to check for
|
|---|
| 416 | // that flag.
|
|---|
| 417 | flags = EAknEditorStandardNumberModeKeymap;
|
|---|
| 418 | }
|
|---|
| 419 | m_fepState->SetNumericKeymap(static_cast<TAknEditorNumericKeymap>(flags));
|
|---|
| 420 |
|
|---|
| 421 | if (hints & ImhEmailCharactersOnly) {
|
|---|
| 422 | m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_EMAIL_ADDR_SPECIAL_CHARACTER_TABLE_DIALOG);
|
|---|
| 423 | } else if (hints & ImhUrlCharactersOnly) {
|
|---|
| 424 | m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_URL_SPECIAL_CHARACTER_TABLE_DIALOG);
|
|---|
| 425 | } else {
|
|---|
| 426 | m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG);
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | if (hints & ImhHiddenText) {
|
|---|
| 430 | m_textCapabilities = TCoeInputCapabilities::EAllText | TCoeInputCapabilities::ESecretText;
|
|---|
| 431 | } else {
|
|---|
| 432 | m_textCapabilities = TCoeInputCapabilities::EAllText;
|
|---|
| 433 | }
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | void QCoeFepInputContext::applyFormat(QList<QInputMethodEvent::Attribute> *attributes)
|
|---|
| 437 | {
|
|---|
| 438 | TCharFormat cFormat;
|
|---|
| 439 | QColor styleTextColor = QApplication::palette("QLineEdit").text().color();
|
|---|
| 440 | TLogicalRgb tontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha()));
|
|---|
| 441 | cFormat.iFontPresentation.iTextColor = tontColor;
|
|---|
| 442 |
|
|---|
| 443 | TInt numChars = 0;
|
|---|
| 444 | TInt charPos = 0;
|
|---|
| 445 | int oldSize = attributes->size();
|
|---|
| 446 | while (m_formatRetriever) {
|
|---|
| 447 | m_formatRetriever->GetFormatOfFepInlineText(cFormat, numChars, charPos);
|
|---|
| 448 | if (numChars <= 0) {
|
|---|
| 449 | // This shouldn't happen according to S60 docs, but apparently does sometimes.
|
|---|
| 450 | break;
|
|---|
| 451 | }
|
|---|
| 452 | attributes->append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
|
|---|
| 453 | charPos,
|
|---|
| 454 | numChars,
|
|---|
| 455 | QVariant(qt_TCharFormat2QTextCharFormat(cFormat))));
|
|---|
| 456 | charPos += numChars;
|
|---|
| 457 | if (charPos >= m_preeditString.size()) {
|
|---|
| 458 | break;
|
|---|
| 459 | }
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | if (attributes->size() == oldSize) {
|
|---|
| 463 | // S60 didn't provide any format, so let's give our own instead.
|
|---|
| 464 | attributes->append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
|
|---|
| 465 | 0,
|
|---|
| 466 | m_preeditString.size(),
|
|---|
| 467 | standardFormat(PreeditFormat)));
|
|---|
| 468 | }
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | void QCoeFepInputContext::queueInputCapabilitiesChanged()
|
|---|
| 472 | {
|
|---|
| 473 | if (m_pendingInputCapabilitiesChanged)
|
|---|
| 474 | return;
|
|---|
| 475 |
|
|---|
| 476 | // Call ensureInputCapabilitiesChanged asynchronously. This is done to improve performance
|
|---|
| 477 | // by not updating input capabilities too often. The reason we don't call the Symbian
|
|---|
| 478 | // asynchronous version of InputCapabilitiesChanged is because we need to ensure that it
|
|---|
| 479 | // is synchronous in some specific cases. Those will call ensureInputCapabilitesChanged.
|
|---|
| 480 | QMetaObject::invokeMethod(this, "ensureInputCapabilitiesChanged", Qt::QueuedConnection);
|
|---|
| 481 | m_pendingInputCapabilitiesChanged = true;
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 | void QCoeFepInputContext::ensureInputCapabilitiesChanged()
|
|---|
| 485 | {
|
|---|
| 486 | if (!m_pendingInputCapabilitiesChanged)
|
|---|
| 487 | return;
|
|---|
| 488 |
|
|---|
| 489 | // The call below is essentially equivalent to InputCapabilitiesChanged(),
|
|---|
| 490 | // but is synchronous, rather than asynchronous.
|
|---|
| 491 | CCoeEnv::Static()->SyncNotifyFocusObserversOfChangeInFocus();
|
|---|
| 492 | m_pendingInputCapabilitiesChanged = false;
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | void QCoeFepInputContext::StartFepInlineEditL(const TDesC& aInitialInlineText,
|
|---|
| 496 | TInt aPositionOfInsertionPointInInlineText, TBool aCursorVisibility, const MFormCustomDraw* /*aCustomDraw*/,
|
|---|
| 497 | MFepInlineTextFormatRetriever& aInlineTextFormatRetriever,
|
|---|
| 498 | MFepPointerEventHandlerDuringInlineEdit& aPointerEventHandlerDuringInlineEdit)
|
|---|
| 499 | {
|
|---|
| 500 | QWidget *w = focusWidget();
|
|---|
| 501 | if (!w)
|
|---|
| 502 | return;
|
|---|
| 503 |
|
|---|
| 504 | m_cursorPos = w->inputMethodQuery(Qt::ImCursorPosition).toInt();
|
|---|
| 505 |
|
|---|
| 506 | QList<QInputMethodEvent::Attribute> attributes;
|
|---|
| 507 |
|
|---|
| 508 | m_cursorVisibility = aCursorVisibility ? 1 : 0;
|
|---|
| 509 | m_inlinePosition = aPositionOfInsertionPointInInlineText;
|
|---|
| 510 | m_preeditString = qt_TDesC2QString(aInitialInlineText);
|
|---|
| 511 |
|
|---|
| 512 | m_formatRetriever = &aInlineTextFormatRetriever;
|
|---|
| 513 | m_pointerHandler = &aPointerEventHandlerDuringInlineEdit;
|
|---|
| 514 |
|
|---|
| 515 | applyFormat(&attributes);
|
|---|
| 516 |
|
|---|
| 517 | attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor,
|
|---|
| 518 | m_inlinePosition,
|
|---|
| 519 | m_cursorVisibility,
|
|---|
| 520 | QVariant()));
|
|---|
| 521 | QInputMethodEvent event(m_preeditString, attributes);
|
|---|
| 522 | sendEvent(event);
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | void QCoeFepInputContext::UpdateFepInlineTextL(const TDesC& aNewInlineText,
|
|---|
| 526 | TInt aPositionOfInsertionPointInInlineText)
|
|---|
| 527 | {
|
|---|
| 528 | QWidget *w = focusWidget();
|
|---|
| 529 | if (!w)
|
|---|
| 530 | return;
|
|---|
| 531 |
|
|---|
| 532 | m_inlinePosition = aPositionOfInsertionPointInInlineText;
|
|---|
| 533 |
|
|---|
| 534 | QList<QInputMethodEvent::Attribute> attributes;
|
|---|
| 535 | applyFormat(&attributes);
|
|---|
| 536 | attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor,
|
|---|
| 537 | m_inlinePosition,
|
|---|
| 538 | m_cursorVisibility,
|
|---|
| 539 | QVariant()));
|
|---|
| 540 | m_preeditString = qt_TDesC2QString(aNewInlineText);
|
|---|
| 541 | QInputMethodEvent event(m_preeditString, attributes);
|
|---|
| 542 | sendEvent(event);
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 | void QCoeFepInputContext::SetInlineEditingCursorVisibilityL(TBool aCursorVisibility)
|
|---|
| 546 | {
|
|---|
| 547 | QWidget *w = focusWidget();
|
|---|
| 548 | if (!w)
|
|---|
| 549 | return;
|
|---|
| 550 |
|
|---|
| 551 | m_cursorVisibility = aCursorVisibility ? 1 : 0;
|
|---|
| 552 |
|
|---|
| 553 | QList<QInputMethodEvent::Attribute> attributes;
|
|---|
| 554 | attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor,
|
|---|
| 555 | m_inlinePosition,
|
|---|
| 556 | m_cursorVisibility,
|
|---|
| 557 | QVariant()));
|
|---|
| 558 | QInputMethodEvent event(m_preeditString, attributes);
|
|---|
| 559 | sendEvent(event);
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | void QCoeFepInputContext::CancelFepInlineEdit()
|
|---|
| 563 | {
|
|---|
| 564 | QList<QInputMethodEvent::Attribute> attributes;
|
|---|
| 565 | QInputMethodEvent event(QLatin1String(""), attributes);
|
|---|
| 566 | event.setCommitString(QLatin1String(""), 0, 0);
|
|---|
| 567 | m_preeditString.clear();
|
|---|
| 568 | sendEvent(event);
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | TInt QCoeFepInputContext::DocumentLengthForFep() const
|
|---|
| 572 | {
|
|---|
| 573 | QWidget *w = focusWidget();
|
|---|
| 574 | if (!w)
|
|---|
| 575 | return 0;
|
|---|
| 576 |
|
|---|
| 577 | QVariant variant = w->inputMethodQuery(Qt::ImSurroundingText);
|
|---|
| 578 | return variant.value<QString>().size() + m_preeditString.size();
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | TInt QCoeFepInputContext::DocumentMaximumLengthForFep() const
|
|---|
| 582 | {
|
|---|
| 583 | QWidget *w = focusWidget();
|
|---|
| 584 | if (!w)
|
|---|
| 585 | return 0;
|
|---|
| 586 |
|
|---|
| 587 | QVariant variant = w->inputMethodQuery(Qt::ImMaximumTextLength);
|
|---|
| 588 | int size;
|
|---|
| 589 | if (variant.isValid()) {
|
|---|
| 590 | size = variant.toInt();
|
|---|
| 591 | } else {
|
|---|
| 592 | size = INT_MAX; // Sensible default for S60.
|
|---|
| 593 | }
|
|---|
| 594 | return size;
|
|---|
| 595 | }
|
|---|
| 596 |
|
|---|
| 597 | void QCoeFepInputContext::SetCursorSelectionForFepL(const TCursorSelection& aCursorSelection)
|
|---|
| 598 | {
|
|---|
| 599 | QWidget *w = focusWidget();
|
|---|
| 600 | if (!w)
|
|---|
| 601 | return;
|
|---|
| 602 |
|
|---|
| 603 | int pos = aCursorSelection.iAnchorPos;
|
|---|
| 604 | int length = aCursorSelection.iCursorPos - pos;
|
|---|
| 605 |
|
|---|
| 606 | QList<QInputMethodEvent::Attribute> attributes;
|
|---|
| 607 | attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, pos, length, QVariant());
|
|---|
| 608 | QInputMethodEvent event(m_preeditString, attributes);
|
|---|
| 609 | sendEvent(event);
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 | void QCoeFepInputContext::GetCursorSelectionForFep(TCursorSelection& aCursorSelection) const
|
|---|
| 613 | {
|
|---|
| 614 | QWidget *w = focusWidget();
|
|---|
| 615 | if (!w) {
|
|---|
| 616 | aCursorSelection.SetSelection(0,0);
|
|---|
| 617 | return;
|
|---|
| 618 | }
|
|---|
| 619 |
|
|---|
| 620 | int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt() + m_preeditString.size();
|
|---|
| 621 | int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt() + m_preeditString.size();
|
|---|
| 622 | QString text = w->inputMethodQuery(Qt::ImSurroundingText).value<QString>();
|
|---|
| 623 | int combinedSize = text.size() + m_preeditString.size();
|
|---|
| 624 | if (combinedSize < anchor || combinedSize < cursor) {
|
|---|
| 625 | // ### TODO! FIXME! QTBUG-5050
|
|---|
| 626 | // This is a hack to prevent crashing in 4.6 with QLineEdits that use input masks.
|
|---|
| 627 | // The root problem is that cursor position is relative to displayed text instead of the
|
|---|
| 628 | // actual text we get.
|
|---|
| 629 | //
|
|---|
| 630 | // To properly fix this we would need to know the displayText of QLineEdits instead
|
|---|
| 631 | // of just the text, which on itself should be a trivial change. The difficulties start
|
|---|
| 632 | // when we need to commit the changes back to the QLineEdit, which would have to be somehow
|
|---|
| 633 | // able to handle displayText, too.
|
|---|
| 634 | //
|
|---|
| 635 | // Until properly fixed, the cursor and anchor positions will not reflect correct positions
|
|---|
| 636 | // for masked QLineEdits, unless all the masked positions are filled in order so that
|
|---|
| 637 | // cursor position relative to the displayed text matches position relative to actual text.
|
|---|
| 638 | aCursorSelection.iAnchorPos = combinedSize;
|
|---|
| 639 | aCursorSelection.iCursorPos = combinedSize;
|
|---|
| 640 | } else {
|
|---|
| 641 | aCursorSelection.iAnchorPos = anchor;
|
|---|
| 642 | aCursorSelection.iCursorPos = cursor;
|
|---|
| 643 | }
|
|---|
| 644 | }
|
|---|
| 645 |
|
|---|
| 646 | void QCoeFepInputContext::GetEditorContentForFep(TDes& aEditorContent, TInt aDocumentPosition,
|
|---|
| 647 | TInt aLengthToRetrieve) const
|
|---|
| 648 | {
|
|---|
| 649 | QWidget *w = focusWidget();
|
|---|
| 650 | if (!w) {
|
|---|
| 651 | aEditorContent.FillZ(aLengthToRetrieve);
|
|---|
| 652 | return;
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | QString text = w->inputMethodQuery(Qt::ImSurroundingText).value<QString>();
|
|---|
| 656 | // FEP expects the preedit string to be part of the editor content, so let's mix it in.
|
|---|
| 657 | int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt();
|
|---|
| 658 | text.insert(cursor, m_preeditString);
|
|---|
| 659 | aEditorContent.Copy(qt_QString2TPtrC(text.mid(aDocumentPosition, aLengthToRetrieve)));
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | void QCoeFepInputContext::GetFormatForFep(TCharFormat& aFormat, TInt /* aDocumentPosition */) const
|
|---|
| 663 | {
|
|---|
| 664 | QWidget *w = focusWidget();
|
|---|
| 665 | if (!w) {
|
|---|
| 666 | aFormat = TCharFormat();
|
|---|
| 667 | return;
|
|---|
| 668 | }
|
|---|
| 669 |
|
|---|
| 670 | QFont font = w->inputMethodQuery(Qt::ImFont).value<QFont>();
|
|---|
| 671 | QFontMetrics metrics(font);
|
|---|
| 672 | //QString name = font.rawName();
|
|---|
| 673 | QString name = font.defaultFamily(); // TODO! FIXME! Should be the above.
|
|---|
| 674 | QHBufC hBufC(name);
|
|---|
| 675 | aFormat = TCharFormat(hBufC->Des(), metrics.height());
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | void QCoeFepInputContext::GetScreenCoordinatesForFepL(TPoint& aLeftSideOfBaseLine, TInt& aHeight,
|
|---|
| 679 | TInt& aAscent, TInt /* aDocumentPosition */) const
|
|---|
| 680 | {
|
|---|
| 681 | QWidget *w = focusWidget();
|
|---|
| 682 | if (!w) {
|
|---|
| 683 | aLeftSideOfBaseLine = TPoint(0,0);
|
|---|
| 684 | aHeight = 0;
|
|---|
| 685 | aAscent = 0;
|
|---|
| 686 | return;
|
|---|
| 687 | }
|
|---|
| 688 |
|
|---|
| 689 | QRect rect = w->inputMethodQuery(Qt::ImMicroFocus).value<QRect>();
|
|---|
| 690 | aLeftSideOfBaseLine.iX = rect.left();
|
|---|
| 691 | aLeftSideOfBaseLine.iY = rect.bottom();
|
|---|
| 692 |
|
|---|
| 693 | QFont font = w->inputMethodQuery(Qt::ImFont).value<QFont>();
|
|---|
| 694 | QFontMetrics metrics(font);
|
|---|
| 695 | aHeight = metrics.height();
|
|---|
| 696 | aAscent = metrics.ascent();
|
|---|
| 697 | }
|
|---|
| 698 |
|
|---|
| 699 | void QCoeFepInputContext::DoCommitFepInlineEditL()
|
|---|
| 700 | {
|
|---|
| 701 | commitCurrentString(true);
|
|---|
| 702 | }
|
|---|
| 703 |
|
|---|
| 704 | void QCoeFepInputContext::commitCurrentString(bool triggeredBySymbian)
|
|---|
| 705 | {
|
|---|
| 706 | if (m_preeditString.size() == 0) {
|
|---|
| 707 | QWidget *w = focusWidget();
|
|---|
| 708 | if (triggeredBySymbian && w) {
|
|---|
| 709 | // We must replace the last character only if the input box has already accepted one
|
|---|
| 710 | if (w->inputMethodQuery(Qt::ImCursorPosition).toInt() != m_cursorPos)
|
|---|
| 711 | m_longPress = 1;
|
|---|
| 712 | }
|
|---|
| 713 | return;
|
|---|
| 714 | }
|
|---|
| 715 |
|
|---|
| 716 | QList<QInputMethodEvent::Attribute> attributes;
|
|---|
| 717 | QInputMethodEvent event(QLatin1String(""), attributes);
|
|---|
| 718 | event.setCommitString(m_preeditString, 0-m_longPress, m_longPress);
|
|---|
| 719 | m_preeditString.clear();
|
|---|
| 720 | sendEvent(event);
|
|---|
| 721 |
|
|---|
| 722 | m_longPress = 0;
|
|---|
| 723 |
|
|---|
| 724 | if (!triggeredBySymbian) {
|
|---|
| 725 | CCoeFep* fep = CCoeEnv::Static()->Fep();
|
|---|
| 726 | if (fep)
|
|---|
| 727 | fep->CancelTransaction();
|
|---|
| 728 | }
|
|---|
| 729 | }
|
|---|
| 730 |
|
|---|
| 731 | MCoeFepAwareTextEditor_Extension1* QCoeFepInputContext::Extension1(TBool& aSetToTrue)
|
|---|
| 732 | {
|
|---|
| 733 | aSetToTrue = ETrue;
|
|---|
| 734 | return this;
|
|---|
| 735 | }
|
|---|
| 736 |
|
|---|
| 737 | void QCoeFepInputContext::SetStateTransferingOwnershipL(MCoeFepAwareTextEditor_Extension1::CState* aState,
|
|---|
| 738 | TUid /*aTypeSafetyUid*/)
|
|---|
| 739 | {
|
|---|
| 740 | // Note: The S60 docs are wrong! See the State() function.
|
|---|
| 741 | if (m_fepState)
|
|---|
| 742 | delete m_fepState;
|
|---|
| 743 | m_fepState = static_cast<CAknEdwinState *>(aState);
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 | MCoeFepAwareTextEditor_Extension1::CState* QCoeFepInputContext::State(TUid /*aTypeSafetyUid*/)
|
|---|
| 747 | {
|
|---|
| 748 | // Note: The S60 docs are horribly wrong when describing the
|
|---|
| 749 | // SetStateTransferingOwnershipL function and this function. They say that the former
|
|---|
| 750 | // sets a CState object identified by the TUid, and the latter retrieves it.
|
|---|
| 751 | // In reality, the CState is expected to always be a CAknEdwinState (even if it was not
|
|---|
| 752 | // previously set), and the TUid is ignored. All in all, there is a single CAknEdwinState
|
|---|
| 753 | // per QCoeFepInputContext, which should be deleted if the SetStateTransferingOwnershipL
|
|---|
| 754 | // function is used to set a new one.
|
|---|
| 755 | return m_fepState;
|
|---|
| 756 | }
|
|---|
| 757 |
|
|---|
| 758 | TTypeUid::Ptr QCoeFepInputContext::MopSupplyObject(TTypeUid /*id*/)
|
|---|
| 759 | {
|
|---|
| 760 | return TTypeUid::Null();
|
|---|
| 761 | }
|
|---|
| 762 |
|
|---|
| 763 | MObjectProvider *QCoeFepInputContext::MopNext()
|
|---|
| 764 | {
|
|---|
| 765 | QWidget *w = focusWidget();
|
|---|
| 766 | if (w)
|
|---|
| 767 | return w->effectiveWinId();
|
|---|
| 768 | return 0;
|
|---|
| 769 | }
|
|---|
| 770 |
|
|---|
| 771 | QT_END_NAMESPACE
|
|---|
| 772 |
|
|---|
| 773 | #endif // QT_NO_IM
|
|---|