|
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 "logger.h" |
|
21 |
|
22 #include "cmmadisplay.h" |
|
23 #include "mmmadisplaywindow.h" |
|
24 |
|
25 // temporary |
|
26 #include <w32std.h> |
|
27 |
|
28 // Destructor (virtual by CBase) |
|
29 CMMADisplay::~CMMADisplay() |
|
30 { |
|
31 /* |
|
32 if (iDirectContainer) |
|
33 { |
|
34 // Remove clip rect if set |
|
35 if (!iClipRect.IsEmpty()) |
|
36 { |
|
37 LOG(EJavaMMAPI,EInfo,"CMMADisplay::~CMMADisplay(): Removing clip rect"); |
|
38 iDirectContainer->MdcRemoveContentBounds(iClipRect); |
|
39 } |
|
40 |
|
41 // Remove this object from MDirectContainer |
|
42 iDirectContainer->MdcRemoveContent(this); |
|
43 } |
|
44 */ |
|
45 } |
|
46 |
|
47 |
|
48 CMMADisplay::CMMADisplay(): |
|
49 iVisible(ETrue), |
|
50 iFullScreen(EFalse), |
|
51 iContainerVisible(ETrue), |
|
52 iIsForeground(ETrue), |
|
53 iResetDrawRect(EFalse) |
|
54 { |
|
55 } |
|
56 |
|
57 void CMMADisplay::Construct(MMAFunctionServer* eventSource , jobject javadisplayref) |
|
58 { |
|
59 iEventSource = eventSource; |
|
60 iJni = iEventSource->getValidJniEnv(); |
|
61 iJavaDisplayObject = iJni->NewGlobalRef(javadisplayref); |
|
62 iJavaDisplayClass = iJni->GetObjectClass(iJavaDisplayObject); |
|
63 // Components must have direct content. |
|
64 /* __ASSERT_LOG(EJavaMMAPI,EInfo,"aDirectContainer, User::Invariant()); |
|
65 |
|
66 // Not owned |
|
67 iDirectContainer = aDirectContainer; |
|
68 |
|
69 // Get component visibility. Later visibility changes will |
|
70 // be informed through MDirectContent observer. |
|
71 iContainerVisible = iDirectContainer->MdcContainerVisibility(); |
|
72 LOG1(EJavaMMAPI,EInfo,"MID::CMMADisplay::Construct iContainerVisible = %d", iContainerVisible); |
|
73 LOG1(EJavaMMAPI,EInfo,"MID::CMMADisplay::Construct iVisible = %d", iVisible); |
|
74 |
|
75 // Add this MDirectContent to the MDirectContainer. Cannot fail. |
|
76 iDirectContainer->MdcAddContent(this); |
|
77 */ |
|
78 } |
|
79 |
|
80 TRect CMMADisplay::ScaleToFullScreen(const TSize& aFullScreenSize, |
|
81 const TSize& aSourceSize) |
|
82 { |
|
83 LOG(EJavaMMAPI,EInfo,"CMMADisplay::ScaleToFullScreen() +"); |
|
84 if ((aSourceSize.iWidth == 0) && |
|
85 (aSourceSize.iHeight == 0)) |
|
86 { |
|
87 // Avoid divide by zero. |
|
88 return TRect(); |
|
89 } |
|
90 |
|
91 // Width or height will be full size. |
|
92 TRect drawRect(TPoint(0, 0), |
|
93 aFullScreenSize); |
|
94 |
|
95 // Smaller dimension scale ratio will be scaled. |
|
96 // Changed to area calculation to avoid reals and dimension |
|
97 // with smaller area will be scaled. |
|
98 TInt vDif((aFullScreenSize.iWidth - aSourceSize.iWidth) |
|
99 * aFullScreenSize.iHeight); |
|
100 TInt hDif((aFullScreenSize.iHeight - aSourceSize.iHeight) |
|
101 * aFullScreenSize.iWidth); |
|
102 |
|
103 TPoint position(0, 0); |
|
104 |
|
105 // Check which side to scale to fullscreen size. |
|
106 if (hDif > vDif) |
|
107 { |
|
108 // Width is full screen width. |
|
109 // Scale height with aspect ratio. |
|
110 drawRect.iBr.iY = aFullScreenSize.iWidth * aSourceSize.iHeight |
|
111 / aSourceSize.iWidth; |
|
112 // move rect middle of the screen |
|
113 position.iY = (aFullScreenSize.iHeight - drawRect.iBr.iY) / 2; |
|
114 } |
|
115 else |
|
116 { |
|
117 // Height is full screen height. |
|
118 // Scale width with aspect ratio. |
|
119 drawRect.iBr.iX = aFullScreenSize.iHeight * aSourceSize.iWidth |
|
120 / aSourceSize.iHeight; |
|
121 // move rect middle of the screen |
|
122 position.iX = (aFullScreenSize.iWidth - drawRect.iBr.iX) / 2; |
|
123 } |
|
124 |
|
125 drawRect.Move(position); |
|
126 LOG(EJavaMMAPI,EInfo,"CMMADisplay::ScaleToFullScreen() -"); |
|
127 return drawRect; |
|
128 } |
|
129 |
|
130 // from MMMADisplay |
|
131 void CMMADisplay::DrawFrameL(const CFbsBitmap* aBitmap) |
|
132 { |
|
133 // This method is called only if bitmap is used. |
|
134 // Runs in mmapi thread |
|
135 if (iVisible && iWindow /*&& iDirectContainer*/) |
|
136 { |
|
137 iWindow->DrawFrameL(aBitmap); |
|
138 //iDirectContainer->MdcFlushContainer(iWindow->WindowRect()); |
|
139 } |
|
140 } |
|
141 |
|
142 void CMMADisplay::SetClippingRegion() |
|
143 { |
|
144 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetClippingRegion"); |
|
145 |
|
146 if (!iWindow || |
|
147 (iWindow->GetDisplayWindowType() == MMMADisplayWindow::EDisplayWindowTypeIsBitmap) || |
|
148 iClipRect == iWindow->DrawRect() && iContainerVisible && iVisible) |
|
149 { |
|
150 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetClippingRegion before return"); |
|
151 return; |
|
152 } |
|
153 |
|
154 TBool refreshScreen(EFalse); |
|
155 // Remove first the current clip rect if set |
|
156 LOG2(EJavaMMAPI,EInfo,"CMMADisplay::SetClippingRegion: iClipRect = %d X %d",iClipRect.Width(),iClipRect.Height()); |
|
157 if (!iClipRect.IsEmpty()) |
|
158 { |
|
159 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetClippingRegion: Removing old rect"); |
|
160 //iDirectContainer->MdcRemoveContentBounds(iClipRect); |
|
161 iClipRect.SetRect(0, 0, 0, 0); |
|
162 refreshScreen = ETrue; |
|
163 } |
|
164 // If visible then set a new clip rect |
|
165 if (iVisible && iContainerVisible) |
|
166 { |
|
167 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetClippingRegion: inside if (iVisible && iContainerVisible)"); |
|
168 iClipRect = iWindow->DrawRect(); |
|
169 LOG2(EJavaMMAPI,EInfo,"CMMADisplay::SetClippingRegion: inside if (iVisible && iContainerVisible)iClipRect = %d X %d",iClipRect.Width(),iClipRect.Height()); |
|
170 if (!iClipRect.IsEmpty()) |
|
171 { |
|
172 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetClippingRegion: Adding new rect"); |
|
173 // Add new clipping rect |
|
174 // iDirectContainer->MdcAddContentBounds(iClipRect); |
|
175 SetContentBoundToJavaControl(iClipRect); |
|
176 refreshScreen = ETrue; |
|
177 } |
|
178 } |
|
179 if (refreshScreen) |
|
180 { |
|
181 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetClippingRegion: inside if(refreshScreen)"); |
|
182 // refresh screen |
|
183 // iDirectContainer->MdcFlushContainer(iWindow->WindowRect()); |
|
184 RefreshJavaControl(iWindow->WindowRect()); |
|
185 } |
|
186 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetClippingRegion -"); |
|
187 } |
|
188 |
|
189 void CMMADisplay::RemoveClippingRegion() |
|
190 { |
|
191 // Called in mmapi thread |
|
192 LOG(EJavaMMAPI,EInfo,"CMMADisplay::RemoveClippingRegion"); |
|
193 |
|
194 if (!iWindow || |
|
195 (iWindow->GetDisplayWindowType() == MMMADisplayWindow::EDisplayWindowTypeIsBitmap)) |
|
196 { |
|
197 return; |
|
198 } |
|
199 // Remove first the current clip rect if set |
|
200 if (!iClipRect.IsEmpty()) |
|
201 { |
|
202 LOG(EJavaMMAPI,EInfo,"CMMADisplay::RemoveClippingRegion: Removing old rect"); |
|
203 //iDirectContainer->MdcRemoveContentBounds(iClipRect); |
|
204 RemoveContentBoundFromJavaControl(iClipRect); |
|
205 iClipRect.SetRect(0, 0, 0, 0); |
|
206 // refresh screen |
|
207 //iDirectContainer->MdcFlushContainer(iWindow->WindowRect()); |
|
208 RefreshJavaControl(iWindow->WindowRect()); |
|
209 } |
|
210 } |
|
211 |
|
212 void CMMADisplay::AddClippingRegion() |
|
213 { |
|
214 // Called in mmapi thread |
|
215 LOG(EJavaMMAPI,EInfo,"CMMADisplay::AddClippingRegion"); |
|
216 LOG2(EJavaMMAPI,EInfo,"CMMADisplay::AddClippingRegion iClipRect width = %d height = %d", iClipRect.Width() , iClipRect.Height()); |
|
217 |
|
218 if (!iWindow || |
|
219 (iWindow->GetDisplayWindowType() == |
|
220 MMMADisplayWindow::EDisplayWindowTypeIsBitmap) || |
|
221 iClipRect == iWindow->DrawRect()) |
|
222 { |
|
223 return; |
|
224 } |
|
225 // If visible then set a new clip rect |
|
226 if (iVisible) |
|
227 { |
|
228 iClipRect = iWindow->DrawRect(); |
|
229 if (!iClipRect.IsEmpty()) |
|
230 { |
|
231 LOG(EJavaMMAPI,EInfo,"CMMADisplay::AddClippingRegion: Adding new rect"); |
|
232 // Add new clipping rect |
|
233 // iDirectContainer->MdcAddContentBounds(iClipRect); |
|
234 SetContentBoundToJavaControl(iClipRect); |
|
235 // refresh screen |
|
236 // iDirectContainer->MdcFlushContainer( |
|
237 // iWindow->WindowRect()); |
|
238 RefreshJavaControl(iWindow->WindowRect()); |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 // from MMMADisplay |
|
244 TSize CMMADisplay::DisplaySize() |
|
245 { |
|
246 if (iWindow && iFullScreen) |
|
247 { |
|
248 return iWindow->DrawRect().Size(); |
|
249 } |
|
250 else |
|
251 { |
|
252 return iUserRect.Size(); |
|
253 } |
|
254 } |
|
255 |
|
256 // from MMMADisplay |
|
257 void CMMADisplay::SetDisplaySizeL(const TSize& aSize) |
|
258 { |
|
259 // user rect contains size set from java. |
|
260 iUserRect.SetSize(aSize); |
|
261 LOG2(EJavaMMAPI,EInfo,"MID::CMMADisplay::SetDisplaySizeL iUserRect = %d X %d", iUserRect.Width() ,iUserRect.Height()); |
|
262 // Size change has no effect if fullscreen mode is on. |
|
263 // New size could be used when fullscreen is turned off. |
|
264 if (iContainerVisible && !iFullScreen && iWindow) |
|
265 { |
|
266 LOG1(EJavaMMAPI,EInfo,"MID::CMMADisplay::SetVisible + iContainerVisible = %d", iContainerVisible); |
|
267 RemoveClippingRegion(); |
|
268 LOG2(EJavaMMAPI,EInfo,"MID::CMMADisplay::SetDisplaySizeL iUserRect after removingClipRegion = %d X %d", iUserRect.Width() ,iUserRect.Height()); |
|
269 iWindow->SetDrawRect(iUserRect); |
|
270 AddClippingRegion(); |
|
271 LOG2(EJavaMMAPI,EInfo,"MID::CMMADisplay::SetDisplaySizeL iUserRect after AddingClipRegion = %d X %d", iUserRect.Width() ,iUserRect.Height()); |
|
272 } |
|
273 else |
|
274 { |
|
275 LOG1(EJavaMMAPI,EInfo,"MID::CMMADisplay::SetVisible + iContainerVisible = %d", iContainerVisible); |
|
276 iResetDrawRect = ETrue; |
|
277 } |
|
278 } |
|
279 |
|
280 // from MMMADisplay |
|
281 void CMMADisplay::SetVisible(TBool aValue) |
|
282 { |
|
283 iVisible = aValue; |
|
284 // Window may be set visible only if container is on screen, |
|
285 |
|
286 LOG1(EJavaMMAPI,EInfo,"MID::CMMADisplay::SetVisible + iContainerVisible = %d", iContainerVisible); |
|
287 LOG1(EJavaMMAPI,EInfo,"MID::CMMADisplay::SetVisible iVisible = %d", iVisible); |
|
288 if (!iIsForeground) |
|
289 { |
|
290 LOG(EJavaMMAPI,EInfo,"MID::CMMADisplay::SetVisible - iIsForeground = 0"); |
|
291 return; |
|
292 } |
|
293 // if not it can not be set visible. |
|
294 if (iWindow && iContainerVisible) |
|
295 { |
|
296 // iWindow->SetVisible(aValue, EFalse); |
|
297 //MMAPI UI 3.x req. (had to comment above line and add below line which excutes in FS thread) |
|
298 iWindow->SetVisible(aValue, ETrue); |
|
299 SetClippingRegion(); |
|
300 } |
|
301 } |
|
302 |
|
303 |
|
304 void CMMADisplay::SetContainerVisibility(TBool aValue) |
|
305 { |
|
306 iContainerVisible = aValue; |
|
307 // TODO : delete the below check once implementation is done as it is used only for testing purpose |
|
308 if(iContainerVisible) |
|
309 LOG(EJavaMMAPI,EInfo,"CMMADisplay:SetContainerVisibility(): Container is visible "); |
|
310 else |
|
311 LOG(EJavaMMAPI,EInfo,"CMMADisplay:SetContainerVisibility(): Container is not visible "); |
|
312 |
|
313 HandleContainerVisibilityChanged(aValue); |
|
314 } |
|
315 // from MMMADisplay |
|
316 void CMMADisplay::SetWindowL(MMMADisplayWindow* aWindow) |
|
317 { |
|
318 // Sets new window. Ownership is not transferred. |
|
319 iWindow = aWindow; |
|
320 } |
|
321 |
|
322 // from MMMADisplay |
|
323 MMMADisplayWindow* CMMADisplay::Window() |
|
324 { |
|
325 return iWindow; |
|
326 } |
|
327 |
|
328 TBool CMMADisplay::IsVisible() |
|
329 { |
|
330 LOG1(EJavaMMAPI,EInfo,"MID::CMMADisplay::IsVisible iContainerVisible = %d", iContainerVisible); |
|
331 LOG1(EJavaMMAPI,EInfo,"MID::CMMADisplay::IsVisible iVisible = %d", iVisible); |
|
332 // display is visible if container is on screen and |
|
333 // java side has set it visible |
|
334 return iVisible && iContainerVisible; |
|
335 } |
|
336 |
|
337 TBool CMMADisplay::IsFullScreen() |
|
338 { |
|
339 return iFullScreen; |
|
340 } |
|
341 |
|
342 TBool CMMADisplay::HasContainer() |
|
343 { |
|
344 // return iDirectContainer != NULL; |
|
345 return EFalse; // temporary |
|
346 } |
|
347 |
|
348 |
|
349 void CMMADisplay::HandleContainerVisibilityChanged( TBool aVisible ) |
|
350 { |
|
351 LOG1(EJavaMMAPI,EInfo, "CMMADisplay::HandleContainerVisibilityChanged aVisible = %d", |
|
352 aVisible ); |
|
353 if(!iIsForeground && aVisible) |
|
354 { |
|
355 LOG(EJavaMMAPI,EInfo," CMMADisplay::HandleContainerVisibilityChanged Condition 1 "); |
|
356 return; |
|
357 } |
|
358 |
|
359 LOG(EJavaMMAPI,EInfo," CMMADisplay::HandleContainerVisibilityChanged After condition1"); |
|
360 |
|
361 if (iWindow) |
|
362 { |
|
363 // midlet comes to foreground (0 to 1 transition), |
|
364 // Allow turn on or turn off based on aVisible |
|
365 if (aVisible != iWindow->IsVisible()) |
|
366 { |
|
367 // Allow |
|
368 LOG(EJavaMMAPI,EInfo,"MID::CMMADisplay::MdcContainerVisibilityChanged Allow "); |
|
369 } |
|
370 else if( iContainerVisible == aVisible ) |
|
371 { |
|
372 LOG(EJavaMMAPI,EInfo,"MID::CMMADisplay::MdcContainerVisibilityChanged iContainerVisible == aVisible "); |
|
373 // if state is not changed, we do not need to do it again |
|
374 return; |
|
375 } |
|
376 } |
|
377 |
|
378 LOG(EJavaMMAPI,EInfo,"MID::CMMADisplay::MdcContainerVisibilityChanged After condition2"); |
|
379 |
|
380 if (iWindow) |
|
381 { |
|
382 LOG(EJavaMMAPI,EInfo,"MID::CMMADisplay::MdcContainerVisibilityChanged iWindow is valid "); |
|
383 // change is only needed if java side has set display visible or |
|
384 // if container loses focus |
|
385 if (!iContainerVisible || iVisible) |
|
386 { |
|
387 if (iResetDrawRect && aVisible && !iFullScreen) |
|
388 { |
|
389 iWindow->SetDrawRectThread(iUserRect); |
|
390 iResetDrawRect = EFalse; |
|
391 } |
|
392 if (iIsForeground) |
|
393 { |
|
394 iWindow->SetVisible(aVisible); |
|
395 } |
|
396 SetClippingRegion(); |
|
397 } |
|
398 } |
|
399 } |
|
400 |
|
401 /* |
|
402 |
|
403 void CMMADisplay::MdcItemContentRectChanged(const TRect& aContentRect, |
|
404 const TRect& aScreenRect) |
|
405 { |
|
406 // To be overwritten if used |
|
407 __ASSERT_LOG(EJavaMMAPI,EInfo,"EFalse, User::Invariant()); |
|
408 } |
|
409 |
|
410 void CMMADisplay::MdcContainerWindowRectChanged(const TRect& |
|
411 #ifdef RD_JAVA_NGA_ENABLED |
|
412 aRect |
|
413 #endif |
|
414 ) |
|
415 { |
|
416 LOG(EJavaMMAPI,EInfo,"CMMADisplay::MdcContainerWindowRectChanged +"); |
|
417 |
|
418 #ifdef RD_JAVA_NGA_ENABLED |
|
419 if( iWindow ) |
|
420 { |
|
421 LOG(EJavaMMAPI,EInfo,"CMMADisplay::MdcContainerWindowRectChanged, SetRWindowRect"); |
|
422 iWindow->SetRWindowRect(aRect, MMMADisplay::EUiThread); |
|
423 } |
|
424 #endif |
|
425 } |
|
426 void CMMADisplay::MdcContainerDestroyed() |
|
427 { |
|
428 LOG(EJavaMMAPI,EInfo,"MMA::CMMADisplay::MdcContainerDestroyed"); |
|
429 |
|
430 if (iWindow) |
|
431 { |
|
432 iWindow->ContainerDestroyed(); |
|
433 } |
|
434 |
|
435 iDirectContainer = NULL; |
|
436 } |
|
437 |
|
438 |
|
439 void CMMADisplay::MdcAbortDSA() |
|
440 { |
|
441 if (iWindow) |
|
442 { |
|
443 iWindow->AbortDSA(); |
|
444 } |
|
445 } |
|
446 |
|
447 |
|
448 void CMMADisplay::MdcResumeDSA() |
|
449 { |
|
450 if (iWindow) |
|
451 { |
|
452 iWindow->ResumeDSA(); |
|
453 } |
|
454 } |
|
455 |
|
456 void CMMADisplay::UIGetCallback( |
|
457 MUiEventConsumer& aConsumer, |
|
458 TInt aCallbackId) |
|
459 { |
|
460 if (iDirectContainer) |
|
461 { |
|
462 iDirectContainer->MdcGetUICallback(aConsumer, aCallbackId); |
|
463 } |
|
464 } |
|
465 */ |
|
466 |
|
467 |
|
468 void CMMADisplay::GetCallbackInUiThread(TInt placeholder) |
|
469 { |
|
470 LOG(EJavaMMAPI,EInfo,"CMMADisplay::GetCallbackInUiThread +"); |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 jmethodID getCallBackMethodID = iJni->GetMethodID( |
|
480 iJavaDisplayClass, |
|
481 "GetCallbackInUiThread", |
|
482 "(I)V"); |
|
483 // LOG1(EJavaMMAPI,EInfo,"CMMADisplay::GetCallbackInUiThread getCallBackMethodID = %d",getCallBackMethodID); |
|
484 iJni->CallVoidMethod(iJavaDisplayObject,getCallBackMethodID,placeholder); |
|
485 LOG(EJavaMMAPI,EInfo,"CMMADisplay::GetCallbackInUiThread -"); |
|
486 } |
|
487 |
|
488 void CMMADisplay::CalledBackInUiThread(TInt placeholder) |
|
489 { |
|
490 LOG(EJavaMMAPI,EInfo,"CMMADisplay::CalledBackInUiThread +"); |
|
491 iWindow->UICallback(placeholder); |
|
492 LOG(EJavaMMAPI,EInfo,"CMMADisplay::CalledBackInUiThread -"); |
|
493 |
|
494 } |
|
495 |
|
496 void CMMADisplay::SourceSizeChanged(TInt aJavaControlWidth, TInt aJavaControlHeight) |
|
497 { |
|
498 LOG2(EJavaMMAPI,EInfo,"CMMADisplay::SourceSizeChanged(aSourceSize,aJavaControlWidth,aJavaControlHeight) + aJavaControlWidth = %d ,aJavaControlHeight = %d",aJavaControlWidth,aJavaControlHeight); |
|
499 iSourceSize = SourceSize(); |
|
500 LOG2(EJavaMMAPI,EInfo,"CMMADisplay::SourceSizeChanged(aSourceSize,aJavaControlWidth,aJavaControlHeight) + sourcesize = %d X %d",iSourceSize.iWidth , iSourceSize.iHeight); |
|
501 #ifdef RD_JAVA_NGA_ENABLED |
|
502 if ( iWindow ) |
|
503 { |
|
504 iWindow->SetVideoCropRegion( TRect( iUserRect.iTl, iSourceSize ) ); |
|
505 } |
|
506 #endif |
|
507 |
|
508 // size of canvas in java |
|
509 TSize canvasSize(aJavaControlWidth, aJavaControlHeight); |
|
510 fullScreenSize = canvasSize; |
|
511 TBool sourceIsBigger = (iSourceSize.iWidth > fullScreenSize.iWidth || |
|
512 iSourceSize.iHeight > fullScreenSize.iHeight); |
|
513 |
|
514 if (sourceIsBigger) |
|
515 { |
|
516 // Source is larger than display area. |
|
517 // Shrink draw are to fit in display. |
|
518 iWindow->SetDrawRect(ScaleToFullScreen(fullScreenSize, iSourceSize)); |
|
519 } |
|
520 else |
|
521 { |
|
522 // source is smaller than display area |
|
523 iWindow->SetDrawRect(TRect(iUserRect.iTl, iSourceSize)); |
|
524 } |
|
525 |
|
526 SetClippingRegion(); |
|
527 |
|
528 if (iUserRect.IsEmpty()) |
|
529 { |
|
530 // Java side hasn't set size. |
|
531 iUserRect = iWindow->DrawRect(); |
|
532 |
|
533 if (!sourceIsBigger) |
|
534 { |
|
535 // Addjusting rect to top left corner. |
|
536 iUserRect = TRect(iUserRect.Size()); |
|
537 } |
|
538 } |
|
539 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SourceSizeChanged(aSourceSize,aJavaControlWidth,aJavaControlHeight) -"); |
|
540 } |
|
541 |
|
542 void CMMADisplay::SetWindowResources(QWidget* qtWidget) |
|
543 { |
|
544 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetWindowResources +"); |
|
545 CCoeControl* control = 0; |
|
546 if(qtWidget && qtWidget ->winId()) |
|
547 { |
|
548 control = reinterpret_cast<CCoeControl*>(qtWidget->winId()); |
|
549 } |
|
550 |
|
551 CCoeEnv *coeEnv = control->ControlEnv(); |
|
552 RWsSession * iWs = &(coeEnv->WsSession()); |
|
553 CWsScreenDevice* iScreenDevice = coeEnv->ScreenDevice(); |
|
554 RWindowBase* window = static_cast<RWindowBase*>(control->DrawableWindow()); |
|
555 if (!iWindow) |
|
556 { |
|
557 return; |
|
558 } |
|
559 iWindow->ProcureWindowResourcesFromQWidget(iWs,iScreenDevice,window); |
|
560 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetWindowResources -"); |
|
561 } |
|
562 |
|
563 |
|
564 void CMMADisplay::SetForeground(TBool aForeground, TBool aUseEventServer) |
|
565 { |
|
566 LOG1(EJavaMMAPI,EInfo,"MMA::CMMADisplay::SetForeground %d", aForeground); |
|
567 iIsForeground = aForeground; |
|
568 |
|
569 if (aForeground) |
|
570 { |
|
571 if (iContainerVisible && !iWindow->IsVisible()) |
|
572 { |
|
573 iWindow->SetVisible(ETrue, aUseEventServer); |
|
574 } |
|
575 } |
|
576 else |
|
577 { |
|
578 if (iWindow->IsVisible()) |
|
579 { |
|
580 iWindow->SetVisible(EFalse, aUseEventServer); |
|
581 } |
|
582 } |
|
583 } |
|
584 |
|
585 TSize CMMADisplay::SourceSize() |
|
586 { |
|
587 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SetSourceSizeToDisplay "); |
|
588 return iUiPlayer->SourceSize(); |
|
589 } |
|
590 |
|
591 void CMMADisplay::SetUIPlayer(MMMAGuiPlayer* player) |
|
592 { |
|
593 iUiPlayer = player; |
|
594 } |
|
595 |
|
596 |
|
597 void CMMADisplay::SourceSizeChanged(const TSize& aSourceSize) |
|
598 { |
|
599 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SourceSizeChanged"); |
|
600 |
|
601 #ifdef RD_JAVA_NGA_ENABLED |
|
602 if ( iWindow ) |
|
603 { |
|
604 iWindow->SetVideoCropRegion( TRect( iUserRect.iTl, aSourceSize ) ); |
|
605 } |
|
606 #endif |
|
607 |
|
608 iSourceSize = aSourceSize; |
|
609 jmethodID getDisplayWidthID = iJni->GetMethodID( |
|
610 iJavaDisplayClass, |
|
611 "getDisplayWidth", |
|
612 "()I"); |
|
613 |
|
614 jmethodID getDisplayHeightID = iJni->GetMethodID( |
|
615 iJavaDisplayClass, |
|
616 "getDisplayHeight", |
|
617 "()I"); |
|
618 |
|
619 |
|
620 TInt x = iJni->CallIntMethod(iJavaDisplayObject,getDisplayWidthID); |
|
621 TInt y = iJni->CallIntMethod(iJavaDisplayObject,getDisplayHeightID); |
|
622 LOG2(EJavaMMAPI,EInfo,"CMMADisplay.cpp : SourceSizeChanged () fullScreenSize is x = %d ,y = %d ",x,y); |
|
623 // get the ScreenSize from canvas in java |
|
624 TSize canvasSize(x, y); |
|
625 fullScreenSize = canvasSize; |
|
626 TBool sourceIsBigger = (aSourceSize.iWidth > fullScreenSize.iWidth || |
|
627 aSourceSize.iHeight > fullScreenSize.iHeight); |
|
628 |
|
629 if (sourceIsBigger) |
|
630 { |
|
631 // Source is larger than display area. |
|
632 // Shrink draw are to fit in display. |
|
633 iWindow->SetDrawRect(ScaleToFullScreen(fullScreenSize, iSourceSize)); |
|
634 } |
|
635 else |
|
636 { |
|
637 // source is smaller than display area |
|
638 iWindow->SetDrawRect(TRect(iUserRect.iTl, iSourceSize)); |
|
639 } |
|
640 |
|
641 SetClippingRegion(); |
|
642 |
|
643 if (iUserRect.IsEmpty()) |
|
644 { |
|
645 // Java side hasn't set size. |
|
646 iUserRect = iWindow->DrawRect(); |
|
647 |
|
648 if (!sourceIsBigger) |
|
649 { |
|
650 // Addjusting rect to top left corner. |
|
651 iUserRect = TRect(iUserRect.Size()); |
|
652 } |
|
653 } |
|
654 } |
|
655 |
|
656 |
|
657 |
|
658 void CMMADisplay::SetDisplayPosition(TInt uiControlLocationX,TInt uiControlLocationY,TInt videoControlLocationX,TInt videoControlLocationY) |
|
659 { |
|
660 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SourceSizeChanged + "); |
|
661 TPoint point(videoControlLocationX ,videoControlLocationY); |
|
662 //calling derived class fuction |
|
663 SetDisplayLocationL(point); |
|
664 LOG(EJavaMMAPI,EInfo,"CMMADisplay::SourceSizeChanged - "); |
|
665 } |
|
666 |
|
667 |
|
668 void CMMADisplay::ResetJavaRectObject(const TRect& aRect) |
|
669 { |
|
670 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::ResetJavaRectObject +"); |
|
671 JNIEnv* validJni = iEventSource->getValidJniEnv(); |
|
672 jmethodID setRectID = validJni->GetMethodID( |
|
673 iJavaDisplayClass, |
|
674 "setRect", |
|
675 "()V"); |
|
676 |
|
677 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::ResetJavaRectObject --1"); |
|
678 // set the value to java,so that we can access those from array |
|
679 jfieldID field = validJni->GetFieldID(iJavaDisplayClass, "rectDimension", "[I"); |
|
680 if(field == NULL) |
|
681 { |
|
682 // handle error |
|
683 } |
|
684 /* Write to the instance fields */ |
|
685 jintArray javaDimensionarr = (jintArray)validJni->GetObjectField(iJavaDisplayObject, field); |
|
686 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::ResetJavaRectObject --2"); |
|
687 jint* nativeRectDimensionArr = validJni->GetIntArrayElements(javaDimensionarr, NULL); |
|
688 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::ResetJavaRectObject --3"); |
|
689 if (!nativeRectDimensionArr) |
|
690 { // inputBuffer was already allocated |
|
691 validJni->ReleaseIntArrayElements(javaDimensionarr, nativeRectDimensionArr, JNI_ABORT); |
|
692 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::ResetJavaRectObject Error in resetting rect dimension to java"); |
|
693 return; |
|
694 } |
|
695 nativeRectDimensionArr[0] = aRect.iTl.iX; |
|
696 nativeRectDimensionArr[1] = aRect.iTl.iY;; |
|
697 nativeRectDimensionArr[2] = aRect.Width(); |
|
698 nativeRectDimensionArr[3] = aRect.Height(); |
|
699 // Now the dimension array in java is updated hence reset the java rect |
|
700 validJni->CallVoidMethod(iJavaDisplayObject,setRectID); |
|
701 |
|
702 validJni->ReleaseIntArrayElements(javaDimensionarr, nativeRectDimensionArr, JNI_COMMIT); |
|
703 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::ResetJavaRectObject -"); |
|
704 } |
|
705 |
|
706 |
|
707 void CMMADisplay::SetContentBoundToJavaControl(const TRect& aRect) |
|
708 { |
|
709 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::SetContentBoundToJavaControl +"); |
|
710 JNIEnv* validJni = iEventSource->getValidJniEnv(); |
|
711 // Reset the java rect |
|
712 ResetJavaRectObject(aRect); |
|
713 jmethodID setContentBoundID = validJni->GetMethodID( |
|
714 iJavaDisplayClass, |
|
715 "setContentBound", |
|
716 "()V"); |
|
717 // call java function |
|
718 validJni->CallVoidMethod(iJavaDisplayObject,setContentBoundID); |
|
719 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::SetContentBoundToJavaControl -"); |
|
720 } |
|
721 |
|
722 void CMMADisplay::RemoveContentBoundFromJavaControl(const TRect& aRect) |
|
723 { |
|
724 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::RemoveContentBoundFromJavaControl +"); |
|
725 JNIEnv* validJni = iEventSource->getValidJniEnv(); |
|
726 // Reset the java rect |
|
727 ResetJavaRectObject(aRect); |
|
728 jmethodID removeContentBoundID = validJni->GetMethodID( |
|
729 iJavaDisplayClass, |
|
730 "removeContentBound", |
|
731 "()V"); |
|
732 // call java function |
|
733 validJni->CallVoidMethod(iJavaDisplayObject,removeContentBoundID); |
|
734 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::RemoveContentBoundFromJavaControl -"); |
|
735 } |
|
736 |
|
737 void CMMADisplay::RefreshJavaControl(const TRect& aRect) |
|
738 { |
|
739 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::RefreshJavaControl +"); |
|
740 JNIEnv* validJni = iEventSource->getValidJniEnv(); |
|
741 // Reset the java rect |
|
742 //ResetJavaRectObject(aRect); |
|
743 jmethodID redrawControlID = validJni->GetMethodID( |
|
744 iJavaDisplayClass, |
|
745 "redrawControl", |
|
746 "()V"); |
|
747 // call java function |
|
748 validJni->CallVoidMethod(iJavaDisplayObject,redrawControlID); |
|
749 LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::RefreshJavaControl -"); |
|
750 } |
|
751 |
|
752 // END OF FILE |