vtuis/videotelui/src/CVtUiZoomControl.cpp
branchRCL_3
changeset 35 779871d1e4f4
equal deleted inserted replaced
34:f15ac8e65a02 35:779871d1e4f4
       
     1 /*
       
     2 * Copyright (c) 2004, 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 "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:  Implementation of the CVtUiZoomControl control class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CVtUiZoomControl.h"
       
    22 #include    "VtUiLayout.h"
       
    23 #include    <AknsUtils.h>
       
    24 #include    <AknsDrawUtils.h>
       
    25 #include    "videotelui.hrh"
       
    26 
       
    27 #include    <cvtlogger.h>
       
    28 // CONSTANTS
       
    29 
       
    30 // Maximum amount of steps.
       
    31 const TInt KVtUiZoomControlMaxSteps = 11;
       
    32 
       
    33 // Minimum amount of steps.
       
    34 const TInt KVtUiZoomControlMinSteps = 1;
       
    35 
       
    36 // Fixed point position.
       
    37 const TInt KVtUiZoomControlFixed = 16;
       
    38 
       
    39 // Fixed point number, corresponds to one.
       
    40 const TInt KVtUiZoomControlOne = ( 1 << KVtUiZoomControlFixed );
       
    41 
       
    42 // Amount of partial bits. It is expected that 
       
    43 // KVtUiZoomControlFixed >= KVtUiZoomControlPartial.
       
    44 const TInt KVtUiZoomControlPartial = 8;
       
    45 
       
    46 // Maximum duration of zooming from minimum to maximum, in microseconds.
       
    47 const TInt KVtUiZoomDurationMax = 2000000;
       
    48 
       
    49 // Maximum duration to increase zoom step by one, in microseconds.
       
    50 const TInt KVtUiZoomStepDurationMax = 200000;
       
    51 
       
    52 // Index of transparent color.
       
    53 const TInt KVtUiZoomTransparent = 0;
       
    54 
       
    55 // MODULE DATA STRUCTURES
       
    56 
       
    57 /**
       
    58 * Inner class to hold everything related to one bitmap.
       
    59 * @since Series 60 2.6
       
    60 */
       
    61 class CVtUiZoomControl::CBitmap
       
    62     : public CBase
       
    63     {
       
    64     public: // Constructors and destructors.
       
    65 
       
    66         /**
       
    67         * Constructor.
       
    68         */
       
    69         CBitmap();
       
    70 
       
    71         /**
       
    72         * Symbian OS constructor.
       
    73         * @param aSize size of the bitmap.
       
    74         * @param aMode display mode of the bitmap.
       
    75         */
       
    76         void ConstructL( 
       
    77             const TSize& aSize,
       
    78             const TDisplayMode aMode );
       
    79 
       
    80         /**
       
    81         * Destructor.
       
    82         */
       
    83         ~CBitmap();
       
    84 
       
    85     public:
       
    86 
       
    87         /**
       
    88         * Returns bitmap.
       
    89         * @return bitmap, ownership not passed.
       
    90         */
       
    91         inline CFbsBitmap* Bitmap() const;
       
    92 
       
    93         /**
       
    94         * Returns bitmap context.
       
    95         * @return bitmap context, ownership not passed.
       
    96         */
       
    97         inline CFbsBitGc* Context() const;
       
    98 
       
    99     private:
       
   100 
       
   101         // Owned bitmap.
       
   102         CFbsBitmap* iBitmap;
       
   103 
       
   104         // Owned device.
       
   105         CFbsBitmapDevice* iDevice;
       
   106 
       
   107         // Owned context.
       
   108         CFbsBitGc* iContext;
       
   109 
       
   110     };
       
   111 
       
   112 // ============================ MEMBER FUNCTIONS ===============================
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CVtUiZoomControl::CVtUiZoomControl
       
   116 // C++ constructor can NOT contain any code, that
       
   117 // might leave.
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 CVtUiZoomControl::CVtUiZoomControl( CVtUiBitmapManager& aBitmapManager )
       
   121     : iBitmapManager( aBitmapManager )
       
   122     {
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CVtUiZoomControl::ConstructL
       
   127 // Symbian 2nd phase constructor.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CVtUiZoomControl::ConstructL()
       
   131     {
       
   132     iZoomDirId = 
       
   133         iBitmapManager.AddBitmapsL( 
       
   134             EVtUiBitmap_qgn_indi_zoom_dir, 
       
   135             EVtUiBitmap_qgn_indi_zoom_dir_mask,
       
   136             ETrue );
       
   137     iZoomAreaId =
       
   138         iBitmapManager.AddBitmapL( EVtUiBitmap_qgn_graf_zoom_area, EFalse );
       
   139     iBitmapManager.SetAspectRatio( iZoomAreaId, EFalse );
       
   140 
       
   141     iZoomMinId =
       
   142         iBitmapManager.AddBitmapL( EVtUiBitmap_qgn_indi_zoom_min, EFalse );
       
   143     iBitmapManager.SetAspectRatio( iZoomMinId, EFalse );
       
   144 
       
   145     iZoomMaxId =
       
   146         iBitmapManager.AddBitmapL( EVtUiBitmap_qgn_indi_zoom_max, EFalse );
       
   147     iBitmapManager.SetAspectRatio( iZoomMaxId, EFalse );
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CVtUiZoomControl::~CVtUiZoomControl
       
   152 // Destructor.
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 CVtUiZoomControl::~CVtUiZoomControl()
       
   156     {
       
   157     AknsUtils::DeregisterControlPosition( this );
       
   158 
       
   159     iBitmapManager.RemoveBitmap( iZoomDirId );
       
   160     iBitmapManager.RemoveBitmap( iZoomAreaId );
       
   161     iBitmapManager.RemoveBitmap( iZoomMinId );
       
   162     iBitmapManager.RemoveBitmap( iZoomMaxId );
       
   163 
       
   164     delete iZoomPartialMask;
       
   165     delete iZoomPartialShade;
       
   166     delete iZoomPartialShadeMask;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CVtUiZoomControl::SetZoomParams
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CVtUiZoomControl::SetZoomParams( 
       
   174         const TInt aStepCount, 
       
   175         const TInt aCurrentStep )
       
   176     {
       
   177     iCurrentZoomStep = aCurrentStep;
       
   178     iMaxZoomStep = aStepCount;
       
   179     if ( iMaxZoomStep < 0 )
       
   180         {
       
   181         iMaxZoomStep = 0;
       
   182         }
       
   183     iCurrentZoomStep = Max( Min( iCurrentZoomStep, iMaxZoomStep ), 0 );
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CVtUiZoomControl::CommitL
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CVtUiZoomControl::CommitL()
       
   191     {
       
   192     ReportEventL( MCoeControlObserver::EEventStateChanged );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CVtUiZoomControl::IsZoomEnabled
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 TBool CVtUiZoomControl::IsZoomEnabled() const
       
   200     {
       
   201     return ( iMaxZoomStep > 0 );
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CVtUiZoomControl::GetZoomParams
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void CVtUiZoomControl::GetZoomParams(
       
   209         TInt& aStepCount,
       
   210         TInt& aCurrentStep ) const
       
   211     {
       
   212     aStepCount = iMaxZoomStep;
       
   213     aCurrentStep = iCurrentZoomStep;
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CVtUiZoomControl::UpdateZoomL
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 TBool CVtUiZoomControl::UpdateZoomL()
       
   221     {
       
   222     const TInt oldZoomStep = iCurrentZoomStep;
       
   223     if ( iZoomDirection )
       
   224         {
       
   225         __VTPRINT( DEBUG_GEN, "VtUiZmCtl.UpdZoom" )
       
   226         TTime timeNow;
       
   227         timeNow.UniversalTime();
       
   228 
       
   229         const TTimeIntervalMicroSeconds duration = 
       
   230             timeNow.MicroSecondsFrom( iZoomStartTime );
       
   231 
       
   232         if ( duration >= TInt64( KVtUiZoomDurationMax ) )
       
   233             {
       
   234             // Duration is over maximum, so we can stop zooming.
       
   235             if ( iZoomDirection > 0 )
       
   236                 {
       
   237                 iCurrentZoomStep = iMaxZoomStep;
       
   238                 }
       
   239             else
       
   240                 {
       
   241                 iCurrentZoomStep = 0;
       
   242                 }
       
   243 
       
   244             iZoomDirection = 0;
       
   245             }
       
   246         else if ( duration < TInt64( 0 ) )
       
   247             {
       
   248             // Clock has been changed. Stop zooming.
       
   249             iZoomDirection = 0;
       
   250             }
       
   251         else
       
   252             {
       
   253             // Zoom is increased at least by one step per 0.2 seconds.
       
   254             TInt64 minimum( duration.Int64() );
       
   255             minimum /= KVtUiZoomStepDurationMax;
       
   256 
       
   257             // Zoom is increased from minimum to maximum in 2 seconds.
       
   258             TInt64 maximum( duration.Int64() );
       
   259             maximum *= iMaxZoomStep;
       
   260             maximum /= KVtUiZoomDurationMax;
       
   261 
       
   262             // Select maximum.
       
   263             TInt zoomStepDelta = 
       
   264                 iZoomDirection * Max( I64INT( minimum ), I64INT( maximum ) );
       
   265             TInt zoomStep = iZoomStepStart + zoomStepDelta;
       
   266 
       
   267             // If minimum has been reached, zooming can be stopped.
       
   268             if ( zoomStep < 0 )
       
   269                 {
       
   270                 zoomStep = 0;
       
   271                 iZoomDirection = 0;
       
   272                 }
       
   273             // If maximum has been reached, zooming can be stopped.
       
   274             if ( zoomStep > iMaxZoomStep )
       
   275                 {
       
   276                 zoomStep = iMaxZoomStep;
       
   277                 iZoomDirection = 0;
       
   278                 }
       
   279 
       
   280             iCurrentZoomStep = zoomStep;
       
   281             }
       
   282         __VTPRINT( DEBUG_GEN, "VtUiZmCtl.chk" )
       
   283         }
       
   284 
       
   285     const TBool updateNeeded = ( oldZoomStep != iCurrentZoomStep );
       
   286     if ( updateNeeded )
       
   287         {
       
   288         __VTPRINT( DEBUG_GEN, "VtUiZmCtl.upd" )
       
   289         ReportEventL( MCoeControlObserver::EEventStateChanged );
       
   290         }
       
   291 
       
   292     return updateNeeded;
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // CVtUiZoomControl::StopZoom
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 void CVtUiZoomControl::StopZoom()
       
   300     {
       
   301     iZoomDirection = 0;
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CVtUiZoomControl::OfferKeyEventL
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 TKeyResponse CVtUiZoomControl::OfferKeyEventL(
       
   309         const TKeyEvent& aKeyEvent,
       
   310         TEventCode aType )
       
   311     {
       
   312     TKeyResponse response = EKeyWasNotConsumed;
       
   313 
       
   314     if ( aKeyEvent.iScanCode == EStdKeyUpArrow ||
       
   315          aKeyEvent.iScanCode == EStdKeyDownArrow ||
       
   316          aKeyEvent.iCode == EKeyZoomIn ||
       
   317          aKeyEvent.iCode == EKeyZoomOut )
       
   318         {
       
   319         switch ( aType )
       
   320             {
       
   321             case EEventKey:
       
   322                 {
       
   323                 TInt direction = +1;
       
   324                 if ( aKeyEvent.iScanCode == EStdKeyDownArrow ||
       
   325                     aKeyEvent.iCode == EKeyZoomOut )
       
   326                     {
       
   327                     direction = -1;
       
   328                     }
       
   329         
       
   330                 if ( !aKeyEvent.iRepeats )
       
   331                     {
       
   332                     // Update start parameters.
       
   333                     iZoomDirection = direction;
       
   334                     iZoomStepStart = iCurrentZoomStep + direction;
       
   335                     iZoomStepStart = Min( iZoomStepStart, iMaxZoomStep );
       
   336                     iZoomStepStart = Max( iZoomStepStart, 0 );
       
   337                     iZoomStartTime.UniversalTime();
       
   338                     }
       
   339                 
       
   340                 (void)UpdateZoomL();
       
   341                 }
       
   342                 break;
       
   343 
       
   344             case EEventKeyUp:
       
   345                 // Stop zooming.
       
   346                 iZoomDirection = 0;
       
   347                 break;
       
   348 
       
   349             default:
       
   350                 // Do nothing.
       
   351                 break;
       
   352             }
       
   353 
       
   354         response = EKeyWasConsumed;
       
   355         }
       
   356 
       
   357     return response;
       
   358     }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CVtUiZoomControl::HandleResourceChange
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 void CVtUiZoomControl::HandleResourceChange(
       
   365         TInt aType )
       
   366     {
       
   367     if ( aType == KAknsMessageSkinChange ) 
       
   368         {
       
   369         // We must refresh partial bitmap upon next redraw.
       
   370         iZoomMaskPartial = KErrNotFound;
       
   371         iZoomMaskRow = KErrNotFound;
       
   372         }
       
   373 
       
   374     CCoeControl::HandleResourceChange( aType );
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CVtUiZoomControl::Draw
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 void CVtUiZoomControl::Draw( const TRect& /*aRect*/ ) const
       
   382     {   
       
   383     __VTPRINT( DEBUG_GEN, "VtUiZmCtl.Draw" )   
       
   384     iBitmapManager.SetSizeAndColor( 
       
   385         iZoomDirId, 
       
   386         iZoomDirLayout.Rect().Size(),
       
   387         iZoomDirLayout.Color() );
       
   388     iBitmapManager.SetSize( 
       
   389         iZoomAreaId, 
       
   390         iZoomAreaLayout.Rect().Size() );
       
   391     iBitmapManager.SetSize( 
       
   392         iZoomMinId, 
       
   393         iZoomAreaLayout.Rect().Size() );
       
   394     iBitmapManager.SetSize( 
       
   395         iZoomMaxId, 
       
   396         iZoomAreaLayout.Rect().Size() );
       
   397 
       
   398     CFbsBitmap* maxBitmap = NULL;
       
   399     CFbsBitmap* minBitmap = NULL;
       
   400     CFbsBitmap* areaBitmap = NULL;
       
   401     iBitmapManager.GetBitmap( iZoomMaxId, maxBitmap );
       
   402     iBitmapManager.GetBitmap( iZoomMinId, minBitmap );
       
   403     iBitmapManager.GetBitmap( iZoomAreaId, areaBitmap );
       
   404 
       
   405     TInt full;
       
   406     TInt partial;
       
   407     TRect drawRect;
       
   408     TPoint drawPos;
       
   409 
       
   410     DetermineSteps( full, partial );
       
   411     if ( areaBitmap && partial && ( full < KVtUiZoomControlMaxSteps ) )
       
   412         {
       
   413         // First generate bitmaps, so that drawing can be done 
       
   414         // quickly in sequence.
       
   415         GetPositionAndRect( 
       
   416             drawPos,
       
   417             drawRect,
       
   418             full + 1 );
       
   419 
       
   420         if ( !GenerateZoomMaskBitmap( 
       
   421                 areaBitmap, 
       
   422                 partial, 
       
   423                 drawRect.iTl.iY,
       
   424                 drawRect.Size() ) )
       
   425             {
       
   426             // If zoom mask generation fails, then we have no choice
       
   427             // than not to draw.
       
   428             partial = 0; 
       
   429             }
       
   430         }
       
   431 
       
   432     CWindowGc& gc = SystemGc();
       
   433     gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   434 
       
   435     // Draw zoom direction indicator:
       
   436 
       
   437     CFbsBitmap* zoomDirBitmap = NULL;
       
   438     CFbsBitmap* zoomDirMask = NULL;
       
   439     iBitmapManager.GetBitmaps( iZoomDirId, zoomDirBitmap, zoomDirMask );
       
   440     if ( zoomDirBitmap && zoomDirMask )
       
   441         {
       
   442         iZoomDirLayout.DrawImage( gc, zoomDirBitmap, zoomDirMask );
       
   443         }
       
   444     
       
   445     // Draw zoom indicator:
       
   446     if ( !areaBitmap )
       
   447         {
       
   448         // If area bitmap is invalid, then we have to return.
       
   449         return;
       
   450         }
       
   451 
       
   452     if ( maxBitmap )
       
   453         {
       
   454         // First, draw maximum area.
       
   455         for ( TInt index = KVtUiZoomControlMinSteps; 
       
   456               index <= full; 
       
   457               index++ )
       
   458             {
       
   459             GetPositionAndRect( 
       
   460                 drawPos, 
       
   461                 drawRect, 
       
   462                 index );
       
   463             gc.BitBltMasked( 
       
   464                 drawPos,
       
   465                 maxBitmap, 
       
   466                 drawRect, 
       
   467                 areaBitmap, 
       
   468                 ETrue );
       
   469             }
       
   470         }
       
   471 
       
   472     if ( minBitmap && ( full < KVtUiZoomControlMaxSteps ) )
       
   473         {
       
   474         // Then draw minimum area.
       
   475         for ( TInt index = full + 1; 
       
   476               index <= KVtUiZoomControlMaxSteps; 
       
   477               index++ )
       
   478             {
       
   479             GetPositionAndRect( 
       
   480                 drawPos, 
       
   481                 drawRect, 
       
   482                 index );
       
   483             gc.BitBltMasked( 
       
   484                 drawPos, 
       
   485                 minBitmap, 
       
   486                 drawRect, 
       
   487                 areaBitmap, 
       
   488                 ETrue );
       
   489             }
       
   490 
       
   491         if ( maxBitmap && partial && iZoomPartialMask )
       
   492             {
       
   493             // Finally draw partial area.
       
   494             GetPositionAndRect( 
       
   495                 drawPos,
       
   496                 drawRect,
       
   497                 full + 1 );
       
   498             gc.BitBltMasked( 
       
   499                 drawPos,
       
   500                 maxBitmap,
       
   501                 drawRect, 
       
   502                 iZoomPartialMask->Bitmap(),
       
   503                 ETrue );
       
   504             }
       
   505         }
       
   506     
       
   507     __VTPRINT( DEBUG_GEN, "VtUiZmCtl.Draw.ok" )
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CVtUiZoomControl::SizeChanged
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 void CVtUiZoomControl::SizeChanged()
       
   515     {
       
   516     AknsUtils::RegisterControlPosition( this );
       
   517 
       
   518     TRect parent( Rect() );
       
   519     TAknWindowLineLayout rect;
       
   520     if ( parent.IsEmpty() )
       
   521         {
       
   522         return;
       
   523         }
       
   524 
       
   525         {
       
   526         TAknLayoutRect& tmpRect = iZoomDirLayout; 
       
   527         VtUiLayout::GetZoomPaneLayout( rect );
       
   528         tmpRect.LayoutRect( parent, rect );
       
   529         parent = tmpRect.Rect();
       
   530         iZoomPaneRect = parent;
       
   531         }
       
   532 
       
   533     VtUiLayout::GetZoomDirLayout( rect );
       
   534     iZoomDirLayout.LayoutRect( parent, rect );
       
   535     iBitmapManager.SetSizeAndColor( 
       
   536         iZoomDirId, 
       
   537         iZoomDirLayout.Rect().Size(),
       
   538         iZoomDirLayout.Color() );
       
   539 
       
   540     VtUiLayout::GetZoomAreaLayout( rect );
       
   541     iZoomAreaLayout.LayoutRect( parent, rect );
       
   542     iBitmapManager.SetSize( 
       
   543         iZoomAreaId, 
       
   544         iZoomAreaLayout.Rect().Size() );
       
   545     iBitmapManager.SetSize( 
       
   546         iZoomMinId, 
       
   547         iZoomAreaLayout.Rect().Size() );
       
   548     iBitmapManager.SetSize( 
       
   549         iZoomMaxId, 
       
   550         iZoomAreaLayout.Rect().Size() );
       
   551     (void) CreateBitmaps();
       
   552     }
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // CVtUiZoomControl::PositionChanged
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 void CVtUiZoomControl::PositionChanged()
       
   559     {
       
   560     AknsUtils::RegisterControlPosition( this );
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CVtUiZoomControl::DetermineSteps
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CVtUiZoomControl::DetermineSteps(
       
   568         TInt& aFullSteps,
       
   569         TInt& aPartialStep ) const
       
   570     {
       
   571     aFullSteps = 1;
       
   572     aPartialStep = 0;
       
   573 
       
   574     TInt currentZoomStep = Max( Min( iCurrentZoomStep, iMaxZoomStep ), 0 );
       
   575 
       
   576     if ( iMaxZoomStep > 0 )
       
   577         {
       
   578         TInt zoomDeltaSteps = 0;
       
   579         TInt zoomDeltaMaxSteps = 0;
       
   580 
       
   581         // Formula equals: x = ( N * ( y - 1 ) ) / 10.
       
   582         
       
   583         aFullSteps = KVtUiZoomControlMinSteps;
       
   584         const TInt divider = 
       
   585             KVtUiZoomControlMaxSteps - KVtUiZoomControlMinSteps;
       
   586         for ( TInt row = KVtUiZoomControlMaxSteps - 1; 
       
   587               row >= KVtUiZoomControlMinSteps - 1;
       
   588               row-- )
       
   589             {
       
   590             const TInt zoomStartSteps = 
       
   591                 ( iMaxZoomStep * row ) / divider;
       
   592             const TInt previousZoomStartSteps = 
       
   593                 ( iMaxZoomStep * ( row - 1 ) ) / divider;
       
   594 
       
   595             if ( ( currentZoomStep >= zoomStartSteps ) &&
       
   596                  ( previousZoomStartSteps != zoomStartSteps ) )
       
   597                 {
       
   598                 aFullSteps = ( row + 1 );
       
   599                 zoomDeltaSteps = currentZoomStep - zoomStartSteps;
       
   600                 zoomDeltaMaxSteps = ( iMaxZoomStep * ( row + 1 ) ) / divider;
       
   601                 zoomDeltaMaxSteps -= zoomStartSteps;
       
   602                 break;
       
   603                 }
       
   604             }
       
   605 
       
   606         aPartialStep = 0;
       
   607         if ( zoomDeltaSteps && zoomDeltaMaxSteps )
       
   608             {
       
   609             TInt64 partial( zoomDeltaSteps );
       
   610             partial *= KVtUiZoomControlOne;
       
   611             partial /= zoomDeltaMaxSteps;
       
   612             
       
   613             partial >>= ( KVtUiZoomControlFixed - KVtUiZoomControlPartial );
       
   614             aPartialStep = I64INT( partial );
       
   615             }
       
   616         }
       
   617     }
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // CVtUiZoomControl::GenerateZoomMaskBitmap
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 TBool CVtUiZoomControl::GenerateZoomMaskBitmap(
       
   624         CFbsBitmap* aMaskBitmap,    
       
   625         const TInt aPartial,
       
   626         const TInt aRow,
       
   627         const TSize& aRowSize ) const
       
   628     {
       
   629     if ( iZoomPartialMask && 
       
   630          ( ( iZoomMaskPartial != aPartial ) || 
       
   631            ( iZoomMaskRow != aRow ) ) )
       
   632         {
       
   633         DoGenerateZoomMaskBitmap( 
       
   634             aMaskBitmap,
       
   635             aPartial, 
       
   636             aRow,
       
   637             aRowSize );
       
   638         }
       
   639     return ( iZoomPartialMask != NULL );
       
   640     }
       
   641 
       
   642 // -----------------------------------------------------------------------------
       
   643 // CVtUiZoomControl::DoGenerateZoomMaskBitmap
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 void CVtUiZoomControl::DoGenerateZoomMaskBitmap(
       
   647         CFbsBitmap* aMaskBitmap,
       
   648         const TInt aPartial,
       
   649         const TInt aRow,
       
   650         const TSize& aRowSize ) const
       
   651     {
       
   652     CFbsBitGc* bitmapMaskGc = iZoomPartialMask->Context();
       
   653     
       
   654     CFbsBitmap* shade = iZoomPartialShade->Bitmap();
       
   655     CFbsBitGc* shadeGc = iZoomPartialShade->Context();
       
   656 
       
   657     // Fill shade with aPartial.
       
   658     shadeGc->SetPenStyle( CGraphicsContext::ENullPen );
       
   659     shadeGc->SetBrushColor( TRgb::Gray256( aPartial ) );
       
   660     shadeGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   661     shadeGc->Clear(); 
       
   662     
       
   663     // Now grab one row from iZoomAreaBitmap.
       
   664     CFbsBitmap* mask = iZoomPartialShadeMask->Bitmap();
       
   665     CFbsBitGc* maskGc = iZoomPartialShadeMask->Context();
       
   666 
       
   667     // Clear with transparency.
       
   668     maskGc->SetPenStyle( CGraphicsContext::ENullPen );
       
   669     maskGc->SetBrushColor( TRgb::Gray2( 1 ) ); // transparency
       
   670     maskGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   671     maskGc->Clear(); 
       
   672 
       
   673     maskGc->SetPenStyle( CGraphicsContext::ENullPen );
       
   674     // Blit appropriate region from aMaskBitmap to maskGc.
       
   675     maskGc->BitBlt( 
       
   676         TPoint( 0, aRow ), 
       
   677         aMaskBitmap, 
       
   678         TRect( TPoint( 0, aRow ), aRowSize ) );
       
   679 
       
   680     // Now fill bitmapMask with black (= transparency).
       
   681     bitmapMaskGc->SetPenStyle( CGraphicsContext::ENullPen );
       
   682     bitmapMaskGc->SetBrushColor( TRgb::Gray256( KVtUiZoomTransparent ) );
       
   683     bitmapMaskGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   684     bitmapMaskGc->Clear();
       
   685 
       
   686     // Then blit shade masked
       
   687     TPoint origin;
       
   688     TRect rect( origin, shade->SizeInPixels() );
       
   689 
       
   690     bitmapMaskGc->BitBltMasked( origin, shade, rect, mask, ETrue );
       
   691 
       
   692     iZoomMaskPartial = aPartial;
       
   693     iZoomMaskRow = aRow;
       
   694     }
       
   695 
       
   696 // -----------------------------------------------------------------------------
       
   697 // CVtUiZoomControl::CreateBitmaps
       
   698 // -----------------------------------------------------------------------------
       
   699 //
       
   700 TInt CVtUiZoomControl::CreateBitmaps()
       
   701     {
       
   702     TRAPD( err, CreateBitmapsL() );
       
   703     return err;
       
   704     }
       
   705 
       
   706 // -----------------------------------------------------------------------------
       
   707 // CVtUiZoomControl::CreateBitmapsL
       
   708 // -----------------------------------------------------------------------------
       
   709 //
       
   710 void CVtUiZoomControl::CreateBitmapsL()
       
   711     {
       
   712     TBool requiredToCreate = ETrue;
       
   713     TSize requiredSize = SizeOfBitmap();
       
   714     if ( iZoomPartialMask )
       
   715         {
       
   716         requiredToCreate = 
       
   717             ( requiredSize != iZoomPartialMask->Bitmap()->SizeInPixels() );
       
   718         }
       
   719 
       
   720     if ( requiredToCreate )
       
   721         {
       
   722         iZoomMaskPartial = KErrNotFound;
       
   723         iZoomMaskRow = KErrNotFound;
       
   724 
       
   725         // Delete old ones away.
       
   726         delete iZoomPartialMask;
       
   727         iZoomPartialMask = NULL;
       
   728 
       
   729         delete iZoomPartialShade;
       
   730         iZoomPartialShade = NULL;
       
   731 
       
   732         delete iZoomPartialShadeMask;
       
   733         iZoomPartialShadeMask = NULL;
       
   734 
       
   735         CBitmap* zoomPartialMask = new ( ELeave ) CBitmap;
       
   736         CleanupStack::PushL( zoomPartialMask );
       
   737         zoomPartialMask->ConstructL( requiredSize, EGray256 );
       
   738 
       
   739         CBitmap* zoomPartialShade = new ( ELeave ) CBitmap;
       
   740         CleanupStack::PushL( zoomPartialShade );
       
   741         zoomPartialShade->ConstructL( requiredSize, EGray256 );
       
   742 
       
   743         CBitmap* zoomPartialShadeMask = new ( ELeave ) CBitmap;
       
   744         CleanupStack::PushL( zoomPartialShadeMask );
       
   745         zoomPartialShadeMask->ConstructL( requiredSize, EGray2 );
       
   746     
       
   747         // Pop zoomPartialShadeMask, zoomPartialShade & zoomPartialMask.
       
   748         CleanupStack::Pop( 3, zoomPartialMask ); 
       
   749         iZoomPartialMask = zoomPartialMask;
       
   750         iZoomPartialShade = zoomPartialShade;
       
   751         iZoomPartialShadeMask = zoomPartialShadeMask;
       
   752         }
       
   753     }
       
   754 
       
   755 // -----------------------------------------------------------------------------
       
   756 // CVtUiZoomControl::SizeOfBitmap
       
   757 // -----------------------------------------------------------------------------
       
   758 //
       
   759 TSize CVtUiZoomControl::SizeOfBitmap() const
       
   760     {
       
   761     // Bitmaps fill the whole zoom area.
       
   762     return iZoomAreaLayout.Rect().Size();
       
   763     }
       
   764 
       
   765 // -----------------------------------------------------------------------------
       
   766 // CVtUiZoomControl::GetPositionAndRect
       
   767 // -----------------------------------------------------------------------------
       
   768 //
       
   769 void CVtUiZoomControl::GetPositionAndRect(
       
   770         TPoint& aPosition,
       
   771         TRect& aSourceRect,
       
   772         const TInt aZoomStep ) const
       
   773     {
       
   774     TAknWindowLineLayout rect;
       
   775     TAknLayoutRect layout;
       
   776     const TRect zoomAreaRect = iZoomAreaLayout.Rect();
       
   777     const TRect& zoomParentRect = iZoomPaneRect;
       
   778 
       
   779     VtUiLayout::GetZoomStepLayout( 
       
   780         rect, 
       
   781         aZoomStep ); 
       
   782     layout.LayoutRect( zoomParentRect, rect );
       
   783     aSourceRect = layout.Rect();
       
   784     aPosition = aSourceRect.iTl;
       
   785 
       
   786     aSourceRect.iTl -= zoomAreaRect.iTl;
       
   787     aSourceRect.iBr -= zoomAreaRect.iTl;
       
   788     }
       
   789 
       
   790 // -----------------------------------------------------------------------------
       
   791 // CVtUiZoomControl::CBitmap::CBitmap
       
   792 // -----------------------------------------------------------------------------
       
   793 //
       
   794 CVtUiZoomControl::CBitmap::CBitmap()
       
   795     {
       
   796     }
       
   797 
       
   798 // -----------------------------------------------------------------------------
       
   799 // CVtUiZoomControl::CBitmap::ConstructL
       
   800 // -----------------------------------------------------------------------------
       
   801 //
       
   802 void CVtUiZoomControl::CBitmap::ConstructL( 
       
   803         const TSize& aSize,
       
   804         const TDisplayMode aMode )
       
   805     {
       
   806     CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap;
       
   807     CleanupStack::PushL( bitmap );
       
   808 
       
   809     User::LeaveIfError(
       
   810         bitmap->Create( aSize, aMode ) );
       
   811 
       
   812     CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( bitmap );
       
   813     CleanupStack::PushL( device );
       
   814 
       
   815     CFbsBitGc* context = NULL;
       
   816     User::LeaveIfError( device->CreateContext( context ) );
       
   817     User::LeaveIfNull( context );
       
   818 
       
   819     CleanupStack::Pop( device );
       
   820     CleanupStack::Pop( bitmap );
       
   821 
       
   822     iContext = context;
       
   823     iDevice = device;
       
   824     iBitmap = bitmap;
       
   825     }
       
   826 
       
   827 // -----------------------------------------------------------------------------
       
   828 // CVtUiZoomControl::CBitmap::~CBitmap
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 CVtUiZoomControl::CBitmap::~CBitmap()
       
   832     {
       
   833     delete iContext;
       
   834     delete iDevice;
       
   835     delete iBitmap;
       
   836     }
       
   837 
       
   838 // -----------------------------------------------------------------------------
       
   839 // CVtUiZoomControl::CBitmap::Bitmap
       
   840 // -----------------------------------------------------------------------------
       
   841 //
       
   842 inline CFbsBitmap* CVtUiZoomControl::CBitmap::Bitmap() const
       
   843     {
       
   844     return iBitmap;
       
   845     }
       
   846 
       
   847 // -----------------------------------------------------------------------------
       
   848 // CVtUiZoomControl::CBitmap::Context
       
   849 // -----------------------------------------------------------------------------
       
   850 //
       
   851 inline CFbsBitGc* CVtUiZoomControl::CBitmap::Context() const
       
   852     {
       
   853     return iContext;
       
   854     }
       
   855 
       
   856 //  End of File