|
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 location field |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cesmrviewerlocationfield.h" |
|
19 #include "cesmrrichtextviewer.h" |
|
20 #include "mesmrlistobserver.h" |
|
21 #include "nmrlayoutmanager.h" |
|
22 #include "cmrimage.h" |
|
23 #include "cesmrfeaturesettings.h" |
|
24 #include "emailtrace.h" |
|
25 #include "cesmrglobalnote.h" |
|
26 #include "cmrbutton.h" |
|
27 |
|
28 #include <calentry.h> |
|
29 #include <esmrgui.rsg> |
|
30 #include <data_caging_path_literals.hrh> |
|
31 #include <AknLayout2ScalableDef.h> |
|
32 #include <gulicon.h> |
|
33 #include <StringLoader.h> |
|
34 |
|
35 // LOCAL DEFINITIONS |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CESMRViewerLocationField::NewL |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CESMRViewerLocationField* CESMRViewerLocationField::NewL( ) |
|
44 { |
|
45 CESMRViewerLocationField* self = new (ELeave) CESMRViewerLocationField; |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL( ); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CESMRViewerLocationField::CESMRViewerLocationField |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CESMRViewerLocationField::~CESMRViewerLocationField() |
|
57 { |
|
58 delete iFieldButton; |
|
59 delete iWaypointIcon; |
|
60 delete iFeatures; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CESMRViewerLocationField::MinimumSize |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 TSize CESMRViewerLocationField::MinimumSize() |
|
68 { |
|
69 TRect parentRect( Parent()->Rect() ); |
|
70 |
|
71 TRect fieldRect = |
|
72 NMRLayoutManager::GetFieldLayoutRect( parentRect, 1 ).Rect(); |
|
73 |
|
74 TRect viewerRect( NMRLayoutManager::GetLayoutText( |
|
75 fieldRect, |
|
76 NMRLayoutManager::EMRTextLayoutTextEditor ).TextRect() ); |
|
77 |
|
78 // Adjust field size so that there's room for expandable editor. |
|
79 fieldRect.Resize( 0, iSize.iHeight - viewerRect.Height() ); |
|
80 |
|
81 return fieldRect.Size(); |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CESMRViewerLocationField::InitializeL |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CESMRViewerLocationField::InitializeL() |
|
90 { |
|
91 // Setting Font for the rich text viewer |
|
92 TAknLayoutText text = NMRLayoutManager::GetLayoutText( |
|
93 Rect(), |
|
94 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
95 |
|
96 iRichTextViewer->SetFontL( text.Font() ); |
|
97 iRichTextViewer->ApplyLayoutChangesL(); |
|
98 |
|
99 // This is called so that theme changes will apply when changing theme "on the fly" |
|
100 if ( IsFocused() ) |
|
101 { |
|
102 iRichTextViewer->FocusChanged( EDrawNow ); |
|
103 } |
|
104 iRichTextViewer->SetEventQueue( iEventQueue ); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CESMRViewerLocationField::InternalizeL() |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CESMRViewerLocationField::InternalizeL( MESMRCalEntry& aEntry ) |
|
112 { |
|
113 TPtrC text = aEntry.Entry().LocationL( ); |
|
114 |
|
115 // Hide this field if location is not set |
|
116 if( text.Length() == 0 ) |
|
117 { |
|
118 iObserver->HideControl( FieldId() ); |
|
119 } |
|
120 else |
|
121 { |
|
122 iRichTextViewer->SetTextL( &text, ETrue ); |
|
123 iRichTextViewer->ApplyLayoutChangesL(); |
|
124 } |
|
125 |
|
126 // If the geo value has set, the waypoint icon has to be shown on right |
|
127 // side of the location field |
|
128 CCalGeoValue* geoValue = aEntry.Entry().GeoValueL(); |
|
129 TReal dummy; |
|
130 if( !iLocked ) |
|
131 { |
|
132 if( geoValue && geoValue->GetLatLong( dummy, dummy ) ) |
|
133 { |
|
134 iWaypointIcon = CMRImage::NewL( |
|
135 NMRBitmapManager::EMRBitmapLocationWaypoint, |
|
136 this, |
|
137 ETrue ); |
|
138 } |
|
139 } |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CESMRViewerLocationField::OfferKeyEventL() |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 |
|
147 TKeyResponse CESMRViewerLocationField::OfferKeyEventL(const TKeyEvent& aEvent, |
|
148 TEventCode aType ) |
|
149 { |
|
150 return iRichTextViewer->OfferKeyEventL( aEvent, aType ); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CESMRViewerLocationField::HandleEdwinSizeEventL() |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 TBool CESMRViewerLocationField::HandleEdwinSizeEventL( CEikEdwin* aEdwin, |
|
158 TEdwinSizeEvent /*aType*/, TSize aSize ) |
|
159 { |
|
160 TBool reDraw( EFalse ); |
|
161 |
|
162 // Let's save the required size for the iRichTextViewer |
|
163 iSize = aSize; |
|
164 |
|
165 if ( iObserver && aEdwin == iRichTextViewer ) |
|
166 { |
|
167 iObserver->ControlSizeChanged( this ); |
|
168 RecordField(); |
|
169 reDraw = ETrue; |
|
170 } |
|
171 |
|
172 return reDraw; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CESMRViewerLocationField::CESMRViewerLocationField() |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 CESMRViewerLocationField::CESMRViewerLocationField() |
|
180 { |
|
181 SetFieldId( EESMRFieldLocation ); |
|
182 SetFocusType( EESMRHighlightFocus ); |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CESMRViewerLocationField::ConstructL() |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 void CESMRViewerLocationField::ConstructL( ) |
|
190 { |
|
191 iFieldButton = CMRButton::NewL( |
|
192 NMRBitmapManager::EMRBitmapLocation, |
|
193 this ); |
|
194 iFieldButton->SetObserver(this); |
|
195 |
|
196 iRichTextViewer = CESMRRichTextViewer::NewL( this ); |
|
197 CESMRField::ConstructL( iRichTextViewer ); // ownership transfered |
|
198 iRichTextViewer->SetEdwinSizeObserver( this ); |
|
199 iRichTextViewer->SetParent( this ); |
|
200 |
|
201 iFeatures = CESMRFeatureSettings::NewL(); |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // CESMRViewerLocationField::ListObserverSet |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 void CESMRViewerLocationField::ListObserverSet() |
|
209 { |
|
210 iRichTextViewer->SetListObserver( iObserver ); |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CESMRViewerLocationField::ExecuteGenericCommandL() |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 TBool CESMRViewerLocationField::ExecuteGenericCommandL( TInt aCommand ) |
|
218 { |
|
219 TBool isUsed( EFalse ); |
|
220 switch ( aCommand ) |
|
221 { |
|
222 case EESMRCmdClipboardCopy: |
|
223 { |
|
224 iRichTextViewer->CopyCurrentLinkToClipBoardL(); |
|
225 isUsed = ETrue; |
|
226 break; |
|
227 } |
|
228 case EESMRCmdDisableWaypointIcon: |
|
229 case EESMRCmdEnableWaypointIcon: |
|
230 { |
|
231 SetWaypointIconL( aCommand == EESMRCmdEnableWaypointIcon ); |
|
232 isUsed = ETrue; |
|
233 break; |
|
234 } |
|
235 case EAknSoftkeySelect: |
|
236 case EAknCmdOpen: |
|
237 { |
|
238 if ( !iRichTextViewer->LinkSelectedL() ) |
|
239 { |
|
240 NotifyEventL( EAknSoftkeyContextOptions ); |
|
241 } |
|
242 isUsed = ETrue; |
|
243 |
|
244 break; |
|
245 } |
|
246 default: |
|
247 { |
|
248 break; |
|
249 } |
|
250 } |
|
251 return isUsed; |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // CESMRViewerLocationField::SetOutlineFocusL() |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 void CESMRViewerLocationField::SetOutlineFocusL( TBool aFocus ) |
|
259 { |
|
260 CESMRField::SetOutlineFocusL( aFocus ); |
|
261 |
|
262 if ( aFocus ) |
|
263 { |
|
264 ChangeMiddleSoftKeyL( EAknSoftkeyContextOptions, R_QTN_MSK_OPEN ); |
|
265 } |
|
266 else |
|
267 { |
|
268 //need to tell action menu that focus has changed |
|
269 iRichTextViewer->ResetActionMenuL(); |
|
270 } |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // CESMRViewerLocationField::SetWaypointIconL |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 void CESMRViewerLocationField::SetWaypointIconL( TBool aEnabled ) |
|
278 { |
|
279 delete iWaypointIcon; |
|
280 iWaypointIcon = NULL; |
|
281 |
|
282 if ( aEnabled ) |
|
283 { |
|
284 iWaypointIcon = CMRImage::NewL( |
|
285 NMRBitmapManager::EMRBitmapLocationWaypoint, |
|
286 this, |
|
287 ETrue ); |
|
288 } |
|
289 |
|
290 // Relayout |
|
291 SizeChanged(); |
|
292 |
|
293 if ( !iOutlineFocus ) |
|
294 { |
|
295 RecordField(); |
|
296 } |
|
297 } |
|
298 |
|
299 // --------------------------------------------------------------------------- |
|
300 // CESMRViewerLocationField::CountComponentControls |
|
301 // --------------------------------------------------------------------------- |
|
302 // |
|
303 TInt CESMRViewerLocationField::CountComponentControls() const |
|
304 { |
|
305 TInt count( 0 ); |
|
306 if ( iFieldButton ) |
|
307 { |
|
308 ++count; |
|
309 } |
|
310 |
|
311 if ( iRichTextViewer ) |
|
312 { |
|
313 ++count; |
|
314 } |
|
315 |
|
316 if( iWaypointIcon ) |
|
317 { |
|
318 ++count; |
|
319 } |
|
320 return count; |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CESMRViewerLocationField::ComponentControl |
|
325 // --------------------------------------------------------------------------- |
|
326 // |
|
327 CCoeControl* CESMRViewerLocationField::ComponentControl( TInt aIndex ) const |
|
328 { |
|
329 switch ( aIndex ) |
|
330 { |
|
331 case 0: |
|
332 return iFieldButton; |
|
333 case 1: |
|
334 return iRichTextViewer; |
|
335 case 2: |
|
336 return iWaypointIcon; |
|
337 default: |
|
338 return NULL; |
|
339 } |
|
340 } |
|
341 |
|
342 // --------------------------------------------------------------------------- |
|
343 // CESMRViewerLocationField::SizeChanged |
|
344 // --------------------------------------------------------------------------- |
|
345 // |
|
346 void CESMRViewerLocationField::SizeChanged( ) |
|
347 { |
|
348 // Store iRichTextViewer original width. |
|
349 TInt richTextViewerWidth = iRichTextViewer->Size().iWidth; |
|
350 TRect rect( Rect() ); |
|
351 |
|
352 TAknLayoutRect rowLayoutRect( |
|
353 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ) ); |
|
354 TRect rowRect( rowLayoutRect.Rect() ); |
|
355 |
|
356 // Layouting field icon |
|
357 if( iFieldButton ) |
|
358 { |
|
359 TAknWindowComponentLayout iconLayout( |
|
360 NMRLayoutManager::GetWindowComponentLayout( |
|
361 NMRLayoutManager::EMRLayoutSingleRowAColumnGraphic ) ); |
|
362 AknLayoutUtils::LayoutControl( iFieldButton, rowRect, iconLayout ); |
|
363 } |
|
364 |
|
365 // Layouting waypoint icon |
|
366 if( iWaypointIcon ) |
|
367 { |
|
368 TAknWindowComponentLayout iconLayout( |
|
369 NMRLayoutManager::GetWindowComponentLayout( |
|
370 NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) ); |
|
371 AknLayoutUtils::LayoutImage( iWaypointIcon, rowRect, iconLayout ); |
|
372 } |
|
373 |
|
374 TAknLayoutText viewerLayoutText; |
|
375 |
|
376 if( iWaypointIcon ) |
|
377 { |
|
378 viewerLayoutText = NMRLayoutManager::GetLayoutText( rowRect, |
|
379 NMRLayoutManager::EMRTextLayoutSingleRowEditorText ); |
|
380 } |
|
381 else |
|
382 { |
|
383 viewerLayoutText = NMRLayoutManager::GetLayoutText( rowRect, |
|
384 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
385 } |
|
386 |
|
387 // Layouting viewer field |
|
388 TRect viewerRect( viewerLayoutText.TextRect() ); |
|
389 |
|
390 // Resize height according to actual height required by edwin. |
|
391 viewerRect.Resize( 0, iSize.iHeight - viewerRect.Height() ); |
|
392 iRichTextViewer->SetRect( viewerRect ); |
|
393 |
|
394 // Layouting focus |
|
395 TRect bgRect( viewerRect ); |
|
396 |
|
397 // Move focus rect so that it's relative to field's position. |
|
398 bgRect.Move( -Position() ); |
|
399 SetFocusRect( bgRect ); |
|
400 |
|
401 // Failures are ignored. |
|
402 TRAP_IGNORE( |
|
403 // Try setting font |
|
404 iRichTextViewer->SetFontL( viewerLayoutText.Font() ); |
|
405 // Try applying changes |
|
406 iRichTextViewer->ApplyLayoutChangesL(); |
|
407 ); |
|
408 |
|
409 if ( iRichTextViewer->Size().iWidth != richTextViewerWidth ) |
|
410 { |
|
411 // Most of this case is screen orientation, in this case we need to |
|
412 // Record the index of focusing link, after updating link array, then |
|
413 // reset the focusing to original one. |
|
414 TInt focusingIndex = iRichTextViewer->GetFocusLink(); |
|
415 if ( KErrNotFound != focusingIndex ) |
|
416 { |
|
417 iRichTextViewer->SetFocusLink( focusingIndex ); |
|
418 //wake up current contact menu selection by calling this |
|
419 iRichTextViewer->FocusChanged(ENoDrawNow); |
|
420 } |
|
421 } |
|
422 } |
|
423 |
|
424 // --------------------------------------------------------------------------- |
|
425 // CESMRViewerLocationField::HandleLongtapEventL |
|
426 // --------------------------------------------------------------------------- |
|
427 // |
|
428 void CESMRViewerLocationField::HandleLongtapEventL( |
|
429 const TPoint& aPosition ) |
|
430 { |
|
431 if ( !iRichTextViewer->LinkSelectedL() ) |
|
432 { |
|
433 HandleTapEventL( aPosition ); |
|
434 } |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------------------------- |
|
438 // CESMRViewerLocationField::DynInitMenuPaneL |
|
439 // --------------------------------------------------------------------------- |
|
440 // |
|
441 void CESMRViewerLocationField::DynInitMenuPaneL( |
|
442 TInt aResourceId, |
|
443 CEikMenuPane* aMenuPane ) |
|
444 { |
|
445 if ( aResourceId == R_MR_VIEWER_MENU || |
|
446 aResourceId == R_MR_VIEWER_LOCATION_MENU ) |
|
447 { |
|
448 TBool showOnMap( EFalse ); |
|
449 |
|
450 if ( iWaypointIcon ) |
|
451 { |
|
452 showOnMap = ETrue; |
|
453 } |
|
454 |
|
455 TBool searchFromMap = !showOnMap; |
|
456 |
|
457 if ( !iFeatures->FeatureSupported( |
|
458 CESMRFeatureSettings::EESMRUIMnFwIntegration ) ) |
|
459 { |
|
460 // Maps disabled |
|
461 showOnMap = EFalse; |
|
462 searchFromMap = EFalse; |
|
463 } |
|
464 |
|
465 aMenuPane->SetItemDimmed( EESMRCmdShowOnMap, !showOnMap ); |
|
466 aMenuPane->SetItemDimmed( EESMRCmdSearchFromMap, !searchFromMap ); |
|
467 } |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------------------------- |
|
471 // CESMRViewerLocationField::LockL |
|
472 // --------------------------------------------------------------------------- |
|
473 // |
|
474 void CESMRViewerLocationField::LockL() |
|
475 { |
|
476 FUNC_LOG; |
|
477 if( IsLocked() ) |
|
478 { |
|
479 return; |
|
480 } |
|
481 |
|
482 CESMRField::LockL(); |
|
483 |
|
484 delete iWaypointIcon; |
|
485 iWaypointIcon = NULL; |
|
486 iWaypointIcon = CMRImage::NewL( |
|
487 NMRBitmapManager::EMRBitmapLockField, |
|
488 this, |
|
489 ETrue ); |
|
490 |
|
491 iWaypointIcon->SetObserver( this ); |
|
492 } |
|
493 |
|
494 // --------------------------------------------------------------------------- |
|
495 // CESMRViewerLocationField::GetCursorLineVerticalPos |
|
496 // --------------------------------------------------------------------------- |
|
497 // |
|
498 void CESMRViewerLocationField::GetCursorLineVerticalPos( |
|
499 TInt& aUpper, TInt& aLower) |
|
500 { |
|
501 aLower = iRichTextViewer->CurrentLineNumber() * iRichTextViewer->RowHeight(); |
|
502 aUpper = aLower - iRichTextViewer->RowHeight(); |
|
503 } |
|
504 |
|
505 // --------------------------------------------------------------------------- |
|
506 // CESMRViewerLocationField::HandleControlEventL |
|
507 // --------------------------------------------------------------------------- |
|
508 // |
|
509 |
|
510 void CESMRViewerLocationField::HandleControlEventL( |
|
511 CCoeControl* aControl,TCoeEvent aEventType ) |
|
512 { |
|
513 if ( aControl == iFieldButton ) |
|
514 { |
|
515 if( iLocked ) |
|
516 { |
|
517 //if field is locked, iFieldButton can't be used. |
|
518 return; |
|
519 } |
|
520 switch ( aEventType ) |
|
521 { |
|
522 // Button state changed (button was pressed) |
|
523 case EEventRequestFocus: |
|
524 { |
|
525 // Clear viewer selection |
|
526 iRichTextViewer->ClearSelectionL(); |
|
527 iRichTextViewer->DrawDeferred(); |
|
528 iRichTextViewer->ResetActionMenuL(); |
|
529 |
|
530 // Show context menu |
|
531 HandleTactileFeedbackL(); |
|
532 NotifyEventL( EAknSoftkeyContextOptions ); |
|
533 } |
|
534 |
|
535 default: |
|
536 break; |
|
537 } |
|
538 } |
|
539 } |
|
540 |
|
541 // --------------------------------------------------------------------------- |
|
542 // CESMRViewerLocationField::HandleSingletapEventL |
|
543 // --------------------------------------------------------------------------- |
|
544 // |
|
545 TBool CESMRViewerLocationField::HandleSingletapEventL( const TPoint& aPosition ) |
|
546 { |
|
547 return HandleTapEventL( aPosition ); |
|
548 } |
|
549 |
|
550 // --------------------------------------------------------------------------- |
|
551 // CESMRViewerLocationField::HandletapEventL |
|
552 // --------------------------------------------------------------------------- |
|
553 // |
|
554 TBool CESMRViewerLocationField::HandleTapEventL( const TPoint& aPosition ) |
|
555 { |
|
556 TBool ret( EFalse ); |
|
557 |
|
558 // Button events are handled by HandleControlEvent. |
|
559 // Tap on link is handled by rich text viewer. |
|
560 if ( !iFieldButton->Rect().Contains( aPosition ) |
|
561 && !iRichTextViewer->GetSelectedLink() ) |
|
562 { |
|
563 HandleTactileFeedbackL(); |
|
564 |
|
565 NotifyEventL( EAknSoftkeyContextOptions ); |
|
566 |
|
567 // Event is always consumed, if we come inside this if-clause |
|
568 ret = ETrue; |
|
569 } |
|
570 |
|
571 return ret; |
|
572 } |
|
573 |
|
574 // --------------------------------------------------------------------------- |
|
575 // CESMRViewerLocationField::SupportsLongTapFunctionalityL |
|
576 // --------------------------------------------------------------------------- |
|
577 // |
|
578 TBool CESMRViewerLocationField::SupportsLongTapFunctionalityL( |
|
579 const TPointerEvent &aPointerEvent ) |
|
580 { |
|
581 FUNC_LOG; |
|
582 TBool ret( EFalse ); |
|
583 |
|
584 if ( iRichTextViewer->Rect().Contains( aPointerEvent.iPosition ) ) |
|
585 { |
|
586 if( iRichTextViewer->PointerEventOccuresOnALinkL( aPointerEvent ) ) |
|
587 { |
|
588 ret = ETrue; |
|
589 } |
|
590 } |
|
591 |
|
592 return ret; |
|
593 } |
|
594 |
|
595 //EOF |