textinput/peninputarc/src/peninputlayoutcontrol/peninputlayoutcursor.cpp
changeset 0 eb1f2e154e89
child 12 5e18d8c489d6
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 "peninputlayoutcursor.h"
       
    21 #include "peninputlayouteditareabase.h"
       
    22 #include "peninputlayouttimer.h"
       
    23 #include "peninputlayoutrootctrl.h"
       
    24 
       
    25 const TInt KDefaultCursorHeight = 10;
       
    26 // ============================ MEMBER FUNCTIONS =============================
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // CFepUiCursor::CFepUiCursor
       
    30 // C++ default constructor can NOT contain any code, that might leave
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CFepUiCursor::CFepUiCursor(const TRect& aRect,CFepUiLayout* aUiLayout,TInt aId)
       
    34                 :CFepUiBaseCtrl(aRect,aUiLayout,aId),
       
    35                 iPosition(0, 0),
       
    36                  iHeight(KDefaultCursorHeight),
       
    37                  iIsOn(EFalse),
       
    38                  iIsVisible(EFalse),
       
    39                  //iEditor(aOwner),
       
    40                  //iBitmapDevice(aBitmapDevice),
       
    41                  //iGc(aGc),
       
    42                  iCursorTempDisabled(EFalse)
       
    43     {
       
    44     SetControlType(ECtrlCursor);
       
    45     }
       
    46  
       
    47 // ---------------------------------------------------------------------------
       
    48 // CFepUiCursor::ConstructL
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 void CFepUiCursor::ConstructL()
       
    53     {
       
    54     CFepUiBaseCtrl::BaseConstructL();
       
    55     iCursorBlinkingTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
    56     iRestoreCursorTimer = CLayoutTimer::NewL(this,CLayoutTimer::EOthers);
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CFepUiCursor::NewL
       
    61 // Two-phased constructor.
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CFepUiCursor* CFepUiCursor::NewL(const TRect& aRect,CFepUiLayout* aUiLayout,TInt aId)
       
    65     {
       
    66     CFepUiCursor* self = new(ELeave) CFepUiCursor(aRect, aUiLayout,aId);
       
    67     CleanupStack::PushL(self);
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop(self); // insertionPoint
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CFepUiCursor::~CFepUiCursor
       
    75 // Destructor
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CFepUiCursor::~CFepUiCursor()
       
    79     {
       
    80     if(iCursorBlinkingTimer)
       
    81         {        
       
    82         iCursorBlinkingTimer->Cancel();
       
    83         delete iCursorBlinkingTimer;
       
    84         }    
       
    85    
       
    86     delete iRestoreCursorTimer;
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CFepUiCursor::SetPosition
       
    92 // Sets the position of the sprite if it has been turned on
       
    93 // (other items were commented in a header).
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C void CFepUiCursor::SetPosition(const TPoint& aPosition)
       
    97     {
       
    98     
       
    99     TBool isOn = iIsOn;
       
   100     if (isOn)
       
   101         {
       
   102         SetOn(EFalse);
       
   103         }
       
   104     iPosition=aPosition;
       
   105     TPoint correction(KCursorPosCorrectionX,KCursorPosCorrectionY );
       
   106     TRect rect = TRect(iPosition + correction , TSize(KCursorWidth,iHeight));
       
   107     if(rect != iCursorRect)
       
   108         {
       
   109         SetRect(rect);
       
   110         iCursorRect = rect;
       
   111         //must update clip region again.
       
   112         for(TInt i = 0 ; i < RootControl()->PopCtrlList().Count(); ++i)
       
   113             {
       
   114             UpdateValidRegion(RootControl()->PopCtrlList()[i],EFalse);
       
   115             }
       
   116         }
       
   117         
       
   118     if (isOn)
       
   119         {
       
   120         SetOn(ETrue);
       
   121         }
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CFepUiCursor::Position
       
   126 // get the cursor position
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 EXPORT_C TPoint CFepUiCursor::Position()
       
   130     {
       
   131     return iPosition;
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CFepUiCursor::SetLayoutOwner
       
   136 // Sets the layout owner
       
   137 // (other items were commented in a header).
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 /*void CFepUiCursor::SetLayoutOwner(MLayoutOwner* aOwner)
       
   141     {
       
   142     iLayoutOwner = aOwner;
       
   143     }
       
   144 */
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CFepUiCursor::SetOn
       
   148 // Turns the sprite on and off
       
   149 // (other items were commented in a header).
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 EXPORT_C void CFepUiCursor::SetOn(TBool aOn, TBool aImmediately)
       
   153     {
       
   154     //aOn = EFalse;
       
   155     iIsOn = aOn;    
       
   156 
       
   157     // If cursor will bee set off and timer is active, Cancel timer
       
   158     if ( !iIsOn )
       
   159         {
       
   160         CancelDelayCursorShown();
       
   161         if ( iCursorBlinkingTimer->IsActive())
       
   162             {
       
   163             iCursorBlinkingTimer->Cancel();    
       
   164             }
       
   165         }
       
   166     else
       
   167         {
       
   168         if(iCursorTempDisabled)
       
   169             {
       
   170             return;
       
   171             }
       
   172         // Activate blinking timer, if it is not already activated
       
   173         if ( !iCursorBlinkingTimer->IsActive() )
       
   174             {
       
   175             iCursorBlinkingTimer->Start(aImmediately ? 0: KCursorBlinkPerioid,
       
   176                    KCursorBlinkPerioid,TCallBack(CursorBlinkCallBack , this));
       
   177             }
       
   178         }
       
   179         
       
   180         // Invalidate InsertionPoint's rect, so it will be removed from editarea
       
   181     InvalidateInsertionPoint();
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CFepUiCursor::SetHeight
       
   186 // Sets caret height
       
   187 // (other items were commented in a header).
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 EXPORT_C void CFepUiCursor::SetHeight(TInt aHeight)
       
   191     {
       
   192     if(aHeight > 0 && aHeight != iHeight )
       
   193         {
       
   194         TBool isOn = iIsOn;
       
   195         if (isOn)
       
   196             {
       
   197             SetOn(EFalse);
       
   198             }
       
   199 
       
   200         iHeight = aHeight;
       
   201         //change the cursor rect
       
   202         TPoint correction(KCursorPosCorrectionX,KCursorPosCorrectionY );
       
   203         iCursorRect = TRect(iPosition + correction , 
       
   204                                     TSize(KCursorWidth,iHeight));
       
   205         if (isOn)
       
   206             {
       
   207             SetOn(ETrue);
       
   208             }
       
   209         }   
       
   210        
       
   211     }
       
   212 
       
   213 EXPORT_C void CFepUiCursor::ReDraw(TBool aReset)
       
   214     {
       
   215     if(aReset)
       
   216         iIsVisible = EFalse;
       
   217     Draw();
       
   218     UpdateArea(iCursorRect,EFalse);
       
   219     }
       
   220     
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CFepUiCursor::Draw
       
   224 // Draws insertion point's Rect and starts blinking timer
       
   225 // (other items were commented in a header).
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void CFepUiCursor::Draw()//CBitmapContext* aGc, TBool aReset)
       
   229     {
       
   230     if(!AbleToDraw())
       
   231         {
       
   232         return;
       
   233         }
       
   234     
       
   235     /*if (aReset)    
       
   236         {
       
   237         iIsVisible = EFalse;
       
   238         }
       
   239       */  
       
   240 
       
   241     CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc());                
       
   242     gc->Activate( BitmapDevice());    
       
   243     if(iIsOn)
       
   244         {        
       
   245         // draw cursor by inverting colors in the selected text rectancle
       
   246         gc->SetClippingRegion(ValidClipRegion());        	        
       
   247         
       
   248         gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   249         gc->SetBrushColor(KRgbBlack);
       
   250         gc->SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
       
   251 
       
   252         gc->SetPenColor(KRgbBlack);
       
   253         gc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   254         gc->SetPenSize( TSize(1,1));
       
   255 
       
   256         // When the blink timer out and cursor is visible, do nothing
       
   257         // else draw the cursor and set the visible flag
       
   258         gc->DrawRect(iCursorRect);
       
   259         iIsVisible = !iIsVisible;
       
   260 
       
   261         // restore normal draw mode
       
   262         gc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   263         gc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   264         
       
   265         //if (iEditor)
       
   266             {
       
   267           //  iEditor->UpdateArea(iCursorRect,EFalse);
       
   268             }
       
   269         
       
   270      //   UpdateArea(iCursorRect,EFalse);
       
   271         } 
       
   272     else
       
   273         {
       
   274         if(iIsVisible) //only do when already shown
       
   275             {                
       
   276             //CFbsBitmapDevice* bitmapDevice = iEditor->BitmapDevice();  
       
   277             //static_cast<CFbsBitGc*>(gc)->Activate(iBitmapDevice);
       
   278             gc->SetClippingRegion(ValidClipRegion());        	    
       
   279             gc->SetPenColor(KRgbBlack);
       
   280             gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   281             gc->SetBrushColor(KRgbBlack);
       
   282             gc->SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
       
   283             gc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   284             gc->SetPenSize( TSize(1,1));
       
   285             gc->DrawRect(iCursorRect);
       
   286 
       
   287             // restore normal draw mode
       
   288             gc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   289             gc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   290             
       
   291             iIsVisible = EFalse;                       
       
   292 
       
   293             /*if (iEditor)
       
   294                 {
       
   295                 iEditor->UpdateArea(iCursorRect,EFalse);
       
   296                 }*/
       
   297        //     UpdateArea(iCursorRect,EFalse);                
       
   298             }   
       
   299         }
       
   300     gc->CancelClippingRegion();        	        
       
   301     }
       
   302     
       
   303 // ---------------------------------------------------------------------------
       
   304 // CFepUiCursor::CursorBlinkCallBack
       
   305 // Invalidates cursor rect, when timer gets out. 
       
   306 // With periodic caused draw/undraw of cursor will cause cursor blinking
       
   307 // (other items were commented in a header).
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 TInt CFepUiCursor::CursorBlinkCallBack(TAny *aPtr)
       
   311     {
       
   312     CFepUiCursor* self = static_cast<CFepUiCursor*>(aPtr); 
       
   313            
       
   314     self->InvalidateInsertionPoint();
       
   315         
       
   316     return(ETrue);        
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // CFepUiCursor::InvalidateCursor
       
   321 // Invalidates InsertionPoint's rect
       
   322 // (other items were commented in a header).
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 void CFepUiCursor::InvalidateInsertionPoint()
       
   326     {    
       
   327     //if(iEditor)
       
   328         {        
       
   329         Draw();
       
   330         UpdateArea(iCursorRect,EFalse);
       
   331         }
       
   332     }
       
   333   
       
   334 // ---------------------------------------------------------------------------
       
   335 // CFepUiCursor::DelayCursorWhileDraging
       
   336 // Disable the cursor while pen is draging
       
   337 // (other items were commented in a header).
       
   338 // ---------------------------------------------------------------------------
       
   339 //    
       
   340 EXPORT_C void CFepUiCursor::DelayCursorWhileDraging()
       
   341     {
       
   342     DelayCursorShown();
       
   343     }
       
   344   
       
   345 // ---------------------------------------------------------------------------
       
   346 // CFepUiCursor::DelayCursorShown
       
   347 // Disable the cursor while pen is draging
       
   348 // (other items were commented in a header).
       
   349 // ---------------------------------------------------------------------------
       
   350 EXPORT_C void CFepUiCursor::DelayCursorShown()
       
   351     {
       
   352     if(!iIsOn && !iCursorTempDisabled) // do nothing is cursor is off
       
   353         return;
       
   354     
       
   355     if(!iCursorTempDisabled)
       
   356         {
       
   357         SetOn(EFalse);  // disable the cursor
       
   358         iCursorTempDisabled = ETrue;
       
   359         }
       
   360     iRestoreCursorTimer->SetTimer(KCursorBlinkPerioid);
       
   361     }
       
   362 // ---------------------------------------------------------------------------
       
   363 // cancel delay shown process
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 void CFepUiCursor::CancelDelayCursorShown()
       
   367     {
       
   368     iRestoreCursorTimer->Cancel();
       
   369     iCursorTempDisabled = EFalse;
       
   370     }
       
   371 // ---------------------------------------------------------------------------
       
   372 // CFepUiCursor::HandleTimerOut
       
   373 // Set the cursor on
       
   374 // (other items were commented in a header).
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 void CFepUiCursor::HandleTimerOut(TInt /*aTimeType*/)
       
   378     {
       
   379     iCursorTempDisabled = EFalse;
       
   380     iIsOn = ETrue;
       
   381     //To avoid the ugly first shown, we draw the cursor directly here.
       
   382     InvalidateInsertionPoint();
       
   383     SetOn(ETrue, EFalse);    
       
   384     }
       
   385     
       
   386     
       
   387 // ---------------------------------------------------------------------------
       
   388 // CFepUiCursor::UpdateValidRegion
       
   389 // Update control's valid region when other control show or hide.
       
   390 // (other items were commented in a header).
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 EXPORT_C void CFepUiCursor::UpdateValidRegion(CFepUiBaseCtrl* aCtrl,TBool aRemoveFlag)
       
   394     {
       
   395     if(!iUpdateFlagEnabled)
       
   396         return;
       
   397    
       
   398     if(aRemoveFlag)
       
   399         {
       
   400         }
       
   401     else
       
   402         {
       
   403         if(aCtrl->Hiden())
       
   404             return;
       
   405         TRect rect = Rect();
       
   406         rect.Intersection(aCtrl->Rect());
       
   407         iValidRegion.SubRect(rect);
       
   408         iClipRegion.SubRect(rect);
       
   409         }
       
   410         //iValidRegion.AddRect(iRect);
       
   411     return;
       
   412     }
       
   413 
       
   414 TInt CFepUiCursor::OrderPos()
       
   415     {
       
   416     TInt ret = 0;
       
   417     TRAP_IGNORE(ret = OrderPosL());
       
   418     return ret;
       
   419     }
       
   420 
       
   421 TInt CFepUiCursor::OrderPosL()
       
   422     {
       
   423     __ASSERT_DEBUG(iEditor,User::Leave(EUiCursorNoOwner));
       
   424     return iEditor->OrderPos();    
       
   425     }
       
   426     
       
   427     
       
   428 void CFepUiCursor::ResetValidClipRegion()
       
   429     {
       
   430     iValidRegion.Clear();
       
   431     iClipRegion.Clear();
       
   432     iValidRegion.AddRect(iRect);
       
   433     iClipRegion.AddRect(iRect);
       
   434     }
       
   435     
       
   436 void CFepUiCursor::UpdateCursorArea(const TRect& aRect, TBool aFlag)
       
   437     {
       
   438     CFepUiBaseCtrl* parent = iEditor->ParentCtrl();
       
   439     
       
   440     if(parent)
       
   441         {
       
   442         if(parent->IsKindOfControl(ECtrlControlGroup))     
       
   443             static_cast<CControlGroup*>(parent)->UpdateAreaInGrp(iEditor,aRect,aFlag);
       
   444         else
       
   445             iEditor->ParentCtrl()->UpdateArea(aRect,aFlag);
       
   446         }
       
   447     else
       
   448         UpdateArea(aRect,aFlag);    
       
   449     }
       
   450 //  End of File