os/graphics/windowing/windowserver/test/HNDLODR.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/HNDLODR.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,175 @@
     1.4 +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Demonstration handwriting class
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "HNDLODR.H"
    1.22 +
    1.23 +
    1.24 +/*RHandWritingAnim*/
    1.25 +
    1.26 +TInt RHandWritingAnim::Construct(const RWsSprite& aDevice)
    1.27 +	{
    1.28 +	TPtrC8 des(NULL,0);
    1.29 +	return RAnim::Construct(aDevice,0,des);
    1.30 +	}
    1.31 +
    1.32 +void RHandWritingAnim::Activate()
    1.33 +	{
    1.34 +	Command(EHwOpActivate);
    1.35 +	}
    1.36 +
    1.37 +void RHandWritingAnim::Deactivate()
    1.38 +	{
    1.39 +	Command(EHwOpDeactivate);
    1.40 +	}
    1.41 +
    1.42 +TInt RHandWritingAnim::SpriteMaskChange(TBool aUsingSeparateMask)
    1.43 +	{
    1.44 +	TPckgBuf<TBool> param;
    1.45 +	param()=aUsingSeparateMask;
    1.46 +	return CommandReply(EHwOpSpriteMask,param);
    1.47 +	}
    1.48 +
    1.49 +void RHandWritingAnim::SetDrawData(const THandwritingDrawData& aDrawData)
    1.50 +	{
    1.51 +	TPckgBuf<THandwritingDrawData> param;
    1.52 +	param()=aDrawData;
    1.53 +	Command(EHwOpSetDrawData,param);
    1.54 +	}
    1.55 +
    1.56 +TInt RHandWritingAnim::GetLastGeneratedCharacter()
    1.57 +	{
    1.58 +	return CommandReply(EHwOpGetLastChar);
    1.59 +	}
    1.60 +
    1.61 +
    1.62 +/*CHandWriting*/
    1.63 +
    1.64 +CHandWriting::CHandWriting(RWsSession& aSession)
    1.65 +	:iSession(aSession), iAnimDll(aSession), iAnim(iAnimDll), iSprite(aSession)
    1.66 +	{}
    1.67 +
    1.68 +void CHandWriting::ConstructL(TSize aScreenSize,RWindowGroup& aGroup,TBool aUseSeparateMask)
    1.69 +	//
    1.70 +	//This function should be called with the correct screen size and 
    1.71 +	//the handle of any group window that will be around as long as the handwriting is required
    1.72 +	//
    1.73 +	{
    1.74 +	CreateSpriteL(aScreenSize,aGroup,aUseSeparateMask);
    1.75 +	LoadDllL();
    1.76 +	}
    1.77 +
    1.78 +void CHandWriting::CreateSpriteL(TSize aScreenSize,RWindowGroup& aGroup,TBool aUseSeparateMask)
    1.79 +	{
    1.80 +	TInt color,gray;		//Unused variables
    1.81 +	TDisplayMode mode=iSession.GetDefModeMaxNumColors(color,gray);
    1.82 +	iBitmap=new(ELeave) CFbsBitmap();
    1.83 +	User::LeaveIfError(iBitmap->Create(aScreenSize,mode));
    1.84 +	TSpriteMember member;
    1.85 +	member.iMaskBitmap=iBitmap;
    1.86 +	if (aUseSeparateMask)
    1.87 +		{
    1.88 +		iMaskBitmap=new(ELeave) CFbsBitmap();
    1.89 +		User::LeaveIfError(iMaskBitmap->Create(aScreenSize,mode));
    1.90 +		member.iMaskBitmap=iMaskBitmap;
    1.91 +		}
    1.92 +	User::LeaveIfError(iSprite.Construct(aGroup,TPoint(),ESpriteNoChildClip|ESpriteNoShadows));
    1.93 +	FillInSpriteMember(member);
    1.94 +	iSprite.AppendMember(member);
    1.95 +	}
    1.96 +
    1.97 +void CHandWriting::LoadDllL()
    1.98 +	{
    1.99 +	_LIT(DllName,"HandAnim.DLL");
   1.100 +	TInt err=iAnimDll.Load(DllName);
   1.101 +	if (err==KErrNone)
   1.102 +		err=iAnim.Construct(iSprite);
   1.103 +	if (err==KErrNone)
   1.104 +		{
   1.105 +		iAnim.Activate();
   1.106 +		iActive=ETrue;
   1.107 +		}
   1.108 +	User::LeaveIfError(err);
   1.109 +	}
   1.110 +
   1.111 +CHandWriting::~CHandWriting()
   1.112 +	{
   1.113 +	delete iBitmap;
   1.114 +	delete iMaskBitmap;
   1.115 +	iSprite.Close();
   1.116 +	iAnimDll.Close();
   1.117 +	}
   1.118 +
   1.119 +void CHandWriting::SetMaskL(TBool aUseSeparateMask)
   1.120 +	{
   1.121 +	if ((iMaskBitmap!=NULL)==aUseSeparateMask)
   1.122 +		return;
   1.123 +	TSpriteMember member;
   1.124 +	FillInSpriteMember(member);
   1.125 +	if (aUseSeparateMask)
   1.126 +		{
   1.127 +		iMaskBitmap=new(ELeave) CFbsBitmap();
   1.128 +		member.iMaskBitmap=iMaskBitmap;
   1.129 +		}
   1.130 +	else
   1.131 +		{
   1.132 +		member.iMaskBitmap=iBitmap;
   1.133 +		}
   1.134 +	if (iActive)
   1.135 +		iAnim.Deactivate();
   1.136 +	iSprite.UpdateMember(1,member);
   1.137 +	TInt err=iAnim.SpriteMaskChange(aUseSeparateMask);
   1.138 +	if (err<0)
   1.139 +		{
   1.140 +		if (aUseSeparateMask)
   1.141 +			{
   1.142 +			delete iMaskBitmap;
   1.143 +			iMaskBitmap=NULL;
   1.144 +			member.iMaskBitmap=iBitmap;
   1.145 +			}
   1.146 +		else
   1.147 +			{
   1.148 +			member.iMaskBitmap=iMaskBitmap;
   1.149 +			}
   1.150 +		iSprite.UpdateMember(1,member);
   1.151 +		}
   1.152 +	else if (!aUseSeparateMask)
   1.153 +		{
   1.154 +		delete iMaskBitmap;
   1.155 +		iMaskBitmap=NULL;
   1.156 +		}
   1.157 +	if (iActive)
   1.158 +		iAnim.Activate();
   1.159 +	User::LeaveIfError(err);
   1.160 +	}
   1.161 +
   1.162 +void CHandWriting::ToggleStatus()
   1.163 +	{
   1.164 +	if (iActive)
   1.165 +		iAnim.Deactivate();
   1.166 +	else
   1.167 +		iAnim.Activate();
   1.168 +	iActive=!iActive;
   1.169 +	}
   1.170 +
   1.171 +void CHandWriting::FillInSpriteMember(TSpriteMember& aMember)
   1.172 +	{
   1.173 +	aMember.iBitmap=iBitmap;
   1.174 +	aMember.iInvertMask=ETrue;		//Must be inverted
   1.175 +	aMember.iDrawMode=CGraphicsContext::EDrawModePEN;		//Ignored when using mask
   1.176 +	aMember.iOffset=TPoint();		//Must be 0,0
   1.177 +	aMember.iInterval=0;		//Not used as only one TSpriteMember in sprite
   1.178 +	}