author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:18:30 +0300 | |
branch | RCL_3 |
changeset 102 | ba63c83f4716 |
parent 88 | 3321d3e205b6 |
permissions | -rw-r--r-- |
83 | 1 |
/* |
2 |
* Copyright (c) 2006-2008 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: Clock control |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
// System includes |
|
20 |
#include <e32std.h> |
|
21 |
||
22 |
// User includes |
|
23 |
#include <debug.h> |
|
24 |
#include "xncontroladapter.h" |
|
25 |
#include "xnclockadapter.h" |
|
26 |
#include "xnclockface.h" |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
27 |
|
83 | 28 |
#include "xnclockcontrol.h" |
29 |
||
30 |
// Constants |
|
31 |
static const TInt KIntervalTime( 60000000 ); // in microseconds |
|
32 |
||
33 |
||
34 |
// ============================ MEMBER FUNCTIONS =============================== |
|
35 |
||
36 |
// ----------------------------------------------------------------------------- |
|
37 |
// CXnClockControl::CXnClockControl |
|
38 |
// C++ default constructor can NOT contain any code, that |
|
39 |
// might leave. |
|
40 |
// ----------------------------------------------------------------------------- |
|
41 |
// |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
42 |
CXnClockControl::CXnClockControl( CXnClockAdapter* aAdapter, |
83 | 43 |
const TBool aFormatFromLocale, |
44 |
const TClockFormat aFormat ) |
|
45 |
: iAdapter( aAdapter ), |
|
46 |
iClockFormat( aFormat ), |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
47 |
iFormatFromLocale ( aFormatFromLocale ) |
83 | 48 |
{ |
49 |
} |
|
50 |
||
51 |
// ----------------------------------------------------------------------------- |
|
52 |
// CXnClockControl::ConstructL |
|
53 |
// Symbian 2nd phase constructor can leave. |
|
54 |
// ----------------------------------------------------------------------------- |
|
55 |
// |
|
56 |
void CXnClockControl::ConstructL() |
|
57 |
{ |
|
58 |
iTimer = CPeriodic::NewL( CActive::EPriorityHigh ); |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
59 |
|
83 | 60 |
SetFormatL( iFormatFromLocale, iClockFormat ); |
61 |
} |
|
62 |
||
63 |
// ----------------------------------------------------------------------------- |
|
64 |
// CXnClockControl::NewL |
|
65 |
// Two-phased constructor. |
|
66 |
// ----------------------------------------------------------------------------- |
|
67 |
// |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
68 |
CXnClockControl* CXnClockControl::NewL( CXnClockAdapter* aAdapter, |
83 | 69 |
const TBool aFormatFromLocale, |
70 |
const TClockFormat aFormat ) |
|
71 |
{ |
|
72 |
CXnClockControl* self = |
|
73 |
new (ELeave) CXnClockControl( aAdapter, aFormatFromLocale, aFormat ); |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
74 |
|
83 | 75 |
CleanupStack::PushL( self ); |
76 |
self->ConstructL(); |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
77 |
|
83 | 78 |
CleanupStack::Pop( self ); |
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
79 |
|
83 | 80 |
return self; |
81 |
} |
|
82 |
||
83 |
// ----------------------------------------------------------------------------- |
|
84 |
// Destructor |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
85 |
// |
83 | 86 |
// ----------------------------------------------------------------------------- |
87 |
// |
|
88 |
CXnClockControl::~CXnClockControl() |
|
89 |
{ |
|
90 |
delete iTimer; |
|
91 |
delete iFace; |
|
92 |
} |
|
93 |
||
94 |
// ----------------------------------------------------------------------------- |
|
95 |
// CXnClockControl::UpdateDisplay |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
96 |
// (other items were commented in a header). |
83 | 97 |
// ----------------------------------------------------------------------------- |
98 |
// |
|
99 |
void CXnClockControl::UpdateDisplay() |
|
100 |
{ |
|
101 |
if( !iFace ) |
|
102 |
{ |
|
103 |
return; |
|
104 |
} |
|
105 |
||
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
106 |
iAdapter->UpdateDisplay(); |
83 | 107 |
} |
108 |
||
109 |
// ----------------------------------------------------------------------------- |
|
110 |
// CXnClockControl::SetFormatL |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
111 |
// (other items were commented in a header). |
83 | 112 |
// ----------------------------------------------------------------------------- |
113 |
// |
|
114 |
void CXnClockControl::SetFormatL( const TBool aFormatFromLocale, |
|
115 |
const TClockFormat aFormat ) |
|
116 |
{ |
|
117 |
TClockFormat format( aFormat ); |
|
118 |
||
119 |
if( aFormatFromLocale ) |
|
120 |
{ |
|
121 |
format = TLocale().ClockFormat(); |
|
122 |
} |
|
123 |
||
124 |
iFormatFromLocale = aFormatFromLocale; |
|
125 |
||
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
126 |
if( format == iClockFormat && iFace ) |
83 | 127 |
{ |
128 |
// Already correct face |
|
129 |
return; |
|
130 |
} |
|
131 |
||
132 |
iClockFormat = format; |
|
133 |
||
134 |
delete iFace; |
|
135 |
iFace = NULL; |
|
136 |
||
137 |
if( format == EClockAnalog ) |
|
138 |
{ |
|
139 |
iFace = CXnClockFaceAnalog::NewL(); |
|
140 |
} |
|
141 |
else if( format == EClockDigital ) |
|
142 |
{ |
|
143 |
iFace = CXnClockFaceDigital::NewL(); |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
144 |
} |
83 | 145 |
} |
146 |
||
147 |
// ----------------------------------------------------------------------------- |
|
148 |
// CXnClockControl::Format |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
149 |
// (other items were commented in a header). |
83 | 150 |
// ----------------------------------------------------------------------------- |
151 |
// |
|
152 |
TClockFormat CXnClockControl::Format() const |
|
153 |
{ |
|
154 |
return iClockFormat; |
|
155 |
} |
|
156 |
||
157 |
// ----------------------------------------------------------------------------- |
|
158 |
// CXnClockControl::Draw |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
159 |
// (other items were commented in a header). |
83 | 160 |
// ----------------------------------------------------------------------------- |
161 |
// |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
162 |
void CXnClockControl::Draw( CWindowGc& aGc, const TRect& aRect ) |
83 | 163 |
{ |
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
164 |
// Ensure correct appearance |
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
165 |
TRAP_IGNORE( SetFormatL( iFormatFromLocale, iClockFormat ) ); |
83 | 166 |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
167 |
if( iFace && !aRect.IsEmpty() ) |
83 | 168 |
{ |
169 |
__PRINT( __DBG_FORMAT( "CXnClockControl::Draw: 0x%X" ), this ); |
|
170 |
||
171 |
TTime homeTime; |
|
172 |
homeTime.HomeTime(); |
|
173 |
||
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
174 |
TRAP_IGNORE( iFace->DrawL( *iAdapter, aGc, aRect, homeTime ) ); |
83 | 175 |
} |
176 |
} |
|
177 |
||
178 |
// ----------------------------------------------------------------------------- |
|
179 |
// CXnClockControl::TimerCallback |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
180 |
// (other items were commented in a header). |
83 | 181 |
// ----------------------------------------------------------------------------- |
182 |
// |
|
183 |
TInt CXnClockControl::TimerCallback( TAny* aThis ) |
|
184 |
{ |
|
185 |
__PRINT( __DBG_FORMAT( "CXnClockControl::TimerCallback: 0x%X" ), aThis ); |
|
186 |
||
187 |
CXnClockControl* self = static_cast< CXnClockControl* >( aThis ); |
|
188 |
||
189 |
// Update the clock display |
|
190 |
self->UpdateDisplay(); |
|
191 |
||
192 |
// Adjust the timer delay if necessary |
|
193 |
TTime time; |
|
194 |
time.HomeTime(); |
|
195 |
TDateTime dateTime( time.DateTime() ); |
|
196 |
||
197 |
if( dateTime.Second() > 0 ) |
|
198 |
{ |
|
199 |
self->iTimer->Cancel(); |
|
200 |
self->iTimer->After( KIntervalTime - |
|
201 |
1000000 * dateTime.Second() - dateTime.MicroSecond() ); |
|
202 |
} |
|
203 |
||
204 |
return KErrNone; |
|
205 |
} |
|
206 |
||
207 |
// ----------------------------------------------------------------------------- |
|
208 |
// CXnClockControl::StartTimer |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
209 |
// (other items were commented in a header). |
83 | 210 |
// ----------------------------------------------------------------------------- |
211 |
// |
|
212 |
void CXnClockControl::StartTimer() |
|
213 |
{ |
|
214 |
if ( iTimer && !iTimer->IsActive() ) |
|
215 |
{ |
|
216 |
__PRINT( __DBG_FORMAT( "CXnClockControl::StartTimer: 0x%X" ), this ); |
|
217 |
||
218 |
TTime time; |
|
219 |
time.HomeTime(); |
|
220 |
TDateTime dateTime( time.DateTime() ); |
|
221 |
TCallBack callBack( TimerCallback, this ); |
|
222 |
||
223 |
iTimer->Start( |
|
224 |
TTimeIntervalMicroSeconds32( |
|
225 |
KIntervalTime - 1000000 * dateTime.Second() - dateTime.MicroSecond() ), |
|
226 |
TTimeIntervalMicroSeconds32( KIntervalTime ), |
|
227 |
callBack ); |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
// ----------------------------------------------------------------------------- |
|
232 |
// CXnClockControl::StopTimer |
|
102
ba63c83f4716
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
88
diff
changeset
|
233 |
// (other items were commented in a header). |
83 | 234 |
// ----------------------------------------------------------------------------- |
235 |
// |
|
236 |
void CXnClockControl::StopTimer() |
|
237 |
{ |
|
238 |
if ( iTimer && iTimer->IsActive() ) |
|
239 |
{ |
|
240 |
__PRINT( __DBG_FORMAT( "CXnClockControl::StopTimer: 0x%X" ), this ); |
|
241 |
||
242 |
iTimer->Cancel(); |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
// End of File |