idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockcontrol.cpp
branchRCL_3
changeset 102 ba63c83f4716
parent 88 3321d3e205b6
equal deleted inserted replaced
93:b01126ce0bec 102:ba63c83f4716
    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 #include "xnnodepluginif.h"
    27 
    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     iTimeFormat = TLocale().TimeFormat();
    59             
    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         
    74     CleanupStack::PushL( self );    
    75     CleanupStack::PushL( self );    
    75     self->ConstructL();
    76     self->ConstructL();
       
    77     
    76     CleanupStack::Pop( self );
    78     CleanupStack::Pop( self );
       
    79     
    77     return self;
    80     return self;
    78     }
    81     }
    79 
    82 
    80 // -----------------------------------------------------------------------------
    83 // -----------------------------------------------------------------------------
    81 // Destructor
    84 // Destructor
       
    85 //
    82 // -----------------------------------------------------------------------------
    86 // -----------------------------------------------------------------------------
    83 //
    87 //
    84 CXnClockControl::~CXnClockControl()
    88 CXnClockControl::~CXnClockControl()
    85     {    
    89     {    
    86     delete iTimer;
    90     delete iTimer;
    87     delete iFace;
    91     delete iFace;
    88     }
    92     }
    89 
    93 
    90 // -----------------------------------------------------------------------------
    94 // -----------------------------------------------------------------------------
    91 // CXnClockControl::UpdateDisplay
    95 // CXnClockControl::UpdateDisplay
       
    96 // (other items were commented in a header).
    92 // -----------------------------------------------------------------------------
    97 // -----------------------------------------------------------------------------
    93 //
    98 //
    94 void CXnClockControl::UpdateDisplay()
    99 void CXnClockControl::UpdateDisplay()
    95     {
   100     {
    96     if( !iFace )
   101     if( !iFace )
    97         {
   102         {
    98         return;
   103         return;
    99         }
   104         }
   100             
   105             
   101     iAdapter.UpdateDisplay();
   106     iAdapter->UpdateDisplay();
   102     }
   107     }
   103 
   108 
   104 // -----------------------------------------------------------------------------
   109 // -----------------------------------------------------------------------------
   105 // CXnClockControl::SetFormatL
   110 // CXnClockControl::SetFormatL
       
   111 // (other items were commented in a header).
   106 // -----------------------------------------------------------------------------
   112 // -----------------------------------------------------------------------------
   107 //
   113 //
   108 void CXnClockControl::SetFormatL( const TBool aFormatFromLocale, 
   114 void CXnClockControl::SetFormatL( const TBool aFormatFromLocale, 
   109                                   const TClockFormat aFormat )
   115                                   const TClockFormat aFormat )
   110     {
   116     {
   114         {
   120         {
   115         format = TLocale().ClockFormat();                
   121         format = TLocale().ClockFormat();                
   116         }
   122         }
   117         
   123         
   118     iFormatFromLocale = aFormatFromLocale;
   124     iFormatFromLocale = aFormatFromLocale;
   119     
   125         
   120     TTimeFormat timeFormat = TLocale().TimeFormat();
   126     if( format == iClockFormat && iFace )
   121         
       
   122     if( format == iClockFormat && iFace && timeFormat == iTimeFormat )
       
   123         {
   127         {
   124         // Already correct face
   128         // Already correct face
   125         return;    
   129         return;    
   126         }      
   130         }      
   127             
   131             
   128     iClockFormat = format;
   132     iClockFormat = format;
   129     iTimeFormat = timeFormat;
       
   130     
   133     
   131     delete iFace;
   134     delete iFace;
   132     iFace = NULL;
   135     iFace = NULL;
   133 
   136 
   134     if( format == EClockAnalog )
   137     if( format == EClockAnalog )
   136         iFace = CXnClockFaceAnalog::NewL();
   139         iFace = CXnClockFaceAnalog::NewL();
   137         }
   140         }
   138     else if( format == EClockDigital )
   141     else if( format == EClockDigital )
   139         {
   142         {
   140         iFace = CXnClockFaceDigital::NewL();
   143         iFace = CXnClockFaceDigital::NewL();
   141         }
   144         }       
   142     
       
   143     iAdapter.SetClockFormatL( format );
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CXnClockControl::CheckClockFormatL
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CXnClockControl::CheckClockFormatL()
       
   151     {
       
   152     SetFormatL( iFormatFromLocale, iClockFormat );
       
   153     }
   145     }
   154 
   146 
   155 // -----------------------------------------------------------------------------
   147 // -----------------------------------------------------------------------------
   156 // CXnClockControl::Format
   148 // CXnClockControl::Format
       
   149 // (other items were commented in a header).
   157 // -----------------------------------------------------------------------------
   150 // -----------------------------------------------------------------------------
   158 //       
   151 //       
   159 TClockFormat CXnClockControl::Format() const
   152 TClockFormat CXnClockControl::Format() const
   160     {
   153     {
   161     return iClockFormat;
   154     return iClockFormat;
   162     }
   155     }
   163 
   156 
   164 // -----------------------------------------------------------------------------
   157 // -----------------------------------------------------------------------------
   165 // CXnClockControl::Draw
   158 // CXnClockControl::Draw
       
   159 // (other items were commented in a header).
   166 // -----------------------------------------------------------------------------
   160 // -----------------------------------------------------------------------------
   167 //       
   161 //       
   168 void CXnClockControl::Draw( CWindowGc& aGc, CXnNodePluginIf* aNode,
   162 void CXnClockControl::Draw( CWindowGc& aGc, const TRect& aRect )
   169         CXnNodePluginIf* aAmpm )
   163     {
   170     {
   164     // Ensure correct appearance
   171     if ( !aNode )
   165     TRAP_IGNORE( SetFormatL( iFormatFromLocale, iClockFormat ) );
   172         {
   166     
   173         return;
   167     if( iFace && !aRect.IsEmpty() )
   174         }
       
   175     
       
   176     if( iFace && !aNode->Rect().IsEmpty() )
       
   177         {
   168         {
   178         __PRINT( __DBG_FORMAT( "CXnClockControl::Draw: 0x%X" ), this );
   169         __PRINT( __DBG_FORMAT( "CXnClockControl::Draw: 0x%X" ), this );
   179                 
   170                 
   180         TTime homeTime;
   171         TTime homeTime;
   181         homeTime.HomeTime();
   172         homeTime.HomeTime();
   182 
   173 
   183         TRAP_IGNORE( iFace->DrawL( iAdapter, aGc, *aNode, homeTime, aAmpm ) );
   174         TRAP_IGNORE( iFace->DrawL( *iAdapter, aGc, aRect, homeTime ) );
   184         }
   175         }
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CXnClockControl::ResetFont
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CXnClockControl::ResetFont()
       
   192     {
       
   193     iFace->ResetFont();
       
   194     }
   176     }
   195 
   177 
   196 // -----------------------------------------------------------------------------
   178 // -----------------------------------------------------------------------------
   197 // CXnClockControl::TimerCallback
   179 // CXnClockControl::TimerCallback
       
   180 // (other items were commented in a header).
   198 // -----------------------------------------------------------------------------
   181 // -----------------------------------------------------------------------------
   199 //
   182 //
   200 TInt CXnClockControl::TimerCallback( TAny* aThis )
   183 TInt CXnClockControl::TimerCallback( TAny* aThis )
   201     {
   184     {
   202     __PRINT( __DBG_FORMAT( "CXnClockControl::TimerCallback: 0x%X" ), aThis );    
   185     __PRINT( __DBG_FORMAT( "CXnClockControl::TimerCallback: 0x%X" ), aThis );    
   221     return KErrNone;
   204     return KErrNone;
   222     }
   205     }
   223     
   206     
   224 // -----------------------------------------------------------------------------
   207 // -----------------------------------------------------------------------------
   225 // CXnClockControl::StartTimer
   208 // CXnClockControl::StartTimer
       
   209 // (other items were commented in a header).
   226 // -----------------------------------------------------------------------------
   210 // -----------------------------------------------------------------------------
   227 //
   211 //
   228 void CXnClockControl::StartTimer()
   212 void CXnClockControl::StartTimer()
   229     {
   213     {
   230     if ( iTimer && !iTimer->IsActive() )
   214     if ( iTimer && !iTimer->IsActive() )
   244         }
   228         }
   245     }
   229     }
   246 
   230 
   247 // -----------------------------------------------------------------------------
   231 // -----------------------------------------------------------------------------
   248 // CXnClockControl::StopTimer
   232 // CXnClockControl::StopTimer
       
   233 // (other items were commented in a header).
   249 // -----------------------------------------------------------------------------
   234 // -----------------------------------------------------------------------------
   250 //
   235 //
   251 void CXnClockControl::StopTimer()
   236 void CXnClockControl::StopTimer()
   252     {
   237     {
   253     if ( iTimer && iTimer->IsActive() )
   238     if ( iTimer && iTimer->IsActive() )