tsrc/xmltestharness/xmlclient/src/windowmanager.cpp
changeset 0 0e4a32b9112d
equal deleted inserted replaced
-1:000000000000 0:0e4a32b9112d
       
     1 /*
       
     2 * Copyright (c) 2008 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 
       
    19 /**
       
    20 @file
       
    21 @internalComponent
       
    22 */
       
    23 
       
    24 #include "windowmanager.h"
       
    25 
       
    26 CWindowManager* CWindowManager::NewL()
       
    27 	{
       
    28 	CWindowManager* self = new(ELeave) CWindowManager();
       
    29 	CleanupStack::PushL(self);
       
    30 	self->ConstructL();
       
    31 	CleanupStack::Pop(self);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 CWindowManager::CWindowManager():
       
    36 CActive(EPriorityStandard)
       
    37 	{
       
    38 	CActiveScheduler::Add(this);
       
    39 	}
       
    40 
       
    41 void CWindowManager::ConstructL()
       
    42 	{
       
    43 	User::LeaveIfError(iMsgQueue.CreateLocal(1));
       
    44 	User::LeaveIfError(iSemaphore.CreateLocal(0));
       
    45 	
       
    46 	User::LeaveIfError(iWsSession.Connect());
       
    47 	// Create the Screen device for the WServ session.
       
    48 	iWsSd = new (ELeave) CWsScreenDevice(iWsSession);
       
    49 	User::LeaveIfError(iWsSd->Construct());
       
    50 	// Create a Window Group.
       
    51 	iWindowGroup = RWindowGroup(iWsSession);
       
    52 	User::LeaveIfError(iWindowGroup.Construct((TUint32)this, ETrue));
       
    53 	iWindow = new (ELeave) RWindow(iWsSession);
       
    54 	User::LeaveIfError(iWindow->Construct(iWindowGroup, ((TUint32)(this)) + 1));
       
    55 
       
    56 	// Reset the screen mode.
       
    57 	if(iWsSd->CurrentScreenMode() != 0)
       
    58 		{
       
    59 		iWsSd->SetAppScreenMode(0);
       
    60 		iWsSd->SetScreenMode(0);
       
    61 		}
       
    62 	
       
    63 	iScreenSize = iWsSd->SizeInPixels();
       
    64 	iWindow->SetExtent(TPoint(0,0), iScreenSize);
       
    65 	iWindow->SetVisible(ETrue);
       
    66 	iWindow->Activate();
       
    67 
       
    68 	User::LeaveIfError(iWindow->SetRequiredDisplayMode(EColor16MA));
       
    69 
       
    70 	// TODO - this forcing of transparency may not be needed, as there is 
       
    71 	//		a defect in the graphics component right now
       
    72 	// force the transparency change to take place
       
    73 	iWindow->SetBackgroundColor(TRgb(0x000000, 0)); 
       
    74 	iWindow->BeginRedraw();
       
    75 	iWindow->EndRedraw();	
       
    76 	iWsSession.Flush();
       
    77 	
       
    78 	iCreatorThreadId = RThread().Id();
       
    79 	
       
    80 	SetActive();
       
    81 	iMsgQueue.NotifyDataAvailable(iStatus);
       
    82 	}
       
    83 
       
    84 CWindowManager::~CWindowManager()
       
    85 	{
       
    86 	Cancel();
       
    87 	if(iWindow)
       
    88 		{
       
    89 		iWindow->Close();
       
    90 		delete iWindow;
       
    91 		}
       
    92 	iWindowGroup.Close();
       
    93 	delete iWsSd;
       
    94 	iWsSession.Close();
       
    95 	
       
    96 	iSemaphore.Close();
       
    97 	iMsgQueue.Close();
       
    98 	}
       
    99 
       
   100 void CWindowManager::RunL()
       
   101 	{
       
   102 	TMessage msg;
       
   103 	TInt err = iMsgQueue.Receive(msg);
       
   104 	if(err != KErrNone && err != KErrUnderflow)
       
   105 		{
       
   106 		iReturnCode = err;
       
   107 		}
       
   108 	else
       
   109 		{
       
   110 		iReturnCode = DoCommand(msg.iCommand, msg.iParam1, msg.iParam2);
       
   111 		}
       
   112 	SetActive();
       
   113 	iMsgQueue.NotifyDataAvailable(iStatus);
       
   114 	iSemaphore.Signal();
       
   115 	}
       
   116 
       
   117 void CWindowManager::DoCancel()
       
   118 	{
       
   119 	iMsgQueue.CancelDataAvailable();
       
   120 	}
       
   121 
       
   122 TInt CWindowManager::RegisterSurface(TSurfaceId& aSurfaceId)
       
   123 	{
       
   124 	return RunCommand(ERegisterSurface, &aSurfaceId);
       
   125 	}
       
   126 
       
   127 TInt CWindowManager::SetBackgroundSurface(TSurfaceConfiguration& aSurfaceConfig, TBool aTriggerRedraw)
       
   128 	{
       
   129 	return RunCommand(ESetBackgroundSurface, &aSurfaceConfig, aTriggerRedraw);
       
   130 	}
       
   131 	
       
   132 TInt CWindowManager::RunCommand(TCommand aCommand, TAny* aParam1, TInt aParam2)
       
   133 	{
       
   134 	if(RThread().Id() == iCreatorThreadId)
       
   135 		{
       
   136 		return DoCommand(aCommand, aParam1, aParam2);
       
   137 		}
       
   138 	else
       
   139 		{
       
   140 		TMessage msg;
       
   141 		msg.iCommand = aCommand;
       
   142 		msg.iParam1 = aParam1;
       
   143 		msg.iParam2 = aParam2;
       
   144 		iMsgQueue.SendBlocking(msg);
       
   145 		iSemaphore.Wait();
       
   146 		return iReturnCode;
       
   147 		}
       
   148 	}
       
   149 
       
   150 TInt CWindowManager::DoCommand(TCommand aCommand, TAny* aParam1, TInt aParam2)
       
   151 	{
       
   152 	switch(aCommand)
       
   153 		{
       
   154 	case ERegisterSurface:
       
   155 		{
       
   156 		TSurfaceId& surfaceId = *reinterpret_cast<TSurfaceId*>(aParam1);
       
   157 		return iWsSession.RegisterSurface(iWsSd->GetScreenNumber(), surfaceId);
       
   158 		}
       
   159 	case ESetBackgroundSurface:
       
   160 		{
       
   161 		TSurfaceConfiguration& surfaceConfig = *reinterpret_cast<TSurfaceConfiguration*>(aParam1);
       
   162 		TBool triggerRedraw = aParam2;
       
   163 		return iWindow->SetBackgroundSurface(surfaceConfig, triggerRedraw);
       
   164 		}
       
   165 	default:
       
   166 		{
       
   167 		User::Invariant();
       
   168 		return KErrNone;
       
   169 		}
       
   170 		}
       
   171 	}
       
   172 
       
   173 TSize CWindowManager::ScreenSize() const
       
   174 	{
       
   175 	return iScreenSize;
       
   176 	}
       
   177 
       
   178 void CWindowManager::Flush()
       
   179 	{
       
   180 	iWsSession.Flush();
       
   181 	}