|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // The text cursor |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include "server.h" |
|
20 #include "tcursor.h" |
|
21 #include "windowgroup.h" |
|
22 #include "wstop.h" |
|
23 #include "panics.h" |
|
24 #include "offscreenbitmap.h" |
|
25 #include "EVENT.H" |
|
26 #include "graphics/windowserverconstants.h" |
|
27 |
|
28 void RWsTextCursor::ConstructL(CWsWindowGroup *aGroupWin) |
|
29 { |
|
30 iInternalFlags = 0; |
|
31 iGroupWin=aGroupWin; |
|
32 iCustomTextCursor = NULL; |
|
33 } |
|
34 |
|
35 void RWsTextCursor::Close() |
|
36 { |
|
37 iDrawRegion.Close(); |
|
38 Cancel(); |
|
39 } |
|
40 |
|
41 void RWsTextCursor::SetL(const TWsWinCmdSetTextCursor &aSet, TBool aClipped) |
|
42 { |
|
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))) |
|
47 { |
|
48 Cancel(); |
|
49 iGroupWin->OwnerPanic(EWservPanicInvalidTextCursor); |
|
50 } |
|
51 else |
|
52 { |
|
53 CWsClientWindow* win = NULL; |
|
54 iGroupWin->WsOwner()->HandleToClientWindow(aSet.window, &win); |
|
55 |
|
56 // Check window is a child of the group window |
|
57 CWsWindowBase* searchWin = NULL; |
|
58 for(searchWin=win; searchWin->WinType()!=EWinTypeGroup; searchWin=searchWin->BaseParent()) |
|
59 {} |
|
60 if (iGroupWin != searchWin) |
|
61 { |
|
62 Cancel(); |
|
63 iGroupWin->OwnerPanic(EWservPanicWindow); |
|
64 } |
|
65 |
|
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; |
|
74 |
|
75 TPoint clipOrigo; |
|
76 TSize clipSize; |
|
77 |
|
78 if (type > TTextCursor::ETypeLastBasic) |
|
79 { |
|
80 changed = ETrue; |
|
81 |
|
82 customTextCursor = CWsClient::FindCustomTextCursor(type); |
|
83 if (!customTextCursor) |
|
84 { |
|
85 Cancel(); |
|
86 iGroupWin->OwnerPanic(EWservPanicNoCustomTextCursor); |
|
87 return; |
|
88 } |
|
89 |
|
90 if( !customTextCursor->HasSpriteMember() ) |
|
91 { |
|
92 iGroupWin->OwnerPanic(EWservPanicNoSpriteMember); |
|
93 return; |
|
94 } |
|
95 |
|
96 TInt yAdjust=0; |
|
97 switch (customTextCursor->Alignment()) |
|
98 { |
|
99 case RWsSession::ECustomTextCursorAlignTop: |
|
100 break; |
|
101 case RWsSession::ECustomTextCursorAlignBaseline: |
|
102 yAdjust = aSet.cursor.iAscent-1; |
|
103 break; |
|
104 case RWsSession::ECustomTextCursorAlignBottom: |
|
105 yAdjust = aSet.cursor.iHeight-1; |
|
106 break; |
|
107 default: |
|
108 Cancel(); |
|
109 iGroupWin->OwnerPanic(EWservPanicCustomTextCursorAlign); |
|
110 return; |
|
111 } |
|
112 pos.iY += yAdjust; |
|
113 // Start with a clipping rect to be the whole window |
|
114 // relative cursor pos and shrink down to what we want |
|
115 clipOrigo = -pos; |
|
116 clipSize = win->Size(); |
|
117 if (flags & TTextCursor::EFlagClipHorizontal) |
|
118 { |
|
119 clipOrigo.iX = 0; |
|
120 clipSize.iWidth = size.iWidth; |
|
121 } |
|
122 if (flags & TTextCursor::EFlagClipVertical) |
|
123 { |
|
124 clipOrigo.iY = -yAdjust; |
|
125 clipSize.iHeight = aSet.cursor.iHeight; |
|
126 } |
|
127 } |
|
128 else |
|
129 { |
|
130 customTextCursor = NULL; |
|
131 } |
|
132 |
|
133 if (aClipped) |
|
134 { |
|
135 flags|=ETextCursorFlagClipped; |
|
136 clipRect=aSet.rect; |
|
137 } |
|
138 |
|
139 if (pos != iPos || size != iSize || iType != type || |
|
140 flags != iFlags || clipRect != iClipRect || color != iColor || |
|
141 customTextCursor != iCustomTextCursor || win != iWin) |
|
142 { |
|
143 // There is a change in the cursor. |
|
144 changed = ETrue; |
|
145 } |
|
146 |
|
147 if (iInternalFlags&EHasFocus && changed) |
|
148 { |
|
149 TCursorSprite::Hide(); |
|
150 } |
|
151 |
|
152 iPos = pos; |
|
153 iSize = size; |
|
154 iType = type; |
|
155 iFlags= flags; |
|
156 iClipRect = clipRect; |
|
157 iColor = color; |
|
158 iCustomTextCursor = customTextCursor; |
|
159 iWin = win; |
|
160 if (customTextCursor && iInternalFlags&EHasFocus) |
|
161 { |
|
162 customTextCursor->CompleteL(win, !(flags&TTextCursor::EFlagNoFlash), flags & (TTextCursor::EFlagClipHorizontal | TTextCursor::EFlagClipVertical), clipOrigo, clipSize); |
|
163 customTextCursor->SetPositionNoRedraw(pos); |
|
164 } |
|
165 |
|
166 if (iInternalFlags&EHasFocus && changed) |
|
167 { |
|
168 TCursorSprite::SetCurrentCursor(this, win); |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 void RWsTextCursor::Cancel() |
|
174 { |
|
175 if (iType!=TTextCursor::ETypeNone) |
|
176 { |
|
177 if (iInternalFlags&EHasFocus) |
|
178 TCursorSprite::SetFocus(NULL); |
|
179 iType=TTextCursor::ETypeNone; |
|
180 iWin=NULL; |
|
181 } |
|
182 } |
|
183 |
|
184 void RWsTextCursor::Disable() |
|
185 { |
|
186 if (iWin) |
|
187 { |
|
188 TCursorSprite::Hide(); |
|
189 } |
|
190 } |
|
191 |
|
192 void RWsTextCursor::Enable() |
|
193 { |
|
194 if (iWin) |
|
195 { |
|
196 TCursorSprite::Reveal(); |
|
197 } |
|
198 } |
|
199 |
|
200 void RWsTextCursor::LostFocus() |
|
201 { |
|
202 TCursorSprite::SetFocus(NULL); |
|
203 iInternalFlags &= ~EHasFocus; |
|
204 } |
|
205 |
|
206 void RWsTextCursor::ReceivedFocus() |
|
207 { |
|
208 iInternalFlags |= EHasFocus; |
|
209 if (iType!=TTextCursor::ETypeNone && iWin) |
|
210 { |
|
211 TCursorSprite::SetFocus(this,iWin); |
|
212 if (iCustomTextCursor) |
|
213 { |
|
214 iCustomTextCursor->SetPositionNoRedraw(iPos); |
|
215 } |
|
216 } |
|
217 } |
|
218 |
|
219 TRect RWsTextCursor::RectRelativeToScreen() const |
|
220 { |
|
221 TRect rect; |
|
222 rect.iTl=iPos+iWin->Origin(); |
|
223 rect.iBr=rect.iTl+iSize; |
|
224 return(rect); |
|
225 } |
|
226 |
|
227 void RWsTextCursor::doDraw(CFbsBitGc* aGc, const TRegion& aRegion) |
|
228 { |
|
229 TRegionFix<1> justInCase; |
|
230 const TRegion *pr= &aRegion; |
|
231 if (aRegion.CheckError()) |
|
232 { |
|
233 justInCase.AddRect(iWin->AbsRect()); |
|
234 pr= &justInCase; |
|
235 } |
|
236 if (!pr->IsEmpty()) |
|
237 { |
|
238 aGc->SetUserDisplayMode(iWin->DisplayMode()); |
|
239 aGc->SetDitherOrigin(iWin->Origin()); |
|
240 aGc->SetDrawMode(CGraphicsContext::EDrawModeXOR); |
|
241 switch (iType) |
|
242 { |
|
243 case TTextCursor::ETypeRectangle: |
|
244 { |
|
245 aGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
246 aGc->SetPenStyle(CGraphicsContext::ENullPen); |
|
247 aGc->SetBrushColor(iColor); |
|
248 } |
|
249 break; |
|
250 case TTextCursor::ETypeHollowRectangle: |
|
251 { |
|
252 aGc->SetBrushStyle(CGraphicsContext::ENullBrush); |
|
253 aGc->SetPenStyle(CGraphicsContext::ESolidPen); |
|
254 aGc->SetPenColor(iColor); |
|
255 } |
|
256 break; |
|
257 default: |
|
258 WS_PANIC_ALWAYS(EWsPanicInvalidCursorType); |
|
259 } |
|
260 aGc->SetClippingRegion(pr); |
|
261 aGc->DrawRect(RectRelativeToScreen()); |
|
262 aGc->SetUserDisplayMode(ENone); |
|
263 |
|
264 TWindowServerEvent::NotifyScreenDrawingEvent(pr); |
|
265 } |
|
266 } |
|
267 |
|
268 void RWsTextCursor::Draw(CFbsBitGc* aGc, const TRegion& aRegion) |
|
269 { |
|
270 iDrawRegion.Copy(iWin->VisibleRegion()); |
|
271 if (iFlags&ETextCursorFlagClipped) |
|
272 { |
|
273 TRect rect(iClipRect); |
|
274 rect.Move(iWin->Origin()); |
|
275 iDrawRegion.ClipRect(rect); |
|
276 } |
|
277 |
|
278 // Need to clip against a possible recent screen size change. |
|
279 iDrawRegion.ClipRect(iWin->Screen()->DrawDevice()->SizeInPixels()); |
|
280 |
|
281 |
|
282 RWsRegion tmpRegion; |
|
283 tmpRegion.Intersection(iDrawRegion, aRegion); |
|
284 if (tmpRegion.CheckError()) |
|
285 doDraw(aGc, iDrawRegion); |
|
286 else |
|
287 { |
|
288 if (!tmpRegion.IsEmpty()) |
|
289 { |
|
290 doDraw(aGc, tmpRegion); |
|
291 } |
|
292 } |
|
293 tmpRegion.Close(); |
|
294 } |
|
295 |
|
296 void RWsTextCursor::WindowDisconnected(CWsWindow *aWindow) |
|
297 { |
|
298 if (iWin==aWindow) |
|
299 Cancel(); |
|
300 } |
|
301 |
|
302 TBool RWsTextCursor::IsStandardCursorActive() |
|
303 { |
|
304 return TCursorSprite::IsStandardCursorActive(); |
|
305 } |
|
306 |
|
307 TBool RWsTextCursor::IsFlashing() const |
|
308 { |
|
309 return !(iFlags&TTextCursor::EFlagNoFlash); |
|
310 } |
|
311 |
|
312 void RWsTextCursor::ScheduleReDrawNow() |
|
313 { |
|
314 iGroupWin->Screen()->ScheduleAnimation(RectRelativeToScreen(), 0, 0, 0); |
|
315 } |
|
316 |
|
317 |
|
318 // Cursor sprite handling |
|
319 |
|
320 TBool TCursorSprite::iHidden=ETrue; |
|
321 RWsTextCursor *TCursorSprite::iCurrentCursor=NULL; |
|
322 |
|
323 // |
|
324 |
|
325 // Hide / Reveal text cursors. |
|
326 void TCursorSprite::Hide() |
|
327 { |
|
328 if (!iHidden && iCurrentCursor) |
|
329 { |
|
330 iHidden=ETrue; |
|
331 if (iCurrentCursor->iCustomTextCursor) |
|
332 { |
|
333 iCurrentCursor->iCustomTextCursor->Deactivate(); |
|
334 } |
|
335 else |
|
336 { |
|
337 iCurrentCursor->ScheduleReDrawNow(); |
|
338 } |
|
339 } |
|
340 } |
|
341 |
|
342 void TCursorSprite::Reveal() |
|
343 { |
|
344 if(iHidden && iCurrentCursor) |
|
345 { |
|
346 iHidden=EFalse; |
|
347 if (iCurrentCursor->iCustomTextCursor) |
|
348 { |
|
349 iCurrentCursor->iCustomTextCursor->Activate(); |
|
350 } |
|
351 else |
|
352 { |
|
353 iCurrentCursor->ScheduleReDrawNow(); |
|
354 } |
|
355 } |
|
356 } |
|
357 |
|
358 void TCursorSprite::SetFocus(RWsTextCursor* aFocus,CWsClientWindow* aWin/*=NULL*/) |
|
359 { |
|
360 if (iCurrentCursor!=aFocus) |
|
361 { |
|
362 Hide(); |
|
363 SetCurrentCursor(aFocus, aWin); |
|
364 } |
|
365 } |
|
366 |
|
367 void TCursorSprite::SetCurrentCursor(RWsTextCursor* aFocus, CWsClientWindow* aWin) |
|
368 { |
|
369 iCurrentCursor = aFocus; |
|
370 if (aWin && iCurrentCursor && iCurrentCursor->iCustomTextCursor) |
|
371 { |
|
372 iCurrentCursor->iCustomTextCursor->SetWindow(aWin); |
|
373 } |
|
374 Reveal(); |
|
375 } |
|
376 |
|
377 TBool TCursorSprite::IsStandardCursorActive() |
|
378 { |
|
379 return iCurrentCursor && !iCurrentCursor->iCustomTextCursor && !iHidden; |
|
380 } |
|
381 |