src/gui/inputmethod/qcoefepinputcontext_s60.cpp
branchRCL_3
changeset 8 3f74d0d4af4c
parent 5 d3bac044e0f0
child 14 c0432d11811c
equal deleted inserted replaced
6:dee5afe5301f 8:3f74d0d4af4c
    69       m_pendingInputCapabilitiesChanged(false),
    69       m_pendingInputCapabilitiesChanged(false),
    70       m_cursorVisibility(1),
    70       m_cursorVisibility(1),
    71       m_inlinePosition(0),
    71       m_inlinePosition(0),
    72       m_formatRetriever(0),
    72       m_formatRetriever(0),
    73       m_pointerHandler(0),
    73       m_pointerHandler(0),
    74       m_longPress(0),
       
    75       m_cursorPos(0),
    74       m_cursorPos(0),
    76       m_hasTempPreeditString(false)
    75       m_hasTempPreeditString(false)
    77 {
    76 {
    78     m_fepState->SetObjectProvider(this);
    77     m_fepState->SetObjectProvider(this);
    79     m_fepState->SetFlags(EAknEditorFlagDefault);
    78     m_fepState->SetFlags(EAknEditorFlagDefault);
    99         delete m_fepState;
    98         delete m_fepState;
   100 }
    99 }
   101 
   100 
   102 void QCoeFepInputContext::reset()
   101 void QCoeFepInputContext::reset()
   103 {
   102 {
   104     commitCurrentString(false);
   103     commitCurrentString(true);
   105 }
   104 }
   106 
   105 
   107 void QCoeFepInputContext::ReportAknEdStateEvent(MAknEdStateObserver::EAknEdwinStateEvent aEventType)
   106 void QCoeFepInputContext::ReportAknEdStateEvent(MAknEdStateObserver::EAknEdwinStateEvent aEventType)
   108 {
   107 {
   109     QT_TRAP_THROWING(m_fepState->ReportAknEdStateEventL(aEventType));
   108     QT_TRAP_THROWING(m_fepState->ReportAknEdStateEventL(aEventType));
   111 
   110 
   112 void QCoeFepInputContext::update()
   111 void QCoeFepInputContext::update()
   113 {
   112 {
   114     updateHints(false);
   113     updateHints(false);
   115 
   114 
   116 	// :QTP: Always show virtual keyboard - fix needed to use feature manager
       
   117     // For pre-5.0 SDKs, we don't do text updates on S60 side.
   115     // For pre-5.0 SDKs, we don't do text updates on S60 side.
   118     //if (QSysInfo::s60Version() != QSysInfo::SV_S60_5_0) {
   116     if (QSysInfo::s60Version() < QSysInfo::SV_S60_5_0) {
   119     //    return;
   117         return;
   120     //}
   118     }
   121 
   119 
   122     // Don't be fooled (as I was) by the name of this enumeration.
   120     // 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
   121     // 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.
   122     // updated and it should be reflected in the internal display of the VK.
   125     ReportAknEdStateEvent(QT_EAknCursorPositionChanged);
   123     ReportAknEdStateEvent(QT_EAknCursorPositionChanged);
   126 }
   124 }
   127 
   125 
   128 void QCoeFepInputContext::setFocusWidget(QWidget *w)
   126 void QCoeFepInputContext::setFocusWidget(QWidget *w)
   129 {
   127 {
   130     commitCurrentString(false);
   128     commitCurrentString(true);
   131 
   129 
   132     QInputContext::setFocusWidget(w);
   130     QInputContext::setFocusWidget(w);
   133 
   131 
   134     updateHints(true);
   132     updateHints(true);
   135 }
   133 }
   218                 return true;
   216                 return true;
   219             }
   217             }
   220             break;
   218             break;
   221         case Qt::Key_Select:
   219         case Qt::Key_Select:
   222             if (!m_preeditString.isEmpty()) {
   220             if (!m_preeditString.isEmpty()) {
   223                 commitCurrentString(false);
   221                 commitCurrentString(true);
   224                 return true;
   222                 return true;
   225             }
   223             }
   226             break;
   224             break;
   227         default:
   225         default:
   228             break;
   226             break;
   230 
   228 
   231         if (keyEvent->type() == QEvent::KeyPress
   229         if (keyEvent->type() == QEvent::KeyPress
   232             && focusWidget()->inputMethodHints() & Qt::ImhHiddenText
   230             && focusWidget()->inputMethodHints() & Qt::ImhHiddenText
   233             && !keyEvent->text().isEmpty()) {
   231             && !keyEvent->text().isEmpty()) {
   234             // Send some temporary preedit text in order to make text visible for a moment.
   232             // Send some temporary preedit text in order to make text visible for a moment.
       
   233             m_cursorPos = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt();
   235             m_preeditString = keyEvent->text();
   234             m_preeditString = keyEvent->text();
   236             QList<QInputMethodEvent::Attribute> attributes;
   235             QList<QInputMethodEvent::Attribute> attributes;
   237             QInputMethodEvent imEvent(m_preeditString, attributes);
   236             QInputMethodEvent imEvent(m_preeditString, attributes);
   238             QApplication::sendEvent(focusWidget(), &imEvent);
   237             sendEvent(imEvent);
   239             m_tempPreeditStringTimeout.start(1000, this);
   238             m_tempPreeditStringTimeout.start(1000, this);
   240             m_hasTempPreeditString = true;
   239             m_hasTempPreeditString = true;
   241             update();
   240             update();
   242             return true;
   241             return true;
   243         }
   242         }
   292 void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event)
   291 void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event)
   293 {
   292 {
   294     Q_ASSERT(focusWidget());
   293     Q_ASSERT(focusWidget());
   295 
   294 
   296     if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::LeftButton) {
   295     if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::LeftButton) {
   297         commitCurrentString(false);
   296         commitCurrentString(true);
   298         int pos = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt();
   297         int pos = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt();
   299 
   298 
   300         QList<QInputMethodEvent::Attribute> attributes;
   299         QList<QInputMethodEvent::Attribute> attributes;
   301         attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, pos + x, 0, QVariant());
   300         attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, pos + x, 0, QVariant());
   302         QInputMethodEvent event(QLatin1String(""), attributes);
   301         QInputMethodEvent event(QLatin1String(""), attributes);
   549     m_inlinePosition = aPositionOfInsertionPointInInlineText;
   548     m_inlinePosition = aPositionOfInsertionPointInInlineText;
   550     m_preeditString = qt_TDesC2QString(aInitialInlineText);
   549     m_preeditString = qt_TDesC2QString(aInitialInlineText);
   551 
   550 
   552     m_formatRetriever = &aInlineTextFormatRetriever;
   551     m_formatRetriever = &aInlineTextFormatRetriever;
   553     m_pointerHandler = &aPointerEventHandlerDuringInlineEdit;
   552     m_pointerHandler = &aPointerEventHandlerDuringInlineEdit;
       
   553 
       
   554     // With T9 aInitialInlineText is typically empty when StartFepInlineEditL is called,
       
   555     // but FEP requires that selected text is always removed at StartFepInlineEditL.
       
   556     // Let's remove the selected text if aInitialInlineText is empty and there is selected text
       
   557     if (m_preeditString.isEmpty()) {
       
   558         int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt();
       
   559         int replacementLength = qAbs(m_cursorPos-anchor);
       
   560         if (replacementLength > 0) {
       
   561             int replacementStart = m_cursorPos < anchor ? 0 : -replacementLength;
       
   562             QList<QInputMethodEvent::Attribute> clearSelectionAttributes;
       
   563             QInputMethodEvent clearSelectionEvent(QLatin1String(""), clearSelectionAttributes);
       
   564             clearSelectionEvent.setCommitString(QLatin1String(""), replacementStart, replacementLength);
       
   565             sendEvent(clearSelectionEvent);
       
   566         }
       
   567     }
   554 
   568 
   555     applyFormat(&attributes);
   569     applyFormat(&attributes);
   556 
   570 
   557     attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor,
   571     attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor,
   558                                                    m_inlinePosition,
   572                                                    m_inlinePosition,
   738     aAscent = metrics.ascent();
   752     aAscent = metrics.ascent();
   739 }
   753 }
   740 
   754 
   741 void QCoeFepInputContext::DoCommitFepInlineEditL()
   755 void QCoeFepInputContext::DoCommitFepInlineEditL()
   742 {
   756 {
   743     commitCurrentString(true);
   757     commitCurrentString(false);
   744 }
   758     if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0)
   745 
   759         ReportAknEdStateEvent(QT_EAknCursorPositionChanged);
   746 void QCoeFepInputContext::commitCurrentString(bool triggeredBySymbian)
   760 
   747 {
   761 }
       
   762 
       
   763 void QCoeFepInputContext::commitCurrentString(bool cancelFepTransaction)
       
   764 {
       
   765     int longPress = 0;
       
   766 
   748     if (m_preeditString.size() == 0) {
   767     if (m_preeditString.size() == 0) {
   749         QWidget *w = focusWidget();
   768         QWidget *w = focusWidget();
   750         if (triggeredBySymbian && w) {
   769         if (!cancelFepTransaction && w) {
   751             // We must replace the last character only if the input box has already accepted one 
   770             // We must replace the last character only if the input box has already accepted one 
   752             if (w->inputMethodQuery(Qt::ImCursorPosition).toInt() != m_cursorPos)
   771             if (w->inputMethodQuery(Qt::ImCursorPosition).toInt() != m_cursorPos)
   753                 m_longPress = 1;
   772                 longPress = 1;
   754         }
   773         }
   755         return;
   774         return;
   756     }
   775     }
   757 
   776 
   758     QList<QInputMethodEvent::Attribute> attributes;
   777     QList<QInputMethodEvent::Attribute> attributes;
   759     QInputMethodEvent event(QLatin1String(""), attributes);
   778     QInputMethodEvent event(QLatin1String(""), attributes);
   760     event.setCommitString(m_preeditString, 0-m_longPress, m_longPress);
   779     event.setCommitString(m_preeditString, 0-longPress, longPress);
   761     m_preeditString.clear();
   780     m_preeditString.clear();
   762     sendEvent(event);
   781     sendEvent(event);
   763 
   782 
   764     m_hasTempPreeditString = false;
   783     m_hasTempPreeditString = false;
   765     m_longPress = 0;
   784     longPress = 0;
   766 
   785 
   767     if (!triggeredBySymbian) {
   786     if (cancelFepTransaction) {
   768         CCoeFep* fep = CCoeEnv::Static()->Fep();
   787         CCoeFep* fep = CCoeEnv::Static()->Fep();
   769         if (fep)
   788         if (fep)
   770             fep->CancelTransaction();
   789             fep->CancelTransaction();
   771     }
   790     }
   772 }
   791 }