os/graphics/windowing/windowserver/nga/SERVER/openwfc/SPRITE.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
// Sprite
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include "sprite.h"
sl@0
    20
#include "rootwin.h"
sl@0
    21
#include "windowgroup.h"
sl@0
    22
#include "ScrDev.H"
sl@0
    23
#include "wstop.h"
sl@0
    24
#include "ANIM.H"
sl@0
    25
#include "panics.h"
sl@0
    26
#include "EVENT.H"
sl@0
    27
#include "bitgditomwsgraphicscontextmappings.h"
sl@0
    28
#include "../debuglog/DEBUGLOG.H"
sl@0
    29
sl@0
    30
static const TInt64 KFlashHalfSecond(500000); //interval for flashing sprites
sl@0
    31
sl@0
    32
GLDEF_D CWsDeltaTimer *CWsSpriteBase::iDeltaTimer=NULL;
sl@0
    33
sl@0
    34
TInt TimerCallBack(TAny *aPtr)
sl@0
    35
	{
sl@0
    36
	((CWsSpriteBase *)aPtr)->TimerExpired();
sl@0
    37
	return(KErrNone);
sl@0
    38
	}
sl@0
    39
sl@0
    40
#ifndef _DEBUG
sl@0
    41
sl@0
    42
#define LOG_SPRITE_REDRAW_START(sprite)
sl@0
    43
#define LOG_SPRITE_REDRAW_END(sprite)
sl@0
    44
#define LOG_SPRITE_FLASH(aSprite)
sl@0
    45
sl@0
    46
#else
sl@0
    47
sl@0
    48
#define LOG_SPRITE_REDRAW_START(sprite) LogSpriteRedrawStart(sprite)
sl@0
    49
#define LOG_SPRITE_REDRAW_END(sprite) LogSpriteRedrawEnd(sprite)
sl@0
    50
#define LOG_SPRITE_FLASH(sprite) LogSpriteFlash(sprite)
sl@0
    51
sl@0
    52
extern CDebugLogBase *wsDebugLog;
sl@0
    53
sl@0
    54
sl@0
    55
static void LogSpriteRedrawStart(const CWsSpriteBase& aSprite)
sl@0
    56
    {
sl@0
    57
    if (wsDebugLog)
sl@0
    58
        {
sl@0
    59
        _LIT(KAnnotateSpriteRedrawStart, ">> MWsDrawAnnotationObserver::FloatingSpriteRedrawStart [%S][app %d]");
sl@0
    60
        const TDesC& clientName = aSprite.WsOwner()->Client().FullName();
sl@0
    61
        TBuf<LogTBufSize> log;
sl@0
    62
        TTruncateOverflow overflow;
sl@0
    63
        log.AppendFormat(KAnnotateSpriteRedrawStart, &overflow, &clientName, aSprite.WsOwner()->ConnectionHandle());
sl@0
    64
        wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
sl@0
    65
        }
sl@0
    66
    }
sl@0
    67
sl@0
    68
static void LogSpriteRedrawEnd(const CWsSpriteBase& aSprite)
sl@0
    69
    {
sl@0
    70
    if (wsDebugLog)
sl@0
    71
        {
sl@0
    72
        _LIT(KAnnotateSpriteRedrawEnd, "<< MWsDrawAnnotationObserver::FloatingSpriteRedrawEnd [%S][app %d]");
sl@0
    73
        const TDesC& clientName = aSprite.WsOwner()->Client().FullName();
sl@0
    74
        TBuf<LogTBufSize> log;
sl@0
    75
        TTruncateOverflow overflow;
sl@0
    76
        log.AppendFormat(KAnnotateSpriteRedrawEnd, &overflow, &clientName, aSprite.WsOwner()->ConnectionHandle());
sl@0
    77
        wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
sl@0
    78
        }
sl@0
    79
    }
sl@0
    80
sl@0
    81
static void LogSpriteFlash(const CWsSpriteBase& /*aSprite*/)
sl@0
    82
    {
sl@0
    83
    if (wsDebugLog)
sl@0
    84
        {
sl@0
    85
        // The following code causes Exception and is commented out, see defect GFX09962
sl@0
    86
        
sl@0
    87
//      _LIT(KAnnotateSpriteFlash, "-- MWsDrawAnnotationObserver::SpriteFlash:%d [%S][app %d]");
sl@0
    88
//      const TDesC& clientName = aSprite.WsOwner()->Client().FullName();
sl@0
    89
//      TBuf<LogTBufSize> log;
sl@0
    90
//      TTruncateOverflow overflow;
sl@0
    91
//      log.AppendFormat(KAnnotateSpriteFlash, &overflow, &clientName, aSprite.WsOwner()->ConnectionHandle());
sl@0
    92
//      wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
sl@0
    93
                
sl@0
    94
        // This code is temporarily here until above problem is resolved
sl@0
    95
        _LIT(KAnnotateSpriteFlash, "-- MWsDrawAnnotationObserver::SpriteFlash");
sl@0
    96
        TBuf<LogTBufSize> log;
sl@0
    97
        log.AppendFormat(KAnnotateSpriteFlash);
sl@0
    98
        wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
sl@0
    99
        }
sl@0
   100
    }
sl@0
   101
sl@0
   102
sl@0
   103
#endif
sl@0
   104
sl@0
   105
sl@0
   106
sl@0
   107
static void AnnotateSpriteRedrawStart(const CWsSpriteBase& aSprite, const TRegion& aRegion)
sl@0
   108
	{
sl@0
   109
	LOG_SPRITE_REDRAW_START(aSprite);
sl@0
   110
	MWsDrawAnnotationObserver* annoObs = aSprite.Screen()->DrawAnnotationObserver();
sl@0
   111
	if(annoObs)
sl@0
   112
		{
sl@0
   113
		annoObs->SpriteRedrawStart(aSprite, aRegion);
sl@0
   114
		}
sl@0
   115
	}
sl@0
   116
sl@0
   117
static void AnnotateSpriteRedrawEnd(const CWsSpriteBase& aSprite)
sl@0
   118
	{
sl@0
   119
	LOG_SPRITE_REDRAW_END(aSprite);
sl@0
   120
	MWsDrawAnnotationObserver* annoObs = aSprite.Screen()->DrawAnnotationObserver();
sl@0
   121
	if(annoObs)
sl@0
   122
		{
sl@0
   123
		annoObs->SpriteRedrawEnd(aSprite);
sl@0
   124
		}		
sl@0
   125
	}
sl@0
   126
sl@0
   127
static void AnnotateSpriteFlash(const CWsSpriteBase& aSprite, TBool aFlashOn)
sl@0
   128
	{
sl@0
   129
	LOG_SPRITE_FLASH(aSprite);
sl@0
   130
	MWsDrawAnnotationObserver* annoObs = aSprite.Screen()->DrawAnnotationObserver();
sl@0
   131
	if(annoObs)
sl@0
   132
		{
sl@0
   133
		annoObs->SpriteFlash(aSprite, aFlashOn);
sl@0
   134
		}	
sl@0
   135
	}
sl@0
   136
sl@0
   137
sl@0
   138
//
sl@0
   139
// CWsSpriteMember
sl@0
   140
//
sl@0
   141
sl@0
   142
CWsSpriteMember::CWsSpriteMember()
sl@0
   143
	{
sl@0
   144
	}
sl@0
   145
sl@0
   146
CWsSpriteMember::~CWsSpriteMember()
sl@0
   147
	{
sl@0
   148
	delete iBitmap;
sl@0
   149
	delete iMaskBitmap;
sl@0
   150
	}
sl@0
   151
sl@0
   152
TBool CWsSpriteMember::SetL(const TCmdSpriteMember &aCmdSpriteMember)
sl@0
   153
	{
sl@0
   154
	if (aCmdSpriteMember.iBitmap!=0)	// Null member of sequence, time is only valid field in member data
sl@0
   155
		{
sl@0
   156
		iBitmap=new(ELeave) CFbsBitmap();
sl@0
   157
		TInt ret = iBitmap->Duplicate(aCmdSpriteMember.iBitmap);
sl@0
   158
		if (ret == KErrNoMemory)
sl@0
   159
			{
sl@0
   160
			User::Leave(ret);
sl@0
   161
			}
sl@0
   162
		if (ret != KErrNone)
sl@0
   163
			return(ETrue);
sl@0
   164
sl@0
   165
		if (aCmdSpriteMember.iMaskBitmap)
sl@0
   166
			{
sl@0
   167
			iMaskBitmap=new(ELeave) CFbsBitmap();
sl@0
   168
			TInt ret = iMaskBitmap->Duplicate(aCmdSpriteMember.iMaskBitmap);
sl@0
   169
			if (ret == KErrNoMemory)
sl@0
   170
				{
sl@0
   171
				User::Leave(ret);
sl@0
   172
				}
sl@0
   173
			if (ret != KErrNone)
sl@0
   174
				return(ETrue);
sl@0
   175
			}
sl@0
   176
		iInvertMask=aCmdSpriteMember.iInvertMask;
sl@0
   177
		iDrawMode=aCmdSpriteMember.iDrawMode;
sl@0
   178
		iOffset=aCmdSpriteMember.iOffset;
sl@0
   179
		}
sl@0
   180
	iInterval=aCmdSpriteMember.iInterval;
sl@0
   181
	return(EFalse);
sl@0
   182
	}
sl@0
   183
sl@0
   184
//
sl@0
   185
// CWsSpriteBase
sl@0
   186
//
sl@0
   187
sl@0
   188
TBool CWsSpriteBase::UpdateMemberL(CWsSpriteMember *aMember, const TCmdSpriteMember &aCmdSpriteMember)
sl@0
   189
	{
sl@0
   190
	CFbsBitmap *old=aMember->iBitmap;
sl@0
   191
	CFbsBitmap *oldMask=aMember->iMaskBitmap;
sl@0
   192
	aMember->iBitmap=NULL;
sl@0
   193
	aMember->iMaskBitmap=NULL;
sl@0
   194
	TBool ret=EFalse;
sl@0
   195
	TRAPD(err,ret=aMember->SetL(aCmdSpriteMember));
sl@0
   196
	if (err!=KErrNone)
sl@0
   197
		{
sl@0
   198
um_error:
sl@0
   199
		delete aMember->iBitmap;
sl@0
   200
		delete aMember->iMaskBitmap;
sl@0
   201
		aMember->iBitmap=old;
sl@0
   202
		aMember->iMaskBitmap=oldMask;
sl@0
   203
		User::Leave(err);
sl@0
   204
		}
sl@0
   205
	TRAP(err,CheckSizesL());
sl@0
   206
	if (err!=KErrNone)
sl@0
   207
		goto um_error;
sl@0
   208
	SetMember(0);
sl@0
   209
	delete old;
sl@0
   210
	delete oldMask;
sl@0
   211
	return(ret);
sl@0
   212
	}
sl@0
   213
sl@0
   214
void CWsSpriteBase::InitStaticsL()
sl@0
   215
	{
sl@0
   216
	iDeltaTimer=CWsDeltaTimer::NewL(ESpriteAnimatePriority);
sl@0
   217
	}
sl@0
   218
sl@0
   219
void CWsSpriteBase::DeleteStatics()
sl@0
   220
	{
sl@0
   221
	delete iDeltaTimer;
sl@0
   222
	}
sl@0
   223
sl@0
   224
CWsSpriteBase::CWsSpriteBase(CWsClient *owner, WH_HANDLES aType) : CWsScreenObject(owner,aType,owner->Screen())
sl@0
   225
	{
sl@0
   226
	}
sl@0
   227
sl@0
   228
CWsSpriteBase::~CWsSpriteBase()
sl@0
   229
	{
sl@0
   230
	Deactivate();
sl@0
   231
	if(IsFloating() && iGroupWin)
sl@0
   232
		{
sl@0
   233
		iGroupWin->RemoveSprite(this);
sl@0
   234
		}
sl@0
   235
	
sl@0
   236
	//iDeltaTimer->Remove(iDeltaTimerEntry);
sl@0
   237
	if (iMembers)
sl@0
   238
		{
sl@0
   239
		iMembers->ResetAndDestroy();
sl@0
   240
		delete iMembers;
sl@0
   241
		}
sl@0
   242
	}
sl@0
   243
sl@0
   244
void CWsSpriteBase::ForceRedraw()
sl@0
   245
	{
sl@0
   246
	TRegionFix<1> region;
sl@0
   247
	region.AddRect(Rect());
sl@0
   248
	Screen()->AddRedrawRegion(region);
sl@0
   249
	}
sl@0
   250
sl@0
   251
void CWsSpriteBase::Deactivate()
sl@0
   252
	{
sl@0
   253
	//Disconnect from the sprite list and hide the sprite
sl@0
   254
	if (iFlags & ESpriteActive)
sl@0
   255
		{
sl@0
   256
		iFlags&=~ESpriteActive;
sl@0
   257
		
sl@0
   258
		MWsWindowTreeObserver* const windowTreeObserver = Screen()->WindowTreeObserver();
sl@0
   259
		if (windowTreeObserver)
sl@0
   260
			{
sl@0
   261
			windowTreeObserver->NodeReleased(*this);
sl@0
   262
			}
sl@0
   263
		
sl@0
   264
		if (iMembers && iMembers->Count()>1)
sl@0
   265
			{
sl@0
   266
			iDeltaTimer->Remove(iDeltaTimerEntry);
sl@0
   267
			}
sl@0
   268
		
sl@0
   269
		if (IsFloating())
sl@0
   270
			{
sl@0
   271
			Screen()->SpriteManager()->RemoveFloatingSprite(this);
sl@0
   272
			if (!Screen()->ChangeTracking())
sl@0
   273
				{
sl@0
   274
				ForceRedraw();
sl@0
   275
				}
sl@0
   276
			}
sl@0
   277
sl@0
   278
		// Note: This could be a floating sprite attached to the root window (PDEF138379)
sl@0
   279
		if(iWin)
sl@0
   280
			{
sl@0
   281
			iWin->RemoveSprite(this);
sl@0
   282
			}
sl@0
   283
		}
sl@0
   284
	}
sl@0
   285
sl@0
   286
/** Called from groupwin destructor only */
sl@0
   287
void CWsSpriteBase::DisconnectGroupWin()
sl@0
   288
	{
sl@0
   289
	WS_ASSERT_DEBUG(IsFloating(),EWsPanicFloatingSprite);
sl@0
   290
	iGroupWin=NULL;
sl@0
   291
	}
sl@0
   292
sl@0
   293
void CWsSpriteBase::CheckSizesL()
sl@0
   294
	{
sl@0
   295
	iMaxSize.SetSize(0,0);
sl@0
   296
	for(TInt index=0;index<iMembers->Count();index++)
sl@0
   297
		{
sl@0
   298
		CWsSpriteMember *wsm=(*iMembers)[index];
sl@0
   299
		if (wsm->iBitmap)
sl@0
   300
			{
sl@0
   301
			TSize size=wsm->iBitmap->SizeInPixels();
sl@0
   302
			if (wsm->iMaskBitmap)
sl@0
   303
				{
sl@0
   304
				TSize maskSize=wsm->iMaskBitmap->SizeInPixels();
sl@0
   305
				if (maskSize.iWidth<size.iWidth || maskSize.iHeight<size.iHeight)
sl@0
   306
					OwnerPanic(EWservPanicMaskSize);
sl@0
   307
				}
sl@0
   308
			if (size.iWidth>iMaxSize.iWidth)
sl@0
   309
				iMaxSize.iWidth=size.iWidth;
sl@0
   310
			if (size.iHeight>iMaxSize.iHeight)
sl@0
   311
				iMaxSize.iHeight=size.iHeight;
sl@0
   312
			}
sl@0
   313
		}
sl@0
   314
	}
sl@0
   315
sl@0
   316
void CWsSpriteBase::ConstructL(TUint aFlags, CWsWindow *aWindow)
sl@0
   317
	{
sl@0
   318
	// Common part of construct for both sprites and pointer cursors
sl@0
   319
	iFlags=aFlags;
sl@0
   320
/*
sl@0
   321
	if (iFlags&ESpriteNoChildClip)
sl@0
   322
		iLink.iPriority+=ENoChildPriorityBoost;
sl@0
   323
	if (iFlags&ESpritePointer)
sl@0
   324
		iLink.iPriority+=EPointerPriorityBoost;
sl@0
   325
*/
sl@0
   326
	iWin=aWindow;
sl@0
   327
	TCallBack callback(TimerCallBack,this);
sl@0
   328
	iDeltaTimerEntry.Set(callback);
sl@0
   329
	iMembers=new(ELeave) CArrayPtrFlat<CWsSpriteMember>(10);
sl@0
   330
	}
sl@0
   331
sl@0
   332
void CWsSpriteBase::AppendMemberL(const TCmdSpriteMember &aCmdSpriteMember)
sl@0
   333
	{
sl@0
   334
	CWsSpriteMember *&pwsm=iMembers->ExtendL();
sl@0
   335
	pwsm=NULL;	// In case new leaves
sl@0
   336
	pwsm=new(ELeave) CWsSpriteMember();
sl@0
   337
	// coverity[leave_without_push]
sl@0
   338
	// pwsm is not owned by the stack and will be deleted by RWsSpriteBase::Close()
sl@0
   339
	if (pwsm->SetL(aCmdSpriteMember))
sl@0
   340
		OwnerPanic(EWservPanicBitmap);
sl@0
   341
	}
sl@0
   342
sl@0
   343
void CWsSpriteBase::CompleteL()
sl@0
   344
	{
sl@0
   345
	if (iMembers->Count() <= 0)
sl@0
   346
		{
sl@0
   347
		if(iWin)
sl@0
   348
			iWin->OwnerPanic(EWservPanicNoSpriteMember);
sl@0
   349
		//Not sure if this is a neccessary fall back if iWin is NULL.
sl@0
   350
		else if(iWin==NULL && iGroupWin)
sl@0
   351
			iGroupWin->OwnerPanic(EWservPanicNoSpriteMember);
sl@0
   352
		}
sl@0
   353
	else
sl@0
   354
		{
sl@0
   355
		iMembers->Compress();
sl@0
   356
		CheckSizesL();
sl@0
   357
		SetMember(0);
sl@0
   358
		}
sl@0
   359
	}
sl@0
   360
sl@0
   361
void CWsSpriteBase::Activate()
sl@0
   362
	{
sl@0
   363
	if (iFlags&ESpriteDisabled)
sl@0
   364
		{
sl@0
   365
		iFlags&=~ESpriteDisabled;
sl@0
   366
		}
sl@0
   367
	if (iMembers->Count()>1)
sl@0
   368
		{
sl@0
   369
		QueueDeltaTimer();
sl@0
   370
		iDeltaTimer->Activate();
sl@0
   371
		}
sl@0
   372
	iFlags|=ESpriteActive;
sl@0
   373
	if(iWin)	
sl@0
   374
		iWin->AddSprite(this);
sl@0
   375
	SetDirty(ETrue);
sl@0
   376
	Screen()->SpriteManager()->Schedule(this);
sl@0
   377
	if(IsFloating())
sl@0
   378
		{		
sl@0
   379
		Screen()->SpriteManager()->AddFloatingSprite(this);
sl@0
   380
		if (!Screen()->ChangeTracking())
sl@0
   381
			ForceRedraw();
sl@0
   382
		}
sl@0
   383
	
sl@0
   384
sl@0
   385
	// As custom text cursors are sprites (CWsCustomTextCursor) and can be activated/deactivated
sl@0
   386
	// on various different windows during their lifetime, when activating
sl@0
   387
	// a text cursor, we pretend it's just been created to give us the option
sl@0
   388
	// of specifying a new parent window. Normal sprites (CWsSprite) are
sl@0
   389
	// treated the same way just for consistency as it does no harm.
sl@0
   390
	MWsWindowTreeObserver* const windowTreeObserver = Screen()->WindowTreeObserver();
sl@0
   391
	if (windowTreeObserver)
sl@0
   392
		{
sl@0
   393
		windowTreeObserver->NodeCreated(*this, ParentNode());
sl@0
   394
		windowTreeObserver->NodeExtentChanged(*this, Rect());
sl@0
   395
		windowTreeObserver->NodeActivated(*this);
sl@0
   396
		}
sl@0
   397
	}
sl@0
   398
sl@0
   399
void CWsSpriteBase::SetMember(TInt aIndex)
sl@0
   400
	{
sl@0
   401
	const TSize oldSize = iSize;
sl@0
   402
	const TPoint oldPos = iPos;
sl@0
   403
	if(IsFloating())
sl@0
   404
		{		
sl@0
   405
		TRect rect(iPos,iSize);
sl@0
   406
		}
sl@0
   407
	iCurIndex=aIndex;
sl@0
   408
	iPos=iBasePos+(*iMembers)[iCurIndex]->iOffset;
sl@0
   409
	if ((*iMembers)[iCurIndex]->iBitmap)
sl@0
   410
		iSize=(*iMembers)[iCurIndex]->iBitmap->SizeInPixels();
sl@0
   411
	else
sl@0
   412
		iSize.SetSize(0,0);
sl@0
   413
sl@0
   414
	if (iSize.iWidth > iMaxSize.iWidth || iSize.iHeight > iMaxSize.iHeight)
sl@0
   415
		{
sl@0
   416
		WS_ASSERT_DEBUG(EFalse, EWsPanicSpriteBitmapSizeChange);
sl@0
   417
		CheckSizesL();
sl@0
   418
		}
sl@0
   419
sl@0
   420
	if(oldSize!=iSize || oldPos!=iPos)
sl@0
   421
		NotifyExtentChanged();
sl@0
   422
	
sl@0
   423
	}
sl@0
   424
sl@0
   425
void CWsSpriteBase::SetPos(const TPoint &aPos)
sl@0
   426
	{
sl@0
   427
	//Non-floating anim whose window is destroyed 
sl@0
   428
	if (!IsFloating() && iWin==NULL) 
sl@0
   429
		{ 
sl@0
   430
		OwnerPanic(EWservPanicWindowDestroyed); 
sl@0
   431
		} 
sl@0
   432
sl@0
   433
	//Floating anim whose group window is destroyed 
sl@0
   434
	if (IsFloating()  && iGroupWin==NULL && iWin->WinType() != EWinTypeRoot) 
sl@0
   435
		{ 
sl@0
   436
		OwnerPanic(EWservPanicWindowDestroyed); 
sl@0
   437
		}
sl@0
   438
	
sl@0
   439
	if(IsFloating())
sl@0
   440
		{		
sl@0
   441
		TRect rect(iPos,iSize);
sl@0
   442
		}
sl@0
   443
sl@0
   444
	iBasePos=aPos;
sl@0
   445
	TPoint newPos(iBasePos+(*iMembers)[iCurIndex]->iOffset);
sl@0
   446
	if (iPos!=newPos)
sl@0
   447
		{
sl@0
   448
		if (!Screen()->ChangeTracking())
sl@0
   449
			//Ensure the region covered by the sprite before as well as after the move gets scheduled for redraw
sl@0
   450
			Screen()->SpriteManager()->Schedule(this);
sl@0
   451
		iPos=newPos;
sl@0
   452
		if (!Screen()->ChangeTracking())
sl@0
   453
			Screen()->SpriteManager()->Schedule(this);
sl@0
   454
		NotifyExtentChanged();
sl@0
   455
		}
sl@0
   456
	}
sl@0
   457
sl@0
   458
void CWsSpriteBase::QueueDeltaTimer()
sl@0
   459
	{
sl@0
   460
	iDeltaTimer->Queue((*iMembers)[iCurIndex]->iInterval,iDeltaTimerEntry);
sl@0
   461
	}
sl@0
   462
sl@0
   463
void CWsSpriteBase::TimerExpired()
sl@0
   464
	{
sl@0
   465
	if (!Screen()->ChangeTracking())
sl@0
   466
		Screen()->SpriteManager()->Schedule(this);
sl@0
   467
	SetMember((iCurIndex+1)==iMembers->Count() ? 0 : iCurIndex+1);
sl@0
   468
	SetDirty(ETrue);
sl@0
   469
	Screen()->SpriteManager()->Schedule(this);
sl@0
   470
	QueueDeltaTimer();
sl@0
   471
	}
sl@0
   472
sl@0
   473
TPoint CWsSpriteBase::Pos() const
sl@0
   474
	{
sl@0
   475
	if (iGroupWin || iWin==NULL || iWin->WinType() == EWinTypeRoot )
sl@0
   476
		{
sl@0
   477
		return(iPos);
sl@0
   478
		}
sl@0
   479
	return(iPos+iWin->Origin());
sl@0
   480
	}
sl@0
   481
sl@0
   482
TRect CWsSpriteBase::Rect() const
sl@0
   483
	{
sl@0
   484
	TRect rect;
sl@0
   485
	rect.iTl=Pos();
sl@0
   486
	rect.iBr=rect.iTl+iSize;
sl@0
   487
	return(rect);
sl@0
   488
	}
sl@0
   489
sl@0
   490
MWsSprite::TSpriteType CWsSpriteBase::SpriteType() const
sl@0
   491
	{
sl@0
   492
	if (IsFloating())
sl@0
   493
		return EFloatingSprite;
sl@0
   494
sl@0
   495
	TSpriteType spriteType = EWindowSprite; 
sl@0
   496
	switch(Type())
sl@0
   497
		{
sl@0
   498
	case WS_HANDLE_SPRITE:
sl@0
   499
		spriteType = EWindowSprite;
sl@0
   500
		break;
sl@0
   501
	case WS_HANDLE_POINTER_CURSOR:
sl@0
   502
		spriteType = EPointerCursorSprite;
sl@0
   503
		break;
sl@0
   504
	case WS_HANDLE_TEXT_CURSOR:
sl@0
   505
		spriteType = ECustomTextCursorSprite;
sl@0
   506
		break;
sl@0
   507
	default:
sl@0
   508
		ASSERT(0);
sl@0
   509
		}
sl@0
   510
	return spriteType;
sl@0
   511
	}
sl@0
   512
sl@0
   513
void CWsSpriteBase::CommandL(TInt aOpcode, const TAny *aCmdData)
sl@0
   514
	{
sl@0
   515
	TWsSpriteCmdUnion pData;
sl@0
   516
sl@0
   517
	pData.any=aCmdData;
sl@0
   518
	switch(aOpcode)
sl@0
   519
		{
sl@0
   520
		case EWsSpriteOpAppendMember:
sl@0
   521
			AppendMemberL(*pData.SpriteMember);
sl@0
   522
			break;
sl@0
   523
		case EWsSpriteOpActivate:
sl@0
   524
			if(!(iFlags&ESpriteActive))
sl@0
   525
				CompleteL();
sl@0
   526
			break;
sl@0
   527
		case EWsSpriteOpUpdateMember:
sl@0
   528
			if (pData.UpdateMember->index==iCurIndex)
sl@0
   529
				{
sl@0
   530
				SetDirty(ETrue);
sl@0
   531
				TRect rect(Pos(), iMaxSize);
sl@0
   532
				Screen()->SpriteManager()->Schedule(this,&rect);
sl@0
   533
				}
sl@0
   534
			break;
sl@0
   535
		case EWsSpriteOpUpdateMember2:
sl@0
   536
			{
sl@0
   537
			SetDirty(ETrue);
sl@0
   538
			Screen()->SpriteManager()->Schedule(this);
sl@0
   539
			if (pData.UpdateMember->index<0 || pData.UpdateMember->index>=iMembers->Count())
sl@0
   540
				User::Leave(KErrArgument);
sl@0
   541
			CWsSpriteMember *member=(*iMembers)[pData.UpdateMember->index];
sl@0
   542
			TBool ret=EFalse;
sl@0
   543
			TRAPD(err,ret=UpdateMemberL(member,pData.UpdateMember->data));
sl@0
   544
			if (err==KErrNone)
sl@0
   545
				{
sl@0
   546
				TRAP(err,CheckSizesL());
sl@0
   547
				SetMember(0);
sl@0
   548
				}
sl@0
   549
			Screen()->SpriteManager()->Schedule(this);
sl@0
   550
			User::LeaveIfError(err);
sl@0
   551
			if (ret)
sl@0
   552
				OwnerPanic(EWservPanicBitmap);
sl@0
   553
			}
sl@0
   554
			break;
sl@0
   555
		default:
sl@0
   556
			OwnerPanic(EWservPanicOpcode);
sl@0
   557
			break;
sl@0
   558
		}
sl@0
   559
	}
sl@0
   560
sl@0
   561
TBool CWsSpriteBase::CanBeSeen() const
sl@0
   562
	{
sl@0
   563
	if(iWin)
sl@0
   564
		return (!(iFlags&ESpriteDisabled)) && (!iWin->VisibleRegion().IsEmpty());
sl@0
   565
	else 
sl@0
   566
		return (!(iFlags&ESpriteDisabled));
sl@0
   567
	}
sl@0
   568
sl@0
   569
void CWsSpriteBase::CalcRedrawRegion(const TRegion& aSourceRegion, TRegion& aTarget) const
sl@0
   570
	{
sl@0
   571
	aTarget.Copy(aSourceRegion);
sl@0
   572
	if (ClipSprite())
sl@0
   573
		{
sl@0
   574
		TPoint origin(0,0);
sl@0
   575
		if(iWin)
sl@0
   576
			origin = iWin->Origin();
sl@0
   577
		TRect rect(iBasePos + origin + iClipOffset, iClipSize);
sl@0
   578
		aTarget.ClipRect(rect);
sl@0
   579
		}
sl@0
   580
	aTarget.ClipRect(RootWindow()->Abs());
sl@0
   581
sl@0
   582
	// Only need to draw if the region being redrawn overlaps the sprite
sl@0
   583
	const TRect spriteRect(Pos(), iSize);
sl@0
   584
	STACK_REGION spriteRegion;
sl@0
   585
	spriteRegion.AddRect(spriteRect);
sl@0
   586
	aTarget.Intersect(spriteRegion);
sl@0
   587
	spriteRegion.Close();
sl@0
   588
	}
sl@0
   589
sl@0
   590
/**
sl@0
   591
 @pre	CWsSpriteBase::CalcRedrawRegion(TRegion&,TRegion&) should have been called.
sl@0
   592
 @param aRegion Is the region that will definitely be redrawn if dirty. This param should
sl@0
   593
                be calculated by calling CalcRedrawRegion(TRegion&,TRegion&)
sl@0
   594
 */
sl@0
   595
void CWsSpriteBase::Redraw(MWsGraphicsContext * aGc, const TRegion& aRegion)
sl@0
   596
	{
sl@0
   597
	TFlashState currentState=EFlashOn;
sl@0
   598
	if(IsFlashingEnabled())
sl@0
   599
		{
sl@0
   600
		currentState=Screen()->SpriteManager()->CurrentSpriteFlashState(this);
sl@0
   601
		AnnotateSpriteFlash(*this, currentState==EFlashOn);
sl@0
   602
		}
sl@0
   603
sl@0
   604
	if(currentState==EFlashOn && (IsDirty() || HasAnimation()) )
sl@0
   605
		{
sl@0
   606
		const TRegion * pr = &aRegion;
sl@0
   607
sl@0
   608
		if (pr->CheckError())
sl@0
   609
			{
sl@0
   610
			if(iWin)
sl@0
   611
				{
sl@0
   612
				if (Screen()->ChangeTracking())
sl@0
   613
					pr = &iWin->WindowArea();
sl@0
   614
				else
sl@0
   615
					pr = &iWin->VisibleRegion();
sl@0
   616
				}
sl@0
   617
			else
sl@0
   618
				pr = &RootWindow()->WindowArea();
sl@0
   619
			}
sl@0
   620
sl@0
   621
		if (!pr->IsEmpty())
sl@0
   622
			{
sl@0
   623
			CWsSpriteMember *member=(*iMembers)[iCurIndex];
sl@0
   624
			if (member->iBitmap)
sl@0
   625
				{
sl@0
   626
				aGc->SetClippingRegion(*pr);
sl@0
   627
sl@0
   628
				// Calculate which piece (rect) of the bitmap needs to be drawn
sl@0
   629
				const TRect redrawRect = pr->BoundingRect();
sl@0
   630
				TRect bitmapRect(Pos(), iSize); // sprite rect relative to screen
sl@0
   631
				bitmapRect.Intersection(redrawRect);
sl@0
   632
				bitmapRect.Move(-Pos()); // adjust relative to bitmap origin
sl@0
   633
sl@0
   634
				if (member->iMaskBitmap)
sl@0
   635
					aGc->BitBltMasked(Pos() + bitmapRect.iTl, *member->iBitmap, bitmapRect, *member->iMaskBitmap, member->iInvertMask);
sl@0
   636
				else
sl@0
   637
					{
sl@0
   638
					aGc->SetDrawMode(BitGdiToMWsGraphicsContextMappings::LossyConvert(member->iDrawMode));
sl@0
   639
					aGc->BitBlt(Pos() + bitmapRect.iTl, *member->iBitmap, bitmapRect);
sl@0
   640
					aGc->SetDrawMode(MWsGraphicsContext::EDrawModePEN);
sl@0
   641
					}
sl@0
   642
				aGc->ResetClippingRegion();
sl@0
   643
				}
sl@0
   644
			}
sl@0
   645
		if (Screen()->ChangeTracking())
sl@0
   646
			SetDirty(EFalse);
sl@0
   647
		
sl@0
   648
		}
sl@0
   649
		
sl@0
   650
	//Flashing sprites need to reschedule themselves after drawing (unless they have
sl@0
   651
	//an animation, because for animating sprites the rescheduling is done in CWsAnim).
sl@0
   652
	if(IsFlashingEnabled() && !HasAnimation())
sl@0
   653
		Screen()->SpriteManager()->Schedule(this);
sl@0
   654
	}
sl@0
   655
sl@0
   656
TBool CWsSpriteBase::IsActivated() const
sl@0
   657
	{
sl@0
   658
	return(iFlags&ESpriteActive);
sl@0
   659
	}
sl@0
   660
sl@0
   661
void CWsSpriteBase::SendState(MWsWindowTreeObserver& aWindowTreeObserver) const
sl@0
   662
	{
sl@0
   663
	if(iNext)
sl@0
   664
		iNext->SendState(aWindowTreeObserver);
sl@0
   665
	
sl@0
   666
	if(IsActivated())
sl@0
   667
		{
sl@0
   668
		//Sprite NodeCreated must only be sent if activated
sl@0
   669
		aWindowTreeObserver.NodeCreated(*this, ParentNode());
sl@0
   670
		aWindowTreeObserver.NodeExtentChanged(*this, Rect());
sl@0
   671
		aWindowTreeObserver.NodeActivated(*this);
sl@0
   672
		}
sl@0
   673
	}
sl@0
   674
sl@0
   675
/** @see MWsWindowTreeNode */
sl@0
   676
MWsWindowTreeNode::TType CWsSpriteBase::NodeType() const
sl@0
   677
	{
sl@0
   678
	return MWsWindowTreeNode::EWinTreeNodeSprite; 
sl@0
   679
	}
sl@0
   680
sl@0
   681
/** @see MWsWindowTreeNode */
sl@0
   682
const MWsWindow* CWsSpriteBase::Window() const
sl@0
   683
	{
sl@0
   684
	return NULL;
sl@0
   685
	}
sl@0
   686
sl@0
   687
/** @see MWsWindowTreeNode */
sl@0
   688
const MWsSprite* CWsSpriteBase::Sprite() const
sl@0
   689
	{
sl@0
   690
	return this;
sl@0
   691
	}
sl@0
   692
sl@0
   693
/** @see MWsWindowTreeNode */
sl@0
   694
const MWsStandardTextCursor* CWsSpriteBase::StandardTextCursor() const
sl@0
   695
	{
sl@0
   696
	return NULL;
sl@0
   697
	}
sl@0
   698
sl@0
   699
/** @see MWsWindowTreeNode */
sl@0
   700
const MWsWindowGroup* CWsSpriteBase::WindowGroup() const
sl@0
   701
	{
sl@0
   702
	if(iWin)
sl@0
   703
		return iWin->WindowGroup();
sl@0
   704
	else if (iGroupWin) 
sl@0
   705
		return static_cast<MWsWindowGroup*>(iGroupWin); //floating Sprite
sl@0
   706
	
sl@0
   707
	WS_ASSERT_DEBUG(EFalse,EWsPanicInvalidOperation);
sl@0
   708
	return NULL;
sl@0
   709
	}
sl@0
   710
sl@0
   711
/** @see MWsWindowTreeNode */
sl@0
   712
const MWsWindowTreeNode* CWsSpriteBase::ParentNode() const
sl@0
   713
	{
sl@0
   714
	if (iWin)
sl@0
   715
		return iWin;
sl@0
   716
	else if (iGroupWin)
sl@0
   717
		return iGroupWin->BaseParent(); //floating Sprite, will return the rootwin
sl@0
   718
	
sl@0
   719
	WS_ASSERT_DEBUG(EFalse,EWsPanicInvalidOperation);
sl@0
   720
	return NULL;
sl@0
   721
	}
sl@0
   722
sl@0
   723
void CWsSpriteBase::NotifyExtentChanged() const
sl@0
   724
	{
sl@0
   725
	if (Screen())
sl@0
   726
		{
sl@0
   727
		MWsWindowTreeObserver* windowTreeObserver = Screen()->WindowTreeObserver();
sl@0
   728
		if (windowTreeObserver && iFlags&ESpriteActive)
sl@0
   729
			{
sl@0
   730
			windowTreeObserver->NodeExtentChanged(*this, Rect());
sl@0
   731
			}
sl@0
   732
		}
sl@0
   733
	}
sl@0
   734
sl@0
   735
//
sl@0
   736
// CWsSprite
sl@0
   737
//
sl@0
   738
sl@0
   739
CWsSprite::CWsSprite(CWsClient *owner) : CWsSpriteBase(owner,WS_HANDLE_SPRITE)
sl@0
   740
	{
sl@0
   741
	}
sl@0
   742
sl@0
   743
CWsSprite::~CWsSprite()
sl@0
   744
	{
sl@0
   745
	if (!IsFloating() && IsActivated() && iWin && iWin->IsVisible() && !Screen()->ChangeTracking())
sl@0
   746
	    ForceRedraw();
sl@0
   747
	if (iAnim)
sl@0
   748
		CWsAnim::CloseAnim(iAnim);
sl@0
   749
	}
sl@0
   750
sl@0
   751
void CWsSprite::ConstructL(const TWsClCmdCreateSprite &aParams)
sl@0
   752
	{
sl@0
   753
	NewObjL();
sl@0
   754
	CWsWindowBase *win;
sl@0
   755
	WsOwner()->HandleToWindow(aParams.window,&win);
sl@0
   756
	WS_ASSERT_DEBUG(win,EWsPanicWindowNull);
sl@0
   757
	if (win->WinType()==EWinTypeGroup)
sl@0
   758
		{
sl@0
   759
		//If a sprite is attached to a group window it is floating. 
sl@0
   760
		//Floating sprite drawing is performed by the sprite manager.
sl@0
   761
		iGroupWin=(CWsWindowGroup *)win;
sl@0
   762
		win=NULL; //Floating sprites aren't associated with any particular window.
sl@0
   763
		SetIsFloating(ETrue);
sl@0
   764
		//In case the GroupWin is destroyed before the sprite it needs to call DisconnectGroupWin 
sl@0
   765
		iGroupWin->AddSprite(this);
sl@0
   766
		}
sl@0
   767
	CWsSpriteBase::ConstructL(aParams.flags&ESpriteNonSystemFlags,(CWsWindow *)win);
sl@0
   768
	iBasePos=aParams.pos;
sl@0
   769
	}
sl@0
   770
sl@0
   771
void CWsSprite::CompleteL()
sl@0
   772
	{
sl@0
   773
	CWsSpriteBase::CompleteL();
sl@0
   774
	Activate();
sl@0
   775
	}
sl@0
   776
sl@0
   777
void CWsSprite::CommandL(TInt aOpcode, const TAny *aCmdData)
sl@0
   778
	{
sl@0
   779
	TWsSpriteCmdUnion pData;
sl@0
   780
	pData.any=aCmdData;
sl@0
   781
	switch(aOpcode)
sl@0
   782
		{
sl@0
   783
		case EWsSpriteOpSetPosition:
sl@0
   784
			SetPos(*pData.Point);
sl@0
   785
			break;
sl@0
   786
		case EWsSpriteOpFree:
sl@0
   787
			{
sl@0
   788
			delete this;
sl@0
   789
			break;
sl@0
   790
			}
sl@0
   791
		default:
sl@0
   792
			CWsSpriteBase::CommandL(aOpcode, aCmdData);
sl@0
   793
			break;
sl@0
   794
		}
sl@0
   795
	}
sl@0
   796
sl@0
   797
/**
sl@0
   798
@see MAnimSpriteFunctions::UpdateMember
sl@0
   799
@param aFullUpdate	Not used. Wserv2 always do full back to front rendering, so there is no distinction between changes needing aFullUpdate or not 
sl@0
   800
 */
sl@0
   801
void CWsSprite::Update(TInt aMember,TRect aRect,TBool /*aFullUpdate*/) 
sl@0
   802
	{
sl@0
   803
	if (iCurIndex!=aMember)
sl@0
   804
		return;
sl@0
   805
	aRect.Move(Pos());
sl@0
   806
	aRect.Intersection(iScreen->CurrentScreenSize());
sl@0
   807
	SetDirty(ETrue);
sl@0
   808
	Screen()->SpriteManager()->Schedule(this, &aRect);
sl@0
   809
	}
sl@0
   810
sl@0
   811
//
sl@0
   812
// CWsPointerCursor
sl@0
   813
//
sl@0
   814
sl@0
   815
CWsPointerCursor::CWsPointerCursor(CWsClient *owner) : CWsSpriteBase(owner,WS_HANDLE_POINTER_CURSOR)
sl@0
   816
	{
sl@0
   817
	}
sl@0
   818
sl@0
   819
void CWsPointerCursor::CloseObject()
sl@0
   820
	{
sl@0
   821
	RemoveFromIndex();
sl@0
   822
	Close();
sl@0
   823
	}
sl@0
   824
sl@0
   825
void CWsPointerCursor::Close()
sl@0
   826
	{
sl@0
   827
	WS_ASSERT_DEBUG(iAccessCount>0, EWsPanicPointerCursorAccessCount);
sl@0
   828
	if (--iAccessCount==0)
sl@0
   829
		delete this;
sl@0
   830
	}
sl@0
   831
sl@0
   832
void CWsPointerCursor::Open()
sl@0
   833
	{
sl@0
   834
	iAccessCount++;
sl@0
   835
	}
sl@0
   836
sl@0
   837
CWsPointerCursor::~CWsPointerCursor()
sl@0
   838
	{
sl@0
   839
	WS_ASSERT_DEBUG(iAccessCount==0, EWsPanicPointerCursorAccessCount);
sl@0
   840
	}
sl@0
   841
sl@0
   842
void CWsPointerCursor::ConstructL(const TWsClCmdCreatePointerCursor &aParams)
sl@0
   843
	{
sl@0
   844
	NewObjL();
sl@0
   845
	SetIsFloating(ETrue);
sl@0
   846
	CWsSpriteBase::ConstructL(ESpriteNoShadows|ESpriteNoChildClip|ESpritePointer|(aParams.flags&ESpriteNonSystemFlags),RootWindow());
sl@0
   847
	Open();
sl@0
   848
	}
sl@0
   849
sl@0
   850
void CWsPointerCursor::CommandL(TInt aOpcode, const TAny *aCmdData)
sl@0
   851
	{
sl@0
   852
	switch(aOpcode)
sl@0
   853
		{
sl@0
   854
		case EWsSpriteOpFree:
sl@0
   855
			CloseObject();
sl@0
   856
			break;
sl@0
   857
		default:
sl@0
   858
			CWsSpriteBase::CommandL(aOpcode, aCmdData);
sl@0
   859
			break;
sl@0
   860
		}
sl@0
   861
	}
sl@0
   862
sl@0
   863
//
sl@0
   864
// CWsCustomTextCursor
sl@0
   865
//
sl@0
   866
sl@0
   867
CWsCustomTextCursor::CWsCustomTextCursor (CWsClient *aOwner, RWsSession::TCustomTextCursorAlignment aAlignment) 
sl@0
   868
: CWsSpriteBase(aOwner, WS_HANDLE_TEXT_CURSOR), iAlignment(aAlignment)
sl@0
   869
	{
sl@0
   870
	}
sl@0
   871
sl@0
   872
CWsCustomTextCursor::~CWsCustomTextCursor()
sl@0
   873
	{
sl@0
   874
	}
sl@0
   875
sl@0
   876
void CWsCustomTextCursor::ConstructL(TInt aFlags)
sl@0
   877
	{
sl@0
   878
	NewObjL();
sl@0
   879
	CWsSpriteBase::ConstructL(ESpriteNoShadows|ESpriteNoChildClip|ESpritePointer|(aFlags&ESpriteNonSystemFlags), NULL);
sl@0
   880
	}
sl@0
   881
sl@0
   882
void CWsCustomTextCursor::CompleteL(CWsWindow *aWin, TBool aFlash, TBool aClipSprite, const TPoint& aClipOffset, const TSize& aClipSize)
sl@0
   883
	{
sl@0
   884
	iWin = aWin;
sl@0
   885
	iFlags = aFlash ? iFlags | ESpriteFlash : iFlags & ~ESpriteFlash;
sl@0
   886
	SetClipSprite(aClipSprite);
sl@0
   887
	iClipOffset = aClipOffset;
sl@0
   888
	iClipSize = aClipSize;
sl@0
   889
	CWsSpriteBase::CompleteL();
sl@0
   890
	}
sl@0
   891
sl@0
   892
// Use SetPositionNoRedraw instead of SetPos when you just want to update
sl@0
   893
// the custom text cursor position without redrawing it
sl@0
   894
void CWsCustomTextCursor::SetPositionNoRedraw(const TPoint& aPos)
sl@0
   895
	{
sl@0
   896
	iBasePos = aPos;
sl@0
   897
	TPoint newPos(iBasePos+(*iMembers)[iCurIndex]->iOffset);
sl@0
   898
	iPos=newPos;
sl@0
   899
	}
sl@0
   900
sl@0
   901
void CWsCustomTextCursor::CommandL(TInt aOpcode, const TAny *aCmdData)
sl@0
   902
	{
sl@0
   903
	switch(aOpcode)
sl@0
   904
		{
sl@0
   905
		case EWsSpriteOpFree:
sl@0
   906
			// CWsCustomTextCursor objects are owned by the text cursor list.
sl@0
   907
			// They are not deleted when the client closes it's R class.
sl@0
   908
			RemoveFromIndex();
sl@0
   909
			break;
sl@0
   910
		default:
sl@0
   911
			CWsSpriteBase::CommandL(aOpcode, aCmdData);
sl@0
   912
			break;
sl@0
   913
		}
sl@0
   914
	}
sl@0
   915
sl@0
   916
//
sl@0
   917
// CWsDeltaTimer, nicked from CDeltaTimer and tweaked so it doesn't re-activate			//
sl@0
   918
// the timers until RunL has finished running all ready timers.							//
sl@0
   919
//																						//
sl@0
   920
// This is to stop a problem in Wserv where sprites could hog 100% CPU if the time		//
sl@0
   921
// it took to process them was longer than the time of the timer queued when the first	//
sl@0
   922
// sprite was updated																	//
sl@0
   923
//
sl@0
   924
sl@0
   925
CWsDeltaTimer* CWsDeltaTimer::NewL(TInt aPriority)
sl@0
   926
	{
sl@0
   927
	CWsDeltaTimer* wsdt=new(ELeave) CWsDeltaTimer(aPriority);
sl@0
   928
	CleanupStack::PushL(wsdt);
sl@0
   929
	User::LeaveIfError(wsdt->iTimer.CreateLocal());
sl@0
   930
	CActiveScheduler::Add(wsdt);
sl@0
   931
	CleanupStack::Pop(wsdt);
sl@0
   932
	return(wsdt);
sl@0
   933
	}
sl@0
   934
sl@0
   935
CWsDeltaTimer::CWsDeltaTimer(TInt aPriority) : CActive(aPriority),iQueue(_FOFF(TWsDeltaTimerEntry,iLink))
sl@0
   936
	{
sl@0
   937
	}
sl@0
   938
sl@0
   939
CWsDeltaTimer::~CWsDeltaTimer()
sl@0
   940
	{
sl@0
   941
	Cancel();
sl@0
   942
	while(iQueue.RemoveFirst()!=NULL)
sl@0
   943
		{}
sl@0
   944
	}
sl@0
   945
sl@0
   946
void CWsDeltaTimer::Queue(TTimeIntervalMicroSeconds32 aTimeInMicroSeconds,TWsDeltaTimerEntry& anEntry)
sl@0
   947
	{
sl@0
   948
	TInt intervals=aTimeInMicroSeconds.Int()/CWsDeltaTimerGranularity;
sl@0
   949
	if (intervals==0)
sl@0
   950
		intervals=1;
sl@0
   951
	iQueue.Add(anEntry,intervals);
sl@0
   952
	}
sl@0
   953
sl@0
   954
void CWsDeltaTimer::Activate()
sl@0
   955
	{
sl@0
   956
	// Queue a request on the timer.
sl@0
   957
	// The timer runs every tenth of a second and decremented the delta of the head of the queue.
sl@0
   958
	if (IsActive())
sl@0
   959
		return;
sl@0
   960
	if (!iQueue.IsEmpty())
sl@0
   961
		{
sl@0
   962
		SetActive();
sl@0
   963
		iTimer.After(iStatus,CWsDeltaTimerGranularity-1); // -1 to compensate for +1 in kernel!
sl@0
   964
		}
sl@0
   965
	}
sl@0
   966
sl@0
   967
void CWsDeltaTimer::RunL()
sl@0
   968
	{
sl@0
   969
	// Call all zero delta callbacks
sl@0
   970
	iQueue.CountDown();
sl@0
   971
	TWsDeltaTimerEntry* ent=iQueue.RemoveFirst();
sl@0
   972
	while (ent)
sl@0
   973
		{       
sl@0
   974
		ent->iCallBack.CallBack();
sl@0
   975
		ent=iQueue.RemoveFirst();
sl@0
   976
		}
sl@0
   977
	Activate();
sl@0
   978
	}
sl@0
   979
sl@0
   980
void CWsDeltaTimer::DoCancel()
sl@0
   981
	{
sl@0
   982
	iTimer.Cancel();
sl@0
   983
	}
sl@0
   984
sl@0
   985
void CWsDeltaTimer::Remove(TWsDeltaTimerEntry& anEntry)
sl@0
   986
	{
sl@0
   987
	if (anEntry.IsPending())
sl@0
   988
		{
sl@0
   989
		iQueue.Remove(anEntry);
sl@0
   990
		Activate();
sl@0
   991
		}
sl@0
   992
	}
sl@0
   993
sl@0
   994
sl@0
   995
//
sl@0
   996
// CWsSpriteManager -handles floating and flashing sprites including flashing custom text cursors. i.e. cursors
sl@0
   997
//					that have an associated sprite.
sl@0
   998
sl@0
   999
sl@0
  1000
CWsSpriteManager::CWsSpriteManager()
sl@0
  1001
	{
sl@0
  1002
	}
sl@0
  1003
	
sl@0
  1004
CWsSpriteManager* CWsSpriteManager::NewL()
sl@0
  1005
	{
sl@0
  1006
	CWsSpriteManager* self = new (ELeave) CWsSpriteManager();
sl@0
  1007
	CleanupStack::PushL(self);
sl@0
  1008
	self->ConstructL();
sl@0
  1009
	CleanupStack::Pop(self);
sl@0
  1010
	return self;	
sl@0
  1011
	}
sl@0
  1012
sl@0
  1013
void CWsSpriteManager::ConstructL()
sl@0
  1014
	{
sl@0
  1015
	}
sl@0
  1016
sl@0
  1017
CWsSpriteManager::~CWsSpriteManager()
sl@0
  1018
    {
sl@0
  1019
    iFloatingSprites.ResetAndDestroy();
sl@0
  1020
    }
sl@0
  1021
void CWsSpriteManager::AddFloatingSprite(CWsSpriteBase* aSprite)
sl@0
  1022
	{
sl@0
  1023
	iFloatingSprites.Append(aSprite);
sl@0
  1024
	}
sl@0
  1025
	
sl@0
  1026
void CWsSpriteManager::RemoveFloatingSprite(CWsSpriteBase* aSprite)
sl@0
  1027
	{
sl@0
  1028
#ifdef _DEBUG 
sl@0
  1029
	TInt removed = 0; 
sl@0
  1030
#endif
sl@0
  1031
	for (TInt i=0 ; i<iFloatingSprites.Count() ; i++)
sl@0
  1032
		{
sl@0
  1033
		if(iFloatingSprites[i]==aSprite)
sl@0
  1034
			{
sl@0
  1035
			//Just remove the sprite don't delete it. the manager doesn't have ownership
sl@0
  1036
			iFloatingSprites.Remove(i);
sl@0
  1037
#ifdef _DEBUG
sl@0
  1038
			removed++;
sl@0
  1039
#else
sl@0
  1040
			break;
sl@0
  1041
#endif
sl@0
  1042
			}
sl@0
  1043
		}
sl@0
  1044
	WS_ASSERT_DEBUG(removed==1,EWsPanicFloatingSprite);
sl@0
  1045
	}
sl@0
  1046
sl@0
  1047
void CWsSpriteManager::DrawFloatingSprites(MWsGraphicsContext* aGc,const TRegion& aRegion)
sl@0
  1048
	{
sl@0
  1049
	if (iFloatingSprites.Count() == 0)
sl@0
  1050
		return; //avoid sending events unless necessary
sl@0
  1051
sl@0
  1052
	for (TInt i = iFloatingSprites.Count() - 1; i >= 0 ; i--)
sl@0
  1053
		{
sl@0
  1054
		STACK_REGION redrawRegion;
sl@0
  1055
		CWsSpriteBase* sprite = iFloatingSprites[i];
sl@0
  1056
		sprite->CalcRedrawRegion(aRegion, redrawRegion);
sl@0
  1057
		if(redrawRegion.CheckError() || !redrawRegion.IsEmpty())
sl@0
  1058
			{
sl@0
  1059
			if (sprite->IsFlashingEnabled() || sprite->IsDirty() || sprite->HasAnimation())
sl@0
  1060
				{
sl@0
  1061
				AnnotateSpriteRedrawStart(*sprite, redrawRegion);
sl@0
  1062
				
sl@0
  1063
				if(sprite->HasAnimation())
sl@0
  1064
					{
sl@0
  1065
					CWsAnim* anim = static_cast<CWsSprite*>(sprite)->iAnim;
sl@0
  1066
					ASSERT(anim);
sl@0
  1067
					
sl@0
  1068
					TRAPD(err, anim->AnimateSpriteAnimL(sprite->Screen()->Now()));
sl@0
  1069
					if(err!=KErrNone)
sl@0
  1070
						{
sl@0
  1071
						AnnotateSpriteRedrawEnd(*sprite);						
sl@0
  1072
						anim->Panic(EWservPanicAnimLeave);
sl@0
  1073
						continue;
sl@0
  1074
						}
sl@0
  1075
					}
sl@0
  1076
				
sl@0
  1077
				aGc->Reset();
sl@0
  1078
				sprite->Redraw(aGc, redrawRegion);
sl@0
  1079
				
sl@0
  1080
				AnnotateSpriteRedrawEnd(*sprite);
sl@0
  1081
				}
sl@0
  1082
			}
sl@0
  1083
		redrawRegion.Close();
sl@0
  1084
		}
sl@0
  1085
	}
sl@0
  1086
	
sl@0
  1087
void CWsSpriteManager::Schedule(CWsSpriteBase* aSprite, TRect* aRect)
sl@0
  1088
	{
sl@0
  1089
	if (aRect != NULL && aRect->IsEmpty())
sl@0
  1090
		return;
sl@0
  1091
sl@0
  1092
	TRect rect = aSprite->Rect();
sl@0
  1093
	if (aRect)
sl@0
  1094
		rect.Intersection(*aRect);
sl@0
  1095
		
sl@0
  1096
	const TAnimType type = aSprite->Win() ? EWindowSprite : EFloatingSprite;
sl@0
  1097
	
sl@0
  1098
	if(aSprite->IsFlashingEnabled())
sl@0
  1099
		{
sl@0
  1100
		aSprite->Screen()->ScheduleAnimation(type, rect,NextSpriteFlashStateChange(aSprite),0,0, aSprite->Win());
sl@0
  1101
		}
sl@0
  1102
	else
sl@0
  1103
		{
sl@0
  1104
		//Scheduling an animation "now" means it will take place at next animation which might 
sl@0
  1105
		//be the full animation grace period into the future (see KAnimationGrace in server.cpp)
sl@0
  1106
		aSprite->Screen()->ScheduleAnimation(type, rect,0,0,0, aSprite->Win());
sl@0
  1107
		}
sl@0
  1108
	}	
sl@0
  1109
sl@0
  1110
// Sprite flashing is clamped to half second intervals in relation to the global time.
sl@0
  1111
// For the first half of each second all sprites have the EFlashOn state (visible)
sl@0
  1112
// For the second half of each second all sprites have the EFlashOff state (not visible) 
sl@0
  1113
TTimeIntervalMicroSeconds CWsSpriteManager::NextSpriteFlashStateChange(const CWsSpriteBase* aSprite) const
sl@0
  1114
	{
sl@0
  1115
	const TTimeIntervalMicroSeconds remainder = aSprite->Screen()->Now().DateTime().MicroSecond();
sl@0
  1116
	return CalculateTimeToNextFlash(remainder);
sl@0
  1117
	}
sl@0
  1118
sl@0
  1119
TTimeIntervalMicroSeconds CWsSpriteManager::NextCursorFlashStateChange() const
sl@0
  1120
	{
sl@0
  1121
	const TTimeIntervalMicroSeconds remainder = CWsTop::CurrentFocusScreen()->Now().DateTime().MicroSecond();
sl@0
  1122
	return CalculateTimeToNextFlash(remainder);
sl@0
  1123
	}
sl@0
  1124
sl@0
  1125
TTimeIntervalMicroSeconds CWsSpriteManager::CalculateTimeToNextFlash(TTimeIntervalMicroSeconds aTime) const
sl@0
  1126
	{
sl@0
  1127
	TInt64 nextStateChange;
sl@0
  1128
	if(aTime<KFlashHalfSecond)
sl@0
  1129
		nextStateChange=KFlashHalfSecond-aTime.Int64();
sl@0
  1130
	else
sl@0
  1131
		nextStateChange=KFlashHalfSecond - (aTime.Int64() - KFlashHalfSecond);
sl@0
  1132
	ASSERT(nextStateChange > 0);
sl@0
  1133
	return TTimeIntervalMicroSeconds(nextStateChange);
sl@0
  1134
	}	
sl@0
  1135
	
sl@0
  1136
TFlashState CWsSpriteManager::CurrentSpriteFlashState(const CWsSpriteBase* aSprite) const
sl@0
  1137
	{
sl@0
  1138
	return (aSprite->Screen()->Now().DateTime().MicroSecond()<KFlashHalfSecond)?EFlashOn:EFlashOff;
sl@0
  1139
	}
sl@0
  1140
sl@0
  1141
void CWsSpriteManager::CalcFloatingSpriteRgn( TRegion& aResultRgn, const TRect& aDefaultRect )
sl@0
  1142
	{
sl@0
  1143
	aResultRgn.Clear();
sl@0
  1144
	for (TInt i=0 ; i<iFloatingSprites.Count() && !aResultRgn.CheckError(); i++)
sl@0
  1145
		{
sl@0
  1146
		CWsSpriteBase* sprite = iFloatingSprites[i]; 
sl@0
  1147
		if ( sprite->CanBeSeen() && ( sprite->IsActive() || sprite->IsActivated() ) )
sl@0
  1148
			{
sl@0
  1149
			aResultRgn.AddRect( sprite->Rect() );
sl@0
  1150
			}
sl@0
  1151
		}
sl@0
  1152
	aResultRgn.Tidy();
sl@0
  1153
	if ( aResultRgn.CheckError() && iFloatingSprites.Count() > 0 )
sl@0
  1154
		{
sl@0
  1155
		aResultRgn.Clear();
sl@0
  1156
		aResultRgn.AddRect( aDefaultRect );
sl@0
  1157
		}
sl@0
  1158
	}
sl@0
  1159
sl@0
  1160
void CWsSpriteManager::SendState(MWsWindowTreeObserver& aWindowTreeObserver) const
sl@0
  1161
	{
sl@0
  1162
	for(TInt i=iFloatingSprites.Count()-1; i>=0; i--)
sl@0
  1163
		{
sl@0
  1164
		CWsSpriteBase* sprite = iFloatingSprites[i];
sl@0
  1165
		sprite->SendState(aWindowTreeObserver);
sl@0
  1166
		}
sl@0
  1167
	}