textinput/peninputarc/src/peninputlayoutcontrol/peninputlayoutpopupwnd.cpp
branchRCL_3
changeset 21 ecbabf52600f
parent 20 ebd48d2de13c
equal deleted inserted replaced
20:ebd48d2de13c 21:ecbabf52600f
    46 	{
    46 	{
    47 	if(iIsShowing) // is showing
    47 	if(iIsShowing) // is showing
    48 		{		
    48 		{		
    49 		//do nothing
    49 		//do nothing
    50 		}
    50 		}
       
    51     delete iExt;
    51 	}	
    52 	}	
    52 	
    53 	
    53 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    54 // CFepLayoutPopupWnd::ConsructL()
    55 // CFepLayoutPopupWnd::ConsructL()
    55 // Symbian 2nd phase constructor
    56 // Symbian 2nd phase constructor
    56 // (other items were commented in a header).
    57 // (other items were commented in a header).
    57 // ---------------------------------------------------------------------------
    58 // ---------------------------------------------------------------------------
    58 EXPORT_C void CFepLayoutPopupWnd::ConstructL()
    59 EXPORT_C void CFepLayoutPopupWnd::ConstructL()
    59 	{
    60 	{
    60 	BaseConstructL();
    61 	BaseConstructL();
       
    62     iExt = CPopupWndExt::NewL();    
       
    63     //check whether we need create backup bmp. Some pop up window is created after UI layout is created
       
    64     //If a pop up window is created during layout constructing, it will create the backup bitmap in Handleresourcechange
       
    65     if (UiLayout()->NotDrawToLayoutDevice())
       
    66         {
       
    67             iExt->ContructBkDeviceL(Rect().Size(),
       
    68                         UiLayout()->LayoutOwner()->BitmapDevice()->DisplayMode());
       
    69         }
    61 	}	
    70 	}	
    62 
    71 
    63 EXPORT_C void CFepLayoutPopupWnd::ReDrawRect(const TRect& /*aRect*/)
    72 EXPORT_C void CFepLayoutPopupWnd::ReDrawRect(const TRect& /*aRect*/)
    64     {
    73     {
    65     Draw();
    74     Draw();
   256 	if(iIsShowing)
   265 	if(iIsShowing)
   257 	    return;
   266 	    return;
   258 	RootControl()->SetActiveCtrl(this);
   267 	RootControl()->SetActiveCtrl(this);
   259     ReportEvent(EEventCapturePointer);
   268     ReportEvent(EEventCapturePointer);
   260 
   269 
       
   270     //When preparing the pop up window, it causes redraw the underlying control sometimes.
       
   271     DisableDrawingInGroup();//disable any drawing during preparation to avoid it dirty the background
       
   272 
   261 	//let pop up window do preparation
   273 	//let pop up window do preparation
   262 	OnDisplay();	
   274 	OnDisplay();	
   263 	
   275 	
   264 	//determine the directoin
   276 	//determine the directoin
   265 	TRect rtPopup; //final position 
   277 	TRect rtPopup; //final position 
   285     offsetRect.Move( ptLayout );
   297     offsetRect.Move( ptLayout );
   286     
   298     
   287     switch( aDisPostion )
   299     switch( aDisPostion )
   288         {
   300         {
   289         case EDispBottomRight:
   301         case EDispBottomRight:
   290             rtPopup.SetRect( TPoint( offsetRect.iTl.iX, offsetRect.iBr.iY ), szPopup );
   302             rtPopup.SetRect( TPoint( offsetRect.iTl.iX, offsetRect.iBr.iY ), szPopup );            
   291             if( rtPopup.iBr.iY > ptScreenSize.iPixelSize.iHeight )
   303             if( rtPopup.iBr.iY > ptScreenSize.iPixelSize.iHeight )
   292                 {
   304                 {
   293                 //we need move x also
   305                 rtPopup.Move( 0, ptScreenSize.iPixelSize.iHeight - rtPopup.iBr.iY );
   294                 rtPopup.Move( aOffsetRect.Width(), 
   306                 }            
   295                               ptScreenSize.iPixelSize.iHeight - rtPopup.iBr.iY );
       
   296                 }
       
   297             if(rtPopup.iBr.iX > ptScreenSize.iPixelSize.iWidth )
   307             if(rtPopup.iBr.iX > ptScreenSize.iPixelSize.iWidth )
   298                 {
   308                 {
   299                 rtPopup.Move ( ptScreenSize.iPixelSize.iWidth - rtPopup.iBr.iX, 0 );
   309                 rtPopup.Move ( ptScreenSize.iPixelSize.iWidth - rtPopup.iBr.iX, 0 );
   300                 }
   310                 }
   301             break;
   311             break;
   302         case EDispBottomLeft:
   312         case EDispBottomLeft:
   303             rtPopup.SetRect( TPoint( offsetRect.iBr.iX - szPopup.iWidth, offsetRect.iBr.iY), 
   313             rtPopup.SetRect( TPoint( offsetRect.iBr.iX - szPopup.iWidth, offsetRect.iBr.iY), 
   304                              szPopup );
   314                              szPopup );
   305             if( rtPopup.iBr.iY > ptScreenSize.iPixelSize.iHeight )
   315             if( rtPopup.iBr.iY > ptScreenSize.iPixelSize.iHeight )
   306                 {
   316                 {
   307                 //we need move x also
   317                 //we need move the pop wnd up to ensure it not to be out of screen
   308                 rtPopup.Move( aOffsetRect.Width(), 
   318                 rtPopup.Move( 0, ptScreenSize.iPixelSize.iHeight - rtPopup.iBr.iY );
   309                               ptScreenSize.iPixelSize.iHeight - rtPopup.iBr.iY );
       
   310                 }
   319                 }
   311             if( rtPopup.iTl.iX < 0 )
   320             if( rtPopup.iTl.iX < 0 )
   312                 {
   321                 {
   313                 rtPopup.Move ( -rtPopup.iTl.iX, 0 );
   322                 rtPopup.Move ( -rtPopup.iTl.iX, 0 );
   314                 }
   323                 }
   315             break;
   324             break;
   316         case EDispTopRight:
   325         case EDispTopRight:
   317             rtPopup.SetRect( TPoint( offsetRect.iTl.iX, offsetRect.iTl.iY - szPopup.iHeight ), 
   326             rtPopup.SetRect( TPoint( offsetRect.iTl.iX, offsetRect.iTl.iY - szPopup.iHeight ), 
   318                              szPopup );
   327                              szPopup );            
   319             if( rtPopup.iTl.iY < 0 )
   328             if( rtPopup.iTl.iY < 0 )
   320                {
   329                {
   321                rtPopup.Move ( aOffsetRect.Width(), -rtPopup.iTl.iY );
   330                rtPopup.Move ( 0, -rtPopup.iTl.iY );
   322                }
   331                }                       
   323             if(rtPopup.iBr.iX > ptScreenSize.iPixelSize.iWidth )
   332             if(rtPopup.iBr.iX > ptScreenSize.iPixelSize.iWidth )
   324                 {
   333                 {
   325                 rtPopup.Move ( ptScreenSize.iPixelSize.iWidth - rtPopup.iBr.iX, 0 );
   334                 rtPopup.Move ( ptScreenSize.iPixelSize.iWidth - rtPopup.iBr.iX, 0 );
   326                 }
   335                 }
   327                
   336                
   330             rtPopup.SetRect( TPoint( offsetRect.iBr.iX - szPopup.iWidth, 
   339             rtPopup.SetRect( TPoint( offsetRect.iBr.iX - szPopup.iWidth, 
   331                                      offsetRect.iTl.iY - szPopup.iHeight ), szPopup );
   340                                      offsetRect.iTl.iY - szPopup.iHeight ), szPopup );
   332                                      
   341                                      
   333             if( rtPopup.iTl.iY < 0 )
   342             if( rtPopup.iTl.iY < 0 )
   334                {
   343                {
   335                rtPopup.Move ( -aOffsetRect.Width(), -rtPopup.iTl.iY );
   344                rtPopup.Move ( 0, -rtPopup.iTl.iY );
   336                }
   345                }
   337                
   346                
   338             if( rtPopup.iTl.iX < 0 )
   347             if( rtPopup.iTl.iX < 0 )
   339                 {
   348                 {
   340                 rtPopup.Move ( -rtPopup.iTl.iX, 0 );
   349                 rtPopup.Move ( -rtPopup.iTl.iX, 0 );
   360         layoutOwner->LayoutSizeChanged(rtFinal.Size(), EFalse);
   369         layoutOwner->LayoutSizeChanged(rtFinal.Size(), EFalse);
   361         layoutOwner->SetPosition(rtFinal.iTl);
   370         layoutOwner->SetPosition(rtFinal.iTl);
   362         //RootControl()->Clear();
   371         //RootControl()->Clear();
   363         DrawTransparentMaskBackground( TRect( TPoint(), rtFinal.Size() ) );
   372         DrawTransparentMaskBackground( TRect( TPoint(), rtFinal.Size() ) );
   364         RootControl()->Move(iLayoutMoveOff);
   373         RootControl()->Move(iLayoutMoveOff);
   365         RootControl()->Draw();	    
   374         EnableDrawingInGroup();
       
   375         RootControl()->Draw();
       
   376         DisableDrawingInGroup();	    
   366     	//UpdateArea( TRect( TPoint(), rtFinal.Size()), ETrue); 	
   377     	//UpdateArea( TRect( TPoint(), rtFinal.Size()), ETrue); 	
   367 	    }
   378 	    }
   368 	else
   379 	else
   369 	    {
   380 	    {
   370 	    iPrevLayoutRect.SetSize(TSize(0,0));	        
   381 	    iPrevLayoutRect.SetSize(TSize(0,0));	        
   378 	    iWndControl->MakeVisible(ETrue);    
   389 	    iWndControl->MakeVisible(ETrue);    
   379 	    }
   390 	    }
   380 	    
   391 	    
   381     //iRect = rtPopup;
   392     //iRect = rtPopup;
   382     Move( rtPopup.iTl - Rect().iTl);
   393     Move( rtPopup.iTl - Rect().iTl);
       
   394     //copy and save the bitmap 
       
   395     if (UiLayout()->NotDrawToLayoutDevice())
       
   396         {    
       
   397         iExt->SetRect(Rect());
       
   398         
       
   399         CFbsBitGc* gc = iExt->BackupGc();
       
   400         gc->Activate( iExt->BackupDevice() );
       
   401         CFbsBitGc* layoutGc = static_cast<CFbsBitGc*>(
       
   402                             UiLayout()->LayoutOwner()->BitmapContext()); 
       
   403         gc->BitBlt(TPoint(0,0),*layoutGc,Rect());
       
   404         
       
   405         Hide(EFalse); 
       
   406         }
       
   407     
       
   408     EnableDrawingInGroup();
       
   409 
   383     UiLayout()->LockArea(iRect,this);
   410     UiLayout()->LockArea(iRect,this);
   384 	Hide(EFalse);    
   411 
       
   412     SetReady(ETrue);//enalbe it as in Close, the flag is reset.
       
   413     if (UiLayout()->NotDrawToLayoutDevice())
       
   414         Draw();//force draw
       
   415     else
       
   416         Hide(EFalse);
       
   417     UpdateArea(iRect, EFalse); 
   385         
   418         
   386     iIsShowing = ETrue;
   419     iIsShowing = ETrue;
   387     AfterDisplayed();
   420     AfterDisplayed();
   388     
   421     
   389 	TRect rectOfPopup =Rect(); //in new layout coord-sys
   422 	TRect rectOfPopup =Rect(); //in new layout coord-sys
   435 	UiLayout()->SignalOwner(ESignalPopupWndClosed); 		    
   468 	UiLayout()->SignalOwner(ESignalPopupWndClosed); 		    
   436 	
   469 	
   437 	iIsShowing = EFalse;
   470 	iIsShowing = EFalse;
   438 	if(iWndControl)
   471 	if(iWndControl)
   439 	    iWndControl->MakeVisible(EFalse);    
   472 	    iWndControl->MakeVisible(EFalse);    
   440 	Hide(ETrue);	
   473     SetReady(EFalse);//disable redraw
       
   474     TRect popRect = iRect;
       
   475     UiLayout()->UnLockArea(iRect, this);
       
   476 
       
   477     //restore the background bitmap
       
   478     TBool bRedraw = ETrue;
       
   479     if (UiLayout()->NotDrawToLayoutDevice())
       
   480         {
       
   481         CFbsBitGc* layoutGc = static_cast<CFbsBitGc*>(
       
   482                     UiLayout()->LayoutOwner()->BitmapContext()); 
       
   483  
       
   484                 iExt->BackupGc();
       
   485         layoutGc->Activate( UiLayout()->LayoutOwner()->BitmapDevice());
       
   486         TRect r;
       
   487         r.SetSize(iExt->Rect().Size());
       
   488         layoutGc->BitBlt(iExt->Rect().iTl,iExt->BackupBitmap(),r);
       
   489         bRedraw = EFalse;
       
   490         }
       
   491     
       
   492     Hide(ETrue);
   441 	UiLayout()->UnLockArea(iRect,this);
   493 	UiLayout()->UnLockArea(iRect,this);
   442 	iRect.Move(-iRect.iTl);	
   494 	iRect.Move(-iRect.iTl);	
   443 	MLayoutOwner* layoutOwner = UiLayout()->LayoutOwner();
   495 	MLayoutOwner* layoutOwner = UiLayout()->LayoutOwner();
   444 	if(!iPrevLayoutRect.IsEmpty())
   496 	if(!iPrevLayoutRect.IsEmpty())
   445 	    {
   497 	    {
   447 	    TRect rt;
   499 	    TRect rt;
   448 	    rt.SetSize( layoutOwner->LayoutRect().Size() );
   500 	    rt.SetSize( layoutOwner->LayoutRect().Size() );
   449         layoutOwner->SetPosition(iPrevLayoutRect.iTl);
   501         layoutOwner->SetPosition(iPrevLayoutRect.iTl);
   450        	layoutOwner->LayoutSizeChanged(iPrevLayoutRect.Size());
   502        	layoutOwner->LayoutSizeChanged(iPrevLayoutRect.Size());
   451         RootControl()->GraphicDeviceSizeChanged();
   503         RootControl()->GraphicDeviceSizeChanged();
       
   504         bRedraw = ETrue;
   452 	    }
   505 	    }
   453 	    
   506 	    
   454     RootControl()->Draw();
   507     if (bRedraw)    
       
   508 	    {
       
   509         RootControl()->Draw();
       
   510 		}
   455 
   511 
   456 	iIsShowing = EFalse;
   512 	iIsShowing = EFalse;
   457 	
   513 	
   458 	TRect rect( TPoint(0,0),iPrevLayoutRect.Size() );
   514     //TRect rect(TPoint(0, 0), iPrevLayoutRect.Size());
   459 	UpdateArea(  rect, EFalse ); 	
   515     UpdateArea(popRect, EFalse);     	
   460 	}		
   516 	}		
   461 		
   517 		
   462 // ---------------------------------------------------------------------------
   518 // ---------------------------------------------------------------------------
   463 // CFepLayoutPopupWnd::SetRect
   519 // CFepLayoutPopupWnd::SetRect
   464 // Set the pop up window's rect
   520 // Set the pop up window's rect
   497 //    	
   553 //    	
   498 EXPORT_C void CFepLayoutPopupWnd::AfterDisplayed()
   554 EXPORT_C void CFepLayoutPopupWnd::AfterDisplayed()
   499     {
   555     {
   500     //do nothing
   556     //do nothing
   501     }
   557     }
       
   558 EXPORT_C void CFepLayoutPopupWnd::HandleResourceChange(TInt aType)
       
   559     {
       
   560     if (aType == KPenInputOwnDeviceChange)
       
   561         {
       
   562         if (UiLayout()->NotDrawToLayoutDevice())
       
   563             {
       
   564             TRAP_IGNORE(iExt->ContructBkDeviceL(Rect().Size(),
       
   565                     UiLayout()->LayoutOwner()->BitmapDevice()->DisplayMode()));
       
   566             }
       
   567         }
       
   568     else
       
   569         CControlGroup::HandleResourceChange(aType);
       
   570     }
       
   571 void CFepLayoutPopupWnd::DisableDrawingInGroup()
       
   572     {
       
   573 
       
   574     UiLayout()->DisableLayoutDrawing(ETrue);
       
   575     SetReady(EFalse);
       
   576     for(TInt i = 0; i < NumOfControls(); ++i)
       
   577         {
       
   578         //There is potential defect that if the child control is a group control, its children not set.
       
   579         //This can be solved by locking the area so no one can update until we unlock it in Enalbegroup
       
   580         ControlList()[i]->SetReady(EFalse); 
       
   581         }
       
   582     }
       
   583 void CFepLayoutPopupWnd::EnableDrawingInGroup()
       
   584     {
       
   585     SetReady(ETrue);
       
   586     for(TInt i = 0; i < NumOfControls(); ++i)
       
   587         {
       
   588         //There is potential defect that if the child control is a group control, its children not set.
       
   589         //This can be solved by locking the area so no one can update until we unlock it in Enalbegroup
       
   590         ControlList()[i]->SetReady(ETrue); 
       
   591         }
       
   592     UiLayout()->DisableLayoutDrawing(EFalse);    
       
   593     }
       
   594 
       
   595 
       
   596 
       
   597 CFepLayoutPopupWnd::CPopupWndExt* CFepLayoutPopupWnd::CPopupWndExt::NewL()
       
   598     {
       
   599     CPopupWndExt* self = new (ELeave)CPopupWndExt();
       
   600     return self;
       
   601     }
       
   602 
       
   603 void CFepLayoutPopupWnd::CPopupWndExt::ContructBkDeviceL(const TSize& aSize,const TDisplayMode& aMode)
       
   604     {
       
   605     TBool bNewBmp = EFalse;
       
   606     if(!iBitmap || iBitmap->DisplayMode() != aMode)
       
   607         {
       
   608         delete iBitmap;
       
   609         iBitmap = 0;
       
   610         iBitmap = new (ELeave) CFbsBitmap;    
       
   611         User::LeaveIfError( iBitmap->Create( aSize,aMode));
       
   612         delete iBitmapDevice;
       
   613         iBitmapDevice = 0;
       
   614         iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
       
   615         bNewBmp = ETrue;
       
   616         }
       
   617     if(!iGc)
       
   618         iGc = CFbsBitGc::NewL();    
       
   619 
       
   620     if(!bNewBmp && aSize != iBitmap->SizeInPixels())
       
   621         {
       
   622         ResizeBackupDeviceL(aSize);
       
   623         }
       
   624     }
       
   625 void CFepLayoutPopupWnd::CPopupWndExt::ResizeBackupDeviceL(const TSize& aSize)
       
   626     {
       
   627     
       
   628     iBitmap->Resize(aSize);
       
   629     iBitmapDevice->Resize( aSize);
       
   630     iGc->Activate(iBitmapDevice);
       
   631     iGc->Resized();    
       
   632     }
       
   633 void CFepLayoutPopupWnd::CPopupWndExt::SetRect(const TRect& aRect)
       
   634     {
       
   635     iRect = aRect;
       
   636     if(iBitmap && iBitmap->SizeInPixels() != aRect.Size())
       
   637         {            
       
   638         TRAP_IGNORE(ResizeBackupDeviceL(aRect.Size()));
       
   639         }
       
   640     }
       
   641 //  End of File