uifw/ganes/src/HgTextFind.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:     
       
    15 *
       
    16 */
       
    17 
       
    18 #include "HgTextFind.h"
       
    19 #include <ganes/HgScroller.h>
       
    20 #include "HgConstants.h"
       
    21 
       
    22 // -----------------------------------------------------------------------------
       
    23 // CHgTextFind::NewL()
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 CHgTextFind* CHgTextFind::NewL(CHgScroller& aScroller)
       
    27     {
       
    28     CHgTextFind* self = new (ELeave) CHgTextFind( aScroller );
       
    29     CleanupStack::PushL(self);
       
    30     self->ConstructL();
       
    31     CleanupStack::Pop(self);
       
    32     return self;
       
    33     }
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CHgTextFind::~CHgTextFind()
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CHgTextFind::~CHgTextFind()
       
    40     {
       
    41     delete iState;
       
    42     iBuf.Close();
       
    43     iSearchDesc.Close();
       
    44     delete iTimer;
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CHgTextFind::CHgTextFind()
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CHgTextFind::CHgTextFind( CHgScroller& aScroller ) 
       
    52     : iScroller( aScroller)
       
    53     {
       
    54             
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CHgTextFind::ConstructL()
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CHgTextFind::ConstructL()
       
    62     {
       
    63     iState = new (ELeave) CAknEdwinState();
       
    64     iState->SetObjectProvider(&iScroller);
       
    65     iState->SetDefaultCase( EAknEditorUpperCase );
       
    66     iState->SetFlags(
       
    67             EAknEditorFlagFixedCase |
       
    68             EAknEditorFlagNoT9 |
       
    69             EAknEditorFlagNoEditIndicators |
       
    70             EAknEditorFlagNoLRNavigation |
       
    71             EAknEditorFlagSupressShiftMenu
       
    72             );
       
    73     
       
    74     iBuf.CreateL( KMaxPopupTextLength );
       
    75     iSearchDesc.CreateL( KMaxSearchLenght );
       
    76     iTimer = CPeriodic::New( CActive::EPriorityLow );
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CHgTextFind::StartFepInlineEditL()
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CHgTextFind::StartFepInlineEditL( const TDesC& aInitialInlineText, 
       
    84         TInt /*aPositionOfInsertionPointInInlineText*/, 
       
    85         TBool /*aCursorVisibility*/, const MFormCustomDraw* /*aCustomDraw*/,
       
    86         MFepInlineTextFormatRetriever& /*aInlineTextFormatRetriever*/, 
       
    87         MFepPointerEventHandlerDuringInlineEdit& /*aPointerEventHandlerDuringInlineEdit*/ )
       
    88     {
       
    89     iTimer->Cancel();
       
    90     if( iBuf.Length() + aInitialInlineText.Length() < iBuf.MaxLength() )
       
    91         iBuf.Append(aInitialInlineText);
       
    92     iScroller.DrawNow();
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CHgTextFind::UpdateFepInlineTextL()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CHgTextFind::UpdateFepInlineTextL( const TDesC& aNewInlineText, 
       
   100         TInt /*aPositionOfInsertionPointInInlineText*/ )
       
   101     {
       
   102     iTimer->Cancel();
       
   103     if( iBuf.Length() + aNewInlineText.Length() < iBuf.MaxLength() )
       
   104         {
       
   105         if(iBuf.Length())
       
   106             {
       
   107             if( aNewInlineText.Length() )
       
   108                 {
       
   109                 iBuf.Replace(iBuf.Length()-1, aNewInlineText.Length(), aNewInlineText);
       
   110                 iScroller.DrawNow();
       
   111                 }
       
   112             else
       
   113                 {
       
   114                 iBuf.Delete(iBuf.Length()-1, 1);
       
   115                 }
       
   116             }
       
   117         else
       
   118             {
       
   119             iBuf.Append(aNewInlineText);
       
   120             iScroller.DrawNow();
       
   121             }
       
   122         }
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CHgTextFind::SetInlineEditingCursorVisibilityL()
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CHgTextFind::SetInlineEditingCursorVisibilityL( TBool /*aCursorVisibility*/ )
       
   130     {
       
   131     
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CHgTextFind::CancelFepInlineEdit()
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CHgTextFind::CancelFepInlineEdit()
       
   139     {
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CHgTextFind::DocumentLengthForFep()
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 TInt CHgTextFind::DocumentLengthForFep() const
       
   147     {
       
   148     return iBuf.Length();
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CHgTextFind::DocumentMaximumLengthForFep()
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 TInt CHgTextFind::DocumentMaximumLengthForFep() const
       
   156     {
       
   157     return iBuf.MaxLength();
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CHgTextFind::SetCursorSelectionForFepL()
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CHgTextFind::SetCursorSelectionForFepL( const TCursorSelection& /*aCursorSelection*/ )
       
   165     {
       
   166     
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CHgTextFind::GetCursorSelectionForFep()
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CHgTextFind::GetCursorSelectionForFep( TCursorSelection& /*aCursorSelection*/ ) const
       
   174     {
       
   175     
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CHgTextFind::GetEditorContentForFep()
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CHgTextFind::GetEditorContentForFep( TDes& /*aEditorContent*/,
       
   183         TInt /*aDocumentPosition*/, TInt /*aLengthToRetrieve*/ ) const
       
   184     {
       
   185     
       
   186     }
       
   187     
       
   188 // -----------------------------------------------------------------------------
       
   189 // CHgTextFind::GetFormatForFep()
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CHgTextFind::GetFormatForFep( TCharFormat& /*aFormat*/, TInt /*aDocumentPosition*/ ) const
       
   193     {
       
   194     
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CHgTextFind::GetScreenCoordinatesForFepL()
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CHgTextFind::GetScreenCoordinatesForFepL( TPoint& /*aLeftSideOfBaseLine*/,
       
   202         TInt& /*aHeight*/, TInt& /*aAscent*/, TInt /*aDocumentPosition*/ ) const
       
   203     {
       
   204     
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CHgTextFind::Extension1()
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 MCoeFepAwareTextEditor_Extension1* CHgTextFind::Extension1(TBool& aSetToTrue)
       
   212     {
       
   213     aSetToTrue = ETrue;
       
   214     return this;
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CHgTextFind::SetStateTransferingOwnershipL()
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 void CHgTextFind::SetStateTransferingOwnershipL( CState* /*aState*/, TUid /*aTypeSafetyUid*/ )
       
   222 // this function must only transfer ownership after it has successfully done everything that can leave
       
   223     {
       
   224     
       
   225     }
       
   226 // -----------------------------------------------------------------------------
       
   227 // CHgTextFind::State()
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 MCoeFepAwareTextEditor_Extension1::CState* CHgTextFind::State( TUid /*aTypeSafetyUid */ )
       
   231     {
       
   232     return iState;
       
   233     }
       
   234 
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CHgTextFind::DoCommitFepInlineEditL()
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 void CHgTextFind::DoCommitFepInlineEditL()
       
   241     {
       
   242     iSearchDesc.Copy(iBuf);
       
   243     iSearchDesc.UpperCase();
       
   244     iScroller.HightlightItem(iSearchDesc);
       
   245     iTimer->Cancel();
       
   246     iTimer->Start(KSearchEndTimeOut, KSearchEndTimeOut,
       
   247             TCallBack(CHgTextFind::SearchTimerCallback, this));
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CHgTextFind::SearchTimerCallback()
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 TInt CHgTextFind::SearchTimerCallback( TAny* aSelf )
       
   255     {
       
   256     CHgTextFind* self = (CHgTextFind*)aSelf;
       
   257     self->ClearSearchDesc();
       
   258     return KErrNone;
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CHgTextFind::ClearSearchDesc()
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CHgTextFind::ClearSearchDesc()
       
   266     {
       
   267     iBuf.Zero();
       
   268     iTimer->Cancel();
       
   269     iScroller.DrawDeferred();
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CHgTextFind::Text()
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 const TDesC& CHgTextFind::Text()
       
   277     {
       
   278     return iBuf;
       
   279     }
       
   280 
       
   281