64
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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: ESMR single time field implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "cesmrsingletimefield.h"
|
|
19 |
#include "mesmrfieldvalidator.h"
|
|
20 |
#include "cesmrglobalnote.h"
|
|
21 |
#include "esmrfieldbuilderdef.h"
|
|
22 |
#include "cmrimage.h"
|
|
23 |
#include "nmrlayoutmanager.h"
|
|
24 |
#include "nmrcolormanager.h"
|
|
25 |
#include "nmrbitmapmanager.h"
|
|
26 |
|
|
27 |
#include <AknsBasicBackgroundControlContext.h>
|
|
28 |
#include <eikmfne.h>
|
|
29 |
|
|
30 |
#include "emailtrace.h"
|
|
31 |
|
|
32 |
namespace{ // codescanner::namespace
|
|
33 |
#define KMinimumTime (TTime(0)) // codescanner::baddefines
|
|
34 |
|
|
35 |
// 24 hours in microseconds
|
|
36 |
const TInt64 KDayInMicroSeconds = 86400000000;
|
|
37 |
#define KMaximumTime (TTime(KDayInMicroSeconds)) // codescanner::baddefines
|
|
38 |
}
|
|
39 |
|
|
40 |
// ======== MEMBER FUNCTIONS ========
|
|
41 |
|
|
42 |
// ---------------------------------------------------------------------------
|
|
43 |
// CESMRSingleTimeField::CESMRSingleTimeField
|
|
44 |
// ---------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
CESMRSingleTimeField::CESMRSingleTimeField( MESMRFieldValidator* aValidator )
|
|
47 |
{
|
|
48 |
FUNC_LOG;
|
|
49 |
|
|
50 |
iValidator = aValidator;
|
|
51 |
SetFieldId ( EESMRFieldAlarmTime );
|
|
52 |
SetFocusType( EESMRHighlightFocus );
|
|
53 |
}
|
|
54 |
|
|
55 |
// ---------------------------------------------------------------------------
|
|
56 |
// CESMRSingleTimeField::~CESMRSingleTimeField
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
//
|
|
59 |
CESMRSingleTimeField::~CESMRSingleTimeField()
|
|
60 |
{
|
|
61 |
FUNC_LOG;
|
|
62 |
delete iFieldIcon;
|
|
63 |
delete iBgCtrlContext;
|
|
64 |
}
|
|
65 |
|
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
// CESMRSingleTimeField::NewL
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
//
|
|
70 |
CESMRSingleTimeField* CESMRSingleTimeField::NewL(
|
|
71 |
MESMRFieldValidator* aValidator )
|
|
72 |
{
|
|
73 |
FUNC_LOG;
|
|
74 |
CESMRSingleTimeField* self =
|
|
75 |
new( ELeave )CESMRSingleTimeField( aValidator );
|
|
76 |
CleanupStack::PushL( self );
|
|
77 |
self->ConstructL();
|
|
78 |
CleanupStack::Pop( self );
|
|
79 |
return self;
|
|
80 |
}
|
|
81 |
|
|
82 |
// ---------------------------------------------------------------------------
|
|
83 |
// CESMRSingleTimeField::ConstructL
|
|
84 |
// ---------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
void CESMRSingleTimeField::ConstructL( )
|
|
87 |
{
|
|
88 |
FUNC_LOG;
|
|
89 |
|
|
90 |
SetComponentsToInheritVisibility( ETrue );
|
|
91 |
|
|
92 |
TTime startTime;
|
|
93 |
startTime.HomeTime();
|
|
94 |
|
|
95 |
iTime = new( ELeave )CEikTimeEditor();
|
|
96 |
|
|
97 |
CESMRField::ConstructL( iTime ); //ownership transferred
|
|
98 |
|
|
99 |
iTime->ConstructL(
|
|
100 |
KMinimumTime,
|
|
101 |
KMaximumTime,
|
|
102 |
startTime,
|
|
103 |
EEikTimeWithoutSecondsField );
|
|
104 |
iTime->SetUpAndDownKeysConsumed( EFalse );
|
|
105 |
|
|
106 |
iFieldIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapAlarmClock );
|
|
107 |
iFieldIcon->SetParent( this );
|
|
108 |
|
|
109 |
if( iValidator )
|
|
110 |
{
|
|
111 |
iValidator->SetAlarmTimeFieldL( *iTime );
|
|
112 |
}
|
|
113 |
|
|
114 |
TRect tempRect( 0, 0, 0, 0 );
|
|
115 |
|
|
116 |
// Setting background instead of theme skin
|
|
117 |
NMRBitmapManager::TMRBitmapStruct bitmapStruct;
|
|
118 |
bitmapStruct = NMRBitmapManager::GetBitmapStruct( NMRBitmapManager::EMRBitmapInputCenter );
|
|
119 |
|
|
120 |
iBgCtrlContext = CAknsBasicBackgroundControlContext::NewL(
|
|
121 |
bitmapStruct.iItemId,
|
|
122 |
tempRect,
|
|
123 |
EFalse );
|
|
124 |
|
|
125 |
iTime->SetSkinBackgroundControlContextL( iBgCtrlContext );
|
|
126 |
}
|
|
127 |
|
|
128 |
// ---------------------------------------------------------------------------
|
|
129 |
// CESMRSingleTimeField::OkToLoseFocusL
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
TBool CESMRSingleTimeField::OkToLoseFocusL(
|
|
133 |
TESMREntryFieldId /*aNextItem*/ )
|
|
134 |
{
|
|
135 |
FUNC_LOG;
|
|
136 |
TInt err( KErrNone );
|
|
137 |
if( iValidator )
|
|
138 |
{
|
|
139 |
TRAP( err, iValidator->AlarmTimeChangedL() );
|
|
140 |
}
|
|
141 |
if( err != KErrNone )
|
|
142 |
{
|
|
143 |
CESMRGlobalNote::ExecuteL(
|
|
144 |
CESMRGlobalNote::EESMRCalenLaterDate );
|
|
145 |
return EFalse;
|
|
146 |
}
|
|
147 |
return ETrue;
|
|
148 |
}
|
|
149 |
|
|
150 |
// ---------------------------------------------------------------------------
|
|
151 |
// CESMRSingleTimeField::OfferKeyEventL
|
|
152 |
// ---------------------------------------------------------------------------
|
|
153 |
//
|
|
154 |
TKeyResponse CESMRSingleTimeField::OfferKeyEventL( const TKeyEvent& aEvent,
|
|
155 |
TEventCode aType )
|
|
156 |
{
|
|
157 |
FUNC_LOG;
|
|
158 |
TKeyResponse response( EKeyWasNotConsumed );
|
|
159 |
if ( aType == EEventKey )
|
|
160 |
{
|
|
161 |
TInt fieldIndex( iTime->CurrentField() );
|
|
162 |
|
|
163 |
switch( aEvent.iScanCode )
|
|
164 |
{
|
|
165 |
// make sure these events are NOT consumed
|
|
166 |
case EStdKeyUpArrow:
|
|
167 |
case EStdKeyDownArrow:
|
|
168 |
break;
|
|
169 |
|
|
170 |
default:
|
|
171 |
response = iTime->OfferKeyEventL ( aEvent, aType );
|
|
172 |
iTime->DrawDeferred();
|
|
173 |
break;
|
|
174 |
}
|
|
175 |
|
|
176 |
CheckIfValidatingNeededL( fieldIndex );
|
|
177 |
}
|
|
178 |
return response;
|
|
179 |
}
|
|
180 |
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
// CESMRSingleTimeField::CheckIfValidatingNeededL
|
|
183 |
// ---------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
void CESMRSingleTimeField::CheckIfValidatingNeededL(
|
|
186 |
TInt aStartFieldIndex )
|
|
187 |
{
|
|
188 |
FUNC_LOG;
|
|
189 |
TInt err( KErrNone );
|
|
190 |
TInt fieldIndex( iTime->CurrentField() );
|
|
191 |
|
|
192 |
if( fieldIndex != aStartFieldIndex )
|
|
193 |
{
|
|
194 |
TRAP( err, iValidator->AlarmTimeChangedL() );
|
|
195 |
}
|
|
196 |
|
|
197 |
if( err != KErrNone )
|
|
198 |
{
|
|
199 |
CESMRGlobalNote::ExecuteL (
|
|
200 |
CESMRGlobalNote::EESMRCalenLaterDate );
|
|
201 |
}
|
|
202 |
}
|
|
203 |
// ---------------------------------------------------------------------------
|
|
204 |
// CESMRSingleTimeField::SetOutlineFocusL
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
void CESMRSingleTimeField::SetOutlineFocusL( TBool aFocus )
|
|
208 |
{
|
|
209 |
FUNC_LOG;
|
|
210 |
CESMRField::SetOutlineFocusL( aFocus );
|
|
211 |
|
|
212 |
if( aFocus )
|
|
213 |
{
|
|
214 |
ChangeMiddleSoftKeyL( EESMRCmdSaveMR, R_QTN_MSK_SAVE );
|
|
215 |
}
|
|
216 |
}
|
|
217 |
|
|
218 |
// ---------------------------------------------------------------------------
|
|
219 |
// CESMRSingleTimeField::SetValidatorL
|
|
220 |
// ---------------------------------------------------------------------------
|
|
221 |
//
|
|
222 |
void CESMRSingleTimeField::SetValidatorL( MESMRFieldValidator* aValidator )
|
|
223 |
{
|
|
224 |
FUNC_LOG;
|
|
225 |
|
|
226 |
CESMRField::SetValidatorL( aValidator );
|
|
227 |
|
|
228 |
if ( iValidator )
|
|
229 |
{
|
|
230 |
iValidator->SetAlarmTimeFieldL( *iTime );
|
|
231 |
}
|
|
232 |
}
|
|
233 |
|
|
234 |
// ---------------------------------------------------------------------------
|
|
235 |
// CESMRSingleTimeField::SizeChanged()
|
|
236 |
// ---------------------------------------------------------------------------
|
|
237 |
//
|
|
238 |
TBool CESMRSingleTimeField::ExecuteGenericCommandL( TInt aCommand )
|
|
239 |
{
|
|
240 |
FUNC_LOG;
|
|
241 |
|
|
242 |
TBool retValue( EFalse );
|
|
243 |
|
|
244 |
if ( EMRCmdDoEnvironmentChange == aCommand )
|
|
245 |
{
|
|
246 |
// Locale has been changed
|
|
247 |
DoEnvChangeL();
|
|
248 |
retValue = ETrue;
|
|
249 |
}
|
|
250 |
|
|
251 |
return retValue;
|
|
252 |
}
|
|
253 |
|
|
254 |
// ---------------------------------------------------------------------------
|
|
255 |
// CESMRSingleTimeField::SizeChanged()
|
|
256 |
// ---------------------------------------------------------------------------
|
|
257 |
//
|
|
258 |
void CESMRSingleTimeField::SizeChanged()
|
|
259 |
{
|
|
260 |
TRect rect( Rect() );
|
|
261 |
|
|
262 |
// Layouting field icon
|
|
263 |
if( iFieldIcon )
|
|
264 |
{
|
|
265 |
TAknWindowComponentLayout iconLayout =
|
|
266 |
NMRLayoutManager::GetWindowComponentLayout(
|
|
267 |
NMRLayoutManager::EMRLayoutDateEditorIcon );
|
|
268 |
AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout );
|
|
269 |
}
|
|
270 |
|
|
271 |
// Layouting time editor
|
|
272 |
if( iTime )
|
|
273 |
{
|
|
274 |
TAknLayoutRect bgLayoutRect =
|
|
275 |
NMRLayoutManager::GetLayoutRect(
|
|
276 |
rect, NMRLayoutManager::EMRLayoutTextEditorBg );
|
|
277 |
TRect bgRect( bgLayoutRect.Rect() );
|
|
278 |
// Move focus rect so that it's relative to field's position.
|
|
279 |
bgRect.Move( -Position() );
|
|
280 |
SetFocusRect( bgRect );
|
|
281 |
|
|
282 |
TAknTextComponentLayout editorLayout =
|
|
283 |
NMRLayoutManager::GetTextComponentLayout(
|
|
284 |
NMRLayoutManager::EMRTextLayoutDateEditor );
|
|
285 |
AknLayoutUtils::LayoutMfne( iTime, rect, editorLayout );
|
|
286 |
|
|
287 |
NMRColorManager::SetColor( *iTime,
|
|
288 |
NMRColorManager::EMRMainAreaTextColor );
|
|
289 |
|
|
290 |
}
|
|
291 |
}
|
|
292 |
|
|
293 |
// ---------------------------------------------------------------------------
|
|
294 |
// CESMRSingleTimeField::CountComponentControls()
|
|
295 |
// ---------------------------------------------------------------------------
|
|
296 |
//
|
|
297 |
TInt CESMRSingleTimeField::CountComponentControls() const
|
|
298 |
{
|
|
299 |
TInt count( 0 );
|
|
300 |
if( iFieldIcon )
|
|
301 |
{
|
|
302 |
++count;
|
|
303 |
}
|
|
304 |
|
|
305 |
if( iTime )
|
|
306 |
{
|
|
307 |
++count;
|
|
308 |
}
|
|
309 |
return count;
|
|
310 |
}
|
|
311 |
|
|
312 |
// ---------------------------------------------------------------------------
|
|
313 |
// CESMRSingleTimeField::ComponentControl()
|
|
314 |
// ---------------------------------------------------------------------------
|
|
315 |
//
|
|
316 |
CCoeControl* CESMRSingleTimeField::ComponentControl( TInt aIndex ) const
|
|
317 |
{
|
|
318 |
switch( aIndex )
|
|
319 |
{
|
|
320 |
case 0:
|
|
321 |
return iFieldIcon;
|
|
322 |
case 1:
|
|
323 |
return iTime;
|
|
324 |
default:
|
|
325 |
return NULL;
|
|
326 |
}
|
|
327 |
}
|
|
328 |
|
|
329 |
// ---------------------------------------------------------------------------
|
|
330 |
// CESMRSingleTimeField::SetContainerWindowL
|
|
331 |
// ---------------------------------------------------------------------------
|
|
332 |
//
|
|
333 |
void CESMRSingleTimeField::SetContainerWindowL(
|
|
334 |
const CCoeControl& aContainer )
|
|
335 |
{
|
|
336 |
iContainerWindow = &aContainer;
|
|
337 |
|
|
338 |
CCoeControl::SetContainerWindowL( *iContainerWindow );
|
|
339 |
|
|
340 |
iFieldIcon->SetContainerWindowL( *iContainerWindow );
|
|
341 |
iTime->SetContainerWindowL( *iContainerWindow );
|
|
342 |
|
|
343 |
iFieldIcon->SetParent( this );
|
|
344 |
iTime->SetParent( this );
|
|
345 |
}
|
|
346 |
|
|
347 |
// ---------------------------------------------------------------------------
|
|
348 |
// CESMRSingleTimeField::DoEnvChangeL
|
|
349 |
// ---------------------------------------------------------------------------
|
|
350 |
//
|
|
351 |
void CESMRSingleTimeField::DoEnvChangeL()
|
|
352 |
{
|
|
353 |
FUNC_LOG;
|
|
354 |
|
|
355 |
CEikTimeEditor* time = new( ELeave )CEikTimeEditor;
|
|
356 |
CleanupStack::PushL( time );
|
|
357 |
|
|
358 |
TTime startTime;
|
|
359 |
startTime.HomeTime();
|
|
360 |
|
|
361 |
time->ConstructL(
|
|
362 |
KMinimumTime,
|
|
363 |
KMaximumTime,
|
|
364 |
startTime,
|
|
365 |
EEikTimeWithoutSecondsField );
|
|
366 |
|
|
367 |
time->SetUpAndDownKeysConsumed( EFalse );
|
|
368 |
|
|
369 |
UpdateExtControlL( time );
|
|
370 |
|
|
371 |
CleanupStack::Pop( time );
|
|
372 |
iTime = time;
|
|
373 |
|
|
374 |
iTime->SetSkinBackgroundControlContextL( iBgCtrlContext );
|
|
375 |
SetContainerWindowL( *iContainerWindow );
|
|
376 |
|
|
377 |
if ( iValidator )
|
|
378 |
{
|
|
379 |
iValidator->SetAlarmTimeFieldL( *iTime );
|
|
380 |
}
|
|
381 |
|
|
382 |
iTime->ActivateL();
|
|
383 |
|
|
384 |
SizeChanged();
|
|
385 |
DrawDeferred();
|
|
386 |
}
|
|
387 |
|
|
388 |
// EOF
|
|
389 |
|