mmsharing/mmshindicator/src/musindicatordsa.cpp
changeset 0 f0cf47e981f9
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     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     if ( AknLayoutUtils::LayoutMirrored() )
       
   230     	{
       
   231         CGraphicsContext::TDrawTextExtendedParam drawParam;
       
   232         drawParam.iParRightToLeft = ETrue;
       
   233         gc.DrawTextExtended(*iText, iTextpos,drawParam);
       
   234     	}
       
   235     else
       
   236     	{
       
   237         gc.DrawText( *iText, iTextpos );
       
   238     	}
       
   239     
       
   240     gc.BitBltMasked( iImagepos, 
       
   241                        iIcon, 
       
   242                        TRect( 0, 0, iImageSize.iWidth, iImageSize.iHeight ),
       
   243                        iIconMask, 
       
   244                        EFalse );
       
   245 
       
   246 
       
   247     
       
   248     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::Draw" )
       
   249     }
       
   250 
       
   251 
       
   252 //------------------------------------------------------------------------------
       
   253 // 
       
   254 //------------------------------------------------------------------------------
       
   255 //
       
   256 void CMusIndicatorDsa::HandleResourceChange( TInt aType )
       
   257     {
       
   258     
       
   259     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   260         {
       
   261         Initialize();
       
   262         DrawDeferred();
       
   263         }
       
   264     
       
   265     StopPeriodicTimer();
       
   266     
       
   267     }
       
   268 
       
   269 
       
   270 
       
   271 //------------------------------------------------------------------------------
       
   272 // Calculates topleft position of drawn text.
       
   273 //------------------------------------------------------------------------------
       
   274 //
       
   275 void CMusIndicatorDsa::Initialize()
       
   276     {
       
   277     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::Initialize" )
       
   278     
       
   279     TRect clientRect = CEikonEnv::Static()->EikAppUi()->ClientRect();
       
   280     MUS_LOG2( "mus: [MUSIND] clientrect : x=%d,y=%d", clientRect.iTl.iX, clientRect.iTl.iY )
       
   281     MUS_LOG2( "mus: [MUSIND] clientrect : x=%d,y=%d", clientRect.iBr.iX, clientRect.iBr.iY )
       
   282     
       
   283     iScreenSize = ControlEnv()->ScreenDevice()->SizeInPixels();
       
   284 
       
   285     //test (indicator goes inside options menu area)  
       
   286     //clientRect.iTl.iY = 150;
       
   287     
       
   288     SetPosition( clientRect.iTl );
       
   289     SetSize(
       
   290         TSize( iScreenSize.iWidth, KMusIndicatorWindowHeight ) );
       
   291     
       
   292     iScreenRect = TRect(
       
   293         TPoint( 0, 0 ),
       
   294         TSize( iScreenSize.iWidth, KMusIndicatorWindowHeight ) );
       
   295     iScreenRect.Shrink( KMusIndicatorWindowShrink, KMusIndicatorWindowShrink );
       
   296     
       
   297     
       
   298     TInt imagePlusTextWidth = Font().TextWidthInPixels( *iText ) + 
       
   299             iImageSize.iWidth + KMusSpaceBetweenImageAndText;
       
   300     if ( AknLayoutUtils::LayoutMirrored() )
       
   301          { 
       
   302          // Text position
       
   303          iTextpos.iX = ( iScreenRect.Width() - imagePlusTextWidth )  >> 1;
       
   304 
       
   305          iTextpos.iY = ( iScreenRect.Height() >> 1 ) +
       
   306                        ( Font().HeightInPixels() >> 1 ) +
       
   307                          iScreenRect.iTl.iY;
       
   308 
       
   309          iImagepos.iX = iTextpos.iX + 
       
   310 		                Font().TextWidthInPixels( *iText ) +
       
   311 						KMusSpaceBetweenImageAndText;
       
   312          iImagepos.iY = ( iScreenRect.Height() - iImageSize.iHeight ) >> 1;
       
   313          }
       
   314     else
       
   315          {
       
   316     iImagepos.iX = ( iScreenRect.Width() - imagePlusTextWidth )  >> 1;
       
   317     iImagepos.iY = ( iScreenRect.Height() - iImageSize.iHeight ) >> 1;
       
   318     
       
   319     // Text position
       
   320     iTextpos.iX = iImagepos.iX + iImageSize.iWidth + KMusSpaceBetweenImageAndText;
       
   321 
       
   322     iTextpos.iY = ( iScreenRect.Height() >> 1 ) +
       
   323                   ( Font().HeightInPixels() >> 1 ) +
       
   324                     iScreenRect.iTl.iY;
       
   325          }
       
   326     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::Initialize" )
       
   327     }
       
   328 
       
   329 
       
   330 
       
   331 //------------------------------------------------------------------------------
       
   332 // Loads displayed image.
       
   333 //------------------------------------------------------------------------------
       
   334 //
       
   335 void CMusIndicatorDsa::LoadImageL()
       
   336     {
       
   337     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::LoadImageL" )
       
   338     
       
   339     if ( iIcon || iIconMask )
       
   340         {
       
   341         MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::LoadImageL" )
       
   342         return;
       
   343         }
       
   344     
       
   345     _LIT( KMyBitmapRomFile, "Z:\\resource\\apps\\musindicatoricons.mbm" );
       
   346     _LIT( KMyBitmapRamFile, "C:\\resource\\apps\\musindicatoricons.mbm" );
       
   347 
       
   348     TFileName imageFileName;
       
   349     if ( MusResourceFinderUtil::IsExistL( KMyBitmapRomFile ) ) 
       
   350         {
       
   351         imageFileName = KMyBitmapRomFile;
       
   352         }
       
   353     else if ( MusResourceFinderUtil::IsExistL( KMyBitmapRamFile ) ) 
       
   354         {
       
   355         imageFileName = KMyBitmapRamFile;
       
   356         }
       
   357     else
       
   358         {
       
   359         MUS_LOG( "mus: [MUSIND]  Icon File Not Found!" );
       
   360         User::Leave( KErrNotFound );
       
   361         } 
       
   362         
       
   363     iIcon = new ( ELeave ) CFbsBitmap();
       
   364     iIconMask = new ( ELeave ) CFbsBitmap();
       
   365     
       
   366     // Enumerations of mbg file are usable only when vector images
       
   367     // in mif file are used. Those cannot be loaded without UI components.
       
   368     const TInt KMusIndicatorIconIndex = 0;
       
   369     const TInt KMusIndicatorIconMaskIndex = 1;
       
   370     User::LeaveIfError( 
       
   371         iIcon->Load( imageFileName, KMusIndicatorIconIndex ) );
       
   372     User::LeaveIfError( 
       
   373         iIconMask->Load( imageFileName, KMusIndicatorIconMaskIndex ) );
       
   374     
       
   375     iImageSize = iIcon->SizeInPixels();
       
   376     
       
   377     // Crop icon if it is too big
       
   378     if ( iImageSize.iHeight > KMusIndicatorWindowHeight )
       
   379         {
       
   380         TInt newHeight = KMusIndicatorWindowHeight >> 1;
       
   381         TInt newWidth = 
       
   382             TReal( iImageSize.iHeight / iImageSize.iWidth  ) * newHeight;
       
   383         iIcon->Resize( TSize( newHeight, newWidth ) );
       
   384         iIconMask->Resize( TSize( newHeight, newWidth ) );
       
   385         }
       
   386     
       
   387     
       
   388     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::LoadImageL" )
       
   389     }
       
   390 
       
   391 
       
   392 //------------------------------------------------------------------------------
       
   393 //
       
   394 //------------------------------------------------------------------------------
       
   395 //
       
   396 void CMusIndicatorDsa::LoadResourceStringL()
       
   397     {
       
   398     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::LoadResourceStringL" )
       
   399     delete iText;
       
   400     iText = NULL;
       
   401     iText = MusResourceUtil::ReadResourceString16L(
       
   402         R_MUSINDICATOR_NOTE_VSREADY_TXT,
       
   403         KMusIndicatorResource );
       
   404     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::LoadResourceStringL" )
       
   405     }
       
   406 
       
   407 //------------------------------------------------------------------------------
       
   408 // Periodic timer completion
       
   409 //------------------------------------------------------------------------------
       
   410 //
       
   411 TInt CMusIndicatorDsa::TryActivate( TAny* aThis )
       
   412     {
       
   413     if ( !aThis )
       
   414         {
       
   415         return KErrArgument;
       
   416         }
       
   417 
       
   418     CMusIndicatorDsa* handle = static_cast< CMusIndicatorDsa* > ( aThis );
       
   419     
       
   420     TInt error = KErrNone;
       
   421     TRAP( error, handle->TryActivateL() );
       
   422 
       
   423     return error;
       
   424     }
       
   425     
       
   426 
       
   427 //------------------------------------------------------------------------------
       
   428 // Periodic timer completion
       
   429 //------------------------------------------------------------------------------
       
   430 //
       
   431 TInt CMusIndicatorDsa::DoHandleResourceChange( TAny* aThis )
       
   432     {
       
   433 
       
   434     if ( !aThis )
       
   435         {
       
   436         return KErrArgument;
       
   437         }
       
   438 
       
   439     CMusIndicatorDsa* handle = static_cast< CMusIndicatorDsa* > ( aThis );
       
   440 
       
   441     handle->HandleResourceChange( KEikDynamicLayoutVariantSwitch );
       
   442     
       
   443     return KErrNone;
       
   444     
       
   445     }
       
   446 
       
   447 
       
   448 
       
   449 //------------------------------------------------------------------------------
       
   450 //
       
   451 //------------------------------------------------------------------------------
       
   452 //
       
   453 void CMusIndicatorDsa::StartPeriodicTimer( const TCallBack& aCallBack) const
       
   454     {
       
   455     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::StartPeriodicTimer" )
       
   456     
       
   457     if ( iPeriodic->IsActive() )
       
   458         {
       
   459         return;
       
   460         }
       
   461     
       
   462     TTimeIntervalMicroSeconds32 delay = 
       
   463             aCallBack.iFunction == CMusIndicatorDsa::TryActivate ?
       
   464                                   KMusIndicatorDelay : KMusRedrawDelay;
       
   465     
       
   466     iPeriodic->Start( delay, delay, aCallBack );
       
   467     
       
   468     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::StartPeriodicTimer" )
       
   469     }
       
   470 
       
   471 
       
   472 //------------------------------------------------------------------------------
       
   473 //
       
   474 //------------------------------------------------------------------------------
       
   475 //
       
   476 void CMusIndicatorDsa::StopPeriodicTimer()
       
   477     {
       
   478     MUS_LOG( "mus: [MUSIND] -> CMusIndicatorDsa::StopPeriodicTimer" )
       
   479     if( iPeriodic )
       
   480         {
       
   481         iPeriodic->Cancel();
       
   482         }
       
   483     MUS_LOG( "mus: [MUSIND] <- CMusIndicatorDsa::StopPeriodicTimer" )
       
   484     }
       
   485 
       
   486     
       
   487 
       
   488 
       
   489 
       
   490 // End of file
       
   491