javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/inc/swtlistview.h
branchRCL_3
changeset 14 04becd199f91
child 17 0fd27995241b
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - S60 implementation
       
    10  *******************************************************************************/
       
    11  
       
    12 
       
    13 #ifndef SWTLISTVIEW_H
       
    14 #define SWTLISTVIEW_H
       
    15 
       
    16 
       
    17 #include <eiklbo.h>
       
    18 #include "eswtmobileextensions.h"
       
    19 #include "swtscrollablebase.h"
       
    20 #include "swtscrollbar.h"
       
    21 
       
    22 
       
    23 class CAknIconArray;
       
    24 class CSelectionIndexArray;
       
    25 class CSwtGrid;
       
    26 class CAknGridM;
       
    27 class CAknGridView;
       
    28 class CSwtControlMenu;
       
    29 class CSwtMenu;
       
    30 class CSwtMenuItem;
       
    31 
       
    32 
       
    33 /**
       
    34  * CSwtListView
       
    35  * This class implements the eSWT ListView on S60 platform
       
    36  * @lib eswt
       
    37  */
       
    38 NONSHARABLE_CLASS(CSwtListView)
       
    39         : public CAknControl
       
    40         , public ASwtScrollableBase
       
    41         , public MSwtListView
       
    42         , public MEikCommandObserver
       
    43         , public MEikListBoxObserver
       
    44 {
       
    45 public:
       
    46     static CSwtListView* NewL(MSwtDisplay& aDisplay, TSwtPeer aPeer,
       
    47     MSwtComposite& aParent, TInt aStyle);
       
    48     static CSwtListView* NewLC(MSwtDisplay& aDisplay, TSwtPeer aPeer,
       
    49                                MSwtComposite& aParent, TInt aStyle);
       
    50     virtual ~CSwtListView();
       
    51     void ScrollViewToShowAsManyItemsAsPossibleL();
       
    52     TInt ScrollBarBreadth(const CEikScrollBar* aBar);
       
    53 
       
    54 // From CCoeControl
       
    55     CCoeControl*    ComponentControl(TInt aIndex) const;
       
    56     TInt            CountComponentControls() const;
       
    57     void            SizeChanged();
       
    58     void            PositionChanged();
       
    59     void            HandleResourceChange(TInt aType);
       
    60     void            FocusChanged(TDrawNow aDrawNow);
       
    61     TKeyResponse    OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
       
    62     void            MakeVisible(TBool aVisible);
       
    63     void            SetDimmed(TBool aDimmed);
       
    64     TTypeUid::Ptr   MopSupplyObject(TTypeUid aId);
       
    65 
       
    66 private:
       
    67     void            Draw(const TRect& aRect) const;
       
    68 
       
    69 // From MSwtListView
       
    70 public:
       
    71     MSwtScrollable* Scrollable();
       
    72     void            AppendL(const TDesC& aPtr, const MSwtImage* aImage);
       
    73     void            InsertL(TInt aPos, const TDesC& aPtr, const MSwtImage* aImage);
       
    74     void            DeselectItem(TInt aIndex);
       
    75     void            DeselectRange(TInt aStart, TInt aEnd);
       
    76     void            DeselectItems(const TInt* aIndices, TInt aCount);
       
    77     void            DeselectAll();
       
    78     TInt            GetFocusIndex() const;
       
    79     void            GetItemL(TInt aItemIndex, TPtrC& aString) const;
       
    80     TPoint          GetIconSize(TInt aStyle) const;
       
    81     TInt            GetItemCount() const;
       
    82     CPtrCArray*     GetItemsL() const;
       
    83     CPtrCArray*     GetSelectionL() const;
       
    84     TInt            GetSelectionCount() const;
       
    85     const           CArrayFix<TInt>* GetSelectionIndices() const;
       
    86     TInt            GetTopIndex() const;
       
    87     TInt            IndexOf(const TDesC& aString, TInt& aStart) const;
       
    88     TBool           IsSelected(TInt aIndex) const;
       
    89     void            RemoveItemL(TInt aIndex);
       
    90     void            RemoveRangeL(TInt aStart, TInt aEnd);
       
    91     void            RemoveItemsL(const TInt* aIndices, TInt aCount);
       
    92     void            RemoveAllL();
       
    93     void            SelectItemL(TInt aIndex, TBool aScroll);
       
    94     void            SelectRangeL(TInt aStart, TInt aEnd);
       
    95     void            SelectAllL();
       
    96     void            SetItemsL(MDesCArray* aStringArray, RPointerArray<MSwtImage>& aImagesArray);
       
    97     void            SetLayoutL(TInt aLayout);
       
    98     void            SetLayoutDensityL(TInt aDensity);
       
    99     void            ShowSelection();
       
   100     void            SetFocusIndex(TInt aIndex);
       
   101 
       
   102 // From ASwtScrollableBase
       
   103     CEikScrollBarFrame* SbFrame() const;
       
   104     void SetVisibleScrollBar(TInt aStyle, TBool aVisible);
       
   105     void ScrollBarDestroyed(const MSwtScrollBar* aScrollBar);
       
   106 #if defined( RD_SCALABLE_UI_V2)
       
   107     void HandleScrollEventL(CEikScrollBar* aScrollBar,
       
   108                             TEikScrollEvent aEventType);
       
   109 #endif
       
   110 
       
   111 // From MSwtControl
       
   112     CCoeControl&    CoeControl();
       
   113     const           CCoeControl& CoeControl() const;
       
   114     void            ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
       
   115     TRgb            GetBackground() const;
       
   116     TRgb            GetForeground() const;
       
   117     void            SetBackgroundL(const MSwtColor* aColor);
       
   118     void            SetForegroundL(const MSwtColor* aColor);
       
   119     TSize           ComputeSizeL(TInt aWHint, TInt aHHint);
       
   120     TBool           IsKeyUsed(TUint aKeyCode) const;
       
   121     TBool           MSKSelCmdEnabled() const;
       
   122     const MSwtMenu* GetControlMenu() const;
       
   123     void            UpdateDoNotDrawFlag();
       
   124     HBufC*          MSKLabelL() const;
       
   125 #if defined( RD_SCALABLE_UI_V2)
       
   126     void            HandlePointerEventL(const TPointerEvent& aPointerEvent);
       
   127     const MSwtMenu* GetStylusPopupControlMenu() const;
       
   128 #endif
       
   129 
       
   130 // From MEikCommandObserver
       
   131 public:
       
   132     void ProcessCommandL(TInt aCmdId);
       
   133 
       
   134 // From MEikListBoxObserver
       
   135 public:
       
   136     void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
       
   137 
       
   138 // Own methods
       
   139 private:
       
   140     CSwtListView(MSwtDisplay& aDisplay, TSwtPeer aPeer, MSwtComposite& aParent, TInt aStyle);
       
   141     void ConstructL();
       
   142 
       
   143     enum TSwtListViewDensity
       
   144     {
       
   145         ELowListViewDensity     = 1,
       
   146         EMediumListViewDensity  = 2,
       
   147         EHighListViewDensity    = 3
       
   148     };
       
   149 
       
   150     void            ApplyGridCellLayoutL();
       
   151     CDesCArray*     GetTextArray() const;
       
   152     CAknIconArray*  GetIconArray() const;
       
   153     CAknGridM*      GetGridModel() const;
       
   154     CAknGridView*   GetGridView() const;
       
   155     CGulIcon*       CreateIconL(const MSwtImage* aIcon) const;
       
   156     void            DoGridCellLayoutL(const TSwtListViewDensity& aDensity);
       
   157     void            LoadLayouts(const TSwtListViewDensity& aDensity, TSize& aCellSize, TRect& aIconRect, TRect& aSelRect, TRect& aTextRect, TInt& aTextCellFontId);
       
   158     void            CalcRowsColumns(const TSize& aCellSize, TInt& aXCells, TInt& aYCells) const;
       
   159     void            AddTextL(const TDesC& aPtr, const TInt& aPos);
       
   160     void            AddIconL(const MSwtImage* aImage, const TInt& aPos);
       
   161     void            AddItemL(const TDesC& aPtr, const MSwtImage* aImage, const TInt& aPos);
       
   162     void            UpdateIconIndexL(const TInt& arrayIndex);
       
   163     void            UpdateSelectionIndexesL(TInt aStart, TInt aEnd, TBool aItemsAdded);
       
   164     void            UntabifyL(RBuf& aAll);
       
   165     TInt            GetCaption(const TInt& aIndex, TPtrC& aTxt) const;
       
   166     void            SingleSelectL(const TInt& aIndex, TBool aScroll);
       
   167     void            SingleOrMultiSelectL(const TInt& aIndex, TBool aScroll);
       
   168     void            UpdateTextColorL();
       
   169     CGulIcon*       GetMarkedItemIconL();
       
   170     void            HandleResourceChangeL(TInt aType);
       
   171     void            SizeChangedL();
       
   172     TInt            ItemIconIndex(const TInt& aItemPos);
       
   173     void            UpdateControlMenu();
       
   174     TInt            GetBorderSize(const TInt& aAlignment) const;
       
   175     TSize           GetCellSize() const;
       
   176     TUint           ISqrt(TUint x);
       
   177     TInt            GetRowColumnCount(const TInt& aItemCount, const TInt& aRowColumnCount) const;
       
   178     void            UpdateMSKLabelL();
       
   179     void            LayoutCell(const TRect& aCellRect, TRect& aTextRect, TRect& aIconRect, TRect& aSelRect);
       
   180     void            UpdateSetItemCount(const TInt& textChange, const TInt& iconChange);
       
   181     void            DoGridCellLayoutIfNeededL();
       
   182     void            UpdateRemovedItemCountersL(const TInt& aIndex);
       
   183     void            GetSelection(CArrayFix<TInt>* aSelectionArray) const;
       
   184     TInt            GetSelectionL(const TInt aIndex) const;
       
   185     void            SetSelectionL(const CArrayFix<TInt>* aSelectionArray) const;
       
   186     void            UpdateImageSizes(const TSize& aNewMaxSize);
       
   187     void            RemoveImageRef(const TInt& aIndex);
       
   188     void            GetCellVariants(const TSwtListViewDensity& aDensity,
       
   189                                     TInt& aCellVariant, TInt& aSubcellVariantG1,
       
   190                                     TInt& aSubcellVariantG2, TInt& aSubcellVariantT) const;
       
   191     void            UpdateIconSizes(const TSwtListViewDensity& aDensity,
       
   192                                     const TRect& aCellRect);
       
   193     void            GetLafFacadeRectIds(
       
   194         const TSwtListViewDensity& aDensity,
       
   195         CSwtLafFacade::TSwtLafFacadeRectId& aRectIdPane,
       
   196         CSwtLafFacade::TSwtLafFacadeRectId& aRectIdPaneG1,
       
   197         CSwtLafFacade::TSwtLafFacadeRectId& aRectIdPaneG2,
       
   198         CSwtLafFacade::TSwtLafFacadeTextId& aRectIdPaneT1,
       
   199         CSwtLafFacade::TSwtLafFacadeFontId& aRectIdPaneT1Font
       
   200     ) const;
       
   201     void            CoerceCellRect(const TSwtListViewDensity& aDensity, 
       
   202                                    TRect& aCellRect) const;
       
   203 
       
   204 #ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK
       
   205 public:
       
   206     void DoControlSpecificFeedback(
       
   207         const TBool& aFirstTap,
       
   208         const TBool& aTappedToChildRect,
       
   209         const TPointerEvent& aPointerEvent) const;
       
   210 #endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK
       
   211 
       
   212 private: // data
       
   213 
       
   214     /**
       
   215      * Cell layout params for the grid.
       
   216      */
       
   217     TBool   iVerticalOrientation;
       
   218     TBool   iLeftToRight;
       
   219     TBool   iTopToBottom;
       
   220     TInt    iNumOfRows;
       
   221     TInt    iNumOfColumns;
       
   222     TInt    iWidthOfSpaceBetweenItems;
       
   223     TInt    iHeightOfSpaceBetweenItems;
       
   224 
       
   225     /**
       
   226      * The current density.
       
   227      */
       
   228     TSwtListViewDensity iDensity;
       
   229 
       
   230     /**
       
   231      * Icon sizes for getIconSize
       
   232      */
       
   233     TPoint iIconSizeInLowDensity;
       
   234     TPoint iIconSizeInMediumDensity;
       
   235     TPoint iIconSizeInHighDensity;
       
   236 
       
   237     /**
       
   238      * Number of non-NULL icons and texts
       
   239      */
       
   240     TInt iNumberOfTexts;
       
   241     TInt iNumberOfIcons;
       
   242 
       
   243     /**
       
   244      * The control menu.
       
   245      * Owned.
       
   246      */
       
   247     CSwtControlMenu* iMenu;
       
   248 
       
   249     /**
       
   250      * The control menu submenu.
       
   251      * Owned.
       
   252      */
       
   253     CSwtControlMenu* iSubMenu;
       
   254 
       
   255     /**
       
   256     * The control menu items.
       
   257     * Owned.
       
   258     */
       
   259     CSwtMenuItem* iMenuItemEditList;
       
   260     CSwtMenuItem* iMenuItemMarkUnmark;
       
   261     CSwtMenuItem* iMenuItemMarkAll;
       
   262     CSwtMenuItem* iMenuItemUnmarkAll;
       
   263 
       
   264     /**
       
   265      * The strings for mark/unmark command and its state.
       
   266      */
       
   267     TBool iIsMarkDisplayed;
       
   268     HBufC* iMarkString;
       
   269     HBufC* iUnmarkString;
       
   270 
       
   271     /**
       
   272      * The Selection array before a key event, for multiselection only.
       
   273      * Own.
       
   274      */
       
   275     CArrayFix<TInt>* iOldSelectionArray;
       
   276 
       
   277     /**
       
   278      * The Selection array for handling selection indexes with mirrored layout.
       
   279      * Own.
       
   280      */
       
   281     CArrayFix<TInt>* iSelectionArray;
       
   282 
       
   283     /**
       
   284      * The colors used to draw text and background.
       
   285      * Not own.
       
   286      */
       
   287     const MSwtColor* iTextColor;
       
   288     const MSwtColor* iBgColor;
       
   289 
       
   290     /**
       
   291      * Referenced images as the ListView does not copy the bitmaps it uses.
       
   292      */
       
   293     RPointerArray<const MSwtImage> iRefImages;
       
   294 
       
   295     /**
       
   296      * Maximum image size for the current layout.
       
   297      */
       
   298     TSize iMaxImageSize;
       
   299 
       
   300     /**
       
   301      * The grid control.
       
   302      * Own.
       
   303      */
       
   304     CSwtGrid* iGrid;
       
   305 
       
   306     /**
       
   307      * Deliver all pointer event to the scrollbar when this on.
       
   308      */
       
   309     TBool iVScrollBarGrabsPointerEvents;
       
   310 
       
   311 #ifdef RD_SCALABLE_UI_V2
       
   312     /**
       
   313      * The control menu for stylus popup.
       
   314      * Owned.
       
   315      */
       
   316     CSwtControlMenu* iStylusPopupMenu;
       
   317 
       
   318     /**
       
   319      * The control menu items fro stylus popup.
       
   320      * Owned.
       
   321      */
       
   322     CSwtMenuItem* iStylusPopupMarkAll;
       
   323     CSwtMenuItem* iStylusPopupUnmarkAll;
       
   324 #endif //RD_SCALABLE_UI_V2    
       
   325 
       
   326     /**
       
   327      * Stores last known focus index. Use only during paint and key handlers.
       
   328      */
       
   329     TInt iPrevFocusIndex;
       
   330 
       
   331     /**
       
   332      * Stores grid cell layout update status
       
   333      */
       
   334     TBool iIsGridCellLayoutNeeded;
       
   335     
       
   336     /**
       
   337      * View visible rect at last draw
       
   338      */
       
   339     mutable TRect iLastViewVisibleRect;
       
   340 };
       
   341 
       
   342 
       
   343 #endif // SWTLISTVIEW_H