sl@0: // Copyright (c) 2008-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: #include "drawresource.h" sl@0: #include "wstop.h" sl@0: #include sl@0: sl@0: sl@0: CWsDrawableSource::CWsDrawableSource(CWsClient *aOwner) sl@0: : CWsObject(aOwner, WS_HANDLE_DRAWABLE_SOURCE) sl@0: { sl@0: } sl@0: sl@0: CWsDrawableSource::~CWsDrawableSource() sl@0: { sl@0: if (iDrawableSource && iDrawResource) sl@0: { sl@0: iDrawResource->CloseDrawableSource(iDrawableSource); sl@0: } sl@0: } sl@0: sl@0: void CWsDrawableSource::ConstructL(const TWsClCmdCreateDrawableSource &aParams) sl@0: { sl@0: NewObjL(); sl@0: sl@0: CScreen* screen = NULL; sl@0: if (Rng(0, aParams.iScreenNumber, CWsTop::NumberOfScreens() - 1)) sl@0: { sl@0: screen = CWsTop::Screen(aParams.iScreenNumber); sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: MWsScreen* pOI=screen; sl@0: CWsDrawableSource::iDrawResource = pOI->ObjectInterface(); sl@0: if (!iDrawResource) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: User::LeaveIfError(iDrawResource->CreateDrawableSource(aParams.iDrawableId, iDrawableSource)); sl@0: IncRefCount(); sl@0: } sl@0: sl@0: void CWsDrawableSource::CommandL(TInt aOpcode, const TAny *) sl@0: { sl@0: switch(aOpcode) sl@0: { sl@0: case EWsDrawableSourceOpFree: sl@0: iFlags |= EWsClientHandleClosed; sl@0: DecRefCount(); sl@0: break; sl@0: default: sl@0: OwnerPanic(EWservPanicOpcode); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: /* sl@0: CWsDrawableSource is a reference counted object so we cannot simply close the object as somebody else may have a reference to it sl@0: */ sl@0: void CWsDrawableSource::CloseObject() sl@0: { sl@0: RemoveFromIndex(); sl@0: if (!(iFlags & EWsClientHandleClosed)) sl@0: { sl@0: DecRefCount(); sl@0: } sl@0: } sl@0: sl@0: void CWsDrawableSource::IncRefCount() sl@0: { sl@0: iRefCount++; sl@0: } sl@0: sl@0: void CWsDrawableSource::DecRefCount() sl@0: { sl@0: if (--iRefCount <= 0) sl@0: { sl@0: delete this; sl@0: } sl@0: } sl@0: sl@0: void CWsDrawableSource::DrawResource(MWsGraphicsContext *aGc, const TPoint& aPos, CWindowGc::TGraphicsRotation aRotation) const sl@0: { sl@0: ASSERT(iDrawResource); sl@0: MWsDrawableSourceProvider* drawResource = aGc->ObjectInterface(); sl@0: if (drawResource == iDrawResource) sl@0: { sl@0: drawResource->DrawResource(iDrawableSource, aPos, aRotation); sl@0: } sl@0: } sl@0: sl@0: void CWsDrawableSource::DrawResource(MWsGraphicsContext *aGc, const TRect& aRect, CWindowGc::TGraphicsRotation aRotation) const sl@0: { sl@0: ASSERT(iDrawResource); sl@0: MWsDrawableSourceProvider* drawResource = aGc->ObjectInterface(); sl@0: if (drawResource == iDrawResource) sl@0: { sl@0: drawResource->DrawResource(iDrawableSource, aRect, aRotation); sl@0: } sl@0: } sl@0: sl@0: void CWsDrawableSource::DrawResource(MWsGraphicsContext *aGc, const TRect& aRectDest, const TRect& aRectSrc, CWindowGc::TGraphicsRotation aRotation) const sl@0: { sl@0: ASSERT(iDrawResource); sl@0: MWsDrawableSourceProvider* drawResource = aGc->ObjectInterface(); sl@0: if (drawResource == iDrawResource) sl@0: { sl@0: drawResource->DrawResource(iDrawableSource, aRectDest, aRectSrc, aRotation); sl@0: } sl@0: } sl@0: sl@0: void CWsDrawableSource::DrawResource(MWsGraphicsContext *aGc, const TRect& aRect, const TDesC8& aDes) const sl@0: { sl@0: ASSERT(iDrawResource); sl@0: MWsDrawableSourceProvider* drawResource = aGc->ObjectInterface(); sl@0: if (drawResource == iDrawResource) sl@0: { sl@0: drawResource->DrawResource(iDrawableSource, aRect, aDes); sl@0: } sl@0: }