startupservices/SplashScreen/src/SplashScreen.cpp
branchRCL_3
changeset 70 739cef680932
parent 63 c2c61fdca848
child 82 4610cd70c542
equal deleted inserted replaced
66:9af619316cbf 70:739cef680932
     1 /*
     1 /*
     2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   198 
   198 
   199 /////////////////////////////////////////////////////////////////////////////////////
   199 /////////////////////////////////////////////////////////////////////////////////////
   200 /////////////////////////// CWsClient implementation ////////////////////////////////
   200 /////////////////////////// CWsClient implementation ////////////////////////////////
   201 /////////////////////////////////////////////////////////////////////////////////////
   201 /////////////////////////////////////////////////////////////////////////////////////
   202 CWsClient::CWsClient()
   202 CWsClient::CWsClient()
   203 : CActive(CActive::EPriorityStandard),
   203 : CActive(CActive::EPriorityStandard)
   204   iPSRemoveSplashState( ESplashRunning )
       
   205 	{
   204 	{
   206     TRACES("CWsClient::CWsClient()");
   205     TRACES("CWsClient::CWsClient()");
       
   206     CActiveScheduler::Add(this);    
   207 	}
   207 	}
   208 
   208 
   209 void CWsClient::ConstructL()
   209 void CWsClient::ConstructL()
   210 	{
   210 	{
   211     TRACES("CWsClient::ConstructL(): Start");
   211     TRACES("CWsClient::ConstructL(): Start");
   212 
       
   213     RProperty::Define(KPSUidStartup,
       
   214                       KPSSplashShutdown,
       
   215                       RProperty::EInt,
       
   216                       KReadPolicy,
       
   217                       KWritePolicy );
       
   218     RProperty::Set( KPSUidStartup, KPSSplashShutdown, iPSRemoveSplashState );
       
   219 	CActiveScheduler::Install(new (ELeave) CActiveScheduler);
       
   220 	CActiveScheduler::Add(this);
       
   221     iProperty.Attach( KPSUidStartup, KPSSplashShutdown );
       
   222     iProperty.Subscribe( iStatus );
       
   223 
   212 
   224 	// get a session going
   213 	// get a session going
   225 	User::LeaveIfError(iWs.Connect());
   214 	User::LeaveIfError(iWs.Connect());
   226 
   215 
   227 	// construct screen device and graphics context
   216 	// construct screen device and graphics context
   250     iWs.EventReady(&iStatus); // request an event
   239     iWs.EventReady(&iStatus); // request an event
   251 	SetActive(); // so we're now active
   240 	SetActive(); // so we're now active
   252 	// request first event and start scheduler
   241 	// request first event and start scheduler
   253 
   242 
   254     TRACES("CWsClient::ConstructL(): About to start CActiveScheduler");
   243     TRACES("CWsClient::ConstructL(): About to start CActiveScheduler");
   255 
       
   256 	CActiveScheduler::Start(); // start the active scheduler
       
   257 
   244 
   258     TRACES("CWsClient::CWsClient(): End");
   245     TRACES("CWsClient::CWsClient(): End");
   259 	}
   246 	}
   260 
   247 
   261 CWsClient::~CWsClient()
   248 CWsClient::~CWsClient()
   272 	delete iRedrawer;
   259 	delete iRedrawer;
   273 	// destroy window group
   260 	// destroy window group
   274 	iGroup.Close();
   261 	iGroup.Close();
   275 	// finish with window server
   262 	// finish with window server
   276     Cancel();
   263     Cancel();
   277     iProperty.Close();
       
   278 	iWs.Close();
   264 	iWs.Close();
   279     TRACES("CWsClient::~CWsClient(): End");
   265     TRACES("CWsClient::~CWsClient(): End");
   280 	}
   266 	}
   281 
   267 
   282 void CWsClient::Exit()
   268 void CWsClient::Exit()
   431 //	TPoint point = aPointerEvent.iPosition;
   417 //	TPoint point = aPointerEvent.iPosition;
   432 //	(void)point;
   418 //	(void)point;
   433     TRACES("CMainWindow::HandlePointerEvent(): End");
   419     TRACES("CMainWindow::HandlePointerEvent(): End");
   434 	}
   420 	}
   435 
   421 
       
   422 
       
   423 
       
   424 
       
   425 /////////////////////////////////////////////////////////////////////////////////////
       
   426 /////////////////////////// CSplashShutdownWatcher implementation ///////////////////
       
   427 /////////////////////////////////////////////////////////////////////////////////////
       
   428 
       
   429 CSplashShutdownWatcher* CSplashShutdownWatcher::NewL()
       
   430     {
       
   431     CSplashShutdownWatcher* self = new(ELeave)CSplashShutdownWatcher();
       
   432     CleanupStack::PushL(self);
       
   433     self->ConstructL();
       
   434     CleanupStack::Pop(self);
       
   435     return self;
       
   436     }
       
   437 
       
   438 void CSplashShutdownWatcher::ConstructL()
       
   439     {
       
   440     TRACES("CSplashShutdownWatcher::ConstructL(): Start");
       
   441     RProperty::Define(KPSUidStartup,
       
   442                       KPSSplashShutdown,
       
   443                       RProperty::EInt,
       
   444                       KReadPolicy,
       
   445                       KWritePolicy );
       
   446     RProperty::Set( KPSUidStartup, KPSSplashShutdown, iPSRemoveSplashState );
       
   447     iProperty.Attach( KPSUidStartup, KPSSplashShutdown );
       
   448     CActiveScheduler::Add(this);
       
   449     IssueRequest();
       
   450     TRACES("CSplashShutdownWatcher::ConstructL(): End");
       
   451     }
       
   452 
       
   453 CSplashShutdownWatcher::CSplashShutdownWatcher():CActive(CActive::EPriorityStandard),iPSRemoveSplashState( ESplashRunning ){}
       
   454 
       
   455 CSplashShutdownWatcher::~CSplashShutdownWatcher()
       
   456     {
       
   457     TRACES("~CSplashShutdownWatcher: Start");
       
   458     Cancel();
       
   459     iProperty.Close();
       
   460     TRACES("~CSplashShutdownWatcher: End");
       
   461     }
       
   462 
       
   463 void CSplashShutdownWatcher::IssueRequest()
       
   464     {
       
   465     iProperty.Subscribe( iStatus );
       
   466     SetActive();
       
   467     }
       
   468 
       
   469 void CSplashShutdownWatcher::DoCancel()
       
   470     {
       
   471     iProperty.Cancel();
       
   472     }
       
   473 
       
   474 void CSplashShutdownWatcher::RunL()
       
   475     {
       
   476     TRACES("CSplashShutdownWatcher::RunL(): Start");
       
   477     TInt state;
       
   478     RProperty::Get( KPSUidStartup, KPSSplashShutdown, state );
       
   479     TRACES1("CSplashShutdownWatcher::RunL(): Property change event received,Splash Shutdown state = %d", state);
       
   480 
       
   481     if ( state == ESplashShutdown )
       
   482             {
       
   483             TRACES("CSplashShutdownWatcher::RunL(): Exit requested");
       
   484             CActiveScheduler::Stop();
       
   485             }
       
   486         else
       
   487             {
       
   488             TRACES("CSplashShutdownWatcher::RunL(): UNEXPECTED state change event received!!, Issue request again");
       
   489             IssueRequest();            
       
   490             }
       
   491     TRACES("CSplashShutdownWatcher::RunL(): End");    
       
   492     }
       
   493 
       
   494 
   436 //////////////////////////////////////////////////////////////////////////////
   495 //////////////////////////////////////////////////////////////////////////////
   437 //					 CSplashWsClient implementation						//
   496 //					 CSplashWsClient implementation						//
   438 //////////////////////////////////////////////////////////////////////////////
   497 //////////////////////////////////////////////////////////////////////////////
   439 
   498 
   440 /****************************************************************************\
   499 /****************************************************************************\
   507 \****************************************************************************/
   566 \****************************************************************************/
   508 void CSplashWsClient::RunL()
   567 void CSplashWsClient::RunL()
   509 	{
   568 	{
   510     TRACES("CSplashWsClient::RunL(): Start");
   569     TRACES("CSplashWsClient::RunL(): Start");
   511 
   570 
   512     TInt state;
   571     TRACES("CSplashWsClient::RunL(): WS event");
   513     RProperty::Get( KPSUidStartup, KPSSplashShutdown, state );
   572 
   514     TRACES1("CSplashWsClient::RunL(): KPSSplashShutdown state = %d", state);
   573     // get the event
   515 
   574     iWs.GetEvent(iWsEvent);
   516     if ( state != iPSRemoveSplashState )
   575     const TInt eventType = iWsEvent.Type();
   517         {
   576 
   518         TRACES("CSplashWsClient::RunL(): KPSSplashShutdown state has changed -> PS event");
   577     // take action on it
   519         if ( state == ESplashShutdown )
   578     switch (eventType)
       
   579         {
       
   580         // window-group related event types
       
   581         case EEventKey:
   520             {
   582             {
   521             TRACES("CSplashWsClient::RunL(): Exit requested");
   583             TRACES("CSplashWsClient::RunL(): EEventKey");
   522             Exit();
   584             TKeyEvent& keyEvent=*iWsEvent.Key(); // get key event
       
   585             HandleKeyEventL (keyEvent);
       
   586             break;
   523             }
   587             }
   524         }
   588         // window related events
   525     else
   589         case EEventPointer:
   526         {
   590             {
   527         TRACES("CSplashWsClient::RunL(): WS event");
   591             TRACES("CSplashWsClient::RunL(): EEventPointer");
   528 
   592             CWindow* window=(CWindow*)(iWsEvent.Handle()); // get window
   529         // get the event
   593             TPointerEvent& pointerEvent=*iWsEvent.Pointer();
   530 	    iWs.GetEvent(iWsEvent);
   594             window->HandlePointerEvent (pointerEvent);
   531 	    const TInt eventType = iWsEvent.Type();
   595             break;
   532 
   596             }
   533         // take action on it
   597         case EEventScreenDeviceChanged:
   534 	    switch (eventType)
   598             {
   535 		    {
   599             const TInt currentScreenMode = iScreen->CurrentScreenMode();
   536     		// window-group related event types
   600             TRACES2("CSplashWsClient::RunL() - EEventScreenDeviceChanged - iLastScreenMode: %d, currentScreenMode: %d", iLastScreenMode, currentScreenMode);
   537     		case EEventKey:
   601             if  ( iLastScreenMode != currentScreenMode )
   538 	    		{
       
   539                 TRACES("CSplashWsClient::RunL(): EEventKey");
       
   540 			    TKeyEvent& keyEvent=*iWsEvent.Key(); // get key event
       
   541     			HandleKeyEventL (keyEvent);
       
   542 	            break;
       
   543     			}
       
   544             // window related events
       
   545     		case EEventPointer:
       
   546 	    		{
       
   547                 TRACES("CSplashWsClient::RunL(): EEventPointer");
       
   548 			    CWindow* window=(CWindow*)(iWsEvent.Handle()); // get window
       
   549 			    TPointerEvent& pointerEvent=*iWsEvent.Pointer();
       
   550 			    window->HandlePointerEvent (pointerEvent);
       
   551     			break;
       
   552 	    		}
       
   553             case EEventScreenDeviceChanged:
       
   554                 {
   602                 {
   555                 const TInt currentScreenMode = iScreen->CurrentScreenMode();
   603                 RDebug::Printf("[SS] CSplashWsClient::RunL() - EEventScreenDeviceChanged - real screen mode change detected!!!!");
   556                 TRACES2("CSplashWsClient::RunL() - EEventScreenDeviceChanged - iLastScreenMode: %d, currentScreenMode: %d", iLastScreenMode, currentScreenMode);
   604                 iScreen->SetAppScreenMode( currentScreenMode );
   557                 if  ( iLastScreenMode != currentScreenMode )
   605                 TPixelsTwipsAndRotation currentRot;
   558                     {
   606                 iScreen->GetScreenModeSizeAndRotation( currentScreenMode, currentRot );
   559                     RDebug::Printf("[SS] CSplashWsClient::RunL() - EEventScreenDeviceChanged - real screen mode change detected!!!!");
   607                 iMainWindow->Window().SetExtent( TPoint(0, 0), currentRot.iPixelSize );
   560                     iScreen->SetAppScreenMode( currentScreenMode );
   608                 iMainWindow->Client()->Group().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront + 10000);	// in front of the Status Bar
   561                     TPixelsTwipsAndRotation currentRot;
   609                 iMainWindow->Window().Invalidate();
   562                     iScreen->GetScreenModeSizeAndRotation( currentScreenMode, currentRot );
   610 
   563                     iMainWindow->Window().SetExtent( TPoint(0, 0), currentRot.iPixelSize );
   611                 iLastScreenMode = currentScreenMode;
   564 	                iMainWindow->Client()->Group().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront + 10000);	// in front of the Status Bar
       
   565                     iMainWindow->Window().Invalidate();
       
   566 
       
   567                     iLastScreenMode = currentScreenMode;
       
   568                     }
       
   569                 TRACES("CSplashWsClient::RunL() - EEventScreenDeviceChanged - done");
       
   570                 }
   612                 }
   571                 break;
   613             TRACES("CSplashWsClient::RunL() - EEventScreenDeviceChanged - done");
   572 		    default:
   614             }
   573                 TRACES("CSplashWsClient::RunL(): default");
   615             break;
   574     			break;
   616         default:
   575 	        }
   617             TRACES("CSplashWsClient::RunL(): default");
   576         IssueRequest(); // maintain outstanding request
   618             break;
   577         }
   619         }
       
   620     IssueRequest(); // maintain outstanding request
       
   621 
   578     TRACES("CSplashWsClient::RunL(): End");
   622     TRACES("CSplashWsClient::RunL(): End");
   579 	}
   623 	}
   580 
   624 
   581 
   625 
   582 /****************************************************************************\
   626 /****************************************************************************\
   600 LOCAL_C void DoItL()
   644 LOCAL_C void DoItL()
   601 	{
   645 	{
   602 	// make new client
   646 	// make new client
   603     TRACES("DoItL(): Start");
   647     TRACES("DoItL(): Start");
   604 
   648 
       
   649     CActiveScheduler::Install(new (ELeave) CActiveScheduler);    
   605 	CSplashWsClient* client=new (ELeave) CSplashWsClient; // allocate new client
   650 	CSplashWsClient* client=new (ELeave) CSplashWsClient; // allocate new client
   606 	CleanupStack::PushL(client); // push, just in case
   651 	CleanupStack::PushL(client); // push, just in case
   607 	client->ConstructL(); // construct and run
   652 	client->ConstructL(); // construct and run
   608 	CleanupStack::PopAndDestroy(); // destruct
   653 	CSplashShutdownWatcher *shutdownWatcher=CSplashShutdownWatcher::NewL();
   609 
   654 	CleanupStack::PushL(shutdownWatcher);
       
   655     CActiveScheduler::Start(); // start the active scheduler	
       
   656 	CleanupStack::PopAndDestroy(2, client); // destruct
   610     TRACES("DoItL(): End");
   657     TRACES("DoItL(): End");
   611 	}
   658 	}
   612 
   659