windowing/windowserver/nga/SERVER/openwfc/WINDOW.CPP
changeset 0 5d03bc08d59c
child 17 e375a7921169
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1994-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 // Window functions
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "server.h"
       
    19 #include "rootwin.h"
       
    20 #include "window.h"
       
    21 #include "walkwindowtree.h"
       
    22 #include "wstop.h"
       
    23 #include "ScrDev.H"
       
    24 #include "EVENT.H"
       
    25 #include "ANIM.H"
       
    26 #include "Direct.H"
       
    27 #include "panics.h"
       
    28 #include "backedupwindow.h"
       
    29 #include "wstypes.h"
       
    30 #include "windowelementset.h"
       
    31 
       
    32 CWsWindow* CWsWindow::iAccessListRecentEnd = 0;
       
    33 CWsWindow* CWsWindow::iAccessListOldestEnd = 0;
       
    34 
       
    35 #ifndef _DEBUG
       
    36 
       
    37 #define LOG_WINDOW_REDRAW_START(wswin)
       
    38 #define LOG_WINDOW_REDRAW_END(wswin)
       
    39 #define LOG_WINDOW_ANIM_REDRAW_START(wswin)
       
    40 #define LOG_WINDOW_ANIM_REDRAW_END(wswin)
       
    41 #define LOG_WINDOW_SPRITE_REDRAW_START(aWsWin)
       
    42 #define LOG_WINDOW_SPRITE_REDRAW_END(aWsWin)
       
    43 
       
    44 #else
       
    45 
       
    46 #define LOG_WINDOW_REDRAW_START(wswin) LogWindowRedrawStart(wswin)
       
    47 #define LOG_WINDOW_REDRAW_END(wswin) LogWindowRedrawEnd(wswin)
       
    48 #define LOG_WINDOW_ANIM_REDRAW_START(wswin) LogWindowAnimRedrawStart(wswin)
       
    49 #define LOG_WINDOW_ANIM_REDRAW_END(wswin) LogWindowAnimRedrawEnd(wswin)
       
    50 #define LOG_WINDOW_SPRITE_REDRAW_START(wswin) LogWindowSpriteRedrawStart(wswin)
       
    51 #define LOG_WINDOW_SPRITE_REDRAW_END(wswin) LogWindowSpriteRedrawEnd(wswin) 
       
    52 
       
    53 #include "../debuglog/DEBUGLOG.H"
       
    54 extern CDebugLogBase *wsDebugLog;
       
    55 
       
    56 extern void LogRegion(const TRegion* aRegion)
       
    57     {
       
    58     TBuf<LogTBufSize> log;
       
    59     TTruncateOverflow overflow;
       
    60     TInt rectCount = (aRegion == NULL ? 0 : aRegion->Count());
       
    61     log.AppendFormat(_L("Fading region: [%d,"), &overflow, rectCount);
       
    62     if (rectCount > 0)
       
    63         {
       
    64         const TRect* rectangles = aRegion->RectangleList();
       
    65         TBuf<1> comma;
       
    66         for (TInt ii = 0; ii < rectCount; ii++)
       
    67             {
       
    68             TRect current = rectangles[ii];
       
    69             log.AppendFormat(_L("%S{{%d,%d},{%d,%d}}"), &overflow, &comma,
       
    70                              current.iTl.iX,current.iTl.iY,current.iBr.iX,current.iBr.iY);
       
    71             comma = _L(",");
       
    72             }
       
    73         }
       
    74     else
       
    75         {
       
    76         log.AppendFormat(_L("NULL"), &overflow);
       
    77         }
       
    78     log.AppendFormat(_L("]"), &overflow);
       
    79     wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
       
    80     }
       
    81 
       
    82 extern void LogFadeStart(const CWsWindow* aWsWin)
       
    83     {
       
    84     if (wsDebugLog && aWsWin->WsOwner())
       
    85         {
       
    86         _LIT(KLogDrawCommandsStart, ">> CWsRedrawMsgWindow::Fade() [%S][app %d] RWindow[%d]");
       
    87         const TDesC& clientName = aWsWin->WsOwner()->Client().FullName();
       
    88         TBuf<LogTBufSize> log;
       
    89         TTruncateOverflow overflow;
       
    90         log.AppendFormat(KLogDrawCommandsStart, &overflow, &clientName, aWsWin->WsOwner()->ConnectionHandle(), aWsWin->LogHandle());
       
    91         wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
       
    92         }
       
    93     }
       
    94 
       
    95 extern void LogFadeRegion(const TRegion* aRegion)
       
    96     {
       
    97     if (wsDebugLog)
       
    98         {
       
    99         LogRegion(aRegion);
       
   100         }
       
   101     }
       
   102 
       
   103 extern void LogFadeEnd(const CWsWindow* aWsWin)
       
   104     {
       
   105     if (wsDebugLog && aWsWin->WsOwner())
       
   106         {
       
   107         _LIT(KLogDrawCommandsEnd, "<< CWsRedrawMsgWindow::Fade() [%S][app %d] RWindow[%d]");
       
   108         const TDesC& clientName = aWsWin->WsOwner()->Client().FullName();
       
   109         TBuf<LogTBufSize> log;
       
   110         TTruncateOverflow overflow;
       
   111         log.AppendFormat(KLogDrawCommandsEnd, &overflow, &clientName, aWsWin->WsOwner()->ConnectionHandle(), aWsWin->LogHandle());      
       
   112         wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
       
   113         }
       
   114     }
       
   115 
       
   116 static void LogWindowRedrawStart(const CWsWindow& aWsWin)
       
   117     {
       
   118     if (wsDebugLog)
       
   119          {
       
   120          TBuf<LogTBufSize> log;
       
   121          TTruncateOverflow overflow;
       
   122          if(aWsWin.Type() == WS_HANDLE_ROOT_WINDOW)
       
   123              {
       
   124              _LIT(KAnnotateWindowRedrawStart, ">> MWsDrawAnnotationObserver::WindowRedrawStart RootWindow for screen:%d");
       
   125              log.AppendFormat(KAnnotateWindowRedrawStart, &overflow, aWsWin.Screen()->ScreenNumber());
       
   126              }
       
   127          else
       
   128              {
       
   129              _LIT(KAnnotateWindowRedrawStart, ">> MWsDrawAnnotationObserver::WindowRedrawStart [%S][app %d] RWindow[%d]");
       
   130              const TDesC& clientName = aWsWin.WsOwner()->Client().FullName();
       
   131              log.AppendFormat(KAnnotateWindowRedrawStart, &overflow, &clientName, aWsWin.WsOwner()->ConnectionHandle(), aWsWin.LogHandle());
       
   132              }
       
   133          wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
       
   134          }    
       
   135     }
       
   136 
       
   137 static void LogWindowRedrawEnd(const CWsWindow& aWsWin)
       
   138     {
       
   139     if (wsDebugLog)
       
   140         {
       
   141         TBuf<LogTBufSize> log;
       
   142         TTruncateOverflow overflow;
       
   143         if(aWsWin.Type() == WS_HANDLE_ROOT_WINDOW)
       
   144             {
       
   145             _LIT(KAnnotateWindowRedrawEnd, "<< MWsDrawAnnotationObserver::WindowRedrawEnd RootWindow for screen:%d");
       
   146             log.AppendFormat(KAnnotateWindowRedrawEnd, &overflow, aWsWin.Screen()->ScreenNumber());
       
   147             }
       
   148         else
       
   149             {
       
   150             _LIT(KAnnotateWindowRedrawEnd, "<< MWsDrawAnnotationObserver::WindowRedrawEnd [%S][app %d] RWindow[%d]");
       
   151             const TDesC& clientName = aWsWin.WsOwner()->Client().FullName();
       
   152             log.AppendFormat(KAnnotateWindowRedrawEnd, &overflow, &clientName, aWsWin.WsOwner()->ConnectionHandle(), aWsWin.LogHandle());
       
   153             }
       
   154         wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
       
   155         }
       
   156     }
       
   157 
       
   158 static void LogWindowAnimRedrawStart(const CWsWindow& aWsWin)
       
   159     {
       
   160     if (wsDebugLog)
       
   161         {
       
   162         _LIT(KAnnotateWindowAnimRedrawStart, " >> MWsDrawAnnotationObserver::WindowAnimRedrawStart [%S][app %d] RWindow[%d]");
       
   163         const TDesC& clientName = aWsWin.WsOwner()->Client().FullName();
       
   164         TBuf<LogTBufSize> log;
       
   165         TTruncateOverflow overflow;
       
   166         log.AppendFormat(KAnnotateWindowAnimRedrawStart, &overflow, &clientName, aWsWin.WsOwner()->ConnectionHandle(), aWsWin.LogHandle());
       
   167         wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
       
   168         }
       
   169     }
       
   170 
       
   171 static void LogWindowAnimRedrawEnd(const CWsWindow& aWsWin)
       
   172     {
       
   173     if (wsDebugLog)
       
   174         {
       
   175         _LIT(KAnnotateWindowAnimRedrawEnd, " << MWsDrawAnnotationObserver::WindowAnimRedrawEnd [%S][app %d] RWindow[%d]");
       
   176         const TDesC& clientName = aWsWin.WsOwner()->Client().FullName();
       
   177         TBuf<LogTBufSize> log;
       
   178         TTruncateOverflow overflow;
       
   179         log.AppendFormat(KAnnotateWindowAnimRedrawEnd, &overflow, &clientName, aWsWin.WsOwner()->ConnectionHandle(), aWsWin.LogHandle());
       
   180         wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
       
   181         }
       
   182     }
       
   183 
       
   184 static void LogWindowSpriteRedrawStart(const CWsWindow& aWsWin)
       
   185     {
       
   186     if (wsDebugLog)
       
   187         {
       
   188         TBuf<LogTBufSize> log;
       
   189         TTruncateOverflow overflow;
       
   190         if(aWsWin.Type() == WS_HANDLE_ROOT_WINDOW)
       
   191             {
       
   192             _LIT(KAnnotateSpriteRedrawStart, "<< MWsDrawAnnotationObserver::WindowSpriteRedrawStart RootWindow for screen:%d");
       
   193             log.AppendFormat(KAnnotateSpriteRedrawStart, &overflow, aWsWin.Screen()->ScreenNumber());
       
   194             }
       
   195         else
       
   196             {
       
   197             _LIT(KAnnotateSpriteRedrawStart, " >> MWsDrawAnnotationObserver::WindowSpriteRedrawStart [%S][app %d] RWindow[%d]");
       
   198             const TDesC& clientName = aWsWin.WsOwner()->Client().FullName();
       
   199             log.AppendFormat(KAnnotateSpriteRedrawStart, &overflow, &clientName, aWsWin.WsOwner()->ConnectionHandle(), aWsWin.LogHandle());
       
   200             }
       
   201         wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
       
   202         }
       
   203     }
       
   204 
       
   205 static void LogWindowSpriteRedrawEnd(const CWsWindow& aWsWin)
       
   206     {
       
   207     if (wsDebugLog)
       
   208         {
       
   209         TBuf<LogTBufSize> log;
       
   210         TTruncateOverflow overflow;
       
   211         if(aWsWin.Type() == WS_HANDLE_ROOT_WINDOW)
       
   212             {
       
   213             _LIT(KAnnotateSpriteRedrawEnd, " << MWsDrawAnnotationObserver::WindowSpriteRedrawEnd RootWindow for screen:%d");
       
   214             log.AppendFormat(KAnnotateSpriteRedrawEnd, &overflow, aWsWin.Screen()->ScreenNumber());
       
   215             }
       
   216         else
       
   217             {
       
   218             _LIT(KAnnotateSpriteRedrawEnd, " << MWsDrawAnnotationObserver::WindowSpriteRedrawEnd [%S][app %d] RWindow[%d]");
       
   219             const TDesC& clientName = aWsWin.WsOwner()->Client().FullName();
       
   220             log.AppendFormat(KAnnotateSpriteRedrawEnd, &overflow, &clientName, aWsWin.WsOwner()->ConnectionHandle(), aWsWin.LogHandle());
       
   221             }
       
   222         wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything, log);
       
   223         }
       
   224     }
       
   225 
       
   226 #endif
       
   227 
       
   228 extern void AnnotateWindowRedrawStart(const CWsWindow& aWsWin, const TRegion& aRegion)
       
   229     {
       
   230     LOG_WINDOW_REDRAW_START(aWsWin);
       
   231     MWsDrawAnnotationObserver* annoObs = aWsWin.Screen()->DrawAnnotationObserver();
       
   232     if(annoObs)
       
   233         {
       
   234         annoObs->WindowRedrawStart(aWsWin, aRegion);
       
   235         }
       
   236     }
       
   237 
       
   238 extern void AnnotateWindowRedrawEnd(const CWsWindow& aWsWin)
       
   239     {
       
   240     LOG_WINDOW_REDRAW_END(aWsWin);
       
   241     MWsDrawAnnotationObserver* annoObs = aWsWin.Screen()->DrawAnnotationObserver();
       
   242     if(annoObs)
       
   243         {
       
   244         annoObs->WindowRedrawEnd(aWsWin);
       
   245         }
       
   246     }
       
   247 
       
   248 extern void AnnotateWindowAnimRedrawStart(const CWsWindow& aWsWin, const CWsAnim& aAnim, const TRegion& aRegion)
       
   249     {
       
   250     LOG_WINDOW_ANIM_REDRAW_START(aWsWin);
       
   251     MWsDrawAnnotationObserver* annoObs = aWsWin.Screen()->DrawAnnotationObserver();
       
   252     if(annoObs)
       
   253         {
       
   254         annoObs->WindowAnimRedrawStart(aAnim, aRegion);
       
   255         }
       
   256     }
       
   257 
       
   258 extern void AnnotateWindowAnimRedrawEnd(const CWsWindow& aWsWin, const CWsAnim& aAnim)
       
   259     {
       
   260     LOG_WINDOW_ANIM_REDRAW_END(aWsWin);
       
   261     MWsDrawAnnotationObserver* annoObs = aWsWin.Screen()->DrawAnnotationObserver();
       
   262     if(annoObs)
       
   263         {
       
   264         annoObs->WindowAnimRedrawEnd(aAnim);
       
   265         }
       
   266     }
       
   267 
       
   268 extern void AnnotateSpriteRedrawStart(const CWsWindow& aWsWin, const CWsSpriteBase& aSprite, const TRegion& aRegion)
       
   269     {
       
   270     LOG_WINDOW_SPRITE_REDRAW_START(aWsWin);
       
   271     MWsDrawAnnotationObserver* annoObs = aWsWin.Screen()->DrawAnnotationObserver();
       
   272     if(annoObs)
       
   273         {
       
   274         annoObs->SpriteRedrawStart(aSprite, aRegion);
       
   275         }   
       
   276     }
       
   277 
       
   278 extern void AnnotateSpriteRedrawEnd(const CWsWindow& aWsWin, const CWsSpriteBase& aSprite)
       
   279     {
       
   280     LOG_WINDOW_SPRITE_REDRAW_END(aWsWin);
       
   281     MWsDrawAnnotationObserver* annoObs = aWsWin.Screen()->DrawAnnotationObserver();
       
   282     if(annoObs)
       
   283         {
       
   284         annoObs->SpriteRedrawEnd(aSprite);
       
   285         }
       
   286     }
       
   287 
       
   288 CWsWindow::CWsWindow(CWsClient* aOwner,WH_HANDLES aType, CScreen* aScreen) : CWsWindowBase(aOwner,aType,aScreen),
       
   289 	iFlags(EFlagHidden),
       
   290 	iDSAs(_FOFF(CWsDirectScreenAccess,iMultipleDSALink))
       
   291 	{
       
   292 	}
       
   293 
       
   294 CWsWindow::~CWsWindow()
       
   295 	{
       
   296 	//2-phase destruction, Shutdown() is called before destructor
       
   297 	iFadableRegion.Reset();
       
   298 	iQuickFadeRegion.Reset();
       
   299 	}
       
   300 
       
   301 void CWsWindow::Fade(MWsGraphicsContext * aGc, const TRegion& aRegion)
       
   302 	{
       
   303 	if ( NULL != iRedraw )
       
   304 		{
       
   305 		iRedraw->Fade( aGc, aRegion );
       
   306 		}
       
   307 	}
       
   308 
       
   309 void CWsWindow::Construct()
       
   310 	{	
       
   311 	InsertIntoAccessListOldestEnd();
       
   312 	}
       
   313 
       
   314 void CWsWindow::Shutdown()
       
   315 	{
       
   316 	TWindowServerEvent::NotifyDrawer(TWservCrEvent(TWservCrEvent::EWindowClosing, 0, 0, this));
       
   317 	RemoveFromAccessList();
       
   318 	CWsAnim::WindowClosing(iAnimList);	// Destroy any animated objects attached to this window
       
   319 	iVisibleRegion.Reset();
       
   320 	iScheduledRegion.Reset();
       
   321 	iScheduledSpriteRegion.Reset();
       
   322 	iDirtyWindowRegion.Reset();
       
   323 	iDirtySpriteRegion.Reset();
       
   324 	AbortAllDSAs();
       
   325 	CWsWindowBase::Shutdown();
       
   326 	SetPointerCursor(NULL);
       
   327 	delete iRedraw;
       
   328 	iRedraw=NULL;
       
   329 	Screen()->RemoveFromScheduledList(this);
       
   330 	Screen()->RemoveFromTimedDrawList(this);
       
   331 	Screen()->RemoveFromQuickFadeList(this);
       
   332 	}
       
   333 
       
   334 //
       
   335 // Region and invalid area functions //
       
   336 //
       
   337 
       
   338 TRect CWsWindow::FullRect() const
       
   339 	{
       
   340 	return(TRect(iOrigin,iRel.Size()));
       
   341 	}
       
   342 
       
   343 //
       
   344 // Normal regions //
       
   345 //
       
   346 
       
   347 void CWsWindow::AreaCovered(TRegion &aRegion)
       
   348 	{
       
   349 	aRegion.Copy(WindowArea());
       
   350 	}
       
   351 
       
   352 void CWsWindow::SetNonFading(TBool aNonFade)
       
   353 	{
       
   354 	const TUint oldFlags = iFlags;
       
   355 
       
   356 	if (aNonFade)
       
   357 		iFlags|=EFlagNonFadingWindow;
       
   358 	else
       
   359 		iFlags&=(~EFlagNonFadingWindow);
       
   360 	
       
   361  	//Schedule window for quickfade if non-fading flag is changed	
       
   362 	if (!Screen()->ChangeTracking() &&  CWsTop::IsFadeEnabled() && (oldFlags != iFlags) ) 
       
   363 		{
       
   364 		Screen()->AcceptFadeRequest(this, !aNonFade);
       
   365 		}
       
   366 	
       
   367 	MWsWindowTreeObserver* const windowTreeObserver = Screen()->WindowTreeObserver();
       
   368 	if (windowTreeObserver && oldFlags!=iFlags)
       
   369 		windowTreeObserver->FlagChanged(*this, MWsWindowTreeObserver::ENonFading, aNonFade); 
       
   370 	}
       
   371 
       
   372 TPoint CWsWindow::InquireOffset(TUint32 aHandle) const
       
   373 	{
       
   374 	CWsWindowBase *win2;
       
   375 	iWsOwner->HandleToWindow(aHandle,&win2);
       
   376 	return(iOrigin-win2->Origin());
       
   377 	}
       
   378 
       
   379 TDisplayMode CWsWindow::SetRequiredDisplayModeL(TDisplayMode)
       
   380 	{
       
   381 	return DisplayMode();
       
   382 	}
       
   383 
       
   384 TDisplayMode CWsWindow::DisplayMode() const
       
   385 	{
       
   386 	return iScreen->DisplayMode();
       
   387 	}
       
   388 
       
   389 void CWsWindow::StatusDump(TDes &aBuf)
       
   390 	{
       
   391 	_LIT(KStatusString1,"CWsWindow[0x%x]RWindow[0x%x,%d],Pos(%d,%d),Size(%d,%d)");
       
   392 	_LIT(KStatusString3,",Mode=%d");
       
   393 	_LIT(KStatusInvisible,",Inv");
       
   394 	aBuf.AppendFormat(KStatusString1,this,iClientHandle,LogHandle(),iRel.iTl.iX,iRel.iTl.iY,Size().iWidth,Size().iHeight);
       
   395 	TDisplayMode displayMode = DisplayMode();
       
   396 	aBuf.AppendFormat(KStatusString3,(TInt&)displayMode);
       
   397 	if (!IsVisible())
       
   398 		aBuf.Append(KStatusInvisible);
       
   399 	}
       
   400 
       
   401 TDblQue<TPointerKeyList> *CWsWindow::PointerKeyList() const
       
   402 	{
       
   403 	return(NULL);
       
   404 	}
       
   405 
       
   406 TInt CWsWindow::AddDSA(CWsDirectScreenAccess& aDirect)
       
   407 	{
       
   408 	TInt error = KErrNone;
       
   409 
       
   410 	if (iDSAs.IsEmpty() && !aDirect.IsRegionTrackingOnly())
       
   411 		{
       
   412 		TRAP(error,iRedraw->SetDsaElementL());
       
   413 		}
       
   414 
       
   415 	if (!error)
       
   416 		{
       
   417 		iDSAs.AddLast(aDirect);
       
   418 		}
       
   419 
       
   420 	return error;
       
   421 	}
       
   422 
       
   423 void CWsWindow::RemoveDSA(CWsDirectScreenAccess& aDirect)
       
   424 	{
       
   425 	iDSAs.Remove(aDirect);
       
   426 	}
       
   427 
       
   428 void CWsWindow::AbortAllDSAs()
       
   429 	{
       
   430 	iScreen->AbortDSAs(RDirectScreenAccess::ETerminateRegion,iDSAs);
       
   431 	}
       
   432 
       
   433 void CWsWindow::PossibleVisibilityChangedEvent(TBool aForceSend)
       
   434 	{
       
   435 	// notify plugin
       
   436 	//
       
   437 	// coverity[unchecked_value]
       
   438 	TWservCrEvent crEvent(TWservCrEvent::EWindowVisibilityChanged, HasBeenDrawnToScreen(), IsVisible()? &iVisibleRegion : NULL, this);
       
   439 	TWindowServerEvent::NotifyDrawer(crEvent);
       
   440 	
       
   441 	if (!(iFlags & EFlagGeneratesVisibilityEvents))
       
   442 		return;
       
   443 
       
   444 	if (!IsVisible())
       
   445 		{
       
   446 		goto notvisible;
       
   447 		}
       
   448 
       
   449 	if (iVisibleRegion.Count() == 0)
       
   450 		{
       
   451 		goto notvisible;
       
   452 		}
       
   453 
       
   454 		{// braces here to avoid gccxml error
       
   455 		TInt visibleArea = 0;
       
   456 		TInt count = iVisibleRegion.Count();
       
   457 		TInt ii;
       
   458 		for (ii = 0; ii < count; ii++)
       
   459 			{
       
   460 			visibleArea+= iVisibleRegion[ii].Width() * iVisibleRegion[ii].Height();
       
   461 			}
       
   462 
       
   463 		const TRegion* baseRegion = (static_cast<CWsClientWindow*>(this))->BaseArea();
       
   464 		TInt baseArea = 0;
       
   465 		count = baseRegion->Count();
       
   466 		for (ii = 0; ii < count; ii++)
       
   467 			{
       
   468 			const TRect& rect = (*baseRegion)[ii];
       
   469 			baseArea+= rect.Width() * rect.Height();
       
   470 			}
       
   471 
       
   472 		if (visibleArea == baseArea)
       
   473 			{
       
   474 			goto fullyvisible;
       
   475 			}
       
   476 		else
       
   477 			{
       
   478 			goto partiallyvisible;
       
   479 			}
       
   480 		}
       
   481 
       
   482 fullyvisible:
       
   483 	if (aForceSend || !(iFlags & EFlagNotCantBeSeen) || !(iFlags & EFlagCanBeSeen))
       
   484 		{
       
   485 		iFlags |= (EFlagCanBeSeen | EFlagNotCantBeSeen);
       
   486 		TWindowServerEvent::SendVisibilityChangedEvents(this, TWsVisibilityChangedEvent::EPartiallyVisible | TWsVisibilityChangedEvent::EFullyVisible);
       
   487 		// we have to set EPartiallyVisible too for compatibility reasons
       
   488 		}
       
   489 	return;
       
   490 
       
   491 partiallyvisible:
       
   492 	if (aForceSend || !(iFlags & EFlagCanBeSeen) || (iFlags & EFlagNotCantBeSeen))
       
   493 		{
       
   494 		iFlags |= EFlagCanBeSeen;
       
   495 		iFlags &= ~EFlagNotCantBeSeen;
       
   496 		TWindowServerEvent::SendVisibilityChangedEvents(this, TWsVisibilityChangedEvent::EPartiallyVisible);
       
   497 		}
       
   498 	return;
       
   499 
       
   500 notvisible:
       
   501 	if (aForceSend || (iFlags & EFlagCanBeSeen) || (iFlags & EFlagNotCantBeSeen))
       
   502 		{
       
   503 		iFlags &= ~(EFlagCanBeSeen | EFlagNotCantBeSeen);
       
   504 		TWindowServerEvent::SendVisibilityChangedEvents(this, TWsVisibilityChangedEvent::ENotVisible);
       
   505 		}
       
   506 	return;
       
   507 	}
       
   508 
       
   509 TPoint CWsWindow::Origin() const
       
   510 	{
       
   511 	return iOrigin;
       
   512 	}
       
   513 
       
   514 TRect CWsWindow::AbsRect() const
       
   515 	{
       
   516 	return iAbs;
       
   517 	}
       
   518 	
       
   519 TSize CWsWindow::Size() const
       
   520 	{
       
   521 	return iRel.Size();
       
   522 	}
       
   523 
       
   524 TBool CWsWindow::SetScheduledRegion(const TRegion& aRegion)
       
   525 	{
       
   526 	iScheduledRegion.Copy(aRegion);
       
   527 	return !iScheduledRegion.CheckError();
       
   528 	}
       
   529 
       
   530 void CWsWindow::ClearScheduledRegion()
       
   531 	{
       
   532 	iScheduledRegion.Reset();
       
   533 	}
       
   534 
       
   535 void CWsWindow::SetFadeBehind(TBool aFade)
       
   536 	{
       
   537 	if (aFade != ((iFlags & EFlagFadeBehind) != 0))
       
   538 		{
       
   539 		iFlags ^= EFlagFadeBehind;
       
   540 		}
       
   541 	}
       
   542 
       
   543 void CWsWindow::FocusChanged(TBool aNewFocusState)
       
   544 	{
       
   545 	TRAPD(err,FocusChangedL(aNewFocusState));
       
   546 	if (err!=KErrNone)
       
   547 		OwnerPanic(EWservPanicAnimLeave);
       
   548 	}
       
   549 
       
   550 void CWsWindow::FocusChangedL(TBool aNewFocusState)
       
   551 	{
       
   552 	for (CWsAnim * anim = iAnimList; anim; anim = anim->Next())
       
   553 		{
       
   554 		anim->FocusChanged(aNewFocusState);
       
   555 		}
       
   556 	}
       
   557 
       
   558 // Moves a window to the recent end of the accessed list
       
   559 void CWsWindow::Accessed()
       
   560 	{
       
   561 	WS_ASSERT_DEBUG(iAccessListRecentEnd && iAccessListOldestEnd, EWsPanicAccessList);
       
   562 
       
   563 	RemoveFromAccessList();	
       
   564 	InsertIntoAccessListRecentEnd();
       
   565 	}
       
   566 
       
   567 void CWsWindow::InsertIntoAccessListOldestEnd()
       
   568 	{
       
   569 	iAccessListPrev = 0;
       
   570 	iAccessListNext = iAccessListOldestEnd;
       
   571 	if (iAccessListNext)
       
   572 		iAccessListNext->iAccessListPrev = this;
       
   573 	iAccessListOldestEnd = this;
       
   574 	if (!iAccessListRecentEnd)
       
   575 		iAccessListRecentEnd = this;
       
   576 	}
       
   577 
       
   578 void CWsWindow::InsertIntoAccessListRecentEnd()
       
   579 	{
       
   580 	iAccessListNext = 0;
       
   581 	iAccessListPrev = iAccessListRecentEnd;
       
   582 	if (iAccessListPrev)
       
   583 		iAccessListPrev->iAccessListNext = this;
       
   584 	iAccessListRecentEnd = this;
       
   585 	if (!iAccessListOldestEnd)
       
   586 		iAccessListOldestEnd = this;
       
   587 	}
       
   588 
       
   589 void CWsWindow::RemoveFromAccessList()
       
   590 	{
       
   591 	if (iAccessListOldestEnd == this)
       
   592 		iAccessListOldestEnd = iAccessListNext;
       
   593 	if (iAccessListRecentEnd == this)
       
   594 		iAccessListRecentEnd = iAccessListPrev;
       
   595 	if (iAccessListPrev)
       
   596 		iAccessListPrev->iAccessListNext = iAccessListNext;
       
   597 	if (iAccessListNext)
       
   598 		iAccessListNext->iAccessListPrev = iAccessListPrev;
       
   599 	}
       
   600 	
       
   601 TBool CWsWindow::ReleaseMemory(MWsMemoryRelease::TMemoryReleaseLevel aLevel)
       
   602 	{
       
   603 	for (CWsWindow * access = iAccessListOldestEnd; access; access = access->iAccessListNext)
       
   604 		{
       
   605 		if(access->Redraw())
       
   606 			{
       
   607 			if (access->Redraw()->ReleaseMemory(aLevel))
       
   608 				return ETrue;
       
   609 			}
       
   610 		}
       
   611 	return EFalse;
       
   612 	}
       
   613 
       
   614 const TRegion& CWsWindow::VisibleRegion() const
       
   615 	{
       
   616 	return(iVisibleRegion);
       
   617 	}
       
   618 
       
   619 const TRegion& CWsWindow::QuickFadeRegion() const
       
   620    	{
       
   621    	return iQuickFadeRegion;
       
   622    	}
       
   623 
       
   624 const TRegion& CWsWindow::FadableRegion() const
       
   625 	{
       
   626 	return iFadableRegion;
       
   627 	}
       
   628 
       
   629 TBool CWsWindow::IsDSAHost() const
       
   630 	{
       
   631 	TBool res = EFalse; 
       
   632 	if ( !iDSAs.IsEmpty() )
       
   633 		{
       
   634 		TSglQueIter<CWsDirectScreenAccess> iter( (TSglQueBase&)iDSAs );
       
   635 		iter.SetToFirst();
       
   636 		CWsDirectScreenAccess* dsa;
       
   637 		while ( (dsa = iter++) != NULL && !res )
       
   638 			{
       
   639 			res = dsa->IsVisible();
       
   640 			}
       
   641 		}
       
   642 	return res;
       
   643 	}
       
   644 
       
   645 void CWsWindow::SendState(MWsWindowTreeObserver& aWindowTreeObserver) const
       
   646 	{
       
   647 	aWindowTreeObserver.NodeCreated(*this, ParentNode());
       
   648 	
       
   649 	if(iFlags & EFlagActive)
       
   650 		{
       
   651 		aWindowTreeObserver.NodeExtentChanged(*this, FullRect());
       
   652 		aWindowTreeObserver.NodeActivated(*this);
       
   653 		}
       
   654 	
       
   655 	if(!IsVisible())
       
   656 		{
       
   657 		aWindowTreeObserver.FlagChanged(*this, MWsWindowTreeObserver::EVisible, EFalse);
       
   658 		}
       
   659 	
       
   660 	if(IsTrackingVisibleRegion())
       
   661 		{
       
   662 		MWsWindowVisibilityNotifier* windowVisibilityNotifier = Screen()->WindowVisibilityNotifier();
       
   663 		if(windowVisibilityNotifier)
       
   664 			windowVisibilityNotifier->RegisterWindow(*this);
       
   665 		}
       
   666 
       
   667 	if(HasAlpha())
       
   668 		{
       
   669 		aWindowTreeObserver.FlagChanged(*this, MWsWindowTreeObserver::EAlphaChannelTransparencyEnabled, ETrue);
       
   670 		}
       
   671 	
       
   672 	if(IsNonFading())
       
   673 		{
       
   674 		aWindowTreeObserver.FlagChanged(*this, MWsWindowTreeObserver::ENonFading, ETrue); 
       
   675 		}
       
   676 	
       
   677 	if(iAnimList)
       
   678 		iAnimList->SendState(aWindowTreeObserver);
       
   679 	
       
   680 	CWsWindowBase::SendState(aWindowTreeObserver);
       
   681 	}
       
   682 
       
   683 void CWsWindow::ResetVisibleRegion()
       
   684 	{
       
   685 	if (!iVisibleRegion.IsEmpty())
       
   686 		{
       
   687 		iVisibleRegion.Reset();
       
   688 		}
       
   689 	iFadableRegion.Reset();
       
   690 	iQuickFadeRegion.Reset();
       
   691 	}
       
   692 
       
   693 void CWsWindow::SetVisibleRegion(const TRegion& aNewRegion, const TRegion* aTop)
       
   694 	{
       
   695 	WS_ASSERT_DEBUG(iScreen, EWsPanicNoScreen);
       
   696 	STACK_REGION difference;
       
   697 	TBool diffs = EFalse;
       
   698 
       
   699 	difference.Copy(iVisibleRegion);	
       
   700 	difference.SubRegion(aNewRegion);
       
   701 	if (!difference.IsEmpty())
       
   702 		{
       
   703 		diffs = ETrue;
       
   704 		if (IsTranslucent())
       
   705 			{
       
   706 			iScreen->AddRedrawRegion(difference, EFalse);	
       
   707 			}
       
   708 		}
       
   709 
       
   710 	difference.Copy(aNewRegion);
       
   711 	if (HasBeenDrawnToScreen())
       
   712 		{
       
   713 		difference.SubRegion(iVisibleRegion);
       
   714 		}
       
   715 	if (!difference.IsEmpty())
       
   716 		{
       
   717 		diffs = ETrue;
       
   718 		if(!iScreen->ChangeTracking())
       
   719 			{
       
   720 			//the following code will restart animations
       
   721 			STACK_REGION topDiff;
       
   722 			topDiff.Copy(difference);
       
   723 			WS_ASSERT_DEBUG(aTop,EWsPanicRegion);
       
   724 			topDiff.Intersect(*aTop);
       
   725 			difference.SubRegion(topDiff);
       
   726 			iScreen->AddRedrawRegion(topDiff, EFalse, ERedrawTopOnly);
       
   727 			iScreen->AddRedrawRegion(difference, EFalse, ERedrawAll);
       
   728 			topDiff.Close();
       
   729 			}
       
   730 		else if(IsVisible())
       
   731 			{
       
   732 			RestartAnimations(aNewRegion);
       
   733 			}
       
   734 		}
       
   735 
       
   736 	difference.Close();
       
   737 
       
   738 	AbortDsaIfRequired(aNewRegion, aTop);
       
   739 
       
   740 	if (diffs)
       
   741 		{
       
   742 		ResetVisibleRegion();
       
   743 		iVisibleRegion.Copy(aNewRegion);
       
   744 		PossibleVisibilityChangedEvent(EFalse);
       
   745 		
       
   746 		if (Redraw()->HasElement())
       
   747 			{
       
   748 			WS_ASSERT_DEBUG(WinType()==EWinTypeClient,EWsPanicWindowType);
       
   749 			
       
   750 			if (WinType()==EWinTypeClient)
       
   751 				{
       
   752 				iScreen->WindowElements().SetVisibleRegion(*static_cast<CWsClientWindow*>(this));
       
   753 				}
       
   754 			}
       
   755 		}
       
   756 
       
   757 	// Just because the visible region (screen coordinates) didn't change doesn't
       
   758 	// mean the invalid region (window coordinates) didn't change, so we always call this.
       
   759 	iRedraw->VisibleRegionChange();
       
   760 	}
       
   761 
       
   762 //This function sets up the quick fadable region.
       
   763 //It removes anything that cannot be quick faded, and schedules it to be drawn in the normal fashion.
       
   764 void CWsWindow::SetFadeableRegion(const TRegion& aNewFadableRegion, const TRegion& aTop)
       
   765 	{
       
   766 	WS_ASSERT_DEBUG(iScreen, EWsPanicNoScreen);
       
   767 	iFadableRegion.Copy(aNewFadableRegion);
       
   768 
       
   769 	//Try to figure out if any part of iFadableRegion can be quick faded (i.e. fading applied to 
       
   770 	//the screen without first having to redraw all visible windows intersecting the region).
       
   771 	if ( !iFadableRegion.IsEmpty() && iScreen->IsQuickFadeScheduled(this) )
       
   772 		{
       
   773 		if (IsTranslucent())
       
   774 			{
       
   775 			//If a window is semitransparent, then we cannot apply a quickfade to it if
       
   776 			//the window below is faded too.
       
   777 			iScreen->AddRedrawRegion(iVisibleRegion, EFalse, ERedrawAll);
       
   778 			iScreen->RemoveFromQuickFadeList(this);
       
   779 			}
       
   780 		else
       
   781 			{
       
   782 			iQuickFadeRegion.Intersection(iFadableRegion, aTop);
       
   783 			
       
   784 			//Remove any regions not possible to quick fade from iQuickFadeRegion and
       
   785 			//schedule these regions for full back-front rendering instead.
       
   786 			STACK_REGION nonQuickFadableRegion;
       
   787 
       
   788 			for(CWsSpriteBase * sprite = iSpriteList; sprite; sprite = sprite->Next())
       
   789 				{
       
   790 				nonQuickFadableRegion.AddRect(sprite->Rect());
       
   791 				}
       
   792 
       
   793 			for(CWsAnim * anim = iAnimList; anim; anim = anim->Next())
       
   794 				{
       
   795 				nonQuickFadableRegion.AddRect(anim->BestRect());
       
   796 				}
       
   797 
       
   798 			RWsTextCursor* const cursor = CWsTop::CurrentTextCursor();
       
   799 			if( cursor && (cursor->Window()==this) && cursor->IsStandardCursorActive() )
       
   800 				{
       
   801 				nonQuickFadableRegion.AddRect(cursor->Rect());
       
   802 				}
       
   803 
       
   804 			//Any regions scheduled for fading but partly or fully covered by transparent windows above them
       
   805 			STACK_REGION coveredFadableRegion;
       
   806 			coveredFadableRegion.Copy(iFadableRegion);
       
   807 			coveredFadableRegion.SubRegion(iQuickFadeRegion);
       
   808 			nonQuickFadableRegion.Union(coveredFadableRegion);
       
   809 			coveredFadableRegion.Close();
       
   810 
       
   811 			nonQuickFadableRegion.Tidy();
       
   812 
       
   813 			//Remove any regions not possible to quick fade from iQuickFadeRegion
       
   814 			iQuickFadeRegion.SubRegion(nonQuickFadableRegion);
       
   815 
       
   816 			if (!nonQuickFadableRegion.CheckError())
       
   817 				{
       
   818 				//Schedule normal drawing (full back to front rendering) for the region not possible to quick fade
       
   819 				if (!nonQuickFadableRegion.IsEmpty())
       
   820 					{ 
       
   821 					iScreen->AddRedrawRegion(nonQuickFadableRegion, EFalse, ERedrawAll);
       
   822 					}
       
   823 				}
       
   824 			else
       
   825 				{
       
   826 				//Schedule normal drawing for the whole iVisibleRegion if the calculations are broken
       
   827 				iScreen->AddRedrawRegion(iVisibleRegion, EFalse, ERedrawAll);
       
   828 				}
       
   829 			nonQuickFadableRegion.Close();
       
   830 			}
       
   831 		}
       
   832 	else
       
   833 		{
       
   834 		iQuickFadeRegion.Reset();
       
   835 		}
       
   836 	}
       
   837 
       
   838 void CWsWindow::RestartAnimations(const TRegion& aNewRegion)
       
   839 	{
       
   840 	 //When not ChangeTracking, restarting is handled by AddRedrawRegion (called from CWsWindow::SetVisibleRegion) and TWalkWindowTreeScheduleRegions
       
   841 	WS_ASSERT_DEBUG(iScreen->ChangeTracking(),EWsPanicNoChangetracking);
       
   842 	
       
   843 	//Restart uncovered window animations 
       
   844 	for (CWsAnim* anim = iAnimList; anim; anim = anim->Next())
       
   845 		{
       
   846 		if(!iScreen->IsScheduled(EWindowAnim, anim->BestRect(), this) && aNewRegion.Intersects(anim->BestRect()))
       
   847 			{
       
   848 			iScreen->ScheduleAnimation(EWindowAnim, anim->BestRect(), 0, 0, 0, this);
       
   849 			}
       
   850 		}
       
   851 	//Restart uncovered sprite animations 
       
   852 	for (CWsSpriteBase* sprite = iSpriteList; sprite; sprite = sprite->Next())
       
   853 		{
       
   854 		if(!iScreen->IsScheduled(ESpriteAnim, sprite->Rect(), sprite->Win()) && aNewRegion.Intersects(sprite->Rect()))
       
   855 			{
       
   856 			iScreen->ScheduleAnimation(ESpriteAnim, sprite->Rect(), 0, 0, 0, sprite->Win());
       
   857 			}
       
   858 		}
       
   859 	}
       
   860 
       
   861 void CWsWindow::ClearVisibleRegion()
       
   862 	{
       
   863 	AbortAllDSAs();         
       
   864 	iScreen->AddRedrawRegion(VisibleRegion(), EFalse);
       
   865 	ResetVisibleRegion();
       
   866 	PossibleVisibilityChangedEvent(EFalse);
       
   867 	if (Redraw()->HasElement())
       
   868 		{
       
   869 		WS_ASSERT_DEBUG(WinType()==EWinTypeClient,EWsPanicWindowType);
       
   870 		
       
   871 		if (WinType()==EWinTypeClient)
       
   872 			{
       
   873 			iScreen->WindowElements().SetVisibleRegion(*static_cast<CWsClientWindow*>(this));
       
   874 			}
       
   875 		}
       
   876 	iFlags &= ~EFlagDrawnToScreen;
       
   877 	}
       
   878 
       
   879 void CWsWindow::AbortDsaIfRequired(const TRegion& aNewRegion, const TRegion* aTop)
       
   880 	{
       
   881 	if (!iDSAs.IsEmpty())
       
   882 		{
       
   883 		// If the top visible region of this window has changed, DSA clients may need
       
   884 		// to be sent a DSA abort, as they may be drawing to a different region
       
   885 		STACK_REGION newTopVisible;
       
   886 		newTopVisible.Copy(aNewRegion); // new visible region
       
   887 		if (aTop!=NULL)
       
   888 			{
       
   889 			newTopVisible.Intersect(*aTop); // area of new visible region not obscured by any other opaque or translucent windows
       
   890 			}
       
   891 		// Build a list of DSA clients that need to be sent a DSA abort
       
   892 		TSglQue<CWsDirectScreenAccess> dsaList(_FOFF(CWsDirectScreenAccess,iAbortLink));
       
   893 		TSglQueIter<CWsDirectScreenAccess> iter(iDSAs);
       
   894 		CWsDirectScreenAccess* dsa;
       
   895 		while ((dsa=iter++)!=NULL)
       
   896 			{
       
   897 			if (dsa->IsAbortRequired(newTopVisible))
       
   898 				{
       
   899 				dsaList.AddLast(*dsa);
       
   900 				}
       
   901 			}
       
   902 		if (!dsaList.IsEmpty())
       
   903 			{
       
   904 			iScreen->AbortDSAs(RDirectScreenAccess::ETerminateRegion, dsaList);
       
   905 			}
       
   906 		newTopVisible.Close();
       
   907 		}
       
   908 	}
       
   909 
       
   910 const TRegion* CWsWindow::VisibleRegionIfValid() const
       
   911 	{
       
   912 	return iVisibleRegion.CheckError() ? NULL : &iVisibleRegion;
       
   913 	}
       
   914 	
       
   915 TBool CWsWindow::ReadyToDraw() const
       
   916 	{
       
   917 	return iRedraw->ReadyToDraw();
       
   918 	}
       
   919 
       
   920 /**
       
   921 This function draws the region specified
       
   922 */
       
   923 void CWsWindow::Render(MWsGraphicsContext& aGc, const TRegion& aWindowRegion, const TRegion& aWindowChildNodeRegion)
       
   924 	{
       
   925 	WS_ASSERT_DEBUG(IsVisible() || (WinType() == EWinTypeRoot), EWsPanicScheduledRedraw);
       
   926 
       
   927 	AnnotateWindowRedrawStart(*this, aWindowRegion);
       
   928 	
       
   929 	Accessed();
       
   930 	iFlags |= EFlagDrawnToScreen;
       
   931 	
       
   932 	aGc.Reset();
       
   933 	iRedraw->PreDrawWindow(&aGc, aWindowRegion);
       
   934 	iRedraw->DrawWindow();
       
   935 	iRedraw->PostDrawWindow(&aGc, aWindowChildNodeRegion);
       
   936 	}
       
   937 
       
   938 void CWsWindow::SetNextScheduled(CWsWindow * aWin)
       
   939 	{
       
   940 	iNextScheduled = aWin;
       
   941 	}
       
   942 	
       
   943 CWsWindow * CWsWindow::NextScheduled()  const
       
   944 	{
       
   945 	return iNextScheduled;
       
   946 	}
       
   947 
       
   948 void CWsWindow::DeactivateAllSprites()
       
   949 	{
       
   950 	CWsSpriteBase * current = iSpriteList;
       
   951 	while (current)
       
   952 		{
       
   953 		CWsSpriteBase * next = current->Next();
       
   954 		current->Deactivate();
       
   955 		current = next;
       
   956 		}
       
   957 	}
       
   958 
       
   959 void CWsWindow::ClipRectToViewport(TRect& aRect) const
       
   960 	{
       
   961 	const CWsWindowBase * win = this;
       
   962 	while (win)
       
   963 		{
       
   964 		if (win->WinType() != EWinTypeGroup)
       
   965 			{
       
   966 			aRect.Intersection(win->AbsRect());
       
   967 			}
       
   968 		win = win->BaseParent();
       
   969 		}
       
   970 	}
       
   971 
       
   972 void CWsWindow::AddDirtyWindowRegion(const TRegion& aRegion)
       
   973 	{
       
   974 	iDirtyWindowRegion.Union(aRegion);
       
   975 	if (iDirtyWindowRegion.CheckError())
       
   976 		{
       
   977 		iDirtyWindowRegion.Reset();
       
   978 		iDirtyWindowRegion.AddRect(AbsRect()); // fallback to potentially visible part of window
       
   979 		}
       
   980 	}
       
   981 
       
   982 const TRegion& CWsWindow::DirtyWindowRegion() const
       
   983 	{
       
   984 	return iDirtyWindowRegion;
       
   985 	}
       
   986 
       
   987 void CWsWindow::ScheduleDirtyWindowRegion()
       
   988 	{
       
   989 	iDirtyWindowRegion.Tidy();
       
   990 	iDirtyWindowRegion.Offset(iOrigin); //convert to screen coords 
       
   991 	iScheduledRegion.Copy(iDirtyWindowRegion);
       
   992 	iDirtyWindowRegion.Reset();
       
   993 	if (iScheduledRegion.CheckError())
       
   994 		{
       
   995 		iScheduledRegion.Reset();
       
   996 		iScheduledRegion.AddRect(AbsRect()); // fallback to potentially visible part of window
       
   997 		}
       
   998 	}
       
   999 
       
  1000 void CWsWindow::AddDirtySpriteRegion(const TRegion& aRegion)
       
  1001 	{
       
  1002 	iDirtySpriteRegion.Union(aRegion);
       
  1003 	if (iDirtySpriteRegion.CheckError())
       
  1004 		{
       
  1005 		iDirtySpriteRegion.Reset();
       
  1006 		iDirtySpriteRegion.AddRect(AbsRect()); // fallback to potentially visible part of window
       
  1007 		}
       
  1008 	}
       
  1009 
       
  1010 const TRegion& CWsWindow::DirtySpriteRegion() const
       
  1011 	{
       
  1012 	return iDirtySpriteRegion;
       
  1013 	}
       
  1014 
       
  1015 void CWsWindow::ScheduleDirtySpriteRegion()
       
  1016 	{
       
  1017 	iDirtySpriteRegion.Tidy();
       
  1018 	iDirtySpriteRegion.Offset(iOrigin); //convert to screen coords 
       
  1019 	iScheduledSpriteRegion.Copy(iDirtySpriteRegion);
       
  1020 	iDirtySpriteRegion.Reset();
       
  1021 	if (iScheduledSpriteRegion.CheckError())
       
  1022 		{
       
  1023 		iScheduledSpriteRegion.Reset();
       
  1024 		iScheduledSpriteRegion.AddRect(AbsRect()); // fallback to potentially visible part of window
       
  1025 		}
       
  1026 	}
       
  1027 
       
  1028 void CWsWindow::ClearScheduledSpriteRegion()
       
  1029 	{
       
  1030 	iScheduledSpriteRegion.Reset();
       
  1031 	}
       
  1032 
       
  1033 /**
       
  1034 In ChangeTracking mode, wserv is not maintaining the visible region of windows.
       
  1035 Windows that need to keep track of their visible region in ChangeTracking mode 
       
  1036 should call this function.
       
  1037 
       
  1038 @param aRegister 	ETrue if iVisibleRegion should be maintained with accurate information, 
       
  1039 					EFalse if not.
       
  1040 					
       
  1041 @internalComponent
       
  1042 */
       
  1043 void CWsWindow::SetupVisibleRegionTracking(TBool aRegister)
       
  1044 	{
       
  1045 	if (aRegister)
       
  1046 		{
       
  1047 		++iVisibleRegionTrackingCounter;
       
  1048 		if (iVisibleRegionTrackingCounter==1)
       
  1049 			{
       
  1050 			//If visible region tracking has not been setup, let's do it now.
       
  1051 			iScreen->SetupVisibleRegionTracking(*this, ETrue);
       
  1052 			}
       
  1053 		}
       
  1054 	else if (iVisibleRegionTrackingCounter>0)
       
  1055 		{
       
  1056 		--iVisibleRegionTrackingCounter;
       
  1057 		if (iVisibleRegionTrackingCounter==0)
       
  1058 			{
       
  1059 			//If aReason was the last reason to track visibility, disable further notifications.
       
  1060 			iScreen->SetupVisibleRegionTracking(*this, EFalse);
       
  1061 			}
       
  1062 		}
       
  1063 	}
       
  1064 
       
  1065 /**
       
  1066 MWsWindow
       
  1067 */
       
  1068 MWsWindow * CWsWindow::FindChildByHandle(TUint32 aHandle)
       
  1069 	{
       
  1070 	TWalkWindowTreeFindByHandle wwt(aHandle);
       
  1071 	WalkWindowTree(wwt, EWalkChildren);
       
  1072 	return wwt.Found();
       
  1073 	}
       
  1074 
       
  1075 TUint32 CWsWindow::Handle() const
       
  1076 	{
       
  1077 	return ClientHandle();
       
  1078 	}
       
  1079 
       
  1080 MWsScreen * CWsWindow::WsScreen() const
       
  1081 	{
       
  1082 	return iScreen;
       
  1083 	}
       
  1084 
       
  1085 TInt CWsWindow::OrdinalPriority() const
       
  1086 	{
       
  1087 	return iOrdinalPriority;
       
  1088 	}