sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: #include sl@0: #include "tcrx.h" sl@0: #include "wsredir.h" sl@0: #include "wslisten.h" sl@0: sl@0: static TRedirectorInfo TheInfo; sl@0: sl@0: class CTwoWindow: public CBase sl@0: { sl@0: public: sl@0: static CTwoWindow* NewL(); sl@0: ~CTwoWindow(); sl@0: private: sl@0: void ConstructL(); sl@0: private: sl@0: RWsSession iWs; sl@0: CWsScreenDevice* iScr; sl@0: CWindowGc* iGc; sl@0: RWindowGroup iGroup; sl@0: RWindow iBg; sl@0: RWindow iFg; sl@0: }; sl@0: sl@0: CTwoWindow* CTwoWindow::NewL() sl@0: { sl@0: CTwoWindow* tw = new(ELeave) CTwoWindow; sl@0: CleanupStack::PushL(tw); sl@0: tw->ConstructL(); sl@0: CleanupStack::Pop(tw); sl@0: return tw; sl@0: } sl@0: sl@0: CTwoWindow::~CTwoWindow() sl@0: { sl@0: iFg.Close(); sl@0: iBg.Close(); sl@0: iGroup.Close(); sl@0: delete iGc; sl@0: delete iScr; sl@0: iWs.Close(); sl@0: } sl@0: sl@0: void CTwoWindow::ConstructL() sl@0: { sl@0: User::LeaveIfError(iWs.Connect()); sl@0: iScr = new(ELeave) CWsScreenDevice(iWs); sl@0: User::LeaveIfError(iScr->Construct()); sl@0: User::LeaveIfError(iScr->CreateContext(iGc)); sl@0: iGroup = RWindowGroup(iWs); sl@0: User::LeaveIfError(iGroup.Construct(0xc0de,ETrue)); sl@0: sl@0: iBg = RWindow(iWs); sl@0: User::LeaveIfError(iBg.Construct(iGroup,0xc0debabe)); sl@0: iBg.SetRequiredDisplayMode(EColor64K); sl@0: iBg.Activate(); sl@0: iWs.Flush(); sl@0: sl@0: iBg.BeginRedraw(); sl@0: iGc->Activate(iBg); sl@0: iGc->SetBrushColor(KRgbGreen); sl@0: iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: TRect rect(iScr->SizeInPixels()); sl@0: iGc->DrawRect(rect); sl@0: iGc->SetBrushColor(KRgbBlue); sl@0: iGc->DrawEllipse(rect); sl@0: iGc->Deactivate(); sl@0: iBg.EndRedraw(); sl@0: iWs.Flush(); sl@0: sl@0: iFg = RWindow(iWs); sl@0: User::LeaveIfError(iFg.Construct(iGroup,0xc0decafe)); sl@0: iFg.SetRequiredDisplayMode(EColor64K); sl@0: iFg.SetTransparencyAlphaChannel(); sl@0: iFg.SetBackgroundColor(TRgb(0xff,0x55,0x55,0x80)); sl@0: iFg.Activate(); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: CClient* CClient::NewL() sl@0: { sl@0: CClient* self = new(ELeave) CClient; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: sl@0: return self; sl@0: } sl@0: sl@0: CClient::CClient(): CActive(CActive::EPriorityStandard) sl@0: { sl@0: } sl@0: sl@0: void CClient::ConstructL() sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: User::LeaveIfError(iWs.Connect()); sl@0: iScreen = new(ELeave) CWsScreenDevice(iWs); sl@0: User::LeaveIfError(iScreen->Construct(0)); sl@0: iGroup = RWindowGroup(iWs); sl@0: User::LeaveIfError(iGroup.Construct(0xCAFE, ETrue)); sl@0: iGc = new(ELeave) CWindowGc(iScreen); sl@0: User::LeaveIfError(iGc->Construct()); sl@0: iWin = new(ELeave) CWindow(this); sl@0: iWin->ConstructL(NULL, EFalse); sl@0: iRedraw = CRedrawHandler::NewL(this); sl@0: sl@0: iRedir = CWsRedir::NewL(); sl@0: iListen = CWsListen::NewL(); sl@0: sl@0: MakeRequest(); sl@0: } sl@0: sl@0: void CClient::HandleCommand(TInt aCmd) sl@0: { sl@0: switch (aCmd) sl@0: { sl@0: case 1: sl@0: iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue); sl@0: break; sl@0: sl@0: case 2: sl@0: iRedir->Redirect(CWsRedir::EBackBuffer, ETrue); sl@0: break; sl@0: sl@0: case 3: sl@0: iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse); sl@0: break; sl@0: sl@0: case 4: sl@0: iRedir->Redirect(CWsRedir::EBackBuffer, EFalse); sl@0: break; sl@0: sl@0: case 5: sl@0: iListen->Enable(ETrue); sl@0: break; sl@0: sl@0: case 6: sl@0: iListen->Enable(EFalse); sl@0: break; sl@0: sl@0: case 7: sl@0: iRedir->QueryPlugin(TheInfo); sl@0: break; sl@0: sl@0: case 8: sl@0: iBlank.Close(); sl@0: iBlank = RBlankWindow(iWs); sl@0: iBlank.Construct(iGroup, 0xbeef); sl@0: iBlank.SetRequiredDisplayMode(EColor64K); sl@0: iBlank.SetColor(KRgbRed); sl@0: iBlank.SetExtent(TPoint(20,20),TSize(100,100)); sl@0: iBlank.Activate(); sl@0: break; sl@0: sl@0: case 9: sl@0: ClearTwoWindow(); sl@0: DrawTwoWindow(); sl@0: break; sl@0: sl@0: case 10: sl@0: CActiveScheduler::Stop(); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: CClient::~CClient() sl@0: { sl@0: Deque(); sl@0: ClearTwoWindow(); sl@0: iBlank.Close(); sl@0: sl@0: delete iListen; sl@0: delete iRedir; sl@0: delete iWin; sl@0: delete iRedraw; sl@0: delete iGc; sl@0: delete iScreen; sl@0: sl@0: iGroup.Close(); sl@0: iWs.Close(); sl@0: } sl@0: sl@0: void CClient::DrawTwoWindow() sl@0: { sl@0: TRAP_IGNORE(iTwo = CTwoWindow::NewL()); sl@0: } sl@0: sl@0: void CClient::ClearTwoWindow() sl@0: { sl@0: delete iTwo; sl@0: iTwo = NULL; sl@0: } sl@0: sl@0: void CClient::RunL() sl@0: { sl@0: iWs.GetEvent(iEvent); sl@0: if (iEvent.Type()==EEventKey) sl@0: HandleCommand(iEvent.Key()->iCode-'0'); sl@0: MakeRequest(); sl@0: } sl@0: sl@0: void CClient::DoCancel() sl@0: { sl@0: iWs.EventReadyCancel(); sl@0: } sl@0: sl@0: void CClient::MakeRequest() sl@0: { sl@0: iWs.EventReady(&iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: CRedrawHandler* CRedrawHandler::NewL(CClient* aClient) sl@0: { sl@0: CRedrawHandler* self=new(ELeave) CRedrawHandler(aClient); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: sl@0: return self; sl@0: } sl@0: sl@0: CRedrawHandler::CRedrawHandler(CClient* aClient) : CActive(CActive::EPriorityStandard), iClient(aClient) sl@0: { sl@0: } sl@0: sl@0: void CRedrawHandler::ConstructL() sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: MakeRequest(); sl@0: } sl@0: sl@0: CRedrawHandler::~CRedrawHandler() sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: void CRedrawHandler::RunL() sl@0: { sl@0: TWsRedrawEvent event; sl@0: iClient->Ws().GetRedraw(event); sl@0: CWindow* win = (CWindow*)event.Handle(); sl@0: if (win) sl@0: { sl@0: TRect rect=event.Rect(); sl@0: iClient->Gc().Activate(win->Window()); sl@0: win->Window().BeginRedraw(rect); sl@0: win->Draw(rect); sl@0: win->Window().EndRedraw(); sl@0: iClient->Gc().Deactivate(); sl@0: } sl@0: sl@0: MakeRequest(); sl@0: } sl@0: sl@0: void CRedrawHandler::MakeRequest() sl@0: { sl@0: iClient->Ws().RedrawReady(&iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CRedrawHandler::DoCancel() sl@0: { sl@0: iClient->Ws().RedrawReadyCancel(); sl@0: } sl@0: sl@0: CWindow::CWindow(CClient* aClient) : iClient(aClient) sl@0: { sl@0: } sl@0: sl@0: CWindow::~CWindow() sl@0: { sl@0: iWin.Close(); sl@0: } sl@0: sl@0: void CWindow::ConstructL(CWindow* aParent, TBool aTransparentFlag) sl@0: { sl@0: iParent = aParent; sl@0: iWin = RWindow(iClient->Ws()); sl@0: RWindowTreeNode* node=iParent? &iParent->Window() : (RWindowTreeNode*)&iClient->Group(); sl@0: User::LeaveIfError(iWin.Construct(*node, (TUint32)this)); sl@0: iWin.SetRequiredDisplayMode(EColor64K); sl@0: if (aTransparentFlag) sl@0: { sl@0: iWin.SetBackgroundColor(TRgb(0,0,0,0x80)); sl@0: iWin.SetTransparencyAlphaChannel(); sl@0: } sl@0: iWin.SetExtent(TPoint(0,0),TSize(240,240)); sl@0: iWin.Activate(); sl@0: } sl@0: sl@0: void CWindow::Draw(const TRect& aRect) const sl@0: { sl@0: CWindowGc& gc = iClient->Gc(); sl@0: gc.SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: gc.SetBrushColor(TRgb(0,0,0xff,0xff)); sl@0: gc.DrawRect(TRect(aRect.iTl.iX,aRect.iTl.iY,aRect.iBr.iX,aRect.iBr.iY/2)); sl@0: gc.SetBrushColor(TRgb(0,0,0xff,0x80)); sl@0: gc.DrawRect(TRect(aRect.iTl.iX,aRect.iBr.iY/2,aRect.iBr.iX,aRect.iBr.iY)); sl@0: DrawMenu(); sl@0: sl@0: gc.DrawWsGraphic(iClient->WsRedir()->Id(),TRect(aRect.iTl.iX,aRect.iBr.iY/2,aRect.iBr.iX,aRect.iBr.iY)); sl@0: } sl@0: sl@0: _LIT(KMenu1, "1. Redirect screen"); sl@0: _LIT(KMenu2, "2. Redirect flickerfree"); sl@0: _LIT(KMenu3, "3. Restore screen"); sl@0: _LIT(KMenu4, "4. Restore flickerfree"); sl@0: _LIT(KMenu5, "5. Register event listener"); sl@0: _LIT(KMenu6, "6. Unregister listener"); sl@0: _LIT(KMenu7, "7. Test send receive msg"); sl@0: _LIT(KMenu8, "8. Test blank window"); sl@0: _LIT(KMenu9, "9. Test two window"); sl@0: _LIT(KMenuA, "A. Exit"); sl@0: sl@0: const TBufC<32> TheMenu[] = sl@0: { sl@0: (const TDesC&)KMenu1, sl@0: (const TDesC&)KMenu2, sl@0: (const TDesC&)KMenu3, sl@0: (const TDesC&)KMenu4, sl@0: (const TDesC&)KMenu5, sl@0: (const TDesC&)KMenu6, sl@0: (const TDesC&)KMenu7, sl@0: (const TDesC&)KMenu8, sl@0: (const TDesC&)KMenu9, sl@0: (const TDesC&)KMenuA sl@0: }; sl@0: sl@0: _LIT(KTypeFace, "DejaVu Sans Condensed"); sl@0: sl@0: void CWindow::DrawMenu() const sl@0: { sl@0: CWsScreenDevice* scr = iClient->Screen(); sl@0: CFont* font = NULL; sl@0: TFontSpec fs(KTypeFace, 15); sl@0: scr->GetNearestFontInPixels(font, fs); sl@0: CWindowGc& gc = iClient->Gc(); sl@0: gc.UseFont(font); sl@0: TInt h = font->HeightInPixels(); sl@0: gc.SetPenColor(KRgbYellow); sl@0: TInt nMenu = sizeof(TheMenu)/sizeof(TheMenu[0]); sl@0: for (TInt ii=0; iiReleaseFont(font); sl@0: } sl@0: sl@0: void MainL() sl@0: { sl@0: CClient* client=CClient::NewL(); sl@0: CActiveScheduler::Start(); sl@0: sl@0: delete client; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: CTrapCleanup* trap=CTrapCleanup::New(); sl@0: if (!trap) sl@0: return KErrNoMemory; sl@0: CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(scheduler); sl@0: sl@0: __UHEAP_MARK; sl@0: TRAPD(err, MainL()); sl@0: __UHEAP_MARKEND; sl@0: sl@0: delete scheduler; sl@0: delete trap; sl@0: return err; sl@0: }