securitydialogs/lockapp/src/lockappdevicelockcontainer.cpp
branchRCL_3
changeset 50 03674e5abf46
parent 0 164170e6151a
equal deleted inserted replaced
49:09b1ac925e3f 50:03674e5abf46
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Devicelock Background UI (window owning control)
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "lockappdevicelockcontainer.h"
       
    21 #include "lockapputils.h"
       
    22 
       
    23 #include <eikenv.h>
       
    24 #include <lockapp.mbg>
       
    25 #include <avkon.hrh>
       
    26 #include <aknlayoutscalable_avkon.cdl.h>
       
    27 #include <aknlayoutscalable_apps.cdl.h>
       
    28 #include <AknsLayeredBackgroundControlContext.h>
       
    29 #include <AknsDrawUtils.h>
       
    30 #include <AknBitmapAnimation.h>
       
    31 #include <AknsUtils.h>
       
    32 #include <AknUtils.h>
       
    33 #include <aknappui.h>
       
    34 
       
    35 #include <layoutmetadata.cdl.h>
       
    36 #include <data_caging_path_literals.hrh>
       
    37 #include <eikdef.h>
       
    38 
       
    39 _LIT(LOCKBITMAPNAME, "AutoLock.mbm"); // TODO change filename
       
    40 
       
    41 // CONSTANTS
       
    42 
       
    43 #ifdef RD_FULLSCREEN_WALLPAPER
       
    44 enum TAutolockBgLayers
       
    45     {
       
    46     EAutolockBgLayerWallpaper = 0,
       
    47     EAutolockBgLayerBackground = 1,
       
    48     EAutolockBgLayersN = 2
       
    49     };
       
    50 #else
       
    51 enum TAutolockBgLayers
       
    52     {
       
    53     EAutolockBgLayerBackground = 0,
       
    54     EAutolockBgLayerWallpaper = 1,
       
    55     EAutolockBgLayersN = 2
       
    56     };
       
    57 #endif //RD_FULLSCREEN_WALLPAPER
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Standard Symbian OS construction sequence
       
    61 // ---------------------------------------------------------------------------
       
    62 CLockAppDevicelockContainer* CLockAppDevicelockContainer::NewL( RWindowGroup& aWg )
       
    63     {
       
    64     CLockAppDevicelockContainer* self = new (ELeave) CLockAppDevicelockContainer( );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL( aWg );
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // Symbian OS two phased constructor
       
    73 // ---------------------------------------------------------
       
    74 void CLockAppDevicelockContainer::ConstructL( RWindowGroup& aWg )
       
    75     {
       
    76     INFO( "CLockAppDevicelockContainer::ConstructL started" );
       
    77 
       
    78     CreateWindowL( aWg );
       
    79     MakeVisible( EFalse );
       
    80 
       
    81     HBufC* bitMapPath = HBufC::NewLC( KMaxPath );
       
    82     TPtr BitmapFile( bitMapPath->Des( ) );
       
    83     BitmapFile.Append( _L("Z:") );
       
    84     BitmapFile.Append( KDC_APP_BITMAP_DIR );
       
    85     BitmapFile.Append( LOCKBITMAPNAME );
       
    86 
       
    87     TRect mainPaneRect = GetMainPaneRect( );
       
    88 
       
    89     iClock = NULL;
       
    90     iEikBitmap = NULL;
       
    91     AknsUtils::CreateIconL( AknsUtils::SkinInstance( ), KAknsIIDQgnGrafPhoneLocked, iBitmap, iMask,
       
    92             BitmapFile, EMbmLockappQgn_graf_phone_locked, EMbmLockappQgn_graf_phone_locked_mask );
       
    93 
       
    94 #ifdef RD_FULLSCREEN_WALLPAPER
       
    95     TSize screenSize = iCoeEnv->ScreenDevice()->SizeInPixels( );
       
    96     TRect wallpaperRect( TPoint( 0, 0 ), screenSize);
       
    97     iBgContext = CAknsLayeredBackgroundControlContext::NewL( KAknsIIDWallpaper, wallpaperRect,
       
    98             ETrue, EAutolockBgLayersN );
       
    99 #else
       
   100     // Create background control context for skins. Use parent absolute mode,
       
   101     // as this is window owning control
       
   102     iBgContext = CAknsLayeredBackgroundControlContext::NewL(
       
   103             KAknsIIDQsnBgAreaMainIdle, mainPaneRect, ETrue, EAutolockBgLayersN );
       
   104     iBgContext->SetLayerImage( EAutolockBgLayerWallpaper, KAknsIIDWallpaper );
       
   105     iBgContext->SetLayerRect( EAutolockBgLayerWallpaper, mainPaneRect );
       
   106 #endif // RD_FULLSCREEN_WALLPAPER
       
   107 
       
   108     SetRect( mainPaneRect );
       
   109     CleanupStack::PopAndDestroy( bitMapPath ); //bitMapPath
       
   110     INFO( "CLockAppDevicelockContainer::ConstructL completed" );
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------
       
   114 // Destructor
       
   115 // ---------------------------------------------------------
       
   116 CLockAppDevicelockContainer::~CLockAppDevicelockContainer( )
       
   117     {
       
   118     delete iBgContext;
       
   119     delete iBitmap;
       
   120     delete iMask;
       
   121     delete iClock;
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // Return the rectangle for this control
       
   126 // ---------------------------------------------------------
       
   127 TRect CLockAppDevicelockContainer::GetMainPaneRect( )
       
   128     {
       
   129     TRect screen( iAvkonAppUi->ApplicationRect());
       
   130     TAknLayoutRect applicationWindow;
       
   131     applicationWindow.LayoutRect( screen, AknLayoutScalable_Avkon::application_window( 0 ) );
       
   132     TInt mainPaneVariety = ( Layout_Meta_Data::IsLandscapeOrientation() ? 4 : 3 );
       
   133     TAknLayoutRect mainPane;
       
   134     mainPane.LayoutRect( applicationWindow.Rect( ),
       
   135             AknLayoutScalable_Avkon::main_pane( mainPaneVariety ) );
       
   136     return mainPane.Rect( );
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // Called by framework when the view size is changed
       
   141 // ---------------------------------------------------------
       
   142 void CLockAppDevicelockContainer::SizeChanged()
       
   143     {
       
   144     INFO( "CLockAppDevicelockContainer::SizeChanged" );
       
   145     TRect mainPaneRect( Rect( ));
       
   146     TAknLayoutRect idleTradPane;
       
   147     idleTradPane.LayoutRect( mainPaneRect, AknLayoutScalable_Avkon::main_idle_trad_pane( ) );
       
   148 
       
   149     TInt variety = ( Layout_Meta_Data::IsLandscapeOrientation() ? 2 : 3 );
       
   150 
       
   151     TAknLayoutRect idlePaneG2;
       
   152     idlePaneG2.LayoutRect( idleTradPane.Rect( ),
       
   153             AknLayoutScalable_Avkon::main_idle_pane_g2( variety ) );
       
   154     AknIconUtils::SetSize( iBitmap, idlePaneG2.Rect().Size( ) );
       
   155 
       
   156     TPoint parentPos( 0, 0);
       
   157 #ifdef RD_FULLSCREEN_WALLPAPER
       
   158     TSize screenSize = iCoeEnv->ScreenDevice()->SizeInPixels( );
       
   159     TRect wallpaperRect( TPoint( 0, 0 ), screenSize);
       
   160     iBgContext->SetLayerRect( EAutolockBgLayerBackground, Rect( ) );
       
   161     iBgContext->SetLayerRect( EAutolockBgLayerWallpaper, wallpaperRect );
       
   162 #else
       
   163     iBgContext->SetLayerRect( EAutolockBgLayerBackground, Rect() );
       
   164     iBgContext->SetLayerRect( EAutolockBgLayerWallpaper, Rect() );
       
   165     //parent must be set when using parent absolute mode.
       
   166     parentPos = PositionRelativeToScreen();
       
   167 #endif //RD_FULLSCREEN_WALLPAPER
       
   168 
       
   169     iBgContext->SetParentPos( parentPos );
       
   170 
       
   171     if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
   172         {
       
   173         // the screen is in portrait mode
       
   174         if ( iClock )
       
   175             {
       
   176             // remove clock, if it exists
       
   177             delete iClock;
       
   178             iClock = NULL;
       
   179             }
       
   180         RRegion autolockRegion;
       
   181 #ifdef  RD_FULLSCREEN_WALLPAPER
       
   182         autolockRegion.AddRect( wallpaperRect );
       
   183 #else
       
   184         autolockRegion.AddRect( Rect() );
       
   185 #endif //RD_FULLSCREEN_WALLPAPER
       
   186         Window().SetShape( autolockRegion );
       
   187         autolockRegion.Close( );
       
   188         }
       
   189     else
       
   190         {
       
   191         // the screen is in landscape mode.
       
   192         // get the correct area from layout utils.
       
   193         TAknLayoutRect popupClockDigitalAnalogueWindowLayoutRect;
       
   194         popupClockDigitalAnalogueWindowLayoutRect.LayoutRect( idleTradPane.Rect( ),
       
   195                 AknLayoutScalable_Avkon::popup_clock_digital_analogue_window( 3 ) );
       
   196         TRect popupClockDigitalAnalogueWindowRect(popupClockDigitalAnalogueWindowLayoutRect.Rect( ));
       
   197 
       
   198         // since the clock is not shown in app shell when the screen is in landscape,
       
   199         // we'll show a clock here.
       
   200         if ( !iClock )
       
   201             {
       
   202             TRAP_IGNORE({
       
   203                         CAknSkinnableClock* clock = CAknSkinnableClock::NewL( this, ETrue, EFalse );
       
   204                         CleanupStack::PushL( clock );
       
   205                         clock->SetRect( popupClockDigitalAnalogueWindowRect );
       
   206                         clock->ActivateL();
       
   207                         CleanupStack::Pop( clock );
       
   208                         iClock = clock;
       
   209                         });
       
   210             }
       
   211         else
       
   212             {
       
   213             iClock->SetRect( popupClockDigitalAnalogueWindowRect );
       
   214             }
       
   215         RRegion autolockRegion;
       
   216 #ifdef RD_FULLSCREEN_WALLPAPER
       
   217         autolockRegion.AddRect( wallpaperRect );
       
   218 #else
       
   219         autolockRegion.AddRect( Rect() );
       
   220 #endif //RD_FULLSCREEN_WALLPAPER
       
   221         autolockRegion.AddRect( iClock->Rect( ) );
       
   222         Window().SetShape( autolockRegion );
       
   223         autolockRegion.Close( );
       
   224         }
       
   225      }
       
   226 
       
   227 // ---------------------------------------------------------
       
   228 // CLockAppDevicelockContainer::CountComponentControls() const
       
   229 // ---------------------------------------------------------
       
   230 TInt CLockAppDevicelockContainer::CountComponentControls( ) const
       
   231     {
       
   232     TInt controlCount = 0;
       
   233     if ( Layout_Meta_Data::IsLandscapeOrientation( ) )
       
   234         {
       
   235         if ( iClock )
       
   236             {
       
   237             controlCount++;
       
   238             }
       
   239         }
       
   240     return controlCount;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------
       
   244 // CLockAppDevicelockContainer::ComponentControl(TInt aIndex) const
       
   245 // ---------------------------------------------------------
       
   246 CCoeControl* CLockAppDevicelockContainer::ComponentControl(TInt /*aIndex*/) const
       
   247     {
       
   248     return iClock;
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------
       
   252 // CLockAppDevicelockContainer::Draw(const TRect& aRect) const
       
   253 // ---------------------------------------------------------
       
   254 void CLockAppDevicelockContainer::Draw(const TRect& aRect) const
       
   255     {
       
   256     CWindowGc& gc = SystemGc( );
       
   257     gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   258     gc.SetBrushColor( KRgbWhite );
       
   259     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   260     MAknsSkinInstance* skin = AknsUtils::SkinInstance( );
       
   261     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   262     AknsDrawUtils::Background( skin, cc, this, gc, aRect );
       
   263 
       
   264     if ( iBitmap )
       
   265         {
       
   266         // Draw "lock" icon centered to this control
       
   267         TInt x = (Rect().Width( ) - iBitmap->SizeInPixels().iWidth) / 2;
       
   268         TInt y = (Rect().Height( ) - iBitmap->SizeInPixels().iHeight) / 2;
       
   269         if ( iMask )
       
   270             {
       
   271             gc.BitBltMasked( TPoint( x, y ), iBitmap, TRect( TPoint( 0, 0 ),
       
   272                     iBitmap->SizeInPixels( ) ), iMask, ETrue );
       
   273             }
       
   274         else
       
   275             {
       
   276             gc.BitBlt( TPoint( x, y ), iBitmap );
       
   277             }
       
   278         }
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------
       
   282 // CLockAppDevicelockContainer::HandleControlEventL( CCoeControl* aControl,TCoeEvent aEventType)
       
   283 // ---------------------------------------------------------
       
   284 void CLockAppDevicelockContainer::HandleControlEventL(CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/)
       
   285     {
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------
       
   289 // CLockAppDevicelockContainer::MopSupplyObject
       
   290 // ---------------------------------------------------------
       
   291 TTypeUid::Ptr CLockAppDevicelockContainer::MopSupplyObject( TTypeUid aId )
       
   292     {
       
   293     if ( aId.iUid == MAknsControlContext::ETypeId )
       
   294         {
       
   295         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   296         }
       
   297     return CCoeControl::MopSupplyObject( aId );
       
   298     }
       
   299 
       
   300 // End of File