mmsharing/mmshindicator/src/musindicatordsa.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     1 /*
       
     2 * Copyright (c) 2007 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:  MusIndicatorApi provides means to show notes and indicate
       
    15 *                availability of videosharing to user.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "musindicatordsa.h"
       
    21 #include "muslogger.h"
       
    22 #include "musresourceutil.h"
       
    23 #include "musresourcefinderutil.h"
       
    24 #include <e32cmn.h>
       
    25 #include <e32std.h>
       
    26 #include <musindicator.rsg>
       
    27 #include <eikenv.h>
       
    28 #include <coefontprovider.h>
       
    29 #include <AknsDrawUtils.h>
       
    30 #include <eikappui.h>
       
    31 #include <musindicatoricons.mbg>
       
    32 #include <AknUtils.h>
       
    33 
       
    34 // constants
       
    35 // Size and positions
       
    36 
       
    37 const TInt KMusIndicatorWindowHeight = 50;
       
    38 const TInt KMusIndicatorWindowShrink = 2;
       
    39 const TInt KMusSpaceBetweenImageAndText = 5;
       
    40 
       
    41 // appereance
       
    42 const TInt KMusIndicatorBorderRoundedCorners = 6;
       
    43 const TInt KMusIndicatorBorderSize = 1;
       
    44 //const TInt KMusIndicatorFontPenSize = 1;
       
    45 
       
    46 
       
    47 
       
    48 
       
    49 CMusIndicatorDsa* CMusIndicatorDsa::NewL()
       
    50     {
       
    51     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::NewL" )
       
    52     CMusIndicatorDsa* self = new (ELeave) CMusIndicatorDsa();
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop( self );
       
    56     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::NewL" )
       
    57     return self;
       
    58     }
       
    59 
       
    60 
       
    61 CMusIndicatorDsa::CMusIndicatorDsa()
       
    62     : iActivateCallBack( CMusIndicatorDsa::TryActivate, this ),
       
    63       iRedrawCallBack( CMusIndicatorDsa::DoHandleResourceChange, this )
       
    64     {
       
    65     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::CMusIndicatorDsa" )
       
    66         
       
    67     iBorderColor = KRgbBlack;
       
    68     iBorderBgColor = KRgbWhite;
       
    69     iFontColor = KRgbBlack;
       
    70     
       
    71     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::CMusIndicatorDsa" )
       
    72     }
       
    73 
       
    74 
       
    75 CMusIndicatorDsa::~CMusIndicatorDsa()
       
    76     {
       
    77     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::~CMusIndicatorDsa" )
       
    78     
       
    79     StopPeriodicTimer();    
       
    80     delete iPeriodic;
       
    81 
       
    82     delete iIcon;
       
    83     delete iIconMask;
       
    84     
       
    85     delete iText;
       
    86     
       
    87     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::~CMusIndicatorDsa" )
       
    88     }
       
    89 
       
    90 
       
    91 const CFont& CMusIndicatorDsa::Font() const
       
    92     {
       
    93     TCoeFont coeFont = TCoeFont::NormalFont();
       
    94     TZoomFactor zoomFactor = AccumulatedZoom();
       
    95     return FindFontProvider().Font(coeFont, zoomFactor);
       
    96     }
       
    97 
       
    98 //------------------------------------------------------------------------------
       
    99 //
       
   100 //------------------------------------------------------------------------------
       
   101 //
       
   102 void CMusIndicatorDsa::ConstructL()
       
   103     {
       
   104     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::ConstructL" )
       
   105 
       
   106     iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
   107     
       
   108     LoadResourceStringL();
       
   109     LoadImageL();
       
   110     CreateWindowL();
       
   111     
       
   112     Initialize();
       
   113     TryActivateL();
       
   114     
       
   115     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::ConstructL" )
       
   116     }
       
   117 
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // 
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CMusIndicatorDsa::TryActivateL()
       
   124     {
       
   125     MAknsControlContext* cc = 
       
   126         AknsDrawUtils::ControlContext( ControlEnv()->AppUi()->TopFocusedControl() );
       
   127 
       
   128     if ( cc )
       
   129         {
       
   130         StopPeriodicTimer();
       
   131         ActivateL();
       
   132         }
       
   133     else
       
   134         {
       
   135         StartPeriodicTimer( iActivateCallBack );
       
   136         }
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // Called by framework to redraw the screen area.
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CMusIndicatorDsa::Draw( const TRect& aRect ) const
       
   145     {
       
   146     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::Draw" )
       
   147     MUS_LOG2( "mus: [MUSIND] : x=%d,y=%d", aRect.iTl.iX, aRect.iTl.iY )
       
   148     MUS_LOG2( "mus: [MUSIND] : x=%d,y=%d", aRect.iBr.iX, aRect.iBr.iY )
       
   149     
       
   150     CWindowGc& gc = SystemGc();
       
   151     
       
   152     TSize screenSizeNow = ControlEnv()->ScreenDevice()->SizeInPixels();
       
   153     
       
   154     if ( screenSizeNow != iScreenSize )
       
   155         {
       
   156         StartPeriodicTimer( iRedrawCallBack );
       
   157         }
       
   158     
       
   159     MAknsControlContext* cc = 
       
   160         AknsDrawUtils::ControlContext( ControlEnv()->AppUi()->TopFocusedControl() );
       
   161     MUS_LOG1( "mus: [MUSIND] : cc = %d", cc )
       
   162 
       
   163     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   164     MUS_LOG1( "mus: [MUSIND] : skin = %d", skin )
       
   165 
       
   166     TRgb fontColor;
       
   167     AknsUtils::GetCachedColor( skin, fontColor, 
       
   168                                KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
       
   169     TRgb borderColor = fontColor;
       
   170     
       
   171     TBool backgroundWithBitmap = 
       
   172                 ( skin && !cc ) ? 
       
   173                  EFalse :
       
   174                  AknsDrawUtils::Background( skin, cc,this,gc,aRect,KAknsDrawParamDefault );
       
   175     
       
   176     if( !backgroundWithBitmap )
       
   177         {
       
   178         MUS_LOG( "mus: [MUSIND] : Clearing rect with null brush") 
       
   179         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   180         gc.Clear( aRect );
       
   181         }
       
   182     else
       
   183         {
       
   184         MUS_LOG( "mus: [MUSIND] : rect was cleared with bitmap") 
       
   185         }
       
   186     
       
   187     gc.UseFont( &Font() );
       
   188     
       
   189     // Border initialization                   
       
   190     gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   191 
       
   192     // Draw border
       
   193     MUS_LOG( "mus: [MUSIND] : Draw border") 
       
   194     gc.SetPenStyle( CGraphicsContext::ESolidPen );
       
   195     gc.SetPenColor( borderColor );
       
   196     gc.SetPenSize(
       
   197         TSize( KMusIndicatorBorderSize, KMusIndicatorBorderSize ) );
       
   198     gc.DrawRoundRect( iScreenRect,
       
   199                         TSize( KMusIndicatorBorderRoundedCorners,
       
   200                                KMusIndicatorBorderRoundedCorners ) );
       
   201     
       
   202     /* 
       
   203     // Draw smaller border with other color
       
   204     MUS_LOG( "mus: [MUSIND] : Draw smaller border with other color") 
       
   205     gc.SetPenColor( iBorderBgColor );
       
   206     TRect smallerRect = iScreenRect;
       
   207     smallerRect.Shrink( KMusIndicatorBorderSize, KMusIndicatorBorderSize );
       
   208     gc.DrawRoundRect( smallerRect,
       
   209                         TSize( KMusIndicatorBorderRoundedCorners,
       
   210                                KMusIndicatorBorderRoundedCorners ) );
       
   211                               
       
   212     // Font outline initialization
       
   213     
       
   214     MUS_LOG( "mus: [MUSIND] : Draw text outlines") 
       
   215     gc.SetPenColor( iBorderBgColor );
       
   216     gc.SetPenSize( TSize( KMusIndicatorFontPenSize, KMusIndicatorFontPenSize ) );
       
   217 
       
   218     // Draw text outlines
       
   219     TPoint outlineTextPos = iTextpos;
       
   220     outlineTextPos -= TPoint( 1, 1 );
       
   221     gc.DrawText( *iText, outlineTextPos );
       
   222     */
       
   223    
       
   224     // Font initialization
       
   225     gc.SetPenColor( fontColor );
       
   226 
       
   227     // Draw text
       
   228     MUS_LOG( "mus: [MUSIND] : Draw text") 
       
   229     gc.DrawText( *iText, iTextpos );
       
   230     
       
   231     gc.BitBltMasked( iImagepos, 
       
   232                        iIcon, 
       
   233                        TRect( 0, 0, iImageSize.iWidth, iImageSize.iHeight ),
       
   234                        iIconMask, 
       
   235                        EFalse );
       
   236 
       
   237 
       
   238     
       
   239     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::Draw" )
       
   240     }
       
   241 
       
   242 
       
   243 //------------------------------------------------------------------------------
       
   244 // 
       
   245 //------------------------------------------------------------------------------
       
   246 //
       
   247 void CMusIndicatorDsa::HandleResourceChange( TInt aType )
       
   248     {
       
   249     
       
   250     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   251         {
       
   252         Initialize();
       
   253         DrawDeferred();
       
   254         }
       
   255     
       
   256     StopPeriodicTimer();
       
   257     
       
   258     }
       
   259 
       
   260 
       
   261 
       
   262 //------------------------------------------------------------------------------
       
   263 // Calculates topleft position of drawn text.
       
   264 //------------------------------------------------------------------------------
       
   265 //
       
   266 void CMusIndicatorDsa::Initialize()
       
   267     {
       
   268     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::Initialize" )
       
   269     
       
   270     TRect clientRect = CEikonEnv::Static()->EikAppUi()->ClientRect();
       
   271     MUS_LOG2( "mus: [MUSIND] clientrect : x=%d,y=%d", clientRect.iTl.iX, clientRect.iTl.iY )
       
   272     MUS_LOG2( "mus: [MUSIND] clientrect : x=%d,y=%d", clientRect.iBr.iX, clientRect.iBr.iY )
       
   273     
       
   274     iScreenSize = ControlEnv()->ScreenDevice()->SizeInPixels();
       
   275 
       
   276     //test (indicator goes inside options menu area)  
       
   277     //clientRect.iTl.iY = 150;
       
   278     
       
   279     SetPosition( clientRect.iTl );
       
   280     SetSize(
       
   281         TSize( iScreenSize.iWidth, KMusIndicatorWindowHeight ) );
       
   282     
       
   283     iScreenRect = TRect(
       
   284         TPoint( 0, 0 ),
       
   285         TSize( iScreenSize.iWidth, KMusIndicatorWindowHeight ) );
       
   286     iScreenRect.Shrink( KMusIndicatorWindowShrink, KMusIndicatorWindowShrink );
       
   287     
       
   288     
       
   289     TInt imagePlusTextWidth = Font().TextWidthInPixels( *iText ) + 
       
   290             iImageSize.iWidth + KMusSpaceBetweenImageAndText;
       
   291 
       
   292     iImagepos.iX = ( iScreenRect.Width() - imagePlusTextWidth )  >> 1;
       
   293     iImagepos.iY = ( iScreenRect.Height() - iImageSize.iHeight ) >> 1;
       
   294     
       
   295     // Text position
       
   296     iTextpos.iX = iImagepos.iX + iImageSize.iWidth + KMusSpaceBetweenImageAndText;
       
   297 
       
   298     iTextpos.iY = ( iScreenRect.Height() >> 1 ) +
       
   299                   ( Font().HeightInPixels() >> 1 ) +
       
   300                     iScreenRect.iTl.iY;
       
   301     
       
   302     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::Initialize" )
       
   303     }
       
   304 
       
   305 
       
   306 
       
   307 //------------------------------------------------------------------------------
       
   308 // Loads displayed image.
       
   309 //------------------------------------------------------------------------------
       
   310 //
       
   311 void CMusIndicatorDsa::LoadImageL()
       
   312     {
       
   313     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::LoadImageL" )
       
   314     
       
   315     if ( iIcon || iIconMask )
       
   316         {
       
   317         MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::LoadImageL" )
       
   318         return;
       
   319         }
       
   320     
       
   321     _LIT( KMyBitmapRomFile, "Z:\\resource\\apps\\musindicatoricons.mbm" );
       
   322     _LIT( KMyBitmapRamFile, "C:\\resource\\apps\\musindicatoricons.mbm" );
       
   323 
       
   324     TFileName imageFileName;
       
   325     if ( MusResourceFinderUtil::IsExistL( KMyBitmapRomFile ) ) 
       
   326         {
       
   327         imageFileName = KMyBitmapRomFile;
       
   328         }
       
   329     else if ( MusResourceFinderUtil::IsExistL( KMyBitmapRamFile ) ) 
       
   330         {
       
   331         imageFileName = KMyBitmapRamFile;
       
   332         }
       
   333     else
       
   334         {
       
   335         MUS_LOG( "mus: [MUSIND]  Icon File Not Found!" );
       
   336         User::Leave( KErrNotFound );
       
   337         } 
       
   338         
       
   339     iIcon = new ( ELeave ) CFbsBitmap();
       
   340     iIconMask = new ( ELeave ) CFbsBitmap();
       
   341     
       
   342     // Enumerations of mbg file are usable only when vector images
       
   343     // in mif file are used. Those cannot be loaded without UI components.
       
   344     const TInt KMusIndicatorIconIndex = 0;
       
   345     const TInt KMusIndicatorIconMaskIndex = 1;
       
   346     User::LeaveIfError( 
       
   347         iIcon->Load( imageFileName, KMusIndicatorIconIndex ) );
       
   348     User::LeaveIfError( 
       
   349         iIconMask->Load( imageFileName, KMusIndicatorIconMaskIndex ) );
       
   350     
       
   351     iImageSize = iIcon->SizeInPixels();
       
   352     
       
   353     // Crop icon if it is too big
       
   354     if ( iImageSize.iHeight > KMusIndicatorWindowHeight )
       
   355         {
       
   356         TInt newHeight = KMusIndicatorWindowHeight >> 1;
       
   357         TInt newWidth = 
       
   358             TReal( iImageSize.iHeight / iImageSize.iWidth  ) * newHeight;
       
   359         iIcon->Resize( TSize( newHeight, newWidth ) );
       
   360         iIconMask->Resize( TSize( newHeight, newWidth ) );
       
   361         }
       
   362     
       
   363     
       
   364     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::LoadImageL" )
       
   365     }
       
   366 
       
   367 
       
   368 //------------------------------------------------------------------------------
       
   369 //
       
   370 //------------------------------------------------------------------------------
       
   371 //
       
   372 void CMusIndicatorDsa::LoadResourceStringL()
       
   373     {
       
   374     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::LoadResourceStringL" )
       
   375     delete iText;
       
   376     iText = NULL;
       
   377     iText = MusResourceUtil::ReadResourceString16L(
       
   378         R_MUSINDICATOR_NOTE_VSREADY_TXT,
       
   379         KMusIndicatorResource );
       
   380     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::LoadResourceStringL" )
       
   381     }
       
   382 
       
   383 //------------------------------------------------------------------------------
       
   384 // Periodic timer completion
       
   385 //------------------------------------------------------------------------------
       
   386 //
       
   387 TInt CMusIndicatorDsa::TryActivate( TAny* aThis )
       
   388     {
       
   389     if ( !aThis )
       
   390         {
       
   391         return KErrArgument;
       
   392         }
       
   393 
       
   394     CMusIndicatorDsa* handle = static_cast< CMusIndicatorDsa* > ( aThis );
       
   395     
       
   396     TInt error = KErrNone;
       
   397     TRAP( error, handle->TryActivateL() );
       
   398 
       
   399     return error;
       
   400     }
       
   401     
       
   402 
       
   403 //------------------------------------------------------------------------------
       
   404 // Periodic timer completion
       
   405 //------------------------------------------------------------------------------
       
   406 //
       
   407 TInt CMusIndicatorDsa::DoHandleResourceChange( TAny* aThis )
       
   408     {
       
   409 
       
   410     if ( !aThis )
       
   411         {
       
   412         return KErrArgument;
       
   413         }
       
   414 
       
   415     CMusIndicatorDsa* handle = static_cast< CMusIndicatorDsa* > ( aThis );
       
   416 
       
   417     handle->HandleResourceChange( KEikDynamicLayoutVariantSwitch );
       
   418     
       
   419     return KErrNone;
       
   420     
       
   421     }
       
   422 
       
   423 
       
   424 
       
   425 //------------------------------------------------------------------------------
       
   426 //
       
   427 //------------------------------------------------------------------------------
       
   428 //
       
   429 void CMusIndicatorDsa::StartPeriodicTimer( const TCallBack& aCallBack) const
       
   430     {
       
   431     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::StartPeriodicTimer" )
       
   432     
       
   433     if ( iPeriodic->IsActive() )
       
   434         {
       
   435         return;
       
   436         }
       
   437     
       
   438     TTimeIntervalMicroSeconds32 delay = 
       
   439             aCallBack.iFunction == CMusIndicatorDsa::TryActivate ?
       
   440                                   KMusIndicatorDelay : KMusRedrawDelay;
       
   441     
       
   442     iPeriodic->Start( delay, delay, aCallBack );
       
   443     
       
   444     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::StartPeriodicTimer" )
       
   445     }
       
   446 
       
   447 
       
   448 //------------------------------------------------------------------------------
       
   449 //
       
   450 //------------------------------------------------------------------------------
       
   451 //
       
   452 void CMusIndicatorDsa::StopPeriodicTimer()
       
   453     {
       
   454     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::StopPeriodicTimer" )
       
   455     if( iPeriodic )
       
   456         {
       
   457         iPeriodic->Cancel();
       
   458         }
       
   459     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::StopPeriodicTimer" )
       
   460     }
       
   461 
       
   462     
       
   463 
       
   464 
       
   465 
       
   466 // End of file
       
   467