idlehomescreen/xmluirendering/renderingplugins/xntexteditorfactory/src/xntexteditoradapter.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Implementation wrapper for CEikEdwin
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <e32base.h>
       
    20 #include <e32const.h>
       
    21 #include <e32property.h>
       
    22 
       
    23 #include <eikedwin.h>
       
    24 #include <AknUtils.h>
       
    25 #include <AknsUtils.h>
       
    26 #include <aknview.h>
       
    27 #include <aknedsts.h>
       
    28 #include <AknPriv.hrh>
       
    29 #include <txtglobl.h>
       
    30 #include <txtfmlyr.h>
       
    31 #include <txtfrmat.h>
       
    32 #include <txtrich.h>
       
    33 #include <gdi.h>
       
    34 #include <gulutil.h>
       
    35 
       
    36 #include <activeidle2domainpskeys.h>
       
    37 
       
    38 // User includes
       
    39 #include "xnappuiadapter.h"
       
    40 #include "xndompropertyvalue.h"
       
    41 #include "xndomlist.h"
       
    42 #include "xndomproperty.h"
       
    43 #include "xnproperty.h"
       
    44 #include "xnnodepluginif.h"
       
    45 #include "xncontroladapter.h"
       
    46 #include "xntexteditoradapter.h"
       
    47 #include "xntexteditorpublisher.h"
       
    48 #include "xnnodepluginif.h"
       
    49 #include "xneditmode.h"
       
    50 #include "c_xnutils.h"
       
    51 #include "xntexteditor.h" 
       
    52 
       
    53 const TInt KMaxLength = 100;
       
    54 
       
    55 enum TSplitInputState
       
    56     {
       
    57     ESplitInputEnabled = 1,   
       
    58     ESplitInputOpen = 2,
       
    59     ESplitInputEditorInStack = 4,
       
    60     EScreenDeviceChanged = 8
       
    61     };
       
    62 
       
    63 _LIT8( KCpsPublishing, "cpspublishing" );
       
    64 _LIT8( KMaxLineAmount, "max-line-amount" );
       
    65 _LIT8( KMaxCharAmount, "max-char-amount" );
       
    66 _LIT8( KEnablePartialInput, "splitinputenabled" );
       
    67 _LIT8( KSplitScreenEnabledTrigger , "splitscreenenabled" );
       
    68 _LIT8( KSplitScreenDisabledTrigger, "splitscreendisabled" );
       
    69 
       
    70 _LIT( KEnterChar, "\x2029" );
       
    71 
       
    72 // Local macros
       
    73 #define IS_ARROW_KEY( k ) \
       
    74     ( k == EStdKeyLeftArrow || k == EStdKeyRightArrow || \
       
    75       k == EStdKeyUpArrow || k == EStdKeyDownArrow ) 
       
    76 
       
    77 // ============================ LOCAL FUNCTIONS ================================   
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 TBool IsFlagSet( TInt aFlags, TInt aFlag )
       
    83     {
       
    84     return aFlags & aFlag;
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void SetFlag( TInt& aFlags, TInt aFlag )
       
    91     {
       
    92     aFlags |= aFlag;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void ClearFlag( TInt& aFlags, TInt aFlag )
       
    99     {
       
   100     aFlags &= ~aFlag;
       
   101     }
       
   102 
       
   103 // ============================ MEMBER FUNCTIONS ===============================
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CXnTextEditorAdapter::NewL
       
   107 // Symbian static 1st phase constructor
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 CXnTextEditorAdapter* CXnTextEditorAdapter::NewL( CXnControlAdapter* aParent, 
       
   111     CXnNodePluginIf& aNode )
       
   112     {
       
   113 	CXnTextEditorAdapter* self = 
       
   114         new( ELeave ) CXnTextEditorAdapter( aParent, aNode );
       
   115 
       
   116     CleanupStack::PushL( self );
       
   117     self->ConstructL();
       
   118     CleanupStack::Pop( self );
       
   119 
       
   120     return self;	
       
   121     }
       
   122     
       
   123 // -----------------------------------------------------------------------------
       
   124 // CXnTextEditorAdapter::CXnTextEditorAdapter
       
   125 // C++ default constructor
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 CXnTextEditorAdapter::CXnTextEditorAdapter( CXnControlAdapter* aParent, 
       
   129     CXnNodePluginIf& aNode )
       
   130     : iParent( aParent ), iNode( aNode )
       
   131     {
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CXnTextEditorAdapter::~CXnTextEditorAdapter
       
   136 // C++ destructor
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 CXnTextEditorAdapter::~CXnTextEditorAdapter()
       
   140     {  
       
   141     if( IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )    
       
   142         {
       
   143         if( iUiEngine )
       
   144             {
       
   145             iUiEngine->EnablePartialTouchInput( iNode, EFalse );    
       
   146             }
       
   147         }
       
   148 
       
   149     if ( iAvkonAppUi )
       
   150         {
       
   151         iAvkonAppUi->RemoveFromStack( iEditor );
       
   152         }
       
   153     
       
   154     if( iFont && iReleaseFont )
       
   155         {
       
   156         CWsScreenDevice* dev( iCoeEnv->ScreenDevice() );
       
   157         dev->ReleaseFont( iFont );
       
   158         }
       
   159 
       
   160     delete iEditorPublisher;
       
   161     delete iEditor;   
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CXnTextEditorAdapter::ConstructL
       
   166 // Symbian 2nd phase constructor can leave.
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CXnTextEditorAdapter::ConstructL()
       
   170     {
       
   171     CXnControlAdapter::ConstructL( iNode );    
       
   172     iUiEngine = iNode.UiEngineL();
       
   173 
       
   174     iAppui = static_cast< CXnAppUiAdapter* >( iAvkonAppUi );
       
   175     
       
   176     // Max line amount
       
   177     iMaxLines = 0;
       
   178     
       
   179     CXnProperty* maxlinesProp( iNode.GetPropertyL( KMaxLineAmount ) );
       
   180         
       
   181     if ( maxlinesProp )
       
   182         {
       
   183         iMaxLines = maxlinesProp->FloatValueL();
       
   184         }
       
   185 
       
   186     // Max char amount
       
   187     TInt maxChars( KMaxLength );
       
   188     
       
   189     CXnProperty* maxcharsProp( iNode.GetPropertyL( KMaxCharAmount ) );    
       
   190     
       
   191     if ( maxcharsProp )
       
   192         {
       
   193         maxChars = maxcharsProp->FloatValueL();
       
   194         }
       
   195     
       
   196     iEditor = new ( ELeave ) CEikEdwin;
       
   197 
       
   198     iEditor->SetContainerWindowL( *iParent );
       
   199     iEditor->ConstructL( 0, maxChars, maxChars, iMaxLines );
       
   200     iEditor->SetBackground( this );
       
   201     
       
   202     // Set allowed input modes
       
   203     iEditor->SetAknEditorAllowedInputModes( EAknEditorAllInputModes );
       
   204 
       
   205     // Set the default input mode
       
   206     iEditor->SetAknEditorInputMode( 
       
   207         EAknEditorTextInputMode | EAknEditorNumericInputMode );
       
   208                                     
       
   209     // Set allowed case modes
       
   210     iEditor->SetAknEditorPermittedCaseModes( EAknEditorAllCaseModes );
       
   211 
       
   212     // Set the default case mode
       
   213     iEditor->SetAknEditorCase( EAknEditorTextCase );
       
   214         
       
   215     iEditor->AddFlagToUserFlags( 
       
   216         CEikEdwin::ENoAutoSelection | CEikEdwin::EAllowUndo );
       
   217                                      
       
   218     // Set numeric keymap
       
   219     iEditor->SetAknEditorNumericKeymap( EAknEditorPlainNumberModeKeymap );
       
   220 
       
   221     // Enable partial Screen
       
   222     CXnProperty* enablepartialinput( iNode.GetPropertyL( KEnablePartialInput ) );
       
   223     iSplitInputFlags = 0;
       
   224      
       
   225     if ( enablepartialinput && 
       
   226          enablepartialinput->StringValue() == XnPropertyNames::KTrue )
       
   227         {
       
   228         iEditor->SetAknEditorFlags( EAknEditorFlagEnablePartialScreen );
       
   229         SetFlag( iSplitInputFlags, ESplitInputEnabled );
       
   230         }
       
   231 
       
   232     // for RTL languages
       
   233     iEditor->SetAknEditorLocalLanguage( User::Language() );
       
   234     ( AknLayoutUtils::LayoutMirrored() ? 
       
   235                         iEditor->SetAlignment( EAknEditorAlignRight ) : 
       
   236                         iEditor->SetAlignment( EAknEditorAlignLeft ) );
       
   237 
       
   238     iEditor->SetObserver( this );
       
   239                                         
       
   240     // Default not focused                                  
       
   241     iEditor->SetFocus( EFalse );                              
       
   242         
       
   243     SetPropertiesL();
       
   244 	}
       
   245  
       
   246 // -----------------------------------------------------------------------------
       
   247 // CXnTextEditorAdapter::CountComponentControls
       
   248 // (other items were commented in a header).
       
   249 // -----------------------------------------------------------------------------
       
   250 //  
       
   251 TInt CXnTextEditorAdapter::CountComponentControls() const
       
   252     {
       
   253     if( iEditor )
       
   254         {
       
   255         return 1;
       
   256         }
       
   257         
       
   258     return 0;        
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CXnTextEditorAdapter::ComponentControl
       
   263 // (other items were commented in a header).
       
   264 // -----------------------------------------------------------------------------
       
   265 // 
       
   266 CCoeControl* CXnTextEditorAdapter::ComponentControl( TInt aIndex ) const
       
   267     {
       
   268     if( aIndex == 0 )
       
   269         {
       
   270         return iEditor;
       
   271         }
       
   272         
       
   273     return NULL;        
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CXnTextEditorAdapter::SizeChanged
       
   278 // (other items were commented in a header).
       
   279 // -----------------------------------------------------------------------------
       
   280 // 
       
   281 void CXnTextEditorAdapter::SizeChanged()
       
   282     {        
       
   283     iEditor->SetRect( iNode.Rect() );  
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CXnTextEditorAdapter::OfferKeyEventL
       
   288 // (other items were commented in a header).
       
   289 // -----------------------------------------------------------------------------
       
   290 // 
       
   291 TKeyResponse CXnTextEditorAdapter::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   292     TEventCode aType )
       
   293     {
       
   294     TKeyResponse ret( EKeyWasNotConsumed );
       
   295 
       
   296     if ( !IsFocused() )
       
   297         {
       
   298         return ret;
       
   299         }
       
   300 
       
   301     ret = iEditor->OfferKeyEventL( aKeyEvent, aType );                    
       
   302 
       
   303     if ( IS_ARROW_KEY( aKeyEvent.iScanCode ) )    
       
   304         {                        
       
   305         if ( ret == EKeyWasNotConsumed && aType == EEventKey )
       
   306             {            
       
   307             iRefusesFocusLoss = EFalse;
       
   308             
       
   309             ret = CXnControlAdapter::OfferKeyEventL( aKeyEvent, aType );
       
   310             }                    
       
   311         }
       
   312 
       
   313     if ( aKeyEvent.iCode == EKeyEnter )
       
   314         {
       
   315         if ( iEditorPublisher && iMaxLines == 1 )
       
   316             {
       
   317             TInt length( iEditor->TextLength() );
       
   318             
       
   319             HBufC* content = HBufC::NewLC( length + 1 );
       
   320             TPtr ptr( content->Des() );
       
   321             
       
   322             iEditor->GetText( ptr );
       
   323             
       
   324             ptr.Append( KEnterChar );
       
   325             
       
   326             iEditorPublisher->PublishTextL( *content );
       
   327             
       
   328             CleanupStack::PopAndDestroy( content );
       
   329             }
       
   330         }
       
   331 
       
   332     return ret;        
       
   333     }
       
   334  
       
   335 // -----------------------------------------------------------------------------
       
   336 // CXnTextEditorAdapter::RefusesFocusLoss
       
   337 // (other items were commented in a header).
       
   338 // -----------------------------------------------------------------------------
       
   339 // 
       
   340 TBool CXnTextEditorAdapter::RefusesFocusLoss() const
       
   341     {    
       
   342     return iRefusesFocusLoss;
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CXnTextEditorAdapter::FocusChanged
       
   347 // (other items were commented in a header).
       
   348 // -----------------------------------------------------------------------------
       
   349 // 
       
   350 void CXnTextEditorAdapter::FocusChanged( TDrawNow aDrawNow )
       
   351     {
       
   352     TBool isFocused( IsFocused() ? ETrue : EFalse );
       
   353     TInt value;
       
   354 
       
   355     if ( isFocused )
       
   356         {      
       
   357         value = EPSAiDontForwardNumericKeysToPhone;
       
   358 
       
   359         if( !IsFlagSet( iSplitInputFlags, ESplitInputEnabled ) )
       
   360             {
       
   361             TRAP_IGNORE( iAppui->AddToStackL( iAppui->View(), iEditor ) );  
       
   362             // AddToStackL calls iEditor->SetFocus( ETrue ); 
       
   363             }
       
   364         else if( !IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   365             {
       
   366             TRAP_IGNORE( iAppui->AddToStackL( iAppui->View(), iEditor ) ); 
       
   367             SetFlag( iSplitInputFlags, ESplitInputEditorInStack );
       
   368             }
       
   369         }
       
   370     else
       
   371         {
       
   372         value = EPSAiForwardNumericKeysToPhone;
       
   373                                       
       
   374         if( !IsFlagSet( iSplitInputFlags, ESplitInputEnabled ) )
       
   375             {    
       
   376             iAppui->RemoveFromStack( iEditor );            
       
   377             iEditor->SetFocus( EFalse, aDrawNow );
       
   378             }
       
   379         
       
   380         // Remove editor from stack if it has not beed removed AND split screen has been closed
       
   381         else if( IsFlagSet( iSplitInputFlags, ESplitInputEditorInStack ) &&
       
   382                  !IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   383             {
       
   384             iAppui->RemoveFromStack( iEditor );            
       
   385             iEditor->SetFocus( EFalse, aDrawNow );
       
   386             ClearFlag( iSplitInputFlags, ESplitInputEditorInStack );            
       
   387             }            
       
   388         }
       
   389 
       
   390     if( IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   391         {
       
   392         value = EPSAiDontForwardNumericKeysToPhone;
       
   393         } 
       
   394 
       
   395     iRefusesFocusLoss = isFocused;
       
   396     
       
   397     RProperty::Set( KPSUidAiInformation,            
       
   398                     KActiveIdleForwardNumericKeysToPhone,
       
   399                     value );    
       
   400     }
       
   401     
       
   402 // -----------------------------------------------------------------------------
       
   403 // CXnTextEditorAdapter::Draw
       
   404 // Draws the editor component
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 void CXnTextEditorAdapter::Draw( const TRect& /*aRect*/ ) const
       
   408     { 
       
   409     // Do nothing. 
       
   410     // Background is drawn through MCoeControlBackground of CEikEdwin. 
       
   411     }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CXnTextEditorAdapter::HandleResourceChange
       
   415 //
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 void CXnTextEditorAdapter::HandleResourceChange( TInt aType )
       
   419     {
       
   420     if ( aType == KAknSplitInputEnabled ) 
       
   421         {
       
   422         if( IsFlagSet( iSplitInputFlags, ESplitInputEditorInStack ) && 
       
   423             !IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   424             {
       
   425             iUiEngine->EnablePartialTouchInput( iNode, ETrue );
       
   426             SetFlag( iSplitInputFlags, ESplitInputOpen );
       
   427             if ( !IsFlagSet( iSplitInputFlags, EScreenDeviceChanged ) )
       
   428                 {
       
   429                 TRAP_IGNORE( iNode.ReportTriggerEventL( KSplitScreenEnabledTrigger, 
       
   430                     KNullDesC8, KNullDesC8) );
       
   431                 }
       
   432             else
       
   433                 {
       
   434                 ClearFlag( iSplitInputFlags, EScreenDeviceChanged );
       
   435                 }
       
   436             }
       
   437         }    
       
   438     
       
   439      if ( aType == KAknSplitInputDisabled ) 
       
   440         {
       
   441         if( IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )    
       
   442             {
       
   443             iUiEngine->EnablePartialTouchInput( iNode, EFalse );
       
   444             ClearFlag( iSplitInputFlags, ESplitInputOpen );
       
   445             
       
   446             // Note that after orientation switch, split screen is first closed and  
       
   447             // then opened again. Therefore these must be discarded
       
   448             if ( !IsFlagSet( iSplitInputFlags, EScreenDeviceChanged ) )
       
   449                 {
       
   450                 TRAP_IGNORE( iNode.ReportTriggerEventL( KSplitScreenDisabledTrigger, 
       
   451                     KNullDesC8, KNullDesC8) );
       
   452             
       
   453                 // If editor is not focused anymore, remove if from stack
       
   454                 CXnNodePluginIf* focusedNode( NULL );
       
   455                 TRAP_IGNORE( focusedNode = iUiEngine->FocusedNodeL() );
       
   456                 if( focusedNode != &iNode && 
       
   457                     IsFlagSet( iSplitInputFlags, ESplitInputEditorInStack ) )
       
   458                     {
       
   459                     iAppui->RemoveFromStack( iEditor );
       
   460                     iEditor->SetFocus( EFalse );
       
   461                     ClearFlag( iSplitInputFlags, ESplitInputEditorInStack );
       
   462     
       
   463                     // Forward keys to phone again    
       
   464                     RProperty::Set( KPSUidAiInformation,            
       
   465                                     KActiveIdleForwardNumericKeysToPhone,
       
   466                                     EPSAiForwardNumericKeysToPhone );
       
   467                     }
       
   468                 }
       
   469             }
       
   470         }
       
   471     CCoeControl::HandleResourceChange( aType );
       
   472     }
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CXnTextEditorAdapter::HandlePointerEventL
       
   476 //
       
   477 // -----------------------------------------------------------------------------
       
   478 //
       
   479 void CXnTextEditorAdapter::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   480     {
       
   481     TPointerEvent pointerEvent( aPointerEvent ); 
       
   482     TRect rect( iEditor->TextView()->ViewRect() );
       
   483     TPoint point( aPointerEvent.iPosition );
       
   484     
       
   485     // this opens partial screen also when margin is tapped
       
   486     if( !IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   487         {
       
   488         if( point.iX < rect.iTl.iX )
       
   489             {
       
   490             pointerEvent.iPosition.iX = rect.iTl.iX;
       
   491             }
       
   492         else if( point.iX > rect.iBr.iX )
       
   493             {
       
   494             pointerEvent.iPosition.iX = rect.iBr.iX;
       
   495             }
       
   496         
       
   497         if( point.iY < rect.iTl.iY )
       
   498             {
       
   499             pointerEvent.iPosition.iY = rect.iTl.iY;
       
   500             }
       
   501         else if( point.iY > rect.iBr.iY )
       
   502             {
       
   503             pointerEvent.iPosition.iY = rect.iBr.iY;
       
   504             }
       
   505         }
       
   506     
       
   507     CXnControlAdapter::HandlePointerEventL( pointerEvent );
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CXnTextEditorAdapter::HandleScreenDeviceChangedL
       
   512 //
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 void CXnTextEditorAdapter::HandleScreenDeviceChangedL()
       
   516     {
       
   517     if( IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   518         {
       
   519         SetFlag( iSplitInputFlags, EScreenDeviceChanged );
       
   520         }
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // From MCoeControlBackground
       
   525 // CXnTextEditorAdapter::Draw
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 void CXnTextEditorAdapter::Draw( CWindowGc& aGc, const CCoeControl& aControl, 
       
   529     const TRect& aRect) const
       
   530     {
       
   531     if( &aControl == iEditor )
       
   532         {
       
   533         CXnControlAdapter::Draw( aRect, aGc );    
       
   534         }
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // CXnTextEditorAdapter::SetTextL
       
   539 // Sets the new content to the underlying CEikEdwin
       
   540 // -----------------------------------------------------------------------------
       
   541 //
       
   542 void CXnTextEditorAdapter::SetTextL( const TDesC& aText )
       
   543     {
       
   544     iEditor->SetTextL( &aText );
       
   545     iNode.SetDirtyL();
       
   546     }
       
   547     
       
   548 // -----------------------------------------------------------------------------
       
   549 // CXnTextEditorAdapter::Text
       
   550 // Returns the text contained in the underlying CEikEdwin
       
   551 // -----------------------------------------------------------------------------
       
   552 //
       
   553 HBufC* CXnTextEditorAdapter::Text() const
       
   554     {
       
   555     HBufC* text( NULL );
       
   556     
       
   557     TRAP_IGNORE( text = iEditor->GetTextInHBufL() );
       
   558     
       
   559     // Ownership is transfered to the calller
       
   560     return text;
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CXnTextEditorAdapter::HandleEditorEvent
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CXnTextEditorAdapter::HandleEditorEvent( TInt aReason )
       
   568     {
       
   569     if( aReason == CXnTextEditor::KDeactivateTextEditor &&
       
   570         IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   571         {
       
   572         iAppui->RemoveFromStack( iEditor );
       
   573         iEditor->SetFocus( EFalse );
       
   574         ClearFlag( iSplitInputFlags, ESplitInputEditorInStack ); 
       
   575         iRefusesFocusLoss = EFalse;
       
   576         }
       
   577     }
       
   578 
       
   579 // -----------------------------------------------------------------------------
       
   580 // CXnTextEditorAdapter::SetPropertiesL
       
   581 // Sets text properties
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 void CXnTextEditorAdapter::SetPropertiesL()
       
   585     {    
       
   586     // Whether to publish text to CPS
       
   587     CXnProperty* cpspublishingProp( iNode.GetPropertyL( KCpsPublishing ) );
       
   588     CXnProperty* idProp( iNode.IdL() );
       
   589     
       
   590     if ( cpspublishingProp && idProp && 
       
   591         cpspublishingProp->StringValue() == XnPropertyNames::KTrue )
       
   592         {
       
   593         iEditorPublisher = CXnTextEditorPublisher::NewL( 
       
   594                 *this, idProp->StringValue() );
       
   595         }    
       
   596 
       
   597     // Store current state
       
   598     if ( iFont && iReleaseFont )
       
   599         {
       
   600         CWsScreenDevice* dev( iCoeEnv->ScreenDevice() );
       
   601         dev->ReleaseFont( iFont ); 
       
   602         iFont = NULL;
       
   603         }
       
   604     
       
   605     // Get new font
       
   606     CXnUtils::CreateFontL( iNode, iFont, iReleaseFont );
       
   607     
       
   608     // And set font
       
   609     TCharFormat cf;
       
   610     TCharFormatMask cfm;
       
   611     cfm.SetAttrib( EAttColor );
       
   612     cfm.SetAttrib( EAttFontTypeface );
       
   613     cfm.SetAttrib( EAttFontHeight );
       
   614     cfm.SetAttrib( EAttFontPosture );
       
   615     cfm.SetAttrib( EAttFontStrokeWeight );
       
   616     cfm.SetAttrib( EAttLineSpacing );
       
   617     cfm.SetAttrib( EAttLineSpacingControl );
       
   618     cf.iFontSpec = iFont->FontSpecInTwips();
       
   619 
       
   620     // Set linespacing    
       
   621     CXnProperty* lineSpaceProp( 
       
   622         iNode.GetPropertyL( XnPropertyNames::appearance::common::KFontLineSpace ) );
       
   623         
       
   624     if ( lineSpaceProp )
       
   625         {
       
   626         TInt lineSpace = 
       
   627             iUiEngine->VerticalPixelValueL( lineSpaceProp, iNode.Rect().Height() );
       
   628         
       
   629         CParaFormatLayer*pFormatLayer = CEikonEnv::NewDefaultParaFormatLayerL();
       
   630         CleanupStack::PushL(pFormatLayer);
       
   631         CParaFormat* paraformat = CParaFormat::NewLC(); 
       
   632         TParaFormatMask paraFormatMask; 
       
   633         paraFormatMask.SetAttrib(EAttLineSpacing);
       
   634         paraFormatMask.SetAttrib(EAttLineSpacingControl);
       
   635         paraformat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips;
       
   636         CGraphicsDevice* screenDevice = iEikonEnv->ScreenDevice();
       
   637         TInt lineHeight = screenDevice->VerticalPixelsToTwips( iFont->HeightInPixels() + lineSpace );
       
   638         paraformat->iLineSpacingInTwips = lineHeight;
       
   639         pFormatLayer->SetL(paraformat, paraFormatMask);
       
   640         iEditor->SetParaFormatLayer(pFormatLayer); // Edwin takes the ownership
       
   641         CleanupStack::PopAndDestroy(paraformat);
       
   642         CleanupStack::Pop(pFormatLayer); 
       
   643         }
       
   644  
       
   645     // Get text color and set it
       
   646     TRgb textColor;
       
   647     CXnProperty* colorProperty( 
       
   648         iNode.GetPropertyL( XnPropertyNames::appearance::common::KColor ) );
       
   649     
       
   650     if ( colorProperty )
       
   651         {
       
   652         CXnDomProperty* domProperty( colorProperty->Property() );
       
   653         
       
   654         if ( domProperty )
       
   655             {
       
   656             TInt error( KErrNotSupported );
       
   657             
       
   658             CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >( 
       
   659                 domProperty->PropertyValueList().Item( 0 ) );
       
   660 
       
   661             if ( value->IsAutoIdent() )
       
   662                 {
       
   663                 MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   664                 error = AknsUtils::GetCachedColor(skinInstance, textColor, KAknsIIDQsnTextColors,
       
   665                 EAknsCIQsnTextColorsCG6);
       
   666                 }
       
   667             else if ( value->PrimitiveValueType() == CXnDomPropertyValue::ERgbColor )
       
   668                 {
       
   669                 textColor = value->RgbColorValueL();
       
   670                 error = KErrNone;
       
   671                 }
       
   672             else
       
   673                 {
       
   674                 HBufC* colorString = colorProperty->StringValueL();
       
   675                 CleanupStack::PushL( colorString );
       
   676                 CXnUtils::StripQuotes( colorString );
       
   677                 TInt index = 0;
       
   678                 TAknsItemID skinID;
       
   679                 TBool idResolved = CXnUtils::ResolveSkinItemIDL( colorString->Des(), skinID, index );
       
   680                 
       
   681                 if ( idResolved )
       
   682                     {
       
   683                     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   684                     error = AknsUtils::GetCachedColor( skinInstance, textColor, skinID, index );
       
   685                     }
       
   686                 else // use auto value if skin id is invalid.
       
   687                     {
       
   688                     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   689                     error = AknsUtils::GetCachedColor(skinInstance, textColor, KAknsIIDQsnTextColors,
       
   690                     EAknsCIQsnTextColorsCG6);
       
   691                     }
       
   692                 
       
   693                 CleanupStack::PopAndDestroy( colorString );                 
       
   694                 }
       
   695             
       
   696             if ( error == KErrNone )
       
   697                 {
       
   698                 cf.iFontPresentation.iTextColor = textColor;
       
   699                 }
       
   700             else
       
   701                 {
       
   702                 cf.iFontPresentation.iTextColor = KRgbBlack;                
       
   703                 }
       
   704             }
       
   705         }
       
   706     
       
   707     SetEditorMarginPropertiesL();
       
   708     
       
   709     CCharFormatLayer *pCharFL = CCharFormatLayer::NewL(cf,cfm);
       
   710     iEditor->SetCharFormatLayer(pCharFL);
       
   711     iEditor->SetTextBaselineSpacing( 2 );
       
   712     }
       
   713 
       
   714 // -----------------------------------------------------------------------------
       
   715 // CXnTextEditorAdapter::SetEditorMarginPropertiesL
       
   716 // Sets text properties
       
   717 // -----------------------------------------------------------------------------
       
   718 //
       
   719 void CXnTextEditorAdapter::SetEditorMarginPropertiesL()
       
   720     {
       
   721     TMargins8 margins;
       
   722     
       
   723     CXnProperty* leftMarginProp( 
       
   724         iNode.GetPropertyL( XnPropertyNames::texteditor::KEditorMarginLeft ) );
       
   725     if( leftMarginProp )
       
   726         {
       
   727         TInt leftValue = iUiEngine->HorizontalPixelValueL( leftMarginProp,
       
   728                 iNode.Rect().Width() );
       
   729         margins.iLeft = leftValue;
       
   730         }
       
   731     
       
   732     CXnProperty* rightMarginProp( 
       
   733         iNode.GetPropertyL( XnPropertyNames::texteditor::KEditorMarginRight ) );
       
   734     if( rightMarginProp )
       
   735         {
       
   736         TInt rightValue = iUiEngine->HorizontalPixelValueL( rightMarginProp,
       
   737                 iNode.Rect().Width() );
       
   738         margins.iRight = rightValue;
       
   739         }
       
   740     
       
   741     CXnProperty* topMarginProp( 
       
   742         iNode.GetPropertyL( XnPropertyNames::texteditor::KEditorMarginTop ) );
       
   743     if( topMarginProp )
       
   744         {
       
   745         TInt topValue = iUiEngine->VerticalPixelValueL( topMarginProp,
       
   746                 iNode.Rect().Width() );
       
   747         margins.iTop = topValue;
       
   748         }
       
   749     
       
   750     CXnProperty* bottomMarginProp( 
       
   751         iNode.GetPropertyL( XnPropertyNames::texteditor::KEditorMarginBottom ) );
       
   752     if( bottomMarginProp )
       
   753         {
       
   754         TInt bottomValue = iUiEngine->VerticalPixelValueL( bottomMarginProp,
       
   755                 iNode.Rect().Width() );
       
   756         margins.iBottom = bottomValue;
       
   757         }
       
   758     
       
   759     iEditor->SetBorderViewMargins( margins );
       
   760     }
       
   761 
       
   762 // End of file