javauis/lcdui_akn/lcdui/src/CMIDGaugeItem.cpp
branchRCL_3
changeset 14 04becd199f91
child 17 0fd27995241b
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2003-2006 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:  Implementation of CMIDGaugeItem
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <coemain.h>
       
    20 #include <e32std.h>
       
    21 #include <eikcapc.h>
       
    22 // CAknSlider - needed for iSlider member
       
    23 #include <aknslider.h>
       
    24 // macros for resources
       
    25 #include <lcdui.rsg>
       
    26 // using TMifAvkon enumeration
       
    27 #include <avkon.mbg>
       
    28 // Api for skin instance
       
    29 // and creating icons
       
    30 #include <AknsUtils.h>
       
    31 
       
    32 // needed CEikProgressInfo API for iProgressInfo member
       
    33 // control used to indicate the progress of an operation
       
    34 #include <eikprogi.h>
       
    35 #include <eikon.hrh>
       
    36 #include <eikpanic.h>
       
    37 // using TResourceReader class in ConstructSliderL (interactive gauge)
       
    38 // interprets resource data read from a resource file
       
    39 #include <barsread.h>
       
    40 #include <gulbordr.h>
       
    41 #include <eikenv.h>
       
    42 // API use to retrieve info if pen is enabled (PenEnabled) in HandlePointerEventL function
       
    43 #include <AknUtils.h> // for arabic texts support
       
    44 #include <gulcolor.h>
       
    45 
       
    46 // using AknsDrawUtils for drawing background
       
    47 #include <AknsDrawUtils.h>
       
    48 #include <applayout.cdl.h>
       
    49 // LAF
       
    50 #include <aknlayoutscalable_avkon.cdl.h>
       
    51 
       
    52 #include <AknDef.h> // For layout change event definitions
       
    53 
       
    54 #ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK
       
    55 #include <touchfeedback.h>
       
    56 #endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK
       
    57 
       
    58 #include <j2me/jdebug.h>
       
    59 #include "CMIDGaugeItem.h"
       
    60 // API used for obtain info about command count for IsSelectable function
       
    61 #include "CMIDCommandList.h"
       
    62 // API for iLabelControl (inherited from CMIDControlItem)
       
    63 #include "CMIDItemLabel.h"
       
    64 // using TlsStruct for creating bitmap storage
       
    65 #include "CMIDMenuHandler.h"
       
    66 #include "CMIDUtils.h"
       
    67 #include "CMIDUIManager.h"
       
    68 // Using of CAknBitmapAnimation for iBitmapAnimation
       
    69 #include <AknBitmapAnimation.h>
       
    70 
       
    71 //
       
    72 // Constants
       
    73 //
       
    74 const TInt KDelayInMicroSeconds = 50000;
       
    75 const TInt KContRunningAnimFramesCount = 7;
       
    76 const TInt KIncUpdatingAnimFramesCount = 19;
       
    77 // Divider to correct pointerEvent y-coordinate close to graphics center
       
    78 const TInt KSliderHeightDivider = 3;
       
    79 
       
    80 
       
    81 // class CGaugeTimer
       
    82 
       
    83 inline CMIDGaugeItem::CGaugeTimer::CGaugeTimer(CMIDGaugeItem& aGauge)
       
    84         :CTimer(CActive::EPriorityStandard),iGauge(aGauge)
       
    85 {
       
    86     CActiveScheduler::Add(this);
       
    87 }
       
    88 
       
    89 CMIDGaugeItem::CGaugeTimer* CMIDGaugeItem::CGaugeTimer::NewL(CMIDGaugeItem& aGauge)
       
    90 {
       
    91     CGaugeTimer* self = new(ELeave) CGaugeTimer(aGauge);
       
    92     CleanupStack::PushL(self);
       
    93     self->ConstructL();
       
    94     CleanupStack::Pop(self);
       
    95     return self;
       
    96 }
       
    97 
       
    98 void CMIDGaugeItem::CGaugeTimer::RunL()
       
    99 {
       
   100     if (!iGauge.iGaugeFrameData)
       
   101     {//if the bitmaps haven't been created it means we are inside an alert,
       
   102         //which is using its own bitmaps for the gauge animation.
       
   103         //Return without restarting the timer
       
   104         return;
       
   105     }
       
   106 
       
   107     iGauge.iValue++;
       
   108 
       
   109     if (iGauge.iValue >= iGauge.iGaugeFrameData->iContRunBitmap.Count())
       
   110     {
       
   111         iGauge.iValue = 0;
       
   112     }
       
   113 
       
   114     CMIDNonInteractiveGauge* nig = static_cast<CMIDNonInteractiveGauge*>(&iGauge);
       
   115     nig->DoSafeDraw();
       
   116 
       
   117     After(TTimeIntervalMicroSeconds32(KDelayInMicroSeconds));
       
   118 }
       
   119 
       
   120 
       
   121 // class CMIDGaugeItem
       
   122 
       
   123 
       
   124 TInt CMIDGaugeItem::GetValue()
       
   125 {
       
   126     return iValue;
       
   127 }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 CMIDGaugeItem::CMIDGaugeItem(CMIDUIManager* aUIManager)
       
   134         : CMIDControlItem(EDefault, aUIManager),
       
   135         iIndefiniteState(EIncrementalIdle),
       
   136         iGaugeFrameData(NULL),
       
   137         iTimer(NULL)
       
   138 {
       
   139     iMMidItem = this;
       
   140     iIsInForeground = ETrue;
       
   141 }
       
   142 
       
   143 CMIDGaugeItem::~CMIDGaugeItem()
       
   144 {
       
   145     if (iGaugeFrameData)
       
   146     {
       
   147         iGaugeFrameData->iNumInstances--;
       
   148 
       
   149         if (!(iGaugeFrameData->iNumInstances))
       
   150         {
       
   151             // delete bitmaps from thread-local bitmap storage
       
   152             DeleteBitmapsInTls();
       
   153             iGaugeFrameData->Close();
       
   154             delete iGaugeFrameData;
       
   155             iUIManager->SetGaugeItemData(NULL);
       
   156         }
       
   157     }
       
   158 }
       
   159 
       
   160 
       
   161 void CMIDGaugeItem::BaseConstructL(const TDesC& aLabel,TInt aMaxValue,TInt aInitialValue)
       
   162 {
       
   163     DEBUG("CMIDGaugeItem::BaseConstructL <");
       
   164 
       
   165     CMIDControlItem::ConstructL();
       
   166     SetLabelL(aLabel);
       
   167 
       
   168     iLabelControl->SetWidthL(FormClientAreaWidth());
       
   169 
       
   170     if (aMaxValue == 0)
       
   171     {
       
   172         aMaxValue = 1;
       
   173     }
       
   174 
       
   175     iMaxValue = aMaxValue;
       
   176     iValue = aInitialValue;
       
   177 
       
   178     SetStateL(aMaxValue,aInitialValue);
       
   179 
       
   180     DEBUG("CMIDGaugeItem::BaseConstructL >");
       
   181 }
       
   182 
       
   183 void CMIDGaugeItem::CreateBitmapsIfNeededL()
       
   184 {
       
   185     if (iGaugeFrameData)
       
   186     {
       
   187         return;
       
   188     }
       
   189     iGaugeFrameData = reinterpret_cast< TGaugeFrameData* >(iUIManager->GetGaugeItemData());
       
   190     if (iGaugeFrameData)
       
   191     {
       
   192         iGaugeFrameData->iNumInstances++;
       
   193     }
       
   194     else
       
   195     {
       
   196         // Create shared data
       
   197         iGaugeFrameData = new(ELeave) TGaugeFrameData;
       
   198         iGaugeFrameData->Clean();
       
   199         iUIManager->SetGaugeItemData(reinterpret_cast< void* >(iGaugeFrameData));
       
   200         // Initialize data
       
   201         CreateBitmapsInTlsL();
       
   202         // Resize data
       
   203         ResizeBitmapsInTlsL();
       
   204     }
       
   205 }
       
   206 
       
   207 
       
   208 void CMIDGaugeItem::CreateBitmapsInTlsL()
       
   209 {
       
   210     // check if thread-local bitmap storage is created
       
   211     if (!iGaugeFrameData)
       
   212     {
       
   213         return;
       
   214     }
       
   215 
       
   216     // eventually delete existing bitmaps
       
   217     DeleteBitmapsInTls();
       
   218 
       
   219     // skin instance and default bitmaps file
       
   220     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   221     TFileName avkonbmpFilename = AknIconUtils::AvkonIconFileName();
       
   222 
       
   223     // for bitmap loading
       
   224     const TAknsItemID* aknsItemId;
       
   225     TInt bitmapId;
       
   226     TInt bitmapMaskId;
       
   227     CFbsBitmap* bitmap;
       
   228     CFbsBitmap* bitmapMask;
       
   229     TInt i;
       
   230 
       
   231     // continuous running bitmaps
       
   232     for (i=0; i<KContRunningAnimFramesCount; i++)
       
   233     {
       
   234         switch (i)
       
   235         {
       
   236         case 0:
       
   237             aknsItemId = &KAknsIIDQgnGrafBarWait1;
       
   238             bitmapId = EMbmAvkonQgn_graf_bar_wait_1;
       
   239             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_1_mask;
       
   240             break;
       
   241         case 1:
       
   242             aknsItemId = &KAknsIIDQgnGrafBarWait2;
       
   243             bitmapId = EMbmAvkonQgn_graf_bar_wait_2;
       
   244             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_2_mask;
       
   245             break;
       
   246         case 2:
       
   247             aknsItemId = &KAknsIIDQgnGrafBarWait3;
       
   248             bitmapId = EMbmAvkonQgn_graf_bar_wait_3;
       
   249             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_3_mask;
       
   250             break;
       
   251         case 3:
       
   252             aknsItemId = &KAknsIIDQgnGrafBarWait4;
       
   253             bitmapId = EMbmAvkonQgn_graf_bar_wait_4;
       
   254             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_4_mask;
       
   255             break;
       
   256         case 4:
       
   257             aknsItemId = &KAknsIIDQgnGrafBarWait5;
       
   258             bitmapId = EMbmAvkonQgn_graf_bar_wait_5;
       
   259             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_5_mask;
       
   260             break;
       
   261         case 5:
       
   262             aknsItemId = &KAknsIIDQgnGrafBarWait6;
       
   263             bitmapId = EMbmAvkonQgn_graf_bar_wait_6;
       
   264             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_6_mask;
       
   265             break;
       
   266         default:
       
   267             aknsItemId = &KAknsIIDQgnGrafBarWait7;
       
   268             bitmapId = EMbmAvkonQgn_graf_bar_wait_7;
       
   269             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   270             break;
       
   271         }
       
   272 
       
   273         AknsUtils::CreateIconL(skinInstance, *aknsItemId, bitmap,
       
   274                                bitmapMask, avkonbmpFilename, bitmapId, bitmapMaskId);
       
   275 
       
   276         TInt appendErr1 = iGaugeFrameData->iContRunBitmap.Append(bitmap);
       
   277         TInt appendErr2 = iGaugeFrameData->iContRunBitmapMask.Append(bitmapMask);
       
   278 
       
   279         if (appendErr1 != KErrNone)
       
   280         {
       
   281             delete bitmap;
       
   282         }
       
   283         if (appendErr2 != KErrNone)
       
   284         {
       
   285             delete bitmapMask;
       
   286         }
       
   287         if ((appendErr1 != KErrNone) || (appendErr2 != KErrNone))
       
   288         {
       
   289             User::LeaveIfError((appendErr1 != KErrNone) ? appendErr1 : appendErr2);
       
   290         }
       
   291     }
       
   292 
       
   293     // incremental updating bitmaps
       
   294     // (bitmaps masks ids "EMbmAvkonQgn_graf_bar_wait_increm_mask" -
       
   295     // "EMbmAvkonQgn_graf_bar_wait_increm_19_mask" are not defined and that's
       
   296     // why masks for continuous running animation are used instead)
       
   297     for (i=0; i<KIncUpdatingAnimFramesCount; i++)
       
   298     {
       
   299         switch (i)
       
   300         {
       
   301         case 0:
       
   302             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem;
       
   303             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm;
       
   304             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_1_mask;
       
   305             break;
       
   306         case 1:
       
   307             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem02;
       
   308             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_02;
       
   309             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_2_mask;
       
   310             break;
       
   311         case 2:
       
   312             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem03;
       
   313             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_03;
       
   314             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_3_mask;
       
   315             break;
       
   316         case 3:
       
   317             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem04;
       
   318             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_04;
       
   319             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_4_mask;
       
   320             break;
       
   321         case 4:
       
   322             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem05;
       
   323             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_05;
       
   324             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_5_mask;
       
   325             break;
       
   326         case 5:
       
   327             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem06;
       
   328             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_06;
       
   329             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_6_mask;
       
   330             break;
       
   331         case 6:
       
   332             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem07;
       
   333             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_07;
       
   334             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   335             break;
       
   336         case 7:
       
   337             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem08;
       
   338             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_08;
       
   339             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   340             break;
       
   341         case 8:
       
   342             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem09;
       
   343             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_09;
       
   344             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   345             break;
       
   346         case 9:
       
   347             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem10;
       
   348             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_10;
       
   349             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   350             break;
       
   351         case 10:
       
   352             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem11;
       
   353             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_11;
       
   354             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   355             break;
       
   356         case 11:
       
   357             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem12;
       
   358             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_12;
       
   359             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   360             break;
       
   361         case 12:
       
   362             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem13;
       
   363             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_13;
       
   364             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   365             break;
       
   366         case 13:
       
   367             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem14;
       
   368             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_14;
       
   369             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   370             break;
       
   371         case 14:
       
   372             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem15;
       
   373             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_15;
       
   374             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   375             break;
       
   376         case 15:
       
   377             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem16;
       
   378             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_16;
       
   379             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   380             break;
       
   381         case 16:
       
   382             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem17;
       
   383             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_17;
       
   384             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   385             break;
       
   386         case 17:
       
   387             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem18;
       
   388             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_18;
       
   389             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   390             break;
       
   391         default:
       
   392             aknsItemId = &KAknsIIDQgnGrafBarWaitIncrem19;
       
   393             bitmapId = EMbmAvkonQgn_graf_bar_wait_increm_19;
       
   394             bitmapMaskId = EMbmAvkonQgn_graf_bar_wait_7_mask;
       
   395             break;
       
   396         }
       
   397 
       
   398         AknsUtils::CreateIconL(skinInstance, *aknsItemId, bitmap,
       
   399                                bitmapMask, avkonbmpFilename, bitmapId, bitmapMaskId);
       
   400 
       
   401         TInt appendErr1 = iGaugeFrameData->iIncUpdBitmap.Append(bitmap);
       
   402         TInt appendErr2 = iGaugeFrameData->iIncUpdBitmapMask.Append(bitmapMask);
       
   403 
       
   404         if (appendErr1 != KErrNone)
       
   405         {
       
   406             delete bitmap;
       
   407         }
       
   408         if (appendErr2 != KErrNone)
       
   409         {
       
   410             delete bitmapMask;
       
   411         }
       
   412         if ((appendErr1 != KErrNone) || (appendErr2 != KErrNone))
       
   413         {
       
   414             User::LeaveIfError((appendErr1 != KErrNone) ? appendErr1 : appendErr2);
       
   415         }
       
   416     }
       
   417 
       
   418     // continuous idle bitmap
       
   419     // (bitmap mask id "EMbmAvkonQgn_graf_bar_wait_idle_mask" is not
       
   420     // defined and that's why mask for continuous running animation is used instead)
       
   421     AknsUtils::CreateIconL(skinInstance, KAknsIIDQgnGrafBarWaitIdle,
       
   422                            iGaugeFrameData->iContIdleBitmap,
       
   423                            iGaugeFrameData->iContIdleBitmapMask,
       
   424                            avkonbmpFilename,
       
   425                            EMbmAvkonQgn_graf_bar_wait_idle, EMbmAvkonQgn_graf_bar_wait_1_mask);
       
   426 
       
   427     // incremental idle bitmap
       
   428     // (bitmap mask id "EMbmAvkonQgn_graf_bar_wait_increm_idle_mask" is not
       
   429     // defined and that's why mask for continuous running animation is used instead)
       
   430     AknsUtils::CreateIconL(skinInstance, KAknsIIDQgnGrafBarWaitIncremIdle,
       
   431                            iGaugeFrameData->iIncIdleBitmap,
       
   432                            iGaugeFrameData->iIncIdleBitmapMask,
       
   433                            avkonbmpFilename,
       
   434                            EMbmAvkonQgn_graf_bar_wait_increm_idle,
       
   435                            EMbmAvkonQgn_graf_bar_wait_1_mask);
       
   436 
       
   437     // bar frame bitmaps (left, center and right part of frame)
       
   438     AknsUtils::CreateIconL(skinInstance, KAknsIIDQgnGrafBarFrameSideL,
       
   439                            iGaugeFrameData->iFrameL, iGaugeFrameData->iFrameLMask,
       
   440                            avkonbmpFilename, EMbmAvkonQgn_graf_bar_frame_side_l,
       
   441                            EMbmAvkonQgn_graf_bar_frame_side_l_mask);
       
   442 
       
   443     AknsUtils::CreateIconL(skinInstance, KAknsIIDQgnGrafBarFrameCenter,
       
   444                            iGaugeFrameData->iFrameCenter, iGaugeFrameData->iFrameCenterMask,
       
   445                            avkonbmpFilename, EMbmAvkonQgn_graf_bar_frame_center,
       
   446                            EMbmAvkonQgn_graf_bar_frame_center_mask);
       
   447 
       
   448     AknsUtils::CreateIconL(skinInstance, KAknsIIDQgnGrafBarFrameSideR,
       
   449                            iGaugeFrameData->iFrameR, iGaugeFrameData->iFrameRMask,
       
   450                            avkonbmpFilename, EMbmAvkonQgn_graf_bar_frame_side_r,
       
   451                            EMbmAvkonQgn_graf_bar_frame_side_r_mask);
       
   452 }
       
   453 
       
   454 
       
   455 void CMIDGaugeItem::DeleteBitmapsInTls()
       
   456 {
       
   457     // check if thread-local bitmap storage is created
       
   458     if (!iGaugeFrameData)
       
   459     {
       
   460         return;
       
   461     }
       
   462 
       
   463     // continuous running bitmaps
       
   464     TInt i;
       
   465 
       
   466     for (i=0; i < iGaugeFrameData->iContRunBitmap.Count(); i++)
       
   467     {
       
   468         delete iGaugeFrameData->iContRunBitmap[i];
       
   469     }
       
   470     iGaugeFrameData->iContRunBitmap.Reset();
       
   471 
       
   472     for (i=0; i < iGaugeFrameData->iContRunBitmapMask.Count(); i++)
       
   473     {
       
   474         delete iGaugeFrameData->iContRunBitmapMask[i];
       
   475     }
       
   476     iGaugeFrameData->iContRunBitmapMask.Reset();
       
   477 
       
   478     // incremental updating bitmaps
       
   479     for (i=0; i < iGaugeFrameData->iIncUpdBitmap.Count(); i++)
       
   480     {
       
   481         delete iGaugeFrameData->iIncUpdBitmap[i];
       
   482     }
       
   483     iGaugeFrameData->iIncUpdBitmap.Reset();
       
   484 
       
   485     for (i=0; i < iGaugeFrameData->iIncUpdBitmapMask.Count(); i++)
       
   486     {
       
   487         delete iGaugeFrameData->iIncUpdBitmapMask[i];
       
   488     }
       
   489     iGaugeFrameData->iIncUpdBitmapMask.Reset();
       
   490 
       
   491     // continuous idle bitmap
       
   492     delete iGaugeFrameData->iContIdleBitmap;
       
   493     iGaugeFrameData->iContIdleBitmap = NULL;
       
   494 
       
   495     delete iGaugeFrameData->iContIdleBitmapMask;
       
   496     iGaugeFrameData->iContIdleBitmapMask = NULL;
       
   497 
       
   498     // incremental idle bitmap
       
   499     delete iGaugeFrameData->iIncIdleBitmap;
       
   500     iGaugeFrameData->iIncIdleBitmap = NULL;
       
   501 
       
   502     delete iGaugeFrameData->iIncIdleBitmapMask;
       
   503     iGaugeFrameData->iIncIdleBitmapMask = NULL;
       
   504 
       
   505     // frame bitmaps
       
   506     delete iGaugeFrameData->iFrameL;
       
   507     iGaugeFrameData->iFrameL = NULL;
       
   508 
       
   509     delete iGaugeFrameData->iFrameLMask;
       
   510     iGaugeFrameData->iFrameLMask = NULL;
       
   511 
       
   512     delete iGaugeFrameData->iFrameCenter;
       
   513     iGaugeFrameData->iFrameCenter = NULL;
       
   514 
       
   515     delete iGaugeFrameData->iFrameCenterMask;
       
   516     iGaugeFrameData->iFrameCenterMask = NULL;
       
   517 
       
   518     delete iGaugeFrameData->iFrameR;
       
   519     iGaugeFrameData->iFrameR = NULL;
       
   520 
       
   521     delete iGaugeFrameData->iFrameRMask;
       
   522     iGaugeFrameData->iFrameRMask = NULL;
       
   523 }
       
   524 
       
   525 
       
   526 void CMIDGaugeItem::ResizeBitmapsInTlsL()
       
   527 {
       
   528     // check if thread-local bitmap storage is created
       
   529     if (!iGaugeFrameData)
       
   530     {
       
   531         return;
       
   532     }
       
   533 
       
   534     // get layout info
       
   535     TRect formRect;
       
   536     TRect waitGaugeRect;
       
   537     TRect waitGaugeBarRect;
       
   538     TRect waitGaugeBarFrameLRect;
       
   539     TRect waitGaugeBarFrameCRect;
       
   540     TRect waitGaugeBarFrameRRect;
       
   541     TAknLayoutRect layoutRect;
       
   542     TSize waitGaugeBarRectSize;
       
   543 
       
   544     formRect = FormClientAreaRect();
       
   545 
       
   546     layoutRect.LayoutRect(formRect,
       
   547                           AknLayoutScalable_Avkon::form2_midp_gauge_wait_pane().LayoutLine());
       
   548     waitGaugeRect = layoutRect.Rect();
       
   549 
       
   550     layoutRect.LayoutRect(waitGaugeRect,
       
   551                           AknLayoutScalable_Avkon::form2_midp_wait_pane(1).LayoutLine());
       
   552     waitGaugeBarRect = layoutRect.Rect();
       
   553 
       
   554     layoutRect.LayoutRect(waitGaugeBarRect,
       
   555                           AknLayoutScalable_Avkon::form2_midp_wait_pane_g1().LayoutLine());
       
   556     waitGaugeBarFrameLRect = layoutRect.Rect();
       
   557 
       
   558     layoutRect.LayoutRect(waitGaugeBarRect,
       
   559                           AknLayoutScalable_Avkon::form2_midp_wait_pane_g2().LayoutLine());
       
   560     waitGaugeBarFrameCRect = layoutRect.Rect();
       
   561 
       
   562     layoutRect.LayoutRect(waitGaugeBarRect,
       
   563                           AknLayoutScalable_Avkon::form2_midp_wait_pane_g3().LayoutLine());
       
   564     waitGaugeBarFrameRRect = layoutRect.Rect();
       
   565 
       
   566     waitGaugeBarRectSize = waitGaugeBarRect.Size();
       
   567 
       
   568     // resize bitmaps
       
   569     TInt i;
       
   570 
       
   571     // continuous running bitmaps
       
   572     for (i=0; i < iGaugeFrameData->iContRunBitmap.Count(); i++)
       
   573     {
       
   574         CFbsBitmap* bitmap = iGaugeFrameData->iContRunBitmap[i];
       
   575 
       
   576         if (bitmap->SizeInPixels() != waitGaugeBarRectSize)
       
   577         {
       
   578             User::LeaveIfError(AknIconUtils::SetSize(bitmap,
       
   579                                waitGaugeBarRectSize, EAspectRatioNotPreserved));
       
   580         }
       
   581     }
       
   582 
       
   583     for (i=0; i < iGaugeFrameData->iContRunBitmapMask.Count(); i++)
       
   584     {
       
   585         CFbsBitmap* bitmap = iGaugeFrameData->iContRunBitmapMask[i];
       
   586 
       
   587         if (bitmap->SizeInPixels() != waitGaugeBarRectSize)
       
   588         {
       
   589             User::LeaveIfError(AknIconUtils::SetSize(bitmap,
       
   590                                waitGaugeBarRectSize, EAspectRatioNotPreserved));
       
   591         }
       
   592     }
       
   593 
       
   594     // incremental updating bitmaps
       
   595     for (i=0; i < iGaugeFrameData->iIncUpdBitmap.Count(); i++)
       
   596     {
       
   597         CFbsBitmap* bitmap = iGaugeFrameData->iIncUpdBitmap[i];
       
   598 
       
   599         if (bitmap->SizeInPixels() != waitGaugeBarRectSize)
       
   600         {
       
   601             User::LeaveIfError(AknIconUtils::SetSize(bitmap,
       
   602                                waitGaugeBarRectSize, EAspectRatioNotPreserved));
       
   603         }
       
   604     }
       
   605 
       
   606     for (i=0; i < iGaugeFrameData->iIncUpdBitmapMask.Count(); i++)
       
   607     {
       
   608         CFbsBitmap* bitmap = iGaugeFrameData->iIncUpdBitmapMask[i];
       
   609 
       
   610         if (bitmap->SizeInPixels() != waitGaugeBarRectSize)
       
   611         {
       
   612             User::LeaveIfError(AknIconUtils::SetSize(bitmap,
       
   613                                waitGaugeBarRectSize, EAspectRatioNotPreserved));
       
   614         }
       
   615     }
       
   616 
       
   617     // continuous idle bitmap
       
   618     if (iGaugeFrameData->iContIdleBitmap && (iGaugeFrameData->
       
   619             iContIdleBitmap->SizeInPixels() != waitGaugeBarRectSize))
       
   620     {
       
   621         User::LeaveIfError(AknIconUtils::SetSize(
       
   622                                iGaugeFrameData->iContIdleBitmap, waitGaugeBarRectSize,
       
   623                                EAspectRatioNotPreserved));
       
   624     }
       
   625 
       
   626     if (iGaugeFrameData->iContIdleBitmapMask && (iGaugeFrameData->
       
   627             iContIdleBitmapMask->SizeInPixels() != waitGaugeBarRectSize))
       
   628     {
       
   629         User::LeaveIfError(AknIconUtils::SetSize(
       
   630                                iGaugeFrameData->iContIdleBitmapMask, waitGaugeBarRectSize,
       
   631                                EAspectRatioNotPreserved));
       
   632     }
       
   633 
       
   634     // incremental idle bitmap
       
   635     if (iGaugeFrameData->iIncIdleBitmap && (iGaugeFrameData->
       
   636                                             iIncIdleBitmap->SizeInPixels() != waitGaugeBarRectSize))
       
   637     {
       
   638         User::LeaveIfError(AknIconUtils::SetSize(
       
   639                                iGaugeFrameData->iIncIdleBitmap, waitGaugeBarRectSize,
       
   640                                EAspectRatioNotPreserved));
       
   641     }
       
   642 
       
   643     if (iGaugeFrameData->iIncIdleBitmapMask && (iGaugeFrameData->
       
   644             iIncIdleBitmapMask->SizeInPixels() != waitGaugeBarRectSize))
       
   645     {
       
   646         User::LeaveIfError(AknIconUtils::SetSize(
       
   647                                iGaugeFrameData->iIncIdleBitmapMask, waitGaugeBarRectSize,
       
   648                                EAspectRatioNotPreserved));
       
   649     }
       
   650 
       
   651     // frame bitmaps
       
   652     if (iGaugeFrameData->iFrameL && (iGaugeFrameData->
       
   653                                      iFrameL->SizeInPixels() != waitGaugeBarFrameLRect.Size()))
       
   654     {
       
   655         User::LeaveIfError(AknIconUtils::SetSize(
       
   656                                iGaugeFrameData->iFrameL, waitGaugeBarFrameLRect.Size(),
       
   657                                EAspectRatioNotPreserved));
       
   658     }
       
   659 
       
   660     if (iGaugeFrameData->iFrameLMask && (iGaugeFrameData->
       
   661                                          iFrameLMask->SizeInPixels() != waitGaugeBarFrameLRect.Size()))
       
   662     {
       
   663         User::LeaveIfError(AknIconUtils::SetSize(
       
   664                                iGaugeFrameData->iFrameLMask, waitGaugeBarFrameLRect.Size(),
       
   665                                EAspectRatioNotPreserved));
       
   666     }
       
   667 
       
   668     if (iGaugeFrameData->iFrameCenter && (iGaugeFrameData->
       
   669                                           iFrameCenter->SizeInPixels() != waitGaugeBarFrameCRect.Size()))
       
   670     {
       
   671         User::LeaveIfError(AknIconUtils::SetSize(
       
   672                                iGaugeFrameData->iFrameCenter, waitGaugeBarFrameCRect.Size(),
       
   673                                EAspectRatioNotPreserved));
       
   674     }
       
   675 
       
   676     if (iGaugeFrameData->iFrameCenterMask && (iGaugeFrameData->
       
   677             iFrameCenterMask->SizeInPixels() != waitGaugeBarFrameCRect.Size()))
       
   678     {
       
   679         User::LeaveIfError(AknIconUtils::SetSize(
       
   680                                iGaugeFrameData->iFrameCenterMask, waitGaugeBarFrameCRect.Size(),
       
   681                                EAspectRatioNotPreserved));
       
   682     }
       
   683 
       
   684     if (iGaugeFrameData->iFrameR && (iGaugeFrameData->
       
   685                                      iFrameR->SizeInPixels() != waitGaugeBarFrameRRect.Size()))
       
   686     {
       
   687         User::LeaveIfError(AknIconUtils::SetSize(
       
   688                                iGaugeFrameData->iFrameR, waitGaugeBarFrameRRect.Size(),
       
   689                                EAspectRatioNotPreserved));
       
   690     }
       
   691 
       
   692     if (iGaugeFrameData->iFrameRMask && (iGaugeFrameData->
       
   693                                          iFrameRMask->SizeInPixels() != waitGaugeBarFrameRRect.Size()))
       
   694     {
       
   695         User::LeaveIfError(AknIconUtils::SetSize(
       
   696                                iGaugeFrameData->iFrameRMask, waitGaugeBarFrameRRect.Size(),
       
   697                                EAspectRatioNotPreserved));
       
   698     }
       
   699 }
       
   700 
       
   701 
       
   702 void CMIDGaugeItem::ColorChange(TInt aType)
       
   703 {
       
   704     // call default implementation
       
   705     CMIDControlItem::ColorChange(aType);
       
   706 
       
   707     // recreate bitmaps (current bitmaps are deleted in CreateBitmapsInTlsBitmapsL())
       
   708     TRAPD(createErr, CreateBitmapsInTlsL());
       
   709 
       
   710     if (createErr != KErrNone)
       
   711     {
       
   712         DEBUG_INT("CMIDGaugeItem::ColorChange() - Exception from CreateBitmapsInTlsL. Error = %d ", createErr);
       
   713     }
       
   714 
       
   715     TRAPD(resizeErr, ResizeBitmapsInTlsL());
       
   716 
       
   717     if (resizeErr != KErrNone)
       
   718     {
       
   719         DEBUG_INT("CMIDGaugeItem::ColorChange() - Exception from ResizeBitmapsInTlsL. Error = %d ", resizeErr);
       
   720     }
       
   721 }
       
   722 
       
   723 void CMIDGaugeItem::HandleForegroundL(TBool aForeground)
       
   724 {
       
   725     // synchronize foreground flag
       
   726     iIsInForeground = aForeground;
       
   727 
       
   728     // if continuous-running ni-gauge is in foreground and it's timer
       
   729     // is not created then create it else if gauge is in background
       
   730     // and if it is inserted in form then dispose it's timer
       
   731     if (iIsInForeground)
       
   732     {
       
   733         if ((iIndefiniteState == EContinuousRunning) && (!iTimer))
       
   734         {
       
   735             iTimer = CGaugeTimer::NewL(*this);
       
   736             iTimer->After(TTimeIntervalMicroSeconds32(KDelayInMicroSeconds));
       
   737         }
       
   738     }
       
   739     else if (iForm)
       
   740     {
       
   741         DisposeTimer();
       
   742     }
       
   743 }
       
   744 
       
   745 void CMIDGaugeItem::SetStateL(TInt aMaxValue,TInt aValue)
       
   746 {
       
   747     iIndefinite = (aMaxValue == EIndefinite) ? ETrue : EFalse;
       
   748 
       
   749     if (iIndefinite)
       
   750     {
       
   751         iIndefiniteState = aValue;
       
   752         iValue = 0;
       
   753         switch (aValue)
       
   754         {
       
   755         case EContinuousIdle:
       
   756         case EIncrementalIdle:
       
   757             DisposeTimer();
       
   758             break;
       
   759         case EContinuousRunning:
       
   760             if (!iTimer)
       
   761             {
       
   762                 iTimer = CGaugeTimer::NewL(*this);
       
   763                 iTimer->After(TTimeIntervalMicroSeconds32(KDelayInMicroSeconds));
       
   764             }
       
   765             break;
       
   766         case EIncrementalUpdating:
       
   767             DisposeTimer();
       
   768             break;
       
   769         default:
       
   770             ASSERT(EFalse);
       
   771         }
       
   772     }
       
   773     else
       
   774     {
       
   775     }
       
   776     //
       
   777     // We're now back in normal mode
       
   778     //
       
   779 }
       
   780 
       
   781 #ifdef RD_SCALABLE_UI_V2
       
   782 void CMIDGaugeItem::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   783 {
       
   784     if (AknLayoutUtils::PenEnabled())
       
   785     {
       
   786         if (IsSelectable())
       
   787         {
       
   788             CMIDControlItem::HandlePointerEventL(aPointerEvent);
       
   789         }
       
   790     }
       
   791 }
       
   792 #endif // RD_SCALABLE_UI_V2
       
   793 
       
   794 
       
   795 /**
       
   796  * An interactive Gauge will always be selectable. A non-interactive
       
   797  * Gauge will only be selectable if it has at least one Command.
       
   798  */
       
   799 TBool CMIDGaugeItem::IsSelectable() const
       
   800 {
       
   801     return (iCommandList->Count() > 0 || !IsNonFocusing());
       
   802 }
       
   803 
       
   804 void CMIDGaugeItem::DisposeTimer()
       
   805 {
       
   806     if (iTimer)
       
   807         iTimer->Cancel();
       
   808     delete iTimer;
       
   809     iTimer = NULL;
       
   810 }
       
   811 
       
   812 void CMIDGaugeItem::FocusChanged(TDrawNow aDrawNow)
       
   813 {
       
   814     CMIDControlItem::FocusChanged(aDrawNow);
       
   815 }
       
   816 
       
   817 void CMIDGaugeItem::SetLabelL(const TDesC& aLabel)
       
   818 {
       
   819     CMIDControlItem::SetLabelL(aLabel);
       
   820 }
       
   821 
       
   822 void CMIDGaugeItem::SetLayoutL(TLayout aLayout)
       
   823 {
       
   824     CMIDItem::SetLayoutL(aLayout);
       
   825 }
       
   826 
       
   827 void CMIDGaugeItem::Dispose()
       
   828 {
       
   829     delete this;
       
   830 }
       
   831 
       
   832 void CMIDGaugeItem::AddCommandL(MMIDCommand* aCommand)
       
   833 {
       
   834     CMIDItem::AddCommandL(aCommand);
       
   835 }
       
   836 
       
   837 void CMIDGaugeItem::RemoveCommand(MMIDCommand* aCommand)
       
   838 {
       
   839     CMIDItem::RemoveCommand(aCommand);
       
   840 }
       
   841 
       
   842 void CMIDGaugeItem::SetDefaultCommand(MMIDCommand* aCommand)
       
   843 {
       
   844     CMIDItem::SetDefaultCommand(aCommand);
       
   845 }
       
   846 
       
   847 void CMIDGaugeItem::SetPreferredSizeL(const TSize& aSize)
       
   848 {
       
   849     CMIDItem::SetPreferredSize(aSize,MinimumSize());
       
   850 }
       
   851 
       
   852 TSize CMIDGaugeItem::PreferredSize() const
       
   853 {
       
   854     return ResetPreferredSize();
       
   855 }
       
   856 
       
   857 TSize CMIDGaugeItem::MinimumSize() const
       
   858 {
       
   859     CCoeControl* control = const_cast<CMIDGaugeItem*>(this);
       
   860     return control->MinimumSize();
       
   861 }
       
   862 
       
   863 TInt CMIDGaugeItem::GetIndefiniteState() const
       
   864 {
       
   865     return iIndefiniteState;
       
   866 }
       
   867 //////////////////////////////////////////////////////////////////////////////
       
   868 
       
   869 // ---------------------------------------------------------------------------
       
   870 //
       
   871 // ---------------------------------------------------------------------------
       
   872 //
       
   873 MMIDGauge* CMIDNonInteractiveGauge::NewL(
       
   874     const TDesC& aLabel,TInt aMaxValue,TInt aInitialValue, CMIDUIManager* aUIManager)
       
   875 {
       
   876     CMIDNonInteractiveGauge* self = new(ELeave) CMIDNonInteractiveGauge(aUIManager);
       
   877     CleanupStack::PushL(self);
       
   878     self->BaseConstructL(aLabel, aMaxValue, aInitialValue);
       
   879     self->ConstructL();
       
   880     CleanupStack::Pop(self);
       
   881     return self;
       
   882 }
       
   883 
       
   884 CMIDNonInteractiveGauge::~CMIDNonInteractiveGauge()
       
   885 {
       
   886     DisposeTimer();
       
   887     delete iProgressInfo;
       
   888     delete iBitmapAnimation;
       
   889 }
       
   890 
       
   891 // ---------------------------------------------------------------------------
       
   892 //
       
   893 // ---------------------------------------------------------------------------
       
   894 //
       
   895 CMIDNonInteractiveGauge::CMIDNonInteractiveGauge(CMIDUIManager* aUIManager)
       
   896         : CMIDGaugeItem(aUIManager),
       
   897         iBitmapAnimation(NULL)
       
   898 {
       
   899     SetFocusing(EFalse);
       
   900 }
       
   901 
       
   902 void CMIDNonInteractiveGauge::ConstructL()
       
   903 {
       
   904     UpdateMemberVariables();
       
   905     ConstructProgressInfoL();
       
   906     ActivateL();
       
   907 }
       
   908 
       
   909 void CMIDNonInteractiveGauge::UpdateMemberVariables()
       
   910 {
       
   911     TRect formRect = FormClientAreaRect();
       
   912 
       
   913     iWaitGaugeRect.LayoutRect(formRect,
       
   914                               AknLayoutScalable_Avkon::form2_midp_gauge_wait_pane().LayoutLine());
       
   915 
       
   916     iWaitBarRect.LayoutRect(iWaitGaugeRect.Rect(),
       
   917                             AknLayoutScalable_Avkon::form2_midp_wait_pane(1).LayoutLine());
       
   918 
       
   919     iWaitBarSize = iWaitBarRect.Rect().Size();
       
   920 
       
   921     // WaitBar position in relation to CCoeControl (CMIDControlItem Rect) area
       
   922     // Note that label height has to be added to the y coordinate
       
   923     iProgressInfoWithLabelHeightTl = iWaitBarRect.Rect().iTl - formRect.iTl;
       
   924 
       
   925     iItemheightWithoutLabel = iWaitGaugeRect.Rect().Height() +
       
   926                               iWaitGaugeRect.Rect().iTl.iY - formRect.iTl.iY + ItemContentBottomMargin();
       
   927 }
       
   928 
       
   929 void CMIDNonInteractiveGauge::ConstructProgressInfoL()
       
   930 {
       
   931     ASSERT(!iProgressInfo);
       
   932 
       
   933     CEikProgressInfo::SInfo info;
       
   934     info.iFinalValue = iIndefinite ? 100 : iMaxValue;
       
   935     info.iSplitsInBlock = 0;
       
   936     info.iTextType = EEikProgressTextPercentage;
       
   937 
       
   938     info.iWidth = iWaitBarSize.iWidth;
       
   939     info.iHeight = iWaitBarSize.iHeight;
       
   940 
       
   941     iProgressInfo = new(ELeave) CEikProgressInfo(info);
       
   942     iProgressInfo->ConstructL();
       
   943     iProgressInfo->SetContainerWindowL(*this);
       
   944     iProgressInfo->SetAndDraw(iValue);
       
   945 
       
   946     if (IsActivated())
       
   947     {
       
   948         iProgressInfo->ActivateL();
       
   949     }
       
   950 }
       
   951 
       
   952 void CMIDNonInteractiveGauge::SetValueL(TInt aValue)
       
   953 {
       
   954     if (iIndefinite)
       
   955     {
       
   956         // indefinite gauge will not be updated when it is inserted in form
       
   957         // and the form is sent to background
       
   958         TBool updateGauge = (iForm) ? iIsInForeground : ETrue;
       
   959 
       
   960         // update gauge state
       
   961         TInt oldIndefiniteState = iIndefiniteState;
       
   962         iIndefiniteState = aValue;
       
   963 
       
   964         switch (iIndefiniteState)
       
   965         {
       
   966         case EContinuousIdle:
       
   967             iValue = 0;
       
   968             DisposeTimer();
       
   969             break;
       
   970         case EIncrementalIdle:
       
   971             iValue = 0;
       
   972             DisposeTimer();
       
   973             break;
       
   974         case EContinuousRunning:
       
   975             if (!iTimer && updateGauge)
       
   976             {
       
   977                 iTimer = CGaugeTimer::NewL(*this);
       
   978                 iTimer->After(TTimeIntervalMicroSeconds32(KDelayInMicroSeconds));
       
   979             }
       
   980             break;
       
   981         case EIncrementalUpdating:
       
   982             DisposeTimer();
       
   983 
       
   984             // update gauge's state
       
   985             if (updateGauge)
       
   986             {
       
   987                 if (iIndefiniteState != oldIndefiniteState)
       
   988                 {
       
   989                     iValue = -1;
       
   990                 }
       
   991                 iValue++;
       
   992                 if (iGaugeFrameData && iValue >= iGaugeFrameData->iIncUpdBitmap.Count())
       
   993                 {
       
   994                     iValue = 0;
       
   995                 }
       
   996             }
       
   997             break;
       
   998         default:
       
   999             ASSERT(EFalse);
       
  1000         }
       
  1001 
       
  1002         // update gauge in alert
       
  1003         if (iGaugeToAlertListner)
       
  1004         {
       
  1005             iGaugeToAlertListner->UpdateGaugeInAlertL(iValue);
       
  1006         }
       
  1007 
       
  1008         // eventually notify alert dialog that indefinite state changed
       
  1009         if (iGaugeToAlertListner && (iIndefiniteState != oldIndefiniteState))
       
  1010         {
       
  1011             iGaugeToAlertListner->GaugeTypeInAlertChangedL();
       
  1012         }
       
  1013 
       
  1014         // redraw gauge if it should be updated or if it's type changed
       
  1015         if (updateGauge || (iIndefiniteState != oldIndefiniteState))
       
  1016         {
       
  1017             DoSafeDraw();
       
  1018         }
       
  1019     }
       
  1020     else
       
  1021     {
       
  1022         iValue = aValue;
       
  1023 
       
  1024         if (iGaugeToAlertListner)
       
  1025         {
       
  1026             iGaugeToAlertListner->UpdateGaugeInAlertL(iValue);
       
  1027         }
       
  1028 
       
  1029         DoSafeDraw();
       
  1030     }
       
  1031 }
       
  1032 
       
  1033 void CMIDNonInteractiveGauge::SetGaugeListenerFromAlert(
       
  1034     MMIDGaugeToAlertListner* aGaugeToAlertListner)
       
  1035 {
       
  1036     iGaugeToAlertListner = aGaugeToAlertListner;
       
  1037 }
       
  1038 
       
  1039 void CMIDNonInteractiveGauge::SetMaxValueL(TInt aMaxValue)
       
  1040 {
       
  1041     // is new max value indefinite?
       
  1042     if (aMaxValue == EIndefinite)
       
  1043     {
       
  1044         if (!iIndefinite)
       
  1045         {
       
  1046             // set gauge state to indefinite
       
  1047             iIndefinite = ETrue;
       
  1048             iMaxValue = EIndefinite;
       
  1049 
       
  1050             // set indefinite state to other type than with which
       
  1051             //  SetValueL function will be called in order to detect change
       
  1052             //  of gauge type in this function
       
  1053             iIndefiniteState = EContinuousIdle+1;
       
  1054             SetValueL(EContinuousIdle);
       
  1055         }
       
  1056     }
       
  1057     else
       
  1058     {
       
  1059         // no timer needed for definite gauge
       
  1060         DisposeTimer();
       
  1061 
       
  1062         // set gauge state to definite
       
  1063         iIndefinite = EFalse;
       
  1064         iMaxValue = aMaxValue;
       
  1065 
       
  1066         // check gauge's value
       
  1067         if (iValue > iMaxValue)
       
  1068         {
       
  1069             iValue = iMaxValue;
       
  1070         }
       
  1071         else if (iValue < 0)
       
  1072         {
       
  1073             iValue = 0;
       
  1074         }
       
  1075 
       
  1076         // eventually update gauge in alert
       
  1077         if (iGaugeToAlertListner)
       
  1078         {
       
  1079             iGaugeToAlertListner->GaugeTypeInAlertChangedL();
       
  1080         }
       
  1081 
       
  1082         // redraw
       
  1083         DoSafeDraw();
       
  1084     }
       
  1085 }
       
  1086 
       
  1087 TSize CMIDNonInteractiveGauge::MinimumSize()
       
  1088 {
       
  1089     if (!iLabelControl || (iLabelControl->Text()->Length() == 0))
       
  1090     { // item doesn't have label
       
  1091         return TSize(FormClientAreaWidth(), iItemheightWithoutLabel);
       
  1092     }
       
  1093     else // item has label
       
  1094     {
       
  1095         return TSize(FormClientAreaWidth(),
       
  1096                      iItemheightWithoutLabel + OneLineLabelHeight());
       
  1097     }
       
  1098 }
       
  1099 
       
  1100 TInt CMIDNonInteractiveGauge::CountComponentControls() const
       
  1101 {
       
  1102     if (iIndefinite)
       
  1103     {
       
  1104         return 1; // we will draw the gauge in our Draw() method
       
  1105     }
       
  1106     else
       
  1107     {
       
  1108         return 2;
       
  1109     }
       
  1110 }
       
  1111 
       
  1112 CCoeControl* CMIDNonInteractiveGauge::ComponentControl(TInt aIndex) const
       
  1113 {
       
  1114     switch (aIndex)
       
  1115     {
       
  1116     case 0:
       
  1117         return iLabelControl;
       
  1118     case 1:
       
  1119         return iProgressInfo;
       
  1120     default:
       
  1121         return NULL;
       
  1122     }
       
  1123 }
       
  1124 
       
  1125 /** Unlike other items, this one here draw the backgorund as well because its draw
       
  1126     method is called without drawing the form first. Other items only draw the control.
       
  1127 */
       
  1128 void CMIDNonInteractiveGauge::Draw(const TRect& /*aRect*/) const
       
  1129 {
       
  1130     CWindowGc& gc=SystemGc();
       
  1131 
       
  1132     // get drawing position
       
  1133     TRect rect(Rect());
       
  1134 
       
  1135     // draw background and control
       
  1136     CMIDControlItem::Draw(rect);
       
  1137 
       
  1138 
       
  1139     // draw non-interactive gauge graphics
       
  1140     if (iIndefinite && iGaugeFrameData)
       
  1141     {
       
  1142         // If Gauge animated in current skin, is drawn by iBitmapAnimation.
       
  1143         // Otherwise is drawn in this block of code.
       
  1144         if ((!iBitmapAnimation) || (!(iBitmapAnimation->BitmapAnimData())) ||
       
  1145                 (!(iBitmapAnimation->BitmapAnimData()->FrameArray().Count()> 0)))
       
  1146         {
       
  1147             CFbsBitmap* bitmap = NULL;
       
  1148             CFbsBitmap* bitmapMask = NULL;
       
  1149 
       
  1150             // Finding of correct bitmap and bitmapMask from TLS
       
  1151             switch (iIndefiniteState)
       
  1152             {
       
  1153             case EContinuousIdle:
       
  1154                 bitmap = iGaugeFrameData->iContIdleBitmap;
       
  1155                 bitmapMask = iGaugeFrameData->iContIdleBitmapMask;
       
  1156                 break;
       
  1157             case EIncrementalIdle:
       
  1158                 bitmap = iGaugeFrameData->iIncIdleBitmap;
       
  1159                 bitmapMask = iGaugeFrameData->iIncIdleBitmapMask;
       
  1160                 break;
       
  1161             case EContinuousRunning:
       
  1162                 if ((iValue>=0) &&
       
  1163                         (iValue < iGaugeFrameData->iContRunBitmap.Count()))
       
  1164                 {
       
  1165                     bitmap = iGaugeFrameData->iContRunBitmap[iValue];
       
  1166                 }
       
  1167                 if ((iValue>=0) &&
       
  1168                         (iValue < iGaugeFrameData->iContRunBitmapMask.Count()))
       
  1169                 {
       
  1170                     bitmapMask = iGaugeFrameData->iContRunBitmapMask[iValue];
       
  1171                 }
       
  1172                 break;
       
  1173             case EIncrementalUpdating:
       
  1174                 if ((iValue>=0) &&
       
  1175                         (iValue < iGaugeFrameData->iIncUpdBitmap.Count()))
       
  1176                 {
       
  1177                     bitmap = iGaugeFrameData->iIncUpdBitmap[iValue];
       
  1178                 }
       
  1179                 if ((iValue>=0) &&
       
  1180                         (iValue < iGaugeFrameData->iIncUpdBitmapMask.Count()))
       
  1181                 {
       
  1182                     bitmapMask = iGaugeFrameData->iIncUpdBitmapMask[iValue];
       
  1183                 }
       
  1184                 break;
       
  1185             default:
       
  1186                 ASSERT(EFalse);
       
  1187             }
       
  1188 
       
  1189             // get drawing position
       
  1190             TPoint drawPosition = Position() + iProgressInfoWithLabelHeightTl +
       
  1191                                   TPoint(0,LabelHeight());
       
  1192 
       
  1193             // draw gague bar
       
  1194             if (bitmap && bitmapMask)
       
  1195             {
       
  1196                 TSize bitmapSize = bitmap->SizeInPixels();
       
  1197                 TRect bitmapRect = TRect(0, 0, bitmapSize.iWidth, bitmapSize.iHeight);
       
  1198                 gc.BitBltMasked(drawPosition, bitmap, bitmapRect, bitmapMask, EFalse);
       
  1199             }
       
  1200             else if (bitmap)
       
  1201             {
       
  1202                 gc.BitBlt(drawPosition, bitmap);
       
  1203             }
       
  1204         }
       
  1205     }
       
  1206 
       
  1207     TPoint drawPositionFrame = Position() + iProgressInfoWithLabelHeightTl +
       
  1208                                TPoint(0,LabelHeight());
       
  1209     // draw gague bar frame
       
  1210     if (iGaugeFrameData && iGaugeFrameData->iFrameL && iGaugeFrameData->iFrameLMask &&
       
  1211             iGaugeFrameData->iFrameCenter && iGaugeFrameData->iFrameCenterMask &&
       
  1212             iGaugeFrameData->iFrameR && iGaugeFrameData->iFrameRMask)
       
  1213     {
       
  1214         // draw of left frame of gauge bar
       
  1215         gc.BitBltMasked(drawPositionFrame, iGaugeFrameData->iFrameL,
       
  1216                         TRect(iGaugeFrameData->iFrameL->SizeInPixels()),
       
  1217                         iGaugeFrameData->iFrameLMask, EFalse);
       
  1218 
       
  1219         // draw of central frame of gauge bar
       
  1220         drawPositionFrame.iX += iGaugeFrameData->iFrameL->SizeInPixels().iWidth;
       
  1221 
       
  1222         gc.BitBltMasked(drawPositionFrame, iGaugeFrameData->iFrameCenter,
       
  1223                         TRect(iGaugeFrameData->iFrameCenter->SizeInPixels()),
       
  1224                         iGaugeFrameData->iFrameCenterMask, EFalse);
       
  1225 
       
  1226         // draw of right frame of gauge bar
       
  1227         drawPositionFrame.iX += iGaugeFrameData->iFrameCenter->SizeInPixels().iWidth;
       
  1228 
       
  1229         gc.BitBltMasked(drawPositionFrame, iGaugeFrameData->iFrameR,
       
  1230                         TRect(iGaugeFrameData->iFrameR->SizeInPixels()),
       
  1231                         iGaugeFrameData->iFrameRMask, EFalse);
       
  1232     }
       
  1233 }
       
  1234 
       
  1235 void CMIDNonInteractiveGauge::SizeChanged()
       
  1236 {
       
  1237     // Base implemation
       
  1238     CMIDControlItem::SizeChanged();
       
  1239 
       
  1240     // If Gauge is animated, the animation will be resized.
       
  1241     if (iBitmapAnimation && iBitmapAnimation->BitmapAnimData() &&
       
  1242             iBitmapAnimation->BitmapAnimData()->FrameArray().Count()> 0)
       
  1243     {
       
  1244         // Stoping of animation.
       
  1245         iBitmapAnimation->CancelAnimation();
       
  1246         // Resizing of animation
       
  1247         SetAnimationSize();
       
  1248 
       
  1249         // Start of animation
       
  1250         TRAPD(errStart, iBitmapAnimation->StartAnimationL());
       
  1251         if (errStart != KErrNone)
       
  1252         {
       
  1253             DEBUG_INT("CMIDNonInteractiveGauge::SizeChanged() - Exception from CAknBitmapAnimation::StartAnimationL(). Error = %d ", errStart);
       
  1254         }
       
  1255 
       
  1256         // Setting of animation mode (cycle).
       
  1257         TRAPD(errSet, iBitmapAnimation->Animation().SetPlayModeL(CBitmapAnimClientData::ECycle));
       
  1258         if (errSet != KErrNone)
       
  1259         {
       
  1260             DEBUG_INT("CMIDNonInteractiveGauge::SizeChanged() - Exception from RBitmapAnim::SetPlayModeL(). Error = %d ", errSet);
       
  1261         }
       
  1262 
       
  1263     }
       
  1264 
       
  1265     // Resizing of label.
       
  1266     iLabelControl->SetExtent(Position(), TSize(FormClientAreaWidth(), LabelHeight()));
       
  1267 
       
  1268     // Positioning progress bar
       
  1269     TPoint p = Position() + iProgressInfoWithLabelHeightTl + TPoint(0,LabelHeight());
       
  1270     iProgressInfo->SetExtent(p, iProgressInfo->Size());
       
  1271 }
       
  1272 
       
  1273 void CMIDNonInteractiveGauge::SetContainerWindowL(const CCoeControl& aContainer)
       
  1274 {
       
  1275     CreateBitmapsIfNeededL();
       
  1276     CMIDControlItem::SetContainerWindowL(aContainer);
       
  1277     iProgressInfo->SetContainerWindowL(*this);
       
  1278 #ifdef RD_SCALABLE_UI_V2
       
  1279     //Enable cancelation of long tap i.e. up event is grabbed from long tap animation
       
  1280     DrawableWindow()->SetPointerGrab(ETrue);
       
  1281 #endif //RD_SCALABLE_UI_V2
       
  1282 }
       
  1283 
       
  1284 void CMIDNonInteractiveGauge::DoSafeDraw()
       
  1285 {
       
  1286     if (iForm && DrawableWindow())
       
  1287     {
       
  1288         if (!iIndefinite && iProgressInfo->DrawableWindow())
       
  1289         {
       
  1290             iProgressInfo->SetFinalValue(iMaxValue);
       
  1291             iProgressInfo->SetAndDraw(iValue);
       
  1292         }
       
  1293 
       
  1294         DrawNow();
       
  1295     }
       
  1296 }
       
  1297 
       
  1298 #ifdef RD_SCALABLE_UI_V2
       
  1299 void CMIDNonInteractiveGauge::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
  1300 {
       
  1301     if (AknLayoutUtils::PenEnabled())
       
  1302     {
       
  1303 #ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK
       
  1304         if (!iForm->TryDetectLongTapL(aPointerEvent) &&
       
  1305                 !iForm->IsFocusChangingWithPen())
       
  1306         {
       
  1307             switch (aPointerEvent.iType)
       
  1308             {
       
  1309             case TPointerEvent::EButton1Down:
       
  1310             case TPointerEvent::EButton1Up:
       
  1311                 MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  1312                 if (feedback)
       
  1313                 {
       
  1314                     feedback->InstantFeedback(ETouchFeedbackList);
       
  1315                 }
       
  1316                 break;
       
  1317             }
       
  1318         }
       
  1319 #else
       
  1320         iForm->TryDetectLongTapL(aPointerEvent);
       
  1321 #endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK        
       
  1322 
       
  1323     }
       
  1324 }
       
  1325 #endif // RD_SCALABLE_UI_V2
       
  1326 
       
  1327 TInt CMIDNonInteractiveGauge::ItemPreferredHeightWithoutLabel()
       
  1328 {
       
  1329     return iItemheightWithoutLabel;
       
  1330 }
       
  1331 
       
  1332 TInt CMIDNonInteractiveGauge::GetMaxValue()
       
  1333 {
       
  1334     return iMaxValue;
       
  1335 }
       
  1336 
       
  1337 /* ResolutionChange
       
  1338  *
       
  1339  * This method is called after dynamic resolution change
       
  1340  */
       
  1341 
       
  1342 void CMIDNonInteractiveGauge::ResolutionChange(TInt /*aType*/)
       
  1343 {
       
  1344     // update member variables
       
  1345     UpdateMemberVariables();
       
  1346 
       
  1347     // resize bitmaps in TLS
       
  1348     TRAPD(resizeErr, ResizeBitmapsInTlsL());
       
  1349     if (resizeErr != KErrNone)
       
  1350     {
       
  1351         DEBUG_INT("CMIDNonInteractiveGauge::ResolutionChange() - Exception from ResizeBitmapsInTlsL. Error = %d ", resizeErr);
       
  1352     }
       
  1353 
       
  1354     // update progressinfo
       
  1355     delete iProgressInfo;
       
  1356     iProgressInfo = NULL;
       
  1357     TRAPD(err, ConstructProgressInfoL());
       
  1358     if (err != KErrNone)
       
  1359     {
       
  1360         DEBUG_INT("NonInteractiveGauge::ResolutionChange - Exception from ConstructProgressInfoL. Error = %d", err);
       
  1361     }
       
  1362 }
       
  1363 
       
  1364 void CMIDNonInteractiveGauge::ConstructAnimation(CAknBitmapAnimation* aBitmapAnimation)
       
  1365 {
       
  1366     // Setting aBitmapAnimation context into this (first stage).
       
  1367     aBitmapAnimation->CopyControlContextFrom(this);
       
  1368     aBitmapAnimation->SetMopParent(this);
       
  1369 
       
  1370     // Setting of CCoeBrushAndPenContext for aBitmapAnimation
       
  1371     CCoeBrushAndPenContext* brushAndPenContext = NULL;
       
  1372     TRAPD(err, brushAndPenContext = CCoeBrushAndPenContext::NewL());
       
  1373     if (err != KErrNone)
       
  1374     {
       
  1375         DEBUG_INT("CMIDNonInteractiveGauge::ResolutionChange() - Exception fromCCoeBrushAndPenContext::NewL. Error = %d ", err);
       
  1376     }
       
  1377 
       
  1378     // Setting aBitmapAnimation context into this (second stage).
       
  1379     aBitmapAnimation->SetControlContext(brushAndPenContext);
       
  1380 
       
  1381     // If iBitmapAnimation exists, it have  to been deleted.
       
  1382     if (iBitmapAnimation)
       
  1383     {
       
  1384         delete iBitmapAnimation;
       
  1385         iBitmapAnimation = NULL;
       
  1386     }
       
  1387 
       
  1388     // Set aAnimation like iBitmapAnimation
       
  1389     iBitmapAnimation = aBitmapAnimation;
       
  1390 }
       
  1391 
       
  1392 void CMIDNonInteractiveGauge::ItemAddedToFormL()
       
  1393 {
       
  1394     // call parent's implementation
       
  1395     CMIDGaugeItem::ItemAddedToFormL();
       
  1396 
       
  1397     CAknBitmapAnimation* bitmapAnimation = CAknBitmapAnimation::NewL();
       
  1398     CleanupStack::PushL(bitmapAnimation);
       
  1399 
       
  1400     TRect waitGaugeRect;
       
  1401 
       
  1402     // setting of window of bitmapAnimation to this
       
  1403     bitmapAnimation->SetContainerWindowL(*this);
       
  1404 
       
  1405     // costruction of bitmapAnimation by ID of Gauge
       
  1406     bitmapAnimation->ConstructFromSkinL(GetAknsItemID());
       
  1407 
       
  1408     CleanupStack::Pop(bitmapAnimation);
       
  1409 
       
  1410     // If bitmapAnimation exist, set bitmapAnimation to IBitmapAnimation.
       
  1411     if (bitmapAnimation && bitmapAnimation->BitmapAnimData()->FrameArray().Count() > 0)
       
  1412     {
       
  1413         ConstructAnimation(bitmapAnimation);
       
  1414     }
       
  1415     // Else create Bitmap in TLS.
       
  1416     else
       
  1417     {
       
  1418         CreateBitmapsIfNeededL();
       
  1419     }
       
  1420 
       
  1421     // initially assume that gauge is in foreground so that indefinite ni-gauges
       
  1422     // can be updated and redrawn (gauge can be inserted into form after form
       
  1423     // is moved to foreground -> no notification to gauge)
       
  1424     HandleForegroundL(ETrue);
       
  1425 }
       
  1426 
       
  1427 void CMIDNonInteractiveGauge::ItemRemovedFromForm()
       
  1428 {
       
  1429     // call parent's implementation
       
  1430     CMIDGaugeItem::ItemRemovedFromForm();
       
  1431 
       
  1432     // if indefinite ni-gauge is removed from form then no notifications
       
  1433     // about moving to foreground/background are sent and so in order to ensure
       
  1434     // full functionality it is assumed that gauge is in foreground
       
  1435     TRAPD(err, HandleForegroundL(ETrue));
       
  1436 
       
  1437     if (err != KErrNone)
       
  1438     {
       
  1439         DEBUG_INT("CMIDNonInteractiveGauge::ItemRemovedFromForm() - Exception from HandleForegroundL. Error = %d ", err);
       
  1440     }
       
  1441 
       
  1442     // When NonInteractiveGauge was removed from form, then animation
       
  1443     // must be deleted because uses form's window.
       
  1444     if (iBitmapAnimation)
       
  1445     {
       
  1446         delete iBitmapAnimation;
       
  1447         iBitmapAnimation = NULL;
       
  1448     }
       
  1449 }
       
  1450 
       
  1451 void CMIDNonInteractiveGauge::ColorChange(TInt aType)
       
  1452 {
       
  1453     // The original CMIDNonInteractiveGauge::ColorChange is using
       
  1454     // CleanupStack::PushL( bitmapAnimation ); in non-leavung method.
       
  1455     // Codescanner notices this as an error.
       
  1456     TRAPD(creatingErr, ColorChangeL(aType));
       
  1457     if (creatingErr != KErrNone)
       
  1458     {
       
  1459         DEBUG_INT("CMIDNonInteractiveGauge::ColorChange() - Exception. Error = %d ", creatingErr);
       
  1460     }
       
  1461 }
       
  1462 
       
  1463 void CMIDNonInteractiveGauge::ColorChangeL(TInt aType)
       
  1464 {
       
  1465     // stopping and deleting iBitmapAnimation
       
  1466     if (iBitmapAnimation && iBitmapAnimation->BitmapAnimData()->FrameArray().Count()> 0)
       
  1467     {
       
  1468         iBitmapAnimation->CancelAnimation();
       
  1469         delete iBitmapAnimation;
       
  1470         iBitmapAnimation = NULL;
       
  1471     }
       
  1472 
       
  1473     // creating new instance of CAknBitmapAnimation for Gauge animation in new skin
       
  1474     CAknBitmapAnimation* bitmapAnimation = NULL;
       
  1475     TRAPD(creatingErr, bitmapAnimation = CAknBitmapAnimation::NewL());
       
  1476     if (creatingErr != KErrNone)
       
  1477     {
       
  1478         DEBUG_INT("CMIDNonInteractiveGauge::ColorChange() - Exception from CAknBitmapAnimation::NewL. Error = %d ", creatingErr);
       
  1479     }
       
  1480 
       
  1481     // CleanupStack::PushL can not be in TRAPD macro.
       
  1482     CleanupStack::PushL(bitmapAnimation);
       
  1483 
       
  1484     // setting of window of bitmapAnimation to this
       
  1485     TRAPD(setErr, bitmapAnimation->SetContainerWindowL(*this));
       
  1486     if (setErr != KErrNone)
       
  1487     {
       
  1488         DEBUG_INT("CMIDNonInteractiveGauge::ColorChange() - Exception from CAknBitmapAnimation::SetContainerWindowL. Error = %d ", setErr);
       
  1489     }
       
  1490 
       
  1491     // costruction of bitmapAnimation by ID of Gauge
       
  1492     TRAPD(constructErr, bitmapAnimation->ConstructFromSkinL(GetAknsItemID()));
       
  1493     if (constructErr != KErrNone)
       
  1494     {
       
  1495         DEBUG_INT("CMIDNonInteractiveGauge::ColorChange() - Exception from CAknBitmapAnimation::ConstructFromSkinL. Error = %d ", constructErr);
       
  1496     }
       
  1497 
       
  1498     CleanupStack::Pop(bitmapAnimation);
       
  1499 
       
  1500     // If bitmapAnimation exist, it sets bitmapAnimation to IBitmapAnimation and
       
  1501     // sets correct size iBitmapAnimation.
       
  1502     if (bitmapAnimation->BitmapAnimData()->FrameArray().Count()> 0)
       
  1503     {
       
  1504         // call of parent's implementation
       
  1505         CMIDGaugeItem::ColorChange(aType);
       
  1506 
       
  1507         // setting bitmapAnimation to IBitmapAnimation
       
  1508         ConstructAnimation(bitmapAnimation);
       
  1509 
       
  1510         // settting correct size iBitmapAnimation
       
  1511         SetAnimationSize();
       
  1512 
       
  1513         // Start of playing iBitmapAnimation
       
  1514         TRAPD(errStart, iBitmapAnimation->StartAnimationL());
       
  1515         if (errStart != KErrNone)
       
  1516         {
       
  1517             DEBUG_INT("CMIDNonInteractiveGauge::ColorChange() - Exception from CAknBitmapAnimation::StartAnimationL(). Error = %d ", errStart);
       
  1518         }
       
  1519 
       
  1520         // Setting of animation mode (cycle).
       
  1521         TRAPD(errSet, iBitmapAnimation->Animation().SetPlayModeL(CBitmapAnimClientData::ECycle));
       
  1522         if (errSet != KErrNone)
       
  1523         {
       
  1524             DEBUG_INT("CMIDNonInteractiveGauge::ColorChange() - Exception from RBitmapAnim::SetPlayModeL(). Error = %d ", errSet);
       
  1525         }
       
  1526     }
       
  1527     else
       
  1528     {
       
  1529         // call parent's implementation
       
  1530         CMIDGaugeItem::ColorChange(aType);
       
  1531     }
       
  1532 
       
  1533     // send resource change event to progress info
       
  1534     if (iProgressInfo)
       
  1535     {
       
  1536         iProgressInfo->HandleResourceChange(aType);
       
  1537     }
       
  1538 }
       
  1539 
       
  1540 void CMIDNonInteractiveGauge::UpdateProgressInfo(CEikProgressInfo* aProgressInfo) const
       
  1541 {
       
  1542     if (!iProgressInfo || !aProgressInfo)
       
  1543     {
       
  1544         return;
       
  1545     }
       
  1546     aProgressInfo->SetFinalValue(iProgressInfo->Info().iFinalValue);
       
  1547 }
       
  1548 
       
  1549 void CMIDNonInteractiveGauge::SetAnimationSize()
       
  1550 {
       
  1551     // When Gauge is animated and initialized, then Get the right rect for the animation.
       
  1552     if (iBitmapAnimation && iForm)
       
  1553     {
       
  1554         TRect parentRect = FormClientAreaRect();
       
  1555         TRect waitGaugeBarRect;
       
  1556         TRect waitGaugeRect;
       
  1557         TAknLayoutRect layoutRect;
       
  1558         TSize waitGaugeBarRectSize;
       
  1559         TRect animationRect;
       
  1560 
       
  1561         // computing layout for whole Gauge
       
  1562         layoutRect.LayoutRect(parentRect,
       
  1563                               AknLayoutScalable_Avkon::form2_midp_gauge_wait_pane().LayoutLine());
       
  1564         waitGaugeRect = layoutRect.Rect();
       
  1565 
       
  1566         // computing layout for animation rectagle
       
  1567         layoutRect.LayoutRect(waitGaugeRect,
       
  1568                               AknLayoutScalable_Avkon::form2_midp_wait_pane(1).LayoutLine());
       
  1569         waitGaugeBarRect = layoutRect.Rect();
       
  1570 
       
  1571         // moving rectagle for animation to correct position
       
  1572         waitGaugeBarRectSize = waitGaugeBarRect.Size();
       
  1573         TPoint drawPosition = Position() + iProgressInfoWithLabelHeightTl +
       
  1574                               TPoint(0,LabelHeight());
       
  1575         animationRect = TRect(drawPosition.iX, drawPosition.iY,
       
  1576                               drawPosition.iX + waitGaugeBarRectSize.iWidth,
       
  1577                               drawPosition.iY + waitGaugeBarRectSize.iHeight);
       
  1578 
       
  1579         // setting EAspectRatioNotPreserved mode for SetRect;
       
  1580         // This prevent of wrong scalling.
       
  1581         iBitmapAnimation->SetScaleModeForAnimationFrames(EAspectRatioNotPreserved);
       
  1582 
       
  1583         //Scalling of iBitmapAnimation
       
  1584         iBitmapAnimation->SetRect(animationRect);
       
  1585     }
       
  1586 }
       
  1587 
       
  1588 TAknsItemID CMIDNonInteractiveGauge::GetAknsItemID()
       
  1589 {
       
  1590     if (GetMaxValue() <= 0)
       
  1591     {
       
  1592         switch (GetIndefiniteState())
       
  1593         {
       
  1594         case MMIDGauge::EContinuousIdle: // continuous idle
       
  1595         {
       
  1596             return KAknsIIDQgnGrafBarWaitIdle;
       
  1597         }
       
  1598         case MMIDGauge::EContinuousRunning: // continuous running
       
  1599         {
       
  1600             return KAknsIIDQgnGrafBarWaitAnim;
       
  1601         }
       
  1602         case MMIDGauge::EIncrementalUpdating: //incremental updating
       
  1603         {
       
  1604             return KAknsIIDQgnGrafBarWaitIncrem;
       
  1605         }
       
  1606         case MMIDGauge::EIncrementalIdle: //incremental idle
       
  1607         {
       
  1608             return KAknsIIDQgnGrafBarWaitIncremIdle;
       
  1609         }
       
  1610         default:
       
  1611             return KAknsIIDNone;
       
  1612         }
       
  1613     }
       
  1614     return KAknsIIDNone;
       
  1615 }
       
  1616 
       
  1617 // ---------------------------------------------------------------------------
       
  1618 //
       
  1619 // ---------------------------------------------------------------------------
       
  1620 //
       
  1621 
       
  1622 MMIDGauge* CMIDInteractiveGauge::NewL(
       
  1623     const TDesC& aLabel,TInt aMaxValue,TInt aInitialValue, CMIDUIManager* aUIManager)
       
  1624 {
       
  1625     CMIDInteractiveGauge* self = new(ELeave) CMIDInteractiveGauge(aUIManager);
       
  1626     CleanupStack::PushL(self);
       
  1627     self->BaseConstructL(aLabel, aMaxValue, aInitialValue);
       
  1628     self->ConstructL();
       
  1629 
       
  1630     CleanupStack::Pop(self);
       
  1631 
       
  1632     return self;
       
  1633 }
       
  1634 
       
  1635 CMIDInteractiveGauge::~CMIDInteractiveGauge()
       
  1636 {
       
  1637 }
       
  1638 
       
  1639 
       
  1640 CMIDInteractiveGauge::CMIDInteractiveGauge(CMIDUIManager* aUIManager)
       
  1641         : CMIDGaugeItem(aUIManager)
       
  1642 {
       
  1643     SetFocusing(ETrue);
       
  1644 }
       
  1645 
       
  1646 // ---------------------------------------------------------------------------
       
  1647 //
       
  1648 // ---------------------------------------------------------------------------
       
  1649 //
       
  1650 
       
  1651 void CMIDInteractiveGauge::ConstructL()
       
  1652 {
       
  1653     iIndefinite = (iMaxValue == EIndefinite);
       
  1654 
       
  1655     UpdateMemberVariables();
       
  1656 
       
  1657     ConstructSliderL();
       
  1658 
       
  1659     ActivateL();
       
  1660 }
       
  1661 
       
  1662 void CMIDInteractiveGauge::UpdateMemberVariables()
       
  1663 {
       
  1664     TRect formRect = FormClientAreaRect();
       
  1665 
       
  1666     iSliderGaugeRect.LayoutRect(formRect,
       
  1667                                 AknLayoutScalable_Avkon::form2_midp_gauge_slider_pane().LayoutLine());
       
  1668 
       
  1669     // Slider position in relation to CCoeControl (CMIDControlItem Rect) area
       
  1670     iSliderPositionTl = iSliderGaugeRect.Rect().iTl - formRect.iTl;
       
  1671 
       
  1672     iItemheightWithoutLabel = iSliderGaugeRect.Rect().Height() +
       
  1673                               iSliderPositionTl.iY + ItemContentBottomMargin();
       
  1674 }
       
  1675 
       
  1676 void CMIDInteractiveGauge::ConstructSliderL()
       
  1677 {
       
  1678     ASSERT(!iSlider);
       
  1679     iSlider = new(ELeave) CAknSlider();
       
  1680     TResourceReader reader;
       
  1681     iCoeEnv->CreateResourceReaderLC(reader, R_MIDP_SLIDER_DEFAULT);
       
  1682     iSlider->HandleResourceChange(KEikMessageCaptionedControlEditableStateChange);
       
  1683     iSlider->ConstructFromResourceL(reader);
       
  1684     CleanupStack::PopAndDestroy();    // reader
       
  1685 
       
  1686     iSlider->SetRange(0, iMaxValue);
       
  1687     iSlider->SetStepSize(1);
       
  1688     iSlider->SetValueL(iValue);
       
  1689     TBuf<10> number;
       
  1690     number.Num(0);
       
  1691     iSlider->SetMinimumTextL(number);
       
  1692     number.Num(iMaxValue);
       
  1693     iSlider->SetMaximumTextL(number);
       
  1694 
       
  1695     iSlider->SetSize(TSize(iSliderGaugeRect.Rect().Width(), iSliderGaugeRect.Rect().Height()));
       
  1696 }
       
  1697 
       
  1698 void CMIDInteractiveGauge::SetValueL(TInt aValue)
       
  1699 {
       
  1700     iValue = aValue;
       
  1701     iSlider->SetValueL(iValue);
       
  1702     DoSafeDraw();
       
  1703 }
       
  1704 
       
  1705 void CMIDInteractiveGauge::SetMaxValueL(TInt aValue)
       
  1706 {
       
  1707     iMaxValue = aValue;
       
  1708     if (iValue > iMaxValue)
       
  1709     {
       
  1710         iValue = iMaxValue;
       
  1711         iSlider->SetValueL(iValue);
       
  1712     }
       
  1713     TBuf<10> number;
       
  1714     number.Num(iMaxValue);
       
  1715     iSlider->SetMaximumTextL(number);
       
  1716     iSlider->SetRange(0, iMaxValue);
       
  1717     DoSafeDraw();
       
  1718 }
       
  1719 
       
  1720 TSize CMIDInteractiveGauge::MinimumSize()
       
  1721 {
       
  1722     if (!iLabelControl || (iLabelControl->Text()->Length() == 0))
       
  1723     { // item doesn't have label
       
  1724         return TSize(FormClientAreaWidth(), iItemheightWithoutLabel);
       
  1725     }
       
  1726     else // item has label
       
  1727     {
       
  1728         return TSize(FormClientAreaWidth(), iItemheightWithoutLabel + OneLineLabelHeight());
       
  1729     }
       
  1730 }
       
  1731 
       
  1732 TInt CMIDInteractiveGauge::CountComponentControls() const
       
  1733 {
       
  1734     return 2;
       
  1735 }
       
  1736 
       
  1737 CCoeControl* CMIDInteractiveGauge::ComponentControl(TInt aIndex) const
       
  1738 {
       
  1739     switch (aIndex)
       
  1740     {
       
  1741     case 0:
       
  1742         return iLabelControl;
       
  1743     case 1:
       
  1744         return iSlider;
       
  1745     default:
       
  1746         return NULL;
       
  1747     }
       
  1748 }
       
  1749 
       
  1750 void CMIDInteractiveGauge::Draw(const TRect& aRect) const
       
  1751 {
       
  1752     CMIDControlItem::Draw(aRect);
       
  1753 }
       
  1754 
       
  1755 void CMIDInteractiveGauge::SizeChanged()
       
  1756 {
       
  1757     CMIDControlItem::SizeChanged();
       
  1758 
       
  1759     iLabelControl->SetExtent(Position() , TSize(FormClientAreaWidth(), LabelHeight()));
       
  1760     iSlider->SetExtent(Position() +
       
  1761                        TSize(iSliderPositionTl.iX, LabelHeight()), iSlider->Size());
       
  1762 }
       
  1763 
       
  1764 void CMIDInteractiveGauge::PositionChanged()
       
  1765 {
       
  1766     iSlider->SetExtent(Position() +
       
  1767                        TSize(iSliderPositionTl.iX, LabelHeight()), iSlider->Size());
       
  1768 }
       
  1769 
       
  1770 void CMIDInteractiveGauge::SetContainerWindowL(const CCoeControl& aContainer)
       
  1771 {
       
  1772     CMIDControlItem::SetContainerWindowL(aContainer);
       
  1773     iSlider->SetContainerWindowL(*this);
       
  1774 #ifdef RD_SCALABLE_UI_V2
       
  1775     if (AknLayoutUtils::PenEnabled())
       
  1776     {
       
  1777         iSlider->EnableDrag();
       
  1778     }
       
  1779 #endif // RD_SCALABLE_UI_V2
       
  1780     SetObserver(iForm);
       
  1781 }
       
  1782 
       
  1783 void CMIDInteractiveGauge::DoSafeDraw()
       
  1784 {
       
  1785     if (DrawableWindow())
       
  1786     {
       
  1787         DrawNow();
       
  1788     }
       
  1789 }
       
  1790 
       
  1791 TInt CMIDInteractiveGauge::ItemPreferredHeightWithoutLabel()
       
  1792 {
       
  1793     return iItemheightWithoutLabel;
       
  1794 }
       
  1795 
       
  1796 TKeyResponse CMIDInteractiveGauge::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
  1797 {
       
  1798     TBool valueChanged = EFalse;
       
  1799     if (aType != EEventKey ||
       
  1800             (aKeyEvent.iCode != EKeyLeftArrow && aKeyEvent.iCode != EKeyRightArrow) ||
       
  1801             IsNonFocusing())
       
  1802     {
       
  1803         return EKeyWasNotConsumed;
       
  1804     }
       
  1805     iValue = iSlider->Value();
       
  1806     if (aKeyEvent.iCode == EKeyLeftArrow)
       
  1807     {
       
  1808         if (iValue > 0)
       
  1809         {
       
  1810             iValue -= 1;
       
  1811             iSlider->SetValueL(iValue);
       
  1812             valueChanged = ETrue;
       
  1813         }
       
  1814     }
       
  1815     else if (aKeyEvent.iCode == EKeyRightArrow)
       
  1816     {
       
  1817         if (iValue < iMaxValue)
       
  1818         {
       
  1819             iValue += 1;
       
  1820             iSlider->SetValueL(iValue);
       
  1821             valueChanged = ETrue;
       
  1822         }
       
  1823     }
       
  1824 
       
  1825     if (valueChanged)
       
  1826     {
       
  1827         ReportEventL(MCoeControlObserver::EEventStateChanged);
       
  1828     }
       
  1829     DoSafeDraw();
       
  1830 
       
  1831     return EKeyWasConsumed;
       
  1832 }
       
  1833 
       
  1834 #ifdef RD_SCALABLE_UI_V2
       
  1835 void CMIDInteractiveGauge::HandlePointerEventL(const TPointerEvent &aPointerEvent)
       
  1836 {
       
  1837     if (AknLayoutUtils::PenEnabled())
       
  1838     {
       
  1839         if (aPointerEvent.iType == TPointerEvent::EButton1Down && !iForm->PhysicsScrolling())
       
  1840         {
       
  1841             iPhysicsScrollingTriggered = EFalse;
       
  1842             iOriginalSliderValue = iSlider->Value();
       
  1843         }
       
  1844         // Enlarge the control area by changing the pointer y-position
       
  1845         // close to center of graphics area.
       
  1846         TPointerEvent pEvent = aPointerEvent;
       
  1847         TBool sliderArea = iSlider->Rect().Contains(aPointerEvent.iPosition);
       
  1848         if (sliderArea)
       
  1849         {
       
  1850             pEvent.iPosition.iY = iSlider->Rect().iTl.iY +
       
  1851                                   ((iSlider->Rect().iBr.iY - iSlider->Rect().iTl.iY) /
       
  1852                                    KSliderHeightDivider);
       
  1853         }
       
  1854         CMIDGaugeItem::HandlePointerEventL(pEvent);
       
  1855         if (iValue != iSlider->Value() && !iForm->PhysicsScrolling())
       
  1856         {
       
  1857             iValue = iSlider->Value();
       
  1858             ReportEventL(MCoeControlObserver::EEventStateChanged);
       
  1859             return;
       
  1860         }
       
  1861         if (sliderArea && iForm->PhysicsScrolling() && !iPhysicsScrollingTriggered)
       
  1862         {
       
  1863             //Physics scrolling triggered, set new slider value.
       
  1864             iPhysicsScrollingTriggered = ETrue;
       
  1865             iSlider->SetValueL(iValue);
       
  1866             return;
       
  1867         }
       
  1868 
       
  1869         iForm->TryDetectLongTapL(aPointerEvent);
       
  1870     }
       
  1871 }
       
  1872 
       
  1873 #endif // RD_SCALABLE_UI_V2
       
  1874 
       
  1875 /* ResolutionChange
       
  1876  *
       
  1877  * This method is called after dynamic resolution change
       
  1878  */
       
  1879 void CMIDInteractiveGauge::ResolutionChange(TInt aType)
       
  1880 {
       
  1881     UpdateMemberVariables();
       
  1882     iSlider->HandleResourceChange(aType);
       
  1883     iSlider->SetSize(TSize(iSliderGaugeRect.Rect().Width(), iSliderGaugeRect.Rect().Height()));
       
  1884 }
       
  1885 
       
  1886 // End of File