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