uifw/eikctl/src/EIKSECED.CPP
changeset 0 2f259fa3e83a
child 9 0aa5fbdfbc30
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 1997-1999 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    20 #include <uikon/eikdefmacros.h>
       
    21 #endif
       
    22 #include <eikseced.h>
       
    23 #include <barsread.h>
       
    24 #include <eikenv.h>
       
    25 #include <eikpanic.h>
       
    26 #include <e32keys.h>
       
    27 #include <aknedsts.h>
       
    28 #include <gulcolor.h>
       
    29 #include <AknUtils.h>
       
    30 
       
    31 #include <avkon.rsg>
       
    32 #include <aknenv.h>
       
    33 #include <aknappui.h>
       
    34 #include <aknsoundsystem.h>
       
    35 
       
    36 #include <AknsFrameBackgroundControlContext.h>
       
    37 #include <AknsDrawUtils.h>
       
    38 
       
    39 #include <PUAcodes.hrh>
       
    40 
       
    41 #include <AknTasHook.h>
       
    42 #include <AknTextDecorationMetrics.h>
       
    43 #include <AknLayoutFont.h>
       
    44 
       
    45 #include <aknextendedinputcapabilities.h>
       
    46 #include <touchfeedback.h>
       
    47 
       
    48 #define KSecretChar '*'
       
    49 #define KSecretCharAsString "*"
       
    50 #define KWait 1000000
       
    51 
       
    52 _LIT(KSecretCharString, "*******************************");
       
    53 
       
    54 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
    55 #include <gfxtranseffect/gfxtranseffect.h>
       
    56 #include <akntransitionutils.h>
       
    57 #include <avkondomainpskeys.h>
       
    58 #include <e32property.h>
       
    59 
       
    60 // Helper class that monitor redirection changes
       
    61 class CRedirectionListener : public CBase, public MAknTransitionUtilsObserver
       
    62     {
       
    63 private:
       
    64     TInt AknTransitionCallback( TInt aEvent, TInt aState,
       
    65             const TDesC8* /*aParams*/ )
       
    66         {
       
    67         if ( aEvent == CAknTransitionUtils::EEventWsBufferRedirection )
       
    68             {
       
    69             iRedirected = aState;
       
    70             if ( iCursorEnabled )
       
    71                 {
       
    72                 if ( iRedirected )
       
    73                     {
       
    74                     if ( iWg && iCursorStatus )
       
    75                         {
       
    76                         iWg->CancelTextCursor();
       
    77                         }
       
    78                     iCursorStatus = EFalse;
       
    79                     }
       
    80                 else
       
    81                     {
       
    82                     iOwner.EnableCursor( ETrue );
       
    83                     }
       
    84                 }
       
    85             }
       
    86         return 0;
       
    87         }
       
    88 
       
    89 public:
       
    90     CRedirectionListener( CEikSecretEditor& aOwner ) : iOwner( aOwner )
       
    91         {
       
    92         RProperty::Get( KPSUidAvkonDomain, KAknTfxServerRedirectionStatus,
       
    93                         iRedirected );
       
    94         iRedirected &= ETfxScreenRedirected;
       
    95         }
       
    96     
       
    97     inline void EnableCursor()
       
    98         {
       
    99         iCursorEnabled = ETrue;
       
   100         }
       
   101     
       
   102     void DisableCursor()
       
   103         {
       
   104         if ( iWg && iCursorStatus )
       
   105             {
       
   106             iWg->CancelTextCursor();
       
   107             }
       
   108         iCursorEnabled = EFalse;
       
   109         iCursorStatus = EFalse;
       
   110         }
       
   111     
       
   112     void UpdateCursor( const TTextCursor& aCursor )
       
   113         {
       
   114         TInt redirected;
       
   115         RProperty::Get( KPSUidAvkonDomain, KAknTfxServerRedirectionStatus,
       
   116                         redirected );
       
   117         redirected &= ETfxScreenRedirected;
       
   118         if ( redirected != iRedirected && redirected )
       
   119             {
       
   120             AknTransitionCallback( CAknTransitionUtils::EEventWsBufferRedirection,
       
   121                                    1, NULL );
       
   122             return;
       
   123             }
       
   124 
       
   125         iRedirected = redirected;
       
   126         
       
   127         if ( iCursorEnabled && iWg && iWindow && !iRedirected )
       
   128             {
       
   129             iWg->SetTextCursor( *iWindow, iOwner.CursorPos(),
       
   130                                 aCursor );
       
   131             iCursorStatus = ETrue;
       
   132             }
       
   133         }
       
   134         
       
   135     inline void SetWindows( RWindowGroup* aWg, RWindowBase* aWindow )
       
   136         {
       
   137         iWg = aWg;
       
   138         iWindow = aWindow;
       
   139         }
       
   140 private:
       
   141     TBool iRedirected;
       
   142     TBool iCursorEnabled;
       
   143     TBool iCursorStatus;
       
   144     RWindowGroup* iWg;
       
   145     RWindowBase* iWindow;
       
   146     CEikSecretEditor& iOwner;
       
   147     };
       
   148 #endif
       
   149 
       
   150 /**
       
   151 * Internal extension class for CEikSecretEditor.
       
   152 *
       
   153 * @since 2.0
       
   154 *
       
   155 * @internal
       
   156 */
       
   157 class CEikSecretEditorExtension : public CBase
       
   158     {
       
   159 public: // Construction and destruction
       
   160 
       
   161     CEikSecretEditorExtension()
       
   162     :iAknSkinColorIndex(KErrNotFound), 
       
   163     iSkinIdForBgColor(KErrNotFound), 
       
   164     iFeedback(MTouchFeedback::Instance())
       
   165                 {
       
   166                 }
       
   167 
       
   168     ~CEikSecretEditorExtension()
       
   169         {
       
   170         delete iExtendedInputCapabilitiesProvider;
       
   171         delete iExtendedInputCapabilities;
       
   172         }
       
   173 
       
   174     static CEikSecretEditorExtension* NewL()
       
   175         {
       
   176         CEikSecretEditorExtension* self =
       
   177         new ( ELeave ) CEikSecretEditorExtension;
       
   178 
       
   179         CleanupStack::PushL( self );
       
   180         self->ConstructL();
       
   181         CleanupStack::Pop();
       
   182         return self;
       
   183         }
       
   184 
       
   185     void ConstructL()
       
   186         {
       
   187         iExtendedInputCapabilities = 
       
   188         CAknExtendedInputCapabilities::NewL();
       
   189         TUint cap( iExtendedInputCapabilities->Capabilities() );
       
   190         cap |= CAknExtendedInputCapabilities::EInputEditorAlignBidi;
       
   191         iExtendedInputCapabilities->SetCapabilities( cap );
       
   192 
       
   193         iExtendedInputCapabilitiesProvider =
       
   194         new ( ELeave ) CAknExtendedInputCapabilities::
       
   195         CAknExtendedInputCapabilitiesProvider;
       
   196 
       
   197         iExtendedInputCapabilitiesProvider->SetExtendedInputCapabilities(
       
   198                 iExtendedInputCapabilities );
       
   199 
       
   200         iExtendedInputCapabilities->SetEditorType( 
       
   201                 CAknExtendedInputCapabilities::EEikSecretEditorBased );                
       
   202         }
       
   203 
       
   204 public: // Data
       
   205     MAknsControlContext* iBgContext; // Not owned
       
   206     TBool iBgContextSet;
       
   207     TInt iAknSkinColorIndex;
       
   208     TInt iSkinIdForBgColor;
       
   209     MTouchFeedback* iFeedback;
       
   210 
       
   211     /**
       
   212      * Pointer to a CAknExtendedInputCapabilities.
       
   213      * Own.
       
   214      */
       
   215     CAknExtendedInputCapabilities* iExtendedInputCapabilities; 
       
   216 
       
   217     /**
       
   218      * Pointer to a extended input capabilities object provider.
       
   219      * Own.
       
   220      */
       
   221     CAknExtendedInputCapabilities::CAknExtendedInputCapabilitiesProvider*
       
   222     iExtendedInputCapabilitiesProvider;
       
   223 
       
   224     TInt iDisablePenInput; // Mainly for 0/1 values
       
   225     TTextCursor iCursor;
       
   226     RWindowGroup* iWg;
       
   227     RWindowBase* iWindow;
       
   228     TRect iTextRect;
       
   229     TBool iCursorEnabled;
       
   230     TBool iWindowSet;
       
   231     TBool iLaunchPenInputAutomatic;
       
   232     TBool iPartialScreenInput;
       
   233     };
       
   234 
       
   235 EXPORT_C void CEikSecretEditor::AknSetFont(const CFont &aFont)
       
   236     { 
       
   237     iFont = &aFont;
       
   238     iCharWidth=iFont->TextWidthInPixels(TPtrC((TText*)KSecretCharAsString, 1));
       
   239     CalculateAscent();
       
   240     }
       
   241 
       
   242 EXPORT_C void CEikSecretEditor::AknSetAlignment(const CGraphicsContext::TTextAlign &aAlign) { iAlign = aAlign; }
       
   243 
       
   244 EXPORT_C void CEikSecretEditor::SetDefaultInputMode(TInt aInputMode)
       
   245     {
       
   246     if (iFepState)
       
   247         {
       
   248         if ( aInputMode != EAknEditorNumericInputMode )
       
   249             {
       
   250             aInputMode = EAknEditorSecretAlphaInputMode;
       
   251             }
       
   252         
       
   253         CAknEdwinState* edwinState = STATIC_CAST(CAknEdwinState*, iFepState);
       
   254         edwinState->SetDefaultInputMode(aInputMode);
       
   255         edwinState->SetCurrentInputMode(aInputMode);
       
   256         }
       
   257     }
       
   258 
       
   259 EXPORT_C CEikSecretEditor::CEikSecretEditor()
       
   260     : CEikBorderedControl(TGulBorder(TGulBorder::ESingleGray))
       
   261     {
       
   262     __DECLARE_NAME(_S("CEikSecretEditor"));
       
   263     const CFont* font=iCoeEnv->NormalFont();
       
   264     iFont = font;
       
   265     iCharWidth=font->TextWidthInPixels(TPtrC((TText*)KSecretCharAsString, 1));
       
   266     CalculateAscent();
       
   267     iAlign = CGraphicsContext::ELeft;
       
   268     AKNTASHOOK_ADD( this, "CEikSecretEditor" );
       
   269     }
       
   270 
       
   271 EXPORT_C CEikSecretEditor::~CEikSecretEditor()
       
   272     {
       
   273     AKNTASHOOK_REMOVE();
       
   274 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
   275     CRedirectionListener* listener = ( CRedirectionListener* )
       
   276         CAknTransitionUtils::GetData( (TInt) this );
       
   277     if ( listener )
       
   278         {
       
   279         CAknTransitionUtils::RemoveObserver( listener,
       
   280             CAknTransitionUtils::EEventWsBufferRedirection );
       
   281         CAknTransitionUtils::RemoveData( (TInt) this );
       
   282         delete listener;
       
   283         }
       
   284 #endif
       
   285     delete iInlineEditText;
       
   286     delete iFepState;
       
   287     delete iTimer;
       
   288     delete iSecCharArr;
       
   289     delete iExtension;
       
   290     }
       
   291 
       
   292 EXPORT_C void CEikSecretEditor::ConstructFromResourceL(TResourceReader& aReader)
       
   293     //
       
   294     // Construct from resource
       
   295     //
       
   296     {
       
   297     iMaxLen=aReader.ReadUint16();
       
   298     __ASSERT_ALWAYS(iMaxLen<=EMaxSecEdSecArrayLength, Panic(EEikPanicSecretEditorTooLong));
       
   299     iSecCharArr = HBufC::NewL( EMaxSecEdSecArrayLength );
       
   300     iFepState = CreateFepStateL();
       
   301 
       
   302     if ( !iExtension )
       
   303         {
       
   304         iExtension = CEikSecretEditorExtension::NewL();
       
   305         }
       
   306     InitCRedirectionListenerL();
       
   307     }
       
   308 
       
   309 void CEikSecretEditor::StartTimer()
       
   310     {
       
   311     iTimer->Start(KWait, KWait, TCallBack(TimerCallback, this));
       
   312     }
       
   313 
       
   314 TInt CEikSecretEditor::TimerCallback(TAny* aThis)
       
   315     {
       
   316     static_cast<CEikSecretEditor*>(aThis)->Update();
       
   317     return NULL;
       
   318     }
       
   319 
       
   320 EXPORT_C void CEikSecretEditor::Update()
       
   321     {
       
   322     if ( iTimer )
       
   323         {
       
   324         iTimer->Cancel();
       
   325         }
       
   326     InsertSecretChar();
       
   327     DrawDeferred();
       
   328     }
       
   329 
       
   330 void CEikSecretEditor::OverflowAlert()
       
   331 /**
       
   332 Display alert to user, when character is entered but there is no more room in the field.
       
   333 Current implementation is to play a sound alert.
       
   334 @publishedComponent
       
   335 */
       
   336     {
       
   337     CAknKeySoundSystem* soundPlayer = (static_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi()))->KeySounds();
       
   338     if(soundPlayer)
       
   339         {
       
   340         soundPlayer->PlaySound(EAvkonSIDWarningTone);
       
   341         }
       
   342     };
       
   343 
       
   344 EXPORT_C TKeyResponse CEikSecretEditor::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   345     //
       
   346     // Respond to key presses
       
   347     //
       
   348     {
       
   349     if ( aType != EEventKey )
       
   350         {
       
   351         return EKeyWasConsumed;
       
   352         }
       
   353     TInt code=aKeyEvent.iCode;
       
   354     if ((code==EKeyUpArrow) || (code==EKeyDownArrow) || (aKeyEvent.iScanCode==EStdKeyHash) ||
       
   355     	(code==EKeyLeftArrow) || (code==EKeyRightArrow))
       
   356         return(EKeyWasNotConsumed);
       
   357     
       
   358     EnableCursor( EFalse );
       
   359 
       
   360     if ( ( code<ENonCharacterKeyBase  && TChar(code).IsPrint() ) || code == KPuaCodeSpaceSymbol)
       
   361         {
       
   362         if (iSecCharArr->Length()<iMaxLen)
       
   363             {
       
   364             AppendCharacterL( code );
       
   365             ReportEventL(MCoeControlObserver::EEventStateChanged);
       
   366             }
       
   367         else
       
   368             {
       
   369             iBufferFull=ETrue;
       
   370             OverflowAlert();
       
   371             }
       
   372         }
       
   373 
       
   374     if (iSecCharArr->Length()>0 && (code==EKeyBackspace || (code==EKeyF20 && !iBufferFull)))
       
   375         {
       
   376         iBufferFull=EFalse;
       
   377 
       
   378         TPtr secCharArrAppend = iSecCharArr->Des();
       
   379         secCharArrAppend.Delete(iSecCharArr->Length() - 1,1);
       
   380         Update();
       
   381         // ---------------
       
   382         // If the text doesn't fit on line and a user presses backspace
       
   383         // it must be illustrated to the user that a char was deleted
       
   384         // (instead of just showing max amount of KSecretChars).
       
   385         if ( iSecCharArr->Length() >= CharsFitOnEditor() )
       
   386             {
       
   387             if (!iTimer)
       
   388                 iTimer=CPeriodic::NewL(CActive::EPriorityLow);
       
   389             if (iTimer->IsActive())
       
   390                 Update();
       
   391 
       
   392             iBuf.Delete(iBuf.Length() - 1,1);
       
   393             DrawDeferred();
       
   394             StartTimer();
       
   395             }
       
   396         //-----------
       
   397         if ( iSecCharArr->Length() == 0 )
       
   398             {
       
   399             EnableCursor( ETrue );
       
   400             }
       
   401         ReportEventL(MCoeControlObserver::EEventStateChanged);
       
   402         }
       
   403     if ( code != EKeyF20 )
       
   404         {
       
   405         ReportUpdate();
       
   406         }
       
   407     return EKeyWasConsumed;
       
   408     }
       
   409 
       
   410 EXPORT_C TSize CEikSecretEditor::MinimumSize()
       
   411     //
       
   412     // Returns the minimum size needed to display
       
   413     //
       
   414     {
       
   415     TSize size=iBorder.SizeDelta();
       
   416 
       
   417     const CAknLayoutFont* layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull( iFont );
       
   418     if ( layoutFont )
       
   419         {
       
   420         size.iHeight += layoutFont->TextPaneHeight();
       
   421         }
       
   422     else
       
   423         {
       
   424         size.iHeight += iFont->HeightInPixels();
       
   425         }
       
   426     TAknTextDecorationMetrics decoration( iFont );
       
   427     TInt leftMargin(0);
       
   428     TInt rightMargin(0);
       
   429     decoration.GetLeftAndRightMargins( rightMargin, leftMargin );
       
   430     size.iWidth+=iCharWidth*(iMaxLen+1)+rightMargin + leftMargin; // 1 is for the cursor 
       
   431 
       
   432     return size;
       
   433     }
       
   434 
       
   435 EXPORT_C TCoeInputCapabilities CEikSecretEditor::InputCapabilities() const
       
   436     {
       
   437     TCoeInputCapabilities inputCaps( 
       
   438         TCoeInputCapabilities::ESecretText|TCoeInputCapabilities::ENavigation,
       
   439         const_cast<CEikSecretEditor*>( this ),
       
   440         NULL );
       
   441         
       
   442     if ( iExtension )
       
   443         {
       
   444         inputCaps.SetObjectProvider( iExtension->iExtendedInputCapabilitiesProvider );
       
   445         }
       
   446     
       
   447     return inputCaps;
       
   448     }
       
   449 
       
   450 EXPORT_C void CEikSecretEditor::GetText(TDes& aText) const
       
   451     //
       
   452     // Get the actual text typed
       
   453     //
       
   454     {
       
   455     // Check the buffer passed relative to the maximum number of characters enterable.
       
   456     // This will cause the panic to occur earlier and not depend upon how many characters 
       
   457     // have actually been entered
       
   458     __ASSERT_ALWAYS( aText.MaxLength() >= iMaxLen, Panic(EEikPanicSecretEditorTooLong));
       
   459     aText.Copy( *iSecCharArr );
       
   460     }
       
   461 
       
   462 EXPORT_C void CEikSecretEditor::SetText( const TDesC& aText )
       
   463     {
       
   464     //
       
   465     // Initialize editor (the buffer and the display)
       
   466     //
       
   467     __ASSERT_ALWAYS( aText.Length() <= iMaxLen, Panic(EEikPanicSecretEditorTooLong));
       
   468 
       
   469     TPtr secCharArrAppend = iSecCharArr->Des();
       
   470     secCharArrAppend.Zero();
       
   471     iBuf.Zero();
       
   472     secCharArrAppend.Append( aText );
       
   473     InsertSecretChar();
       
   474     ReportUpdate();
       
   475     DrawDeferred();
       
   476     UpdateCursor();
       
   477     }
       
   478 
       
   479 EXPORT_C void CEikSecretEditor::InitializeDisplay( TInt aNumberOfChars )
       
   480     {
       
   481     //
       
   482     // Initialize display with KSecretChars, doesn't affect the actual buffer.
       
   483     //
       
   484     __ASSERT_ALWAYS( aNumberOfChars <= iBuf.MaxLength(), Panic(EEikPanicSecretEditorTooLong));
       
   485     Reset();
       
   486     iBuf.Fill(KSecretChar, aNumberOfChars);
       
   487     ReportUpdate();
       
   488     DrawDeferred();
       
   489     }
       
   490 
       
   491 EXPORT_C void CEikSecretEditor::Reset()
       
   492     //
       
   493     // Clear the text
       
   494     //
       
   495     {
       
   496     TPtr secCharArrAppend = iSecCharArr->Des();
       
   497     secCharArrAppend.Zero();
       
   498     iBuf.Zero();
       
   499     ReportUpdate();
       
   500     DrawDeferred();
       
   501 	UpdateCursor();
       
   502     }
       
   503 
       
   504 EXPORT_C void CEikSecretEditor::SetMaxLength(TInt aMaxLength)
       
   505     //
       
   506     // Set the maximum number of characters for the secret editor
       
   507     //
       
   508     {
       
   509     iMaxLen=aMaxLength;
       
   510     __ASSERT_ALWAYS(iMaxLen<=EMaxSecEdSecArrayLength, Panic(EEikPanicSecretEditorTooLong));
       
   511     
       
   512     // Docs claim that CEikSecretEditor's 2nd stage construction can be
       
   513     // done either by ConstructFromResourceL() or SetMaxLength().
       
   514     // We'll have to at least try to create extension here, sadly adding to the
       
   515     // iExtension creation mess already prevalent in this class.
       
   516     if ( !iExtension )
       
   517         {
       
   518         TRAP_IGNORE ( iExtension = CEikSecretEditorExtension::NewL() );
       
   519         }
       
   520     }
       
   521 
       
   522 EXPORT_C void CEikSecretEditor::Draw(const TRect& /*aRect*/) const
       
   523     //
       
   524     // Draw the whole secret editor
       
   525     //
       
   526     {
       
   527     CWindowGc& gc=SystemGc();
       
   528 
       
   529     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   530     MAknsControlContext* cc = NULL;
       
   531 
       
   532     TRgb textColor = iEikonEnv->ControlColor(EColorControlText, *this);
       
   533     TRgb bgColor = iEikonEnv->ControlColor(EColorControlBackground, *this);
       
   534 
       
   535     if( iExtension && iExtension->iBgContextSet )
       
   536         {
       
   537         cc = iExtension->iBgContext;
       
   538         }
       
   539     else
       
   540         {
       
   541         cc = AknsDrawUtils::ControlContext( this );
       
   542         }
       
   543  
       
   544     if (iExtension)
       
   545         {
       
   546         AknsUtils::GetCachedColor(skin, textColor, KAknsIIDQsnTextColors, iExtension->iAknSkinColorIndex); 
       
   547         AknsUtils::GetCachedColor(skin, bgColor, KAknsIIDQsnTextColors, iExtension->iSkinIdForBgColor);         
       
   548         }
       
   549 
       
   550     TBool drawn(EFalse);
       
   551     
       
   552     const MCoeControlBackground* backgroundDrawer = FindBackground();
       
   553 	
       
   554     if ( !backgroundDrawer )
       
   555         {
       
   556         if ( CAknEnv::Static()->TransparencyEnabled() )
       
   557             {
       
   558             drawn = AknsDrawUtils::Background( skin, cc, this, gc, Rect(), KAknsDrawParamNoClearUnderImage );
       
   559             }
       
   560         else
       
   561             {
       
   562             drawn = AknsDrawUtils::Background( skin, cc, this, gc, Rect() );
       
   563             }
       
   564         }
       
   565     else
       
   566         {
       
   567         drawn = ETrue;
       
   568         }
       
   569 
       
   570     if( drawn )
       
   571         {
       
   572         gc.SetBrushStyle(CGraphicsContext::ENullBrush);        
       
   573         }
       
   574     else       
       
   575         {
       
   576         gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   577         gc.SetBrushColor(bgColor); // KEikSecretEditorBackgroundColor
       
   578         iBorder.Draw(SystemGc(), Rect());
       
   579         }
       
   580     
       
   581     gc.SetPenColor(textColor);
       
   582     gc.UseFont(iFont);
       
   583 
       
   584     TSize size=iBorder.SizeDelta();
       
   585 
       
   586     if ( iRevealSecretText )
       
   587         {
       
   588         gc.DrawText( iSecCharArr->Des(), iExtension->iTextRect, 
       
   589             iAscent, iAlign, 0 );
       
   590         }
       
   591     else
       
   592         {
       
   593         gc.DrawText(iBuf, iExtension->iTextRect, iAscent, iAlign, 0);
       
   594         }
       
   595         
       
   596     gc.DiscardFont();    
       
   597     }
       
   598 
       
   599 void CEikSecretEditor::InsertChar()
       
   600     {
       
   601     InsertSecretChar();
       
   602     TInt charsFit = CharsFitOnEditor();
       
   603     TInt pos = (iSecCharArr->Length() < charsFit ? iSecCharArr->Length()-1 : charsFit-1);
       
   604     if ( pos < 0 )
       
   605         return;
       
   606     iBuf.Replace(pos, 1, iSecCharArr->Right(1));
       
   607     }
       
   608 
       
   609 void CEikSecretEditor::InsertSecretChar()
       
   610     {
       
   611     TInt charsFit = CharsFitOnEditor();
       
   612     TInt pos = (iSecCharArr->Length() < charsFit ? iSecCharArr->Length() : charsFit);
       
   613     iBuf.Fill(KSecretChar, pos);
       
   614     }
       
   615 
       
   616 TInt CEikSecretEditor::CharsFitOnEditor() const
       
   617     {
       
   618     TRect rect=iBorder.InnerRect(Rect());
       
   619     const CFont* font=iFont;
       
   620     TInt ret = font->TextCount( KSecretCharString, rect.Width() );   
       
   621     return ((ret <= 1)? ret : ret-1); // there might be chars wider than asterisk visible.
       
   622     }
       
   623 
       
   624 void CEikSecretEditor::ReportUpdate()
       
   625     {
       
   626     TRAP_IGNORE (
       
   627         iExtension->iExtendedInputCapabilities->ReportEventL(
       
   628         CAknExtendedInputCapabilities::MAknEventObserver::EControlContentUpdatedInternally,
       
   629         NULL );
       
   630         )
       
   631     }
       
   632 
       
   633 EXPORT_C void CEikSecretEditor::AppendCharacterL( TInt aKeyCode )
       
   634     { // Replace this if a timer is not needed.
       
   635     if (!iTimer)
       
   636         iTimer=CPeriodic::NewL(CActive::EPriorityLow);
       
   637     if (iTimer->IsActive())
       
   638         Update();
       
   639 
       
   640     TPtr secCharArrAppend = iSecCharArr->Des();
       
   641     secCharArrAppend.Append( (TText)aKeyCode );
       
   642     iSecPos++;
       
   643     InsertChar();
       
   644     DrawDeferred();
       
   645     StartTimer();
       
   646     }
       
   647 
       
   648 EXPORT_C void CEikSecretEditor::SizeChanged()
       
   649     {
       
   650     InsertSecretChar();
       
   651     //DrawNow();
       
   652     if ( iExtension )
       
   653         {
       
   654         iExtension->iTextRect = iBorder.InnerRect( Rect() );
       
   655         TAknTextDecorationMetrics metrics( iFont );
       
   656         TInt topMargin(0);
       
   657         TInt bottomMargin(0);
       
   658         TInt leftMargin(0);
       
   659         TInt rightMargin(0);
       
   660 
       
   661         metrics.GetTopAndBottomMargins( topMargin, bottomMargin );
       
   662         metrics.GetLeftAndRightMargins( leftMargin, rightMargin );
       
   663 
       
   664         iExtension->iTextRect.iTl.iY += topMargin;
       
   665         iExtension->iTextRect.iBr.iY -= bottomMargin;
       
   666         iExtension->iTextRect.iTl.iX += leftMargin;
       
   667         iExtension->iTextRect.iBr.iX -= rightMargin;
       
   668         }
       
   669     }
       
   670 
       
   671 /**
       
   672  * Gets the list of logical colors employed in the drawing of the control,
       
   673  * paired with an explanation of how they are used. Appends the list to aColorUseList.
       
   674  *
       
   675  * @since ER5U 
       
   676  */
       
   677 EXPORT_C void CEikSecretEditor::GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList) const
       
   678     {
       
   679     CEikBorderedControl::GetColorUseListL(aColorUseList);
       
   680 
       
   681     TInt commonAttributes = TCoeColorUse::EContents|TCoeColorUse::EActive|TCoeColorUse::ENormal|TCoeColorUse::ENeutral;
       
   682     TCoeColorUse colorUse;
       
   683 
       
   684     colorUse.SetLogicalColor(EColorControlText);
       
   685     colorUse.SetUse(TCoeColorUse::EFore|commonAttributes);
       
   686     aColorUseList.AppendL(colorUse);
       
   687 
       
   688     colorUse.SetLogicalColor(EColorControlBackground);
       
   689     colorUse.SetUse(TCoeColorUse::EBack|commonAttributes);
       
   690     aColorUseList.AppendL(colorUse);
       
   691     }
       
   692 
       
   693 /**
       
   694  * Handles a change to the control's resources of type aType
       
   695  * which are shared across the environment, e.g. colors or fonts.
       
   696  *
       
   697  * @since ER5U 
       
   698  */
       
   699 EXPORT_C void CEikSecretEditor::HandleResourceChange(TInt aType)
       
   700     {
       
   701     // redraw if skin changes and skin control color has been set.
       
   702     if ( aType == KAknsMessageSkinChange && 
       
   703         iExtension && iExtension->iAknSkinColorIndex != KErrNotFound )
       
   704         {
       
   705         DrawDeferred(); // no hurry anyway.. 
       
   706         }
       
   707     if( aType == KEikDynamicLayoutVariantSwitch )
       
   708         {
       
   709         UpdateCursor();
       
   710         }
       
   711     
       
   712     CEikBorderedControl::HandleResourceChange(aType);
       
   713     }
       
   714 
       
   715 EXPORT_C TInt CEikSecretEditor::MaxLength() const
       
   716     {
       
   717     return iMaxLen;
       
   718     }
       
   719 
       
   720 EXPORT_C const TDesC& CEikSecretEditor::Buffer() const
       
   721     {
       
   722     return *iSecCharArr;
       
   723     }
       
   724 
       
   725 EXPORT_C void CEikSecretEditor::RevealSecretText( TBool aReveal )
       
   726     {
       
   727 
       
   728     TBool oldShown = iRevealSecretText;
       
   729     iRevealSecretText = aReveal;
       
   730 
       
   731     if ( !COMPARE_BOOLS( oldShown, iRevealSecretText ) )
       
   732         {
       
   733         TInt caps = iExtension->iExtendedInputCapabilities->Capabilities();
       
   734         if ( iRevealSecretText )
       
   735             {            
       
   736             caps |= CAknExtendedInputCapabilities::EInputEditorRevealSecretText;
       
   737             }
       
   738         else
       
   739             {
       
   740             caps &= ~CAknExtendedInputCapabilities::EInputEditorRevealSecretText;
       
   741             }
       
   742         iExtension->iExtendedInputCapabilities->SetCapabilities( caps );
       
   743         // Work probably done in the Draw routine
       
   744         DrawDeferred();
       
   745         }
       
   746     }
       
   747 
       
   748 EXPORT_C void CEikSecretEditor::EnableSCT( TBool aEnable )
       
   749     {
       
   750     if( iExtension )
       
   751         {
       
   752         TInt capabilities = iExtension->iExtendedInputCapabilities->Capabilities();
       
   753         if (aEnable)
       
   754             {
       
   755             capabilities &= ~CAknExtendedInputCapabilities::EDisableSCT;            
       
   756             }
       
   757         else
       
   758             {
       
   759             capabilities |= CAknExtendedInputCapabilities::EDisableSCT;
       
   760             }
       
   761         iExtension->iExtendedInputCapabilities->SetCapabilities( capabilities );
       
   762         }
       
   763     }
       
   764 
       
   765 
       
   766 // -----------------------------------------------------------------------------
       
   767 // CEikSecretEditor::SetSkinBackgroundControlContextL
       
   768 // Sets the skin control context, and also constructs CEikSecretEditorExtension
       
   769 // if not already available.
       
   770 // (other items were commented in a header).
       
   771 // -----------------------------------------------------------------------------
       
   772 //
       
   773 EXPORT_C void CEikSecretEditor::SetSkinBackgroundControlContextL(
       
   774     MAknsControlContext* aContext )
       
   775     {
       
   776     if( !iExtension )
       
   777         {
       
   778         iExtension = CEikSecretEditorExtension::NewL();
       
   779         }
       
   780     
       
   781     iExtension->iBgContext = aContext;
       
   782     iExtension->iBgContextSet = ETrue;
       
   783     }
       
   784     
       
   785 EXPORT_C void CEikSecretEditor::HandlePointerEventL(const TPointerEvent& aPointerEvent) 
       
   786     { 
       
   787     if ( iFepState )
       
   788         {
       
   789         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   790             {
       
   791             if ( iExtension 
       
   792               && iExtension->iFeedback )
       
   793                 {
       
   794                 // tactile feedback is always given on down event
       
   795                 iExtension->iFeedback->InstantFeedback( this, ETouchFeedbackEdit );
       
   796                 }
       
   797             
       
   798             CAknExtendedInputCapabilities::
       
   799                 MAknEventObserver::TPointerEventReceivedParams params;
       
   800             params.iPointerEvent = aPointerEvent;
       
   801             
       
   802             if (IsFocused() && !iExtension->iDisablePenInput)
       
   803                 {
       
   804                 TRAP_IGNORE (
       
   805                     iExtension->iExtendedInputCapabilities->ReportEventL(
       
   806                         CAknExtendedInputCapabilities::MAknEventObserver::EPointerEventReceived,
       
   807                         &params );
       
   808                       )
       
   809                 }
       
   810             }
       
   811         else if ( aPointerEvent.iType == TPointerEvent::EButton1Up && 
       
   812             iExtension && !iExtension->iDisablePenInput)
       
   813             {
       
   814             if (iExtension && iExtension->iFeedback)
       
   815                 {
       
   816                 // Edit feedback is given if PenInput will open on up event
       
   817                 iExtension->iFeedback->InstantFeedback( this,
       
   818                                                         ETouchFeedbackEdit,
       
   819                                                         ETouchFeedbackVibra,
       
   820                                                         aPointerEvent );
       
   821                 }
       
   822             TRAP_IGNORE( 
       
   823                 static_cast<CAknEdwinState*>(iFepState)->ReportAknEdStateEventL( 
       
   824                     MAknEdStateObserver::EAknActivatePenInputRequest ) 
       
   825                 );
       
   826             }
       
   827         }
       
   828 
       
   829     CEikBorderedControl::HandlePointerEventL(aPointerEvent); 
       
   830     }    
       
   831 
       
   832 EXPORT_C void* CEikSecretEditor::ExtensionInterface( TUid /*aInterface*/ )
       
   833     {
       
   834     return NULL;
       
   835     }
       
   836 
       
   837 EXPORT_C void CEikSecretEditor::Reserved_1()
       
   838     {}
       
   839 
       
   840 EXPORT_C void CEikSecretEditor::Reserved_2()
       
   841     {}
       
   842 
       
   843 EXPORT_C void CEikSecretEditor::StartFepInlineEditL(const TDesC& aInitialInlineText, TInt /*aPositionOfInsertionPointInInlineText*/, TBool /*aCursorVisibility*/, const MFormCustomDraw* /*aCustomDraw*/, MFepInlineTextFormatRetriever& /*aInlineTextFormatRetriever*/, MFepPointerEventHandlerDuringInlineEdit& /*aPointerEventHandlerDuringInlineEdit*/)
       
   844     {
       
   845     delete iInlineEditText;
       
   846     iInlineEditText = NULL;
       
   847     iInlineEditText = aInitialInlineText.AllocL();
       
   848     }
       
   849 
       
   850 EXPORT_C void CEikSecretEditor::UpdateFepInlineTextL(const TDesC& aNewInlineText, TInt /*aPositionOfInsertionPointInInlineText*/)
       
   851     {
       
   852     delete iInlineEditText;
       
   853     iInlineEditText = NULL;
       
   854     iInlineEditText = aNewInlineText.AllocL();
       
   855     }
       
   856 
       
   857 EXPORT_C void CEikSecretEditor::SetInlineEditingCursorVisibilityL(TBool /*aCursorVisibility*/)
       
   858     {
       
   859     }
       
   860 
       
   861 EXPORT_C void CEikSecretEditor::CancelFepInlineEdit()
       
   862     {
       
   863     }
       
   864 
       
   865 EXPORT_C TInt CEikSecretEditor::DocumentLengthForFep() const
       
   866     {
       
   867     return iSecCharArr->Length();
       
   868     }
       
   869 
       
   870 EXPORT_C TInt CEikSecretEditor::DocumentMaximumLengthForFep() const
       
   871     {
       
   872     return MaxLength();
       
   873     }
       
   874 
       
   875 EXPORT_C void CEikSecretEditor::SetCursorSelectionForFepL(const TCursorSelection& /*aCursorSelection*/)
       
   876     {
       
   877     }
       
   878 
       
   879 EXPORT_C void CEikSecretEditor::GetCursorSelectionForFep(TCursorSelection& aCursorSelection) const
       
   880     {
       
   881     aCursorSelection.iCursorPos = iSecCharArr->Length();
       
   882     aCursorSelection.iAnchorPos = iSecCharArr->Length();
       
   883     }
       
   884 
       
   885 EXPORT_C void CEikSecretEditor::GetEditorContentForFep(TDes& aEditorContent, TInt aDocumentPosition, TInt aLengthToRetrieve) const
       
   886     {
       
   887     aEditorContent = iSecCharArr->Mid(aDocumentPosition).Left(aLengthToRetrieve);
       
   888     }
       
   889 
       
   890 EXPORT_C void CEikSecretEditor::GetFormatForFep(TCharFormat& /*aFormat*/, TInt /*aDocumentPosition*/) const
       
   891     {
       
   892     }
       
   893 
       
   894 EXPORT_C void CEikSecretEditor::GetScreenCoordinatesForFepL(TPoint& /*aLeftSideOfBaseLine*/, TInt& /*aHeight*/, TInt& /*aAscent*/, TInt /*aDocumentPosition*/) const
       
   895     {
       
   896     }
       
   897 
       
   898 EXPORT_C void CEikSecretEditor::DoCommitFepInlineEditL()
       
   899     {
       
   900     if (iInlineEditText)
       
   901         {
       
   902         for (TInt i=0; i<iInlineEditText->Length(); i++)
       
   903             {
       
   904             if (iSecCharArr->Length()<iMaxLen)
       
   905                 AppendCharacterL((*iInlineEditText)[i]);
       
   906             }
       
   907         ReportEventL(MCoeControlObserver::EEventStateChanged);
       
   908         }
       
   909     delete iInlineEditText;
       
   910     iInlineEditText = NULL;
       
   911     }
       
   912 
       
   913 EXPORT_C MCoeFepAwareTextEditor_Extension1* CEikSecretEditor::Extension1(TBool& aSetToTrue)
       
   914     {
       
   915     aSetToTrue=ETrue;
       
   916     return this;
       
   917     }
       
   918 
       
   919 EXPORT_C void CEikSecretEditor::SetStateTransferingOwnershipL(CState* aState, TUid /*aTypeSafetyUid*/)
       
   920     {
       
   921     if (iFepState)
       
   922         delete iFepState;
       
   923     iFepState=aState;
       
   924     }
       
   925 
       
   926 EXPORT_C MCoeFepAwareTextEditor_Extension1::CState* CEikSecretEditor::State(TUid /*aTypeSafetzyUid*/)
       
   927     {
       
   928     return iFepState;
       
   929     }
       
   930 
       
   931 EXPORT_C MCoeFepAwareTextEditor_Extension1::CState* CEikSecretEditor::CreateFepStateL()
       
   932     {
       
   933     CAknEdwinState* editorState = new(ELeave) CAknEdwinState();
       
   934 
       
   935     // The status of AknLayoutUtils::Variant() is no longer checked -> Both
       
   936     // European and APAC variants enable EAknEditorFlagLatinInputModesOnly.
       
   937     editorState->SetFlags( EAknEditorFlagNoLRNavigation |
       
   938                            EAknEditorFlagLatinInputModesOnly |
       
   939                            EAknEditorFlagNoT9 |
       
   940                            EAknEditorFlagUseSCTNumericCharmap );
       
   941 
       
   942     editorState->SetDefaultInputMode(EAknEditorSecretAlphaInputMode);
       
   943     editorState->SetCurrentInputMode(EAknEditorSecretAlphaInputMode);
       
   944     editorState->SetPermittedCases(EAknEditorLowerCase|EAknEditorUpperCase);
       
   945     editorState->SetCurrentCase(EAknEditorLowerCase);    
       
   946     editorState->SetPermittedInputModes(EAknEditorSecretAlphaInputMode | EAknEditorNumericInputMode);
       
   947     editorState->SetDefaultCase(EAknEditorLowerCase);
       
   948     editorState->SetSpecialCharacterTableResourceId(R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG_LATIN_ONLY);    
       
   949     editorState->SetNumericKeymap(EAknEditorPlainNumberModeKeymap);
       
   950     editorState->SetObjectProvider(this);
       
   951     
       
   952     return editorState;
       
   953     }
       
   954 
       
   955 EXPORT_C void CEikSecretEditor::MCoeFepAwareTextEditor_Reserved_2()
       
   956     {
       
   957     }
       
   958 
       
   959 EXPORT_C void CEikSecretEditor::MCoeFepAwareTextEditor_Extension1_Reserved_2()
       
   960     {
       
   961     }
       
   962 
       
   963 EXPORT_C void CEikSecretEditor::MCoeFepAwareTextEditor_Extension1_Reserved_3()
       
   964     {
       
   965     }
       
   966 
       
   967 EXPORT_C void CEikSecretEditor::MCoeFepAwareTextEditor_Extension1_Reserved_4()
       
   968     {
       
   969     }
       
   970 
       
   971 void CEikSecretEditor::CalculateAscent()
       
   972     {
       
   973     const CAknLayoutFont* layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull( iFont );
       
   974     if ( layoutFont )
       
   975         iAscent = layoutFont->TextPaneTopToBaseline();
       
   976     else
       
   977         iAscent = iFont->AscentInPixels();
       
   978     }
       
   979     
       
   980 EXPORT_C void CEikSecretEditor::SetSkinTextColorL(TInt aAknSkinIDForTextColor, TInt aAknSkinIdForBgColor )
       
   981     {
       
   982     if( !iExtension )
       
   983         {
       
   984         iExtension = CEikSecretEditorExtension::NewL();
       
   985         }
       
   986         
       
   987     iExtension->iAknSkinColorIndex = aAknSkinIDForTextColor;
       
   988     iExtension->iSkinIdForBgColor = aAknSkinIdForBgColor;
       
   989     
       
   990     
       
   991     // if we are already visible, try to apply new color
       
   992     if (IsVisible())
       
   993         {
       
   994         DrawDeferred();
       
   995         }
       
   996     }
       
   997 
       
   998 
       
   999 EXPORT_C TInt CEikSecretEditor::SetFeature( TInt aFeatureId, TInt aFeatureParam )
       
  1000     {
       
  1001     TInt ret = KErrNone;
       
  1002     
       
  1003     if ( !SupportsFeature( aFeatureId ) )
       
  1004         {
       
  1005         ret = KErrNotSupported;
       
  1006         }
       
  1007     else
       
  1008         {
       
  1009         switch ( aFeatureId )
       
  1010             {
       
  1011             case EDisablePenInput:
       
  1012                 if ( iExtension )
       
  1013                     {
       
  1014                     iExtension->iDisablePenInput = aFeatureParam;
       
  1015                     }
       
  1016                 else
       
  1017                     {
       
  1018                     ret = KErrGeneral;
       
  1019                     }
       
  1020                 break;
       
  1021             case ELaunchPenInputAutomatic:
       
  1022                 if ( iExtension )
       
  1023                     {
       
  1024                     iExtension->iLaunchPenInputAutomatic = aFeatureParam;
       
  1025                     }
       
  1026                 else
       
  1027                     {
       
  1028                     ret = KErrGeneral;
       
  1029                     }
       
  1030                 break; 
       
  1031             case EPartialScreenInput:
       
  1032                 if ( iFepState && iExtension )
       
  1033                     {
       
  1034                     iExtension->iPartialScreenInput = aFeatureParam;
       
  1035                     CAknEdwinState* state( static_cast<CAknEdwinState*>( iFepState ) );
       
  1036                     TInt flags( state->Flags() );
       
  1037                     if ( aFeatureParam )
       
  1038                         {
       
  1039                         flags |= EAknEditorFlagEnablePartialScreen;
       
  1040                         }
       
  1041                     else
       
  1042                         {
       
  1043                         flags &= ~EAknEditorFlagEnablePartialScreen;
       
  1044                         }
       
  1045                     state->SetFlags( flags );
       
  1046                     }
       
  1047                 else
       
  1048                     {
       
  1049                     ret = KErrGeneral;
       
  1050                     }
       
  1051                 break;
       
  1052 
       
  1053             default:
       
  1054                 ret = KErrNotSupported;
       
  1055                 break;
       
  1056             }
       
  1057         }
       
  1058     
       
  1059     return ret;
       
  1060     }
       
  1061 
       
  1062 EXPORT_C TInt CEikSecretEditor::GetFeature( TInt aFeatureId, TInt& aFeatureParam ) const
       
  1063     {
       
  1064     TInt ret = KErrNone;
       
  1065     
       
  1066     if ( !SupportsFeature( aFeatureId ) )
       
  1067         {
       
  1068         ret = KErrNotSupported;
       
  1069         }
       
  1070     else
       
  1071         {
       
  1072         switch ( aFeatureId )
       
  1073             {
       
  1074             case EDisablePenInput:
       
  1075                 if ( iExtension )
       
  1076                     {
       
  1077                     aFeatureParam = iExtension->iDisablePenInput;
       
  1078                     }
       
  1079                 else
       
  1080                     {
       
  1081                     ret = KErrGeneral;
       
  1082                     }
       
  1083                 break;
       
  1084             case ELaunchPenInputAutomatic:
       
  1085                 if ( iExtension )
       
  1086                     {
       
  1087                     aFeatureParam = iExtension->iLaunchPenInputAutomatic;
       
  1088                     }
       
  1089                 else
       
  1090                     {
       
  1091                     ret = KErrGeneral;
       
  1092                     }
       
  1093                 break;
       
  1094             case EPartialScreenInput:
       
  1095                 if ( iExtension )
       
  1096                     {
       
  1097                     aFeatureParam = iExtension->iPartialScreenInput;
       
  1098                     }
       
  1099                 else
       
  1100                     {
       
  1101                     ret = KErrGeneral;
       
  1102                     }
       
  1103                 break;
       
  1104 
       
  1105             default:
       
  1106                 ret = KErrNotSupported;
       
  1107                 break;
       
  1108             }
       
  1109         }
       
  1110     return ret;
       
  1111     }
       
  1112 
       
  1113 EXPORT_C TBool CEikSecretEditor::SupportsFeature( TInt aFeatureId ) const
       
  1114     {
       
  1115     // This is done so that there is an option of leaving out
       
  1116     // a feature instead of using the enum TFeatureId, although
       
  1117     // for simplified BC that will probably never be done.
       
  1118     const TInt supportedFeatures[] = 
       
  1119         {
       
  1120         EDisablePenInput,
       
  1121         ELaunchPenInputAutomatic,
       
  1122         EPartialScreenInput
       
  1123         };
       
  1124         
       
  1125     TBool ret = EFalse;
       
  1126     
       
  1127     for ( TInt i = 0; i < sizeof( supportedFeatures ) / sizeof( TInt ); ++i )
       
  1128         {
       
  1129         if ( supportedFeatures[i] == aFeatureId )
       
  1130             {
       
  1131             ret = ETrue;
       
  1132             break;
       
  1133             }
       
  1134         }
       
  1135          
       
  1136     return ret;   
       
  1137     }
       
  1138 
       
  1139 void CEikSecretEditor::SetCursorFormat()
       
  1140     {    
       
  1141     iExtension->iCursor.iType = TTextCursor::ETypeRectangle;        
       
  1142     iExtension->iCursor.iFlags = 0;    
       
  1143     iExtension->iCursor.iHeight = AknLayoutUtils::CursorHeightFromFont( 
       
  1144         iFont->FontSpecInTwips() );
       
  1145     iExtension->iCursor.iAscent = AknLayoutUtils::CursorAscentFromFont( 
       
  1146         iFont->FontSpecInTwips() );
       
  1147     iExtension->iCursor.iWidth  = AknLayoutUtils::CursorWidthFromFont ( 
       
  1148         iFont->FontSpecInTwips() );
       
  1149     iExtension->iCursor.iColor = KRgbWhite;
       
  1150     if ( !iExtension->iWindowSet )
       
  1151         {
       
  1152 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
  1153         CRedirectionListener* listener = ( CRedirectionListener* )
       
  1154         CAknTransitionUtils::GetData( (TInt) this );
       
  1155         listener->SetWindows( &( iCoeEnv->RootWin() ), DrawableWindow() );
       
  1156 #else           
       
  1157         iExtension->iWg = &( iCoeEnv->RootWin() );
       
  1158         iExtension->iWindow = DrawableWindow();
       
  1159 #endif
       
  1160         iExtension->iWindowSet = ETrue;
       
  1161         }
       
  1162     }
       
  1163 
       
  1164 TPoint CEikSecretEditor::CursorPos()
       
  1165     {
       
  1166     TInt charsFit = CharsFitOnEditor();
       
  1167     TInt pos = ( iSecCharArr->Length() < charsFit ? 
       
  1168         iSecCharArr->Length() : charsFit );
       
  1169     TInt textWidth( iRevealSecretText ? 
       
  1170         iFont->TextWidthInPixels( *iSecCharArr ) : 
       
  1171         iFont->CharWidthInPixels( KSecretChar ) * pos );
       
  1172     TInt x;
       
  1173     if ( iAlign == CGraphicsContext::ELeft )
       
  1174     	{
       
  1175         x = iExtension->iTextRect.iTl.iX + textWidth;
       
  1176     	}
       
  1177     else if (iAlign == CGraphicsContext::ECenter)
       
  1178     	{
       
  1179         x = iExtension->iTextRect.iTl.iX +
       
  1180             (iExtension->iTextRect.Width() + textWidth) / 2;
       
  1181     	}
       
  1182     else
       
  1183     	{
       
  1184     	x = iExtension->iTextRect.iBr.iX;
       
  1185     	}
       
  1186     TInt y( Rect().iTl.iY + iAscent );    
       
  1187     return TPoint( x, y );
       
  1188     }
       
  1189 
       
  1190 EXPORT_C void CEikSecretEditor::EnableCursor( TBool aEnable )
       
  1191     {        
       
  1192     if ( !iExtension )
       
  1193         {
       
  1194         TRAPD( errorCode, iExtension = CEikSecretEditorExtension::NewL() );
       
  1195         if ( KErrNone != errorCode )
       
  1196             {
       
  1197             return;
       
  1198             }
       
  1199         }
       
  1200 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
  1201         TRAPD( errorCode, InitCRedirectionListenerL() );
       
  1202         if ( KErrNone != errorCode )
       
  1203             {
       
  1204             return;
       
  1205             }
       
  1206         CRedirectionListener* listener = ( CRedirectionListener* )
       
  1207             CAknTransitionUtils::GetData( (TInt) this );
       
  1208 #endif
       
  1209     
       
  1210     if ( aEnable )
       
  1211         {
       
  1212         SetCursorFormat();
       
  1213 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
  1214         listener->EnableCursor();
       
  1215 #else
       
  1216         iExtension->iCursorEnabled = ETrue;        
       
  1217 #endif        
       
  1218         UpdateCursor();
       
  1219         }
       
  1220     else
       
  1221         {
       
  1222 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
  1223         listener->DisableCursor();
       
  1224 #else
       
  1225         if ( iExtension->iCursorEnabled )
       
  1226             {
       
  1227             iExtension->iWg->CancelTextCursor();
       
  1228             iExtension->iCursorEnabled = EFalse;
       
  1229             }
       
  1230 #endif        
       
  1231         }
       
  1232   if ( iFepState )
       
  1233         {
       
  1234         CAknEdwinState* edwinState( static_cast<CAknEdwinState*>(
       
  1235             iFepState ) );
       
  1236         TInt flags( edwinState->Flags() );
       
  1237         if ( aEnable )
       
  1238             {
       
  1239             flags &= ~EEikEdwinAvkonDisableCursor;
       
  1240             }
       
  1241         else
       
  1242             {
       
  1243             flags |= EEikEdwinAvkonDisableCursor;
       
  1244             }
       
  1245         edwinState->SetFlags( flags );
       
  1246         }    
       
  1247     }
       
  1248 
       
  1249 void CEikSecretEditor::UpdateCursor()
       
  1250     {
       
  1251 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
  1252     CRedirectionListener* listener = ( CRedirectionListener* )
       
  1253         CAknTransitionUtils::GetData( (TInt) this );
       
  1254     listener->UpdateCursor( iExtension->iCursor );
       
  1255 #else
       
  1256     if ( iExtension->iCursorEnabled )
       
  1257         {                
       
  1258         if ( iExtension->iWindow )
       
  1259             {            
       
  1260             iExtension->iWg->SetTextCursor( *iExtension->iWindow, CursorPos(), 
       
  1261                 iExtension->iCursor );            
       
  1262             }
       
  1263         iExtension->iCursorEnabled = ETrue;
       
  1264         }
       
  1265 #endif       
       
  1266     }
       
  1267 
       
  1268 EXPORT_C void CEikSecretEditor::FocusChanged( TDrawNow /*aDrawNow*/ )
       
  1269     {
       
  1270     EnableCursor( IsFocused() );        
       
  1271     if ( IsFocused() && iExtension && !iExtension->iDisablePenInput && 
       
  1272         iExtension->iLaunchPenInputAutomatic )
       
  1273         {
       
  1274         TRAP_IGNORE( 
       
  1275             static_cast<CAknEdwinState*>(iFepState)->ReportAknEdStateEventL( 
       
  1276                 MAknEdStateObserver::EAknActivatePenInputRequest ) 
       
  1277             );
       
  1278         }
       
  1279     }
       
  1280     
       
  1281 void CEikSecretEditor::InitCRedirectionListenerL()
       
  1282     {
       
  1283 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
  1284     CRedirectionListener* listener = ( CRedirectionListener* )
       
  1285         CAknTransitionUtils::GetData( (TInt) this );    
       
  1286     if(!listener)
       
  1287     	{
       
  1288         // Create listener that listen for redirection changes
       
  1289     	CRedirectionListener* listener = new (ELeave) CRedirectionListener( *this );
       
  1290         User::LeaveIfError( CAknTransitionUtils::SetData( (TInt) this,
       
  1291             (TDesC8*) listener ) );
       
  1292         User::LeaveIfError( CAknTransitionUtils::AddObserver( listener,
       
  1293             CAknTransitionUtils::EEventWsBufferRedirection ) );
       
  1294     	} 
       
  1295 #endif
       
  1296     }