os/graphics/windowing/windowserver/nga/SERVER/TCURSOR.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 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
// The text cursor
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <graphics/wscursor.h>
sl@0
    20
#include "server.h"
sl@0
    21
#include "tcursor.h"
sl@0
    22
#include "windowgroup.h"
sl@0
    23
#include "wstop.h"
sl@0
    24
#include "panics.h"
sl@0
    25
#include "EVENT.H"
sl@0
    26
#include "graphics/windowserverconstants.h"
sl@0
    27
sl@0
    28
static const TInt64 KFlashRate(500000); // duration cursor is ON or OFF
sl@0
    29
sl@0
    30
void RWsTextCursor::ConstructL(CWsWindowGroup *aGroupWin)
sl@0
    31
	{
sl@0
    32
	iInternalFlags = 0;
sl@0
    33
	iGroupWin=aGroupWin;
sl@0
    34
	iCustomTextCursor = NULL;
sl@0
    35
	}
sl@0
    36
sl@0
    37
void RWsTextCursor::Close()
sl@0
    38
	{
sl@0
    39
	iDrawRegion.Close();
sl@0
    40
	Cancel();
sl@0
    41
	}
sl@0
    42
sl@0
    43
void RWsTextCursor::SetL(const TWsWinCmdSetTextCursor &aSet, TBool aClipped)
sl@0
    44
	{
sl@0
    45
	if (aSet.cursor.iType < TTextCursor::ETypeFirst ||
sl@0
    46
	        (aSet.cursor.iType > TTextCursor::ETypeLast &&
sl@0
    47
		 aSet.cursor.iType <= TTextCursor::ETypeLastBasic) ||
sl@0
    48
		(aSet.cursor.iFlags&static_cast<TUint>(ETextCursorPrivateFlags)))
sl@0
    49
		{
sl@0
    50
		Cancel();
sl@0
    51
		iGroupWin->OwnerPanic(EWservPanicInvalidTextCursor);
sl@0
    52
		}
sl@0
    53
	else
sl@0
    54
		{
sl@0
    55
		CWsClientWindow* win = NULL;
sl@0
    56
		iGroupWin->WsOwner()->HandleToClientWindow(aSet.window, &win);
sl@0
    57
sl@0
    58
		// Check window is a child of the group window
sl@0
    59
		CWsWindowBase* searchWin = NULL;
sl@0
    60
		for(searchWin=win; searchWin->WinType()!=EWinTypeGroup; searchWin=searchWin->BaseParent())
sl@0
    61
			{}
sl@0
    62
		if (iGroupWin != searchWin)
sl@0
    63
			{
sl@0
    64
			Cancel();
sl@0
    65
			iGroupWin->OwnerPanic(EWservPanicWindow);
sl@0
    66
			}
sl@0
    67
sl@0
    68
		TPoint pos(aSet.pos.iX, aSet.pos.iY-aSet.cursor.iAscent);
sl@0
    69
		TSize size(aSet.cursor.iWidth, aSet.cursor.iHeight);
sl@0
    70
		TUint flags = aSet.cursor.iFlags;
sl@0
    71
		TInt type = aSet.cursor.iType;
sl@0
    72
		TRect clipRect = iClipRect;
sl@0
    73
		TRgb color = aSet.cursor.iColor;
sl@0
    74
		CWsCustomTextCursor* customTextCursor = iCustomTextCursor;
sl@0
    75
		TBool changed = EFalse;
sl@0
    76
sl@0
    77
		TPoint clipOrigo;
sl@0
    78
		TSize clipSize;
sl@0
    79
sl@0
    80
		if (type > TTextCursor::ETypeLastBasic)
sl@0
    81
			{
sl@0
    82
			changed = ETrue;
sl@0
    83
sl@0
    84
			customTextCursor = CWsClient::FindCustomTextCursor(type);
sl@0
    85
			if (!customTextCursor)
sl@0
    86
				{
sl@0
    87
				Cancel();
sl@0
    88
				iGroupWin->OwnerPanic(EWservPanicNoCustomTextCursor);
sl@0
    89
				return;
sl@0
    90
				}
sl@0
    91
			
sl@0
    92
			if( !customTextCursor->HasSpriteMember() )
sl@0
    93
				{
sl@0
    94
				iGroupWin->OwnerPanic(EWservPanicNoSpriteMember);
sl@0
    95
				return;
sl@0
    96
				}
sl@0
    97
			
sl@0
    98
			TInt yAdjust=0;
sl@0
    99
			switch (customTextCursor->Alignment())
sl@0
   100
				{
sl@0
   101
				case RWsSession::ECustomTextCursorAlignTop:
sl@0
   102
					break;
sl@0
   103
				case RWsSession::ECustomTextCursorAlignBaseline:
sl@0
   104
					yAdjust = aSet.cursor.iAscent-1;
sl@0
   105
					break;
sl@0
   106
				case RWsSession::ECustomTextCursorAlignBottom:
sl@0
   107
					yAdjust = aSet.cursor.iHeight-1;
sl@0
   108
					break;
sl@0
   109
				default:
sl@0
   110
					Cancel();
sl@0
   111
					iGroupWin->OwnerPanic(EWservPanicCustomTextCursorAlign);
sl@0
   112
					return;
sl@0
   113
				}
sl@0
   114
			pos.iY += yAdjust;
sl@0
   115
			// Start with a clipping rect to be the whole window
sl@0
   116
			// relative cursor pos and shrink down to what we want
sl@0
   117
			clipOrigo = -pos;
sl@0
   118
			clipSize = win->Size();
sl@0
   119
			if (flags & TTextCursor::EFlagClipHorizontal)
sl@0
   120
				{
sl@0
   121
				clipOrigo.iX = 0;
sl@0
   122
				clipSize.iWidth = size.iWidth;
sl@0
   123
				}
sl@0
   124
			if (flags & TTextCursor::EFlagClipVertical)
sl@0
   125
				{
sl@0
   126
				clipOrigo.iY = -yAdjust;
sl@0
   127
				clipSize.iHeight = aSet.cursor.iHeight;
sl@0
   128
				}
sl@0
   129
			}
sl@0
   130
		else
sl@0
   131
			{
sl@0
   132
			customTextCursor = NULL;
sl@0
   133
			}
sl@0
   134
sl@0
   135
		if (aClipped)
sl@0
   136
			{
sl@0
   137
			flags|=ETextCursorFlagClipped;
sl@0
   138
			clipRect=aSet.rect;
sl@0
   139
			}
sl@0
   140
sl@0
   141
		TPoint absPos(pos.iX,pos.iY);
sl@0
   142
		absPos=absPos+win->Origin();
sl@0
   143
		if (pos != iPos || absPos != iAbsPos || size != iSize || iType != type ||
sl@0
   144
			flags != iFlags || clipRect != iClipRect || color != iColor ||
sl@0
   145
			customTextCursor != iCustomTextCursor || win != iWin)
sl@0
   146
			{
sl@0
   147
			// There is a change in the cursor.
sl@0
   148
			changed = ETrue;
sl@0
   149
			}
sl@0
   150
sl@0
   151
		if (iInternalFlags&EHasFocus && changed)
sl@0
   152
			{
sl@0
   153
			if ((win != iWin && !iCustomTextCursor) || (customTextCursor && !iCustomTextCursor))
sl@0
   154
				ReleaseNode();
sl@0
   155
			TCursorSprite::Hide();
sl@0
   156
			}
sl@0
   157
sl@0
   158
		UpdateAttributes(pos, absPos, size, type, flags, clipRect, color, customTextCursor, win);
sl@0
   159
sl@0
   160
		if (customTextCursor && iInternalFlags&EHasFocus)
sl@0
   161
			{
sl@0
   162
			customTextCursor->CompleteL(win, !(flags&TTextCursor::EFlagNoFlash), flags & (TTextCursor::EFlagClipHorizontal | TTextCursor::EFlagClipVertical), clipOrigo, clipSize);
sl@0
   163
			customTextCursor->SetPositionNoRedraw(pos);
sl@0
   164
			}
sl@0
   165
sl@0
   166
		if (iInternalFlags&EHasFocus && changed)
sl@0
   167
			{
sl@0
   168
			TCursorSprite::SetCurrentCursor(this, win);
sl@0
   169
			}
sl@0
   170
		}
sl@0
   171
	}
sl@0
   172
void RWsTextCursor::UpdateAttributes(TPoint aPos, TPoint aAbsPos, TSize aSize, TInt aType, TUint aFlags, TRect aClipRect, TRgb aColor, CWsCustomTextCursor* aCustomTextCursor, CWsClientWindow* aWin)
sl@0
   173
	{
sl@0
   174
	if (aPos != iPos || aSize != iSize || aAbsPos != iAbsPos)
sl@0
   175
		{
sl@0
   176
		iPos = aPos;
sl@0
   177
        iAbsPos = aAbsPos;
sl@0
   178
		iSize = aSize;
sl@0
   179
		WS_ASSERT_DEBUG(iGroupWin->Screen(),EWsPanicNoScreen);
sl@0
   180
		MWsWindowTreeObserver* const windowTreeObserver = iGroupWin->Screen()->WindowTreeObserver();
sl@0
   181
		if (windowTreeObserver && iInternalFlags&EHasFocus && iInternalFlags&EActiveNode)
sl@0
   182
			windowTreeObserver->NodeExtentChanged(*this, RectRelativeToScreen());
sl@0
   183
		}
sl@0
   184
sl@0
   185
	if (aType != iType)
sl@0
   186
		{
sl@0
   187
		iType = aType;
sl@0
   188
		NotifyObserver(MWsWindowTreeObserver::ECursorType);
sl@0
   189
		}
sl@0
   190
sl@0
   191
	if (aClipRect != iClipRect)
sl@0
   192
		{
sl@0
   193
		iClipRect = aClipRect; // must update clip rect before sending clip rect set/unset notification
sl@0
   194
		if ((aFlags&ETextCursorFlagClipped) && (iFlags&ETextCursorFlagClipped))
sl@0
   195
			NotifyObserver(MWsWindowTreeObserver::ECursorClipRect); // clip rect changed
sl@0
   196
		}
sl@0
   197
sl@0
   198
	if (aFlags != iFlags)
sl@0
   199
		{
sl@0
   200
		TBool sendFlagChanged = EFalse;
sl@0
   201
		if ((aFlags&ETextCursorFlagClipped) != (iFlags&ETextCursorFlagClipped))
sl@0
   202
			{
sl@0
   203
			if (iInternalFlags&EHasFocus && iInternalFlags&EActiveNode)
sl@0
   204
				{
sl@0
   205
				// We can't send flag changed till iFlags has been updated, as otherwise plugins responding to
sl@0
   206
				// the flag changed notification by calling ClipRect() may get the wrong rect
sl@0
   207
				sendFlagChanged = ETrue;
sl@0
   208
				}
sl@0
   209
			}
sl@0
   210
		const TBool userFlagsChanged((aFlags&ETextCursorUserFlags) != (iFlags&ETextCursorUserFlags)); 
sl@0
   211
		iFlags = aFlags;
sl@0
   212
		if (userFlagsChanged)
sl@0
   213
			NotifyObserver(MWsWindowTreeObserver::ECursorFlags);
sl@0
   214
		if (sendFlagChanged)
sl@0
   215
			{
sl@0
   216
			WS_ASSERT_DEBUG(iGroupWin->Screen(),EWsPanicNoScreen);
sl@0
   217
			MWsWindowTreeObserver* const windowTreeObserver = iGroupWin->Screen()->WindowTreeObserver();
sl@0
   218
			if (windowTreeObserver)
sl@0
   219
				windowTreeObserver->FlagChanged(*this, MWsWindowTreeObserver::ECursorClipRectSet, !!(iFlags&ETextCursorFlagClipped)); // clip rect set/unset
sl@0
   220
			}
sl@0
   221
		}
sl@0
   222
sl@0
   223
	if (aColor != iColor)
sl@0
   224
		{
sl@0
   225
		iColor = aColor;
sl@0
   226
		NotifyObserver(MWsWindowTreeObserver::ECursorColor);
sl@0
   227
		}
sl@0
   228
	iCustomTextCursor = aCustomTextCursor;
sl@0
   229
	iWin = aWin;
sl@0
   230
	}
sl@0
   231
sl@0
   232
void RWsTextCursor::NotifyObserver(MWsWindowTreeObserver::TAttributes aAttribute) const
sl@0
   233
	{
sl@0
   234
	if (iInternalFlags&EHasFocus && iInternalFlags&EActiveNode)
sl@0
   235
		{
sl@0
   236
		WS_ASSERT_DEBUG(iGroupWin->Screen(),EWsPanicNoScreen);
sl@0
   237
		MWsWindowTreeObserver* const windowTreeObserver = iGroupWin->Screen()->WindowTreeObserver();
sl@0
   238
		if (windowTreeObserver)
sl@0
   239
			windowTreeObserver->AttributeChanged(*this, aAttribute);
sl@0
   240
		}
sl@0
   241
	}
sl@0
   242
sl@0
   243
void RWsTextCursor::CreateNode()
sl@0
   244
	{
sl@0
   245
	WS_ASSERT_DEBUG(iGroupWin->Screen(),EWsPanicNoScreen);
sl@0
   246
	MWsWindowTreeObserver* const windowTreeObserver = iGroupWin->Screen()->WindowTreeObserver();
sl@0
   247
	if (windowTreeObserver && !(iInternalFlags&EActiveNode))
sl@0
   248
		{
sl@0
   249
		iInternalFlags |= EActiveNode;
sl@0
   250
		windowTreeObserver->NodeCreated(*this, iWin);
sl@0
   251
		windowTreeObserver->NodeExtentChanged(*this, RectRelativeToScreen());
sl@0
   252
		if (iFlags&ETextCursorFlagClipped)
sl@0
   253
			windowTreeObserver->FlagChanged(*this, MWsWindowTreeObserver::ECursorClipRectSet, ETrue);
sl@0
   254
		windowTreeObserver->NodeActivated(*this);
sl@0
   255
		}
sl@0
   256
	}
sl@0
   257
sl@0
   258
void RWsTextCursor::ReleaseNode()
sl@0
   259
	{
sl@0
   260
	if (iInternalFlags&EActiveNode)
sl@0
   261
		{
sl@0
   262
		WS_ASSERT_DEBUG(iGroupWin->Screen(),EWsPanicNoScreen);
sl@0
   263
		MWsWindowTreeObserver* const windowTreeObserver = iGroupWin->Screen()->WindowTreeObserver();
sl@0
   264
		if (windowTreeObserver)
sl@0
   265
			{
sl@0
   266
			windowTreeObserver->NodeReleased(*this);
sl@0
   267
			iInternalFlags &= ~EActiveNode;
sl@0
   268
			}
sl@0
   269
		}
sl@0
   270
	}
sl@0
   271
sl@0
   272
void RWsTextCursor::SendState(MWsWindowTreeObserver& aWindowTreeObserver) const
sl@0
   273
	{
sl@0
   274
	if (iInternalFlags & EActiveNode)
sl@0
   275
		{
sl@0
   276
		aWindowTreeObserver.NodeCreated(*this, iWin);
sl@0
   277
		aWindowTreeObserver.NodeExtentChanged(*this, RectRelativeToScreen());
sl@0
   278
		if (iFlags&ETextCursorFlagClipped)
sl@0
   279
			aWindowTreeObserver.FlagChanged(*this, MWsWindowTreeObserver::ECursorClipRectSet, ETrue);
sl@0
   280
		aWindowTreeObserver.NodeActivated(*this);
sl@0
   281
		}
sl@0
   282
	}
sl@0
   283
sl@0
   284
void RWsTextCursor::Cancel()
sl@0
   285
	{
sl@0
   286
	if (iType!=TTextCursor::ETypeNone)
sl@0
   287
		{
sl@0
   288
		if (iInternalFlags&EHasFocus)
sl@0
   289
			TCursorSprite::SetFocus(NULL);
sl@0
   290
		iType=TTextCursor::ETypeNone;
sl@0
   291
		iWin=NULL;
sl@0
   292
		}
sl@0
   293
	}
sl@0
   294
sl@0
   295
void RWsTextCursor::Disable()
sl@0
   296
	{
sl@0
   297
	if (iWin)
sl@0
   298
		{
sl@0
   299
		TCursorSprite::Hide();
sl@0
   300
		}
sl@0
   301
	}
sl@0
   302
sl@0
   303
void RWsTextCursor::Enable()
sl@0
   304
	{
sl@0
   305
	if (iWin)
sl@0
   306
		{
sl@0
   307
		TCursorSprite::Reveal();
sl@0
   308
		}
sl@0
   309
	}
sl@0
   310
sl@0
   311
void RWsTextCursor::LostFocus()
sl@0
   312
	{
sl@0
   313
	TCursorSprite::SetFocus(NULL);
sl@0
   314
	iInternalFlags &= ~EHasFocus;
sl@0
   315
	}
sl@0
   316
sl@0
   317
void RWsTextCursor::ReceivedFocus()
sl@0
   318
	{
sl@0
   319
	iInternalFlags |= EHasFocus;
sl@0
   320
	if (iType!=TTextCursor::ETypeNone && iWin)
sl@0
   321
		{
sl@0
   322
		TCursorSprite::SetFocus(this,iWin);
sl@0
   323
		if (iCustomTextCursor)
sl@0
   324
			{
sl@0
   325
			iCustomTextCursor->SetPositionNoRedraw(iPos);
sl@0
   326
			}
sl@0
   327
		}
sl@0
   328
	}
sl@0
   329
sl@0
   330
TRect RWsTextCursor::RectRelativeToScreen() const
sl@0
   331
	{
sl@0
   332
	TRect rect;
sl@0
   333
	rect.iTl=iPos+iWin->Origin();
sl@0
   334
	rect.iBr=rect.iTl+iSize;
sl@0
   335
	return(rect);
sl@0
   336
	}
sl@0
   337
sl@0
   338
TRect RWsTextCursor::RectRelativeToWindow() const
sl@0
   339
	{
sl@0
   340
	TRect rect;
sl@0
   341
	rect.iTl=iPos;
sl@0
   342
	rect.iBr=rect.iTl+iSize;
sl@0
   343
	return rect;
sl@0
   344
	}
sl@0
   345
sl@0
   346
void RWsTextCursor::doDraw(const TRegion& aRegion)
sl@0
   347
	{
sl@0
   348
	TRegionFix<1> fallbackClipRegion;
sl@0
   349
	const TRegion *clipRegion= &aRegion;
sl@0
   350
	if (aRegion.CheckError())
sl@0
   351
		{
sl@0
   352
		fallbackClipRegion.AddRect(iWin->AbsRect());
sl@0
   353
		clipRegion= &fallbackClipRegion;
sl@0
   354
		}
sl@0
   355
sl@0
   356
	if(!clipRegion->IsEmpty())
sl@0
   357
		{
sl@0
   358
		MWsTextCursor::TTextCursorInfo renderStageCursorInfo(
sl@0
   359
			RectRelativeToWindow(),
sl@0
   360
			*clipRegion,
sl@0
   361
			iType, static_cast<MWsWindow *>(Win()), iColor
sl@0
   362
			);
sl@0
   363
		
sl@0
   364
		MWsTextCursor* textCursor = iWin->Screen()->RenderStageTextCursor();
sl@0
   365
sl@0
   366
		textCursor->DrawTextCursor(renderStageCursorInfo);
sl@0
   367
sl@0
   368
		TWindowServerEvent::NotifyScreenDrawingEvent(clipRegion);
sl@0
   369
		}
sl@0
   370
	}
sl@0
   371
sl@0
   372
void RWsTextCursor::Draw(const TRegion& aRegion)
sl@0
   373
	{
sl@0
   374
	iDrawRegion.Copy(iWin->VisibleRegion());
sl@0
   375
	if (iFlags&ETextCursorFlagClipped)
sl@0
   376
		{
sl@0
   377
		TRect rect(iClipRect);
sl@0
   378
		rect.Move(iWin->Origin());
sl@0
   379
		iDrawRegion.ClipRect(rect);
sl@0
   380
		}
sl@0
   381
sl@0
   382
	// Need to clip against a possible recent screen size change.
sl@0
   383
	iDrawRegion.ClipRect(iWin->Screen()->SizeInPixels());
sl@0
   384
sl@0
   385
	RWsRegion tmpRegion;
sl@0
   386
	tmpRegion.Intersection(iDrawRegion, aRegion);
sl@0
   387
	if (tmpRegion.CheckError())
sl@0
   388
		doDraw(iDrawRegion);
sl@0
   389
	else
sl@0
   390
		{
sl@0
   391
		if (!tmpRegion.IsEmpty())
sl@0
   392
			{
sl@0
   393
			doDraw(tmpRegion);
sl@0
   394
			}
sl@0
   395
		}
sl@0
   396
	tmpRegion.Close();
sl@0
   397
	}
sl@0
   398
sl@0
   399
void RWsTextCursor::WindowDisconnected(CWsWindow *aWindow)
sl@0
   400
	{
sl@0
   401
	if (iWin==aWindow)
sl@0
   402
		Cancel();
sl@0
   403
	}
sl@0
   404
sl@0
   405
TBool RWsTextCursor::IsStandardCursorActive()
sl@0
   406
	{
sl@0
   407
	return TCursorSprite::IsStandardCursorActive();
sl@0
   408
	}
sl@0
   409
sl@0
   410
TBool RWsTextCursor::IsFlashing() const
sl@0
   411
	{
sl@0
   412
	return !(iFlags&TTextCursor::EFlagNoFlash);
sl@0
   413
	}
sl@0
   414
sl@0
   415
void RWsTextCursor::ScheduleReDrawNow()
sl@0
   416
	{
sl@0
   417
	if (!iGroupWin->Screen()->ChangeTracking())
sl@0
   418
		iGroupWin->Screen()->ScheduleAnimation(ETextCursor, RectRelativeToScreen(), 0, 0, 0, iWin);
sl@0
   419
	}
sl@0
   420
sl@0
   421
/** @see MWsWindowTreeNode */
sl@0
   422
MWsWindowTreeNode::TType RWsTextCursor::NodeType() const
sl@0
   423
	{
sl@0
   424
	return MWsWindowTreeNode::EWinTreeNodeStandardTextCursor; 
sl@0
   425
	}
sl@0
   426
sl@0
   427
/** @see MWsWindowTreeNode */
sl@0
   428
const MWsWindow* RWsTextCursor::Window() const
sl@0
   429
	{
sl@0
   430
	return NULL;
sl@0
   431
	}
sl@0
   432
sl@0
   433
/** @see MWsWindowTreeNode */
sl@0
   434
const MWsSprite* RWsTextCursor::Sprite() const
sl@0
   435
	{
sl@0
   436
	return NULL;
sl@0
   437
	}
sl@0
   438
sl@0
   439
/** @see MWsWindowTreeNode */
sl@0
   440
const MWsStandardTextCursor* RWsTextCursor::StandardTextCursor() const
sl@0
   441
	{
sl@0
   442
	return this;
sl@0
   443
	}
sl@0
   444
sl@0
   445
/** @see MWsWindowTreeNode */
sl@0
   446
const MWsWindowGroup* RWsTextCursor::WindowGroup() const
sl@0
   447
	{
sl@0
   448
	return static_cast<MWsWindowGroup*>(iGroupWin);
sl@0
   449
	}
sl@0
   450
sl@0
   451
/** @see MWsWindowTreeNode */
sl@0
   452
const MWsWindowTreeNode* RWsTextCursor::ParentNode() const
sl@0
   453
	{
sl@0
   454
	return iWin;
sl@0
   455
	}
sl@0
   456
sl@0
   457
/** @see MWsStandardTextCursor */
sl@0
   458
TInt RWsTextCursor::Type() const
sl@0
   459
	{
sl@0
   460
	return iType;
sl@0
   461
	}
sl@0
   462
sl@0
   463
/** @see MWsStandardTextCursor */
sl@0
   464
TRect RWsTextCursor::Rect() const
sl@0
   465
	{
sl@0
   466
	return RectRelativeToScreen();
sl@0
   467
	}
sl@0
   468
sl@0
   469
/** @see MWsStandardTextCursor */
sl@0
   470
TRect RWsTextCursor::ClipRect() const
sl@0
   471
	{
sl@0
   472
	if (iFlags&ETextCursorFlagClipped)
sl@0
   473
		{
sl@0
   474
		TRect clipRectRelativeToScreen(iClipRect);
sl@0
   475
		clipRectRelativeToScreen.Move(iWin->Origin());
sl@0
   476
		return clipRectRelativeToScreen;
sl@0
   477
		}
sl@0
   478
	else
sl@0
   479
		{
sl@0
   480
		return Rect();
sl@0
   481
		}
sl@0
   482
	}
sl@0
   483
sl@0
   484
/** @see MWsStandardTextCursor */
sl@0
   485
TUint RWsTextCursor::Flags() const
sl@0
   486
	{
sl@0
   487
	return iFlags&ETextCursorUserFlags;
sl@0
   488
	}
sl@0
   489
sl@0
   490
/** @see MWsStandardTextCursor */
sl@0
   491
TRgb RWsTextCursor::Color() const
sl@0
   492
	{
sl@0
   493
	return iColor;
sl@0
   494
	}
sl@0
   495
sl@0
   496
/** @see MWsStandardTextCursor */
sl@0
   497
TTimeIntervalMicroSeconds32 RWsTextCursor::FlashInterval() const
sl@0
   498
	{
sl@0
   499
	return iFlags&TTextCursor::EFlagNoFlash ? 0 : KFlashRate;
sl@0
   500
	}
sl@0
   501
sl@0
   502
TFlashState RWsTextCursor::CurrentCursorFlashState() const
sl@0
   503
	{
sl@0
   504
	if (IsFlashing())
sl@0
   505
		{
sl@0
   506
		return (CWsTop::CurrentFocusScreen()->Now().DateTime().MicroSecond()<KFlashRate)?EFlashOn:EFlashOff;
sl@0
   507
		}
sl@0
   508
	else
sl@0
   509
		{
sl@0
   510
		return EFlashOn;
sl@0
   511
		}
sl@0
   512
	}
sl@0
   513
sl@0
   514
sl@0
   515
// Cursor sprite handling
sl@0
   516
sl@0
   517
TBool TCursorSprite::iHidden=ETrue;
sl@0
   518
RWsTextCursor *TCursorSprite::iCurrentCursor=NULL;
sl@0
   519
sl@0
   520
//
sl@0
   521
sl@0
   522
// Hide / Reveal text cursors.
sl@0
   523
void TCursorSprite::Hide()
sl@0
   524
	{
sl@0
   525
	if (!iHidden && iCurrentCursor)
sl@0
   526
		{
sl@0
   527
		iHidden=ETrue;
sl@0
   528
		if (iCurrentCursor->iCustomTextCursor)
sl@0
   529
			{
sl@0
   530
			iCurrentCursor->iCustomTextCursor->Deactivate();
sl@0
   531
			}
sl@0
   532
		else
sl@0
   533
			{
sl@0
   534
			iCurrentCursor->ScheduleReDrawNow();
sl@0
   535
			}
sl@0
   536
		}
sl@0
   537
	}
sl@0
   538
	
sl@0
   539
void TCursorSprite::Reveal()
sl@0
   540
	{
sl@0
   541
	if(iHidden && iCurrentCursor)
sl@0
   542
		{
sl@0
   543
		iHidden=EFalse;
sl@0
   544
		if (iCurrentCursor->iCustomTextCursor)
sl@0
   545
			{
sl@0
   546
			iCurrentCursor->iCustomTextCursor->Activate();
sl@0
   547
			}
sl@0
   548
		else
sl@0
   549
			{
sl@0
   550
			iCurrentCursor->ScheduleReDrawNow();
sl@0
   551
			}
sl@0
   552
		}
sl@0
   553
	}
sl@0
   554
sl@0
   555
void TCursorSprite::SetFocus(RWsTextCursor* aFocus,CWsClientWindow* aWin/*=NULL*/)
sl@0
   556
	{
sl@0
   557
	if (iCurrentCursor!=aFocus)
sl@0
   558
		{
sl@0
   559
		if (iCurrentCursor)
sl@0
   560
			iCurrentCursor->ReleaseNode();
sl@0
   561
		Hide();
sl@0
   562
		SetCurrentCursor(aFocus, aWin);
sl@0
   563
		}
sl@0
   564
	}
sl@0
   565
sl@0
   566
void TCursorSprite::SetCurrentCursor(RWsTextCursor* aFocus, CWsClientWindow* aWin)
sl@0
   567
	{
sl@0
   568
	if (aFocus && !aFocus->iCustomTextCursor)
sl@0
   569
		aFocus->CreateNode();
sl@0
   570
	iCurrentCursor = aFocus;
sl@0
   571
	if (aWin && iCurrentCursor && iCurrentCursor->iCustomTextCursor)
sl@0
   572
		{
sl@0
   573
		iCurrentCursor->iCustomTextCursor->SetWindow(aWin);
sl@0
   574
		}
sl@0
   575
	Reveal();
sl@0
   576
	}
sl@0
   577
sl@0
   578
TBool TCursorSprite::IsStandardCursorActive()
sl@0
   579
	{
sl@0
   580
	return iCurrentCursor && !iCurrentCursor->iCustomTextCursor && !iHidden;
sl@0
   581
	}
sl@0
   582