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