williamr@2: /* williamr@2: * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@4: * under the terms of "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@4: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * CAknGridView handles the drawing, the mapping williamr@2: * of the grid data index to the underlying listbox index (and williamr@2: * visa versa) as well as the movement around the grid. williamr@2: * williamr@2: */ williamr@2: williamr@2: #ifndef __AKNGRIDVIEW_H__ williamr@2: #define __AKNGRIDVIEW_H__ williamr@2: williamr@2: // INCLUDES williamr@2: #include williamr@4: #include williamr@2: #include williamr@2: williamr@2: // CLASS DECLARATION williamr@2: williamr@2: /** williamr@2: * @c CAknGridView handles the drawing, the mapping of the grid data index williamr@2: * to the underlying listbox index (and vice versa) as well as the movement williamr@2: * around the grid. Differentiation is needed between a data index and the williamr@2: * list box index since the inherited list box code handles the top, bottom williamr@2: * and current indexes as though everything is order topdown and left to williamr@2: * right. This is no good for grid that maybe order in 8 different williamr@2: * ways so need conversion between list box index and actual data williamr@2: * index. williamr@2: * List box index is the index for the data item according to the williamr@2: * snaking list box format of numbering data items. williamr@2: * Data index is the actual index in the grid according to the williamr@2: * ordering applied to the data by the user. williamr@2: * Note: the logical position is the intermediate form used to map williamr@2: * from a list box index to a data index or vi sa versa. It is williamr@2: * essentialy the position of the item in relation to the top left williamr@2: * corner of the grid. I.e. the top left position has logical williamr@2: * position 0,0. williamr@2: * williamr@2: * @since 0.9 williamr@2: * @lib avkon.lib williamr@2: */ williamr@2: class CAknGridView : public CListBoxView williamr@2: { williamr@2: public: williamr@2: /** Enumeration flags for grid.*/ williamr@2: enum TGridFlags williamr@2: { williamr@2: /** Vertical is primary direction.*/ williamr@2: EPrimaryIsVertical = 0x0001, williamr@2: /** From top to bottom.*/ williamr@2: ETopToBottom = 0x0002, williamr@2: /** From left to right.*/ williamr@2: ELeftToRight = 0x0004 williamr@2: }; williamr@2: /** Enumeration for different scrolling types.*/ williamr@2: enum TScrollingType williamr@2: { williamr@2: /** Scrolling follows items and stops.*/ williamr@2: EScrollFollowsItemsAndStops, williamr@2: /** Scrolling follows items and loops.*/ williamr@2: EScrollFollowsItemsAndLoops, williamr@2: /** Scrolling follows grid. */ williamr@2: EScrollFollowsGrid, williamr@2: /** Scrolling stops. */ williamr@2: EScrollStops, williamr@2: /** Scrolls one line and stops.*/ williamr@2: EScrollIncrementLineAndStops, williamr@2: /** Scrolls one line and loops.*/ williamr@2: EScrollIncrementLineAndLoops williamr@2: }; williamr@2: /** Enumeration flags for different layouts.*/ williamr@2: struct SGrid williamr@2: { williamr@2: /** Current size of entire grid. */ williamr@2: TSize iGridDimensions; williamr@2: /** Flags. */ williamr@2: TInt iGridFlags; williamr@2: /** Size of the viewable area ( iColsInView * iRowsInView ). */ williamr@2: TInt iPageSize; williamr@2: /** The number of columns in the viewable area. */ williamr@2: TInt iColsInView; williamr@2: /** The number of rows in the viewable area. */ williamr@2: TInt iRowsInView; williamr@2: /** The size of gap between items (height and width). */ williamr@2: TSize iSizeBetweenItems; williamr@2: /** The size of an item. */ williamr@2: TSize iSizeOfItems; williamr@2: }; williamr@2: williamr@2: protected: williamr@2: /** Enumeration flags for pages.*/ williamr@2: enum TPageIndex williamr@2: { williamr@2: /** Previous page.*/ williamr@2: EPreviousPage, williamr@2: /** Next page.*/ williamr@2: ENextPage, williamr@2: /** First page. */ williamr@2: EHome, williamr@2: /** Last page.*/ williamr@2: EEnd williamr@2: }; williamr@2: /* Enumeration of position of current index.*/ williamr@2: enum TPositionCurrentIndex williamr@2: { williamr@2: /** Page. */ williamr@2: EPage, williamr@2: /** Column.*/ williamr@2: EColumn, williamr@2: /** Opposite corner.*/ williamr@2: EOppositeCorner williamr@2: }; williamr@2: williamr@2: public: williamr@2: /** williamr@2: * Default C++ constructor. williamr@2: */ williamr@2: IMPORT_C CAknGridView(); williamr@2: williamr@2: /** williamr@2: * Destructor. williamr@2: */ williamr@2: IMPORT_C virtual ~CAknGridView(); williamr@2: williamr@2: // actual <-> listbox index conversion routines williamr@2: /** williamr@2: * Returns the actual index of given listbox index. williamr@2: * @param aListBoxIndex The index of the listbox. williamr@2: * @return The actual data index. williamr@2: */ williamr@2: IMPORT_C TInt ActualDataIndex(TInt aListBoxIndex) const; williamr@2: williamr@2: /** williamr@2: * Returns the listbox index of given data index. williamr@2: * @param aDataIndex The index of the actual data. williamr@2: * @return The index in listbox. williamr@2: */ williamr@2: IMPORT_C TInt ListBoxIndex(TInt aDataIndex) const; williamr@2: williamr@2: /** williamr@2: * Returns the current data index with respect to the ordering of the cells williamr@2: * in the grid. williamr@2: * @return Current data index. williamr@2: */ williamr@2: IMPORT_C TInt CurrentDataIndex() const; williamr@2: williamr@2: /** williamr@2: * Sets the current data index with a value given with respect to the williamr@2: * ordering of the cells in the grid. williamr@2: * @param aDataIndex The index to be set. williamr@2: */ williamr@2: IMPORT_C void SetCurrentDataIndex(TInt aDataIndex); williamr@2: williamr@2: /** williamr@2: * Sets the form of scroll to activate upon reaching the limit when moving williamr@2: * in the primary direction of grid, primary meaning whether the items are williamr@2: * organised vertically or horizontally. williamr@2: * @param aScrollingType The primary scrolling type. williamr@2: */ williamr@2: IMPORT_C void SetPrimaryScrollingType(TScrollingType aScrollingType); williamr@2: /** williamr@2: * Sets the form of scroll to activate upon reaching the limit when moving williamr@2: * in the secondary direction of grid. williamr@2: * @param aSecondaryScrolling The secondary scrolling type. williamr@2: */ williamr@2: IMPORT_C void SetSecondaryScrollingType(TScrollingType aSecondaryScrolling); williamr@2: williamr@2: /** williamr@2: * Checks that number of cells in the grid is always enough to fill the williamr@2: * current grid dimensions. This method should be called after any method williamr@2: * that may alter the amount of data within the grid. williamr@2: * @param aGridDimensions Grid diemnsions. williamr@2: */ williamr@2: IMPORT_C void SetGridCellDimensions(TSize aGridDimensions); williamr@2: williamr@2: /** williamr@2: * Returns the current grid dimensions. williamr@2: * @return The size of the current grid. williamr@2: */ williamr@2: IMPORT_C TSize GridCellDimensions() const; williamr@2: /** williamr@2: * Sets the size of the spaces between items. williamr@2: * @param aSizeOfSpaceBetweenItems The size of the spaces between items. williamr@2: */ williamr@2: IMPORT_C void SetSpacesBetweenItems(TSize aSizeOfSpaceBetweenItems); williamr@2: williamr@2: /** williamr@2: * Returns @c ETrue if the primary dimension of the grid is vertical. williamr@2: * @return @ETrue if vertical is set as primary, otherwise @c EFalse. williamr@2: */ williamr@2: IMPORT_C TBool IsPrimaryVertical() const; williamr@2: williamr@2: /** williamr@2: * Converts a logical position on the grid, where the co-ordinates are with williamr@2: * respect to the top left hand corner of the grid, to an index for the cell williamr@2: * with respect to the ordering of the cells in the grid. williamr@2: * @param aItemIndex Reference to the index for the cell in the grid. williamr@2: * @param aRowIndex The row in the grid. williamr@2: * @param aColIndex The column in the grid. williamr@2: */ williamr@2: IMPORT_C void DataIndexFromLogicalPos( williamr@2: TInt& aItemIndex, williamr@2: TInt aRowIndex, williamr@2: TInt aColIndex) const; williamr@2: williamr@2: /** williamr@2: * Converts an index for a cell in the grid, given with respect to the williamr@2: * ordering of the cells in the grid, to a logical position on the grid, williamr@2: * where the co-ordinates are with respect to the top left hand corner of williamr@2: * the grid. williamr@2: * @param aItemIndex The index for the cell in the grid. williamr@2: * @param aRowIndex Reference to the row in the grid. williamr@2: * @param aColIndex Reference to the column in the grid. williamr@2: */ williamr@2: IMPORT_C void LogicalPosFromDataIndex( williamr@2: TInt aItemIndex, williamr@2: TInt& aRowIndex, williamr@2: TInt& aColIndex) const; williamr@2: williamr@2: /** williamr@2: * Converts a CEikListBox index for a cell in the grid, given with respect williamr@2: * to the snaking listbox top down, left to right structure underlying the williamr@2: * grid structure, to a logical position on the grid, where the co-ordinates williamr@2: * are with respect to the top left hand corner of the grid. williamr@2: * @param aItemIndex Reference to the index for the cell in the grid. williamr@2: * @param aRowIndex The row in the grid. williamr@2: * @param aColIndex The column in the grid. williamr@2: */ williamr@2: IMPORT_C void ListBoxIndexFromLogicalPos( williamr@2: TInt& aItemIndex, williamr@2: TInt aRowIndex, williamr@2: TInt aColIndex) const; williamr@2: /** williamr@2: * Converts a logical position on the grid, where the co-ordinates are with williamr@2: * respect to the top left hand corner of the grid, to a CEikListBox index williamr@2: * for the cell with respect to the snaking listbox top down, left to right williamr@2: * structure underlying the grid structure. williamr@2: * @param aItemIndex The index for the cell in the grid. williamr@2: * @param aRowIndex Reference to the row in the grid. williamr@2: * @param aColIndex Reference to the column in the grid. williamr@2: */ williamr@2: IMPORT_C void LogicalPosFromListBoxIndex( williamr@2: TInt aItemIndex, williamr@2: TInt& aRowIndex, williamr@2: TInt& aColIndex) const; williamr@2: williamr@2: /** williamr@2: * Draws empty grid list. williamr@2: */ williamr@2: IMPORT_C virtual void DrawEmptyList() const; williamr@2: williamr@2: /** williamr@2: * Grid initialisation function. williamr@2: * @param aGridDetails Struct of grid details. williamr@2: */ williamr@2: IMPORT_C void SetGridDetails(SGrid aGridDetails); williamr@2: williamr@2: /** williamr@2: * This moves to the item and draws the grid in the right place. williamr@2: * @param aItemIndex The wanted item index. williamr@2: * @param aSelectionMode Mode for modifying the selection. williamr@2: */ williamr@2: IMPORT_C void MoveToItemIndexL(TInt aItemIndex, TSelectionMode aSelectionMode); williamr@2: williamr@2: /** williamr@2: * This function returns the number of visible columns. williamr@2: * @return The number of visible columns in view. williamr@2: */ williamr@2: IMPORT_C TInt NumberOfColsInView() const; williamr@2: williamr@2: /** williamr@2: * This function returns the number of visible rows. williamr@2: * @return The number of visible rows in view. williamr@2: */ williamr@2: IMPORT_C TInt NumberOfRowsInView() const; williamr@2: williamr@2: /** williamr@2: * Moves cursor with repeats. williamr@2: * @param aNext ETrue if next, EFalse if previous. williamr@2: * @param aSelectionMode selection mode. williamr@2: * @param aAmount Amount of steps to move. williamr@2: * @since S60 3.2 williamr@2: */ williamr@2: void MoveCursorWithRepeatsL( williamr@2: TBool aNextOrPrev, williamr@2: TSelectionMode aSelectionMode, williamr@2: TInt aAmount ); williamr@2: williamr@2: public: // from CListBoxView williamr@2: /** williamr@2: * From @c CListBoxView. Basically empty implementation of williamr@2: * @c CListBoxView::DrawMatcherCursor. williamr@2: */ williamr@2: IMPORT_C virtual void DrawMatcherCursor(); williamr@2: williamr@2: /** williamr@2: * From @c CListBoxView. This function returns the current item in the grid williamr@2: * and -1 if there is no current item, williamr@2: * @return The current item. williamr@2: */ williamr@2: IMPORT_C TInt CurrentItemIndex() const; williamr@2: williamr@2: protected: williamr@2: /** williamr@2: * This function tests whether an item exists. williamr@2: * @param aListBoxIndex Index to test. williamr@2: * @return @c ETrue if the specified item exists, @c EFalse otherwise. williamr@2: */ williamr@2: IMPORT_C TBool ItemExists(TInt aListBoxIndex) const; williamr@2: williamr@2: public: // code moved from CSnakingListBoxView williamr@2: /** williamr@2: * This function sets the width of the grid column. This should only be williamr@2: * called via the selection box class's @c SetColumnWidth method. williamr@2: * @param aColumnWidth The required width of all columns in the view, williamr@2: * in pixels. williamr@2: */ williamr@2: IMPORT_C void SetColumnWidth(TInt aColumnWidth); williamr@2: williamr@2: /** williamr@2: * Overloaded @c MoveCursorL method to process cursor movement according to williamr@2: * orientation of the grid. williamr@2: * @param aCursorMovement The cursor movement to apply williamr@2: * etc. @c ECursorNextItem and @c ECursorPreviousItem. williamr@2: * @param aSelectionMode The selection mode of the calling list box. williamr@2: */ williamr@2: IMPORT_C virtual void MoveCursorL( williamr@2: TCursorMovement aCursorMovement, williamr@2: TSelectionMode aSelectionMode); williamr@2: williamr@2: /** williamr@2: * This function draws every visible item into the specified rectangle. williamr@2: * As implemented in @c CListBoxView, this function's argument is ignored williamr@2: * and the internal viewing rectangle is used. See @c SetViewRect(). williamr@2: * @param @c TRect* @c aClipRect = @c NULL The rectangle to draw into. williamr@2: */ williamr@2: IMPORT_C virtual void Draw(const TRect* aClipRect = NULL) const; williamr@2: williamr@2: /** williamr@2: * This has been overloaded to ensure that only valid cells are drawn and williamr@2: * not the empty cells. williamr@2: * @param aItemIndex Index number of the item to draw. williamr@2: */ williamr@2: IMPORT_C virtual void DrawItem(TInt aItemIndex) const; williamr@2: williamr@2: /** williamr@2: * This function gets the position of the top left corner of the specified williamr@2: * item, in pixels. williamr@2: * @param aItemIndex An item in the model. williamr@2: * @return @c TPoint position of the top left corner of the item, in pixels. williamr@2: */ williamr@2: IMPORT_C virtual TPoint ItemPos(TInt aItemIndex) const; williamr@2: williamr@2: /** williamr@2: * This function has been overloaded to draw items correctly. Recalculates williamr@2: * the bottom item’s index. This is called by the list box control when williamr@2: * either the size or the number of items in its model changes. williamr@2: */ williamr@2: IMPORT_C virtual void CalcBottomItemIndex(); williamr@2: williamr@2: /** williamr@2: * This function gets the item the view would need to be moved to in order williamr@2: * to make the specified item visible. williamr@2: * @param aItemIndex The item to make visible. williamr@2: * @return The item to scroll to to make @c aItemIndex visible. williamr@2: */ williamr@2: IMPORT_C virtual TInt CalcNewTopItemIndexSoItemIsVisible(TInt aItemIndex) const; williamr@2: williamr@2: /** williamr@2: * This function draws every item between the start and end indices williamr@2: * inclusively. williamr@2: * @param aStartItemIndex The first item to draw. williamr@2: * @param aEndItemIndex The final item to draw. williamr@2: */ williamr@2: IMPORT_C virtual void DrawItemRange(TInt aStartItemIndex, TInt aEndItemIndex) const; williamr@2: williamr@2: /** williamr@2: * This function gets the width of all columns in the view. williamr@2: * @return The width of all columns in the view, in pixels. williamr@2: */ williamr@2: inline TInt ColumnWidth() const; williamr@2: williamr@2: /** williamr@2: * Sets which item appears at the top left corner of the view. The function williamr@2: * changes items displayed in the view appropriately. williamr@2: * @param aItemIndex Index of the item to set at the top left. williamr@2: */ williamr@2: IMPORT_C virtual void SetTopItemIndex(TInt aItemIndex); williamr@2: williamr@2: /** williamr@2: * This function sets item height in pixels. williamr@2: * @param aItemHeight New height in pixels for this view’s items. williamr@2: */ williamr@2: IMPORT_C virtual void SetItemHeight(TInt aItemHeight); williamr@2: williamr@2: /* williamr@2: * This function converts an (x, y) pixel position to an item index. williamr@2: * @param aPosition Pixel position in the viewing rectangle. williamr@2: * @param aItemIndex Reference to the item index. williamr@2: * @return Whether there was an item at aPosition. williamr@2: */ williamr@2: IMPORT_C virtual TBool XYPosToItemIndex(TPoint aPosition, TInt& aItemIndex) const; williamr@2: williamr@2: /** williamr@2: * Calculates the data width in columns. @c iDataWidth is calculated based on williamr@2: * model and drawer information. williamr@2: */ williamr@2: IMPORT_C virtual void CalcDataWidth(); williamr@2: williamr@2: /** williamr@2: * Gets the visible width of the specified rectangle in pixels. williamr@2: * @param aRect Reference to the rectangle for which to get the visible williamr@2: * width. williamr@2: * @return Visible width of aRect in pixels. williamr@2: */ williamr@2: IMPORT_C virtual TInt VisibleWidth(const TRect& aRect) const; williamr@2: williamr@2: /** williamr@2: * Makes the specified item visible by moving the view location and williamr@2: * redrawing the control. Index of the item to make visible. williamr@2: * @param aItemIndex Index of the item to make visible. williamr@2: * @return @c ETrue if the control was redrawn, @c EFalse if no redraw williamr@2: * happened (i.e. the item was already visible, or redraw was disabled). williamr@2: */ williamr@2: IMPORT_C virtual TBool ScrollToMakeItemVisible(TInt aItemIndex); williamr@2: williamr@2: /** williamr@2: * Gets the number of columns that this view would need to be scrolled by williamr@2: * to make the specified item visible. The function returns 0 if no williamr@2: * scrolling is needed. @c ScrollToMakeItemVisible() uses this function. williamr@2: * @param aItemIndex Item to make visible. williamr@2: * @return The number of columns to scroll, or zero if no scrolling is williamr@2: * needed. williamr@2: */ williamr@2: IMPORT_C virtual TInt CalculateHScrollOffsetSoItemIsVisible(TInt aItemIndex); williamr@2: williamr@2: /** williamr@2: * Gets the size of the specified item. williamr@2: * @param aItemIndex=0 The index of the item whose size this call is to get. williamr@2: * @return @c TSize The size of the item in pixels. williamr@2: */ williamr@2: IMPORT_C virtual TSize ItemSize(TInt aItemIndex=0) const; williamr@2: williamr@2: /** williamr@2: * Converts an item index into the (row, column) pair describing that item. williamr@2: * @param aItemIndex The item index. williamr@2: * @param aRowIndex Reference to the row index. williamr@2: * @param aColIndex Reference the column index. williamr@2: */ williamr@2: IMPORT_C void CalcRowAndColIndexesFromItemIndex(TInt aItemIndex, TInt& aRowIndex, TInt& aColIndex) const; williamr@2: williamr@2: /** williamr@2: * This function converts a row/column pair into the item index for that williamr@2: * item. williamr@2: * @param aItemIndex Reference to the item index. williamr@2: * @param aRowIndex Row index of the item. williamr@2: * @param aColIndex Column index of the item. williamr@2: */ williamr@2: IMPORT_C void CalcItemIndexFromRowAndColIndexes(TInt& aItemIndex, TInt aRowIndex, TInt aColIndex) const; williamr@2: williamr@2: protected: // code moved from CSnakingListBoxView williamr@2: /** williamr@2: * This function draws every item in every column between the start and end williamr@2: * columns inclusively. williamr@2: * @param aStartColIndex The first column to draw. williamr@2: * @param aEndColIndex The last column to draw. williamr@2: */ williamr@2: IMPORT_C void DrawColumnRange(TInt aStartColIndex, TInt aEndColIndex) const; williamr@2: williamr@2: /** williamr@2: * This function clears each item’s rectangle between the specified start williamr@2: * and finish item’s indexes. williamr@2: * @param aStartItemIndex The first item to clear. williamr@2: * @param aEndItemIndex The last item to clear. williamr@2: */ williamr@2: IMPORT_C void ClearUnusedItemSpace(TInt aStartItemIndex, TInt aEndItemIndex) const; williamr@2: williamr@2: /** williamr@2: * This function updates the horizontal scroll offset (iHScrollOffset) williamr@2: * based on the top item’s index. This function is called internally by williamr@2: * @c CEikSnakingListBoxes when needed. williamr@2: */ williamr@2: IMPORT_C void UpdateHScrollOffsetBasedOnTopItemIndex(); williamr@2: williamr@2: protected: williamr@2: /** williamr@2: * This inline function is grid model helper. williamr@2: * @return A pointer to @c CAknGridM object. williamr@2: */ williamr@2: inline CAknGridM* GridModel() const; williamr@2: williamr@2: /** williamr@2: * This function handles movement routines. williamr@2: * @param aCursorMovement Handles cursor movements etc. @c ECursorNextItem williamr@2: * and @c ECursorPreviousItem. williamr@2: * @param aSelectionMode Modes for modifying the selection. williamr@2: */ williamr@2: IMPORT_C void DoMoveL(TCursorMovement aCursorMovement, TSelectionMode aSelectionMode); williamr@2: williamr@2: private: williamr@2: // movement handling routines williamr@2: IMPORT_C TInt SearchByLines(TInt aX, TInt aY, TCursorMovement aCursorMovement, TBool aBeginSearchOnIndex = EFalse); williamr@2: IMPORT_C TInt FindNextItem(TInt aItemIndex, TBool aLookDown, TBool aLookRight, TBool aFirstLookHorizontal, TBool aBeginSearchOnIndex = EFalse); williamr@2: TBool IsEdgePassed(TInt aItemIndex, TBool aLookDown, TBool aLookRight, TBool aFirstLookHorizontal, TBool aBeginSearchOnIndex, TInt& aNewIndex); williamr@2: williamr@2: TBool IsMoveRight(TCursorMovement aCursorMovement); williamr@2: TBool IsMoveDown(TCursorMovement aCursorMovement); williamr@2: private: // overridden from CListBoxView williamr@2: IMPORT_C virtual TAny* Reserved_1(); williamr@2: williamr@2: private: williamr@2: williamr@2: /** williamr@2: * Draws the portion of the grid view rectangle that contains no items. williamr@2: */ williamr@2: void DrawUnusedViewPortion() const; williamr@2: williamr@2: private: williamr@2: TScrollingType iScrollingType; williamr@2: TScrollingType iScrollInSecondaryDimension; williamr@2: williamr@2: SGrid iGridDetails; williamr@2: TInt iSpare[2]; williamr@2: }; williamr@2: williamr@2: inline CAknGridM* CAknGridView::GridModel() const williamr@2: { williamr@2: return STATIC_CAST(CAknGridM*,iModel); williamr@2: } williamr@2: williamr@2: inline TInt CAknGridView::ColumnWidth() const williamr@2: { return iGridDetails.iSizeOfItems.iWidth; } williamr@2: williamr@2: #endif // __AKNGRIDVIEW_H__