webengine/pagescaler/src/minimapscaler.cpp
changeset 0 dd21522fd290
child 68 92a765b5b3e7
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2005 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 the License "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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "minimapscaler.h"
       
    23 
       
    24 #include <fbs.h>
       
    25 #include <BitmapTransforms.h>
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES  
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // MACROS
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 
       
    37 // MODULE DATA STRUCTURES
       
    38 
       
    39 // LOCAL FUNCTION PROTOTYPES
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 
       
    43 // ============================= LOCAL FUNCTIONS ===============================
       
    44 
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CMinimapScaler::CMinimapScaler
       
    50 // C++ default constructor can NOT contain any code, that
       
    51 // might leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CMinimapScaler::CMinimapScaler(MMinimapScalerCallback& aCallback)
       
    55     : CActive(CActive::EPriorityIdle-1), iCallback(&aCallback)
       
    56     {
       
    57     CActiveScheduler::Add(this);
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CMinimapScaler::ConstructL
       
    62 // Symbian 2nd phase constructor can leave.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CMinimapScaler::ConstructL()
       
    66     {
       
    67     iScaler = CBitmapScaler::NewL();
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CMinimapScaler::NewL
       
    72 // Two-phased constructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CMinimapScaler* CMinimapScaler::NewL(MMinimapScalerCallback& aCallback)
       
    76     {
       
    77     CMinimapScaler* self = new( ELeave ) CMinimapScaler(aCallback);
       
    78     
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     CleanupStack::Pop();
       
    82 
       
    83     return self;
       
    84     }
       
    85 
       
    86     
       
    87 // Destructor
       
    88 CMinimapScaler::~CMinimapScaler()
       
    89     {       
       
    90     Cancel();
       
    91     delete iScaler;
       
    92     delete iResultBitmap;
       
    93     }
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CMinimapScaler::StartScalingL
       
    98 // 
       
    99 // 
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CMinimapScaler::StartScalingL(CFbsBitmap& aSource, const TRect& aTargetRect)
       
   103     {
       
   104     // cancel outstanding request
       
   105     Cancel();
       
   106     
       
   107     if (!iResultBitmap || iResultBitmap->SizeInPixels() != aTargetRect.Size())
       
   108         {        
       
   109         DeleteResultBitmap();
       
   110         // create target bitmap
       
   111         iResultBitmap = new (ELeave) CFbsBitmap();
       
   112         User::LeaveIfError(iResultBitmap->Create(aTargetRect.Size(),aSource.DisplayMode()));              
       
   113         }   
       
   114     // start scaling, async        
       
   115     iTargetRect = aTargetRect;
       
   116     iScaler->Scale(&iStatus, aSource, *iResultBitmap, EFalse);
       
   117     
       
   118     SetActive();     
       
   119     }    
       
   120 
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMinimap::DeleteResultBitmap
       
   124 // 
       
   125 // 
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CMinimapScaler::DeleteResultBitmap()
       
   129     {
       
   130     delete iResultBitmap;    
       
   131     iResultBitmap = 0;
       
   132     }
       
   133         
       
   134         
       
   135 // -----------------------------------------------------------------------------
       
   136 // CMinimap::DoCancel
       
   137 // 
       
   138 // 
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CMinimapScaler::DoCancel()
       
   142     {
       
   143     iScaler->Cancel();
       
   144     DeleteResultBitmap();
       
   145     }
       
   146     
       
   147     
       
   148 // -----------------------------------------------------------------------------
       
   149 // CMinimap::RunL
       
   150 // 
       
   151 // 
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CMinimapScaler::RunL()
       
   155     {
       
   156     iCallback->ScalingCompletedL(*iResultBitmap, iTargetRect);
       
   157     // if the callback called StartScalingL(), we must not delete the bitmap
       
   158     if (!IsActive())
       
   159         {
       
   160         DeleteResultBitmap();
       
   161         }
       
   162     }    
       
   163 
       
   164 
       
   165 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   166 
       
   167 
       
   168 //  End of File