src/screensaverindicatoricon.cpp
branchRCL_3
changeset 26 e8d784ac1a4b
parent 0 040fcad49f44
equal deleted inserted replaced
25:aaeeca1f15af 26:e8d784ac1a4b
       
     1 /*
       
     2 * Copyright (c) 2003 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:   CScreensaverIndicatorIcon implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <AknsUtils.h>
       
    21 #include <barsread.h>
       
    22 
       
    23 #include "screensaverindicatoricon.h"
       
    24 
       
    25 //
       
    26 // CScreensaverIconIndicator
       
    27 //
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CScreensaverIconIndicator::~CScreensaverIconIndicator
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CScreensaverIndicatorIcon::~CScreensaverIndicatorIcon()
       
    34     {
       
    35     delete iIcon;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CScreensaverIconIndicator::Draw
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 void CScreensaverIndicatorIcon::Draw(CWindowGc& aGc) const
       
    43     {
       
    44     aGc.SetPenColor(iTextColor);
       
    45     aGc.SetBrushColor(iBgColor);
       
    46     if (Visible() && iIcon)
       
    47         {
       
    48         if (!iIcon->Mask())
       
    49             {
       
    50             aGc.BitBlt(iTopLeft, iIcon->Bitmap(), iRect);
       
    51             }
       
    52         else
       
    53             {
       
    54             aGc.BitBltMasked(iTopLeft, iIcon->Bitmap(), iRect, iIcon->Mask(),
       
    55                     ETrue);
       
    56             }
       
    57         }
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CScreensaverIconIndicator::ConstructL
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CScreensaverIndicatorIcon::ConstructL(TResourceReader &aReader,
       
    65         TUint32 aBgColor, TUint aTextColor)
       
    66     {
       
    67     CScreensaverIndicator::ConstructL(aReader, aBgColor, aTextColor);
       
    68 
       
    69     // Icon & mask ids
       
    70     TInt id = aReader.ReadInt32();
       
    71     TInt maskid = aReader.ReadInt32();
       
    72 
       
    73     // Icon & mask skin identifiers
       
    74     TInt skinid = aReader.ReadInt32();
       
    75     TInt skinmaskid = aReader.ReadInt32();
       
    76 
       
    77     iIcon = CGulIcon::NewL();
       
    78 
       
    79     CFbsBitmap* bmp= NULL;
       
    80     CFbsBitmap* mask= NULL;
       
    81 
       
    82     // Load skinned bitmap
       
    83     AknsUtils::CreateColorIconLC(AknsUtils::SkinInstance(),
       
    84             MakeSkinItemId(skinid),
       
    85             KAknsIIDNone, // Lie so that we get default color, not skin color
       
    86             0, // No color group
       
    87             bmp, mask, AknIconUtils::AvkonIconFileName(), id, maskid,
       
    88             iTextColor);
       
    89 
       
    90     CleanupStack::Pop(2);
       
    91 
       
    92     // Save the icon
       
    93     iIcon->SetBitmap(bmp);
       
    94     iIcon->SetMask(mask);
       
    95 
       
    96     // Set initial size for SVG graphics, this is later altered
       
    97     // as the layout is known
       
    98     // Set desired size for SVG graphics (height from LAF, width 3 x height)
       
    99     TAknLayoutRect screenLayout;
       
   100     screenLayout.LayoutRect(TRect(0, 0, 0, 0), AknLayout::screen() );
       
   101     TRect screenRect = screenLayout.Rect();
       
   102     TAknLayoutRect powerSavePaneLayout;
       
   103     powerSavePaneLayout.LayoutRect(screenRect,
       
   104             AknLayout::Power_save_pane_descendants_Line_1() );
       
   105     TRect powerSavePaneRect = powerSavePaneLayout.Rect();
       
   106     TAknLayoutRect rect;
       
   107     rect.LayoutRect(powerSavePaneRect,
       
   108             AknLayout::Power_save_pane_descendants_Line_3() );
       
   109     TInt height = rect.Rect().Height();
       
   110     TSize iconSize(3 * height, height);
       
   111     AknIconUtils::SetSize(iIcon->Bitmap(), iconSize);
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CScreensaverIconIndicator::SetupDrawingParameters
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CScreensaverIndicatorIcon::SetupDrawingParameters(const TPoint &aCorner,
       
   119         const TRect& aParentRect)
       
   120     {
       
   121     iVisible = EFalse;
       
   122 
       
   123     if (!iIcon)
       
   124         {
       
   125         return;
       
   126         }
       
   127 
       
   128     TSize size = iIcon->Bitmap()->SizeInPixels();
       
   129     iTopLeft.iX = aCorner.iX;
       
   130     if (iAlignment == ESsAlignRight)
       
   131         {
       
   132         // Change topright to topleft.      
       
   133         iTopLeft.iX -= size.iWidth;
       
   134         }
       
   135     // Center bitmap in y direction.
       
   136     iTopLeft.iY = aCorner.iY + (aParentRect.Size().iHeight / 2) - (size.iHeight / 2) - 2;
       
   137 
       
   138     iRect = TRect(0, 0, size.iWidth, size.iHeight);
       
   139 
       
   140     iVisible = ETrue;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CScreensaverIconIndicator::CheckVisibilityConditions
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 TBool CScreensaverIndicatorIcon::CheckVisibilityConditions() const
       
   148     {
       
   149     return (iIcon == 0 ? EFalse : ETrue);
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CScreensaverIconIndicator::Payload
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CScreensaverIndicatorIcon::Payload(TIndicatorPayload& aPayload) const
       
   157     {
       
   158     aPayload.iType = EPayloadTypeIcon;
       
   159     aPayload.iInteger = -1;
       
   160     aPayload.iText = KNullDesC;
       
   161     aPayload.iIsDisplayed = Visible();
       
   162     aPayload.iIcon = iIcon;
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CScreensaverIconIndicator::SetPayload
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CScreensaverIndicatorIcon::SetPayload(const TIndicatorPayload& /*aPayload*/)
       
   170     {
       
   171     // Nothing to set, payload is icon and it is created from resources.    
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CScreensaverIconIndicator::SetIconLayout
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CScreensaverIndicatorIcon::SetIconLayout(TAknLayoutRect& aLayout, TInt aX)
       
   179     {
       
   180     if (!iIcon)
       
   181         {
       
   182         ASSERT(iIcon);
       
   183         return;
       
   184         }
       
   185 
       
   186     // Resize icon according to layout
       
   187     TInt height = aLayout.Rect().Height();
       
   188     TSize iconSize(KMaxTInt, height);
       
   189     AknIconUtils::SetSize(iIcon->Bitmap(), iconSize,
       
   190             EAspectRatioPreservedAndUnusedSpaceRemoved);
       
   191 
       
   192     // Set vertical icon position according to layout (this overrides
       
   193     // what's already there. Also set correct width in iRect
       
   194     iTopLeft.iY = aLayout.Rect().iTl.iY;
       
   195     iTopLeft.iX = aX;
       
   196     TSize size = iIcon->Bitmap()->SizeInPixels();
       
   197     iRect = TRect(0, 0, size.iWidth, size.iHeight);
       
   198 
       
   199     if (iAlignment == ESsAlignRight)
       
   200         {
       
   201         // Change topright to topleft.
       
   202         iTopLeft.iX -= size.iWidth;
       
   203         }
       
   204 
       
   205 #ifdef SS_LAYOUTTRACE
       
   206     SCRLOGGER_WRITEF(_L("SCR: Icon indicator (%d):"), iId);
       
   207     SCRLOGGER_WRITEF(_L("SCR:   Rect: (%d,%d,%d,%d)"),
       
   208             iRect.iTl.iX,
       
   209             iRect.iTl.iY,
       
   210             iRect.iBr.iX,
       
   211             iRect.iBr.iY);
       
   212     SCRLOGGER_WRITEF(_L("SCR:   Size: (%d,%d)"), size.iWidth, size.iHeight);
       
   213     SCRLOGGER_WRITEF(_L("SCR:   Pos:  (%d,%d)"), iTopLeft.iX, iTopLeft.iY);
       
   214 #endif
       
   215     }
       
   216 
       
   217 
       
   218 // End of file