9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Implementation for xuikon clock. |
14 * Description: Clock control |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 // SYSTEM INCLUDE FILES |
19 // System includes |
20 #include <e32std.h> // for RChangeNotifier |
20 #include <e32std.h> |
|
21 |
|
22 // User includes |
21 #include <debug.h> |
23 #include <debug.h> |
22 |
|
23 // USER INCLUDE FILES |
|
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 |
28 #include "xnclockcontrol.h" |
28 #include "xnclockcontrol.h" |
29 |
29 |
30 |
30 // Constants |
31 // LOCAL CONSTANTS AND MACROS |
|
32 static const TInt KIntervalTime( 60000000 ); // in microseconds |
31 static const TInt KIntervalTime( 60000000 ); // in microseconds |
33 |
32 |
34 |
|
35 // MODULE DATA STRUCTURES |
|
36 class CXnClockChangeHandler : public CActive |
|
37 { |
|
38 public: // Constructor and destructor |
|
39 static CXnClockChangeHandler* NewL( |
|
40 CXnClockControl& aClient ) |
|
41 { |
|
42 CXnClockChangeHandler* self = |
|
43 new (ELeave) CXnClockChangeHandler( aClient ); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 virtual ~CXnClockChangeHandler() |
|
51 { |
|
52 Cancel(); |
|
53 iChangeNotifier.Close(); |
|
54 } |
|
55 |
|
56 private: // From CActive |
|
57 void DoCancel() |
|
58 { |
|
59 iChangeNotifier.LogonCancel(); |
|
60 // Return value is ignored. |
|
61 } |
|
62 |
|
63 void RunL() |
|
64 { |
|
65 __PRINTS( "CXnClockChangeHandler::RunL, timer runs" ); |
|
66 if( iStatus.Int() & ( EChangesLocale | EChangesSystemTime ) ) |
|
67 { |
|
68 iClient.TimeOrLocaleChanged(); |
|
69 } |
|
70 |
|
71 User::LeaveIfError( iChangeNotifier.Logon( iStatus ) ); |
|
72 SetActive(); |
|
73 } |
|
74 |
|
75 private: // Private constructors |
|
76 void ConstructL() |
|
77 { |
|
78 User::LeaveIfError( iChangeNotifier.Create() ); |
|
79 User::LeaveIfError( iChangeNotifier.Logon( iStatus ) ); |
|
80 SetActive(); |
|
81 } |
|
82 |
|
83 CXnClockChangeHandler( CXnClockControl& aClient ) |
|
84 : CActive( EPriorityStandard ), iClient( aClient ) |
|
85 { |
|
86 CActiveScheduler::Add( this ); |
|
87 } |
|
88 |
|
89 private: // Data |
|
90 RChangeNotifier iChangeNotifier; |
|
91 CXnClockControl& iClient; |
|
92 }; |
|
93 |
33 |
94 // ============================ MEMBER FUNCTIONS =============================== |
34 // ============================ MEMBER FUNCTIONS =============================== |
95 |
35 |
96 // ----------------------------------------------------------------------------- |
36 // ----------------------------------------------------------------------------- |
97 // CXnClockControl::CXnClockControl |
37 // CXnClockControl::CXnClockControl |
115 // |
55 // |
116 void CXnClockControl::ConstructL() |
56 void CXnClockControl::ConstructL() |
117 { |
57 { |
118 iTimer = CPeriodic::NewL( CActive::EPriorityHigh ); |
58 iTimer = CPeriodic::NewL( CActive::EPriorityHigh ); |
119 |
59 |
120 SetFormatL( iFormatFromLocale, iClockFormat ); |
60 SetFormatL( iFormatFromLocale, iClockFormat ); |
121 |
|
122 iHandler = CXnClockChangeHandler::NewL( *this ); |
|
123 } |
61 } |
124 |
62 |
125 // ----------------------------------------------------------------------------- |
63 // ----------------------------------------------------------------------------- |
126 // CXnClockControl::NewL |
64 // CXnClockControl::NewL |
127 // Two-phased constructor. |
65 // Two-phased constructor. |
164 { |
102 { |
165 return; |
103 return; |
166 } |
104 } |
167 |
105 |
168 iAdapter->UpdateDisplay(); |
106 iAdapter->UpdateDisplay(); |
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CXnClockControl::TimeOrLocaleChanged |
|
173 // (other items were commented in a header). |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CXnClockControl::TimeOrLocaleChanged() |
|
177 { |
|
178 TLocale locale; |
|
179 |
|
180 if( iFormatFromLocale && ( locale.ClockFormat() != iClockFormat ) ) |
|
181 { |
|
182 TRAP_IGNORE( SetFormatL( iFormatFromLocale, locale.ClockFormat() ) ); |
|
183 } |
|
184 |
|
185 UpdateDisplay(); |
|
186 } |
107 } |
187 |
108 |
188 // ----------------------------------------------------------------------------- |
109 // ----------------------------------------------------------------------------- |
189 // CXnClockControl::SetFormatL |
110 // CXnClockControl::SetFormatL |
190 // (other items were commented in a header). |
111 // (other items were commented in a header). |
218 iFace = CXnClockFaceAnalog::NewL(); |
139 iFace = CXnClockFaceAnalog::NewL(); |
219 } |
140 } |
220 else if( format == EClockDigital ) |
141 else if( format == EClockDigital ) |
221 { |
142 { |
222 iFace = CXnClockFaceDigital::NewL(); |
143 iFace = CXnClockFaceDigital::NewL(); |
223 } |
144 } |
224 } |
145 } |
225 |
146 |
226 // ----------------------------------------------------------------------------- |
147 // ----------------------------------------------------------------------------- |
227 // CXnClockControl::Format |
148 // CXnClockControl::Format |
228 // (other items were commented in a header). |
149 // (other items were commented in a header). |
236 // ----------------------------------------------------------------------------- |
157 // ----------------------------------------------------------------------------- |
237 // CXnClockControl::Draw |
158 // CXnClockControl::Draw |
238 // (other items were commented in a header). |
159 // (other items were commented in a header). |
239 // ----------------------------------------------------------------------------- |
160 // ----------------------------------------------------------------------------- |
240 // |
161 // |
241 void CXnClockControl::Draw( CWindowGc& aGc, const TRect& aRect ) const |
162 void CXnClockControl::Draw( CWindowGc& aGc, const TRect& aRect ) |
242 { |
163 { |
|
164 // Ensure correct appearance |
|
165 TRAP_IGNORE( SetFormatL( iFormatFromLocale, iClockFormat ) ); |
|
166 |
243 if( iFace && !aRect.IsEmpty() ) |
167 if( iFace && !aRect.IsEmpty() ) |
244 { |
168 { |
|
169 __PRINT( __DBG_FORMAT( "CXnClockControl::Draw: 0x%X" ), this ); |
|
170 |
245 TTime homeTime; |
171 TTime homeTime; |
246 homeTime.HomeTime(); |
172 homeTime.HomeTime(); |
247 |
173 |
248 TRAP_IGNORE( iFace->DrawL( *iAdapter, aGc, aRect, homeTime ) ); |
174 TRAP_IGNORE( iFace->DrawL( *iAdapter, aGc, aRect, homeTime ) ); |
249 } |
175 } |
254 // (other items were commented in a header). |
180 // (other items were commented in a header). |
255 // ----------------------------------------------------------------------------- |
181 // ----------------------------------------------------------------------------- |
256 // |
182 // |
257 TInt CXnClockControl::TimerCallback( TAny* aThis ) |
183 TInt CXnClockControl::TimerCallback( TAny* aThis ) |
258 { |
184 { |
259 __PRINTS( "CXnClockControl::TimerCallback, timer runs" ); |
185 __PRINT( __DBG_FORMAT( "CXnClockControl::TimerCallback: 0x%X" ), aThis ); |
|
186 |
260 CXnClockControl* self = static_cast< CXnClockControl* >( aThis ); |
187 CXnClockControl* self = static_cast< CXnClockControl* >( aThis ); |
261 |
188 |
262 // Update the clock display |
189 // Update the clock display |
263 self->UpdateDisplay(); |
190 self->UpdateDisplay(); |
264 |
191 |