Update contrib.
1 // Copyright (c) 1995-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include "windowgroup.h"
24 #include "offscreenbitmap.h"
26 #include "graphics/windowserverconstants.h"
28 void RWsTextCursor::ConstructL(CWsWindowGroup *aGroupWin)
32 iCustomTextCursor = NULL;
35 void RWsTextCursor::Close()
41 void RWsTextCursor::SetL(const TWsWinCmdSetTextCursor &aSet, TBool aClipped)
43 if (aSet.cursor.iType < TTextCursor::ETypeFirst ||
44 (aSet.cursor.iType > TTextCursor::ETypeLast &&
45 aSet.cursor.iType <= TTextCursor::ETypeLastBasic) ||
46 (aSet.cursor.iFlags&static_cast<TUint>(ETextCursorPrivateFlags)))
49 iGroupWin->OwnerPanic(EWservPanicInvalidTextCursor);
53 CWsClientWindow* win = NULL;
54 iGroupWin->WsOwner()->HandleToClientWindow(aSet.window, &win);
56 // Check window is a child of the group window
57 CWsWindowBase* searchWin = NULL;
58 for(searchWin=win; searchWin->WinType()!=EWinTypeGroup; searchWin=searchWin->BaseParent())
60 if (iGroupWin != searchWin)
63 iGroupWin->OwnerPanic(EWservPanicWindow);
66 TPoint pos(aSet.pos.iX, aSet.pos.iY-aSet.cursor.iAscent);
67 TSize size(aSet.cursor.iWidth, aSet.cursor.iHeight);
68 TUint flags = aSet.cursor.iFlags;
69 TInt type = aSet.cursor.iType;
70 TRect clipRect = iClipRect;
71 TRgb color = aSet.cursor.iColor;
72 CWsCustomTextCursor* customTextCursor = iCustomTextCursor;
73 TBool changed = EFalse;
78 if (type > TTextCursor::ETypeLastBasic)
82 customTextCursor = CWsClient::FindCustomTextCursor(type);
83 if (!customTextCursor)
86 iGroupWin->OwnerPanic(EWservPanicNoCustomTextCursor);
90 if( !customTextCursor->HasSpriteMember() )
92 iGroupWin->OwnerPanic(EWservPanicNoSpriteMember);
97 switch (customTextCursor->Alignment())
99 case RWsSession::ECustomTextCursorAlignTop:
101 case RWsSession::ECustomTextCursorAlignBaseline:
102 yAdjust = aSet.cursor.iAscent-1;
104 case RWsSession::ECustomTextCursorAlignBottom:
105 yAdjust = aSet.cursor.iHeight-1;
109 iGroupWin->OwnerPanic(EWservPanicCustomTextCursorAlign);
113 // Start with a clipping rect to be the whole window
114 // relative cursor pos and shrink down to what we want
116 clipSize = win->Size();
117 if (flags & TTextCursor::EFlagClipHorizontal)
120 clipSize.iWidth = size.iWidth;
122 if (flags & TTextCursor::EFlagClipVertical)
124 clipOrigo.iY = -yAdjust;
125 clipSize.iHeight = aSet.cursor.iHeight;
130 customTextCursor = NULL;
135 flags|=ETextCursorFlagClipped;
139 if (pos != iPos || size != iSize || iType != type ||
140 flags != iFlags || clipRect != iClipRect || color != iColor ||
141 customTextCursor != iCustomTextCursor || win != iWin)
143 // There is a change in the cursor.
147 if (iInternalFlags&EHasFocus && changed)
149 TCursorSprite::Hide();
156 iClipRect = clipRect;
158 iCustomTextCursor = customTextCursor;
160 if (customTextCursor && iInternalFlags&EHasFocus)
162 customTextCursor->CompleteL(win, !(flags&TTextCursor::EFlagNoFlash), flags & (TTextCursor::EFlagClipHorizontal | TTextCursor::EFlagClipVertical), clipOrigo, clipSize);
163 customTextCursor->SetPositionNoRedraw(pos);
166 if (iInternalFlags&EHasFocus && changed)
168 TCursorSprite::SetCurrentCursor(this, win);
173 void RWsTextCursor::Cancel()
175 if (iType!=TTextCursor::ETypeNone)
177 if (iInternalFlags&EHasFocus)
178 TCursorSprite::SetFocus(NULL);
179 iType=TTextCursor::ETypeNone;
184 void RWsTextCursor::Disable()
188 TCursorSprite::Hide();
192 void RWsTextCursor::Enable()
196 TCursorSprite::Reveal();
200 void RWsTextCursor::LostFocus()
202 TCursorSprite::SetFocus(NULL);
203 iInternalFlags &= ~EHasFocus;
206 void RWsTextCursor::ReceivedFocus()
208 iInternalFlags |= EHasFocus;
209 if (iType!=TTextCursor::ETypeNone && iWin)
211 TCursorSprite::SetFocus(this,iWin);
212 if (iCustomTextCursor)
214 iCustomTextCursor->SetPositionNoRedraw(iPos);
219 TRect RWsTextCursor::RectRelativeToScreen() const
222 rect.iTl=iPos+iWin->Origin();
223 rect.iBr=rect.iTl+iSize;
227 void RWsTextCursor::doDraw(CFbsBitGc* aGc, const TRegion& aRegion)
229 TRegionFix<1> justInCase;
230 const TRegion *pr= &aRegion;
231 if (aRegion.CheckError())
233 justInCase.AddRect(iWin->AbsRect());
238 aGc->SetUserDisplayMode(iWin->DisplayMode());
239 aGc->SetDitherOrigin(iWin->Origin());
240 aGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
243 case TTextCursor::ETypeRectangle:
245 aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
246 aGc->SetPenStyle(CGraphicsContext::ENullPen);
247 aGc->SetBrushColor(iColor);
250 case TTextCursor::ETypeHollowRectangle:
252 aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
253 aGc->SetPenStyle(CGraphicsContext::ESolidPen);
254 aGc->SetPenColor(iColor);
258 WS_PANIC_ALWAYS(EWsPanicInvalidCursorType);
260 aGc->SetClippingRegion(pr);
261 aGc->DrawRect(RectRelativeToScreen());
262 aGc->SetUserDisplayMode(ENone);
264 TWindowServerEvent::NotifyScreenDrawingEvent(pr);
268 void RWsTextCursor::Draw(CFbsBitGc* aGc, const TRegion& aRegion)
270 iDrawRegion.Copy(iWin->VisibleRegion());
271 if (iFlags&ETextCursorFlagClipped)
273 TRect rect(iClipRect);
274 rect.Move(iWin->Origin());
275 iDrawRegion.ClipRect(rect);
278 // Need to clip against a possible recent screen size change.
279 iDrawRegion.ClipRect(iWin->Screen()->DrawDevice()->SizeInPixels());
283 tmpRegion.Intersection(iDrawRegion, aRegion);
284 if (tmpRegion.CheckError())
285 doDraw(aGc, iDrawRegion);
288 if (!tmpRegion.IsEmpty())
290 doDraw(aGc, tmpRegion);
296 void RWsTextCursor::WindowDisconnected(CWsWindow *aWindow)
302 TBool RWsTextCursor::IsStandardCursorActive()
304 return TCursorSprite::IsStandardCursorActive();
307 TBool RWsTextCursor::IsFlashing() const
309 return !(iFlags&TTextCursor::EFlagNoFlash);
312 void RWsTextCursor::ScheduleReDrawNow()
314 iGroupWin->Screen()->ScheduleAnimation(RectRelativeToScreen(), 0, 0, 0);
318 // Cursor sprite handling
320 TBool TCursorSprite::iHidden=ETrue;
321 RWsTextCursor *TCursorSprite::iCurrentCursor=NULL;
325 // Hide / Reveal text cursors.
326 void TCursorSprite::Hide()
328 if (!iHidden && iCurrentCursor)
331 if (iCurrentCursor->iCustomTextCursor)
333 iCurrentCursor->iCustomTextCursor->Deactivate();
337 iCurrentCursor->ScheduleReDrawNow();
342 void TCursorSprite::Reveal()
344 if(iHidden && iCurrentCursor)
347 if (iCurrentCursor->iCustomTextCursor)
349 iCurrentCursor->iCustomTextCursor->Activate();
353 iCurrentCursor->ScheduleReDrawNow();
358 void TCursorSprite::SetFocus(RWsTextCursor* aFocus,CWsClientWindow* aWin/*=NULL*/)
360 if (iCurrentCursor!=aFocus)
363 SetCurrentCursor(aFocus, aWin);
367 void TCursorSprite::SetCurrentCursor(RWsTextCursor* aFocus, CWsClientWindow* aWin)
369 iCurrentCursor = aFocus;
370 if (aWin && iCurrentCursor && iCurrentCursor->iCustomTextCursor)
372 iCurrentCursor->iCustomTextCursor->SetWindow(aWin);
377 TBool TCursorSprite::IsStandardCursorActive()
379 return iCurrentCursor && !iCurrentCursor->iCustomTextCursor && !iHidden;