83
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2007 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: Implementation for xuikon clock face.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// SYSTEM INCLUDE FILES
|
|
20 |
#include <e32math.h>
|
|
21 |
#include <bitdev.h>
|
|
22 |
#include <AknsUtils.h>
|
|
23 |
#include <AknIconUtils.h>
|
|
24 |
#include <AknBidiTextUtils.h>
|
|
25 |
#include <AknLayoutFont.h>
|
|
26 |
#include <AknUtils.h>
|
|
27 |
#include <gdi.h>
|
|
28 |
|
|
29 |
// USER INCLUDE FILES
|
|
30 |
#include "xnnodepluginif.h"
|
|
31 |
#include "xnclockadapter.h"
|
|
32 |
#include "xntext.h"
|
|
33 |
|
|
34 |
#include "xnclockface.h"
|
|
35 |
|
|
36 |
|
|
37 |
// LOCAL CONSTANTS AND MACROS
|
|
38 |
_LIT( KAmPmFormat, "%B" );
|
|
39 |
_LIT( KTimeFormat, "%J%:1%T" );
|
|
40 |
|
|
41 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
42 |
|
|
43 |
// -----------------------------------------------------------------------------
|
|
44 |
// CXnClockFaceDigital::CXnClockFaceDigital
|
|
45 |
// C++ default constructor can NOT contain any code, that
|
|
46 |
// might leave.
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
//
|
|
49 |
CXnClockFaceDigital::CXnClockFaceDigital()
|
|
50 |
{
|
|
51 |
}
|
|
52 |
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
// CXnClockFaceDigital::ConstructL
|
|
55 |
// Symbian 2nd phase constructor can leave.
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
//
|
|
58 |
void CXnClockFaceDigital::ConstructL()
|
|
59 |
{
|
|
60 |
}
|
|
61 |
|
|
62 |
// -----------------------------------------------------------------------------
|
|
63 |
// CXnClockFaceDigital::NewL
|
|
64 |
// Two-phased constructor.
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
CXnClockFaceDigital* CXnClockFaceDigital::NewL()
|
|
68 |
{
|
|
69 |
CXnClockFaceDigital* self =
|
|
70 |
new ( ELeave ) CXnClockFaceDigital();
|
|
71 |
|
|
72 |
CleanupStack::PushL( self );
|
|
73 |
self->ConstructL();
|
|
74 |
CleanupStack::Pop( self );
|
|
75 |
|
|
76 |
return self;
|
|
77 |
}
|
|
78 |
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
// Destructor
|
|
81 |
// -----------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
CXnClockFaceDigital::~CXnClockFaceDigital()
|
|
84 |
{
|
|
85 |
}
|
|
86 |
|
|
87 |
// -----------------------------------------------------------------------------
|
|
88 |
// CXnClockFaceDigital::DrawL
|
|
89 |
// (other items were commented in a header).
|
|
90 |
// -----------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
void CXnClockFaceDigital::DrawL( CXnClockAdapter& aAdapter, CWindowGc& aGc,
|
|
93 |
const TRect& aRect, const TTime& aTime )
|
|
94 |
{
|
|
95 |
TBuf< KMaxTimeFormatSpec > time;
|
|
96 |
aTime.FormatL( time, KTimeFormat() );
|
|
97 |
|
|
98 |
TBuf< KMaxTimeFormatSpec > ampm;
|
|
99 |
aTime.FormatL( ampm, KAmPmFormat() );
|
|
100 |
|
|
101 |
AknTextUtils::LanguageSpecificNumberConversion( time );
|
|
102 |
|
|
103 |
const CAknLayoutFont* clockFont(
|
|
104 |
aAdapter.FontL( CXnClockAdapter::EDigitalFont ) );
|
|
105 |
|
|
106 |
const CAknLayoutFont* ampmFont(
|
|
107 |
aAdapter.FontL( CXnClockAdapter::EAmPmFont ) );
|
|
108 |
|
|
109 |
const CAknLayoutFont* dateFont(
|
|
110 |
aAdapter.FontL( CXnClockAdapter::EDateFont ) );
|
|
111 |
|
|
112 |
const TRgb& color( aAdapter.TextColorL() );
|
|
113 |
|
|
114 |
CXnNodePluginIf* date( aAdapter.Date() );
|
|
115 |
|
|
116 |
const TInt deltaHeight( aRect.Height() - clockFont->TextPaneHeight() );
|
|
117 |
TInt offset( clockFont->TextPaneTopToBaseline() + deltaHeight / 2 );
|
|
118 |
|
|
119 |
if( date )
|
|
120 |
{
|
|
121 |
// When date string is shown, time string must be lifted up
|
|
122 |
offset -= ( dateFont->TextPaneHeight() / 2 );
|
|
123 |
}
|
|
124 |
|
|
125 |
// Measure the full width of the time string
|
|
126 |
TInt textWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *clockFont, time,
|
|
127 |
CFont::TMeasureTextInput::EFVisualOrder ) );
|
|
128 |
|
|
129 |
TInt extraWidth( aRect.Width() - textWidth );
|
|
130 |
|
|
131 |
TInt margin( extraWidth / 2 );
|
|
132 |
|
|
133 |
aGc.SetPenColor( color );
|
|
134 |
|
|
135 |
aGc.UseFont( clockFont );
|
|
136 |
|
|
137 |
CGraphicsContext::TTextAlign align;
|
|
138 |
|
|
139 |
TBool mirrored( AknLayoutUtils::LayoutMirrored() );
|
|
140 |
|
|
141 |
if( mirrored )
|
|
142 |
{
|
|
143 |
align = CGraphicsContext::ERight;
|
|
144 |
}
|
|
145 |
else
|
|
146 |
{
|
|
147 |
align = CGraphicsContext::ELeft;
|
|
148 |
}
|
|
149 |
|
|
150 |
aGc.DrawText( time, aRect, offset, align, margin );
|
|
151 |
|
|
152 |
aGc.DiscardFont();
|
|
153 |
|
|
154 |
if( TLocale().TimeFormat() == ETime12 )
|
|
155 |
{
|
|
156 |
TRect ampmRect( aRect );
|
|
157 |
TInt ampmHeight( ampmFont->TextPaneHeight() );
|
|
158 |
|
|
159 |
if( mirrored )
|
|
160 |
{
|
|
161 |
align = CGraphicsContext::ELeft;
|
|
162 |
}
|
|
163 |
else
|
|
164 |
{
|
|
165 |
align = CGraphicsContext::ERight;
|
|
166 |
}
|
|
167 |
|
|
168 |
ampmRect.iTl.iY += ampmHeight;
|
|
169 |
|
|
170 |
aGc.UseFont( ampmFont );
|
|
171 |
|
|
172 |
aGc.DrawText( ampm, ampmRect, offset, align, margin );
|
|
173 |
|
|
174 |
aGc.DiscardFont();
|
|
175 |
}
|
|
176 |
|
|
177 |
if( date )
|
|
178 |
{
|
|
179 |
const TDesC* dateStr( &KNullDesC() );
|
|
180 |
|
|
181 |
CXnText* textIf( NULL );
|
|
182 |
|
|
183 |
XnComponentInterface::MakeInterfaceL( textIf, date->AppIfL() );
|
|
184 |
|
|
185 |
if( textIf )
|
|
186 |
{
|
|
187 |
dateStr = textIf->Text();
|
|
188 |
}
|
|
189 |
|
|
190 |
// Measure the full width of the time string
|
|
191 |
TInt dateWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *dateFont, *dateStr,
|
|
192 |
CFont::TMeasureTextInput::EFVisualOrder ) );
|
|
193 |
|
|
194 |
TInt width( aRect.Width() - dateWidth );
|
|
195 |
TInt margin( width / 2 );
|
|
196 |
|
|
197 |
// Move date string down by text pane height and 5% of rect height
|
|
198 |
offset += dateFont->TextPaneHeight() + ( aRect.Height() / 20 );
|
|
199 |
|
|
200 |
aGc.UseFont( dateFont );
|
|
201 |
|
|
202 |
aGc.DrawText( *dateStr, aRect, offset, align, margin );
|
|
203 |
|
|
204 |
aGc.DiscardFont();
|
|
205 |
}
|
|
206 |
}
|
|
207 |
|
|
208 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
209 |
|
|
210 |
// -----------------------------------------------------------------------------
|
|
211 |
// CXnClockFaceAnalog::CXnClockFaceAnalog
|
|
212 |
// C++ default constructor can NOT contain any code, that
|
|
213 |
// might leave.
|
|
214 |
// -----------------------------------------------------------------------------
|
|
215 |
//
|
|
216 |
CXnClockFaceAnalog::CXnClockFaceAnalog()
|
|
217 |
{
|
|
218 |
}
|
|
219 |
|
|
220 |
// -----------------------------------------------------------------------------
|
|
221 |
// CXnClockFaceAnalog::ConstructL
|
|
222 |
// Symbian 2nd phase constructor can leave.
|
|
223 |
// -----------------------------------------------------------------------------
|
|
224 |
//
|
|
225 |
void CXnClockFaceAnalog::ConstructL()
|
|
226 |
{
|
|
227 |
}
|
|
228 |
|
|
229 |
// -----------------------------------------------------------------------------
|
|
230 |
// CXnClockFaceAnalog::NewL
|
|
231 |
// Two-phased constructor.
|
|
232 |
// -----------------------------------------------------------------------------
|
|
233 |
//
|
|
234 |
CXnClockFaceAnalog* CXnClockFaceAnalog::NewL()
|
|
235 |
{
|
|
236 |
CXnClockFaceAnalog* self =
|
|
237 |
new( ELeave ) CXnClockFaceAnalog();
|
|
238 |
|
|
239 |
CleanupStack::PushL( self );
|
|
240 |
self->ConstructL();
|
|
241 |
CleanupStack::Pop( self );
|
|
242 |
|
|
243 |
return self;
|
|
244 |
}
|
|
245 |
|
|
246 |
// -----------------------------------------------------------------------------
|
|
247 |
// Destructor
|
|
248 |
// -----------------------------------------------------------------------------
|
|
249 |
//
|
|
250 |
CXnClockFaceAnalog::~CXnClockFaceAnalog()
|
|
251 |
{
|
|
252 |
}
|
|
253 |
|
|
254 |
// -----------------------------------------------------------------------------
|
|
255 |
// CXnClockFaceAnalog::DrawL
|
|
256 |
// (other items were commented in a header).
|
|
257 |
// -----------------------------------------------------------------------------
|
|
258 |
//
|
|
259 |
void CXnClockFaceAnalog::DrawL( CXnClockAdapter& /*aAdapter*/, CWindowGc& aGc,
|
|
260 |
const TRect& aRect, const TTime& aTime )
|
|
261 |
{
|
|
262 |
TSize faceSize( aRect.Size() );
|
|
263 |
|
|
264 |
TDateTime dateTime( aTime.DateTime() );
|
|
265 |
|
|
266 |
MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
|
|
267 |
|
|
268 |
// 1-2: Face number 1
|
|
269 |
CFbsBitmap* skinBmp( NULL );
|
|
270 |
CFbsBitmap* skinMask( NULL );
|
|
271 |
|
|
272 |
AknsUtils::GetCachedMaskedBitmap( skin,
|
|
273 |
KAknsIIDQsnHomeClockAnalogueFace,
|
|
274 |
skinBmp,
|
|
275 |
skinMask );
|
|
276 |
|
|
277 |
// If there is no bitmap, don't draw
|
|
278 |
if( !skinBmp )
|
|
279 |
{
|
|
280 |
return;
|
|
281 |
}
|
|
282 |
|
|
283 |
User::LeaveIfError( AknIconUtils::SetSize( skinBmp, faceSize ) );
|
|
284 |
|
|
285 |
if( skinMask )
|
|
286 |
{
|
|
287 |
User::LeaveIfError( AknIconUtils::SetSize( skinMask, faceSize ) );
|
|
288 |
|
|
289 |
aGc.BitBltMasked( aRect.iTl,
|
|
290 |
skinBmp,
|
|
291 |
TRect( TPoint( 0, 0 ), skinBmp->SizeInPixels() ),
|
|
292 |
skinMask,
|
|
293 |
ETrue );
|
|
294 |
}
|
|
295 |
else
|
|
296 |
{
|
|
297 |
aGc.BitBlt( aRect.iTl, skinBmp );
|
|
298 |
}
|
|
299 |
|
|
300 |
aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
|
|
301 |
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
|
|
302 |
|
|
303 |
DrawHandsL( aGc, aRect, dateTime );
|
|
304 |
}
|
|
305 |
|
|
306 |
// -----------------------------------------------------------------------------
|
|
307 |
// CXnClockFaceAnalog::DrawHands
|
|
308 |
// (other items were commented in a header).
|
|
309 |
// -----------------------------------------------------------------------------
|
|
310 |
//
|
|
311 |
void CXnClockFaceAnalog::DrawHandsL( CWindowGc& aGc,
|
|
312 |
const TRect& aRect,
|
|
313 |
const TDateTime& aDateTime )
|
|
314 |
{
|
|
315 |
TRect rect( aRect );
|
|
316 |
|
|
317 |
CFbsBitmap* hrbitmap( NULL );
|
|
318 |
CFbsBitmap* hrmask( NULL );
|
|
319 |
|
|
320 |
CFbsBitmap* minbitmap( NULL );
|
|
321 |
CFbsBitmap* minmask( NULL );
|
|
322 |
|
|
323 |
MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
|
|
324 |
|
|
325 |
AknsUtils::GetCachedMaskedBitmap(
|
|
326 |
skin, KAknsIIDQsnHomeClockAnaloguePointerHour,
|
|
327 |
hrbitmap, hrmask );
|
|
328 |
|
|
329 |
AknsUtils::GetCachedMaskedBitmap(
|
|
330 |
skin, KAknsIIDQsnHomeClockAnaloguePointerMinute,
|
|
331 |
minbitmap, minmask );
|
|
332 |
|
|
333 |
User::LeaveIfError( AknIconUtils::SetSizeAndRotation(
|
|
334 |
hrbitmap,
|
|
335 |
rect.Size(),
|
|
336 |
EAspectRatioPreserved,
|
|
337 |
aDateTime.Hour() * 30 + aDateTime.Minute() / 2 ) );
|
|
338 |
|
|
339 |
aGc.BitBltMasked( rect.iTl,
|
|
340 |
hrbitmap,
|
|
341 |
TRect( TPoint( 0, 0 ), hrbitmap->SizeInPixels() ),
|
|
342 |
hrmask,
|
|
343 |
EFalse );
|
|
344 |
|
|
345 |
|
|
346 |
User::LeaveIfError( AknIconUtils::SetSizeAndRotation(
|
|
347 |
minbitmap,
|
|
348 |
rect.Size(),
|
|
349 |
EAspectRatioPreserved,
|
|
350 |
aDateTime.Minute() * 6 ) );
|
|
351 |
|
|
352 |
aGc.BitBltMasked( rect.iTl,
|
|
353 |
minbitmap,
|
|
354 |
TRect( TPoint( 0, 0 ), minbitmap->SizeInPixels() ),
|
|
355 |
minmask,
|
|
356 |
EFalse );
|
|
357 |
}
|
|
358 |
|
|
359 |
// End of File
|