|
1 /* |
|
2 * Copyright (c) 2002-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: This class implements MMMADisplay |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Include Files |
|
20 #include <jdebug.h> |
|
21 |
|
22 #include "cmmadisplay.h" |
|
23 #include "mmmadisplaywindow.h" |
|
24 |
|
25 // Destructor (virtual by CBase) |
|
26 CMMADisplay::~CMMADisplay() |
|
27 { |
|
28 |
|
29 if (iDirectContainer) |
|
30 { |
|
31 // Remove clip rect if set |
|
32 if (!iClipRect.IsEmpty()) |
|
33 { |
|
34 DEBUG("CMMADisplay::~CMMADisplay(): Removing clip rect"); |
|
35 iDirectContainer->MdcRemoveContentBounds(iClipRect); |
|
36 } |
|
37 |
|
38 // Remove this object from MDirectContainer |
|
39 iDirectContainer->MdcRemoveContent(this); |
|
40 } |
|
41 } |
|
42 |
|
43 |
|
44 CMMADisplay::CMMADisplay(): |
|
45 iVisible(EFalse), |
|
46 iFullScreen(EFalse), |
|
47 iContainerVisible(EFalse), |
|
48 iIsForeground(ETrue), |
|
49 iResetDrawRect(EFalse) |
|
50 { |
|
51 } |
|
52 |
|
53 void CMMADisplay::Construct(MDirectContainer* aDirectContainer) |
|
54 { |
|
55 // Components must have direct content. |
|
56 __ASSERT_DEBUG(aDirectContainer, User::Invariant()); |
|
57 |
|
58 // Not owned |
|
59 iDirectContainer = aDirectContainer; |
|
60 |
|
61 // Get component visibility. Later visibility changes will |
|
62 // be informed through MDirectContent observer. |
|
63 iContainerVisible = iDirectContainer->MdcContainerVisibility(); |
|
64 DEBUG_INT("MID::CMMADisplay::Construct iContainerVisible = %d", iContainerVisible); |
|
65 DEBUG_INT("MID::CMMADisplay::Construct iVisible = %d", iVisible); |
|
66 |
|
67 // Add this MDirectContent to the MDirectContainer. Cannot fail. |
|
68 iDirectContainer->MdcAddContent(this); |
|
69 } |
|
70 |
|
71 TRect CMMADisplay::ScaleToFullScreen(const TSize& aFullScreenSize, |
|
72 const TSize& aSourceSize) |
|
73 { |
|
74 if ((aSourceSize.iWidth == 0) && |
|
75 (aSourceSize.iHeight == 0)) |
|
76 { |
|
77 // Avoid divide by zero. |
|
78 return TRect(); |
|
79 } |
|
80 |
|
81 // Width or height will be full size. |
|
82 TRect drawRect(TPoint(0, 0), |
|
83 aFullScreenSize); |
|
84 |
|
85 // Smaller dimension scale ratio will be scaled. |
|
86 // Changed to area calculation to avoid reals and dimension |
|
87 // with smaller area will be scaled. |
|
88 TInt vDif((aFullScreenSize.iWidth - aSourceSize.iWidth) |
|
89 * aFullScreenSize.iHeight); |
|
90 TInt hDif((aFullScreenSize.iHeight - aSourceSize.iHeight) |
|
91 * aFullScreenSize.iWidth); |
|
92 |
|
93 TPoint position(0, 0); |
|
94 |
|
95 // Check which side to scale to fullscreen size. |
|
96 if (hDif > vDif) |
|
97 { |
|
98 // Width is full screen width. |
|
99 // Scale height with aspect ratio. |
|
100 drawRect.iBr.iY = aFullScreenSize.iWidth * aSourceSize.iHeight |
|
101 / aSourceSize.iWidth; |
|
102 // move rect middle of the screen |
|
103 position.iY = (aFullScreenSize.iHeight - drawRect.iBr.iY) / 2; |
|
104 } |
|
105 else |
|
106 { |
|
107 // Height is full screen height. |
|
108 // Scale width with aspect ratio. |
|
109 drawRect.iBr.iX = aFullScreenSize.iHeight * aSourceSize.iWidth |
|
110 / aSourceSize.iHeight; |
|
111 // move rect middle of the screen |
|
112 position.iX = (aFullScreenSize.iWidth - drawRect.iBr.iX) / 2; |
|
113 } |
|
114 |
|
115 drawRect.Move(position); |
|
116 return drawRect; |
|
117 } |
|
118 |
|
119 // from MMMADisplay |
|
120 void CMMADisplay::DrawFrameL(const CFbsBitmap* aBitmap) |
|
121 { |
|
122 // This method is called only if bitmap is used. |
|
123 // Runs in mmapi thread |
|
124 if (iVisible && iWindow && iDirectContainer) |
|
125 { |
|
126 iWindow->DrawFrameL(aBitmap); |
|
127 iDirectContainer->MdcFlushContainer(iWindow->WindowRect()); |
|
128 } |
|
129 } |
|
130 |
|
131 void CMMADisplay::SetClippingRegion() |
|
132 { |
|
133 DEBUG("CMMADisplay::SetClippingRegion"); |
|
134 |
|
135 if (!iWindow || |
|
136 (iWindow->GetDisplayWindowType() == MMMADisplayWindow::EDisplayWindowTypeIsBitmap) || |
|
137 iClipRect == iWindow->DrawRect() && iContainerVisible && iVisible) |
|
138 { |
|
139 return; |
|
140 } |
|
141 |
|
142 TBool refreshScreen(EFalse); |
|
143 // Remove first the current clip rect if set |
|
144 if (!iClipRect.IsEmpty()) |
|
145 { |
|
146 DEBUG("CMMADisplay::SetClippingRegion: Removing old rect"); |
|
147 iDirectContainer->MdcRemoveContentBounds(iClipRect); |
|
148 iClipRect.SetRect(0, 0, 0, 0); |
|
149 refreshScreen = ETrue; |
|
150 } |
|
151 // If visible then set a new clip rect |
|
152 if (iVisible && iContainerVisible) |
|
153 { |
|
154 iClipRect = iWindow->DrawRect(); |
|
155 |
|
156 if (!iClipRect.IsEmpty()) |
|
157 { |
|
158 DEBUG("CMMADisplay::SetClippingRegion: Adding new rect"); |
|
159 // Add new clipping rect |
|
160 iDirectContainer->MdcAddContentBounds(iClipRect); |
|
161 refreshScreen = ETrue; |
|
162 } |
|
163 } |
|
164 if (refreshScreen) |
|
165 { |
|
166 // refresh screen |
|
167 iDirectContainer->MdcFlushContainer(iWindow->WindowRect()); |
|
168 } |
|
169 DEBUG("CMMADisplay::SetClippingRegion -"); |
|
170 } |
|
171 |
|
172 void CMMADisplay::RemoveClippingRegion() |
|
173 { |
|
174 // Called in mmapi thread |
|
175 DEBUG("CMMADisplay::RemoveClippingRegion"); |
|
176 |
|
177 if (!iWindow || |
|
178 (iWindow->GetDisplayWindowType() == MMMADisplayWindow::EDisplayWindowTypeIsBitmap)) |
|
179 { |
|
180 return; |
|
181 } |
|
182 // Remove first the current clip rect if set |
|
183 if (!iClipRect.IsEmpty()) |
|
184 { |
|
185 DEBUG("CMMADisplay::RemoveClippingRegion: Removing old rect"); |
|
186 iDirectContainer->MdcRemoveContentBounds(iClipRect); |
|
187 iClipRect.SetRect(0, 0, 0, 0); |
|
188 // refresh screen |
|
189 iDirectContainer->MdcFlushContainer(iWindow->WindowRect()); |
|
190 } |
|
191 } |
|
192 |
|
193 void CMMADisplay::AddClippingRegion() |
|
194 { |
|
195 // Called in mmapi thread |
|
196 DEBUG("CMMADisplay::AddClippingRegion"); |
|
197 |
|
198 if (!iWindow || |
|
199 (iWindow->GetDisplayWindowType() == |
|
200 MMMADisplayWindow::EDisplayWindowTypeIsBitmap) || |
|
201 iClipRect == iWindow->DrawRect()) |
|
202 { |
|
203 return; |
|
204 } |
|
205 // If visible then set a new clip rect |
|
206 if (iVisible) |
|
207 { |
|
208 iClipRect = iWindow->DrawRect(); |
|
209 |
|
210 if (!iClipRect.IsEmpty()) |
|
211 { |
|
212 DEBUG("CMMADisplay::AddClippingRegion: Adding new rect"); |
|
213 // Add new clipping rect |
|
214 iDirectContainer->MdcAddContentBounds(iClipRect); |
|
215 // refresh screen |
|
216 iDirectContainer->MdcFlushContainer( |
|
217 iWindow->WindowRect()); |
|
218 } |
|
219 } |
|
220 } |
|
221 |
|
222 // from MMMADisplay |
|
223 TSize CMMADisplay::DisplaySize() |
|
224 { |
|
225 if (iWindow && iFullScreen) |
|
226 { |
|
227 return iWindow->DrawRect().Size(); |
|
228 } |
|
229 else |
|
230 { |
|
231 return iUserRect.Size(); |
|
232 } |
|
233 } |
|
234 |
|
235 // from MMMADisplay |
|
236 void CMMADisplay::SetDisplaySizeL(const TSize& aSize) |
|
237 { |
|
238 // user rect contains size set from java. |
|
239 iUserRect.SetSize(aSize); |
|
240 |
|
241 // Size change has no effect if fullscreen mode is on. |
|
242 // New size could be used when fullscreen is turned off. |
|
243 if (iContainerVisible && !iFullScreen && iWindow) |
|
244 { |
|
245 RemoveClippingRegion(); |
|
246 iWindow->SetDrawRect(iUserRect); |
|
247 AddClippingRegion(); |
|
248 } |
|
249 else |
|
250 { |
|
251 iResetDrawRect = ETrue; |
|
252 } |
|
253 } |
|
254 |
|
255 // from MMMADisplay |
|
256 void CMMADisplay::SetVisible(TBool aValue) |
|
257 { |
|
258 iVisible = aValue; |
|
259 // Window may be set visible only if container is on screen, |
|
260 |
|
261 DEBUG_INT("MID::CMMADisplay::SetVisible + iContainerVisible = %d", iContainerVisible); |
|
262 DEBUG_INT("MID::CMMADisplay::SetVisible iVisible = %d", iVisible); |
|
263 |
|
264 if (!iIsForeground) |
|
265 { |
|
266 DEBUG("MID::CMMADisplay::SetVisible - iIsForeground = 0"); |
|
267 return; |
|
268 } |
|
269 // if not it can not be set visible. |
|
270 if (iWindow && iContainerVisible) |
|
271 { |
|
272 iWindow->SetVisible(aValue, EFalse); |
|
273 SetClippingRegion(); |
|
274 } |
|
275 } |
|
276 |
|
277 // from MMMADisplay |
|
278 void CMMADisplay::SetWindowL(MMMADisplayWindow* aWindow) |
|
279 { |
|
280 // Sets new window. Ownership is not transferred. |
|
281 iWindow = aWindow; |
|
282 } |
|
283 |
|
284 // from MMMADisplay |
|
285 MMMADisplayWindow* CMMADisplay::Window() |
|
286 { |
|
287 return iWindow; |
|
288 } |
|
289 |
|
290 TBool CMMADisplay::IsVisible() |
|
291 { |
|
292 DEBUG_INT("MID::CMMADisplay::IsVisible iContainerVisible = %d", iContainerVisible); |
|
293 DEBUG_INT("MID::CMMADisplay::IsVisible iVisible = %d", iVisible); |
|
294 // display is visible if container is on screen and |
|
295 // java side has set it visible |
|
296 return iVisible && iContainerVisible; |
|
297 } |
|
298 |
|
299 TBool CMMADisplay::IsFullScreen() |
|
300 { |
|
301 return iFullScreen; |
|
302 } |
|
303 |
|
304 TBool CMMADisplay::HasContainer() |
|
305 { |
|
306 return iDirectContainer != NULL; |
|
307 } |
|
308 |
|
309 void CMMADisplay::MdcContainerVisibilityChanged(TBool aVisible) |
|
310 { |
|
311 DEBUG_INT("MID::CMMADisplay::MdcContainerVisibilityChanged aVisible = %d", |
|
312 aVisible); |
|
313 if (!iIsForeground && aVisible) |
|
314 { |
|
315 DEBUG("MID::CMMADisplay::MdcContainerVisibilityChanged Condition 1 "); |
|
316 return; |
|
317 } |
|
318 |
|
319 DEBUG("MID::CMMADisplay::MdcContainerVisibilityChanged After condition1"); |
|
320 |
|
321 iContainerVisible = aVisible; |
|
322 |
|
323 if (iWindow) |
|
324 { |
|
325 // midlet comes to foreground (0 to 1 transition), |
|
326 // Allow turn on or turn off based on aVisible |
|
327 if (aVisible != iWindow->IsVisible()) |
|
328 { |
|
329 // Allow |
|
330 DEBUG("MID::CMMADisplay::MdcContainerVisibilityChanged Allow "); |
|
331 } |
|
332 else //if( iContainerVisible == aVisible ) |
|
333 { |
|
334 DEBUG("MID::CMMADisplay::MdcContainerVisibilityChanged iContainerVisible == aVisible "); |
|
335 // if state is not changed, we do not need to do it again |
|
336 return; |
|
337 } |
|
338 } |
|
339 |
|
340 DEBUG("MID::CMMADisplay::MdcContainerVisibilityChanged After condition2"); |
|
341 |
|
342 if (iWindow) |
|
343 { |
|
344 DEBUG("MID::CMMADisplay::MdcContainerVisibilityChanged iWindow is valid "); |
|
345 // change is only needed if java side has set display visible or |
|
346 // if container loses focus |
|
347 if (!iContainerVisible || iVisible) |
|
348 { |
|
349 if (iResetDrawRect && aVisible && !iFullScreen) |
|
350 { |
|
351 iWindow->SetDrawRectThread(iUserRect); |
|
352 iResetDrawRect = EFalse; |
|
353 } |
|
354 if (iIsForeground) |
|
355 { |
|
356 iWindow->SetVisible(aVisible); |
|
357 } |
|
358 SetClippingRegion(); |
|
359 } |
|
360 } |
|
361 } |
|
362 |
|
363 void CMMADisplay::MdcItemContentRectChanged(const TRect& /*aContentRect*/, |
|
364 const TRect& /*aScreenRect*/) |
|
365 { |
|
366 // To be overwritten if used |
|
367 __ASSERT_DEBUG(EFalse, User::Invariant()); |
|
368 } |
|
369 |
|
370 void CMMADisplay::MdcContainerWindowRectChanged(const TRect& |
|
371 #ifdef RD_JAVA_NGA_ENABLED |
|
372 aRect |
|
373 #endif |
|
374 ) |
|
375 { |
|
376 DEBUG("CMMADisplay::MdcContainerWindowRectChanged +"); |
|
377 |
|
378 #ifdef RD_JAVA_NGA_ENABLED |
|
379 if (iWindow) |
|
380 { |
|
381 DEBUG("CMMADisplay::MdcContainerWindowRectChanged, SetRWindowRect"); |
|
382 iWindow->SetRWindowRect(aRect, MMMADisplay::EUiThread); |
|
383 } |
|
384 #endif |
|
385 } |
|
386 void CMMADisplay::MdcContainerDestroyed() |
|
387 { |
|
388 DEBUG("MMA::CMMADisplay::MdcContainerDestroyed"); |
|
389 |
|
390 if (iWindow) |
|
391 { |
|
392 iWindow->ContainerDestroyed(); |
|
393 } |
|
394 |
|
395 iDirectContainer = NULL; |
|
396 } |
|
397 |
|
398 |
|
399 void CMMADisplay::SetForeground(TBool aForeground, TBool aUseEventServer) |
|
400 { |
|
401 DEBUG_INT("MMA::CMMADisplay::SetForeground %d", aForeground); |
|
402 iIsForeground = aForeground; |
|
403 |
|
404 if (aForeground) |
|
405 { |
|
406 if (iContainerVisible && !iWindow->IsVisible()) |
|
407 { |
|
408 iWindow->SetVisible(ETrue, aUseEventServer); |
|
409 } |
|
410 } |
|
411 else |
|
412 { |
|
413 if (iWindow->IsVisible()) |
|
414 { |
|
415 iWindow->SetVisible(EFalse, aUseEventServer); |
|
416 } |
|
417 } |
|
418 } |
|
419 |
|
420 void CMMADisplay::MdcAbortDSA() |
|
421 { |
|
422 if (iWindow) |
|
423 { |
|
424 iWindow->AbortDSA(); |
|
425 } |
|
426 } |
|
427 |
|
428 |
|
429 void CMMADisplay::MdcResumeDSA() |
|
430 { |
|
431 if (iWindow) |
|
432 { |
|
433 iWindow->ResumeDSA(); |
|
434 } |
|
435 } |
|
436 |
|
437 |
|
438 void CMMADisplay::UIGetDSAResources( |
|
439 MUiEventConsumer& aConsumer, |
|
440 MMMADisplay::TThreadType /* aThreadType */) |
|
441 { |
|
442 if (iDirectContainer) |
|
443 { |
|
444 iDirectContainer->MdcGetDSAResources(aConsumer); |
|
445 } |
|
446 } |
|
447 |
|
448 void CMMADisplay::UIGetCallback( |
|
449 MUiEventConsumer& aConsumer, |
|
450 TInt aCallbackId) |
|
451 { |
|
452 if (iDirectContainer) |
|
453 { |
|
454 iDirectContainer->MdcGetUICallback(aConsumer, aCallbackId); |
|
455 } |
|
456 } |
|
457 |
|
458 void CMMADisplay::FixUIOrientation(TBool aFix) |
|
459 { |
|
460 if (iDirectContainer) |
|
461 { |
|
462 iDirectContainer->MdcFixUIOrientation(aFix); |
|
463 } |
|
464 } |
|
465 |
|
466 // END OF FILE |