|
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: Meeting Request viewer response field implementation |
|
15 * |
|
16 */ |
|
17 #include "cesmrresponseitem.h" |
|
18 #include "nmrlayoutmanager.h" |
|
19 #include "nmrbitmapmanager.h" |
|
20 #include "nmrcolormanager.h" |
|
21 #include "cmrimage.h" |
|
22 #include "cmrlabel.h" |
|
23 |
|
24 #include <esmrgui.rsg> |
|
25 |
|
26 // DEBUG |
|
27 #include "emailtrace.h" |
|
28 |
|
29 namespace // codescanner::namespace |
|
30 { |
|
31 const TInt KMaxLinesInResponseTopicItem( 1 ); |
|
32 const TInt KEdge(8); |
|
33 } // unnamed namespace |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CESMRResponseItem::NewL |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CESMRResponseItem* CESMRResponseItem::NewL( TESMRCommand aCmd, |
|
41 const TDesC& aItemText, |
|
42 TBool aHasIcon ) |
|
43 { |
|
44 FUNC_LOG; |
|
45 CESMRResponseItem* self = CESMRResponseItem::NewLC( aCmd, |
|
46 aItemText, |
|
47 aHasIcon ); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CESMRResponseItem::NewL |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CESMRResponseItem* CESMRResponseItem::NewLC( TESMRCommand aCmd, |
|
57 const TDesC& aItemText, |
|
58 TBool aHasIcon ) |
|
59 { |
|
60 FUNC_LOG; |
|
61 CESMRResponseItem* self = new (ELeave) CESMRResponseItem( aCmd ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL( aItemText, aHasIcon ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CESMRResponseItem::~CESMRResponseItem |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CESMRResponseItem::~CESMRResponseItem() |
|
72 { |
|
73 FUNC_LOG; |
|
74 delete iSelectionLabel; |
|
75 delete iIcon; |
|
76 delete iItemText; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CESMRResponseItem::CESMRResponseItem |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CESMRResponseItem::CESMRResponseItem(TESMRCommand aCmd) |
|
84 : iCmd (aCmd) |
|
85 { |
|
86 FUNC_LOG; |
|
87 //do nothing |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CESMRResponseItem::ConstructL |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CESMRResponseItem::ConstructL( const TDesC& aItemText, TBool aHasIcon ) |
|
95 { |
|
96 FUNC_LOG; |
|
97 iSelectionLabel = CMRLabel::NewL( this ); |
|
98 iSelectionLabel->SetTextL( aItemText ); |
|
99 |
|
100 // Response item might not have icon. e.g. topic line |
|
101 iHasIcon = aHasIcon; |
|
102 if( aHasIcon ) |
|
103 { |
|
104 iIcon = IconL( EFalse ); |
|
105 } |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CESMRResponseItem::Draw |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CESMRResponseItem::Draw( const TRect& aRect ) const |
|
113 { |
|
114 FUNC_LOG; |
|
115 NMRColorManager::SetColor( *iSelectionLabel, |
|
116 NMRColorManager::EMRMainAreaTextColor ); |
|
117 |
|
118 if( iHighlighted ) |
|
119 { |
|
120 CWindowGc& gc = SystemGc(); |
|
121 TRect rect = aRect; |
|
122 TBool enableEdges(ETrue); |
|
123 |
|
124 CFbsBitmap* selector = NULL; |
|
125 CFbsBitmap* selectorMask = NULL; |
|
126 |
|
127 TSize corner(KEdge, KEdge); |
|
128 NMRBitmapManager::GetSkinBasedBitmap( |
|
129 NMRBitmapManager::EMRBitmapListTopLeft, |
|
130 selector, selectorMask, corner ); |
|
131 |
|
132 if( selector && selectorMask && enableEdges) |
|
133 { |
|
134 //corner TL |
|
135 gc.BitBltMasked( rect.iTl, selector, corner, selectorMask, EFalse ); |
|
136 |
|
137 //side L |
|
138 TSize side(KEdge, (rect.Height() - 2 * KEdge) ); |
|
139 NMRBitmapManager::GetSkinBasedBitmap( |
|
140 NMRBitmapManager::EMRBitmapListLeft, |
|
141 selector, selectorMask, side ); |
|
142 gc.BitBltMasked( TPoint(rect.iTl.iX, rect.iTl.iY + KEdge), |
|
143 selector, side, selectorMask, EFalse ); |
|
144 |
|
145 //corner BL |
|
146 NMRBitmapManager::GetSkinBasedBitmap( |
|
147 NMRBitmapManager::EMRBitmapListBottomLeft, |
|
148 selector, selectorMask, corner ); |
|
149 gc.BitBltMasked( TPoint(rect.iTl.iX, |
|
150 rect.iTl.iY + KEdge + side.iHeight), |
|
151 selector, corner, selectorMask, EFalse ); |
|
152 |
|
153 //top |
|
154 TSize top( (rect.Width() - 2 * KEdge) , KEdge); |
|
155 NMRBitmapManager::GetSkinBasedBitmap( |
|
156 NMRBitmapManager::EMRBitmapListTop, |
|
157 selector, selectorMask, top ); |
|
158 gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge, rect.iTl.iY), |
|
159 selector, top, selectorMask, EFalse ); |
|
160 |
|
161 //center |
|
162 TSize center( top.iWidth, side.iHeight); |
|
163 NMRBitmapManager::GetSkinBasedBitmap( |
|
164 NMRBitmapManager::EMRBitmapListCenter, |
|
165 selector, selectorMask, center ); |
|
166 gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge, rect.iTl.iY + KEdge), |
|
167 selector, center, selectorMask, EFalse ); |
|
168 |
|
169 //bottom |
|
170 NMRBitmapManager::GetSkinBasedBitmap( |
|
171 NMRBitmapManager::EMRBitmapListBottom, |
|
172 selector, selectorMask, top ); |
|
173 gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge, |
|
174 rect.iTl.iY + side.iHeight + KEdge), |
|
175 selector, top, selectorMask, EFalse ); |
|
176 |
|
177 //corner TR |
|
178 NMRBitmapManager::GetSkinBasedBitmap( |
|
179 NMRBitmapManager::EMRBitmapListTopRight, |
|
180 selector, selectorMask, corner ); |
|
181 gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge + top.iWidth, |
|
182 rect.iTl.iY), |
|
183 selector, corner, selectorMask, EFalse ); |
|
184 |
|
185 //side R |
|
186 NMRBitmapManager::GetSkinBasedBitmap( |
|
187 NMRBitmapManager::EMRBitmapListRight, |
|
188 selector, selectorMask, side ); |
|
189 gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge + top.iWidth, |
|
190 rect.iTl.iY + KEdge), |
|
191 selector, side, selectorMask, EFalse ); |
|
192 |
|
193 //corner Br |
|
194 NMRBitmapManager::GetSkinBasedBitmap( |
|
195 NMRBitmapManager::EMRBitmapListBottomRight, |
|
196 selector, selectorMask, corner ); |
|
197 gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge + top.iWidth, |
|
198 rect.iTl.iY + KEdge + side.iHeight), |
|
199 selector, corner, selectorMask, EFalse ); |
|
200 } |
|
201 else if(!enableEdges) |
|
202 { |
|
203 //center |
|
204 TSize center( rect.Width(), rect.Height() ); |
|
205 NMRBitmapManager::GetSkinBasedBitmap( |
|
206 NMRBitmapManager::EMRBitmapListCenter, |
|
207 selector, selectorMask, center ); |
|
208 gc.BitBltMasked( TPoint(rect.iTl.iX, rect.iTl.iY), |
|
209 selector, center, selectorMask, EFalse ); |
|
210 } |
|
211 else // This should NOT be called ever. |
|
212 { |
|
213 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
214 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
215 gc.SetBrushColor( KRgbGreen ); |
|
216 rect.SetSize( TSize(rect.Size().iWidth - 1, |
|
217 rect.Size().iHeight ) ); |
|
218 gc.DrawRect( rect ); |
|
219 } |
|
220 |
|
221 delete selector; |
|
222 delete selectorMask; |
|
223 } |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CESMRResponseItem::CountComponentControls |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 TInt CESMRResponseItem::CountComponentControls() const |
|
231 { |
|
232 FUNC_LOG; |
|
233 TInt itemCount = 0; |
|
234 if( iSelectionLabel ) |
|
235 { |
|
236 itemCount++; |
|
237 } |
|
238 if( iIcon ) |
|
239 { |
|
240 itemCount++; |
|
241 } |
|
242 |
|
243 return itemCount; |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CESMRResponseItem::ComponentControl |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 CCoeControl* CESMRResponseItem::ComponentControl( TInt aInd ) const |
|
251 { |
|
252 FUNC_LOG; |
|
253 CCoeControl* control = NULL; |
|
254 if ( aInd == 0 ) |
|
255 { |
|
256 control = iSelectionLabel; |
|
257 } |
|
258 |
|
259 if ( aInd == 1 ) |
|
260 { |
|
261 control = iIcon; |
|
262 } |
|
263 return control; |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CESMRResponseItem::SizeChanged |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 void CESMRResponseItem::SizeChanged() |
|
271 { |
|
272 FUNC_LOG; |
|
273 TRect rect( this->Rect() ); |
|
274 |
|
275 // Icon exists, this is answer item ( accept / tentative / decline ) |
|
276 if( iIcon ) |
|
277 { |
|
278 // Icon |
|
279 TAknWindowComponentLayout iconLayout = |
|
280 NMRLayoutManager::GetWindowComponentLayout( |
|
281 NMRLayoutManager::EMRLayoutCheckboxIcon ); |
|
282 AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout ); |
|
283 // Label |
|
284 TAknTextComponentLayout labelLayout = |
|
285 NMRLayoutManager::GetTextComponentLayout( |
|
286 NMRLayoutManager::EMRTextLayoutCheckboxEditor ); |
|
287 AknLayoutUtils::LayoutLabel( iSelectionLabel, rect, labelLayout ); |
|
288 } |
|
289 else // There is no icon (this is the topic item) |
|
290 { |
|
291 TAknTextComponentLayout labelLayout = |
|
292 NMRLayoutManager::GetTextComponentLayout( |
|
293 NMRLayoutManager::EMRTextLayoutText ); |
|
294 AknLayoutUtils::LayoutLabel( iSelectionLabel, rect, labelLayout ); |
|
295 // SizeChange() is called when rect for ResponseItem is ready to be used. |
|
296 // If setting text to response topic label fails, no need to catch it. |
|
297 TRAP_IGNORE(SetTextToLabelL()); |
|
298 } |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CESMRResponseItem::SetContainerWindowL |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 void CESMRResponseItem::SetContainerWindowL( const CCoeControl& aContainer ) |
|
306 { |
|
307 FUNC_LOG; |
|
308 |
|
309 CCoeControl::SetContainerWindowL( aContainer ); |
|
310 |
|
311 TInt count( CountComponentControls() ); |
|
312 |
|
313 for ( TInt i = 0; i < count; ++i ) |
|
314 { |
|
315 ComponentControl( i )->SetContainerWindowL( *this ); |
|
316 } |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CESMRResponseItem::IconL |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 CMRImage* CESMRResponseItem::IconL( TBool aChecked ) |
|
324 { |
|
325 FUNC_LOG; |
|
326 NMRBitmapManager::TMRBitmapId iconID( |
|
327 NMRBitmapManager::EMRBitmapCheckBoxOff ); |
|
328 |
|
329 if( aChecked ) |
|
330 { |
|
331 iconID = NMRBitmapManager::EMRBitmapCheckBoxOn; |
|
332 } |
|
333 CMRImage* icon = CMRImage::NewL( iconID, this ); |
|
334 return icon; |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CESMRResponseItem::SetHighlight |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CESMRResponseItem::SetHighlight() |
|
342 { |
|
343 FUNC_LOG; |
|
344 iHighlighted = ETrue; |
|
345 } |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // CESMRResponseItem::RemoveHighlight |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void CESMRResponseItem::RemoveHighlight() |
|
352 { |
|
353 FUNC_LOG; |
|
354 iHighlighted = EFalse; |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CESMRResponseItem::ChangeIconL |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 void CESMRResponseItem::ChangeIconL( TBool aChecked ) |
|
362 { |
|
363 FUNC_LOG; |
|
364 delete iIcon; |
|
365 iIcon = NULL; |
|
366 iIcon = IconL( aChecked ); |
|
367 SizeChanged(); |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // CESMRResponseItem::SetFont |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 void CESMRResponseItem::SetFont( const CFont* aFont ) |
|
375 { |
|
376 FUNC_LOG; |
|
377 iSelectionLabel->SetFont( aFont ); |
|
378 |
|
379 NMRColorManager::SetColor( *iSelectionLabel, |
|
380 NMRColorManager::EMRMainAreaTextColor ); |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CESMRResponseItem::SetTextL |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 void CESMRResponseItem::SetTextL( const TDesC& aItemText ) |
|
388 { |
|
389 FUNC_LOG; |
|
390 // When this method is called for the first time(with valid text) |
|
391 // text is stored to member variable. This is done because |
|
392 // text needs to be wrapped again (orientation might have |
|
393 // changed) when SizeChanged() gets called. |
|
394 if( !iItemText && aItemText.Length() > 0 ) |
|
395 { |
|
396 iOriginalTextLength = aItemText.Length(); |
|
397 iItemText = HBufC::NewL( aItemText.Length() ); |
|
398 *iItemText = aItemText; |
|
399 } |
|
400 else if( !iItemText && aItemText.Length() <= 0 ) |
|
401 { |
|
402 // if there is no new text yet, there is nothing to do here. |
|
403 return; |
|
404 } |
|
405 SetTextToLabelL(); |
|
406 } |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // CESMRResponseItem::SetTextToLabelL |
|
410 // ----------------------------------------------------------------------------- |
|
411 // |
|
412 void CESMRResponseItem::SetTextToLabelL() |
|
413 { |
|
414 if( iItemText ) |
|
415 { |
|
416 TInt lineCount = 1; // Default line count. |
|
417 // If this item has no icon, it may use two lines for the text |
|
418 if( !iIcon ) |
|
419 { |
|
420 lineCount = KMaxLinesInResponseTopicItem; |
|
421 } |
|
422 |
|
423 // Text wrapping |
|
424 CArrayFixFlat<TInt>* widthArray = |
|
425 new (ELeave) CArrayFixFlat<TInt>( lineCount ); |
|
426 CleanupStack::PushL( widthArray ); |
|
427 |
|
428 for ( TInt i(0); i < lineCount; i++ ) |
|
429 { |
|
430 // If this item has no icon, all the space is for text |
|
431 if( !iIcon ) |
|
432 { |
|
433 TAknLayoutText layout = NMRLayoutManager::GetLayoutText( |
|
434 Rect(), NMRLayoutManager::EMRTextLayoutText ); |
|
435 widthArray->AppendL( layout.TextRect().Width() ); |
|
436 } |
|
437 else |
|
438 { |
|
439 // This layout leaves space for the icon to the left side |
|
440 TAknLayoutText layout = NMRLayoutManager::GetLayoutText( |
|
441 Rect(), NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
442 widthArray->AppendL( layout.TextRect().Width() ); |
|
443 } |
|
444 } |
|
445 |
|
446 HBufC* wrappedText; |
|
447 // Set the font for the text |
|
448 const CFont* font = iSelectionLabel->Font(); |
|
449 RBuf buffer; // codescanner::resourcenotoncleanupstack |
|
450 buffer.CreateL( iOriginalTextLength + widthArray->Count() ); |
|
451 buffer.CleanupClosePushL(); |
|
452 |
|
453 // Wrap the text |
|
454 AknTextUtils::WrapToStringAndClipL( *iItemText, *widthArray, *font, buffer ); |
|
455 wrappedText = buffer.AllocLC(); |
|
456 |
|
457 // Set the text to label |
|
458 iSelectionLabel->SetTextL( *wrappedText ); |
|
459 CleanupStack::PopAndDestroy(3); // widthArray, wrappedText, buffer |
|
460 } |
|
461 } |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CESMRResponseItem::ItemTextLineCount |
|
465 // ----------------------------------------------------------------------------- |
|
466 // |
|
467 TInt CESMRResponseItem::ItemTextLineCount() |
|
468 { |
|
469 FUNC_LOG; |
|
470 TInt retValue( KErrNotFound ); |
|
471 if( iSelectionLabel ) |
|
472 { |
|
473 retValue = iSelectionLabel->NumberOfLines(); |
|
474 } |
|
475 return retValue; |
|
476 } |
|
477 |
|
478 // ----------------------------------------------------------------------------- |
|
479 // CESMRResponseItem::CommandId |
|
480 // ----------------------------------------------------------------------------- |
|
481 // |
|
482 TESMRCommand CESMRResponseItem::CommandId() const |
|
483 { |
|
484 FUNC_LOG; |
|
485 return iCmd; |
|
486 } |
|
487 |
|
488 // ----------------------------------------------------------------------------- |
|
489 // CESMRResponseItem::SetUnderlineL |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 void CESMRResponseItem::SetUnderlineL( TBool aUndreline ) |
|
493 { |
|
494 iSelectionLabel->SetUnderlining( aUndreline ); |
|
495 } |
|
496 |