|
1 /* |
|
2 * Copyright (c) 2007-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 Description (summary) field implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <calentry.h> |
|
21 #include <StringLoader.h> |
|
22 #include <esmrgui.rsg> |
|
23 #include <AknUtils.h> |
|
24 #include <AknsDrawUtils.h> |
|
25 #include <AknsFrameBackgroundControlContext.h> |
|
26 //<cmail> |
|
27 #include "cesmrurlparserplugin.h" |
|
28 //</cmail> |
|
29 |
|
30 #include "cesmrdescriptionfield.h" |
|
31 #include "mesmrlistobserver.h" |
|
32 #include "cesmreditor.h" |
|
33 #include "cesmrrichtextlink.h" |
|
34 #include "cesmrlayoutmgr.h" |
|
35 #include "esmrfieldbuilderdef.h" |
|
36 #include "cesmrfeaturesettings.h" |
|
37 #include "cesmrglobalnote.h" |
|
38 |
|
39 namespace{ // codescanner::namespace |
|
40 const TInt KFieldInnerShrink(3); |
|
41 }//namespace |
|
42 |
|
43 // ======== MEMBER FUNCTIONS ======== |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CESMRDescriptionField::NewL |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CESMRDescriptionField* CESMRDescriptionField::NewL( ) |
|
50 { |
|
51 FUNC_LOG; |
|
52 CESMRDescriptionField* self = new (ELeave) CESMRDescriptionField; |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CESMRDescriptionField::~CESMRDescriptionField |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CESMRDescriptionField::~CESMRDescriptionField( ) |
|
64 { |
|
65 FUNC_LOG; |
|
66 delete iFrameBgContext; |
|
67 |
|
68 delete iLocationLink; |
|
69 |
|
70 delete iFeatures; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CESMRDescriptionField::InitializeL |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CESMRDescriptionField::InitializeL() |
|
78 { |
|
79 FUNC_LOG; |
|
80 iDescription->SetFontL( iLayout->Font (iCoeEnv, iFieldId ), iLayout ); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CESMRDescriptionField::InternalizeL |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CESMRDescriptionField::InternalizeL( MESMRCalEntry& aEntry ) |
|
88 { |
|
89 FUNC_LOG; |
|
90 CCalEntry& entry = aEntry.Entry ( ); |
|
91 HBufC* summary = entry.DescriptionL().AllocLC ( ); |
|
92 |
|
93 // externalize is done only when there is text and its NOT the default one. |
|
94 if ( summary->Length ( )> 0 && iDescription->DefaultText().Compare (*summary )!= 0 ) |
|
95 { |
|
96 iDescription->ClearSelectionAndSetTextL ( *summary ); |
|
97 if ( FeaturesL().FeatureSupported( |
|
98 CESMRFeatureSettings::EESMRUIMnFwIntegration ) ) |
|
99 { |
|
100 StoreLinkL( aEntry ); |
|
101 } |
|
102 } |
|
103 |
|
104 CleanupStack::PopAndDestroy ( summary ); |
|
105 |
|
106 // this is needed to be re-called here, otherwise the CEikEdwin |
|
107 // does not get correctly instantiated with default text |
|
108 iDescription->FocusChanged(EDrawNow); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CESMRDescriptionField::ExternalizeL |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CESMRDescriptionField::ExternalizeL( MESMRCalEntry& aEntry ) |
|
116 { |
|
117 FUNC_LOG; |
|
118 HBufC* buf = iDescription->GetTextInHBufL(); |
|
119 |
|
120 if( buf ) |
|
121 { |
|
122 CleanupStack::PushL( buf ); |
|
123 |
|
124 if( iDescription->DefaultText().Compare( *buf ) != 0 ) |
|
125 { |
|
126 CCalEntry& entry = aEntry.Entry(); |
|
127 |
|
128 HBufC* newBuf = AddLinkToTextL( *buf ); |
|
129 if( newBuf ) |
|
130 { |
|
131 CleanupStack::PopAndDestroy( buf ); |
|
132 buf = newBuf; |
|
133 CleanupStack::PushL( buf ); |
|
134 } |
|
135 entry.SetDescriptionL( *buf ); |
|
136 } |
|
137 CleanupStack::PopAndDestroy( buf ); |
|
138 } |
|
139 else if( iLocationLink ) |
|
140 { |
|
141 CCalEntry& entry = aEntry.Entry(); |
|
142 entry.SetDescriptionL( iLocationLink->Value() ); |
|
143 } |
|
144 else |
|
145 { |
|
146 CCalEntry& entry = aEntry.Entry(); |
|
147 entry.SetDescriptionL( KNullDesC ); |
|
148 } |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // CESMRDescriptionField::SetOutlineFocusL |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 void CESMRDescriptionField::SetOutlineFocusL( TBool aFocus ) |
|
156 { |
|
157 FUNC_LOG; |
|
158 CESMRField::SetOutlineFocusL ( aFocus ); |
|
159 if ( aFocus ) |
|
160 { |
|
161 ChangeMiddleSoftKeyL(EESMRCmdSaveMR,R_QTN_MSK_SAVE); |
|
162 } |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CESMRDescriptionField::ExpandedHeight |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 TInt CESMRDescriptionField::ExpandedHeight( ) const |
|
170 { |
|
171 FUNC_LOG; |
|
172 return iSize.iHeight; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CESMRDescriptionField::OfferKeyEventL |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 TKeyResponse CESMRDescriptionField::OfferKeyEventL(const TKeyEvent& aEvent, |
|
180 TEventCode aType ) |
|
181 { |
|
182 FUNC_LOG; |
|
183 return iDescription->OfferKeyEventL( aEvent, aType ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CESMRDescriptionField::HandleEdwinSizeEventL |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 TBool CESMRDescriptionField::HandleEdwinSizeEventL(CEikEdwin* /*aEdwin*/, |
|
191 TEdwinSizeEvent /*aType*/, TSize aSize ) |
|
192 { |
|
193 FUNC_LOG; |
|
194 iSize = aSize; |
|
195 iSize.iHeight -= KEditorDifference; |
|
196 |
|
197 if (iLayout->CurrentFontZoom() == EAknUiZoomSmall || |
|
198 iLayout->CurrentFontZoom() == EAknUiZoomVerySmall) |
|
199 { |
|
200 iSize.iHeight -= KEditorDifference; |
|
201 } |
|
202 |
|
203 if ( iObserver ) |
|
204 { |
|
205 iObserver->ControlSizeChanged ( this ); |
|
206 } |
|
207 |
|
208 if( iFrameBgContext ) |
|
209 { |
|
210 TRect visibleRect = CalculateVisibleRect( iDescription->Rect() ); |
|
211 iFrameBgContext->SetFrameRects( visibleRect, visibleRect ); |
|
212 } |
|
213 |
|
214 return ETrue; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CESMRDescriptionField::HandleEdwinEventL |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CESMRDescriptionField::HandleEdwinEventL(CEikEdwin* aEdwin,TEdwinEvent aEventType) |
|
222 { |
|
223 FUNC_LOG; |
|
224 if ( aEdwin == iDescription |
|
225 && aEventType == EEventTextUpdate ) |
|
226 { |
|
227 HBufC* text = iDescription->GetTextInHBufL(); |
|
228 if ( text ) |
|
229 { |
|
230 CleanupStack::PushL( text ); |
|
231 TInt textLength( text->Length() ); |
|
232 if ( iDescription->GetLimitLength() <= textLength ) |
|
233 { |
|
234 NotifyEventAsyncL( EESMRCmdSizeExceeded ); |
|
235 } |
|
236 CleanupStack::PopAndDestroy( text ); |
|
237 } |
|
238 } |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // CESMRDescriptionField::CESMRDescriptionField |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 CESMRDescriptionField::CESMRDescriptionField() : |
|
246 iSize( TSize( 0, 0 )) |
|
247 { |
|
248 FUNC_LOG; |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CESMRDescriptionField::ActivateL |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 void CESMRDescriptionField::ActivateL() |
|
256 { |
|
257 FUNC_LOG; |
|
258 CCoeControl::ActivateL(); |
|
259 TRect rect(TPoint(iDescription->Position()), iDescription->Size()); |
|
260 TRect inner(rect); |
|
261 inner.Shrink( KFieldInnerShrink, KFieldInnerShrink ); |
|
262 TRect outer(rect); |
|
263 |
|
264 delete iFrameBgContext; |
|
265 iFrameBgContext = NULL; |
|
266 iFrameBgContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrInput, |
|
267 outer, |
|
268 inner, |
|
269 EFalse ); |
|
270 |
|
271 iFrameBgContext->SetParentContext( iBackground ); |
|
272 iDescription->SetSkinBackgroundControlContextL( iFrameBgContext ); |
|
273 } |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // CESMRDescriptionField::PositionChanged() |
|
277 // --------------------------------------------------------------------------- |
|
278 // |
|
279 void CESMRDescriptionField::PositionChanged() |
|
280 { |
|
281 FUNC_LOG; |
|
282 CCoeControl::PositionChanged(); |
|
283 if( iFrameBgContext ) |
|
284 { |
|
285 TRect visibleRect = CalculateVisibleRect( iDescription->Rect() ); |
|
286 iFrameBgContext->SetFrameRects( visibleRect, visibleRect ); |
|
287 } |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // CESMRDescriptionField::ConstructL |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 void CESMRDescriptionField::ConstructL() |
|
295 { |
|
296 FUNC_LOG; |
|
297 SetFieldId( EESMRFieldDescription ); |
|
298 SetExpandable( ); |
|
299 iDescription = CESMREditor::NewL( this, 1, KTextLimit, |
|
300 CEikEdwin::EResizable | |
|
301 CEikEdwin::EAvkonEditor ); |
|
302 iDescription->SetEdwinSizeObserver( this ); |
|
303 iDescription->SetEdwinObserver( this ); |
|
304 |
|
305 HBufC* buf = StringLoader::LoadLC( R_QTN_MEET_REQ_DETAILS_FIELD ); |
|
306 iDescription->SetDefaultTextL( buf ); // ownership transferred |
|
307 CleanupStack::Pop( buf ); |
|
308 |
|
309 iBackground = AknsDrawUtils::ControlContext( this ); |
|
310 |
|
311 CESMRField::ConstructL( iDescription ); |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // CESMRDescriptionField::GetMinimumVisibleVerticalArea |
|
316 // --------------------------------------------------------------------------- |
|
317 // |
|
318 void CESMRDescriptionField::GetMinimumVisibleVerticalArea(TInt& aUpper, TInt& aLower) |
|
319 { |
|
320 FUNC_LOG; |
|
321 aLower = iDescription->CurrentLineNumber() * iDescription->RowHeight(); |
|
322 aUpper = aLower - iDescription->RowHeight(); |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CESMRDescriptionField::ListObserverSet |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 void CESMRDescriptionField::ListObserverSet() |
|
330 { |
|
331 FUNC_LOG; |
|
332 iDescription->SetListObserver( iObserver ); |
|
333 } |
|
334 |
|
335 // --------------------------------------------------------------------------- |
|
336 // CESMRDescriptionField::StoreLinkL |
|
337 // --------------------------------------------------------------------------- |
|
338 // |
|
339 void CESMRDescriptionField::StoreLinkL( MESMRCalEntry& aEntry ) |
|
340 { |
|
341 FUNC_LOG; |
|
342 TInt command( EESMRCmdDisableWaypointIcon ); |
|
343 CESMRUrlParserPlugin* urlParser = CESMRUrlParserPlugin::NewL(); |
|
344 CleanupStack::PushL( urlParser ); |
|
345 TPtrC urlPointer; |
|
346 TInt position; |
|
347 position = urlParser->FindLocationUrl( aEntry.Entry().DescriptionL(), |
|
348 urlPointer ); |
|
349 CleanupStack::PopAndDestroy( urlParser ); |
|
350 if ( position >= KErrNone ) |
|
351 { |
|
352 command = EESMRCmdEnableWaypointIcon; |
|
353 HBufC* description = |
|
354 HBufC::NewL( aEntry.Entry().DescriptionL().Length() ); |
|
355 CleanupStack::PushL( description ); |
|
356 TPtr descriptionPointer( description->Des() ); |
|
357 descriptionPointer.Append( aEntry.Entry().DescriptionL() ); |
|
358 descriptionPointer.Delete( position, urlPointer.Length() ); |
|
359 descriptionPointer.TrimLeft(); |
|
360 if ( description->Length() != 0 ) |
|
361 { |
|
362 iDescription->ClearSelectionAndSetTextL( *description ); |
|
363 } |
|
364 else |
|
365 { |
|
366 iDescription->ClearSelectionAndSetTextL( iDescription->DefaultText() ); |
|
367 } |
|
368 CleanupStack::PopAndDestroy( description ); |
|
369 |
|
370 if ( iLocationLink ) |
|
371 { |
|
372 delete iLocationLink; |
|
373 iLocationLink = NULL; |
|
374 } |
|
375 HBufC* showOnMapBuf = |
|
376 StringLoader::LoadLC( R_MEET_REQ_LINK_SHOW_ON_MAP ); |
|
377 iLocationLink = CESMRRichTextLink::NewL( position, |
|
378 showOnMapBuf->Length(), |
|
379 urlPointer, |
|
380 CESMRRichTextLink::ETypeLocationUrl, |
|
381 CESMRRichTextLink::ETriggerKeyOk ); |
|
382 CleanupStack::PopAndDestroy( showOnMapBuf ); |
|
383 } |
|
384 |
|
385 NotifyEventL( command ); |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 // CESMRDescriptionField::AddLinkToTextL |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 HBufC* CESMRDescriptionField::AddLinkToTextL( const TDesC& aBuf ) |
|
393 { |
|
394 FUNC_LOG; |
|
395 if( iLocationLink ) |
|
396 { |
|
397 TInt newTextLen = aBuf.Length() + iLocationLink->Value().Length() + 1; |
|
398 HBufC* retBuf = HBufC::NewL( newTextLen ); |
|
399 |
|
400 retBuf->Des().Append( iLocationLink->Value() ); |
|
401 _LIT( KParagraphSeparator, "\x2029" ); // unicode paragraph separator |
|
402 // add the separator after url |
|
403 retBuf->Des().Append( KParagraphSeparator ); |
|
404 retBuf->Des().Append( aBuf ); |
|
405 |
|
406 return retBuf; |
|
407 } |
|
408 else |
|
409 { |
|
410 return NULL; |
|
411 } |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // CESMRDescriptionField::FeaturesL |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 CESMRFeatureSettings& CESMRDescriptionField::FeaturesL() |
|
419 { |
|
420 FUNC_LOG; |
|
421 if ( !iFeatures ) |
|
422 { |
|
423 iFeatures = CESMRFeatureSettings::NewL(); |
|
424 } |
|
425 |
|
426 return *iFeatures; |
|
427 } |
|
428 |
|
429 // --------------------------------------------------------------------------- |
|
430 // CESMRDescriptionField::ExecuteGenericCommandL |
|
431 // --------------------------------------------------------------------------- |
|
432 // |
|
433 void CESMRDescriptionField::ExecuteGenericCommandL( |
|
434 TInt aCommand ) |
|
435 { |
|
436 FUNC_LOG; |
|
437 if ( EESMRCmdSizeExceeded == aCommand ) |
|
438 { |
|
439 CESMRGlobalNote::ExecuteL ( |
|
440 CESMRGlobalNote::EESMRCannotDisplayMuchMore ); |
|
441 |
|
442 HBufC* text = iDescription->GetTextInHBufL(); |
|
443 CleanupDeletePushL( text ); |
|
444 if ( text ) |
|
445 { |
|
446 TInt curPos = iDescription->CursorPos(); |
|
447 if( curPos > iDescription->GetLimitLength() - 1 ) |
|
448 curPos = iDescription->GetLimitLength() - 1; |
|
449 HBufC* newText = |
|
450 text->Des().Mid( 0, iDescription->GetLimitLength() - 1 ).AllocLC(); |
|
451 |
|
452 iDescription->SetTextL ( newText ); |
|
453 CleanupStack::PopAndDestroy( newText ); |
|
454 newText = NULL; |
|
455 |
|
456 iDescription->SetCursorPosL (curPos, EFalse ); |
|
457 iDescription->HandleTextChangedL(); |
|
458 iDescription->UpdateScrollBarsL(); |
|
459 SetFocus(ETrue); |
|
460 } |
|
461 CleanupStack::PopAndDestroy( text ); |
|
462 } |
|
463 } |
|
464 |
|
465 |
|
466 // EOF |