fep/aknfep/UiPlugins/AknFepUiInterface/AvkonImpl/src/aknfepuictrleepcontrol.cpp
changeset 36 a7632c26d895
parent 35 0f326f2e628e
child 42 b3eaa440ab06
equal deleted inserted replaced
35:0f326f2e628e 36:a7632c26d895
     1 /*
       
     2 * Copyright (c) 2008 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  *      Provides the CAknFepUICtrlEEPControl definition 
       
    16  *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include <eikappui.h>
       
    31 #include <eikenv.h> 
       
    32 #include <AknUtils.h> 
       
    33 #include <AknBidiTextUtils.h> //AknBidiTextUtils 
       
    34 #include <bidivisual.h> //TBidiLogicalToVisual
       
    35 #include <AknsSkinInstance.h> 
       
    36 #include <AknsDrawUtils.h> 
       
    37 #include <skinlayout.cdl.h>
       
    38 #include "aknlayoutscalable_avkon.cdl.h"
       
    39 
       
    40 #include "aknfepuictrleepcontrol.h"
       
    41 #include "insertionpoint.h"
       
    42 #include "aknfepuilayoutdatamgr.h"
       
    43 #include "aknfepchineseuidataconv.h"
       
    44 
       
    45 const TInt KMaxDispNum = 100;
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // NewL function.
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 CAknFepUICtrlEEPControl* CAknFepUICtrlEEPControl::NewL( RWindow& aParent, CAknFepUiLayoutDataMgr* aLafDataMgr )
       
    52     {
       
    53     CAknFepUICtrlEEPControl* self= CAknFepUICtrlEEPControl::NewLC( aParent, aLafDataMgr );
       
    54     CleanupStack::Pop( self ); // self;
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // NewLC function.
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 CAknFepUICtrlEEPControl* CAknFepUICtrlEEPControl::NewLC( RWindow& aParent, CAknFepUiLayoutDataMgr* aLafDataMgr )
       
    63     {
       
    64     CAknFepUICtrlEEPControl* self = new ( ELeave ) CAknFepUICtrlEEPControl(aLafDataMgr);
       
    65     CleanupStack::PushL( self ) ;
       
    66     self->ConstructL( aParent );
       
    67     return self;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // Cancel and destroy.
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 CAknFepUICtrlEEPControl::~CAknFepUICtrlEEPControl( )
       
    75     {
       
    76     if ( iBuffer )
       
    77         {
       
    78         delete iBuffer;
       
    79         iBuffer = NULL;
       
    80         }
       
    81     if ( iInsertionPoint )
       
    82         {
       
    83         delete iInsertionPoint;
       
    84         iInsertionPoint = NULL;
       
    85         }
       
    86     iArray.ResetAndDestroy( );
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------
       
    90 // Draw the control.
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 void CAknFepUICtrlEEPControl::Draw( const TRect& /*aRect*/ ) const
       
    94     {
       
    95     CWindowGc& gc = SystemGc( );
       
    96     TAknTextLineLayout textPaneTextLayout;
       
    97     gc.Clear( Rect( ) ) ;
       
    98     gc.SetPenStyle( CGraphicsContext::ESolidPen ) ;
       
    99     TInt fontWidth = 0;
       
   100     TRect editRectTmp;
       
   101     MAknsSkinInstance* skin = AknsUtils::SkinInstance( );
       
   102     TRect outerRect;
       
   103     TRect innerRect;
       
   104     CalculateFrameRects( outerRect, innerRect ) ;
       
   105 
       
   106     AknsDrawUtils::DrawFrame( skin, gc, outerRect, innerRect,
       
   107         KAknsIIDQsnFrPopupSub, KAknsIIDQsnFrPopupCenterSubmenu ) ;
       
   108 
       
   109     TRect textrect;
       
   110     textrect.iTl = Rect().iTl + TPoint( Rect().Width( )*KLROffset/KDenominator, 3 ) ;
       
   111     textrect.SetHeight( Rect().Height( ) ) ;
       
   112     textrect.SetWidth( Rect().Width( )- Rect().Width( )*KLROffset/KDenominator * 2 ) ;
       
   113 
       
   114         TAknLayoutText layoutText;
       
   115         TAknTextLineLayout
       
   116             textLayout=
       
   117             AKN_LAYOUT_TEXT_Chinese_universal_FEP_entry_pane_texts_Line_1( 0);
       
   118         layoutText.LayoutText( textrect, textLayout ) ;
       
   119         const CFont* font = layoutText.Font( );
       
   120         gc.UseFont( font ) ;
       
   121     TInt baseLine = font->AscentInPixels( )/2 + Rect().Height( )/2 - 2;
       
   122 
       
   123     TInt arrayCount = iArray.Count( );
       
   124     TInt beg = 0;
       
   125     TInt end = iBuffer->Length( ) - 1;
       
   126     
       
   127     for ( TInt i = 0; i < arrayCount; i++ )
       
   128         {
       
   129         TSegment* tmp = iArray[i];
       
   130         fontWidth = font->TextWidthInPixels( iBuffer->Left( beg ) ) ;
       
   131         editRectTmp = textrect;
       
   132         editRectTmp.iTl.iX = textrect.iTl.iX + fontWidth;
       
   133         gc.SetPenColor( iDefaultTextColor ) ;
       
   134         gc.SetUnderlineStyle( EUnderlineOff ) ;
       
   135         gc.DrawText( iBuffer->Mid( beg, tmp->iBegin - beg ) , editRectTmp,
       
   136             baseLine ) ;
       
   137         fontWidth = font->TextWidthInPixels( iBuffer->Left( tmp->iBegin ) ) ;
       
   138         editRectTmp = textrect;
       
   139         editRectTmp.iTl.iX = textrect.iTl.iX + fontWidth;
       
   140         if ( tmp->iStyle == EHighlight )
       
   141             {
       
   142             gc.SetPenColor( iHighlightColor ) ;
       
   143             }
       
   144         else if ( tmp->iStyle == EUnderline )
       
   145             {
       
   146             gc.SetUnderlineStyle( EUnderlineOn ) ;
       
   147             }
       
   148         else if ( tmp->iStyle == EUnderlineHighlight )
       
   149             {
       
   150             gc.SetPenColor( iHighlightColor ) ;
       
   151             gc.SetUnderlineStyle( EUnderlineOn ) ;
       
   152             }
       
   153         gc.DrawText(
       
   154             iBuffer->Mid( tmp->iBegin, tmp->iEnd - tmp->iBegin + 1 ) ,
       
   155             editRectTmp, baseLine ) ;
       
   156         beg = tmp->iEnd + 1;
       
   157         }
       
   158     gc.SetPenColor( iDefaultTextColor ) ;
       
   159     gc.SetUnderlineStyle( EUnderlineOff ) ;
       
   160     fontWidth = font->TextWidthInPixels( iBuffer->Left( beg ) ) ;
       
   161     editRectTmp = textrect;
       
   162     editRectTmp.iTl.iX = textrect.iTl.iX + fontWidth;
       
   163     gc.DrawText( iBuffer->Right( end - beg + 1 ) , editRectTmp, baseLine ) ;
       
   164     gc.DiscardFont( );
       
   165     
       
   166     if ( isCursorDraw )
       
   167         {
       
   168         iInsertionPoint->SetTextRect( textrect ) ;
       
   169         //iInsertionPoint->SetHeight( font->HeightInPixels( ) + 4 ) ;
       
   170         iInsertionPoint->SetHeight();
       
   171         iInsertionPoint->Draw( gc ) ;
       
   172         }
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------
       
   176 // From CCoeControl.
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 void CAknFepUICtrlEEPControl::SizeChanged( )
       
   180     {
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------
       
   184 // Set the visual text and store it into member data buffer.
       
   185 // ---------------------------------------------------------
       
   186 //
       
   187 void CAknFepUICtrlEEPControl::SetText( const TDesC& aDes )
       
   188     {
       
   189     ResetAll( );
       
   190     * (this->iBuffer ) = aDes;
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------
       
   194 // Set the cursor position in the visual text rect.
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 TInt CAknFepUICtrlEEPControl::SetCursorPosition( TInt aIndex )
       
   198     {
       
   199     if ( aIndex < 0 || aIndex> iBuffer->Length() + 1 )
       
   200         {
       
   201         return -1;
       
   202         }
       
   203     else
       
   204         {
       
   205         iCursorPosition = aIndex;
       
   206         TInt offSetInPixel = 0;
       
   207         TAknTextLineLayout textPaneTextLayout = 
       
   208             CAknFepChineseUIDataConv::AnyToTextLine( iLafDataMgr->RequestData( EEEPTextLine ));
       
   209         const CFont* font = AknLayoutUtils::FontFromId ( textPaneTextLayout.iFont,
       
   210             NULL );
       
   211         offSetInPixel = font->TextWidthInPixels ( iBuffer->Left ( iCursorPosition ) );
       
   212         this->iInsertionPoint->SetPosition ( offSetInPixel );
       
   213         return 0;
       
   214         }
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------
       
   218 // Get the cursor position in visual text.
       
   219 // ---------------------------------------------------------
       
   220 //
       
   221 TInt CAknFepUICtrlEEPControl::GetCursorPosition( )
       
   222     {
       
   223     return iCursorPosition;
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------
       
   227 // Set the underlined text beginning index and ending index.
       
   228 // ---------------------------------------------------------
       
   229 //
       
   230 TInt CAknFepUICtrlEEPControl::SetUnderline( TInt aBeg, TInt aEnd )
       
   231     {
       
   232     if ( aBeg> aEnd 
       
   233     		|| ( aBeg < 0 || aBeg> iBuffer->Length() )
       
   234     		|| ( aEnd < 0 || aEnd> iBuffer->Length() ))
       
   235         {
       
   236         return -1;
       
   237         }
       
   238     else
       
   239         {
       
   240         SetSegment ( aBeg, aEnd, EUnderline );
       
   241         return 0;
       
   242         }
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // Set the highlighted text beginning index and ending index.
       
   247 // ---------------------------------------------------------
       
   248 //
       
   249 TInt CAknFepUICtrlEEPControl::SetHighlight( TInt aBeg, TInt aEnd )
       
   250     {
       
   251     if ( aBeg> aEnd 
       
   252     		|| ( aBeg < 0 || aBeg> iBuffer->Length() )
       
   253     		|| ( aEnd < 0 || aEnd> iBuffer->Length() ))
       
   254         {
       
   255         return -1;
       
   256         }
       
   257     else
       
   258         {
       
   259         SetSegment ( aBeg, aEnd, EHighlight );
       
   260         return 0;
       
   261         }
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------
       
   265 // Add a TSegment into iArray to identify the segment with a specified style.
       
   266 // ---------------------------------------------------------
       
   267 //
       
   268 void CAknFepUICtrlEEPControl::SetSegmentL ( TInt aBeg, TInt aEnd, TDspStyle aStyle )
       
   269     {
       
   270     TInt left = aBeg;
       
   271     TInt right = aEnd;
       
   272     TSegment* tmp;
       
   273     TSegment* newSeg;
       
   274     RPointerArray<TSegment> newArray;
       
   275     TBool consumed = EFalse;
       
   276     
       
   277     if ( iArray.Count() == 0 )
       
   278         {
       
   279         tmp = new ( ELeave )TSegment ( aBeg, aEnd, aStyle );
       
   280         TLinearOrder<TSegment> orderByBegIndex(TSegment::CompareByBegIndex);
       
   281         iArray.InsertInOrder ( tmp, orderByBegIndex );
       
   282         consumed = ETrue;
       
   283         return;
       
   284         }
       
   285     
       
   286     for ( TInt i = 0; i < iArray.Count(); i++ )
       
   287         {
       
   288         tmp = iArray[i];
       
   289         if ( left > tmp->iBegin && left < tmp->iEnd 
       
   290             && right > tmp->iEnd )
       
   291             {
       
   292             if ( aStyle == tmp->iStyle )
       
   293                 {
       
   294                 left = tmp->iEnd + 1;
       
   295                 }
       
   296             else
       
   297                 {
       
   298                 TInt tmpIndex = tmp->iEnd;
       
   299                 tmp->iEnd = left - 1;
       
   300                 newSeg = new ( ELeave ) TSegment ( left, tmpIndex, EUnderlineHighlight );
       
   301                 CleanupStack::PushL( newSeg );
       
   302                 newArray.AppendL( newSeg );
       
   303                 CleanupStack::Pop( newSeg );
       
   304                 left = tmpIndex + 1;
       
   305                 }
       
   306             }
       
   307         else if ( left < tmp->iBegin
       
   308             && right > tmp->iBegin && right < tmp->iEnd )
       
   309             {
       
   310             if ( aStyle == tmp->iStyle )
       
   311                 {
       
   312                 tmp->iBegin = left;
       
   313                 consumed = ETrue;
       
   314                 break;
       
   315                 }
       
   316             else
       
   317                 {
       
   318                 newSeg = new ( ELeave ) TSegment ( left, tmp->iBegin - 1, aStyle );
       
   319                 CleanupStack::PushL(newSeg);
       
   320                 newArray.AppendL( newSeg );
       
   321                 CleanupStack::Pop(newSeg);
       
   322                 newSeg = new ( ELeave ) TSegment ( tmp->iBegin, right, EUnderlineHighlight );
       
   323                 CleanupStack::PushL(newSeg);
       
   324                 newArray.AppendL( newSeg );
       
   325                 CleanupStack::Pop(newSeg);
       
   326                 tmp->iBegin = right + 1;
       
   327                 consumed = ETrue;
       
   328                 break;
       
   329                 }
       
   330             }
       
   331         else if ( left > tmp->iBegin && left < tmp->iEnd 
       
   332             && right > tmp->iBegin && right < tmp->iEnd )
       
   333             {
       
   334             if ( aStyle == tmp->iStyle )
       
   335                 {
       
   336                 consumed = ETrue;
       
   337                 break;
       
   338                 }
       
   339             else
       
   340                 {
       
   341                 newSeg = new ( ELeave ) TSegment ( tmp->iBegin, left - 1, tmp->iStyle );
       
   342                 CleanupStack::PushL(newSeg);
       
   343                 newArray.AppendL( newSeg );
       
   344                 CleanupStack::Pop(newSeg);
       
   345                 newSeg = new ( ELeave ) TSegment ( left, right, EUnderlineHighlight );
       
   346                 CleanupStack::PushL(newSeg);
       
   347                 newArray.AppendL( newSeg );
       
   348                 CleanupStack::Pop(newSeg);
       
   349                 tmp->iBegin = right + 1;
       
   350                 consumed = ETrue;
       
   351                 break;
       
   352                 }
       
   353             }
       
   354         else if ( left < tmp->iBegin && right > tmp->iEnd )
       
   355             {
       
   356             if ( aStyle == tmp->iStyle )
       
   357                 {
       
   358                 tmp->iBegin = left;
       
   359                 left = tmp->iEnd + 1;
       
   360                 }
       
   361             else
       
   362                 {
       
   363                 newSeg = new ( ELeave ) TSegment ( left, tmp->iBegin - 1, aStyle );
       
   364                 CleanupStack::PushL(newSeg);
       
   365                 newArray.AppendL( newSeg );
       
   366                 CleanupStack::Pop(newSeg);
       
   367                 tmp->iStyle = EUnderlineHighlight;
       
   368                 left = tmp->iEnd + 1;
       
   369                 }
       
   370             }
       
   371         else if ( left < tmp->iBegin && right < tmp->iBegin )
       
   372             {
       
   373             newSeg = new ( ELeave ) TSegment ( left, right, aStyle );
       
   374             CleanupStack::PushL(newSeg);
       
   375             newArray.AppendL( newSeg );
       
   376             CleanupStack::Pop(newSeg);
       
   377             consumed = ETrue;
       
   378             break;
       
   379             }
       
   380         else if ( left > tmp->iEnd && right > tmp->iEnd )
       
   381             {
       
   382             if ( i == ( iArray.Count() - 1 )
       
   383                 || right < iArray[i+1]->iBegin )
       
   384                 {
       
   385                 newSeg = new ( ELeave ) TSegment ( left, right, aStyle );
       
   386                 CleanupStack::PushL(newSeg);
       
   387                 newArray.AppendL( newSeg );
       
   388                 CleanupStack::Pop(newSeg);
       
   389                 consumed = ETrue;
       
   390                 break;
       
   391                 }
       
   392             }
       
   393         else if (left == tmp->iBegin && right < tmp->iEnd )
       
   394         	{
       
   395         	if ( aStyle == tmp->iStyle )
       
   396         		{
       
   397         		consumed = ETrue;
       
   398         		break;
       
   399         		}
       
   400         	else
       
   401         		{
       
   402         		newSeg = new ( ELeave ) TSegment ( left, right, EUnderlineHighlight );
       
   403                 CleanupStack::PushL(newSeg);
       
   404                 newArray.AppendL( newSeg );
       
   405                 CleanupStack::Pop(newSeg);
       
   406         		tmp->iBegin = right + 1;
       
   407         		consumed = ETrue;
       
   408         		break;
       
   409         		}
       
   410         	}
       
   411         else if (left > tmp->iBegin && right == tmp->iEnd )
       
   412         	{
       
   413         	if ( aStyle == tmp->iStyle )
       
   414         		{
       
   415         		consumed = ETrue;
       
   416         		break;
       
   417         		}
       
   418         	else
       
   419         		{
       
   420         		newSeg = new ( ELeave ) TSegment ( left, right, EUnderlineHighlight );
       
   421                 CleanupStack::PushL(newSeg);
       
   422                 newArray.AppendL( newSeg );
       
   423                 CleanupStack::Pop(newSeg);
       
   424         		tmp->iEnd = left - 1;
       
   425         		consumed = ETrue;
       
   426         		break;
       
   427         		}
       
   428         	}
       
   429         else if (left == tmp->iBegin && right == tmp->iEnd )
       
   430         	{
       
   431         	if ( aStyle == tmp->iStyle )
       
   432         		{
       
   433         		consumed = ETrue;
       
   434         		break;
       
   435         		}
       
   436         	else
       
   437         		{
       
   438         		tmp->iStyle = EUnderlineHighlight;
       
   439         		consumed = ETrue;
       
   440         		break;
       
   441         		}
       
   442         	}
       
   443         else if (left == tmp->iBegin && right > tmp->iEnd )
       
   444         	{
       
   445         	if ( aStyle == tmp->iStyle )
       
   446         		{
       
   447         		left = tmp->iEnd + 1;
       
   448         		}
       
   449         	else
       
   450         		{
       
   451         		tmp->iStyle = EUnderlineHighlight;
       
   452         		left = tmp->iEnd + 1;
       
   453         		}
       
   454         	}
       
   455         else if (left < tmp->iBegin && right == tmp->iEnd )
       
   456         	{
       
   457         	if ( aStyle == tmp->iStyle )
       
   458         		{
       
   459         		tmp->iBegin = left;
       
   460         		consumed = ETrue;
       
   461         		break;
       
   462         		}
       
   463         	else
       
   464         		{
       
   465         		newSeg = new ( ELeave ) TSegment ( left, tmp->iBegin - 1, aStyle );
       
   466                 CleanupStack::PushL(newSeg);
       
   467                 newArray.AppendL( newSeg );
       
   468                 CleanupStack::Pop(newSeg);
       
   469         		tmp->iStyle = EUnderlineHighlight;
       
   470         		consumed = ETrue;
       
   471         		break;
       
   472         		}
       
   473         	}
       
   474         else if (left == tmp->iEnd && tmp->iBegin < left )
       
   475         	{
       
   476         	if ( aStyle == tmp->iStyle )
       
   477         		{
       
   478         		left = tmp->iEnd + 1;
       
   479         		}
       
   480         	else
       
   481         		{
       
   482         		tmp->iEnd = tmp->iEnd - 1;
       
   483                 newSeg = new ( ELeave ) TSegment ( left, left, EUnderlineHighlight );
       
   484                 CleanupStack::PushL(newSeg);
       
   485                 newArray.AppendL( newSeg );
       
   486                 CleanupStack::Pop(newSeg);
       
   487                 left = left + 1;
       
   488         		}
       
   489         	}
       
   490         else if (right == tmp->iBegin && tmp->iEnd > right )
       
   491         	{
       
   492         	if ( aStyle == tmp->iStyle )
       
   493         		{
       
   494         		tmp->iBegin = left;
       
   495         		consumed = ETrue;
       
   496         		break;
       
   497         		}
       
   498         	else
       
   499         		{
       
   500         		tmp->iBegin = tmp->iBegin + 1;
       
   501                 newSeg = new ( ELeave ) TSegment ( right, right, EUnderlineHighlight );
       
   502                 CleanupStack::PushL(newSeg);
       
   503                 newArray.AppendL( newSeg );
       
   504                 CleanupStack::Pop(newSeg);
       
   505                 right = right - 1;
       
   506         		}
       
   507         	}
       
   508         }
       
   509     
       
   510     if ( consumed == EFalse )
       
   511     	{
       
   512     	newSeg = new ( ELeave ) TSegment ( left, right, aStyle );
       
   513         CleanupStack::PushL(newSeg);
       
   514         newArray.AppendL( newSeg );
       
   515         CleanupStack::Pop(newSeg);
       
   516     	consumed = ETrue;
       
   517     	}
       
   518     
       
   519     for ( TInt ii = 0; ii < newArray.Count();  ii++ )
       
   520         {
       
   521         TLinearOrder<TSegment> orderByBegIndex(TSegment::CompareByBegIndex);
       
   522         TSegment* tmp1 = newArray[ii];
       
   523         TInt err = 0;
       
   524         err = iArray.InsertInOrder ( newArray[ii], orderByBegIndex );
       
   525         if ( err == KErrAlreadyExists )
       
   526         	{
       
   527         	delete tmp1;
       
   528         	}
       
   529         }
       
   530     newArray.Reset();
       
   531     
       
   532     for ( TInt ii = 0; ii < iArray.Count() - 1; )
       
   533     	{
       
   534     	if ( iArray[ii]->iStyle == iArray[ii + 1]->iStyle 
       
   535     		&& iArray[ii]->iEnd + 1 == iArray[ii + 1]->iBegin )
       
   536     		{
       
   537     		iArray[ii]->iEnd = iArray[ii + 1]->iEnd;
       
   538     		TSegment* tmp1 = iArray[ii + 1];
       
   539     		iArray.Remove(ii + 1);
       
   540     		delete tmp1;
       
   541     		}
       
   542     	else
       
   543     		{
       
   544     		ii ++;
       
   545     		}
       
   546     	}
       
   547     return;
       
   548     }
       
   549 
       
   550 // ---------------------------------------------------------
       
   551 // Add a TSegment into iArray to identify the segment with a specified style.
       
   552 // ---------------------------------------------------------
       
   553 //
       
   554 void CAknFepUICtrlEEPControl::SetSegment( TInt aBeg, TInt aEnd, TDspStyle aStyle )
       
   555 	{
       
   556 	TRAP_IGNORE( SetSegmentL( aBeg,aEnd,aStyle ) );
       
   557 	}
       
   558 
       
   559 // ---------------------------------------------------------
       
   560 // Active the cursor,the cursor will be appeared with a glint.
       
   561 // ---------------------------------------------------------
       
   562 //
       
   563 void CAknFepUICtrlEEPControl::ActiveCursor( )
       
   564     {
       
   565     iInsertionPoint->Active( );
       
   566     }
       
   567 
       
   568 // ---------------------------------------------------------
       
   569 // Deactive the cursor, the cursor will be gray and with no glint.
       
   570 // ---------------------------------------------------------
       
   571 //
       
   572 void CAknFepUICtrlEEPControl::DeactiveCursor( )
       
   573     {
       
   574     iInsertionPoint->Deactive( );
       
   575     }
       
   576 
       
   577 // ---------------------------------------------------------
       
   578 // Enable the cursor.
       
   579 // ---------------------------------------------------------
       
   580 //
       
   581 void CAknFepUICtrlEEPControl::EnableCursor()
       
   582     {
       
   583     isCursorDraw = ETrue;
       
   584     DrawDeferred();
       
   585     }
       
   586 
       
   587 // ---------------------------------------------------------
       
   588 // Disable the cursor.
       
   589 // ---------------------------------------------------------
       
   590 //
       
   591 void CAknFepUICtrlEEPControl::DisableCursor()
       
   592     {
       
   593     isCursorDraw = EFalse;
       
   594     DrawDeferred();
       
   595     }
       
   596 
       
   597 // ---------------------------------------------------------
       
   598 // Move cursor to the left by a specified stride.
       
   599 // ---------------------------------------------------------
       
   600 //
       
   601 TInt CAknFepUICtrlEEPControl::MoveCursorLeft( TInt aStride )
       
   602     {
       
   603     TRect panerect = Rect( );
       
   604     TAknTextLineLayout textPaneTextLayout = 
       
   605         CAknFepChineseUIDataConv::AnyToTextLine( iLafDataMgr->RequestData( EEEPTextLine ));
       
   606     const CFont* font = AknLayoutUtils::FontFromId(
       
   607         textPaneTextLayout.iFont, NULL ) ;
       
   608     if ( iCursorPosition - aStride >= 0 
       
   609     	&& font->TextWidthInPixels( iBuffer->Left( iCursorPosition - aStride ) ) >= panerect.Width() * KLROffset / KDenominator)
       
   610         {
       
   611         iCursorPosition = iCursorPosition - aStride;
       
   612         TInt offSetInPixel = 0;
       
   613         offSetInPixel
       
   614             = font->TextWidthInPixels( iBuffer->Left( iCursorPosition ) ) ;
       
   615         this->iInsertionPoint->SetPosition( offSetInPixel ) ;
       
   616         return 0;
       
   617         }
       
   618     else
       
   619         {
       
   620         return -1;
       
   621         }
       
   622     }
       
   623 
       
   624 // ---------------------------------------------------------
       
   625 // Move cursor to the right by a specified stride.
       
   626 // ---------------------------------------------------------
       
   627 //
       
   628 TInt CAknFepUICtrlEEPControl::MoveCursorRight( TInt aStride )
       
   629     {
       
   630     TRect panerect = Rect( );
       
   631     TAknTextLineLayout textPaneTextLayout = 
       
   632             CAknFepChineseUIDataConv::AnyToTextLine( iLafDataMgr->RequestData( EEEPTextLine ));
       
   633     const CFont* font = AknLayoutUtils::FontFromId(
       
   634         textPaneTextLayout.iFont, NULL ) ;
       
   635     TInt lenBegToCursor = font->TextWidthInPixels( iBuffer->Left( iCursorPosition + aStride ) );
       
   636     if ( iBuffer->Length( ) >= iCursorPosition + aStride 
       
   637     	&& lenBegToCursor < panerect.Width() * KCursorResetStartOffset / KDenominator
       
   638     	)
       
   639         {
       
   640         iCursorPosition = iCursorPosition + aStride;
       
   641         TInt offSetInPixel = 0;
       
   642         offSetInPixel
       
   643             = font->TextWidthInPixels( iBuffer->Left( iCursorPosition ) );
       
   644         this->iInsertionPoint->SetPosition( offSetInPixel ) ;
       
   645         return 0;
       
   646         }
       
   647     else
       
   648         {
       
   649         return -1;
       
   650         }
       
   651     }
       
   652 
       
   653 // ---------------------------------------------------------
       
   654 // Called by the cursor object.
       
   655 // ---------------------------------------------------------
       
   656 //
       
   657 void CAknFepUICtrlEEPControl::Refresh( )
       
   658     {
       
   659     this->DrawDeferred( );
       
   660     }
       
   661 
       
   662 // ---------------------------------------------------------
       
   663 // C++ constructor.
       
   664 // ---------------------------------------------------------
       
   665 //
       
   666 CAknFepUICtrlEEPControl::CAknFepUICtrlEEPControl( CAknFepUiLayoutDataMgr* aLafDataMgr )
       
   667     {
       
   668     iBuffer = NULL;
       
   669     iInsertionPoint = NULL;
       
   670     iCursorPosition = 0;
       
   671     isCursorDraw = ETrue;
       
   672     iLafDataMgr = aLafDataMgr;
       
   673     }
       
   674 
       
   675 // ---------------------------------------------------------
       
   676 // Two-phrase constructor.
       
   677 // ---------------------------------------------------------
       
   678 //
       
   679 void CAknFepUICtrlEEPControl::ConstructL( RWindow& aParent )
       
   680     {
       
   681     SetContainerWindowL( aParent );
       
   682     this->iBuffer = HBufC::New( KMaxDispNum ) ;
       
   683     this->iInsertionPoint = CInsertionPoint::NewL( iLafDataMgr );
       
   684     this->iInsertionPoint->SetRefreshObserver( this ) ;
       
   685     iHighlightColor = KRgbRed;
       
   686     iDefaultTextColor = KRgbBlack;
       
   687     }
       
   688 
       
   689 // ---------------------------------------------------------
       
   690 // Reset all its member data to initialized state.
       
   691 // ---------------------------------------------------------
       
   692 //
       
   693 void CAknFepUICtrlEEPControl::ResetAll( )
       
   694     {
       
   695     iBuffer->Des().Zero( );
       
   696     iArray.ResetAndDestroy( );
       
   697     iCursorPosition = 0;
       
   698     isCursorDraw = ETrue;
       
   699     this->iInsertionPoint->SetPosition( 0 );
       
   700     }
       
   701 
       
   702 // ---------------------------------------------------------
       
   703 // Calculate the frame rect.
       
   704 // ---------------------------------------------------------
       
   705 //
       
   706 void CAknFepUICtrlEEPControl::CalculateFrameRects( TRect& aOuterRect,
       
   707     TRect& aInnerRect ) const
       
   708     {
       
   709     TRect windowRect = CAknFepChineseUIDataConv::AnyToRect( iLafDataMgr->RequestData( EPopupRectEEP ));
       
   710     TAknLayoutRect eepFirstHorizLineLayoutRect = CAknFepChineseUIDataConv::AnyToLayoutRect( iLafDataMgr->RequestData( EEEPFirstHorizLine ));
       
   711     TAknLayoutRect eepSecondHorizLineLayoutRect = CAknFepChineseUIDataConv::AnyToLayoutRect( iLafDataMgr->RequestData( EEEPSecondHorizLine ));
       
   712     TRect eepFirstHorizLineRect = eepFirstHorizLineLayoutRect.Rect();
       
   713     TRect eepSecondHorizLineRect = eepSecondHorizLineLayoutRect.Rect();
       
   714     TInt rectHeight = eepFirstHorizLineRect.iTl.iY - windowRect.iTl.iY;
       
   715     //TInt rectHeight = eepSecondHorizLineRect.iTl.iY - windowRect.iTl.iY - 1;
       
   716     TInt rectWidth = windowRect.Width( );
       
   717     windowRect.iTl.iX = 0;
       
   718     windowRect.iTl.iY = 0;
       
   719     windowRect.SetHeight( rectHeight ) ;
       
   720     windowRect.SetWidth( rectWidth ) ;
       
   721     TAknLayoutRect topLeft;
       
   722     topLeft.LayoutRect( windowRect,
       
   723         SkinLayout::Submenu_skin_placing_Line_2( ) ) ;
       
   724 
       
   725     TAknLayoutRect bottomRight;
       
   726     bottomRight.LayoutRect( windowRect,
       
   727         SkinLayout::Submenu_skin_placing_Line_5( ) ) ;
       
   728    
       
   729     aOuterRect = TRect( topLeft.Rect().iTl, bottomRight.Rect().iBr ) ;
       
   730     aInnerRect = TRect( topLeft.Rect().iBr, bottomRight.Rect().iTl ) ;
       
   731 //    aOuterRect.SetHeight();
       
   732 //    aInnerRect = aOuterRect;
       
   733     aInnerRect.iBr.iY = aOuterRect.iBr.iY;
       
   734     }
       
   735 
       
   736 // End of file