textinput/peninputarc/src/peninputlayoutcontrol/peninputlayoutcursor.cpp
branchRCL_3
changeset 21 ecbabf52600f
parent 20 ebd48d2de13c
equal deleted inserted replaced
20:ebd48d2de13c 21:ecbabf52600f
    19 
    19 
    20 #include "peninputlayoutcursor.h"
    20 #include "peninputlayoutcursor.h"
    21 #include "peninputlayouteditareabase.h"
    21 #include "peninputlayouteditareabase.h"
    22 #include "peninputlayouttimer.h"
    22 #include "peninputlayouttimer.h"
    23 #include "peninputlayoutrootctrl.h"
    23 #include "peninputlayoutrootctrl.h"
       
    24 #include "peninputcmd.h"
       
    25 #include "peninputlayout.h"
    24 
    26 
    25 const TInt KDefaultCursorHeight = 10;
    27 const TInt KDefaultCursorHeight = 10;
    26 // ============================ MEMBER FUNCTIONS =============================
    28 // ============================ MEMBER FUNCTIONS =============================
    27 
    29 
    28 // ---------------------------------------------------------------------------
    30 // ---------------------------------------------------------------------------
    52 void CFepUiCursor::ConstructL()
    54 void CFepUiCursor::ConstructL()
    53     {
    55     {
    54     CFepUiBaseCtrl::BaseConstructL();
    56     CFepUiBaseCtrl::BaseConstructL();
    55     iCursorBlinkingTimer = CPeriodic::NewL(CActive::EPriorityStandard);
    57     iCursorBlinkingTimer = CPeriodic::NewL(CActive::EPriorityStandard);
    56     iRestoreCursorTimer = CLayoutTimer::NewL(this,CLayoutTimer::EOthers);
    58     iRestoreCursorTimer = CLayoutTimer::NewL(this,CLayoutTimer::EOthers);
       
    59     CreateCursorBmpL();
    57     }
    60     }
    58 
    61 
    59 // ---------------------------------------------------------------------------
    62 // ---------------------------------------------------------------------------
    60 // CFepUiCursor::NewL
    63 // CFepUiCursor::NewL
    61 // Two-phased constructor.
    64 // Two-phased constructor.
    82         iCursorBlinkingTimer->Cancel();
    85         iCursorBlinkingTimer->Cancel();
    83         delete iCursorBlinkingTimer;
    86         delete iCursorBlinkingTimer;
    84         }    
    87         }    
    85    
    88    
    86     delete iRestoreCursorTimer;
    89     delete iRestoreCursorTimer;
       
    90     delete iBitmap;
       
    91     delete iBitmapDevice;
       
    92     delete iGc;
    87     }
    93     }
    88 
    94 
    89 
    95 
    90 // ---------------------------------------------------------------------------
    96 // ---------------------------------------------------------------------------
    91 // CFepUiCursor::SetPosition
    97 // CFepUiCursor::SetPosition
    94 // ---------------------------------------------------------------------------
   100 // ---------------------------------------------------------------------------
    95 //
   101 //
    96 EXPORT_C void CFepUiCursor::SetPosition(const TPoint& aPosition)
   102 EXPORT_C void CFepUiCursor::SetPosition(const TPoint& aPosition)
    97     {
   103     {
    98     
   104     
    99     TBool isOn = iIsOn;
   105 	if( iPosition != aPosition )
   100     if (isOn)
   106 		{
   101         {
   107 		TBool isOn = iIsOn;
   102         SetOn(EFalse);
   108 		if (isOn)
   103         }
   109 			{
   104     iPosition=aPosition;
   110 			SetOn(EFalse);
   105     TPoint correction(KCursorPosCorrectionX,KCursorPosCorrectionY );
   111 
   106     TRect rect = TRect(iPosition + correction , TSize(KCursorWidth,iHeight));
   112 			}
   107     if(rect != iCursorRect)
   113 		iPosition=aPosition;
   108         {
   114 		TPoint correction(KCursorPosCorrectionX,KCursorPosCorrectionY );
   109         SetRect(rect);
   115 		TRect rect = TRect(iPosition + correction , TSize(KCursorWidth,iHeight));
   110         iCursorRect = rect;
   116 		if(rect != iCursorRect)
   111         //must update clip region again.
   117 			{
   112         for(TInt i = 0 ; i < RootControl()->PopCtrlList().Count(); ++i)
   118 			SetRect(rect);
   113             {
   119 			iCursorRect = rect;
   114             UpdateValidRegion(RootControl()->PopCtrlList()[i],EFalse);
   120 			//must update clip region again.
   115             }
   121 			for(TInt i = 0 ; i < RootControl()->PopCtrlList().Count(); ++i)
   116         }
   122 				{
   117         
   123 				UpdateValidRegion(RootControl()->PopCtrlList()[i],EFalse);
   118     if (isOn)
   124 				}
   119         {
   125 			}
   120         SetOn(ETrue);
   126 			
   121         }
   127 		if (isOn)
       
   128 			{
       
   129 			SetOn(ETrue);
       
   130 			}
       
   131 		}
       
   132 
   122     }
   133     }
   123 
   134 
   124 // ---------------------------------------------------------------------------
   135 // ---------------------------------------------------------------------------
   125 // CFepUiCursor::Position
   136 // CFepUiCursor::Position
   126 // get the cursor position
   137 // get the cursor position
   160         CancelDelayCursorShown();
   171         CancelDelayCursorShown();
   161         if ( iCursorBlinkingTimer->IsActive())
   172         if ( iCursorBlinkingTimer->IsActive())
   162             {
   173             {
   163             iCursorBlinkingTimer->Cancel();    
   174             iCursorBlinkingTimer->Cancel();    
   164             }
   175             }
       
   176         InvalidateInsertionPoint();
   165         }
   177         }
   166     else
   178     else
   167         {
   179         {
   168         if(iCursorTempDisabled)
   180         if(iCursorTempDisabled)
   169             {
   181             {
   176                    KCursorBlinkPerioid,TCallBack(CursorBlinkCallBack , this));
   188                    KCursorBlinkPerioid,TCallBack(CursorBlinkCallBack , this));
   177             }
   189             }
   178         }
   190         }
   179         
   191         
   180         // Invalidate InsertionPoint's rect, so it will be removed from editarea
   192         // Invalidate InsertionPoint's rect, so it will be removed from editarea
   181     InvalidateInsertionPoint();
   193     //InvalidateInsertionPoint();
   182     }
   194     }
   183 
   195 
   184 // ---------------------------------------------------------------------------
   196 // ---------------------------------------------------------------------------
   185 // CFepUiCursor::SetHeight
   197 // CFepUiCursor::SetHeight
   186 // Sets caret height
   198 // Sets caret height
   213 EXPORT_C void CFepUiCursor::ReDraw(TBool aReset)
   225 EXPORT_C void CFepUiCursor::ReDraw(TBool aReset)
   214     {
   226     {
   215     if(aReset)
   227     if(aReset)
   216         iIsVisible = EFalse;
   228         iIsVisible = EFalse;
   217     Draw();
   229     Draw();
   218     UpdateArea(iCursorRect,EFalse);
   230     //UpdateArea(iCursorRect,EFalse);
   219     }
   231     UpdateCursorArea(iCursorRect,EFalse);
   220     
   232     }
   221 
   233     
       
   234 void CFepUiCursor::DrawCursor(CFbsBitGc* aGc,CFbsBitmapDevice* aDevice)
       
   235     {
       
   236     aGc->Activate(aDevice);    
       
   237    
       
   238    // draw cursor by inverting colors in the selected text rectancle
       
   239     //aGc->SetClippingRegion(ValidClipRegion());                   
       
   240     
       
   241     aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   242     aGc->SetBrushColor(KRgbBlack);
       
   243     //aGc->SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
       
   244     aGc->Clear();
       
   245     aGc->SetPenColor(KRgbBlack);
       
   246     aGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   247     aGc->SetPenSize( TSize(1,1));
       
   248 
       
   249     // When the blink timer out and cursor is visible, do nothing
       
   250     // else draw the cursor and set the visible flag
       
   251     //aGc->DrawRect(iCursorRect);
       
   252     //iIsVisible = !iIsVisible;
       
   253 
       
   254     // restore normal draw mode
       
   255     aGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   256     aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   257     }
       
   258 	
   222 // ---------------------------------------------------------------------------
   259 // ---------------------------------------------------------------------------
   223 // CFepUiCursor::Draw
   260 // CFepUiCursor::Draw
   224 // Draws insertion point's Rect and starts blinking timer
   261 // Draws insertion point's Rect and starts blinking timer
   225 // (other items were commented in a header).
   262 // (other items were commented in a header).
   226 // ---------------------------------------------------------------------------
   263 // ---------------------------------------------------------------------------
   229     {
   266     {
   230     if(!AbleToDraw())
   267     if(!AbleToDraw())
   231         {
   268         {
   232         return;
   269         return;
   233         }
   270         }
   234     
   271 
       
   272 //#ifdef FIX_FOR_NGA
       
   273     if(UiLayout()->NotDrawToLayoutDevice())
       
   274         {
       
   275         if(iIsOn)
       
   276             {   
       
   277             iIsVisible = !iIsVisible;
       
   278             } 
       
   279         else
       
   280             {
       
   281             if(iIsVisible) //only do when already shown
       
   282                 {                
       
   283                 iIsVisible = EFalse;                       
       
   284                 }   
       
   285             }
       
   286         
       
   287         return;
       
   288         }
       
   289 //#endif
   235     /*if (aReset)    
   290     /*if (aReset)    
   236         {
   291         {
   237         iIsVisible = EFalse;
   292         iIsVisible = EFalse;
   238         }
   293         }
   239       */  
   294       */  
   242     gc->Activate( BitmapDevice());    
   297     gc->Activate( BitmapDevice());    
   243     if(iIsOn)
   298     if(iIsOn)
   244         {        
   299         {        
   245         // draw cursor by inverting colors in the selected text rectancle
   300         // draw cursor by inverting colors in the selected text rectancle
   246         gc->SetClippingRegion(ValidClipRegion());        	        
   301         gc->SetClippingRegion(ValidClipRegion());        	        
   247         
   302 
       
   303         const TRegion& tr = ValidClipRegion();
       
   304         const TRect* rl = tr.RectangleList();
       
   305         TRect rr;
       
   306         for(TInt id = 0; id < tr.Count(); ++id)
       
   307             {
       
   308             rr = rl[id];
       
   309             }
   248         gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   310         gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   249         gc->SetBrushColor(KRgbBlack);
   311         gc->SetBrushColor(KRgbBlack);
   250         gc->SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
   312         gc->SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
   251 
   313 
   252         gc->SetPenColor(KRgbBlack);
   314         gc->SetPenColor(KRgbBlack);
   322 // (other items were commented in a header).
   384 // (other items were commented in a header).
   323 // ---------------------------------------------------------------------------
   385 // ---------------------------------------------------------------------------
   324 //
   386 //
   325 void CFepUiCursor::InvalidateInsertionPoint()
   387 void CFepUiCursor::InvalidateInsertionPoint()
   326     {    
   388     {    
   327     //if(iEditor)
   389     if(AbleToDraw())
   328         {        
   390         {        
   329         Draw();
   391         Draw();
   330         UpdateArea(iCursorRect,EFalse);
   392         //UpdateArea(iCursorRect,EFalse);
       
   393         
       
   394         UpdateCursorArea(iCursorRect,EFalse);
   331         }
   395         }
   332     }
   396     }
   333   
   397   
   334 // ---------------------------------------------------------------------------
   398 // ---------------------------------------------------------------------------
   335 // CFepUiCursor::DelayCursorWhileDraging
   399 // CFepUiCursor::DelayCursorWhileDraging
   377 void CFepUiCursor::HandleTimerOut(TInt /*aTimeType*/)
   441 void CFepUiCursor::HandleTimerOut(TInt /*aTimeType*/)
   378     {
   442     {
   379     iCursorTempDisabled = EFalse;
   443     iCursorTempDisabled = EFalse;
   380     iIsOn = ETrue;
   444     iIsOn = ETrue;
   381     //To avoid the ugly first shown, we draw the cursor directly here.
   445     //To avoid the ugly first shown, we draw the cursor directly here.
   382     InvalidateInsertionPoint();
   446     //InvalidateInsertionPoint();
   383     SetOn(ETrue, EFalse);    
   447     SetOn(ETrue, EFalse);    
   384     }
   448     }
   385     
   449     
   386     
   450     
   387 // ---------------------------------------------------------------------------
   451 // ---------------------------------------------------------------------------
   433     iClipRegion.AddRect(iRect);
   497     iClipRegion.AddRect(iRect);
   434     }
   498     }
   435     
   499     
   436 void CFepUiCursor::UpdateCursorArea(const TRect& aRect, TBool aFlag)
   500 void CFepUiCursor::UpdateCursorArea(const TRect& aRect, TBool aFlag)
   437     {
   501     {
       
   502     if(UiLayout()->NotDrawToLayoutDevice())
       
   503         {
       
   504         //CopyToBmp();
       
   505         //signal special update
       
   506     
       
   507         struct SData
       
   508             {
       
   509             TBool onOff;
       
   510             CFbsBitmap* bmp;
       
   511             TRect rect;
       
   512             } data;
       
   513         data.onOff = iIsVisible;
       
   514         data.bmp = iBitmap;
       
   515         data.rect = iCursorRect;
       
   516         TPtrC ptr;
       
   517         ptr.Set(reinterpret_cast<const TUint16*>(&data),sizeof(data)/sizeof(TUint16));
       
   518         
       
   519         UiLayout()->SignalOwner(ESignalUpdateCursor,ptr);
       
   520         
       
   521 		return;
       
   522 		}
       
   523 
   438     CFepUiBaseCtrl* parent = iEditor->ParentCtrl();
   524     CFepUiBaseCtrl* parent = iEditor->ParentCtrl();
   439     
   525     
   440     if(parent)
   526     if(parent)
   441         {
   527         {
   442         if(parent->IsKindOfControl(ECtrlControlGroup))     
   528         if(parent->IsKindOfControl(ECtrlControlGroup))     
   445             iEditor->ParentCtrl()->UpdateArea(aRect,aFlag);
   531             iEditor->ParentCtrl()->UpdateArea(aRect,aFlag);
   446         }
   532         }
   447     else
   533     else
   448         UpdateArea(aRect,aFlag);    
   534         UpdateArea(aRect,aFlag);    
   449     }
   535     }
       
   536 
       
   537 void CFepUiCursor::CreateCursorBmpL()
       
   538     {
       
   539     iBitmap = new ( ELeave ) CFbsBitmap;    
       
   540     
       
   541     TRect rect = TRect(TPoint(0,0) , TSize(KCursorWidth,iHeight));
       
   542 
       
   543     User::LeaveIfError( iBitmap->Create( rect.Size(), BitmapDevice()->DisplayMode() ) );
       
   544     
       
   545     iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
       
   546     iGc = CFbsBitGc::NewL();
       
   547     iGc->Reset();
       
   548     DrawCursor(iGc,iBitmapDevice);
       
   549     }
       
   550 
       
   551 void CFepUiCursor::ResizeCursorBmp()
       
   552     {
       
   553     TRect rect = TRect(TPoint(0,0) , TSize(KCursorWidth,iHeight));
       
   554     iBitmap->Resize(rect.Size());
       
   555     
       
   556     iBitmapDevice->Resize( rect.Size());
       
   557     //gc must be adjusted
       
   558     iGc->Activate(iBitmapDevice);
       
   559     iGc->Resized();
       
   560     DrawCursor(iGc,iBitmapDevice);    
       
   561     }
   450 //  End of File  
   562 //  End of File