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