perfmon/ui/avkon/src/perfmon_valuescontainer.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     1 /*
       
     2 * Copyright (c) 2009 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "perfmon_valuescontainer.h"
       
    21 #include "perfmon.hrh"
       
    22 #include "perfmon_document.h"
       
    23 #include "perfmon_appui.h"
       
    24 #include "perfmon_model.h"
       
    25 
       
    26 #include <AknUtils.h>
       
    27 
       
    28 _LIT(KPercentageFormat,"%S %d%%");
       
    29 _LIT(KFreeFormat,"%S free %S%S"); 
       
    30 _LIT(KSizeFormat,"%S size %S%S"); 
       
    31 
       
    32 const TInt KLeftMargin = 2;
       
    33 
       
    34 
       
    35 // ===================================== MEMBER FUNCTIONS =====================================
       
    36 
       
    37 void CPerfMonValuesContainer::ConstructL(const TRect& aRect)
       
    38     {
       
    39     iModel = static_cast<CPerfMonDocument*>(reinterpret_cast<CEikAppUi*>(iEikonEnv->AppUi())->Document())->Model();
       
    40     iFont = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont);
       
    41  
       
    42     CreateWindowL();
       
    43     SetRect(aRect);
       
    44     SetBlank();
       
    45 
       
    46     ActivateL();
       
    47     }
       
    48 
       
    49 // --------------------------------------------------------------------------------------------
       
    50 
       
    51 CPerfMonValuesContainer::~CPerfMonValuesContainer()
       
    52     {
       
    53     }
       
    54     
       
    55 // --------------------------------------------------------------------------------------------
       
    56 
       
    57 void CPerfMonValuesContainer::Draw(const TRect& aRect) const
       
    58     {
       
    59     CWindowGc& gc = SystemGc();
       
    60     gc.SetBrushColor(KRgbWhite);
       
    61     gc.Clear(aRect);
       
    62     
       
    63     // check if sample array has been constructed
       
    64     if (iModel->SampleEntryArray())
       
    65         {
       
    66         // init font
       
    67         gc.SetPenColor(KRgbBlack);
       
    68         gc.UseFont( iFont );
       
    69         TUint separator = iFont->HeightInPixels()-2;
       
    70 
       
    71         TInt c(1);
       
    72 
       
    73         // draw all entries
       
    74         for (TInt i=0; i<iModel->SampleEntryArray()->Count(); i++)
       
    75             {
       
    76             // check if data available
       
    77             if (iModel->SampleEntryArray()->At(i).iSampleDataArray->Count() > 0)
       
    78                 {
       
    79                 TSampleData& currentSample = iModel->SampleEntryArray()->At(i).iSampleDataArray->At(0);
       
    80                 
       
    81                 if (i == ESourceCPU) // for CPU draw %
       
    82                     {
       
    83                     TBuf<16> buf;
       
    84                     buf.Format(KPercentageFormat, &iModel->SampleEntryArray()->At(i).iDescription, currentSample.iSize > 0 ? TInt( (1 - ((TReal)(currentSample.iFree) / (TReal)currentSample.iSize)) * 100) : 0 );
       
    85                     gc.DrawText(buf, TPoint(KLeftMargin,separator*c));
       
    86                     c++;
       
    87                     }
       
    88                 
       
    89                 else if (currentSample.iSize > 0) // ram+drives, ignore absent drives
       
    90                     {
       
    91                     TBuf<32> amountBuf;
       
    92                     amountBuf.AppendNum(currentSample.iFree, TRealFormat(KDefaultRealWidth, 0));
       
    93         
       
    94                     TBuf<32> buf;
       
    95                     buf.Format(KFreeFormat, &iModel->SampleEntryArray()->At(i).iDescription, &amountBuf, &iModel->SampleEntryArray()->At(i).iUnitTypeShort);
       
    96                     gc.DrawText(buf, TPoint(KLeftMargin,separator*c));
       
    97                     c++;
       
    98                     
       
    99                     amountBuf.Copy(KNullDesC);
       
   100                     amountBuf.AppendNum(currentSample.iSize, TRealFormat(KDefaultRealWidth, 0));
       
   101         
       
   102                     buf.Format(KSizeFormat, &iModel->SampleEntryArray()->At(i).iDescription, &amountBuf, &iModel->SampleEntryArray()->At(i).iUnitTypeShort);
       
   103                     gc.DrawText(buf, TPoint(KLeftMargin,separator*c));
       
   104                     c++;            
       
   105                     }                    
       
   106                 }
       
   107             }
       
   108            
       
   109         gc.DiscardFont();        
       
   110         }
       
   111     }
       
   112 
       
   113 // --------------------------------------------------------------------------------------------
       
   114 
       
   115 TKeyResponse CPerfMonValuesContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   116     {
       
   117     return CCoeControl::OfferKeyEventL(aKeyEvent, aType);
       
   118     }
       
   119         
       
   120 // --------------------------------------------------------------------------------------------
       
   121 
       
   122 void CPerfMonValuesContainer::HandleResourceChange(TInt aType)
       
   123     {
       
   124     if (aType == KEikDynamicLayoutVariantSwitch)
       
   125         {
       
   126         TRect mainPaneRect;
       
   127         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   128         SetRect(mainPaneRect);
       
   129         }
       
   130     else
       
   131         CCoeControl::HandleResourceChange(aType);    
       
   132     }
       
   133 
       
   134 // --------------------------------------------------------------------------------------------
       
   135 
       
   136 void CPerfMonValuesContainer::DrawUpdate()
       
   137     {
       
   138     DrawDeferred(); 
       
   139     }
       
   140     
       
   141 // --------------------------------------------------------------------------------------------
       
   142        
       
   143 // End of File