uifw/AvKon/src/aknsgcc.cpp
changeset 0 2f259fa3e83a
child 51 fcdfafb36fe7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include <uikon/eikenvinterface.h>
       
    20 #include <uikon/eikdefmacros.h>
       
    21 #endif
       
    22 #include "AknSgcc.h"
       
    23 #include <eikspane.h>
       
    24 #include <eikappui.h>
       
    25 #include <eikenv.h>
       
    26 #include <barsread.h>
       
    27 #include <AknPriv.hrh>
       
    28 #include <aknenv.h>
       
    29 #include <aknconsts.h>
       
    30 #include "AknDef.h"
       
    31 #include <aknappui.h>
       
    32 #include "AknSettingCache.h"
       
    33 #include "AknLayoutConfig.h"
       
    34 #include "UikonInternalPSKeys.h"
       
    35 #include "AknPanic.h"
       
    36 
       
    37 #define KLegacyScreenSize TSize(176, 208)
       
    38 
       
    39 const TUid KAknSgcClientStaticId = { 0x101f7674 };
       
    40 const TUint32 KPeninputServerUid = 0x10281855;
       
    41 
       
    42 const TInt KStartupUnblankPriority = 10000;
       
    43 
       
    44 enum TSgcClientFlags
       
    45 	{
       
    46 	EHandlingChange,
       
    47 	EInAknSrv,
       
    48 	ESystemFaded,
       
    49 	ENeverRelinquish
       
    50 	};
       
    51 
       
    52 
       
    53 NONSHARABLE_CLASS(CAknSgcClientImpl) : public CAknSgcImpl
       
    54 	{
       
    55 public:
       
    56 	CAknSgcClientImpl(RAknUiServer& aAknSrv);
       
    57     void MoveApp(TInt aAppWindowGroupId, TSgcMoveAppToWhere aWhere);
       
    58 
       
    59 private:
       
    60 	RAknUiServer& iAknSrv;
       
    61 	};
       
    62 
       
    63 
       
    64 NONSHARABLE_CLASS(CAknSgcClientServerInst) : public CAknSgcClient
       
    65 	{
       
    66 public:
       
    67 	CAknSgcClientServerInst();
       
    68 	~CAknSgcClientServerInst();
       
    69 private: // from CAknSgcClient
       
    70     const TDesC8& DoLayoutConfigBuf();
       
    71 	void ConstructL();
       
    72 private:
       
    73 	HBufC8* iPackedLayoutConfigBuf;
       
    74 	};
       
    75 
       
    76 
       
    77 EXPORT_C void MAknSgcStatusPaneRedrawCoordinator::MAknSgcStatusPaneRedrawCoordinator_Reserved_1() {}
       
    78 EXPORT_C void MAknSgcStatusPaneRedrawCoordinator::MAknSgcStatusPaneRedrawCoordinator_Reserved_2() {}
       
    79 
       
    80 
       
    81 inline CAknSgcClient* CAknSgcClient::Static()
       
    82 	{ return static_cast<CAknSgcClient*>(CCoeEnv::Static(KAknSgcClientStaticId)); }
       
    83 
       
    84 
       
    85 
       
    86 NONSHARABLE_CLASS(TSgcClientStatusPaneRedrawCoordinator) : public MAknSgcStatusPaneRedrawCoordinator
       
    87 	{
       
    88 public:
       
    89 	TSgcClientStatusPaneRedrawCoordinator(RAknUiServer& aAknSrv);
       
    90 	void BlockServerStatusPaneRedrawsL();
       
    91 	void RedrawServerStatusPane();
       
    92 	
       
    93 private:
       
    94 	RAknUiServer& iAknSrv;
       
    95 	};
       
    96 
       
    97 TSgcClientStatusPaneRedrawCoordinator::TSgcClientStatusPaneRedrawCoordinator(RAknUiServer& aAknSrv)
       
    98 : iAknSrv(aAknSrv)
       
    99 	{
       
   100 	}
       
   101 
       
   102 void TSgcClientStatusPaneRedrawCoordinator::BlockServerStatusPaneRedrawsL()
       
   103 	{
       
   104 	}
       
   105 
       
   106 void TSgcClientStatusPaneRedrawCoordinator::RedrawServerStatusPane()
       
   107 	{
       
   108 	iAknSrv.RedrawServerStatusPane();
       
   109 	}
       
   110 
       
   111 
       
   112 
       
   113 EXPORT_C void CAknSgcClient::CreateL()
       
   114 	{
       
   115 	CAknSgcClient* self=CAknSgcClient::Static();
       
   116 	if (!self)
       
   117 		{
       
   118 		RThread thread;
       
   119 		if (thread.Name() == _L("akncapserver"))
       
   120 			self = new(ELeave) CAknSgcClientServerInst();  // CCoeEnv takes ownership immediately
       
   121 		else
       
   122 			self = new(ELeave) CAknSgcClient(); // CCoeEnv takes ownership immediately
       
   123 		self->ConstructL();
       
   124 		}
       
   125 	}
       
   126 
       
   127 CAknSgcClient::~CAknSgcClient()
       
   128 	{
       
   129 	delete iImpl;
       
   130 	delete iLayoutConfig;
       
   131 	if (!iFlags[EInAknSrv])
       
   132 		{
       
   133     	DoStartupUnblank();
       
   134 		// iSpRedrawCoord and iAknSrv are only owned/opened if this object
       
   135 		// is not running in the AknSrv process (see ConstructL()).
       
   136 		delete static_cast<TSgcClientStatusPaneRedrawCoordinator*>(iSpRedrawCoord);
       
   137 		iAknSrv.Close();
       
   138 		}
       
   139 	delete iDrawSync;
       
   140 	}
       
   141 
       
   142 void CAknSgcClient::ClearHandlingChangeFlag(TAny* aThis)
       
   143 	{
       
   144 	static_cast<CAknSgcClient*>(aThis)->iFlags.Clear(EHandlingChange);
       
   145 	}
       
   146 
       
   147 EXPORT_C void CAknSgcClient::HandleChangeL()
       
   148 	{
       
   149 	CAknSgcClient* self = Static();
       
   150 	if (self)
       
   151 		self->DoHandleChangeL();
       
   152 	}
       
   153 
       
   154 void CAknSgcClient::DoHandleChangeL()
       
   155 	{
       
   156 	if (iFlags[EInAknSrv])
       
   157 		return;
       
   158 
       
   159 	CAknAppUi* topAppUi = iAvkonAppUi;
       
   160 
       
   161 	if (!topAppUi)
       
   162 		return;
       
   163 
       
   164 	if (iFlags[EHandlingChange])
       
   165 		return;
       
   166 	iFlags.Set(EHandlingChange);
       
   167 	CleanupStack::PushL(TCleanupItem(ClearHandlingChangeFlag, this));
       
   168 
       
   169 	TInt spLayout = 0;
       
   170 	TInt spFlags = 0;
       
   171 	TBitFlags appFlags;
       
   172 	TInt screenMode = KAknScreenModeUnset;
       
   173 	SetLegacyOrientationAndScreenModeAppUiFlags(appFlags, screenMode, topAppUi);
       
   174 	appFlags.Assign(EFullScreen, topAppUi->IsFullScreenApp());
       
   175 	TBool partialFg = topAppUi->IsPartialForeground();
       
   176 	TBool foreground = topAppUi->IsForeground();
       
   177 
       
   178 	// loop over app UIs from most embedded to base app
       
   179 	for (CAknAppUiBase* appUi = static_cast<CAknAppUiBase*>(topAppUi); appUi; appUi = static_cast<CAknAppUiBase*>(appUi->ContainerAppUi()))
       
   180 		{
       
   181 		CEikStatusPane* sp = StatusPane(appUi);
       
   182 		if (sp && !spLayout)
       
   183 			{
       
   184 			spLayout = sp->CurrentLayoutResId();
       
   185 			spFlags = sp->Flags();
       
   186 			}
       
   187 
       
   188 		if (appUi != topAppUi)
       
   189 			{
       
   190 			SetLegacyOrientationAndScreenModeAppUiFlags(appFlags, screenMode, appUi);
       
   191 
       
   192 			partialFg = (foreground || partialFg) && !appFlags[EFullScreen];
       
   193 			foreground = EFalse;
       
   194 			appFlags.Assign(EFullScreen, appFlags[EFullScreen] || appUi->IsFullScreenApp());
       
   195 
       
   196 			SetAppUiForegroundL(appUi, foreground);
       
   197 			SetAppUiPartialFgL(appUi, partialFg);
       
   198 			}
       
   199 		}
       
   200 
       
   201 	if (spLayout != iSpLayout || 
       
   202 	    !(appFlags == iAppFlags) || 
       
   203 	    spFlags != iSpFlags ||
       
   204 	    screenMode != iAppScreenMode)
       
   205 		{
       
   206 		iSpLayout = spLayout;
       
   207 		iSpFlags = spFlags;
       
   208 		iAppFlags = appFlags;
       
   209 		iAppScreenMode = screenMode;
       
   210 		User::LeaveIfError(iAknSrv.SetSgcParams(iEikonEnv->RootWin().Identifier(), appFlags, spLayout, spFlags, screenMode));
       
   211 		}
       
   212 
       
   213 	CleanupStack::PopAndDestroy();
       
   214 	}
       
   215 
       
   216 CAknSgcClient::CAknSgcClient()
       
   217 : CCoeStatic(KAknSgcClientStaticId), iCoeEnv(CCoeEnv::Static())
       
   218 	{
       
   219 	}
       
   220 
       
   221 void CAknSgcClient::BaseConstructL()
       
   222 	{
       
   223 	RProcess process;
       
   224 	if( process.SecureId() == KPeninputServerUid )
       
   225 	    {
       
   226 	    iFlags.Set(ENeverRelinquish);
       
   227 	    }
       
   228 	
       
   229 	iDrawSync = CAknDrawSynchronizer::NewL();
       
   230 	iLayoutConfig = new(ELeave) CAknLayoutConfig;
       
   231 	}
       
   232 	
       
   233 void CAknSgcClient::ConstructL()
       
   234 	{
       
   235 	BaseConstructL();
       
   236 	
       
   237 	User::LeaveIfError(iAknSrv.Connect());
       
   238 	iSpRedrawCoord = new(ELeave) TSgcClientStatusPaneRedrawCoordinator(iAknSrv);
       
   239 	SetImpl(new(ELeave) CAknSgcClientImpl(iAknSrv));
       
   240 
       
   241     if(iAvkonEnv->HasBlank())
       
   242         StartupBlankL();
       
   243 
       
   244 	HBufC8* packedBuf;
       
   245 	if (iAknSrv.Handle())
       
   246 		{
       
   247 		packedBuf = iAknSrv.GetPackedConfigL();
       
   248 		}
       
   249 	else
       
   250 		{	// eiksrv will end up here
       
   251 		packedBuf = iLayoutConfig->CreatePackedBufL();
       
   252 		}
       
   253 	iLayoutConfig->ConstructL(packedBuf);
       
   254 	}
       
   255 
       
   256 CEikStatusPane* CAknSgcClient::StatusPane(CEikAppUi* aAppUi)
       
   257 	{
       
   258 	MEikAppUiFactory* factory = iEikonEnv->AppUiFactory(*aAppUi);
       
   259 	if (factory)
       
   260 		return factory->StatusPane();
       
   261 	else
       
   262 		return NULL;
       
   263 	}
       
   264 
       
   265 void CAknSgcClient::SetAppUiForegroundL(CAknAppUiBase* aAppUi, TBool aForeground)
       
   266 	{
       
   267 	if (!COMPARE_BOOLS(aAppUi->IsForeground(), aForeground))
       
   268 		SimulateWsEventL(aAppUi, aForeground ? EEventFocusGained : EEventFocusLost);
       
   269 	}
       
   270 
       
   271 void CAknSgcClient::SetAppUiPartialFgL(CAknAppUiBase* aAppUi, TBool aPartialFg)
       
   272 	{
       
   273 	if (!COMPARE_BOOLS(aAppUi->IsPartialForeground(), aPartialFg))
       
   274 		SimulateWsEventL(aAppUi, aPartialFg ? KEikPartialForeground : KEikClearPartialForegroundState);
       
   275 	}
       
   276 
       
   277 void CAknSgcClient::SimulateWsEventL(CEikAppUi* aAppUi, TInt aEventId)
       
   278 	{
       
   279 	TWsEvent event;
       
   280 	event.SetType(aEventId);
       
   281 	event.SetHandle(0);
       
   282 #if (defined(SYMBIAN_SUPPORT_UI_FRAMEWORKS_V1) || defined(__SERIES60_27__) || defined(__SERIES60_28__)) 
       
   283 	static_cast<CCoeAppUiBase*>(aAppUi)->HandleWsEventL(event, NULL);	
       
   284 #else 
       
   285 	static_cast<CCoeAppUi*>(aAppUi)->HandleWsEventL(event, NULL);
       
   286 #endif 
       
   287 	}
       
   288 
       
   289 EXPORT_C RAknUiServer* CAknSgcClient::AknSrv()
       
   290 	{
       
   291 	CAknSgcClient* self = Static();
       
   292 	if (self)
       
   293 		return &self->iAknSrv;
       
   294 	else
       
   295 		return NULL;
       
   296 	}
       
   297 
       
   298 EXPORT_C void CAknSgcClient::SetStatusPaneRedrawCoordinator(MAknSgcStatusPaneRedrawCoordinator* aSpRedrawCoord)
       
   299 	{
       
   300 	CAknSgcClient* self = Static();
       
   301 	if (self)
       
   302 		{
       
   303 		ASSERT(!self->iSpRedrawCoord || !aSpRedrawCoord);
       
   304 		self->iSpRedrawCoord = aSpRedrawCoord;
       
   305 		}
       
   306 	}
       
   307 
       
   308 EXPORT_C void CAknSgcClient::BlockServerStatusPaneRedrawsL()
       
   309 	{
       
   310 	}
       
   311 
       
   312 EXPORT_C void CAknSgcClient::RedrawServerStatusPane()
       
   313 	{
       
   314 	CAknSgcClient* self = Static();
       
   315 	if (self && self->iSpRedrawCoord)
       
   316 		self->iSpRedrawCoord->RedrawServerStatusPane();
       
   317 	}
       
   318 
       
   319 EXPORT_C CAknDrawSynchronizer* CAknSgcClient::DrawSynchronizer()
       
   320 	{
       
   321 	CAknSgcClient* self = Static();
       
   322 	if (self)
       
   323 		return self->iDrawSync;
       
   324 	else
       
   325 		return NULL;
       
   326 	}
       
   327 
       
   328 EXPORT_C void CAknSgcClient::PrepareForAppExit()
       
   329 	{
       
   330 	CAknSgcClient* self = Static();
       
   331 	if (self)
       
   332 		self->DoPrepareForAppExit();
       
   333 	}
       
   334 
       
   335 void CAknSgcClient::DoPrepareForAppExit()
       
   336 	{
       
   337 	if (!iFlags[EInAknSrv])
       
   338 		{
       
   339 		iAknSrv.PrepareForAppExit(iEikonEnv->RootWin().Identifier());
       
   340 		}
       
   341 	}
       
   342 
       
   343 EXPORT_C void CAknSgcClient::SetSystemFaded(TBool aFade)
       
   344 	{
       
   345 	CAknSgcClient* self = Static();
       
   346 	if (self)
       
   347 		self->DoSetSystemFaded(aFade);
       
   348 	}
       
   349 
       
   350 EXPORT_C TBool CAknSgcClient::IsSystemFaded()
       
   351 	{
       
   352 	CAknSgcClient* self = Static();
       
   353 	if (self)
       
   354 		return self->DoIsSystemFaded();
       
   355 	else
       
   356 		return EFalse;
       
   357 	}
       
   358 
       
   359 void CAknSgcClient::DoSetSystemFaded(TBool aFade)
       
   360 	{
       
   361 	if (iFlags[EInAknSrv])
       
   362 		{
       
   363 		if (!COMPARE_BOOLS(iFlags[ESystemFaded], aFade))
       
   364 			{
       
   365 			if (aFade)
       
   366 				{
       
   367 				RedrawServerStatusPane();
       
   368 				}
       
   369 			}
       
   370 		iEikonEnv->WsSession().SetSystemFaded(aFade);
       
   371 		iFlags.Assign(ESystemFaded, aFade);	
       
   372 		}
       
   373 	else
       
   374 		{
       
   375 		iAknSrv.SetSystemFaded(aFade);
       
   376 		}
       
   377 	}
       
   378 
       
   379 TBool CAknSgcClient::DoIsSystemFaded() const
       
   380 	{
       
   381 	if (iFlags[EInAknSrv])
       
   382 		{
       
   383 		return iFlags[ESystemFaded];
       
   384 		}
       
   385 	else
       
   386 		{
       
   387 		TBool fade;
       
   388 		iAknSrv.IsSystemFaded(fade);
       
   389 		return fade;
       
   390 		}
       
   391 	}
       
   392 
       
   393 void CAknSgcClient::SetLegacyOrientationAndScreenModeAppUiFlags(TBitFlags& aAppFlags, TInt& aScreenMode, CAknAppUiBase* aAppUi)
       
   394 	{
       
   395 	if (!aAppFlags[EFullScreen] && aAppUi->IsFullScreenApp())
       
   396 		{
       
   397 	//	aAppFlags.Assign(ELegacyLayout, !aAppUi->IsLayoutAwareApp()); // Fix Me !!
       
   398 		CAknAppUiBase::TAppUiOrientation r = aAppUi->Orientation();
       
   399 		aAppFlags.Assign(EOrientationSpecified, r != CAknAppUiBase::EAppUiOrientationUnspecified);
       
   400 		aAppFlags.Assign(EOrientationLandscape, r == CAknAppUiBase::EAppUiOrientationLandscape);
       
   401 		aScreenMode = aAppUi->ScreenMode();
       
   402 		}
       
   403 	}
       
   404 
       
   405 EXPORT_C TPixelsTwipsAndRotation CAknSgcClient::PixelsAndRotation()
       
   406 	{
       
   407 	CAknSgcClient* self = Static();
       
   408 	if (self)
       
   409 		{
       
   410 		TBitFlags& flags = self->iAppFlags;
       
   411     	TInt mode = self->iAppScreenMode;
       
   412 		return self->DoCalculatePixelsAndRotation(flags[EFullScreen], flags[ELegacyLayout], flags[EOrientationSpecified], flags[EOrientationLandscape], mode);
       
   413 		}
       
   414 	else
       
   415 		{
       
   416 		TPixelsTwipsAndRotation r;
       
   417 		CEikonEnv::Static()->ScreenDevice()->GetDefaultScreenSizeAndRotation(r);
       
   418 		return r;
       
   419 		}
       
   420 	}
       
   421 
       
   422 inline TBool AspectIsLandscape(const TPixelsTwipsAndRotation& aR)
       
   423 	{
       
   424 	return aR.iPixelSize.iWidth > aR.iPixelSize.iHeight;
       
   425 	}
       
   426 
       
   427 EXPORT_C TPixelsTwipsAndRotation CAknSgcClient::CalculatePixelsAndRotation(TBool aFullScreen, TBool aLegacyApp, TBool aAppOrientationSpecified, TBool aAppOrientationLandscape)
       
   428 	{
       
   429 	CAknSgcClient* self = Static();
       
   430 	if (self)
       
   431 		{
       
   432 		return self->DoCalculatePixelsAndRotation(aFullScreen, aLegacyApp, aAppOrientationSpecified, aAppOrientationLandscape, KAknScreenModeUnset);
       
   433 		}
       
   434 	else
       
   435 		{
       
   436 		TPixelsTwipsAndRotation r;
       
   437 		CEikonEnv::Static()->ScreenDevice()->GetDefaultScreenSizeAndRotation(r);
       
   438 		return r;
       
   439 		}
       
   440 	}
       
   441 
       
   442 TPixelsTwipsAndRotation CAknSgcClient::DoCalculatePixelsAndRotation(TBool aFullScreen, TBool aLegacyApp, TBool aAppOrientationSpecified, TBool aAppOrientationLandscape, TInt aAppScreenMode)
       
   443 	{
       
   444 	CAknLayoutConfig::TScreenMode screenMode = DoCalculateScreenMode(aFullScreen, aAppOrientationSpecified, aAppOrientationLandscape, aAppScreenMode);
       
   445 	TPixelsTwipsAndRotation r = screenMode.PixelsTwipsAndRotation();
       
   446 
       
   447 	// legacy mode
       
   448 	if (aLegacyApp && aFullScreen)
       
   449 		r.iPixelSize = KLegacyScreenSize;
       
   450 
       
   451 	return r;
       
   452 	}
       
   453 	
       
   454 EXPORT_C CAknLayoutConfig::TScreenMode CAknSgcClient::ScreenMode()
       
   455 	{
       
   456 	CAknSgcClient* self = Static();
       
   457 	__ASSERT_ALWAYS(self, Panic(EAknPanicSgccNull));
       
   458 	TBitFlags& flags = self->iAppFlags;
       
   459 	TInt mode = self->iAppScreenMode;
       
   460 	return self->DoCalculateScreenMode(flags[EFullScreen], flags[EOrientationSpecified], flags[EOrientationLandscape], mode);
       
   461 	}
       
   462 
       
   463 EXPORT_C CAknLayoutConfig::TScreenMode CAknSgcClient::CalculateScreenMode(TBool aFullScreen, TBool aAppOrientationSpecified, TBool aAppOrientationLandscape)
       
   464 	{
       
   465 	return CalculateScreenMode(aFullScreen, aAppOrientationSpecified, aAppOrientationLandscape, KAknScreenModeUnset);
       
   466 	}
       
   467 
       
   468 EXPORT_C CAknLayoutConfig::TScreenMode CAknSgcClient::CalculateScreenMode(TBool aFullScreen, TBool aAppOrientationSpecified, TBool aAppOrientationLandscape, TInt aAppScreenMode)
       
   469 	{
       
   470 	CAknSgcClient* self = Static();
       
   471 	__ASSERT_ALWAYS(self, Panic(EAknPanicSgccNull));
       
   472 	return self->DoCalculateScreenMode(aFullScreen, aAppOrientationSpecified, aAppOrientationLandscape, aAppScreenMode);
       
   473 	}
       
   474 
       
   475 CAknLayoutConfig::TScreenMode CAknSgcClient::DoCalculateScreenMode(TBool aFullScreen, TBool aAppOrientationSpecified, TBool aAppOrientationLandscape, TInt aAppScreenMode)
       
   476 	{
       
   477 	if (!aFullScreen)
       
   478 		{
       
   479 		// return current screen mode for partial screen apps
       
   480 		return iLayoutConfig->ScreenModes().Find(iEikonEnv->ScreenDevice()->CurrentScreenMode());
       
   481 		}
       
   482 
       
   483     if (aAppScreenMode != KAknScreenModeUnset)
       
   484 		{
       
   485 		// return current screen mode set by the app
       
   486 		return iLayoutConfig->ScreenModes().Find(aAppScreenMode);
       
   487 		}
       
   488 
       
   489 	TInt hwStateNum = iAvkonEnv->SettingCache().HardwareLayoutState();
       
   490 	CAknLayoutConfig::THardwareState hwScreen = iLayoutConfig->HardwareStates().Find(hwStateNum);
       
   491 
       
   492     TInt mode;
       
   493     TInt orientation = iAvkonEnv->SettingCache().PreferredOrientation();
       
   494     if ( orientation == EPreferredOrientationNormal )
       
   495         {
       
   496         mode = hwScreen.ScreenMode();
       
   497         }
       
   498     else
       
   499         {
       
   500         mode = hwScreen.AlternateScreenMode();
       
   501         }
       
   502 
       
   503 	CAknLayoutConfig::TScreenMode screenMode = iLayoutConfig->ScreenModes().Find(mode);
       
   504 	
       
   505 	if (aAppOrientationSpecified &&
       
   506 		!COMPARE_BOOLS(aAppOrientationLandscape, AspectIsLandscape(screenMode.PixelsTwipsAndRotation())))
       
   507 		{
       
   508         if ( orientation == EPreferredOrientationNormal )
       
   509             {
       
   510     		// App rotation specificied but orientation is different to hw state
       
   511 	    	// so use alternate mode
       
   512             mode = hwScreen.AlternateScreenMode();
       
   513             }
       
   514         else 
       
   515             {
       
   516             mode = hwScreen.ScreenMode();
       
   517             }
       
   518 		return iLayoutConfig->ScreenModes().Find(mode);
       
   519 		}
       
   520 		
       
   521 	return screenMode;
       
   522 	}
       
   523 
       
   524 EXPORT_C void CAknSgcClient::SetKeyBlockMode(TAknKeySoundOpcode aMode)
       
   525     {
       
   526 	CAknSgcClient* self = Static();
       
   527 	if (self)
       
   528         {
       
   529         self->DoSetKeyBlockMode(aMode);
       
   530         }
       
   531     }
       
   532 
       
   533 EXPORT_C void CAknSgcClient::SetKeyboardRepeatRate(TAknDefaultKeyboardRepeatRate aRate)
       
   534     {
       
   535 	CAknSgcClient* self = Static();
       
   536 	if (self)
       
   537         {
       
   538         self->DoSetKeyboardRepeatRate(aRate);
       
   539         }
       
   540     }
       
   541 
       
   542 EXPORT_C TInt CAknSgcClient::CurrentStatuspaneResource()
       
   543     {
       
   544 	CAknSgcClient* self = Static();
       
   545 	if (self)
       
   546         {
       
   547         return self->DoAskCurrentStatuspaneResource();
       
   548         }
       
   549         
       
   550     return 0; // not able to resolve
       
   551     }
       
   552     
       
   553 
       
   554 TInt CAknSgcClient::DoAskCurrentStatuspaneResource()
       
   555     {
       
   556     if (CEikStatusPaneBase::Current())
       
   557         {
       
   558         return CEikStatusPaneBase::Current()->CurrentLayoutResId();
       
   559         }
       
   560     else 
       
   561         return iAknSrv.StatusPaneResourceId();   
       
   562     }
       
   563 
       
   564 void CAknSgcClient::DoSetKeyBlockMode(TAknKeySoundOpcode aMode)
       
   565     {
       
   566 	if (iFlags[EInAknSrv])
       
   567 		{
       
   568         TRawEvent event;
       
   569         TAknKeySoundOpcode opcode = EEnableKeyBlock; // default
       
   570 	    if (aMode == ENoKeyBlock)
       
   571 		    {
       
   572 		    opcode = EDisableKeyBlock;
       
   573 		    }
       
   574 	    event.Set((TRawEvent::TType)opcode);
       
   575         iEikonEnv->WsSession().SimulateRawEvent(event);		
       
   576 		}
       
   577 	else
       
   578 		{
       
   579 		iAknSrv.SetKeyblockMode(aMode);
       
   580 		}
       
   581     }
       
   582 
       
   583 void CAknSgcClient::DoSetKeyboardRepeatRate(TAknDefaultKeyboardRepeatRate aRate)
       
   584     {
       
   585 	if (iFlags[EInAknSrv])
       
   586 		{
       
   587         TInt repeatRate = KAknStandardKeyboardRepeatRate; // default 
       
   588         if (aRate == EAknEditorDefaulRepeatRate)
       
   589             {
       
   590             repeatRate = KAknEditorKeyboardRepeatRate;
       
   591             }
       
   592         iEikonEnv->WsSession().SetKeyboardRepeatRate(KAknKeyboardRepeatInitialDelay,repeatRate);
       
   593         }
       
   594 	else
       
   595 		{
       
   596 		iAknSrv.SetKeyboardRepeatRate(aRate);
       
   597 		}
       
   598     }
       
   599 
       
   600 void CAknSgcClient::RelinquishPriorityToForegroundAppLC(TBool aIsForeground)
       
   601 	{
       
   602 	CAknSgcClient* self = Static();
       
   603 	if (self)
       
   604 		self->DoRelinquishPriorityToForegroundAppLC(aIsForeground);
       
   605 	}
       
   606 
       
   607 void RestorePriority(TAny* aPriority)
       
   608     {
       
   609     if (!aPriority)
       
   610         return;
       
   611 	RThread myThread;
       
   612 	TProcessPriority priority = *(TProcessPriority*)&aPriority;
       
   613 	myThread.SetProcessPriority(priority);
       
   614     }
       
   615 
       
   616 void CAknSgcClient::DoRelinquishPriorityToForegroundAppLC(TBool aIsForeground)
       
   617 	{
       
   618 	RThread myThread;
       
   619 	TProcessPriority priority = myThread.ProcessPriority();
       
   620 
       
   621 	if( IsSystemFaded() )
       
   622 		{
       
   623 		// Solution for EKKG-7RQ9U8:
       
   624 		// If the system is faded we have a popup on screen.
       
   625 		// Get the process behind the foreground process. 
       
   626 		TApaTask task = TApaTaskList(iEikonEnv->WsSession()).FindByPos(1);
       
   627 
       
   628 		// Check if this application is next behind the foreground app.
       
   629 		if( task.Exists() && myThread.Id() == task.ThreadId())
       
   630 			{
       
   631 			// Act as if we were foreground because some portion of the app might be visible.
       
   632 			// The actual foreground application might only be displaying the popup and therefore
       
   633 			// would not update the entire screen. 	
       
   634 			aIsForeground = ETrue;
       
   635 			}
       
   636 		}
       
   637 
       
   638 	if (!aIsForeground && priority > EPriorityBackground && !iFlags[ENeverRelinquish] )
       
   639 	    {
       
   640 	    // App is not visible, but has priority higher than background
       
   641 	    // Temporarily move it to background priority
       
   642         CleanupStack::PushL(TCleanupItem(RestorePriority, (TAny*)priority));
       
   643         iAknSrv.RelinquishPriorityToForegroundApp();
       
   644 	    }
       
   645 	else if (aIsForeground && priority < EPriorityForeground)
       
   646 	    {
       
   647 	    // App is visible, but has priority lower than foreground
       
   648 	    // Temporarily move it to foreground priority
       
   649         CleanupStack::PushL(TCleanupItem(RestorePriority, (TAny*)priority));
       
   650         myThread.SetProcessPriority(EPriorityForeground);
       
   651 	    }
       
   652 	else
       
   653 	    {
       
   654 	    // App has correct priority
       
   655 	    // push a dummy cleanup item onto the cleanup stack
       
   656         CleanupStack::PushL(TCleanupItem(RestorePriority, NULL));
       
   657 	    }
       
   658 	}
       
   659 
       
   660 EXPORT_C CAknLayoutConfig& CAknSgcClient::LayoutConfig()
       
   661 	{
       
   662 	CAknSgcClient* self = Static();
       
   663 	__ASSERT_ALWAYS(self && self->iLayoutConfig, Panic(EAknPanicSgccLayoutConfigNull));
       
   664 	return *self->iLayoutConfig;
       
   665 	}
       
   666 
       
   667 EXPORT_C const TDesC8& CAknSgcClient::LayoutConfigBuf()
       
   668 	{
       
   669 	CAknSgcClient* self = Static();
       
   670 	if (!self)
       
   671 		return KNullDesC8;
       
   672 	else
       
   673 		return self->DoLayoutConfigBuf();
       
   674 	}
       
   675 
       
   676 const TDesC8& CAknSgcClient::DoLayoutConfigBuf()
       
   677 	{
       
   678 	return KNullDesC8;
       
   679 	}
       
   680 
       
   681 void CAknSgcClient::StartupBlankL()
       
   682 	{
       
   683 	// Only use blanker when this app is focused, ie foreground
       
   684 	if (iEikonEnv->WsSession().GetFocusWindowGroup() == iEikonEnv->RootWin().Identifier())
       
   685 		{
       
   686 	    iStartupBlank = CIdle::New(KStartupUnblankPriority);
       
   687 	    iStartupBlank->Start(TCallBack(StartupUnblank, this));
       
   688 		User::LeaveIfError(iAknSrv.BlankScreen());
       
   689 		}
       
   690 	}
       
   691 
       
   692 TInt CAknSgcClient::StartupUnblank(TAny* aThis)
       
   693 	{
       
   694 	((CAknSgcClient*)aThis)->DoStartupUnblank();
       
   695 	return 0;
       
   696 	}
       
   697 
       
   698 void CAknSgcClient::DoStartupUnblank()
       
   699 	{
       
   700     if (iStartupBlank)
       
   701     	{
       
   702 		iAknSrv.UnblankScreen();
       
   703 		delete iStartupBlank;
       
   704 		iStartupBlank = NULL;
       
   705     	}
       
   706 	}
       
   707 
       
   708 EXPORT_C void CAknSgcClient::MoveApp(TInt aAppWindowGroupId, TSgcMoveAppToWhere aWhere)
       
   709 	{
       
   710 	CAknSgcClient* self = Static();
       
   711 	if (self && self->iImpl)
       
   712 		self->iImpl->MoveApp(aAppWindowGroupId, aWhere);
       
   713 	}
       
   714 
       
   715 EXPORT_C void CAknSgcClient::SetImpl(CAknSgcImpl* aImpl)
       
   716 	{
       
   717 	CAknSgcClient* self = Static();
       
   718 	if (self)
       
   719 		{
       
   720 		delete self->iImpl;
       
   721 		self->iImpl = aImpl;
       
   722 		}
       
   723 	}
       
   724 
       
   725 //
       
   726 // CAknSgcClientServerInst
       
   727 //
       
   728 CAknSgcClientServerInst::CAknSgcClientServerInst()
       
   729 	{
       
   730 	iFlags.Set(EInAknSrv);
       
   731 	iFlags.Set(ENeverRelinquish);
       
   732 	}
       
   733 
       
   734 CAknSgcClientServerInst::~CAknSgcClientServerInst()
       
   735 	{
       
   736 	delete iPackedLayoutConfigBuf;
       
   737 	}
       
   738 
       
   739 const TDesC8& CAknSgcClientServerInst::DoLayoutConfigBuf()
       
   740 	{
       
   741 	return *iPackedLayoutConfigBuf;
       
   742 	}
       
   743 
       
   744 void CAknSgcClientServerInst::ConstructL()
       
   745 	{
       
   746 	BaseConstructL();
       
   747 	
       
   748 	iPackedLayoutConfigBuf = iLayoutConfig->CreatePackedBufL();
       
   749 	iLayoutConfig->ConstructL(iPackedLayoutConfigBuf->AllocL());
       
   750 	}
       
   751 
       
   752 
       
   753 //
       
   754 // CAknSgcClientImpl
       
   755 //
       
   756 CAknSgcClientImpl::CAknSgcClientImpl(RAknUiServer& aAknSrv)
       
   757 : iAknSrv(aAknSrv)
       
   758 	{
       
   759 	}
       
   760 	
       
   761 void CAknSgcClientImpl::MoveApp(TInt aAppWindowGroupId, TSgcMoveAppToWhere aWhere)
       
   762 	{
       
   763 	iAknSrv.MoveAppInZOrder(aAppWindowGroupId, aWhere);
       
   764 	}
       
   765 
       
   766 
       
   767 // End of File