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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <ganes/HgGrid.h> |
|
21 #include <ganes/HgItem.h> |
|
22 |
|
23 #include "HgLayoutData.h" |
|
24 #include "HgIndicatorManager.h" |
|
25 #include "HgDrawUtils.h" |
|
26 |
|
27 |
|
28 #include <aknphysics.h> |
|
29 |
|
30 #include "HgConstants.h" |
|
31 |
|
32 #include <AknIconUtils.h> |
|
33 #include <avkon.mbg> |
|
34 #include <AknUtils.h> |
|
35 #include <AknsUtils.h> |
|
36 #include <AknsDrawUtils.h> |
|
37 #include <AknsConstants.h> |
|
38 #include <gulicon.h> |
|
39 #include <AknUtils.h> |
|
40 |
|
41 #include <layoutmetadata.cdl.h> |
|
42 #include <aknlayoutscalable_apps.cdl.h> |
|
43 #include <aknlayoutscalable_avkon.cdl.h> |
|
44 |
|
45 using namespace AknLayoutScalable_Apps; |
|
46 |
|
47 // ============================ MEMBER FUNCTIONS =============================== |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CHgGrid::NewL() |
|
51 // Two-phased constructor. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C CHgGrid* CHgGrid::NewL ( |
|
55 const TRect& aRect, |
|
56 TInt aItemCount, |
|
57 CGulIcon* aDefaultIcon, |
|
58 RWsSession* aSession ) |
|
59 { |
|
60 CHgGrid* self = new ( ELeave ) CHgGrid( |
|
61 aItemCount, |
|
62 aDefaultIcon); |
|
63 CleanupStack::PushL (self ); |
|
64 self->ConstructL( aRect, aSession ); |
|
65 CleanupStack::Pop (self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CHgGrid::ConstructL() |
|
71 // Symbian 2nd phase constructor can leave. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CHgGrid::ConstructL (const TRect& aRect, RWsSession* aSession ) |
|
75 { |
|
76 TAknLayoutScalableParameterLimits limits = cell_gallery2_pane_ParamLimits(0); |
|
77 TInt cols = limits.LastColumn() + 1; |
|
78 iLayoutData = CHgGridLayoutData::NewL( cols ); |
|
79 |
|
80 CHgScroller::ConstructL( aRect, aSession ); |
|
81 |
|
82 // Activate the window, which makes it ready to be drawn |
|
83 ActivateL ( ); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CHgGrid::CHgGrid() |
|
88 // C++ default constructor can NOT contain any code, that might leave. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CHgGrid::CHgGrid( |
|
92 TInt aItemCount, |
|
93 CGulIcon* aDefaultIcon ) |
|
94 : CHgScroller( aItemCount, aDefaultIcon ) |
|
95 { |
|
96 // No implementation required |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CHgGrid::~CHgGrid() |
|
101 // Destructor. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C CHgGrid::~CHgGrid ( ) |
|
105 { |
|
106 delete iLayoutData; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CHgGrid::PreferredImageSize() |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C TSize CHgGrid::PreferredImageSize() |
|
114 { |
|
115 TAknLayoutRect gridAppPane; |
|
116 TAknLayoutRect gridItem; |
|
117 TAknLayoutRect gridImage; |
|
118 |
|
119 gridAppPane.LayoutRect( TRect(), grid_gallery2_pane(0)); |
|
120 gridItem.LayoutRect( gridAppPane.Rect(), cell_gallery2_pane(1, 0, 0)); |
|
121 gridImage.LayoutRect(gridItem.Rect(), cell_gallery2_pane_g2(1)); |
|
122 |
|
123 return gridImage.Rect().Size(); |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CHgGrid::InitItemsL() |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CHgGrid::InitItemsL() |
|
131 { |
|
132 for(TInt i = 0; i < iItemCount; ++i) |
|
133 { |
|
134 iItems.Append( CHgItem::NewL() ); |
|
135 } |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CHgGrid::DoDraw() |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CHgGrid::DoDraw (const TRect& /*aRect*/) const |
|
143 { |
|
144 // Get the standard graphics context |
|
145 TInt xdiff = (iViewPosition.iX-(iWidth/2))% (iLandscapeScrolling ? iRowHeight : iRowWidth); |
|
146 TInt ydiff = (iViewPosition.iY-(iHeight/2))%( iLandscapeScrolling ? iRowWidth : iRowHeight); |
|
147 |
|
148 if( iItemCount == 0 ) |
|
149 { |
|
150 TRgb color( KRgbBlack ); |
|
151 if ( AknsUtils::AvkonSkinEnabled() ) |
|
152 { |
|
153 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
154 color, |
|
155 KAknsIIDQsnTextColors, |
|
156 EAknsCIQsnTextColorsCG6 ); |
|
157 } |
|
158 if( iEmptyText ) |
|
159 iDrawUtils->DrawEmptyText(SystemGc(), Rect(), *iEmptyText, color); |
|
160 } |
|
161 else |
|
162 { |
|
163 TAknLayoutRect gridAppPane; |
|
164 gridAppPane.LayoutRect( GridRect(), iLayoutData->ItemLayout() ); |
|
165 |
|
166 if( iLandscapeScrolling ) |
|
167 { |
|
168 if( AknLayoutUtils::LayoutMirrored() ) |
|
169 { |
|
170 for(TInt i = iCurrentRow; i < iCols; ++i) |
|
171 { |
|
172 TInt xPos = - (((i-iCurrentRow)*iRowHeight) - xdiff); |
|
173 if( i < 0 ) |
|
174 continue; |
|
175 else if( xPos < -iWidth ) |
|
176 break; |
|
177 |
|
178 DrawRows( i, gridAppPane.Rect(), xPos ); |
|
179 } |
|
180 } |
|
181 else |
|
182 { |
|
183 for(TInt i = iCurrentRow; i < iCols; ++i) |
|
184 { |
|
185 TInt xPos = ((i-iCurrentRow)*iRowHeight) - xdiff; |
|
186 if( i < 0 ) |
|
187 continue; |
|
188 else if( xPos > iWidth ) |
|
189 break; |
|
190 |
|
191 DrawRows( i, gridAppPane.Rect(), xPos ); |
|
192 } |
|
193 } |
|
194 } |
|
195 else |
|
196 { |
|
197 for(TInt i = iCurrentRow; i < iRows; ++i) |
|
198 { |
|
199 TInt yPos = ((i-iCurrentRow)*iRowHeight) - ydiff; |
|
200 if( i < 0 ) |
|
201 continue; |
|
202 else if( yPos > iHeight ) |
|
203 break; |
|
204 |
|
205 DrawCols( i, gridAppPane.Rect(), yPos ); |
|
206 } |
|
207 } |
|
208 } |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CHgGrid::DrawRows() |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CHgGrid::DrawRows( TInt aCol, const TRect& aRect, TInt aXPos ) const |
|
216 { |
|
217 for(TInt j = 0; j < iRows; ++j) |
|
218 { |
|
219 TInt index = aCol*iRows + j; |
|
220 if( index < iItems.Count()) |
|
221 { |
|
222 TAknLayoutRect gridItem; |
|
223 gridItem.LayoutRect( aRect,iLayoutData->ColumnLayout(j) ); |
|
224 |
|
225 TRect rect(gridItem.Rect()); |
|
226 rect.Move( aXPos, 0 ); |
|
227 |
|
228 DrawItem( index, rect ); |
|
229 } |
|
230 else |
|
231 { |
|
232 break; |
|
233 } |
|
234 } |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CHgGrid::DrawCols() |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 void CHgGrid::DrawCols(TInt aRow, const TRect& aRect, TInt aYPos) const |
|
242 { |
|
243 for(TInt j = 0; j < iCols; ++j) |
|
244 { |
|
245 TInt index = aRow*iCols + j; |
|
246 if( index < iItems.Count()) |
|
247 { |
|
248 TAknLayoutRect gridItem; |
|
249 gridItem.LayoutRect( aRect,iLayoutData->ColumnLayout(j) ); |
|
250 |
|
251 TRect rect(gridItem.Rect()); |
|
252 rect.Move( 0, aYPos ); |
|
253 |
|
254 DrawItem( index, rect ); |
|
255 } |
|
256 else |
|
257 { |
|
258 break; |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CHgGrid::DoDraw() |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 void CHgGrid::DrawItem(TInt aIndex, const TRect& aRect ) const |
|
268 { |
|
269 CHgItem* item = iItems[aIndex]; |
|
270 CGulIcon* icon = item->Icon() ? item->Icon() : iDefaultIcon; |
|
271 |
|
272 if( aIndex == iSelectedIndex ) |
|
273 { |
|
274 DrawHighlight(aRect); |
|
275 } |
|
276 |
|
277 CWindowGc& gc = SystemGc(); |
|
278 |
|
279 iDrawUtils->DrawImage(gc, aRect, iLayoutData->IconLayout(), *icon); |
|
280 |
|
281 // Draw the indicators. |
|
282 iIndicatorManager->DrawIndicators( |
|
283 gc, |
|
284 aRect, |
|
285 item->Flags(), |
|
286 iLayoutData->FirstIndicatorLayout(), |
|
287 iLayoutData->SecondIndicatorLayout() ); |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CHgGrid::HandleSizeChanged() |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 void CHgGrid::HandleSizeChanged ( ) |
|
295 { |
|
296 iLandscapeScrolling = Layout_Meta_Data::IsLandscapeOrientation() && iLandScapeScrollingSupported; |
|
297 |
|
298 TInt oldCount = iLandscapeScrolling ? iRows : iCols; |
|
299 |
|
300 CalculateSizes(); |
|
301 |
|
302 if( iLandscapeScrolling ) |
|
303 { |
|
304 iCols = iItemCount / iRows; |
|
305 if(iItemCount%iRows) |
|
306 { |
|
307 ++iCols; // partially filled col |
|
308 } |
|
309 |
|
310 iItemsOnScreen = iWidth / iRowHeight; |
|
311 if((iWidth % iRowHeight)) |
|
312 iItemsOnScreen += 2; |
|
313 else |
|
314 iItemsOnScreen++; |
|
315 |
|
316 iItemsOnScreen *= iRows; |
|
317 |
|
318 if( oldCount != iRows ) |
|
319 { |
|
320 FitTopItemToView( iCurrentRow*oldCount ); |
|
321 } |
|
322 } |
|
323 else |
|
324 { |
|
325 iRows = iItemCount / iCols; |
|
326 if(iItemCount%iCols) |
|
327 { |
|
328 ++iRows; // partially filled row |
|
329 } |
|
330 |
|
331 iItemsOnScreen = iHeight / iRowHeight; |
|
332 if((iHeight % iRowHeight)) |
|
333 iItemsOnScreen += 2; |
|
334 else |
|
335 iItemsOnScreen++; |
|
336 |
|
337 iItemsOnScreen *= iCols; |
|
338 |
|
339 if( oldCount != iCols ) |
|
340 { |
|
341 FitTopItemToView( iCurrentRow*oldCount ); |
|
342 } |
|
343 } |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CHgGrid::CalculateSizes() |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 void CHgGrid::CalculateSizes() |
|
351 { |
|
352 // Count number of visible rows |
|
353 // First is checked if 3x4 or 4x3 items fits to the grid. |
|
354 TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; |
|
355 |
|
356 TAknLayoutScalableParameterLimits limits = cell_gallery2_pane_ParamLimits(variety); |
|
357 iCols = limits.LastColumn() + 1; |
|
358 iRows = limits.LastRow() + 1; |
|
359 |
|
360 iLayoutData->ChangeCols( iCols ); |
|
361 |
|
362 iLayoutData->SetBaseLayout(main_gallery2_pane(0)); |
|
363 iLayoutData->SetItemLayout(grid_gallery2_pane(variety)); |
|
364 iLayoutData->SetIconLayout(cell_gallery2_pane_g2(variety)); |
|
365 |
|
366 for(TInt i = 0; i < iCols; ++i) |
|
367 { |
|
368 if( iLandscapeScrolling ) |
|
369 { |
|
370 iLayoutData->SetColumnLayout(i, cell_gallery2_pane(variety, 0, i)); |
|
371 } |
|
372 else |
|
373 { |
|
374 iLayoutData->SetColumnLayout(i, cell_gallery2_pane(variety, i, 0)); |
|
375 } |
|
376 } |
|
377 iLayoutData->SetFirstIndicatorLayout(cell_gallery2_pane_g5(variety)); |
|
378 iLayoutData->SetSecondIndicatorLayout(cell_gallery2_pane_g4(variety)); |
|
379 |
|
380 TAknLayoutRect gridAppPane; |
|
381 TAknLayoutRect gridItem; |
|
382 TAknLayoutRect gridImage; |
|
383 |
|
384 gridAppPane.LayoutRect( GridRect(), iLayoutData->ItemLayout()); |
|
385 gridItem.LayoutRect( gridAppPane.Rect(), iLayoutData->ColumnLayout(0)); |
|
386 gridImage.LayoutRect( gridItem.Rect(), iLayoutData->IconLayout()); |
|
387 |
|
388 if( iLandscapeScrolling ) |
|
389 { |
|
390 iRowHeight = gridItem.Rect().Width(); |
|
391 iRowWidth = gridItem.Rect().Height(); |
|
392 } |
|
393 else |
|
394 { |
|
395 iRowHeight = gridItem.Rect().Height(); |
|
396 iRowWidth = gridItem.Rect().Width(); |
|
397 } |
|
398 |
|
399 iImageSize = gridImage.Rect().Size(); |
|
400 |
|
401 TAknLayoutRect indicator; |
|
402 indicator.LayoutRect( gridItem.Rect(), iLayoutData->FirstIndicatorLayout() ); |
|
403 iIndicatorSize = indicator.Rect().Size(); |
|
404 } |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CHgGrid::GetSelected() |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 TInt CHgGrid::GetSelected( TPoint aPosition ) const |
|
411 { |
|
412 TAknLayoutRect gridAppPane; |
|
413 gridAppPane.LayoutRect( GridRect(), iLayoutData->ItemLayout()); |
|
414 aPosition -= gridAppPane.Rect().iTl; |
|
415 |
|
416 TInt index = 0; |
|
417 if( iLandscapeScrolling ) |
|
418 { |
|
419 TInt y = aPosition.iY + ((iViewPosition.iY - (iHeight/2)) % iRowWidth); |
|
420 y /= iRowWidth; |
|
421 TInt x = 0; |
|
422 if( AknLayoutUtils::LayoutMirrored() ) |
|
423 { |
|
424 x = aPosition.iX - ((iViewPosition.iX - (iWidth/2)) % iRowHeight); |
|
425 |
|
426 if(x < 0) // to correct the division |
|
427 x-= iRowHeight; |
|
428 x /= iRowHeight; |
|
429 x = ((iWidth / iRowHeight) - 1) - x; // mirrored correction to x |
|
430 } |
|
431 else |
|
432 { |
|
433 x = aPosition.iX + ((iViewPosition.iX - (iWidth/2)) % iRowHeight); |
|
434 x /= iRowHeight; |
|
435 } |
|
436 index = (iCurrentRow*iRows) + (x*iRows) + y; |
|
437 } |
|
438 else |
|
439 { |
|
440 TInt x = aPosition.iX + ((iViewPosition.iX - (iWidth/2)) % iRowWidth); |
|
441 TInt y = aPosition.iY + ((iViewPosition.iY - (iHeight/2)) % iRowHeight); |
|
442 x /= iRowWidth; |
|
443 y /= iRowHeight; |
|
444 |
|
445 if( AknLayoutUtils::LayoutMirrored() ) |
|
446 { |
|
447 x = (iCols - 1) - x; |
|
448 } |
|
449 |
|
450 index = (iCurrentRow*iCols) + (y*iCols) + x; |
|
451 } |
|
452 |
|
453 |
|
454 return index >= iItems.Count() || index < 0 ? KErrNotFound : index; |
|
455 } |
|
456 |
|
457 // ----------------------------------------------------------------------------- |
|
458 // CHgGrid::TotalSize() |
|
459 // ----------------------------------------------------------------------------- |
|
460 // |
|
461 TSize CHgGrid::TotalSize() const |
|
462 { |
|
463 return iLandscapeScrolling ? TSize( iCols*iRowHeight, iHeight ) : TSize(iWidth, iRows*iRowHeight); |
|
464 } |
|
465 |
|
466 // ----------------------------------------------------------------------------- |
|
467 // CHgGrid::DrawHighlight() |
|
468 // ----------------------------------------------------------------------------- |
|
469 // |
|
470 void CHgGrid::DrawHighlight( const TRect& aOuterRect ) const |
|
471 { |
|
472 TRect innerRect( aOuterRect ); |
|
473 innerRect.Shrink(2,2); |
|
474 |
|
475 CWindowGc& gc = SystemGc(); |
|
476 |
|
477 if( HasHighlight() ) |
|
478 { |
|
479 if( iPointerDown && !iPanning && iFocusedIndex != KErrNotFound && iSelectionToFocusedItem ) |
|
480 { |
|
481 AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), |
|
482 gc, |
|
483 aOuterRect, |
|
484 innerRect, |
|
485 KAknsIIDQsnFrGridPressed, |
|
486 KAknsIIDQsnFrGridCenterPressed ); |
|
487 } |
|
488 else |
|
489 { |
|
490 AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), |
|
491 gc, |
|
492 aOuterRect, |
|
493 innerRect, |
|
494 KAknsIIDQsnFrGrid, |
|
495 KAknsIIDQsnFrGridCenter ); |
|
496 } |
|
497 } |
|
498 else if( iPointerDown && !iPanning ) |
|
499 { |
|
500 AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), |
|
501 gc, |
|
502 aOuterRect, |
|
503 innerRect, |
|
504 KAknsIIDQsnFrGrid, |
|
505 KAknsIIDQsnFrGridCenter ); |
|
506 } |
|
507 } |
|
508 |
|
509 // ----------------------------------------------------------------------------- |
|
510 // CHgGrid::DoHandleKeyEvent() |
|
511 // ----------------------------------------------------------------------------- |
|
512 // |
|
513 TBool CHgGrid::DoHandleKeyEvent( const TKeyEvent& aEvent ) |
|
514 { |
|
515 TBool ret = ETrue; |
|
516 switch( aEvent.iCode ) |
|
517 { |
|
518 case EKeyUpArrow: |
|
519 HandleUpArrow(); |
|
520 break; |
|
521 case EKeyDownArrow: |
|
522 HandleDownArrow(); |
|
523 break; |
|
524 case EKeyLeftArrow: |
|
525 HandleLeftArrow(); |
|
526 break; |
|
527 case EKeyRightArrow: |
|
528 HandleRightArrow(); |
|
529 break; |
|
530 default: |
|
531 ret = EFalse; |
|
532 break; |
|
533 } |
|
534 |
|
535 return ret; |
|
536 } |
|
537 |
|
538 // ----------------------------------------------------------------------------- |
|
539 // CHgGrid::HandleDownArrow() |
|
540 // ----------------------------------------------------------------------------- |
|
541 // |
|
542 void CHgGrid::HandleDownArrow() |
|
543 { |
|
544 if( iSelectedIndex == KErrNotFound ) |
|
545 { |
|
546 SelectDefaultItem(); |
|
547 } |
|
548 else |
|
549 { |
|
550 if( iLandscapeScrolling ) |
|
551 { |
|
552 ChangeSelectedIndex( 1 ); |
|
553 } |
|
554 else |
|
555 { |
|
556 ChangeSelectedIndex( iCols ); |
|
557 } |
|
558 FitSelectionToView(); |
|
559 SelectionChanged(); |
|
560 DrawDeferred(); |
|
561 } |
|
562 } |
|
563 |
|
564 // ----------------------------------------------------------------------------- |
|
565 // CHgGrid::GridRect() |
|
566 // ----------------------------------------------------------------------------- |
|
567 // |
|
568 TRect CHgGrid::GridRect() const |
|
569 { |
|
570 TAknLayoutRect listscrollAppPane; |
|
571 listscrollAppPane.LayoutRect( Rect(), iLayoutData->BaseLayout()); |
|
572 return listscrollAppPane.Rect(); |
|
573 } |
|
574 |
|
575 // ----------------------------------------------------------------------------- |
|
576 // CHgGrid::HandleUpArrow() |
|
577 // ----------------------------------------------------------------------------- |
|
578 // |
|
579 void CHgGrid::HandleUpArrow() |
|
580 { |
|
581 if( iSelectedIndex == KErrNotFound ) |
|
582 { |
|
583 SelectDefaultItem(); |
|
584 } |
|
585 else |
|
586 { |
|
587 if( iLandscapeScrolling ) |
|
588 { |
|
589 ChangeSelectedIndex( -1 ); |
|
590 } |
|
591 else |
|
592 { |
|
593 ChangeSelectedIndex( -iCols ); |
|
594 } |
|
595 FitSelectionToView(); |
|
596 SelectionChanged(); |
|
597 DrawDeferred(); |
|
598 } |
|
599 } |
|
600 |
|
601 // ----------------------------------------------------------------------------- |
|
602 // CHgGrid::HandleRightArrow() |
|
603 // ----------------------------------------------------------------------------- |
|
604 // |
|
605 void CHgGrid::HandleRightArrow() |
|
606 { |
|
607 if( iSelectedIndex == KErrNotFound ) |
|
608 { |
|
609 SelectDefaultItem(); |
|
610 } |
|
611 else |
|
612 { |
|
613 if( iLandscapeScrolling ) |
|
614 { |
|
615 TInt change = AknLayoutUtils::LayoutMirrored() ? -iRows : iRows; |
|
616 ChangeSelectedIndex( change ); |
|
617 } |
|
618 else |
|
619 { |
|
620 ChangeSelectedIndex( 1 ); |
|
621 } |
|
622 FitSelectionToView(); |
|
623 SelectionChanged(); |
|
624 DrawDeferred(); |
|
625 } |
|
626 } |
|
627 |
|
628 // ----------------------------------------------------------------------------- |
|
629 // CHgGrid::HandleLeftArrow() |
|
630 // ----------------------------------------------------------------------------- |
|
631 // |
|
632 void CHgGrid::HandleLeftArrow() |
|
633 { |
|
634 if( iSelectedIndex == KErrNotFound ) |
|
635 { |
|
636 SelectDefaultItem(); |
|
637 } |
|
638 else |
|
639 { |
|
640 if( iLandscapeScrolling ) |
|
641 { |
|
642 TInt change = AknLayoutUtils::LayoutMirrored() ? iRows : -iRows; |
|
643 ChangeSelectedIndex( change ); |
|
644 } |
|
645 else |
|
646 { |
|
647 ChangeSelectedIndex( -1 ); |
|
648 } |
|
649 FitSelectionToView(); |
|
650 SelectionChanged(); |
|
651 DrawDeferred(); |
|
652 } |
|
653 } |
|
654 |
|
655 // ----------------------------------------------------------------------------- |
|
656 // CHgGrid::FitSelectionToView() |
|
657 // ----------------------------------------------------------------------------- |
|
658 // |
|
659 void CHgGrid::FitSelectionToView() |
|
660 { |
|
661 const TInt index = iLandscapeScrolling ? |
|
662 iSelectedIndex/iRows : iSelectedIndex/iCols; |
|
663 FitRowToView( index ); |
|
664 } |
|
665 |
|
666 // ----------------------------------------------------------------------------- |
|
667 // CHgGrid::SelectDefaultItem() |
|
668 // ----------------------------------------------------------------------------- |
|
669 // |
|
670 void CHgGrid::SelectDefaultItem() |
|
671 { |
|
672 iSelectedIndex = CurrentIndex(); |
|
673 FitSelectionToView(); |
|
674 DrawDeferred(); |
|
675 } |
|
676 |
|
677 // ----------------------------------------------------------------------------- |
|
678 // CHgGrid::CurrentIndex() |
|
679 // ----------------------------------------------------------------------------- |
|
680 // |
|
681 TInt CHgGrid::CurrentIndex() |
|
682 { |
|
683 return iLandscapeScrolling ? iCurrentRow * iRows : iCurrentRow * iCols; |
|
684 } |
|
685 |
|
686 // ----------------------------------------------------------------------------- |
|
687 // CHgGrid::IsDisplayed() |
|
688 // ----------------------------------------------------------------------------- |
|
689 // |
|
690 TBool CHgGrid::IsDisplayed( TInt aIndex ) |
|
691 { |
|
692 TInt start = CurrentIndex(); |
|
693 TInt end = start + iItemsOnScreen; |
|
694 return aIndex >= start && aIndex < end; |
|
695 } |
|
696 |
|
697 // ----------------------------------------------------------------------------- |
|
698 // CHgGrid::FitTopItemToView() |
|
699 // ----------------------------------------------------------------------------- |
|
700 // |
|
701 void CHgGrid::FitTopItemToView( TInt aIndex ) |
|
702 { |
|
703 if( iLandscapeScrolling ) |
|
704 { |
|
705 // Higlighted item is set to top of the list |
|
706 const TInt newCol = aIndex/iRows; |
|
707 TInt newPos = newCol*iRowWidth + iWidth/2; |
|
708 |
|
709 if( ItemsOnScreen() >= iItems.Count() ) |
|
710 { |
|
711 newPos = iWidth/2; |
|
712 } |
|
713 else |
|
714 { |
|
715 const TInt endMid = TotalSize().iWidth - iWidth/2; |
|
716 if( newPos > endMid ) |
|
717 { |
|
718 // We are presenting last items in the list |
|
719 newPos = endMid; |
|
720 } |
|
721 } |
|
722 |
|
723 iViewPosition.iX = newPos; |
|
724 } |
|
725 else |
|
726 { |
|
727 // Higlighted item is set to top of the list |
|
728 const TInt newRow = aIndex/iCols; |
|
729 TInt newPos = newRow*iRowHeight + iHeight/2; |
|
730 |
|
731 if( ItemsOnScreen() >= iItems.Count() ) |
|
732 { |
|
733 newPos = iHeight/2; |
|
734 } |
|
735 else |
|
736 { |
|
737 const TInt endMid = TotalSize().iHeight - iHeight/2; |
|
738 if( newPos > endMid ) |
|
739 { |
|
740 // We are presenting last items in the list |
|
741 newPos = endMid; |
|
742 } |
|
743 } |
|
744 |
|
745 iViewPosition.iY = newPos; |
|
746 } |
|
747 |
|
748 HandleViewPositionChanged(); |
|
749 } |
|
750 |
|
751 // ----------------------------------------------------------------------------- |
|
752 // CHgGrid::SetLandscapeScrollingSupport() |
|
753 // ----------------------------------------------------------------------------- |
|
754 // |
|
755 EXPORT_C void CHgGrid::SetLandscapeScrollingSupport( TBool aSupportLandscapeScrolling ) |
|
756 { |
|
757 iLandScapeScrollingSupported = aSupportLandscapeScrolling; |
|
758 } |
|
759 |
|
760 void CHgGrid::ChangeSelectedIndex( TInt aMove ) |
|
761 { |
|
762 TInt nextIndex = 0; |
|
763 if( iSelectedIndex + aMove > iItems.Count() - 1 ) |
|
764 { |
|
765 // go to beginning |
|
766 nextIndex = 0; |
|
767 } |
|
768 else if( iSelectedIndex + aMove < 0 ) |
|
769 { |
|
770 // go to end |
|
771 nextIndex = iItems.Count() - 1; |
|
772 } |
|
773 else |
|
774 { |
|
775 nextIndex = iSelectedIndex + aMove; |
|
776 } |
|
777 |
|
778 if( iSelectionMode == ESelectionMark ) |
|
779 { |
|
780 Mark( iSelectedIndex ); |
|
781 Mark( nextIndex ); |
|
782 } |
|
783 else if( iSelectionMode == ESelectionUnMark ) |
|
784 { |
|
785 UnMark( iSelectedIndex ); |
|
786 UnMark( nextIndex ); |
|
787 } |
|
788 |
|
789 iSelectedIndex = nextIndex; |
|
790 } |
|
791 |
|
792 // End of File |
|