idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockadapter.cpp
branchRCL_3
changeset 88 3321d3e205b6
parent 83 5456b4e8b3a8
child 93 b01126ce0bec
--- a/idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockadapter.cpp	Wed Sep 01 12:32:46 2010 +0100
+++ b/idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockadapter.cpp	Tue Sep 14 20:58:58 2010 +0300
@@ -31,15 +31,13 @@
 #include "xncontroladapter.h"
 #include "xnclockcontrol.h"
 #include "xnclockadapter.h"
+#include "xndatecontrol.h"
 #include "c_xnutils.h"
 
 // Constants
-_LIT8( KDateInformation, "Clock/DateInformation" );
-_LIT8( KDayInformation, "Clock/DayInformation" );
-
-_LIT( KDigitalFont, "EAknLogicalFontSecondaryFont" );
-_LIT( KAmPmFont, "EAknLogicalFontSecondaryFont" );
-_LIT( KDateFont, "EAknLogicalFontSecondaryFont" );
+_LIT8( KDisplay, "display" );
+_LIT8( KNone, "none" );
+_LIT8( KBlock, "block" );
 
 // ============================ LOCAL FUNCTIONS ===============================    
 
@@ -120,6 +118,8 @@
 
     delete iLightObserver;    
     delete iClockControl;
+    delete iDateControl;
+    delete iDayControl;
     }
 
 // -----------------------------------------------------------------------------
@@ -135,45 +135,177 @@
     
     iLightObserver = CHWRMLight::NewL( this );
     
+    TBool useLocale;
+    CXnProperty* prop( 
+        iNode.GetPropertyL( XnPropertyNames::clock::KS60Format ) );
+    TClockFormat format( ClockFormat( prop, useLocale ) );
+    
     RPointerArray< CXnNodePluginIf > children( iNode.ChildrenL() );
     CleanupClosePushL( children );
     
-    for( TInt i = 0; i < children.Count(); i++ )
+    for ( TInt i = 0; i < children.Count(); i++ )
         {
         CXnNodePluginIf* child( children[i] );
-        
-        CXnProperty* id( child->IdL() );
+        const TDesC8& clocktype = child->Type()->Type();
         
-        if( id )         
+        if ( clocktype == XnPropertyNames::clock::format::KDigital )
+            {
+            iDigital = child;
+            }
+        else if ( clocktype == XnPropertyNames::clock::format::KAnalog )
+            {
+            iAnalog = child;
+            }
+        else if ( clocktype == XnPropertyNames::clock::KDate )
             {
-            if( id->StringValue() == KDateInformation )
+            if ( !iDateControl )
+                {
+                iDateControl = CXnDateControl::NewL( *this, EDate );
+                }
+            iDate = child;
+            }
+
+        RPointerArray< CXnNodePluginIf > clockChildren( child->ChildrenL() );
+        CleanupClosePushL( clockChildren );
+        for ( TInt j = 0; j < clockChildren.Count(); j++ )
+            {
+            CXnNodePluginIf* clockChild( clockChildren[j] );
+            const TDesC8& childType = clockChild->Type()->Type();
+            
+            if ( childType == XnPropertyNames::clock::KFace12 )
+                {
+                if ( !iClockControl )
+                    {
+                    iClockControl = CXnClockControl::NewL( *this, useLocale, format );
+                    }
+                iDigitalFace12 = clockChild;
+                }
+            else if ( childType == XnPropertyNames::clock::KFace24 )
                 {
-                iDate = child;                               
+                if ( !iClockControl )
+                    {
+                    iClockControl = CXnClockControl::NewL( *this, useLocale, format );
+                    }
+                iDigitalFace24 = clockChild;
                 }
-            else if( id->StringValue() == KDayInformation )
+            else if ( childType == XnPropertyNames::clock::KFace )
+               {
+                if ( !iClockControl )
+                    {
+                    iClockControl = CXnClockControl::NewL( *this, useLocale, format );
+                    }
+                iAnalogFace = clockChild;
+               }
+            else if ( childType == XnPropertyNames::clock::KDate &&
+                      clocktype == XnPropertyNames::clock::format::KDigital )
                 {
-                iDay = child;
+                if ( !iDateControl )
+                    {
+                    iDateControl = CXnDateControl::NewL( *this, EDate );
+                    }
+                iDigitalDate = clockChild;
+                }
+            else if ( childType == XnPropertyNames::clock::KDate &&
+                      clocktype == XnPropertyNames::clock::format::KAnalog )
+                {
+                if ( !iDateControl )
+                    {
+                    iDateControl = CXnDateControl::NewL( *this, EDate );
+                    }
+                iAnalogDate = clockChild;
                 }
+            else if ( childType == XnPropertyNames::clock::KDay )
+               {
+                if ( !iDayControl )
+                    {
+                    iDayControl = CXnDateControl::NewL( *this, EDay );
+                    }
+                iDay = clockChild;
+               }
+            else if ( childType == XnPropertyNames::clock::KAmpm )
+               {
+                iAmpm = clockChild;
+               }
             }
+        CleanupStack::PopAndDestroy( &clockChildren );
         }
         
     CleanupStack::PopAndDestroy( &children );
     
-    TBool useLocale;
-
-    CXnProperty* prop( 
-        iNode.GetPropertyL( XnPropertyNames::clock::KS60Format ) );    
-    
-    TClockFormat format( ClockFormat( prop, useLocale ) );   
-    
-    iClockControl = CXnClockControl::NewL( this, useLocale, format );    
+    SetClockFormatL( format );
     
     iCoeEnv->AddMessageMonitorObserverL( *this );
 	}
+
+// -----------------------------------------------------------------------------
+// CXnClockAdapter::SetDisplayToBlockL
+// -----------------------------------------------------------------------------
+// 
+void CXnClockAdapter::SetDisplayToBlockL( CXnNodePluginIf& aNode, TBool aBlock )
+    {
+    CXnDomStringPool& sp = aNode.UiEngineL()->StringPool();
+    CXnProperty* prop;
+    if ( aBlock )
+        {
+        prop = CXnProperty::NewL( 
+            KDisplay, KBlock, CXnDomPropertyValue::EString, sp );
+        }
+    else
+        {
+        prop = CXnProperty::NewL( 
+            KDisplay, KNone, CXnDomPropertyValue::EString, sp );
+        }
+    CleanupStack::PushL( prop );
+    aNode.SetPropertyL( prop );
+    CleanupStack::Pop( prop );
+    }
+
+// -----------------------------------------------------------------------------
+// CXnClockAdapter::SetClockFormatL
+// -----------------------------------------------------------------------------
+// 
+void CXnClockAdapter::SetClockFormatL( TClockFormat aFormat )
+    {
+    if ( iAnalog && iDigital )
+        {
+        if ( aFormat == EClockAnalog  )
+            {
+            SetDisplayToBlockL( *iAnalog, ETrue );
+            SetDisplayToBlockL( *iDigital, EFalse );
+            }
+        else
+            {
+            SetDisplayToBlockL( *iDigital, ETrue );
+            SetDisplayToBlockL( *iAnalog, EFalse );
+            // check whether time format is 12 or 24
+            if ( iDigitalFace12 && iDigitalFace24 )
+                {
+                if ( TLocale().TimeFormat() == ETime12 )
+                    {
+                    SetDisplayToBlockL( *iDigitalFace12, ETrue );
+                    if ( iAmpm )
+                        {
+                        SetDisplayToBlockL( *iAmpm, ETrue );
+                        }
+                    SetDisplayToBlockL( *iDigitalFace24, EFalse );
+                    }
+                else
+                    {
+                    SetDisplayToBlockL( *iDigitalFace24, ETrue );
+                    SetDisplayToBlockL( *iDigitalFace12, EFalse );
+                    if ( iAmpm )
+                        {
+                        SetDisplayToBlockL( *iAmpm, EFalse );
+                        }
+                    }
+                }
+            }
+        iNode.UiEngineL()->LayoutUIL( &iNode );
+        }
+    }
  
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::DoHandlePropertyChangeL
-//
 // -----------------------------------------------------------------------------
 //
 void CXnClockAdapter::DoHandlePropertyChangeL( CXnProperty* aProperty )
@@ -182,7 +314,7 @@
         {
         const TDesC8& name( aProperty->Property()->Name() );
         
-        if( name == XnPropertyNames::clock::KS60Format )
+        if( iClockControl && name == XnPropertyNames::clock::KS60Format )
             {
             TBool useLocale;
             
@@ -190,28 +322,11 @@
             
             iClockControl->SetFormatL( useLocale, format );
             }
-        else if( name == XnPropertyNames::clock::KS60DigitalFontSize )            
-            {
-            iDigitalFont = NULL;            
-            }
-        else if( name == XnPropertyNames::clock::KS60AmPmFontSize )
-            {
-            iAmPmFont = NULL;
-            }
-        else if( name == XnPropertyNames::clock::KS60DateFontSize )
-            {
-            iDateFont = NULL;
-            }
-        else if( name == XnPropertyNames::appearance::common::KColor )
-            {
-            iColorSet = EFalse;
-            }
         }
     }
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::UpdateDisplay
-// Draws the clock component
 // -----------------------------------------------------------------------------
 //
 void CXnClockAdapter::UpdateDisplay() const
@@ -224,7 +339,6 @@
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::Draw
-// Draws the clock component
 // -----------------------------------------------------------------------------
 //
 void CXnClockAdapter::Draw( const TRect& aRect ) const
@@ -232,13 +346,51 @@
     CXnControlAdapter::Draw( aRect );
     
     CWindowGc& gc( SystemGc() );
-           
-    iClockControl->Draw( gc, iNode.Rect() );
+
+    if ( iClockControl )
+        {
+        TClockFormat format = iClockControl->Format();
+        if ( format == EClockAnalog )
+            {
+            iClockControl->Draw( gc, iAnalogFace, NULL );
+            }
+        else
+            {
+            if ( TLocale().TimeFormat() == ETime12 )
+                {
+                iClockControl->Draw( gc, iDigitalFace12, iAmpm );
+                }
+            else
+                {
+                iClockControl->Draw( gc, iDigitalFace24, NULL );
+                }
+            }
+        }
+    
+    if ( iDateControl )
+        {
+        if ( iClockControl && iClockControl->Format() == EClockAnalog && iAnalogDate )
+            {
+            TRAP_IGNORE( iDateControl->DrawL( gc, iAnalogDate ) );
+            }
+        else if ( iClockControl && iClockControl->Format() == EClockDigital && iDigitalDate )
+            {
+            TRAP_IGNORE( iDateControl->DrawL( gc, iDigitalDate ) );
+            }
+        else
+            {
+            TRAP_IGNORE( iDateControl->DrawL( gc, iDate ) );
+            }
+        }
+    
+    if ( iDayControl )
+        {
+        TRAP_IGNORE( iDayControl->DrawL( gc, iDay ) );
+        }
     }
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::MakeVisible
-// 
 // -----------------------------------------------------------------------------
 //        
 void CXnClockAdapter::MakeVisible( TBool aVisible )
@@ -263,7 +415,6 @@
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::MonitorWsMessage
-// 
 // -----------------------------------------------------------------------------
 //    
 void CXnClockAdapter::MonitorWsMessage( const TWsEvent& aEvent )
@@ -284,9 +435,13 @@
     if( foreground != iForeground )            
         {
         if( iForeground )
-            {   
+            {
+            // check if clock format has changed
+            if ( iClockControl )
+                {
+                TRAP_IGNORE( iClockControl->CheckClockFormatL() );
+                }
             UpdateDisplay();
-            
             // Start clock ensures UI state
             StartClock();
             }
@@ -299,7 +454,6 @@
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::LightStatusChanged
-// 
 // -----------------------------------------------------------------------------
 //    
 void CXnClockAdapter::LightStatusChanged( TInt aTarget, 
@@ -328,185 +482,101 @@
         }
     }
 
-
 // -----------------------------------------------------------------------------
-// CXnClockAdapter::FontL
-// 
+// CXnClockAdapter::GetTextAlignL
 // -----------------------------------------------------------------------------
-//    
-const CAknLayoutFont* CXnClockAdapter::FontL( const TInt aType )
+// 
+CGraphicsContext::TTextAlign CXnClockAdapter::GetTextAlignL( CXnNodePluginIf& aNode )
     {
-    CFont* font( NULL );
+    CGraphicsContext::TTextAlign ret = CGraphicsContext::ECenter;
+    CXnProperty* prop( aNode.GetPropertyL( 
+            XnPropertyNames::appearance::common::KTextAlign ) );
     
-    if( aType == EDigitalFont )
-        {
-        if( !iDigitalFont )
-            {            
-            CreateFontL( aType );
-            }
-        
-        font = iDigitalFont;        
-        }
-    else if( aType == EAmPmFont )
-        {
-        if( !iAmPmFont )
-            {
-            CreateFontL( aType );        
-            }
-        
-        font = iAmPmFont;
-        }
-    else if( aType == EDateFont )
-        {
-        if( !iDateFont )
-            {
-            CreateFontL( aType );        
-            }
-        
-        font = iDateFont;        
-        }
-    
-    if( font )
+    if( prop )
         {
-        return CAknLayoutFont::AsCAknLayoutFontOrNull( font );
-        }
-    
-    return NULL;
-    }
-
-// -----------------------------------------------------------------------------
-// CXnClockAdapter::TextColorL
-// 
-// -----------------------------------------------------------------------------
-//    
-const TRgb& CXnClockAdapter::TextColorL()
-    {    
-    if( !iColorSet )
-        {
-        CreateColorL();
+        if ( prop->StringValue() ==
+                XnPropertyNames::appearance::common::textalign::KAlignLeft )
+            {
+            ret = CGraphicsContext::ELeft;
+            }
+        else if ( prop->StringValue() ==
+                XnPropertyNames::appearance::common::textalign::KAlignRight )
+            {
+            ret = CGraphicsContext::ERight;
+            }
+        else if ( prop->StringValue() ==
+                XnPropertyNames::appearance::common::textalign::KAlignCenter )
+            {
+            ret = CGraphicsContext::ECenter;
+            }
         }
-        
-    return iColor;            
-    }
-
-// -----------------------------------------------------------------------------
-// CXnClockAdapter::Date
-// 
-// -----------------------------------------------------------------------------
-//    
-CXnNodePluginIf* CXnClockAdapter::Date() const
-    {
-    return iDate;
-    }
-
-// -----------------------------------------------------------------------------
-// CXnClockAdapter::Day
-// 
-// -----------------------------------------------------------------------------
-//    
-CXnNodePluginIf* CXnClockAdapter::Day() const
-    {
-    return iDay;
+    return ret;
     }
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::CreateFontL
-// 
 // -----------------------------------------------------------------------------
 //    
-void CXnClockAdapter::CreateFontL( const TInt aType )   
+void CXnClockAdapter::CreateFontL( CXnNodePluginIf& aNode,
+                                   const TDesC& aFontName,
+                                   CFont*& aFont )
     {
     TFontSpec spec;
     TInt dummy;
+    
+    CXnProperty* prop( aNode.GetPropertyL( 
+        XnPropertyNames::clock::KS60FontSize ) );
 
-    if( aType == EDigitalFont )
+    // default
+    TInt height( ( aNode.Rect().Height() / 5 ) );
+
+    if ( prop )
         {
-        iDigitalFont = NULL;
-        
-        CXnProperty* prop( iNode.GetPropertyL( 
-            XnPropertyNames::clock::KS60DigitalFontSize ) );
-
-        // default
-        TInt height( ( iNode.Rect().Height() / 3 ) * 2 );
-
+        height = aNode.UiEngineL()->VerticalPixelValueL(
+            prop, aNode.Rect().Height() );
+        }
+    else
+        {
+        // check if fontsize is defined in clock element
+        prop = iNode.GetPropertyL( 
+            XnPropertyNames::clock::KS60FontSize );
         if ( prop )
             {
             height = iNode.UiEngineL()->VerticalPixelValueL(
                 prop, iNode.Rect().Height() );
             }
-                                            
-        // No need to relase avkon font
-        CXnUtils::CreateFontL( KDigitalFont, 
-                               height,
-                               spec.iFontStyle,
-                               iDigitalFont,
-                               dummy );
         }
-    else if( aType == EAmPmFont )
-        {
-        iAmPmFont = NULL;
-
-        CXnProperty* prop( iNode.GetPropertyL( 
-            XnPropertyNames::clock::KS60AmPmFontSize ) );
-        
-        // default
-        TInt height( ( iNode.Rect().Height() / 5 ) );
-
-        if ( prop )
-            {
-            height = iNode.UiEngineL()->VerticalPixelValueL(
-                prop, iNode.Rect().Height() );
-            }        
-        
-        // No need to relase avkon font
-        CXnUtils::CreateFontL( KAmPmFont, 
-                               height,
-                               spec.iFontStyle,
-                               iAmPmFont,
-                               dummy );      
-        }
-    else if( aType == EDateFont )
-        {
-        iDateFont = NULL;
-        
-        CXnProperty* prop( iNode.GetPropertyL( 
-            XnPropertyNames::clock::KS60DateFontSize ) );
-        
-        // default 
-        TInt height( ( iNode.Rect().Height() / 5 ) );
-        
-        if ( prop )
-            {
-            height = iNode.UiEngineL()->VerticalPixelValueL(
-                prop, iNode.Rect().Height() );
-            }
-        
-        // No need to relase avkon font
-        CXnUtils::CreateFontL( KDateFont, 
-                               height,
-                               spec.iFontStyle,
-                               iDateFont,
-                               dummy );              
-        }
+                                        
+    // No need to relase avkon font
+    CXnUtils::CreateFontL( aFontName, 
+                           height,
+                           spec.iFontStyle,
+                           aFont,
+                           dummy );
     }
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::CreateColorL
-// 
 // -----------------------------------------------------------------------------
 //    
-void CXnClockAdapter::CreateColorL()
+void CXnClockAdapter::CreateColorL( CXnNodePluginIf& aNode, TRgb& aColor )
     {        
     TRgb color;
             
     TInt result( KErrNone );
         
-    CXnProperty* prop( iNode.GetPropertyL( 
+    CXnProperty* prop( aNode.GetPropertyL( 
         XnPropertyNames::appearance::common::KColor ) );
     
     if( !prop )
         {
-        return;
+        // check if color is defined in clock element
+        prop = iNode.GetPropertyL( 
+            XnPropertyNames::appearance::common::KColor );
+        if ( !prop )
+            {
+            return;
+            }
         }
         
     CXnDomProperty* domProp( prop->Property() );
@@ -554,53 +624,78 @@
         
     if( result == KErrNone )
         {
-        iColorSet = ETrue;
-        iColor = color;
+        aColor = color;
         }            
     }
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::SkinChanged
-// Skin change notification
 // -----------------------------------------------------------------------------
 //  
 void CXnClockAdapter::SkinChanged()
     {
-    iAmPmFont = iDigitalFont = iDateFont = NULL;
-    iColorSet = EFalse;
+    if ( iClockControl )
+        {
+        iClockControl->ResetFont();
+        }
+    if ( iDateControl )
+        {
+        iDateControl->ResetFont();
+        }
+    if ( iDayControl )
+        {
+        iDayControl->ResetFont();
+        }
     
     CXnControlAdapter::SkinChanged();
     }
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::HandleScreenDeviceChangedL
-// Screen device change notification
 // -----------------------------------------------------------------------------
 //  
 void CXnClockAdapter::HandleScreenDeviceChangedL()
     {
-    iAmPmFont = iDigitalFont = iDateFont = NULL;
-    iColorSet = EFalse;
+    if ( iClockControl )
+        {
+        iClockControl->ResetFont();
+        }
+    if ( iDateControl )
+        {
+        iDateControl->ResetFont();
+        }
+    if ( iDayControl )
+        {
+        iDayControl->ResetFont();
+        }
     
     CXnControlAdapter::HandleScreenDeviceChangedL();
     }
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::SizeChanged
-// Size changed notification
 // -----------------------------------------------------------------------------
 //  
 void CXnClockAdapter::SizeChanged()
     {
-    iAmPmFont = iDigitalFont = iDateFont = NULL;
-    iColorSet = EFalse;
+    if ( iClockControl )
+        {
+        iClockControl->ResetFont();
+        }
+    if ( iDateControl )
+        {
+        iDateControl->ResetFont();
+        }
+    if ( iDayControl )
+        {
+        iDayControl->ResetFont();
+        }
     
     CXnControlAdapter::SizeChanged();    
     }
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::StartClock
-// 
 // -----------------------------------------------------------------------------
 // 
 void CXnClockAdapter::StartClock()
@@ -620,7 +715,6 @@
 
 // -----------------------------------------------------------------------------
 // CXnClockAdapter::StopClock
-// 
 // -----------------------------------------------------------------------------
 // 
 void CXnClockAdapter::StopClock()
@@ -628,7 +722,7 @@
     if ( iClockControl )
         {
         iClockControl->StopTimer();
-        }    
+        }
     }
 
 // End of file