emailuis/emailui/src/ncsaddressinputfield.cpp
branchRCL_3
changeset 80 726fba06891a
parent 73 c8382f7b54ef
equal deleted inserted replaced
73:c8382f7b54ef 80:726fba06891a
    31 #include <AknsDrawUtils.h>
    31 #include <AknsDrawUtils.h>
    32 #include <sysutil.h>
    32 #include <sysutil.h>
    33 #include <AknUtils.h>
    33 #include <AknUtils.h>
    34 #include <FreestyleEmailUi.rsg>
    34 #include <FreestyleEmailUi.rsg>
    35 #include <aknphysics.h>
    35 #include <aknphysics.h>
    36 #include <centralrepository.h>
       
    37 
    36 
    38 #include "FreestyleEmailUiAppui.h"
    37 #include "FreestyleEmailUiAppui.h"
    39 #include "FreestyleEmailUiLayoutData.h"
    38 #include "FreestyleEmailUiLayoutData.h"
    40 #include "FreestyleEmailUiLayoutHandler.h"
    39 #include "FreestyleEmailUiLayoutHandler.h"
    41 #include "ncsaddressinputfield.h"
    40 #include "ncsaddressinputfield.h"
    43 #include "ncsaifeditor.h"
    42 #include "ncsaifeditor.h"
    44 #include "ncsfieldsizeobserver.h"
    43 #include "ncsfieldsizeobserver.h"
    45 #include "ncsutility.h"
    44 #include "ncsutility.h"
    46 #include "ncsheadercontainer.h"
    45 #include "ncsheadercontainer.h"
    47 #include "txtrich.h"
    46 #include "txtrich.h"
    48 #include "freestyleemailcenrepkeys.h"
       
    49 
    47 
    50 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    51 // constructor
    49 // constructor
    52 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    53 //
    51 //
    90 // CNcsAddressInputField::ConstructL()
    88 // CNcsAddressInputField::ConstructL()
    91 // Symbian 2nd phase constructor can leave.
    89 // Symbian 2nd phase constructor can leave.
    92 // -----------------------------------------------------------------------------
    90 // -----------------------------------------------------------------------------
    93 //
    91 //
    94 void CNcsAddressInputField::ConstructL( TInt aLabelTextId )
    92 void CNcsAddressInputField::ConstructL( TInt aLabelTextId )
    95     {
    93 	{
    96     FUNC_LOG;
    94     FUNC_LOG;
    97     // Create label
    95 	// Create label
    98     //Load the label string
    96 	//Load the label string
    99     HBufC* aTextBuf = StringLoader::LoadLC( aLabelTextId );
    97 	HBufC* aTextBuf = StringLoader::LoadLC( aLabelTextId );
   100 
    98 
   101     TPtrC captionText = aTextBuf ? aTextBuf->Des() : TPtrC();
    99 	TPtrC captionText = aTextBuf ? aTextBuf->Des() : TPtrC();
   102     CreateControlsL( captionText );
   100 	CreateControlsL( captionText );
   103 
   101 	
   104     iTextEditor = new ( ELeave ) CNcsAifEditor( iSizeObserver, captionText );
   102 	iTextEditor = new ( ELeave ) CNcsAifEditor( iSizeObserver,
       
   103                                                 captionText );
   105     // iTextEditor is not completely constructed until in SetContainerWindowL()
   104     // iTextEditor is not completely constructed until in SetContainerWindowL()
   106 
   105 
   107     iTextEditor->SetPopupList(iAddressPopupList);
   106 	iTextEditor->SetPopupList(iAddressPopupList);
   108 
   107 
   109     CleanupStack::PopAndDestroy( aTextBuf );
   108 	CleanupStack::PopAndDestroy( aTextBuf );
   110     }
   109 	}
   111 
   110 
   112 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   113 // Destructor
   112 // Destructor
   114 // ---------------------------------------------------------------------------
   113 // ---------------------------------------------------------------------------
   115 //
   114 //
   117     {
   116     {
   118     FUNC_LOG;
   117     FUNC_LOG;
   119     delete iTextEditor;
   118     delete iTextEditor;
   120     delete iButton;
   119     delete iButton;
   121     delete iLabel;
   120     delete iLabel;
   122     }
   121 // <cmail> Platform layout change
   123 
   122     /*if ( iFont )
       
   123         {
       
   124         ControlEnv()->ScreenDevice()->ReleaseFont( iFont );
       
   125         iFont = NULL;
       
   126         }</cmail>*/
       
   127     }
       
   128 
       
   129 //<cmail>
   124 // -----------------------------------------------------------------------------
   130 // -----------------------------------------------------------------------------
   125 // CNcsHeaderContainer::CreateControlsL()
   131 // CNcsHeaderContainer::CreateControlsL()
   126 // -----------------------------------------------------------------------------
   132 // -----------------------------------------------------------------------------
   127 //
   133 //
   128 void CNcsAddressInputField::CreateControlsL( const TDesC& aControlText )
   134 void CNcsAddressInputField::CreateControlsL( const TDesC& aControlText )
   146         iLabel = new ( ELeave ) CNcsLabel( *this, NULL );
   152         iLabel = new ( ELeave ) CNcsLabel( *this, NULL );
   147         iLabel->SetTextL( aControlText );
   153         iLabel->SetTextL( aControlText );
   148         iLabel->SetBrushStyle(CWindowGc::ENullBrush);
   154         iLabel->SetBrushStyle(CWindowGc::ENullBrush);
   149         }
   155         }
   150     }
   156     }
       
   157 //</cmail>
   151 
   158 
   152 // ---------------------------------------------------------------------------
   159 // ---------------------------------------------------------------------------
   153 // SetContainerWindow
   160 // SetContainerWindow
   154 // Don't construct the window dependent elements until the window
   161 // Don't construct the window dependent elements until the window
   155 // container is set
   162 // container is set
   158 void CNcsAddressInputField::SetContainerWindowL( const CCoeControl& aContainer )
   165 void CNcsAddressInputField::SetContainerWindowL( const CCoeControl& aContainer )
   159     {
   166     {
   160     FUNC_LOG;
   167     FUNC_LOG;
   161     CCoeControl::SetContainerWindowL(aContainer);
   168     CCoeControl::SetContainerWindowL(aContainer);
   162 
   169 
   163     InitComponentArrayL();
   170 	InitComponentArrayL();
   164     // Check if we need to construct the components
   171 	// Check if we need to construct the components
   165     if (Components().Count() == 2) return;
   172 	if (Components().Count() == 2) return;
   166 
   173 
   167     // Load the controls into the compoent array
   174 	// Load the controls into the compoent array
   168     CCoeControlArray& controls = Components();
   175 	CCoeControlArray& controls = Components();
   169     controls.SetControlsOwnedExternally(ETrue);
   176 	controls.SetControlsOwnedExternally(ETrue);
   170     //<cmail>
   177 	//<cmail>
   171     if( iButton )
   178 	if( iButton )
   172         {
   179 	    {
   173         controls.AppendLC( iButton );
   180 	    controls.AppendLC( iButton );
   174         CleanupStack::Pop( iButton );
   181 	    CleanupStack::Pop( iButton );
   175         }
   182 	    }
   176     else
   183 	else
   177         {
   184 	    {
   178         controls.AppendLC( iLabel );
   185 	    controls.AppendLC( iLabel );
   179         CleanupStack::Pop( iLabel );
   186 	    CleanupStack::Pop( iLabel );
   180         }
   187 	    }
   181 
   188 	//</cmail>
   182     controls.AppendLC(iTextEditor);
   189 	controls.AppendLC(iTextEditor);
   183     CleanupStack::Pop(iTextEditor);
   190     CleanupStack::Pop(iTextEditor);
   184 
   191 
   185     // Setup the text editor
   192 // <cmail>
   186     iTextEditor->ConstructL( &aContainer, KMaxAddressFieldLines, 0 );
   193 
       
   194 	// Setup the text editor
       
   195 	iTextEditor->ConstructL( &aContainer, KMaxAddressFieldLines, 0 );
       
   196 // </cmail>
   187 
   197 
   188     iTextEditor->SetBorder( TGulBorder::ENone );
   198     iTextEditor->SetBorder( TGulBorder::ENone );
   189     iTextEditor->SetAknEditorInputMode( EAknEditorTextInputMode );
   199 	iTextEditor->SetAknEditorInputMode( EAknEditorTextInputMode );
   190     iTextEditor->SetAknEditorFlags( EAknEditorFlagNoT9 | EAknEditorFlagUseSCTNumericCharmap );
   200 	iTextEditor->SetAknEditorFlags( EAknEditorFlagNoT9 | EAknEditorFlagUseSCTNumericCharmap );
   191 
   201 	iTextEditor->SetAknEditorCurrentCase( EAknEditorLowerCase );
   192      CRepository* repository = NULL;
   202 	iTextEditor->CreateScrollBarFrameL()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff );
   193      TRAPD( err, repository = CRepository::NewL( KFreestyleEmailCenRep ) );
       
   194      if ( !err )
       
   195          {
       
   196          TInt value( 0 );
       
   197          err = repository->Get( KEmailFeatureSplitScreen, value );
       
   198          if( !err && value )
       
   199             {
       
   200              iTextEditor->SetAknEditorFlags( iTextEditor->AknEditorFlags() | EAknEditorFlagEnablePartialScreen );
       
   201              }
       
   202          }
       
   203     delete repository;
       
   204     repository = NULL;
       
   205 
       
   206     iTextEditor->SetAknEditorCurrentCase( EAknEditorLowerCase );
       
   207     iTextEditor->CreateScrollBarFrameL()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff );
       
   208     iTextEditor->SetEdwinSizeObserver( this );
   203     iTextEditor->SetEdwinSizeObserver( this );
   209     iTextEditor->SetupEditorL();
   204     iTextEditor->SetupEditorL();
   210 
   205 
   211     // Setup the label
   206     // Setup the label
   212     UpdateFontSize();
   207     UpdateFontSize();
   252 // CNcsAddressInputField::SizeChanged()
   247 // CNcsAddressInputField::SizeChanged()
   253 // set size
   248 // set size
   254 // -----------------------------------------------------------------------------
   249 // -----------------------------------------------------------------------------
   255 //
   250 //
   256 void CNcsAddressInputField::SizeChanged()
   251 void CNcsAddressInputField::SizeChanged()
   257     {
   252 	{
   258     FUNC_LOG;
   253     FUNC_LOG;
   259 
   254 
   260     TRect rect = Rect();
   255    	TRect rect = Rect();
   261 
   256  
   262     if( AknLayoutUtils::PenEnabled() )
   257    	if( AknLayoutUtils::PenEnabled() )
   263         {
   258    	    {
   264         LayoutTouch();
   259    	    LayoutTouch();
   265         }
   260    	    }
   266     else
   261    	  else
   267         {
   262    	    {
   268         LayoutNonTouch();
   263    	    LayoutNonTouch();
   269         }
   264    	    }
   270 
   265 
   271     // This needs to be bidi as in mirrored layout 
   266     // This needs to be bidi as in mirrored layout 
   272     // writing language left to right can be set. 
   267     // writing language left to right can be set. 
   273     // Need to set here as layout sets it also to left or right.
   268     // Need to set here as layout sets it also to left or right.
   274     iTextEditor->SetAlignment( EAknEditorAlignBidi );
   269     iTextEditor->SetAlignment( EAknEditorAlignBidi );
   275 
   270    	    
   276     UpdateFontSize();
   271     UpdateFontSize();
   277 
   272     
   278     if (iTextEditor->ScrollBarFrame())
   273     if (iTextEditor->ScrollBarFrame())
   279         {
   274         {
   280         TRect rc = iTextEditor->Rect();
   275         TRect rc = iTextEditor->Rect();
   281         if (AknLayoutUtils::LayoutMirrored())
   276         if (AknLayoutUtils::LayoutMirrored())
   282             {
   277             {
   286             {
   281             {
   287             rc.iBr.iX -= iTextEditor->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EVertical);
   282             rc.iBr.iX -= iTextEditor->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EVertical);
   288             }
   283             }
   289         iTextEditor->SetRect(rc);
   284         iTextEditor->SetRect(rc);
   290         }
   285         }
   291 
   286     
   292     PositionChanged();
   287     PositionChanged();
   293     }
   288 	}
   294 
   289 
   295 // -----------------------------------------------------------------------------
   290 // -----------------------------------------------------------------------------
   296 // CNcsHeaderContainer::PositionChanged()
   291 // CNcsHeaderContainer::PositionChanged()
   297 // set size
   292 // set size
   298 // -----------------------------------------------------------------------------
   293 // -----------------------------------------------------------------------------
   299 void CNcsAddressInputField::PositionChanged()
   294 void CNcsAddressInputField::PositionChanged()
   300     {
   295 	{
   301     FUNC_LOG;
   296     FUNC_LOG;
   302 
   297     
   303     // keep the button in view as long as possible
   298     // keep the button in view as long as possible
   304     if( iButton && iParentControl->IsVisible() )
   299     if( iButton && iParentControl->IsVisible() )
   305         {
   300     	{
   306         const TRect rect( Rect() );
   301 		const TRect rect( Rect() );
   307         const TRect buttonRect( iButton->Rect() );
   302 		const TRect buttonRect( iButton->Rect() );
   308 
   303 		
   309         TInt newButtonPos( iOriginalButtonPos.iY - iOriginalFieldPos.iY );
   304 		TInt newButtonPos( iOriginalButtonPos.iY - iOriginalFieldPos.iY );
   310 
   305 		
   311         if( rect.iTl.iY < 0 && newButtonPos + buttonRect.Height() < rect.iBr.iY )
   306 		if( rect.iTl.iY < 0 && newButtonPos + buttonRect.Height() < rect.iBr.iY )
   312             {
   307 			{
   313             iButton->SetPosition( TPoint(iOriginalButtonPos.iX, newButtonPos) );
   308 			iButton->SetPosition( TPoint(iOriginalButtonPos.iX, newButtonPos) );
   314             }
   309 			}
   315         else
   310 		else
   316             {
   311 			{
   317             iButton->SetPosition( TPoint(iOriginalButtonPos.iX, newButtonPos + rect.iTl.iY) );
   312 			iButton->SetPosition( TPoint(iOriginalButtonPos.iX, newButtonPos + rect.iTl.iY) );
   318             }
   313 			}
   319         }
   314     	}
   320     }
   315 	}
   321 
   316 
       
   317 //<cmail>
   322 // -----------------------------------------------------------------------------
   318 // -----------------------------------------------------------------------------
   323 // CNcsAddressInputField::LayoutNonTouch()
   319 // CNcsAddressInputField::LayoutNonTouch()
   324 // 
   320 // 
   325 // -----------------------------------------------------------------------------
   321 // -----------------------------------------------------------------------------
   326 //
   322 //
   346     iOriginalFieldPos = rect.iTl;
   342     iOriginalFieldPos = rect.iTl;
   347     iOriginalButtonPos = iButton->Position();    
   343     iOriginalButtonPos = iButton->Position();    
   348 
   344 
   349     iTextEditor->UpdateCustomDrawer();
   345     iTextEditor->UpdateCustomDrawer();
   350     }
   346     }
   351 
   347     
   352 // -----------------------------------------------------------------------------
   348 // -----------------------------------------------------------------------------
   353 // CNcsAddressInputField::HandlePointerEventL()
   349 // CNcsAddressInputField::HandlePointerEventL()
   354 // Handles pointer events
   350 // Handles pointer events
   355 // -----------------------------------------------------------------------------
   351 // -----------------------------------------------------------------------------
   356 //
   352 //
   357 void CNcsAddressInputField::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   353 void CNcsAddressInputField::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   358     {
   354     {
   359     FUNC_LOG;
   355 	FUNC_LOG;
   360     CCoeControl::HandlePointerEventL( aPointerEvent );
   356     iTextEditor->HandlePointerEventL(aPointerEvent);
   361 
   357     if( iButton )
   362     switch ( aPointerEvent.iType )
   358         {
   363         {
   359         iButton->HandlePointerEventL( aPointerEvent );
   364         case TPointerEvent::EButton1Down:
   360         }
   365             {
   361     
       
   362     switch( aPointerEvent.iType )
       
   363     	{
       
   364     	case TPointerEvent::EButton1Down:
       
   365     		{
   366             // Save start position so that it can be used in
   366             // Save start position so that it can be used in
   367             // drag/scrolling calculations
   367             // drag/scrolling calculations
   368             iStartPosition = aPointerEvent.iPosition;
   368             iStartPosition = aPointerEvent.iPosition;
   369             iIsDraggingStarted = EFalse;
   369             iIsDraggingStarted = EFalse;
   370             break;
   370             break;
   371             }
   371     		}
   372 
   372     		
   373         case TPointerEvent::EDrag:
   373     	case TPointerEvent::EDrag:
   374             {
   374     		{
   375             if ( !iIsDraggingStarted && iPhysics )
   375             if ( !iIsDraggingStarted && iPhysics )
   376                 {
   376                 {
   377                 TInt drag( iStartPosition.iY - aPointerEvent.iPosition.iY );
   377                 TInt drag( iStartPosition.iY - aPointerEvent.iPosition.iY );
   378                 if ( Abs( drag ) > iPhysics->DragThreshold() )
   378                 if ( Abs( drag ) > iPhysics->DragThreshold() )
   379                     {
   379                     {
   380                     iIsDraggingStarted = ETrue;
   380 					iIsDraggingStarted = ETrue;
   381                     }
   381                     }
   382                 }
   382                 }
   383             break;
   383             break;
   384             }
   384     		}
   385         }
   385     	}
   386     }
   386     }
   387 
   387 
   388 // -----------------------------------------------------------------------------
   388 // -----------------------------------------------------------------------------
   389 // CNcsAddressInputField::HandleControlEventL()
   389 // CNcsAddressInputField::HandleControlEventL()
   390 // 
   390 // 
   398             {
   398             {
   399             iParentControl->OpenPhonebookL();
   399             iParentControl->OpenPhonebookL();
   400             }
   400             }
   401         }
   401         }
   402     }
   402     }
       
   403 //</cmail>
   403 
   404 
   404 // -----------------------------------------------------------------------------
   405 // -----------------------------------------------------------------------------
   405 // CNcsAddressInputField::OfferKeyEventL()
   406 // CNcsAddressInputField::OfferKeyEventL()
   406 // Handles key events
   407 // Handles key events
   407 // -----------------------------------------------------------------------------
   408 // -----------------------------------------------------------------------------
   408 //
   409 //
   409 TKeyResponse 
   410 TKeyResponse 
   410 CNcsAddressInputField::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
   411 CNcsAddressInputField::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
   411     {
   412 	{
   412     FUNC_LOG;
   413     FUNC_LOG;
   413     TKeyResponse ret( EKeyWasNotConsumed );
   414 	TKeyResponse ret( EKeyWasNotConsumed );
   414 
   415 
   415     if( aKeyEvent.iCode == EKeyOK )
   416 	if( aKeyEvent.iCode == EKeyOK )
   416         {
   417 		{
   417         iTextEditor->SetCursorPosL( iTextEditor->TextLength(), EFalse );
   418 		iTextEditor->SetCursorPosL( iTextEditor->TextLength(), EFalse );
   418         iTextEditor->UpdateAddressListAllL();
   419 		iTextEditor->UpdateAddressListAllL();
   419         }
   420 		}
   420     else
   421 	else
   421         {
   422 		{
   422         ret = iTextEditor->OfferKeyEventL( aKeyEvent, aType );
   423 		ret = iTextEditor->OfferKeyEventL( aKeyEvent, aType );
   423         }
   424 		}
   424 
   425 
   425     return ret;
   426 	return ret;
   426     }
   427 	}
   427 
   428 
   428 // -----------------------------------------------------------------------------
   429 // -----------------------------------------------------------------------------
   429 // CNcsAddressInputField::FocusChanged()
   430 // CNcsAddressInputField::FocusChanged()
   430 // -----------------------------------------------------------------------------
   431 // -----------------------------------------------------------------------------
   431 //
   432 //
   434     FUNC_LOG;
   435     FUNC_LOG;
   435 	if ( IsFocused() )
   436 	if ( IsFocused() )
   436 		{
   437 		{
   437 		iTextEditor->SetFocus( ETrue, aDrawNow );
   438 		iTextEditor->SetFocus( ETrue, aDrawNow );
   438         //TRAP_IGNORE( iTextEditor->SetCursorPosL( iTextEditor->TextLength(), EFalse ) );
   439         //TRAP_IGNORE( iTextEditor->SetCursorPosL( iTextEditor->TextLength(), EFalse ) );
       
   440 
       
   441         // make sure that control is visible on screen
       
   442 		if ( Rect().iTl.iY < 0 )
       
   443 			{
       
   444 			TPoint pt = TPoint( 0, 0 );
       
   445 			Reposition( pt,Rect().Width() );
       
   446             iSizeObserver->UpdateFieldPosition( this );
       
   447 			}
       
   448 		else
       
   449 		    {
       
   450 		    TPoint pos = PositionRelativeToScreen();
       
   451 		    pos.iY += Size().iHeight;
       
   452     	    CWsScreenDevice* screenDev = ControlEnv()->ScreenDevice();
       
   453     	    TPixelsAndRotation pix;
       
   454     		screenDev->GetDefaultScreenSizeAndRotation( pix );
       
   455     		const TInt h = pix.iPixelSize.iHeight;
       
   456     		if ( pos.iY >= h - h / 3 )
       
   457     		    {
       
   458     			TPoint pt = TPoint( 0, h / 3 );
       
   459     			Reposition( pt,Rect().Width() );
       
   460                 iSizeObserver->UpdateFieldPosition( this );
       
   461     		    }
       
   462 		    }
       
   463 
   439         if ( iParentControl )
   464         if ( iParentControl )
   440             {
   465             {
   441             TRAP_IGNORE( iParentControl->SetMskL() );
   466             TRAP_IGNORE( iParentControl->SetMskL() );
   442             }
   467             }
   443 		}
   468 		}
   726 
   751 
   727 // -----------------------------------------------------------------------------
   752 // -----------------------------------------------------------------------------
   728 // CNcsAddressInputField::GetLineRectL()
   753 // CNcsAddressInputField::GetLineRectL()
   729 // -----------------------------------------------------------------------------
   754 // -----------------------------------------------------------------------------
   730 //
   755 //
   731 void CNcsAddressInputField::GetLineRect( TRect& aLineRect ) const
   756 void CNcsAddressInputField::GetLineRectL( TRect& aLineRect ) const
   732 	{
   757 	{
   733     FUNC_LOG;
   758     FUNC_LOG;
   734     return iTextEditor->GetLineRect( aLineRect );
   759     return iTextEditor->GetLineRectL( aLineRect );
   735 	}
   760 	}
   736 
   761 
   737 // -----------------------------------------------------------------------------
   762 // -----------------------------------------------------------------------------
   738 // CNcsAddressInputField::SetMaxLabelLength()
   763 // CNcsAddressInputField::SetMaxLabelLength()
   739 // -----------------------------------------------------------------------------
   764 // -----------------------------------------------------------------------------