textinput/peninputarc/src/peninputlayoutcontrol/peninputlayoutmultilineicfeditor.cpp
changeset 0 eb1f2e154e89
child 3 f5a1e66df979
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include <peninputcmd.h>
       
    18 #include <coemain.h>
       
    19 #include <txtrich.h>
       
    20 #include <frmtlay.h>
       
    21 #include <frmtview.h>
       
    22 #include <eiksbfrm.h>
       
    23 #include <aknappui.h>
       
    24 #include <AknUtils.h>
       
    25 #include <w32std.h>
       
    26 #include <frmtlay.h>
       
    27 #include <AknsDrawUtils.h>
       
    28 #include <avkon.hrh>
       
    29 #include <AknBidiTextUtils.h>
       
    30 #include <bidivisual.h>
       
    31 #include <AknFepGlobalEnums.h>
       
    32 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    33 #include <tagmalayoutandsource.h>
       
    34 #endif
       
    35 #include "peninputlayoutcursor.h"
       
    36 #include "peninputlayoutbubblectrl.h"
       
    37 
       
    38 #include "peninputlayoutmultilineicf.h"
       
    39 #include "peninputlayout.h"
       
    40 
       
    41 #include "peninputlayoutmicfcustomdraw.h"
       
    42 #include "peninputlayoutmicfnomatchesinline.h"
       
    43 #include "AknPhoneNumberInlineTextSource.h"
       
    44 #include "AknEdwinFormExtendedInterfaceProvider.h"
       
    45 #include "AknCompositeInlineTextSource.h"
       
    46 #include "peninputlayoutsmiley.h"
       
    47 
       
    48 #include <gdi.h>
       
    49 const TInt KParagraphSeperator = 0x2029;
       
    50 const TInt KSecretUpdateTimer = 1000000; // 1s
       
    51 const TInt KSecretInstantShowTimer = 100000; // 100ms
       
    52 
       
    53 const TUint16 KSegment = 0x0020;
       
    54 // separator between prompt text and normal text,
       
    55 // should use localized character soon
       
    56 const TUint16 KSeparator = 0x003a;
       
    57 const TUint16 KSeparatorcn = 0xff1a;
       
    58 _LIT(KLineSeparator, "\n");
       
    59 const TInt KStar = '*';
       
    60 
       
    61 const TInt KMaxMfneDataLen = 30;
       
    62 // Message bubble position adjust
       
    63 const TInt KMsgBubblePosAdjustValueX = 3;
       
    64 const TInt KMsgBubblePosAdjustValueY = 2;
       
    65 const TInt KPromptAdjustLen = 5;
       
    66 EXPORT_C CFepLayoutMultiLineIcfEditor* CFepLayoutMultiLineIcfEditor::NewL(TRect aRect,
       
    67                                                               CFepUiLayout* aUiLayout,
       
    68                                                               TInt aControlId,
       
    69                                                               TInt aFontHeight,
       
    70                                                               TInt aMaxFontHeight,
       
    71                                                               const CFont* aFont)
       
    72     {
       
    73     CFepLayoutMultiLineIcfEditor* self = new (ELeave) CFepLayoutMultiLineIcfEditor(aRect, 
       
    74                                                                        aUiLayout, 
       
    75                                                                        aControlId);
       
    76     CleanupStack::PushL(self);
       
    77     self->BaseConstructL(aFontHeight, aMaxFontHeight, aFont);
       
    78     CleanupStack::Pop(self);
       
    79 
       
    80     return self;
       
    81     }
       
    82 
       
    83 CFepLayoutMultiLineIcfEditor::CFepLayoutMultiLineIcfEditor(TRect aRect,
       
    84                                                CFepUiLayout* aUiLayout,
       
    85                                                TInt aControlId)
       
    86     :CFepUiBaseCtrl(aRect,aUiLayout,aControlId),
       
    87      iTextSelectionOn(ETrue),
       
    88      iTextInited(EFalse),
       
    89      iPntDownOnInline(EFalse),
       
    90      iPreInlineStartPos(0),
       
    91      iPreInlineEndPos(0),
       
    92      iPreAutoStartPos(0),
       
    93      iPreAutoEndPos(0),
       
    94      iPreTextSelStartPos(0),
       
    95      iPreTextSelEndPos(0),
       
    96      iSkinIdSet(EFalse),
       
    97      iNoMatchState(EFalse),
       
    98      iLineSeparator( EFalse ),
       
    99      iLeadingEdge(EFalse),
       
   100      iState(CFepLayoutMultiLineIcf::EIcfNormal)
       
   101     {
       
   102     SetControlType(ECtrlEditAreaBase);
       
   103     iCursorVisible = ETrue;
       
   104     iCursorSelVisible = ETrue;
       
   105     
       
   106 #ifdef RD_TACTILE_FEEDBACK     
       
   107     //register the area for tactile feedback
       
   108     if(aUiLayout)
       
   109     	{
       
   110     	//Advanced Tactile feedback REQ417-47932
       
   111     	SetTactileFeedbackType(ETouchFeedbackSensitiveInput);    	
       
   112     	aUiLayout->RegisterFeedbackArea(reinterpret_cast<TInt>(this),aRect,ETouchFeedbackSensitiveInput);
       
   113     	}
       
   114 #endif //RD_TACTILE_FEEDBACK     
       
   115     }
       
   116 
       
   117 CFepLayoutMultiLineIcfEditor::~CFepLayoutMultiLineIcfEditor()
       
   118     {
       
   119     delete iCustomDraw;
       
   120     delete iTextWrapper;
       
   121     delete iTextView; // text view
       
   122     delete iLayout; // text layout
       
   123     delete iRichText; // contained text object
       
   124     delete iCharFormatLayer; // char format layer
       
   125     delete iParaFormatLayer; // para format layer
       
   126     if (iWin)
       
   127         {
       
   128         iWin->Close();
       
   129         delete iWin;
       
   130         }
       
   131     //delete iContentCtrl;
       
   132 
       
   133     iOverlappedCtrlList.Close();
       
   134     iOverLapRects.Close();
       
   135 	iOldMfneText.Close();
       
   136 
       
   137     if (iSecretTextTimer)
       
   138         iSecretTextTimer->Cancel();
       
   139     delete iSecretTextTimer;
       
   140     delete iInitPromptText;
       
   141     delete iPromptText;
       
   142     
       
   143     delete iMfneIcfData;
       
   144     //delete iCtrl;
       
   145     if(iFormExtendedInterfaceProvider)
       
   146         {
       
   147         delete iFormExtendedInterfaceProvider;
       
   148         iFormExtendedInterfaceProvider = NULL;
       
   149         }
       
   150     
       
   151     delete iSmileyManager;
       
   152     }
       
   153 
       
   154 void CFepLayoutMultiLineIcfEditor::InitTextLayoutL()
       
   155     {
       
   156 	iParaFormatLayer=CParaFormatLayer::NewL();
       
   157 	iCharFormatLayer=CCharFormatLayer::NewL();
       
   158 
       
   159 	iRichText = CRichText::NewL(iParaFormatLayer, iCharFormatLayer);
       
   160 
       
   161 	iViewRect = Rect();
       
   162 	iLayout = CTextLayout::NewL(iRichText, iViewRect.Width());
       
   163     //iLayout->SetAmountToFormat( CTextLayout::EFFormatBand );
       
   164     //TInt x = 0;
       
   165     //iLayout->SetFontHeightIncreaseFactor(10);
       
   166     //iLayout->SetMinimumLineDescent( x );
       
   167     //CContentControl* ctrl = new(ELeave) CContentControl;
       
   168     //iWndControl = ctrl;    
       
   169     //ctrl->ConstructL();    
       
   170     
       
   171     iWin = new(ELeave) RWindow(iCoeEnv->WsSession());
       
   172     iWin->Construct(iCoeEnv->RootWin(),reinterpret_cast<TInt>(this));
       
   173     //iWin = ctrl->GetWindow();
       
   174     //TBool b = iWin->IsRedrawStoreEnabled();
       
   175     iWin->EnableRedrawStore(EFalse);
       
   176     iWin->SetVisible(EFalse);
       
   177 
       
   178     // another method to avoid crash caused by HandleRedrawEvent 
       
   179     // when (screen resolution changed)
       
   180     //iCtrl = new (ELeave) CCoeControl;
       
   181     //iCtrl->SetContainerWindowL(*iWin);    
       
   182     //iWin->Construct(iCoeEnv->RootWin(),reinterpret_cast<TInt>(iCtrl));
       
   183     //ctrl->SetExtent(iViewRect.iTl, iViewRect.Size());
       
   184 
       
   185 	iTextView = CTextView::NewL(iLayout, 
       
   186 	                            iViewRect,
       
   187                         		BitmapDevice(),
       
   188                         		iCoeEnv->ScreenDevice(),
       
   189                         		iWin,
       
   190                         		&iCoeEnv->RootWin(),
       
   191                         		&iCoeEnv->WsSession()); 
       
   192                        		
       
   193     iTextView->SetCursorVisibilityL(TCursor::EFCursorInvisible, TCursor::EFCursorInvisible);
       
   194 
       
   195     if (!iCustomDraw)
       
   196         {
       
   197         iCustomDraw = new (ELeave) CFepLayoutMIcfCustomDraw(this);
       
   198         iLayout->SetCustomDraw(iCustomDraw);
       
   199         }
       
   200 
       
   201     if ( !iTextWrapper )
       
   202         {
       
   203         iTextWrapper = new (ELeave) CFepLayoutMIcfCustomWrap();
       
   204         iLayout->SetCustomWrap( iTextWrapper );
       
   205         }
       
   206         
       
   207     //SetTextMarginL(30);
       
   208     iTextView->DisableFlickerFreeRedraw();
       
   209     iTextView->FormatTextL(); 
       
   210     iMfneIcfData = HBufC::NewL( KMaxMfneDataLen );
       
   211     }
       
   212 
       
   213 void CFepLayoutMultiLineIcfEditor::SetTextAlignmentL(TInt aAlignment, TInt aLanguage)
       
   214     {
       
   215     CParaFormat* paraFormat = CParaFormat::NewL();
       
   216     CleanupStack::PushL(paraFormat);
       
   217     TParaFormatMask paraFormatMask;
       
   218     
       
   219     paraFormat->iLanguage = ELangEnglish;
       
   220     if ( aAlignment == EAknEditorAlignNone )
       
   221         {
       
   222         // fix: Prompt text in ICF moves on dimmed VITU-T window after rotating screen.
       
   223         aAlignment = iAlignment;
       
   224         }
       
   225     switch (aAlignment)
       
   226         {
       
   227         case EAknEditorAlignLeft: 
       
   228             paraFormat->iHorizontalAlignment = CParaFormat::EAbsoluteLeftAlign;
       
   229             iTextAlign = CGraphicsContext::ELeft;
       
   230             break;
       
   231         case EAknEditorAlignRight:
       
   232             paraFormat->iHorizontalAlignment = CParaFormat::EAbsoluteRightAlign;
       
   233             iTextAlign = CGraphicsContext::ERight;
       
   234             break;
       
   235         case EAknEditorAlignCenter:
       
   236             paraFormat->iHorizontalAlignment = CParaFormat::ECenterAlign;
       
   237             iTextAlign = CGraphicsContext::ECenter;
       
   238             break;
       
   239         case EAknEditorAlignBidi:
       
   240             {
       
   241             paraFormat->iHorizontalAlignment = CParaFormat::ELeftAlign;
       
   242             paraFormat->iLanguage = aLanguage;
       
   243             iTextAlign = CGraphicsContext::ELeft;
       
   244             break;
       
   245             }
       
   246         default:
       
   247             paraFormat->iHorizontalAlignment = CParaFormat::ELeftAlign;
       
   248             iTextAlign = CGraphicsContext::ELeft;
       
   249             break;
       
   250         }
       
   251 
       
   252     paraFormatMask.SetAttrib(EAttParaLanguage);
       
   253     paraFormatMask.SetAttrib(EAttAlignment);
       
   254     
       
   255     iRichText->ApplyParaFormatL(paraFormat,
       
   256                                 paraFormatMask,
       
   257                                 0,
       
   258                                 iPromptTextLen);
       
   259 
       
   260     iRichText->ApplyParaFormatL(paraFormat,
       
   261                                 paraFormatMask,
       
   262                                 iPromptTextLen,
       
   263                                 iRichText->DocumentLength() - iPromptTextLen);
       
   264 	iTextView->FormatTextL();                            
       
   265     
       
   266     CleanupStack::PopAndDestroy(paraFormat);
       
   267     
       
   268     iAlignment = aAlignment;
       
   269     }
       
   270 
       
   271 void CFepLayoutMultiLineIcfEditor::BaseConstructL(TInt aFontHeight, 
       
   272                                             TInt aMaxFontHeight, 
       
   273                                             const CFont* aFont)
       
   274     {
       
   275     CFepUiBaseCtrl::BaseConstructL();
       
   276 
       
   277     iCoeEnv = CCoeEnv::Static();
       
   278     //iMaxFontHeight = aMaxFontHeight;
       
   279     //iFontHeight = aFontHeight;
       
   280     //iFont = aFont;
       
   281     InitTextLayoutL();
       
   282     iInsertionPoint = UiLayout()->CreateCursor();
       
   283     iInsertionPoint->SetOwner(this);
       
   284     SetFontL(aFontHeight, aMaxFontHeight, aFont);
       
   285 
       
   286     iSecretTextTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
   287 
       
   288     SetAutoCompleteTextColor(KRgbGray);
       
   289     
       
   290     
       
   291     //EnableTextSelection(EFalse);
       
   292     
       
   293     iSmileyManager = CPeninputSmileyManager::NewL();
       
   294     }
       
   295 
       
   296 void CFepLayoutMultiLineIcfEditor::SetTextColorL(const TRgb aColor)
       
   297     {
       
   298     iCharFormatMask.ClearAttrib( EAttFontUnderline );
       
   299     
       
   300     iTextColor = aColor;
       
   301     iCharFormat.iFontPresentation.iTextColor = aColor;
       
   302     iCharFormatMask.SetAttrib(EAttColor);
       
   303 
       
   304     iRichText->ApplyCharFormatL(iCharFormat, iCharFormatMask, 0, iRichText->DocumentLength());
       
   305     //iRichText->SetInsertCharFormatL(iCharFormat, iCharFormatMask, iRichText->DocumentLength());    
       
   306     }
       
   307 
       
   308 void CFepLayoutMultiLineIcfEditor::SetTextSelColorL(const TRgb aColor)
       
   309     {
       
   310     iCharFormatMask.ClearAttrib( EAttFontUnderline );
       
   311     
       
   312     iTextSelColor = aColor;
       
   313     iCharFormat.iFontPresentation.iHighlightColor = aColor;
       
   314     iCharFormatMask.SetAttrib(EAttFontHighlightColor);
       
   315 
       
   316     iRichText->ApplyCharFormatL(iCharFormat, iCharFormatMask, 0, iRichText->DocumentLength());
       
   317     //iRichText->SetInsertCharFormatL(iCharFormat, iCharFormatMask, iRichText->DocumentLength());    
       
   318     }
       
   319 
       
   320 void CFepLayoutMultiLineIcfEditor::SetAutoCompleteTextColor(const TRgb aColor)
       
   321     {
       
   322     iTextAutoColor = aColor;
       
   323     }
       
   324 
       
   325 TBool CFepLayoutMultiLineIcfEditor::IsFocused()
       
   326     {
       
   327     return iHasFocus;
       
   328     }
       
   329 
       
   330 void CFepLayoutMultiLineIcfEditor::DeletePromptTextL()
       
   331     {
       
   332     // delete original prompt text
       
   333     if (iPromptTextLen > 0)
       
   334         {
       
   335         iRichText->DeleteL(0, iPromptTextLen);
       
   336         iTextView->HandleInsertDeleteL(TCursorSelection(0, 0),
       
   337                                        iPromptTextLen);
       
   338         }
       
   339     }
       
   340 
       
   341 void CFepLayoutMultiLineIcfEditor::RecalculatePosByNewPromptTextL(const TDesC& aNewPromptText)
       
   342     {
       
   343     // recalculate cursor pos
       
   344     AdjustSelectionL(TCursorSelection(iTextView->Selection().iCursorPos + aNewPromptText.Length() - iPromptTextLen,
       
   345                      iTextView->Selection().iAnchorPos + aNewPromptText.Length() - iPromptTextLen));
       
   346 
       
   347     // set new cursor position    
       
   348 
       
   349     iPreInlineStartPos += (aNewPromptText.Length() - iPromptTextLen);
       
   350     iPreInlineEndPos += (aNewPromptText.Length() - iPromptTextLen);
       
   351     iPreAutoStartPos += (aNewPromptText.Length() - iPromptTextLen);
       
   352     iPreAutoEndPos += (aNewPromptText.Length() - iPromptTextLen);
       
   353     iPreTextSelStartPos += (aNewPromptText.Length() - iPromptTextLen);
       
   354     iPreTextSelEndPos += (aNewPromptText.Length() - iPromptTextLen);
       
   355 
       
   356     }
       
   357 
       
   358 const HBufC* CFepLayoutMultiLineIcfEditor::PromptText()
       
   359 	{
       
   360 	return iPromptText;	
       
   361 	}
       
   362 	
       
   363 void CFepLayoutMultiLineIcfEditor::SetPromptTextL(const TDesC& aPromptText, TBool aCleanContent)
       
   364     {
       
   365     
       
   366     if ( aCleanContent )
       
   367     	{
       
   368     	//clean all the content (include prompt text) on the ICF
       
   369         TInt length = iRichText->DocumentLength();
       
   370         iRichText->DeleteL( 0,  length);
       
   371         iTextView->HandleInsertDeleteL(TCursorSelection(0, 0), length);
       
   372     	iTextView->SetSelectionL( TCursorSelection(0, 0) );
       
   373     	iCursorSel = TCursorSelection(0, 0);
       
   374         iNoMatchState = EFalse;
       
   375     	}
       
   376     else 
       
   377         {
       
   378         /*if ( ( ( !iInitPromptText && aPromptText.Length() == 0 ) )|| 
       
   379             ( iInitPromptText && *iInitPromptText == aPromptText && 
       
   380             iPromptText && TextWidth(*iPromptText) <= iViewRect.Width()) )
       
   381     	    {
       
   382     	    //prompt text has not been change then need not to be reset
       
   383     	    //but iLineSeparator may be changed, need reset prompt text
       
   384     	    return;
       
   385             }*/
       
   386         //prompt text need to be reset and not clean the content
       
   387         iRichText->DeleteL( 0,  iPromptTextLen );
       
   388         iTextView->HandleInsertDeleteL(TCursorSelection(0, 0), iPromptTextLen );
       
   389         }
       
   390     
       
   391     TBool bPromptTextChange = EFalse;
       
   392     if ( !iInitPromptText || *iInitPromptText != aPromptText )
       
   393         {
       
   394         //prompt text has been changed
       
   395         delete iInitPromptText;
       
   396         iInitPromptText = NULL;
       
   397         if ( aPromptText.Length() > 0 )
       
   398             {
       
   399         	iInitPromptText = HBufC::NewL( aPromptText.Length() );
       
   400         	iInitPromptText->Des().Copy( aPromptText );
       
   401             }
       
   402         bPromptTextChange = ETrue;
       
   403         }
       
   404 
       
   405     delete iPromptText;
       
   406     iPromptText = NULL;
       
   407 
       
   408     if (aPromptText == KNullDesC)
       
   409         {
       
   410         RecalculatePosByNewPromptTextL(KNullDesC);
       
   411         iPromptTextLen = 0;
       
   412         if( bPromptTextChange )
       
   413         	{
       
   414         	UpdateArea( Rect(), EFalse );
       
   415         	} 
       
   416         return;
       
   417         }
       
   418 
       
   419     // The extra length is separators between prompt text and normal text
       
   420     TInt prompttextLen;
       
   421     
       
   422     if ( !iLineSeparator )
       
   423         {
       
   424         iLineSeparator = ( TBidiText::TextDirectionality( aPromptText ) == TBidiText:: ERightToLeft );
       
   425         }
       
   426         
       
   427     iLineSeparator ? 
       
   428                prompttextLen = aPromptText.Length() + TBidiLogicalToVisual::KMinCharAvailable + 3 :
       
   429                prompttextLen = aPromptText.Length() + TBidiLogicalToVisual::KMinCharAvailable + 2;
       
   430     iPromptText = HBufC::NewL(prompttextLen);
       
   431     TPtr text = iPromptText->Des();
       
   432 
       
   433     TBuf<1> ptr0;
       
   434     ptr0.Append( KEllipsis );
       
   435 
       
   436     TPtrC ptr1(&KSegment, 1);
       
   437     TPtrC ptr2(&KSeparator, 1);
       
   438     
       
   439     TInt separatorLen = TextWidth(ptr1) + TextWidth(ptr2) + TextWidth(ptr0);
       
   440     TInt textWidth = TextWidth(aPromptText) + separatorLen;
       
   441     TBool ret = EFalse;
       
   442     
       
   443     if (textWidth >= iViewRect.Width() )
       
   444         {
       
   445         ret = ETrue;
       
   446         AknBidiTextUtils::ConvertToVisualAndClip(aPromptText,
       
   447                                                  text,
       
   448                                                  *iFont,
       
   449                                                  iViewRect.Width() - separatorLen - KPromptAdjustLen,
       
   450                                                  iViewRect.Width() - separatorLen - KPromptAdjustLen,
       
   451                                                  AknBidiTextUtils::EImplicit,
       
   452                                                  0xFFFF);
       
   453                                                  
       
   454         TInt charNums = iFont->TextCount( text, iViewRect.Width() - separatorLen );
       
   455         text = aPromptText.Left( charNums );
       
   456         }
       
   457     else
       
   458         {
       
   459         text.Copy(aPromptText);
       
   460         }
       
   461     
       
   462 	for ( ;(text.Length() > 0 && text.LocateReverse(KSegment) == text.Length()-1 ); )
       
   463 	    {
       
   464 		text.Delete( text.Length()-1, 1 );
       
   465 	    }
       
   466 		
       
   467     if ((text.LocateReverse(KSeparator) != text.Length() - 1) && 
       
   468         (text.LocateReverse(KSeparatorcn) != text.Length() - 1))
       
   469         {
       
   470         // if sent prompt text already include separator, then no need to 
       
   471         // append it again
       
   472         if ( ret )
       
   473             {
       
   474             text.Append( ptr0 );
       
   475             }
       
   476         text.Append(ptr2);
       
   477         }
       
   478     else if ( ret )
       
   479         {
       
   480         text.Insert( text.Length()-1, ptr0 );
       
   481         }        
       
   482 
       
   483     text.Append(ptr1); // segment between prompt text and official text
       
   484     textWidth = TextWidth(text);
       
   485     
       
   486     iRichText->InsertL(0, text);
       
   487     iTextView->HandleInsertDeleteL(TCursorSelection(0, text.Length()),
       
   488                                    0);
       
   489     
       
   490     if (iLineSeparator)
       
   491         {
       
   492     	iRichText->InsertL(text.Length(), CEditableText::EParagraphDelimiter);
       
   493     	iTextView->HandleInsertDeleteL(TCursorSelection(text.Length(), text.Length()+1), 0);
       
   494     	text.Append(KLineSeparator);
       
   495         }
       
   496 
       
   497     RecalculatePosByNewPromptTextL(text);
       
   498 
       
   499     iPromptTextLen = text.Length();
       
   500     // apply format to prompt text and normal text
       
   501     SetPromptTextFormatL(iPromptTextLen);
       
   502     CalcPromptTextRectL();
       
   503     if( bPromptTextChange )
       
   504     	{
       
   505     	UpdateArea(Rect(),EFalse);
       
   506     	} 
       
   507     }
       
   508 
       
   509 void CFepLayoutMultiLineIcfEditor::AdjustIcfDataForPromptText(TFepInputContextFieldData& aData)
       
   510     {
       
   511     if (iPromptTextLen == 0)
       
   512         return;
       
   513     aData.iCurSel.iCursorPos += iPromptTextLen;
       
   514     aData.iCurSel.iAnchorPos += iPromptTextLen;
       
   515     
       
   516     aData.iStartPos += iPromptTextLen;
       
   517     }
       
   518 
       
   519 void CFepLayoutMultiLineIcfEditor::SetMfneTextL(const TFepInputContextFieldData& aData)
       
   520     {
       
   521     TFepInputContextFieldData icfdata = aData;
       
   522     
       
   523     TPtr ptr = iMfneIcfData->Des();
       
   524     
       
   525     switch (icfdata.iCmd)
       
   526         {
       
   527         case EPeninputICFInitial:
       
   528             {
       
   529             if ( iRichText->DocumentLength() > iPromptTextLen )
       
   530                 {
       
   531                 TInt delLen = iRichText->DocumentLength() - iPromptTextLen;
       
   532                 iRichText->DeleteL(iPromptTextLen, delLen );
       
   533                 iTextView->HandleInsertDeleteL(TCursorSelection(iPromptTextLen, iPromptTextLen), 
       
   534                                                delLen);
       
   535                 }
       
   536             ptr.Copy(icfdata.iText);
       
   537             }
       
   538             break;
       
   539         case EPeninputICFReplace:
       
   540             {
       
   541             ptr.Replace( icfdata.iStartPos, icfdata.iLength, icfdata.iText);
       
   542             }
       
   543             break;
       
   544         case EPeninputICFDelete:
       
   545             {
       
   546             ptr.Delete(icfdata.iStartPos, icfdata.iLength);
       
   547             }
       
   548             break;
       
   549         case EPeninputICFSetCurSel:
       
   550             {
       
   551             
       
   552             }
       
   553             break;
       
   554         default:
       
   555             {
       
   556             return;
       
   557             }
       
   558         }
       
   559         
       
   560     if ( iSynCursor || iOldMfneText != ptr ||
       
   561          iCursorSel.iCursorPos - iPromptTextLen != icfdata.iCurSel.iCursorPos ||
       
   562          iCursorSel.iAnchorPos - iPromptTextLen != icfdata.iCurSel.iAnchorPos )
       
   563         {
       
   564         iCursorSel.iCursorPos = icfdata.iCurSel.iCursorPos + iPromptTextLen;
       
   565         iCursorSel.iAnchorPos = icfdata.iCurSel.iAnchorPos + iPromptTextLen;
       
   566         DrawMfneText();
       
   567         iSynCursor = EFalse;
       
   568         iOldMfneText.CreateL(ptr);
       
   569         }
       
   570         
       
   571     iInsertionPoint->SetVisible( EFalse ); 
       
   572 
       
   573     SetCursorSelVisibility( icfdata.iCursorSelVisible );    
       
   574 
       
   575     SetCursorVisible(aData.iCursorVisibility);
       
   576      
       
   577     UpdateArea(Rect(),EFalse); 
       
   578     
       
   579     return;
       
   580     }
       
   581     
       
   582 void CFepLayoutMultiLineIcfEditor::SetTextL(const TFepInputContextFieldData& aData)
       
   583     {
       
   584     if ( aData.iCmd == EPeninputICFSetCurSel && 
       
   585          aData.iFlag == EFepICFDataInlineNoMatch && iNoMatchState )
       
   586         {
       
   587         return;
       
   588         }
       
   589         
       
   590     if ( !iSycnFepData )
       
   591         {
       
   592         iSycnFepData = ETrue;
       
   593         }
       
   594     else if ( this == UiLayout()->RootControl()->CtrlCapPointer() )
       
   595     	{
       
   596     	return;
       
   597     	}
       
   598     	
       
   599     TBool bScroll = EFalse;	
       
   600     TFepInputContextFieldData icfdata = aData;
       
   601     AdjustIcfDataForPromptText(icfdata);
       
   602     
       
   603 	if (/*(iPreLanguageID == ELangUrdu || iPreLanguageID == ELangArabic || 
       
   604          iPreLanguageID == ELangFarsi || iPreLanguageID == ELangHebrew) &&*/
       
   605          icfdata.iFlag & EFepICFDataDirectionMFNE )
       
   606         {
       
   607         iRtlMfneEditor = ETrue;
       
   608         iInsertionPoint->SetHeight( iFontHeight + iLineSpace );
       
   609         SetMfneTextL( aData );
       
   610         return;
       
   611         }    
       
   612 
       
   613     //iInsertionPoint->SetOn( EFalse );
       
   614     	
       
   615     iLeadingEdge = icfdata.iLeadingEdge;
       
   616 
       
   617     if (icfdata.iFlag != EFepICFDataInlineNoMatch && iNoMatchState)
       
   618         {
       
   619         UpdateNoMatchTextL(iPreInlineEndPos, KNullDesC, EFalse);
       
   620         }
       
   621 
       
   622     switch (icfdata.iCmd)
       
   623         {
       
   624         case EPeninputICFInitial:
       
   625             {
       
   626             iRtlMfneEditor = EFalse;
       
   627             if ( !iLayout->CustomDraw() )
       
   628                 {
       
   629                 iLayout->SetCustomDraw(iCustomDraw);    
       
   630                 }
       
   631             
       
   632             TInt delLen = iRichText->DocumentLength() - iPromptTextLen;
       
   633             iRichText->DeleteL(iPromptTextLen, delLen );
       
   634             iTextView->HandleInsertDeleteL(TCursorSelection(iPromptTextLen, iPromptTextLen), 
       
   635                                            delLen);
       
   636             iRichText->InsertL(iRichText->DocumentLength(), icfdata.iText);
       
   637             
       
   638             iTextView->HandleInsertDeleteL(
       
   639                          TCursorSelection(iPromptTextLen + icfdata.iText.Length(), iPromptTextLen),
       
   640                          0);
       
   641             iTextInited = ETrue;
       
   642             bScroll = ETrue;
       
   643             //UpdateArea( Rect() );
       
   644             
       
   645             iPreInlineStartPos = iPromptTextLen;
       
   646             iPreInlineEndPos = iRichText->DocumentLength();
       
   647             
       
   648             if ( icfdata.iCursorVisibility )
       
   649                 {
       
   650                 iInsertionPoint->DelayCursorShown();     
       
   651                 }
       
   652             
       
   653             AdjustSelectionL( icfdata.iCurSel );
       
   654             RecalcualteTextPositionL();
       
   655             SetMsgBubbleRect();
       
   656             Draw();
       
   657             }
       
   658             break;
       
   659         case EPeninputICFReplace:
       
   660             {
       
   661             if (( icfdata.iStartPos < 0 ) || 
       
   662                 ( icfdata.iStartPos > iRichText->DocumentLength()))
       
   663                 {
       
   664                 return;
       
   665                 }
       
   666             
       
   667             if (icfdata.iLength > 0)
       
   668                 {
       
   669 				TInt count = iRichText->DocumentLength();
       
   670 				if ( count < 1 )
       
   671 				    {
       
   672 				    return;
       
   673 				    }
       
   674                   
       
   675                 iRichText->DeleteL(icfdata.iStartPos, icfdata.iLength);
       
   676                 iTextView->HandleInsertDeleteL(
       
   677                                             TCursorSelection(icfdata.iStartPos, icfdata.iStartPos),
       
   678                                             icfdata.iLength);
       
   679                 }
       
   680 
       
   681             iRichText->InsertL(icfdata.iStartPos, icfdata.iText);
       
   682             iTextView->HandleInsertDeleteL(
       
   683                  TCursorSelection( icfdata.iStartPos + icfdata.iText.Length(), icfdata.iStartPos ),
       
   684                  0);
       
   685             bScroll = ETrue;
       
   686             if ( icfdata.iCursorVisibility )
       
   687                 {
       
   688                 iInsertionPoint->DelayCursorShown();     
       
   689                 }
       
   690             }
       
   691             break;
       
   692         case EPeninputICFDelete:
       
   693             {
       
   694             if (( icfdata.iStartPos < 0 ) || 
       
   695                 ( icfdata.iStartPos > iRichText->DocumentLength()))
       
   696                 {
       
   697                 return;
       
   698                 }
       
   699             
       
   700             iRichText->DeleteL(icfdata.iStartPos, icfdata.iLength);
       
   701             iTextView->HandleInsertDeleteL(TCursorSelection(icfdata.iStartPos, icfdata.iStartPos), 
       
   702                                            icfdata.iLength);
       
   703             bScroll = ETrue;
       
   704             }
       
   705             break;
       
   706         case EPeninputICFSetCurSel:
       
   707             {
       
   708             bScroll = ETrue;
       
   709             }
       
   710             break;
       
   711         default:
       
   712             {
       
   713             return;
       
   714             }
       
   715         }
       
   716         
       
   717     UpdateTextL(icfdata);    
       
   718     
       
   719     // Need to set selection visible before set selection for textview
       
   720     SetCursorSelVisibility( icfdata.iCursorSelVisible );    
       
   721     
       
   722     SetSelectionL(icfdata.iCurSel);
       
   723     ResetViewHeightL();
       
   724     
       
   725     if (icfdata.iMidPos == 0)
       
   726         {
       
   727         // inline state
       
   728         // if there is paragraph separater inside icfdata's iText, then should not
       
   729         // set to inline state
       
   730         if (icfdata.iText.Locate(KParagraphSeperator) == KErrNotFound)
       
   731             {
       
   732             SetAutoCompleteStateL(EFalse);
       
   733             icfdata.iFlag == EFepICFDataInlineNoMatch ? 
       
   734                                                       SetInlineStateL(ETrue, icfdata.iStartPos, 
       
   735                                                                       icfdata.iCurSel.iCursorPos, 
       
   736                                                                       ETrue, icfdata.iText) :
       
   737                                                       SetInlineStateL(ETrue, icfdata.iStartPos, 
       
   738                                                                       icfdata.iCurSel.iCursorPos);
       
   739             }
       
   740         }
       
   741     else if (icfdata.iMidPos > 0)
       
   742         {
       
   743         // auto complete state
       
   744         // Q: does insertion point need to be shown when auto complete?
       
   745         // on the assumption that insertion point do not shown
       
   746         SetAutoCompleteStateL( ETrue, icfdata.iStartPos, 
       
   747                                icfdata.iStartPos + icfdata.iText.Length() - icfdata.iMidPos, 
       
   748                                icfdata.iCurSel.iCursorPos );
       
   749         }
       
   750     else
       
   751         {
       
   752         // icfdata.iMidPos < 0, normal state
       
   753         //
       
   754         SetInlineStateL(EFalse, icfdata.iStartPos, icfdata.iCurSel.iCursorPos);
       
   755         SetAutoCompleteStateL(EFalse);
       
   756         
       
   757         }    
       
   758 
       
   759     // after inline adjust, cusor position may be updated
       
   760     if( bScroll )
       
   761         {
       
   762         TryDisplayMaxTextL(iCursorSel.iCursorPos);
       
   763         }
       
   764     
       
   765     iTextView->DrawL(iViewRect);    
       
   766     //if(iMsgBubble)    
       
   767 //        iMsgBubble->Draw();   
       
   768 
       
   769     iInsertionPoint->SetVisible( EFalse ); 
       
   770 
       
   771     SetCursorVisible(icfdata.iCursorVisibility);
       
   772     
       
   773     if (AbleToDraw())
       
   774         {
       
   775         UpdateAreaImmed(Rect(),EFalse);    
       
   776         }
       
   777     }
       
   778 
       
   779 void CFepLayoutMultiLineIcfEditor::SetSelectionL(TCursorSelection aCurSel)
       
   780     {
       
   781     if ( !IsTextPosValid(aCurSel.LowerPos()) || 
       
   782          !IsTextPosValid(aCurSel.HigherPos()) )
       
   783         {
       
   784         return;
       
   785         }
       
   786     
       
   787     AdjustSelectionL( aCurSel );
       
   788     
       
   789     if ( iLayout->FirstLineInBand() != 0 && iLineMaxCount > 1 &&
       
   790         iPromptTextLen > 0 && aCurSel.iCursorPos == iPromptTextLen )
       
   791     	{
       
   792         iTextView->SetViewLineAtTopL( 1 );	
       
   793     	}
       
   794         
       
   795     RecalcualteTextPositionL();
       
   796     
       
   797     if ( iCursorSel.Length() > 0 )
       
   798         {
       
   799         if ( iMsgBubble->IsShowing() && HighlightOverlapWithBubble( iMsgBubble->Rect() )  ) 
       
   800             {
       
   801             HideBubbleTemp();    
       
   802             }
       
   803         else if ( iHideBubbleTemp && !HighlightOverlapWithBubble( iMsgBubble->Rect() ) )
       
   804             {
       
   805             iMsgBubble->Popup( iMsgBubble->Rect() );
       
   806             iHideBubbleTemp = EFalse;
       
   807             }
       
   808         }
       
   809     else
       
   810         {
       
   811         SetMsgBubbleRect();
       
   812         SetInfoBubbleRect();
       
   813         }    
       
   814     }
       
   815 
       
   816 TBool CFepLayoutMultiLineIcfEditor::HighlightOverlapWithBubble( const TRect& aRect )
       
   817     {
       
   818     TBool ret = EFalse;
       
   819     
       
   820     if ( iCursorSel.Length() == 0 || iCursorSel.iCursorPos < 0 ||
       
   821          !iViewRect.Intersects( aRect ) )
       
   822         {
       
   823         return ret;
       
   824         }
       
   825   
       
   826     if ( aRect.Intersects( iInsertionPoint->CursorRect() ) )
       
   827         {
       
   828         ret = ETrue;
       
   829         return ret;
       
   830         }
       
   831         
       
   832     TRect rect = iViewRect;
       
   833     rect.Intersection( aRect );
       
   834     
       
   835     TPoint leftTopPoint = TPoint( rect.iTl.iX, rect.iTl.iY );
       
   836     TPoint leftBottomPoint = TPoint( rect.iTl.iX, rect.iBr.iY );
       
   837     TPoint rightTopPoint = TPoint( rect.iBr.iX, rect.iTl.iY );
       
   838     TPoint rightBottomPoint = TPoint( rect.iBr.iX, rect.iBr.iY );
       
   839     
       
   840     TInt leftTopIndex = 0;
       
   841     TRAP_IGNORE(leftTopIndex = iTextView->XyPosToDocPosL( leftTopPoint ));
       
   842     TInt leftBottomIndex = 0;
       
   843     TRAP_IGNORE(leftBottomIndex = iTextView->XyPosToDocPosL( leftBottomPoint ));
       
   844     TInt rightTopIndex = 0;
       
   845     TRAP_IGNORE(rightTopIndex = iTextView->XyPosToDocPosL( rightTopPoint ));
       
   846     TInt rightBottomIndex = 0;
       
   847     TRAP_IGNORE(rightBottomIndex = iTextView->XyPosToDocPosL( rightBottomPoint ));
       
   848     
       
   849     ret =  ( leftTopIndex > iCursorSel.LowerPos() && leftTopIndex < iCursorSel.HigherPos() ) || 
       
   850          ( leftBottomIndex > iCursorSel.LowerPos() && leftBottomIndex < iCursorSel.HigherPos() ) ||
       
   851          ( rightTopIndex > iCursorSel.LowerPos() && rightTopIndex < iCursorSel.HigherPos() ) ||
       
   852          ( rightBottomIndex > iCursorSel.LowerPos() && rightBottomIndex < iCursorSel.HigherPos() );
       
   853 
       
   854     return ret;
       
   855     }
       
   856     
       
   857 void CFepLayoutMultiLineIcfEditor::HideBubbleTemp()
       
   858     {
       
   859     HideBubble();
       
   860     iHideBubbleTemp = ETrue;
       
   861     }
       
   862     
       
   863 // for secret editor
       
   864 void CFepLayoutMultiLineIcfEditor::UpdateTextL(const TFepInputContextFieldData& aData)
       
   865     {
       
   866     if (!iTextIsSecret)
       
   867         {
       
   868         return;
       
   869         }
       
   870 
       
   871     switch (aData.iCmd)
       
   872         {
       
   873         case EPeninputICFInitial:
       
   874             {
       
   875             TPtrC icfPtr = aData.iText;
       
   876             TPtr buf( const_cast<TUint16*>( icfPtr.Ptr() ), icfPtr.Length(), icfPtr.Length() );
       
   877             buf.Fill( KStar );
       
   878             
       
   879             TInt delLen = iRichText->DocumentLength() - iPromptTextLen;
       
   880             iRichText->DeleteL(iPromptTextLen, delLen);
       
   881             iTextView->HandleInsertDeleteL( TCursorSelection( iPromptTextLen, iPromptTextLen ), 
       
   882                                             delLen );
       
   883             iRichText->InsertL(iRichText->DocumentLength(), buf);
       
   884             iTextView->HandleInsertDeleteL
       
   885                 ( TCursorSelection( iRichText->DocumentLength(), iPromptTextLen ), 0 );
       
   886             }
       
   887             break;
       
   888         case EPeninputICFReplace:
       
   889             {                    
       
   890             if (iSecretTextTimer->IsActive())
       
   891                 {
       
   892                 iSecretTextTimer->Cancel();
       
   893 
       
   894                 if (aData.iStartPos >= iPromptTextLen + 1)
       
   895                     {
       
   896                     TBuf<1> buf;
       
   897                     buf.Append( '*' );
       
   898                     for( TInt i = 0; i < aData.iText.Length(); i++ )
       
   899                         {
       
   900                         iRichText->DeleteL( aData.iStartPos - 1 + i, 1 );
       
   901                         iTextView->HandleInsertDeleteL(
       
   902                                         TCursorSelection( aData.iStartPos - 1 + i, 
       
   903                                                           aData.iStartPos - 1 + i ), 1 );
       
   904                         
       
   905                         iRichText->InsertL( aData.iStartPos - 1 + i, buf );
       
   906                         iTextView->HandleInsertDeleteL(
       
   907                              TCursorSelection( aData.iStartPos - 1 + i, 
       
   908                                                aData.iStartPos - 1 + i + buf.Length() ), 0 );
       
   909                         }
       
   910                     }
       
   911                 }
       
   912             else if( aData.iText.Length() > 1 )
       
   913                 {
       
   914                 TBuf<1> buf;
       
   915                 buf.Append( '*' );
       
   916                 for( TInt i = 0; i < aData.iText.Length() - 2; i++ )
       
   917                     {
       
   918                     iRichText->DeleteL( aData.iStartPos + i, 1 );
       
   919                     iTextView->HandleInsertDeleteL(
       
   920                                     TCursorSelection( aData.iStartPos + i, 
       
   921                                                       aData.iStartPos + i ), 1 );
       
   922                         
       
   923                     iRichText->InsertL( aData.iStartPos + i, buf );
       
   924                     iTextView->HandleInsertDeleteL(
       
   925                                  TCursorSelection( aData.iStartPos + i, 
       
   926                                                    aData.iStartPos + i + buf.Length() ), 0 );
       
   927                     }
       
   928                 }
       
   929             iSecretTextTimer->Start(
       
   930                                  aData.iText.Length()>1?KSecretInstantShowTimer:KSecretUpdateTimer,
       
   931                                  KSecretUpdateTimer, TCallBack(UpdateSecretTextL, this));
       
   932             }
       
   933             break;
       
   934         case EPeninputICFSetCurSel:
       
   935         default:
       
   936             {
       
   937             break;
       
   938             }
       
   939         }
       
   940     }
       
   941 
       
   942 TInt CFepLayoutMultiLineIcfEditor::UpdateSecretTextL(TAny* aEditArea)
       
   943     {
       
   944     CFepLayoutMultiLineIcfEditor* editArea = static_cast<CFepLayoutMultiLineIcfEditor*>(aEditArea);
       
   945 
       
   946     if ( !editArea->iTextIsSecret )
       
   947         {
       
   948         editArea->iSecretTextTimer->Cancel();
       
   949         return KErrNone;
       
   950         }
       
   951     TPtrC icftext = editArea->iRichText->Read(editArea->iPromptTextLen, 
       
   952                                               editArea->iRichText->DocumentLength());
       
   953     TInt startPos = icftext.LocateReverse(KStar) + 1 + editArea->iPromptTextLen;
       
   954 
       
   955     TBuf<1> buf;
       
   956     buf.Append(KStar);
       
   957 
       
   958     TInt textlen = editArea->iRichText->DocumentLength();
       
   959 
       
   960     if (startPos < textlen)
       
   961         {
       
   962         editArea->iRichText->DeleteL(startPos, 1);
       
   963         editArea->iTextView->HandleInsertDeleteL(TCursorSelection(startPos, startPos), 1);
       
   964         editArea->iRichText->InsertL(startPos, buf);
       
   965         editArea->iTextView->HandleInsertDeleteL(TCursorSelection(startPos, startPos+buf.Length()),
       
   966                                                  0);
       
   967 
       
   968         if (startPos == textlen - 1)
       
   969             {
       
   970             editArea->iSecretTextTimer->Cancel();
       
   971             }
       
   972         }
       
   973     editArea->UpdateArea(editArea->Rect(),EFalse);
       
   974     return KErrNone;
       
   975     }
       
   976     
       
   977 void CFepLayoutMultiLineIcfEditor::UpdateSecretTextL()
       
   978     {
       
   979     if (!iTextIsSecret)
       
   980         {
       
   981         return;
       
   982         }
       
   983         
       
   984     if (iSecretTextTimer->IsActive())
       
   985         {
       
   986         iSecretTextTimer->Cancel();
       
   987         UpdateSecretTextL( this );
       
   988         }
       
   989     }
       
   990 
       
   991 void CFepLayoutMultiLineIcfEditor::SetDimmed(TBool aDimFlag)
       
   992     {
       
   993     iDimmed = aDimFlag;
       
   994     }
       
   995 
       
   996 void CFepLayoutMultiLineIcfEditor::SetFontL(TInt aFontHeight, 
       
   997                                             TInt aMaxFontHeight, 
       
   998                                             const CFont* aFont)
       
   999     {
       
  1000     TInt newHeightInPixel = iCoeEnv->ScreenDevice()->VerticalPixelsToTwips(aFontHeight);
       
  1001     TInt OldHeightInPixel = iCoeEnv->ScreenDevice()->VerticalPixelsToTwips(iFontHeight);
       
  1002     
       
  1003     if( newHeightInPixel == OldHeightInPixel )
       
  1004         {
       
  1005         return;
       
  1006         }
       
  1007     else
       
  1008         {
       
  1009         iFormatChange = ETrue;
       
  1010         }    
       
  1011     
       
  1012     iMaxFontHeight = aMaxFontHeight;
       
  1013     iFontHeight = aFontHeight;
       
  1014     iFont = aFont;
       
  1015     
       
  1016         
       
  1017     iCharFormatMask.ClearAttrib( EAttFontUnderline );
       
  1018     iCharFormatMask.SetAttrib(EAttFontHeight); 
       
  1019     iCharFormatMask.SetAttrib(EAttFontStrokeWeight); 
       
  1020     iCharFormatMask.SetAttrib(EAttFontTypeface);
       
  1021 
       
  1022     iCharFormat.iFontSpec.iHeight = iCoeEnv->ScreenDevice()->VerticalPixelsToTwips(iFontHeight);
       
  1023     iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
       
  1024     iCharFormat.iFontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
       
  1025 
       
  1026     iRichText->ApplyCharFormatL(iCharFormat, iCharFormatMask, 0, iRichText->DocumentLength());    
       
  1027     if( InlineStateOn() || AutoCompletionStateOn() )
       
  1028         {
       
  1029         iCharFormatMask.ClearAll();
       
  1030         iCharFormatMask.SetAttrib( EAttFontUnderline );        
       
  1031         iCharFormat.iFontPresentation.iUnderline = EUnderlineOn ;
       
  1032         iRichText->ApplyCharFormatL(iCharFormat, iCharFormatMask, iPreInlineStartPos, 
       
  1033                                     iPreInlineEndPos - iPreInlineStartPos);
       
  1034         }
       
  1035     
       
  1036     //iRichText->SetInsertCharFormatL(iCharFormat, iCharFormatMask, iRichText->DocumentLength() - iPromptTextLen);
       
  1037 
       
  1038     SetPromptTextFormatL( iPromptTextLen );
       
  1039     
       
  1040     iFormatChange = ETrue;
       
  1041     }
       
  1042 
       
  1043 void CFepLayoutMultiLineIcfEditor::SetFocus(TBool aFlag)
       
  1044     {
       
  1045     if(aFlag == iHasFocus)
       
  1046         return;
       
  1047 
       
  1048     if(aFlag) //gain focus
       
  1049         {
       
  1050         PrepareForFocusGain();
       
  1051         }
       
  1052     else
       
  1053         {
       
  1054         PrepareForFocusLoss();
       
  1055         }
       
  1056     }
       
  1057 
       
  1058 void CFepLayoutMultiLineIcfEditor::SetCursorVisible( TBool aCursorVisibleFlag )
       
  1059     {
       
  1060     if ( aCursorVisibleFlag != iCursorVisible )
       
  1061         {
       
  1062         iCursorVisible = aCursorVisibleFlag;
       
  1063         iInsertionPoint->SetOn( iCursorVisible && iHasFocus );
       
  1064         }            
       
  1065     }
       
  1066 
       
  1067 TBool CFepLayoutMultiLineIcfEditor::CursorVisible() const
       
  1068     {
       
  1069     return iCursorVisible;
       
  1070     }
       
  1071 
       
  1072 void CFepLayoutMultiLineIcfEditor::Draw()
       
  1073     {
       
  1074     //return;
       
  1075     if (!AbleToDraw())
       
  1076         {
       
  1077         return;
       
  1078         }
       
  1079 
       
  1080     CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc());
       
  1081 
       
  1082     DrawOpaqueMaskBackground();
       
  1083 	
       
  1084     if( BackgroundBmp() )
       
  1085 	    {
       
  1086 	    CFbsBitmap* bmp = BackgroundBmp();
       
  1087 	    if( Rect().Size() != bmp->SizeInPixels() )
       
  1088 	        {
       
  1089 	        AknIconUtils::SetSize(bmp, Rect().Size(), EAspectRatioNotPreserved);            
       
  1090 	        }
       
  1091 	    }
       
  1092     DrawBackground();
       
  1093 
       
  1094     if (iSkinIdSet)
       
  1095         {
       
  1096         gc->Clear(Rect());
       
  1097         TRect innerrect = Rect();
       
  1098   	    //innerrect.Shrink(4, 4);
       
  1099 
       
  1100         AknsDrawUtils::DrawFrame(AknsUtils::SkinInstance(), 
       
  1101    		                         *gc, 
       
  1102    		                         Rect(), 
       
  1103    		                         innerrect,
       
  1104    		                         BgImgSkinId(),
       
  1105    		                         KAknsIIDDefault);
       
  1106         }
       
  1107     
       
  1108     TRAP_IGNORE(iTextView->DrawL(iViewRect));
       
  1109     
       
  1110     if ( iRtlMfneEditor )
       
  1111         {
       
  1112         DrawMfneText();
       
  1113         }    
       
  1114     iInsertionPoint->SetVisible( EFalse );
       
  1115     }
       
  1116     
       
  1117 void CFepLayoutMultiLineIcfEditor::DrawMfneText()
       
  1118     {
       
  1119     if ( iCursorSel.LowerPos() < 0 || iCursorSel.HigherPos() < 0 )
       
  1120         {
       
  1121         return;
       
  1122         }
       
  1123         
       
  1124     CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc());
       
  1125     
       
  1126     TPoint tl = iViewRect.iTl;
       
  1127     TPoint br = TPoint( iViewRect.iBr.iX, iViewRect.iTl.iY+iFontHeight + iLineSpace );
       
  1128     
       
  1129     if ( iPromptTextLen > 0 )
       
  1130         {
       
  1131         tl.iY += iFontHeight + iLineSpace;
       
  1132         br.iY += iFontHeight + iLineSpace;
       
  1133         }
       
  1134     
       
  1135     if( iTextAlign == CGraphicsContext::ECenter )   
       
  1136         {
       
  1137         iOffset = (iViewRect.Width() - iFont->TextWidthInPixels(iMfneIcfData->Des()))/2;
       
  1138         }
       
  1139     else if ( iTextAlign == CGraphicsContext::ERight )
       
  1140         {
       
  1141         iOffset = iViewRect.Width() - iFont->TextWidthInPixels(iMfneIcfData->Des());
       
  1142         }
       
  1143     else
       
  1144     	{
       
  1145     	iOffset = 0;
       
  1146     	}
       
  1147     
       
  1148     TRect rect = TRect( tl, br );
       
  1149     
       
  1150     TPtrC ptr1 = iMfneIcfData->Des().Left(iCursorSel.iCursorPos-iPromptTextLen);
       
  1151     TInt width1 = iFont->TextWidthInPixels( ptr1 ); 
       
  1152     iInsertionPoint->SetPosition( TPoint(rect.iTl.iX + width1 + iOffset,rect.iTl.iY ));
       
  1153     
       
  1154     TInt baseLine = iFont->AscentInPixels()/2 + rect.Height()/2;
       
  1155     
       
  1156     TRect clipRect = 
       
  1157         TRect( TPoint(Rect().iTl.iX, rect.iTl.iY), TPoint( Rect().iBr.iX, rect.iBr.iY));    
       
  1158     
       
  1159     gc->SetClippingRect( clipRect );
       
  1160     gc->Clear( clipRect );
       
  1161     
       
  1162     DrawOpaqueMaskBackground( clipRect );
       
  1163     DrawBackground( clipRect );
       
  1164 
       
  1165     if (iSkinIdSet)
       
  1166         {
       
  1167    		AknsDrawUtils::DrawFrame(AknsUtils::SkinInstance(), 
       
  1168     	                         *gc, 
       
  1169     	                         Rect(), 
       
  1170     	                         Rect(),
       
  1171     	                         BgImgSkinId(),
       
  1172     	                         KAknsIIDDefault);
       
  1173    		                         
       
  1174         }
       
  1175 	
       
  1176     gc->UseFont( iFont );
       
  1177     gc->SetPenStyle(CGraphicsContext::ESolidPen);
       
  1178     gc->SetPenColor(iTextColor);
       
  1179     gc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
  1180     gc->DrawText(iMfneIcfData->Des(), rect, baseLine, iTextAlign );//printPos, 
       
  1181     gc->DiscardFont();
       
  1182     
       
  1183     if ( iCursorSel.Length() > 0 )
       
  1184         {
       
  1185         TRect selRect(rect);
       
  1186         
       
  1187         TPtrC ptr1 = iMfneIcfData->Des().Left(iCursorSel.LowerPos()-iPromptTextLen);
       
  1188         TPtrC ptr2 = iMfneIcfData->Des().Left(iCursorSel.HigherPos()-iPromptTextLen);
       
  1189         
       
  1190         TInt width1 = 
       
  1191             iFont->TextWidthInPixels( ptr1 );
       
  1192         TInt width2 = 
       
  1193             iFont->TextWidthInPixels( ptr2 );
       
  1194         
       
  1195         selRect.iTl.iX = iViewRect.iTl.iX + width1 + iOffset;
       
  1196         selRect.iBr.iX = iViewRect.iTl.iX + width2 + iOffset;
       
  1197         
       
  1198         // draw selection by inverting colors in the selected text rectancle
       
  1199         gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  1200         gc->SetPenStyle(CGraphicsContext::ENullPen);
       
  1201         gc->SetBrushColor(KRgbBlack);
       
  1202         gc->SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
       
  1203         gc->DrawRect(selRect);
       
  1204 
       
  1205         // restore normal draw mode
       
  1206         gc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
  1207         gc->SetBrushStyle(CGraphicsContext::ENullBrush); 
       
  1208         }
       
  1209     gc->CancelClipping();
       
  1210     }
       
  1211 
       
  1212 void CFepLayoutMultiLineIcfEditor::SetRectL(const TRect& aRect)
       
  1213     {
       
  1214     if ( aRect == TRect() )
       
  1215         {
       
  1216         return;
       
  1217         }
       
  1218     CFepUiBaseCtrl::SetRect(aRect);
       
  1219     
       
  1220     iTextView->SetViewRect( aRect );
       
  1221     iLayout->SetWrapWidth(aRect.Width());
       
  1222     //iWndControl->SetExtent(aRect.iTl, aRect.Size());
       
  1223     
       
  1224     iViewRect.iTl.iX = aRect.iTl.iX + iLeftMargin;
       
  1225     iViewRect.iBr.iX = aRect.iBr.iX - iRightMargin;
       
  1226 
       
  1227     iViewRect.iTl.iY = aRect.iTl.iY + iTopMargin ;
       
  1228     iViewRect.iBr.iY = aRect.iBr.iY - iBottomMargin;
       
  1229 
       
  1230     iMaxIcfEditorHeight = iViewRect.Height();
       
  1231     
       
  1232     // calculate the viewrect height
       
  1233     const TInt lineCount=iLayout->NumFormattedLines();
       
  1234     const TInt height=iLayout->FormattedHeightInPixels();
       
  1235     TInt lineHeight = (height+lineCount-1) / lineCount;
       
  1236     if ( lineHeight > iMaxIcfEditorHeight )
       
  1237         {
       
  1238         lineHeight = iMaxIcfEditorHeight;
       
  1239         }
       
  1240     if ( iFormatLineHeight != lineHeight )
       
  1241         {
       
  1242         iFormatLineHeight = lineHeight;
       
  1243         ApplyLineSpaceFormatL( iFormatLineHeight );
       
  1244         }
       
  1245     
       
  1246     iInsertionPoint->SetHeight( iFormatLineHeight );
       
  1247     
       
  1248     iLineMaxCount = iViewRect.Height()/iFormatLineHeight;
       
  1249     TInt viewHeight = iFormatLineHeight * iLineMaxCount;
       
  1250     
       
  1251     TInt margin =  iViewRect.Height() - viewHeight;
       
  1252     if ( iViewRect.iBr.iY - margin > Rect().iBr.iY )
       
  1253     	{
       
  1254     	iViewRect.iTl.iY += margin;
       
  1255     	}
       
  1256     else
       
  1257     	{
       
  1258     	iViewRect.iBr.iY -= margin;
       
  1259     	}
       
  1260     //iViewRect.iBr.iX -= 50;
       
  1261     iTextView->SetViewRect(iViewRect);
       
  1262     iLayout->SetWrapWidth(iViewRect.Width());
       
  1263 //    iWndControl->SetExtent(iViewRect.iTl, iViewRect.Size());
       
  1264     
       
  1265     if ( iCursorSel.iCursorPos >= 0 && !iRtlMfneEditor )
       
  1266         {
       
  1267         TPoint cursorPt;
       
  1268         TRAP_IGNORE(iTextView->DocPosToXyPosL(iCursorSel.iCursorPos, cursorPt));
       
  1269         CalculateCursorPos(cursorPt);
       
  1270         if ( !iViewRect.Contains( cursorPt ) )
       
  1271             {
       
  1272             TRAP_IGNORE(iTextView->SetViewLineAtTopL( iLineNumber+1 ));
       
  1273             }
       
  1274         }
       
  1275 
       
  1276     TRAP_IGNORE(RecalcualteTextPositionL());        
       
  1277     SetMsgBubbleRect();
       
  1278     }
       
  1279 
       
  1280 void CFepLayoutMultiLineIcfEditor::ResetViewHeightL()
       
  1281     {
       
  1282     const TInt height = iLayout->FormattedHeightInPixels();
       
  1283     const TInt lineCount=iLayout->NumFormattedLines();
       
  1284     if ( lineCount <= 0 )
       
  1285         {
       
  1286         return;
       
  1287         }
       
  1288         
       
  1289     TInt lineHeight = (height+lineCount-1) / lineCount;
       
  1290     
       
  1291     if ( iFormatLineHeight == lineHeight )
       
  1292         {
       
  1293         return;
       
  1294         }
       
  1295         
       
  1296     if ( lineHeight > iMaxIcfEditorHeight )
       
  1297         {
       
  1298         lineHeight = iMaxIcfEditorHeight;
       
  1299         }
       
  1300     if ( iFormatLineHeight != lineHeight )
       
  1301         {
       
  1302         iFormatLineHeight = lineHeight;
       
  1303         ApplyLineSpaceFormatL( iFormatLineHeight );
       
  1304         }
       
  1305             
       
  1306     iInsertionPoint->SetHeight( iFormatLineHeight );
       
  1307     
       
  1308     iViewRect.iTl.iY = Rect().iTl.iY + iTopMargin;
       
  1309     iViewRect.iBr.iY = Rect().iBr.iY - iBottomMargin;
       
  1310     
       
  1311     // calculate the max line count    
       
  1312     iLineMaxCount = iViewRect.Height()/iFormatLineHeight;
       
  1313     
       
  1314     // calculate the viewrect height
       
  1315     TInt viewHeight = iFormatLineHeight * iLineMaxCount;
       
  1316     
       
  1317     TInt margin =  iViewRect.Height() - viewHeight;
       
  1318     if ( iViewRect.iBr.iY - margin > Rect().iBr.iY )
       
  1319     	{
       
  1320     	iViewRect.iTl.iY += margin;
       
  1321     	}
       
  1322     else
       
  1323     	{
       
  1324     	iViewRect.iBr.iY -= margin;
       
  1325     	}
       
  1326     iTextView->SetViewRect(iViewRect);
       
  1327     }
       
  1328 
       
  1329 void CFepLayoutMultiLineIcfEditor::SetMsgBubbleRect()
       
  1330     {
       
  1331     if( ( !iMsgBubble->IsShowing() && !iHideBubbleTemp ) ||
       
  1332         iLineMaxCount < 1 || iCursorSel.iCursorPos < 0 )
       
  1333         {
       
  1334         return;
       
  1335         }
       
  1336     
       
  1337     TBool rtlLanguage = EFalse;
       
  1338     if ( iPreLanguageID == ELangUrdu || iPreLanguageID == ELangArabic || 
       
  1339          iPreLanguageID == ELangFarsi || iPreLanguageID == ELangHebrew )
       
  1340         {
       
  1341         rtlLanguage = ETrue;
       
  1342         }
       
  1343     TPoint startPoint;
       
  1344     TSize size = iMsgBubble->Rect().Size();
       
  1345     TRect rect1;
       
  1346     TRect rect2;
       
  1347     
       
  1348     if ( iLineMaxCount == 1 )
       
  1349         {
       
  1350         TRect rectLeft;
       
  1351         TRect rectRight;
       
  1352         
       
  1353 		// top left corner of ICF
       
  1354         startPoint = TPoint(Rect().iTl.iX, Rect().iTl.iY );
       
  1355         startPoint += TPoint( KMsgBubblePosAdjustValueX, KMsgBubblePosAdjustValueY );
       
  1356         rectLeft = TRect(startPoint,size);
       
  1357                     
       
  1358         // top right corner of ICF
       
  1359         startPoint = TPoint(Rect().iBr.iX-iMsgBubble->Rect().Width(), Rect().iTl.iY);
       
  1360         startPoint += TPoint( -KMsgBubblePosAdjustValueX, KMsgBubblePosAdjustValueY );
       
  1361         rectRight = TRect(startPoint,size);
       
  1362         
       
  1363         if ( rtlLanguage ) //rtl
       
  1364             {
       
  1365             rect1 = rectLeft;
       
  1366             rect2 = rectRight;
       
  1367             }
       
  1368         else
       
  1369             {
       
  1370             rect1 = rectRight;
       
  1371             rect2 = rectLeft;
       
  1372             }  
       
  1373         }
       
  1374     else
       
  1375         {
       
  1376         TRect rectTopLeft;
       
  1377         TRect rectTopRight;
       
  1378         TRect rectBottomLeft;
       
  1379         TRect rectBottomRight;
       
  1380         
       
  1381         // bottom left corner of ICF
       
  1382         startPoint = TPoint(Rect().iTl.iX, Rect().iBr.iY-iMsgBubble->Rect().Height() );
       
  1383         startPoint += TPoint( KMsgBubblePosAdjustValueX, -KMsgBubblePosAdjustValueY );
       
  1384         rectBottomLeft =  TRect(startPoint,size);
       
  1385        
       
  1386         // bottom right corner of ICF
       
  1387         startPoint = TPoint(Rect().iBr.iX-iMsgBubble->Rect().Width(), 
       
  1388                             Rect().iBr.iY-iMsgBubble->Rect().Height());
       
  1389         startPoint += TPoint( -KMsgBubblePosAdjustValueX, -KMsgBubblePosAdjustValueY );
       
  1390         rectBottomRight =  TRect(startPoint,size);
       
  1391         
       
  1392         // top left corner of ICF
       
  1393         startPoint = TPoint(Rect().iTl.iX, Rect().iTl.iY );
       
  1394         startPoint += TPoint( KMsgBubblePosAdjustValueX, KMsgBubblePosAdjustValueY );
       
  1395         rectTopLeft =  TRect(startPoint,size);
       
  1396         
       
  1397         // top right corner of ICF
       
  1398         startPoint = TPoint(Rect().iBr.iX-iMsgBubble->Rect().Width(), Rect().iTl.iY);
       
  1399         startPoint += TPoint( -KMsgBubblePosAdjustValueX, KMsgBubblePosAdjustValueY );
       
  1400         rectTopRight =  TRect(startPoint,size);
       
  1401         
       
  1402         TBool firstLine =  iLayout->FirstLineInBand() == iLineNumber ;
       
  1403             
       
  1404         if ( rtlLanguage ) //rtl
       
  1405             {
       
  1406             rect1 = firstLine ? rectBottomLeft : rectTopLeft;
       
  1407             rect2 = firstLine ? rectTopLeft : rectBottomLeft;
       
  1408             }
       
  1409         else
       
  1410             {
       
  1411             rect1 = firstLine ? rectBottomRight : rectTopRight;
       
  1412             rect2 = firstLine ? rectTopRight : rectBottomRight;
       
  1413             }
       
  1414         }
       
  1415 
       
  1416     TBool rect1Shown = !rect1.Intersects( iInsertionPoint->CursorRect() ) && 
       
  1417                        !HighlightOverlapWithBubble( rect1 );
       
  1418     if ( rect1Shown && iLayout->FirstLineInBand() == 0 )
       
  1419         {
       
  1420         rect1Shown = rect1Shown && !rect1.Intersects( iPromptTextRect );
       
  1421         }
       
  1422     TBool rect2Shown = !rect2.Intersects( iInsertionPoint->CursorRect() ) && 
       
  1423                        !HighlightOverlapWithBubble( rect2 );
       
  1424     if ( rect2Shown && iLayout->FirstLineInBand() == 0 )
       
  1425         {
       
  1426         rect2Shown =  rect2Shown && !rect2.Intersects( iPromptTextRect );
       
  1427         }
       
  1428     
       
  1429     if ( !rect1Shown && !rect2Shown )
       
  1430         {
       
  1431         if ( iMsgBubble->IsShowing() )
       
  1432             {
       
  1433             HideBubbleTemp();
       
  1434             }
       
  1435         return;
       
  1436         }
       
  1437     
       
  1438     TRect bubbleRect = rect1Shown? rect1 : rect2;
       
  1439     
       
  1440     if ( iMsgBubble->IsShowing() )
       
  1441         {
       
  1442         if ( bubbleRect != iMsgBubble->Rect() )
       
  1443             {
       
  1444             HideBubbleTemp();
       
  1445             }
       
  1446         iMsgBubble->Popup( bubbleRect );
       
  1447         
       
  1448         iHideBubbleTemp = EFalse;
       
  1449         return;
       
  1450         }
       
  1451         
       
  1452     if ( iHideBubbleTemp )
       
  1453         {
       
  1454         iMsgBubble->Popup( bubbleRect);
       
  1455         iHideBubbleTemp = EFalse;
       
  1456         }
       
  1457     
       
  1458     return;
       
  1459     }
       
  1460 void CFepLayoutMultiLineIcfEditor::SetInfoBubbleRect()
       
  1461     {
       
  1462     if( ( !iInfoBubble->IsShowing() && !iHideInfoBubbleTemp ) ||
       
  1463         iLineMaxCount < 1 || iCursorSel.iCursorPos < 0 )
       
  1464         {
       
  1465         return;
       
  1466         }
       
  1467     
       
  1468     TBool rtlLanguage = EFalse;
       
  1469     if ( iPreLanguageID == ELangUrdu || iPreLanguageID == ELangArabic || 
       
  1470          iPreLanguageID == ELangFarsi || iPreLanguageID == ELangHebrew )
       
  1471         {
       
  1472         rtlLanguage = ETrue;
       
  1473         }
       
  1474     TPoint startPoint;
       
  1475     TSize size = iInfoBubble->Rect().Size();
       
  1476     TRect rect1;
       
  1477     TRect rect2;
       
  1478     if ( iLineMaxCount == 1 )
       
  1479         {
       
  1480         TRect rectLeft;
       
  1481         TRect rectRight;
       
  1482         startPoint = TPoint(Rect().iTl.iX, Rect().iTl.iY );
       
  1483         startPoint += TPoint( KMsgBubblePosAdjustValueX, KMsgBubblePosAdjustValueY );
       
  1484         rectLeft = TRect(startPoint,size);
       
  1485         startPoint = TPoint(Rect().iBr.iX-iInfoBubble->Rect().Width(), Rect().iTl.iY);
       
  1486         startPoint += TPoint( -KMsgBubblePosAdjustValueX, KMsgBubblePosAdjustValueY );
       
  1487         rectRight = TRect(startPoint,size);
       
  1488         if ( rtlLanguage ) //rtl
       
  1489             {
       
  1490             rect1 = rectLeft;
       
  1491             rect2 = rectRight;
       
  1492             }
       
  1493         else
       
  1494             {
       
  1495             rect1 = rectRight;
       
  1496             rect2 = rectLeft;
       
  1497             }  
       
  1498         }
       
  1499     else
       
  1500         {
       
  1501         TRect rectTopLeft;
       
  1502         TRect rectTopRight;
       
  1503         TRect rectBottomLeft;
       
  1504         TRect rectBottomRight;
       
  1505         startPoint = TPoint(Rect().iTl.iX, Rect().iBr.iY-iInfoBubble->Rect().Height() );
       
  1506         startPoint += TPoint( KMsgBubblePosAdjustValueX, -KMsgBubblePosAdjustValueY );
       
  1507         rectBottomLeft =  TRect(startPoint,size);
       
  1508         startPoint = TPoint(Rect().iBr.iX-iInfoBubble->Rect().Width(), 
       
  1509                             Rect().iBr.iY-iInfoBubble->Rect().Height());
       
  1510         startPoint += TPoint( -KMsgBubblePosAdjustValueX, -KMsgBubblePosAdjustValueY );
       
  1511         rectBottomRight =  TRect(startPoint,size);
       
  1512         startPoint = TPoint(Rect().iTl.iX, Rect().iTl.iY );
       
  1513         startPoint += TPoint( KMsgBubblePosAdjustValueX, KMsgBubblePosAdjustValueY );
       
  1514         rectTopLeft =  TRect(startPoint,size);
       
  1515         startPoint = TPoint(Rect().iBr.iX-iInfoBubble->Rect().Width(), Rect().iTl.iY);
       
  1516         startPoint += TPoint( -KMsgBubblePosAdjustValueX, KMsgBubblePosAdjustValueY );
       
  1517         rectTopRight =  TRect(startPoint,size);
       
  1518         TBool firstLine =  iLayout->FirstLineInBand() == iLineNumber ;
       
  1519         if ( rtlLanguage ) //rtl
       
  1520             {
       
  1521             rect1 = firstLine ? rectBottomLeft : rectTopLeft;
       
  1522             rect2 = firstLine ? rectTopLeft : rectBottomLeft;
       
  1523             }
       
  1524         else
       
  1525             {
       
  1526             rect1 = firstLine ? rectBottomRight : rectTopRight;
       
  1527             rect2 = firstLine ? rectTopRight : rectBottomRight;
       
  1528             }
       
  1529         }
       
  1530        TBool rect1Shown = !rect1.Intersects( iInsertionPoint->CursorRect() ) && !HighlightOverlapWithBubble( rect1 );
       
  1531        TBool rect2Shown = !rect2.Intersects( iInsertionPoint->CursorRect() ) && !HighlightOverlapWithBubble( rect2 );
       
  1532     if ( !rect1Shown && !rect2Shown )
       
  1533         {
       
  1534         if ( iInfoBubble->IsShowing() )
       
  1535             {
       
  1536             HideBubbleTemp();
       
  1537             }
       
  1538         return;
       
  1539         }
       
  1540     TRect bubbleRect = rect1Shown? rect2 : rect1;
       
  1541     if ( iInfoBubble->IsShowing() )
       
  1542         {
       
  1543         if ( bubbleRect != iInfoBubble->Rect() )
       
  1544             {
       
  1545             HideBubbleTemp();
       
  1546             }
       
  1547         iInfoBubble->Popup( bubbleRect );
       
  1548         iHideInfoBubbleTemp = EFalse;
       
  1549         return;
       
  1550         }
       
  1551     if ( iHideInfoBubbleTemp )
       
  1552         {
       
  1553         iInfoBubble->Popup( bubbleRect);
       
  1554         iHideInfoBubbleTemp = EFalse;
       
  1555         }
       
  1556     return;
       
  1557     }
       
  1558 void CFepLayoutMultiLineIcfEditor::SetMsgBubbleCtrlSize(const TSize& aSize)
       
  1559     {
       
  1560     TPoint leftTop = TPoint(Rect().iBr.iX-iMsgBubble->Rect().Width(),Rect().iTl.iY);
       
  1561     iMsgBubble->SetRect( TRect(leftTop,aSize) ) ;        
       
  1562     }
       
  1563 void CFepLayoutMultiLineIcfEditor::SetInfoBubbleCtrlSize(const TSize& aSize)
       
  1564     {
       
  1565     TPoint leftTop = TPoint(Rect().iBr.iX-iInfoBubble->Rect().Width(),Rect().iTl.iY);
       
  1566     iInfoBubble->SetRect( TRect(leftTop,aSize) ) ;        
       
  1567     }
       
  1568 
       
  1569 void CFepLayoutMultiLineIcfEditor::ShowTooltipL(const TDesC& aText)
       
  1570 	{
       
  1571 	if ( !iTooltip )
       
  1572 	    {
       
  1573 	    return;
       
  1574 	    }
       
  1575 
       
  1576     iTooltip->SetTextL( aText );
       
  1577     TPoint tl = iInsertionPoint->Position();
       
  1578     if ( iLineMaxCount > 1 )
       
  1579 	    {
       
  1580 		TBool firstLine =  iLayout->FirstLineInBand() == iLineNumber;
       
  1581 		if ( firstLine )
       
  1582 		    {
       
  1583 			tl.iY += iInsertionPoint->Height();
       
  1584 			}
       
  1585 		else
       
  1586 		    {
       
  1587 			tl.iY -= iTooltip->Rect().Height();
       
  1588 			}
       
  1589 		}
       
  1590     TRect tooltipRect = TRect( tl, iTooltip->Rect().Size() );
       
  1591     
       
  1592     TInt moveX = tooltipRect.iBr.iX - Rect().iBr.iX;
       
  1593     if ( moveX > 0 )
       
  1594     	{
       
  1595     	tooltipRect.iBr.iX -= moveX;
       
  1596     	tooltipRect.iTl.iX -= moveX;
       
  1597     	}
       
  1598 		
       
  1599 	if ( tooltipRect.Intersects( iMsgBubble->Rect() ) )
       
  1600 	    {
       
  1601 		moveX = tooltipRect.iBr.iX - iMsgBubble->Rect().iTl.iX;
       
  1602 		if ( moveX > 0 && tooltipRect.iTl.iX - moveX >= Rect().iTl.iX )
       
  1603 	    	{
       
  1604 	    	tooltipRect.iBr.iX -= moveX;
       
  1605 	    	tooltipRect.iTl.iX -= moveX;
       
  1606 	    	}
       
  1607 		moveX = iMsgBubble->Rect().iBr.iX - tooltipRect.iTl.iX;
       
  1608 		if ( moveX > 0 && tooltipRect.iBr.iX + moveX <= Rect().iBr.iX )
       
  1609 	    	{
       
  1610 	    	tooltipRect.iBr.iX += moveX;
       
  1611 	    	tooltipRect.iTl.iX += moveX;
       
  1612 	    	}
       
  1613 	    }
       
  1614     iTooltip->Popup( tooltipRect );
       
  1615 	}
       
  1616 
       
  1617 void CFepLayoutMultiLineIcfEditor::HideTooltip()
       
  1618 	{
       
  1619 	if ( iTooltip )
       
  1620 	    {
       
  1621 	    iTooltip->Close();
       
  1622 	    }	
       
  1623 	}
       
  1624 
       
  1625 void CFepLayoutMultiLineIcfEditor::RemoveOverlappedCtrlIfNeeded()
       
  1626     {
       
  1627     for (TInt i = iOverlappedCtrlList.Count()-1; i >= 0 ; i--)
       
  1628         {
       
  1629         if (!iOverlappedCtrlList[i].iCtrl->Rect().Intersects(Rect()))
       
  1630             {
       
  1631             RestoreCursorState(i);
       
  1632             }
       
  1633         }
       
  1634     }
       
  1635 
       
  1636 void CFepLayoutMultiLineIcfEditor::SizeChangedL(const TRect& aRect,
       
  1637                                                 TInt aFontHeight,
       
  1638                                                 TInt aMaxFontHeight,
       
  1639                                                 const CFont* aFont)
       
  1640     {   
       
  1641     TRect oriRect = Rect();
       
  1642     
       
  1643     AdjustBmpDeviceIfNeeded();
       
  1644     // apply font formats 
       
  1645     SetFontL(aFontHeight, aMaxFontHeight, aFont);
       
  1646     
       
  1647     if ( !iFormatChange && oriRect == aRect )
       
  1648         {
       
  1649         return;
       
  1650         }
       
  1651         
       
  1652     if( BackgroundBmp() )
       
  1653         {
       
  1654         CFbsBitmap* bmp = BackgroundBmp();
       
  1655         if( aRect.Size() != bmp->SizeInPixels() )
       
  1656             {
       
  1657             AknIconUtils::SetSize(bmp, aRect.Size(), EAspectRatioNotPreserved);            
       
  1658             }
       
  1659         }
       
  1660    
       
  1661     RemoveOverlappedCtrlIfNeeded();
       
  1662  
       
  1663     ApplyFormatL();
       
  1664     
       
  1665     SetRectL(aRect);
       
  1666     
       
  1667     AdjustPromptTextL();
       
  1668     
       
  1669 
       
  1670     iLayout->SetAmountToFormat(CTextLayout::EFFormatAllText);    
       
  1671     
       
  1672     if ( iFormatChange )
       
  1673         {
       
  1674         iTextView->HandleGlobalChangeNoRedrawL();
       
  1675         }
       
  1676     
       
  1677     TBool ready = Ready();
       
  1678     if( ready )
       
  1679         {
       
  1680         SetReady( EFalse );     
       
  1681         }
       
  1682     
       
  1683 	RootControl()->ReDrawRect( oriRect );
       
  1684 	if( ready )
       
  1685 	    {
       
  1686 	    SetReady( ETrue );    
       
  1687 	    }
       
  1688 
       
  1689     if ( iFormatChange )	    
       
  1690         {
       
  1691         iTextView->SetSelectionL( iTextView->Selection() );
       
  1692         RecalcualteTextPositionL();
       
  1693         SetMsgBubbleRect();
       
  1694         Draw();
       
  1695         }
       
  1696     }
       
  1697 
       
  1698 TBool CFepLayoutMultiLineIcfEditor::BelongToPromptText(TInt aPos)
       
  1699     {
       
  1700     if (!iPromptText || iPromptText->Length() == 0 )
       
  1701         {
       
  1702         return EFalse;
       
  1703         }
       
  1704 
       
  1705     return (aPos >= 0 && aPos <= (iPromptText->Length() - 1));
       
  1706     }
       
  1707 
       
  1708 CFepUiBaseCtrl* CFepLayoutMultiLineIcfEditor::HandlePointerDownEventL(const TPoint& aPt)
       
  1709     {
       
  1710     TBool isNormalState = ( iState == CFepLayoutMultiLineIcf::EIcfNormal );
       
  1711     TBool isCursorDisabled = !iCursorVisible && !iCursorSelVisible && isNormalState;
       
  1712     
       
  1713     if ( iDimmed || isCursorDisabled )
       
  1714         {
       
  1715         return NULL;
       
  1716         }
       
  1717 
       
  1718     if(!iViewRect.Contains(aPt))
       
  1719         {
       
  1720         return this;
       
  1721         }
       
  1722     
       
  1723     CFepUiBaseCtrl::HandlePointerDownEventL(aPt);
       
  1724     CapturePointer(ETrue);  
       
  1725     iSycnFepData = EFalse;
       
  1726     
       
  1727     // For keeping previous cursor pos.
       
  1728     TInt preCursorPos = iCursorSel.iCursorPos;
       
  1729     if ( iRtlMfneEditor )
       
  1730         {
       
  1731         TInt cursorPos = iFont->TextCount(iMfneIcfData->Des(), aPt.iX - iViewRect.iTl.iX - iOffset );
       
  1732         iCursorSel = TCursorSelection(cursorPos+iPromptTextLen, cursorPos+iPromptTextLen);
       
  1733         AdjustFepCursorPosForPromptText( ETrue );
       
  1734         return this;
       
  1735         }
       
  1736 
       
  1737     TInt cursorPos = iTextView->XyPosToDocPosL(const_cast<TPoint&>(aPt));
       
  1738 
       
  1739     iPntDownOnInline = EFalse;
       
  1740 
       
  1741     if (BelongToPromptText(cursorPos))
       
  1742         {
       
  1743         ReportEvent(EEventControlFocusGained);
       
  1744         return this;
       
  1745         }
       
  1746     SetSelectionL(TCursorSelection(cursorPos, cursorPos)); 
       
  1747     iTextView->DrawL(iViewRect);  
       
  1748     iInsertionPoint->SetVisible( EFalse );
       
  1749     UpdateArea(Rect(),EFalse);
       
  1750     SetFocus(ETrue);
       
  1751 
       
  1752     switch (iState)
       
  1753         {
       
  1754         case CFepLayoutMultiLineIcf::EIcfInline:
       
  1755             {
       
  1756             TInt inlineEndPos =  iNoMatchState ? iPreInlineEndPos + 1 : iPreInlineEndPos;
       
  1757             
       
  1758             if (iTextView->Selection().iCursorPos >= iPreInlineStartPos && 
       
  1759                 iTextView->Selection().iCursorPos < inlineEndPos )
       
  1760                 {
       
  1761                 // when pointer down on non-text, the pointer down pos is considerred
       
  1762                 // last character in ICF
       
  1763                 // open match selection list
       
  1764                 iPntDownOnInline = ETrue;
       
  1765                 CapturePointer(EFalse); 
       
  1766                 if (iNoMatchState)
       
  1767                     {
       
  1768                     ReportEvent(EEventPointerDownOnNomatch);
       
  1769                     }
       
  1770                     
       
  1771                 else
       
  1772                     {
       
  1773                     if (iTooltip && iTooltip->IsShowing())
       
  1774                         {
       
  1775                         iTooltip->Hide(ETrue);
       
  1776                         }
       
  1777                     else
       
  1778                         {
       
  1779                         ReportEvent(EEventPointerDownOnInline);
       
  1780                         }
       
  1781                     
       
  1782                     }
       
  1783                     
       
  1784                 }
       
  1785              
       
  1786     
       
  1787     	    if (!iPntDownOnInline)
       
  1788     	        {
       
  1789                 TPoint point = aPt;
       
  1790                 TInt cursorPos = iTextView->XyPosToDocPosL( point );
       
  1791     	        
       
  1792     	        if(cursorPos == iRichText->DocumentLength() ||
       
  1793     	           BelongToPromptText(cursorPos))
       
  1794     	            {
       
  1795                     if (iTooltip && !iTooltip->IsShowing())
       
  1796                         {
       
  1797  //                       ReportEvent(EEventInsertSpace);    
       
  1798                         }
       
  1799     	            }
       
  1800     	        else
       
  1801     	            {
       
  1802     	            /*
       
  1803                     if (iTooltip && !iTooltip->IsShowing())
       
  1804                         {
       
  1805             	        ReportEvent(EEventControlFocusGained);               
       
  1806                         UiLayout()->SignalOwner( ESignalCommitInlineText );
       
  1807         			    SetInlineStateL(EFalse, iPreInlineStartPos, iPreInlineEndPos);
       
  1808                         }
       
  1809                     */
       
  1810     	            }
       
  1811     	        
       
  1812                 }
       
  1813    
       
  1814             }
       
  1815             break;
       
  1816         case CFepLayoutMultiLineIcf::EIcfAutoComplete:
       
  1817             {
       
  1818             if (iTextView->Selection().iCursorPos >= iPreInlineStartPos && 
       
  1819                 iTextView->Selection().iCursorPos < iPreInlineEndPos )
       
  1820                 {
       
  1821                 iPntDownOnInline = ETrue;
       
  1822                 CapturePointer(EFalse);                 
       
  1823                 if (iTooltip && iTooltip->IsShowing())
       
  1824                     {
       
  1825                     iTooltip->Hide(ETrue);
       
  1826                     }
       
  1827                 else
       
  1828                     {
       
  1829                     ReportEvent(EEventPointerDownOnInline);
       
  1830                     }
       
  1831                 }
       
  1832             else
       
  1833                 {
       
  1834                 // do nothing
       
  1835                 //submit autocomplete when set text
       
  1836                 if (iTooltip && !iTooltip->IsShowing())
       
  1837                     {
       
  1838     	            ReportEvent( EEventControlFocusGained );
       
  1839                     UiLayout()->SignalOwner( ESignalCommitITIInlineText );
       
  1840 			        SetInlineStateL( EFalse, iPreInlineStartPos, iPreInlineEndPos );
       
  1841 			        SetAutoCompleteStateL( EFalse );
       
  1842                     }
       
  1843                 }
       
  1844             }
       
  1845             break;
       
  1846         case CFepLayoutMultiLineIcf::EIcfNormal:
       
  1847     		{
       
  1848 		    if (preCursorPos != iCursorSel.iCursorPos)
       
  1849 			   {
       
  1850 			   ReportEvent(EEventSetAppCursorSelection);
       
  1851 			   }		   			
       
  1852     		}
       
  1853     		break;
       
  1854         default:
       
  1855             break;
       
  1856         }
       
  1857         
       
  1858     iLastCursorPos = iCursorSel.iCursorPos;
       
  1859     return this;
       
  1860     }
       
  1861 
       
  1862 void CFepLayoutMultiLineIcfEditor::AdjustFepCursorPosForPromptText( TBool aSyncCursor )
       
  1863     {
       
  1864     TCursorSelection cursor;
       
  1865     
       
  1866     if ( iRtlMfneEditor )
       
  1867         {
       
  1868         cursor = iCursorSel;
       
  1869         }
       
  1870     else
       
  1871         {
       
  1872         cursor = iTextView->Selection();
       
  1873         }
       
  1874     
       
  1875     cursor.iCursorPos -= iPromptTextLen;
       
  1876     cursor.iAnchorPos -= iPromptTextLen;
       
  1877 
       
  1878     UiLayout()->SetAppEditorCursor(cursor, aSyncCursor);
       
  1879     iSynCursor = ETrue;
       
  1880     }
       
  1881 
       
  1882 CFepUiBaseCtrl* CFepLayoutMultiLineIcfEditor::HandlePointerUpEventL(const TPoint& aPt)
       
  1883     {
       
  1884     TBool isNormalState = ( iState == CFepLayoutMultiLineIcf::EIcfNormal );
       
  1885     TBool isCursorDisabled = !iCursorVisible && !iCursorSelVisible && isNormalState;
       
  1886     
       
  1887     if ( iDimmed || isCursorDisabled || !PointerDown() )
       
  1888         {
       
  1889         return NULL;
       
  1890         }
       
  1891    
       
  1892     CFepUiBaseCtrl::HandlePointerUpEventL(aPt);
       
  1893     CapturePointer(EFalse); 
       
  1894     
       
  1895     if ( iRtlMfneEditor )
       
  1896         {
       
  1897         TInt cursorPos = iFont->TextCount(iMfneIcfData->Des(), aPt.iX - iViewRect.iTl.iX - iOffset );
       
  1898         iCursorSel = TCursorSelection(cursorPos+iPromptTextLen, 
       
  1899                                       iCursorSel.iAnchorPos);
       
  1900         AdjustFepCursorPosForPromptText( ETrue );
       
  1901         return this;
       
  1902         }
       
  1903         
       
  1904     if (!iPntDownOnInline)
       
  1905         {
       
  1906         if(iViewRect.Contains(aPt))
       
  1907             {
       
  1908             TPoint point = aPt;
       
  1909             TInt cursorPos = iTextView->XyPosToDocPosL( point );
       
  1910             if ( !Rect().Contains(aPt) || 
       
  1911                  ( Rect().Contains(aPt) && BelongToPromptText(cursorPos) ) )
       
  1912                 {
       
  1913                 cursorPos = iCursorSel.iCursorPos;
       
  1914                 }
       
  1915             
       
  1916             if ( cursorPos != iCursorSel.iCursorPos )
       
  1917                 {
       
  1918                 SetSelectionL( TCursorSelection(cursorPos,iCursorSel.iAnchorPos) );
       
  1919                 }
       
  1920             }
       
  1921             
       
  1922         if (iTooltip && iTooltip->IsShowing())
       
  1923             {
       
  1924             iTooltip->Hide(ETrue);
       
  1925             }
       
  1926         else
       
  1927             {
       
  1928             AdjustFepCursorPosForPromptText( !iPntDownOnInline );
       
  1929             if(iState != CFepLayoutMultiLineIcf::EIcfNormal)
       
  1930                 {
       
  1931                 UiLayout()->SignalOwner( ESignalStartInlineText );
       
  1932                 }
       
  1933             }
       
  1934         }
       
  1935 
       
  1936     iPntDownOnInline = EFalse;    
       
  1937     
       
  1938     ReportEvent(EEventIcfPointerUpEvent);   
       
  1939     
       
  1940     return this;
       
  1941     }
       
  1942 
       
  1943 TBool CFepLayoutMultiLineIcfEditor::MoveCursorL( const TPoint& aPt, TInt& aCursorPos )
       
  1944 	{
       
  1945 	TBool selectionUpdated = ETrue;
       
  1946 	
       
  1947 	if ( aPt.iX < iViewRect.iTl.iX )
       
  1948         {
       
  1949         // selection was dragged beyond the left edge of iCorrectedRect -> scroll left
       
  1950         TInt prev = iCursorSel.iCursorPos;
       
  1951         aCursorPos = iCursorSel.iCursorPos-1 > iPromptTextLen ? 
       
  1952             iCursorSel.iCursorPos-1 : iPromptTextLen;
       
  1953         if(prev != aCursorPos)
       
  1954             {
       
  1955             TCursorPosition::TMovementType move = TCursorPosition::EFLeft;
       
  1956             iTextView->MoveCursorL(move,EFalse);
       
  1957             }
       
  1958         else
       
  1959         	{
       
  1960         	selectionUpdated = EFalse;
       
  1961         	}
       
  1962         } 
       
  1963     else if ( aPt.iX > iViewRect.iBr.iX )
       
  1964         {
       
  1965         // selection was dragged beyond the right edge of iCorrectedRect -> scroll right
       
  1966         TInt prev = iCursorSel.iCursorPos;
       
  1967         aCursorPos = iCursorSel.iCursorPos+1 < iRichText->DocumentLength() ?
       
  1968             iCursorSel.iCursorPos+1 : iRichText->DocumentLength();
       
  1969         if(prev != aCursorPos)            
       
  1970             {
       
  1971             TCursorPosition::TMovementType move = TCursorPosition::EFRight;
       
  1972             iTextView->MoveCursorL(move,EFalse);
       
  1973             } 
       
  1974         else
       
  1975         	{
       
  1976         	selectionUpdated = EFalse;
       
  1977         	}     
       
  1978         }
       
  1979     else if ( aPt.iY > iViewRect.iBr.iY )
       
  1980         {
       
  1981         TInt prev = iCursorSel.iCursorPos;
       
  1982     	if ( prev < iRichText->DocumentLength() )
       
  1983         	{
       
  1984         	TCursorPosition::TMovementType move = TCursorPosition::EFLineDown;
       
  1985         	iTextView->MoveCursorL( move, EFalse );
       
  1986 	        TPoint point = aPt;
       
  1987 	        aCursorPos = iTextView->XyPosToDocPosL( point );
       
  1988 	        if ( aCursorPos == prev )
       
  1989 	        	{
       
  1990 	        	selectionUpdated = EFalse;
       
  1991 	        	}
       
  1992         	}
       
  1993         else
       
  1994         	{
       
  1995         	selectionUpdated = EFalse;
       
  1996         	}
       
  1997         }
       
  1998     else if ( aPt.iY < iViewRect.iTl.iY )
       
  1999     	{
       
  2000     	TInt prev = iCursorSel.iCursorPos;
       
  2001     	if ( prev > iPromptTextLen )
       
  2002         	{
       
  2003         	TCursorPosition::TMovementType move = TCursorPosition::EFLineUp;
       
  2004         	iTextView->MoveCursorL( move, EFalse );
       
  2005 	        TPoint point = aPt;
       
  2006 	        aCursorPos = iTextView->XyPosToDocPosL( point );
       
  2007 	        if ( aCursorPos == prev )
       
  2008 	        	{
       
  2009 	        	selectionUpdated = EFalse;
       
  2010 	        	}
       
  2011         	}
       
  2012         else
       
  2013         	{
       
  2014         	selectionUpdated = EFalse;
       
  2015         	}
       
  2016     	}
       
  2017     	
       
  2018     return selectionUpdated;
       
  2019 	}
       
  2020 CFepUiBaseCtrl* CFepLayoutMultiLineIcfEditor::HandlePointerMoveEventL(const TPoint& aPt)
       
  2021     {       
       
  2022     TBool isNormalState = ( iState == CFepLayoutMultiLineIcf::EIcfNormal );
       
  2023     TBool isCursorDisabled = !iCursorVisible && !iCursorSelVisible && isNormalState;
       
  2024     
       
  2025     if ( !PointerDown() || iDimmed || isCursorDisabled || iPntDownOnInline )
       
  2026     	{
       
  2027         return this;
       
  2028     	}
       
  2029     
       
  2030     if ( iRtlMfneEditor )
       
  2031         {
       
  2032         TInt cursorPos = iFont->TextCount(iMfneIcfData->Des(), aPt.iX - iViewRect.iTl.iX - iOffset );
       
  2033         iCursorSel = TCursorSelection(cursorPos+iPromptTextLen, 
       
  2034                                       iCursorSel.iAnchorPos);
       
  2035         AdjustFepCursorPosForPromptText( ETrue );
       
  2036         return this;
       
  2037         }
       
  2038         
       
  2039     TPoint point = aPt;
       
  2040     
       
  2041     TInt cursorPos = iTextView->XyPosToDocPosL( point );
       
  2042 
       
  2043     if( Rect().Contains(aPt) && 
       
  2044         ( BelongToPromptText(cursorPos) || cursorPos == iCursorSel.iCursorPos ) )
       
  2045         {
       
  2046         return this;
       
  2047         }
       
  2048     
       
  2049     iInsertionPoint->DelayCursorShown();
       
  2050     
       
  2051     TBool selectUpdated = MoveCursorL( aPt, cursorPos );
       
  2052     
       
  2053     if ( selectUpdated )
       
  2054     	{
       
  2055     	SetSelectionL(TCursorSelection(cursorPos,iCursorSel.iAnchorPos) ); 
       
  2056     	}
       
  2057     	
       
  2058     if( !iViewRect.Contains(aPt))
       
  2059     	{
       
  2060         AdjustFepCursorPosForPromptText();
       
  2061     	}
       
  2062         
       
  2063 	UpdateArea(Rect(),EFalse);
       
  2064 #ifdef RD_TACTILE_FEEDBACK
       
  2065     if (UiLayout()->SupportTactileFeedback())
       
  2066         {
       
  2067         if ( iLastCursorPos != iCursorSel.iCursorPos ) 
       
  2068             {
       
  2069             UiLayout()->DoTactileFeedback(ETouchFeedbackSensitiveInput);
       
  2070             iLastCursorPos = iCursorSel.iCursorPos;
       
  2071             }
       
  2072         }
       
  2073 #endif //RD_TACTILE_FEEDBACK
       
  2074 
       
  2075     return this;
       
  2076     }
       
  2077 
       
  2078 void CFepLayoutMultiLineIcfEditor::CancelPointerDownL()
       
  2079     {
       
  2080     if (PointerDown())
       
  2081         {
       
  2082         SetPointerDown(EFalse);
       
  2083         CapturePointer(EFalse); 
       
  2084         }
       
  2085     }
       
  2086 
       
  2087 void CFepLayoutMultiLineIcfEditor::HandlePointerLeave(const TPoint& aPt)
       
  2088     {
       
  2089     TBool isInline = ( iState == CFepLayoutMultiLineIcf::EIcfInline );
       
  2090     TBool isCursorDisabled = !iCursorVisible && !iCursorSelVisible && !isInline;
       
  2091     
       
  2092     if ( !PointerDown() || iDimmed || isCursorDisabled )    
       
  2093         {
       
  2094         return;
       
  2095         }
       
  2096 
       
  2097     UiLayout()->SetAppEditorCursor(iCursorSel);
       
  2098     CFepUiBaseCtrl::HandlePointerLeave(aPt);
       
  2099     }
       
  2100 
       
  2101 void CFepLayoutMultiLineIcfEditor::PrepareForFocusLoss()
       
  2102     {
       
  2103     iInsertionPoint->SetOn(EFalse);
       
  2104 
       
  2105     iHasFocus = EFalse;
       
  2106 
       
  2107     ReportEvent(EEventControlFocusLost);
       
  2108     }
       
  2109 
       
  2110 TBool CFepLayoutMultiLineIcfEditor::PrepareForFocusGain()
       
  2111     {
       
  2112     iHasFocus = ETrue;
       
  2113 
       
  2114     iInsertionPoint->SetOn( iCursorVisible );
       
  2115     
       
  2116     ReportEvent(EEventControlFocusGained);
       
  2117 
       
  2118     return ETrue;
       
  2119     }
       
  2120 
       
  2121 void CFepLayoutMultiLineIcfEditor::Move(const TPoint& aOffset)
       
  2122     {
       
  2123     CFepUiBaseCtrl::Move(aOffset);
       
  2124 
       
  2125     iViewRect.Move(aOffset);
       
  2126     iTextView->SetViewRect(iViewRect);
       
  2127     
       
  2128     if (iInsertionPoint)
       
  2129         {
       
  2130         TPoint curPos = iInsertionPoint->Position();
       
  2131         curPos += aOffset;
       
  2132         iInsertionPoint->SetPosition(curPos);
       
  2133         }
       
  2134     }
       
  2135 
       
  2136 void CFepLayoutMultiLineIcfEditor::OnDeActivate()
       
  2137     {    
       
  2138     CFepUiBaseCtrl::OnDeActivate();
       
  2139     iTextInited = EFalse;
       
  2140     TRAP_IGNORE(UpdateSecretTextL());
       
  2141     //cancel the insertion pointer timer
       
  2142     if(iHasFocus)
       
  2143         {
       
  2144         iInsertionPoint->SetOn(EFalse);
       
  2145         }
       
  2146 
       
  2147     // avoid crash caused by HandleRedrawEvent 
       
  2148     // (called when screen resolution changed)
       
  2149     iWin->SetVisible(EFalse);
       
  2150     }
       
  2151 
       
  2152 void CFepLayoutMultiLineIcfEditor::OnActivate()
       
  2153     {
       
  2154     CFepUiBaseCtrl::OnActivate();
       
  2155     EnableRegionUpdating();
       
  2156 
       
  2157     AdjustBmpDeviceIfNeeded();
       
  2158 
       
  2159     //set cursor if needed    
       
  2160     //cancel the insertion pointer timer
       
  2161     TBool on = (iCursorVisible && iHasFocus );//&& (iOverlappedCtrlList.Count() <= 0))
       
  2162     for(TInt i = 0 ; i < iOverlappedCtrlList.Count(); ++i)
       
  2163         {
       
  2164         on = on && iOverlappedCtrlList[i].iCtrl->Hiden();
       
  2165         }
       
  2166     iInsertionPoint->SetOn(on); 
       
  2167     iWin->SetVisible(ETrue);
       
  2168     }
       
  2169 
       
  2170 void CFepLayoutMultiLineIcfEditor::HandleArrowBtnEventL(
       
  2171                                                 CFepLayoutMultiLineIcf::TArrowBtnEvent aEventType)
       
  2172     {
       
  2173     TCursorPosition::TMovementType movement;    
       
  2174 
       
  2175     switch (aEventType)
       
  2176         {
       
  2177         case CFepLayoutMultiLineIcf::EArrowUp:
       
  2178             {
       
  2179             movement = TCursorPosition::EFLineUp;
       
  2180             iTextView->MoveCursorL(movement, EFalse);
       
  2181             AdjustSelectionL( iTextView->Selection() );
       
  2182             }
       
  2183             break;
       
  2184         case CFepLayoutMultiLineIcf::EArrowDown:
       
  2185             {
       
  2186             movement = TCursorPosition::EFLineDown;
       
  2187             iTextView->MoveCursorL(movement, EFalse);
       
  2188             }
       
  2189             break;
       
  2190         default:
       
  2191             return;
       
  2192         }
       
  2193 
       
  2194     AdjustFepCursorPosForPromptText();
       
  2195     }
       
  2196 
       
  2197 TBool CFepLayoutMultiLineIcfEditor::Contains(const TPoint& aPt)
       
  2198     {
       
  2199     TBool contain = EFalse;
       
  2200 
       
  2201     if (iSupportOverLap)
       
  2202         {
       
  2203         TBool isOverlap = EFalse;
       
  2204         
       
  2205         for (TInt i = 0; i < iOverLapRects.Count(); i++)
       
  2206             {
       
  2207             if (iOverLapRects[i].Contains(aPt))
       
  2208                 {
       
  2209                 isOverlap = ETrue;
       
  2210                 break;	
       
  2211                 }
       
  2212             }
       
  2213 
       
  2214         contain = iRect.Contains(aPt) && !isOverlap;
       
  2215         return contain;
       
  2216         }
       
  2217 
       
  2218     contain = iRect.Contains(aPt);
       
  2219     return contain;
       
  2220     }
       
  2221 
       
  2222 void CFepLayoutMultiLineIcfEditor::SetOverLapState(TBool aSupportOverLap, TRect aRect)
       
  2223     {
       
  2224     iSupportOverLap = aSupportOverLap;
       
  2225     iOverLapRects.Reset();
       
  2226 
       
  2227     if (iSupportOverLap)
       
  2228         {
       
  2229         iOverLapRects.Append(aRect);
       
  2230         }
       
  2231     }
       
  2232 
       
  2233 void CFepLayoutMultiLineIcfEditor::AddOverLapState(TRect aRect)
       
  2234     {
       
  2235     if (iSupportOverLap)
       
  2236         {
       
  2237         iOverLapRects.Append(aRect);
       
  2238         }
       
  2239     }
       
  2240 
       
  2241 TInt CFepLayoutMultiLineIcfEditor::GetEditorFieldMaxLen()
       
  2242     {
       
  2243     return iRect.Width()/2;
       
  2244     }
       
  2245 
       
  2246 void CFepLayoutMultiLineIcfEditor::SetCursorSizeAndType()
       
  2247     {
       
  2248     iWeight = AknLayoutUtils::CursorWidthFromFont(CursorFontSpec());
       
  2249     }
       
  2250 
       
  2251 TFontSpec CFepLayoutMultiLineIcfEditor::CursorFontSpec()
       
  2252     {
       
  2253     TCharFormat charFormat;
       
  2254     TCharFormatMask notUsed;
       
  2255     iRichText->GetCharFormat(charFormat, notUsed, iTextView->Selection().iCursorPos, 0);
       
  2256     return charFormat.iFontSpec;
       
  2257     }
       
  2258 
       
  2259 void CFepLayoutMultiLineIcfEditor::CalculateCursorPos(TPoint& aCaretPos)
       
  2260     {
       
  2261     TInt caret_width, caret_ascent, caret_descent;
       
  2262 
       
  2263     TTmLineInfo info;
       
  2264 
       
  2265     TInt pos = iTextView->Selection().iCursorPos >= iPromptTextLen ? 
       
  2266         iTextView->Selection().iCursorPos : iPromptTextLen;
       
  2267 
       
  2268     iLayout->TagmaTextLayout().GetCursor(TTmDocPos(pos, iLeadingEdge), 
       
  2269                                          ECursorVertical,
       
  2270                                          info,
       
  2271                                          aCaretPos,
       
  2272                                          caret_width,
       
  2273                                          caret_ascent,
       
  2274                                          caret_descent);
       
  2275     
       
  2276     iLineNumber = info.iLineNumber;
       
  2277     aCaretPos.iY = info.iInnerRect.iTl.iY;
       
  2278     
       
  2279     // get bandtop of CTextLayout
       
  2280     TPoint band;
       
  2281     iLayout->GetOrigin(band);
       
  2282     TInt bandtop = -(band.iY);
       
  2283     aCaretPos.iY -= bandtop;
       
  2284    
       
  2285     aCaretPos += iViewRect.iTl;
       
  2286     
       
  2287     // adjust which side the cursor hands around the origin
       
  2288     // based on the sign of the 'width' from tagma
       
  2289     if (caret_width < 0)
       
  2290         aCaretPos.iX -= iWeight;
       
  2291     }
       
  2292 
       
  2293 void CFepLayoutMultiLineIcfEditor::RecalcualteTextPositionL()
       
  2294     {
       
  2295     TPoint newcursorPos;
       
  2296     CalculateCursorPos(newcursorPos);
       
  2297         
       
  2298     newcursorPos = TPoint(newcursorPos.iX, newcursorPos.iY );//- iCursorHeight iFontHeight
       
  2299 
       
  2300     if (newcursorPos.iY < iViewRect.iTl.iY)
       
  2301         {
       
  2302         newcursorPos.iY = iViewRect.iTl.iY;
       
  2303         }
       
  2304     else if (newcursorPos.iY + iInsertionPoint->Height()> iViewRect.iBr.iY)
       
  2305         {
       
  2306         newcursorPos.iY = iViewRect.iBr.iY - iInsertionPoint->Height();
       
  2307         }
       
  2308     if ( newcursorPos.iX + KCursorPosCorrectionX < iViewRect.iTl.iX )
       
  2309 		{
       
  2310 		newcursorPos.iX = iViewRect.iTl.iX - KCursorPosCorrectionX;
       
  2311 		}
       
  2312     else if ( newcursorPos.iX + KCursorPosCorrectionX + KCursorWidth > iViewRect.iBr.iX )
       
  2313         {
       
  2314         newcursorPos.iX = iViewRect.iBr.iX - KCursorPosCorrectionX - KCursorWidth; 
       
  2315         }
       
  2316         
       
  2317     iInsertionPoint->SetPosition(newcursorPos);
       
  2318     }
       
  2319 
       
  2320 void CFepLayoutMultiLineIcfEditor::UpdateValidRegion(CFepUiBaseCtrl* aCtrl,TBool aRemoveFlag)
       
  2321     {
       
  2322     if (!iUpdateFlagEnabled || !aCtrl || aCtrl == this)
       
  2323         {
       
  2324         return;
       
  2325         }
       
  2326     
       
  2327     if (aRemoveFlag)
       
  2328         {
       
  2329         RestoreCursorState(aCtrl);
       
  2330         }
       
  2331     else
       
  2332         {
       
  2333         if( aCtrl->IsKindOfControl(ECtrlBackgroundCtrl) )
       
  2334             {
       
  2335             return;
       
  2336             }
       
  2337             
       
  2338         if (iTextInited)
       
  2339             {
       
  2340             //a shown control changes rect
       
  2341             TInt idx = FindOverlappedCtrl(aCtrl);
       
  2342 
       
  2343             if (idx != KErrNotFound)
       
  2344                 {
       
  2345                 if (aCtrl->Rect().Intersects(iInsertionPoint->CursorRect()))
       
  2346                     return;
       
  2347                 //restore
       
  2348                 RestoreCursorState(idx);
       
  2349                 }
       
  2350             else  //new control
       
  2351                 {
       
  2352                 TRect intersectRect = aCtrl->Rect();
       
  2353                 intersectRect.Intersection(iInsertionPoint->CursorRect());
       
  2354                 if ( iInsertionPoint->CursorRect() != intersectRect )                
       
  2355                     {
       
  2356                     return;
       
  2357                     }
       
  2358                     
       
  2359                 //check whether it's parent
       
  2360                 CFepUiBaseCtrl* parent = ParentCtrl();
       
  2361                 while(parent && parent != aCtrl) parent = parent->ParentCtrl();
       
  2362                 
       
  2363                 if(parent)  // the given control is the ancestor of ICF.
       
  2364                     return;
       
  2365                 
       
  2366                 SaveCursorState(aCtrl);
       
  2367                 //disable cursor
       
  2368                 iInsertionPoint->SetOn(EFalse);
       
  2369                 }
       
  2370             }
       
  2371         }    
       
  2372     }
       
  2373 
       
  2374 void CFepLayoutMultiLineIcfEditor::SaveCursorState(CFepUiBaseCtrl* aCtrl)
       
  2375     {
       
  2376     for(TInt i = 0 ; i < iOverlappedCtrlList.Count(); ++i)
       
  2377         {        
       
  2378         if(aCtrl == iOverlappedCtrlList[i].iCtrl)
       
  2379             return;
       
  2380         }
       
  2381     TOverlappedInfo ctrlInfo={aCtrl,iInsertionPoint->IsOn()};
       
  2382     
       
  2383     iOverlappedCtrlList.Append(ctrlInfo);
       
  2384     }
       
  2385 
       
  2386 void CFepLayoutMultiLineIcfEditor::RestoreCursorState(CFepUiBaseCtrl* aCtrl)
       
  2387     {
       
  2388     //need check whether that control previously overlapped with ICF    
       
  2389     TInt idx = FindOverlappedCtrl(aCtrl);
       
  2390     if(idx != KErrNotFound)
       
  2391         RestoreCursorState(idx);
       
  2392     }
       
  2393 
       
  2394 void CFepLayoutMultiLineIcfEditor::RestoreCursorState(TInt aIndex)
       
  2395     {
       
  2396     //no need to check index. as it's checked before called.							   
       
  2397     iInsertionPoint->SetOn(iOverlappedCtrlList[aIndex].iCursorStateBeforeOverlapped);
       
  2398     iOverlappedCtrlList.Remove(aIndex);
       
  2399     }
       
  2400 
       
  2401 TInt CFepLayoutMultiLineIcfEditor::FindOverlappedCtrl(CFepUiBaseCtrl* aCtrl)
       
  2402     {
       
  2403     for(TInt i = 0 ; i < iOverlappedCtrlList.Count(); ++i)
       
  2404         {        
       
  2405         if (aCtrl == iOverlappedCtrlList[i].iCtrl)
       
  2406             return i;
       
  2407         }
       
  2408 
       
  2409     return KErrNotFound;
       
  2410     }
       
  2411 
       
  2412 TBool CFepLayoutMultiLineIcfEditor::IsTextPosValid(TInt aPos)
       
  2413     {
       
  2414     return (aPos >= 0 && aPos <= iRichText->DocumentLength());
       
  2415     }
       
  2416 
       
  2417 void CFepLayoutMultiLineIcfEditor::UpdateNoMatchTextL(TInt aPos, const TDesC& aNoMatchText, 
       
  2418                                                       TBool aNoMatchState)
       
  2419     {
       
  2420     if ( iNoMatchState == aNoMatchState )
       
  2421         {
       
  2422         return;
       
  2423         }
       
  2424         
       
  2425     if (aNoMatchState)
       
  2426         {
       
  2427         iNoMatchState = aNoMatchState;
       
  2428         iRichText->InsertL(aPos, aNoMatchText);
       
  2429         iTextView->HandleInsertDeleteL(TCursorSelection(aPos+aNoMatchText.Length(), aPos),0);
       
  2430         SetSelectionL( TCursorSelection( aPos+aNoMatchText.Length(), aPos+aNoMatchText.Length() ));
       
  2431         }
       
  2432     else
       
  2433         {
       
  2434         iNoMatchState = aNoMatchState;
       
  2435 
       
  2436         iRichText->DeleteL(aPos, 1);
       
  2437         iTextView->HandleInsertDeleteL(TCursorSelection(aPos, aPos),1);
       
  2438         SetSelectionL( TCursorSelection( aPos - 1, aPos - 1 ) );
       
  2439         }         
       
  2440     }
       
  2441 
       
  2442 void CFepLayoutMultiLineIcfEditor::SetPromptTextFormatL(TInt aPromptTextLen)
       
  2443     {
       
  2444     if ( aPromptTextLen <= 0 )
       
  2445         {
       
  2446         return;
       
  2447         }
       
  2448     iCharFormatMask.ClearAll();
       
  2449     iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);//EStrokeWeightBold
       
  2450     iCharFormat.iFontPresentation.iUnderline = EUnderlineOff;
       
  2451     iCharFormatMask.SetAttrib(EAttFontStrokeWeight);
       
  2452     iCharFormatMask.SetAttrib( EAttFontUnderline );
       
  2453     iCharFormatMask.SetAttrib( EAttColor );
       
  2454     iCharFormat.iFontPresentation.iTextColor = iTextColor;
       
  2455 
       
  2456     // set prompt text as bold
       
  2457     iRichText->ApplyCharFormatL(iCharFormat, iCharFormatMask, 0, aPromptTextLen );//- 1
       
  2458     iTextView->HandleRangeFormatChangeL(TCursorSelection(0, aPromptTextLen ), ETrue);//- 1
       
  2459 
       
  2460     // set remain text as non-bold
       
  2461     iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
       
  2462     //iRichText->SetInsertCharFormatL(iCharFormat, iCharFormatMask, aPromptTextLen - 1);
       
  2463     }
       
  2464 
       
  2465 void CFepLayoutMultiLineIcfEditor::SetSpecialStateL(TBool aStateOn, 
       
  2466                                               TInt aStartPos, 
       
  2467                                               TInt aEndPos, 
       
  2468                                               TInt& aPreStartPos,
       
  2469                                               TInt& aPreEndPos,
       
  2470                                               TTextFormatAttribute aAttribute,
       
  2471                                               TBool aNoMatchState,
       
  2472                                               const TDesC& aNoMatchText)
       
  2473     {
       
  2474     iCharFormatMask.ClearAll();
       
  2475 
       
  2476     if (aAttribute == EAttFontUnderline)
       
  2477         {
       
  2478         // inline
       
  2479         // set original inline as non-inline
       
  2480         iCharFormat.iFontPresentation.iUnderline = EUnderlineOff;
       
  2481         }
       
  2482     else if (aAttribute == EAttColor)
       
  2483         {
       
  2484         // auto complete
       
  2485         // set original auto as non-auto
       
  2486         iCharFormat.iFontPresentation.iTextColor = iTextColor;
       
  2487         }
       
  2488     else
       
  2489         {
       
  2490         return;
       
  2491         }
       
  2492         
       
  2493     iCharFormatMask.SetAttrib(aAttribute);
       
  2494 
       
  2495     if (IsTextPosValid(aPreStartPos) && IsTextPosValid(aPreEndPos))
       
  2496         {
       
  2497         iRichText->ApplyCharFormatL(iCharFormat, iCharFormatMask, 0, 
       
  2498                                     iRichText->DocumentLength());
       
  2499         //iTextView->HandleRangeFormatChangeL(TCursorSelection(aPreStartPos, aPreEndPos), ETrue);    
       
  2500         } 
       
  2501 
       
  2502     aPreStartPos = 0;
       
  2503     aPreEndPos = 0;
       
  2504 
       
  2505     if (aStateOn)
       
  2506         {
       
  2507         if (aAttribute == EAttFontUnderline)
       
  2508             {
       
  2509             iCharFormat.iFontPresentation.iUnderline = EUnderlineOn;
       
  2510             UpdateNoMatchTextL(aEndPos, 
       
  2511                TFepLayoutMIcfNoMatchesInline::TextForUnknownPredictiveTextIndication(aNoMatchText),
       
  2512                aNoMatchState);
       
  2513             }
       
  2514         else if (aAttribute == EAttColor)
       
  2515             {
       
  2516             iCharFormat.iFontPresentation.iTextColor = iTextAutoColor;
       
  2517             }
       
  2518         iCharFormatMask.SetAttrib(aAttribute);
       
  2519 
       
  2520         if (aNoMatchState)
       
  2521             {
       
  2522             iRichText->ApplyCharFormatL(iCharFormat, iCharFormatMask, 
       
  2523                                         Min(aStartPos,aEndPos), Abs( aEndPos - aStartPos ) + 1);
       
  2524             iTextView->HandleRangeFormatChangeL(TCursorSelection(aStartPos, aEndPos + 1), ETrue);
       
  2525             }
       
  2526         else
       
  2527             {
       
  2528             iRichText->ApplyCharFormatL(iCharFormat, iCharFormatMask, 
       
  2529                                         Min(aStartPos,aEndPos), Abs( aEndPos - aStartPos ) );
       
  2530             iTextView->HandleRangeFormatChangeL(TCursorSelection(aStartPos, aEndPos), ETrue);
       
  2531             }
       
  2532 
       
  2533         aPreStartPos = aStartPos;
       
  2534         aPreEndPos = aEndPos;
       
  2535         }
       
  2536     }
       
  2537 
       
  2538 void CFepLayoutMultiLineIcfEditor::SetInlineStateL(TBool aInline, 
       
  2539                                              TInt aStartPos, 
       
  2540                                              TInt aEndPos, 
       
  2541                                              TBool aNoMatchState, 
       
  2542                                              const TDesC& aNoMatchText)
       
  2543     {
       
  2544     if (aInline)
       
  2545         iState = CFepLayoutMultiLineIcf::EIcfInline;
       
  2546     else
       
  2547         {
       
  2548         iState = CFepLayoutMultiLineIcf::EIcfNormal;
       
  2549         UpdateNoMatchTextL(iPreInlineEndPos, KNullDesC, EFalse);
       
  2550         }
       
  2551 
       
  2552     SetSpecialStateL(aInline, 
       
  2553                      aStartPos, 
       
  2554                      aEndPos, 
       
  2555                      iPreInlineStartPos, 
       
  2556                      iPreInlineEndPos, 
       
  2557                      EAttFontUnderline, 
       
  2558                      aNoMatchState, 
       
  2559                      aNoMatchText);
       
  2560     }
       
  2561 
       
  2562 void CFepLayoutMultiLineIcfEditor::SetAutoCompleteStateL(TBool aAutoComplete, 
       
  2563                                                    TInt aStartPos, 
       
  2564                                                    TInt aMidPos,
       
  2565                                                    TInt aEndPos)
       
  2566     {
       
  2567     iAutoComplete = aAutoComplete;
       
  2568     
       
  2569     if ( aAutoComplete )
       
  2570         {
       
  2571         iState = CFepLayoutMultiLineIcf::EIcfAutoComplete;
       
  2572         }
       
  2573     else
       
  2574         {
       
  2575         iState = CFepLayoutMultiLineIcf::EIcfNormal;
       
  2576         }
       
  2577         
       
  2578     SetSpecialStateL(aAutoComplete, 
       
  2579                      aStartPos, 
       
  2580                      aMidPos, 
       
  2581                      iPreInlineStartPos, 
       
  2582                      iPreInlineEndPos, 
       
  2583                      EAttFontUnderline);
       
  2584                      
       
  2585     SetSpecialStateL(aAutoComplete, 
       
  2586                      aMidPos, 
       
  2587                      aEndPos, 
       
  2588                      iPreAutoStartPos, 
       
  2589                      iPreAutoEndPos, 
       
  2590                      EAttColor);
       
  2591     }
       
  2592 
       
  2593 TAknsItemID CFepLayoutMultiLineIcfEditor::BgImgSkinId() const
       
  2594     {
       
  2595     if (iSkinIdSet)
       
  2596         {
       
  2597         return iBgSkinId;
       
  2598         }
       
  2599 
       
  2600     return KAknsIIDNone;
       
  2601     }
       
  2602 TBool CFepLayoutMultiLineIcfEditor::IsEmpty()
       
  2603     {
       
  2604     TPtrC icftext = iRichText->Read(0, iRichText->DocumentLength());
       
  2605     return (icftext.Length() - iPromptTextLen <= 0);
       
  2606     }
       
  2607 
       
  2608 void CFepLayoutMultiLineIcfEditor::InlineTextPos(TPoint& aPosBelow, TPoint& aPosRight)
       
  2609     {
       
  2610     if ( InlineStateOn() || AutoCompletionStateOn() )
       
  2611         {
       
  2612         TRAP_IGNORE(iTextView->DocPosToXyPosL(iPreInlineStartPos, aPosBelow));
       
  2613         TRAP_IGNORE(iTextView->DocPosToXyPosL(iPreInlineEndPos, aPosRight));
       
  2614         }
       
  2615     }
       
  2616     
       
  2617 void CFepLayoutMultiLineIcfEditor::AdjustBmpDeviceIfNeeded()
       
  2618     {
       
  2619     TSize deviceSz = BitmapDevice()->SizeInPixels();
       
  2620     if( ! (deviceSz == iLastDeviceSize) )
       
  2621         {
       
  2622         TRAP_IGNORE(iTextView->SetDisplayContextL(BitmapDevice(), NULL, NULL, NULL));
       
  2623         iLastDeviceSize = deviceSz;
       
  2624         //reset font
       
  2625         //ResetApplyFont();
       
  2626         iFormatChange = ETrue;
       
  2627         }    
       
  2628     }
       
  2629     
       
  2630 CBubbleCtrl* CFepLayoutMultiLineIcfEditor::MsgBubbleCtrl()
       
  2631     {
       
  2632     return iMsgBubble;
       
  2633     }
       
  2634             
       
  2635 void CFepLayoutMultiLineIcfEditor::ShowBubble(const TDesC& aText, const TRect& /*aRect*/)
       
  2636     {
       
  2637     TRAP_IGNORE(iMsgBubble->SetTextL(aText));
       
  2638     iHideBubbleTemp = ETrue;
       
  2639     SetMsgBubbleRect();
       
  2640     }
       
  2641     
       
  2642 void CFepLayoutMultiLineIcfEditor::ShowByteWarningBubble(const TDesC& aInfo)
       
  2643     {
       
  2644     TSize size = iInfoBubble->Rect().Size();
       
  2645     CFont::TMeasureTextInput*  input = new (ELeave) CFont::TMeasureTextInput;
       
  2646     CleanupStack::PushL(input);
       
  2647     input->iMaxBounds = iRect.Width();
       
  2648     TInt width = iFont->MeasureText(aInfo, input, NULL);
       
  2649     CleanupStack::PopAndDestroy();
       
  2650     size.SetSize(width, size.iHeight);
       
  2651     SetInfoBubbleCtrlSize(size);
       
  2652     TRAP_IGNORE(iInfoBubble->SetTextL(aInfo));
       
  2653     iHideInfoBubbleTemp = ETrue;
       
  2654     SetInfoBubbleRect();
       
  2655     }
       
  2656 void CFepLayoutMultiLineIcfEditor::HideBubble()
       
  2657     {
       
  2658     if ( iMsgBubble->IsShowing() )
       
  2659         {
       
  2660         iMsgBubble->Hide( ETrue );
       
  2661         }
       
  2662 	iHideBubbleTemp = EFalse;
       
  2663     }
       
  2664 void CFepLayoutMultiLineIcfEditor::HideInfoBubble()
       
  2665     {
       
  2666    if ( iInfoBubble->IsShowing() )
       
  2667         {
       
  2668         iInfoBubble->Hide( ETrue );
       
  2669         }
       
  2670     iHideInfoBubbleTemp = EFalse;
       
  2671     }
       
  2672     
       
  2673 void CFepLayoutMultiLineIcfEditor::ApplyFormatL()
       
  2674     {
       
  2675     if( !iFormatChange )
       
  2676         {
       
  2677         return;
       
  2678         }
       
  2679     //apply line space
       
  2680     CParaFormat* paraFormat=CParaFormat::NewL();
       
  2681     CleanupStack::PushL( paraFormat );
       
  2682     TParaFormatMask paraFormatMask;
       
  2683     paraFormat->iVerticalAlignment = CParaFormat::ECenterAlign;
       
  2684     paraFormatMask.SetAttrib(EAttVerticalAlignment);
       
  2685     paraFormat->iLineSpacingInTwips = iCoeEnv->ScreenDevice()->VerticalPixelsToTwips(
       
  2686                                                                iLineSpace+iFontHeight);
       
  2687     iFormatLineHeight = 0;
       
  2688     
       
  2689     paraFormatMask.SetAttrib(EAttLineSpacing);
       
  2690     iRichText->ApplyParaFormatL(paraFormat,
       
  2691 	                            paraFormatMask,
       
  2692 	                            0,
       
  2693 	                            iRichText->DocumentLength());
       
  2694     CleanupStack::PopAndDestroy(paraFormat);
       
  2695     
       
  2696     //apply font
       
  2697     SetCursorSizeAndType();
       
  2698     
       
  2699     iFormatChange = EFalse;
       
  2700 
       
  2701     iTextView->FormatTextL();
       
  2702     }
       
  2703 
       
  2704 TInt CFepLayoutMultiLineIcfEditor::TextWidth( const TDesC& aText )
       
  2705     {
       
  2706     return iFont->TextWidthInPixels( aText );
       
  2707     }
       
  2708     
       
  2709 void CFepLayoutMultiLineIcfEditor::AdjustPromptTextL()
       
  2710     {
       
  2711     if ( iInitPromptText )
       
  2712         {
       
  2713         SetPromptTextL( *iInitPromptText, EFalse );	
       
  2714         }
       
  2715     }
       
  2716     
       
  2717 void CFepLayoutMultiLineIcfEditor::ResetApplyFont()
       
  2718     {
       
  2719     TInt fontHeight = iFontHeight; 
       
  2720     TInt maxFontHeight = iMaxFontHeight;
       
  2721     const CFont *font = iFont;
       
  2722     
       
  2723     iFontHeight = 0;
       
  2724     TRAP_IGNORE(SetFontL(fontHeight, maxFontHeight, font));
       
  2725     }
       
  2726 
       
  2727 void CFepLayoutMultiLineIcfEditor::TryDisplayMaxTextL( TInt aCursorPos )
       
  2728     {
       
  2729     iTextView->FinishBackgroundFormattingL();
       
  2730     TInt lineIndex = iLayout->GetLineNumber( aCursorPos );
       
  2731 
       
  2732     if ( aCursorPos >= 0 )
       
  2733         {
       
  2734         TPoint cursorPt;
       
  2735         TRAP_IGNORE(iTextView->DocPosToXyPosL(iCursorSel.iCursorPos, cursorPt));
       
  2736         CalculateCursorPos(cursorPt);
       
  2737         if ( !iViewRect.Contains( cursorPt ) && ( lineIndex + 1 ) > ( iLineMaxCount - 1 ) )
       
  2738             {
       
  2739             iTextView->SetViewLineAtTopL(( lineIndex + 1 ) - ( iLineMaxCount - 1 ));
       
  2740             RecalcualteTextPositionL();
       
  2741             SetMsgBubbleRect();
       
  2742             }
       
  2743         }
       
  2744     
       
  2745     const TInt lineCount = iLayout->NumFormattedLines();
       
  2746    
       
  2747     if( lineIndex == lineCount - 1 )
       
  2748         {
       
  2749         TInt pageCount = iViewRect.Height()/iFormatLineHeight;
       
  2750         TPoint ptCursor = iInsertionPoint->Position() ;
       
  2751         TInt lineCursor = ( ptCursor.iY + iInsertionPoint->Height() / 2 
       
  2752                             - iViewRect.iTl.iY) / iFormatLineHeight + 1;
       
  2753         if( lineCursor < pageCount )
       
  2754             {
       
  2755             
       
  2756             iTextView->SetViewLineAtTopL( 
       
  2757                                    lineCount - pageCount + 1 < 1 ? 1 : lineCount - pageCount + 1 );
       
  2758             
       
  2759             RecalcualteTextPositionL();
       
  2760             SetMsgBubbleRect();
       
  2761             }
       
  2762         }
       
  2763     }
       
  2764     
       
  2765 void CFepLayoutMultiLineIcfEditor::DrawIcfBackground( CFbsBitGc& /*aGc*/, const TRect& aDrawnRect, 
       
  2766                                                       TBool /*aBmpStretchFlag*/ )
       
  2767 	{
       
  2768 	DrawBackground( aDrawnRect );
       
  2769 	}
       
  2770 	
       
  2771 void CFepLayoutMultiLineIcfEditor::GraphicDeviceSizeChanged()
       
  2772     {
       
  2773     AdjustBmpDeviceIfNeeded();    
       
  2774     }
       
  2775 
       
  2776 void CFepLayoutMultiLineIcfEditor::ExtractText(TDes &aBuf, TInt aPos, TInt aLength)
       
  2777     {
       
  2778     if ( aPos < 0 )
       
  2779         {
       
  2780         aBuf = KNullDesC();
       
  2781         return;
       
  2782         }
       
  2783     iRichText->Extract( aBuf, aPos + iPromptTextLen, aLength);
       
  2784     } 
       
  2785 
       
  2786 void CFepLayoutMultiLineIcfEditor::AdjustSelectionL( const TCursorSelection& aCurSel )
       
  2787     {
       
  2788     if (!IsTextPosValid(aCurSel.LowerPos()) || 
       
  2789     !IsTextPosValid(aCurSel.HigherPos()) )
       
  2790 		{
       
  2791 		return;
       
  2792 		}
       
  2793 
       
  2794     iCursorSel = aCurSel;   
       
  2795    
       
  2796     if ( BelongToPromptText(aCurSel.iCursorPos) )
       
  2797         {
       
  2798         //pls refer to bug: ELWG-7MZ5EZ, why to use iPromptText->Length() instead of iPromptTextLen 
       
  2799         //iCursorSel.iCursorPos = iPromptTextLen;
       
  2800         iCursorSel.iCursorPos = iPromptText->Length();
       
  2801         }
       
  2802     if ( BelongToPromptText(aCurSel.iAnchorPos) )
       
  2803         {
       
  2804         //pls refer to bug: ELWG-7MZ5EZ, why to use iPromptText->Length() instead of iPromptTextLen
       
  2805         //iCursorSel.iAnchorPos = iPromptTextLen;
       
  2806         iCursorSel.iAnchorPos = iPromptText->Length();
       
  2807         }
       
  2808  
       
  2809     iTextView->SetSelectionL( iCursorSel );
       
  2810     iTextView->SetSelectionVisibilityL( iCursorSelVisible );
       
  2811     }  
       
  2812 
       
  2813 void CFepLayoutMultiLineIcfEditor::ReDrawRect(const TRect& aRect)
       
  2814     {
       
  2815     Draw();
       
  2816     
       
  2817     if(aRect.Intersects(iInsertionPoint->Rect()))
       
  2818         {
       
  2819         iInsertionPoint->ReDraw();
       
  2820         }
       
  2821     }
       
  2822 void CFepLayoutMultiLineIcfEditor::SetNumberGroupingL(TBool aIsNumberGrouping)
       
  2823     {
       
  2824     if(aIsNumberGrouping)
       
  2825         {
       
  2826         if(!iFormExtendedInterfaceProvider)
       
  2827             {
       
  2828             iFormExtendedInterfaceProvider = CAknEdwinFormExtendedInterfaceProvider::NewL();
       
  2829             }
       
  2830         if(!iPhoneNumberFormatter && iRichText)
       
  2831             {
       
  2832             CAknPhoneNumberInlineTextSource* phoneNumberFormatter = 
       
  2833             CAknPlainPhoneNumberInlineTextSource::NewL( *iRichText );
       
  2834             CleanupStack::PushL( phoneNumberFormatter );
       
  2835             iFormExtendedInterfaceProvider->
       
  2836                 CompositeInlineTextSource().InstallInlineTextSourceL( phoneNumberFormatter );
       
  2837             CleanupStack::Pop( phoneNumberFormatter );
       
  2838             iPhoneNumberFormatter = phoneNumberFormatter;
       
  2839             
       
  2840             // regist custerm form
       
  2841             iLayout->SetInterfaceProvider( iFormExtendedInterfaceProvider );
       
  2842             }
       
  2843         }
       
  2844     else
       
  2845         {
       
  2846         // un-regist custerm form
       
  2847         iLayout->SetInterfaceProvider( NULL );
       
  2848         delete iFormExtendedInterfaceProvider;
       
  2849         iFormExtendedInterfaceProvider = NULL;
       
  2850         iPhoneNumberFormatter = NULL;
       
  2851         }
       
  2852     }
       
  2853 
       
  2854 void CFepLayoutMultiLineIcfEditor::TrimCustomDrawText( TDes& aText )
       
  2855     {
       
  2856     TInt index = -1;
       
  2857     const TText KTrimChar = 0xFFFF;
       
  2858     for ( TInt i = 0; i < aText.Length() && aText[i] == KTrimChar; i++ )
       
  2859         {        
       
  2860         index = i;
       
  2861         }
       
  2862     if ( index != -1 )
       
  2863         {
       
  2864         aText.Delete( 0, index + 1 );
       
  2865         }
       
  2866     index = -1;
       
  2867     for ( TInt i = aText.Length() - 1; i >= 0 && aText[i] == KTrimChar; i-- )
       
  2868         {
       
  2869         index = i;
       
  2870         }
       
  2871     if ( index != -1 )
       
  2872         {
       
  2873         aText.Delete( index, aText.Length() - index );
       
  2874         }        
       
  2875     }
       
  2876 
       
  2877 TBool CFepLayoutMultiLineIcfEditor::SmileyEnabled()
       
  2878     {
       
  2879     return ETrue;
       
  2880     }
       
  2881 
       
  2882 CPeninputSmileyManager* CFepLayoutMultiLineIcfEditor::SmileyManager()
       
  2883     {
       
  2884     return iSmileyManager;
       
  2885     }
       
  2886 
       
  2887 void CFepLayoutMultiLineIcfEditor::CalcSmileyClipRegionL( RRegion& aRgn, 
       
  2888                                                           CGraphicsContext& aGc, 
       
  2889                                                           CFont& aFont,  
       
  2890                                                           const TDesC& aText, 
       
  2891                                                           TPoint& aBasePoint, 
       
  2892                                                           TInt aTopLine, 
       
  2893                                                           TInt aBottomLine )
       
  2894     {
       
  2895     TRect rectCurLine =iViewRect;
       
  2896     rectCurLine.iTl.iY = aTopLine;
       
  2897     rectCurLine.iBr.iY = aBottomLine;
       
  2898     aRgn.AddRect( rectCurLine );
       
  2899     
       
  2900     HBufC* buf = aText.Alloc();
       
  2901     CleanupStack::PushL( buf );
       
  2902     TPtr text = buf->Des();
       
  2903     TrimCustomDrawText( text );
       
  2904     
       
  2905     TInt docpos = iTextView->XyPosToDocPosL( aBasePoint );
       
  2906     
       
  2907     for ( TInt i = 0; i < text.Length(); i++ )
       
  2908         {
       
  2909         if ( iSmileyManager->IsSmileyCode( text[i] ) )
       
  2910             {
       
  2911             TPoint point(0,0);
       
  2912             iTextView->DocPosToXyPosL( docpos + i, point );
       
  2913             
       
  2914             TInt charwidth = aFont.CharWidthInPixels( text[i] );
       
  2915             
       
  2916             TInt x = point.iX;
       
  2917             TRect rc( TPoint(x,aTopLine), TSize(charwidth,aBottomLine - aTopLine) );
       
  2918             aRgn.SubRect( rc, NULL );
       
  2919             }
       
  2920         }
       
  2921     
       
  2922     CleanupStack::PopAndDestroy( buf );
       
  2923     }
       
  2924 
       
  2925 void CFepLayoutMultiLineIcfEditor::CustomDrawSmileyL( CGraphicsContext& aGc, 
       
  2926                                                       CFont& aFont, 
       
  2927                                                       const TDesC& aText, 
       
  2928                                                       TPoint& aBasePoint,
       
  2929                                                       TInt aTopLine, 
       
  2930                                                       TInt aBottomLine )
       
  2931     {
       
  2932     if( &aGc != static_cast<CGraphicsContext*>(iTextView->BitmapContext()) )
       
  2933         {
       
  2934         return;
       
  2935         }
       
  2936     
       
  2937     CBitmapContext& gc = static_cast<CBitmapContext&>( aGc );
       
  2938     
       
  2939     TInt smileyWidth = aFont.TextWidthInPixels( iSmileyManager->SmileySizeTemplate() );
       
  2940     
       
  2941     TInt startDocPos = iTextView->XyPosToDocPosL( aBasePoint );
       
  2942     
       
  2943     HBufC* buf = aText.Alloc();
       
  2944     CleanupStack::PushL( buf );
       
  2945     
       
  2946     TPtr text = buf->Des();
       
  2947     
       
  2948     TrimCustomDrawText( text );
       
  2949     
       
  2950     for ( TInt i = 0; i < text.Length(); i++ )
       
  2951         {
       
  2952         if ( iSmileyManager->IsSmileyCode( text[i] ) )
       
  2953             {
       
  2954             TPoint pt;
       
  2955             iTextView->DocPosToXyPosL( startDocPos + i, pt );
       
  2956             TInt x = pt.iX;
       
  2957             TRect rect( x, aTopLine, x + smileyWidth, aBottomLine );
       
  2958             
       
  2959             TInt code = text[i];
       
  2960             
       
  2961             CPeninputSmileyImage* smiley = iSmileyManager->SmileyImage( code );
       
  2962             if ( smiley )
       
  2963                 {
       
  2964                 gc.SetBrushColor( TRgb(255,0,0) );
       
  2965                 gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
  2966                 
       
  2967                 smiley->SetImageSize( rect.Size() );
       
  2968                 
       
  2969                 if ( smiley->MaskBitmap() )
       
  2970                     {
       
  2971                     TRect rcsrc( TPoint(0,0), rect.Size() );
       
  2972                     gc.BitBltMasked( rect.iTl, smiley->ImageBitmap(), rcsrc, 
       
  2973                                      smiley->MaskBitmap(), EFalse );
       
  2974                     }
       
  2975                 else
       
  2976                     {
       
  2977                     gc.BitBlt( rect.iTl, smiley->ImageBitmap() );
       
  2978                     }
       
  2979                 }
       
  2980             }
       
  2981         }
       
  2982     
       
  2983     CleanupStack::PopAndDestroy( buf );
       
  2984     }
       
  2985 
       
  2986 void CFepLayoutMultiLineIcfEditor::ApplyLineSpaceFormatL( TInt aLineHeight )
       
  2987     {
       
  2988     //apply line space
       
  2989     CParaFormat* paraFormat=CParaFormat::NewL();
       
  2990     CleanupStack::PushL( paraFormat );
       
  2991     TParaFormatMask paraFormatMask;
       
  2992     paraFormat->iLineSpacingInTwips = 
       
  2993         iCoeEnv->ScreenDevice()->VerticalPixelsToTwips( aLineHeight );
       
  2994     paraFormatMask.SetAttrib(EAttLineSpacing);
       
  2995     iRichText->ApplyParaFormatL(paraFormat,
       
  2996 	                            paraFormatMask,
       
  2997 	                            0,
       
  2998 	                            iRichText->DocumentLength());
       
  2999     CleanupStack::PopAndDestroy(paraFormat);
       
  3000     
       
  3001     iTextView->FormatTextL();
       
  3002     }
       
  3003 
       
  3004 void CFepLayoutMultiLineIcfEditor::CalcPromptTextRectL()
       
  3005     {
       
  3006     if ( iPromptTextLen <= 0 )
       
  3007         {
       
  3008         iPromptTextRect.SetSize( TSize( 0,0 ) );
       
  3009         return;
       
  3010         }
       
  3011     
       
  3012     TPoint tlBaseLine( 0,0 );
       
  3013     TPoint brBaseLine( 0,0 );
       
  3014     TPoint tl( 0,0 );
       
  3015     TPoint br( 0,0 );
       
  3016     TRAP_IGNORE( iTextView->DocPosToXyPosL(0, tlBaseLine) );
       
  3017     TRAP_IGNORE( iTextView->DocPosToXyPosL(iPromptTextLen - 1, brBaseLine) );
       
  3018     
       
  3019     if ( tlBaseLine.iY != brBaseLine.iY )
       
  3020         {
       
  3021         return;
       
  3022         }
       
  3023     TInt topY = tlBaseLine.iY - iFont->AscentInPixels();
       
  3024     TInt bottomY = br.iY = tlBaseLine.iY + iFont->DescentInPixels();
       
  3025     
       
  3026     iPromptTextRect = TRect( tlBaseLine.iX, topY, brBaseLine.iX, bottomY );
       
  3027     }
       
  3028 // End Of File