os/graphics/windowing/windowserver/test/HNDLODR.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) 1999-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
// Demonstration handwriting class
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "HNDLODR.H"
sl@0
    19
sl@0
    20
sl@0
    21
/*RHandWritingAnim*/
sl@0
    22
sl@0
    23
TInt RHandWritingAnim::Construct(const RWsSprite& aDevice)
sl@0
    24
	{
sl@0
    25
	TPtrC8 des(NULL,0);
sl@0
    26
	return RAnim::Construct(aDevice,0,des);
sl@0
    27
	}
sl@0
    28
sl@0
    29
void RHandWritingAnim::Activate()
sl@0
    30
	{
sl@0
    31
	Command(EHwOpActivate);
sl@0
    32
	}
sl@0
    33
sl@0
    34
void RHandWritingAnim::Deactivate()
sl@0
    35
	{
sl@0
    36
	Command(EHwOpDeactivate);
sl@0
    37
	}
sl@0
    38
sl@0
    39
TInt RHandWritingAnim::SpriteMaskChange(TBool aUsingSeparateMask)
sl@0
    40
	{
sl@0
    41
	TPckgBuf<TBool> param;
sl@0
    42
	param()=aUsingSeparateMask;
sl@0
    43
	return CommandReply(EHwOpSpriteMask,param);
sl@0
    44
	}
sl@0
    45
sl@0
    46
void RHandWritingAnim::SetDrawData(const THandwritingDrawData& aDrawData)
sl@0
    47
	{
sl@0
    48
	TPckgBuf<THandwritingDrawData> param;
sl@0
    49
	param()=aDrawData;
sl@0
    50
	Command(EHwOpSetDrawData,param);
sl@0
    51
	}
sl@0
    52
sl@0
    53
TInt RHandWritingAnim::GetLastGeneratedCharacter()
sl@0
    54
	{
sl@0
    55
	return CommandReply(EHwOpGetLastChar);
sl@0
    56
	}
sl@0
    57
sl@0
    58
sl@0
    59
/*CHandWriting*/
sl@0
    60
sl@0
    61
CHandWriting::CHandWriting(RWsSession& aSession)
sl@0
    62
	:iSession(aSession), iAnimDll(aSession), iAnim(iAnimDll), iSprite(aSession)
sl@0
    63
	{}
sl@0
    64
sl@0
    65
void CHandWriting::ConstructL(TSize aScreenSize,RWindowGroup& aGroup,TBool aUseSeparateMask)
sl@0
    66
	//
sl@0
    67
	//This function should be called with the correct screen size and 
sl@0
    68
	//the handle of any group window that will be around as long as the handwriting is required
sl@0
    69
	//
sl@0
    70
	{
sl@0
    71
	CreateSpriteL(aScreenSize,aGroup,aUseSeparateMask);
sl@0
    72
	LoadDllL();
sl@0
    73
	}
sl@0
    74
sl@0
    75
void CHandWriting::CreateSpriteL(TSize aScreenSize,RWindowGroup& aGroup,TBool aUseSeparateMask)
sl@0
    76
	{
sl@0
    77
	TInt color,gray;		//Unused variables
sl@0
    78
	TDisplayMode mode=iSession.GetDefModeMaxNumColors(color,gray);
sl@0
    79
	iBitmap=new(ELeave) CFbsBitmap();
sl@0
    80
	User::LeaveIfError(iBitmap->Create(aScreenSize,mode));
sl@0
    81
	TSpriteMember member;
sl@0
    82
	member.iMaskBitmap=iBitmap;
sl@0
    83
	if (aUseSeparateMask)
sl@0
    84
		{
sl@0
    85
		iMaskBitmap=new(ELeave) CFbsBitmap();
sl@0
    86
		User::LeaveIfError(iMaskBitmap->Create(aScreenSize,mode));
sl@0
    87
		member.iMaskBitmap=iMaskBitmap;
sl@0
    88
		}
sl@0
    89
	User::LeaveIfError(iSprite.Construct(aGroup,TPoint(),ESpriteNoChildClip|ESpriteNoShadows));
sl@0
    90
	FillInSpriteMember(member);
sl@0
    91
	iSprite.AppendMember(member);
sl@0
    92
	}
sl@0
    93
sl@0
    94
void CHandWriting::LoadDllL()
sl@0
    95
	{
sl@0
    96
	_LIT(DllName,"HandAnim.DLL");
sl@0
    97
	TInt err=iAnimDll.Load(DllName);
sl@0
    98
	if (err==KErrNone)
sl@0
    99
		err=iAnim.Construct(iSprite);
sl@0
   100
	if (err==KErrNone)
sl@0
   101
		{
sl@0
   102
		iAnim.Activate();
sl@0
   103
		iActive=ETrue;
sl@0
   104
		}
sl@0
   105
	User::LeaveIfError(err);
sl@0
   106
	}
sl@0
   107
sl@0
   108
CHandWriting::~CHandWriting()
sl@0
   109
	{
sl@0
   110
	delete iBitmap;
sl@0
   111
	delete iMaskBitmap;
sl@0
   112
	iSprite.Close();
sl@0
   113
	iAnimDll.Close();
sl@0
   114
	}
sl@0
   115
sl@0
   116
void CHandWriting::SetMaskL(TBool aUseSeparateMask)
sl@0
   117
	{
sl@0
   118
	if ((iMaskBitmap!=NULL)==aUseSeparateMask)
sl@0
   119
		return;
sl@0
   120
	TSpriteMember member;
sl@0
   121
	FillInSpriteMember(member);
sl@0
   122
	if (aUseSeparateMask)
sl@0
   123
		{
sl@0
   124
		iMaskBitmap=new(ELeave) CFbsBitmap();
sl@0
   125
		member.iMaskBitmap=iMaskBitmap;
sl@0
   126
		}
sl@0
   127
	else
sl@0
   128
		{
sl@0
   129
		member.iMaskBitmap=iBitmap;
sl@0
   130
		}
sl@0
   131
	if (iActive)
sl@0
   132
		iAnim.Deactivate();
sl@0
   133
	iSprite.UpdateMember(1,member);
sl@0
   134
	TInt err=iAnim.SpriteMaskChange(aUseSeparateMask);
sl@0
   135
	if (err<0)
sl@0
   136
		{
sl@0
   137
		if (aUseSeparateMask)
sl@0
   138
			{
sl@0
   139
			delete iMaskBitmap;
sl@0
   140
			iMaskBitmap=NULL;
sl@0
   141
			member.iMaskBitmap=iBitmap;
sl@0
   142
			}
sl@0
   143
		else
sl@0
   144
			{
sl@0
   145
			member.iMaskBitmap=iMaskBitmap;
sl@0
   146
			}
sl@0
   147
		iSprite.UpdateMember(1,member);
sl@0
   148
		}
sl@0
   149
	else if (!aUseSeparateMask)
sl@0
   150
		{
sl@0
   151
		delete iMaskBitmap;
sl@0
   152
		iMaskBitmap=NULL;
sl@0
   153
		}
sl@0
   154
	if (iActive)
sl@0
   155
		iAnim.Activate();
sl@0
   156
	User::LeaveIfError(err);
sl@0
   157
	}
sl@0
   158
sl@0
   159
void CHandWriting::ToggleStatus()
sl@0
   160
	{
sl@0
   161
	if (iActive)
sl@0
   162
		iAnim.Deactivate();
sl@0
   163
	else
sl@0
   164
		iAnim.Activate();
sl@0
   165
	iActive=!iActive;
sl@0
   166
	}
sl@0
   167
sl@0
   168
void CHandWriting::FillInSpriteMember(TSpriteMember& aMember)
sl@0
   169
	{
sl@0
   170
	aMember.iBitmap=iBitmap;
sl@0
   171
	aMember.iInvertMask=ETrue;		//Must be inverted
sl@0
   172
	aMember.iDrawMode=CGraphicsContext::EDrawModePEN;		//Ignored when using mask
sl@0
   173
	aMember.iOffset=TPoint();		//Must be 0,0
sl@0
   174
	aMember.iInterval=0;		//Not used as only one TSpriteMember in sprite
sl@0
   175
	}