|
1 /* |
|
2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: generic HWR layout |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System includes |
|
20 #include <aknfeppeninputenums.h> // Command from fep or IME to plugin |
|
21 #include <AknFepGlobalEnums.h> // Define EPluginInputModeHwr |
|
22 #include <peninputcmd.h> // Use global signal |
|
23 #include <peninputpluginutils.h> // Use resource utils and laf env |
|
24 #include <peninputlayoutchoicelist.h> |
|
25 #include <peninputlayoutbutton.h> |
|
26 #include <peninputdragbutton.h> |
|
27 #include <peninputcommonlayoutglobalenum.h> |
|
28 #include <peninputdataconverter.h> |
|
29 |
|
30 // User includes |
|
31 #include "peninputhwrarabic.hrh" |
|
32 //#include "peninputhwrevent.h" |
|
33 #include "peninputuistatemgrinterface.h" |
|
34 #include "peninputhwrarabiclayout.h" |
|
35 #include "peninputhwrarabicwindow.h" |
|
36 #include "peninputhwrarabicdatamgr.h" |
|
37 #include "peninputhwrarabicstate.h" |
|
38 #include "peninputhwrarabicstatestandby.h" |
|
39 #include "peninputhwrarabicstatebeginwriting.h" |
|
40 #include "peninputhwrarabicstateendwriting.h" |
|
41 #include "peninputhwrboxarabicstatecandidateselecting.h" |
|
42 #include "peninputuistatemgr.h" |
|
43 #include "peninputlayouthwrwnd.h" |
|
44 |
|
45 // constant definition |
|
46 //const TInt KMaxPredictiveLen = 128; |
|
47 const TInt KMaxCandidateLen = 128; |
|
48 //const TUint16 KBackRep = 0x2408; |
|
49 // convert displayable backspace |
|
50 const TUint16 KBackRep = 0x2190; |
|
51 const TUint16 KEnterRep = 0xF801; |
|
52 const TUint16 KSpaceRep = 0xF800; |
|
53 //const TUint16 KEnterCode = 0x2029; |
|
54 |
|
55 // ======== MEMBER FUNCTIONS ======== |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CPeninputHwrBxAbLayoutImp::NewL |
|
59 // (other items were commented in a header) |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CPeninputHwrBxAbLayoutImp* CPeninputHwrBxAbLayoutImp::NewL( |
|
63 TAny* /*aInitParams*/ ) |
|
64 { |
|
65 CPeninputHwrBxAbLayoutImp* self = |
|
66 new ( ELeave ) CPeninputHwrBxAbLayoutImp(); |
|
67 CleanupStack::PushL( self ); |
|
68 self->Construct(); |
|
69 CleanupStack::Pop( self ); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CPeninputHwrBxAbLayoutImp::~CPeninputHwrBxAbLayoutImp |
|
76 // (other items were commented in a header) |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CPeninputHwrBxAbLayoutImp::~CPeninputHwrBxAbLayoutImp() |
|
80 { |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CPeninputHwrBxAbLayoutImp::CPeninputHwrBxAbLayoutImp |
|
85 // (other items were commented in a header) |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 CPeninputHwrBxAbLayoutImp::CPeninputHwrBxAbLayoutImp() |
|
89 { |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CPeninputHwrBxAbLayoutImp::ConstructL |
|
94 // (other items were commented in a header) |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 void CPeninputHwrBxAbLayoutImp::Construct() |
|
98 { |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CPeninputHwrBxAbLayoutImp::CreateFepUiLayoutL |
|
103 // (other items were commented in a header) |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CFepUiLayout* CPeninputHwrBxAbLayoutImp::CreateFepUiLayoutL( |
|
107 MLayoutOwner* aLayoutOwner, const TAny* aData ) |
|
108 { |
|
109 CPeninputHwrBxAbLayout* uiLayout = |
|
110 CPeninputHwrBxAbLayout::NewL( aLayoutOwner, aData ); |
|
111 |
|
112 return uiLayout; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CPeninputHwrBxAbLayout::NewL |
|
117 // (other items were commented in a header) |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 CPeninputHwrBxAbLayout* CPeninputHwrBxAbLayout::NewL( |
|
121 MLayoutOwner* aLayoutOwner, |
|
122 const TAny* aInitData ) |
|
123 { |
|
124 CPeninputHwrBxAbLayout* self = |
|
125 new ( ELeave ) CPeninputHwrBxAbLayout( aLayoutOwner ); |
|
126 CleanupStack::PushL( self ); |
|
127 self->ConstructL( aInitData ); |
|
128 CleanupStack::Pop( self ); |
|
129 |
|
130 return self; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // CPeninputHwrBxAbLayout::CPeninputHwrBxAbLayout |
|
135 // (other items were commented in a header) |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 CPeninputHwrBxAbLayout::CPeninputHwrBxAbLayout( |
|
139 MLayoutOwner* aLayoutOwner ) |
|
140 : CPeninputCommonLayout( aLayoutOwner ) |
|
141 { |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // CPeninputHwrBxAbLayout::~CPeninputHwrBxAbLayout |
|
146 // (other items were commented in a header) |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 CPeninputHwrBxAbLayout::~CPeninputHwrBxAbLayout() |
|
150 { |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CPeninputHwrBxAbLayout::ConstructL |
|
155 // (other items were commented in a header) |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 void CPeninputHwrBxAbLayout::ConstructL( const TAny *aInitData ) |
|
159 { |
|
160 CPeninputCommonLayout::ConstructL( aInitData ); |
|
161 |
|
162 |
|
163 CPeninputHwrBxAbStateBase* initState = CPeninputHwrBxAbStateBase::NewL( UiStateMgr(), this ); |
|
164 CPeninputHwrBxAbStateStandby* standbyState = CPeninputHwrBxAbStateStandby::NewL( UiStateMgr(), this ); |
|
165 CPeninputHwrBxAbStateBeginWriting* beginWritingState = CPeninputHwrBxAbStateBeginWriting::NewL( UiStateMgr(), this ); |
|
166 CPeninputHwrBxAbStateEndWriting* endWritingState = CPeninputHwrBxAbStateEndWriting::NewL( UiStateMgr(), this ); |
|
167 CPeninputHwrBxAbStateCandidateSelecting* candSelectingState = CPeninputHwrBxAbStateCandidateSelecting::NewL( UiStateMgr(), this ); |
|
168 |
|
169 UiStateMgr()->AddUiState( initState, EPeninputHwrBxAbStateInit ); |
|
170 UiStateMgr()->AddUiState( standbyState, EPeninputHwrBxAbStateStandby ); |
|
171 UiStateMgr()->AddUiState( beginWritingState, EPeninputHwrBxAbStateBeginWriting ); |
|
172 UiStateMgr()->AddUiState( endWritingState, EPeninputHwrBxAbStateEndWriting ); |
|
173 UiStateMgr()->AddUiState( candSelectingState, EPeninputHwrBxAbStateCandidateSelecting ); |
|
174 UiStateMgr()->SetCurrentUiState( initState ); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CPeninputHwrBxAbLayout::HandleCommand |
|
179 // (other items were commented in a header) |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 TInt CPeninputHwrBxAbLayout::HandleCommand( TInt aCmd, TUint8* aData ) |
|
183 { |
|
184 CPeninputCommonLayout::HandleCommand( aCmd, aData ); |
|
185 |
|
186 if ( aCmd == ECmdPenInputWindowOpen ) |
|
187 { |
|
188 TInt curRange = CPeninputDataConverter::AnyToInt( RequestData( EPeninputDataTypeCurrentRange ) ); |
|
189 UiStateMgr()->SetCurrentUiState( EPeninputHwrBxAbStateStandby ); |
|
190 if (curRange == ERangeNative) |
|
191 { |
|
192 static_cast<CPeninputHwrBxAbWnd *>(LayoutWindow())->ResetAndShowDropdownList(); |
|
193 } |
|
194 else |
|
195 { |
|
196 static_cast<CPeninputHwrBxAbWnd *>(LayoutWindow())->ClearAndCloseDropdownList(); |
|
197 } |
|
198 } |
|
199 else if ( aCmd == ECmdPenInputWindowClose ) |
|
200 { |
|
201 UiStateMgr()->SetCurrentUiState( EPeninputHwrBxAbStateInit ); |
|
202 } |
|
203 else if( aCmd == ECmdPenInputLanguage ) |
|
204 { |
|
205 ((CPeninputHwrBxAbWnd*)iLayoutWindow)->OnLanguageChange(); |
|
206 } |
|
207 else if(aCmd == ECmdPenInputRange) |
|
208 { |
|
209 UiStateMgr()->SetCurrentUiState( EPeninputHwrBxAbStateStandby ); |
|
210 iLayoutWindow->SizeChanged(ETrue); |
|
211 } |
|
212 return KErrNone; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CPeninputHwrBxAbLayout::HandleControlEvent |
|
217 // Handle event from control |
|
218 // --------------------------------------------------------- |
|
219 // |
|
220 void CPeninputHwrBxAbLayout::HandleControlEvent(TInt aEventType, CFepUiBaseCtrl* aCtrl, |
|
221 const TDesC& aEventData) |
|
222 { |
|
223 MPeninputUiStateMgr * UIStateMgr = UiStateMgr(); |
|
224 if (UIStateMgr) |
|
225 { |
|
226 CPeninputHwrBxAbStateBase* current = |
|
227 static_cast<CPeninputHwrBxAbStateBase*>(UIStateMgr->CurrentUiState()); |
|
228 if (current) |
|
229 { |
|
230 TBuf<KMaxCandidateLen> charCode; |
|
231 TBool handled = EFalse; |
|
232 TRAPD(err, current->HandleControlEventPenL(aEventType, aEventData, *this, |
|
233 charCode, handled)); |
|
234 if (KErrNone != err) |
|
235 { // close peninput |
|
236 CPeninputCommonLayout::HandleControlEvent( |
|
237 EPeninputLayoutEventClose, NULL, KNullDesC); |
|
238 handled = ETrue; |
|
239 } |
|
240 if (handled) |
|
241 { |
|
242 return; |
|
243 } |
|
244 } |
|
245 } |
|
246 CPeninputCommonLayout::HandleControlEvent(aEventType, aCtrl, aEventData); |
|
247 |
|
248 return; |
|
249 } |
|
250 // --------------------------------------------------------------------------- |
|
251 // CPeninputHwrBxAbLayout::CreateLayoutWindowL |
|
252 // (other items were commented in a header) |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 void CPeninputHwrBxAbLayout::CreateLayoutWindowL() |
|
256 { |
|
257 iLayoutWindow = CPeninputHwrBxAbWnd::NewL( this, this ); |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // CPeninputHwrBxAbLayout::CreateDataMgrL |
|
262 // (other items were commented in a header) |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 void CPeninputHwrBxAbLayout::CreateDataMgrL( const TAny* aInitData ) |
|
266 { |
|
267 TPeninputLayoutData* layoutData = (TPeninputLayoutData*)aInitData; |
|
268 |
|
269 iDataMgr = CPeninputHwrBxAbDataMgr::NewL( this, (*layoutData).iPtiEngine ); |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CPeninputHwrBxAbLayout::LayoutType |
|
274 // (other items were commented in a header) |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 TInt CPeninputHwrBxAbLayout::LayoutType() |
|
278 { |
|
279 return EPluginInputModeHwr; |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // CPeninputHwrBxAbLayout::SemiTransparencyRequired |
|
284 // (other items were commented in a header) |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 TBool CPeninputHwrBxAbLayout::SemiTransparencyRequired() |
|
288 { |
|
289 return ETrue; |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------------------------- |
|
293 // CPeninputHwrBxAbLayout::LayoutWindow |
|
294 // (other items were commented in a header) |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 CPeninputLayoutWindow* CPeninputHwrBxAbLayout::LayoutWindow() const |
|
298 { |
|
299 return iLayoutWindow; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // CPeninputHwrBxAbLayout::TranslateCharCode |
|
304 // Translate the char code. |
|
305 // --------------------------------------------------------- |
|
306 // |
|
307 void CPeninputHwrBxAbLayout::TranslateCharCode( TDes& aCharCode ) |
|
308 { |
|
309 TPtrC16 ptr; |
|
310 ptr.Set(&KBackRep, sizeof(KBackRep)/2); |
|
311 |
|
312 if (aCharCode.CompareC(ptr) == 0) |
|
313 { |
|
314 aCharCode.Zero(); |
|
315 aCharCode.Append((TChar)EKeyBackspace); |
|
316 } |
|
317 else |
|
318 { |
|
319 ptr.Set(&KSpaceRep, sizeof(KSpaceRep)/2); |
|
320 if (aCharCode.CompareC(ptr) == 0) |
|
321 { |
|
322 aCharCode.Zero(); |
|
323 aCharCode.Append((TChar)EKeySpace); |
|
324 } |
|
325 else |
|
326 { |
|
327 ptr.Set(&KEnterRep, sizeof(KEnterRep)/2); |
|
328 if (aCharCode.CompareC(ptr) == 0) |
|
329 { |
|
330 aCharCode.Zero(); |
|
331 aCharCode.Append((TChar)EKeyEnter); |
|
332 } |
|
333 } |
|
334 } |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------------------------- |
|
338 // CPeninputHwrBxAbLayout::ReplaceL |
|
339 // Delete the previous charcode and submit the new one |
|
340 // --------------------------------------------------------- |
|
341 // |
|
342 void CPeninputHwrBxAbLayout::ReplaceL(const TDesC& aOldCharCode, const TDesC& aNewCharCode) |
|
343 { |
|
344 // user tries to correct the previous selection |
|
345 // Delete the previous character and append the new one |
|
346 _LIT(KSpaceChar, " "); |
|
347 TBuf<1> buf; |
|
348 buf.Zero(); |
|
349 buf.Append(KSpaceChar); |
|
350 HBufC* p = NULL; |
|
351 HBufC* oldCharCode = aOldCharCode.AllocLC(); |
|
352 HBufC* newCharCode = aNewCharCode.AllocLC(); |
|
353 |
|
354 if (static_cast<CPeninputHwrBxAbWnd *>(LayoutWindow())->IsAddingSpace(newCharCode)) |
|
355 { |
|
356 p = HBufC::New(aNewCharCode.Length() + 2 + buf.Length()); |
|
357 } |
|
358 else |
|
359 { |
|
360 p = HBufC::New(aNewCharCode.Length() + 2); |
|
361 } |
|
362 if( p ) |
|
363 { |
|
364 TInt len = aOldCharCode.Length(); |
|
365 if (static_cast<CPeninputHwrBxAbWnd *>(LayoutWindow())->IsAddingSpace(oldCharCode)) |
|
366 { |
|
367 len += buf.Length(); |
|
368 } |
|
369 p->Des().Append((TUint16*)&len, 2); |
|
370 p->Des().Append(aNewCharCode); |
|
371 if (static_cast<CPeninputHwrBxAbWnd *>(LayoutWindow())->IsAddingSpace(newCharCode)) |
|
372 { |
|
373 p->Des().Append(buf); |
|
374 } |
|
375 SignalOwner( ESignalReplaceText, *p ); |
|
376 delete p; |
|
377 } |
|
378 CleanupStack::PopAndDestroy(newCharCode); |
|
379 CleanupStack::PopAndDestroy(oldCharCode); |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------------------------- |
|
383 // CPeninputHwrBxAbLayout::SubmitL |
|
384 // Submit the char code. |
|
385 // --------------------------------------------------------- |
|
386 // |
|
387 void CPeninputHwrBxAbLayout::SubmitL(const TDesC& aCharCode) |
|
388 { |
|
389 HBufC* buf = HBufC::NewLC(aCharCode.Length()); |
|
390 TPtr charcode(buf->Des()); |
|
391 charcode = aCharCode; |
|
392 TranslateCharCode( charcode ); |
|
393 SignalOwner(ESignalKeyEvent, charcode); |
|
394 |
|
395 CleanupStack::PopAndDestroy(buf); |
|
396 } |
|
397 |
|
398 //End Of File |