os/graphics/windowing/windowserver/test/tcrx/tcrx.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Internal Symbian test code
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include <gdi.h>
sl@0
    23
#include "tcrx.h"
sl@0
    24
#include "wsredir.h"
sl@0
    25
#include "wslisten.h"
sl@0
    26
sl@0
    27
static TRedirectorInfo TheInfo;
sl@0
    28
sl@0
    29
class CTwoWindow: public CBase
sl@0
    30
	{
sl@0
    31
public:
sl@0
    32
	static CTwoWindow* NewL();
sl@0
    33
	~CTwoWindow();
sl@0
    34
private:
sl@0
    35
	void ConstructL();
sl@0
    36
private:
sl@0
    37
	RWsSession iWs;
sl@0
    38
	CWsScreenDevice* iScr;
sl@0
    39
	CWindowGc* iGc;
sl@0
    40
	RWindowGroup iGroup;
sl@0
    41
	RWindow iBg;
sl@0
    42
	RWindow iFg;
sl@0
    43
	};
sl@0
    44
sl@0
    45
CTwoWindow* CTwoWindow::NewL()
sl@0
    46
	{
sl@0
    47
	CTwoWindow* tw = new(ELeave) CTwoWindow;
sl@0
    48
	CleanupStack::PushL(tw);
sl@0
    49
	tw->ConstructL();
sl@0
    50
	CleanupStack::Pop(tw);
sl@0
    51
	return tw;
sl@0
    52
	}
sl@0
    53
sl@0
    54
CTwoWindow::~CTwoWindow()
sl@0
    55
	{
sl@0
    56
	iFg.Close();
sl@0
    57
	iBg.Close();
sl@0
    58
	iGroup.Close();
sl@0
    59
	delete iGc;
sl@0
    60
	delete iScr;
sl@0
    61
	iWs.Close();	
sl@0
    62
	}
sl@0
    63
sl@0
    64
void CTwoWindow::ConstructL()
sl@0
    65
	{
sl@0
    66
	User::LeaveIfError(iWs.Connect());
sl@0
    67
	iScr = new(ELeave) CWsScreenDevice(iWs);
sl@0
    68
	User::LeaveIfError(iScr->Construct());
sl@0
    69
	User::LeaveIfError(iScr->CreateContext(iGc));
sl@0
    70
	iGroup = RWindowGroup(iWs);
sl@0
    71
	User::LeaveIfError(iGroup.Construct(0xc0de,ETrue));
sl@0
    72
	
sl@0
    73
	iBg = RWindow(iWs);
sl@0
    74
	User::LeaveIfError(iBg.Construct(iGroup,0xc0debabe));
sl@0
    75
	iBg.SetRequiredDisplayMode(EColor64K);
sl@0
    76
	iBg.Activate();
sl@0
    77
	iWs.Flush();
sl@0
    78
sl@0
    79
	iBg.BeginRedraw();
sl@0
    80
	iGc->Activate(iBg);
sl@0
    81
	iGc->SetBrushColor(KRgbGreen);
sl@0
    82
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
    83
	TRect rect(iScr->SizeInPixels());
sl@0
    84
	iGc->DrawRect(rect);
sl@0
    85
	iGc->SetBrushColor(KRgbBlue);
sl@0
    86
	iGc->DrawEllipse(rect);
sl@0
    87
	iGc->Deactivate();
sl@0
    88
	iBg.EndRedraw();
sl@0
    89
	iWs.Flush();
sl@0
    90
	
sl@0
    91
	iFg = RWindow(iWs);
sl@0
    92
	User::LeaveIfError(iFg.Construct(iGroup,0xc0decafe));
sl@0
    93
	iFg.SetRequiredDisplayMode(EColor64K);
sl@0
    94
	iFg.SetTransparencyAlphaChannel();
sl@0
    95
	iFg.SetBackgroundColor(TRgb(0xff,0x55,0x55,0x80));
sl@0
    96
	iFg.Activate();
sl@0
    97
	iWs.Flush();
sl@0
    98
	}
sl@0
    99
sl@0
   100
CClient* CClient::NewL()
sl@0
   101
	{
sl@0
   102
	CClient* self = new(ELeave) CClient;
sl@0
   103
	CleanupStack::PushL(self);
sl@0
   104
	self->ConstructL();
sl@0
   105
	CleanupStack::Pop(self);
sl@0
   106
	
sl@0
   107
	return self;
sl@0
   108
	}
sl@0
   109
sl@0
   110
CClient::CClient(): CActive(CActive::EPriorityStandard)
sl@0
   111
	{
sl@0
   112
	}
sl@0
   113
sl@0
   114
void CClient::ConstructL()
sl@0
   115
	{
sl@0
   116
	CActiveScheduler::Add(this);
sl@0
   117
	User::LeaveIfError(iWs.Connect());
sl@0
   118
	iScreen = new(ELeave) CWsScreenDevice(iWs);
sl@0
   119
	User::LeaveIfError(iScreen->Construct(0));
sl@0
   120
	iGroup = RWindowGroup(iWs);
sl@0
   121
	User::LeaveIfError(iGroup.Construct(0xCAFE, ETrue));
sl@0
   122
	iGc = new(ELeave) CWindowGc(iScreen);
sl@0
   123
	User::LeaveIfError(iGc->Construct());
sl@0
   124
	iWin = new(ELeave) CWindow(this);
sl@0
   125
	iWin->ConstructL(NULL, EFalse);
sl@0
   126
	iRedraw = CRedrawHandler::NewL(this);
sl@0
   127
sl@0
   128
	iRedir = CWsRedir::NewL();
sl@0
   129
	iListen = CWsListen::NewL();
sl@0
   130
		
sl@0
   131
	MakeRequest();
sl@0
   132
	}
sl@0
   133
sl@0
   134
void CClient::HandleCommand(TInt aCmd)
sl@0
   135
	{
sl@0
   136
	switch (aCmd)
sl@0
   137
		{
sl@0
   138
		case 1:
sl@0
   139
		iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
sl@0
   140
		break;
sl@0
   141
sl@0
   142
		case 2:
sl@0
   143
		iRedir->Redirect(CWsRedir::EBackBuffer, ETrue);
sl@0
   144
		break;
sl@0
   145
sl@0
   146
		case 3:
sl@0
   147
		iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
sl@0
   148
		break;
sl@0
   149
sl@0
   150
		case 4:
sl@0
   151
		iRedir->Redirect(CWsRedir::EBackBuffer, EFalse);
sl@0
   152
		break;
sl@0
   153
sl@0
   154
		case 5:
sl@0
   155
		iListen->Enable(ETrue);
sl@0
   156
		break;
sl@0
   157
sl@0
   158
		case 6:
sl@0
   159
		iListen->Enable(EFalse);
sl@0
   160
		break;
sl@0
   161
sl@0
   162
		case 7:
sl@0
   163
		iRedir->QueryPlugin(TheInfo);
sl@0
   164
		break;
sl@0
   165
		
sl@0
   166
		case 8:
sl@0
   167
		iBlank.Close();
sl@0
   168
		iBlank = RBlankWindow(iWs);
sl@0
   169
		iBlank.Construct(iGroup, 0xbeef);
sl@0
   170
		iBlank.SetRequiredDisplayMode(EColor64K);
sl@0
   171
		iBlank.SetColor(KRgbRed);
sl@0
   172
		iBlank.SetExtent(TPoint(20,20),TSize(100,100));
sl@0
   173
		iBlank.Activate();
sl@0
   174
		break;
sl@0
   175
		
sl@0
   176
		case 9:
sl@0
   177
		ClearTwoWindow();
sl@0
   178
		DrawTwoWindow();
sl@0
   179
		break;
sl@0
   180
		
sl@0
   181
		case 10:
sl@0
   182
		CActiveScheduler::Stop();
sl@0
   183
		break;
sl@0
   184
		}
sl@0
   185
	}
sl@0
   186
	
sl@0
   187
CClient::~CClient()
sl@0
   188
	{	
sl@0
   189
	Deque();
sl@0
   190
	ClearTwoWindow();
sl@0
   191
	iBlank.Close();
sl@0
   192
	
sl@0
   193
	delete iListen;
sl@0
   194
	delete iRedir;
sl@0
   195
	delete iWin;
sl@0
   196
	delete iRedraw;
sl@0
   197
	delete iGc;
sl@0
   198
	delete iScreen;
sl@0
   199
	
sl@0
   200
	iGroup.Close();
sl@0
   201
	iWs.Close();
sl@0
   202
	}
sl@0
   203
sl@0
   204
void CClient::DrawTwoWindow()
sl@0
   205
	{
sl@0
   206
	TRAP_IGNORE(iTwo = CTwoWindow::NewL());
sl@0
   207
	}
sl@0
   208
sl@0
   209
void CClient::ClearTwoWindow()
sl@0
   210
	{
sl@0
   211
	delete iTwo;
sl@0
   212
	iTwo = NULL;	
sl@0
   213
	}
sl@0
   214
sl@0
   215
void CClient::RunL()
sl@0
   216
	{
sl@0
   217
	iWs.GetEvent(iEvent);
sl@0
   218
	if (iEvent.Type()==EEventKey)
sl@0
   219
		HandleCommand(iEvent.Key()->iCode-'0');
sl@0
   220
	MakeRequest();
sl@0
   221
	}
sl@0
   222
sl@0
   223
void CClient::DoCancel()
sl@0
   224
	{
sl@0
   225
	iWs.EventReadyCancel();
sl@0
   226
	}
sl@0
   227
sl@0
   228
void CClient::MakeRequest()
sl@0
   229
	{
sl@0
   230
	iWs.EventReady(&iStatus);
sl@0
   231
	SetActive();
sl@0
   232
	}
sl@0
   233
sl@0
   234
CRedrawHandler* CRedrawHandler::NewL(CClient* aClient)
sl@0
   235
	{
sl@0
   236
	CRedrawHandler* self=new(ELeave) CRedrawHandler(aClient);
sl@0
   237
	CleanupStack::PushL(self);
sl@0
   238
	self->ConstructL();
sl@0
   239
	CleanupStack::Pop(self);
sl@0
   240
	
sl@0
   241
	return self;
sl@0
   242
	}
sl@0
   243
sl@0
   244
CRedrawHandler::CRedrawHandler(CClient* aClient) : CActive(CActive::EPriorityStandard), iClient(aClient)
sl@0
   245
	{
sl@0
   246
	}
sl@0
   247
sl@0
   248
void CRedrawHandler::ConstructL()
sl@0
   249
	{
sl@0
   250
	CActiveScheduler::Add(this);
sl@0
   251
	MakeRequest();
sl@0
   252
	}
sl@0
   253
sl@0
   254
CRedrawHandler::~CRedrawHandler()
sl@0
   255
	{
sl@0
   256
	Cancel();
sl@0
   257
	}
sl@0
   258
sl@0
   259
void CRedrawHandler::RunL()
sl@0
   260
	{
sl@0
   261
	TWsRedrawEvent event;
sl@0
   262
	iClient->Ws().GetRedraw(event);
sl@0
   263
	CWindow* win = (CWindow*)event.Handle();
sl@0
   264
	if (win) 
sl@0
   265
		{
sl@0
   266
		TRect rect=event.Rect();
sl@0
   267
		iClient->Gc().Activate(win->Window());
sl@0
   268
		win->Window().BeginRedraw(rect);
sl@0
   269
		win->Draw(rect);
sl@0
   270
		win->Window().EndRedraw();
sl@0
   271
		iClient->Gc().Deactivate();
sl@0
   272
		}
sl@0
   273
		
sl@0
   274
	MakeRequest();
sl@0
   275
	}
sl@0
   276
sl@0
   277
void CRedrawHandler::MakeRequest()
sl@0
   278
	{
sl@0
   279
	iClient->Ws().RedrawReady(&iStatus);
sl@0
   280
	SetActive();
sl@0
   281
	}
sl@0
   282
sl@0
   283
void CRedrawHandler::DoCancel()
sl@0
   284
	{
sl@0
   285
	iClient->Ws().RedrawReadyCancel();
sl@0
   286
	}
sl@0
   287
sl@0
   288
CWindow::CWindow(CClient* aClient) : iClient(aClient)
sl@0
   289
	{
sl@0
   290
	}
sl@0
   291
sl@0
   292
CWindow::~CWindow()
sl@0
   293
	{
sl@0
   294
	iWin.Close();
sl@0
   295
	}
sl@0
   296
sl@0
   297
void CWindow::ConstructL(CWindow* aParent, TBool aTransparentFlag)
sl@0
   298
	{
sl@0
   299
	iParent = aParent;
sl@0
   300
	iWin = RWindow(iClient->Ws());
sl@0
   301
	RWindowTreeNode* node=iParent? &iParent->Window() : (RWindowTreeNode*)&iClient->Group();
sl@0
   302
	User::LeaveIfError(iWin.Construct(*node, (TUint32)this));
sl@0
   303
	iWin.SetRequiredDisplayMode(EColor64K);
sl@0
   304
	if (aTransparentFlag)
sl@0
   305
		{
sl@0
   306
		iWin.SetBackgroundColor(TRgb(0,0,0,0x80));
sl@0
   307
		iWin.SetTransparencyAlphaChannel();
sl@0
   308
		}
sl@0
   309
	iWin.SetExtent(TPoint(0,0),TSize(240,240));
sl@0
   310
	iWin.Activate();
sl@0
   311
	}
sl@0
   312
sl@0
   313
void CWindow::Draw(const TRect& aRect) const
sl@0
   314
	{
sl@0
   315
	CWindowGc& gc = iClient->Gc();
sl@0
   316
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   317
	gc.SetBrushColor(TRgb(0,0,0xff,0xff));	
sl@0
   318
	gc.DrawRect(TRect(aRect.iTl.iX,aRect.iTl.iY,aRect.iBr.iX,aRect.iBr.iY/2));
sl@0
   319
	gc.SetBrushColor(TRgb(0,0,0xff,0x80));	
sl@0
   320
	gc.DrawRect(TRect(aRect.iTl.iX,aRect.iBr.iY/2,aRect.iBr.iX,aRect.iBr.iY));	
sl@0
   321
	DrawMenu();
sl@0
   322
	
sl@0
   323
	gc.DrawWsGraphic(iClient->WsRedir()->Id(),TRect(aRect.iTl.iX,aRect.iBr.iY/2,aRect.iBr.iX,aRect.iBr.iY));
sl@0
   324
	}
sl@0
   325
sl@0
   326
_LIT(KMenu1, "1. Redirect screen");
sl@0
   327
_LIT(KMenu2, "2. Redirect flickerfree");
sl@0
   328
_LIT(KMenu3, "3. Restore screen");
sl@0
   329
_LIT(KMenu4, "4. Restore flickerfree");
sl@0
   330
_LIT(KMenu5, "5. Register event listener");
sl@0
   331
_LIT(KMenu6, "6. Unregister listener");
sl@0
   332
_LIT(KMenu7, "7. Test send receive msg");
sl@0
   333
_LIT(KMenu8, "8. Test blank window");
sl@0
   334
_LIT(KMenu9, "9. Test two window");
sl@0
   335
_LIT(KMenuA, "A. Exit");
sl@0
   336
sl@0
   337
const TBufC<32> TheMenu[] = 
sl@0
   338
	{
sl@0
   339
	(const TDesC&)KMenu1,
sl@0
   340
	(const TDesC&)KMenu2,
sl@0
   341
	(const TDesC&)KMenu3,
sl@0
   342
	(const TDesC&)KMenu4,
sl@0
   343
	(const TDesC&)KMenu5,
sl@0
   344
	(const TDesC&)KMenu6,
sl@0
   345
	(const TDesC&)KMenu7,
sl@0
   346
	(const TDesC&)KMenu8,
sl@0
   347
	(const TDesC&)KMenu9,
sl@0
   348
	(const TDesC&)KMenuA
sl@0
   349
	};
sl@0
   350
	
sl@0
   351
_LIT(KTypeFace, "DejaVu Sans Condensed");
sl@0
   352
sl@0
   353
void CWindow::DrawMenu() const
sl@0
   354
	{
sl@0
   355
	CWsScreenDevice* scr = iClient->Screen();
sl@0
   356
	CFont* font = NULL;
sl@0
   357
	TFontSpec fs(KTypeFace, 15);
sl@0
   358
	scr->GetNearestFontInPixels(font, fs);
sl@0
   359
	CWindowGc& gc = iClient->Gc();
sl@0
   360
	gc.UseFont(font);
sl@0
   361
	TInt h = font->HeightInPixels();
sl@0
   362
	gc.SetPenColor(KRgbYellow);
sl@0
   363
	TInt nMenu = sizeof(TheMenu)/sizeof(TheMenu[0]);
sl@0
   364
	for (TInt ii=0; ii<nMenu; ++ii)
sl@0
   365
		gc.DrawText(TheMenu[ii], TPoint(10,(ii+1)*h));
sl@0
   366
	gc.DiscardFont();
sl@0
   367
	scr->ReleaseFont(font);
sl@0
   368
	}
sl@0
   369
sl@0
   370
void MainL()
sl@0
   371
	{
sl@0
   372
	CClient* client=CClient::NewL();
sl@0
   373
	CActiveScheduler::Start();
sl@0
   374
	
sl@0
   375
	delete client;
sl@0
   376
	}
sl@0
   377
sl@0
   378
GLDEF_C TInt E32Main()
sl@0
   379
	{
sl@0
   380
	CTrapCleanup* trap=CTrapCleanup::New();
sl@0
   381
	if (!trap)
sl@0
   382
		return KErrNoMemory;
sl@0
   383
	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
sl@0
   384
	CActiveScheduler::Install(scheduler);
sl@0
   385
	
sl@0
   386
	__UHEAP_MARK;	
sl@0
   387
	TRAPD(err, MainL());
sl@0
   388
	__UHEAP_MARKEND;	
sl@0
   389
	
sl@0
   390
	delete scheduler;
sl@0
   391
	delete trap;
sl@0
   392
	return err;
sl@0
   393
	}