|
1 /* |
|
2 * Copyright (c) 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: CMIDCanvasGraphicsItem - Implements the native part Canvas Graphics Item Painter class. |
|
15 |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CMIDCANVASGRAPHICSITEMPAINTER_H |
|
21 #define CMIDCANVASGRAPHICSITEMPAINTER_H |
|
22 |
|
23 // EXTERNAL INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <MMIDCanvasGraphicsItemPainter.h> |
|
26 #include <MMIDCustomComponent.h> |
|
27 |
|
28 #include <reflcdui.h> |
|
29 #include <coecntrl.h> |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class CCoeControl; |
|
33 class MMIDCustomComponentContainer; |
|
34 class CMIDCanvasGraphicsItem; |
|
35 |
|
36 |
|
37 // CLASS DESCRIPTION |
|
38 /** |
|
39 * Defines the Canvas Graphics Item Painter native side component. |
|
40 */ |
|
41 NONSHARABLE_CLASS(CMIDCanvasGraphicsItemPainter) : |
|
42 public CCoeControl, |
|
43 public MMIDCanvasGraphicsItemPainter, |
|
44 public MMIDBufferProcessor, |
|
45 public MDirectContent |
|
46 { |
|
47 public: // Type definitions |
|
48 |
|
49 class TCtorParams |
|
50 { |
|
51 public: |
|
52 // The width of the graphics item in pixels. |
|
53 TInt iWidth; |
|
54 |
|
55 // The height of the graphics item in pixels or in rows. |
|
56 TInt iHeight; |
|
57 |
|
58 // Environment instance |
|
59 MMIDEnv* iEnv; |
|
60 |
|
61 TCtorParams::TCtorParams() : |
|
62 iWidth(0), |
|
63 iHeight(0), |
|
64 iEnv(NULL) |
|
65 {} |
|
66 }; |
|
67 |
|
68 public: // Constructors and destructor |
|
69 |
|
70 /** |
|
71 * Two-phased constructor. Creates an instance from this class |
|
72 * The caller takes the ownership of the returned instance |
|
73 * |
|
74 * @param aParams The construction parameters of this class. |
|
75 * @return New instance from this class |
|
76 */ |
|
77 static CMIDCanvasGraphicsItemPainter* NewL(const TCtorParams& aParams); |
|
78 |
|
79 /** |
|
80 * Destructor. |
|
81 */ |
|
82 virtual ~CMIDCanvasGraphicsItemPainter(); |
|
83 |
|
84 // from base class MMIDCanvasGraphicsItemPainter |
|
85 |
|
86 /** |
|
87 * From MMIDComponent |
|
88 * Invoked by the framework to clean up any resources used by the |
|
89 * implementation. |
|
90 * |
|
91 * Typically, the implementation will do "delete this" but is clearly |
|
92 * not restricted to |
|
93 * |
|
94 * @since S60 5.0 |
|
95 */ |
|
96 void Dispose(); |
|
97 |
|
98 /** |
|
99 * From MMIDComponent. |
|
100 * Returns buffer processor associated with this component. |
|
101 * |
|
102 * @since S60 v3.0 |
|
103 * @return Always returns this. |
|
104 */ |
|
105 MMIDBufferProcessor* Processor(); |
|
106 |
|
107 /** |
|
108 * From MMIDCanvasGraphicsItemPainter |
|
109 * Sets the position of this canvas graphics item component. |
|
110 * |
|
111 * @param aX The x coordinate of the anchor point. |
|
112 * @param aY The y coordinate of the anchor point. |
|
113 * @since S60 5.0 |
|
114 */ |
|
115 void SetPosition(const TInt aX, const TInt aY); |
|
116 |
|
117 /** |
|
118 * From MMIDCanvasGraphicsItemPainter |
|
119 * Sets the size of this graphics item component. |
|
120 * |
|
121 * @param aWidth The width value of the anchor point. |
|
122 * @param aHeight The height value of the anchor point. |
|
123 * @since S60 5.0 |
|
124 */ |
|
125 void SetItemSizeL(const TInt aWidth, const TInt aHeight); |
|
126 |
|
127 /** |
|
128 * From MMIDCanvasGraphicsItemPainter |
|
129 * Sets the direct container of this canvas graphics item component. |
|
130 * |
|
131 * Note that the canvas graphics item does not necessary need to have |
|
132 * direct container. If the parent component is responsible for somekind |
|
133 * of custom drawing using direct screena access, this method can be used |
|
134 * to register the direct container. |
|
135 * |
|
136 * The canvas graphics item adds itself to the direct container so that it |
|
137 * is not able to draw on top of the canvas graphics item when direct |
|
138 * content is added to the screen. |
|
139 * |
|
140 * @param aDirectContainer The direct container of this compoennt if |
|
141 * any. <code>NULL</code> removes the current container. |
|
142 * @since S60 5.0 |
|
143 */ |
|
144 void SetDirectContainerL(MDirectContainer* aDirectContainer); |
|
145 |
|
146 /** |
|
147 * Propagates the parent to set window of this |
|
148 * canvas graphics item component. |
|
149 * |
|
150 * @param aContainer The parent MIDP custom component |
|
151 * container. |
|
152 * @since S60 5.0 |
|
153 */ |
|
154 void SetParentL(MMIDCustomComponentContainer* aComponentContainer); |
|
155 |
|
156 /** |
|
157 * Sets this canvas graphics item component visible if it is hidden. |
|
158 * |
|
159 * Depending on the current status of the canvas graphics item, this |
|
160 * operation is no-op if there is nothing to do. (i.e. the canvas graphics |
|
161 * item is set hidden when it is already hidden). |
|
162 * |
|
163 * @param aVisible Indicates the visibility status of the canvas graphics |
|
164 * item. |
|
165 * @since S60 5.0 |
|
166 */ |
|
167 void SetVisibleL(TBool aVisible); |
|
168 |
|
169 /** |
|
170 * Returns painter's frame buffer |
|
171 * |
|
172 * @since S60 5.0 |
|
173 */ |
|
174 CFbsBitmap* FrameBuffer() const; |
|
175 |
|
176 /** |
|
177 * Resets frame buffer bitmap before paint method is called. |
|
178 */ |
|
179 void ResetFrameBuffer(const TPoint& aPosition, const TSize& aSize); |
|
180 |
|
181 // from base class MMIDBufferProcessor |
|
182 |
|
183 /** |
|
184 * From MMIDBufferProcessor. |
|
185 * Process a block of commands, updating read pointer as you go. |
|
186 * |
|
187 * @since S60 v3.0 |
|
188 * @param aRead The address of the first command in the buffer for this |
|
189 * processor. |
|
190 * @param aEnd The address of the command *after* the last command in the |
|
191 * buffer for this processor. |
|
192 * @param aCycles The amount of 'compute effort' remaining in the current |
|
193 * AO RunL. |
|
194 * @param aStatus The request status. |
|
195 * @return Returns ETrue if processing will be async. |
|
196 */ |
|
197 #ifdef RD_JAVA_NGA_ENABLED |
|
198 virtual TBool ProcessL( |
|
199 const TMIDBufferOp*& aRead, const TMIDBufferOp* aEnd, |
|
200 TInt& aCycles, java::util::Monitor* aMonitor); |
|
201 #else |
|
202 virtual TBool ProcessL( |
|
203 const TMIDBufferOp*& aRead, const TMIDBufferOp* aEnd, |
|
204 TInt& aCycles, TRequestStatus* aStatus = NULL); |
|
205 #endif |
|
206 |
|
207 /** |
|
208 * From MMIDBufferProcessor. |
|
209 * Called by framework if the processor is doing some async operation |
|
210 * when the MIDlet is closed down. Processor should cancel the async |
|
211 * operation and clean up any resources. |
|
212 * |
|
213 * @since S60 v3.0 |
|
214 */ |
|
215 void AbortAsync(); |
|
216 |
|
217 |
|
218 // From basic class MDirectContent |
|
219 |
|
220 /** |
|
221 * Notify content that container window has changed. |
|
222 * This should only be called when the content is displayed on an |
|
223 * Item. |
|
224 * |
|
225 * @param aWindow New window on which content can be displayed or NULL |
|
226 * if the Item has been removed from the Form |
|
227 * @since S60 5.0 |
|
228 */ |
|
229 void MdcContainerWindowRectChanged(const TRect& /*aRect*/); |
|
230 |
|
231 /** |
|
232 * Notify content that container visiblity has changed. The content |
|
233 * must not be displayed when it's container is invisible. |
|
234 * |
|
235 * @param aVisible ETrue if the container is visible, EFalse if it is |
|
236 * invisible. |
|
237 * @since S60 5.0 |
|
238 */ |
|
239 void MdcContainerVisibilityChanged(TBool aVisible); |
|
240 |
|
241 /** |
|
242 * Notify content that the container bounds have changed. |
|
243 * |
|
244 * @param aRect Maximum area the content can occupy in screen |
|
245 * co-ordinates. The content should be clipped to this area. |
|
246 * @since S60 5.0 |
|
247 */ |
|
248 void MdcContentBoundsChanged(const TRect& aRect); |
|
249 |
|
250 /** |
|
251 * Notify content that its display area has changed. |
|
252 * This should only be called when the content is displayed on an |
|
253 * Item. |
|
254 * |
|
255 * @param aDisplayRect Display area in Item co-ordinates. |
|
256 * @param aScreenRect Display area in screen co-ordinates. |
|
257 * @since S60 5.0 |
|
258 */ |
|
259 void MdcItemContentRectChanged( |
|
260 const TRect& aContentRect, const TRect& aScreenRect); |
|
261 |
|
262 /** |
|
263 * Notify content that container is about to be destoryed. |
|
264 * |
|
265 * @since S60 5.0 |
|
266 */ |
|
267 void MdcContainerDestroyed(); |
|
268 |
|
269 /** |
|
270 * Aborts DSA. |
|
271 * |
|
272 * @since S60 5.0 |
|
273 */ |
|
274 void MdcAbortDSA(); |
|
275 |
|
276 /** |
|
277 * Resumes DSA. |
|
278 * |
|
279 * @since S60 5.0 |
|
280 */ |
|
281 void MdcResumeDSA(); |
|
282 |
|
283 public: // Own methods |
|
284 |
|
285 /** |
|
286 * Sets the new view size. Needed by scaling. |
|
287 * |
|
288 * @param aSize New view size. |
|
289 * @since S60 5.0 |
|
290 */ |
|
291 inline void SetViewSize(const TSize& aSize); |
|
292 |
|
293 /** |
|
294 * Sets the rect of canvas if it is scaled. Needed by scaling. |
|
295 * |
|
296 * @param aSize New view size. |
|
297 * @since S60 5.0 |
|
298 */ |
|
299 inline void SetOnScreenCanvasRect(const TRect& aSize); |
|
300 |
|
301 /** |
|
302 * Sets the item. Called during construction of CMIDCanvasGraphicsItem. |
|
303 * |
|
304 * @param aItem CMIDCanvasGraphicsItem to which is this painter assigned. |
|
305 * @since S60 5.0 |
|
306 */ |
|
307 inline void SetItem(CMIDCanvasGraphicsItem* aItem); |
|
308 |
|
309 |
|
310 private: // Construtors |
|
311 |
|
312 /** |
|
313 * C++ constructor. |
|
314 */ |
|
315 CMIDCanvasGraphicsItemPainter(MMIDEnv& aEnv); |
|
316 |
|
317 /** |
|
318 * Second phase constructor |
|
319 * |
|
320 * @param aParams The construction parameters of this class. |
|
321 * @since S60 5.0 |
|
322 */ |
|
323 void ConstructL(const TCtorParams& aParams); |
|
324 |
|
325 /** |
|
326 * Resets buffers of painter. |
|
327 * |
|
328 * @since S60 5.0 |
|
329 */ |
|
330 void ResetBuffers(); |
|
331 |
|
332 /** |
|
333 * Creates buffers for painter. |
|
334 * |
|
335 * Creates the frame buffer with its associated device and context and the |
|
336 * offscreen buffer with its device and context. They are both of the same size, |
|
337 * the size of the content rect. The skin background is then printed on the |
|
338 * frame buffer via the frame context. |
|
339 * |
|
340 * @since S60 5.0 |
|
341 */ |
|
342 void CreateBuffersL(); |
|
343 |
|
344 /** |
|
345 * Draws painter. |
|
346 * |
|
347 * If painter is visible, blits his frame buffer. |
|
348 * |
|
349 * @since S60 5.0 |
|
350 */ |
|
351 void Draw(const TRect& aRect) const; |
|
352 |
|
353 private: // Data |
|
354 |
|
355 // Canvas graphics item control. Owned. |
|
356 CMIDCanvasGraphicsItem* iItem; |
|
357 |
|
358 // Container for the direct content. Not owned. |
|
359 MDirectContainer* iDirectContainer; |
|
360 |
|
361 /** |
|
362 * Frame buffer. |
|
363 * Own. |
|
364 */ |
|
365 CFbsBitmap* iFrameBuffer; |
|
366 |
|
367 /** |
|
368 * Frame bitmapped graphics context. |
|
369 * Own. |
|
370 */ |
|
371 CFbsBitGc* iFrameContext; |
|
372 |
|
373 /** |
|
374 * Frame bitmap graphics device. |
|
375 * Own. |
|
376 */ |
|
377 CFbsBitmapDevice* iFrameDevice; |
|
378 |
|
379 /** |
|
380 * Canvas graphics item rect |
|
381 */ |
|
382 TRect iContentRect; |
|
383 |
|
384 /** |
|
385 * View rectangle. |
|
386 */ |
|
387 TSize iViewSize; |
|
388 |
|
389 /** |
|
390 * Canvas graphics item painter inner visibility |
|
391 */ |
|
392 TBool iVisible; |
|
393 |
|
394 // A MIDlet environment. |
|
395 MMIDEnv& iEnv; |
|
396 |
|
397 // rect of canvas if it is scaled |
|
398 TRect iOnScreenCanvasRect; |
|
399 |
|
400 }; |
|
401 |
|
402 inline void CMIDCanvasGraphicsItemPainter::SetItem( |
|
403 CMIDCanvasGraphicsItem* aItem) |
|
404 { |
|
405 iItem = aItem; |
|
406 } |
|
407 |
|
408 inline void CMIDCanvasGraphicsItemPainter::SetViewSize(const TSize& aSize) |
|
409 { |
|
410 iViewSize = aSize; |
|
411 } |
|
412 |
|
413 inline void CMIDCanvasGraphicsItemPainter::SetOnScreenCanvasRect( |
|
414 const TRect& aRect) |
|
415 { |
|
416 iOnScreenCanvasRect = aRect; |
|
417 } |
|
418 |
|
419 #endif // CMIDCANVASGRAPHICSITEMPAINTER_H |
|
420 |
|
421 // End of file |