emailuis/emailui/src/ncspopuplistbox.cpp
branchRCL_3
changeset 19 b13141f05c3d
parent 17 8592a65ad3fb
child 24 b5fbb9b25d57
equal deleted inserted replaced
17:8592a65ad3fb 19:b13141f05c3d
    24 #include <StringLoader.h>						// StringLoader
    24 #include <StringLoader.h>						// StringLoader
    25 #include <CPbkContactEngine.h>
    25 #include <CPbkContactEngine.h>
    26 #include <aknnotewrappers.h>					//For LanguageNotSupported errorNote
    26 #include <aknnotewrappers.h>					//For LanguageNotSupported errorNote
    27 #include <aknsdrawutils.h>
    27 #include <aknsdrawutils.h>
    28 #include <aknsutils.h>
    28 #include <aknsutils.h>
       
    29 #include <aknlayoutscalable_apps.cdl.h>
       
    30 #include <aknlayoutscalable_avkon.cdl.h>
    29 
    31 
    30 #include "ncspopuplistbox.h"
    32 #include "ncspopuplistbox.h"
    31 #include "ncsemailaddressobject.h"					// CNcsEmailAddressObject
    33 #include "ncsemailaddressobject.h"					// CNcsEmailAddressObject
    32 #include "ncsconstants.h"
    34 #include "ncsconstants.h"
    33 #include "ncsheadercontainer.h"						// CNcsHeaderContainer
    35 #include "ncsheadercontainer.h"						// CNcsHeaderContainer
    37 #include "FreestyleEmailUiAppui.h"
    39 #include "FreestyleEmailUiAppui.h"
    38 #include "FreestyleEmailUiLayoutHandler.h"
    40 #include "FreestyleEmailUiLayoutHandler.h"
    39 #include "FSDelayedLoader.h"
    41 #include "FSDelayedLoader.h"
    40 #include "FreestyleEmailUiCLSItem.h"
    42 #include "FreestyleEmailUiCLSItem.h"
    41 
    43 
    42 const TInt KBackgroundFrameWidth = 4;
       
    43 const TInt KHighlightFrameWidth = 2;
    44 const TInt KHighlightFrameWidth = 2;
    44 
    45 
    45 // ========================= MEMBER FUNCTIONS ==================================
    46 // ========================= MEMBER FUNCTIONS ==================================
    46 
    47 
    47 // -----------------------------------------------------------------------------
    48 // -----------------------------------------------------------------------------
    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
   153 // CNcsPopupListBox::SizeChanged
   159 // CNcsPopupListBox::SizeChanged
   154 // -----------------------------------------------------------------------------
   160 // -----------------------------------------------------------------------------
   155 void CNcsPopupListBox::SizeChanged()
   161 void CNcsPopupListBox::SizeChanged()
   156     {
   162     {
   157     FUNC_LOG;
   163     FUNC_LOG;
   158     TRect outerRect = Rect();
   164     const TRect outerRect = Rect();
   159     TRect innerRect = outerRect;
   165 
   160     innerRect.Shrink( KBackgroundFrameWidth, KBackgroundFrameWidth );
   166     TAknLayoutRect subpane;
       
   167     subpane.LayoutRect( outerRect, 
       
   168         AknLayoutScalable_Avkon::bg_popup_sub_pane_g1() );
       
   169     const TRect innerRect = subpane.Rect();
       
   170 
       
   171     iBackgroundContext->SetFrameRects( outerRect, innerRect );
       
   172 
   161     SetViewRectFromClientRect( innerRect );
   173     SetViewRectFromClientRect( innerRect );
   162     TRAP_IGNORE( HandleViewRectSizeChangeL() );
   174     TRAP_IGNORE( HandleViewRectSizeChangeL() );
   163     iBackgroundContext->SetFrameRects( outerRect, innerRect );
       
   164     }
   175     }
   165 
   176 
   166 void CNcsPopupListBox::HandleResourceChange( TInt aType )
   177 void CNcsPopupListBox::HandleResourceChange( TInt aType )
   167     {
   178     {
   168     FUNC_LOG;
   179     FUNC_LOG;
   172         }
   183         }
   173     }
   184     }
   174 
   185 
   175 void CNcsPopupListBox::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   186 void CNcsPopupListBox::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   176     {
   187     {
   177     // When scrollbar is non-window-owning, the pointer events should be passed
   188     CEikTextListBox::HandlePointerEventL( aPointerEvent );
   178     // to it through control hierachy, but the CEikTextListBox does not seem to 
       
   179     // do that, so that is handled here.
       
   180     CEikScrollBar* sb = iSBFrame->VerticalScrollBar();
       
   181     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   182         {
       
   183         if ( sb && sb->Rect().Contains( aPointerEvent.iPosition ) )
       
   184             {
       
   185             sb->ClaimPointerGrab( EFalse );
       
   186             sb->HandlePointerEventL( aPointerEvent );
       
   187             }
       
   188         else
       
   189             {
       
   190             ClaimPointerGrab( EFalse );
       
   191             }
       
   192         }
       
   193 
       
   194     CCoeControl* pointerRecipient = GrabbingComponent();
       
   195     if ( sb && pointerRecipient == sb )
       
   196         {
       
   197         sb->HandlePointerEventL( aPointerEvent );
       
   198         }
       
   199     else
       
   200         {
       
   201         CEikTextListBox::HandlePointerEventL( aPointerEvent );
       
   202         }
       
   203     }
   189     }
   204 
   190 
   205 // -----------------------------------------------------------------------------
   191 // -----------------------------------------------------------------------------
   206 // CNcsPopupListBox::OfferKeyEventL
   192 // CNcsPopupListBox::OfferKeyEventL
   207 // -----------------------------------------------------------------------------
   193 // -----------------------------------------------------------------------------
   370 // -----------------------------------------------------------------------------
   356 // -----------------------------------------------------------------------------
   371 void CNcsPopupListBox::SetPopupMaxRect( const TRect& aPopupMaxRect )
   357 void CNcsPopupListBox::SetPopupMaxRect( const TRect& aPopupMaxRect )
   372     {
   358     {
   373     FUNC_LOG;
   359     FUNC_LOG;
   374     iPopupMaxRect = aPopupMaxRect;
   360     iPopupMaxRect = aPopupMaxRect;
   375     SetPopupHeight();
   361 
       
   362     SetPopupRect();
   376     TRAP_IGNORE( UpdateScrollBarsL() );
   363     TRAP_IGNORE( UpdateScrollBarsL() );
   377     TRAP_IGNORE( SetScrollBarVisibilityL() );
   364     TRAP_IGNORE( SetScrollBarVisibilityL() );
   378     }
   365     }
   379 
   366 
   380 // -----------------------------------------------------------------------------
   367 // -----------------------------------------------------------------------------
   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()
   667 
   688 
   668     TRect itemRect = aActualItemRect;
   689     TRect itemRect = aActualItemRect;
   669     { 
   690     { 
   670     // temporary const_cast to get the scrollbar width
   691     // temporary const_cast to get the scrollbar width
   671     CNcsPopupListBox& tmpListBox = const_cast<CNcsPopupListBox&>( iListBox );
   692     CNcsPopupListBox& tmpListBox = const_cast<CNcsPopupListBox&>( iListBox );
   672     itemRect.Resize( -tmpListBox.ScrollBarFrame()->ScrollBarBreadth(
   693     const TInt scrollbarBreadth = tmpListBox.ScrollBarFrame()->
   673         CEikScrollBar::EVertical ) + KBackgroundFrameWidth, 0 );
   694         ScrollBarBreadth( CEikScrollBar::EVertical );
       
   695     if ( AknLayoutUtils::LayoutMirrored() )
       
   696         {
       
   697         itemRect.iTl.iX = iListBox.Rect().iTl.iX + scrollbarBreadth;
       
   698         }
       
   699     else
       
   700         {
       
   701         itemRect.iBr.iX = iListBox.Rect().iBr.iX - scrollbarBreadth;
       
   702         }
   674     }
   703     }
   675 
   704 
   676     TRect textRect = itemRect;
   705     TRect textRect = itemRect;
   677     textRect.Shrink( KHighlightFrameWidth, KHighlightFrameWidth );
   706     textRect.Shrink( KHighlightFrameWidth, KHighlightFrameWidth );
   678 
   707 
   681 
   710 
   682     // Draw background using the control context from the list box.
   711     // Draw background using the control context from the list box.
   683     MAknsControlContext* cc = AknsDrawUtils::ControlContext( &iListBox );
   712     MAknsControlContext* cc = AknsDrawUtils::ControlContext( &iListBox );
   684     if ( cc )
   713     if ( cc )
   685         {
   714         {
   686         AknsDrawUtils::Background( skin, cc, *iGc, itemRect );
   715         AknsDrawUtils::Background( skin, cc, *iGc, aActualItemRect );
   687         }
   716         }
   688     else
   717     else
   689         {
   718         {
   690         iGc->Clear( itemRect );
   719         iGc->Clear( aActualItemRect );
   691         }
   720         }
   692 
   721 
   693     // Draw the highlight, when necessary.
   722     // Draw the highlight, when necessary.
   694     if ( aItemIsCurrent ) 
   723     if ( aItemIsCurrent ) 
   695         {
   724         {
   879             EAknsCIQsnTextColorsCG10 );
   908             EAknsCIQsnTextColorsCG10 );
   880         iItemDrawer->SetHighlightedTextColor( textColor );
   909         iItemDrawer->SetHighlightedTextColor( textColor );
   881         }
   910         }
   882     }
   911     }
   883 
   912 
   884 void CNcsPopupListBox::Draw( const TRect& aRect ) const
   913 void CNcsPopupListBox::Draw( const TRect& /*aRect*/ ) const
   885     {
   914     {
   886     CWindowGc& gc = SystemGc();
   915     CWindowGc& gc = SystemGc();
   887     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   916     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   888     if ( iBackgroundContext )
   917     if ( iBackgroundContext )
   889         {
   918         {
   890         AknsDrawUtils::Background( skin, iBackgroundContext, gc, aRect );
   919         AknsDrawUtils::DrawBackground( skin, iBackgroundContext, this, gc,
       
   920             Rect().iTl, Rect(), KAknsDrawParamNoClearUnderImage );
   891         }
   921         }
   892     else
   922     else
   893         {
   923         {
   894         gc.Clear( aRect );
   924         gc.Clear( Rect() );
   895         }
   925         }
   896     CEikListBox::Draw( aRect );
   926     CEikListBox::Draw( Rect() );
   897     }
   927     }
   898 
   928 
   899 // End of File
   929 // End of File
   900 
   930