|
1 // Copyright (c) 1999-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 // Sprite |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include "sprite.h" |
|
20 #include "rootwin.h" |
|
21 #include "windowgroup.h" |
|
22 #include "ScrDev.H" |
|
23 #include "wstop.h" |
|
24 #include "ANIM.H" |
|
25 #include "offscreenbitmap.h" |
|
26 #include "panics.h" |
|
27 #include "EVENT.H" |
|
28 |
|
29 static const TInt64 KFlashHalfSecond(500000); //interval for flashing sprites |
|
30 |
|
31 GLDEF_D CWsDeltaTimer *CWsSpriteBase::iDeltaTimer=NULL; |
|
32 |
|
33 TInt TimerCallBack(TAny *aPtr) |
|
34 { |
|
35 ((CWsSpriteBase *)aPtr)->TimerExpired(); |
|
36 return(KErrNone); |
|
37 } |
|
38 |
|
39 // |
|
40 // CWsSpriteMember |
|
41 // |
|
42 |
|
43 CWsSpriteMember::CWsSpriteMember() |
|
44 { |
|
45 } |
|
46 |
|
47 CWsSpriteMember::~CWsSpriteMember() |
|
48 { |
|
49 delete iBitmap; |
|
50 delete iMaskBitmap; |
|
51 } |
|
52 |
|
53 TBool CWsSpriteMember::SetL(const TCmdSpriteMember &aCmdSpriteMember) |
|
54 { |
|
55 if (aCmdSpriteMember.iBitmap!=0) // Null member of sequence, time is only valid field in member data |
|
56 { |
|
57 iBitmap=new(ELeave) CFbsBitmap(); |
|
58 TInt ret = iBitmap->Duplicate(aCmdSpriteMember.iBitmap); |
|
59 if (ret == KErrNoMemory) |
|
60 { |
|
61 User::Leave(ret); |
|
62 } |
|
63 if (ret != KErrNone) |
|
64 return(ETrue); |
|
65 |
|
66 if (aCmdSpriteMember.iMaskBitmap) |
|
67 { |
|
68 iMaskBitmap=new(ELeave) CFbsBitmap(); |
|
69 TInt ret = iMaskBitmap->Duplicate(aCmdSpriteMember.iMaskBitmap); |
|
70 if (ret == KErrNoMemory) |
|
71 { |
|
72 User::Leave(ret); |
|
73 } |
|
74 if (ret != KErrNone) |
|
75 return(ETrue); |
|
76 } |
|
77 iInvertMask=aCmdSpriteMember.iInvertMask; |
|
78 iDrawMode=aCmdSpriteMember.iDrawMode; |
|
79 iOffset=aCmdSpriteMember.iOffset; |
|
80 } |
|
81 iInterval=aCmdSpriteMember.iInterval; |
|
82 return(EFalse); |
|
83 } |
|
84 |
|
85 // |
|
86 // CWsSpriteBase |
|
87 // |
|
88 |
|
89 TBool CWsSpriteBase::UpdateMemberL(CWsSpriteMember *aMember, const TCmdSpriteMember &aCmdSpriteMember) |
|
90 { |
|
91 CFbsBitmap *old=aMember->iBitmap; |
|
92 CFbsBitmap *oldMask=aMember->iMaskBitmap; |
|
93 aMember->iBitmap=NULL; |
|
94 aMember->iMaskBitmap=NULL; |
|
95 TBool ret=EFalse; |
|
96 TRAPD(err,ret=aMember->SetL(aCmdSpriteMember)); |
|
97 if (err!=KErrNone) |
|
98 { |
|
99 um_error: |
|
100 delete aMember->iBitmap; |
|
101 delete aMember->iMaskBitmap; |
|
102 aMember->iBitmap=old; |
|
103 aMember->iMaskBitmap=oldMask; |
|
104 User::Leave(err); |
|
105 } |
|
106 TRAP(err,CheckSizesL()); |
|
107 if (err!=KErrNone) |
|
108 goto um_error; |
|
109 SetMember(0); |
|
110 delete old; |
|
111 delete oldMask; |
|
112 return(ret); |
|
113 } |
|
114 |
|
115 void CWsSpriteBase::InitStaticsL() |
|
116 { |
|
117 iDeltaTimer=CWsDeltaTimer::NewL(ESpriteAnimatePriority); |
|
118 } |
|
119 |
|
120 void CWsSpriteBase::DeleteStatics() |
|
121 { |
|
122 delete iDeltaTimer; |
|
123 } |
|
124 |
|
125 CWsSpriteBase::CWsSpriteBase(CWsClient *owner, WH_HANDLES aType) : CWsScreenObject(owner,aType,owner->Screen()), iClipSprite(EFalse) |
|
126 { |
|
127 } |
|
128 |
|
129 CWsSpriteBase::~CWsSpriteBase() |
|
130 { |
|
131 Deactivate(); |
|
132 |
|
133 //iDeltaTimer->Remove(iDeltaTimerEntry); |
|
134 if (iMembers) |
|
135 { |
|
136 iMembers->ResetAndDestroy(); |
|
137 delete iMembers; |
|
138 } |
|
139 } |
|
140 |
|
141 void CWsSpriteBase::ForceRedraw() |
|
142 { |
|
143 TRegionFix<1> region; |
|
144 region.AddRect(Rect()); |
|
145 Screen()->AddRedrawRegion(region); |
|
146 } |
|
147 |
|
148 void CWsSpriteBase::Deactivate() |
|
149 { |
|
150 //Disconnect from the sprite list and hide the sprite |
|
151 if (iFlags & ESpriteActive) |
|
152 { |
|
153 if(iWin) |
|
154 iWin->RemoveSprite(this); |
|
155 if (iMembers && iMembers->Count()>1) |
|
156 iDeltaTimer->Remove(iDeltaTimerEntry); |
|
157 iFlags&=~ESpriteActive; |
|
158 if (iFloating) |
|
159 { |
|
160 Screen()->SpriteManager()->RemoveFloatingSprite(this); |
|
161 ForceRedraw(); |
|
162 } |
|
163 } |
|
164 } |
|
165 |
|
166 void CWsSpriteBase::CheckSizesL() |
|
167 { |
|
168 iMaxSize.SetSize(0,0); |
|
169 for(TInt index=0;index<iMembers->Count();index++) |
|
170 { |
|
171 CWsSpriteMember *wsm=(*iMembers)[index]; |
|
172 if (wsm->iBitmap) |
|
173 { |
|
174 TSize size=wsm->iBitmap->SizeInPixels(); |
|
175 if (wsm->iMaskBitmap) |
|
176 { |
|
177 TSize maskSize=wsm->iMaskBitmap->SizeInPixels(); |
|
178 if (maskSize.iWidth<size.iWidth || maskSize.iHeight<size.iHeight) |
|
179 OwnerPanic(EWservPanicMaskSize); |
|
180 } |
|
181 if (size.iWidth>iMaxSize.iWidth) |
|
182 iMaxSize.iWidth=size.iWidth; |
|
183 if (size.iHeight>iMaxSize.iHeight) |
|
184 iMaxSize.iHeight=size.iHeight; |
|
185 } |
|
186 } |
|
187 } |
|
188 |
|
189 void CWsSpriteBase::ConstructL(TUint aFlags, CWsWindow *aWindow) |
|
190 { |
|
191 // Common part of construct for both sprites and pointer cursors |
|
192 iFlags=aFlags; |
|
193 /* |
|
194 if (iFlags&ESpriteNoChildClip) |
|
195 iLink.iPriority+=ENoChildPriorityBoost; |
|
196 if (iFlags&ESpritePointer) |
|
197 iLink.iPriority+=EPointerPriorityBoost; |
|
198 */ |
|
199 iWin=aWindow; |
|
200 TCallBack callback(TimerCallBack,this); |
|
201 iDeltaTimerEntry.Set(callback); |
|
202 iMembers=new(ELeave) CArrayPtrFlat<CWsSpriteMember>(10); |
|
203 } |
|
204 |
|
205 void CWsSpriteBase::AppendMemberL(const TCmdSpriteMember &aCmdSpriteMember) |
|
206 { |
|
207 CWsSpriteMember *&pwsm=iMembers->ExtendL(); |
|
208 pwsm=NULL; // In case new leaves |
|
209 pwsm=new(ELeave) CWsSpriteMember(); |
|
210 if (pwsm->SetL(aCmdSpriteMember)) |
|
211 OwnerPanic(EWservPanicBitmap); |
|
212 } |
|
213 |
|
214 void CWsSpriteBase::CompleteL() |
|
215 { |
|
216 if (iMembers->Count() <= 0) |
|
217 { |
|
218 if(iWin) |
|
219 iWin->OwnerPanic(EWservPanicNoSpriteMember); |
|
220 //Not sure if this is a neccessary fall back if iWin is NULL. |
|
221 else if(iWin==NULL && iGroupWin) |
|
222 iGroupWin->OwnerPanic(EWservPanicNoSpriteMember); |
|
223 } |
|
224 else |
|
225 { |
|
226 iMembers->Compress(); |
|
227 CheckSizesL(); |
|
228 SetMember(0); |
|
229 } |
|
230 } |
|
231 |
|
232 void CWsSpriteBase::Activate() |
|
233 { |
|
234 if (iFlags&ESpriteDisabled) |
|
235 { |
|
236 iFlags&=~ESpriteDisabled; |
|
237 } |
|
238 if (iMembers->Count()>1) |
|
239 { |
|
240 QueueDeltaTimer(); |
|
241 iDeltaTimer->Activate(); |
|
242 } |
|
243 iFlags|=ESpriteActive; |
|
244 if(iWin) |
|
245 iWin->AddSprite(this); |
|
246 Screen()->SpriteManager()->Schedule(this); |
|
247 if(iFloating) |
|
248 { |
|
249 Screen()->SpriteManager()->AddFloatingSprite(this); |
|
250 ForceRedraw(); |
|
251 } |
|
252 } |
|
253 |
|
254 void CWsSpriteBase::SetMember(TInt aIndex) |
|
255 { |
|
256 iCurIndex=aIndex; |
|
257 iPos=iBasePos+(*iMembers)[iCurIndex]->iOffset; |
|
258 if ((*iMembers)[iCurIndex]->iBitmap) |
|
259 iSize=(*iMembers)[iCurIndex]->iBitmap->SizeInPixels(); |
|
260 else |
|
261 iSize.SetSize(0,0); |
|
262 |
|
263 if (iSize.iWidth > iMaxSize.iWidth || iSize.iHeight > iMaxSize.iHeight) |
|
264 { |
|
265 WS_ASSERT_DEBUG(EFalse, EWsPanicSpriteBitmapSizeChange); |
|
266 CheckSizesL(); |
|
267 } |
|
268 } |
|
269 |
|
270 void CWsSpriteBase::SetPos(const TPoint &aPos) |
|
271 { |
|
272 //Non-floating anim whose window is destroyed |
|
273 if (!iFloating && iWin==NULL) |
|
274 { |
|
275 OwnerPanic(EWservPanicWindowDestroyed); |
|
276 } |
|
277 |
|
278 //Floating anim whose group window is destroyed |
|
279 if (iFloating && iGroupWin==NULL) |
|
280 { |
|
281 OwnerPanic(EWservPanicWindowDestroyed); |
|
282 } |
|
283 |
|
284 iBasePos=aPos; |
|
285 TPoint newPos(iBasePos+(*iMembers)[iCurIndex]->iOffset); |
|
286 if (iPos!=newPos) |
|
287 { |
|
288 //Ensure the region covered by the sprite before as well as after the move gets scheduled for redraw |
|
289 Screen()->SpriteManager()->Schedule(this); |
|
290 iPos=newPos; |
|
291 Screen()->SpriteManager()->Schedule(this); |
|
292 } |
|
293 } |
|
294 |
|
295 // Andy - replace delta timer with animation scheduling via screen |
|
296 void CWsSpriteBase::QueueDeltaTimer() |
|
297 { |
|
298 iDeltaTimer->Queue((*iMembers)[iCurIndex]->iInterval,iDeltaTimerEntry); |
|
299 } |
|
300 |
|
301 void CWsSpriteBase::TimerExpired() |
|
302 { |
|
303 Screen()->SpriteManager()->Schedule(this); |
|
304 SetMember((iCurIndex+1)==iMembers->Count() ? 0 : iCurIndex+1); |
|
305 Screen()->SpriteManager()->Schedule(this); |
|
306 QueueDeltaTimer(); |
|
307 iScreen->Update(); |
|
308 } |
|
309 |
|
310 TPoint CWsSpriteBase::Pos() const |
|
311 { |
|
312 if (iGroupWin || iWin==NULL) |
|
313 { |
|
314 return(iPos); |
|
315 } |
|
316 return(iPos+iWin->Origin()); |
|
317 } |
|
318 |
|
319 TRect CWsSpriteBase::Rect() const |
|
320 { |
|
321 TRect rect; |
|
322 rect.iTl=Pos(); |
|
323 rect.iBr=rect.iTl+iSize; |
|
324 return(rect); |
|
325 } |
|
326 |
|
327 void CWsSpriteBase::CommandL(TInt aOpcode, const TAny *aCmdData) |
|
328 { |
|
329 TWsSpriteCmdUnion pData; |
|
330 |
|
331 pData.any=aCmdData; |
|
332 switch(aOpcode) |
|
333 { |
|
334 case EWsSpriteOpAppendMember: |
|
335 AppendMemberL(*pData.SpriteMember); |
|
336 break; |
|
337 case EWsSpriteOpActivate: |
|
338 if(!(iFlags&ESpriteActive)) |
|
339 { |
|
340 CompleteL(); |
|
341 } |
|
342 break; |
|
343 case EWsSpriteOpUpdateMember: |
|
344 if (pData.UpdateMember->index==iCurIndex) |
|
345 { |
|
346 TRect rect(Pos(), iMaxSize); |
|
347 Screen()->SpriteManager()->Schedule(this,&rect); |
|
348 } |
|
349 break; |
|
350 case EWsSpriteOpUpdateMember2: |
|
351 { |
|
352 Screen()->SpriteManager()->Schedule(this); |
|
353 if (pData.UpdateMember->index<0 || pData.UpdateMember->index>=iMembers->Count()) |
|
354 User::Leave(KErrArgument); |
|
355 CWsSpriteMember *member=(*iMembers)[pData.UpdateMember->index]; |
|
356 TBool ret=EFalse; |
|
357 TRAPD(err,ret=UpdateMemberL(member,pData.UpdateMember->data)); |
|
358 if (err==KErrNone) |
|
359 { |
|
360 TRAP(err,CheckSizesL()); |
|
361 SetMember(0); |
|
362 } |
|
363 Screen()->SpriteManager()->Schedule(this); |
|
364 User::LeaveIfError(err); |
|
365 if (ret) |
|
366 OwnerPanic(EWservPanicBitmap); |
|
367 } |
|
368 break; |
|
369 default: |
|
370 OwnerPanic(EWservPanicOpcode); |
|
371 break; |
|
372 } |
|
373 } |
|
374 |
|
375 TBool CWsSpriteBase::CanBeSeen() const |
|
376 { |
|
377 if(iWin) |
|
378 return (!(iFlags&ESpriteDisabled)) && (!iWin->VisibleRegion().IsEmpty()); |
|
379 else |
|
380 return (!(iFlags&ESpriteDisabled)); |
|
381 } |
|
382 |
|
383 void CWsSpriteBase::Redraw(CFbsBitGc * aGc, const TRegion& aRegion) |
|
384 { |
|
385 TFlashState currentState=EFlashOn; |
|
386 if(IsFlashingEnabled()) |
|
387 currentState=Screen()->SpriteManager()->CurrentSpriteFlashState(this); |
|
388 |
|
389 if(currentState==EFlashOn) |
|
390 { |
|
391 STACK_REGION region; |
|
392 region.Copy(aRegion); |
|
393 const TRegion * pr = ®ion; |
|
394 if (iClipSprite) |
|
395 { |
|
396 //PeterI iWin shouldn't be null as iClipSprite is currently only set by the text cursor (which is never floating) |
|
397 //but just in case make sure we don't derefernce if it is null. |
|
398 TPoint origin(0,0); |
|
399 if(iWin) |
|
400 origin = iWin->Origin(); |
|
401 TRect rect(iBasePos + origin + iClipOffset, iClipSize); |
|
402 region.ClipRect(rect); |
|
403 } |
|
404 region.ClipRect(RootWindow()->Abs()); |
|
405 |
|
406 // Only need to draw if the region being redrawn overlaps the sprite |
|
407 const TRect spriteRect(Pos(), iSize); |
|
408 STACK_REGION spriteRegion; |
|
409 spriteRegion.AddRect(spriteRect); |
|
410 region.Intersect(spriteRegion); |
|
411 spriteRegion.Close(); |
|
412 |
|
413 if (pr->CheckError()) |
|
414 { |
|
415 if(iWin) |
|
416 pr = &iWin->VisibleRegion(); |
|
417 else |
|
418 pr = &RootWindow()->WindowArea(); |
|
419 } |
|
420 |
|
421 if (!pr->IsEmpty()) |
|
422 { |
|
423 CWsSpriteMember *member=(*iMembers)[iCurIndex]; |
|
424 if (member->iBitmap) |
|
425 { |
|
426 aGc->SetClippingRegion(pr); |
|
427 |
|
428 // Calculate which piece (rect) of the bitmap needs to be drawn |
|
429 const TRect redrawRect = pr->BoundingRect(); |
|
430 TRect bitmapRect(spriteRect); // sprite rect relative to screen |
|
431 bitmapRect.Intersection(redrawRect); |
|
432 bitmapRect.Move(-Pos()); // adjust relative to bitmap origin |
|
433 |
|
434 if (member->iMaskBitmap) |
|
435 aGc->BitBltMasked(Pos() + bitmapRect.iTl, member->iBitmap, bitmapRect, member->iMaskBitmap, member->iInvertMask); |
|
436 else |
|
437 { |
|
438 aGc->SetDrawMode(member->iDrawMode); |
|
439 aGc->BitBlt(Pos() + bitmapRect.iTl, member->iBitmap, bitmapRect); |
|
440 aGc->SetDrawMode(CGraphicsContext::EDrawModePEN); |
|
441 } |
|
442 aGc->SetClippingRegion(NULL); |
|
443 } |
|
444 } |
|
445 region.Close(); |
|
446 } |
|
447 //flashing sprites need to reschedule themselves after drawing |
|
448 if(IsFlashingEnabled()) |
|
449 Screen()->SpriteManager()->Schedule(this); |
|
450 } |
|
451 |
|
452 TBool CWsSpriteBase::IsActivated() const |
|
453 { |
|
454 return (iFlags&ESpriteActive); |
|
455 } |
|
456 |
|
457 // |
|
458 // CWsSprite |
|
459 // |
|
460 |
|
461 CWsSprite::CWsSprite(CWsClient *owner) : CWsSpriteBase(owner,WS_HANDLE_SPRITE) |
|
462 { |
|
463 } |
|
464 |
|
465 CWsSprite::~CWsSprite() |
|
466 { |
|
467 if (!iFloating && IsActivated() && iWin && iWin->IsVisible()) |
|
468 ForceRedraw(); |
|
469 |
|
470 if (iAnim) |
|
471 CWsAnim::CloseAnim(iAnim); |
|
472 } |
|
473 |
|
474 void CWsSprite::ConstructL(const TWsClCmdCreateSprite &aParams) |
|
475 { |
|
476 NewObjL(); |
|
477 CWsWindowBase *win; |
|
478 WsOwner()->HandleToWindow(aParams.window,&win); |
|
479 if (win->WinType()==EWinTypeGroup) |
|
480 { |
|
481 //If a sprite is attached to a group window it is floating. |
|
482 //Floating sprite drawing is performed by the sprite manager. |
|
483 iGroupWin=(CWsWindowGroup *)win; |
|
484 win=NULL; //Floating sprites aren't associated with any particular window. |
|
485 iFloating=ETrue; |
|
486 } |
|
487 CWsSpriteBase::ConstructL(aParams.flags&ESpriteNonSystemFlags,(CWsWindow *)win); |
|
488 iBasePos=aParams.pos; |
|
489 } |
|
490 |
|
491 void CWsSprite::CompleteL() |
|
492 { |
|
493 CWsSpriteBase::CompleteL(); |
|
494 Activate(); |
|
495 } |
|
496 |
|
497 void CWsSprite::CommandL(TInt aOpcode, const TAny *aCmdData) |
|
498 { |
|
499 TWsSpriteCmdUnion pData; |
|
500 pData.any=aCmdData; |
|
501 switch(aOpcode) |
|
502 { |
|
503 case EWsSpriteOpSetPosition: |
|
504 SetPos(*pData.Point); |
|
505 break; |
|
506 case EWsSpriteOpFree: |
|
507 delete this; |
|
508 break; |
|
509 default: |
|
510 CWsSpriteBase::CommandL(aOpcode, aCmdData); |
|
511 break; |
|
512 } |
|
513 } |
|
514 |
|
515 /** |
|
516 @see MAnimSpriteFunctions::UpdateMember |
|
517 @param aFullUpdate Not used. Wserv2 always do full back to front rendering, so there is no distinction between changes needing aFullUpdate or not |
|
518 */ |
|
519 void CWsSprite::Update(TInt aMember,TRect aRect,TBool /*aFullUpdate*/) |
|
520 { |
|
521 if (iCurIndex!=aMember) |
|
522 return; |
|
523 aRect.Move(Pos()); |
|
524 aRect.Intersection(iScreen->CurrentScreenSize()); |
|
525 Screen()->SpriteManager()->Schedule(this, &aRect); |
|
526 } |
|
527 |
|
528 // |
|
529 // CWsPointerCursor |
|
530 // |
|
531 |
|
532 CWsPointerCursor::CWsPointerCursor(CWsClient *owner) : CWsSpriteBase(owner,WS_HANDLE_POINTER_CURSOR) |
|
533 { |
|
534 } |
|
535 |
|
536 void CWsPointerCursor::CloseObject() |
|
537 { |
|
538 RemoveFromIndex(); |
|
539 Close(); |
|
540 } |
|
541 |
|
542 void CWsPointerCursor::Close() |
|
543 { |
|
544 WS_ASSERT_DEBUG(iAccessCount>0, EWsPanicPointerCursorAccessCount); |
|
545 if (--iAccessCount==0) |
|
546 delete this; |
|
547 } |
|
548 |
|
549 void CWsPointerCursor::Open() |
|
550 { |
|
551 iAccessCount++; |
|
552 } |
|
553 |
|
554 CWsPointerCursor::~CWsPointerCursor() |
|
555 { |
|
556 WS_ASSERT_DEBUG(iAccessCount==0, EWsPanicPointerCursorAccessCount); |
|
557 } |
|
558 |
|
559 void CWsPointerCursor::ConstructL(const TWsClCmdCreatePointerCursor &aParams) |
|
560 { |
|
561 NewObjL(); |
|
562 CWsSpriteBase::ConstructL(ESpriteNoShadows|ESpriteNoChildClip|ESpritePointer|(aParams.flags&ESpriteNonSystemFlags),RootWindow()); |
|
563 Open(); |
|
564 } |
|
565 |
|
566 void CWsPointerCursor::CommandL(TInt aOpcode, const TAny *aCmdData) |
|
567 { |
|
568 switch(aOpcode) |
|
569 { |
|
570 case EWsSpriteOpFree: |
|
571 CloseObject(); |
|
572 break; |
|
573 default: |
|
574 CWsSpriteBase::CommandL(aOpcode, aCmdData); |
|
575 break; |
|
576 } |
|
577 } |
|
578 |
|
579 // |
|
580 // CWsCustomTextCursor |
|
581 // |
|
582 |
|
583 CWsCustomTextCursor::CWsCustomTextCursor (CWsClient *aOwner, RWsSession::TCustomTextCursorAlignment aAlignment) |
|
584 : CWsSpriteBase(aOwner, WS_HANDLE_TEXT_CURSOR), iAlignment(aAlignment) |
|
585 { |
|
586 } |
|
587 |
|
588 CWsCustomTextCursor::~CWsCustomTextCursor() |
|
589 { |
|
590 } |
|
591 |
|
592 void CWsCustomTextCursor::ConstructL(TInt aFlags) |
|
593 { |
|
594 NewObjL(); |
|
595 CWsSpriteBase::ConstructL(ESpriteNoShadows|ESpriteNoChildClip|ESpritePointer|(aFlags&ESpriteNonSystemFlags), NULL); |
|
596 } |
|
597 |
|
598 void CWsCustomTextCursor::CompleteL(CWsWindow *aWin, TBool aFlash, TBool aClipSprite, const TPoint& aClipOffset, const TSize& aClipSize) |
|
599 { |
|
600 iWin = aWin; |
|
601 iFlags = aFlash ? iFlags | ESpriteFlash : iFlags & ~ESpriteFlash; |
|
602 iClipSprite = aClipSprite; |
|
603 iClipOffset = aClipOffset; |
|
604 iClipSize = aClipSize; |
|
605 CWsSpriteBase::CompleteL(); |
|
606 } |
|
607 |
|
608 // Use SetPositionNoRedraw instead of SetPos when you just want to update |
|
609 // the custom text cursor position without redrawing it |
|
610 void CWsCustomTextCursor::SetPositionNoRedraw(const TPoint& aPos) |
|
611 { |
|
612 iBasePos = aPos; |
|
613 TPoint newPos(iBasePos+(*iMembers)[iCurIndex]->iOffset); |
|
614 iPos=newPos; |
|
615 } |
|
616 |
|
617 void CWsCustomTextCursor::CommandL(TInt aOpcode, const TAny *aCmdData) |
|
618 { |
|
619 switch(aOpcode) |
|
620 { |
|
621 case EWsSpriteOpFree: |
|
622 // CWsCustomTextCursor objects are owned by the text cursor list. |
|
623 // They are not deleted when the client closes it's R class. |
|
624 RemoveFromIndex(); |
|
625 break; |
|
626 default: |
|
627 CWsSpriteBase::CommandL(aOpcode, aCmdData); |
|
628 break; |
|
629 } |
|
630 } |
|
631 |
|
632 // |
|
633 // CWsDeltaTimer, nicked from CDeltaTimer and tweaked so it doesn't re-activate // |
|
634 // the timers until RunL has finished running all ready timers. // |
|
635 // // |
|
636 // This is to stop a problem in Wserv where sprites could hog 100% CPU if the time // |
|
637 // it took to process them was longer than the time of the timer queued when the first // |
|
638 // sprite was updated // |
|
639 // |
|
640 |
|
641 CWsDeltaTimer* CWsDeltaTimer::NewL(TInt aPriority) |
|
642 { |
|
643 CWsDeltaTimer* wsdt=new(ELeave) CWsDeltaTimer(aPriority); |
|
644 CleanupStack::PushL(wsdt); |
|
645 User::LeaveIfError(wsdt->iTimer.CreateLocal()); |
|
646 CActiveScheduler::Add(wsdt); |
|
647 CleanupStack::Pop(wsdt); |
|
648 return(wsdt); |
|
649 } |
|
650 |
|
651 CWsDeltaTimer::CWsDeltaTimer(TInt aPriority) : CActive(aPriority),iQueue(_FOFF(TWsDeltaTimerEntry,iLink)) |
|
652 { |
|
653 } |
|
654 |
|
655 CWsDeltaTimer::~CWsDeltaTimer() |
|
656 { |
|
657 Cancel(); |
|
658 while(iQueue.RemoveFirst()!=NULL) |
|
659 {} |
|
660 } |
|
661 |
|
662 void CWsDeltaTimer::Queue(TTimeIntervalMicroSeconds32 aTimeInMicroSeconds,TWsDeltaTimerEntry& anEntry) |
|
663 { |
|
664 TInt intervals=aTimeInMicroSeconds.Int()/CWsDeltaTimerGranularity; |
|
665 if (intervals==0) |
|
666 intervals=1; |
|
667 iQueue.Add(anEntry,intervals); |
|
668 } |
|
669 |
|
670 void CWsDeltaTimer::Activate() |
|
671 { |
|
672 // Queue a request on the timer. |
|
673 // The timer runs every tenth of a second and decremented the delta of the head of the queue. |
|
674 if (IsActive()) |
|
675 return; |
|
676 if (!iQueue.IsEmpty()) |
|
677 { |
|
678 SetActive(); |
|
679 iTimer.After(iStatus,CWsDeltaTimerGranularity-1); // -1 to compensate for +1 in kernel! |
|
680 } |
|
681 } |
|
682 |
|
683 void CWsDeltaTimer::RunL() |
|
684 { |
|
685 // Call all zero delta callbacks |
|
686 iQueue.CountDown(); |
|
687 TWsDeltaTimerEntry* ent=iQueue.RemoveFirst(); |
|
688 while (ent) |
|
689 { |
|
690 ent->iCallBack.CallBack(); |
|
691 ent=iQueue.RemoveFirst(); |
|
692 } |
|
693 Activate(); |
|
694 } |
|
695 |
|
696 void CWsDeltaTimer::DoCancel() |
|
697 { |
|
698 iTimer.Cancel(); |
|
699 } |
|
700 |
|
701 void CWsDeltaTimer::Remove(TWsDeltaTimerEntry& anEntry) |
|
702 { |
|
703 if (anEntry.IsPending()) |
|
704 { |
|
705 iQueue.Remove(anEntry); |
|
706 Activate(); |
|
707 } |
|
708 } |
|
709 |
|
710 |
|
711 // |
|
712 // CWsSpriteManager -handles floating and flashing sprites including flashing custom text cursors. i.e. cursors |
|
713 // that have an associated sprite. |
|
714 |
|
715 |
|
716 CWsSpriteManager::CWsSpriteManager() |
|
717 { |
|
718 } |
|
719 |
|
720 CWsSpriteManager::~CWsSpriteManager() |
|
721 { |
|
722 iFloatingSprites.ResetAndDestroy(); |
|
723 } |
|
724 |
|
725 CWsSpriteManager* CWsSpriteManager::NewL() |
|
726 { |
|
727 CWsSpriteManager* self = new (ELeave) CWsSpriteManager(); |
|
728 CleanupStack::PushL(self); |
|
729 self->ConstructL(); |
|
730 CleanupStack::Pop(self); |
|
731 return self; |
|
732 } |
|
733 |
|
734 void CWsSpriteManager::ConstructL() |
|
735 { |
|
736 } |
|
737 |
|
738 void CWsSpriteManager::AddFloatingSprite(CWsSpriteBase* aSprite) |
|
739 { |
|
740 iFloatingSprites.Append(aSprite); |
|
741 } |
|
742 |
|
743 void CWsSpriteManager::RemoveFloatingSprite(CWsSpriteBase* aSprite) |
|
744 { |
|
745 for (TInt i=0 ; i<iFloatingSprites.Count() ; i++) |
|
746 { |
|
747 if(iFloatingSprites[i]==aSprite) |
|
748 { |
|
749 //Just remove the sprite don't delete it. the manager doesn't have ownership |
|
750 iFloatingSprites.Remove(i); |
|
751 break; |
|
752 } |
|
753 } |
|
754 } |
|
755 |
|
756 void CWsSpriteManager::DrawFloatingSprites(CFbsBitGc* aGc,const TRegion& aRegion) |
|
757 { |
|
758 for (TInt i=0 ; i<iFloatingSprites.Count() ; i++) |
|
759 { |
|
760 aGc->Reset(); |
|
761 iFloatingSprites[i]->Redraw(aGc, aRegion); |
|
762 } |
|
763 } |
|
764 |
|
765 void CWsSpriteManager::Schedule(CWsSpriteBase* aSprite, TRect* aRect) |
|
766 { |
|
767 if (aRect != NULL && aRect->IsEmpty()) |
|
768 return; |
|
769 |
|
770 TRect rect = aSprite->Rect(); |
|
771 if (aRect) |
|
772 rect.Intersection(*aRect); |
|
773 |
|
774 if(aSprite->IsFlashingEnabled()) |
|
775 { |
|
776 aSprite->Screen()->ScheduleAnimation(rect,NextSpriteFlashStateChange(aSprite),0,0); |
|
777 } |
|
778 else |
|
779 { |
|
780 //Scheduling an animation "now" means it will take place at next animation which might |
|
781 //be the full animation grace period into the future (see KAnimationGrace in server.cpp) |
|
782 aSprite->Screen()->ScheduleAnimation(rect,0,0,0); |
|
783 } |
|
784 } |
|
785 |
|
786 // Sprite flashing is clamped to half second intervals in relation to the global time. |
|
787 // For the first half of each second all sprites have the EFlashOn state (visible) |
|
788 // For the second half of each second all sprites have the EFlashOff state (not visible) |
|
789 TTimeIntervalMicroSeconds CWsSpriteManager::NextSpriteFlashStateChange(const CWsSpriteBase* aSprite) const |
|
790 { |
|
791 const TTimeIntervalMicroSeconds remainder = aSprite->Screen()->Now().DateTime().MicroSecond(); |
|
792 return CalculateTimeToNextFlash(remainder); |
|
793 } |
|
794 |
|
795 TTimeIntervalMicroSeconds CWsSpriteManager::NextCursorFlashStateChange() const |
|
796 { |
|
797 const TTimeIntervalMicroSeconds remainder = CWsTop::CurrentFocusScreen()->Now().DateTime().MicroSecond(); |
|
798 return CalculateTimeToNextFlash(remainder); |
|
799 } |
|
800 |
|
801 TTimeIntervalMicroSeconds CWsSpriteManager::CalculateTimeToNextFlash(TTimeIntervalMicroSeconds aTime) const |
|
802 { |
|
803 TInt64 nextStateChange; |
|
804 if(aTime<KFlashHalfSecond) |
|
805 nextStateChange=KFlashHalfSecond-aTime.Int64(); |
|
806 else |
|
807 nextStateChange=KFlashHalfSecond - (aTime.Int64() - KFlashHalfSecond); |
|
808 return TTimeIntervalMicroSeconds(nextStateChange); |
|
809 } |
|
810 |
|
811 TFlashState CWsSpriteManager::CurrentSpriteFlashState(const CWsSpriteBase* aSprite) const |
|
812 { |
|
813 return (aSprite->Screen()->Now().DateTime().MicroSecond()<KFlashHalfSecond)?EFlashOn:EFlashOff; |
|
814 } |
|
815 |
|
816 TFlashState CWsSpriteManager::CurrentCursorFlashState() const |
|
817 { |
|
818 return (CWsTop::CurrentFocusScreen()->Now().DateTime().MicroSecond()<KFlashHalfSecond)?EFlashOn:EFlashOff; |
|
819 } |
|
820 |
|
821 void CWsSpriteManager::CalcFloatingSpriteRgn( TRegion& aResultRgn, const TRect& aDefaultRect ) |
|
822 { |
|
823 aResultRgn.Clear(); |
|
824 for (TInt i=0 ; i<iFloatingSprites.Count() && !aResultRgn.CheckError(); i++) |
|
825 { |
|
826 CWsSpriteBase* sprite = iFloatingSprites[i]; |
|
827 if ( sprite->CanBeSeen() && ( sprite->IsActive() || sprite->IsActivated() ) ) |
|
828 { |
|
829 aResultRgn.AddRect( sprite->Rect() ); |
|
830 } |
|
831 } |
|
832 aResultRgn.Tidy(); |
|
833 if ( aResultRgn.CheckError() && iFloatingSprites.Count() > 0 ) |
|
834 { |
|
835 aResultRgn.Clear(); |
|
836 aResultRgn.AddRect( aDefaultRect ); |
|
837 } |
|
838 } |