emailuis/emailui/src/ncsattachmentfield.cpp
branchRCL_3
changeset 80 726fba06891a
parent 64 3533d4323edc
equal deleted inserted replaced
73:c8382f7b54ef 80:726fba06891a
    35 
    35 
    36 
    36 
    37 CNcsAttachmentField* CNcsAttachmentField::NewL(
    37 CNcsAttachmentField* CNcsAttachmentField::NewL(
    38     TInt aLabelTextId,
    38     TInt aLabelTextId,
    39     MNcsFieldSizeObserver* aSizeObserver,
    39     MNcsFieldSizeObserver* aSizeObserver,
       
    40     MNcsAttachmentFieldObserver* aObserver,
    40     CNcsHeaderContainer* aParentControl )
    41     CNcsHeaderContainer* aParentControl )
    41     {
    42     {
    42     FUNC_LOG;
    43     FUNC_LOG;
    43     CNcsAttachmentField* self =
    44     CNcsAttachmentField* self =
    44         new ( ELeave ) CNcsAttachmentField( aLabelTextId, aSizeObserver, aParentControl );
    45         new ( ELeave ) CNcsAttachmentField( aLabelTextId, aSizeObserver,
       
    46                                             aObserver, aParentControl );
    45     CleanupStack::PushL( self );
    47     CleanupStack::PushL( self );
    46     self->ConstructL();
    48     self->ConstructL();
    47     CleanupStack::Pop( self );
    49     CleanupStack::Pop( self );
    48     return self;
    50     return self;
    49     }
    51     }
    64 // CNcsAttachmentField::CNcsAttachmentField()
    66 // CNcsAttachmentField::CNcsAttachmentField()
    65 // -----------------------------------------------------------------------------
    67 // -----------------------------------------------------------------------------
    66 //
    68 //
    67 CNcsAttachmentField::CNcsAttachmentField( TInt aLabelTextId, 
    69 CNcsAttachmentField::CNcsAttachmentField( TInt aLabelTextId, 
    68         MNcsFieldSizeObserver* aSizeObserver,
    70         MNcsFieldSizeObserver* aSizeObserver,
       
    71         MNcsAttachmentFieldObserver* aObserver,
    69         CNcsHeaderContainer* aParentControl ):
    72         CNcsHeaderContainer* aParentControl ):
    70     MNcsControl( aSizeObserver ),
    73     MNcsControl( aSizeObserver ),
    71     iParentControl( aParentControl ),
    74     iParentControl( aParentControl ),
       
    75     iObserver( aObserver ),
    72     iLabelTextId ( aLabelTextId ),
    76     iLabelTextId ( aLabelTextId ),
    73     iFocusedLabelIndex( KNoAttachmentLabelFocused )
    77     iFocusedLabelIndex( KNoAttachmentLabelFocused )
    74     {
    78     {
    75     FUNC_LOG;
    79     FUNC_LOG;
    76     }
    80     }
   272 // -----------------------------------------------------------------------------
   276 // -----------------------------------------------------------------------------
   273 // CNcsAttachmentField::SetContainerWindowL()
   277 // CNcsAttachmentField::SetContainerWindowL()
   274 // -----------------------------------------------------------------------------
   278 // -----------------------------------------------------------------------------
   275 //
   279 //
   276 void CNcsAttachmentField::SetContainerWindowL( const CCoeControl& aContainer )
   280 void CNcsAttachmentField::SetContainerWindowL( const CCoeControl& aContainer )
   277 	{
   281     {
   278     FUNC_LOG;
   282     FUNC_LOG;
   279 	CCoeControl::SetContainerWindowL( aContainer );
   283     CCoeControl::SetContainerWindowL( aContainer );
   280 
   284     UpdateComponentArrayL();
   281 	UpdateComponentArrayL();
   285     }
   282 	}
       
   283 
   286 
   284 // -----------------------------------------------------------------------------
   287 // -----------------------------------------------------------------------------
   285 // CNcsAttachmentField::UpdateComponentArrayL()
   288 // CNcsAttachmentField::UpdateComponentArrayL()
   286 // -----------------------------------------------------------------------------
   289 // -----------------------------------------------------------------------------
   287 //
   290 //
   374 
   377 
   375 // -----------------------------------------------------------------------------
   378 // -----------------------------------------------------------------------------
   376 // CNcsAttachmentField::FocusedAttachmentLabelIndex()
   379 // CNcsAttachmentField::FocusedAttachmentLabelIndex()
   377 // -----------------------------------------------------------------------------
   380 // -----------------------------------------------------------------------------
   378 //
   381 //
   379 TInt CNcsAttachmentField::FocusedAttachmentLabelIndex()
   382 TInt CNcsAttachmentField::FocusedAttachmentLabelIndex() const
   380     {
   383     {
   381     FUNC_LOG;
   384     FUNC_LOG;
   382     return iFocusedLabelIndex;
   385     return iFocusedLabelIndex;
       
   386     }
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CNcsAttachmentField::SetFocusedAttachmentLabelIndex()
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 void CNcsAttachmentField::SetFocusedAttachmentLabelIndex( TInt aIndex )
       
   393     {
       
   394     FUNC_LOG;
       
   395     iFocusedLabelIndex = aIndex;
   383     }
   396     }
   384 
   397 
   385 // -----------------------------------------------------------------------------
   398 // -----------------------------------------------------------------------------
   386 // CNcsAttachmentField::UpdateAttachmentTextsL()
   399 // CNcsAttachmentField::UpdateAttachmentTextsL()
   387 // -----------------------------------------------------------------------------
   400 // -----------------------------------------------------------------------------
   455 // -----------------------------------------------------------------------------
   468 // -----------------------------------------------------------------------------
   456 // CNcsAttachmentField::FocusChanged()
   469 // CNcsAttachmentField::FocusChanged()
   457 // -----------------------------------------------------------------------------
   470 // -----------------------------------------------------------------------------
   458 //
   471 //
   459 void CNcsAttachmentField::FocusChanged( TDrawNow aDrawNow )
   472 void CNcsAttachmentField::FocusChanged( TDrawNow aDrawNow )
   460 	{
   473     {
   461     FUNC_LOG;
   474     FUNC_LOG;
   462 	if ( IsFocused() )
   475     if ( IsFocused() )
   463 	    {
   476         {
   464 	    for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i )
   477         for ( TInt i( 0 ); i < iAttachmentLabelCount; ++i )
   465 	        {
   478             {
   466 	        iAttachmentLabels[i]->SetFocus( i==iFocusedLabelIndex );
   479             iAttachmentLabels[i]->SetFocus( i==iFocusedLabelIndex );
   467 	        }
   480             }
   468         // make sure that control is visible on screen
   481         // make sure that control is visible on screen
   469 		if ( Rect().iTl.iY < 0 )
   482 		if ( Rect().iTl.iY < 0 )
   470 			{
   483 			{
   471 			TPoint pt = TPoint( 0, 0 );
   484 			TPoint pt = TPoint( 0, 0 );
   472 			Reposition( pt,Rect().Width() );
   485 			Reposition( pt,Rect().Width() );
   490 
   503 
   491         if ( iParentControl )
   504         if ( iParentControl )
   492             {
   505             {
   493             TRAP_IGNORE( iParentControl->SetMskL() );
   506             TRAP_IGNORE( iParentControl->SetMskL() );
   494             }
   507             }
   495 		}
   508         }
   496 	else
   509     else
   497 		{
   510         {
   498 		for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i )
   511         for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i )
   499 		    {
   512             {
   500 		    iAttachmentLabels[i]->SetFocus( EFalse );
   513             iAttachmentLabels[i]->SetFocus( EFalse );
   501 		    }
   514             }
   502 		}
   515         }
   503 	
   516 
   504     UpdateColors();
   517     UpdateColors();
   505     
   518 
   506 	if ( aDrawNow )
   519     if ( aDrawNow )
   507 		{
   520         {
   508 		DrawNow();
   521         DrawNow();
   509 		}
   522         }
   510 	else
   523     else
   511 	    {
   524         {
   512 	    DrawDeferred();
   525         DrawDeferred();
   513 	    }
   526         }
   514 	}
   527     }
   515 
   528 
   516 // -----------------------------------------------------------------------------
   529 // -----------------------------------------------------------------------------
   517 // CNcsAttachmentField::UpdateColors()
   530 // CNcsAttachmentField::UpdateColors()
   518 // -----------------------------------------------------------------------------
   531 // -----------------------------------------------------------------------------
   519 //
   532 //
   660 void CNcsAttachmentField::HandlePointerEventL( 
   673 void CNcsAttachmentField::HandlePointerEventL( 
   661         const TPointerEvent& aPointerEvent )
   674         const TPointerEvent& aPointerEvent )
   662     {
   675     {
   663     FUNC_LOG;
   676     FUNC_LOG;
   664     CCoeControl::HandlePointerEventL( aPointerEvent );
   677     CCoeControl::HandlePointerEventL( aPointerEvent );
   665     
   678 
   666     if ( aPointerEvent.iType == TPointerEvent::EButton1Down  &&
   679     if ( aPointerEvent.iType == TPointerEvent::EButton1Down  &&
   667          Rect().Contains( aPointerEvent.iPosition ) )
   680          Rect().Contains( aPointerEvent.iPosition ) )
   668         {
   681         {
   669         TBool focusedAttachmentLabelIndexChanged( EFalse );
   682         TBool focusedAttachmentLabelIndexChanged( EFalse );
   670         TInt i( 0 );
   683         TInt i( 0 );
   677                 MTouchFeedback* feedback = MTouchFeedback::Instance();
   690                 MTouchFeedback* feedback = MTouchFeedback::Instance();
   678                 if ( feedback )
   691                 if ( feedback )
   679                     {
   692                     {
   680                     feedback->InstantFeedback( this, ETouchFeedbackBasic );
   693                     feedback->InstantFeedback( this, ETouchFeedbackBasic );
   681                     }
   694                     }
   682                 
   695 
   683                 if ( iFocusedLabelIndex != i )
   696                 if ( iFocusedLabelIndex != i )
   684                     {
   697                     {
   685                     focusedAttachmentLabelIndexChanged = ETrue;
   698                     focusedAttachmentLabelIndexChanged = ETrue;
   686                     iFocusedLabelIndex =  i;
   699                     iFocusedLabelIndex =  i;
   687                     }
   700                     }
   707                 }
   720                 }
   708             UpdateColors();
   721             UpdateColors();
   709             DrawDeferred();
   722             DrawDeferred();
   710             }
   723             }
   711         }
   724         }
       
   725     }
       
   726 
       
   727 // -----------------------------------------------------------------------------
       
   728 // CNcsAttachmentField::OfferKeyEventL()
       
   729 // -----------------------------------------------------------------------------
       
   730 //
       
   731 TKeyResponse CNcsAttachmentField::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   732     TEventCode aType )
       
   733     {
       
   734     TKeyResponse response = EKeyWasNotConsumed;
       
   735     TBool focusedAttachmentLabelIndexChanged = EFalse;
       
   736 
       
   737     if ( aType == EEventKey )
       
   738         {
       
   739         if ( aKeyEvent.iCode == EKeyUpArrow )
       
   740             {
       
   741             if ( iFocusedLabelIndex > 0 )
       
   742                 {
       
   743                 iFocusedLabelIndex -= 1;
       
   744                 focusedAttachmentLabelIndexChanged = ETrue;
       
   745                 response = EKeyWasConsumed;
       
   746                 }
       
   747             }
       
   748         else if ( aKeyEvent.iCode == EKeyDownArrow )
       
   749             {
       
   750             if ( iFocusedLabelIndex < iAttachmentLabelCount - 1 )
       
   751                 {
       
   752                 iFocusedLabelIndex += 1;
       
   753                 focusedAttachmentLabelIndexChanged = ETrue;
       
   754                 response = EKeyWasConsumed;
       
   755                 }
       
   756             }
       
   757         else if ( aKeyEvent.iCode == EKeyBackspace ||
       
   758                   aKeyEvent.iCode == EKeyDelete )
       
   759             {
       
   760             iObserver->AttachmentRemoveL();
       
   761             response = EKeyWasConsumed;
       
   762             }
       
   763         else if ( aKeyEvent.iCode == EKeyEnter ||
       
   764                   aKeyEvent.iScanCode == EStdKeyEnter ||
       
   765                   aKeyEvent.iCode == EKeyOK ||
       
   766                   aKeyEvent.iScanCode == EStdKeyDevice3 )
       
   767             {
       
   768             iObserver->AttachmentOpenL();
       
   769             response = EKeyWasConsumed;
       
   770             }
       
   771         }
       
   772 
       
   773     if ( focusedAttachmentLabelIndexChanged )
       
   774         {
       
   775         // only redraw if focused attachment label changed
       
   776         for ( TInt i = 0; i < iAttachmentLabelCount; i++ )
       
   777             {
       
   778             iAttachmentLabels[i]->SetFocus( i == iFocusedLabelIndex );
       
   779             }
       
   780 
       
   781         UpdateColors();
       
   782         DrawDeferred();
       
   783         }
       
   784 
       
   785     return response;
   712     }
   786     }
   713 
   787 
   714 // -----------------------------------------------------------------------------
   788 // -----------------------------------------------------------------------------
   715 // CNcsAttachmentField::CreateIcons()
   789 // CNcsAttachmentField::CreateIcons()
   716 // -----------------------------------------------------------------------------
   790 // -----------------------------------------------------------------------------