uifw/AvKon/src/aknbattery.cpp
branchRCL_3
changeset 9 aabf2c525e0f
parent 4 8ca85d2f0db7
child 10 9f56a4e1b8ab
equal deleted inserted replaced
4:8ca85d2f0db7 9:aabf2c525e0f
     1 /*
     1 /*
     2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2002-2010 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 
    28 #include <AknTasHook.h>
    31 #include <AknTasHook.h>
    29 #include "AknUtils.h"
    32 #include "AknUtils.h"
    30 #include "aknconsts.h"
    33 #include "aknconsts.h"
    31 #include "AknBattery.h"
    34 #include "AknBattery.h"
    32 #include "AknStatuspaneUtils.h"
    35 #include "AknStatuspaneUtils.h"
    64 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
    65 //
    68 //
    66 EXPORT_C CAknBatteryPane::~CAknBatteryPane()
    69 EXPORT_C CAknBatteryPane::~CAknBatteryPane()
    67     {
    70     {
    68     AKNTASHOOK_REMOVE();
    71     AKNTASHOOK_REMOVE();
       
    72     
       
    73     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
    74     if ( feedback )
       
    75         {
       
    76         feedback->RemoveFeedbackForControl( this );
       
    77         }
       
    78     
    69     AknsUtils::DeregisterControlPosition( this );
    79     AknsUtils::DeregisterControlPosition( this );
    70 
    80 
    71     delete iBatteryIconControl;
    81     delete iBatteryIconControl;
    72     delete iBatteryStrengthControl;
    82     delete iBatteryStrengthControl;
    73 
    83 
    93     iBatteryStrengthControl = CAknBatteryStrength::NewL();
   103     iBatteryStrengthControl = CAknBatteryStrength::NewL();
    94     iBatteryStrengthControl->SetContainerWindowL( *this );
   104     iBatteryStrengthControl->SetContainerWindowL( *this );
    95     iPrivateFlags = 0; // reset flags
   105     iPrivateFlags = 0; // reset flags
    96     iDataObserver = new (ELeave) CAknBatteryDataObserver( this );
   106     iDataObserver = new (ELeave) CAknBatteryDataObserver( this );
    97     iIsActiveIdle = AknStatuspaneUtils::IsActiveIdle();
   107     iIsActiveIdle = AknStatuspaneUtils::IsActiveIdle();
       
   108     
       
   109     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   110     if ( feedback )
       
   111         {
       
   112         CFeedbackSpec* fbSpec = CFeedbackSpec::New();
       
   113         if ( fbSpec )
       
   114             {
       
   115             fbSpec->AddFeedback( ETouchEventStylusDown,
       
   116                                  ETouchFeedbackSensitiveButton );
       
   117             fbSpec->AddFeedback( ETouchEventStylusUp,
       
   118                                  ETouchFeedbackSensitiveButton,
       
   119                                  ETouchFeedbackVibra );
       
   120 
       
   121             feedback->SetFeedbackArea( this,
       
   122                                        0,
       
   123                                        Rect(),
       
   124                                        fbSpec );
       
   125             delete fbSpec; 
       
   126             }        
       
   127         }
    98     }
   128     }
    99 
   129 
   100 
   130 
   101 // ---------------------------------------------------------------------------
   131 // ---------------------------------------------------------------------------
   102 // CAknBatteryPane::ConstructFromResourceL
   132 // CAknBatteryPane::ConstructFromResourceL
   324 
   354 
   325     AknLayoutUtils::LayoutControl(
   355     AknLayoutUtils::LayoutControl(
   326         iBatteryStrengthControl, parent, batteryStrenghtLayout );
   356         iBatteryStrengthControl, parent, batteryStrenghtLayout );
   327 
   357 
   328     AknsUtils::RegisterControlPosition( this );
   358     AknsUtils::RegisterControlPosition( this );
       
   359     
       
   360     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   361     if ( feedback )
       
   362         {
       
   363         if ( AknStatuspaneUtils::ExtendedFlatLayoutActive() )
       
   364             {
       
   365             // Disable tactile feedback in extended flat layout because
       
   366             // the battery pane isn't adjacent to the universal indicator
       
   367             // and small digital clock pane.
       
   368             feedback->EnableFeedbackForControl( this, EFalse );
       
   369             }
       
   370         else
       
   371             {
       
   372             feedback->EnableFeedbackForControl( this, ETrue );
       
   373             feedback->ChangeFeedbackArea( this,
       
   374                                           0,
       
   375                                           parent );
       
   376             }
       
   377         }
   329     }
   378     }
   330 
   379 
   331 
   380 
   332 // ---------------------------------------------------------------------------
   381 // ---------------------------------------------------------------------------
   333 // CAknBatteryPane::SizeChanged
   382 // CAknBatteryPane::SizeChanged
   345 // Draws the battery pane.
   394 // Draws the battery pane.
   346 // ---------------------------------------------------------------------------
   395 // ---------------------------------------------------------------------------
   347 //
   396 //
   348 EXPORT_C void CAknBatteryPane::Draw( const TRect& /*aRect*/ ) const
   397 EXPORT_C void CAknBatteryPane::Draw( const TRect& /*aRect*/ ) const
   349     {
   398     {
   350     if ( iIsActiveIdle )
   399     if ( iStatusPane && 
       
   400          iStatusPane->IsTransparent() )
   351         {
   401         {
   352         return;
   402         return;
   353         }
   403         }
       
   404         
   354 
   405 
   355     // Don't allow normal background drawing if
   406     // Don't allow normal background drawing if
   356     // background is already drawn with a background drawer.
   407     // background is already drawn with a background drawer.
   357     const MCoeControlBackground* backgroundDrawer = FindBackground();
   408     const MCoeControlBackground* backgroundDrawer = FindBackground();
   358     if ( !backgroundDrawer )
   409     if ( !backgroundDrawer )
   511     }
   562     }
   512 
   563 
   513 
   564 
   514 // ---------------------------------------------------------------------------
   565 // ---------------------------------------------------------------------------
   515 // CAknBatteryPane::HandlePointerEventL
   566 // CAknBatteryPane::HandlePointerEventL
   516 // Processes battery pane's pointer events. Actually this does nothing yet.
   567 // Processes battery pane's pointer events.
   517 // ---------------------------------------------------------------------------
   568 // ---------------------------------------------------------------------------
   518 //
   569 //
   519 void CAknBatteryPane::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   570 void CAknBatteryPane::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   520     {
   571     {
   521     if ( AknLayoutUtils::PenEnabled() )
   572     if ( IsDimmed() )
   522         {
   573         {
   523         if ( IsDimmed() )
   574         iPrivateFlags &= (~EAknBatteryPaneButton1DownInBatteryRect);
   524             {
   575         return;
   525             iPrivateFlags &= (~EAknBatteryPaneButton1DownInBatteryRect);
   576         }
   526             return;
   577 
   527             }
   578     // Get the rect of battery pane.
   528 
   579     TRect rect( Rect() );
   529         // Get the rect of battery pane.
   580 
   530         TRect rect( Rect() );
   581     // Switch by type
   531 
   582     switch ( aPointerEvent.iType )
   532         // Switch by type
   583         {
   533         switch ( aPointerEvent.iType )
   584         case TPointerEvent::EButton1Down:
   534             {
   585             {
   535             case TPointerEvent::EButton1Down:
   586             // if battery pane's rect contains pointer down position
       
   587             if ( rect.Contains( aPointerEvent.iPosition ) )
   536                 {
   588                 {
   537                 // if battery pane's rect contains pointer down position
   589                 // set flag that pointerdown was inside battery pane
   538                 if ( rect.Contains( aPointerEvent.iPosition ) )
   590                 iPrivateFlags |= EAknBatteryPaneButton1DownInBatteryRect;
       
   591                 }
       
   592             }
       
   593             break;
       
   594 
       
   595         case TPointerEvent::EButton1Up:
       
   596             {
       
   597             if ( !AknStatuspaneUtils::ExtendedFlatLayoutActive() )
       
   598                 {
       
   599                 // Currently the small digital clock pane, universal
       
   600                 // indicator pane and battery pane (in status pane layouts
       
   601                 // where it's adjacent to universal indicator or digital
       
   602                 // clock pane) are regarded as one touch responsive
       
   603                 // area from which the universal indicator popup should
       
   604                 // open on tap, so upon pointer up event it must be checked
       
   605                 // here if the down event happened inside this control,
       
   606                 // but the up event inside digital clock or indicator
       
   607                 // pane area.
       
   608                 CEikStatusPaneBase* sp = CEikStatusPaneBase::Current();
       
   609                 TBool pointerUpInIndicatorArea( EFalse );
       
   610                 TBool pointerUpInClockArea( EFalse );
       
   611                     
       
   612                 if ( sp )
   539                     {
   613                     {
   540                     // set flag that pointerdown was inside battery pane
   614                     CCoeControl* clockPane = sp->ContainerControlL(
   541                     iPrivateFlags |= EAknBatteryPaneButton1DownInBatteryRect;
   615                         TUid::Uid( EEikStatusPaneUidDigitalClock ) );
       
   616                     if ( clockPane )
       
   617                         {
       
   618                         TRect clockRect(
       
   619                             clockPane->PositionRelativeToScreen(),
       
   620                             clockPane->Size() );
       
   621                         pointerUpInClockArea =
       
   622                             clockRect.Contains( aPointerEvent.iParentPosition );
       
   623                         }
       
   624                         
       
   625                     CCoeControl* indicatorPane = sp->ContainerControlL(
       
   626                         TUid::Uid( EEikStatusPaneUidIndic ) );
       
   627                     if ( indicatorPane )
       
   628                         {
       
   629                         TRect indicatorRect(
       
   630                             indicatorPane->PositionRelativeToScreen(),
       
   631                             indicatorPane->Size() );
       
   632                         pointerUpInIndicatorArea =
       
   633                             indicatorRect.Contains( aPointerEvent.iParentPosition );
       
   634                         }
       
   635                     }
       
   636     
       
   637                 if ( ( iPrivateFlags & EAknBatteryPaneButton1DownInBatteryRect &&
       
   638                        rect.Contains( aPointerEvent.iPosition ) ) ||
       
   639                      pointerUpInClockArea ||
       
   640                      pointerUpInIndicatorArea )
       
   641                     {
       
   642                     if ( pointerUpInClockArea || pointerUpInIndicatorArea )
       
   643                         {
       
   644                         MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   645                         if ( feedback )
       
   646                             {
       
   647                             // The pointer down was received in another
       
   648                             // control, so the tactile feedback must be
       
   649                             // given directly.
       
   650                             feedback->InstantFeedback(
       
   651                                 this,
       
   652                                 ETouchFeedbackSensitiveButton,
       
   653                                 ETouchFeedbackVibra,
       
   654                                 aPointerEvent );
       
   655                             }
       
   656                         }
       
   657 
       
   658                     CAknSmallIndicator* indicatorNotifier =
       
   659                         CAknSmallIndicator::NewLC( TUid::Uid( 0 ) );
       
   660                     indicatorNotifier->HandleIndicatorTapL();
       
   661                     CleanupStack::PopAndDestroy( indicatorNotifier );
   542                     }
   662                     }
   543                 }
   663                 }
   544                 break;
   664 
   545 
   665             // Up happened, reset button down flag
   546             case TPointerEvent::EButton1Up:
   666             iPrivateFlags &= (~EAknBatteryPaneButton1DownInBatteryRect);
   547                 {
   667             }
   548                 // if battery pane's rect contains pointer down position and
   668             break;
   549                 // Button1Down was clicked inside battery rect
   669 
   550                 if ( iPrivateFlags&EAknBatteryPaneButton1DownInBatteryRect &&
   670         default:
   551                     rect.Contains( aPointerEvent.iPosition ) )
   671             break;
   552                     {
       
   553                     // Up happened inside battery pane's rect
       
   554                     // activate something
       
   555                     }
       
   556 
       
   557                 // Up happened, reset button down flag
       
   558                 iPrivateFlags &= (~EAknBatteryPaneButton1DownInBatteryRect);
       
   559                 }
       
   560                 break;
       
   561 
       
   562             default:
       
   563                 break;
       
   564             }
       
   565         }
   672         }
   566     }
   673     }
   567 
   674 
   568 
   675 
   569 // ---------------------------------------------------------------------------
   676 // ---------------------------------------------------------------------------