os/graphics/windowing/windowserver/test/tcontaindrawer/containdrawer.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) 2007-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 "containdrawer.h"
sl@0
    23
#include "wsgraphicdrawercontext.h"
sl@0
    24
#include <s32mem.h>
sl@0
    25
#include <s32strm.h>
sl@0
    26
sl@0
    27
const TGraphicDrawerId KChildInterfaceId1={0x1028353A, ETrue};
sl@0
    28
const TGraphicDrawerId KChildInterfaceId2={0x1028353C, ETrue};
sl@0
    29
sl@0
    30
sl@0
    31
// CWsGraphicDrawer	
sl@0
    32
CWsContainGraphicDrawer* CWsContainGraphicDrawer::NewL()
sl@0
    33
	{
sl@0
    34
	return new(ELeave) CWsContainGraphicDrawer;	
sl@0
    35
	}
sl@0
    36
	
sl@0
    37
CWsContainGraphicDrawer::~CWsContainGraphicDrawer()
sl@0
    38
	{
sl@0
    39
	if (iContext)
sl@0
    40
		{
sl@0
    41
		iContext->Destroy();
sl@0
    42
		iContext = NULL;
sl@0
    43
		}
sl@0
    44
	}
sl@0
    45
sl@0
    46
void CWsContainGraphicDrawer::ConstructL(MWsGraphicDrawerEnvironment& aEnv, const TGraphicDrawerId& aId, MWsClient& aOwner, const TDesC8& /*aData*/)
sl@0
    47
	{
sl@0
    48
	BaseConstructL(aEnv, aId, aOwner);
sl@0
    49
	iColor = KRgbWhite;
sl@0
    50
	if (!(aEnv.Screen(0)->ResolveObjectInterface(KMWsCompositionContext) || aEnv.Screen(0)->ResolveObjectInterface(KMWsScene)))
sl@0
    51
		{
sl@0
    52
		iContext = CWsGraphicDrawerNonNgaContext::NewL();
sl@0
    53
		}
sl@0
    54
	else
sl@0
    55
		{
sl@0
    56
		iContext = CWsGraphicDrawerNgaContext::NewL();
sl@0
    57
		}
sl@0
    58
	}
sl@0
    59
sl@0
    60
void CWsContainGraphicDrawer::HandleMessage(const TDesC8& aData)
sl@0
    61
	{
sl@0
    62
	TInt red = aData[0];
sl@0
    63
	TInt green = aData[1];
sl@0
    64
	TInt blue = aData[2];
sl@0
    65
	TRgb color(red, green, blue);
sl@0
    66
	DoUpdateColor(color);
sl@0
    67
	}
sl@0
    68
	
sl@0
    69
void CWsContainGraphicDrawer::DoUpdateColor(TRgb aColor)
sl@0
    70
	{
sl@0
    71
    iColor = aColor;
sl@0
    72
    // Invalidate the redrawing
sl@0
    73
    Invalidate();
sl@0
    74
 	}
sl@0
    75
sl@0
    76
void CWsContainGraphicDrawer::DoDraw(MWsGc& aGc, const TRect& aRect, const TDesC8& aData) const
sl@0
    77
	{
sl@0
    78
	iContext->DrawEllipse(aGc, aRect, iColor);
sl@0
    79
sl@0
    80
	// invoke another CRPs to draw their artwork
sl@0
    81
    TRect rect1 = TRect(TPoint(100,150),TSize(50,50));
sl@0
    82
	const CWsGraphicDrawer* child1 = Env().ResolveGraphic(KChildInterfaceId1);
sl@0
    83
   	if (child1)
sl@0
    84
   		child1->Draw(aGc, rect1, aData);	
sl@0
    85
	TRect rect2 = TRect(TPoint(200,150),TSize(50,50));
sl@0
    86
   	const CWsGraphicDrawer* child2 = Env().ResolveGraphic(KChildInterfaceId2);
sl@0
    87
   	if (child2)
sl@0
    88
        child2->Draw(aGc, rect2, aData);		
sl@0
    89
	}
sl@0
    90
	
sl@0
    91
// inherited API to indicate there are contained drawers	
sl@0
    92
TBool CWsContainGraphicDrawer::HasAsChild(const TArray<TGraphicDrawerId>& aIds) const
sl@0
    93
	{
sl@0
    94
	// Two child CRPs
sl@0
    95
	const CWsGraphicDrawer* child1 = Env().ResolveGraphic(KChildInterfaceId1);
sl@0
    96
   	const CWsGraphicDrawer* child2 = Env().ResolveGraphic(KChildInterfaceId2);
sl@0
    97
   	if (child1 && child1->Contains(aIds))
sl@0
    98
   		return ETrue;
sl@0
    99
   	else if (child2 && child2->Contains(aIds))
sl@0
   100
   		return ETrue;
sl@0
   101
   	else
sl@0
   102
   		return EFalse;
sl@0
   103
	}