|
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 All day event checkbox field implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cesmrcheckbox.h" |
|
19 #include "mesmrlistobserver.h" |
|
20 #include "mesmrmeetingrequestentry.h" |
|
21 #include "mesmrfieldvalidator.h" |
|
22 #include "esmrconfig.hrh" |
|
23 #include "esmrhelper.h" |
|
24 #include "nmrbitmapmanager.h" |
|
25 #include "cmrimage.h" |
|
26 #include "cmrlabel.h" |
|
27 #include "nmrlayoutmanager.h" |
|
28 #include "mesmrfieldeventqueue.h" |
|
29 #include "cesmrgenericfieldevent.h" |
|
30 |
|
31 #include <esmrgui.rsg> |
|
32 #include <StringLoader.h> |
|
33 #include <data_caging_path_literals.hrh> |
|
34 |
|
35 // DEBUG |
|
36 #include "emailtrace.h" |
|
37 |
|
38 |
|
39 // ======== MEMBER FUNCTIONS ======== |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CESMRCheckbox::NewL |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CESMRCheckBox* CESMRCheckBox::NewL( MESMRFieldValidator* aValidator ) |
|
46 { |
|
47 FUNC_LOG; |
|
48 CESMRCheckBox* self = new( ELeave )CESMRCheckBox( aValidator ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CESMRCheckbox::CESMRCheckbox |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CESMRCheckBox::CESMRCheckBox( MESMRFieldValidator* aValidator ) |
|
60 : iChecked( EFalse ) |
|
61 { |
|
62 FUNC_LOG; |
|
63 |
|
64 iValidator = aValidator; |
|
65 |
|
66 SetFieldId( EESMRFieldAllDayEvent ); |
|
67 SetFocusType ( EESMRHighlightFocus ); |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CESMRCheckbox::ConstructL |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CESMRCheckBox::ConstructL() |
|
75 { |
|
76 FUNC_LOG; |
|
77 iLabel = CMRLabel::NewL(); |
|
78 iLabel->SetParent( this ); |
|
79 |
|
80 CESMRField::ConstructL( iLabel ); //ownership transfered |
|
81 |
|
82 HBufC* txt = StringLoader::LoadLC ( R_QTN_MEET_REQ_ALL_DAY_EVENT ); |
|
83 iLabel->SetTextL( *txt ); |
|
84 CleanupStack::PopAndDestroy( txt ); |
|
85 |
|
86 // Creating field icon |
|
87 SetIconL ( iChecked ); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CESMRCheckbox::~CESMRCheckbox |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 CESMRCheckBox::~CESMRCheckBox( ) |
|
95 { |
|
96 FUNC_LOG; |
|
97 delete iFieldIcon; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CESMRCheckbox::SetOutlineFocusL |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 void CESMRCheckBox::SetOutlineFocusL( TBool aFocus ) |
|
105 { |
|
106 FUNC_LOG; |
|
107 CESMRField::SetOutlineFocusL ( aFocus ); |
|
108 |
|
109 //Focus gained |
|
110 if ( aFocus ) |
|
111 { |
|
112 SwitchMSKLabelL(); |
|
113 } |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CESMRCheckbox::ExecuteGenericCommandL |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TBool CESMRCheckBox::ExecuteGenericCommandL( TInt aCommand ) |
|
121 { |
|
122 FUNC_LOG; |
|
123 TBool isUsed( EFalse ); |
|
124 // EAknCmdOpen is added for the Pointer events, see ListPane |
|
125 if( aCommand == EESMRCmdCheckEvent || aCommand == EAknCmdOpen ) |
|
126 { |
|
127 HandleTactileFeedbackL(); |
|
128 |
|
129 HandleCheckEventL(); |
|
130 SwitchMSKLabelL(); |
|
131 SendFieldChangeEventL( EESMRFieldAllDayEvent ); |
|
132 isUsed = ETrue; |
|
133 } |
|
134 return isUsed; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // CESMRCheckbox::OfferKeyEventL |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 TKeyResponse CESMRCheckBox::OfferKeyEventL(const TKeyEvent& aEvent, |
|
142 TEventCode aType ) |
|
143 { |
|
144 FUNC_LOG; |
|
145 TKeyResponse response( EKeyWasNotConsumed); |
|
146 if ( aType == EEventKey ) |
|
147 { |
|
148 if ( aEvent.iScanCode == EStdKeyDevice3 ) |
|
149 { |
|
150 HandleCheckEventL(); |
|
151 SwitchMSKLabelL(); |
|
152 SendFieldChangeEventL( EESMRFieldAllDayEvent ); |
|
153 response = EKeyWasConsumed; |
|
154 } |
|
155 } |
|
156 return response; |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // CESMRCheckbox::CountComponentControls |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 TInt CESMRCheckBox::CountComponentControls( ) const |
|
164 { |
|
165 FUNC_LOG; |
|
166 TInt count( 0 ); |
|
167 if ( iFieldIcon ) |
|
168 { |
|
169 ++count; |
|
170 } |
|
171 if ( iLabel ) |
|
172 { |
|
173 ++count; |
|
174 } |
|
175 return count; |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CESMRCheckbox::ComponentControl |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 CCoeControl* CESMRCheckBox::ComponentControl( TInt aInd ) const |
|
183 { |
|
184 FUNC_LOG; |
|
185 switch ( aInd ) |
|
186 { |
|
187 case 0: |
|
188 return iFieldIcon; |
|
189 case 1: |
|
190 return iLabel; |
|
191 default: |
|
192 return NULL; |
|
193 } |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // CESMRCheckbox::SizeChanged |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CESMRCheckBox::SizeChanged() |
|
201 { |
|
202 FUNC_LOG; |
|
203 TRect rect = Rect(); |
|
204 |
|
205 TAknLayoutRect rowLayoutRect = |
|
206 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ); |
|
207 rect = rowLayoutRect.Rect(); |
|
208 |
|
209 TAknWindowComponentLayout iconLayout = |
|
210 NMRLayoutManager::GetWindowComponentLayout( |
|
211 NMRLayoutManager::EMRLayoutTextEditorIcon ); |
|
212 AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout ); |
|
213 |
|
214 TAknLayoutRect bgLayoutRect = |
|
215 NMRLayoutManager::GetLayoutRect( |
|
216 rect, NMRLayoutManager::EMRLayoutTextEditorBg ); |
|
217 TRect bgRect( bgLayoutRect.Rect() ); |
|
218 // Move focus rect so that it's relative to field's position. |
|
219 bgRect.Move( -Position() ); |
|
220 SetFocusRect( bgRect ); |
|
221 |
|
222 TAknTextComponentLayout editorLayout = |
|
223 NMRLayoutManager::GetTextComponentLayout( |
|
224 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
225 |
|
226 AknLayoutUtils::LayoutLabel( iLabel, rect, editorLayout ); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // CESMRCheckbox::InternalizeL |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void CESMRCheckBox::InternalizeL( MESMRCalEntry& aEntry ) |
|
234 { |
|
235 FUNC_LOG; |
|
236 TBool alldayEvent( aEntry.IsAllDayEventL() ); |
|
237 |
|
238 // Update the validator |
|
239 iValidator->SetAllDayEventL( alldayEvent ); |
|
240 |
|
241 // if this is all day event and not checked |
|
242 if ( alldayEvent && !iChecked ) |
|
243 { |
|
244 HandleCheckEventL(); |
|
245 } |
|
246 SetIconL( iChecked ); |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // CESMRCheckbox::ExternalizeL |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void CESMRCheckBox::ExternalizeL( MESMRCalEntry& /*aEntry*/) |
|
254 { |
|
255 FUNC_LOG; |
|
256 iValidator->SetAllDayEventL( iChecked ); |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // CESMRCheckbox::SetIconL |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void CESMRCheckBox::SetIconL( TBool aChecked ) |
|
264 { |
|
265 FUNC_LOG; |
|
266 delete iFieldIcon; |
|
267 iFieldIcon = NULL; |
|
268 |
|
269 NMRBitmapManager::TMRBitmapId iconID; |
|
270 if( aChecked ) |
|
271 { |
|
272 iconID = NMRBitmapManager::EMRBitmapCheckBoxOn; |
|
273 } |
|
274 else |
|
275 { |
|
276 iconID = NMRBitmapManager::EMRBitmapCheckBoxOff; |
|
277 } |
|
278 |
|
279 iFieldIcon = CMRImage::NewL( iconID ); |
|
280 iFieldIcon->SetParent( this ); |
|
281 |
|
282 SizeChanged(); |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // CESMRCheckbox::HandleCheckEventL |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 void CESMRCheckBox::HandleCheckEventL( ) |
|
290 { |
|
291 FUNC_LOG; |
|
292 /* |
|
293 * Change check status |
|
294 */ |
|
295 iChecked = !iChecked; // change status |
|
296 SetIconL ( iChecked ); // set icon for the status |
|
297 |
|
298 // update validator status: |
|
299 iValidator->SetAllDayEventL ( iChecked ); |
|
300 |
|
301 /* |
|
302 * Add / remove new fields to list |
|
303 */ |
|
304 if ( iChecked ) |
|
305 { |
|
306 // start - end time should be removed |
|
307 // relateive alarm should be removed |
|
308 iObserver->HideControl ( EESMRFieldMeetingTime ); |
|
309 iObserver->HideControl ( EESMRFieldAlarm ); |
|
310 // absolute alarm should be inserted |
|
311 iObserver->ShowControl ( EESMRFieldAlarmOnOff ); |
|
312 } |
|
313 else |
|
314 { |
|
315 iObserver->ShowControl ( EESMRFieldMeetingTime ); |
|
316 iObserver->ShowControl ( EESMRFieldAlarm ); |
|
317 iObserver->HideControl ( EESMRFieldAlarmOnOff ); |
|
318 iObserver->HideControl ( EESMRFieldAlarmTime ); |
|
319 iObserver->HideControl ( EESMRFieldAlarmDate ); |
|
320 } |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CESMRCheckbox::SwitchMSKLabelL |
|
325 // --------------------------------------------------------------------------- |
|
326 // |
|
327 void CESMRCheckBox::SwitchMSKLabelL() |
|
328 { |
|
329 FUNC_LOG; |
|
330 if( iChecked ) |
|
331 { |
|
332 ChangeMiddleSoftKeyL(EESMRCmdCheckEvent, R_QTN_MSK_UNMARK); |
|
333 } |
|
334 else |
|
335 { |
|
336 ChangeMiddleSoftKeyL(EESMRCmdCheckEvent, R_QTN_MSK_MARK); |
|
337 } |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // CESMRCheckbox::SetContainerWindowL |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 void CESMRCheckBox::SetContainerWindowL( |
|
345 const CCoeControl& aContainer ) |
|
346 { |
|
347 CCoeControl::SetContainerWindowL( aContainer ); |
|
348 iLabel->SetContainerWindowL( aContainer ); |
|
349 iLabel->SetParent( this ); |
|
350 } |
|
351 // --------------------------------------------------------------------------- |
|
352 // CESMRCheckBox::SendFieldChangeEventL |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 void CESMRCheckBox::SendFieldChangeEventL( |
|
356 TESMREntryFieldId aFieldId ) |
|
357 { |
|
358 FUNC_LOG; |
|
359 if ( iEventQueue ) |
|
360 { |
|
361 CESMRGenericFieldEvent* event = |
|
362 CESMRGenericFieldEvent::NewLC( NULL, |
|
363 MESMRFieldEvent::EESMRFieldChangeEvent ); |
|
364 TInt fieldId = aFieldId; |
|
365 CESMRFieldEventValue* field = CESMRFieldEventValue::NewLC( |
|
366 CESMRFieldEventValue::EESMRInteger, &fieldId ); |
|
367 event->AddParamL( field ); |
|
368 CleanupStack::Pop( field ); |
|
369 CESMRFieldEventValue* checked = CESMRFieldEventValue::NewLC( |
|
370 CESMRFieldEventValue::EESMRInteger, &iChecked ); |
|
371 event->AddParamL( checked ); |
|
372 CleanupStack::Pop( checked ); |
|
373 iEventQueue->NotifyEventL( *event ); |
|
374 CleanupStack::PopAndDestroy( event ); |
|
375 } |
|
376 } |
|
377 // EOF |