fep/aknfep/UiPlugins/AknFepUiInterface/AvkonImpl/src/insertionpoint.cpp
changeset 36 a7632c26d895
parent 35 0f326f2e628e
child 42 b3eaa440ab06
equal deleted inserted replaced
35:0f326f2e628e 36:a7632c26d895
     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 
       
    19 #include "insertionpoint.h"
       
    20 #include "aknfepchineseuidataconv.h"
       
    21 
       
    22 //Cursor position offset
       
    23 const TInt KCursorPosCorrectionX = 0;
       
    24 //define the timer
       
    25 const TInt KTimer = 500000;
       
    26 
       
    27 // ---------------------------------------------------------
       
    28 // Cancel and destroy.
       
    29 // ---------------------------------------------------------
       
    30 CInsertionPoint::~CInsertionPoint()
       
    31     {
       
    32     Cancel(); // Cancel any request, if outstanding
       
    33     iTimer.Close(); // Destroy the RTimer object
       
    34     // Delete instance variables if any
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // NewL function.
       
    39 // ---------------------------------------------------------
       
    40 CInsertionPoint* CInsertionPoint::NewL( CAknFepUiLayoutDataMgr* aLafDataMgr )
       
    41     {
       
    42     CInsertionPoint* self = CInsertionPoint::NewLC( aLafDataMgr );
       
    43     CleanupStack::Pop( self ); // self;
       
    44     return self;
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // NewLC funciton.
       
    49 // ---------------------------------------------------------
       
    50 CInsertionPoint* CInsertionPoint::NewLC( CAknFepUiLayoutDataMgr* aLafDataMgr )
       
    51     {
       
    52     CInsertionPoint* self = new ( ELeave ) CInsertionPoint( aLafDataMgr );
       
    53     CleanupStack::PushL( self ) ;
       
    54     self->ConstructL();
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // Set iRefreshObserver member.
       
    60 // ---------------------------------------------------------
       
    61 void CInsertionPoint::SetRefreshObserver(MRefreshObserver* aObserver)
       
    62     {
       
    63     iRefreshObserver = aObserver;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // Set the position of cursor.
       
    68 // ---------------------------------------------------------
       
    69 void CInsertionPoint::SetPosition(TInt aOffSet)
       
    70     {
       
    71     iOffSet = aOffSet;
       
    72     isVisible = ETrue;
       
    73     iRefreshObserver->Refresh();
       
    74     TPoint point(iTextRect.iTl.iX -1 + iOffSet + KCursorPosCorrectionX,
       
    75             iCursorRect.iTl.iY);
       
    76     iCursorRect = TRect(point, TSize(iWidth, iHeight) ) ;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // Set the rect where visual text will be displayed.
       
    81 // ---------------------------------------------------------
       
    82 void CInsertionPoint::SetTextRect(TRect aRect)
       
    83     {
       
    84     iTextRect = aRect;
       
    85     TPoint point(iTextRect.iTl.iX + iOffSet + KCursorPosCorrectionX,
       
    86             iCursorRect.iTl.iY);
       
    87     iCursorRect = TRect(point, TSize(iWidth, iHeight) ) ;
       
    88     if ( 0 == iHeight )
       
    89         {
       
    90         iHeight = 
       
    91             CAknFepChineseUIDataConv::AnyToInt( iLafDataMgr->RequestData(EEEPCursorHeight));
       
    92         iWidth = 1;
       
    93         }
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------
       
    97 // Set the height of cursor.
       
    98 // ---------------------------------------------------------
       
    99 void CInsertionPoint::SetHeight()
       
   100     {
       
   101     TPoint point(iTextRect.iTl.iX + iOffSet + KCursorPosCorrectionX,
       
   102             iTextRect.iTl.iY - 1 + iTextRect.Height() / 2 - iHeight / 2);
       
   103     iCursorRect = TRect(point, TSize(iWidth, iHeight) ) ;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // Draw the cursor on the screen.
       
   108 // ---------------------------------------------------------
       
   109 void CInsertionPoint::Draw(CWindowGc& aGc)
       
   110     {
       
   111     if (isActive)
       
   112         {
       
   113         if ( !this->isVisible)
       
   114             {
       
   115             return;
       
   116             }
       
   117         else
       
   118             {
       
   119             aGc.SetBrushStyle(CGraphicsContext::ESolidBrush) ;
       
   120             aGc.SetBrushColor(iActiveBrushColor) ;
       
   121             aGc.SetPenColor(iActivePenColor) ;
       
   122             aGc.SetPenStyle(CGraphicsContext::ESolidPen) ;
       
   123             aGc.SetPenSize(TSize( 1, 1) ) ;
       
   124             aGc.DrawRect(iCursorRect) ;
       
   125             aGc.SetBrushStyle(CGraphicsContext::ENullBrush) ;
       
   126             }
       
   127         }
       
   128     else
       
   129         {
       
   130         aGc.SetBrushStyle(CGraphicsContext::ESolidBrush) ;
       
   131         aGc.SetBrushColor(iInactiveBrushColor) ;
       
   132         aGc.SetPenColor(iInactivePenColor) ;
       
   133         aGc.SetPenStyle(CGraphicsContext::ESolidPen) ;
       
   134         aGc.SetPenSize(TSize( 1, 1) ) ;
       
   135         aGc.DrawRect(iCursorRect) ;
       
   136         aGc.SetBrushStyle(CGraphicsContext::ENullBrush) ;
       
   137         }
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------
       
   141 // Active the cursor into active state.
       
   142 // ---------------------------------------------------------
       
   143 void CInsertionPoint::Active()
       
   144     {
       
   145     Cancel();
       
   146     iTimer.Cancel();
       
   147     iTimer.After(iStatus, KTimer); // Set for 1 sec later
       
   148     SetActive(); // Tell scheduler a request is active
       
   149     isActive = ETrue;
       
   150     this->iRefreshObserver->Refresh();
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // Deactive the cursor into deactive state.
       
   155 // ---------------------------------------------------------
       
   156 void CInsertionPoint::Deactive()
       
   157     {
       
   158     Cancel();
       
   159     isActive = EFalse;
       
   160     this->iRefreshObserver->Refresh();
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------
       
   164 // Insertion Point.
       
   165 // ---------------------------------------------------------
       
   166 CInsertionPoint::CInsertionPoint( CAknFepUiLayoutDataMgr* aLafDataMgr ) :
       
   167     CActive(EPriorityStandard)
       
   168     {
       
   169     iState = EUninitialized;
       
   170     isVisible = ETrue;
       
   171     iHeight = 0;
       
   172     iWidth = 0;
       
   173     iOffSet = 0;
       
   174     isActive = EFalse;
       
   175     iRefreshObserver = NULL;
       
   176     iLafDataMgr = aLafDataMgr;
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // Two-phrase constructor.
       
   181 // ---------------------------------------------------------
       
   182 void CInsertionPoint::ConstructL()
       
   183     {
       
   184     User::LeaveIfError(iTimer.CreateLocal() ) ; // Initialize timer
       
   185     CActiveScheduler::Add( this); // Add to scheduler
       
   186     iActiveBrushColor = KRgbBlack;
       
   187     iActivePenColor = KRgbBlack;
       
   188     iInactiveBrushColor = KRgbGray;
       
   189     iInactivePenColor = KRgbGray;
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------
       
   193 // The callback function used by CActiveScheduler.
       
   194 // ---------------------------------------------------------
       
   195 void CInsertionPoint::RunL()
       
   196     {
       
   197     if (iState == EUninitialized)
       
   198         {
       
   199         // Do something the first time RunL() is called
       
   200         iState = EInitialized;
       
   201         }
       
   202     else
       
   203         if (iState != EError)
       
   204             {
       
   205             // Do something
       
   206             isVisible = isVisible ? EFalse : ETrue;
       
   207             if (iRefreshObserver)
       
   208                 {
       
   209                 this->iRefreshObserver->Refresh();
       
   210                 }
       
   211             }
       
   212     
       
   213     iTimer.Cancel();
       
   214     iTimer.After( iStatus, KTimer ) ; // Set for 1 sec later
       
   215     SetActive(); // Tell scheduler a request is active
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------
       
   219 // How to cancel me.
       
   220 // ---------------------------------------------------------
       
   221 void CInsertionPoint::DoCancel()
       
   222     {
       
   223     iTimer.Cancel();
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------
       
   227 // C++ constructor
       
   228 // ---------------------------------------------------------
       
   229 TInt CInsertionPoint::RunError(TInt aError)
       
   230     {
       
   231     return aError;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------
       
   235 // Start the cursor with glint if actived or with gray color if deactived.
       
   236 // ---------------------------------------------------------
       
   237 void CInsertionPoint::StartL( TTimeIntervalMicroSeconds32 aDelay )
       
   238     {
       
   239     Cancel(); // Cancel any request, just to be sure
       
   240     iState = EUninitialized;
       
   241     iTimer.Cancel();
       
   242     iTimer.After(iStatus, aDelay) ; // Set for later
       
   243     SetActive(); // Tell scheduler a request is active
       
   244     }
       
   245 
       
   246 // End of file