securitydialogs/Autolock/src/AutolockContainer.cpp
changeset 0 164170e6151a
child 1 d5423fbb4f29
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002 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 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "AutolockContainer.h"
       
    21 #include <eikenv.h>
       
    22 #include <autolock.mbg>
       
    23 #include <avkon.hrh>
       
    24 #include <aknlayoutscalable_avkon.cdl.h>
       
    25 #include <aknlayoutscalable_apps.cdl.h>
       
    26 #include <layoutmetadata.cdl.h>
       
    27 #include <data_caging_path_literals.hrh>
       
    28 #include "AutolockAppUiPS.h"
       
    29 #include <Autolock.rsg>
       
    30 #include "autolock.hrh"
       
    31 #include <eikdef.h>
       
    32 
       
    33 #include <coreapplicationuisdomainpskeys.h>
       
    34 
       
    35 #include <AknsLayeredBackgroundControlContext.h>
       
    36 #include <AknsDrawUtils.h>
       
    37 #include <AknBitmapAnimation.h>
       
    38 #include    <AknsUtils.h>
       
    39 #include	<AknUtils.h>
       
    40 
       
    41 #include <e32property.h>
       
    42 #include <PSVariables.h>   // Property values
       
    43 #include <coreapplicationuisdomainpskeys.h>
       
    44 #include <StartupDomainPSKeys.h>
       
    45 #include <ctsydomainpskeys.h>
       
    46 _LIT(BitmapName,"AutoLock.mbm");
       
    47 
       
    48 // CONSTANTS
       
    49 
       
    50 #ifdef RD_FULLSCREEN_WALLPAPER
       
    51 enum TAutolockBgLayers
       
    52     {
       
    53     EAutolockBgLayerWallpaper      = 0,    
       
    54     EAutolockBgLayerBackground     = 1,
       
    55     EAutolockBgLayersN             = 2
       
    56     };
       
    57 #else
       
    58 enum TAutolockBgLayers
       
    59     {
       
    60     EAutolockBgLayerBackground     = 0,
       
    61     EAutolockBgLayerWallpaper      = 1,
       
    62     EAutolockBgLayersN             = 2
       
    63     };
       
    64 #endif //RD_FULLSCREEN_WALLPAPER
       
    65 
       
    66         TInt aCallRect_x;
       
    67         TInt aCallRect_y;
       
    68         TInt aCallRect_width;
       
    69         TInt aCallRect_height;
       
    70 // ================= MEMBER FUNCTIONS =======================
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CAutolockContainer::ConstructL(const TRect& aRect)
       
    74 // Symbian OS two phased constructor
       
    75 // ---------------------------------------------------------
       
    76 //
       
    77 void CAutolockContainer::ConstructL(const TRect& aRect)
       
    78     {
       
    79     #if defined(_DEBUG)
       
    80     RDebug::Print(_L("(AUTOLOCK)CAutolockContainer::ConstructL"));
       
    81     #endif
       
    82     CreateWindowL();
       
    83 
       
    84     HBufC* bitMapPath = HBufC::NewLC(KMaxPath);
       
    85     TPtr BitmapFile(bitMapPath->Des());
       
    86     BitmapFile.Append(_L("Z:"));
       
    87     BitmapFile.Append(KDC_APP_BITMAP_DIR);
       
    88     BitmapFile.Append(BitmapName);
       
    89 
       
    90     iEikBitmap = 0;
       
    91     iEikBitmapCall = 0;
       
    92     AknsUtils::CreateIconL( 
       
    93         AknsUtils::SkinInstance(), 
       
    94         KAknsIIDQgnGrafPhoneLocked,
       
    95         iBitmap,
       
    96         iMask,
       
    97         BitmapFile,
       
    98         EMbmAutolockQgn_graf_phone_locked, 
       
    99         EMbmAutolockQgn_graf_phone_locked_mask );
       
   100     AknsUtils::CreateIconL( 
       
   101         AknsUtils::SkinInstance(), 
       
   102         KAknsIIDQgnGrafPhoneLocked,
       
   103         iBitmapCall,
       
   104         iMaskCall,
       
   105         BitmapFile,
       
   106         EMbmAutolockQgn_indi_button_end_call, 
       
   107         EMbmAutolockQgn_indi_button_end_call_mask );
       
   108     
       
   109 #ifdef RD_FULLSCREEN_WALLPAPER
       
   110     TSize screenSize = iCoeEnv->ScreenDevice()->SizeInPixels();
       
   111     TRect wallpaperRect( TPoint(0,0), screenSize );    
       
   112     iBgContext = CAknsLayeredBackgroundControlContext::NewL(
       
   113     KAknsIIDWallpaper, wallpaperRect, ETrue, EAutolockBgLayersN );
       
   114     SetRect(aRect);
       
   115 #else    
       
   116     // Create background control context for skins. Use parent absolute mode,
       
   117     // as this is window owning control
       
   118     iBgContext = CAknsLayeredBackgroundControlContext::NewL(
       
   119         KAknsIIDQsnBgAreaMainIdle, aRect, ETrue, EAutolockBgLayersN );
       
   120     iBgContext->SetLayerImage( EAutolockBgLayerWallpaper, KAknsIIDWallpaper );
       
   121     iBgContext->SetLayerRect( EAutolockBgLayerWallpaper, aRect );
       
   122     SetRect(aRect);
       
   123 #endif // RD_FULLSCREEN_WALLPAPER
       
   124     ActivateL();
       
   125 
       
   126     CleanupStack::PopAndDestroy(bitMapPath); //bitMapPath
       
   127     #if defined(_DEBUG)
       
   128     RDebug::Print(_L("(AUTOLOCK)CAutolockContainer::ConstructL END"));
       
   129     #endif
       
   130     }
       
   131 
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // CAutolockContainer::~CAutolockContainer()
       
   135 // Destructor
       
   136 // ---------------------------------------------------------
       
   137 //
       
   138 CAutolockContainer::~CAutolockContainer()
       
   139     {
       
   140     delete iBgContext;
       
   141     delete iBitmap;
       
   142     delete iMask;
       
   143     delete iBitmapCall;
       
   144     delete iMaskCall;
       
   145 
       
   146 	}
       
   147 // ---------------------------------------------------------
       
   148 // CAutolockContainer::SizeChanged()
       
   149 // Called by framework when the view size is changed
       
   150 // ---------------------------------------------------------
       
   151 //
       
   152 void CAutolockContainer::SizeChanged()
       
   153     {
       
   154     #if defined(_DEBUG)
       
   155     RDebug::Print(_L("(AUTOLOCK)CAutolockContainer::SizeChanged()"));
       
   156     #endif
       
   157     
       
   158     TRect mainPaneRect(Rect());
       
   159     TAknLayoutRect idleTradPane;
       
   160     idleTradPane.LayoutRect(mainPaneRect, AknLayoutScalable_Avkon::main_idle_trad_pane());
       
   161 
       
   162     TInt variety = 3;
       
   163     if (Layout_Meta_Data::IsLandscapeOrientation())
       
   164         {
       
   165         variety = 2;
       
   166         }
       
   167 
       
   168 
       
   169     TAknLayoutRect idlePaneG2;
       
   170     idlePaneG2.LayoutRect(idleTradPane.Rect(), AknLayoutScalable_Avkon::main_idle_pane_g2(variety));
       
   171 
       
   172     TInt callState = 0;
       
   173 	  RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
       
   174     if ( callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized )
       
   175     	{
       
   176     AknIconUtils::SetSize( iBitmap, idlePaneG2.Rect().Size() );
       
   177     	}
       
   178     else
       
   179     	{
       
   180 		  TSize lockSize = TSize(0.8 * idlePaneG2.Rect().Size().iWidth, 0.8 * idlePaneG2.Rect().Size().iHeight);
       
   181 	    AknIconUtils::SetSize( iBitmap, lockSize );
       
   182     	}
       
   183 		TSize callSize = TSize(60,60);
       
   184     AknIconUtils::SetSize( iBitmapCall, callSize );
       
   185     
       
   186 #ifdef  RD_FULLSCREEN_WALLPAPER
       
   187     TSize screenSize = iCoeEnv->ScreenDevice()->SizeInPixels();
       
   188     TRect wallpaperRect( TPoint(0,0), screenSize );    
       
   189     iBgContext->SetLayerRect( EAutolockBgLayerBackground, Rect() ) ;
       
   190     iBgContext->SetLayerRect( EAutolockBgLayerWallpaper, wallpaperRect ) ;
       
   191     
       
   192     TPoint origo( 0, 0);
       
   193     iBgContext->SetParentPos(origo);
       
   194 #else
       
   195 
       
   196     iBgContext->SetLayerRect( EAutolockBgLayerBackground, Rect() ) ;
       
   197     iBgContext->SetLayerRect( EAutolockBgLayerWallpaper, Rect() ) ;
       
   198      
       
   199     TPoint positionRelativeToScreen = PositionRelativeToScreen();
       
   200     //parent must be set when using parent absolute mode.
       
   201     iBgContext->SetParentPos(positionRelativeToScreen);
       
   202 #endif //RD_FULLSCREEN_WALLPAPER
       
   203 
       
   204         RRegion autolockRegion;
       
   205 #ifdef  RD_FULLSCREEN_WALLPAPER    	
       
   206     	autolockRegion.AddRect( wallpaperRect);
       
   207 #else    	
       
   208     	autolockRegion.AddRect(Rect());
       
   209 #endif //RD_FULLSCREEN_WALLPAPER   
       
   210         Window().SetShape(autolockRegion);
       
   211         autolockRegion.Close();
       
   212     
       
   213      #if defined(_DEBUG)
       
   214     RDebug::Print(_L("(AUTOLOCK)CAutolockContainer::SizeChanged() END"));
       
   215     #endif
       
   216 	 }
       
   217 // ---------------------------------------------------------
       
   218 // CAutolockContainer::CountComponentControls() const
       
   219 // ---------------------------------------------------------
       
   220 //
       
   221 TInt CAutolockContainer::CountComponentControls() const
       
   222     {
       
   223     TInt controlCount = 0;
       
   224 
       
   225     return controlCount;
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------
       
   229 // CAutolockContainer::ComponentControl(TInt aIndex) const
       
   230 // ---------------------------------------------------------
       
   231 //
       
   232 CCoeControl* CAutolockContainer::ComponentControl(TInt /*aIndex*/) const
       
   233     {
       
   234     return NULL;
       
   235 	} 
       
   236  // ---------------------------------------------------------
       
   237 // CAutolockContainer::Draw(const TRect& aRect) const
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 void CAutolockContainer::Draw(const TRect& aRect) const
       
   241     {
       
   242     #if defined(_DEBUG)
       
   243     RDebug::Print(_L("(AUTOLOCK)CAutolockContainer::Draw"));
       
   244     #endif
       
   245     if (AknLayoutUtils::PenEnabled() )
       
   246     	{
       
   247 			TInt value = 0;
       
   248 			RProperty::Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, value);	    
       
   249 			if(value <= EAutolockOff)
       
   250 				{	// Avoid displaying the icon
       
   251 				#if defined(_DEBUG)
       
   252 				RDebug::Printf( "%s %s (%u) no Draw value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, value );
       
   253 				#endif
       
   254 				return;
       
   255 				}
       
   256 			}
       
   257 
       
   258     CWindowGc& gc = SystemGc();
       
   259     gc.SetPenStyle(CGraphicsContext::ENullPen);
       
   260     gc.SetBrushColor(KRgbWhite); 
       
   261     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   262     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   263     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   264     AknsDrawUtils::Background( skin, cc, this, gc, aRect );
       
   265 
       
   266     // Draw "lock" icon centered to this control    
       
   267     // fist calculate the correct x coordinate based on this 
       
   268     // controls rect and bitmap width    
       
   269     TInt x = Rect().Width()/2 - iBitmap->SizeInPixels().iWidth /2;
       
   270     // and do same with y
       
   271     TInt y = Rect().Height()/2 - iBitmap->SizeInPixels().iHeight/2;
       
   272 		TInt width =iBitmap->SizeInPixels().iWidth;
       
   273 		TInt height =iBitmap->SizeInPixels().iHeight;
       
   274       TInt callState = 0;
       
   275   	  RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
       
   276     if ( callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized )
       
   277     	{
       
   278     	}
       
   279     else
       
   280     	{
       
   281     	y-=100;
       
   282     	}
       
   283     
       
   284     if (iBitmap && iMask)
       
   285         {
       
   286           // gc.BitBltMasked(TPoint(x,y),iBitmap,TRect(TPoint(0,0),iBitmap->SizeInPixels()), iMask, ETrue);
       
   287           gc.BitBltMasked(TPoint(x,y),iBitmap,TRect(TPoint(0,0),TPoint(width,height)), iMask, ETrue);
       
   288     	  if ( callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized )
       
   289     	  	{
       
   290     	  }
       
   291     	  else
       
   292     	  	{
       
   293    	    	aCallRect_x=Rect().Width()/2 - iBitmapCall->SizeInPixels().iWidth/2;
       
   294 		    	aCallRect_y=Rect().Height() * 0.75;
       
   295 		    	aCallRect_width=iBitmapCall->SizeInPixels().iWidth;
       
   296 		    	aCallRect_height=iBitmapCall->SizeInPixels().iHeight;
       
   297     	  	TSize cornerSize(20,20); 
       
   298     	  	TSize cornerEllipseSize(cornerSize.iHeight*2,cornerSize.iWidth*2);
       
   299     	  	TRect box(aCallRect_x-3*10	, aCallRect_y-3*10, aCallRect_x+aCallRect_width+3*10, aCallRect_y+aCallRect_height+3*10);
       
   300 					TRect cornerRectTl(box.iTl,cornerEllipseSize);
       
   301 					gc.SetBrushColor(KRgbRed); 
       
   302 					gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   303 					gc.SetPenStyle(CGraphicsContext::EDottedPen);
       
   304 					gc.DrawRoundRect(box,cornerSize);
       
   305         	gc.BitBltMasked(TPoint(aCallRect_x,aCallRect_y),iBitmapCall,TRect(TPoint(0,0),TPoint(aCallRect_width,aCallRect_height)), iMaskCall, ETrue);
       
   306     	  	aCallRect_y+=100;	// coordinates are realtive to TRect, not to Screen
       
   307         	}
       
   308         }
       
   309     else if (iBitmap && !iMask)
       
   310         {
       
   311         gc.BitBlt(TPoint(x,y),iBitmap);
       
   312     	  if ( callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized )
       
   313     	  	{
       
   314     	  	}
       
   315     	  else
       
   316     	  	{
       
   317         	gc.BitBlt(TPoint(x,y+iBitmap->SizeInPixels().iHeight),iBitmapCall);
       
   318         	}
       
   319         }
       
   320     #if defined(_DEBUG)
       
   321     RDebug::Print(_L("(AUTOLOCK)CAutolockContainer::Draw END"));
       
   322     #endif
       
   323     }
       
   324 
       
   325 // ---------------------------------------------------------
       
   326 // CAutolockContainer::HandleControlEventL(
       
   327 //     CCoeControl* aControl,TCoeEvent aEventType)
       
   328 // ---------------------------------------------------------
       
   329 //
       
   330 void CAutolockContainer::HandleControlEventL(
       
   331     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   332     {
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------
       
   336 // CAutolockContainer::MopSupplyObject
       
   337 // 
       
   338 // ---------------------------------------------------------
       
   339 //
       
   340 TTypeUid::Ptr CAutolockContainer::MopSupplyObject( TTypeUid aId )
       
   341     {
       
   342     if (aId.iUid == MAknsControlContext::ETypeId)
       
   343         {
       
   344         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   345         }
       
   346     return CCoeControl::MopSupplyObject( aId );
       
   347     }
       
   348 void CAutolockContainer::GiveCoords( TRect& aRect )
       
   349     {
       
   350     	aRect.iBr.iX=aCallRect_x;
       
   351     	aRect.iBr.iY=aCallRect_y;
       
   352     	aRect.iTl.iX=aCallRect_width+2*3*10;
       
   353     	aRect.iTl.iY=aCallRect_height+2*3*10;
       
   354     }
       
   355 // End of File