textinput/peninputarc/src/peninputserverapp/penuiwndctrl.cpp
changeset 0 eb1f2e154e89
child 3 f5a1e66df979
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     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 #include <AknSgcc.h>
       
    18 #include <AknIncallBubbleNotify.h>
       
    19 #include <avkon.hrh>
       
    20 #include <eikappui.h>
       
    21 #include <apgwgnam.h>
       
    22 
       
    23 #include "penuiwndctrl.h"
       
    24 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
    25 #include <gfxtranseffect/gfxtranseffect.h>
       
    26 #include <AknTransitionUtils.h>
       
    27 #include <akntranseffect.h>
       
    28 
       
    29 #include <e32property.h>
       
    30 #include <AvkonDomainPSKeys.h>
       
    31 #endif
       
    32 
       
    33 
       
    34 const TInt KAknCapServerUid = 0x10207218;
       
    35 const TInt KAknNotifySrvUid = 0x10281EF2;  
       
    36     
       
    37 CPenUiWndCtrl::CPenUiWndCtrl(RWindowGroup& aWndGroup,CFbsBitmap * aBitmap)
       
    38     :iWndGroup(aWndGroup),
       
    39      iBitmap(aBitmap),
       
    40      iAknUiSrv(CAknSgcClient::AknSrv())
       
    41 {
       
    42 }
       
    43 
       
    44 CPenUiWndCtrl::~CPenUiWndCtrl()
       
    45 {
       
    46     delete iPopupWnd;
       
    47 
       
    48 	delete iIncallBubble;  
       
    49 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
    50 
       
    51     if ( GfxTransEffect::IsRegistered( this ) )
       
    52         {
       
    53         // abort component effects (possibly appear effect) 
       
    54         // if aknnote gets destroyed without user interaction or timers
       
    55         GfxTransEffect::NotifyExternalState( ENotifyGlobalAbort );
       
    56         GfxTransEffect::Deregister(this); //Always deregister in destructor.
       
    57         }
       
    58 #endif    	
       
    59 }
       
    60 
       
    61 void CPenUiWndCtrl::ConstructL()
       
    62 {
       
    63     CreateWindowL(iWndGroup);
       
    64     SetComponentsToInheritVisibility();
       
    65 
       
    66     Window().SetRequiredDisplayMode( EColor16MA );
       
    67     iIncallBubble = CAknIncallBubble::NewL();        
       
    68     MakeVisible( EFalse );
       
    69 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS    
       
    70     // only change registration, if not registered, don't register
       
    71     if (!GfxTransEffect::IsRegistered( this ) ) 
       
    72         {
       
    73         GfxTransEffect::Register( this, TUid::Uid( 0x2000B477 ));
       
    74         }
       
    75 #endif    
       
    76   //  ActivateL();
       
    77     iPopupWnd = CPenUiPopWnd::NewL(iWndGroup,iBitmap,this);
       
    78 }
       
    79 
       
    80 
       
    81 void CPenUiWndCtrl::Draw(const TRect& aRect) const
       
    82     {
       
    83     CWindowGc& gc = SystemGc();
       
    84         
       
    85     if ( iShowPopup ) 
       
    86         {
       
    87         //layout is extended by popup
       
    88         gc.SetClippingRect( iLayoutClipRect );
       
    89         gc.BitBlt( aRect.iTl, iBitmap, aRect );
       
    90         // Add to fix NGA refresh problem
       
    91         CCoeEnv::Static()->WsSession().Flush();
       
    92         CCoeEnv::Static()->WsSession().Finish(); 
       
    93         return;
       
    94         }
       
    95     
       
    96     gc.BitBlt(aRect.iTl,iBitmap,aRect);
       
    97     // Add to fix NGA refresh problem
       
    98     CCoeEnv::Static()->WsSession().Flush();
       
    99     CCoeEnv::Static()->WsSession().Finish(); 
       
   100     }
       
   101 
       
   102 TInt CPenUiWndCtrl::WndPriority()
       
   103     {
       
   104     return iPriority;
       
   105     }
       
   106     
       
   107 TUid CPenUiWndCtrl::WindowGroupNameAppUidL( RWsSession& aWS, TInt aWGId )
       
   108     {
       
   109     CApaWindowGroupName* wg = CApaWindowGroupName::NewLC( aWS,aWGId );
       
   110     TUid id = wg->AppUid();
       
   111     CleanupStack::PopAndDestroy(wg);
       
   112     return id;
       
   113     }
       
   114     
       
   115 TInt CPenUiWndCtrl::GetWndPriority()
       
   116     {
       
   117     RWsSession &ws = CCoeEnv::Static()->WsSession();
       
   118     TInt wgId =ws.GetFocusWindowGroup();    
       
   119     
       
   120     TUid id = {0x00000000};
       
   121     TRAP_IGNORE( id = WindowGroupNameAppUidL( ws, wgId ) );
       
   122     
       
   123     TBool isGlobalServs = ( id.iUid == KAknCapServerUid || id.iUid == KAknNotifySrvUid );
       
   124     if( ( iInGlobalEditorState && isGlobalServs ) || !isGlobalServs )
       
   125         {
       
   126          //TUid id = GetFocusAppUid();
       
   127         //set the window group priority so as pen UI can be shown and global notes can also
       
   128         //be shown.
       
   129         TInt priority = ws.GetWindowGroupOrdinalPriority(wgId);
       
   130         (priority == ECoeWinPriorityNormal) ? ++priority : priority;// + 1;
       
   131         iPreEditorPriority = priority;
       
   132         return priority;
       
   133         }
       
   134         
       
   135     return iPreEditorPriority;
       
   136     }
       
   137     
       
   138 void CPenUiWndCtrl::ShowPenUiL(TBool /*aDimmed*/)
       
   139     {
       
   140     if (iResourceChange)
       
   141         {
       
   142         ActivateL();
       
   143         iIncallBubble->SetIncallBubbleFlagsL( EAknStatusBubbleInputShow );
       
   144         MakeVisible( ETrue );
       
   145     	ClaimPointerGrab( ETrue );
       
   146         return;
       
   147         }
       
   148 
       
   149     TInt priority = GetWndPriority();
       
   150     iPriority =  priority;
       
   151     iWndGroup.SetOrdinalPosition( 0, iPriority);
       
   152     DrawableWindow()->SetOrdinalPosition( 0, iPriority);
       
   153     //OnActivate();
       
   154     iWndGroup.SetNonFading(ETrue);
       
   155     //ChangeSysteFadeStatus();
       
   156     ActivateL();
       
   157     iIncallBubble->SetIncallBubbleFlagsL( EAknStatusBubbleInputShow );
       
   158    // MakeVisible( ETrue );
       
   159 	ClaimPointerGrab( ETrue );
       
   160 	
       
   161 	
       
   162 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS      
       
   163 	
       
   164     if ( GfxTransEffect::IsRegistered( this ) && !IsVisible())
       
   165         {
       
   166         this->MakeVisible(EFalse);
       
   167         GfxTransEffect::NotifyExternalState( ENotifyGlobalAbort ); 
       
   168 
       
   169         //If still visible, do a transition to invisible state.
       
   170         CAknTransitionUtils::SetAllParents(this);
       
   171         GfxTransEffect::Begin(this, KGfxControlAppearAction);
       
   172         GfxTransEffect::NotifyExternalState(ECaptureComponentsBegin, (const TDesC8*)this);
       
   173         
       
   174         TRect demarcation;
       
   175         CAknTransitionUtils::GetDemarcation(CAknTransitionUtils::EPopup, 
       
   176                                             demarcation);
       
   177         GfxTransEffect::SetDemarcation(this, demarcation);
       
   178         
       
   179         this->MakeVisible(ETrue);
       
   180         
       
   181         GfxTransEffect::NotifyExternalState(ECaptureComponentsEnd, (const TDesC8*)this);
       
   182         GfxTransEffect::End(this);
       
   183          }
       
   184    
       
   185 
       
   186     else
       
   187         {
       
   188 #endif // RD_UI_TRANSITION_EFFECTS_POPUPS   
       
   189         MakeVisible( ETrue );
       
   190 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS            
       
   191         }
       
   192 #endif // RD_UI_TRANSITION_EFFECTS_POPUPS       
       
   193     }
       
   194 
       
   195 void CPenUiWndCtrl::ClosePenUi(TBool aResChanging)
       
   196     {
       
   197     if (aResChanging)
       
   198         {
       
   199         TRAP_IGNORE(iIncallBubble->SetIncallBubbleFlagsL( EAknStatusBubbleInputHide ));
       
   200         MakeVisible( EFalse );
       
   201         return;
       
   202         }
       
   203 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS           
       
   204     if ( GfxTransEffect::IsRegistered( this ))
       
   205         {
       
   206 
       
   207         GfxTransEffect::NotifyExternalState( ENotifyGlobalAbort ); 
       
   208 
       
   209         //If still visible, do a transition to invisible state.
       
   210         CAknTransitionUtils::SetAllParents(this);
       
   211         GfxTransEffect::Begin(this, KGfxControlDisappearAction);
       
   212         GfxTransEffect::NotifyExternalState(ECaptureComponentsBegin, (const TDesC8*)this);
       
   213         
       
   214         TRect demarcation;
       
   215         CAknTransitionUtils::GetDemarcation(CAknTransitionUtils::EPopup, 
       
   216                                             demarcation);
       
   217         GfxTransEffect::SetDemarcation(this, demarcation);
       
   218         
       
   219         this->MakeVisible(EFalse);
       
   220         
       
   221         GfxTransEffect::NotifyExternalState(ECaptureComponentsEnd, (const TDesC8*)this);
       
   222         GfxTransEffect::End(this);
       
   223          }
       
   224     else
       
   225         {
       
   226 #endif // RD_UI_TRANSITION_EFFECTS_POPUPS   
       
   227         MakeVisible( EFalse );
       
   228 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS            
       
   229         }
       
   230 #endif // RD_UI_TRANSITION_EFFECTS_POPUPS
       
   231 
       
   232     //iResourceChange = EFalse;
       
   233     iShowPopup = EFalse;
       
   234     iWndGroup.SetOrdinalPosition( -1, ECoeWinPriorityNormal-1 );
       
   235     DrawableWindow()->SetOrdinalPosition(-1, ECoeWinPriorityNormal-1 );
       
   236     TRAP_IGNORE(iIncallBubble->SetIncallBubbleFlagsL( EAknStatusBubbleInputHide ));
       
   237     //MakeVisible( EFalse );
       
   238       
       
   239 }
       
   240 
       
   241 
       
   242 void CPenUiWndCtrl::ShowPopup( const TRect& aRectInScreen, const TRect& aRectInLayout, const TRect& aLayoutTrimRect )
       
   243     {
       
   244     iPopupWnd->PopUp( aRectInScreen, aRectInLayout );
       
   245     iLayoutClipRect = aLayoutTrimRect;
       
   246     iShowPopup = ETrue;
       
   247     }
       
   248 
       
   249 void CPenUiWndCtrl::ClosePopup()
       
   250     {
       
   251     iShowPopup = EFalse;    
       
   252     iPopupWnd->Close();
       
   253     }
       
   254 TKeyResponse CPenUiWndCtrl::OfferKeyEventL( const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/ )
       
   255     {
       
   256     return EKeyWasNotConsumed;
       
   257     }
       
   258     
       
   259 void CPenUiWndCtrl::Invalidate(const TRect& aRect,TBool /*aFullUpdate*/)
       
   260     {
       
   261     //Window().Invalidate(aRect);
       
   262     /*********************************************************************/
       
   263     //Invalidate() should be used. But I don't know why there the rect in 
       
   264     // Draw is always full-screen in such case. So I change to DrawNow
       
   265     // for temprory solution.
       
   266     /*********************************************************************/ 
       
   267     
       
   268     if(iShowPopup)
       
   269         {        
       
   270         iPopupWnd->MakeVisible(EFalse);//This is a temproary fix due to pop up UI not updated.
       
   271         iPopupWnd->Invalidate(aRect);
       
   272         iPopupWnd->MakeVisible(ETrue);//This is a temproary fix due to pop up UI not updated.
       
   273         iPopupWnd->Invalidate(aRect);
       
   274         iPopupWnd->DrawNow();
       
   275         }
       
   276     else
       
   277         //DrawNow(aRect);
       
   278         {
       
   279         iInvalidateRect = aRect;
       
   280         Window().Invalidate(aRect);
       
   281         }
       
   282     }
       
   283 
       
   284 void CPenUiWndCtrl::OnActivate(EditorType aType)
       
   285     {
       
   286     //TBool dim = IsDimmed();
       
   287     RestoreSystemFadeStatus();
       
   288     //have to call this, otherwise pen UI is faded
       
   289     iWndGroup.SetNonFading(ETrue);
       
   290     
       
   291     if (iResourceChange)
       
   292         {
       
   293         return;    
       
   294         }
       
   295     TInt priority = GetWndPriority();
       
   296     
       
   297     switch (aType)
       
   298         {
       
   299         case EGlobleNotesWithEditor:
       
   300             {
       
   301             iInGlobalEditorState = ETrue;
       
   302             iWndGroup.SetOrdinalPosition( 0, priority);
       
   303             DrawableWindow()->SetOrdinalPosition( 0, priority);
       
   304             iPriority = priority;                
       
   305             }
       
   306         break;
       
   307         case EGlobleNotes:
       
   308         default:
       
   309             {
       
   310             iInGlobalEditorState = EFalse;
       
   311             if( priority != iPriority)
       
   312                 {
       
   313                 //iDimForClientMenu = EFalse;
       
   314                 iWndGroup.SetOrdinalPosition( 0, priority);
       
   315                 DrawableWindow()->SetOrdinalPosition( 0, priority);
       
   316                 iPriority = priority;
       
   317                 }                
       
   318             }
       
   319         }
       
   320     }
       
   321 
       
   322 void CPenUiWndCtrl::OnDeactivate()
       
   323     {
       
   324     iWndGroup.SetNonFading(EFalse);
       
   325     }    
       
   326 
       
   327 void CPenUiWndCtrl::ChangeSysteFadeStatus()
       
   328     {
       
   329     TBool faded = IsDimmed();//EFalse;
       
   330     //iAknUiSrv->IsSystemFaded(faded);
       
   331 
       
   332     if (faded)
       
   333         {
       
   334         iChangeSystemFadeStatus = ETrue;
       
   335         iAknUiSrv->SetSystemFaded(EFalse);
       
   336         }
       
   337     }
       
   338 
       
   339 void CPenUiWndCtrl::Fade()
       
   340     {
       
   341     //iAknUiSrv->SetSystemFaded(ETrue) ;
       
   342     iWndGroup.SetFaded(ETrue,RWindowTreeNode::EFadeIncludeChildren);
       
   343     }
       
   344     
       
   345 TBool CPenUiWndCtrl::IsDimmed()
       
   346     {
       
   347     TBool faded = EFalse;
       
   348     iAknUiSrv->IsSystemFaded(faded);    
       
   349     return faded;    
       
   350     }
       
   351 void CPenUiWndCtrl::RestoreSystemFadeStatus()
       
   352     {
       
   353     if(iChangeSystemFadeStatus)
       
   354         {
       
   355         iAknUiSrv->SetSystemFaded(EFalse);
       
   356         iChangeSystemFadeStatus = EFalse;
       
   357         }
       
   358     }
       
   359     
       
   360 void CPenUiWndCtrl::DimPenUiForMenu()    
       
   361     {
       
   362     iWndGroup.SetNonFading(EFalse);
       
   363     Window().SetFaded(ETrue,RWindowTreeNode::EFadeWindowOnly);
       
   364     //return;
       
   365     /*RWsSession &ws = CCoeEnv::Static()->WsSession();
       
   366     TInt wgId =ws.GetFocusWindowGroup();    
       
   367     TInt priority = ws.GetWindowGroupOrdinalPriority(wgId);
       
   368     if(iPriority != priority)
       
   369         {
       
   370         //TInt p1 = DrawableWindow()->FullOrdinalPosition();
       
   371         //TInt p2 = DrawableWindow()->OrdinalPosition();
       
   372         
       
   373         iWndGroup.SetOrdinalPosition( 0, priority);
       
   374         DrawableWindow()->SetOrdinalPosition( 0, priority);
       
   375         //p1 = DrawableWindow()->FullOrdinalPosition();
       
   376         //p2 = DrawableWindow()->OrdinalPosition();
       
   377         }*/
       
   378     }
       
   379 static TBool bTest = EFalse;
       
   380     
       
   381 void CPenUiWndCtrl::DimPenUiForMenu(TInt aPriority)    
       
   382     {
       
   383     if(bTest)
       
   384         {
       
   385         MakeVisible(EFalse);
       
   386         return;
       
   387         }
       
   388     
       
   389     if (!iResourceChange)
       
   390         {
       
   391         if(iPriority != aPriority)
       
   392             {
       
   393             iWndGroup.SetOrdinalPosition( 0, aPriority);
       
   394             DrawableWindow()->SetOrdinalPosition( 0, aPriority);
       
   395             iPriority = aPriority;
       
   396             }
       
   397         DimPenUiForMenu(); 
       
   398         }
       
   399     
       
   400    
       
   401     }
       
   402  
       
   403 void CPenUiWndCtrl::DimInternalPenUiForMenu(TInt aPriority)    
       
   404     {
       
   405     if(iPriority != aPriority)
       
   406         {
       
   407         iWndGroup.SetOrdinalPosition( 0, aPriority);
       
   408         DrawableWindow()->SetOrdinalPosition( 0, aPriority);
       
   409         iPriority = aPriority;
       
   410         }
       
   411 
       
   412     return;
       
   413     } 
       
   414        
       
   415 void CPenUiWndCtrl::SetResourceChange(TBool aResourceChange)
       
   416     {
       
   417     iResourceChange = aResourceChange;
       
   418     }
       
   419     
       
   420 //End Of File
       
   421 // class CInternalBkCtrl
       
   422 CInternalBkCtrl::CInternalBkCtrl(RWindowGroup& aWndGroup)    
       
   423             :iWndGroup(aWndGroup)
       
   424     {
       
   425     }
       
   426  
       
   427 void CInternalBkCtrl::ConstructL()
       
   428     {
       
   429     CreateWindowL(iWndGroup);
       
   430     SetComponentsToInheritVisibility(EFalse);
       
   431     MakeVisible(EFalse);
       
   432     //SetCanDrawOutsideRect();   
       
   433     }
       
   434 //class for pop up window
       
   435 
       
   436 CPenUiPopWnd* CPenUiPopWnd::NewL(RWindowGroup& aWndGroup,CFbsBitmap * aBitmap,
       
   437                                                           CPenUiWndCtrl* aCtrl)
       
   438     {
       
   439     CPenUiPopWnd* self = new (ELeave) CPenUiPopWnd(aWndGroup,aBitmap,aCtrl);
       
   440     CleanupStack::PushL(self);
       
   441     self->ConstructL();
       
   442     CleanupStack::Pop(self);
       
   443     return self;    
       
   444     }
       
   445 CPenUiPopWnd::CPenUiPopWnd(RWindowGroup& aWndGroup,CFbsBitmap * aBitmap,
       
   446                                                         CPenUiWndCtrl* aCtrl)
       
   447     :iWndGroup(aWndGroup),
       
   448      iBitmap(aBitmap),
       
   449      iAknUiSrv(CAknSgcClient::AknSrv()),
       
   450      iBackgroundCtrl(aCtrl)
       
   451 {
       
   452 }
       
   453 
       
   454 CPenUiPopWnd::~CPenUiPopWnd()
       
   455 {
       
   456 }
       
   457 
       
   458 void CPenUiPopWnd::ConstructL()
       
   459 {
       
   460     CreateWindowL(iWndGroup);
       
   461     SetComponentsToInheritVisibility();
       
   462 
       
   463     Window().SetRequiredDisplayMode( EColor16MA );
       
   464     //Window().EnableRedrawStore(EFalse);    
       
   465     MakeVisible( EFalse );
       
   466     ActivateL();
       
   467     
       
   468 }
       
   469 
       
   470 void CPenUiPopWnd::PopUp(TInt aPriority)
       
   471     {
       
   472     //iWndGroup.SetOrdinalPosition( 0, ECoeWinPriorityNormal);    
       
   473     Window().SetFaded(EFalse,RWindowTreeNode::EFadeWindowOnly);
       
   474     DrawableWindow()->SetOrdinalPosition( 0, aPriority);      
       
   475     MakeVisible( ETrue );
       
   476     Window().Invalidate();
       
   477     }
       
   478 void CPenUiPopWnd::Invalidate(const TRect& aRect)
       
   479     {
       
   480     //Window().Invalidate(aRect);
       
   481     DrawNow(aRect);
       
   482     }
       
   483 
       
   484 void CPenUiPopWnd::PopUp(const TRect& aRectInScreen, const TRect aRectInLayout )
       
   485     {
       
   486     iRectInLayout = aRectInLayout;
       
   487     SetRect( aRectInScreen );
       
   488     iWndGroup.SetNonFading(ETrue);
       
   489     PopUp(iBackgroundCtrl->WndPriority());   
       
   490     Window().FadeBehind(ETrue); 
       
   491     }
       
   492 
       
   493 void CPenUiPopWnd::Close()
       
   494     {
       
   495     Window().FadeBehind(EFalse);
       
   496     MakeVisible(EFalse);   
       
   497     iWndGroup.SetNonFading(ETrue);    
       
   498     Window().ClearRedrawStore();
       
   499     }
       
   500     
       
   501 void CPenUiPopWnd::Draw(const TRect& /*aRect*/) const
       
   502     {
       
   503     CWindowGc& gc = SystemGc();
       
   504     gc.BitBlt( TPoint(0,0), iBitmap, iRectInLayout ); 
       
   505     // Add to fix NGA refresh problem
       
   506     CCoeEnv::Static()->WsSession().Flush();
       
   507     CCoeEnv::Static()->WsSession().Finish(); 
       
   508     }
       
   509