idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockadapter.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Clock rendering plugin
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <e32base.h>
       
    20 #include <e32const.h>
       
    21 #include <AknLayoutFont.h>
       
    22 #include <AknsUtils.h>
       
    23 
       
    24 // User includes
       
    25 #include "xndomproperty.h"
       
    26 #include "xndomlist.h"
       
    27 #include "xnproperty.h"
       
    28 #include "xntype.h"
       
    29 #include "xnuienginepluginif.h"
       
    30 #include "xnnodepluginif.h"
       
    31 #include "xncontroladapter.h"
       
    32 #include "xnclockcontrol.h"
       
    33 #include "xnclockadapter.h"
       
    34 #include "c_xnutils.h"
       
    35 
       
    36 // Constants
       
    37 _LIT8( KDateInformation, "Clock/DateInformation" );
       
    38 _LIT8( KDayInformation, "Clock/DayInformation" );
       
    39 
       
    40 _LIT( KDigitalFont, "EAknLogicalFontSecondaryFont" );
       
    41 _LIT( KAmPmFont, "EAknLogicalFontSecondaryFont" );
       
    42 _LIT( KDateFont, "EAknLogicalFontSecondaryFont" );
       
    43 
       
    44 // ============================ LOCAL FUNCTIONS ===============================    
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // ClockFormat
       
    48 // Resolves the clock format
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 static TClockFormat ClockFormat( CXnProperty* aProperty, TBool& aUseLocale )
       
    52     {
       
    53     // Default, from locale    
       
    54     TClockFormat format( TLocale().ClockFormat() );
       
    55     
       
    56     aUseLocale = ETrue;
       
    57     
       
    58     if( aProperty )
       
    59         {
       
    60         const TDesC8& name( aProperty->Property()->Name() );
       
    61         
       
    62         if( name == XnPropertyNames::clock::KS60Format )
       
    63             {                                                        
       
    64             const TDesC8& value( aProperty->StringValue() );            
       
    65                                     
       
    66             if( value == XnPropertyNames::clock::format::KDigital )
       
    67                 {                          
       
    68                 format = EClockDigital;
       
    69                 aUseLocale = EFalse;
       
    70                 }
       
    71             else if( value == XnPropertyNames::clock::format::KAnalog )
       
    72                 {
       
    73                 format = EClockAnalog;
       
    74                 aUseLocale = EFalse;
       
    75                 }                        
       
    76             }    
       
    77         }
       
    78     
       
    79     return format;
       
    80     }
       
    81     
       
    82 // ============================ MEMBER FUNCTIONS ===============================
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CXnClockAdapter::NewL
       
    86 // Symbian static 1st phase constructor
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CXnClockAdapter* CXnClockAdapter::NewL( CXnControlAdapter* aParent, 
       
    90     CXnNodePluginIf& aNode )
       
    91     {
       
    92 	CXnClockAdapter* self = new( ELeave ) CXnClockAdapter( aParent, aNode );
       
    93 
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL();
       
    96     CleanupStack::Pop( self );
       
    97 
       
    98     return self;	
       
    99     }
       
   100     
       
   101 // -----------------------------------------------------------------------------
       
   102 // CXnClockAdapter::CXnClockAdapter
       
   103 // C++ default constructor
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 CXnClockAdapter::CXnClockAdapter( CXnControlAdapter* aParent, 
       
   107     CXnNodePluginIf& aNode )
       
   108     : iParent( aParent ), iNode( aNode )
       
   109     {
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CXnClockAdapter::~CXnClockAdapter
       
   114 // C++ destructor
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CXnClockAdapter::~CXnClockAdapter()
       
   118     {    
       
   119     iCoeEnv->RemoveMessageMonitorObserver( *this );    
       
   120 
       
   121     delete iLightObserver;    
       
   122     delete iClockControl;
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CXnClockAdapter::ConstructL
       
   127 // Symbian 2nd phase constructor can leave.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CXnClockAdapter::ConstructL()
       
   131     {          
       
   132     CXnControlAdapter::ConstructL( iNode );   
       
   133     
       
   134     iForeground = iAvkonAppUi->IsForeground();
       
   135     
       
   136     iLightObserver = CHWRMLight::NewL( this );
       
   137     
       
   138     RPointerArray< CXnNodePluginIf > children( iNode.ChildrenL() );
       
   139     CleanupClosePushL( children );
       
   140     
       
   141     for( TInt i = 0; i < children.Count(); i++ )
       
   142         {
       
   143         CXnNodePluginIf* child( children[i] );
       
   144         
       
   145         CXnProperty* id( child->IdL() );
       
   146         
       
   147         if( id )         
       
   148             {
       
   149             if( id->StringValue() == KDateInformation )
       
   150                 {
       
   151                 iDate = child;                               
       
   152                 }
       
   153             else if( id->StringValue() == KDayInformation )
       
   154                 {
       
   155                 iDay = child;
       
   156                 }
       
   157             }
       
   158         }
       
   159         
       
   160     CleanupStack::PopAndDestroy( &children );
       
   161     
       
   162     TBool useLocale;
       
   163 
       
   164     CXnProperty* prop( 
       
   165         iNode.GetPropertyL( XnPropertyNames::clock::KS60Format ) );    
       
   166     
       
   167     TClockFormat format( ClockFormat( prop, useLocale ) );   
       
   168     
       
   169     iClockControl = CXnClockControl::NewL( this, useLocale, format );    
       
   170     
       
   171     iCoeEnv->AddMessageMonitorObserverL( *this );
       
   172 	}
       
   173  
       
   174 // -----------------------------------------------------------------------------
       
   175 // CXnClockAdapter::DoHandlePropertyChangeL
       
   176 //
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CXnClockAdapter::DoHandlePropertyChangeL( CXnProperty* aProperty )
       
   180     {        
       
   181     if( aProperty )
       
   182         {
       
   183         const TDesC8& name( aProperty->Property()->Name() );
       
   184         
       
   185         if( name == XnPropertyNames::clock::KS60Format )
       
   186             {
       
   187             TBool useLocale;
       
   188             
       
   189             TClockFormat format( ClockFormat( aProperty, useLocale ) );
       
   190             
       
   191             iClockControl->SetFormatL( useLocale, format );
       
   192             }
       
   193         else if( name == XnPropertyNames::clock::KS60DigitalFontSize )            
       
   194             {
       
   195             iDigitalFont = NULL;            
       
   196             }
       
   197         else if( name == XnPropertyNames::clock::KS60AmPmFontSize )
       
   198             {
       
   199             iAmPmFont = NULL;
       
   200             }
       
   201         else if( name == XnPropertyNames::clock::KS60DateFontSize )
       
   202             {
       
   203             iDateFont = NULL;
       
   204             }
       
   205         else if( name == XnPropertyNames::appearance::common::KColor )
       
   206             {
       
   207             iColorSet = EFalse;
       
   208             }
       
   209         }
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CXnClockAdapter::UpdateDisplay
       
   214 // Draws the clock component
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CXnClockAdapter::UpdateDisplay() const
       
   218     {    
       
   219     if ( !iNode.Rect().IsEmpty() )
       
   220         {
       
   221         DrawNow();
       
   222         }
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CXnClockAdapter::Draw
       
   227 // Draws the clock component
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CXnClockAdapter::Draw( const TRect& aRect ) const
       
   231     {                           
       
   232     CXnControlAdapter::Draw( aRect );
       
   233     
       
   234     CWindowGc& gc( SystemGc() );
       
   235            
       
   236     iClockControl->Draw( gc, iNode.Rect() );
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CXnClockAdapter::MakeVisible
       
   241 // 
       
   242 // -----------------------------------------------------------------------------
       
   243 //        
       
   244 void CXnClockAdapter::MakeVisible( TBool aVisible )
       
   245     {
       
   246     TBool visible( IsVisible() );
       
   247     
       
   248     if ( visible != aVisible )
       
   249         {
       
   250         CCoeControl::MakeVisible( aVisible );
       
   251         
       
   252         if ( aVisible )
       
   253             {
       
   254             // Start clock ensures UI state
       
   255             StartClock();
       
   256             }
       
   257         else
       
   258             {
       
   259             StopClock();        
       
   260             }    
       
   261         }
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CXnClockAdapter::MonitorWsMessage
       
   266 // 
       
   267 // -----------------------------------------------------------------------------
       
   268 //    
       
   269 void CXnClockAdapter::MonitorWsMessage( const TWsEvent& aEvent )
       
   270     {   
       
   271     TInt type( aEvent.Type() );
       
   272     
       
   273     TBool foreground( iForeground );
       
   274         
       
   275     if( type == KAknFullOrPartialForegroundGained )
       
   276         {
       
   277         iForeground = ETrue;        
       
   278         }
       
   279     else if( type == KAknFullOrPartialForegroundLost )        
       
   280         {
       
   281         iForeground = EFalse;        
       
   282         }
       
   283 
       
   284     if( foreground != iForeground )            
       
   285         {
       
   286         if( iForeground )
       
   287             {   
       
   288             UpdateDisplay();
       
   289             
       
   290             // Start clock ensures UI state
       
   291             StartClock();
       
   292             }
       
   293         else
       
   294             {
       
   295             StopClock();
       
   296             }            
       
   297         }
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CXnClockAdapter::LightStatusChanged
       
   302 // 
       
   303 // -----------------------------------------------------------------------------
       
   304 //    
       
   305 void CXnClockAdapter::LightStatusChanged( TInt aTarget, 
       
   306     CHWRMLight::TLightStatus aStatus )
       
   307     {
       
   308     if ( aTarget == CHWRMLight::EPrimaryDisplay )
       
   309         {
       
   310         if ( aStatus == CHWRMLight::ELightOn )
       
   311             {
       
   312             iLightsOn = ETrue;
       
   313             
       
   314             if ( iForeground )
       
   315                 {
       
   316                 UpdateDisplay();
       
   317                 }
       
   318                         
       
   319             // Start clock ensures UI state
       
   320             StartClock();
       
   321             }
       
   322         else if ( aStatus == CHWRMLight::ELightOff )
       
   323             {
       
   324             iLightsOn = EFalse;
       
   325         
       
   326             StopClock();
       
   327             }        
       
   328         }
       
   329     }
       
   330 
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CXnClockAdapter::FontL
       
   334 // 
       
   335 // -----------------------------------------------------------------------------
       
   336 //    
       
   337 const CAknLayoutFont* CXnClockAdapter::FontL( const TInt aType )
       
   338     {
       
   339     CFont* font( NULL );
       
   340     
       
   341     if( aType == EDigitalFont )
       
   342         {
       
   343         if( !iDigitalFont )
       
   344             {            
       
   345             CreateFontL( aType );
       
   346             }
       
   347         
       
   348         font = iDigitalFont;        
       
   349         }
       
   350     else if( aType == EAmPmFont )
       
   351         {
       
   352         if( !iAmPmFont )
       
   353             {
       
   354             CreateFontL( aType );        
       
   355             }
       
   356         
       
   357         font = iAmPmFont;
       
   358         }
       
   359     else if( aType == EDateFont )
       
   360         {
       
   361         if( !iDateFont )
       
   362             {
       
   363             CreateFontL( aType );        
       
   364             }
       
   365         
       
   366         font = iDateFont;        
       
   367         }
       
   368     
       
   369     if( font )
       
   370         {
       
   371         return CAknLayoutFont::AsCAknLayoutFontOrNull( font );
       
   372         }
       
   373     
       
   374     return NULL;
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CXnClockAdapter::TextColorL
       
   379 // 
       
   380 // -----------------------------------------------------------------------------
       
   381 //    
       
   382 const TRgb& CXnClockAdapter::TextColorL()
       
   383     {    
       
   384     if( !iColorSet )
       
   385         {
       
   386         CreateColorL();
       
   387         }
       
   388         
       
   389     return iColor;            
       
   390     }
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 // CXnClockAdapter::Date
       
   394 // 
       
   395 // -----------------------------------------------------------------------------
       
   396 //    
       
   397 CXnNodePluginIf* CXnClockAdapter::Date() const
       
   398     {
       
   399     return iDate;
       
   400     }
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 // CXnClockAdapter::Day
       
   404 // 
       
   405 // -----------------------------------------------------------------------------
       
   406 //    
       
   407 CXnNodePluginIf* CXnClockAdapter::Day() const
       
   408     {
       
   409     return iDay;
       
   410     }
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // CXnClockAdapter::CreateFontL
       
   414 // 
       
   415 // -----------------------------------------------------------------------------
       
   416 //    
       
   417 void CXnClockAdapter::CreateFontL( const TInt aType )   
       
   418     {
       
   419     TFontSpec spec;
       
   420     TInt dummy;
       
   421 
       
   422     if( aType == EDigitalFont )
       
   423         {
       
   424         iDigitalFont = NULL;
       
   425         
       
   426         CXnProperty* prop( iNode.GetPropertyL( 
       
   427             XnPropertyNames::clock::KS60DigitalFontSize ) );
       
   428 
       
   429         // default
       
   430         TInt height( ( iNode.Rect().Height() / 3 ) * 2 );
       
   431 
       
   432         if ( prop )
       
   433             {
       
   434             height = iNode.UiEngineL()->VerticalPixelValueL(
       
   435                 prop, iNode.Rect().Height() );
       
   436             }
       
   437                                             
       
   438         // No need to relase avkon font
       
   439         CXnUtils::CreateFontL( KDigitalFont, 
       
   440                                height,
       
   441                                spec.iFontStyle,
       
   442                                iDigitalFont,
       
   443                                dummy );
       
   444         }
       
   445     else if( aType == EAmPmFont )
       
   446         {
       
   447         iAmPmFont = NULL;
       
   448 
       
   449         CXnProperty* prop( iNode.GetPropertyL( 
       
   450             XnPropertyNames::clock::KS60AmPmFontSize ) );
       
   451         
       
   452         // default
       
   453         TInt height( ( iNode.Rect().Height() / 5 ) );
       
   454 
       
   455         if ( prop )
       
   456             {
       
   457             height = iNode.UiEngineL()->VerticalPixelValueL(
       
   458                 prop, iNode.Rect().Height() );
       
   459             }        
       
   460         
       
   461         // No need to relase avkon font
       
   462         CXnUtils::CreateFontL( KAmPmFont, 
       
   463                                height,
       
   464                                spec.iFontStyle,
       
   465                                iAmPmFont,
       
   466                                dummy );      
       
   467         }
       
   468     else if( aType == EDateFont )
       
   469         {
       
   470         iDateFont = NULL;
       
   471         
       
   472         CXnProperty* prop( iNode.GetPropertyL( 
       
   473             XnPropertyNames::clock::KS60DateFontSize ) );
       
   474         
       
   475         // default 
       
   476         TInt height( ( iNode.Rect().Height() / 5 ) );
       
   477         
       
   478         if ( prop )
       
   479             {
       
   480             height = iNode.UiEngineL()->VerticalPixelValueL(
       
   481                 prop, iNode.Rect().Height() );
       
   482             }
       
   483         
       
   484         // No need to relase avkon font
       
   485         CXnUtils::CreateFontL( KDateFont, 
       
   486                                height,
       
   487                                spec.iFontStyle,
       
   488                                iDateFont,
       
   489                                dummy );              
       
   490         }
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CXnClockAdapter::CreateColorL
       
   495 // 
       
   496 // -----------------------------------------------------------------------------
       
   497 //    
       
   498 void CXnClockAdapter::CreateColorL()
       
   499     {        
       
   500     TRgb color;
       
   501             
       
   502     TInt result( KErrNone );
       
   503         
       
   504     CXnProperty* prop( iNode.GetPropertyL( 
       
   505         XnPropertyNames::appearance::common::KColor ) );
       
   506     
       
   507     if( !prop )
       
   508         {
       
   509         return;
       
   510         }
       
   511         
       
   512     CXnDomProperty* domProp( prop->Property() );
       
   513     
       
   514     MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
       
   515     
       
   516     if( domProp )
       
   517         {        
       
   518         CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >
       
   519                                         ( domProp->PropertyValueList().Item( 0 ) );
       
   520         
       
   521         if( value->PrimitiveValueType() == CXnDomPropertyValue::ERgbColor )
       
   522             {
       
   523             color = value->RgbColorValueL();                
       
   524             }
       
   525         else if( !value->IsAutoIdent() )
       
   526         	{
       
   527             HBufC* str( prop->StringValueL() );
       
   528             CleanupStack::PushL( str );
       
   529             
       
   530             CXnUtils::StripQuotes( str );
       
   531             
       
   532             TInt index( 0 );
       
   533             TAknsItemID skinID;
       
   534             
       
   535             TBool idResolved( CXnUtils::ResolveSkinItemIDL( *str, skinID, index ) );
       
   536             
       
   537             result = KErrNotFound;
       
   538             
       
   539             if( idResolved )
       
   540             	{                	
       
   541             	result = AknsUtils::GetCachedColor( skin, color, skinID, index );
       
   542             	}                        
       
   543 
       
   544         	CleanupStack::PopAndDestroy( str );                	
       
   545         	}
       
   546         	
       
   547         if( value->IsAutoIdent() || result != KErrNone )
       
   548             {                                
       
   549             result = AknsUtils::GetCachedColor( skin, color, 
       
   550                                                 KAknsIIDQsnTextColors,
       
   551                                                 EAknsCIQsnTextColorsCG6 );
       
   552             }
       
   553         }
       
   554         
       
   555     if( result == KErrNone )
       
   556         {
       
   557         iColorSet = ETrue;
       
   558         iColor = color;
       
   559         }            
       
   560     }
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // CXnClockAdapter::SkinChanged
       
   564 // Skin change notification
       
   565 // -----------------------------------------------------------------------------
       
   566 //  
       
   567 void CXnClockAdapter::SkinChanged()
       
   568     {
       
   569     iAmPmFont = iDigitalFont = iDateFont = NULL;
       
   570     iColorSet = EFalse;
       
   571     
       
   572     CXnControlAdapter::SkinChanged();
       
   573     }
       
   574 
       
   575 // -----------------------------------------------------------------------------
       
   576 // CXnClockAdapter::HandleScreenDeviceChangedL
       
   577 // Screen device change notification
       
   578 // -----------------------------------------------------------------------------
       
   579 //  
       
   580 void CXnClockAdapter::HandleScreenDeviceChangedL()
       
   581     {
       
   582     iAmPmFont = iDigitalFont = iDateFont = NULL;
       
   583     iColorSet = EFalse;
       
   584     
       
   585     CXnControlAdapter::HandleScreenDeviceChangedL();
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CXnClockAdapter::SizeChanged
       
   590 // Size changed notification
       
   591 // -----------------------------------------------------------------------------
       
   592 //  
       
   593 void CXnClockAdapter::SizeChanged()
       
   594     {
       
   595     iAmPmFont = iDigitalFont = iDateFont = NULL;
       
   596     iColorSet = EFalse;
       
   597     
       
   598     CXnControlAdapter::SizeChanged();    
       
   599     }
       
   600 
       
   601 // -----------------------------------------------------------------------------
       
   602 // CXnClockAdapter::StartClock
       
   603 // 
       
   604 // -----------------------------------------------------------------------------
       
   605 // 
       
   606 void CXnClockAdapter::StartClock()
       
   607     {    
       
   608     if ( iClockControl )
       
   609         {        
       
   610         if ( iForeground && iLightsOn && IsVisible() )
       
   611             {
       
   612             iClockControl->StartTimer();
       
   613             }
       
   614         else
       
   615             {
       
   616             StopClock();
       
   617             }    
       
   618         }
       
   619     }
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 // CXnClockAdapter::StopClock
       
   623 // 
       
   624 // -----------------------------------------------------------------------------
       
   625 // 
       
   626 void CXnClockAdapter::StopClock()
       
   627     {
       
   628     if ( iClockControl )
       
   629         {
       
   630         iClockControl->StopTimer();
       
   631         }    
       
   632     }
       
   633 
       
   634 // End of file