idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockcontrol.cpp
branchRCL_3
changeset 35 3321d3e205b6
parent 34 5456b4e8b3a8
equal deleted inserted replaced
34:5456b4e8b3a8 35:3321d3e205b6
    22 // User includes
    22 // User includes
    23 #include <debug.h>
    23 #include <debug.h>
    24 #include "xncontroladapter.h"
    24 #include "xncontroladapter.h"
    25 #include "xnclockadapter.h"
    25 #include "xnclockadapter.h"
    26 #include "xnclockface.h"
    26 #include "xnclockface.h"
    27 
    27 #include "xnnodepluginif.h"
    28 #include "xnclockcontrol.h"
    28 #include "xnclockcontrol.h"
    29 
    29 
    30 // Constants
    30 // Constants
    31 static const TInt KIntervalTime( 60000000 ); // in microseconds
    31 static const TInt KIntervalTime( 60000000 ); // in microseconds
    32 
    32 
    37 // CXnClockControl::CXnClockControl
    37 // CXnClockControl::CXnClockControl
    38 // C++ default constructor can NOT contain any code, that
    38 // C++ default constructor can NOT contain any code, that
    39 // might leave.
    39 // might leave.
    40 // -----------------------------------------------------------------------------
    40 // -----------------------------------------------------------------------------
    41 //
    41 //
    42 CXnClockControl::CXnClockControl( CXnClockAdapter* aAdapter,
    42 CXnClockControl::CXnClockControl( CXnClockAdapter& aAdapter,
    43                                   const TBool aFormatFromLocale,
    43                                   const TBool aFormatFromLocale,
    44                                   const TClockFormat aFormat )
    44                                   const TClockFormat aFormat )
    45     : iAdapter( aAdapter ), 
    45     : iAdapter( aAdapter ), 
    46       iClockFormat( aFormat ),
    46       iClockFormat( aFormat ),
    47       iFormatFromLocale ( aFormatFromLocale )      
    47       iFormatFromLocale ( aFormatFromLocale )
    48     {
    48     {
    49     }
    49     }
    50 
    50 
    51 // -----------------------------------------------------------------------------
    51 // -----------------------------------------------------------------------------
    52 // CXnClockControl::ConstructL
    52 // CXnClockControl::ConstructL
    54 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
    55 //
    55 //
    56 void CXnClockControl::ConstructL()
    56 void CXnClockControl::ConstructL()
    57     {           
    57     {           
    58     iTimer = CPeriodic::NewL( CActive::EPriorityHigh );
    58     iTimer = CPeriodic::NewL( CActive::EPriorityHigh );
    59             
    59     iTimeFormat = TLocale().TimeFormat();
    60     SetFormatL( iFormatFromLocale, iClockFormat );   
    60     SetFormatL( iFormatFromLocale, iClockFormat );   
    61     }
    61     }
    62 
    62 
    63 // -----------------------------------------------------------------------------
    63 // -----------------------------------------------------------------------------
    64 // CXnClockControl::NewL
    64 // CXnClockControl::NewL
    65 // Two-phased constructor.
    65 // Two-phased constructor.
    66 // -----------------------------------------------------------------------------
    66 // -----------------------------------------------------------------------------
    67 //
    67 //
    68 CXnClockControl* CXnClockControl::NewL( CXnClockAdapter* aAdapter,
    68 CXnClockControl* CXnClockControl::NewL( CXnClockAdapter& aAdapter,
    69                                         const TBool aFormatFromLocale,
    69                                         const TBool aFormatFromLocale,
    70                                         const TClockFormat aFormat )
    70                                         const TClockFormat aFormat )
    71     {
    71     {
    72     CXnClockControl* self =
    72     CXnClockControl* self =
    73         new (ELeave) CXnClockControl( aAdapter, aFormatFromLocale, aFormat );
    73         new (ELeave) CXnClockControl( aAdapter, aFormatFromLocale, aFormat );
    74         
       
    75     CleanupStack::PushL( self );    
    74     CleanupStack::PushL( self );    
    76     self->ConstructL();
    75     self->ConstructL();
    77     
       
    78     CleanupStack::Pop( self );
    76     CleanupStack::Pop( self );
    79     
       
    80     return self;
    77     return self;
    81     }
    78     }
    82 
    79 
    83 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    84 // Destructor
    81 // Destructor
    85 //
       
    86 // -----------------------------------------------------------------------------
    82 // -----------------------------------------------------------------------------
    87 //
    83 //
    88 CXnClockControl::~CXnClockControl()
    84 CXnClockControl::~CXnClockControl()
    89     {    
    85     {    
    90     delete iTimer;
    86     delete iTimer;
    91     delete iFace;
    87     delete iFace;
    92     }
    88     }
    93 
    89 
    94 // -----------------------------------------------------------------------------
    90 // -----------------------------------------------------------------------------
    95 // CXnClockControl::UpdateDisplay
    91 // CXnClockControl::UpdateDisplay
    96 // (other items were commented in a header).
       
    97 // -----------------------------------------------------------------------------
    92 // -----------------------------------------------------------------------------
    98 //
    93 //
    99 void CXnClockControl::UpdateDisplay()
    94 void CXnClockControl::UpdateDisplay()
   100     {
    95     {
   101     if( !iFace )
    96     if( !iFace )
   102         {
    97         {
   103         return;
    98         return;
   104         }
    99         }
   105             
   100             
   106     iAdapter->UpdateDisplay();
   101     iAdapter.UpdateDisplay();
   107     }
   102     }
   108 
   103 
   109 // -----------------------------------------------------------------------------
   104 // -----------------------------------------------------------------------------
   110 // CXnClockControl::SetFormatL
   105 // CXnClockControl::SetFormatL
   111 // (other items were commented in a header).
       
   112 // -----------------------------------------------------------------------------
   106 // -----------------------------------------------------------------------------
   113 //
   107 //
   114 void CXnClockControl::SetFormatL( const TBool aFormatFromLocale, 
   108 void CXnClockControl::SetFormatL( const TBool aFormatFromLocale, 
   115                                   const TClockFormat aFormat )
   109                                   const TClockFormat aFormat )
   116     {
   110     {
   120         {
   114         {
   121         format = TLocale().ClockFormat();                
   115         format = TLocale().ClockFormat();                
   122         }
   116         }
   123         
   117         
   124     iFormatFromLocale = aFormatFromLocale;
   118     iFormatFromLocale = aFormatFromLocale;
   125         
   119     
   126     if( format == iClockFormat && iFace )
   120     TTimeFormat timeFormat = TLocale().TimeFormat();
       
   121         
       
   122     if( format == iClockFormat && iFace && timeFormat == iTimeFormat )
   127         {
   123         {
   128         // Already correct face
   124         // Already correct face
   129         return;    
   125         return;    
   130         }      
   126         }      
   131             
   127             
   132     iClockFormat = format;
   128     iClockFormat = format;
       
   129     iTimeFormat = timeFormat;
   133     
   130     
   134     delete iFace;
   131     delete iFace;
   135     iFace = NULL;
   132     iFace = NULL;
   136 
   133 
   137     if( format == EClockAnalog )
   134     if( format == EClockAnalog )
   139         iFace = CXnClockFaceAnalog::NewL();
   136         iFace = CXnClockFaceAnalog::NewL();
   140         }
   137         }
   141     else if( format == EClockDigital )
   138     else if( format == EClockDigital )
   142         {
   139         {
   143         iFace = CXnClockFaceDigital::NewL();
   140         iFace = CXnClockFaceDigital::NewL();
   144         }       
   141         }
       
   142     
       
   143     iAdapter.SetClockFormatL( format );
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CXnClockControl::CheckClockFormatL
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CXnClockControl::CheckClockFormatL()
       
   151     {
       
   152     SetFormatL( iFormatFromLocale, iClockFormat );
   145     }
   153     }
   146 
   154 
   147 // -----------------------------------------------------------------------------
   155 // -----------------------------------------------------------------------------
   148 // CXnClockControl::Format
   156 // CXnClockControl::Format
   149 // (other items were commented in a header).
       
   150 // -----------------------------------------------------------------------------
   157 // -----------------------------------------------------------------------------
   151 //       
   158 //       
   152 TClockFormat CXnClockControl::Format() const
   159 TClockFormat CXnClockControl::Format() const
   153     {
   160     {
   154     return iClockFormat;
   161     return iClockFormat;
   155     }
   162     }
   156 
   163 
   157 // -----------------------------------------------------------------------------
   164 // -----------------------------------------------------------------------------
   158 // CXnClockControl::Draw
   165 // CXnClockControl::Draw
   159 // (other items were commented in a header).
       
   160 // -----------------------------------------------------------------------------
   166 // -----------------------------------------------------------------------------
   161 //       
   167 //       
   162 void CXnClockControl::Draw( CWindowGc& aGc, const TRect& aRect )
   168 void CXnClockControl::Draw( CWindowGc& aGc, CXnNodePluginIf* aNode,
   163     {
   169         CXnNodePluginIf* aAmpm )
   164     // Ensure correct appearance
   170     {
   165     TRAP_IGNORE( SetFormatL( iFormatFromLocale, iClockFormat ) );
   171     if ( !aNode )
   166     
   172         {
   167     if( iFace && !aRect.IsEmpty() )
   173         return;
       
   174         }
       
   175     
       
   176     if( iFace && !aNode->Rect().IsEmpty() )
   168         {
   177         {
   169         __PRINT( __DBG_FORMAT( "CXnClockControl::Draw: 0x%X" ), this );
   178         __PRINT( __DBG_FORMAT( "CXnClockControl::Draw: 0x%X" ), this );
   170                 
   179                 
   171         TTime homeTime;
   180         TTime homeTime;
   172         homeTime.HomeTime();
   181         homeTime.HomeTime();
   173 
   182 
   174         TRAP_IGNORE( iFace->DrawL( *iAdapter, aGc, aRect, homeTime ) );
   183         TRAP_IGNORE( iFace->DrawL( iAdapter, aGc, *aNode, homeTime, aAmpm ) );
   175         }
   184         }
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CXnClockControl::ResetFont
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CXnClockControl::ResetFont()
       
   192     {
       
   193     iFace->ResetFont();
   176     }
   194     }
   177 
   195 
   178 // -----------------------------------------------------------------------------
   196 // -----------------------------------------------------------------------------
   179 // CXnClockControl::TimerCallback
   197 // CXnClockControl::TimerCallback
   180 // (other items were commented in a header).
       
   181 // -----------------------------------------------------------------------------
   198 // -----------------------------------------------------------------------------
   182 //
   199 //
   183 TInt CXnClockControl::TimerCallback( TAny* aThis )
   200 TInt CXnClockControl::TimerCallback( TAny* aThis )
   184     {
   201     {
   185     __PRINT( __DBG_FORMAT( "CXnClockControl::TimerCallback: 0x%X" ), aThis );    
   202     __PRINT( __DBG_FORMAT( "CXnClockControl::TimerCallback: 0x%X" ), aThis );    
   204     return KErrNone;
   221     return KErrNone;
   205     }
   222     }
   206     
   223     
   207 // -----------------------------------------------------------------------------
   224 // -----------------------------------------------------------------------------
   208 // CXnClockControl::StartTimer
   225 // CXnClockControl::StartTimer
   209 // (other items were commented in a header).
       
   210 // -----------------------------------------------------------------------------
   226 // -----------------------------------------------------------------------------
   211 //
   227 //
   212 void CXnClockControl::StartTimer()
   228 void CXnClockControl::StartTimer()
   213     {
   229     {
   214     if ( iTimer && !iTimer->IsActive() )
   230     if ( iTimer && !iTimer->IsActive() )
   228         }
   244         }
   229     }
   245     }
   230 
   246 
   231 // -----------------------------------------------------------------------------
   247 // -----------------------------------------------------------------------------
   232 // CXnClockControl::StopTimer
   248 // CXnClockControl::StopTimer
   233 // (other items were commented in a header).
       
   234 // -----------------------------------------------------------------------------
   249 // -----------------------------------------------------------------------------
   235 //
   250 //
   236 void CXnClockControl::StopTimer()
   251 void CXnClockControl::StopTimer()
   237     {
   252     {
   238     if ( iTimer && iTimer->IsActive() )
   253     if ( iTimer && iTimer->IsActive() )