uifw/AvKon/src/aknbattery.cpp
branchRCL_3
changeset 19 aecbbf00d063
parent 10 3d340a0166ff
child 20 d48ab3b357f1
equal deleted inserted replaced
18:fcdfafb36fe7 19:aecbbf00d063
     1 /*
     1 /*
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    23 #include <AknsDrawUtils.h>
    23 #include <AknsDrawUtils.h>
    24 #include <eikspane.h>
    24 #include <eikspane.h>
    25 #include <aknlayoutscalable_avkon.cdl.h>
    25 #include <aknlayoutscalable_avkon.cdl.h>
    26 #include <layoutmetadata.cdl.h>
    26 #include <layoutmetadata.cdl.h>
    27 
    27 
    28 #include <AknSmallIndicator.h>
       
    29 #include <touchfeedback.h>
       
    30 
       
    31 #include <AknTasHook.h>
    28 #include <AknTasHook.h>
    32 #include "AknUtils.h"
    29 #include "AknUtils.h"
    33 #include "aknconsts.h"
    30 #include "aknconsts.h"
    34 #include "AknBattery.h"
    31 #include "AknBattery.h"
    35 #include "AknStatuspaneUtils.h"
    32 #include "AknStatuspaneUtils.h"
    67 // ---------------------------------------------------------------------------
    64 // ---------------------------------------------------------------------------
    68 //
    65 //
    69 EXPORT_C CAknBatteryPane::~CAknBatteryPane()
    66 EXPORT_C CAknBatteryPane::~CAknBatteryPane()
    70     {
    67     {
    71     AKNTASHOOK_REMOVE();
    68     AKNTASHOOK_REMOVE();
    72     
       
    73     AknsUtils::DeregisterControlPosition( this );
    69     AknsUtils::DeregisterControlPosition( this );
    74 
    70 
    75     delete iBatteryIconControl;
    71     delete iBatteryIconControl;
    76     delete iBatteryStrengthControl;
    72     delete iBatteryStrengthControl;
    77 
    73 
    96     iBatteryIconControl->SetContainerWindowL( *this );
    92     iBatteryIconControl->SetContainerWindowL( *this );
    97     iBatteryStrengthControl = CAknBatteryStrength::NewL();
    93     iBatteryStrengthControl = CAknBatteryStrength::NewL();
    98     iBatteryStrengthControl->SetContainerWindowL( *this );
    94     iBatteryStrengthControl->SetContainerWindowL( *this );
    99     iPrivateFlags = 0; // reset flags
    95     iPrivateFlags = 0; // reset flags
   100     iDataObserver = new (ELeave) CAknBatteryDataObserver( this );
    96     iDataObserver = new (ELeave) CAknBatteryDataObserver( this );
   101     iStatusPane = CEikStatusPaneBase::Current();
    97     iIsActiveIdle = AknStatuspaneUtils::IsActiveIdle();
   102     }
    98     }
   103 
    99 
   104 
   100 
   105 // ---------------------------------------------------------------------------
   101 // ---------------------------------------------------------------------------
   106 // CAknBatteryPane::ConstructFromResourceL
   102 // CAknBatteryPane::ConstructFromResourceL
   328 
   324 
   329     AknLayoutUtils::LayoutControl(
   325     AknLayoutUtils::LayoutControl(
   330         iBatteryStrengthControl, parent, batteryStrenghtLayout );
   326         iBatteryStrengthControl, parent, batteryStrenghtLayout );
   331 
   327 
   332     AknsUtils::RegisterControlPosition( this );
   328     AknsUtils::RegisterControlPosition( this );
   333     
       
   334     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   335     if ( feedback )
       
   336         {
       
   337         if ( AknStatuspaneUtils::ExtendedFlatLayoutActive() )
       
   338             {
       
   339             // Disable tactile feedback in extended flat layout because
       
   340             // the battery pane isn't adjacent to the universal indicator
       
   341             // and small digital clock pane.
       
   342             feedback->EnableFeedbackForControl( this, EFalse );
       
   343             }
       
   344         else
       
   345             {
       
   346             feedback->EnableFeedbackForControl( this, ETrue );
       
   347             }
       
   348         }
       
   349     }
   329     }
   350 
   330 
   351 
   331 
   352 // ---------------------------------------------------------------------------
   332 // ---------------------------------------------------------------------------
   353 // CAknBatteryPane::SizeChanged
   333 // CAknBatteryPane::SizeChanged
   363 // ---------------------------------------------------------------------------
   343 // ---------------------------------------------------------------------------
   364 // CAknBatteryPane::Draw
   344 // CAknBatteryPane::Draw
   365 // Draws the battery pane.
   345 // Draws the battery pane.
   366 // ---------------------------------------------------------------------------
   346 // ---------------------------------------------------------------------------
   367 //
   347 //
   368 EXPORT_C void CAknBatteryPane::Draw( const TRect& aRect ) const
   348 EXPORT_C void CAknBatteryPane::Draw( const TRect& /*aRect*/ ) const
   369     {
   349     {
   370     if ( iStatusPane && 
   350     if ( iIsActiveIdle )
   371          iStatusPane->IsTransparent() )
   351         {
   372         {
       
   373         CWindowGc& gc = SystemGc();
       
   374         TRgb rgb(TRgb::Color16MA(0));
       
   375         gc.SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   376         gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   377         gc.SetBrushColor(rgb);
       
   378         gc.Clear(aRect);
       
   379         return;
   352         return;
   380         }
   353         }
   381         
   354 
   382 
   355     if ( AknStatuspaneUtils::StaconPaneActive() )
   383     // Don't allow normal background drawing if
   356         {
   384     // background is already drawn with a background drawer.
   357         DrawInStaconPane( Rect() );
   385     const MCoeControlBackground* backgroundDrawer = FindBackground();
   358         }
   386     if ( !backgroundDrawer )
   359     else if ( AknStatuspaneUtils::FlatLayoutActive() )
   387         {
   360         {
   388         if ( AknStatuspaneUtils::StaconPaneActive() )
   361         DrawInFlatStatusPane( Rect() );
   389             {
   362         }
   390             DrawInStaconPane( Rect() );
   363     else
   391             }
   364         {
   392         else if ( AknStatuspaneUtils::FlatLayoutActive() )
   365         DrawInNormalStatusPane( Rect() );
   393             {
       
   394             DrawInFlatStatusPane( Rect() );
       
   395             }
       
   396         else
       
   397             {
       
   398             DrawInNormalStatusPane( Rect() );
       
   399             }
       
   400         }
   366         }
   401     }
   367     }
   402 
   368 
   403 
   369 
   404 // ---------------------------------------------------------------------------
   370 // ---------------------------------------------------------------------------
   539     }
   505     }
   540 
   506 
   541 
   507 
   542 // ---------------------------------------------------------------------------
   508 // ---------------------------------------------------------------------------
   543 // CAknBatteryPane::HandlePointerEventL
   509 // CAknBatteryPane::HandlePointerEventL
   544 // Processes battery pane's pointer events.
   510 // Processes battery pane's pointer events. Actually this does nothing yet.
   545 // ---------------------------------------------------------------------------
   511 // ---------------------------------------------------------------------------
   546 //
   512 //
   547 void CAknBatteryPane::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   513 void CAknBatteryPane::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   548     {
   514     {
   549     if ( IsDimmed() )
   515     if ( AknLayoutUtils::PenEnabled() )
   550         {
   516         {
   551         iPrivateFlags &= (~EAknBatteryPaneButton1DownInBatteryRect);
   517         if ( IsDimmed() )
   552         return;
       
   553         }
       
   554 
       
   555     CEikStatusPaneBase* sp = CEikStatusPaneBase::Current();
       
   556 	if ( sp )
       
   557 	    {
       
   558         TInt statusPaneCurrentLayoutResourceId = sp->CurrentLayoutResId();
       
   559         if ( statusPaneCurrentLayoutResourceId ==
       
   560                  R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE ||
       
   561              statusPaneCurrentLayoutResourceId ==
       
   562                  R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE_MIRRORED )
       
   563             {
   518             {
   564             AknsUtils::DeregisterControlPosition( this );
   519             iPrivateFlags &= (~EAknBatteryPaneButton1DownInBatteryRect);
   565             return;
   520             return;
   566             }
   521             }
   567         }
   522 
   568     // Get the rect of battery pane.
   523         // Get the rect of battery pane.
   569     TRect rect( Rect() );
   524         TRect rect( Rect() );
   570 
   525 
   571     // Switch by type
   526         // Switch by type
   572     switch ( aPointerEvent.iType )
   527         switch ( aPointerEvent.iType )
   573         {
       
   574         case TPointerEvent::EButton1Down:
       
   575             {
   528             {
   576             // if battery pane's rect contains pointer down position
   529             case TPointerEvent::EButton1Down:
   577             if ( rect.Contains( aPointerEvent.iPosition ) )
       
   578                 {
   530                 {
   579                 // set flag that pointerdown was inside battery pane
   531                 // if battery pane's rect contains pointer down position
   580                 iPrivateFlags |= EAknBatteryPaneButton1DownInBatteryRect;
   532                 if ( rect.Contains( aPointerEvent.iPosition ) )
   581                 if ( !AknStatuspaneUtils::ExtendedFlatLayoutActive() )
       
   582                     {
   533                     {
   583                     MTouchFeedback* feedback = MTouchFeedback::Instance();
   534                     // set flag that pointerdown was inside battery pane
   584                     if ( feedback )
   535                     iPrivateFlags |= EAknBatteryPaneButton1DownInBatteryRect;
   585                         {
       
   586                         feedback->InstantFeedback( ETouchFeedbackSensitiveButton );
       
   587                         }
       
   588                     }
   536                     }
   589                 }
   537                 }
       
   538                 break;
       
   539 
       
   540             case TPointerEvent::EButton1Up:
       
   541                 {
       
   542                 // if battery pane's rect contains pointer down position and
       
   543                 // Button1Down was clicked inside battery rect
       
   544                 if ( iPrivateFlags&EAknBatteryPaneButton1DownInBatteryRect &&
       
   545                     rect.Contains( aPointerEvent.iPosition ) )
       
   546                     {
       
   547                     // Up happened inside battery pane's rect
       
   548                     // activate something
       
   549                     }
       
   550 
       
   551                 // Up happened, reset button down flag
       
   552                 iPrivateFlags &= (~EAknBatteryPaneButton1DownInBatteryRect);
       
   553                 }
       
   554                 break;
       
   555 
       
   556             default:
       
   557                 break;
   590             }
   558             }
   591             break;
       
   592 
       
   593         case TPointerEvent::EButton1Up:
       
   594             {
       
   595             if ( !AknStatuspaneUtils::ExtendedFlatLayoutActive() )
       
   596                 {
       
   597                 // Currently the small digital clock pane, universal
       
   598                 // indicator pane and battery pane (in status pane layouts
       
   599                 // where it's adjacent to universal indicator or digital
       
   600                 // clock pane) are regarded as one touch responsive
       
   601                 // area from which the universal indicator popup should
       
   602                 // open on tap, so upon pointer up event it must be checked
       
   603                 // here if the down event happened inside this control,
       
   604                 // but the up event inside digital clock or indicator
       
   605                 // pane area.
       
   606                 
       
   607                 TBool pointerUpInIndicatorArea( EFalse );
       
   608                 TBool pointerUpInClockArea( EFalse );
       
   609                     
       
   610                 if ( sp )
       
   611                     {
       
   612                     CCoeControl* clockPane = sp->ContainerControlL(
       
   613                         TUid::Uid( EEikStatusPaneUidDigitalClock ) );
       
   614                     if ( clockPane )
       
   615                         {
       
   616                         TRect clockRect(
       
   617                             clockPane->PositionRelativeToScreen(),
       
   618                             clockPane->Size() );
       
   619                         pointerUpInClockArea =
       
   620                             clockRect.Contains( aPointerEvent.iParentPosition );
       
   621                         }
       
   622                         
       
   623                     CCoeControl* indicatorPane = sp->ContainerControlL(
       
   624                         TUid::Uid( EEikStatusPaneUidIndic ) );
       
   625                     if ( indicatorPane )
       
   626                         {
       
   627                         TRect indicatorRect(
       
   628                             indicatorPane->PositionRelativeToScreen(),
       
   629                             indicatorPane->Size() );
       
   630                         pointerUpInIndicatorArea =
       
   631                             indicatorRect.Contains( aPointerEvent.iParentPosition );
       
   632                         }
       
   633                     }
       
   634     
       
   635                 if ( ( iPrivateFlags & EAknBatteryPaneButton1DownInBatteryRect &&
       
   636                        rect.Contains( aPointerEvent.iPosition ) ) ||
       
   637                      pointerUpInClockArea ||
       
   638                      pointerUpInIndicatorArea )
       
   639                     {
       
   640                     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   641                     if ( feedback )
       
   642                         {
       
   643                         feedback->InstantFeedback(
       
   644                             this,
       
   645                             ETouchFeedbackSensitiveButton,
       
   646                             ETouchFeedbackVibra,
       
   647                             aPointerEvent );
       
   648                         }
       
   649 
       
   650                     CAknSmallIndicator* indicatorNotifier =
       
   651                         CAknSmallIndicator::NewLC( TUid::Uid( 0 ) );
       
   652                     indicatorNotifier->HandleIndicatorTapL();
       
   653                     //for indicator popup event
       
   654                     if ( feedback )
       
   655                         {
       
   656                         feedback->InstantFeedback(
       
   657                                            this,
       
   658                                            ETouchFeedbackPopUp,
       
   659                                            ETouchFeedbackVibra,
       
   660                                            aPointerEvent );
       
   661                         }
       
   662                     CleanupStack::PopAndDestroy( indicatorNotifier );
       
   663                     }
       
   664                 }
       
   665 
       
   666             // Up happened, reset button down flag
       
   667             iPrivateFlags &= (~EAknBatteryPaneButton1DownInBatteryRect);
       
   668             }
       
   669             break;
       
   670 
       
   671         default:
       
   672             break;
       
   673         }
   559         }
   674     }
   560     }
   675 
   561 
   676 
   562 
   677 // ---------------------------------------------------------------------------
   563 // ---------------------------------------------------------------------------