idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockadapter.cpp
changeset 0 f72a12da539e
child 5 c743ef5928ba
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     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:  Implementation wrapper for CAknSkinnableClock
       
    15 *
       
    16 */
       
    17 
       
    18 // SYSTEM INCLUDE FILES
       
    19 #include <e32base.h>
       
    20 #include <e32const.h>
       
    21 #include <AknLayoutFont.h>
       
    22 #include <AknsUtils.h>
       
    23 
       
    24 // USER INCLUDE FILES
       
    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, "EAknLogicalFontDigitalFont" );
       
    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 iClockControl;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CXnClockAdapter::ConstructL
       
   126 // Symbian 2nd phase constructor can leave.
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CXnClockAdapter::ConstructL()
       
   130     {
       
   131     CXnControlAdapter::ConstructL( iNode );     
       
   132             
       
   133     RPointerArray< CXnNodePluginIf > children( iNode.ChildrenL() );
       
   134     CleanupClosePushL( children );
       
   135     
       
   136     for( TInt i = 0; i < children.Count(); i++ )
       
   137         {
       
   138         CXnNodePluginIf* child( children[i] );
       
   139         
       
   140         CXnProperty* id( child->IdL() );
       
   141         
       
   142         if( id )         
       
   143             {
       
   144             if( id->StringValue() == KDateInformation )
       
   145                 {
       
   146                 iDate = child;                               
       
   147                 }
       
   148             else if( id->StringValue() == KDayInformation )
       
   149                 {
       
   150                 iDay = child;
       
   151                 }
       
   152             }
       
   153         }
       
   154         
       
   155     CleanupStack::PopAndDestroy( &children );
       
   156     
       
   157     TBool useLocale;
       
   158 
       
   159     CXnProperty* prop( 
       
   160         iNode.GetPropertyL( XnPropertyNames::clock::KS60Format ) );    
       
   161     
       
   162     TClockFormat format( ClockFormat( prop, useLocale ) );   
       
   163     
       
   164     iClockControl = CXnClockControl::NewL( this, useLocale, format );    
       
   165     
       
   166     iCoeEnv->AddMessageMonitorObserverL( *this );
       
   167 	}
       
   168  
       
   169 // -----------------------------------------------------------------------------
       
   170 // CXnClockAdapter::DoHandlePropertyChangeL
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CXnClockAdapter::DoHandlePropertyChangeL( CXnProperty* aProperty )
       
   174     {        
       
   175     if( aProperty )
       
   176         {
       
   177         const TDesC8& name( aProperty->Property()->Name() );
       
   178         
       
   179         if( name == XnPropertyNames::clock::KS60Format )
       
   180             {
       
   181             TBool useLocale;
       
   182             
       
   183             TClockFormat format( ClockFormat( aProperty, useLocale ) );
       
   184             
       
   185             iClockControl->SetFormatL( useLocale, format );
       
   186             }
       
   187         else if( name == XnPropertyNames::clock::KS60DigitalFontSize )            
       
   188             {
       
   189             iDigitalFont = NULL;            
       
   190             }
       
   191         else if( name == XnPropertyNames::clock::KS60AmPmFontSize )
       
   192             {
       
   193             iAmPmFont = NULL;
       
   194             }
       
   195         else if( name == XnPropertyNames::clock::KS60DateFontSize )
       
   196             {
       
   197             iDateFont = NULL;
       
   198             }
       
   199         else if( name == XnPropertyNames::appearance::common::KColor )
       
   200             {
       
   201             iColorSet = EFalse;
       
   202             }
       
   203         }
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CXnClockAdapter::UpdateDisplay
       
   208 // Draws the clock component
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void CXnClockAdapter::UpdateDisplay() const
       
   212     {    
       
   213     if ( !iNode.Rect().IsEmpty() )
       
   214         {
       
   215         DrawNow();
       
   216         }
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CXnClockAdapter::Draw
       
   221 // Draws the clock component
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CXnClockAdapter::Draw( const TRect& aRect ) const
       
   225     {                           
       
   226     CXnControlAdapter::Draw( aRect );
       
   227     
       
   228     CWindowGc& gc( SystemGc() );
       
   229            
       
   230     iClockControl->Draw( gc, iNode.Rect() );
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CXnClockAdapter::MakeVisible
       
   235 // 
       
   236 // -----------------------------------------------------------------------------
       
   237 //        
       
   238 void CXnClockAdapter::MakeVisible( TBool aVisible )
       
   239     {
       
   240     TBool visible( IsVisible() );
       
   241     
       
   242     if ( aVisible != visible )
       
   243         {
       
   244         CCoeControl::MakeVisible( aVisible );
       
   245 
       
   246         if ( !aVisible )
       
   247             {
       
   248             iClockControl->StopTimer();
       
   249             }
       
   250         }
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CXnClockAdapter::MonitorWsMessage
       
   255 // 
       
   256 // -----------------------------------------------------------------------------
       
   257 //    
       
   258 void CXnClockAdapter::MonitorWsMessage( const TWsEvent& aEvent )
       
   259     {   
       
   260     TInt type( aEvent.Type() );
       
   261     
       
   262     TBool foreground( iForeground );
       
   263         
       
   264     if( type == KAknFullOrPartialForegroundGained )
       
   265         {
       
   266         iForeground = ETrue;        
       
   267         }
       
   268     else if( type == KAknFullOrPartialForegroundLost )        
       
   269         {
       
   270         iForeground = EFalse;        
       
   271         }
       
   272 
       
   273     if( foreground != iForeground && IsVisible() )            
       
   274         {
       
   275         if( iForeground )
       
   276             {
       
   277             iClockControl->StartTimer();
       
   278             }
       
   279         else
       
   280             {
       
   281             iClockControl->StopTimer();
       
   282             }            
       
   283         }
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CXnClockAdapter::FontL
       
   288 // 
       
   289 // -----------------------------------------------------------------------------
       
   290 //    
       
   291 const CAknLayoutFont* CXnClockAdapter::FontL( const TInt aType )
       
   292     {
       
   293     CFont* font( NULL );
       
   294     
       
   295     if( aType == EDigitalFont )
       
   296         {
       
   297         if( !iDigitalFont )
       
   298             {            
       
   299             CreateFontL( aType );
       
   300             }
       
   301         
       
   302         font = iDigitalFont;        
       
   303         }
       
   304     else if( aType == EAmPmFont )
       
   305         {
       
   306         if( !iAmPmFont )
       
   307             {
       
   308             CreateFontL( aType );        
       
   309             }
       
   310         
       
   311         font = iAmPmFont;
       
   312         }
       
   313     else if( aType == EDateFont )
       
   314         {
       
   315         if( !iDateFont )
       
   316             {
       
   317             CreateFontL( aType );        
       
   318             }
       
   319         
       
   320         font = iDateFont;        
       
   321         }
       
   322     
       
   323     if( font )
       
   324         {
       
   325         return CAknLayoutFont::AsCAknLayoutFontOrNull( font );
       
   326         }
       
   327     
       
   328     return NULL;
       
   329     }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CXnClockAdapter::TextColorL
       
   333 // 
       
   334 // -----------------------------------------------------------------------------
       
   335 //    
       
   336 const TRgb& CXnClockAdapter::TextColorL()
       
   337     {    
       
   338     if( !iColorSet )
       
   339         {
       
   340         CreateColorL();
       
   341         }
       
   342         
       
   343     return iColor;            
       
   344     }
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // CXnClockAdapter::Date
       
   348 // 
       
   349 // -----------------------------------------------------------------------------
       
   350 //    
       
   351 CXnNodePluginIf* CXnClockAdapter::Date() const
       
   352     {
       
   353     return iDate;
       
   354     }
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CXnClockAdapter::Day
       
   358 // 
       
   359 // -----------------------------------------------------------------------------
       
   360 //    
       
   361 CXnNodePluginIf* CXnClockAdapter::Day() const
       
   362     {
       
   363     return iDay;
       
   364     }
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // CXnClockAdapter::CreateFontL
       
   368 // 
       
   369 // -----------------------------------------------------------------------------
       
   370 //    
       
   371 void CXnClockAdapter::CreateFontL( const TInt aType )   
       
   372     {
       
   373     TFontSpec spec;
       
   374     TInt dummy;
       
   375 
       
   376     if( aType == EDigitalFont )
       
   377         {
       
   378         iDigitalFont = NULL;
       
   379         
       
   380         CXnProperty* prop( iNode.GetPropertyL( 
       
   381             XnPropertyNames::clock::KS60DigitalFontSize ) );
       
   382 
       
   383         // default
       
   384         TInt height( ( iNode.Rect().Height() / 3 ) * 2 );
       
   385 
       
   386         if ( prop )
       
   387             {
       
   388             height = iNode.UiEngineL()->VerticalPixelValueL(
       
   389                 prop, iNode.Rect().Height() );
       
   390             }
       
   391                                             
       
   392         // No need to relase avkon font
       
   393         CXnUtils::CreateFontL( KDigitalFont, 
       
   394                                height,
       
   395                                spec.iFontStyle,
       
   396                                iDigitalFont,
       
   397                                dummy );
       
   398         }
       
   399     else if( aType == EAmPmFont )
       
   400         {
       
   401         iAmPmFont = NULL;
       
   402 
       
   403         CXnProperty* prop( iNode.GetPropertyL( 
       
   404             XnPropertyNames::clock::KS60AmPmFontSize ) );
       
   405         
       
   406         // default
       
   407         TInt height( ( iNode.Rect().Height() / 5 ) );
       
   408 
       
   409         if ( prop )
       
   410             {
       
   411             height = iNode.UiEngineL()->VerticalPixelValueL(
       
   412                 prop, iNode.Rect().Height() );
       
   413             }        
       
   414         
       
   415         // No need to relase avkon font
       
   416         CXnUtils::CreateFontL( KAmPmFont, 
       
   417                                height,
       
   418                                spec.iFontStyle,
       
   419                                iAmPmFont,
       
   420                                dummy );      
       
   421         }
       
   422     else if( aType == EDateFont )
       
   423         {
       
   424         iDateFont = NULL;
       
   425         
       
   426         CXnProperty* prop( iNode.GetPropertyL( 
       
   427             XnPropertyNames::clock::KS60DateFontSize ) );
       
   428         
       
   429         // default 
       
   430         TInt height( ( iNode.Rect().Height() / 5 ) );
       
   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( KDateFont, 
       
   440                                height,
       
   441                                spec.iFontStyle,
       
   442                                iDateFont,
       
   443                                dummy );              
       
   444         }
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CXnClockAdapter::CreateColorL
       
   449 // 
       
   450 // -----------------------------------------------------------------------------
       
   451 //    
       
   452 void CXnClockAdapter::CreateColorL()
       
   453     {        
       
   454     TRgb color;
       
   455             
       
   456     TInt result( KErrNone );
       
   457         
       
   458     CXnProperty* prop( iNode.GetPropertyL( 
       
   459         XnPropertyNames::appearance::common::KColor ) );
       
   460     
       
   461     if( !prop )
       
   462         {
       
   463         return;
       
   464         }
       
   465         
       
   466     CXnDomProperty* domProp( prop->Property() );
       
   467     
       
   468     MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
       
   469     
       
   470     if( domProp )
       
   471         {        
       
   472         CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >
       
   473                                         ( domProp->PropertyValueList().Item( 0 ) );
       
   474         
       
   475         if( value->PrimitiveValueType() == CXnDomPropertyValue::ERgbColor )
       
   476             {
       
   477             color = value->RgbColorValueL();                
       
   478             }
       
   479         else if( !value->IsAutoIdent() )
       
   480         	{
       
   481             HBufC* str( prop->StringValueL() );
       
   482             CleanupStack::PushL( str );
       
   483             
       
   484             CXnUtils::StripQuotes( str );
       
   485             
       
   486             TInt index( 0 );
       
   487             TAknsItemID skinID;
       
   488             
       
   489             TBool idResolved( CXnUtils::ResolveSkinItemIDL( *str, skinID, index ) );
       
   490             
       
   491             result = KErrNotFound;
       
   492             
       
   493             if( idResolved )
       
   494             	{                	
       
   495             	result = AknsUtils::GetCachedColor( skin, color, skinID, index );
       
   496             	}                        
       
   497 
       
   498         	CleanupStack::PopAndDestroy( str );                	
       
   499         	}
       
   500         	
       
   501         if( value->IsAutoIdent() || result != KErrNone )
       
   502             {                                
       
   503             result = AknsUtils::GetCachedColor( skin, color, 
       
   504                                                 KAknsIIDQsnTextColors,
       
   505                                                 EAknsCIQsnTextColorsCG6 );
       
   506             }
       
   507         }
       
   508         
       
   509     if( result == KErrNone )
       
   510         {
       
   511         iColorSet = ETrue;
       
   512         iColor = color;
       
   513         }            
       
   514     }
       
   515 
       
   516 // -----------------------------------------------------------------------------
       
   517 // CXnClockAdapter::SkinChanged
       
   518 // Skin change notification
       
   519 // -----------------------------------------------------------------------------
       
   520 //  
       
   521 void CXnClockAdapter::SkinChanged()
       
   522     {
       
   523     iAmPmFont = iDigitalFont = iDateFont = NULL;
       
   524     iColorSet = EFalse;
       
   525     
       
   526     CXnControlAdapter::SkinChanged();
       
   527     }
       
   528 
       
   529 // -----------------------------------------------------------------------------
       
   530 // CXnClockAdapter::HandleScreenDeviceChangedL
       
   531 // Screen device change notification
       
   532 // -----------------------------------------------------------------------------
       
   533 //  
       
   534 void CXnClockAdapter::HandleScreenDeviceChangedL()
       
   535     {
       
   536     iAmPmFont = iDigitalFont = iDateFont = NULL;
       
   537     iColorSet = EFalse;
       
   538     
       
   539     CXnControlAdapter::HandleScreenDeviceChangedL();
       
   540     }
       
   541 
       
   542 // -----------------------------------------------------------------------------
       
   543 // CXnClockAdapter::SizeChanged
       
   544 // Size changed notification
       
   545 // -----------------------------------------------------------------------------
       
   546 //  
       
   547 void CXnClockAdapter::SizeChanged()
       
   548     {
       
   549     iAmPmFont = iDigitalFont = iDateFont = NULL;
       
   550     iColorSet = EFalse;
       
   551     
       
   552     CXnControlAdapter::SizeChanged();    
       
   553     }
       
   554 
       
   555 // End of file