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 #include <debug.h> |
|
22 #include <AknLayoutFont.h> |
|
23 #include <AknUtils.h> |
|
24 #include <AknBidiTextUtils.h> |
|
25 #include <StringLoader.h> |
|
26 #include <bacntf.h> |
|
27 |
|
28 // User includes |
|
29 #include "xndatecontrol.h" |
|
30 #include "xncontroladapter.h" |
|
31 #include "xnclockadapter.h" |
|
32 #include "xnnodepluginif.h" |
|
33 #include "xnproperty.h" |
|
34 #include "xnuienginepluginif.h" |
|
35 #include "c_xnutils.h" |
|
36 |
|
37 // Constants |
|
38 const TInt KMaxDateStringLength = 100; |
|
39 const TInt KMaxDayNumberStringLength = 10; |
|
40 |
|
41 _LIT( KTimeFormat, "%0U %1U" ); |
|
42 |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CXnDateControl::CXnDateControl |
|
48 // C++ default constructor can NOT contain any code, that |
|
49 // might leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CXnDateControl::CXnDateControl( CXnClockAdapter& aAdapter, |
|
53 TXnDateType aType ) |
|
54 : iAdapter( aAdapter ), iDateType( aType ) |
|
55 { |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CXnDateControl::ConstructL |
|
60 // Symbian 2nd phase constructor can leave. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CXnDateControl::ConstructL() |
|
64 { |
|
65 // Create enviroment notifier |
|
66 iEnvNotifier = CEnvironmentChangeNotifier::NewL( |
|
67 CActive::EPriorityStandard, TCallBack( HandleCallBackL, this ) ); |
|
68 // Start listening notifications |
|
69 iEnvNotifier->Start(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CXnDateControl::NewL |
|
74 // Two-phased constructor. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CXnDateControl* CXnDateControl::NewL( CXnClockAdapter& aAdapter, |
|
78 TXnDateType aType ) |
|
79 { |
|
80 CXnDateControl* self = new (ELeave) CXnDateControl( aAdapter, aType ); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 CleanupStack::Pop( self ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // Destructor |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CXnDateControl::~CXnDateControl() |
|
92 { |
|
93 delete iDateText; |
|
94 delete iEnvNotifier; |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CXnDateControl::DrawL |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void CXnDateControl::DrawL( CWindowGc& aGc, CXnNodePluginIf* aNode ) |
|
102 { |
|
103 if ( !aNode || |
|
104 !iDateText || |
|
105 ( aNode && aNode->Rect().IsEmpty() ) ) |
|
106 { |
|
107 return; |
|
108 } |
|
109 |
|
110 const CAknLayoutFont* dateFont( CreateFontL( *aNode ) ); |
|
111 if ( !dateFont ) |
|
112 { |
|
113 return; |
|
114 } |
|
115 |
|
116 const TRgb& color( CreateColorL( *aNode ) ); |
|
117 |
|
118 CGraphicsContext::TTextAlign align = iAdapter.GetTextAlignL( *aNode ); |
|
119 |
|
120 const TInt deltaHeight( aNode->Rect().Height() - dateFont->TextPaneHeight() ); |
|
121 TInt offset( dateFont->TextPaneTopToBaseline() + deltaHeight / 2 ); |
|
122 |
|
123 aGc.SetPenColor( color ); |
|
124 aGc.UseFont( dateFont ); |
|
125 aGc.DrawText( *iDateText, aNode->Rect(), offset, align ); |
|
126 aGc.DiscardFont(); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CXnDateControl::ConstructDateStringL |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 HBufC* CXnDateControl::ConstructDateStringL() |
|
134 { |
|
135 // Construct date string using date format from resource file |
|
136 CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
137 |
|
138 if( !coeEnv ) |
|
139 { |
|
140 User::Leave( KErrNotReady ); |
|
141 } |
|
142 |
|
143 TTime time; |
|
144 time.HomeTime(); |
|
145 |
|
146 HBufC* aiDateString = HBufC::NewLC( KMaxDateStringLength ); |
|
147 HBufC* aiDateFormatString = HBufC::NewLC( KMaxDateStringLength ); |
|
148 aiDateFormatString->Des().Copy( KTimeFormat() ); |
|
149 // TODO: when localisation is ready read format string from resource |
|
150 //HBufC* aiDateFormatString = StringLoader::LoadLC( R_ACTIVEIDLE_TIME_FORMAT, |
|
151 // coeEnv ); |
|
152 HBufC* dateStringBuf = HBufC::NewLC( KMaxDateStringLength ); |
|
153 HBufC* dateFormatString = StringLoader::LoadLC( R_QTN_DATE_SHORT_WITH_ZERO, |
|
154 coeEnv ); |
|
155 TPtr dateString( dateStringBuf->Des() ); |
|
156 time.FormatL( dateString, *dateFormatString ); |
|
157 CleanupStack::PopAndDestroy( dateFormatString ); |
|
158 |
|
159 //now dateString contains string which is formatted using |
|
160 //R_QTN_DATE_USUAL_WITH_ZERO |
|
161 |
|
162 // To arabic |
|
163 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( dateString ); |
|
164 |
|
165 TPtr aiDateStringPtr = aiDateString->Des(); |
|
166 |
|
167 TDayNameAbb wkDayAbb = TDayNameAbb(); |
|
168 wkDayAbb.Set(time.DayNoInWeek()); |
|
169 |
|
170 //add date to string |
|
171 StringLoader::Format( aiDateStringPtr, *aiDateFormatString, 1,dateString ); |
|
172 |
|
173 //reuse dateString |
|
174 dateString.Copy( aiDateStringPtr ); |
|
175 |
|
176 //add weekday to string |
|
177 StringLoader::Format( aiDateStringPtr, dateString, 0, wkDayAbb ); |
|
178 |
|
179 CleanupStack::PopAndDestroy( dateStringBuf );//dateStringBuf, aiDateFormatString |
|
180 CleanupStack::PopAndDestroy( aiDateFormatString ); |
|
181 |
|
182 CleanupStack::Pop( aiDateString ); |
|
183 return aiDateString; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CXnDateControl::ConstructDayStringL |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 HBufC* CXnDateControl::ConstructDayStringL() |
|
191 { |
|
192 TTime time; |
|
193 time.HomeTime(); |
|
194 |
|
195 HBufC* aiDayString = HBufC::NewLC( KMaxDayNumberStringLength ); |
|
196 aiDayString->Des().Num( time.DayNoInMonth() + 1 ); |
|
197 // To arabic |
|
198 TPtr dayStringPtr = aiDayString->Des(); |
|
199 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( dayStringPtr ); |
|
200 CleanupStack::Pop( aiDayString ); |
|
201 return aiDayString; |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CXnDateControl::CreateFontL |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 const CAknLayoutFont* CXnDateControl::CreateFontL( CXnNodePluginIf& aNode ) |
|
209 { |
|
210 if ( !iDateFont ) |
|
211 { |
|
212 iAdapter.CreateFontL( aNode, iDateFont ); |
|
213 } |
|
214 return CAknLayoutFont::AsCAknLayoutFontOrNull( iDateFont ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CXnDateControl::CreateColorL |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 const TRgb& CXnDateControl::CreateColorL( CXnNodePluginIf& aNode ) |
|
222 { |
|
223 if ( !iIsColorSet ) |
|
224 { |
|
225 iAdapter.CreateColorL( aNode, iDateColor ); |
|
226 iIsColorSet = ETrue; |
|
227 } |
|
228 return iDateColor; |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CXnDateControl::ResetFont |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CXnDateControl::ResetFont() |
|
236 { |
|
237 iDateFont = NULL; |
|
238 iIsColorSet = EFalse; |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CXnDateControl::RefreshDateL |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 void CXnDateControl::RefreshDateL() |
|
246 { |
|
247 delete iDateText; |
|
248 iDateText = NULL; |
|
249 if ( iDateType == EDate ) |
|
250 { |
|
251 iDateText = ConstructDateStringL(); |
|
252 } |
|
253 else if ( iDateType == EDay ) |
|
254 { |
|
255 iDateText = ConstructDayStringL(); |
|
256 } |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CXnDateControl::HandleCallBackL |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 TInt CXnDateControl::HandleCallBackL( TAny *aPtr ) |
|
264 { |
|
265 CXnDateControl* self = static_cast<CXnDateControl*>( aPtr ); |
|
266 |
|
267 if( self ) |
|
268 { |
|
269 TInt changes( self->iEnvNotifier->Change() ); |
|
270 |
|
271 if ( changes & |
|
272 ( EChangesLocale | EChangesMidnightCrossover | EChangesSystemTime ) ) |
|
273 { |
|
274 self->RefreshDateL(); |
|
275 } |
|
276 } |
|
277 |
|
278 return KErrNone; |
|
279 } |
|
280 |
|
281 // End of File |
|