javauis/mmapi_qt/baseline/src/cmmacanvasdisplay.cpp
changeset 23 98ccebc37403
child 26 dc7c549001d5
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     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:  Draws to Canvas.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  Include Files
       
    20 #include <logger.h>
       
    21 //#include <lcdui.h> // MMIDCanvas
       
    22 
       
    23 #ifdef EXTENDED_LCDUI_CANVAS
       
    24 #include <MMIDCanvasExtended.h>
       
    25 #endif
       
    26 
       
    27 #include "cmmacanvasdisplay.h"
       
    28 #include "cmmabitmapwindow.h"
       
    29 #include "mmafunctionserver.h"
       
    30 
       
    31 // CONSTRUCTION
       
    32 // Static constructor, leaves pointer to cleanup-stack
       
    33 CMMACanvasDisplay* CMMACanvasDisplay::NewLC(MMAFunctionServer* aEventSource, jobject obj/*MMIDCanvas* aCanvas*/)
       
    34 {
       
    35 	CMMACanvasDisplay* self =
       
    36         new(ELeave) CMMACanvasDisplay(aEventSource, obj/*aCanvas*/);
       
    37 
       
    38     CleanupStack::PushL(self);
       
    39     self->Construct(aEventSource,obj);
       
    40     return self;
       
    41 }
       
    42 
       
    43 // Destructor (virtual by CBase)
       
    44 CMMACanvasDisplay::~CMMACanvasDisplay()
       
    45 {
       
    46 }
       
    47 
       
    48 CMMACanvasDisplay::CMMACanvasDisplay(MMAFunctionServer* aEventSource ,jobject aJavaDisplayRef)
       
    49 {
       
    50 	/*
       
    51 iJni = aEventSource->getValidJniEnv();
       
    52 javaDisplayObject = iJni->NewGlobalRef(javadisplayref);
       
    53 javaDisplayClass = iJni->GetObjectClass(javaDisplayObject);
       
    54 */
       
    55 }
       
    56 
       
    57 
       
    58 /*
       
    59 void CMMACanvasDisplay::SourceSizeChanged(const TSize& aSourceSize)
       
    60 {
       
    61     LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged");
       
    62 
       
    63     #ifdef RD_JAVA_NGA_ENABLED
       
    64     if ( iWindow )
       
    65 			{
       
    66     	iWindow->SetVideoCropRegion( TRect( iUserRect.iTl, aSourceSize ) );
       
    67     	}
       
    68     #endif
       
    69 
       
    70     iSourceSize = aSourceSize;
       
    71     jmethodID getDisplayWidthID = iJni->GetMethodID(
       
    72                                          iJavaDisplayClass,
       
    73                                          "getDisplayWidth",
       
    74                                          "()I");
       
    75 
       
    76     jmethodID getDisplayHeightID = iJni->GetMethodID(
       
    77                                          iJavaDisplayClass,
       
    78                                          "getDisplayHeight",
       
    79                                          "()I");
       
    80 
       
    81 
       
    82      TInt x =  iJni->CallIntMethod(iJavaDisplayObject,getDisplayWidthID);
       
    83      TInt y = iJni->CallIntMethod(iJavaDisplayObject,getDisplayHeightID);
       
    84 
       
    85    // TSize fullScreenSize(100,100);    // TO-Do remove hardcoded with the relevent one
       
    86 	LOG2(EJavaMMAPI,EInfo,"CMMACanvasdisplay.cpp : SourceSizeChanged () fullScreenSize is x = %d ,y = %d ",x,y);
       
    87 	// get the ScreenSize from canvas in java
       
    88     TSize canvasSize(x, y);
       
    89     fullScreenSize = canvasSize;
       
    90     TBool sourceIsBigger = (aSourceSize.iWidth > fullScreenSize.iWidth ||
       
    91                             aSourceSize.iHeight > fullScreenSize.iHeight);
       
    92 
       
    93     if (sourceIsBigger)
       
    94     {
       
    95         // Source is larger than display area.
       
    96         // Shrink draw are to fit in display.
       
    97         iWindow->SetDrawRect(ScaleToFullScreen(fullScreenSize, iSourceSize));
       
    98     }
       
    99     else
       
   100     {
       
   101         // source is smaller than display area
       
   102         iWindow->SetDrawRect(TRect(iUserRect.iTl, iSourceSize));
       
   103     }
       
   104 
       
   105     SetClippingRegion();
       
   106 
       
   107     if (iUserRect.IsEmpty())
       
   108     {
       
   109         // Java side hasn't set size.
       
   110         iUserRect = iWindow->DrawRect();
       
   111 
       
   112         if (!sourceIsBigger)
       
   113         {
       
   114             // Addjusting rect to top left corner.
       
   115             iUserRect = TRect(iUserRect.Size());
       
   116         }
       
   117     }
       
   118 }
       
   119 
       
   120 */
       
   121 
       
   122 void CMMACanvasDisplay::SetFullScreenL(TBool aFullScreen)
       
   123 {
       
   124 	LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL +");
       
   125     iFullScreen = aFullScreen;
       
   126     if (iContainerVisible)
       
   127     {
       
   128         RemoveClippingRegion();
       
   129 
       
   130         if (aFullScreen)
       
   131         {
       
   132             // use new scaled rect
       
   133             // iWindow->SetDrawRect(ScaleToFullScreen(fullScreenSize, iSourceSize));
       
   134             iWindow->SetDrawRectThread(ScaleToFullScreen(fullScreenSize, iSourceSize));
       
   135 		}
       
   136         else
       
   137         {
       
   138 			// use size set from java
       
   139             //iWindow->SetDrawRect(iUserRect);
       
   140             iWindow->SetDrawRectThread(iUserRect);
       
   141         }
       
   142 
       
   143         AddClippingRegion();
       
   144     }
       
   145     LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL +");
       
   146 }
       
   147 
       
   148 void CMMACanvasDisplay::SetWindowL(MMMADisplayWindow* aWindow)
       
   149 {
       
   150     LOG( EJavaMMAPI, EInfo, "CMMACanvasDisplay::SetWindowL");
       
   151     CMMADisplay::SetWindowL(aWindow);
       
   152     if (!iWindow)
       
   153     {
       
   154         LOG( EJavaMMAPI, EInfo, "CMMACanvasDisplay::SetWindowL: NULL window, returning");
       
   155         return;
       
   156     }
       
   157 	/*
       
   158     CFbsBitmap* bitmap = iCanvas->FrameBuffer();
       
   159 
       
   160     __ASSERT_DEBUG(bitmap,
       
   161                    User::Panic(_L("Canvas has no bitmap"),
       
   162                                KErrNotFound));
       
   163 
       
   164     iWindow->SetDestinationBitmapL(bitmap);
       
   165 
       
   166     // Check that container exists
       
   167     User::LeaveIfNull(iDirectContainer);
       
   168 
       
   169     LOG2( EJavaMMAPI, EInfo, "MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() TL %d %d", iDirectContainer->MdcContentBounds().iTl.iX, iDirectContainer->MdcContentBounds().iTl.iY);
       
   170     LOG2( EJavaMMAPI, EInfo, "MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() BR %d %d", iDirectContainer->MdcContentBounds().iBr.iX, iDirectContainer->MdcContentBounds().iBr.iY);
       
   171 	*/
       
   172 	LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::before calling  BoundRect");
       
   173 	TRect boundrect = BoundRect();
       
   174     iWindow->SetWindowRect(boundrect/*iDirectContainer->MdcContentBounds()*/, MMMADisplay::EMmaThread);
       
   175 
       
   176     #ifdef RD_JAVA_NGA_ENABLED
       
   177     //iWindow->SetRWindowRect( iDirectContainer->MdcContainerWindowRect(),
       
   178     //                         MMMADisplay::EMmaThread );
       
   179 	iWindow->SetRWindowRect( boundrect,
       
   180      							MMMADisplay::EMmaThread );
       
   181     #endif
       
   182     
       
   183     SetClippingRegion();
       
   184 }
       
   185 
       
   186 
       
   187 
       
   188 TRect& CMMACanvasDisplay::BoundRect()
       
   189 {
       
   190   LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect +");
       
   191   jmethodID getBoundRectID = iJni->GetMethodID(
       
   192 	                                         iJavaDisplayClass,
       
   193 	                                         "getBoundRect",
       
   194                                          "()V");
       
   195 
       
   196   LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --1");
       
   197   // set the value to java,so that we can access those from array
       
   198   iJni->CallVoidMethod(iJavaDisplayObject,getBoundRectID);
       
   199   jfieldID field = iJni->GetFieldID(iJavaDisplayClass, "displayboundarr", "[I");
       
   200   if(field == NULL)
       
   201   {
       
   202 	  // handle error
       
   203   }
       
   204   /* Read the instance field s */
       
   205   jintArray javaboundinfoarr = (jintArray)iJni->GetObjectField(iJavaDisplayObject, field);
       
   206   LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --2");
       
   207   jint* nativeboundinfoarr = iJni->GetIntArrayElements(javaboundinfoarr, NULL);
       
   208     LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --3");
       
   209     if (!nativeboundinfoarr)
       
   210     {    // outputBuffer was already allocated
       
   211         iJni->ReleaseIntArrayElements(javaboundinfoarr, nativeboundinfoarr, JNI_ABORT);
       
   212         // return invalid rect.
       
   213         TRect rect(0,0,0,0);
       
   214         return rect;
       
   215     }
       
   216   LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --4");
       
   217 // create TRect
       
   218   TInt xcoordinate = nativeboundinfoarr[0];
       
   219   TInt ycoordinate = nativeboundinfoarr[1];
       
   220   TInt width = nativeboundinfoarr[2];
       
   221   TInt height = nativeboundinfoarr[3];
       
   222   LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay: BoundRect() co-ordinate of topleftcorner is x = %d,y =%d",xcoordinate,ycoordinate);
       
   223   LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay: BoundRect() size of bound rect is width = %d,height =%d",width,height);
       
   224   TPoint topleft(xcoordinate,ycoordinate);
       
   225   TSize rectsize(width,height);
       
   226   TRect boundRect(topleft,rectsize);
       
   227   iJni->ReleaseIntArrayElements(javaboundinfoarr, nativeboundinfoarr, JNI_COMMIT);
       
   228    LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect -");
       
   229   return boundRect;
       
   230 }
       
   231 
       
   232 // ask java side peer about the container rect size
       
   233 // currently assuming the boundrect and containerrect will be same in case of canvas
       
   234 TRect& CMMACanvasDisplay::ContainerWindowRect()
       
   235 {
       
   236 
       
   237   return BoundRect();
       
   238 
       
   239 }
       
   240 
       
   241 
       
   242 void CMMACanvasDisplay::SetDisplayLocationL(const TPoint& aPosition)
       
   243 {
       
   244     // Move iUserRect top left corner to aPosition.
       
   245     TSize size(iUserRect.Size());
       
   246     iUserRect.iTl = aPosition;
       
   247     iUserRect.SetSize(size);
       
   248 
       
   249     if (iContainerVisible && !iFullScreen && iWindow)
       
   250     {
       
   251         iWindow->SetDrawRect(iUserRect);
       
   252         SetClippingRegion();
       
   253     }
       
   254     else
       
   255     {
       
   256         iResetDrawRect = ETrue;
       
   257     }
       
   258 }
       
   259 
       
   260 TPoint CMMACanvasDisplay::DisplayLocation()
       
   261 {
       
   262     if (iWindow && iFullScreen)
       
   263     {
       
   264         return iWindow->DrawRect().iTl;
       
   265     }
       
   266     else
       
   267     {
       
   268         return iUserRect.iTl;
       
   269     }
       
   270 }
       
   271 
       
   272 
       
   273 
       
   274 
       
   275 
       
   276 /*
       
   277 void CMMACanvasDisplay::MdcContentBoundsChanged(const TRect& aRect)
       
   278 {
       
   279     LOG2(EJavaMMAPI,EInfo,"MID::CMMACanvasDisplay::MdcContentBoundsChanged aRect TL %d %d",
       
   280                aRect.iTl.iX, aRect.iTl.iY);
       
   281     LOG2(EJavaMMAPI,EInfo,"MID::CMMACanvasDisplay::MdcContentBoundsChanged aRect BR %d %d",
       
   282                aRect.iBr.iX, aRect.iBr.iY);
       
   283 
       
   284     if (iWindow)
       
   285     {
       
   286         // Set new rect to window.
       
   287         iWindow->SetWindowRect(aRect, MMMADisplay::EUiThread);
       
   288 
       
   289         if (iFullScreen)
       
   290         {
       
   291             TRect fullRect = ScaleToFullScreen(iCanvas->ContentSize(),
       
   292                                                iSourceSize);
       
   293 
       
   294             // use SetDrawRectThread because this code is executed
       
   295             // in lcdui thread
       
   296             iWindow->SetDrawRectThread(fullRect);
       
   297         }
       
   298         else
       
   299         {
       
   300             // move to user defined position.
       
   301             iWindow->SetPosition(iUserRect.iTl);
       
   302         }
       
   303     }
       
   304     SetClippingRegion();
       
   305 }
       
   306 */
       
   307 
       
   308 //  END OF FILE