|
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: Meeting request location field |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <calentry.h> |
|
19 #include <esmrgui.rsg> |
|
20 #include <data_caging_path_literals.hrh> |
|
21 #include <AknLayout2ScalableDef.h> |
|
22 |
|
23 #include "cesmrviewerlocationfield.h" |
|
24 #include "cesmrrichtextviewer.h" |
|
25 #include "mesmrlistobserver.h" |
|
26 #include "cesmrfeaturesettings.h" |
|
27 #include "nmrlayoutmanager.h" |
|
28 #include "cmrimage.h" |
|
29 |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // CESMRViewerLocationField::NewL |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CESMRViewerLocationField* CESMRViewerLocationField::NewL( ) |
|
38 { |
|
39 CESMRViewerLocationField* self = new (ELeave) CESMRViewerLocationField; |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL( ); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CESMRViewerLocationField::CESMRViewerLocationField |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CESMRViewerLocationField::~CESMRViewerLocationField() |
|
51 { |
|
52 iObserver = NULL; |
|
53 delete iFieldIcon; |
|
54 delete iRichTextViewer; |
|
55 delete iFeatures; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CESMRViewerLocationField::MinimumSize |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 TSize CESMRViewerLocationField::MinimumSize() |
|
63 { |
|
64 // Let's calculate the required rect of the iRichTextViewer. |
|
65 // We will not use directly the iRichTextViewer height, because it might |
|
66 // not exist, or the height of the viewer might still be incorrect |
|
67 TRect richTextViewerRect = RichTextViewerRect(); |
|
68 |
|
69 // We will use as minimum size the parents width |
|
70 // but the calculated iRichTextViewers height |
|
71 return TSize( Parent()->Size().iWidth, richTextViewerRect.Height() ); |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CESMRViewerLocationField::InitializeL |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CESMRViewerLocationField::InitializeL() |
|
80 { |
|
81 // Setting Font for the rich text viewer |
|
82 TAknLayoutText text = NMRLayoutManager::GetLayoutText( |
|
83 Rect(), |
|
84 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
85 |
|
86 iRichTextViewer->SetFontL( text.Font(), iLayout ); |
|
87 |
|
88 // This is called so that theme changes will apply when changing theme "on the fly" |
|
89 if ( IsFocused() ) |
|
90 { |
|
91 iRichTextViewer->FocusChanged( EDrawNow ); |
|
92 } |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CESMRViewerLocationField::InternalizeL() |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CESMRViewerLocationField::InternalizeL( MESMRCalEntry& aEntry ) |
|
100 { |
|
101 TPtrC text = aEntry.Entry().LocationL( ); |
|
102 |
|
103 // Hide this field if location is not set |
|
104 if( text.Length() == 0 ) |
|
105 { |
|
106 iObserver->RemoveControl( FieldId() ); |
|
107 } |
|
108 else |
|
109 { |
|
110 iRichTextViewer->SetTextL( &text, ETrue ); |
|
111 // After setting the text, the viewer line count is known |
|
112 iLineCount = iRichTextViewer->LineCount(); |
|
113 } |
|
114 iDisableRedraw = ETrue; |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CESMRViewerLocationField::OfferKeyEventL() |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 |
|
122 TKeyResponse CESMRViewerLocationField::OfferKeyEventL(const TKeyEvent& aEvent, |
|
123 TEventCode aType ) |
|
124 { |
|
125 return iRichTextViewer->OfferKeyEventL( aEvent, aType ); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // CESMRViewerLocationField::HandleEdwinSizeEventL() |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 TBool CESMRViewerLocationField::HandleEdwinSizeEventL( CEikEdwin* aEdwin, |
|
133 TEdwinSizeEvent /*aType*/, TSize aSize ) |
|
134 { |
|
135 TBool reDraw( EFalse ); |
|
136 |
|
137 // Let's save the required size for the iRichTextViewer |
|
138 iSize = aSize; |
|
139 |
|
140 if ( iObserver && aEdwin == iRichTextViewer ) |
|
141 { |
|
142 iObserver->ControlSizeChanged( this ); |
|
143 reDraw = ETrue; |
|
144 } |
|
145 |
|
146 return reDraw; |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CESMRViewerLocationField::CESMRViewerLocationField() |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 CESMRViewerLocationField::CESMRViewerLocationField() |
|
154 { |
|
155 SetFieldId( EESMRFieldLocation ); |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CESMRViewerLocationField::ConstructL() |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CESMRViewerLocationField::ConstructL( ) |
|
163 { |
|
164 SetFocusType( EESMRHighlightFocus ); |
|
165 |
|
166 iFieldIcon = CMRImage::NewL( KAknsIIDQgnMeetReqIndiLocation ); |
|
167 iFieldIcon->SetParent( this ); |
|
168 |
|
169 iRichTextViewer = CESMRRichTextViewer::NewL( this ); |
|
170 iRichTextViewer->SetEdwinSizeObserver( this ); |
|
171 iRichTextViewer->SetParent( this ); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // CESMRViewerLocationField::ListObserverSet |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void CESMRViewerLocationField::ListObserverSet() |
|
179 { |
|
180 iRichTextViewer->SetListObserver( iObserver ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CESMRViewerLocationField::ExecuteGenericCommandL() |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CESMRViewerLocationField::ExecuteGenericCommandL( TInt aCommand ) |
|
188 { |
|
189 switch ( aCommand ) |
|
190 { |
|
191 case EESMRCmdClipboardCopy: |
|
192 { |
|
193 iRichTextViewer->CopyCurrentLinkToClipBoardL(); |
|
194 break; |
|
195 } |
|
196 case EESMRCmdDisableWaypointIcon: |
|
197 case EESMRCmdEnableWaypointIcon: |
|
198 { |
|
199 SetWaypointIconL( aCommand == EESMRCmdEnableWaypointIcon ); |
|
200 break; |
|
201 } |
|
202 case EAknSoftkeySelect: |
|
203 { |
|
204 iRichTextViewer->LinkSelectedL(); |
|
205 break; |
|
206 } |
|
207 default: |
|
208 { |
|
209 break; |
|
210 } |
|
211 } |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // CESMRViewerLocationField::SetOutlineFocusL() |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CESMRViewerLocationField::SetOutlineFocusL( TBool aFocus ) |
|
219 { |
|
220 CESMRField::SetOutlineFocusL( aFocus ); |
|
221 |
|
222 iRichTextViewer->SetFocus( aFocus ); |
|
223 |
|
224 if ( FeaturesL().FeatureSupported( |
|
225 CESMRFeatureSettings::EESMRUILocationFeatures ) ) |
|
226 { |
|
227 |
|
228 if ( aFocus ) |
|
229 { |
|
230 //Store MSK function before changing it |
|
231 CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current(); |
|
232 if ( cba->PositionById( EESMRCmdEdit ) == |
|
233 CEikButtonGroupContainer::EMiddleSoftkeyPosition ) |
|
234 { |
|
235 iMskCommandId = EESMRCmdEdit; |
|
236 |
|
237 } |
|
238 else if ( cba->PositionById( EESMRCmdEditLocal ) == |
|
239 CEikButtonGroupContainer::EMiddleSoftkeyPosition ) |
|
240 { |
|
241 iMskCommandId = EESMRCmdEditLocal; |
|
242 } |
|
243 else if ( cba->PositionById( EESMRCmdCalEntryUIEdit ) == |
|
244 CEikButtonGroupContainer::EMiddleSoftkeyPosition ) |
|
245 { |
|
246 iMskCommandId = EESMRCmdCalEntryUIEdit; |
|
247 } |
|
248 |
|
249 ChangeMiddleSoftKeyL( EAknSoftkeyContextOptions, R_QTN_MSK_OPEN ); |
|
250 } |
|
251 else |
|
252 { |
|
253 switch ( iMskCommandId ) |
|
254 { |
|
255 case EESMRCmdEdit: |
|
256 case EESMRCmdEditLocal: |
|
257 case EESMRCmdCalEntryUIEdit: |
|
258 { |
|
259 ChangeMiddleSoftKeyL( iMskCommandId, R_QTN_MSK_EDIT ); |
|
260 break; |
|
261 } |
|
262 default: |
|
263 { |
|
264 CEikButtonGroupContainer* cba = |
|
265 CEikButtonGroupContainer::Current(); |
|
266 cba->SetCommandL( |
|
267 CEikButtonGroupContainer::EMiddleSoftkeyPosition, |
|
268 R_MR_SELECT_SOFTKEY ); |
|
269 cba->DrawNow(); |
|
270 break; |
|
271 } |
|
272 } |
|
273 |
|
274 //need to tell action menu that focus has changed |
|
275 iRichTextViewer->ResetActionMenuL(); |
|
276 } |
|
277 } |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // CESMRViewerLocationField::FeaturesL() |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 CESMRFeatureSettings& CESMRViewerLocationField::FeaturesL() |
|
285 { |
|
286 if ( !iFeatures ) |
|
287 { |
|
288 iFeatures = CESMRFeatureSettings::NewL(); |
|
289 } |
|
290 return *iFeatures; |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // CESMRCheckbox::SetWaypointIconL |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 void CESMRViewerLocationField::SetWaypointIconL( TBool /*aEnabled*/ ) |
|
298 { |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // CESMRViewerLocationField::CountComponentControls |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 TInt CESMRViewerLocationField::CountComponentControls() const |
|
306 { |
|
307 TInt count( 0 ); |
|
308 if ( iFieldIcon ) |
|
309 { |
|
310 ++count; |
|
311 } |
|
312 |
|
313 if ( iRichTextViewer ) |
|
314 { |
|
315 ++count; |
|
316 } |
|
317 return count; |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CESMRViewerLocationField::ComponentControl |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 CCoeControl* CESMRViewerLocationField::ComponentControl( TInt aIndex ) const |
|
325 { |
|
326 switch ( aIndex ) |
|
327 { |
|
328 case 0: |
|
329 return iFieldIcon; |
|
330 case 1: |
|
331 return iRichTextViewer; |
|
332 default: |
|
333 return NULL; |
|
334 } |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------------------------- |
|
338 // CESMRViewerLocationField::SizeChanged |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 void CESMRViewerLocationField::SizeChanged( ) |
|
342 { |
|
343 TRect rect = Rect(); |
|
344 |
|
345 // LAYOUTING FIELD ICON |
|
346 if( iFieldIcon ) |
|
347 { |
|
348 TAknWindowComponentLayout iconLayout = |
|
349 NMRLayoutManager::GetWindowComponentLayout( NMRLayoutManager::EMRLayoutTextEditorIcon ); |
|
350 AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout ); |
|
351 } |
|
352 |
|
353 // LAYOUTING FIELD BACKGROUND |
|
354 TAknLayoutRect bgLayoutRect = |
|
355 NMRLayoutManager::GetLayoutRect( rect, NMRLayoutManager::EMRLayoutTextEditorBg ); |
|
356 TRect bgRect( bgLayoutRect.Rect() ); |
|
357 // Move focus rect so that it's relative to field's position |
|
358 bgRect.Move( -Position() ); |
|
359 SetFocusRect( bgRect ); |
|
360 |
|
361 // LAYOUTING FIELD TEXT VIEWER |
|
362 if( iRichTextViewer ) |
|
363 { |
|
364 iRichTextViewer->SetRect( RichTextViewerRect() ); |
|
365 } |
|
366 } |
|
367 |
|
368 // --------------------------------------------------------------------------- |
|
369 // CESMRViewerLocationField::SetContainerWindowL |
|
370 // --------------------------------------------------------------------------- |
|
371 // |
|
372 void CESMRViewerLocationField::SetContainerWindowL( const CCoeControl& aContainer ) |
|
373 { |
|
374 CCoeControl::SetContainerWindowL( aContainer ); |
|
375 iRichTextViewer->SetContainerWindowL( aContainer ); |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------------------------- |
|
379 // CESMRViewerLocationField::RichTextViewerRect |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 TRect CESMRViewerLocationField::RichTextViewerRect() |
|
383 { |
|
384 TRect rect = Rect(); |
|
385 |
|
386 TAknTextComponentLayout edwinLayout = NMRLayoutManager::GetTextComponentLayout( |
|
387 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
388 |
|
389 // Text layout rect for one line viewer |
|
390 TAknLayoutText textLayout; |
|
391 textLayout.LayoutText( rect, edwinLayout ); |
|
392 TRect textLayoutRect = textLayout.TextRect(); |
|
393 |
|
394 TRect viewerRect = textLayoutRect; |
|
395 |
|
396 // If iRichTextViewer has lines and iSize has been set, |
|
397 // we will use iSize.iHeight as the viewers height |
|
398 if( iLineCount > 0 && iSize.iHeight > 0 ) |
|
399 { |
|
400 viewerRect.SetHeight( iSize.iHeight ); |
|
401 } |
|
402 // Otherwise we will use one row height as the height of the |
|
403 // iRichTextViewer |
|
404 else |
|
405 { |
|
406 TAknLayoutRect rowLayoutRect = |
|
407 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ); |
|
408 viewerRect.SetHeight( rowLayoutRect.Rect().Height() ); |
|
409 } |
|
410 |
|
411 return viewerRect; |
|
412 } |
|
413 |
|
414 //EOF |