|
1 /* |
|
2 * Copyright (c) 2003-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: Dialog for selecting smile icon. |
|
15 |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 |
|
24 #include "CCASmileIconDialog.h" |
|
25 |
|
26 #include "CCASmileIconGrid.h" |
|
27 |
|
28 #include "IMSmileUtilityNG.hrh" |
|
29 |
|
30 #include "layoutdebugprint.h" |
|
31 |
|
32 #include "catouchutils.h" |
|
33 |
|
34 |
|
35 |
|
36 #include <akndef.h> |
|
37 |
|
38 #include <aknappui.h> |
|
39 |
|
40 #include <aknutils.h> |
|
41 |
|
42 #include <aknconsts.h> |
|
43 |
|
44 #include <aknborders.h> |
|
45 |
|
46 #include <AknsDrawUtils.h> |
|
47 |
|
48 #include <AknLayoutScalable_Avkon.cdl.h> |
|
49 |
|
50 #include <eikbtgpc.h> |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 // CONSTANTS |
|
57 |
|
58 const TInt KAknSctCBaButtonDirections = 3; // bottom, right and left |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 // ================= MEMBER FUNCTIONS ======================= |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 // Two-phased constructor. |
|
71 |
|
72 CCASmileIconDialog* CCASmileIconDialog::NewL( |
|
73 |
|
74 const RPointerArray<CGulIcon>& aIconArray, |
|
75 |
|
76 TInt& aSelectedIconId ) |
|
77 |
|
78 { |
|
79 |
|
80 CCASmileIconDialog* self = |
|
81 |
|
82 new ( ELeave ) CCASmileIconDialog( aIconArray, aSelectedIconId ); |
|
83 |
|
84 return self; |
|
85 |
|
86 } |
|
87 |
|
88 |
|
89 |
|
90 // Destructor |
|
91 |
|
92 CCASmileIconDialog::~CCASmileIconDialog() |
|
93 |
|
94 { |
|
95 |
|
96 } |
|
97 |
|
98 |
|
99 |
|
100 // C++ constructor can NOT contain any code, that |
|
101 |
|
102 // might leave. |
|
103 |
|
104 // |
|
105 |
|
106 CCASmileIconDialog::CCASmileIconDialog( |
|
107 |
|
108 const RPointerArray<CGulIcon>& aIconArray, |
|
109 |
|
110 TInt& aSelectedIconId ) |
|
111 |
|
112 : iIconArray( aIconArray ), iIconId( aSelectedIconId ), iIsMirrored( EFalse ) |
|
113 |
|
114 { |
|
115 |
|
116 } |
|
117 |
|
118 |
|
119 |
|
120 // --------------------------------------------------------- |
|
121 |
|
122 // CCASmileIconDialog::OfferKeyEventL |
|
123 |
|
124 // Handle key event. |
|
125 |
|
126 // If key code is other than OK and arrow key, no action. |
|
127 |
|
128 // (other items were commented in a header). |
|
129 |
|
130 // --------------------------------------------------------- |
|
131 |
|
132 // |
|
133 |
|
134 TKeyResponse CCASmileIconDialog::OfferKeyEventL( |
|
135 |
|
136 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
137 |
|
138 { |
|
139 |
|
140 TKeyResponse response( EKeyWasConsumed ); |
|
141 |
|
142 |
|
143 |
|
144 switch ( aKeyEvent.iCode ) |
|
145 |
|
146 { |
|
147 |
|
148 // fall through |
|
149 |
|
150 case EKeyLeftArrow: |
|
151 |
|
152 case EKeyRightArrow: |
|
153 |
|
154 case EKeyUpArrow: |
|
155 |
|
156 case EKeyDownArrow: |
|
157 |
|
158 { |
|
159 |
|
160 CCASmileIconGrid* grid = |
|
161 |
|
162 static_cast< CCASmileIconGrid*>( |
|
163 |
|
164 Control( EIMIdSelectSmileGrid ) ); |
|
165 |
|
166 grid->MoveCursor( aKeyEvent.iCode ); |
|
167 |
|
168 break; |
|
169 |
|
170 } |
|
171 |
|
172 // case EKeyEscape: // handle dialog shutdown. let it go in its default way |
|
173 case EKeyEnter: |
|
174 { |
|
175 |
|
176 TryExitL( EAknSoftkeySelect ); |
|
177 |
|
178 return EKeyWasConsumed; |
|
179 |
|
180 } |
|
181 |
|
182 default: |
|
183 |
|
184 { |
|
185 |
|
186 response = CAknDialog::OfferKeyEventL( aKeyEvent, aType ); |
|
187 |
|
188 break; |
|
189 |
|
190 } |
|
191 |
|
192 } |
|
193 |
|
194 return response; |
|
195 |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------- |
|
199 |
|
200 // CCASmileIconDialog::OkToExitL |
|
201 |
|
202 // Called when CBA-key or OK-key is pressed. |
|
203 |
|
204 // (other items were commented in a header). |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 |
|
208 // |
|
209 |
|
210 void CCASmileIconDialog::HandleResourceChange( TInt aType ) |
|
211 |
|
212 { |
|
213 |
|
214 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
215 |
|
216 { |
|
217 |
|
218 SetLayout(); |
|
219 |
|
220 } |
|
221 |
|
222 CAknDialog::HandleResourceChange( aType ); |
|
223 |
|
224 } |
|
225 |
|
226 |
|
227 |
|
228 // --------------------------------------------------------- |
|
229 |
|
230 // CCASmileIconDialog::OkToExitL |
|
231 |
|
232 // Called when CBA-key or OK-key is pressed. |
|
233 |
|
234 // (other items were commented in a header). |
|
235 |
|
236 // --------------------------------------------------------- |
|
237 |
|
238 // |
|
239 |
|
240 TBool CCASmileIconDialog::OkToExitL( TInt aButtonId ) |
|
241 |
|
242 { |
|
243 |
|
244 if ( aButtonId == EAknSoftkeySelect || |
|
245 |
|
246 aButtonId == EEikBidOk ) |
|
247 |
|
248 { |
|
249 |
|
250 CCASmileIconGrid* grid = |
|
251 |
|
252 static_cast< CCASmileIconGrid*>( |
|
253 |
|
254 Control( EIMIdSelectSmileGrid ) ); |
|
255 |
|
256 iIconId = grid->SelectedBitmapId(); |
|
257 return ETrue; |
|
258 } |
|
259 |
|
260 return EFalse; |
|
261 |
|
262 } |
|
263 |
|
264 |
|
265 |
|
266 // --------------------------------------------------------- |
|
267 |
|
268 // CCASmileIconDialog::PreLayoutDynInitL |
|
269 |
|
270 // Prepare for drawing dialog. |
|
271 |
|
272 // (other items were commented in a header). |
|
273 |
|
274 // --------------------------------------------------------- |
|
275 |
|
276 // |
|
277 |
|
278 void CCASmileIconDialog::PreLayoutDynInitL() |
|
279 |
|
280 { |
|
281 |
|
282 SetLineNonFocusing( EIMIdSelectSmileLabel ); |
|
283 |
|
284 EnableDragEvents(); |
|
285 |
|
286 } |
|
287 |
|
288 |
|
289 |
|
290 // --------------------------------------------------------- |
|
291 |
|
292 // CCASmileIconDialog::SetSizeAndPosition |
|
293 |
|
294 // Control size is set. This is called just after PreLayoutDynInitL(). |
|
295 |
|
296 // (other items were commented in a header). |
|
297 |
|
298 // --------------------------------------------------------- |
|
299 |
|
300 // |
|
301 |
|
302 void CCASmileIconDialog::SetSizeAndPosition( const TSize& /*aSize*/ ) |
|
303 |
|
304 { |
|
305 |
|
306 SetLayout(); |
|
307 |
|
308 } |
|
309 |
|
310 |
|
311 |
|
312 // --------------------------------------------------------- |
|
313 |
|
314 // CCASmileIconDialog::CalculatePopupVariety |
|
315 |
|
316 // (other items were commented in a header). |
|
317 |
|
318 // --------------------------------------------------------- |
|
319 |
|
320 // |
|
321 |
|
322 TInt CCASmileIconDialog::CalculatePopupVariety() |
|
323 |
|
324 { |
|
325 |
|
326 CCASmileIconGrid* grid = |
|
327 |
|
328 static_cast< CCASmileIconGrid*>( |
|
329 |
|
330 Control( EIMIdSelectSmileGrid ) ); |
|
331 |
|
332 |
|
333 |
|
334 TAknLayoutScalableParameterLimits smileyDialogVariety = |
|
335 |
|
336 AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits(); |
|
337 |
|
338 TInt maxVariety = smileyDialogVariety.LastVariety(); |
|
339 |
|
340 |
|
341 |
|
342 // CBA location affects popup layout |
|
343 |
|
344 AknLayoutUtils::TAknCbaLocation cbaLocation = AknLayoutUtils::CbaLocation(); |
|
345 |
|
346 |
|
347 |
|
348 // bottom variety |
|
349 |
|
350 TInt maxVarietyOffset = 0; |
|
351 |
|
352 TInt varietyOffset = maxVariety + 1; |
|
353 |
|
354 |
|
355 |
|
356 // right variety |
|
357 |
|
358 if ( cbaLocation == AknLayoutUtils::EAknCbaLocationRight ) |
|
359 |
|
360 { |
|
361 |
|
362 varietyOffset = ( maxVariety + 1 ) / KAknSctCBaButtonDirections; |
|
363 |
|
364 maxVarietyOffset = varietyOffset; |
|
365 |
|
366 } |
|
367 |
|
368 |
|
369 |
|
370 // left variety |
|
371 |
|
372 else if ( cbaLocation == AknLayoutUtils::EAknCbaLocationLeft ) |
|
373 |
|
374 { |
|
375 |
|
376 varietyOffset = ( maxVariety + 1 ) / KAknSctCBaButtonDirections; |
|
377 |
|
378 maxVarietyOffset = varietyOffset + varietyOffset; |
|
379 |
|
380 } |
|
381 |
|
382 if ( ( maxVarietyOffset + varietyOffset ) > maxVariety ) |
|
383 return maxVariety; |
|
384 else |
|
385 return maxVarietyOffset + varietyOffset; |
|
386 } |
|
387 |
|
388 |
|
389 |
|
390 // --------------------------------------------------------- |
|
391 |
|
392 // CCASmileIconDialog::SetLayout |
|
393 |
|
394 // Set dialog layout. |
|
395 |
|
396 // (other items were commented in a header). |
|
397 |
|
398 // --------------------------------------------------------- |
|
399 |
|
400 // |
|
401 |
|
402 void CCASmileIconDialog::SetLayout() |
|
403 |
|
404 { |
|
405 |
|
406 iIsMirrored = AknLayoutUtils::LayoutMirrored() ; |
|
407 TRect clientRect = iAvkonAppUi->ApplicationRect(); |
|
408 |
|
409 //check LAF docs for constants |
|
410 |
|
411 TAknLayoutRect mainPane; |
|
412 |
|
413 mainPane.LayoutRect( clientRect, AknLayoutScalable_Avkon::main_pane( 6 ) ); |
|
414 |
|
415 LAYOUT_DP_RECT( "CCASmileIconDialog main_pane( 6 )", |
|
416 |
|
417 mainPane.Rect() ); |
|
418 |
|
419 CCASmileIconGrid* grid = |
|
420 |
|
421 static_cast< CCASmileIconGrid*>( |
|
422 |
|
423 Control( EIMIdSelectSmileGrid ) ); |
|
424 |
|
425 // Select correct popup layout |
|
426 |
|
427 TInt varietyNumber = CalculatePopupVariety(); |
|
428 TRect rect = grid->GetFirstCellRect(); |
|
429 TInt iconCount = iIconArray.Count(); |
|
430 TInt areaOfIcon = iconCount * rect.Width() * rect.Height(); |
|
431 TInt variety = varietyNumber; |
|
432 TInt viewableWidth = 0; |
|
433 |
|
434 for ( TInt i = varietyNumber; i > 0; i-- ) |
|
435 { |
|
436 |
|
437 TAknWindowLineLayout popupGridDialogLayout( |
|
438 AknLayoutScalable_Avkon::popup_grid_graphic_window( i ) ); |
|
439 |
|
440 |
|
441 TAknLayoutRect dialogRect; |
|
442 |
|
443 dialogRect.LayoutRect( |
|
444 mainPane.Rect(), popupGridDialogLayout ); |
|
445 |
|
446 viewableWidth = CheckDialog( dialogRect, rect ); |
|
447 if ( viewableWidth ) |
|
448 { |
|
449 varietyNumber = i; |
|
450 break; |
|
451 } |
|
452 } |
|
453 |
|
454 if ( viewableWidth ) |
|
455 { |
|
456 TAknWindowLineLayout popupGridDialogLayout( |
|
457 AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) ); |
|
458 |
|
459 TAknLayoutRect dialogRect; |
|
460 |
|
461 dialogRect.LayoutRect( |
|
462 mainPane.Rect(), popupGridDialogLayout ); |
|
463 |
|
464 LAYOUT_DP_RECT( "CCASmileIconDialog popup_grid_graphic_window", |
|
465 dialogRect.Rect() ); |
|
466 |
|
467 grid->SetViewableWindowWidth( viewableWidth ); |
|
468 |
|
469 SetRect( dialogRect.Rect() ); |
|
470 } |
|
471 // If there is no suitable solution for the smiley dialog layout |
|
472 else |
|
473 { |
|
474 // Use the max variety number |
|
475 varietyNumber = CalculatePopupVariety(); |
|
476 |
|
477 TAknWindowLineLayout popupGridDialogLayout( |
|
478 AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) ); |
|
479 |
|
480 TAknLayoutRect dialogRect; |
|
481 |
|
482 dialogRect.LayoutRect( |
|
483 mainPane.Rect(), popupGridDialogLayout ); |
|
484 |
|
485 LAYOUT_DP_RECT( "CCASmileIconDialog popup_grid_graphic_window", |
|
486 dialogRect.Rect() ); |
|
487 |
|
488 if ( !iIsMirrored ) |
|
489 { |
|
490 // Right Margin of the top left (top right) icon's X |
|
491 TInt leftMargin = rect.iTl.iX; |
|
492 |
|
493 // Use the max viewable width |
|
494 viewableWidth = dialogRect.Rect().iBr.iX - dialogRect.Rect().iTl.iX - leftMargin; |
|
495 } |
|
496 else |
|
497 { |
|
498 // Left Margin of the top left (top right) icon's X |
|
499 TInt rightMargin = rect.iBr.iX; |
|
500 |
|
501 // Use the max viewable width |
|
502 viewableWidth = dialogRect.Rect().iBr.iX - dialogRect.Rect().iTl.iX + rightMargin; |
|
503 } |
|
504 |
|
505 grid->SetViewableWindowWidth( viewableWidth ); |
|
506 |
|
507 if ( !iIsMirrored ) |
|
508 SetRect( dialogRect.Rect() ); |
|
509 // When the Hebrew is the language as well as the Arb languages |
|
510 // The align is not right |
|
511 else |
|
512 { |
|
513 TRect mirroredDialogRect; |
|
514 |
|
515 // Align to right. |
|
516 mirroredDialogRect = dialogRect.Rect(); |
|
517 |
|
518 // Get the rect of the cba pane. |
|
519 TRect controlPaneRect; |
|
520 AknLayoutUtils::LayoutMetricsRect( |
|
521 AknLayoutUtils::EControlPane, controlPaneRect ); |
|
522 |
|
523 TInt cbaWidth = controlPaneRect.iBr.iX - controlPaneRect.iTl.iX; |
|
524 |
|
525 mirroredDialogRect.iTl.iX -= cbaWidth; |
|
526 mirroredDialogRect.iBr.iX -= cbaWidth; |
|
527 |
|
528 SetRect( mirroredDialogRect ); |
|
529 } |
|
530 } |
|
531 } |
|
532 |
|
533 // --------------------------------------------------------- |
|
534 |
|
535 // CCASmileIconDialog::CheckDialog |
|
536 |
|
537 // Check if Dialog is suitable to fit all smile icon |
|
538 |
|
539 // (other items were commented in a header). |
|
540 |
|
541 // --------------------------------------------------------- |
|
542 |
|
543 TInt CCASmileIconDialog::CheckDialog( TAknLayoutRect aDialogRect, TRect aRect ) |
|
544 { |
|
545 CCASmileIconGrid* grid = static_cast< CCASmileIconGrid* >( Control( EIMIdSelectSmileGrid ) ); |
|
546 |
|
547 TInt topMargin = aRect.iTl.iY; |
|
548 |
|
549 TInt viewableWidth = 0; |
|
550 |
|
551 if ( !iIsMirrored ) |
|
552 { |
|
553 TInt leftMargin = aRect.iTl.iX; |
|
554 |
|
555 viewableWidth = aDialogRect.Rect().iBr.iX - aDialogRect.Rect().iTl.iX - 2 * leftMargin; |
|
556 } |
|
557 else |
|
558 { |
|
559 TInt rightMargin = aRect.iBr.iX; |
|
560 |
|
561 viewableWidth = aDialogRect.Rect().iBr.iX - aDialogRect.Rect().iTl.iX + 2 * rightMargin; |
|
562 } |
|
563 TInt viewableHight = aDialogRect.Rect().iBr.iY - aDialogRect.Rect().iTl.iY - topMargin; |
|
564 |
|
565 TInt viewableArea = viewableWidth * viewableHight; |
|
566 |
|
567 TInt iconCount = iIconArray.Count(); |
|
568 TInt areaOfIcon = iconCount * aRect.Width() * aRect.Height(); |
|
569 |
|
570 if ( areaOfIcon > viewableArea ) |
|
571 { |
|
572 return 0; |
|
573 } |
|
574 else |
|
575 { |
|
576 return viewableWidth; |
|
577 } |
|
578 } |
|
579 |
|
580 // --------------------------------------------------------- |
|
581 |
|
582 // CCASmileIconDialog::CreateCustomControlL |
|
583 |
|
584 // Create CCASmileIconGrid class in order to display |
|
585 |
|
586 // icons in grid. |
|
587 |
|
588 // This is called when dialog is created. |
|
589 |
|
590 // (other items were commented in a header). |
|
591 |
|
592 // --------------------------------------------------------- |
|
593 |
|
594 // |
|
595 |
|
596 SEikControlInfo CCASmileIconDialog::CreateCustomControlL( |
|
597 |
|
598 TInt aControlType ) |
|
599 |
|
600 { |
|
601 |
|
602 SEikControlInfo controlInfo; |
|
603 |
|
604 controlInfo.iControl = NULL; |
|
605 |
|
606 controlInfo.iTrailerTextId = 0; |
|
607 |
|
608 controlInfo.iFlags = 0; |
|
609 |
|
610 |
|
611 |
|
612 if ( aControlType == EIMCtrlSelectSmileGrid ) |
|
613 |
|
614 { |
|
615 |
|
616 controlInfo.iControl = CCASmileIconGrid::NewL( this, iIconArray ); |
|
617 |
|
618 static_cast<CCASmileIconGrid*> |
|
619 |
|
620 ( controlInfo.iControl )->SetTapObserver( this, 0 ); |
|
621 |
|
622 } |
|
623 |
|
624 return controlInfo; |
|
625 |
|
626 } |
|
627 |
|
628 |
|
629 |
|
630 // --------------------------------------------------------- |
|
631 |
|
632 // CCASmileIconDialog::HandleDialogPageEventL |
|
633 |
|
634 // (other items were commented in a header). |
|
635 |
|
636 // --------------------------------------------------------- |
|
637 |
|
638 // |
|
639 |
|
640 void CCASmileIconDialog::HandleDialogPageEventL( TInt aEventID ) |
|
641 |
|
642 { |
|
643 if ( CATouchUtils::PenEnabled() ) |
|
644 { |
|
645 if ( iSmileyPointed && |
|
646 aEventID == MEikDialogPageObserver::EDialogPageTapped ) |
|
647 { |
|
648 // Exit requested, exit with ok. |
|
649 TryExitL( EAknSoftkeyOk ); |
|
650 } |
|
651 //else keep dialog as it is do not exit. |
|
652 } |
|
653 } |
|
654 |
|
655 // --------------------------------------------------------- |
|
656 |
|
657 // CCASmileIconDialog::HandleTapEventL |
|
658 |
|
659 // (other items were commented in a header). |
|
660 |
|
661 // --------------------------------------------------------- |
|
662 |
|
663 // |
|
664 |
|
665 void CCASmileIconDialog::HandleTapEventL( TTapEvent aEvent, |
|
666 |
|
667 TUint /*aControlId*/ ) |
|
668 |
|
669 { |
|
670 |
|
671 // User tapped on smiley. |
|
672 |
|
673 if ( aEvent == MCATapEventObserver::ESingleTap ) |
|
674 |
|
675 { |
|
676 |
|
677 // Smiley was selected but we can't exit directly from here. |
|
678 |
|
679 // Instead we put the flag on and wait for |
|
680 |
|
681 // HandleDialogPageEventL. |
|
682 |
|
683 iSmileyPointed = ETrue; |
|
684 |
|
685 } |
|
686 |
|
687 } |
|
688 |
|
689 |
|
690 |
|
691 // End of File |