startupservices/SplashScreen/src/SplashScreen.cpp
branchRCL_3
changeset 82 4610cd70c542
parent 70 739cef680932
child 83 20e07ff6040b
equal deleted inserted replaced
70:739cef680932 82:4610cd70c542
     1 /*
     1 /*
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2002-2008 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 )
   204 	{
   205 	{
   205     TRACES("CWsClient::CWsClient()");
   206     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 );
   212 
   223 
   213 	// get a session going
   224 	// get a session going
   214 	User::LeaveIfError(iWs.Connect());
   225 	User::LeaveIfError(iWs.Connect());
   215 
   226 
   216 	// construct screen device and graphics context
   227 	// construct screen device and graphics context
   239     iWs.EventReady(&iStatus); // request an event
   250     iWs.EventReady(&iStatus); // request an event
   240 	SetActive(); // so we're now active
   251 	SetActive(); // so we're now active
   241 	// request first event and start scheduler
   252 	// request first event and start scheduler
   242 
   253 
   243     TRACES("CWsClient::ConstructL(): About to start CActiveScheduler");
   254     TRACES("CWsClient::ConstructL(): About to start CActiveScheduler");
       
   255 
       
   256 	CActiveScheduler::Start(); // start the active scheduler
   244 
   257 
   245     TRACES("CWsClient::CWsClient(): End");
   258     TRACES("CWsClient::CWsClient(): End");
   246 	}
   259 	}
   247 
   260 
   248 CWsClient::~CWsClient()
   261 CWsClient::~CWsClient()
   259 	delete iRedrawer;
   272 	delete iRedrawer;
   260 	// destroy window group
   273 	// destroy window group
   261 	iGroup.Close();
   274 	iGroup.Close();
   262 	// finish with window server
   275 	// finish with window server
   263     Cancel();
   276     Cancel();
       
   277     iProperty.Close();
   264 	iWs.Close();
   278 	iWs.Close();
   265     TRACES("CWsClient::~CWsClient(): End");
   279     TRACES("CWsClient::~CWsClient(): End");
   266 	}
   280 	}
   267 
   281 
   268 void CWsClient::Exit()
   282 void CWsClient::Exit()
   417 //	TPoint point = aPointerEvent.iPosition;
   431 //	TPoint point = aPointerEvent.iPosition;
   418 //	(void)point;
   432 //	(void)point;
   419     TRACES("CMainWindow::HandlePointerEvent(): End");
   433     TRACES("CMainWindow::HandlePointerEvent(): End");
   420 	}
   434 	}
   421 
   435 
   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 
       
   495 //////////////////////////////////////////////////////////////////////////////
   436 //////////////////////////////////////////////////////////////////////////////
   496 //					 CSplashWsClient implementation						//
   437 //					 CSplashWsClient implementation						//
   497 //////////////////////////////////////////////////////////////////////////////
   438 //////////////////////////////////////////////////////////////////////////////
   498 
   439 
   499 /****************************************************************************\
   440 /****************************************************************************\
   566 \****************************************************************************/
   507 \****************************************************************************/
   567 void CSplashWsClient::RunL()
   508 void CSplashWsClient::RunL()
   568 	{
   509 	{
   569     TRACES("CSplashWsClient::RunL(): Start");
   510     TRACES("CSplashWsClient::RunL(): Start");
   570 
   511 
   571     TRACES("CSplashWsClient::RunL(): WS event");
   512     TInt state;
   572 
   513     RProperty::Get( KPSUidStartup, KPSSplashShutdown, state );
   573     // get the event
   514     TRACES1("CSplashWsClient::RunL(): KPSSplashShutdown state = %d", state);
   574     iWs.GetEvent(iWsEvent);
   515 
   575     const TInt eventType = iWsEvent.Type();
   516     if ( state != iPSRemoveSplashState )
   576 
   517         {
   577     // take action on it
   518         TRACES("CSplashWsClient::RunL(): KPSSplashShutdown state has changed -> PS event");
   578     switch (eventType)
   519         if ( state == ESplashShutdown )
   579         {
       
   580         // window-group related event types
       
   581         case EEventKey:
       
   582             {
   520             {
   583             TRACES("CSplashWsClient::RunL(): EEventKey");
   521             TRACES("CSplashWsClient::RunL(): Exit requested");
   584             TKeyEvent& keyEvent=*iWsEvent.Key(); // get key event
   522             Exit();
   585             HandleKeyEventL (keyEvent);
       
   586             break;
       
   587             }
   523             }
   588         // window related events
   524         }
   589         case EEventPointer:
   525     else
   590             {
   526         {
   591             TRACES("CSplashWsClient::RunL(): EEventPointer");
   527         TRACES("CSplashWsClient::RunL(): WS event");
   592             CWindow* window=(CWindow*)(iWsEvent.Handle()); // get window
   528 
   593             TPointerEvent& pointerEvent=*iWsEvent.Pointer();
   529         // get the event
   594             window->HandlePointerEvent (pointerEvent);
   530 	    iWs.GetEvent(iWsEvent);
   595             break;
   531 	    const TInt eventType = iWsEvent.Type();
   596             }
   532 
   597         case EEventScreenDeviceChanged:
   533         // take action on it
   598             {
   534 	    switch (eventType)
   599             const TInt currentScreenMode = iScreen->CurrentScreenMode();
   535 		    {
   600             TRACES2("CSplashWsClient::RunL() - EEventScreenDeviceChanged - iLastScreenMode: %d, currentScreenMode: %d", iLastScreenMode, currentScreenMode);
   536     		// window-group related event types
   601             if  ( iLastScreenMode != currentScreenMode )
   537     		case EEventKey:
       
   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:
   602                 {
   554                 {
   603                 RDebug::Printf("[SS] CSplashWsClient::RunL() - EEventScreenDeviceChanged - real screen mode change detected!!!!");
   555                 const TInt currentScreenMode = iScreen->CurrentScreenMode();
   604                 iScreen->SetAppScreenMode( currentScreenMode );
   556                 TRACES2("CSplashWsClient::RunL() - EEventScreenDeviceChanged - iLastScreenMode: %d, currentScreenMode: %d", iLastScreenMode, currentScreenMode);
   605                 TPixelsTwipsAndRotation currentRot;
   557                 if  ( iLastScreenMode != currentScreenMode )
   606                 iScreen->GetScreenModeSizeAndRotation( currentScreenMode, currentRot );
   558                     {
   607                 iMainWindow->Window().SetExtent( TPoint(0, 0), currentRot.iPixelSize );
   559                     RDebug::Printf("[SS] CSplashWsClient::RunL() - EEventScreenDeviceChanged - real screen mode change detected!!!!");
   608                 iMainWindow->Client()->Group().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront + 10000);	// in front of the Status Bar
   560                     iScreen->SetAppScreenMode( currentScreenMode );
   609                 iMainWindow->Window().Invalidate();
   561                     TPixelsTwipsAndRotation currentRot;
   610 
   562                     iScreen->GetScreenModeSizeAndRotation( currentScreenMode, currentRot );
   611                 iLastScreenMode = currentScreenMode;
   563                     iMainWindow->Window().SetExtent( TPoint(0, 0), currentRot.iPixelSize );
       
   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");
   612                 }
   570                 }
   613             TRACES("CSplashWsClient::RunL() - EEventScreenDeviceChanged - done");
   571                 break;
   614             }
   572 		    default:
   615             break;
   573                 TRACES("CSplashWsClient::RunL(): default");
   616         default:
   574     			break;
   617             TRACES("CSplashWsClient::RunL(): default");
   575 	        }
   618             break;
   576         IssueRequest(); // maintain outstanding request
   619         }
   577         }
   620     IssueRequest(); // maintain outstanding request
       
   621 
       
   622     TRACES("CSplashWsClient::RunL(): End");
   578     TRACES("CSplashWsClient::RunL(): End");
   623 	}
   579 	}
   624 
   580 
   625 
   581 
   626 /****************************************************************************\
   582 /****************************************************************************\
   644 LOCAL_C void DoItL()
   600 LOCAL_C void DoItL()
   645 	{
   601 	{
   646 	// make new client
   602 	// make new client
   647     TRACES("DoItL(): Start");
   603     TRACES("DoItL(): Start");
   648 
   604 
   649     CActiveScheduler::Install(new (ELeave) CActiveScheduler);    
       
   650 	CSplashWsClient* client=new (ELeave) CSplashWsClient; // allocate new client
   605 	CSplashWsClient* client=new (ELeave) CSplashWsClient; // allocate new client
   651 	CleanupStack::PushL(client); // push, just in case
   606 	CleanupStack::PushL(client); // push, just in case
   652 	client->ConstructL(); // construct and run
   607 	client->ConstructL(); // construct and run
   653 	CSplashShutdownWatcher *shutdownWatcher=CSplashShutdownWatcher::NewL();
   608 	CleanupStack::PopAndDestroy(); // destruct
   654 	CleanupStack::PushL(shutdownWatcher);
   609 
   655     CActiveScheduler::Start(); // start the active scheduler	
       
   656 	CleanupStack::PopAndDestroy(2, client); // destruct
       
   657     TRACES("DoItL(): End");
   610     TRACES("DoItL(): End");
   658 	}
   611 	}
   659 
   612