uifw/AvKon/src/aknstatuspanedigitalclock.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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 for digital clock status pane control.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDE FILES
       
    20 #include <eikspane.h>
       
    21 #include <AknsDrawUtils.h>
       
    22 #include <AknsUtils.h>
       
    23 #include <AknDef.h>
       
    24 #include <aknlayoutscalable_avkon.cdl.h>
       
    25 #include <AknStatuspaneUtils.h>
       
    26 
       
    27 #include <AknTasHook.h> // for testability hooks
       
    28 // USER INCLUDE FILES
       
    29 #include "aknstatuspanedigitalclock.h"
       
    30 #include "akndigitalclock.h"
       
    31 
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS =============================
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CAknStatuspaneDigitalClock::CAknStatuspaneDigitalClock
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CAknStatuspaneDigitalClock::CAknStatuspaneDigitalClock()
       
    42     : iInForeground( EFalse )
       
    43     {
       
    44     AKNTASHOOK_ADD( this, "CAknStatuspaneDigitalClock" );
       
    45     }
       
    46 
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Destructor
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CAknStatuspaneDigitalClock::~CAknStatuspaneDigitalClock()
       
    53     {
       
    54     AKNTASHOOK_REMOVE();
       
    55     AknsUtils::DeregisterControlPosition( this );
       
    56 
       
    57     iCoeEnv->RemoveMessageMonitorObserver( *this );
       
    58 
       
    59     delete iClock;
       
    60     delete iLight;
       
    61     }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CAknStatuspaneDigitalClock::ConstructFromResourceL
       
    66 // (other items were commented in a header).
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CAknStatuspaneDigitalClock::ConstructFromResourceL(
       
    70     TResourceReader& /*aReader*/ )
       
    71     {
       
    72     // We observe foreground events in order
       
    73     // to stop the clock timer if clock is not visible.
       
    74     iCoeEnv->AddMessageMonitorObserverL( *this );
       
    75 
       
    76     SetComponentsToInheritVisibility( ETrue );
       
    77 
       
    78     iClock = CAknDigitalClock::NewL( this, ETrue );
       
    79     iClock->ActivateL();
       
    80 
       
    81     /* Register MHWRMLightObserver */
       
    82     iLight = CHWRMLight::NewL( this );
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CAknStatuspaneDigitalClock::SizeChanged
       
    88 // (other items were commented in a header).
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CAknStatuspaneDigitalClock::SizeChanged()
       
    92     {
       
    93     SetContainerWindowNonFading(
       
    94         AknStatuspaneUtils::ExtendedStaconPaneActive());
       
    95 
       
    96 
       
    97     TPoint tl( Rect().iTl );
       
    98     iClock->SetExtent( tl, Size() );
       
    99 
       
   100     // Set layout for extended statuspane layout (portrait)
       
   101 
       
   102     TAknTextLineLayout clockLayout =
       
   103         AknLayoutScalable_Avkon::clock_nsta_pane_t1().LayoutLine();
       
   104 
       
   105     if ( AknStatuspaneUtils::ExtendedStaconPaneActive() )
       
   106         {
       
   107         clockLayout =
       
   108             AknLayoutScalable_Avkon::clock_nsta_pane_cp2_t1().LayoutLine();
       
   109         }
       
   110     else if ( AknStatuspaneUtils::ExtendedFlatLayoutActive() )
       
   111         {
       
   112         clockLayout =
       
   113             AknLayoutScalable_Avkon::clock_nsta_pane_cp_t1().LayoutLine();
       
   114         }
       
   115 
       
   116     iClock->SetTimeLayout( clockLayout );
       
   117 
       
   118     TRgb color = KRgbBlack;
       
   119 
       
   120     if ( AknStatuspaneUtils::ExtendedStaconPaneActive() ||
       
   121          AknStatuspaneUtils::HDLayoutActive() )
       
   122         {
       
   123         // Set color for stacon pane layout (landscape)
       
   124         AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   125                                    color,
       
   126                                    KAknsIIDQsnIconColors,
       
   127                                    EAknsCIQsnIconColorsCG20 );
       
   128         }
       
   129     else if (AknStatuspaneUtils::ExtendedFlatLayoutActive())
       
   130         {
       
   131         // Set color for flat status pane layout (landscape).
       
   132         // Actually clock is in control pane area in this case.
       
   133         // Uses right sk color
       
   134         if ( AknStatuspaneUtils::IdleLayoutActive() )
       
   135             {
       
   136             AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   137                                        color,
       
   138                                        KAknsIIDQsnTextColors,
       
   139                                        EAknsCIQsnTextColorsCG16 );
       
   140             }
       
   141         else
       
   142             {
       
   143             AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   144                                        color,
       
   145                                        KAknsIIDQsnTextColors,
       
   146                                        EAknsCIQsnTextColorsCG14 );
       
   147             }
       
   148         }
       
   149     else
       
   150         {
       
   151         // Set color for extended statuspane layout (portrait)
       
   152         AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   153                                    color,
       
   154                                    KAknsIIDQsnIconColors,
       
   155                                    EAknsCIQsnIconColorsCG2 );
       
   156         }
       
   157 
       
   158     AknsUtils::RegisterControlPosition( this );
       
   159 
       
   160     iClock->SetColor( color );
       
   161     iClock->DrawDeferred();
       
   162     }
       
   163 
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CAknStatuspaneDigitalClock::MakeVisible
       
   167 // (other items were commented in a header).
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CAknStatuspaneDigitalClock::MakeVisible( TBool aVisible )
       
   171     {
       
   172     CAknControl::MakeVisible( aVisible );
       
   173 
       
   174 	if ( iClock )
       
   175 	    {
       
   176 	    if ( !aVisible )
       
   177     	    {
       
   178     	    // Stop the timer if this control is made non-visible.
       
   179     	    // This control may exist in status pane layouts which
       
   180     	    // don't show clock, and in those it's hidden via
       
   181     	    // this method, so no need to keep the timer running.
       
   182         	iClock->StopTimer();
       
   183     	    }
       
   184 	    else if ( aVisible && iInForeground )
       
   185 	        {
       
   186 	        iClock->StartTimer();
       
   187 	        }
       
   188 	    }
       
   189     }
       
   190 
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CAknStatuspaneDigitalClock::CountComponentControls
       
   194 // (other items were commented in a header).
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 TInt CAknStatuspaneDigitalClock::CountComponentControls() const
       
   198     {
       
   199     return iClock ? 1 : 0;
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CAknStatuspaneDigitalClock::ComponentControl
       
   204 // (other items were commented in a header).
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 CCoeControl* CAknStatuspaneDigitalClock::ComponentControl(
       
   208     TInt /*aIndex*/ ) const
       
   209     {
       
   210     return iClock;
       
   211     }
       
   212 
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CAknStatuspaneDigitalClock::Draw
       
   216 // (other items were commented in a header).
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CAknStatuspaneDigitalClock::Draw( const TRect& /*aRect*/ ) const
       
   220     {
       
   221     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   222 
       
   223     CWindowGc& gc = SystemGc();
       
   224     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   225     AknsDrawUtils::Background( skin, cc, this, gc, Rect() );
       
   226     }
       
   227 
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // CAknStatuspaneDigitalClock::SetDimmed
       
   231 // (other items were commented in a header).
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 void CAknStatuspaneDigitalClock::SetDimmed( TBool aDimmed )
       
   235     {
       
   236     CCoeControl::SetDimmed( aDimmed );
       
   237     if ( iClock )
       
   238         {
       
   239         iClock->SetDimmed( aDimmed );
       
   240         }
       
   241     }
       
   242 
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CAknStatuspaneDigitalClock::HandleResourceChange
       
   246 // (other items were commented in a header).
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 void CAknStatuspaneDigitalClock::HandleResourceChange( TInt aType )
       
   250     {
       
   251     if( iClock )
       
   252         {
       
   253         iClock->HandleResourceChange( aType );
       
   254         }
       
   255 
       
   256     if ( aType == KEikDynamicLayoutVariantSwitch ||
       
   257          aType == KEikColorResourceChange ||
       
   258          aType == KAknsMessageSkinChange )
       
   259         {
       
   260         SizeChanged();
       
   261         DrawDeferred();
       
   262         }
       
   263     }
       
   264 
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CAknStatuspaneDigitalClock::SetContainerWindowNonFading
       
   268 // (other items were commented in a header).
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void CAknStatuspaneDigitalClock::SetContainerWindowNonFading(
       
   272     TBool aNonFading )
       
   273     {
       
   274     CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current();
       
   275     if ( statusPane )
       
   276         {
       
   277         CCoeControl* control = NULL;
       
   278         TRAP_IGNORE( control = statusPane->ContainerControlL(
       
   279                                  TUid::Uid( EEikStatusPaneUidDigitalClock ) ) );
       
   280         if ( control )
       
   281             {
       
   282             control->DrawableWindow()->SetNonFading( aNonFading );
       
   283             }
       
   284         }
       
   285     }
       
   286 
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CAknStatuspaneDigitalClock::MonitorWsMessage
       
   290 // (other items were commented in a header).
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CAknStatuspaneDigitalClock::MonitorWsMessage( const TWsEvent& aEvent )
       
   294     {
       
   295     switch ( aEvent.Type() )
       
   296         {
       
   297         case KAknFullOrPartialForegroundGained:
       
   298             {
       
   299             iInForeground = ETrue;
       
   300 
       
   301             TRAP_IGNORE( ForegroundGainedL() );
       
   302 
       
   303             break;
       
   304             }
       
   305 
       
   306         case KAknFullOrPartialForegroundLost:
       
   307             {
       
   308             iInForeground = EFalse;
       
   309 
       
   310             iClock->StopTimer();
       
   311 
       
   312             break;
       
   313             }
       
   314 
       
   315         default:
       
   316             break;
       
   317         }
       
   318     }
       
   319 
       
   320 
       
   321 // ---------------------------------------------------------------------------
       
   322 // CAknStatuspaneDigitalClock::ForegroundGainedL
       
   323 // Contains the leaving function calls in the foreground gain situation.
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 void CAknStatuspaneDigitalClock::ForegroundGainedL()
       
   327     {
       
   328     if ( IsVisible() )
       
   329         {
       
   330         iClock->StartTimer();
       
   331         }
       
   332     }
       
   333 
       
   334 void CAknStatuspaneDigitalClock::LightStatusChanged(TInt aTarget, 
       
   335                                                     CHWRMLight::TLightStatus aStatus)
       
   336     {
       
   337     if( aTarget == CHWRMLight::EPrimaryDisplay
       
   338         || aTarget == CHWRMLight::EPrimaryDisplayAndKeyboard )
       
   339         {
       
   340         if( aStatus == CHWRMLight::ELightOn && iInForeground )
       
   341             {
       
   342             iClock->StartTimer();
       
   343             }
       
   344         else if( aStatus == CHWRMLight::ELightOff )
       
   345             {
       
   346             iClock->StopTimer();
       
   347             }
       
   348         }
       
   349     }
       
   350 
       
   351 //  End of File