textinput/peninputarc/src/peninputlayoutcontrol/peninputlayoutinsertionpoint.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2005-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation for insertion point
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "peninputlayoutinsertionpoint.h"
       
    21 #include "peninputlayouteditareabase.h"
       
    22 #include "peninputlayouttimer.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS =============================
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CInsertionPoint::CInsertionPoint
       
    28 // C++ default constructor can NOT contain any code, that might leave
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CInsertionPoint::CInsertionPoint(CFepUiBaseCtrl* aOwner,CFbsBitmapDevice* aBitmapDevice,
       
    32                                  CBitmapContext* aGc,TInt aHeight)
       
    33     :iPosition(0, 0),
       
    34      iHeight(aHeight),
       
    35      iIsOn(EFalse),
       
    36      iIsVisible(EFalse),
       
    37      iEditor(aOwner),
       
    38      iBitmapDevice(aBitmapDevice),
       
    39      iGc(aGc),
       
    40      iCursorTempDisabled(EFalse)
       
    41     {
       
    42     }
       
    43  
       
    44 // ---------------------------------------------------------------------------
       
    45 // CInsertionPoint::ConstructL
       
    46 // Symbian 2nd phase constructor can leave.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 void CInsertionPoint::ConstructL()
       
    50     {
       
    51     iCursorBlinkingTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
    52     iRestoreCursorTimer = CLayoutTimer::NewL(this,CLayoutTimer::EOthers);
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CInsertionPoint::NewL
       
    57 // Two-phased constructor.
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C CInsertionPoint* CInsertionPoint::NewL(CFepUiBaseCtrl* aOwner,CFbsBitmapDevice* 
       
    61                                        aBitmapDevice,CBitmapContext* aGc,TInt aHeight)
       
    62     {
       
    63     CInsertionPoint* self = new(ELeave) CInsertionPoint(aOwner,aBitmapDevice,aGc,aHeight);
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop(self); // insertionPoint
       
    67     return self;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CInsertionPoint::~CInsertionPoint
       
    72 // Destructor
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CInsertionPoint::~CInsertionPoint()
       
    76     {
       
    77     if(iCursorBlinkingTimer)
       
    78         {        
       
    79         iCursorBlinkingTimer->Cancel();
       
    80         delete iCursorBlinkingTimer;
       
    81         }    
       
    82    
       
    83     delete iRestoreCursorTimer;
       
    84     }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CInsertionPoint::SetPosition
       
    89 // Sets the position of the sprite if it has been turned on
       
    90 // (other items were commented in a header).
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C void CInsertionPoint::SetPosition(const TPoint& aPosition)
       
    94     {
       
    95     
       
    96     TBool isOn = iIsOn;
       
    97     if (isOn)
       
    98         {
       
    99         SetOn(EFalse);
       
   100         }
       
   101     iPosition=aPosition;
       
   102     TPoint correction(KCursorPosCorrectionX,KCursorPosCorrectionY );
       
   103     iCursorRect = TRect(iPosition + correction , TSize(KCursorWidth,iHeight));
       
   104 
       
   105     if (isOn)
       
   106         {
       
   107         SetOn(ETrue);
       
   108         }
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CInsertionPoint::Position
       
   113 // get the cursor position
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 TPoint CInsertionPoint::Position()
       
   117     {
       
   118     return iPosition;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CInsertionPoint::SetLayoutOwner
       
   123 // Sets the layout owner
       
   124 // (other items were commented in a header).
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 /*void CInsertionPoint::SetLayoutOwner(MLayoutOwner* aOwner)
       
   128     {
       
   129     iLayoutOwner = aOwner;
       
   130     }
       
   131 */
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CInsertionPoint::SetOn
       
   135 // Turns the sprite on and off
       
   136 // (other items were commented in a header).
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 EXPORT_C void CInsertionPoint::SetOn(TBool aOn)
       
   140     {
       
   141     iIsOn = aOn;    
       
   142     
       
   143     if(iCursorTempDisabled)
       
   144         return;
       
   145     // If cursor will bee set off and timer is active, Cancel timer
       
   146     if ( !iIsOn )
       
   147         {
       
   148         if ( iCursorBlinkingTimer->IsActive())
       
   149             {
       
   150             iCursorBlinkingTimer->Cancel();    
       
   151             }
       
   152         }
       
   153     else
       
   154         {
       
   155         // Activate blinking timer, if it is not already activated
       
   156         if ( !iCursorBlinkingTimer->IsActive() )
       
   157             {
       
   158             iCursorBlinkingTimer->Start(0, 
       
   159                    KCursorBlinkPerioid,TCallBack(CursorBlinkCallBack , this));
       
   160             }      
       
   161         }
       
   162         
       
   163         // Invalidate InsertionPoint's rect, so it will be removed from editarea
       
   164     InvalidateInsertionPoint();
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CInsertionPoint::SetHeight
       
   169 // Sets caret height
       
   170 // (other items were commented in a header).
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C void CInsertionPoint::SetHeight(TInt aHeight)
       
   174     {
       
   175     if(aHeight > 0 && aHeight != iHeight )
       
   176         {
       
   177         TBool isOn = iIsOn;
       
   178         if (isOn)
       
   179             {
       
   180             SetOn(EFalse);
       
   181             }
       
   182 
       
   183         iHeight = aHeight;
       
   184         //change the cursor rect
       
   185         TPoint correction(KCursorPosCorrectionX,KCursorPosCorrectionY );
       
   186         iCursorRect = TRect(iPosition + correction , 
       
   187                                     TSize(KCursorWidth,iHeight));
       
   188         if (isOn)
       
   189             {
       
   190             SetOn(ETrue);
       
   191             }
       
   192         }   
       
   193        
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CInsertionPoint::Draw
       
   198 // Draws insertion point's Rect and starts blinking timer
       
   199 // (other items were commented in a header).
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 EXPORT_C void CInsertionPoint::Draw(CBitmapContext* aGc, TBool aReset)
       
   203     {
       
   204     if(!iEditor || !iEditor->AbleToDraw())
       
   205         return;
       
   206     if (aReset)    
       
   207         {
       
   208         iIsVisible = EFalse;
       
   209         }
       
   210         
       
   211     if(iIsOn)
       
   212         {        
       
   213         // draw cursor by inverting colors in the selected text rectancle
       
   214         static_cast<CFbsBitGc*>(aGc)->Activate( iBitmapDevice );
       
   215         aGc->SetClippingRegion(iEditor->ValidClipRegion());        	        
       
   216         
       
   217         aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   218         aGc->SetBrushColor(KRgbBlack);
       
   219         aGc->SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
       
   220 
       
   221         aGc->SetPenColor(KRgbBlack);
       
   222         aGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   223         aGc->SetPenSize( TSize(1,1));
       
   224 
       
   225         aGc->DrawRect(iCursorRect);
       
   226         iIsVisible = !iIsVisible;
       
   227 
       
   228         // restore normal draw mode
       
   229         aGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   230         aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   231         
       
   232         if (iEditor)
       
   233             {
       
   234             iEditor->UpdateArea(iCursorRect,EFalse);
       
   235             }
       
   236         
       
   237         // Activate blinking timer, if it is not already activated
       
   238         if ( !iCursorBlinkingTimer->IsActive() )
       
   239     	    {
       
   240             iCursorBlinkingTimer->Start(KCursorBlinkPerioid, KCursorBlinkPerioid, 
       
   241                                         TCallBack(CursorBlinkCallBack , this));	
       
   242     	    }
       
   243         } 
       
   244     else
       
   245         {
       
   246         if(iIsVisible) //only do when already shown
       
   247             {                
       
   248             //CFbsBitmapDevice* bitmapDevice = iEditor->BitmapDevice();  
       
   249             static_cast<CFbsBitGc*>(aGc)->Activate(iBitmapDevice);
       
   250             aGc->SetClippingRegion(iEditor->ValidClipRegion());        	    
       
   251             aGc->SetPenColor(KRgbBlack);
       
   252             aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   253             aGc->SetBrushColor(KRgbBlack);
       
   254             aGc->SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
       
   255             aGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   256             aGc->SetPenSize( TSize(1,1));
       
   257             aGc->DrawRect(iCursorRect);
       
   258 
       
   259             // restore normal draw mode
       
   260             aGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   261             aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   262             
       
   263             iIsVisible = EFalse;                       
       
   264 
       
   265             if (iEditor)
       
   266                 {
       
   267                 iEditor->UpdateArea(iCursorRect,EFalse);
       
   268                 }
       
   269             }   
       
   270         }
       
   271     aGc->CancelClippingRegion();        	        
       
   272     }
       
   273     
       
   274 // ---------------------------------------------------------------------------
       
   275 // CInsertionPoint::CursorBlinkCallBack
       
   276 // Invalidates cursor rect, when timer gets out. 
       
   277 // With periodic caused draw/undraw of cursor will cause cursor blinking
       
   278 // (other items were commented in a header).
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 TInt CInsertionPoint::CursorBlinkCallBack(TAny *aPtr)
       
   282     {
       
   283     CInsertionPoint* self = static_cast<CInsertionPoint*>(aPtr); 
       
   284            
       
   285     self->InvalidateInsertionPoint();
       
   286         
       
   287     return(ETrue);        
       
   288     }
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // CInsertionPoint::InvalidateCursor
       
   292 // Invalidates InsertionPoint's rect
       
   293 // (other items were commented in a header).
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CInsertionPoint::InvalidateInsertionPoint()
       
   297     {    
       
   298     if(iEditor)
       
   299         {        
       
   300         Draw(iGc);
       
   301         }
       
   302     }
       
   303   
       
   304 // ---------------------------------------------------------------------------
       
   305 // CInsertionPoint::DelayCursorWhileDraging
       
   306 // Disable the cursor while pen is draging
       
   307 // (other items were commented in a header).
       
   308 // ---------------------------------------------------------------------------
       
   309 //    
       
   310 EXPORT_C void CInsertionPoint::DelayCursorWhileDraging()
       
   311     {
       
   312     if(!iIsOn && !iCursorTempDisabled) // do nothing is cursor is off
       
   313         return;
       
   314     
       
   315     if(!iCursorTempDisabled)
       
   316         {
       
   317         SetOn(EFalse);  // disable the cursor
       
   318         iCursorTempDisabled = ETrue;
       
   319         }
       
   320     iRestoreCursorTimer->SetTimer(KCursorBlinkPerioid);
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // CInsertionPoint::HandleTimerOut
       
   325 // Set the cursor on
       
   326 // (other items were commented in a header).
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 void CInsertionPoint::HandleTimerOut(TInt /*aTimeType*/)
       
   330     {
       
   331     iCursorTempDisabled = EFalse;
       
   332     iIsOn = ETrue;
       
   333     //To avoid the ugly first shown, we draw the cursor directly here.
       
   334     InvalidateInsertionPoint();
       
   335     SetOn(ETrue);    
       
   336     }
       
   337 //  End of File