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