34
|
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"
|
|
27 |
|
|
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 |
//
|
|
42 |
CXnClockControl::CXnClockControl( CXnClockAdapter* aAdapter,
|
|
43 |
const TBool aFormatFromLocale,
|
|
44 |
const TClockFormat aFormat )
|
|
45 |
: iAdapter( aAdapter ),
|
|
46 |
iClockFormat( aFormat ),
|
|
47 |
iFormatFromLocale ( aFormatFromLocale )
|
|
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 );
|
|
59 |
|
|
60 |
SetFormatL( iFormatFromLocale, iClockFormat );
|
|
61 |
}
|
|
62 |
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
// CXnClockControl::NewL
|
|
65 |
// Two-phased constructor.
|
|
66 |
// -----------------------------------------------------------------------------
|
|
67 |
//
|
|
68 |
CXnClockControl* CXnClockControl::NewL( CXnClockAdapter* aAdapter,
|
|
69 |
const TBool aFormatFromLocale,
|
|
70 |
const TClockFormat aFormat )
|
|
71 |
{
|
|
72 |
CXnClockControl* self =
|
|
73 |
new (ELeave) CXnClockControl( aAdapter, aFormatFromLocale, aFormat );
|
|
74 |
|
|
75 |
CleanupStack::PushL( self );
|
|
76 |
self->ConstructL();
|
|
77 |
|
|
78 |
CleanupStack::Pop( self );
|
|
79 |
|
|
80 |
return self;
|
|
81 |
}
|
|
82 |
|
|
83 |
// -----------------------------------------------------------------------------
|
|
84 |
// Destructor
|
|
85 |
//
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
CXnClockControl::~CXnClockControl()
|
|
89 |
{
|
|
90 |
delete iTimer;
|
|
91 |
delete iFace;
|
|
92 |
}
|
|
93 |
|
|
94 |
// -----------------------------------------------------------------------------
|
|
95 |
// CXnClockControl::UpdateDisplay
|
|
96 |
// (other items were commented in a header).
|
|
97 |
// -----------------------------------------------------------------------------
|
|
98 |
//
|
|
99 |
void CXnClockControl::UpdateDisplay()
|
|
100 |
{
|
|
101 |
if( !iFace )
|
|
102 |
{
|
|
103 |
return;
|
|
104 |
}
|
|
105 |
|
|
106 |
iAdapter->UpdateDisplay();
|
|
107 |
}
|
|
108 |
|
|
109 |
// -----------------------------------------------------------------------------
|
|
110 |
// CXnClockControl::SetFormatL
|
|
111 |
// (other items were commented in a header).
|
|
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 |
|
|
126 |
if( format == iClockFormat && iFace )
|
|
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();
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
// CXnClockControl::Format
|
|
149 |
// (other items were commented in a header).
|
|
150 |
// -----------------------------------------------------------------------------
|
|
151 |
//
|
|
152 |
TClockFormat CXnClockControl::Format() const
|
|
153 |
{
|
|
154 |
return iClockFormat;
|
|
155 |
}
|
|
156 |
|
|
157 |
// -----------------------------------------------------------------------------
|
|
158 |
// CXnClockControl::Draw
|
|
159 |
// (other items were commented in a header).
|
|
160 |
// -----------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
void CXnClockControl::Draw( CWindowGc& aGc, const TRect& aRect )
|
|
163 |
{
|
|
164 |
// Ensure correct appearance
|
|
165 |
TRAP_IGNORE( SetFormatL( iFormatFromLocale, iClockFormat ) );
|
|
166 |
|
|
167 |
if( iFace && !aRect.IsEmpty() )
|
|
168 |
{
|
|
169 |
__PRINT( __DBG_FORMAT( "CXnClockControl::Draw: 0x%X" ), this );
|
|
170 |
|
|
171 |
TTime homeTime;
|
|
172 |
homeTime.HomeTime();
|
|
173 |
|
|
174 |
TRAP_IGNORE( iFace->DrawL( *iAdapter, aGc, aRect, homeTime ) );
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
|
178 |
// -----------------------------------------------------------------------------
|
|
179 |
// CXnClockControl::TimerCallback
|
|
180 |
// (other items were commented in a header).
|
|
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
|
|
209 |
// (other items were commented in a header).
|
|
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
|
|
233 |
// (other items were commented in a header).
|
|
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
|