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