|
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 TInt ampmWidth( 0 ); |
|
117 |
|
118 if( TLocale().TimeFormat() == ETime12 ) |
|
119 { |
|
120 // Measure the full width of the ampm string |
|
121 ampmWidth = AknBidiTextUtils::MeasureTextBoundsWidth( *ampmFont, ampm, |
|
122 CFont::TMeasureTextInput::EFVisualOrder ); |
|
123 } |
|
124 |
|
125 const TInt deltaHeight( aRect.Height() - clockFont->TextPaneHeight() ); |
|
126 TInt offset( clockFont->TextPaneTopToBaseline() + deltaHeight / 2 ); |
|
127 |
|
128 if( date ) |
|
129 { |
|
130 // When date string is shown, time string must be lifted up |
|
131 offset -= ( dateFont->TextPaneHeight() / 2 ); |
|
132 } |
|
133 |
|
134 // Measure the full width of the time string |
|
135 TInt textWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *clockFont, time, |
|
136 CFont::TMeasureTextInput::EFVisualOrder ) ); |
|
137 |
|
138 TInt extraWidth( aRect.Width() - ampmWidth - textWidth ); |
|
139 |
|
140 TInt margin( extraWidth / 2 ); |
|
141 |
|
142 aGc.SetPenColor( color ); |
|
143 |
|
144 aGc.UseFont( clockFont ); |
|
145 |
|
146 CGraphicsContext::TTextAlign align; |
|
147 |
|
148 TBool mirrored( AknLayoutUtils::LayoutMirrored() ); |
|
149 |
|
150 if( mirrored ) |
|
151 { |
|
152 align = CGraphicsContext::ERight; |
|
153 } |
|
154 else |
|
155 { |
|
156 align = CGraphicsContext::ELeft; |
|
157 } |
|
158 |
|
159 aGc.DrawText( time, aRect, offset, align, margin ); |
|
160 |
|
161 aGc.DiscardFont(); |
|
162 |
|
163 if( TLocale().TimeFormat() == ETime12 ) |
|
164 { |
|
165 TRect ampmRect( aRect ); |
|
166 |
|
167 if( mirrored ) |
|
168 { |
|
169 ampmRect.iBr.iX -= ( textWidth + ( margin / 2 ) ); |
|
170 } |
|
171 else |
|
172 { |
|
173 ampmRect.iTl.iX += ( textWidth + ( margin / 2 ) ); |
|
174 } |
|
175 |
|
176 extraWidth = ampmRect.Width() - ampmWidth; |
|
177 |
|
178 margin = extraWidth / 2; |
|
179 |
|
180 aGc.UseFont( ampmFont ); |
|
181 |
|
182 aGc.DrawText( ampm, ampmRect, offset, align, margin ); |
|
183 |
|
184 aGc.DiscardFont(); |
|
185 } |
|
186 |
|
187 if( date ) |
|
188 { |
|
189 const TDesC* dateStr( &KNullDesC() ); |
|
190 |
|
191 CXnText* textIf( NULL ); |
|
192 |
|
193 XnComponentInterface::MakeInterfaceL( textIf, date->AppIfL() ); |
|
194 |
|
195 if( textIf ) |
|
196 { |
|
197 dateStr = textIf->Text(); |
|
198 } |
|
199 |
|
200 // Measure the full width of the time string |
|
201 TInt dateWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *dateFont, *dateStr, |
|
202 CFont::TMeasureTextInput::EFVisualOrder ) ); |
|
203 |
|
204 TInt width( aRect.Width() - dateWidth ); |
|
205 TInt margin( width / 2 ); |
|
206 |
|
207 // Move date string down by text pane height and 5% of rect height |
|
208 offset += dateFont->TextPaneHeight() + ( aRect.Height() / 20 ); |
|
209 |
|
210 aGc.UseFont( dateFont ); |
|
211 |
|
212 aGc.DrawText( *dateStr, aRect, offset, align, margin ); |
|
213 |
|
214 aGc.DiscardFont(); |
|
215 } |
|
216 } |
|
217 |
|
218 // ============================ MEMBER FUNCTIONS =============================== |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CXnClockFaceAnalog::CXnClockFaceAnalog |
|
222 // C++ default constructor can NOT contain any code, that |
|
223 // might leave. |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 CXnClockFaceAnalog::CXnClockFaceAnalog() |
|
227 { |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CXnClockFaceAnalog::ConstructL |
|
232 // Symbian 2nd phase constructor can leave. |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CXnClockFaceAnalog::ConstructL() |
|
236 { |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CXnClockFaceAnalog::NewL |
|
241 // Two-phased constructor. |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 CXnClockFaceAnalog* CXnClockFaceAnalog::NewL() |
|
245 { |
|
246 CXnClockFaceAnalog* self = |
|
247 new( ELeave ) CXnClockFaceAnalog(); |
|
248 |
|
249 CleanupStack::PushL( self ); |
|
250 self->ConstructL(); |
|
251 CleanupStack::Pop( self ); |
|
252 |
|
253 return self; |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // Destructor |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 CXnClockFaceAnalog::~CXnClockFaceAnalog() |
|
261 { |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CXnClockFaceAnalog::DrawL |
|
266 // (other items were commented in a header). |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 void CXnClockFaceAnalog::DrawL( CXnClockAdapter& /*aAdapter*/, CWindowGc& aGc, |
|
270 const TRect& aRect, const TTime& aTime ) |
|
271 { |
|
272 TSize faceSize( aRect.Size() ); |
|
273 |
|
274 TDateTime dateTime( aTime.DateTime() ); |
|
275 |
|
276 MAknsSkinInstance* skin( AknsUtils::SkinInstance() ); |
|
277 |
|
278 // 1-2: Face number 1 |
|
279 CFbsBitmap* skinBmp( NULL ); |
|
280 CFbsBitmap* skinMask( NULL ); |
|
281 |
|
282 AknsUtils::GetCachedMaskedBitmap( skin, |
|
283 KAknsIIDQsnHomeClockAnalogueFace, |
|
284 skinBmp, |
|
285 skinMask ); |
|
286 |
|
287 // If there is no bitmap, don't draw |
|
288 if( !skinBmp ) |
|
289 { |
|
290 return; |
|
291 } |
|
292 |
|
293 User::LeaveIfError( AknIconUtils::SetSize( skinBmp, faceSize ) ); |
|
294 |
|
295 if( skinMask ) |
|
296 { |
|
297 User::LeaveIfError( AknIconUtils::SetSize( skinMask, faceSize ) ); |
|
298 |
|
299 aGc.BitBltMasked( aRect.iTl, |
|
300 skinBmp, |
|
301 TRect( TPoint( 0, 0 ), skinBmp->SizeInPixels() ), |
|
302 skinMask, |
|
303 ETrue ); |
|
304 } |
|
305 else |
|
306 { |
|
307 aGc.BitBlt( aRect.iTl, skinBmp ); |
|
308 } |
|
309 |
|
310 aGc.SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
311 aGc.SetPenStyle( CGraphicsContext::ESolidPen ); |
|
312 |
|
313 DrawHandsL( aGc, aRect, dateTime ); |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CXnClockFaceAnalog::DrawHands |
|
318 // (other items were commented in a header). |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 void CXnClockFaceAnalog::DrawHandsL( CWindowGc& aGc, |
|
322 const TRect& aRect, |
|
323 const TDateTime& aDateTime ) |
|
324 { |
|
325 TRect rect( aRect ); |
|
326 |
|
327 CFbsBitmap* hrbitmap( NULL ); |
|
328 CFbsBitmap* hrmask( NULL ); |
|
329 |
|
330 CFbsBitmap* minbitmap( NULL ); |
|
331 CFbsBitmap* minmask( NULL ); |
|
332 |
|
333 MAknsSkinInstance* skin( AknsUtils::SkinInstance() ); |
|
334 |
|
335 AknsUtils::GetCachedMaskedBitmap( |
|
336 skin, KAknsIIDQsnHomeClockAnaloguePointerHour, |
|
337 hrbitmap, hrmask ); |
|
338 |
|
339 AknsUtils::GetCachedMaskedBitmap( |
|
340 skin, KAknsIIDQsnHomeClockAnaloguePointerMinute, |
|
341 minbitmap, minmask ); |
|
342 |
|
343 User::LeaveIfError( AknIconUtils::SetSizeAndRotation( |
|
344 hrbitmap, |
|
345 rect.Size(), |
|
346 EAspectRatioPreserved, |
|
347 aDateTime.Hour() * 30 + aDateTime.Minute() / 2 ) ); |
|
348 |
|
349 aGc.BitBltMasked( rect.iTl, |
|
350 hrbitmap, |
|
351 TRect( TPoint( 0, 0 ), hrbitmap->SizeInPixels() ), |
|
352 hrmask, |
|
353 EFalse ); |
|
354 |
|
355 |
|
356 User::LeaveIfError( AknIconUtils::SetSizeAndRotation( |
|
357 minbitmap, |
|
358 rect.Size(), |
|
359 EAspectRatioPreserved, |
|
360 aDateTime.Minute() * 6 ) ); |
|
361 |
|
362 aGc.BitBltMasked( rect.iTl, |
|
363 minbitmap, |
|
364 TRect( TPoint( 0, 0 ), minbitmap->SizeInPixels() ), |
|
365 minmask, |
|
366 EFalse ); |
|
367 } |
|
368 |
|
369 // End of File |