windowing/windowserver/tcontaindrawer/containdrawer.cpp
changeset 110 7f25ef56562d
parent 98 bf7481649c98
child 111 29ddb8a72f0e
equal deleted inserted replaced
98:bf7481649c98 110:7f25ef56562d
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code
       
    20 */
       
    21 
       
    22 #include "containdrawer.h"
       
    23 #include "wsgraphicdrawercontext.h"
       
    24 #include <s32mem.h>
       
    25 #include <s32strm.h>
       
    26 
       
    27 const TGraphicDrawerId KChildInterfaceId1={0x1028353A, ETrue};
       
    28 const TGraphicDrawerId KChildInterfaceId2={0x1028353C, ETrue};
       
    29 
       
    30 
       
    31 // CWsGraphicDrawer	
       
    32 CWsContainGraphicDrawer* CWsContainGraphicDrawer::NewL()
       
    33 	{
       
    34 	return new(ELeave) CWsContainGraphicDrawer;	
       
    35 	}
       
    36 	
       
    37 CWsContainGraphicDrawer::~CWsContainGraphicDrawer()
       
    38 	{
       
    39 	if (iContext)
       
    40 		{
       
    41 		iContext->Destroy();
       
    42 		iContext = NULL;
       
    43 		}
       
    44 	}
       
    45 
       
    46 void CWsContainGraphicDrawer::ConstructL(MWsGraphicDrawerEnvironment& aEnv, const TGraphicDrawerId& aId, MWsClient& aOwner, const TDesC8& /*aData*/)
       
    47 	{
       
    48 	BaseConstructL(aEnv, aId, aOwner);
       
    49 	iColor = KRgbWhite;
       
    50 	if (!(aEnv.Screen(0)->ResolveObjectInterface(KMWsCompositionContext) || aEnv.Screen(0)->ResolveObjectInterface(KMWsScene)))
       
    51 		{
       
    52 		iContext = CWsGraphicDrawerNonNgaContext::NewL();
       
    53 		}
       
    54 	else
       
    55 		{
       
    56 		iContext = CWsGraphicDrawerNgaContext::NewL();
       
    57 		}
       
    58 	}
       
    59 
       
    60 void CWsContainGraphicDrawer::HandleMessage(const TDesC8& aData)
       
    61 	{
       
    62 	TInt red = aData[0];
       
    63 	TInt green = aData[1];
       
    64 	TInt blue = aData[2];
       
    65 	TRgb color(red, green, blue);
       
    66 	DoUpdateColor(color);
       
    67 	}
       
    68 	
       
    69 void CWsContainGraphicDrawer::DoUpdateColor(TRgb aColor)
       
    70 	{
       
    71     iColor = aColor;
       
    72     // Invalidate the redrawing
       
    73     Invalidate();
       
    74  	}
       
    75 
       
    76 void CWsContainGraphicDrawer::DoDraw(MWsGc& aGc, const TRect& aRect, const TDesC8& aData) const
       
    77 	{
       
    78 	iContext->DrawEllipse(aGc, aRect, iColor);
       
    79 
       
    80 	// invoke another CRPs to draw their artwork
       
    81     TRect rect1 = TRect(TPoint(100,150),TSize(50,50));
       
    82 	const CWsGraphicDrawer* child1 = Env().ResolveGraphic(KChildInterfaceId1);
       
    83    	if (child1)
       
    84    		child1->Draw(aGc, rect1, aData);	
       
    85 	TRect rect2 = TRect(TPoint(200,150),TSize(50,50));
       
    86    	const CWsGraphicDrawer* child2 = Env().ResolveGraphic(KChildInterfaceId2);
       
    87    	if (child2)
       
    88         child2->Draw(aGc, rect2, aData);		
       
    89 	}
       
    90 	
       
    91 // inherited API to indicate there are contained drawers	
       
    92 TBool CWsContainGraphicDrawer::HasAsChild(const TArray<TGraphicDrawerId>& aIds) const
       
    93 	{
       
    94 	// Two child CRPs
       
    95 	const CWsGraphicDrawer* child1 = Env().ResolveGraphic(KChildInterfaceId1);
       
    96    	const CWsGraphicDrawer* child2 = Env().ResolveGraphic(KChildInterfaceId2);
       
    97    	if (child1 && child1->Contains(aIds))
       
    98    		return ETrue;
       
    99    	else if (child2 && child2->Contains(aIds))
       
   100    		return ETrue;
       
   101    	else
       
   102    		return EFalse;
       
   103 	}