imageeditor/ImageEditorUI/src/WaitIndicator.cpp
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "WaitIndicator.h"
       
    21 #include <ImageEditorUI.mbg>
       
    22 
       
    23 #include <fbs.h>
       
    24 #include <w32std.h>
       
    25 
       
    26 #include <AknIconUtils.h>
       
    27 #include <data_caging_path_literals.hrh>
       
    28 #include <aknlayoutscalable_apps.cdl.h>
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CWaitIndicator::CWaitIndicator()
       
    32 // C++ constructor can NOT contain any code, that might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CWaitIndicator::CWaitIndicator()
       
    36 :CTimer( EPriorityStandard )
       
    37     {
       
    38     CActiveScheduler::Add( this );
       
    39 	}
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CWaitIndicator::NewL
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CWaitIndicator* CWaitIndicator::NewL()
       
    47 	{
       
    48     CWaitIndicator* self = new( ELeave ) CWaitIndicator();
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop( self );
       
    52     return self;
       
    53 	}
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CWaitIndicator::ConstructL
       
    57 // Symbian two phased constructor may leave
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CWaitIndicator::ConstructL()
       
    61     {
       
    62     CTimer::ConstructL();
       
    63 
       
    64     // Bitmap file name and drive letter.
       
    65     // Path is generated using PathInfo.
       
    66     _LIT( KMbmDrive, "z:" );
       
    67     _LIT( KMbmFileName, "ImageEditorUI.mbm" );
       
    68 
       
    69     // Waitnote bitmap count
       
    70     const TInt KWaitnoteBitmapCount = 10;
       
    71 
       
    72 	TFileName mbmPath;
       
    73 	mbmPath.Copy( KMbmDrive );
       
    74 	mbmPath.Append( KDC_APP_BITMAP_DIR );
       
    75 	mbmPath.Append( KMbmFileName );
       
    76 
       
    77 	for ( TInt i = 0; i < KWaitnoteBitmapCount; ++i )
       
    78 		{
       
    79 		CFbsBitmap* bitmap;
       
    80 		CFbsBitmap* mask;
       
    81 
       
    82 		// *2 for bitmap and mask
       
    83 		AknIconUtils::CreateIconL( bitmap, mask, mbmPath,
       
    84 						EMbmImageeditoruiQgn_graf_ring_wait_01 + i * 2,
       
    85 						EMbmImageeditoruiQgn_graf_ring_wait_01_mask + i * 2 );
       
    86 
       
    87         TInt err = iBitmaps.Append( bitmap );
       
    88 		if( err )
       
    89 		    {
       
    90 		    delete bitmap;
       
    91 		    delete mask;
       
    92 		    }
       
    93         else
       
    94             {
       
    95             err = iBitmaps.Append( mask );
       
    96             if( err )
       
    97                 {
       
    98 		        delete mask;
       
    99                 }            
       
   100             }
       
   101 	    User::LeaveIfError( err );
       
   102 		}
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // Destructor
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 CWaitIndicator::~CWaitIndicator()
       
   110     {
       
   111     Cancel();
       
   112     iBitmaps.ResetAndDestroy();
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CWaitIndicator::
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TBool CWaitIndicator::IsVisible()
       
   120     {
       
   121     return IsActive();
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CWaitIndicator::
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CWaitIndicator::Show()
       
   129     {
       
   130 	// From LAF
       
   131 	TTimeIntervalMicroSeconds32 KWaitNoteDelay = TTimeIntervalMicroSeconds32( 1000*100 );
       
   132     
       
   133     if( !IsActive() )
       
   134         {
       
   135         // Start timer if not already
       
   136         After( KWaitNoteDelay );
       
   137         }
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CWaitIndicator::
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CWaitIndicator::Hide()
       
   145     {
       
   146     // Stop waitnote
       
   147     Cancel();
       
   148 
       
   149     // Request draw event
       
   150     DrawNow();
       
   151     }
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // CWaitIndicator::RunL
       
   155 // ----------------------------------------------------------------------------
       
   156 //
       
   157 void CWaitIndicator::RunL()
       
   158 	{
       
   159 	// From LAF
       
   160 	TTimeIntervalMicroSeconds32 KWaitNoteInterval = TTimeIntervalMicroSeconds32( 1000*100 );
       
   161 
       
   162     // Waitnote bitmap count
       
   163     const TInt KWaitnoteBitmapCount = 10;
       
   164 
       
   165     // Start timer again
       
   166     After( KWaitNoteInterval );
       
   167 
       
   168 	// Draw next frame
       
   169     ++iIndex;
       
   170     if ( iIndex >= KWaitnoteBitmapCount )
       
   171         {
       
   172         iIndex = 0;
       
   173         }
       
   174     DrawNow();
       
   175 	}
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CWaitIndicator::Draw
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CWaitIndicator::Draw( CWindowGc& aGc ) const
       
   182     {
       
   183     if( IsActive() )
       
   184         {
       
   185         // *2 because masks are in same array
       
   186         CFbsBitmap* bitmap = iBitmaps[iIndex * 2];
       
   187         CFbsBitmap* mask = iBitmaps[iIndex * 2 + 1];
       
   188 
       
   189         TSize bitmapSize( bitmap->SizeInPixels() );
       
   190         TSize rectSize( iRect.Size() );
       
   191         TPoint topLeft( iRect.iTl );
       
   192 
       
   193         // Center the image
       
   194         if( bitmapSize.iWidth < rectSize.iWidth )
       
   195             {
       
   196             topLeft.iX = ( rectSize.iWidth - bitmapSize.iWidth ) / 2;
       
   197             }
       
   198         if( bitmapSize.iHeight < rectSize.iHeight )
       
   199             {
       
   200             topLeft.iY = ( rectSize.iHeight - bitmapSize.iHeight ) / 2;
       
   201             }
       
   202 
       
   203         // Draw wait indicator
       
   204         aGc.BitBltMasked( topLeft, bitmap, TRect( bitmapSize ), mask, EFalse );
       
   205         }
       
   206     }
       
   207     
       
   208 // -----------------------------------------------------------------------------
       
   209 // CWaitIndicator::
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CWaitIndicator::SizeChanged()
       
   213     {
       
   214     // Waitnote bitmap count
       
   215     const TInt KWaitnoteBitmapCount = 10;
       
   216 
       
   217     // From LAF
       
   218 	// Variety 0
       
   219 	TAknWindowLineLayout layout = AknLayoutScalable_Apps::main_image2_pane_g1( 0 );
       
   220     TSize waitNoteSize( layout.iW, layout.iH );
       
   221 	for ( TInt i = 0; i < KWaitnoteBitmapCount; ++i )
       
   222 		{
       
   223         AknIconUtils::SetSize( iBitmaps[i * 2], waitNoteSize );
       
   224 		}
       
   225     }
       
   226     
       
   227 // End of File