|
1 /* |
|
2 * Copyright (c) 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: Info popup note UI control. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include <AknsDrawUtils.h> |
|
23 #include <AknsFrameBackgroundControlContext.h> |
|
24 #include <eiklabel.h> |
|
25 #include <gulicon.h> |
|
26 #include <aknappui.h> |
|
27 #include <AknUtils.h> |
|
28 #include <layoutmetadata.cdl.h> |
|
29 #include <aknlayoutscalable_avkon.cdl.h> |
|
30 #include <AknStatuspaneUtils.h> |
|
31 #include <touchfeedback.h> |
|
32 #include "akntextcontrol.h" |
|
33 #include "AknInfoPopupNote.h" |
|
34 #include "AknInfoPopupNoteController.h" |
|
35 |
|
36 #include <AknTasHook.h> // for testability hooks |
|
37 |
|
38 // CONSTANTS |
|
39 const TInt KMaxNumOfLines = 5; // max number of lines in popup |
|
40 |
|
41 // ============================ MEMBER FUNCTIONS =============================== |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // ConstructL |
|
45 // |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CAknInfoPopupNote::ConstructL() |
|
49 { |
|
50 /* Popup should disappear quickly. By making popup as window-owning |
|
51 * control, that backups graphics behind it (backed-up-behind window) |
|
52 * we enable fast hiding. However, it eats more memory, and in OOM |
|
53 * situation backup is not done, but status pane is actually redrawn. |
|
54 * See Symbian documentation of RWindowBase::EnableBackup for more |
|
55 * information. |
|
56 */ |
|
57 |
|
58 delete iBgContext; |
|
59 iBgContext = NULL; |
|
60 |
|
61 iBgContext = CAknsFrameBackgroundControlContext::NewL( |
|
62 KAknsIIDQsnFrPopupPreview, TRect(), TRect(), EFalse ); |
|
63 |
|
64 CreateWindowL(); |
|
65 |
|
66 EnableDragEvents(); |
|
67 SetAllowStrayPointers(); |
|
68 |
|
69 if( CAknEnv::Static()->TransparencyEnabled() ) |
|
70 { |
|
71 // try to enable window transparency |
|
72 if ( Window().SetTransparencyAlphaChannel() == KErrNone ) |
|
73 { |
|
74 Window().SetRequiredDisplayMode( EColor16MA ); |
|
75 Window().SetBackgroundColor( ~0 ); |
|
76 } |
|
77 } |
|
78 |
|
79 DrawableWindow()->EnableBackup( EWindowBackupAreaBehind ); |
|
80 |
|
81 DrawableWindow()->SetNonFading( ETrue); |
|
82 if ( !iText ) |
|
83 { |
|
84 iText = CAknTextControl::NewL(); |
|
85 iText->SetContainerWindowL( *this ); |
|
86 iText->CopyControlContextFrom( this ); |
|
87 iText->SetComponentsToInheritVisibility( ETrue ); |
|
88 } |
|
89 |
|
90 iAvkonAppUi->AddToStackL( this, ECoeStackPriorityCba, |
|
91 ECoeStackFlagRefusesAllKeys | |
|
92 ECoeStackFlagRefusesFocus ); |
|
93 |
|
94 DrawableWindow()->SetPointerGrab( ETrue ); |
|
95 |
|
96 SetComponentsToInheritVisibility( ETrue ); |
|
97 Hide(); |
|
98 |
|
99 ControlEnv()->AddForegroundObserverL( *this ); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // NewL |
|
104 // |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 CAknInfoPopupNote* CAknInfoPopupNote::NewL( |
|
108 CAknInfoPopupNoteController& aController ) |
|
109 { |
|
110 CAknInfoPopupNote* self = |
|
111 new( ELeave ) CAknInfoPopupNote( aController ); |
|
112 |
|
113 CleanupStack::PushL( self ); |
|
114 self->ConstructL(); |
|
115 CleanupStack::Pop(); |
|
116 AKNTASHOOK_ADDL( self, "CAknInfoPopupNote" ); |
|
117 return self; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CAknInfoPopupNote |
|
122 // |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 CAknInfoPopupNote::CAknInfoPopupNote( CAknInfoPopupNoteController& aController ) |
|
126 : iController( aController ), |
|
127 iTooltipMode( EFalse ), |
|
128 iHideWhenAppFaded( ETrue ), |
|
129 iFloatingPositionUsed( EFalse ), |
|
130 iFloatingPosition( 0, 0 ), |
|
131 iAlignment( EHLeftVTop ) |
|
132 |
|
133 { |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // ~CAknInfoPopupNote |
|
138 // |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 CAknInfoPopupNote::~CAknInfoPopupNote() |
|
142 { |
|
143 AKNTASHOOK_REMOVE(); |
|
144 ControlEnv()->RemoveForegroundObserver( *this ); |
|
145 |
|
146 if ( iAvkonAppUi ) |
|
147 { |
|
148 iAvkonAppUi->RemoveFromStack( this ); |
|
149 } |
|
150 |
|
151 delete iBgContext; |
|
152 delete iText; |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CountComponentControls |
|
157 // |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 TInt CAknInfoPopupNote::CountComponentControls() const |
|
161 { |
|
162 return 1; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // ComponentControl |
|
167 // |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 CCoeControl* CAknInfoPopupNote::ComponentControl( TInt /*aIndex*/ ) const |
|
171 { |
|
172 return iText; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // Hide |
|
177 // |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CAknInfoPopupNote::Hide() |
|
181 { |
|
182 if ( IsVisible() ) |
|
183 { |
|
184 MakeVisible( EFalse ); |
|
185 |
|
186 // Change stacked control to refuse all key events while not visible. |
|
187 iAvkonAppUi->UpdateStackedControlFlags( this, |
|
188 ECoeStackFlagRefusesAllKeys, |
|
189 ECoeStackFlagRefusesAllKeys ); |
|
190 } |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // SetTextL |
|
195 // |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 void CAknInfoPopupNote::SetTextL( const TDesC& aText ) |
|
199 { |
|
200 if ( aText != iText->Text() ) |
|
201 { |
|
202 iText->SetTextL( aText ); |
|
203 |
|
204 for ( TInt i = 0; i < iText->NumberOfLines(); i++ ) |
|
205 { |
|
206 // Draw the label after the background. |
|
207 CEikLabel* line = iText->Line( i ); |
|
208 line->ActivateL(); // Never leaves |
|
209 |
|
210 if ( !IsVisible() ) |
|
211 { |
|
212 line->MakeVisible( EFalse ); |
|
213 } |
|
214 |
|
215 iText->SetLineModified( i, EFalse ); |
|
216 } |
|
217 |
|
218 SetWindowLayoutL(); |
|
219 |
|
220 if ( IsVisible() ) |
|
221 { |
|
222 Window().Invalidate( Rect() ); |
|
223 } |
|
224 } |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // GetText |
|
229 // |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 const TPtrC CAknInfoPopupNote::GetText() const |
|
233 { |
|
234 if ( iText->Text().Length() == 0 ) |
|
235 { |
|
236 return KNullDesC().Ptr(); |
|
237 } |
|
238 return iText->Text(); |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // SetPositionAndAlignment |
|
243 // |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CAknInfoPopupNote::SetPositionAndAlignment( const TPoint& aPosition, |
|
247 const TGulAlignmentValue& aAlignment ) |
|
248 { |
|
249 iFloatingPositionUsed = ETrue; |
|
250 iFloatingPosition = aPosition; |
|
251 iAlignment = aAlignment; |
|
252 Relocate(); |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // SetPositionAndAlignment |
|
257 // |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CAknInfoPopupNote::SetPositionByHighlight( const TRect& aHighlightRect ) |
|
261 { |
|
262 SetRect( AknLayoutUtils::HighlightBasedRect( aHighlightRect, this ) ); |
|
263 iFloatingPositionUsed = ETrue; |
|
264 iFloatingPosition = Position(); |
|
265 iAlignment = EHLeftVTop; |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // RestoreDefaultPosition |
|
270 // |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CAknInfoPopupNote::RestoreDefaultPosition() |
|
274 { |
|
275 // Get parameter limits for popup preview text window |
|
276 TAknLayoutScalableParameterLimits limits = |
|
277 AknLayoutScalable_Avkon::popup_preview_text_window_ParamLimits(); |
|
278 |
|
279 // Select the variety index depending on the number of lines |
|
280 TInt variety = SelectWindowVariety( iText->NumberOfLines(), limits ); |
|
281 |
|
282 // Get layout rects |
|
283 TRect rectScreen = iAvkonAppUi->ApplicationRect(); |
|
284 TRect rectMainPane = rectScreen; |
|
285 TRect rectPopupWindow = RectFromLayout( rectMainPane, |
|
286 AknLayoutScalable_Avkon::popup_preview_text_window( variety ) ); |
|
287 |
|
288 // Set the default position |
|
289 SetPosition( rectPopupWindow.iTl ); |
|
290 iFloatingPositionUsed = EFalse; |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // SetTooltipModeL |
|
295 // |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CAknInfoPopupNote::SetTooltipModeL( const TBool aTooltipMode ) |
|
299 { |
|
300 if ( iTooltipMode != aTooltipMode ) |
|
301 { |
|
302 iTooltipMode = aTooltipMode; |
|
303 SetWindowLayoutL(); |
|
304 } |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // AppFaded |
|
309 // |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 |
|
313 void CAknInfoPopupNote::HideWhenAppFaded( const TBool aHide ) |
|
314 { |
|
315 iHideWhenAppFaded = aHide; |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // ShowL |
|
320 // |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 void CAknInfoPopupNote::ShowL() |
|
324 { |
|
325 // Info pop-up note is not shown, when it does not contain any text, or |
|
326 // when the screen background is faded by some other UI component. |
|
327 if ( !iText->Text().Length() || ( !iAvkonAppUi->IsForeground() |
|
328 && iAvkonAppUi->IsFaded() && iHideWhenAppFaded )) |
|
329 { |
|
330 return; |
|
331 } |
|
332 |
|
333 // Because info pop-up note has to be drawn over pop-up toolbar, which has |
|
334 // normal window priority, the window priority of info pop-up note has to |
|
335 // be also set again to be shown over toolbar. |
|
336 Window().SetOrdinalPosition( 0, ECoeWinPriorityNormal ); |
|
337 |
|
338 if( !IsActivated() ) |
|
339 { |
|
340 ActivateL(); |
|
341 } |
|
342 |
|
343 MakeVisible( ETrue ); |
|
344 |
|
345 // Change stacked control not to refuse key events |
|
346 iAvkonAppUi->UpdateStackedControlFlags( this, NULL, |
|
347 ECoeStackFlagRefusesAllKeys ); |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // Draw |
|
352 // |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 void CAknInfoPopupNote::Draw( const TRect& aRect ) const |
|
356 { |
|
357 CWindowGc& gc = SystemGc(); |
|
358 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
359 |
|
360 if ( !AknsDrawUtils::Background( skin, iBgContext, gc, aRect ) ) |
|
361 { |
|
362 gc.Clear( aRect ); |
|
363 gc.DrawRect( aRect ); |
|
364 } |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // SizeChanged |
|
369 // |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 void CAknInfoPopupNote::SizeChanged() |
|
373 { |
|
374 const TRect popupRect( Rect() ); |
|
375 |
|
376 TRect windowPaneBgRect = RectFromLayout( popupRect, |
|
377 AknLayoutScalable_Avkon::bg_popup_preview_window_pane( 0 ) ); |
|
378 |
|
379 // Note: bg_popup_preview_window_pane might not be the right outer rect, |
|
380 // but it is used for now, because bg_popup_preview_window_pane_g# |
|
381 // functions do not return the correct values. |
|
382 iOuterRect = windowPaneBgRect; |
|
383 iInnerRect = RectFromLayout( windowPaneBgRect, |
|
384 AknLayoutScalable_Avkon::bg_popup_preview_window_pane_g1() ); |
|
385 |
|
386 iBgContext->SetFrameRects( iOuterRect, iInnerRect ); |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // OfferKeyEventL |
|
391 // |
|
392 // ----------------------------------------------------------------------------- |
|
393 // |
|
394 TKeyResponse CAknInfoPopupNote::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
395 TEventCode aType ) |
|
396 { |
|
397 if ( aType == EEventKeyDown || aKeyEvent.iCode == EKeyEscape ) |
|
398 { |
|
399 Hide(); |
|
400 } |
|
401 |
|
402 return EKeyWasNotConsumed; |
|
403 } |
|
404 |
|
405 // ----------------------------------------------------------------------------- |
|
406 // CAknInfoPopupNote::MakeVisible |
|
407 // |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 void CAknInfoPopupNote::MakeVisible( TBool aVisible ) |
|
411 { |
|
412 if ( aVisible != IsVisible() ) |
|
413 { |
|
414 CCoeControl::MakeVisible( aVisible ); |
|
415 |
|
416 if ( aVisible ) |
|
417 { |
|
418 iController.NotifyObservers( |
|
419 MAknInfoPopupNoteObserver::EInfoPopupNoteShown ); |
|
420 } |
|
421 else |
|
422 { |
|
423 iController.NotifyObservers( |
|
424 MAknInfoPopupNoteObserver::EInfoPopupNoteHidden ); |
|
425 } |
|
426 } |
|
427 } |
|
428 |
|
429 // ----------------------------------------------------------------------------- |
|
430 // CAknInfoPopupNote::HandleResourceChange |
|
431 // |
|
432 // ----------------------------------------------------------------------------- |
|
433 // |
|
434 void CAknInfoPopupNote::HandleResourceChange( TInt aType ) |
|
435 { |
|
436 CCoeControl::HandleResourceChange( aType ); |
|
437 |
|
438 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
439 { |
|
440 TRAP_IGNORE( SetWindowLayoutL() ); |
|
441 } |
|
442 else if ( aType == KAknsMessageSkinChange && iText ) |
|
443 { |
|
444 TRgb textColor = KRgbBlack; |
|
445 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, |
|
446 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG55 ); |
|
447 TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL( *iText, EColorLabelText, |
|
448 textColor ) ); |
|
449 } |
|
450 else if( aType == KEikMessageFadeAllWindows ) |
|
451 { |
|
452 if ( IsVisible() && iHideWhenAppFaded ) |
|
453 { |
|
454 iController.HideInfoPopupNote(); |
|
455 } |
|
456 } |
|
457 } |
|
458 |
|
459 // ----------------------------------------------------------------------------- |
|
460 // CAknInfoPopupNote::HandlePointerEventL |
|
461 // |
|
462 // ----------------------------------------------------------------------------- |
|
463 // |
|
464 void CAknInfoPopupNote::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
|
465 { |
|
466 if ( AknLayoutUtils::PenEnabled() ) |
|
467 { |
|
468 SetPointerCapture( ETrue ); |
|
469 |
|
470 if ( aPointerEvent.iType == TPointerEvent::EButton1Down |
|
471 || aPointerEvent.iType == TPointerEvent::EButton1Up |
|
472 || aPointerEvent.iType == TPointerEvent::EDrag ) |
|
473 { |
|
474 if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
475 { |
|
476 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
477 if ( feedback ) |
|
478 { |
|
479 feedback->InstantFeedback( ETouchFeedbackPopUp ); |
|
480 } |
|
481 } |
|
482 |
|
483 Hide(); |
|
484 SetPointerCapture( EFalse ); |
|
485 } |
|
486 } |
|
487 } |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // SetWindowLayoutL |
|
491 // |
|
492 // ----------------------------------------------------------------------------- |
|
493 // |
|
494 void CAknInfoPopupNote::SetWindowLayoutL() |
|
495 { |
|
496 if ( iText && iText->Text().Length() > 0 ) |
|
497 { |
|
498 if ( iTooltipMode ) |
|
499 { |
|
500 SetTooltipWindowLayoutL(); |
|
501 } |
|
502 else |
|
503 { |
|
504 SetInfoPopupWindowLayoutL(); |
|
505 } |
|
506 } |
|
507 } |
|
508 |
|
509 // ----------------------------------------------------------------------------- |
|
510 // SetInfoPopupWindowLayoutL |
|
511 // |
|
512 // ----------------------------------------------------------------------------- |
|
513 // |
|
514 void CAknInfoPopupNote::SetInfoPopupWindowLayoutL() |
|
515 { |
|
516 // Get parameter and table limits for popup preview text window |
|
517 TAknLayoutScalableParameterLimits limits = |
|
518 AknLayoutScalable_Avkon::popup_preview_text_window_ParamLimits(); |
|
519 |
|
520 TAknLayoutScalableTableLimits tableLimits = |
|
521 AknLayoutScalable_Avkon::popup_preview_text_window_t_Limits(); |
|
522 |
|
523 // Get layout rects |
|
524 TRect rectScreen = iAvkonAppUi->ApplicationRect(); |
|
525 TInt mainPaneVariety = Layout_Meta_Data::IsLandscapeOrientation() ? 4 : 1; |
|
526 TRect rectMainPane = RectFromLayout( rectScreen, |
|
527 AknLayoutScalable_Avkon::main_pane( mainPaneVariety ) ); |
|
528 |
|
529 // Use first variety to be able to get the font for text parsing |
|
530 TInt firstVariety = SelectWindowVariety( 1, limits ); |
|
531 |
|
532 TRect rectPopupWindow = RectFromLayout( rectMainPane, |
|
533 AknLayoutScalable_Avkon::popup_preview_text_window( firstVariety ) ); |
|
534 |
|
535 TInt firstIndex = tableLimits.FirstIndex(); |
|
536 TInt firstLineVariety = AknLayoutScalable_Avkon:: |
|
537 popup_preview_text_window_t_ParamLimits( firstIndex ).FirstVariety(); |
|
538 |
|
539 TAknTextLineLayout popupTextLayout = |
|
540 AknLayoutScalable_Avkon::popup_preview_text_window_t( |
|
541 firstIndex, firstLineVariety ); |
|
542 |
|
543 TAknLayoutText layoutText; |
|
544 layoutText.LayoutText( rectPopupWindow, popupTextLayout ); |
|
545 TRect rectText = layoutText.TextRect(); |
|
546 |
|
547 // Prepare text parsing |
|
548 const CFont *font = layoutText.Font(); |
|
549 |
|
550 CArrayFixFlat<TInt>* lineWidths |
|
551 = new ( ELeave ) CArrayFixFlat<TInt>( KMaxNumOfLines ); |
|
552 CleanupStack::PushL( lineWidths ); |
|
553 |
|
554 for ( TInt i = 0; i < KMaxNumOfLines; i++ ) |
|
555 { |
|
556 lineWidths->AppendL( rectText.Width() ); |
|
557 } |
|
558 |
|
559 // Parse text |
|
560 iText->ParseTextL( font, lineWidths ); |
|
561 TInt numberOfLines = iText->NumberOfLines(); |
|
562 |
|
563 CleanupStack::PopAndDestroy( lineWidths ); |
|
564 |
|
565 // Select the variety index depending on the number of lines |
|
566 TInt windowVariety = SelectWindowVariety( numberOfLines, limits ); |
|
567 |
|
568 // Set layouts for window and text lines |
|
569 AknLayoutUtils::LayoutControl( this, rectMainPane, |
|
570 AknLayoutScalable_Avkon::popup_preview_text_window( windowVariety ) ); |
|
571 |
|
572 rectPopupWindow = Rect(); |
|
573 iText->SetRect( rectPopupWindow ); |
|
574 |
|
575 for ( TInt lineIndex = tableLimits.FirstIndex(), ii = 0; |
|
576 ( lineIndex <= tableLimits.LastIndex() ) && ( ii < numberOfLines ); |
|
577 ++lineIndex, ++ii ) |
|
578 { |
|
579 // Select the variety index depending on the number of lines |
|
580 TInt lineVariety = SelectLineVariety( numberOfLines, |
|
581 AknLayoutScalable_Avkon::popup_preview_text_window_t_ParamLimits( |
|
582 lineIndex ) ); |
|
583 |
|
584 popupTextLayout = AknLayoutScalable_Avkon::popup_preview_text_window_t( |
|
585 lineIndex, lineVariety ); |
|
586 |
|
587 AknLayoutUtils::LayoutLabel( iText->Line( ii ), rectPopupWindow, |
|
588 popupTextLayout, font ); |
|
589 } |
|
590 |
|
591 // Override text color |
|
592 TRgb textColor = KRgbBlack; |
|
593 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, |
|
594 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG55 ); |
|
595 AknLayoutUtils::OverrideControlColorL( *iText, EColorLabelText, textColor ); |
|
596 |
|
597 // Move pop-up note to right location |
|
598 if ( IsVisible() ) |
|
599 { |
|
600 Relocate(); |
|
601 } |
|
602 } |
|
603 |
|
604 // ----------------------------------------------------------------------------- |
|
605 // SetTooltipWindowLayoutL |
|
606 // |
|
607 // ----------------------------------------------------------------------------- |
|
608 // |
|
609 void CAknInfoPopupNote::SetTooltipWindowLayoutL() |
|
610 { |
|
611 // Get parameter and table limits for popup preview text window |
|
612 TAknLayoutScalableParameterLimits limits = |
|
613 AknLayoutScalable_Avkon::popup_preview_text_window_ParamLimits(); |
|
614 |
|
615 TAknLayoutScalableTableLimits tableLimits = |
|
616 AknLayoutScalable_Avkon::popup_preview_text_window_t_Limits(); |
|
617 |
|
618 // Get layout rects |
|
619 const TRect rectScreen = iAvkonAppUi->ApplicationRect(); |
|
620 const TRect rectMainPane = rectScreen; |
|
621 |
|
622 // Set pop-up to contain only one line of text |
|
623 const TInt numberOfLines = 1; |
|
624 TInt windowVariety = SelectWindowVariety( numberOfLines, limits ); |
|
625 |
|
626 TInt lineVariety = SelectLineVariety( numberOfLines, |
|
627 AknLayoutScalable_Avkon:: popup_preview_text_window_t_ParamLimits( |
|
628 tableLimits.FirstIndex() ) ); |
|
629 |
|
630 // Get the font for the text |
|
631 TRect rectPopupWindow = RectFromLayout( rectMainPane, |
|
632 AknLayoutScalable_Avkon::popup_preview_text_window( |
|
633 windowVariety ) ); |
|
634 |
|
635 TAknTextComponentLayout popupTextLayout = |
|
636 AknLayoutScalable_Avkon::popup_preview_text_window_t( |
|
637 tableLimits.FirstIndex(), lineVariety ); |
|
638 |
|
639 TAknLayoutText layoutText; |
|
640 layoutText.LayoutText( rectPopupWindow, popupTextLayout ); |
|
641 const CFont *font = layoutText.Font(); |
|
642 |
|
643 TInt maxLineWidth = ( rectMainPane.Width() - popupTextLayout.l() ) |
|
644 - popupTextLayout.r(); |
|
645 |
|
646 TInt textWidth = font->TextWidthInPixels( iText->Text() ); |
|
647 textWidth = Min( textWidth, maxLineWidth ); |
|
648 |
|
649 // Parse text |
|
650 CArrayFixFlat<TInt>* lineWidths |
|
651 = new ( ELeave ) CArrayFixFlat<TInt>( numberOfLines ); |
|
652 CleanupStack::PushL( lineWidths ); |
|
653 |
|
654 lineWidths->AppendL( textWidth ); |
|
655 iText->ParseTextL( font, lineWidths ); |
|
656 |
|
657 CleanupStack::PopAndDestroy( lineWidths ); |
|
658 |
|
659 // Set layout for window |
|
660 rectPopupWindow = RectFromLayout( rectMainPane, |
|
661 AknLayoutScalable_Avkon::popup_preview_text_window( windowVariety ) ); |
|
662 |
|
663 // Adjust window size depending on text length |
|
664 SetSize( TSize( textWidth + popupTextLayout.l() + popupTextLayout.r(), |
|
665 rectPopupWindow.Height() ) ); |
|
666 |
|
667 // Set layout for text lines |
|
668 rectPopupWindow = Rect(); |
|
669 iText->SetRect( rectPopupWindow ); |
|
670 |
|
671 for ( TInt lineIndex = tableLimits.FirstIndex(), ii = 0; |
|
672 ( lineIndex <= tableLimits.LastIndex() ) && ( ii < numberOfLines ); |
|
673 ++lineIndex, ++ii ) |
|
674 { |
|
675 popupTextLayout = AknLayoutScalable_Avkon::popup_preview_text_window_t( |
|
676 lineIndex, lineVariety ); |
|
677 |
|
678 AknLayoutUtils::LayoutLabel( iText->Line( ii ), rectPopupWindow, |
|
679 popupTextLayout, font ); |
|
680 } |
|
681 |
|
682 // Override text color |
|
683 TRgb textColor = KRgbBlack; |
|
684 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, |
|
685 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG55 ); |
|
686 AknLayoutUtils::OverrideControlColorL( *iText, EColorLabelText, textColor ); |
|
687 |
|
688 // Move tooltip to right location |
|
689 if ( IsVisible() ) |
|
690 { |
|
691 Relocate(); |
|
692 } |
|
693 } |
|
694 |
|
695 // ----------------------------------------------------------------------------- |
|
696 // Relocate |
|
697 // |
|
698 // ----------------------------------------------------------------------------- |
|
699 // |
|
700 void CAknInfoPopupNote::Relocate() |
|
701 { |
|
702 if ( !iFloatingPositionUsed ) |
|
703 { |
|
704 return; |
|
705 } |
|
706 |
|
707 TRect rect( Rect() ); |
|
708 TPoint delta( 0, 0 ); |
|
709 |
|
710 switch (iAlignment) |
|
711 { |
|
712 case EHLeftVTop: |
|
713 { |
|
714 // Tooltip is left and top aligned. |
|
715 break; |
|
716 } |
|
717 case EHLeftVCenter: |
|
718 { |
|
719 // Tooltip left aligned and centred vertically. |
|
720 delta.iY = rect.Height() / 2; |
|
721 break; |
|
722 } |
|
723 case EHLeftVBottom: |
|
724 { |
|
725 // Tooltip is left aligned and at the bottom. |
|
726 delta.iY = rect.Height(); |
|
727 break; |
|
728 } |
|
729 case EHCenterVTop: |
|
730 { |
|
731 // Tooltip is centre aligned horizontally and at the top. |
|
732 delta.iX = rect.Width() / 2; |
|
733 break; |
|
734 } |
|
735 case EHCenterVCenter: |
|
736 { |
|
737 // Tooltip is centred horizontally and vertically. |
|
738 delta.SetXY( rect.Width() / 2, rect.Height() / 2 ); |
|
739 break; |
|
740 } |
|
741 case EHCenterVBottom: |
|
742 { |
|
743 // Tooltip is centred horizontally and at the bottom. |
|
744 delta.SetXY( rect.Width() / 2, rect.Height() ); |
|
745 break; |
|
746 } |
|
747 case EHRightVTop: |
|
748 { |
|
749 // Tooltip is right and top aligned. |
|
750 delta.iX = rect.Width(); |
|
751 break; |
|
752 } |
|
753 case EHRightVCenter: |
|
754 { |
|
755 // Tooltip right aligned and centred vertically. |
|
756 delta.SetXY( rect.Width(), rect.Height() / 2 ); |
|
757 break; |
|
758 } |
|
759 case EHRightVBottom: |
|
760 { |
|
761 // Tooltip is right aligned and at the bottom. |
|
762 delta.SetXY( rect.Width(), rect.Height() ); |
|
763 break; |
|
764 } |
|
765 default: |
|
766 { |
|
767 break; |
|
768 } |
|
769 } |
|
770 |
|
771 AdjustPosition( TPoint( iFloatingPosition - delta ) ); |
|
772 |
|
773 if ( iFloatingPosition != iPosition ) |
|
774 { |
|
775 SetPosition( iFloatingPosition ); |
|
776 } |
|
777 } |
|
778 |
|
779 // ----------------------------------------------------------------------------- |
|
780 // AdjustPosition |
|
781 // Adjusts the position of the info pop-up note so that it fits the screen and |
|
782 // does not overlap with the control pane. |
|
783 // ----------------------------------------------------------------------------- |
|
784 // |
|
785 void CAknInfoPopupNote::AdjustPosition( const TPoint& aFloatingPosition ) |
|
786 { |
|
787 TRect area( iAvkonAppUi->ApplicationRect() ); |
|
788 |
|
789 if ( iAvkonAppUi->IsDisplayingControlBetweenPriorities( |
|
790 ECoeStackPriorityCba - 1, ECoeStackPriorityCba + 1 ) ) |
|
791 { |
|
792 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, area ); |
|
793 |
|
794 if ( !AknStatuspaneUtils::StaconPaneActive() ) |
|
795 { |
|
796 TRect statusPaneRect; |
|
797 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, |
|
798 statusPaneRect ); |
|
799 |
|
800 area.BoundingRect( statusPaneRect ); |
|
801 } |
|
802 } |
|
803 |
|
804 TRect rect( aFloatingPosition, Size() ); |
|
805 |
|
806 iFloatingPosition.SetXY( Max( area.iTl.iX, Min( rect.iBr.iX, area.iBr.iX ) |
|
807 - rect.Width() ), |
|
808 Max( area.iTl.iY, Min( rect.iBr.iY, area.iBr.iY ) |
|
809 - rect.Height() ) ); |
|
810 } |
|
811 |
|
812 // ----------------------------------------------------------------------------- |
|
813 // RectFromLayout |
|
814 // |
|
815 // ----------------------------------------------------------------------------- |
|
816 // |
|
817 TRect CAknInfoPopupNote::RectFromLayout( const TRect& aParent, |
|
818 const TAknWindowComponentLayout& aComponentLayout ) const |
|
819 { |
|
820 TAknWindowLineLayout lineLayout = aComponentLayout.LayoutLine(); |
|
821 TAknLayoutRect layoutRect; |
|
822 layoutRect.LayoutRect(aParent, lineLayout); |
|
823 return layoutRect.Rect(); |
|
824 } |
|
825 |
|
826 // ----------------------------------------------------------------------------- |
|
827 // SelectLineVariety |
|
828 // |
|
829 // ----------------------------------------------------------------------------- |
|
830 // |
|
831 TInt CAknInfoPopupNote::SelectLineVariety( const TInt aNumberOfLines, |
|
832 const TAknLayoutScalableParameterLimits& aLimits ) const |
|
833 { |
|
834 return Min( Max( aNumberOfLines - 1, aLimits.FirstVariety() ), |
|
835 aLimits.LastVariety() ); |
|
836 } |
|
837 |
|
838 // ----------------------------------------------------------------------------- |
|
839 // SelectWindowVariety |
|
840 // |
|
841 // ----------------------------------------------------------------------------- |
|
842 // |
|
843 TInt CAknInfoPopupNote::SelectWindowVariety( const TInt aNumberOfLines, |
|
844 const TAknLayoutScalableParameterLimits& aLimits ) const |
|
845 { |
|
846 TInt index = aNumberOfLines - 1; |
|
847 if ( Layout_Meta_Data::IsLandscapeOrientation() ) |
|
848 { |
|
849 index += 5; |
|
850 } |
|
851 |
|
852 return Min( Max( index, aLimits.FirstVariety() ), |
|
853 aLimits.LastVariety() ); |
|
854 } |
|
855 |
|
856 // ----------------------------------------------------------------------------- |
|
857 // HandleGainingForeground |
|
858 // |
|
859 // ----------------------------------------------------------------------------- |
|
860 // |
|
861 void CAknInfoPopupNote::HandleGainingForeground() |
|
862 { |
|
863 // empty implementation |
|
864 } |
|
865 |
|
866 // ----------------------------------------------------------------------------- |
|
867 // HandleLosingForeground |
|
868 // |
|
869 // ----------------------------------------------------------------------------- |
|
870 // |
|
871 void CAknInfoPopupNote::HandleLosingForeground() |
|
872 { |
|
873 if ( IsVisible() && iHideWhenAppFaded ) |
|
874 { |
|
875 iController.HideInfoPopupNote(); |
|
876 } |
|
877 } |
|
878 |
|
879 // End of File |