2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * CAknGridView handles the drawing, the mapping
16 * of the grid data index to the underlying listbox index (and
17 * visa versa) as well as the movement around the grid.
21 #ifndef __AKNGRIDVIEW_H__
22 #define __AKNGRIDVIEW_H__
32 * @c CAknGridView handles the drawing, the mapping of the grid data index
33 * to the underlying listbox index (and vice versa) as well as the movement
34 * around the grid. Differentiation is needed between a data index and the
35 * list box index since the inherited list box code handles the top, bottom
36 * and current indexes as though everything is order topdown and left to
37 * right. This is no good for grid that maybe order in 8 different
38 * ways so need conversion between list box index and actual data
40 * List box index is the index for the data item according to the
41 * snaking list box format of numbering data items.
42 * Data index is the actual index in the grid according to the
43 * ordering applied to the data by the user.
44 * Note: the logical position is the intermediate form used to map
45 * from a list box index to a data index or vi sa versa. It is
46 * essentialy the position of the item in relation to the top left
47 * corner of the grid. I.e. the top left position has logical
53 class CAknGridView : public CListBoxView
56 /** Enumeration flags for grid.*/
59 /** Vertical is primary direction.*/
60 EPrimaryIsVertical = 0x0001,
61 /** From top to bottom.*/
62 ETopToBottom = 0x0002,
63 /** From left to right.*/
66 /** Enumeration for different scrolling types.*/
69 /** Scrolling follows items and stops.*/
70 EScrollFollowsItemsAndStops,
71 /** Scrolling follows items and loops.*/
72 EScrollFollowsItemsAndLoops,
73 /** Scrolling follows grid. */
75 /** Scrolling stops. */
77 /** Scrolls one line and stops.*/
78 EScrollIncrementLineAndStops,
79 /** Scrolls one line and loops.*/
80 EScrollIncrementLineAndLoops
82 /** Enumeration flags for different layouts.*/
85 /** Current size of entire grid. */
86 TSize iGridDimensions;
89 /** Size of the viewable area ( iColsInView * iRowsInView ). */
91 /** The number of columns in the viewable area. */
93 /** The number of rows in the viewable area. */
95 /** The size of gap between items (height and width). */
96 TSize iSizeBetweenItems;
97 /** The size of an item. */
102 /** Enumeration flags for pages.*/
114 /* Enumeration of position of current index.*/
115 enum TPositionCurrentIndex
121 /** Opposite corner.*/
127 * Default C++ constructor.
129 IMPORT_C CAknGridView();
134 IMPORT_C virtual ~CAknGridView();
136 // actual <-> listbox index conversion routines
138 * Returns the actual index of given listbox index.
139 * @param aListBoxIndex The index of the listbox.
140 * @return The actual data index.
142 IMPORT_C TInt ActualDataIndex(TInt aListBoxIndex) const;
145 * Returns the listbox index of given data index.
146 * @param aDataIndex The index of the actual data.
147 * @return The index in listbox.
149 IMPORT_C TInt ListBoxIndex(TInt aDataIndex) const;
152 * Returns the current data index with respect to the ordering of the cells
154 * @return Current data index.
156 IMPORT_C TInt CurrentDataIndex() const;
159 * Sets the current data index with a value given with respect to the
160 * ordering of the cells in the grid.
161 * @param aDataIndex The index to be set.
163 IMPORT_C void SetCurrentDataIndex(TInt aDataIndex);
166 * Sets the form of scroll to activate upon reaching the limit when moving
167 * in the primary direction of grid, primary meaning whether the items are
168 * organised vertically or horizontally.
169 * @param aScrollingType The primary scrolling type.
171 IMPORT_C void SetPrimaryScrollingType(TScrollingType aScrollingType);
173 * Sets the form of scroll to activate upon reaching the limit when moving
174 * in the secondary direction of grid.
175 * @param aSecondaryScrolling The secondary scrolling type.
177 IMPORT_C void SetSecondaryScrollingType(TScrollingType aSecondaryScrolling);
180 * Checks that number of cells in the grid is always enough to fill the
181 * current grid dimensions. This method should be called after any method
182 * that may alter the amount of data within the grid.
183 * @param aGridDimensions Grid diemnsions.
185 IMPORT_C void SetGridCellDimensions(TSize aGridDimensions);
188 * Returns the current grid dimensions.
189 * @return The size of the current grid.
191 IMPORT_C TSize GridCellDimensions() const;
193 * Sets the size of the spaces between items.
194 * @param aSizeOfSpaceBetweenItems The size of the spaces between items.
196 IMPORT_C void SetSpacesBetweenItems(TSize aSizeOfSpaceBetweenItems);
199 * Returns @c ETrue if the primary dimension of the grid is vertical.
200 * @return @ETrue if vertical is set as primary, otherwise @c EFalse.
202 IMPORT_C TBool IsPrimaryVertical() const;
205 * Converts a logical position on the grid, where the co-ordinates are with
206 * respect to the top left hand corner of the grid, to an index for the cell
207 * with respect to the ordering of the cells in the grid.
208 * @param aItemIndex Reference to the index for the cell in the grid.
209 * @param aRowIndex The row in the grid.
210 * @param aColIndex The column in the grid.
212 IMPORT_C void DataIndexFromLogicalPos(
215 TInt aColIndex) const;
218 * Converts an index for a cell in the grid, given with respect to the
219 * ordering of the cells in the grid, to a logical position on the grid,
220 * where the co-ordinates are with respect to the top left hand corner of
222 * @param aItemIndex The index for the cell in the grid.
223 * @param aRowIndex Reference to the row in the grid.
224 * @param aColIndex Reference to the column in the grid.
226 IMPORT_C void LogicalPosFromDataIndex(
229 TInt& aColIndex) const;
232 * Converts a CEikListBox index for a cell in the grid, given with respect
233 * to the snaking listbox top down, left to right structure underlying the
234 * grid structure, to a logical position on the grid, where the co-ordinates
235 * are with respect to the top left hand corner of the grid.
236 * @param aItemIndex Reference to the index for the cell in the grid.
237 * @param aRowIndex The row in the grid.
238 * @param aColIndex The column in the grid.
240 IMPORT_C void ListBoxIndexFromLogicalPos(
243 TInt aColIndex) const;
245 * Converts a logical position on the grid, where the co-ordinates are with
246 * respect to the top left hand corner of the grid, to a CEikListBox index
247 * for the cell with respect to the snaking listbox top down, left to right
248 * structure underlying the grid structure.
249 * @param aItemIndex The index for the cell in the grid.
250 * @param aRowIndex Reference to the row in the grid.
251 * @param aColIndex Reference to the column in the grid.
253 IMPORT_C void LogicalPosFromListBoxIndex(
256 TInt& aColIndex) const;
259 * Draws empty grid list.
261 IMPORT_C virtual void DrawEmptyList() const;
264 * Grid initialisation function.
265 * @param aGridDetails Struct of grid details.
267 IMPORT_C void SetGridDetails(SGrid aGridDetails);
270 * This moves to the item and draws the grid in the right place.
271 * @param aItemIndex The wanted item index.
272 * @param aSelectionMode Mode for modifying the selection.
274 IMPORT_C void MoveToItemIndexL(TInt aItemIndex, TSelectionMode aSelectionMode);
277 * This function returns the number of visible columns.
278 * @return The number of visible columns in view.
280 IMPORT_C TInt NumberOfColsInView() const;
283 * This function returns the number of visible rows.
284 * @return The number of visible rows in view.
286 IMPORT_C TInt NumberOfRowsInView() const;
289 * Moves cursor with repeats.
290 * @param aNext ETrue if next, EFalse if previous.
291 * @param aSelectionMode selection mode.
292 * @param aAmount Amount of steps to move.
295 void MoveCursorWithRepeatsL(
297 TSelectionMode aSelectionMode,
300 public: // from CListBoxView
302 * From @c CListBoxView. Basically empty implementation of
303 * @c CListBoxView::DrawMatcherCursor.
305 IMPORT_C virtual void DrawMatcherCursor();
308 * From @c CListBoxView. This function returns the current item in the grid
309 * and -1 if there is no current item,
310 * @return The current item.
312 IMPORT_C TInt CurrentItemIndex() const;
316 * This function tests whether an item exists.
317 * @param aListBoxIndex Index to test.
318 * @return @c ETrue if the specified item exists, @c EFalse otherwise.
320 IMPORT_C TBool ItemExists(TInt aListBoxIndex) const;
322 public: // code moved from CSnakingListBoxView
324 * This function sets the width of the grid column. This should only be
325 * called via the selection box class's @c SetColumnWidth method.
326 * @param aColumnWidth The required width of all columns in the view,
329 IMPORT_C void SetColumnWidth(TInt aColumnWidth);
332 * Overloaded @c MoveCursorL method to process cursor movement according to
333 * orientation of the grid.
334 * @param aCursorMovement The cursor movement to apply
335 * etc. @c ECursorNextItem and @c ECursorPreviousItem.
336 * @param aSelectionMode The selection mode of the calling list box.
338 IMPORT_C virtual void MoveCursorL(
339 TCursorMovement aCursorMovement,
340 TSelectionMode aSelectionMode);
343 * This function draws every visible item into the specified rectangle.
344 * As implemented in @c CListBoxView, this function's argument is ignored
345 * and the internal viewing rectangle is used. See @c SetViewRect().
346 * @param @c TRect* @c aClipRect = @c NULL The rectangle to draw into.
348 IMPORT_C virtual void Draw(const TRect* aClipRect = NULL) const;
351 * This has been overloaded to ensure that only valid cells are drawn and
352 * not the empty cells.
353 * @param aItemIndex Index number of the item to draw.
355 IMPORT_C virtual void DrawItem(TInt aItemIndex) const;
358 * This function gets the position of the top left corner of the specified
360 * @param aItemIndex An item in the model.
361 * @return @c TPoint position of the top left corner of the item, in pixels.
363 IMPORT_C virtual TPoint ItemPos(TInt aItemIndex) const;
366 * This function has been overloaded to draw items correctly. Recalculates
367 * the bottom item’s index. This is called by the list box control when
368 * either the size or the number of items in its model changes.
370 IMPORT_C virtual void CalcBottomItemIndex();
373 * This function gets the item the view would need to be moved to in order
374 * to make the specified item visible.
375 * @param aItemIndex The item to make visible.
376 * @return The item to scroll to to make @c aItemIndex visible.
378 IMPORT_C virtual TInt CalcNewTopItemIndexSoItemIsVisible(TInt aItemIndex) const;
381 * This function draws every item between the start and end indices
383 * @param aStartItemIndex The first item to draw.
384 * @param aEndItemIndex The final item to draw.
386 IMPORT_C virtual void DrawItemRange(TInt aStartItemIndex, TInt aEndItemIndex) const;
389 * This function gets the width of all columns in the view.
390 * @return The width of all columns in the view, in pixels.
392 inline TInt ColumnWidth() const;
395 * Sets which item appears at the top left corner of the view. The function
396 * changes items displayed in the view appropriately.
397 * @param aItemIndex Index of the item to set at the top left.
399 IMPORT_C virtual void SetTopItemIndex(TInt aItemIndex);
402 * This function sets item height in pixels.
403 * @param aItemHeight New height in pixels for this view’s items.
405 IMPORT_C virtual void SetItemHeight(TInt aItemHeight);
408 * This function converts an (x, y) pixel position to an item index.
409 * @param aPosition Pixel position in the viewing rectangle.
410 * @param aItemIndex Reference to the item index.
411 * @return Whether there was an item at aPosition.
413 IMPORT_C virtual TBool XYPosToItemIndex(TPoint aPosition, TInt& aItemIndex) const;
416 * Calculates the data width in columns. @c iDataWidth is calculated based on
417 * model and drawer information.
419 IMPORT_C virtual void CalcDataWidth();
422 * Gets the visible width of the specified rectangle in pixels.
423 * @param aRect Reference to the rectangle for which to get the visible
425 * @return Visible width of aRect in pixels.
427 IMPORT_C virtual TInt VisibleWidth(const TRect& aRect) const;
430 * Makes the specified item visible by moving the view location and
431 * redrawing the control. Index of the item to make visible.
432 * @param aItemIndex Index of the item to make visible.
433 * @return @c ETrue if the control was redrawn, @c EFalse if no redraw
434 * happened (i.e. the item was already visible, or redraw was disabled).
436 IMPORT_C virtual TBool ScrollToMakeItemVisible(TInt aItemIndex);
439 * Gets the number of columns that this view would need to be scrolled by
440 * to make the specified item visible. The function returns 0 if no
441 * scrolling is needed. @c ScrollToMakeItemVisible() uses this function.
442 * @param aItemIndex Item to make visible.
443 * @return The number of columns to scroll, or zero if no scrolling is
446 IMPORT_C virtual TInt CalculateHScrollOffsetSoItemIsVisible(TInt aItemIndex);
449 * Gets the size of the specified item.
450 * @param aItemIndex=0 The index of the item whose size this call is to get.
451 * @return @c TSize The size of the item in pixels.
453 IMPORT_C virtual TSize ItemSize(TInt aItemIndex=0) const;
456 * Converts an item index into the (row, column) pair describing that item.
457 * @param aItemIndex The item index.
458 * @param aRowIndex Reference to the row index.
459 * @param aColIndex Reference the column index.
461 IMPORT_C void CalcRowAndColIndexesFromItemIndex(TInt aItemIndex, TInt& aRowIndex, TInt& aColIndex) const;
464 * This function converts a row/column pair into the item index for that
466 * @param aItemIndex Reference to the item index.
467 * @param aRowIndex Row index of the item.
468 * @param aColIndex Column index of the item.
470 IMPORT_C void CalcItemIndexFromRowAndColIndexes(TInt& aItemIndex, TInt aRowIndex, TInt aColIndex) const;
472 protected: // code moved from CSnakingListBoxView
474 * This function draws every item in every column between the start and end
475 * columns inclusively.
476 * @param aStartColIndex The first column to draw.
477 * @param aEndColIndex The last column to draw.
479 IMPORT_C void DrawColumnRange(TInt aStartColIndex, TInt aEndColIndex) const;
482 * This function clears each item’s rectangle between the specified start
483 * and finish item’s indexes.
484 * @param aStartItemIndex The first item to clear.
485 * @param aEndItemIndex The last item to clear.
487 IMPORT_C void ClearUnusedItemSpace(TInt aStartItemIndex, TInt aEndItemIndex) const;
490 * This function updates the horizontal scroll offset (iHScrollOffset)
491 * based on the top item’s index. This function is called internally by
492 * @c CEikSnakingListBoxes when needed.
494 IMPORT_C void UpdateHScrollOffsetBasedOnTopItemIndex();
498 * This inline function is grid model helper.
499 * @return A pointer to @c CAknGridM object.
501 inline CAknGridM* GridModel() const;
504 * This function handles movement routines.
505 * @param aCursorMovement Handles cursor movements etc. @c ECursorNextItem
506 * and @c ECursorPreviousItem.
507 * @param aSelectionMode Modes for modifying the selection.
509 IMPORT_C void DoMoveL(TCursorMovement aCursorMovement, TSelectionMode aSelectionMode);
512 // movement handling routines
513 IMPORT_C TInt SearchByLines(TInt aX, TInt aY, TCursorMovement aCursorMovement, TBool aBeginSearchOnIndex = EFalse);
514 IMPORT_C TInt FindNextItem(TInt aItemIndex, TBool aLookDown, TBool aLookRight, TBool aFirstLookHorizontal, TBool aBeginSearchOnIndex = EFalse);
515 TBool IsEdgePassed(TInt aItemIndex, TBool aLookDown, TBool aLookRight, TBool aFirstLookHorizontal, TBool aBeginSearchOnIndex, TInt& aNewIndex);
517 TBool IsMoveRight(TCursorMovement aCursorMovement);
518 TBool IsMoveDown(TCursorMovement aCursorMovement);
519 private: // overridden from CListBoxView
520 IMPORT_C virtual TAny* Reserved_1();
525 * Draws the portion of the grid view rectangle that contains no items.
527 void DrawUnusedViewPortion() const;
530 TScrollingType iScrollingType;
531 TScrollingType iScrollInSecondaryDimension;
537 inline CAknGridM* CAknGridView::GridModel() const
539 return STATIC_CAST(CAknGridM*,iModel);
542 inline TInt CAknGridView::ColumnWidth() const
543 { return iGridDetails.iSizeOfItems.iWidth; }
545 #endif // __AKNGRIDVIEW_H__