|
1 /* |
|
2 * Copyright (c) 2007 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: Manager for selectable elements (hotspots and expand areas) |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //<cmail> removed __FS_ALFRED_SUPPORT flag |
|
20 //#include <fsconfig.h> |
|
21 //</cmail> removed __FS_ALFRED_SUPPORT flag |
|
22 // <cmail> SF |
|
23 #include "emailtrace.h" |
|
24 #include <alf/alfvisual.h> |
|
25 // </cmail> |
|
26 #include "fstextviewerselectsmanager.h" |
|
27 #include "fstextviewerselecthotspot.h" |
|
28 #include "fstextviewerselectembed.h" |
|
29 #include "fstextviewerselectline.h" |
|
30 #include "fstextviewervisualizer.h" |
|
31 #include "fstextviewervisualizersettings.h" |
|
32 #include "fstextviewervisualizerdata.h" |
|
33 #include "fstextparser.h" |
|
34 |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // NewL |
|
38 // --------------------------------------------------------------------------- |
|
39 CFsTextViewerSelectsManager* CFsTextViewerSelectsManager::NewL( |
|
40 CFsTextViewerVisualizer* aOwner ) |
|
41 { |
|
42 FUNC_LOG; |
|
43 CFsTextViewerSelectsManager* self = |
|
44 new (ELeave) CFsTextViewerSelectsManager( aOwner ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // ~CFsTextViewerSelectsManager |
|
53 // --------------------------------------------------------------------------- |
|
54 CFsTextViewerSelectsManager::~CFsTextViewerSelectsManager() |
|
55 { |
|
56 FUNC_LOG; |
|
57 iOwner = NULL; |
|
58 for ( TInt i = 0; i < iSelects.Count(); ++i ) |
|
59 { |
|
60 delete iSelects[i]; |
|
61 } |
|
62 iSelects.Close(); |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // AppendSelectVisL |
|
67 // --------------------------------------------------------------------------- |
|
68 void CFsTextViewerSelectsManager::AppendSelectVisL( TFsRangedVisual* aVisual, |
|
69 TInt aId, |
|
70 CFsTextViewerSelect::TFsTextViewerSelectType aType ) |
|
71 { |
|
72 FUNC_LOG; |
|
73 TBool newNeeded = ETrue; |
|
74 for ( TInt i = 0; i < iSelects.Count(); ++i ) |
|
75 { |
|
76 if ( iSelects[i]->GetId() == aId |
|
77 && iSelects[i]->GetType() == aType ) |
|
78 { |
|
79 iSelects[i]->AppendVisualL( aVisual ); |
|
80 newNeeded = EFalse; |
|
81 } |
|
82 } |
|
83 |
|
84 if ( newNeeded ) |
|
85 { |
|
86 CFsTextViewerSelect* select = NULL; |
|
87 switch ( aType ) |
|
88 { |
|
89 case CFsTextViewerSelect::EFsHotspotType: |
|
90 { |
|
91 select = CFsTextViewerSelectHotspot::NewL( this ); |
|
92 break; |
|
93 } |
|
94 case CFsTextViewerSelect::EFsEmbedType: |
|
95 { |
|
96 select = CFsTextViewerSelectEmbed::NewL( this ); |
|
97 break; |
|
98 } |
|
99 case CFsTextViewerSelect::EFsLineType: |
|
100 { |
|
101 select = CFsTextViewerSelectLine::NewL( this ); |
|
102 break; |
|
103 } |
|
104 default: |
|
105 { |
|
106 break; |
|
107 } |
|
108 |
|
109 } |
|
110 select->SetId( aId ); |
|
111 select->AppendVisualL( aVisual ); |
|
112 iSelects.AppendL( select ); |
|
113 } |
|
114 else |
|
115 { |
|
116 } |
|
117 |
|
118 TLinearOrder<CFsTextViewerSelect> order( Compare ); |
|
119 iSelects.Sort( order ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // Visualizer |
|
124 // --------------------------------------------------------------------------- |
|
125 CFsTextViewerVisualizer* CFsTextViewerSelectsManager::Visualizer() |
|
126 { |
|
127 FUNC_LOG; |
|
128 return iOwner; |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // MoveNext |
|
133 // --------------------------------------------------------------------------- |
|
134 TBool CFsTextViewerSelectsManager::MoveNextL( TBool& aChanged ) |
|
135 { |
|
136 FUNC_LOG; |
|
137 TBool retVal = EFalse; |
|
138 |
|
139 if ( iCurrent >= 0 && iCurrent < iSelects.Count() ) |
|
140 { |
|
141 iSelects[iCurrent]->DeselectL(); |
|
142 } |
|
143 |
|
144 if ( iCurrent < 0 && iSelects.Count() > 0 ) |
|
145 { |
|
146 iCurrent = 0; |
|
147 if ( iSelects[0]->IsVisible() ) |
|
148 { |
|
149 retVal = ETrue; |
|
150 } |
|
151 } |
|
152 else if ( iSelects.Count() > 0 ) |
|
153 { |
|
154 for ( TInt i = iCurrent + 1; i < iSelects.Count(); ++i ) |
|
155 { |
|
156 if ( iSelects[i]->IsVisible() && !retVal ) |
|
157 { |
|
158 iCurrent = i; |
|
159 retVal = ETrue; |
|
160 } |
|
161 } |
|
162 } |
|
163 |
|
164 if ( !retVal && iCurrent >= 0 && iCurrent < iSelects.Count() && !iSelects[iCurrent]->IsVisible() ) |
|
165 { |
|
166 for ( TInt i = 0; i < iCurrent; ++i ) |
|
167 { |
|
168 if ( iSelects[i]->IsVisible() && !retVal ) |
|
169 { |
|
170 iCurrent = i; |
|
171 retVal = ETrue; |
|
172 } |
|
173 } |
|
174 } |
|
175 |
|
176 if ( iCurrent >= 0 && iCurrent < iSelects.Count() && iSelects[iCurrent]->IsVisible() ) |
|
177 { |
|
178 iSelects[iCurrent]->SelectL(); |
|
179 } |
|
180 |
|
181 aChanged = retVal; |
|
182 if ( iCurrent >= 0 |
|
183 && iCurrent < iSelects.Count() |
|
184 && iSelects[iCurrent]->GetStartLine() >= iOwner->Navigator()->GetFirstVisible()->iLineNumber + 4 |
|
185 && aChanged ) |
|
186 { |
|
187 retVal = EFalse; |
|
188 } |
|
189 else |
|
190 { |
|
191 |
|
192 } |
|
193 |
|
194 return retVal; |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // MovePrev |
|
199 // --------------------------------------------------------------------------- |
|
200 TBool CFsTextViewerSelectsManager::MovePrevL( TBool& aChanged ) |
|
201 { |
|
202 FUNC_LOG; |
|
203 TBool retVal = EFalse; |
|
204 |
|
205 if ( iCurrent >= 0 && iCurrent < iSelects.Count() ) |
|
206 { |
|
207 iSelects[iCurrent]->DeselectL(); |
|
208 } |
|
209 |
|
210 if ( iCurrent < 0 && iSelects.Count() > 0 ) |
|
211 { |
|
212 iCurrent = 0; |
|
213 if ( iSelects[0]->IsVisible() ) |
|
214 { |
|
215 retVal = ETrue; |
|
216 } |
|
217 } |
|
218 else if ( iSelects.Count() > 0 ) |
|
219 { |
|
220 for ( TInt i = iCurrent - 1; i >= 0; --i ) |
|
221 { |
|
222 if ( iSelects[i]->IsVisible() && !retVal ) |
|
223 { |
|
224 iCurrent = i; |
|
225 retVal = ETrue; |
|
226 } |
|
227 } |
|
228 } |
|
229 |
|
230 if ( !retVal && iCurrent >= 0 && iCurrent < iSelects.Count() && !iSelects[iCurrent]->IsVisible() ) |
|
231 { |
|
232 for ( TInt i = iSelects.Count() - 1; i > iCurrent; --i ) |
|
233 { |
|
234 if ( iSelects[i]->IsVisible() && !retVal ) |
|
235 { |
|
236 iCurrent = i; |
|
237 retVal = ETrue; |
|
238 } |
|
239 } |
|
240 } |
|
241 |
|
242 if ( iCurrent >= 0 && iCurrent < iSelects.Count() && iSelects[iCurrent]->IsVisible() ) |
|
243 { |
|
244 iSelects[iCurrent]->SelectL(); |
|
245 } |
|
246 |
|
247 if ( iCurrent >= 0 && iCurrent < iSelects.Count() |
|
248 && iSelects[iCurrent]->GetStartLine() <= iOwner->Navigator()->GetLastVisible()->iLineNumber - 4 && aChanged ) |
|
249 { |
|
250 retVal = EFalse; |
|
251 } |
|
252 else |
|
253 { |
|
254 |
|
255 } |
|
256 |
|
257 aChanged = retVal; |
|
258 return retVal; |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------------------------- |
|
262 // RemoveVisual |
|
263 // --------------------------------------------------------------------------- |
|
264 void CFsTextViewerSelectsManager::RemoveVisual( TFsRangedVisual* aVisual ) |
|
265 { |
|
266 FUNC_LOG; |
|
267 for ( TInt i = 0; i < iSelects.Count(); ++i ) |
|
268 { |
|
269 iSelects[i]->RemoveVisual( aVisual ); |
|
270 } |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // Clicked |
|
275 // --------------------------------------------------------------------------- |
|
276 void CFsTextViewerSelectsManager::ClickedL() |
|
277 { |
|
278 FUNC_LOG; |
|
279 if ( iCurrent >= 0 && iCurrent < iSelects.Count() ) |
|
280 { |
|
281 iSelects[iCurrent]->SelectedL(); |
|
282 } |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // IsHotspotHighlighted |
|
287 // --------------------------------------------------------------------------- |
|
288 TBool CFsTextViewerSelectsManager::IsHotspotHighlighted() |
|
289 { |
|
290 FUNC_LOG; |
|
291 TBool retVal = EFalse; |
|
292 if ( iCurrent >= 0 && |
|
293 iSelects.Count() > 0 |
|
294 && ( iSelects[iCurrent]->GetType() |
|
295 == CFsTextViewerSelect::EFsHotspotType |
|
296 || iSelects[iCurrent]->GetType() |
|
297 == CFsTextViewerSelect::EFsLineType ) ) |
|
298 { |
|
299 retVal = ETrue; |
|
300 } |
|
301 |
|
302 return retVal; |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // GetCurrentSelectId |
|
307 // --------------------------------------------------------------------------- |
|
308 TInt CFsTextViewerSelectsManager::GetCurrentSelectId() |
|
309 { |
|
310 FUNC_LOG; |
|
311 TInt retVal = -1; |
|
312 |
|
313 if ( iCurrent >= 0 && |
|
314 iSelects.Count() > 0 |
|
315 && ( iSelects[iCurrent]->GetType() |
|
316 == CFsTextViewerSelect::EFsHotspotType |
|
317 || iSelects[iCurrent]->GetType() |
|
318 == CFsTextViewerSelect::EFsLineType ) ) |
|
319 { |
|
320 retVal = iSelects[iCurrent]->GetId(); |
|
321 } |
|
322 |
|
323 return retVal; |
|
324 } |
|
325 |
|
326 // <cmail> |
|
327 TInt CFsTextViewerSelectsManager::GetCurrentSelectedIndex() |
|
328 { |
|
329 return iCurrent; |
|
330 } |
|
331 // </cmail> |
|
332 |
|
333 // --------------------------------------------------------------------------- |
|
334 // DimAll |
|
335 // --------------------------------------------------------------------------- |
|
336 void CFsTextViewerSelectsManager::DimAllL() |
|
337 { |
|
338 FUNC_LOG; |
|
339 for ( TInt i = 0; i < iSelects.Count(); ++i ) |
|
340 { |
|
341 if ( i != iCurrent |
|
342 && iSelects[i]->GetType() != CFsTextViewerSelect::EFsLineType ) |
|
343 { |
|
344 if ( iSelects[i]->IsVisible() ) |
|
345 { |
|
346 iSelects[i]->DeselectL(); |
|
347 } |
|
348 } |
|
349 } |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // RefreshSelection |
|
354 // --------------------------------------------------------------------------- |
|
355 void CFsTextViewerSelectsManager::RefreshSelectionL() |
|
356 { |
|
357 FUNC_LOG; |
|
358 for ( TInt i = 0; i < iSelects.Count(); ++i ) |
|
359 { |
|
360 if ( i != iCurrent |
|
361 && iSelects[i]->GetType() != CFsTextViewerSelect::EFsLineType ) |
|
362 { |
|
363 iSelects[i]->DeselectL(); |
|
364 } |
|
365 } |
|
366 if ( iCurrent >= 0 ) |
|
367 { |
|
368 iSelects[iCurrent]->SelectL(); |
|
369 } |
|
370 } |
|
371 |
|
372 |
|
373 // --------------------------------------------------------------------------- |
|
374 // SelectL |
|
375 // --------------------------------------------------------------------------- |
|
376 void CFsTextViewerSelectsManager::SelectL( TInt aId ) |
|
377 { |
|
378 FUNC_LOG; |
|
379 CFsTextViewerSelect* hotspotFound = NULL; |
|
380 TInt arrayIndex = 0; |
|
381 for ( TInt i = 0; i < iSelects.Count(); ++i ) |
|
382 { |
|
383 if ( iSelects[i]->GetId() == aId ) |
|
384 { |
|
385 hotspotFound = iSelects[i]; |
|
386 arrayIndex = i; |
|
387 } |
|
388 } |
|
389 if ( hotspotFound ) |
|
390 { |
|
391 if ( iCurrent >= 0 ) |
|
392 { |
|
393 iSelects[iCurrent]->DeselectL(); |
|
394 } |
|
395 iCurrent = arrayIndex; |
|
396 if ( iSelects[iCurrent]->IsVisible() ) |
|
397 { |
|
398 iSelects[iCurrent]->SelectL(); |
|
399 } |
|
400 } |
|
401 } |
|
402 |
|
403 // --------------------------------------------------------------------------- |
|
404 // SelectByCharL |
|
405 // --------------------------------------------------------------------------- |
|
406 void CFsTextViewerSelectsManager::SelectByCharL( TInt aIndex ) |
|
407 { |
|
408 FUNC_LOG; |
|
409 CFsTextViewerSelect* hotspotFound = NULL; |
|
410 TInt arrayIndex = 0; |
|
411 |
|
412 for ( TInt i = 0; i < iSelects.Count(); ++i ) |
|
413 { |
|
414 if ( iOwner->Parser()->GetStartIndexOfHotSpotAreaL( iSelects[i]->GetId(), ETrue ) <= aIndex && |
|
415 iOwner->Parser()->GetEndIndexOfHotSpotAreaL( iSelects[i]->GetId(), ETrue ) >= aIndex ) |
|
416 { |
|
417 hotspotFound = iSelects[i]; |
|
418 arrayIndex = i; |
|
419 } |
|
420 } |
|
421 |
|
422 if ( hotspotFound ) |
|
423 { |
|
424 if ( iCurrent >= 0 ) |
|
425 { |
|
426 iSelects[iCurrent]->DeselectL(); |
|
427 } |
|
428 iCurrent = arrayIndex; |
|
429 if ( iSelects[iCurrent]->IsVisible() ) |
|
430 { |
|
431 iSelects[iCurrent]->SelectL(); |
|
432 } |
|
433 } |
|
434 } |
|
435 |
|
436 // --------------------------------------------------------------------------- |
|
437 // SelectByIndexL |
|
438 // --------------------------------------------------------------------------- |
|
439 void CFsTextViewerSelectsManager::SelectByIndexL( TInt aIndex ) |
|
440 { |
|
441 FUNC_LOG; |
|
442 if ( aIndex >= 0 && aIndex < iSelects.Count() ) |
|
443 { |
|
444 if ( iCurrent >= 0 && iCurrent < iSelects.Count() ) |
|
445 { |
|
446 if ( iSelects[iCurrent]->IsVisible() ) |
|
447 { |
|
448 iSelects[iCurrent]->DeselectL(); |
|
449 } |
|
450 } |
|
451 iCurrent = aIndex; |
|
452 if ( iSelects[iCurrent]->IsVisible() ) |
|
453 { |
|
454 iSelects[iCurrent]->SelectL(); |
|
455 } |
|
456 } |
|
457 } |
|
458 |
|
459 // --------------------------------------------------------------------------- |
|
460 // GetDisplaySize |
|
461 // --------------------------------------------------------------------------- |
|
462 TSize CFsTextViewerSelectsManager::GetDisplaySize() |
|
463 { |
|
464 FUNC_LOG; |
|
465 return iDisplaySize; |
|
466 } |
|
467 |
|
468 // --------------------------------------------------------------------------- |
|
469 // IsCurrentHotspotVisible |
|
470 // --------------------------------------------------------------------------- |
|
471 TBool CFsTextViewerSelectsManager::IsCurrentHotspotVisible() |
|
472 { |
|
473 FUNC_LOG; |
|
474 TBool retVal = EFalse; |
|
475 if ( iSelects.Count() > 0 && iCurrent >=0 ) |
|
476 { |
|
477 retVal = iSelects[iCurrent]->IsVisible(); |
|
478 } |
|
479 return retVal; |
|
480 } |
|
481 |
|
482 // --------------------------------------------------------------------------- |
|
483 // GetCurrentHotspotLine |
|
484 // --------------------------------------------------------------------------- |
|
485 TInt CFsTextViewerSelectsManager::GetCurrentHotspotLine() |
|
486 { |
|
487 FUNC_LOG; |
|
488 TInt retVal = -1; |
|
489 if ( iSelects.Count() > 0 && iCurrent >=0 ) |
|
490 { |
|
491 retVal = iSelects[iCurrent]->GetStartLine(); |
|
492 } |
|
493 return retVal; |
|
494 } |
|
495 |
|
496 // --------------------------------------------------------------------------- |
|
497 // HideActionButtonFromCurrentHighlightedHotspot |
|
498 // --------------------------------------------------------------------------- |
|
499 void CFsTextViewerSelectsManager |
|
500 ::HideActionButtonFromCurrentHighlightedHotspot() |
|
501 { |
|
502 FUNC_LOG; |
|
503 if ( iCurrent >= 0 && |
|
504 iSelects.Count() > 0 && |
|
505 iSelects[iCurrent]->GetType() == CFsTextViewerSelect::EFsLineType) |
|
506 { |
|
507 static_cast<CFsTextViewerSelectLine*>(iSelects[iCurrent]) |
|
508 ->HideActionButton(); |
|
509 } |
|
510 } |
|
511 |
|
512 // --------------------------------------------------------------------------- |
|
513 // ShowActionButtonForCurrentHighlightedHotspotL |
|
514 // --------------------------------------------------------------------------- |
|
515 void CFsTextViewerSelectsManager |
|
516 ::ShowActionButtonForCurrentHighlightedHotspotL() |
|
517 { |
|
518 FUNC_LOG; |
|
519 if ( iCurrent >= 0 && |
|
520 iSelects.Count() > 0 && |
|
521 iSelects[iCurrent]->GetType() == CFsTextViewerSelect::EFsLineType) |
|
522 { |
|
523 static_cast<CFsTextViewerSelectLine*> |
|
524 (iSelects[iCurrent])->ShowActionButtonL(); |
|
525 } |
|
526 } |
|
527 |
|
528 // --------------------------------------------------------------------------- |
|
529 // Compare |
|
530 // --------------------------------------------------------------------------- |
|
531 TInt CFsTextViewerSelectsManager::Compare( |
|
532 const CFsTextViewerSelect& aFirst, |
|
533 const CFsTextViewerSelect& aSecond ) |
|
534 { |
|
535 FUNC_LOG; |
|
536 // if ( aFirst.iRect.iTl.iY > aSecond.iRect.iTl.iY ) |
|
537 // { |
|
538 // return 1; |
|
539 // } |
|
540 // else if ( aFirst.iRect.iTl.iY == aSecond.iRect.iTl.iY ) |
|
541 // { |
|
542 // if ( aFirst.iRect.iTl.iX > aSecond.iRect.iTl.iX ) |
|
543 // { |
|
544 // return 1; |
|
545 // } |
|
546 // else if ( aFirst.iRect.iTl.iX == aSecond.iRect.iTl.iX ) |
|
547 // { |
|
548 // return 0; |
|
549 // } |
|
550 // else |
|
551 // { |
|
552 // return -1; |
|
553 // } |
|
554 // } |
|
555 if ( aFirst.GetId() > aSecond.GetId() ) |
|
556 { |
|
557 return 1; |
|
558 } |
|
559 else if ( aFirst.GetId() == aSecond.GetId() ) |
|
560 { |
|
561 return 0; |
|
562 } |
|
563 else |
|
564 { |
|
565 return -1; |
|
566 } |
|
567 } |
|
568 |
|
569 // --------------------------------------------------------------------------- |
|
570 // ConstructL |
|
571 // --------------------------------------------------------------------------- |
|
572 void CFsTextViewerSelectsManager::ConstructL() |
|
573 { |
|
574 FUNC_LOG; |
|
575 iCurrent = -1; |
|
576 iHighlightLine = iOwner->iSettings->iHighlightLine; |
|
577 iHighlightLineOpacity = iOwner->iSettings->iHighlightLineOpacity; |
|
578 iActionButton = iOwner->iSettings->iActionButton; |
|
579 iActionButtonOpacity = iOwner->iSettings->iActionButtonOpacity; |
|
580 iActionButtonMargin = iOwner->iSettings->iActionButtonMargin; |
|
581 iActionButtonWidth = iOwner->iSettings->iActionButtonWidth; |
|
582 iActionButtonHeight = iOwner->iSettings->iActionButtonHeight; |
|
583 iDisplaySize = iOwner->iDisplaySize; |
|
584 iControl = iOwner->Control(); |
|
585 } |
|
586 |
|
587 // --------------------------------------------------------------------------- |
|
588 // CFsTextViewerSelectsManager |
|
589 // --------------------------------------------------------------------------- |
|
590 CFsTextViewerSelectsManager::CFsTextViewerSelectsManager( |
|
591 CFsTextViewerVisualizer* aOwner ) |
|
592 { |
|
593 FUNC_LOG; |
|
594 iOwner = aOwner; |
|
595 } |
|
596 |