|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "FRMTVIEW.H" |
|
20 #include "FRMCONST.H" |
|
21 #include "FORMUTIL.H" |
|
22 |
|
23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 #include "FRMCONST_INTERNAL.H" |
|
25 #include "FRMCONST_PARTNER.H" |
|
26 #include "TAGMA_INTERNAL.H" |
|
27 #endif |
|
28 |
|
29 RScreenDisplay::RScreenDisplay(TDrawTextLayoutContext* const aDrawTextLayoutContext): |
|
30 iSession(NULL), |
|
31 iGroupWin(NULL), |
|
32 iWin(NULL), |
|
33 iGc(NULL), |
|
34 iDrawTextLayoutContext(aDrawTextLayoutContext), |
|
35 iBackground(KRgbWhite) |
|
36 { |
|
37 } |
|
38 |
|
39 void RScreenDisplay::Close() |
|
40 // |
|
41 { |
|
42 |
|
43 DestroyContexts(); |
|
44 } |
|
45 |
|
46 void RScreenDisplay::Destroy() |
|
47 // |
|
48 { |
|
49 |
|
50 Close(); |
|
51 delete this; |
|
52 } |
|
53 |
|
54 void RScreenDisplay::DestroyContexts() |
|
55 // |
|
56 //Destroy the graphics contexts |
|
57 // |
|
58 { |
|
59 |
|
60 if (iGc) |
|
61 delete iGc; |
|
62 iGc=NULL; |
|
63 } |
|
64 |
|
65 void RScreenDisplay::ActivateContext() |
|
66 // |
|
67 { |
|
68 ActivateContext(iGc); |
|
69 iBackground = iDrawTextLayoutContext->iBackgroundColor; |
|
70 const MFormParam* p = MFormParam::Get(); |
|
71 FormUtil::LogicalToActualColor(p,iBackground); |
|
72 } |
|
73 |
|
74 void RScreenDisplay::ActivateContext(CGraphicsContext *aGc) |
|
75 // |
|
76 //Activate a gc on the current window |
|
77 // |
|
78 { |
|
79 |
|
80 //__ASSERT_DEBUG(aGc!=NULL,FormPanic()); |
|
81 if (iWin) |
|
82 ((CWindowGc *) aGc)->Activate(*iWin); |
|
83 } |
|
84 |
|
85 void RScreenDisplay::DeactivateContext() |
|
86 // |
|
87 { |
|
88 DeactivateContext(iGc); |
|
89 } |
|
90 |
|
91 void RScreenDisplay::DeactivateContext(CGraphicsContext *aGc) |
|
92 // |
|
93 //Deactivate a gc on the current window |
|
94 // |
|
95 { |
|
96 |
|
97 //__ASSERT_DEBUG(aGc!=NULL,FormPanic()); |
|
98 if (iWin) |
|
99 ((CWindowGc *) aGc)->Deactivate(); |
|
100 } |
|
101 |
|
102 void RScreenDisplay::CreateContextL() |
|
103 // |
|
104 //Create and activate the main Graphics Context |
|
105 // |
|
106 { |
|
107 __ASSERT_DEBUG(iGc==NULL,FormPanic(EFGcNotSet)); |
|
108 User::LeaveIfError(iGd->CreateBitmapContext(iGc)); |
|
109 if (iWin) |
|
110 iDrawTextLayoutContext->SetWindowGc((CWindowGc *)iGc); |
|
111 else |
|
112 iDrawTextLayoutContext->SetBitmapGc(iGc); |
|
113 } |
|
114 |
|
115 void RScreenDisplay::CreateContextL(CBitmapDevice *aGd) |
|
116 // |
|
117 //Create and activate the main Graphics Context |
|
118 // |
|
119 { |
|
120 CBitmapContext* localGc; |
|
121 localGc=NULL; |
|
122 //__ASSERT_DEBUG(iGc==NULL,FormPanic(EFGcNotSet)); |
|
123 User::LeaveIfError(aGd->CreateBitmapContext(localGc)); |
|
124 delete iGc; |
|
125 iGc=NULL; |
|
126 iGc=localGc; |
|
127 iGd=aGd; |
|
128 if (iWin) |
|
129 iDrawTextLayoutContext->SetWindowGc((CWindowGc *)iGc); |
|
130 else |
|
131 iDrawTextLayoutContext->SetBitmapGc(iGc); |
|
132 } |
|
133 |
|
134 void RScreenDisplay::SetWindow(RWindow *aWin) |
|
135 // |
|
136 { |
|
137 |
|
138 iWin=aWin; |
|
139 } |
|
140 |
|
141 void RScreenDisplay::SetGraphicsDeviceL(CBitmapDevice *aGd) |
|
142 // |
|
143 { |
|
144 |
|
145 //DestroyContexts(); |
|
146 //iGd=aGd; |
|
147 CreateContextL(aGd); |
|
148 } |
|
149 |
|
150 void RScreenDisplay::SetInvalidRect(const TRect& aRect) |
|
151 // |
|
152 { |
|
153 |
|
154 iInvalidRect=aRect; |
|
155 } |
|
156 |
|
157 void RScreenDisplay::SetInvalidRect(TInt aHeight) |
|
158 // |
|
159 //Set the clipping region to the top or bottom abs(aHeight) pixels of the screen |
|
160 //aHeight<0 ==> bottom of the screen |
|
161 // |
|
162 { |
|
163 |
|
164 iInvalidRect=iDrawTextLayoutContext->iViewRect; |
|
165 if (aHeight<0) |
|
166 iInvalidRect.iTl.iY=iInvalidRect.iBr.iY+aHeight; |
|
167 else |
|
168 iInvalidRect.iBr.iY=iInvalidRect.iTl.iY+aHeight; |
|
169 } |
|
170 |
|
171 void RScreenDisplay::SetInvalidRectHorizontal(TInt aWidth) |
|
172 // |
|
173 //Set the clipping region to the left or right abs(aHeight) pixels of the screen |
|
174 //aWidth<0 ==> right of the screen |
|
175 // |
|
176 { |
|
177 |
|
178 iInvalidRect=iDrawTextLayoutContext->TextArea(); |
|
179 if (aWidth<0) |
|
180 iInvalidRect.iTl.iX=iInvalidRect.iBr.iX+aWidth; |
|
181 else |
|
182 iInvalidRect.iBr.iX=iInvalidRect.iTl.iX+aWidth; |
|
183 } |
|
184 |
|
185 void RScreenDisplay::SetRects(TUint aRects) |
|
186 // |
|
187 //Set the clipping region to the union of rectangles specified in the enum |
|
188 // |
|
189 { |
|
190 |
|
191 iRects=aRects; |
|
192 } |
|
193 |
|
194 void RScreenDisplay::AddRects(TUint aRects) |
|
195 // |
|
196 { |
|
197 |
|
198 iRects|=aRects; |
|
199 } |
|
200 |
|
201 void RScreenDisplay::SubRects(TUint aRects) |
|
202 // |
|
203 { |
|
204 |
|
205 iRects&=EFClipAllFlags-aRects; |
|
206 } |
|
207 |
|
208 |
|
209 TRect RScreenDisplay::ClippingRect() |
|
210 // |
|
211 { |
|
212 |
|
213 TRect clipRect(iDrawTextLayoutContext->iViewRect); |
|
214 |
|
215 if (!(iRects&EFClipViewRect)) |
|
216 { |
|
217 if (iRects&EFClipTextArea) |
|
218 clipRect=iDrawTextLayoutContext->TextArea(); |
|
219 else if (iRects&EFClipLineCursor) |
|
220 clipRect=LineCursorMargin(); |
|
221 if (iRects&EFClipExtendedViewRect && iTextLayout) |
|
222 iTextLayout->HighlightExtensions().ExtendRect(clipRect); |
|
223 if (iRects&EFClipExtendedTextArea) |
|
224 { |
|
225 clipRect=iDrawTextLayoutContext->TextArea(); |
|
226 if (iTextLayout) |
|
227 iTextLayout->HighlightExtensions().ExtendRect(clipRect); |
|
228 } |
|
229 } |
|
230 if (iRects&EFClipInvalid) |
|
231 clipRect.Intersection(iInvalidRect); |
|
232 return clipRect; |
|
233 } |
|
234 |
|
235 |
|
236 void RScreenDisplay::ResetClippingRect() |
|
237 { |
|
238 TRect clipRect=ClippingRect(); |
|
239 iGc->SetClippingRect(clipRect); |
|
240 } |
|
241 |
|
242 void RScreenDisplay::BlastBitmap(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aRect) |
|
243 // |
|
244 // Blast bitmap to screen |
|
245 // |
|
246 { |
|
247 iGc->BitBlt(aPoint,aBitmap,aRect); |
|
248 } |
|
249 |
|
250 void RScreenDisplay::DrawPictureFrame(TFrameOverlay* aPictureFrame,const TRect& aLineRect) |
|
251 // |
|
252 // Draw a frame overlay, using XOR brush. Therefore if frame visible, the frame will disappear, |
|
253 // and vice versa. |
|
254 // |
|
255 { |
|
256 TRect clipRect=ClippingRect(); |
|
257 clipRect.Intersection(aLineRect); |
|
258 iGc->SetClippingRect(clipRect); |
|
259 iGc->SetPenSize(TSize(1,1)); |
|
260 aPictureFrame->XorDraw(*iGc); |
|
261 ResetClippingRect(); |
|
262 } |
|
263 |
|
264 void RScreenDisplay::Invalidate(TRect aRect) |
|
265 // |
|
266 //Invalidate the view rect |
|
267 // |
|
268 { |
|
269 if (iWin) |
|
270 iWin->Invalidate(aRect); |
|
271 } |
|
272 |
|
273 void RScreenDisplay::SetTextCursor(TPoint aPos, const TTextCursor &aCursor) |
|
274 // |
|
275 //Display a cursor at position aPos |
|
276 // |
|
277 { |
|
278 if (iWin && iGroupWin) |
|
279 { |
|
280 aPos.iX+=iDrawTextLayoutContext->iTextStartX; |
|
281 iGroupWin->SetTextCursor(*iWin,aPos,aCursor,iDrawTextLayoutContext->TextArea()); |
|
282 } |
|
283 } |
|
284 |
|
285 void RScreenDisplay::RemoveTextCursor() |
|
286 // |
|
287 //Remove cursor from window |
|
288 // |
|
289 { |
|
290 |
|
291 if (iGroupWin) |
|
292 iGroupWin->CancelTextCursor(); |
|
293 } |
|
294 |
|
295 void RScreenDisplay::ClearRect(const TRect& aRect) |
|
296 // |
|
297 //Clear a rectangle on the screen |
|
298 // |
|
299 { |
|
300 if (iTextLayout) |
|
301 { |
|
302 TPoint top_left = iDrawTextLayoutContext->TopLeftText(); |
|
303 iTextLayout->DrawBackground(*iGc,top_left,aRect,iBackground); |
|
304 ResetClippingRect(); |
|
305 } |
|
306 else |
|
307 { |
|
308 iGc->SetBrushColor(iBackground); |
|
309 iGc->Clear(aRect); |
|
310 } |
|
311 } |
|
312 |
|
313 void RScreenDisplay::InvertRect(TRect aRect,const TRgb aInvertColor) |
|
314 { |
|
315 aRect.Move(iDrawTextLayoutContext->iTextStartX,0); |
|
316 iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR); |
|
317 iGc->SetBrushColor(aInvertColor); |
|
318 iGc->Clear(aRect); |
|
319 iGc->SetBrushColor(iBackground); |
|
320 iGc->SetDrawMode(CGraphicsContext::EDrawModePEN); |
|
321 } |
|
322 |
|
323 void RScreenDisplay::Scroll(TRect aRect,const TPoint& aBy,TBool aScrollBackground) |
|
324 { |
|
325 if (iWin) |
|
326 { |
|
327 if (!aScrollBackground || (iTextLayout && iTextLayout->CustomDraw())) |
|
328 { |
|
329 aRect.Move(aBy); |
|
330 iWin->Invalidate(aRect); |
|
331 } |
|
332 else |
|
333 iWin->Scroll(aBy,aRect); |
|
334 } |
|
335 return; |
|
336 } |
|
337 |
|
338 void RScreenDisplay::Flush() |
|
339 { |
|
340 if (iSession) |
|
341 iSession->Flush(); |
|
342 } |
|
343 |
|
344 TBool RScreenDisplay::IsLineCursor() const |
|
345 { |
|
346 return iDrawTextLayoutContext->IsGutterMargin(); |
|
347 } |
|
348 |
|
349 TRect RScreenDisplay::LineCursorMargin() const |
|
350 { |
|
351 return iDrawTextLayoutContext->GutterMargin(); |
|
352 } |
|
353 |
|
354 TPoint RScreenDisplay::TopLeftTextArea() const |
|
355 { |
|
356 return iDrawTextLayoutContext->TopLeftTextArea(); |
|
357 } |
|
358 |
|
359 void RScreenDisplay::SetLayout(CTextLayout* aLayout) |
|
360 { |
|
361 iTextLayout = aLayout; |
|
362 iTextLayout->SetWindow(iWin); |
|
363 } |
|
364 |
|
365 CTextLayout* RScreenDisplay::Layout() |
|
366 { |
|
367 return iTextLayout; |
|
368 } |
|
369 |
|
370 TBool RScreenDisplay::UseWindowGc() const |
|
371 { |
|
372 return iDrawTextLayoutContext->UseWindowGc(); |
|
373 } |