os/graphics/windowing/windowserver/nga/SERVER/openwfc/WINBASE.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-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
// Window virtual base class, windows and window groups are derived from this
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include "server.h"
sl@0
    20
#include "winbase.h"
sl@0
    21
#include "rootwin.h"
sl@0
    22
#include "windowgroup.h"
sl@0
    23
#include "walkwindowtree.h"
sl@0
    24
#include "wstop.h"
sl@0
    25
#include "EVQUEUE.H"
sl@0
    26
#include "EVENT.H"
sl@0
    27
#include "panics.h"
sl@0
    28
#include "pointer.h"
sl@0
    29
#include "windowelementset.h"
sl@0
    30
sl@0
    31
CWsWindowBase::CWsWindowBase(CWsClient* aOwner,WH_HANDLES aType, CScreen* aScreen) : CWsScreenObject(aOwner,aType,aScreen)		
sl@0
    32
	{
sl@0
    33
	}
sl@0
    34
sl@0
    35
void CWsWindowBase::ConstructL(CWsWindowBase *aParent)
sl@0
    36
	{
sl@0
    37
	iParent=aParent;
sl@0
    38
	iSibling=aParent->iChild;
sl@0
    39
	aParent->iChild=this;
sl@0
    40
	CScreen* screen = aParent->Screen();
sl@0
    41
	WS_ASSERT_DEBUG(screen,EWsPanicNoScreen);
sl@0
    42
	MWsWindowTreeObserver* const windowTreeObserver = screen->WindowTreeObserver();
sl@0
    43
	if (windowTreeObserver)
sl@0
    44
		{
sl@0
    45
		windowTreeObserver->NodeCreated(*this, ParentNode());
sl@0
    46
		iBaseWinFlags |= EBaseWinNodeCreated;
sl@0
    47
		}
sl@0
    48
	SetOrdinalPosition(0);
sl@0
    49
	iFadeCount = iParent->iFadeCount;
sl@0
    50
	}
sl@0
    51
sl@0
    52
CWsWindowBase *CWsWindowBase::GetPrevSibling() const
sl@0
    53
	{
sl@0
    54
	if(iParent == NULL) //RootWindow
sl@0
    55
		return(NULL);
sl@0
    56
	
sl@0
    57
	CWsWindowBase* prev=iParent->iChild;
sl@0
    58
	CWsWindowBase *ret=NULL;
sl@0
    59
	while (prev!=this)
sl@0
    60
		{
sl@0
    61
		ret=prev;
sl@0
    62
		prev=prev->iSibling;
sl@0
    63
		}
sl@0
    64
	return(ret);
sl@0
    65
	}
sl@0
    66
sl@0
    67
CWsWindowBase *CWsWindowBase::LastSibling() const
sl@0
    68
	{
sl@0
    69
	const CWsWindowBase *win;
sl@0
    70
	for(win=this;win->iSibling;win=win->iSibling)
sl@0
    71
		{}
sl@0
    72
	return (CWsWindowBase*)win;
sl@0
    73
	}
sl@0
    74
sl@0
    75
CWsWindowBase *CWsWindowBase::PrevSiblingMultiParent() const
sl@0
    76
	{
sl@0
    77
	CWsWindowBase *win=GetPrevSibling();
sl@0
    78
	if (win)
sl@0
    79
		return(win);
sl@0
    80
	for(CWsWindowBase *parent=iParent->GetPrevSibling();parent;parent=parent->GetPrevSibling())
sl@0
    81
		if ((win=parent->iChild)!=NULL)
sl@0
    82
			return(win->LastSibling());
sl@0
    83
	return(NULL);
sl@0
    84
	}
sl@0
    85
sl@0
    86
CWsWindowBase *CWsWindowBase::NextSiblingMultiParent() const
sl@0
    87
	{
sl@0
    88
	if (iSibling)
sl@0
    89
		return(iSibling);
sl@0
    90
	for(CWsWindowBase *parent=iParent->iSibling;parent;parent=parent->iSibling)
sl@0
    91
		{
sl@0
    92
		if (parent->iChild!=NULL)
sl@0
    93
			return(parent->iChild);
sl@0
    94
		}
sl@0
    95
	return(NULL);
sl@0
    96
	}
sl@0
    97
sl@0
    98
TInt CWsWindowBase::OrdinalPosition(TBool aFull) const
sl@0
    99
	{
sl@0
   100
	if (!iParent)
sl@0
   101
		{
sl@0
   102
		OwnerPanic(EWservPanicParentDeleted);
sl@0
   103
		}
sl@0
   104
	CWsWindowBase *win=iParent->iChild;
sl@0
   105
	if (!aFull)
sl@0
   106
		while(iOrdinalPriority<win->iOrdinalPriority)
sl@0
   107
			win=win->iSibling;
sl@0
   108
	TInt count;
sl@0
   109
	for(count=0;win!=this;count++)
sl@0
   110
		win=win->iSibling;
sl@0
   111
	return(count);
sl@0
   112
	}
sl@0
   113
sl@0
   114
/** Removes a window from the list of siblings maintained by its parent window.
sl@0
   115
sl@0
   116
The iSibling stored inside the window we remove is kept unchanged as it may be needed later.
sl@0
   117
sl@0
   118
@internalComponent
sl@0
   119
@released
sl@0
   120
*/
sl@0
   121
void CWsWindowBase::RemoveFromSiblingList()
sl@0
   122
	{
sl@0
   123
	if (iParent!=NULL)
sl@0
   124
		{
sl@0
   125
		CWsWindowBase **prev= &iParent->iChild;
sl@0
   126
		while ((*prev)!=this)
sl@0
   127
			prev= &(*prev)->iSibling;
sl@0
   128
		*prev=iSibling;
sl@0
   129
		}
sl@0
   130
	}
sl@0
   131
sl@0
   132
CWsWindowGroup *CWsWindowBase::WinGroup() const
sl@0
   133
	{
sl@0
   134
	if (iWinType==EWinTypeClient)
sl@0
   135
		return(((CWsClientWindow *)this)->TopClientWindow()->Parent());
sl@0
   136
	if (iWinType==EWinTypeGroup)
sl@0
   137
		return((CWsWindowGroup *)this);
sl@0
   138
	return(NULL);
sl@0
   139
	}
sl@0
   140
sl@0
   141
TBool CWsWindowBase::CheckOrdinalPositionChange(TInt aPos)
sl@0
   142
//
sl@0
   143
// This routine checks to see whether the specified new ordinal position
sl@0
   144
// will causes a change, if so returns ETrue else EFalse.
sl@0
   145
//
sl@0
   146
	{
sl@0
   147
	CWsWindowBase *win= iParent->iChild;
sl@0
   148
	CWsWindowBase *prev= NULL;
sl@0
   149
	while(win==this || (win!=NULL && iOrdinalPriority<win->iOrdinalPriority))
sl@0
   150
		{
sl@0
   151
		prev=win;
sl@0
   152
		win=win->iSibling;
sl@0
   153
		}
sl@0
   154
	if (prev==this)
sl@0
   155
		win=this;
sl@0
   156
	else if (win==NULL || (win->iSibling==this && iOrdinalPriority>win->iOrdinalPriority))
sl@0
   157
		return ETrue;
sl@0
   158
	while(aPos--!=0 && win->iSibling!=NULL && iOrdinalPriority==win->iSibling->iOrdinalPriority)
sl@0
   159
		win=win->iSibling;
sl@0
   160
	return(win!=this);
sl@0
   161
	}
sl@0
   162
sl@0
   163
void CWsWindowBase::ChangeWindowPosition(TInt aPos,CWsWindowBase* aNewParent)
sl@0
   164
	{
sl@0
   165
	TBool changedWindowGroup = EFalse;
sl@0
   166
	WS_ASSERT_DEBUG(aNewParent,EWsPanicWindowNull);
sl@0
   167
	if (aNewParent != iParent)
sl@0
   168
		{
sl@0
   169
		iScreen->ScheduleRegionUpdate(NULL);		
sl@0
   170
		TWalkWindowTreeScheduleRedraws wwt;
sl@0
   171
		WalkWindowTree(wwt, EWalkChildren);
sl@0
   172
		changedWindowGroup = ETrue;
sl@0
   173
		}
sl@0
   174
	else if (WinType() == EWinTypeClient)
sl@0
   175
		{
sl@0
   176
		CWsClientWindow * cliwin = static_cast<CWsClientWindow*>(this);
sl@0
   177
		if (cliwin->IsVisible())
sl@0
   178
			{
sl@0
   179
			iScreen->ScheduleRegionUpdate(NULL);
sl@0
   180
			if (cliwin->IsTranslucent())
sl@0
   181
				{
sl@0
   182
				// There is still room for optimization here.  These redraws are only required if the window
sl@0
   183
				// moved through another window and BOTH of them were transparent, otherwise the visible
sl@0
   184
				// region change will sort out the redraws required.
sl@0
   185
				TWalkWindowTreeScheduleRedraws wwt;
sl@0
   186
				WalkWindowTree(wwt, EWalkChildren);
sl@0
   187
				}
sl@0
   188
			}
sl@0
   189
		}
sl@0
   190
	else if (WinType() == EWinTypeGroup)
sl@0
   191
		{
sl@0
   192
		iScreen->ScheduleRegionUpdate(NULL);
sl@0
   193
		if (static_cast<CWsWindowGroup*>(this)->HasVisibleTranslucentChild())
sl@0
   194
			{
sl@0
   195
			TWalkWindowTreeScheduleRedraws wwt;
sl@0
   196
			WalkWindowTree(wwt, EWalkChildren);				
sl@0
   197
			}
sl@0
   198
		}
sl@0
   199
sl@0
   200
	RemoveFromSiblingList();
sl@0
   201
	CWsWindowBase **prevWinPtr= &aNewParent->iChild;
sl@0
   202
	while((*prevWinPtr)!=NULL && iOrdinalPriority<(*prevWinPtr)->iOrdinalPriority)
sl@0
   203
		{
sl@0
   204
		prevWinPtr= &(*prevWinPtr)->iSibling;
sl@0
   205
		}
sl@0
   206
	while(aPos--!=0 && *prevWinPtr!=NULL && iOrdinalPriority==(*prevWinPtr)->iOrdinalPriority)
sl@0
   207
		{
sl@0
   208
		prevWinPtr= &(*prevWinPtr)->iSibling;
sl@0
   209
		}
sl@0
   210
	iSibling=*prevWinPtr;
sl@0
   211
	iParent=aNewParent;
sl@0
   212
	*prevWinPtr=this;
sl@0
   213
sl@0
   214
	Screen()->WindowElements().SortByZOrder();
sl@0
   215
sl@0
   216
	MWsWindowTreeObserver* const windowTreeObserver = Screen()->WindowTreeObserver();
sl@0
   217
	if (windowTreeObserver)
sl@0
   218
		{
sl@0
   219
		if(changedWindowGroup && (WinType() == EWinTypeClient))
sl@0
   220
			{
sl@0
   221
			windowTreeObserver->MovedToWindowGroup(*this, *(this->WinGroup()));
sl@0
   222
			}
sl@0
   223
		else if(!changedWindowGroup)
sl@0
   224
			{
sl@0
   225
			windowTreeObserver->SiblingOrderChanged(*this, OrdinalPosition(ETrue));
sl@0
   226
			}
sl@0
   227
		else if(changedWindowGroup)
sl@0
   228
			{
sl@0
   229
			OwnerPanic(EWservPanicInvalidParameter); //Should be impossible to end up here as only WinType() EWinTypeClient 
sl@0
   230
			}										 //and EWinTypeGroup can be moved to another windowgroup.
sl@0
   231
		}											 //@see RWindowBase::MoveToGroup
sl@0
   232
	}
sl@0
   233
sl@0
   234
void CWsWindowBase::SetOrdinalPosition(TInt aPos)
sl@0
   235
	{
sl@0
   236
	if (CheckOrdinalPositionChange(aPos))
sl@0
   237
		ChangeWindowPosition(aPos,iParent);
sl@0
   238
	}
sl@0
   239
sl@0
   240
TEventQueueWalkRet EventPurgeFunc(TAny *aPtr, TWsEvent *aEvent)
sl@0
   241
//
sl@0
   242
// Callback function for event queue walk
sl@0
   243
//
sl@0
   244
	{
sl@0
   245
	return(((CWsWindowBase *)aPtr)->EventPurgeCheck(aEvent));
sl@0
   246
	}
sl@0
   247
sl@0
   248
TEventQueueWalkRet CWsWindowBase::EventPurgeCheck(TWsEvent *aEvent)
sl@0
   249
	{
sl@0
   250
	if (aEvent->Handle()==ClientHandle())
sl@0
   251
		return(EEventQueueWalkDeleteEvent);
sl@0
   252
	return(EEventQueueWalkOk);
sl@0
   253
	}
sl@0
   254
sl@0
   255
void CWsWindowBase::PurgeEvents()
sl@0
   256
	{
sl@0
   257
	iWsOwner->EventQueue()->WalkEventQueue(&EventPurgeFunc,this);
sl@0
   258
	}
sl@0
   259
sl@0
   260
void CWsWindowBase::Shutdown()
sl@0
   261
//
sl@0
   262
// Destroy a window, disconnects from the window tree and destroys all it's child windows
sl@0
   263
//
sl@0
   264
	{
sl@0
   265
	if (iWsOwner!=NULL)
sl@0
   266
		PurgeEvents();
sl@0
   267
	if (iParent!=NULL)	// Check it's connected to something
sl@0
   268
		{
sl@0
   269
		CWsWindowBase *win;
sl@0
   270
		for(win=this;win && win->iParent!=(CWsWindowBase *)RootWindow();win=win->iParent)
sl@0
   271
			{}
sl@0
   272
		RemoveFromSiblingList();
sl@0
   273
		TWalkWindowTreeDisconnect wwt2(win ? ((CWsWindowGroup *)win)->TextCursor() : NULL);
sl@0
   274
		WalkWindowTree(wwt2,EWalkChildren); // Disconnect all child windows
sl@0
   275
		iChild=NULL;
sl@0
   276
		}
sl@0
   277
	TWindowServerEvent::RemoveFromSwitchOnEventList(*this);
sl@0
   278
	TWindowServerEvent::RemoveFromErrorMessageList(*this);
sl@0
   279
	TWindowServerEvent::RemoveFromGroupChangeEventEventList(*this);
sl@0
   280
	TWindowServerEvent::RemoveFromFocusChangeEventEventList(*this);
sl@0
   281
	TWindowServerEvent::RemoveFromGroupListChangeEventEventList(*this);
sl@0
   282
	TWindowServerEvent::RemoveFromModifierChangedEventList(*this);
sl@0
   283
	TWindowServerEvent::RemoveFromScreenDeviceChangeEventList(*this);
sl@0
   284
	CWsTop::StopWindowGettingOffEvents(this);
sl@0
   285
	}
sl@0
   286
sl@0
   287
TBool CWsWindowBase::CommandL(TInt aOpcode, TWsWinCmdUnion &aCmd)
sl@0
   288
//
sl@0
   289
// If the command is supported by the window base class process it and return ETrue
sl@0
   290
// if it is not supported return EFalse
sl@0
   291
//
sl@0
   292
	{
sl@0
   293
	switch(aOpcode)
sl@0
   294
		{
sl@0
   295
		case EWsWinOpFree:
sl@0
   296
			{
sl@0
   297
			delete this;
sl@0
   298
			break;
sl@0
   299
			}
sl@0
   300
		case EWsWinOpSetOrdinalPosition:
sl@0
   301
			SetOrdinalPosition(*aCmd.Int);
sl@0
   302
			break;
sl@0
   303
		case EWsWinOpOrdinalPriority:
sl@0
   304
			SetReply(iOrdinalPriority);
sl@0
   305
			break;
sl@0
   306
		case EWsWinOpOrdinalPosition:
sl@0
   307
			SetReply(OrdinalPosition(EFalse));
sl@0
   308
			break;
sl@0
   309
		case EWsWinOpFullOrdinalPosition:
sl@0
   310
			SetReply(OrdinalPosition(ETrue));
sl@0
   311
			break;
sl@0
   312
		case EWsWinOpClientHandle:
sl@0
   313
			SetReply(iClientHandle);
sl@0
   314
			break;
sl@0
   315
		case EWsWinOpParent:
sl@0
   316
			if (!iParent)
sl@0
   317
				{
sl@0
   318
				OwnerPanic(EWservPanicParentDeleted);
sl@0
   319
				}
sl@0
   320
			SetReply(iParent->iClientHandle);
sl@0
   321
			break;
sl@0
   322
		case EWsWinOpPrevSibling:
sl@0
   323
			{
sl@0
   324
			if (!iParent)
sl@0
   325
				{
sl@0
   326
				OwnerPanic(EWservPanicParentDeleted);
sl@0
   327
				}
sl@0
   328
			TUint32 reply=NULL;
sl@0
   329
			for(CWsWindowBase *win=this->GetPrevSibling();win;win=win->GetPrevSibling())
sl@0
   330
				{
sl@0
   331
				if (win->iWsOwner==iWsOwner)
sl@0
   332
					{
sl@0
   333
					reply=win->iClientHandle;
sl@0
   334
					break;
sl@0
   335
					}
sl@0
   336
				}
sl@0
   337
			SetReply(reply);
sl@0
   338
			}
sl@0
   339
			break;
sl@0
   340
		case EWsWinOpNextSibling:
sl@0
   341
			{
sl@0
   342
			TUint32 reply=NULL;
sl@0
   343
			for(CWsWindowBase *win=this->iSibling;win;win=win->iSibling)
sl@0
   344
				{
sl@0
   345
				if (win->iWsOwner==iWsOwner)
sl@0
   346
					{
sl@0
   347
					reply=win->iClientHandle;
sl@0
   348
					break;
sl@0
   349
					}
sl@0
   350
				}
sl@0
   351
			SetReply(reply);
sl@0
   352
			}
sl@0
   353
			break;
sl@0
   354
		case EWsWinOpChild:
sl@0
   355
			SetReply(iChild==NULL ? NULL : iChild->iClientHandle);
sl@0
   356
			break;
sl@0
   357
		case EWsWinOpScreenNumber:
sl@0
   358
			SetReply(Screen()->ScreenNumber());
sl@0
   359
			break;
sl@0
   360
		case EWsWinOpWindowGroupId:
sl@0
   361
			{
sl@0
   362
			TUint32 reply=NULL;
sl@0
   363
			CWsWindowGroup *wg=WinGroup();
sl@0
   364
			if (wg)
sl@0
   365
				{
sl@0
   366
				reply=wg->Identifier();
sl@0
   367
				}
sl@0
   368
			SetReply(reply);
sl@0
   369
			}
sl@0
   370
			break;
sl@0
   371
		case EWsWinOpEnableOnEvents:
sl@0
   372
			{
sl@0
   373
			const TEventControl circumstances = *aCmd.EventControl;
sl@0
   374
			TWindowServerEvent::AddToSwitchOnEventListL(*this, circumstances);
sl@0
   375
			if (iScreen->ChangeTracking())
sl@0
   376
				{
sl@0
   377
				if(circumstances & EEventControlOnlyWhenVisible)
sl@0
   378
					{
sl@0
   379
					TWalkWindowTreeSetupVisibleRegionTracking wwt(ETrue);
sl@0
   380
					WalkWindowTree(wwt, EWalkChildren);
sl@0
   381
					}
sl@0
   382
				}
sl@0
   383
			break;
sl@0
   384
			}
sl@0
   385
		case EWsWinOpDisableOnEvents:
sl@0
   386
			{
sl@0
   387
			TWindowServerEvent::RemoveFromSwitchOnEventList(*this);
sl@0
   388
			if (iScreen->ChangeTracking())
sl@0
   389
				{
sl@0
   390
				TWalkWindowTreeSetupVisibleRegionTracking wwt(EFalse);
sl@0
   391
				WalkWindowTree(wwt, EWalkChildren);
sl@0
   392
				}
sl@0
   393
			break;
sl@0
   394
			}
sl@0
   395
		case EWsWinOpEnableErrorMessages:
sl@0
   396
			{
sl@0
   397
			const TEventControl circumstances = *aCmd.EventControl;
sl@0
   398
			TWindowServerEvent::AddToErrorMessageListL(*this, circumstances);
sl@0
   399
			if (iScreen->ChangeTracking())
sl@0
   400
				{
sl@0
   401
				if(circumstances & EEventControlOnlyWhenVisible)
sl@0
   402
					{
sl@0
   403
					TWalkWindowTreeSetupVisibleRegionTracking wwt(ETrue);
sl@0
   404
					WalkWindowTree(wwt, EWalkChildren);
sl@0
   405
					}
sl@0
   406
				}
sl@0
   407
			break;
sl@0
   408
			}
sl@0
   409
		case EWsWinOpDisableErrorMessages:
sl@0
   410
			{
sl@0
   411
			TWindowServerEvent::RemoveFromErrorMessageList(*this);
sl@0
   412
			if (iScreen->ChangeTracking())
sl@0
   413
				{
sl@0
   414
				TWalkWindowTreeSetupVisibleRegionTracking wwt(EFalse);
sl@0
   415
				WalkWindowTree(wwt, EWalkChildren);
sl@0
   416
				}
sl@0
   417
			break;
sl@0
   418
			}
sl@0
   419
		case EWsWinOpEnableModifierChangedEvents:
sl@0
   420
			{
sl@0
   421
			const TInt modifierMask = aCmd.EnableModifierChangedEvents->modifierMask;
sl@0
   422
			const TEventControl circumstances = aCmd.EnableModifierChangedEvents->circumstances;
sl@0
   423
			TWindowServerEvent::AddToModifierChangedEventListL(*this, modifierMask, circumstances);
sl@0
   424
			if (iScreen->ChangeTracking())
sl@0
   425
				{
sl@0
   426
				if(circumstances & EEventControlOnlyWhenVisible)
sl@0
   427
					{
sl@0
   428
					TWalkWindowTreeSetupVisibleRegionTracking wwt(ETrue);
sl@0
   429
					WalkWindowTree(wwt, EWalkChildren);
sl@0
   430
					}
sl@0
   431
				}
sl@0
   432
			break;
sl@0
   433
			}
sl@0
   434
		case EWsWinOpDisableModifierChangedEvents:
sl@0
   435
			{
sl@0
   436
			TWindowServerEvent::RemoveFromModifierChangedEventList(*this);
sl@0
   437
			if (iScreen->ChangeTracking())
sl@0
   438
				{
sl@0
   439
				TWalkWindowTreeSetupVisibleRegionTracking wwt(EFalse);
sl@0
   440
				WalkWindowTree(wwt, EWalkChildren);
sl@0
   441
				}
sl@0
   442
			break;
sl@0
   443
			}
sl@0
   444
		case EWsWinOpEnableGroupChangeEvents:
sl@0
   445
			TWindowServerEvent::AddToGroupChangeEventListL(*this);
sl@0
   446
			break;
sl@0
   447
		case EWsWinOpDisableGroupChangeEvents:
sl@0
   448
			TWindowServerEvent::RemoveFromGroupChangeEventEventList(*this);
sl@0
   449
			break;
sl@0
   450
		case EWsWinOpEnableFocusChangeEvents:
sl@0
   451
			TWindowServerEvent::AddToFocusChangeEventListL(*this);
sl@0
   452
			break;
sl@0
   453
		case EWsWinOpDisableFocusChangeEvents:
sl@0
   454
			TWindowServerEvent::RemoveFromFocusChangeEventEventList(*this);
sl@0
   455
			break;
sl@0
   456
		case EWsWinOpEnableGroupListChangeEvents:
sl@0
   457
			TWindowServerEvent::AddToGroupListChangeEventListL(*this);
sl@0
   458
			break;
sl@0
   459
		case EWsWinOpDisableGroupListChangeEvents:
sl@0
   460
			TWindowServerEvent::RemoveFromGroupListChangeEventEventList(*this);
sl@0
   461
			break;
sl@0
   462
		case EWsWinOpSetCustomPointerCursor:
sl@0
   463
			CWsObject *pointercursor;
sl@0
   464
			if ((pointercursor=iWsOwner->HandleToObj(*aCmd.Int, WS_HANDLE_POINTER_CURSOR))==NULL)
sl@0
   465
				OwnerPanic(EWservPanicSprite);
sl@0
   466
			SetPointerCursor((CWsPointerCursor *)pointercursor);
sl@0
   467
			break;
sl@0
   468
		case EWsWinOpSetPointerCursor:
sl@0
   469
			SetPointerCursorByIndex(*aCmd.UInt);
sl@0
   470
			break;
sl@0
   471
		case EWsWinOpClearPointerCursor:
sl@0
   472
			SetPointerCursor(NULL);
sl@0
   473
			break;
sl@0
   474
		case EWsWinOpSetNonFading:
sl@0
   475
			{
sl@0
   476
			WS_ASSERT_DEBUG(iScreen, EWsPanicNoScreen);
sl@0
   477
			// No fading will occur from a graphical perspective, but the fade counts
sl@0
   478
			// are maintained for BC reasons.
sl@0
   479
			TWalkWindowTreeSetNonFading wwt(*aCmd.Bool);
sl@0
   480
			WalkWindowTree(wwt,EWalkChildren);
sl@0
   481
			}
sl@0
   482
			break;
sl@0
   483
		case EWsWinOpSetFade:
sl@0
   484
			{
sl@0
   485
			WS_ASSERT_DEBUG(iScreen, EWsPanicNoScreen);
sl@0
   486
			
sl@0
   487
			TUint8 blackMap;
sl@0
   488
			TUint8 whiteMap;
sl@0
   489
			if (aCmd.SetFaded->UseDefaultMap())
sl@0
   490
				{
sl@0
   491
				iScreen->GetFadingParams(blackMap,whiteMap);
sl@0
   492
				}
sl@0
   493
			else
sl@0
   494
				{
sl@0
   495
				aCmd.SetFaded->GetFadingParams(blackMap,whiteMap);
sl@0
   496
				}
sl@0
   497
			
sl@0
   498
			if (aCmd.SetFaded->IncludeChildren())
sl@0
   499
				{
sl@0
   500
				TWalkWindowTreeSetFaded wwt(aCmd.SetFaded->Faded(),this,blackMap,whiteMap);
sl@0
   501
				WalkWindowTree(wwt,EWalkChildren);
sl@0
   502
				}
sl@0
   503
			else
sl@0
   504
				{
sl@0
   505
				if (iWinType==EWinTypeGroup)
sl@0
   506
					OwnerPanic(EWservPanicOpcode);
sl@0
   507
				
sl@0
   508
				const TBool KNotifyObserver = ETrue; //yes please
sl@0
   509
				const TBool KFaded = aCmd.SetFaded->Faded();
sl@0
   510
				static_cast<CWsClientWindow*>(this)->SetFaded(KFaded, blackMap, whiteMap, KNotifyObserver); 
sl@0
   511
				}
sl@0
   512
			}
sl@0
   513
			break;
sl@0
   514
		case EWsWinOpEnableAdvancedPointers:
sl@0
   515
      if(!IsActivated())
sl@0
   516
          {
sl@0
   517
          // Must call this BEFORE activating the window.
sl@0
   518
          iBaseWinFlags |= EBaseWinAdvancedPointersEnabled;
sl@0
   519
          }
sl@0
   520
      else
sl@0
   521
          {                    
sl@0
   522
          // Called after activation, so panic the client.                
sl@0
   523
          OwnerPanic(EWservPanicUnableToEnableAdvPointer);
sl@0
   524
          }
sl@0
   525
			break;
sl@0
   526
		case EWsWinOpSetSurfaceTransparency:
sl@0
   527
			RDebug::Printf("[Bug 3343] OpCode EWsWinOpSetSurfaceTransparency not supported.");
sl@0
   528
			break;
sl@0
   529
		default:
sl@0
   530
			return(EFalse);
sl@0
   531
		}
sl@0
   532
	return(ETrue);
sl@0
   533
	}
sl@0
   534
sl@0
   535
/** @see MWsWindowTreeNode */
sl@0
   536
MWsWindowTreeNode::TType CWsWindowBase::NodeType() const
sl@0
   537
	{
sl@0
   538
	return static_cast<MWsWindowTreeNode::TType>(iWinType); //TWinType is a subset of MWsWindowTreeNode::TType
sl@0
   539
	}
sl@0
   540
sl@0
   541
/** @see MWsWindowTreeNode */
sl@0
   542
const MWsWindow* CWsWindowBase::Window() const
sl@0
   543
	{
sl@0
   544
	return (iWinType!=EWinTypeGroup) ? (static_cast<const CWsWindow*>(this)) : NULL;
sl@0
   545
	}
sl@0
   546
sl@0
   547
/** @see MWsWindowTreeNode */
sl@0
   548
const MWsSprite* CWsWindowBase::Sprite() const
sl@0
   549
	{
sl@0
   550
	return NULL;
sl@0
   551
	}
sl@0
   552
sl@0
   553
/** @see MWsWindowTreeNode */
sl@0
   554
const MWsStandardTextCursor* CWsWindowBase::StandardTextCursor() const
sl@0
   555
	{
sl@0
   556
	return NULL;
sl@0
   557
	}
sl@0
   558
sl@0
   559
/** @see MWsWindowTreeNode */
sl@0
   560
const MWsWindowGroup* CWsWindowBase::WindowGroup() const
sl@0
   561
	{
sl@0
   562
	return static_cast<MWsWindowGroup*>(WinGroup()); 
sl@0
   563
	}
sl@0
   564
sl@0
   565
/** @see MWsWindowTreeNode */
sl@0
   566
const MWsWindowTreeNode* CWsWindowBase::ParentNode() const
sl@0
   567
	{
sl@0
   568
	return iParent;
sl@0
   569
	}
sl@0
   570
sl@0
   571
TBool CWsWindowBase::QueueEvent(TInt aEvent, TInt aIntVal) const
sl@0
   572
	{
sl@0
   573
	if (WsOwner())
sl@0
   574
		return(WsOwner()->EventQueue()->QueueEvent(iClientHandle, aEvent, aIntVal));
sl@0
   575
	return(EFalse);
sl@0
   576
	}
sl@0
   577
sl@0
   578
void CWsWindowBase::SetPointerCursorByIndex(TInt aIndex)
sl@0
   579
	{
sl@0
   580
	SetPointerCursor(CWsClient::SystemPointerCursor(aIndex));
sl@0
   581
	}
sl@0
   582
sl@0
   583
void CWsWindowBase::SetPointerCursor(CWsPointerCursor *aCursor)
sl@0
   584
	{
sl@0
   585
	CWsPointerCursor *old=iPointerCursor;
sl@0
   586
	iPointerCursor=aCursor;
sl@0
   587
	if (iPointerCursor)
sl@0
   588
		iPointerCursor->Open();
sl@0
   589
	TWsPointer::UpdatePointerCursor();
sl@0
   590
	if (old)
sl@0
   591
		old->Close();
sl@0
   592
	}
sl@0
   593
sl@0
   594
TBool CWsWindowBase::TreeIsObscured() const
sl@0
   595
	{
sl@0
   596
	TBool result;
sl@0
   597
	TWalkWindowTreeIsObscured wwt(result);
sl@0
   598
	CONST_CAST(CWsWindowBase *,this)->WalkWindowTree(wwt,EWalkChildren);
sl@0
   599
	return(result);
sl@0
   600
	}
sl@0
   601
sl@0
   602
CEventQueue *CWsWindowBase::EventQueue() const
sl@0
   603
	{
sl@0
   604
	CEventQueue* eventQueue = NULL;
sl@0
   605
	if (iWsOwner)
sl@0
   606
		eventQueue = iWsOwner->EventQueue();
sl@0
   607
	return eventQueue;
sl@0
   608
	}
sl@0
   609
sl@0
   610
TInt CWsWindowBase::Depth() const
sl@0
   611
	{
sl@0
   612
	TInt count=0;
sl@0
   613
	const CWsWindowBase *win=this;
sl@0
   614
	while (win->WinType()!=EWinTypeRoot)
sl@0
   615
		{
sl@0
   616
		++count;
sl@0
   617
		win=win->iParent;
sl@0
   618
		}
sl@0
   619
	return(count);
sl@0
   620
	}
sl@0
   621
sl@0
   622
void CWsWindowBase::WalkWindowTree(TWalkWindowTreeBase &aWalkClass,TWalkMode aMode)
sl@0
   623
//
sl@0
   624
// Walks windows in a front to back order
sl@0
   625
//
sl@0
   626
// If mode is EWalkBehind
sl@0
   627
//	call DoIt for all windows that are behind 'this'
sl@0
   628
// else if mode is EWalkChildren
sl@0
   629
//  call DoIt for all descendents
sl@0
   630
// else if mode is EWalkChildrenAndBehind
sl@0
   631
//  call DoIt for for all descendents and windows behind
sl@0
   632
//
sl@0
   633
	{
sl@0
   634
	if (this!=NULL)
sl@0
   635
		{
sl@0
   636
		CWsWindowBase *win=this;
sl@0
   637
		CWsWindowBase *end=RootWindow();
sl@0
   638
		CWsWindowBase *sibling=win->iSibling;
sl@0
   639
		CWsWindowBase *parent=win->iParent;
sl@0
   640
		if (aMode!=EWalkBehind)
sl@0
   641
			{
sl@0
   642
			if (aMode==EWalkChildren)
sl@0
   643
				end=win;
sl@0
   644
			goto start;
sl@0
   645
			}
sl@0
   646
		do
sl@0
   647
			{
sl@0
   648
			if (sibling!=NULL)
sl@0
   649
				{
sl@0
   650
				win=sibling;
sl@0
   651
start:			while(win->iChild!=NULL)
sl@0
   652
					win=win->iChild;
sl@0
   653
				}
sl@0
   654
			else
sl@0
   655
				win=parent;
sl@0
   656
			sibling=win->iSibling;	// De-reference win so it can be destroyed by 'DoIt'
sl@0
   657
			parent=win->iParent;
sl@0
   658
			if (win->iWinType!=EWinTypeGroup && aWalkClass.DoIt((CWsWindow *)win))
sl@0
   659
				return;
sl@0
   660
			} while(win!=end);
sl@0
   661
		}
sl@0
   662
	}
sl@0
   663
sl@0
   664
/* Walks windows in a front to back order
sl@0
   665
sl@0
   666
 If aResume is EFalse the walk is identical to above.
sl@0
   667
 Otherwise iWin is taken as the restart point, (any child windows will have been
sl@0
   668
 walked previously).
sl@0
   669
 */
sl@0
   670
void CWsWindowBase::WalkWindowTree(TResumableWalkWindowTreeBase& aWalkClass, TWalkMode aMode, TBool aResume)
sl@0
   671
	{
sl@0
   672
	if (this != NULL)
sl@0
   673
		{ // init
sl@0
   674
		if (!aResume)
sl@0
   675
			{
sl@0
   676
			aWalkClass.iWin = this;
sl@0
   677
			aWalkClass.iEnd = (aMode == EWalkChildren) ? this : RootWindow();
sl@0
   678
			aWalkClass.iParent = aWalkClass.iWin->iParent;
sl@0
   679
			if (aMode == EWalkBehind)
sl@0
   680
				{
sl@0
   681
				aWalkClass.iNextChild = aWalkClass.iWin->iSibling;
sl@0
   682
				}
sl@0
   683
			else
sl@0
   684
				{ // ensure walk includes this and its child windows
sl@0
   685
				aWalkClass.iNextChild = this;
sl@0
   686
				}
sl@0
   687
			}
sl@0
   688
		else if (aWalkClass.iWin == aWalkClass.iEnd)
sl@0
   689
			{
sl@0
   690
			return; // walk had already reached end
sl@0
   691
			}
sl@0
   692
sl@0
   693
		do
sl@0
   694
			{
sl@0
   695
			if (aWalkClass.iNextChild != NULL)
sl@0
   696
				{ // walk down tree to a leaf window
sl@0
   697
				aWalkClass.iWin = aWalkClass.iNextChild;
sl@0
   698
				while (aWalkClass.iWin->iChild != NULL)
sl@0
   699
					{
sl@0
   700
					aWalkClass.iWin = aWalkClass.iWin->iChild;
sl@0
   701
					}
sl@0
   702
				}
sl@0
   703
			else
sl@0
   704
				{ // walk up tree
sl@0
   705
				aWalkClass.iWin = aWalkClass.iParent;
sl@0
   706
				}
sl@0
   707
			// De-reference iWin so it can be destroyed by 'DoIt'
sl@0
   708
			aWalkClass.iNextChild = aWalkClass.iWin->iSibling;
sl@0
   709
			aWalkClass.iParent = aWalkClass.iWin->iParent;
sl@0
   710
			if ( ( aWalkClass.iWin->iWinType != EWinTypeGroup ) && aWalkClass.DoIt(static_cast<CWsWindow *>(aWalkClass.iWin)) )
sl@0
   711
				{
sl@0
   712
				return;
sl@0
   713
				}
sl@0
   714
			}
sl@0
   715
		while (aWalkClass.iWin != aWalkClass.iEnd);
sl@0
   716
		}
sl@0
   717
	}
sl@0
   718
sl@0
   719
void CWsWindowBase::WalkWindowTreeBackToFront(TWalkWindowTreeBase &aWalkClass, TWalkModeBackToFront aMode)
sl@0
   720
	{
sl@0
   721
	// Walks windows in a back to front order
sl@0
   722
	//
sl@0
   723
	// If mode is EVisitParentNodesFirst
sl@0
   724
	// call DoIt() on each node before walking their child windows.	
sl@0
   725
	
sl@0
   726
	if(iSibling)
sl@0
   727
		iSibling->WalkWindowTreeBackToFront(aWalkClass,aMode);
sl@0
   728
	
sl@0
   729
	if(aMode == EVisitParentNodesFirst)
sl@0
   730
		aWalkClass.DoIt(static_cast<CWsWindow *>(this));
sl@0
   731
	
sl@0
   732
	if(iChild)
sl@0
   733
		iChild->WalkWindowTreeBackToFront(aWalkClass,aMode);
sl@0
   734
	
sl@0
   735
	}
sl@0
   736
sl@0
   737
TBool CWsWindowBase::IsDSAHost() const
sl@0
   738
	{
sl@0
   739
	return EFalse;
sl@0
   740
	}
sl@0
   741
sl@0
   742
TBool CWsWindowBase::IsActivated() const
sl@0
   743
	{
sl@0
   744
	return EFalse;
sl@0
   745
	}
sl@0
   746
sl@0
   747
void CWsWindowBase::AddSprite(CWsSpriteBase * aSprite)
sl@0
   748
	{
sl@0
   749
	aSprite->SetNext(iSpriteList);
sl@0
   750
	iSpriteList = aSprite;
sl@0
   751
	}
sl@0
   752
	
sl@0
   753
void CWsWindowBase::RemoveSprite(CWsSpriteBase * aSprite)
sl@0
   754
	{
sl@0
   755
	if (aSprite == iSpriteList)
sl@0
   756
		{
sl@0
   757
		iSpriteList = aSprite->Next();
sl@0
   758
		}
sl@0
   759
	else
sl@0
   760
		{
sl@0
   761
		for (CWsSpriteBase * sprite = iSpriteList; sprite; sprite = sprite->Next())
sl@0
   762
			{
sl@0
   763
			if (sprite->Next() == aSprite)
sl@0
   764
				{
sl@0
   765
				sprite->SetNext(aSprite->Next());
sl@0
   766
				}
sl@0
   767
			}
sl@0
   768
		}
sl@0
   769
	aSprite->SetNext(0);
sl@0
   770
	}
sl@0
   771
sl@0
   772
void CWsWindowBase::SendState(MWsWindowTreeObserver& aWindowTreeObserver) const
sl@0
   773
	{
sl@0
   774
	//Sprites
sl@0
   775
	if(iSpriteList)
sl@0
   776
		iSpriteList->SendState(aWindowTreeObserver);
sl@0
   777
	}
sl@0
   778
sl@0
   779
#if defined(_DEBUG)
sl@0
   780
sl@0
   781
void CWsWindowBase::CheckTree()
sl@0
   782
	{
sl@0
   783
	TWalkWindowTreeCheck wwt1;
sl@0
   784
	WalkWindowTree(wwt1,EWalkChildren);
sl@0
   785
	}
sl@0
   786
sl@0
   787
enum {ENullWsHandle=0xFFFFFFFF};	// Events delivered to this handle are thrown away
sl@0
   788
TBool CWsWindowBase::IsClientHandleInUse(TUint32 aHandle)
sl@0
   789
	{
sl@0
   790
	if (aHandle==static_cast<TUint>(ENullWsHandle))		//This value has a special meaning in test code
sl@0
   791
		return EFalse;
sl@0
   792
	CWsObjectIx* index=iWsOwner->ObjectIndex();
sl@0
   793
	const CWsObject* obj;
sl@0
   794
	TInt length=index->Length();
sl@0
   795
	TInt ii;
sl@0
   796
	for (ii=0;ii<length;++ii)
sl@0
   797
		{
sl@0
   798
		obj=index->At(ii);
sl@0
   799
		if (obj && (obj->Type()==WS_HANDLE_WINDOW || obj->Type()==WS_HANDLE_GROUP_WINDOW))
sl@0
   800
			{
sl@0
   801
			if (STATIC_CAST(const CWsWindowBase*,obj)->ClientHandle()==aHandle)
sl@0
   802
				return ETrue;
sl@0
   803
			}
sl@0
   804
		}
sl@0
   805
	return EFalse;
sl@0
   806
	}
sl@0
   807
sl@0
   808
#endif