65 // CNcsPopupListBox::CNcsPopupListBox |
66 // CNcsPopupListBox::CNcsPopupListBox |
66 // ----------------------------------------------------------------------------- |
67 // ----------------------------------------------------------------------------- |
67 CNcsPopupListBox::CNcsPopupListBox( CNcsHeaderContainer& aHeaderContainer, |
68 CNcsPopupListBox::CNcsPopupListBox( CNcsHeaderContainer& aHeaderContainer, |
68 TBool aRemoteLookupSupported, |
69 TBool aRemoteLookupSupported, |
69 CFSMailBox& aMailBox) |
70 CFSMailBox& aMailBox) |
70 : iHeaderContainer( aHeaderContainer ),iMailBox( aMailBox ), |
71 : iHeaderContainer( aHeaderContainer ), |
71 iRemoteLookupSupported( aRemoteLookupSupported ),iCachingInProgress( EFalse ) |
72 iMailBox( aMailBox ), |
72 { |
73 iRemoteLookupSupported( aRemoteLookupSupported ), |
73 FUNC_LOG; |
74 iCachingInProgress( EFalse ), |
|
75 iAppUi( static_cast<CFreestyleEmailUiAppUi*>( iEikonEnv->AppUi() ) ) |
|
76 { |
|
77 FUNC_LOG; |
|
78 iPopupMaxRect = TRect( 100, 100, 100, 100 ); |
74 } |
79 } |
75 |
80 |
76 // ----------------------------------------------------------------------------- |
81 // ----------------------------------------------------------------------------- |
77 // CNcsPopupListBox::ConstructL |
82 // CNcsPopupListBox::ConstructL |
78 // ----------------------------------------------------------------------------- |
83 // ----------------------------------------------------------------------------- |
79 void CNcsPopupListBox::ConstructL( const CCoeControl* aParent ) |
84 void CNcsPopupListBox::ConstructL( const CCoeControl* aParent ) |
80 { |
85 { |
81 FUNC_LOG; |
86 FUNC_LOG; |
82 CEikTextListBox::ConstructL( aParent, CEikListBox::EPopout ); |
87 CEikTextListBox::ConstructL( NULL, CEikListBox::EPopout ); |
83 // Create non-window-owning scrollbar to avoid flickering. |
88 SetMopParent( const_cast<CCoeControl*>( aParent ) ); |
84 CEikScrollBarFrame* frame = CreateScrollBarFrameL( EFalse, EFalse, EFalse ); |
89 User::LeaveIfError( SetParent( const_cast<CCoeControl*>( aParent ) ) ); |
|
90 |
|
91 CEikScrollBarFrame* frame = CreateScrollBarFrameL( EFalse, EFalse, ETrue ); |
85 |
92 |
86 CEikTextListBox::SetBorder( TGulBorder::ENone ); |
93 CEikTextListBox::SetBorder( TGulBorder::ENone ); |
87 |
94 |
88 const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimarySmallFont ); |
95 const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimarySmallFont ); |
89 CEikTextListBox::SetItemHeightL( font->FontMaxHeight() + 12 ); |
96 CEikTextListBox::SetItemHeightL( font->FontMaxHeight() + 12 ); |
90 |
97 |
91 iBackgroundContext = CAknsFrameBackgroundControlContext::NewL( |
98 iBackgroundContext = CAknsFrameBackgroundControlContext::NewL( |
92 KAknsIIDQsnFrPopup, Rect(), Rect(), EFalse ); |
99 KAknsIIDQsnFrPopupSub, Rect(), Rect(), EFalse ); |
93 UpdateTextColors(); |
100 UpdateTextColors(); |
94 |
101 |
95 iContactHandler = CFsDelayedLoader::InstanceL()->GetContactHandlerL(); |
102 iContactHandler = CFsDelayedLoader::InstanceL()->GetContactHandlerL(); |
96 if ( !iContactHandler->IsLanguageSupportedL() ) |
103 if ( !iContactHandler->IsLanguageSupportedL() ) |
97 { |
104 { |
98 iContactHandler = NULL; |
105 iContactHandler = NULL; |
99 } |
106 } |
100 |
107 |
101 iAppUi = static_cast<CFreestyleEmailUiAppUi*>( iEikonEnv->AppUi() ); |
|
102 SetListBoxObserver( this ); |
108 SetListBoxObserver( this ); |
103 } |
109 } |
104 |
110 |
105 // ----------------------------------------------------------------------------- |
111 // ----------------------------------------------------------------------------- |
106 // CNcsPopupListBox::InitAndSearchL |
112 // CNcsPopupListBox::InitAndSearchL |
447 } |
434 } |
448 |
435 |
449 // Update rmlu item |
436 // Update rmlu item |
450 SetRemoteLookupItemFirstToTheListL(); |
437 SetRemoteLookupItemFirstToTheListL(); |
451 |
438 |
452 SetPopupHeight(); |
439 SetPopupRect(); |
453 SetScrollBarVisibilityL(); |
440 SetScrollBarVisibilityL(); |
454 HandleItemAdditionL(); |
441 HandleItemAdditionL(); |
455 |
442 |
456 if( iItemTextsArray && iItemTextsArray->Count() > 0 ) |
443 if ( iItemTextsArray && iItemTextsArray->Count() > 0 ) |
457 SetCurrentItemIndex( 0 ); |
444 { |
458 |
445 SetCurrentItemIndex( 0 ); |
459 if( IsVisible() ) |
446 } |
460 DrawDeferred(); |
447 |
461 } |
448 if ( IsVisible() ) |
|
449 { |
|
450 DrawDeferred(); |
|
451 } |
|
452 } |
462 |
453 |
463 // ----------------------------------------------------------------------------- |
454 // ----------------------------------------------------------------------------- |
464 // CNcsPopupListBox::RoundToItemHeight |
455 // CNcsPopupListBox::RoundToItemHeight |
465 // ----------------------------------------------------------------------------- |
456 // ----------------------------------------------------------------------------- |
466 TInt CNcsPopupListBox::RoundToItemHeight(const TInt aPopupHeight) const |
457 TInt CNcsPopupListBox::RoundToItemHeight(const TInt aPopupHeight) const |
467 { |
458 { |
468 TReal fullItems; // number of full visible items in window |
459 TReal fullItems; // number of full visible items in window |
469 TInt err = Math::Round(fullItems, (aPopupHeight / ItemHeight()), 0); |
460 TInt err = Math::Round(fullItems, (aPopupHeight / ItemHeight()), 0); |
470 if(err == KErrNone) |
461 if (err == KErrNone) |
471 { |
462 { |
472 return (TInt)(fullItems * ItemHeight()); |
463 return (TInt)(fullItems * ItemHeight()); |
473 } |
464 } |
474 return aPopupHeight; // in case of error |
465 return aPopupHeight; // in case of error |
475 } |
466 } |
476 |
467 |
477 // ----------------------------------------------------------------------------- |
468 // ----------------------------------------------------------------------------- |
478 // CNcsPopupListBox::SetPopupHeight |
469 // CNcsPopupListBox::SetPopupRect |
479 // ----------------------------------------------------------------------------- |
470 // ----------------------------------------------------------------------------- |
480 void CNcsPopupListBox::SetPopupHeight() |
471 void CNcsPopupListBox::SetPopupRect() |
481 { |
472 { |
482 FUNC_LOG; |
473 FUNC_LOG; |
|
474 // The popup width and horizontal position is adjusted so that it |
|
475 // will be within the area specified in both layout data and the set |
|
476 // maximum rect. |
|
477 TAknLayoutRect editorPane; |
|
478 editorPane.LayoutRect( iAppUi->ClientRect(), |
|
479 TAknWindowComponentLayout::Compose( |
|
480 TAknWindowComponentLayout::Compose( |
|
481 AknLayoutScalable_Apps::list_cmail_pane(), |
|
482 AknLayoutScalable_Apps::list_single_cmail_header_detail_pane( 0 ) ), |
|
483 AknLayoutScalable_Apps::list_single_cmail_header_editor_pane_bg( 4 ) ) ); |
|
484 TRect editorPaneRect = editorPane.Rect(); |
|
485 |
|
486 TRect newRect = iPopupMaxRect; |
|
487 newRect.iTl.iX = Max( iPopupMaxRect.iTl.iX, editorPaneRect.iTl.iX ); |
|
488 newRect.iBr.iX = Min( iPopupMaxRect.iBr.iX, editorPaneRect.iBr.iX ); |
|
489 |
|
490 // Thhe popup height and vertical position is adjusted based on the |
|
491 // available space below and above the cursor and the number of items |
|
492 // in the list. |
|
493 const TRect rect = iPopupMaxRect; |
|
494 TAknLayoutRect subpane; |
|
495 subpane.LayoutRect( rect, AknLayoutScalable_Avkon::bg_popup_sub_pane_g1() ); |
|
496 const TRect subpaneRect = subpane.Rect(); |
|
497 |
|
498 const TInt frameHeights = iPopupMaxRect.Height() - subpaneRect.Height(); |
|
499 |
483 // This is the total height in pixels needed to show all items |
500 // This is the total height in pixels needed to show all items |
484 TInt minimumHeight = 2 * KBackgroundFrameWidth + |
501 TInt minimumHeight = frameHeights + |
485 CalcHeightBasedOnNumOfItems( Model()->NumberOfItems() ); |
502 CalcHeightBasedOnNumOfItems( Model()->NumberOfItems() ); |
486 TRect newRect = iPopupMaxRect; |
503 |
487 TInt areaHeight = Parent()->Parent()->Rect().Height(); |
504 CCoeControl* container = Parent()->Parent(); |
488 TInt halfAreaHeight = areaHeight/2; |
505 TInt containerTop = container->PositionRelativeToScreen().iY; |
|
506 TInt containerHeight = container->Rect().Height(); |
|
507 TInt containerCenter = containerTop + containerHeight / 2; |
489 |
508 |
490 // Get height of one line in Address field |
509 // Get height of one line in Address field |
491 CNcsHeaderContainer* headerObj = static_cast<CNcsHeaderContainer* >(Parent()); |
510 CNcsHeaderContainer* headerObj = static_cast<CNcsHeaderContainer* >(Parent()); |
492 TInt toLineHeight = headerObj->GetToLineHeight(); // height of one line height |
511 TInt toLineHeight = headerObj->GetToLineHeight(); // height of one line height |
493 if(toLineHeight == 0) |
512 if ( toLineHeight == 0 ) |
494 { |
513 { |
495 toLineHeight = ItemHeight(); |
514 toLineHeight = ItemHeight(); |
496 } |
515 } |
497 |
516 |
498 TInt newHeight = minimumHeight; // default window height |
517 TInt newHeight = minimumHeight; // default window height |
499 |
518 |
500 //latch listbox on the bottom of the editor field |
519 // latch listbox on the bottom of the editor field |
501 if ( newRect.iTl.iY <= halfAreaHeight ) |
520 if ( newRect.iTl.iY <= containerCenter ) |
502 { |
521 { |
503 newHeight = RoundToItemHeight( areaHeight - newRect.iTl.iY ); |
522 TInt maxHeight = containerHeight - ( newRect.iTl.iY - containerTop ); |
504 if(newHeight > minimumHeight) |
523 newHeight = RoundToItemHeight( maxHeight - frameHeights ) + frameHeights; |
505 { |
524 if ( newHeight > minimumHeight ) |
|
525 { |
506 newHeight = minimumHeight; // shrink window (if needed) |
526 newHeight = minimumHeight; // shrink window (if needed) |
507 } |
527 } |
508 } |
528 } |
509 //latch listbox on the top of the editor field |
529 // latch listbox on the top of the editor field |
510 else |
530 else |
511 { |
531 { |
512 TInt yOffset = -minimumHeight - toLineHeight; // how much up |
532 TInt yOffset = -minimumHeight - toLineHeight; // how much up |
513 TInt newTlY = newRect.iTl.iY + yOffset; // new Top Left Y coordinate |
533 TInt newTlY = newRect.iTl.iY + yOffset; // new Top Left Y coordinate |
514 if(newTlY>=0) |
534 if ( newTlY >= containerTop ) |
515 { |
535 { |
516 newRect.Move( 0, yOffset ); |
536 newRect.Move( 0, yOffset ); |
517 } |
537 } |
518 else |
538 else |
519 { |
539 { |
520 // shrink height to visible area and move |
540 // shrink height to visible area and move |
521 newHeight = RoundToItemHeight( minimumHeight + newTlY); |
541 TInt maxHeight = newRect.iTl.iY - toLineHeight - containerTop; |
522 newRect.Move( 0, -newHeight - toLineHeight); |
542 newHeight = RoundToItemHeight( maxHeight - frameHeights ) + frameHeights; |
|
543 newRect.Move( 0, -newHeight - toLineHeight ); |
523 } |
544 } |
524 } |
545 } |
525 newRect.SetHeight(newHeight); // set new height |
546 newRect.SetHeight( newHeight ); // set new height |
526 SetRect( newRect ); |
547 SetRect( newRect ); |
527 } |
548 } |
528 |
549 |
529 // ----------------------------------------------------------------------------- |
550 // ----------------------------------------------------------------------------- |
530 // CNcsPopupListBox::SetScrollBarVisibilityL |
551 // CNcsPopupListBox::SetScrollBarVisibilityL |
531 // ----------------------------------------------------------------------------- |
552 // ----------------------------------------------------------------------------- |
532 void CNcsPopupListBox::SetScrollBarVisibilityL() |
553 void CNcsPopupListBox::SetScrollBarVisibilityL() |