| 22 |      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 | #include <e32std.h>
 | 
|  |     19 | #include <eiklabel.h>
 | 
|  |     20 | #include <eikfutil.h>
 | 
|  |     21 | #include <aknconsts.h>
 | 
|  |     22 | #include <akntitle.h>
 | 
|  |     23 | #include <avkon.mbg>
 | 
|  |     24 | #include <aknview.h>
 | 
|  |     25 | #include <aknViewAppUi.h>
 | 
|  |     26 | #include <Autolock.rsg>
 | 
|  |     27 | #include "autolock.hrh"
 | 
|  |     28 | #include <aknlayoutscalable_avkon.cdl.h>
 | 
|  |     29 | #include <layoutmetadata.cdl.h>
 | 
|  |     30 | #include <AknUtils.h>
 | 
|  |     31 | #include "AutolockAppUiPS.h"
 | 
|  |     32 | #include "AutoLockModelPS.h"
 | 
|  |     33 | #include "AutolockView.h"
 | 
|  |     34 | #include "AutolockContainer.h"
 | 
|  |     35 | 
 | 
|  |     36 | 
 | 
|  |     37 | 
 | 
|  |     38 | 
 | 
|  |     39 | // CONSTANTS
 | 
|  |     40 | 
 | 
|  |     41 | const TUid KUidStartUp = { 0x100058F4 };
 | 
|  |     42 | const TInt KPhoneAppOrdinalPosition = 1; // used to pull phone app closer to foreground
 | 
|  |     43 | 
 | 
|  |     44 | // ================= MEMBER FUNCTIONS =======================
 | 
|  |     45 | //
 | 
|  |     46 | // ----------------------------------------------------
 | 
|  |     47 | // CAutolockView::ConstructL()
 | 
|  |     48 | // Symbian OS default constructor can leave..
 | 
|  |     49 | // ----------------------------------------------------
 | 
|  |     50 | //
 | 
|  |     51 | void CAutolockView::ConstructL()
 | 
|  |     52 | 	{
 | 
|  |     53 | 	#if defined(_DEBUG)
 | 
|  |     54 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::ConstructL()"));
 | 
|  |     55 |     #endif
 | 
|  |     56 |     BaseConstructL();
 | 
|  |     57 | 	}
 | 
|  |     58 | // ----------------------------------------------------
 | 
|  |     59 | // CAutolockView::~CAutolockView()
 | 
|  |     60 | // Destructor
 | 
|  |     61 | // ----------------------------------------------------
 | 
|  |     62 | //
 | 
|  |     63 | CAutolockView::~CAutolockView()
 | 
|  |     64 | 	{
 | 
|  |     65 | 	#if defined(_DEBUG)
 | 
|  |     66 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::~CAutolockView()"));
 | 
|  |     67 |     #endif
 | 
|  |     68 |     CAutolockContainer* view = iView;
 | 
|  |     69 |     iView = NULL;
 | 
|  |     70 | 	if (view)
 | 
|  |     71 |         {
 | 
|  |     72 | 		AppUi()->RemoveFromStack(view);
 | 
|  |     73 |         }
 | 
|  |     74 | 	delete view;
 | 
|  |     75 | 	}
 | 
|  |     76 | // ----------------------------------------------------
 | 
|  |     77 | // CAutolockView::Id()
 | 
|  |     78 | // Returns view Id
 | 
|  |     79 | // ----------------------------------------------------
 | 
|  |     80 | //
 | 
|  |     81 | TUid CAutolockView::Id() const
 | 
|  |     82 |     {
 | 
|  |     83 |     return KAutoLockViewId;
 | 
|  |     84 |     }
 | 
|  |     85 | // ----------------------------------------------------
 | 
|  |     86 | // CAutolockView::HandleCommandL()
 | 
|  |     87 | // Handles user inputs
 | 
|  |     88 | // ----------------------------------------------------
 | 
|  |     89 | //
 | 
|  |     90 | void CAutolockView::HandleCommandL(TInt aCommand)
 | 
|  |     91 |     {
 | 
|  |     92 |     #if defined(_DEBUG)
 | 
|  |     93 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::HandleCommandL()"));
 | 
|  |     94 |     #endif   
 | 
|  |     95 |     AppUi()->HandleCommandL(aCommand);
 | 
|  |     96 |     #if defined(_DEBUG)
 | 
|  |     97 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::HandleCommandL END()"));
 | 
|  |     98 |     #endif
 | 
|  |     99 |     }
 | 
|  |    100 | void CAutolockView::HandleCall(TInt aCommand, TRect &aRect)
 | 
|  |    101 |     {
 | 
|  |    102 |     	// RDebug::Printf( "%s %s (%u) aCommand=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aCommand );
 | 
|  |    103 |     if (iView)
 | 
|  |    104 |     	{
 | 
|  |    105 |         TRect cr = ClientRect();
 | 
|  |    106 |         iView->SetRect( cr );
 | 
|  |    107 |     		// RDebug::Printf( "%s %s (%u) got 2 cr=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aCommand );
 | 
|  |    108 |         iView->DrawNow( );
 | 
|  |    109 |         iView->GiveCoords( aRect );
 | 
|  |    110 | 			}
 | 
|  |    111 |     else
 | 
|  |    112 | 			{
 | 
|  |    113 | 			// RDebug::Printf( "%s %s (%u) !iView ???=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iView );
 | 
|  |    114 | 			}
 | 
|  |    115 |     }
 | 
|  |    116 | void CAutolockView::MakeVisible(TBool aVisibility)
 | 
|  |    117 |     {
 | 
|  |    118 |     #if defined(_DEBUG)
 | 
|  |    119 |     RDebug::Printf( "%s %s (%u) aVisibility=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aVisibility );
 | 
|  |    120 |     #endif   
 | 
|  |    121 |     if (iView)
 | 
|  |    122 | 	iView->MakeVisible( aVisibility );
 | 
|  |    123 |     else
 | 
|  |    124 | 	{
 | 
|  |    125 | 	#if defined(_DEBUG)
 | 
|  |    126 | 	RDebug::Printf( "%s %s (%u) !iView ???=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iView );
 | 
|  |    127 | 	#endif   
 | 
|  |    128 | 	}
 | 
|  |    129 |     #if defined(_DEBUG)
 | 
|  |    130 |     RDebug::Printf( "%s %s (%u) aVisibility=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aVisibility );
 | 
|  |    131 |     #endif
 | 
|  |    132 |     }
 | 
|  |    133 | // ----------------------------------------------------
 | 
|  |    134 | // CAutolockView::HandleStatusPaneSizeChange()
 | 
|  |    135 | // Handles StatusPane Size Change
 | 
|  |    136 | // ----------------------------------------------------
 | 
|  |    137 | //
 | 
|  |    138 | void CAutolockView::HandleStatusPaneSizeChange()
 | 
|  |    139 | 	{
 | 
|  |    140 | 	#if defined(_DEBUG)
 | 
|  |    141 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::HandleStatusPaneSizeChange()"));
 | 
|  |    142 |     #endif
 | 
|  |    143 |     if (iView)
 | 
|  |    144 |         {
 | 
|  |    145 |         #if defined(_DEBUG)
 | 
|  |    146 |         RDebug::Print(_L("(AUTOLOCK)CAutolockView::HandleStatusPaneSizeChange() SET RECT"));
 | 
|  |    147 |         #endif
 | 
|  |    148 |         TRect cr = ClientRect();
 | 
|  |    149 |         iView->SetRect( cr );
 | 
|  |    150 |         }
 | 
|  |    151 |     #if defined(_DEBUG)
 | 
|  |    152 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::HandleStatusPaneSizeChange() END"));
 | 
|  |    153 |     #endif
 | 
|  |    154 | 	}
 | 
|  |    155 | // ----------------------------------------------------
 | 
|  |    156 | // CAutolockView::DoActivateL
 | 
|  |    157 | // Activates the view
 | 
|  |    158 | // ----------------------------------------------------
 | 
|  |    159 | //
 | 
|  |    160 | void CAutolockView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,TUid aCustomMessageId,const TDesC8& /*aCustomMessage*/)
 | 
|  |    161 | 	{
 | 
|  |    162 | 	#if defined(_DEBUG)
 | 
|  |    163 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::DoActivateL"));
 | 
|  |    164 |     #endif	
 | 
|  |    165 | 	iView = new(ELeave) CAutolockContainer;
 | 
|  |    166 | 
 | 
|  |    167 |     TRect screen( iAvkonAppUi->ApplicationRect() );
 | 
|  |    168 |     TAknLayoutRect applicationWindow;
 | 
|  |    169 |     applicationWindow.LayoutRect(screen, AknLayoutScalable_Avkon::application_window(0));
 | 
|  |    170 |     TInt mainPaneVariety = 0;
 | 
|  |    171 |     if((AknLayoutUtils::PenEnabled()) && !(Layout_Meta_Data::IsLandscapeOrientation()))
 | 
|  |    172 |         {//Use main pane without softkey area
 | 
|  |    173 |             mainPaneVariety = 5;
 | 
|  |    174 |         }
 | 
|  |    175 |     else if (Layout_Meta_Data::IsLandscapeOrientation())
 | 
|  |    176 |         {
 | 
|  |    177 |             mainPaneVariety = 4;
 | 
|  |    178 |         }
 | 
|  |    179 |     else
 | 
|  |    180 |         {
 | 
|  |    181 |             mainPaneVariety = 3;
 | 
|  |    182 |         }
 | 
|  |    183 | 
 | 
|  |    184 |     
 | 
|  |    185 |     
 | 
|  |    186 |     TAknLayoutRect mainPane;
 | 
|  |    187 |     mainPane.LayoutRect(applicationWindow.Rect(), AknLayoutScalable_Avkon::main_pane(mainPaneVariety));     	
 | 
|  |    188 | 	iView->ConstructL( mainPane.Rect() );
 | 
|  |    189 |     AppUi()->AddToStackL(*this,iView);
 | 
|  |    190 | 
 | 
|  |    191 |     // Message comes from start-up. We need to lock the device.
 | 
|  |    192 |     if ( aCustomMessageId == KUidStartUp )
 | 
|  |    193 |         {
 | 
|  |    194 |         static_cast<CAutolockAppUi*>(AppUi())->Model()->LockSystemL();
 | 
|  |    195 | 
 | 
|  |    196 |         // Set phone app window group to position 2. This is the same position 
 | 
|  |    197 |         // as the phone app set is self when it goes to background.
 | 
|  |    198 |         TVwsViewId phoneAppId;
 | 
|  |    199 |         TApaTaskList taskList( iEikonEnv->WsSession() );
 | 
|  |    200 |         User::LeaveIfError( AknDef::GetPhoneIdleViewId(phoneAppId) );
 | 
|  |    201 |         const TInt phoneWgId = taskList.FindApp( phoneAppId.iAppUid ).WgId();
 | 
|  |    202 |         User::LeaveIfError( iCoeEnv->WsSession().SetWindowGroupOrdinalPosition( phoneWgId, KPhoneAppOrdinalPosition ) );
 | 
|  |    203 |         }
 | 
|  |    204 |     #if defined(_DEBUG)
 | 
|  |    205 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::DoActivateL END"));
 | 
|  |    206 |     #endif
 | 
|  |    207 |     }
 | 
|  |    208 | // ----------------------------------------------------
 | 
|  |    209 | // CAutolockView::DoDeActivateL
 | 
|  |    210 | // Deactivates the view
 | 
|  |    211 | // ----------------------------------------------------
 | 
|  |    212 | //
 | 
|  |    213 | void CAutolockView::DoDeactivate()
 | 
|  |    214 | 	{
 | 
|  |    215 | 	#if defined(_DEBUG)
 | 
|  |    216 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::DoDeActivateL"));
 | 
|  |    217 |     #endif
 | 
|  |    218 |     CAutolockContainer* view = iView;
 | 
|  |    219 |     iView = NULL;
 | 
|  |    220 | 	if (view)
 | 
|  |    221 |         {
 | 
|  |    222 | 		AppUi()->RemoveFromStack(view);
 | 
|  |    223 |         }
 | 
|  |    224 | 	delete view;
 | 
|  |    225 |     }
 | 
|  |    226 | // ----------------------------------------------------
 | 
|  |    227 | // CAutolockView::ScreenDeviceChanged()
 | 
|  |    228 | // Handles screen layout changes
 | 
|  |    229 | // ----------------------------------------------------
 | 
|  |    230 | //
 | 
|  |    231 | void CAutolockView::ScreenDeviceChanged()
 | 
|  |    232 | {
 | 
|  |    233 |  if (Layout_Meta_Data::IsLandscapeOrientation() && AknLayoutUtils::PenEnabled())
 | 
|  |    234 |         {//do not change layout in touch device to conserve battery
 | 
|  |    235 |         #if defined(_DEBUG)
 | 
|  |    236 |     		RDebug::Print(_L("(AUTOLOCK)CAutolockView::ScreenDeviceChanged(): Do Nothing"));
 | 
|  |    237 |     		#endif
 | 
|  |    238 |         return;
 | 
|  |    239 |         }
 | 
|  |    240 |         
 | 
|  |    241 |  if (iView)
 | 
|  |    242 |     {
 | 
|  |    243 |     TRect screen( iAvkonAppUi->ApplicationRect() );
 | 
|  |    244 |     TAknLayoutRect applicationWindow;
 | 
|  |    245 |     applicationWindow.LayoutRect(screen, AknLayoutScalable_Avkon::application_window(0));
 | 
|  |    246 | 
 | 
|  |    247 |     TInt mainPaneVariety = 0;
 | 
|  |    248 |     if((AknLayoutUtils::PenEnabled()) && !(Layout_Meta_Data::IsLandscapeOrientation()))
 | 
|  |    249 |         {//Use main pane without softkey area
 | 
|  |    250 |             mainPaneVariety = 5;
 | 
|  |    251 |         }
 | 
|  |    252 |     else if (Layout_Meta_Data::IsLandscapeOrientation())
 | 
|  |    253 |         {
 | 
|  |    254 |             mainPaneVariety = 4;
 | 
|  |    255 |         }
 | 
|  |    256 |     else
 | 
|  |    257 |         {
 | 
|  |    258 |             mainPaneVariety = 3;
 | 
|  |    259 |         }
 | 
|  |    260 |     #if defined(_DEBUG)
 | 
|  |    261 |     RDebug::Print(_L("(AUTOLOCK)CAutolockView::ScreenDeviceChanged() variety: %d"), mainPaneVariety);
 | 
|  |    262 |     #endif
 | 
|  |    263 |     TAknLayoutRect mainPane;
 | 
|  |    264 |     mainPane.LayoutRect(applicationWindow.Rect(), AknLayoutScalable_Avkon::main_pane(mainPaneVariety));     
 | 
|  |    265 |     iView->SetRect(mainPane.Rect());        
 | 
|  |    266 |     }
 | 
|  |    267 | }
 | 
|  |    268 | // end of file
 | 
|  |    269 | 
 |