perfmon/src/perfmon_datapopupcontainer.cpp
branchRCL_3
changeset 22 fad26422216a
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_datapopupcontainer.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 
       
    31 const TInt KLeftMargin = 2;
       
    32  
       
    33 
       
    34 // ===================================== MEMBER FUNCTIONS =====================================
       
    35 
       
    36 void CPerfMonDataPopupContainer::ConstructL(const TRect& /*aRect*/)
       
    37     {
       
    38     iModel = static_cast<CPerfMonDocument*>(reinterpret_cast<CEikAppUi*>(iEikonEnv->AppUi())->Document())->Model();
       
    39     iFont = LatinPlain12();
       
    40     iFontSize = iFont->FontMaxHeight();
       
    41  
       
    42     // set windowgroup so that it always on top and does not receive focus
       
    43     iWindowGroup = RWindowGroup(iCoeEnv->WsSession());
       
    44     User::LeaveIfError(iWindowGroup.Construct((TUint32)&iWindowGroup));
       
    45     iWindowGroup.SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
       
    46     iWindowGroup.EnableReceiptOfFocus(EFalse);
       
    47     
       
    48     CreateWindowL(&iWindowGroup);
       
    49     //SetRect(aRect);
       
    50     SetPositionAndSize();
       
    51     SetBlank();
       
    52 
       
    53     ActivateL();
       
    54     }
       
    55 
       
    56 // --------------------------------------------------------------------------------------------
       
    57 
       
    58 CPerfMonDataPopupContainer::~CPerfMonDataPopupContainer()
       
    59     {
       
    60     iWindowGroup.Close();    
       
    61     }
       
    62     
       
    63 // --------------------------------------------------------------------------------------------
       
    64 
       
    65 void CPerfMonDataPopupContainer::Draw(const TRect& aRect) const
       
    66     {
       
    67     CWindowGc& gc = SystemGc();
       
    68     gc.SetBrushColor(KRgbWhite);
       
    69     gc.Clear(aRect);
       
    70     
       
    71     // check if sample array has been constructed
       
    72     if (iModel->SampleEntryArray())
       
    73         {
       
    74         // init font
       
    75         gc.SetPenColor(KRgbBlack);
       
    76         gc.UseFont( iFont );
       
    77         
       
    78         // draw a rect around the popup
       
    79         gc.DrawRect(aRect);
       
    80         
       
    81         TInt posCounter(1);
       
    82         
       
    83         for (TInt i=0; i<iModel->SampleEntryArray()->Count(); i++)
       
    84             {
       
    85             // check if this setting has been enabled and it has some data
       
    86             if (iModel->Settings().iDataPopupSources.iSrcEnabled[i] && iModel->SampleEntryArray()->At(i).iSampleDataArray->Count() > 0)
       
    87                 {
       
    88                 TSampleData& currentSample = iModel->SampleEntryArray()->At(i).iSampleDataArray->At(0);    
       
    89                 TBuf<32> buf;
       
    90 
       
    91                 // for CPU draw %, other amount of free memory
       
    92                 if (i == ESourceCPU)
       
    93                     {
       
    94                     buf.Format(KPercentageFormat, &iModel->SampleEntryArray()->At(i).iDescription, currentSample.iSize > 0 ? TInt( (1 - ((TReal)(currentSample.iFree) / (TReal)currentSample.iSize)) * 100) : 0 );
       
    95                     gc.DrawText(buf, TPoint(KLeftMargin, iFontSize*posCounter));
       
    96                     }
       
    97                 else
       
    98                     {
       
    99                     TBuf<32> freeBuf;
       
   100                     freeBuf.AppendNum(currentSample.iFree, TRealFormat(KDefaultRealWidth, 0));
       
   101 
       
   102                     TBuf<32> buf;
       
   103                     buf.Format(KFreeFormat, &iModel->SampleEntryArray()->At(i).iDescription, &freeBuf, &iModel->SampleEntryArray()->At(i).iUnitTypeShort);
       
   104                     gc.DrawText(buf, TPoint(KLeftMargin, iFontSize*posCounter));                    
       
   105                     }    
       
   106                 
       
   107                 posCounter++;
       
   108                 }
       
   109             }
       
   110             
       
   111         gc.DiscardFont();        
       
   112         }
       
   113     }
       
   114 
       
   115 // --------------------------------------------------------------------------------------------
       
   116 
       
   117 void CPerfMonDataPopupContainer::SizeChanged()
       
   118     {
       
   119     DrawNow();
       
   120     }   
       
   121 
       
   122 // --------------------------------------------------------------------------------------------
       
   123 
       
   124 void CPerfMonDataPopupContainer::SetPositionAndSize()
       
   125     {
       
   126     CWsScreenDevice* screenDevice = iEikonEnv->ScreenDevice();
       
   127 
       
   128     // top right
       
   129     if (iModel->Settings().iDataPopupLocation == EDataPopupLocationTopRight)
       
   130         {
       
   131         // screen orientation is landscape with softkeys on right
       
   132         if (AknLayoutUtils::CbaLocation()==AknLayoutUtils::EAknCbaLocationRight)
       
   133             {
       
   134             SetRect(
       
   135                 TRect(
       
   136                     screenDevice->SizeInPixels().iWidth-102-15,
       
   137                     0,
       
   138                     screenDevice->SizeInPixels().iWidth-15,
       
   139                     iModel->Settings().iDataPopupSources.EnabledSourcesCount()*iFontSize + 3
       
   140                     ));
       
   141             }
       
   142 
       
   143         // any other orientation
       
   144         else
       
   145             {
       
   146             SetRect(
       
   147                 TRect(
       
   148                     screenDevice->SizeInPixels().iWidth-102,
       
   149                     0,
       
   150                     screenDevice->SizeInPixels().iWidth,
       
   151                     iModel->Settings().iDataPopupSources.EnabledSourcesCount()*iFontSize + 3
       
   152                     ));
       
   153             }        
       
   154         }
       
   155 
       
   156     // bottom middle
       
   157     else if (iModel->Settings().iDataPopupLocation == EDataPopupLocationBottomMiddle)
       
   158         {
       
   159         SetRect(
       
   160             TRect(
       
   161                 screenDevice->SizeInPixels().iWidth/2-102/2,
       
   162                 screenDevice->SizeInPixels().iHeight - iModel->Settings().iDataPopupSources.EnabledSourcesCount()*iFontSize - 3,
       
   163                 screenDevice->SizeInPixels().iWidth/2+102/2,
       
   164                 screenDevice->SizeInPixels().iHeight
       
   165                 ));
       
   166         }
       
   167     }
       
   168 
       
   169 // --------------------------------------------------------------------------------------------
       
   170 
       
   171 void CPerfMonDataPopupContainer::UpdateVisibility(TBool aForeground)
       
   172     {
       
   173     // application has been brought to foregound
       
   174     if (aForeground)
       
   175         {
       
   176         if (iModel->Settings().iDataPopupVisibility==EDataPopupVisbilityAlwaysOn)
       
   177             {
       
   178             MakeVisible(ETrue);
       
   179             }
       
   180         else
       
   181             {
       
   182             MakeVisible(EFalse);
       
   183             }    
       
   184         }
       
   185     
       
   186     // application has been sent to background
       
   187     else
       
   188         {
       
   189         if (iModel->Settings().iDataPopupVisibility==EDataPopupVisbilityAlwaysOn
       
   190             || iModel->Settings().iDataPopupVisibility==EDataPopupVisbilityBackgroundOnly)
       
   191             {
       
   192             MakeVisible(ETrue);
       
   193             }
       
   194         else
       
   195             {
       
   196             MakeVisible(EFalse);
       
   197             }              
       
   198         }    
       
   199     }
       
   200             
       
   201 // --------------------------------------------------------------------------------------------
       
   202 
       
   203 void CPerfMonDataPopupContainer::DrawUpdate()
       
   204     {
       
   205     DrawDeferred(); 
       
   206     }
       
   207     
       
   208 // --------------------------------------------------------------------------------------------
       
   209        
       
   210 // End of File