javauis/mmapi_akn/baseline/src/cmmacanvasdisplay.cpp
branchRCL_3
changeset 19 04becd199f91
child 71 d5e927d5853b
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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 <jdebug.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 
       
    30 // CONSTRUCTION
       
    31 // Static constructor, leaves pointer to cleanup-stack
       
    32 CMMACanvasDisplay* CMMACanvasDisplay::NewLC(MMIDCanvas* aCanvas)
       
    33 {
       
    34     CMMACanvasDisplay* self =
       
    35         new(ELeave) CMMACanvasDisplay(aCanvas);
       
    36 
       
    37     CleanupStack::PushL(self);
       
    38     self->Construct(&aCanvas->DirectContainer());
       
    39     return self;
       
    40 }
       
    41 
       
    42 // Destructor (virtual by CBase)
       
    43 CMMACanvasDisplay::~CMMACanvasDisplay()
       
    44 {
       
    45 }
       
    46 
       
    47 CMMACanvasDisplay::CMMACanvasDisplay(MMIDCanvas* aCanvas):
       
    48         iCanvas(aCanvas)
       
    49 {
       
    50 }
       
    51 
       
    52 void CMMACanvasDisplay::SourceSizeChanged(const TSize& aSourceSize)
       
    53 {
       
    54     DEBUG_INT("MMA::CMMACanvasDisplay::SourceSizeChanged %d",
       
    55               aSourceSize.iWidth);
       
    56     DEBUG_INT("MMA::CMMACanvasDisplay::SourceSizeChanged %d",
       
    57               aSourceSize.iHeight);
       
    58 
       
    59     iSourceSize = aSourceSize;
       
    60     TSize fullScreenSize(iCanvas->ContentSize());
       
    61 
       
    62     TBool sourceIsBigger = (aSourceSize.iWidth > fullScreenSize.iWidth ||
       
    63                             aSourceSize.iHeight > fullScreenSize.iHeight);
       
    64 
       
    65     if (iWindow)
       
    66     {
       
    67 #ifdef RD_JAVA_NGA_ENABLED
       
    68         TPoint topLeft(0, 0);
       
    69         iWindow->SetVideoCropRegion(TRect(topLeft, aSourceSize));
       
    70 #endif
       
    71 
       
    72         if (sourceIsBigger)
       
    73         {
       
    74             // Source is larger than display area.
       
    75             // Shrink draw are to fit in display.
       
    76             iWindow->SetDrawRect(ScaleToFullScreen(fullScreenSize, iSourceSize));
       
    77         }
       
    78         else
       
    79         {
       
    80             // source is smaller than display area
       
    81             iWindow->SetDrawRect(TRect(iUserRect.iTl, iSourceSize));
       
    82         }
       
    83     }
       
    84     SetClippingRegion();
       
    85 
       
    86     if (iUserRect.IsEmpty())
       
    87     {
       
    88         if (iWindow)
       
    89         {
       
    90             // Java side hasn't set size.
       
    91             iUserRect = iWindow->DrawRect();
       
    92         }
       
    93 
       
    94         if (!sourceIsBigger)
       
    95         {
       
    96             // Addjusting rect to top left corner.
       
    97             iUserRect = TRect(iUserRect.Size());
       
    98         }
       
    99     }
       
   100 }
       
   101 
       
   102 
       
   103 void CMMACanvasDisplay::SetFullScreenL(TBool aFullScreen)
       
   104 {
       
   105     iFullScreen = aFullScreen;
       
   106     if (iContainerVisible)
       
   107     {
       
   108         RemoveClippingRegion();
       
   109 
       
   110         if (aFullScreen)
       
   111         {
       
   112             // use new scaled rect
       
   113             iWindow->SetDrawRect(ScaleToFullScreen(
       
   114                                      iCanvas->ContentSize(), iSourceSize));
       
   115         }
       
   116         else
       
   117         {
       
   118             // use size set from java
       
   119             iWindow->SetDrawRect(iUserRect);
       
   120         }
       
   121 
       
   122         AddClippingRegion();
       
   123     }
       
   124 }
       
   125 
       
   126 void CMMACanvasDisplay::SetWindowL(MMMADisplayWindow* aWindow)
       
   127 {
       
   128     DEBUG("CMMACanvasDisplay::SetWindowL");
       
   129     CMMADisplay::SetWindowL(aWindow);
       
   130     if (!iWindow)
       
   131     {
       
   132         DEBUG("CMMACanvasDisplay::SetWindowL: NULL window, returning");
       
   133         return;
       
   134     }
       
   135 
       
   136     CFbsBitmap* bitmap = iCanvas->FrameBuffer();
       
   137 
       
   138     __ASSERT_DEBUG(bitmap,
       
   139                    User::Panic(_L("Canvas has no bitmap"),
       
   140                                KErrNotFound));
       
   141 
       
   142     iWindow->SetDestinationBitmapL(bitmap);
       
   143 
       
   144     // Check that container exists
       
   145     User::LeaveIfNull(iDirectContainer);
       
   146 
       
   147     DEBUG_INT2("MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() TL %d %d", iDirectContainer->MdcContentBounds().iTl.iX, iDirectContainer->MdcContentBounds().iTl.iY);
       
   148     DEBUG_INT2("MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() BR %d %d", iDirectContainer->MdcContentBounds().iBr.iX, iDirectContainer->MdcContentBounds().iBr.iY);
       
   149 
       
   150     iWindow->SetWindowRect(iDirectContainer->MdcContentBounds(), MMMADisplay::EMmaThread);
       
   151 #ifdef RD_JAVA_NGA_ENABLED
       
   152     iWindow->SetRWindowRect(iDirectContainer->MdcContainerWindowRect(),
       
   153                             MMMADisplay::EMmaThread);
       
   154 #endif
       
   155 }
       
   156 
       
   157 void CMMACanvasDisplay::SetDisplayLocationL(const TPoint& aPosition)
       
   158 {
       
   159     // Move iUserRect top left corner to aPosition.
       
   160     TSize size(iUserRect.Size());
       
   161     iUserRect.iTl = aPosition;
       
   162     iUserRect.SetSize(size);
       
   163 
       
   164     if (iContainerVisible && !iFullScreen && iWindow)
       
   165     {
       
   166         iWindow->SetDrawRect(iUserRect);
       
   167         SetClippingRegion();
       
   168     }
       
   169     else
       
   170     {
       
   171         iResetDrawRect = ETrue;
       
   172     }
       
   173 }
       
   174 
       
   175 TPoint CMMACanvasDisplay::DisplayLocation()
       
   176 {
       
   177     if (iWindow && iFullScreen)
       
   178     {
       
   179         return iWindow->DrawRect().iTl;
       
   180     }
       
   181     else
       
   182     {
       
   183         return iUserRect.iTl;
       
   184     }
       
   185 }
       
   186 
       
   187 void CMMACanvasDisplay::MdcContentBoundsChanged(const TRect& aRect)
       
   188 {
       
   189     DEBUG_INT2("MID::CMMACanvasDisplay::MdcContentBoundsChanged aRect TL %d %d",
       
   190                aRect.iTl.iX, aRect.iTl.iY);
       
   191     DEBUG_INT2("MID::CMMACanvasDisplay::MdcContentBoundsChanged aRect BR %d %d",
       
   192                aRect.iBr.iX, aRect.iBr.iY);
       
   193 
       
   194     if (iWindow)
       
   195     {
       
   196         // Set new rect to window.
       
   197         iWindow->SetWindowRect(aRect, MMMADisplay::EUiThread);
       
   198 
       
   199         if (iFullScreen)
       
   200         {
       
   201             TRect fullRect = ScaleToFullScreen(iCanvas->ContentSize(),
       
   202                                                iSourceSize);
       
   203 
       
   204             // use SetDrawRectThread because this code is executed
       
   205             // in lcdui thread
       
   206             iWindow->SetDrawRectThread(fullRect);
       
   207         }
       
   208         else
       
   209         {
       
   210             // move to user defined position.
       
   211             iWindow->SetPosition(iUserRect.iTl);
       
   212         }
       
   213     }
       
   214     SetClippingRegion();
       
   215 }
       
   216 
       
   217 //  END OF FILE