|
1 /* |
|
2 * Copyright (c) 2007-2007 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: Implementation for PeninputLayoutControl |
|
15 * |
|
16 */ |
|
17 |
|
18 //#include <e32base.h> |
|
19 #include <AknIconUtils.h> |
|
20 #include <w32std.h> |
|
21 #include <AknsDrawUtils.h> |
|
22 #include <eikenv.h> |
|
23 #include <AknsConstants.h> |
|
24 #include <AknUtils.h> |
|
25 |
|
26 #include "peninputlayoutvirtualkeyctrl.h" |
|
27 #include "peninputlayoutvkb.h" |
|
28 #include "peninputlayout.h" |
|
29 #include "peninputpluginutils.h" |
|
30 |
|
31 _LIT( KKeyShiftCharacter, "\x2191"); |
|
32 |
|
33 const TInt KDefaultKeyMargin = 10; |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // CVirtualKeyCtrl::NewL |
|
37 // Static factory creator |
|
38 // (other items were commented in a header). |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CVirtualKeyCtrl* CVirtualKeyCtrl::NewL(CVirtualKeyboard* aKeyboard, |
|
42 CVirtualKey* aKeyInfo) |
|
43 { |
|
44 if(!aKeyInfo || !aKeyboard) |
|
45 return 0; |
|
46 |
|
47 CVirtualKeyCtrl* keyCtrl = new(ELeave) CVirtualKeyCtrl(aKeyboard,aKeyInfo); |
|
48 CleanupStack::PushL(keyCtrl); |
|
49 keyCtrl->ConstructL(); |
|
50 CleanupStack::Pop(); |
|
51 return keyCtrl; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CVirtualKeyCtrl::CVirtualKeyCtrl |
|
56 // constuctor |
|
57 // (other items were commented in a header). |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CVirtualKeyCtrl::CVirtualKeyCtrl(CVirtualKeyboard* aKeyboard, CVirtualKey* aKeyInfo) |
|
61 :CFepUiBaseCtrl(aKeyInfo->Rect(), aKeyboard->UiLayout(),-1), |
|
62 iKeyInfo(aKeyInfo), iKeyboard(aKeyboard) |
|
63 { |
|
64 SetControlType(ECtrlVirtualKey); |
|
65 //virtual key postion is kept as relative to key board, so we must change the |
|
66 //key control's position relative to layout. |
|
67 Move(aKeyboard->Rect().iTl); |
|
68 |
|
69 #ifdef RD_TACTILE_FEEDBACK |
|
70 //register the key feedback area |
|
71 //UiLayout()->RegisterFeedbackArea(reinterpret_cast<TInt>(this),Rect()); |
|
72 #endif // RD_TACTILE_FEEDBACK |
|
73 |
|
74 aKeyInfo->iKeyCtrl = this; |
|
75 iScanCode = aKeyInfo->ScanCode(); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CVirtualKeyCtrl::~CVirtualKeyCtrl |
|
80 // destructor |
|
81 // (other items were commented in a header). |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 CVirtualKeyCtrl::~CVirtualKeyCtrl() |
|
85 { |
|
86 //Never uncomment the following statement. When this control is deleted, |
|
87 //iKeyInfo may be already invalid!!! |
|
88 //iKeyInfo->iKeyCtrl = 0; |
|
89 |
|
90 #ifdef RD_TACTILE_FEEDBACK |
|
91 UiLayout()->DeRegisterFeedbackArea(reinterpret_cast<TInt>(this),Rect()); |
|
92 #endif // RD_TACTILE_FEEDBACK |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CVirtualKeyCtrl::ConsructL |
|
97 // 2nd phase constuctor |
|
98 // (other items were commented in a header). |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CVirtualKeyCtrl::ConstructL() |
|
102 { |
|
103 BaseConstructL(); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CVirtualKeyCtrl::DrawKeyText |
|
108 // Draw key text |
|
109 // (other items were commented in a header). |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CVirtualKeyCtrl::DrawKeyText() |
|
113 { |
|
114 TBool textlineset = EFalse; |
|
115 |
|
116 // if text line set |
|
117 for (TInt i = 0; i <= EPosLast; i++) |
|
118 { |
|
119 if (iKeyboard->TextLineLayoutSet(TVirtualKeyTextPos(i))) |
|
120 { |
|
121 textlineset = ETrue; |
|
122 |
|
123 if (iKeyInfo->KeyUnicodes(TVirtualKeyTextPos(i)) != KNullDesC) |
|
124 { |
|
125 TAknLayoutText textLayout; |
|
126 textLayout.LayoutText(Rect(), |
|
127 iKeyboard->TextLineLayout(TVirtualKeyTextPos(i))); |
|
128 TRgb color( KRgbBlack ); // sane default for nonskinned case |
|
129 if ( AknsUtils::AvkonSkinEnabled() ) |
|
130 { |
|
131 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
132 color, |
|
133 KAknsIIDQsnTextColors, |
|
134 iKeyboard->KeyTextColorGroup() ); |
|
135 } |
|
136 |
|
137 // replace the shift text to shift icon |
|
138 if( iKeyboard->ShiftIcon() && |
|
139 iKeyInfo->KeyUnicodes(TVirtualKeyTextPos(i)) == KKeyShiftCharacter ) |
|
140 { |
|
141 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
142 AknPenInputDrawUtils::DrawColorIcon( iKeyboard->ShiftIcon(), |
|
143 *gc, |
|
144 textLayout.TextRect() ); |
|
145 } |
|
146 else |
|
147 { |
|
148 textLayout.DrawText(*BitGc(), iKeyInfo->KeyUnicodes(TVirtualKeyTextPos(i)), |
|
149 EFalse, color); |
|
150 } |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 if (!textlineset) |
|
156 { |
|
157 TAknLayoutText textLayout; |
|
158 textLayout.LayoutText(Rect(), iKeyboard->iVKBTextLineLayout); |
|
159 |
|
160 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
161 |
|
162 //charRect.Move(keyboardRect.iTl); |
|
163 //if(iKeyInfo->Dimmed()) |
|
164 // { |
|
165 // gc->SetFadingParameters(iKeyboard->iFadingParamBlack, iKeyboard->iFadingParamWhite); |
|
166 // gc->SetFaded(ETrue); |
|
167 // } |
|
168 TRgb color( KRgbBlack ); // sane default for nonskinned case |
|
169 if ( AknsUtils::AvkonSkinEnabled() || |
|
170 iKeyboard->KeyTextColorGroup() != INVALID_COLOR_GROUP ) |
|
171 { |
|
172 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
173 color, |
|
174 KAknsIIDQsnTextColors, |
|
175 iKeyboard->KeyTextColorGroup() ); |
|
176 } |
|
177 else |
|
178 { |
|
179 color = iKeyboard->iFontColor; |
|
180 } |
|
181 |
|
182 if( iKeyInfo->Dimmed() ) |
|
183 { |
|
184 color = KRgbGray; |
|
185 } |
|
186 if( iKeyInfo->DisplayUnicode() && iKeyInfo->DisplayUnicode()->Length() != 0) |
|
187 { |
|
188 textLayout.DrawText(*BitGc(), *iKeyInfo->DisplayUnicode(), EFalse, color); |
|
189 } |
|
190 else |
|
191 { |
|
192 textLayout.DrawText(*BitGc(), iKeyInfo->KeyUnicodes(), EFalse, color); |
|
193 } |
|
194 |
|
195 //if(iKeyInfo->Dimmed()) |
|
196 // gc->SetFaded(EFalse); |
|
197 |
|
198 } |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CVirtualKeyCtrl::DrawDimKey |
|
203 // Draw dimmed key |
|
204 // (other items were commented in a header). |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 void CVirtualKeyCtrl::DrawDimKey() |
|
208 { |
|
209 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
210 TRect rect = Rect(); |
|
211 TRect bmpRect(TPoint(0,0),rect.Size()); |
|
212 gc->Activate( BitmapDevice() ); |
|
213 |
|
214 |
|
215 if(iVirtualKeyDrawInfo.iVKDimLeftImgID.iMajor && |
|
216 iVirtualKeyDrawInfo.iVKDimMiddleImgID.iMajor && |
|
217 iVirtualKeyDrawInfo.iVKDimRightImgID.iMajor) |
|
218 { |
|
219 TRect innerRect = Rect(); |
|
220 innerRect.Shrink( 4, 0 ); |
|
221 |
|
222 AknPenInputDrawUtils::Draw3PiecesFrame(AknsUtils::SkinInstance(), |
|
223 *gc, |
|
224 Rect(), |
|
225 innerRect, |
|
226 iVirtualKeyDrawInfo.iVKDimLeftImgID, |
|
227 iVirtualKeyDrawInfo.iVKDimMiddleImgID, |
|
228 iVirtualKeyDrawInfo.iVKDimRightImgID); |
|
229 } |
|
230 else if (iKeyboard->IsIrregularKeyBoard()) |
|
231 { |
|
232 DrawIrregularKey(EKeyStateDimmed, EKeyStateDimmedMask); |
|
233 } |
|
234 else if (iKeyboard->KeySkinId(EKeyBmpDim) != KAknsIIDNone) |
|
235 { |
|
236 TRect innerrect = rect; |
|
237 innerrect.Shrink( KDefaultKeyMargin, KDefaultKeyMargin ); |
|
238 |
|
239 AknsDrawUtils::DrawFrame(AknsUtils::SkinInstance(), |
|
240 *gc, |
|
241 rect, |
|
242 innerrect, |
|
243 iKeyboard->KeySkinId(EKeyBmpDim), |
|
244 KAknsIIDDefault); |
|
245 } |
|
246 else if( iKeyboard->NonIrregularKeyBitmap( EKeyBmpDim ) ) |
|
247 { |
|
248 TRect srcRect(TPoint(0,0), iKeyboard->NonIrregularKeyBitmap( EKeyBmpDim )->SizeInPixels()); |
|
249 DrawBmp(rect, |
|
250 srcRect, |
|
251 iKeyboard->NonIrregularKeyBitmap( EKeyBmpDim ), |
|
252 iKeyboard->NonIrregularKeyBitmap( EkeyBmpDimMask ), |
|
253 ETrue); |
|
254 } |
|
255 else if (iKeyboard->iDimKeyBmp) |
|
256 { |
|
257 TRect srcRect(TPoint(0,0),iKeyboard->iDimKeyBmp->SizeInPixels()); |
|
258 DrawBmp(rect,srcRect,iKeyboard->iDimKeyBmp, |
|
259 iKeyboard->iDimKeyMaskBmp,ETrue); |
|
260 } |
|
261 |
|
262 else |
|
263 { |
|
264 gc->SetFaded(ETrue); |
|
265 |
|
266 //use if keboard has background bitmap |
|
267 if (iKeyboard->BackgroundBmp()) |
|
268 { |
|
269 TRect srcRect = Rect(); |
|
270 srcRect.Move(-iKeyboard->Rect().iTl); |
|
271 DrawBmp(Rect(),srcRect,iKeyboard->BackgroundBmp(),iKeyboard->BkMaskBmp()); |
|
272 } |
|
273 else |
|
274 { |
|
275 //self draw background if background bitmap |
|
276 gc->SetBrushColor( BkColor()); |
|
277 gc->SetPenColor( BkColor() ); |
|
278 gc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
279 gc->DrawRect(rect); |
|
280 } |
|
281 } |
|
282 |
|
283 gc->SetPenColor(KRgbBlack); |
|
284 gc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
285 //Draw text again. |
|
286 DrawKeyText(); |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // CVirtualKeyCtrl::DrawBmp |
|
291 // Draw bitmap |
|
292 // (other items were commented in a header). |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 void CVirtualKeyCtrl::DrawBmp(const TRect& aDestRect,const TRect& aSourceRect, |
|
296 const CFbsBitmap* aBmp,CFbsBitmap* aMask, |
|
297 TBool aInvertFlag) |
|
298 { |
|
299 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
300 if(aMask) |
|
301 { |
|
302 //TRect bmpRect(TPoint(0,0),aMask->SizeInPixels()); |
|
303 gc->DrawBitmapMasked(aDestRect,aBmp,aSourceRect,aMask,aInvertFlag); |
|
304 } |
|
305 else |
|
306 { |
|
307 gc->DrawBitmap(aDestRect,aBmp,aSourceRect); |
|
308 } |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // CVirtualKeyCtrl::DrawNormalStateKey |
|
313 // Draw key in normal state |
|
314 // (other items were commented in a header). |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 void CVirtualKeyCtrl::DrawNormalStateKey() |
|
318 { |
|
319 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
320 |
|
321 TRect rect = Rect(); |
|
322 TRect bmpRect(TPoint(0,0),rect.Size()); |
|
323 |
|
324 if(iVirtualKeyDrawInfo.iVKLeftImgID.iMajor && |
|
325 iVirtualKeyDrawInfo.iVKMiddleImgID.iMajor && |
|
326 iVirtualKeyDrawInfo.iVKRightImgID.iMajor) |
|
327 { |
|
328 TRect innerRect = Rect(); |
|
329 innerRect.Shrink( 4, 0 ); |
|
330 |
|
331 AknPenInputDrawUtils::Draw3PiecesFrame(AknsUtils::SkinInstance(), |
|
332 *gc, |
|
333 Rect(), |
|
334 innerRect, |
|
335 iVirtualKeyDrawInfo.iVKLeftImgID, |
|
336 iVirtualKeyDrawInfo.iVKMiddleImgID, |
|
337 iVirtualKeyDrawInfo.iVKRightImgID); |
|
338 } |
|
339 else if (iKeyboard->IsIrregularKeyBoard()) |
|
340 { |
|
341 DrawIrregularKey(EKeyStateNormal, EKeyStateNormalMask); |
|
342 } |
|
343 else if (iKeyboard->KeySkinId(EKeyBmpNormal) != KAknsIIDNone) |
|
344 { |
|
345 TRect innerrect = rect; |
|
346 innerrect.Shrink( KDefaultKeyMargin, KDefaultKeyMargin ); |
|
347 |
|
348 AknsDrawUtils::DrawFrame(AknsUtils::SkinInstance(), |
|
349 *gc, |
|
350 rect, |
|
351 innerrect, |
|
352 iKeyboard->KeySkinId(EKeyBmpNormal), |
|
353 KAknsIIDDefault); |
|
354 } |
|
355 else if( iKeyboard->NonIrregularKeyBitmap( EKeyBmpNormal ) ) |
|
356 { |
|
357 TRect srcRect(TPoint(0,0), |
|
358 iKeyboard->NonIrregularKeyBitmap( EKeyBmpNormal )->SizeInPixels()); |
|
359 DrawBmp(rect, |
|
360 srcRect, |
|
361 iKeyboard->NonIrregularKeyBitmap( EKeyBmpNormal ), |
|
362 iKeyboard->NonIrregularKeyBitmap( EKeyBmpNormalMask ), |
|
363 ETrue); |
|
364 } |
|
365 |
|
366 else |
|
367 { |
|
368 gc->SetFaded(EFalse); |
|
369 |
|
370 //use if keboard has background bitmap |
|
371 if (iKeyboard->BackgroundBmp()) |
|
372 { |
|
373 TRect srcRect = Rect(); |
|
374 srcRect.Move(-iKeyboard->Rect().iTl); |
|
375 DrawBmp(Rect(),srcRect,iKeyboard->BackgroundBmp(),iKeyboard->BkMaskBmp()); |
|
376 } |
|
377 else |
|
378 { |
|
379 //self draw background if background bitmap |
|
380 gc->SetBrushColor( BkColor()); |
|
381 gc->SetPenColor( BkColor() ); |
|
382 gc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
383 gc->DrawRect(rect); |
|
384 } |
|
385 } |
|
386 |
|
387 gc->SetPenColor( KRgbBlack ); |
|
388 gc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
389 gc->SetFaded(EFalse); |
|
390 DrawKeyText(); |
|
391 } |
|
392 |
|
393 // --------------------------------------------------------------------------- |
|
394 // CVirtualKeyCtrl::DrawHighlightKey |
|
395 // Draw key in highlight state |
|
396 // (other items were commented in a header). |
|
397 // --------------------------------------------------------------------------- |
|
398 // |
|
399 void CVirtualKeyCtrl::DrawHighlightKey() |
|
400 { |
|
401 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
402 TRect rect = Rect(); |
|
403 TPoint bmpPos = rect.iTl; |
|
404 TRect bmpRect(TPoint(0,0),rect.Size()); |
|
405 |
|
406 if(iVirtualKeyDrawInfo.iVKPressedLeftImgID.iMajor && |
|
407 iVirtualKeyDrawInfo.iVKPressedMiddleImgID.iMajor && |
|
408 iVirtualKeyDrawInfo.iVKPressedRightImgID.iMajor) |
|
409 { |
|
410 TRect innerRect = Rect(); |
|
411 innerRect.Shrink( 4, 0 ); |
|
412 |
|
413 AknPenInputDrawUtils::Draw3PiecesFrame(AknsUtils::SkinInstance(), |
|
414 *gc, |
|
415 Rect(), |
|
416 innerRect, |
|
417 iVirtualKeyDrawInfo.iVKPressedLeftImgID, |
|
418 iVirtualKeyDrawInfo.iVKPressedMiddleImgID, |
|
419 iVirtualKeyDrawInfo.iVKPressedRightImgID); |
|
420 |
|
421 } |
|
422 else if (iKeyboard->IsIrregularKeyBoard()) |
|
423 { |
|
424 DrawIrregularKey(EKeyStatePressed, EKeyStatePressedMask); |
|
425 } |
|
426 |
|
427 //do we have highlight background bmp for this key? |
|
428 else if (iKeyboard->KeySkinId(EKeyBmpHighlight) != KAknsIIDNone) |
|
429 { |
|
430 TRect innerrect = rect; |
|
431 innerrect.Shrink( KDefaultKeyMargin, KDefaultKeyMargin ); |
|
432 |
|
433 AknsDrawUtils::DrawFrame(AknsUtils::SkinInstance(), |
|
434 *gc, |
|
435 rect, |
|
436 innerrect, |
|
437 iKeyboard->KeySkinId(EKeyBmpHighlight), |
|
438 KAknsIIDDefault); |
|
439 } |
|
440 else if( iKeyboard->NonIrregularKeyBitmap( EKeyBmpHighlight ) ) |
|
441 { |
|
442 TRect srcRect(TPoint(0,0), |
|
443 iKeyboard->NonIrregularKeyBitmap( EKeyBmpHighlight )->SizeInPixels()); |
|
444 DrawBmp(rect, |
|
445 srcRect, |
|
446 iKeyboard->NonIrregularKeyBitmap( EKeyBmpHighlight ), |
|
447 iKeyboard->NonIrregularKeyBitmap( EKeyBmpHighlightMask ), |
|
448 ETrue); |
|
449 } |
|
450 else if(iKeyInfo->HighlightBmpIndex() >= 0 && |
|
451 iKeyInfo->HighlightBmpIndex() < iKeyboard->iKeyHighLightBmpList.Count()) |
|
452 { |
|
453 gc->DrawBitmap(rect,iKeyboard->iKeyHighLightBmpList[iKeyInfo->HighlightBmpIndex()]); |
|
454 } |
|
455 else //using fading |
|
456 { |
|
457 gc->SetFadingParameters(iKeyboard->iFadingParamBlack, iKeyboard->iFadingParamWhite); |
|
458 gc->SetFaded(ETrue); |
|
459 |
|
460 if(iKeyboard->BackgroundBmp())//use keyboard background bitmap |
|
461 { |
|
462 gc->BitBlt(bmpPos, iKeyboard->BackgroundBmp(), iKeyInfo->Rect()); |
|
463 } |
|
464 else //draw background if not background bitmap |
|
465 { |
|
466 gc->SetBrushColor( BkColor()); |
|
467 gc->SetPenColor( BkColor() ); |
|
468 gc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
469 gc->DrawRect(rect); |
|
470 } |
|
471 } |
|
472 |
|
473 gc->SetPenColor( KRgbBlack ); |
|
474 |
|
475 gc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
476 gc->SetFaded(EFalse); |
|
477 DrawKeyText(); |
|
478 |
|
479 } |
|
480 |
|
481 // --------------------------------------------------------------------------- |
|
482 // CVirtualKeyCtrl::Draw |
|
483 // Draw key |
|
484 // (other items were commented in a header). |
|
485 // --------------------------------------------------------------------------- |
|
486 // |
|
487 void CVirtualKeyCtrl::Draw() |
|
488 { |
|
489 if(!AbleToDraw()) |
|
490 return; |
|
491 |
|
492 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
493 |
|
494 //mask bitmaps |
|
495 DrawOpaqueMaskBackground(); |
|
496 |
|
497 // ----- draw bitmaps ----- |
|
498 gc->Activate( BitmapDevice() ); |
|
499 |
|
500 /* if (iScanCode == -1 && !iKeyInfo->Dimmed() && iKeyboard) |
|
501 { |
|
502 iKeyboard->DimKey(iKeyInfo, ETrue); |
|
503 }*/ |
|
504 |
|
505 if(iKeyInfo->Dimmed()) |
|
506 { |
|
507 DrawDimKey(); |
|
508 return; |
|
509 } |
|
510 |
|
511 if(iKeyInfo->Latched()||(PointerDown()&&!iKeyInfo->IsLatchKey())) |
|
512 { |
|
513 DrawHighlightKey(); |
|
514 |
|
515 // remove DrawBubble() into HandlePointerDownEventL() |
|
516 // to avoid showing more than one bubble at the same time. |
|
517 // iKeyboard->DrawBubble(iKeyInfo); |
|
518 } |
|
519 else |
|
520 { |
|
521 DrawNormalStateKey(); |
|
522 } |
|
523 } |
|
524 |
|
525 // --------------------------------------------------------------------------- |
|
526 // CVirtualKeyCtrl::HandlePointerDownEventL |
|
527 // Handle pointer down event |
|
528 // (other items were commented in a header). |
|
529 // --------------------------------------------------------------------------- |
|
530 // |
|
531 CFepUiBaseCtrl* CVirtualKeyCtrl::HandlePointerDownEventL(const TPoint& aPoint) |
|
532 { |
|
533 //do nothing if key is dimmed. |
|
534 if(iKeyInfo->Dimmed()) |
|
535 return this; |
|
536 |
|
537 CFepUiBaseCtrl::HandlePointerDownEventL(aPoint); |
|
538 |
|
539 //draw key new state |
|
540 iKeyboard->DrawBubble(iKeyInfo); |
|
541 ReDraw(); |
|
542 UpdateArea( Rect() ); |
|
543 |
|
544 if(iKeyInfo->IsLatchKey()) |
|
545 { |
|
546 // Only set latch status, not generate event for latch key |
|
547 iKeyInfo->SetLatched(!iKeyInfo->Latched()); |
|
548 } |
|
549 else |
|
550 { |
|
551 ReportKeyEvent(GetKeyEventType(EVirtualKeyControlDown)); |
|
552 } |
|
553 |
|
554 return this; |
|
555 } |
|
556 |
|
557 // --------------------------------------------------------------------------- |
|
558 // CVirtualKeyCtrl::HandlePointerUpEventL |
|
559 // Handle pointer up event |
|
560 // (other items were commented in a header). |
|
561 // --------------------------------------------------------------------------- |
|
562 // |
|
563 CFepUiBaseCtrl* CVirtualKeyCtrl::HandlePointerUpEventL(const TPoint& aPoint) |
|
564 { |
|
565 if(!PointerDown() || iKeyInfo->Dimmed()) |
|
566 { |
|
567 return this; |
|
568 } |
|
569 CFepUiBaseCtrl::HandlePointerUpEventL(aPoint); |
|
570 |
|
571 iKeyboard->ClearBubble(ETrue); |
|
572 |
|
573 TControlEvent eventType = GetKeyEventType(EVirtualKeyControlUp); |
|
574 if(iKeyInfo->IsLatchKey()) |
|
575 { |
|
576 // When key up, latch key will generate event. |
|
577 // When key down, latch key won't generate event. |
|
578 eventType = iKeyInfo->Latched() ? EEventVirtualKeyLatched : EEventVirtualKeyUnLatched; |
|
579 } |
|
580 ReDraw(); |
|
581 UpdateAreaImmed( Rect() ); |
|
582 ReportKeyEvent(eventType); |
|
583 |
|
584 |
|
585 //Advanced tactile feedback REQ 417-47932 |
|
586 #ifdef RD_TACTILE_FEEDBACK |
|
587 if (UiLayout()->SupportTactileFeedback()) |
|
588 { |
|
589 UiLayout()->DoTactileFeedback(ETouchFeedbackSensitiveInput, ETrue, EFalse); |
|
590 } |
|
591 #endif // RD_TACTILE_FEEDBACK |
|
592 return this; |
|
593 } |
|
594 |
|
595 // --------------------------------------------------------------------------- |
|
596 // CVirtualKeyCtrl::HandlePointerEnter |
|
597 // Handle pointer enter event |
|
598 // (other items were commented in a header). |
|
599 // --------------------------------------------------------------------------- |
|
600 // |
|
601 void CVirtualKeyCtrl::HandlePointerEnter(const TPoint& aPoint) |
|
602 { |
|
603 //do nothing if key is dimmed. |
|
604 if(iKeyInfo->Dimmed()) |
|
605 return; |
|
606 |
|
607 CFepUiBaseCtrl::HandlePointerEnter(aPoint); |
|
608 if(iKeyInfo->IsLatchKey()) |
|
609 { |
|
610 iKeyInfo->SetLatched(!iKeyInfo->Latched()); |
|
611 } |
|
612 |
|
613 iKeyboard->DrawBubble(iKeyInfo); |
|
614 ReDraw(); |
|
615 UpdateArea( Rect() ); |
|
616 |
|
617 } |
|
618 |
|
619 // --------------------------------------------------------------------------- |
|
620 // CVirtualKeyCtrl::HandlePointerLeave |
|
621 // Handle pointer left event |
|
622 // (other items were commented in a header). |
|
623 // --------------------------------------------------------------------------- |
|
624 // |
|
625 void CVirtualKeyCtrl::HandlePointerLeave(const TPoint& aPoint) |
|
626 { |
|
627 //do nothing if key is dimmed. |
|
628 if(iKeyInfo->Dimmed()) |
|
629 return; |
|
630 |
|
631 CFepUiBaseCtrl::HandlePointerLeave(aPoint); |
|
632 if(iKeyInfo->IsLatchKey()) |
|
633 { |
|
634 iKeyInfo->SetLatched(!iKeyInfo->Latched()); |
|
635 } |
|
636 |
|
637 iKeyboard->ClearBubble(ETrue); |
|
638 ReDraw(); |
|
639 UpdateArea( Rect() ); |
|
640 |
|
641 #ifdef RD_TACTILE_FEEDBACK |
|
642 if ( iKeyboard->GowithPointerDown() ) |
|
643 { |
|
644 |
|
645 if (UiLayout()->SupportTactileFeedback()) |
|
646 { |
|
647 if (!Hiden()) |
|
648 { |
|
649 UiLayout()->DoTactileFeedback(ETouchFeedbackCharacterInputButton, ETrue, EFalse); |
|
650 } |
|
651 } |
|
652 } |
|
653 #endif //RD_TACTILE_FEEDBACK |
|
654 } |
|
655 |
|
656 void CVirtualKeyCtrl::CancelPointerDownL() |
|
657 { |
|
658 CFepUiBaseCtrl::CancelPointerDownL(); |
|
659 iKeyboard->ClearBubble(ETrue); |
|
660 ReDraw(); |
|
661 UpdateArea( Rect() ); |
|
662 } |
|
663 // --------------------------------------------------------------------------- |
|
664 // CVirtualKeyCtrl::ReDraw |
|
665 // Redraw and updates the key |
|
666 // (other items were commented in a header). |
|
667 // --------------------------------------------------------------------------- |
|
668 // |
|
669 void CVirtualKeyCtrl::ReDraw() |
|
670 { |
|
671 Draw(); |
|
672 UpdateArea(Rect(), EFalse); |
|
673 } |
|
674 |
|
675 // --------------------------------------------------------------------------- |
|
676 // CVirtualKeyCtrl::ReportKeyEvent |
|
677 // Report current key event |
|
678 // (other items were commented in a header). |
|
679 // --------------------------------------------------------------------------- |
|
680 // |
|
681 void CVirtualKeyCtrl::ReportKeyEvent(TControlEvent aEventType) |
|
682 { |
|
683 if (iKeyInfo->ScanCode() == 0xffffffff || |
|
684 iKeyInfo->ScanCode() == 0xffff) |
|
685 { |
|
686 return; |
|
687 } |
|
688 |
|
689 TVirtualKeyEventData eventData; |
|
690 |
|
691 eventData.iKeyEvent.iCode = iKeyInfo->KeyCode(); |
|
692 eventData.iKeyEvent.iScanCode = iKeyInfo->ScanCode(); |
|
693 |
|
694 TInt unicodeidx; |
|
695 |
|
696 if (iKeyInfo->UnicodesListEmpty(unicodeidx)) |
|
697 { |
|
698 eventData.iKeyData.Set(iKeyInfo->KeyUnicodes()); |
|
699 } |
|
700 else |
|
701 { |
|
702 eventData.iKeyData.Set(iKeyInfo->KeyUnicodes(TVirtualKeyTextPos(unicodeidx))); |
|
703 } |
|
704 eventData.iKey = iKeyInfo; |
|
705 TPtrC eventDataPtr; |
|
706 eventDataPtr.Set(reinterpret_cast<TUint16*>(&eventData),sizeof(eventData)/sizeof(TUint16)); |
|
707 |
|
708 iKeyboard->ReportEvent(aEventType,eventDataPtr); |
|
709 } |
|
710 |
|
711 // --------------------------------------------------------------------------- |
|
712 // CVirtualKeyCtrl::GetKeyEventType |
|
713 // Convert event type |
|
714 // (other items were commented in a header). |
|
715 // --------------------------------------------------------------------------- |
|
716 // |
|
717 TControlEvent CVirtualKeyCtrl::GetKeyEventType(TVirtualKeyEventType aEvent) |
|
718 { |
|
719 TControlEvent event = EEventVirtualKeyUp; |
|
720 switch(aEvent) |
|
721 { |
|
722 case EVirtualKeyControlUp: |
|
723 event = EEventVirtualKeyUp; |
|
724 break; |
|
725 case EVirtualKeyControlDown: |
|
726 event = EEventVirtualKeyDown; |
|
727 break; |
|
728 default: |
|
729 __ASSERT_DEBUG(EFalse, User::Panic(_L("peninputserver"), EUiLayoutBadEvent)); |
|
730 } |
|
731 return event; |
|
732 } |
|
733 |
|
734 TBool CVirtualKeyCtrl::Contains(const TPoint& aPt) |
|
735 { |
|
736 if (!CFepUiBaseCtrl::Contains(aPt)) // OR: if (!iRect.Contains(aPt)) |
|
737 { |
|
738 return EFalse; |
|
739 } |
|
740 |
|
741 if (iKeyboard->IsIrregularKeyBoard()) |
|
742 { |
|
743 return MaskBmpContains(aPt); |
|
744 } |
|
745 |
|
746 return ETrue; |
|
747 } |
|
748 |
|
749 TBool CVirtualKeyCtrl::MaskBmpContains(const TPoint& aPt) |
|
750 { |
|
751 // judge if mask bitmap contains a point |
|
752 TRgb ptColor; |
|
753 |
|
754 // map aPt to maskbmp's point |
|
755 TPoint ptInBmp = TPoint(aPt.iX - iRect.iTl.iX, aPt.iY - iRect.iTl.iY); |
|
756 |
|
757 CFbsBitmap* maskbmp = MaskBmp(); |
|
758 if (!maskbmp) |
|
759 { |
|
760 return EFalse; |
|
761 } |
|
762 |
|
763 // before following call, when mask bitmap created, you must call IMPORT_C static void DisableCompression( CFbsBitmap* aBitmap ); in akniconutils.h to make sure following call not crash |
|
764 maskbmp->GetPixel(ptColor, ptInBmp); |
|
765 |
|
766 return (ptColor != KRgbBlack); |
|
767 } |
|
768 |
|
769 CFbsBitmap* CVirtualKeyCtrl::MaskBmp() // there may be other method to get mask bitmap |
|
770 { |
|
771 if (iKeyInfo->Dimmed()) |
|
772 { |
|
773 return iKeyboard->IrregularKeyBitmap(iKeyInfo->IrregualrKeyType(),EKeyStateDimmedMask); |
|
774 } |
|
775 |
|
776 if (PointerDown() || iKeyInfo->Latched()) |
|
777 { |
|
778 return iKeyboard->IrregularKeyBitmap(iKeyInfo->IrregualrKeyType(),EKeyStatePressedMask); |
|
779 } |
|
780 return iKeyboard->IrregularKeyBitmap(iKeyInfo->IrregualrKeyType(),EKeyStateNormalMask); |
|
781 } |
|
782 |
|
783 void CVirtualKeyCtrl::DrawIrregularKey(TVirtualKeyIrregularKeyState aKeyState, |
|
784 TVirtualKeyIrregularKeyState aKeyStateMask) |
|
785 { |
|
786 TRect rect = Rect(); |
|
787 |
|
788 if( rect.IsEmpty() ) |
|
789 { |
|
790 return; |
|
791 } |
|
792 TSize bitmapSize = |
|
793 iKeyboard->IrregularKeyBitmap(iKeyInfo->IrregualrKeyType(),aKeyState)->SizeInPixels(); |
|
794 |
|
795 |
|
796 TRect srcRect(TPoint(0,0), bitmapSize); |
|
797 |
|
798 DrawBmp(rect, |
|
799 srcRect, |
|
800 iKeyboard->IrregularKeyBitmap(iKeyInfo->IrregualrKeyType(),aKeyState), |
|
801 iKeyboard->IrregularKeyBitmap(iKeyInfo->IrregualrKeyType(),aKeyStateMask), |
|
802 ETrue); |
|
803 |
|
804 } |
|
805 |
|
806 void CVirtualKeyCtrl::SetVirtualKeyImgID(TVirtualKeyDrawInfo aVirtualKeyDrawInfo) |
|
807 { |
|
808 iVirtualKeyDrawInfo = aVirtualKeyDrawInfo; |
|
809 } |
|
810 |
|
811 //implementation for class CVirtualRawKeyCtrl |
|
812 // --------------------------------------------------------------------------- |
|
813 // CVirtualRawKeyCtrl::NewL |
|
814 // Factory function |
|
815 // (other items were commented in a header). |
|
816 // --------------------------------------------------------------------------- |
|
817 // |
|
818 CVirtualRawKeyCtrl* CVirtualRawKeyCtrl::NewL(CVirtualKeyboard* aKeyboard, |
|
819 CVirtualKey* aKeyInfo) |
|
820 { |
|
821 if(!aKeyInfo) |
|
822 return 0; |
|
823 |
|
824 CVirtualRawKeyCtrl* keyCtrl = |
|
825 new(ELeave) CVirtualRawKeyCtrl(aKeyboard,aKeyInfo); |
|
826 CleanupStack::PushL(keyCtrl); |
|
827 keyCtrl->ConstructL(); |
|
828 CleanupStack::Pop(); |
|
829 return keyCtrl; |
|
830 } |
|
831 |
|
832 // --------------------------------------------------------------------------- |
|
833 // CVirtualRawKeyCtrl::CVirtualRawKeyCtrl |
|
834 // Constructor |
|
835 // (other items were commented in a header). |
|
836 // --------------------------------------------------------------------------- |
|
837 // |
|
838 CVirtualRawKeyCtrl::CVirtualRawKeyCtrl(CVirtualKeyboard* aKeyboard, |
|
839 CVirtualKey* aKeyInfo) |
|
840 :CVirtualKeyCtrl(aKeyboard,aKeyInfo) |
|
841 { |
|
842 SetControlType(ECtrlVirtualItutKey); |
|
843 } |
|
844 |
|
845 // --------------------------------------------------------------------------- |
|
846 // CVirtualRawKeyCtrl::GetKeyEventType |
|
847 // Convert key event type |
|
848 // (other items were commented in a header). |
|
849 // --------------------------------------------------------------------------- |
|
850 // |
|
851 TControlEvent CVirtualRawKeyCtrl::GetKeyEventType(TVirtualKeyEventType aEvent) |
|
852 { |
|
853 TControlEvent event = EEventVirtualKeyUp; |
|
854 switch(aEvent) |
|
855 { |
|
856 case EVirtualKeyControlUp: |
|
857 event = EEventRawKeyUpEvent; |
|
858 break; |
|
859 case EVirtualKeyControlDown: |
|
860 event = EEventRawKeyDownEvent; |
|
861 break; |
|
862 default: |
|
863 __ASSERT_DEBUG(EFalse, User::Panic(_L("peninputserver"), EUiLayoutBadEvent)); |
|
864 } |
|
865 return event; |
|
866 } |
|
867 |
|
868 // --------------------------------------------------------------------------- |
|
869 // CVirtualRawKeyCtrl::CancelPointerDownL |
|
870 // Handle cancel pointer down event |
|
871 // (other items were commented in a header). |
|
872 // --------------------------------------------------------------------------- |
|
873 // |
|
874 void CVirtualRawKeyCtrl::CancelPointerDownL() |
|
875 { |
|
876 CFepUiBaseCtrl::CancelPointerDownL(); |
|
877 |
|
878 //simulates key up event |
|
879 ReportKeyEvent(EEventRawKeyUpEvent); |
|
880 } |
|
881 |
|
882 // --------------------------------------------------------------------------- |
|
883 // CVirtualRawKeyCtrl::HandlePointerLeave |
|
884 // Handle pointer left event |
|
885 // (other items were commented in a header). |
|
886 // --------------------------------------------------------------------------- |
|
887 // |
|
888 void CVirtualRawKeyCtrl::HandlePointerLeave(const TPoint& aPoint) |
|
889 { |
|
890 TRawEvent event; |
|
891 event.Set(TRawEvent::EButton1Up,aPoint.iX,aPoint.iY); |
|
892 |
|
893 SimulateRawEvent(event); |
|
894 |
|
895 // Advanced tactile feedback REQ 417-47932 |
|
896 #ifdef RD_TACTILE_FEEDBACK |
|
897 if (UiLayout()->SupportTactileFeedback()) |
|
898 { |
|
899 if (!VirtualKey()->Dimmed() && !Hiden()) |
|
900 { |
|
901 UiLayout()->DoTactileFeedback(ETouchFeedbackSensitiveInput, ETrue, EFalse); |
|
902 } |
|
903 } |
|
904 #endif //RD_TACTILE_FEEDBACK |
|
905 } |
|
906 //end of file |