idlehomescreen/xmluirendering/renderingplugins/xntexteditorfactory/src/xntexteditoradapter.cpp
branchRCL_3
changeset 102 ba63c83f4716
parent 88 3321d3e205b6
equal deleted inserted replaced
93:b01126ce0bec 102:ba63c83f4716
    49 #include "xneditmode.h"
    49 #include "xneditmode.h"
    50 #include "c_xnutils.h"
    50 #include "c_xnutils.h"
    51 #include "xntexteditor.h" 
    51 #include "xntexteditor.h" 
    52 
    52 
    53 // Constants
    53 // Constants
    54 enum EFlags
    54 
    55     {
    55 enum TSplitInputState
    56     EUsePartialScreenInput = 1,
    56     {
    57     EIsAlreadyFocused,
    57     ESplitInputEnabled = 1,   
    58     EIsFocused,
    58     ESplitInputOpen = 2,
    59     ESetText    
    59     ESplitInputEditorInStack = 4,
       
    60     EScreenDeviceChanged = 8
    60     };
    61     };
    61 
    62 
    62 const TInt KDefaultLength( 100 );
    63 const TInt KDefaultLength( 100 );
    63 
    64 
    64 _LIT8( KCpsPublishing, "cpspublishing" );
    65 _LIT8( KCpsPublishing, "cpspublishing" );
    65 _LIT8( KMaxLineAmount, "max-line-amount" );
    66 _LIT8( KMaxLineAmount, "max-line-amount" );
    66 _LIT8( KMaxCharAmount, "max-char-amount" );
    67 _LIT8( KMaxCharAmount, "max-char-amount" );
    67 _LIT8( KEnablePartialInput, "splitinputenabled" );
    68 _LIT8( KEnablePartialInput, "splitinputenabled" );
       
    69 _LIT8( KSplitScreenEnabledTrigger , "splitscreenenabled" );
       
    70 _LIT8( KSplitScreenDisabledTrigger, "splitscreendisabled" );
    68 
    71 
    69 _LIT( KEnterChar, "\x2029" );
    72 _LIT( KEnterChar, "\x2029" );
    70 
    73 
    71 // Macros
    74 // Macros
    72 #define IS_ARROW_KEY( k ) \
    75 #define IS_ARROW_KEY( k ) \
    73     ( k == EStdKeyLeftArrow || k == EStdKeyRightArrow || \
    76     ( k == EStdKeyLeftArrow || k == EStdKeyRightArrow || \
    74       k == EStdKeyUpArrow || k == EStdKeyDownArrow ) 
    77       k == EStdKeyUpArrow || k == EStdKeyDownArrow ) 
    75 
    78 
    76 // ============================ LOCAL FUNCTIONS ================================   
    79 // ============================ LOCAL FUNCTIONS ================================   
    77 
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 TBool IsFlagSet( TInt aFlags, TInt aFlag )
       
    85     {
       
    86     return aFlags & aFlag;
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void SetFlag( TInt& aFlags, TInt aFlag )
       
    93     {
       
    94     aFlags |= aFlag;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void ClearFlag( TInt& aFlags, TInt aFlag )
       
   101     {
       
   102     aFlags &= ~aFlag;
       
   103     }
       
   104 
    78 // ============================ MEMBER FUNCTIONS ===============================
   105 // ============================ MEMBER FUNCTIONS ===============================
       
   106 
    79 // -----------------------------------------------------------------------------
   107 // -----------------------------------------------------------------------------
    80 // CXnTextEditorAdapter::NewL
   108 // CXnTextEditorAdapter::NewL
    81 // Symbian static 1st phase constructor
   109 // Symbian static 1st phase constructor
    82 // -----------------------------------------------------------------------------
   110 // -----------------------------------------------------------------------------
    83 //
   111 //
   110 // C++ destructor
   138 // C++ destructor
   111 // -----------------------------------------------------------------------------
   139 // -----------------------------------------------------------------------------
   112 //
   140 //
   113 CXnTextEditorAdapter::~CXnTextEditorAdapter()
   141 CXnTextEditorAdapter::~CXnTextEditorAdapter()
   114     {  
   142     {  
   115     if ( iAppui )
   143     if( IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )    
   116         {
   144         {
   117         iAppui->RemoveFromStack( iEditor );
   145         if( iUiEngine )
   118         }
   146             {
   119         
   147             iUiEngine->EnablePartialTouchInput( iNode, EFalse );    
   120     if ( iFlags.IsSet( EIsFocused ) )
   148             }
   121         {
   149         }
   122         RProperty::Set( KPSUidAiInformation, 
   150 
   123             KActiveIdleForwardNumericKeysToPhone, 
   151     if ( iAvkonAppUi )
   124             EPSAiForwardNumericKeysToPhone );                    
   152         {
       
   153         iAvkonAppUi->RemoveFromStack( iEditor );
   125         }
   154         }
   126     
   155     
   127     if( iFont && iReleaseFont )
   156     if( iFont && iReleaseFont )
   128         {
   157         {
   129         CWsScreenDevice* dev( iCoeEnv->ScreenDevice() );
   158         CWsScreenDevice* dev( iCoeEnv->ScreenDevice() );
   141 // -----------------------------------------------------------------------------
   170 // -----------------------------------------------------------------------------
   142 //
   171 //
   143 void CXnTextEditorAdapter::ConstructL()
   172 void CXnTextEditorAdapter::ConstructL()
   144     {
   173     {
   145     CXnControlAdapter::ConstructL( iNode );    
   174     CXnControlAdapter::ConstructL( iNode );    
   146     
       
   147     iUiEngine = iNode.UiEngineL();
   175     iUiEngine = iNode.UiEngineL();
   148 
   176 
   149     iAppui = static_cast< CXnAppUiAdapter* >( iAvkonAppUi );
   177     iAppui = static_cast< CXnAppUiAdapter* >( iAvkonAppUi );
   150     
   178     
   151     // Max line amount
   179     // Max line amount
   193                                              
   221                                              
   194     // Set numeric keymap
   222     // Set numeric keymap
   195     iEditor->SetAknEditorNumericKeymap( EAknEditorPlainNumberModeKeymap );
   223     iEditor->SetAknEditorNumericKeymap( EAknEditorPlainNumberModeKeymap );
   196 
   224 
   197     // Enable partial Screen
   225     // Enable partial Screen
   198     CXnProperty* prop( iNode.GetPropertyL( KEnablePartialInput ) );
   226     CXnProperty* enablepartialinput( iNode.GetPropertyL( KEnablePartialInput ) );
   199                
   227     iSplitInputFlags = 0;
   200     if ( prop && prop->StringValue() == XnPropertyNames::KTrue )          
   228      
       
   229     if ( enablepartialinput && 
       
   230          enablepartialinput->StringValue() == XnPropertyNames::KTrue )
   201         {
   231         {
   202         iEditor->SetAknEditorFlags( EAknEditorFlagEnablePartialScreen );
   232         iEditor->SetAknEditorFlags( EAknEditorFlagEnablePartialScreen );
   203                         
   233         SetFlag( iSplitInputFlags, ESplitInputEnabled );
   204         iFlags.Set( EUsePartialScreenInput );        
       
   205         }
   234         }
   206         
   235         
   207     iEditor->SetAlignment( AknLayoutUtils::LayoutMirrored() ? 
   236     iEditor->SetAlignment( AknLayoutUtils::LayoutMirrored() ? 
   208         EAknEditorAlignRight : EAknEditorAlignLeft ); 
   237         EAknEditorAlignRight : EAknEditorAlignLeft ); 
   209                                                 
   238                                                 
   270     ret = iEditor->OfferKeyEventL( aKeyEvent, aType );                    
   299     ret = iEditor->OfferKeyEventL( aKeyEvent, aType );                    
   271 
   300 
   272     if ( IS_ARROW_KEY( aKeyEvent.iScanCode ) )    
   301     if ( IS_ARROW_KEY( aKeyEvent.iScanCode ) )    
   273         {                        
   302         {                        
   274         if ( ret == EKeyWasNotConsumed && aType == EEventKey )
   303         if ( ret == EKeyWasNotConsumed && aType == EEventKey )
   275             {                  
   304             {            
       
   305             iRefusesFocusLoss = EFalse;
       
   306             
   276             ret = CXnControlAdapter::OfferKeyEventL( aKeyEvent, aType );
   307             ret = CXnControlAdapter::OfferKeyEventL( aKeyEvent, aType );
   277             }                    
   308             }                    
   278         }
   309         }
   279 
   310 
   280     if ( aKeyEvent.iCode == EKeyEnter )
   311     if ( aKeyEvent.iCode == EKeyEnter )
   296             }
   327             }
   297         }
   328         }
   298 
   329 
   299     return ret;        
   330     return ret;        
   300     }
   331     }
       
   332  
       
   333 // -----------------------------------------------------------------------------
       
   334 // CXnTextEditorAdapter::RefusesFocusLoss
       
   335 // (other items were commented in a header).
       
   336 // -----------------------------------------------------------------------------
       
   337 // 
       
   338 TBool CXnTextEditorAdapter::RefusesFocusLoss() const
       
   339     {    
       
   340     return iRefusesFocusLoss;
       
   341     }
   301 
   342 
   302 // -----------------------------------------------------------------------------
   343 // -----------------------------------------------------------------------------
   303 // CXnTextEditorAdapter::FocusChanged
   344 // CXnTextEditorAdapter::FocusChanged
   304 // (other items were commented in a header).
   345 // (other items were commented in a header).
   305 // -----------------------------------------------------------------------------
   346 // -----------------------------------------------------------------------------
   306 // 
   347 // 
   307 void CXnTextEditorAdapter::FocusChanged( TDrawNow /*aDrawNow*/ )
   348 void CXnTextEditorAdapter::FocusChanged( TDrawNow aDrawNow )
   308     {
   349     {
   309     TBool isFocused( IsFocused() ? ETrue : EFalse );
   350     TBool isFocused( IsFocused() ? ETrue : EFalse );
   310     TBool wasFocused( iFlags.IsSet( EIsFocused ) ? ETrue : EFalse );
   351     TInt value;
   311     
   352 
   312     if ( isFocused != wasFocused )
   353     if ( isFocused )
   313         {
   354         {      
   314         TInt value;
   355         value = EPSAiDontForwardNumericKeysToPhone;
   315         
   356 
   316         if ( isFocused )
   357         if( !IsFlagSet( iSplitInputFlags, ESplitInputEnabled ) )
   317             {      
   358             {
   318             value = EPSAiDontForwardNumericKeysToPhone;
   359             TRAP_IGNORE( iAppui->AddToStackL( iAppui->View(), iEditor ) );  
   319             
   360             // AddToStackL calls iEditor->SetFocus( ETrue ); 
   320             iFlags.Set( EIsFocused );
   361             }
   321             
   362         else if( !IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
   322             TRAP_IGNORE( iAppui->AddToStackL( iAppui->View(), iEditor ) );
   363             {
   323             }
   364             TRAP_IGNORE( iAppui->AddToStackL( iAppui->View(), iEditor ) ); 
   324         else
   365             SetFlag( iSplitInputFlags, ESplitInputEditorInStack );
   325             {
   366             }
   326             value = EPSAiForwardNumericKeysToPhone;
   367         }
   327             
   368     else
   328             iFlags.Clear( EIsFocused );
   369         {
   329             
   370         value = EPSAiForwardNumericKeysToPhone;
       
   371                                       
       
   372         if( !IsFlagSet( iSplitInputFlags, ESplitInputEnabled ) )
       
   373             {    
   330             iAppui->RemoveFromStack( iEditor );            
   374             iAppui->RemoveFromStack( iEditor );            
   331             iEditor->SetFocus( EFalse );                       
   375             iEditor->SetFocus( EFalse, aDrawNow );
   332             } 
   376             }
   333         
   377         
   334         RProperty::Set( KPSUidAiInformation, 
   378         // Remove editor from stack if it has not beed removed AND split screen has been closed
   335             KActiveIdleForwardNumericKeysToPhone, value );                    
   379         else if( IsFlagSet( iSplitInputFlags, ESplitInputEditorInStack ) &&
   336         }        
   380                  !IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   381             {
       
   382             iAppui->RemoveFromStack( iEditor );            
       
   383             iEditor->SetFocus( EFalse, aDrawNow );
       
   384             ClearFlag( iSplitInputFlags, ESplitInputEditorInStack );            
       
   385             }            
       
   386         }
       
   387 
       
   388     if( IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   389         {
       
   390         value = EPSAiDontForwardNumericKeysToPhone;
       
   391         } 
       
   392 
       
   393     iRefusesFocusLoss = isFocused;
       
   394     
       
   395     RProperty::Set( KPSUidAiInformation,            
       
   396                     KActiveIdleForwardNumericKeysToPhone,
       
   397                     value );    
   337     }
   398     }
   338     
   399     
   339 // -----------------------------------------------------------------------------
   400 // -----------------------------------------------------------------------------
   340 // CXnTextEditorAdapter::Draw
   401 // CXnTextEditorAdapter::Draw
   341 // Draws the editor component
   402 // Draws the editor component
   346     // Do nothing. 
   407     // Do nothing. 
   347     // Background is drawn through MCoeControlBackground of CEikEdwin. 
   408     // Background is drawn through MCoeControlBackground of CEikEdwin. 
   348     }
   409     }
   349 
   410 
   350 // -----------------------------------------------------------------------------
   411 // -----------------------------------------------------------------------------
       
   412 // CXnTextEditorAdapter::HandleResourceChange
       
   413 //
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 void CXnTextEditorAdapter::HandleResourceChange( TInt aType )
       
   417     {
       
   418     if ( aType == KAknSplitInputEnabled ) 
       
   419         {
       
   420         if( IsFlagSet( iSplitInputFlags, ESplitInputEditorInStack ) && 
       
   421             !IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   422             {
       
   423             iUiEngine->EnablePartialTouchInput( iNode, ETrue );
       
   424             SetFlag( iSplitInputFlags, ESplitInputOpen );
       
   425             if ( !IsFlagSet( iSplitInputFlags, EScreenDeviceChanged ) )
       
   426                 {
       
   427                 TRAP_IGNORE( iNode.ReportTriggerEventL( KSplitScreenEnabledTrigger, 
       
   428                     KNullDesC8, KNullDesC8) );
       
   429                 }
       
   430             else
       
   431                 {
       
   432                 ClearFlag( iSplitInputFlags, EScreenDeviceChanged );
       
   433                 }
       
   434             }
       
   435         }    
       
   436     
       
   437      if ( aType == KAknSplitInputDisabled ) 
       
   438         {
       
   439         if( IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )    
       
   440             {
       
   441             iUiEngine->EnablePartialTouchInput( iNode, EFalse );
       
   442             ClearFlag( iSplitInputFlags, ESplitInputOpen );
       
   443             
       
   444             // Note that after orientation switch, split screen is first closed and  
       
   445             // then opened again. Therefore these must be discarded
       
   446             if ( !IsFlagSet( iSplitInputFlags, EScreenDeviceChanged ) )
       
   447                 {
       
   448                 TRAP_IGNORE( iNode.ReportTriggerEventL( KSplitScreenDisabledTrigger, 
       
   449                     KNullDesC8, KNullDesC8) );
       
   450             
       
   451                 // If editor is not focused anymore, remove if from stack
       
   452                 CXnNodePluginIf* focusedNode( NULL );
       
   453                 TRAP_IGNORE( focusedNode = iUiEngine->FocusedNodeL() );
       
   454                 if( focusedNode != &iNode && 
       
   455                     IsFlagSet( iSplitInputFlags, ESplitInputEditorInStack ) )
       
   456                     {
       
   457                     iAppui->RemoveFromStack( iEditor );
       
   458                     iEditor->SetFocus( EFalse );
       
   459                     ClearFlag( iSplitInputFlags, ESplitInputEditorInStack );
       
   460     
       
   461                     // Forward keys to phone again    
       
   462                     RProperty::Set( KPSUidAiInformation,            
       
   463                                     KActiveIdleForwardNumericKeysToPhone,
       
   464                                     EPSAiForwardNumericKeysToPhone );
       
   465                     }
       
   466                 }
       
   467             }
       
   468         }
       
   469     CCoeControl::HandleResourceChange( aType );
       
   470     }
       
   471 
       
   472 // -----------------------------------------------------------------------------
   351 // CXnTextEditorAdapter::HandlePointerEventL
   473 // CXnTextEditorAdapter::HandlePointerEventL
   352 //
   474 //
   353 // -----------------------------------------------------------------------------
   475 // -----------------------------------------------------------------------------
   354 //
   476 //
   355 void CXnTextEditorAdapter::HandlePointerEventL( 
   477 void CXnTextEditorAdapter::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   356     const TPointerEvent& aPointerEvent )
   478     {
   357     {       
   479     TPointerEvent pointerEvent( aPointerEvent ); 
   358     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
   480     TRect rect( iEditor->TextView()->ViewRect() );
   359         {
   481     TPoint point( aPointerEvent.iPosition );
   360         iFlags.Clear( EIsAlreadyFocused );
   482     
   361         
   483     // this opens partial screen also when margin is tapped
   362         if ( IsFocused() )
   484     if( !IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
   363             {
   485         {
   364             iFlags.Set( EIsAlreadyFocused );
   486         if( point.iX < rect.iTl.iX )
   365             }
   487             {
   366         }
   488             pointerEvent.iPosition.iX = rect.iTl.iX;
   367     
   489             }
   368     if ( iFlags.IsSet( EIsAlreadyFocused ) )
   490         else if( point.iX > rect.iBr.iX )
   369         {
   491             {
   370         CCoeControl::HandlePointerEventL( aPointerEvent );
   492             pointerEvent.iPosition.iX = rect.iBr.iX;
   371         }
   493             }
   372     else
   494         
   373         {
   495         if( point.iY < rect.iTl.iY )
   374         TPointerEvent pointerEvent( aPointerEvent ); 
   496             {
   375         TRect rect( iEditor->TextView()->ViewRect() );
   497             pointerEvent.iPosition.iY = rect.iTl.iY;
   376         TPoint point( aPointerEvent.iPosition );
   498             }
   377         
   499         else if( point.iY > rect.iBr.iY )
   378         // this opens partial screen also when margin is tapped
   500             {
   379         if ( iFlags.IsSet( EUsePartialScreenInput ) )    
   501             pointerEvent.iPosition.iY = rect.iBr.iY;
   380             {
   502             }
   381             if( point.iX < rect.iTl.iX )
   503         }
   382                 {
   504     
   383                 pointerEvent.iPosition.iX = rect.iTl.iX;
   505     CXnControlAdapter::HandlePointerEventL( pointerEvent );
   384                 }
   506     }
   385             else if( point.iX > rect.iBr.iX )
   507 
   386                 {
   508 // -----------------------------------------------------------------------------
   387                 pointerEvent.iPosition.iX = rect.iBr.iX;
   509 // CXnTextEditorAdapter::HandleScreenDeviceChangedL
   388                 }
   510 //
   389             
   511 // -----------------------------------------------------------------------------
   390             if( point.iY < rect.iTl.iY )
   512 //
   391                 {
   513 void CXnTextEditorAdapter::HandleScreenDeviceChangedL()
   392                 pointerEvent.iPosition.iY = rect.iTl.iY;
   514     {
   393                 }
   515     if( IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
   394             else if( point.iY > rect.iBr.iY )
   516         {
   395                 {
   517         SetFlag( iSplitInputFlags, EScreenDeviceChanged );
   396                 pointerEvent.iPosition.iY = rect.iBr.iY;
   518         }
   397                 }
       
   398             }
       
   399         
       
   400         CXnControlAdapter::HandlePointerEventL( pointerEvent );    
       
   401         }         
       
   402     }
   519     }
   403 
   520 
   404 // -----------------------------------------------------------------------------
   521 // -----------------------------------------------------------------------------
   405 // From MCoeControlBackground
   522 // From MCoeControlBackground
   406 // CXnTextEditorAdapter::Draw
   523 // CXnTextEditorAdapter::Draw
   444     delete text;
   561     delete text;
   445     text = NULL;
   562     text = NULL;
   446     
   563     
   447     if ( update )
   564     if ( update )
   448         {
   565         {
   449         iFlags.Set( ESetText );
   566         iIsSetText = ETrue;
   450         
   567                 
   451         TRAP_IGNORE( iEditor->SetTextL( &aText ) );
   568         TRAP_IGNORE( iEditor->SetTextL( &aText ) );
   452         
   569         
   453         iFlags.Clear( ESetText );
   570         iIsSetText = EFalse;
   454         
   571         
   455         iNode.SetDirtyL();        
   572         iNode.SetDirtyL();        
   456         }
   573         }
   457     }
   574     }
   458 
   575 
   461 // Queries whether SetText API has generated edwin content change
   578 // Queries whether SetText API has generated edwin content change
   462 // -----------------------------------------------------------------------------
   579 // -----------------------------------------------------------------------------
   463 //
   580 //
   464 TBool CXnTextEditorAdapter::IsSetText() const
   581 TBool CXnTextEditorAdapter::IsSetText() const
   465     {
   582     {
   466     return iFlags.IsSet( ESetText ) ? ETrue : EFalse;
   583     return iIsSetText;
   467     }
   584     }
   468     
   585     
   469 // -----------------------------------------------------------------------------
   586 // -----------------------------------------------------------------------------
   470 // CXnTextEditorAdapter::Text
   587 // CXnTextEditorAdapter::Text
   471 // Returns the text contained in the underlying CEikEdwin
   588 // Returns the text contained in the underlying CEikEdwin
   477     
   594     
   478     TRAP_IGNORE( text = iEditor->GetTextInHBufL() );
   595     TRAP_IGNORE( text = iEditor->GetTextInHBufL() );
   479     
   596     
   480     // Ownership is transfered to the calller
   597     // Ownership is transfered to the calller
   481     return text;
   598     return text;
       
   599     }
       
   600 
       
   601 // -----------------------------------------------------------------------------
       
   602 // CXnTextEditorAdapter::HandleEditorEvent
       
   603 // -----------------------------------------------------------------------------
       
   604 //
       
   605 void CXnTextEditorAdapter::HandleEditorEvent( TInt aReason )
       
   606     {
       
   607     if( aReason == CXnTextEditor::KDeactivateTextEditor &&
       
   608         IsFlagSet( iSplitInputFlags, ESplitInputOpen ) )
       
   609         {
       
   610         iAppui->RemoveFromStack( iEditor );
       
   611         iEditor->SetFocus( EFalse );
       
   612         ClearFlag( iSplitInputFlags, ESplitInputEditorInStack ); 
       
   613         iRefusesFocusLoss = EFalse;
       
   614         }
   482     }
   615     }
   483 
   616 
   484 // -----------------------------------------------------------------------------
   617 // -----------------------------------------------------------------------------
   485 // CXnTextEditorAdapter::SetPropertiesL
   618 // CXnTextEditorAdapter::SetPropertiesL
   486 // Sets text properties
   619 // Sets text properties