javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/inc/swttable.h
branchRCL_3
changeset 19 04becd199f91
child 34 71c436fe3ce0
equal deleted inserted replaced
16:f5050f1da672 19: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 SWTTABLE_H
       
    14 #define SWTTABLE_H
       
    15 
       
    16 
       
    17 #include "eswtwidgetsexpanded.h"
       
    18 #include "swtscrollablebase.h"
       
    19 #include "swtcomposite.h"
       
    20 
       
    21 
       
    22 class MSwtTableItem;
       
    23 class MSwtTableColumn;
       
    24 class CSwtTableListBox;
       
    25 class CSwtImageTextItem;
       
    26 class TSwtTableMargins;
       
    27 class CSwtTableHeader;
       
    28 
       
    29 
       
    30 /**
       
    31  *  This class implements the native peer of Table.
       
    32  *  Table is implemented as a compound control with 2 components:
       
    33  *  a listbox control and a column header control.
       
    34  *  @lib eswt.dll
       
    35  */
       
    36 NONSHARABLE_CLASS(CSwtTable)
       
    37         : public CSwtComposite
       
    38         , public MSwtTable
       
    39         , public MCoeControlObserver
       
    40 {
       
    41 public:
       
    42     /**
       
    43      * Two-phased constructor.
       
    44      * @param aDisplay  The display object
       
    45      * @param aPeer     The Java peer of the table
       
    46      * @param aParent   The parent Composite of the table
       
    47      * @param aStyle    The style flags given to the table Java constructor
       
    48      */
       
    49     static CSwtTable* NewL(MSwtDisplay& aDisplay, TSwtPeer aPeer,
       
    50     MSwtComposite& aParent, TInt aStyle);
       
    51 
       
    52     /**
       
    53     * Destructor.
       
    54     */
       
    55     virtual ~CSwtTable();
       
    56 
       
    57     /**
       
    58      * Returns the component listbox items.
       
    59      * @return An array of items.
       
    60      */
       
    61     const RPointerArray<CSwtImageTextItem>& GetImageTextItems() const;
       
    62 
       
    63     /**
       
    64      * A helper for posting a selection event for an item in the Table.
       
    65      * @param aDetail       Detail code for the event.
       
    66      * @param aItemIndex    The index of the selected item.
       
    67      */
       
    68     void PostSelectionEventL(TInt aDetail, TInt aItemIndex) const;
       
    69 
       
    70     /**
       
    71      * A helper for posting a default selection event for an item in the Table.
       
    72      * @param The index of the selected item.
       
    73      */
       
    74     void PostDefaultSelectionEventL(TInt aItemIndex) const;
       
    75 
       
    76     /**
       
    77      * A helper for posting a selection event for a column in the Table.
       
    78      * @param The native peer of the selected column.
       
    79      */
       
    80     void PostColumnSelectionEventL(TSwtPeer aColumn) const;
       
    81 
       
    82     /**
       
    83      * A helper for posting a resize event for a column in the Table.
       
    84      * @param The native peer of the selected column.
       
    85      */
       
    86     void PostColumnResizeEventL(TSwtPeer aColumn) const;
       
    87 
       
    88     /**
       
    89      * A helper for posting a move event for a column in the Table.
       
    90      * @param The native peer of the selected column.
       
    91      */
       
    92     void PostColumnMoveEventL(TSwtPeer aColumn) const;
       
    93 
       
    94     /**
       
    95      * Returns the position and extent of the header.
       
    96      * @return The header rectangle.
       
    97      */
       
    98     TRect GetHeaderRect() const;
       
    99 
       
   100     /**
       
   101      * Return the margins common to all items.
       
   102      * @return The margins to use in the currently active layout.
       
   103      */
       
   104     TSwtTableMargins GetMargins() const;
       
   105 
       
   106     /**
       
   107      * Return the checkbox size common to all items.
       
   108      * @return The checkbox size to use in the currently active layout.
       
   109      */
       
   110     TSize GetCheckBoxSize() const;
       
   111 
       
   112     /**
       
   113      * Return the checkbox bitmaps common to all items.
       
   114      * @param aChecked  True if the checked state bitmap should be returned, false for unchecked
       
   115      * @param aBitmap   aBitmap Returned checkbox bitmap. Owned by this class.
       
   116      * @param aMask     aMask   Returned checkbox mask. Owned by this class.
       
   117      */
       
   118     void GetCheckBoxBitmaps(const TBool& aChecked, const CFbsBitmap** aBitmap,
       
   119                             const CFbsBitmap** aMask) const;
       
   120 
       
   121     /**
       
   122      * Gets index of an item by its CSwtImageTextItem pointer.
       
   123      * @param aItem The pointer.
       
   124      * @return      The index. -1 if not found.
       
   125      */
       
   126     TInt IndexOfTableItem(const CSwtImageTextItem* aItem) const;
       
   127 
       
   128     /**
       
   129      * Returns the highlighted text color rgb value to use in the currently active layout.
       
   130      * @return The rgb value.
       
   131      */
       
   132     TRgb GetHighlightTextRgb() const;
       
   133 
       
   134     /**
       
   135      * Returns if the table background has a custom color set for it.
       
   136      * @return True if a custom color has been set, false otherwise.
       
   137      */
       
   138     TBool BackgroundSet() const;
       
   139 
       
   140     /**
       
   141      * Returns if the item at the specified index has been checked.
       
   142      * Items can only be checked in KSwtStyleCheck style table.
       
   143      * @param aIndex    The index of the item to query.
       
   144      * @return          True if the item has been checked, false otherwise.
       
   145      */
       
   146     TBool IsChecked(const TInt& aIndex) const;
       
   147 
       
   148     /**
       
   149      * Checks the item at the specified index.
       
   150      * Items can only be checked in KSwtStyleCheck style table.
       
   151      * @param aIndex    The index of the item to check.
       
   152      */
       
   153     void CheckItem(const TInt& aIndex);
       
   154 
       
   155     /**
       
   156      * Unchecks the item at the specified index.
       
   157      * Items can only be checked in KSwtStyleCheck style table.
       
   158      * @param aIndex    The index of the item to uncheck.
       
   159      */
       
   160     void UncheckItem(const TInt& aIndex);
       
   161 
       
   162     /**
       
   163      * @return True if the table is operating in list-mode (no TableColumns).
       
   164      */
       
   165     TBool ListMode() const;
       
   166 
       
   167     /**
       
   168      * Unchecks the item at the specified index.
       
   169      * Items can only be checked in KSwtStyleCheck style table.
       
   170      * @param aHScrollOffset
       
   171      */
       
   172     void UpdateHeaderHScrollOffset(const TInt& aHScrollOffset);
       
   173 
       
   174     /**
       
   175      * Notifies the Table compound control that the default font in the component
       
   176      * list box has changed.
       
   177      */
       
   178     void ListBoxDefaultFontChanged();
       
   179 
       
   180     /**
       
   181      * Get notified by the contained listbox about kinetic scrolling
       
   182      */
       
   183     void HandlePhysics(TBool aStatus);
       
   184 
       
   185     /**
       
   186      * If a fg colors has been set, get its rgb otherwise get NULL.
       
   187      */
       
   188     const TRgb* CustomForeground() const;
       
   189 
       
   190 // from base class CCoeControl
       
   191 
       
   192     TInt            CountComponentControls() const;
       
   193     CCoeControl*    ComponentControl(TInt aIndex) const;
       
   194     void            SizeChanged();
       
   195     void            HandleResourceChange(TInt aType);
       
   196     TKeyResponse    OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
       
   197     void            FocusChanged(TDrawNow aDrawNow);
       
   198     TTypeUid::Ptr   MopSupplyObject(TTypeUid aId);
       
   199     void            Draw(const TRect& aRect) const;
       
   200 
       
   201 // from base class MSwtTable
       
   202 
       
   203     CSwtPeerArray*  GetTableItemsL();
       
   204     CSwtPeerArray*  GetTableColumnsL();
       
   205     const RArray<TInt>& GetColumnWidths() const;
       
   206     const RArray<TInt>& GetColumnAlignments() const;
       
   207     const RArray<TInt>& GetColumnImageCounts() const;
       
   208     MSwtComposite*  Composite();
       
   209     void            AddTableItemL(MSwtTableItem& aChild, TInt aRowIndex);
       
   210     void            AddTableColumnL(MSwtTableColumn& aChild, TInt aColumnIndex);
       
   211     void            RemoveTableColumn(MSwtTableColumn& aChild);
       
   212     void            DeselectItems(const TInt* aIndices, TInt aCount);
       
   213     void            DeselectRange(TInt aStart, TInt aEnd);
       
   214     TInt            IndexOfTableColumn(const MSwtTableColumn *aColumn) const;
       
   215     TInt            IndexOfTableItemAt(const MSwtTableItem *aItem, TInt aStart) const;
       
   216     TInt            IndexOfTableItem(const MSwtTableItem *aItem) const;
       
   217     TInt            GetColumnCount() const;
       
   218     TInt            GetTableColumnCount() const;
       
   219     TBool           GetHeaderVisible() const;
       
   220     TSwtPeer        GetItemL(TInt aIndex) const;
       
   221     TSwtPeer        GetColumnL(TInt aIndex) const;
       
   222     TInt            GetItemCount() const;
       
   223     TRect           GetItemRect(TInt aRowIndex) const;
       
   224     TBool           GetLinesVisible() const;
       
   225     TInt            GetSelectionIndex() const;
       
   226     TInt            GetSelectionCount() const;
       
   227     const CArrayFix<TInt>* GetSelectionIndicesL() const;
       
   228     const TSize&    ImageSize() const;
       
   229     void            NotifyImageAdded(TInt aColumnIndex);
       
   230     void            NotifyImageRemoved(TInt aColumnIndex);
       
   231     void            PackColumn(TInt aColumnIndex);
       
   232     void            RemoveItemL(TInt aIndex);
       
   233     void            RemoveRangeL(TInt aStart, TInt aEnd);
       
   234     void            RemoveItemsL(const TInt* aIndices, TInt aCount);
       
   235     void            RemoveAll();
       
   236     void            SelectItemL(TInt aIndex, TBool aScroll);
       
   237     void            SetHeaderVisible(TBool aShow);
       
   238     void            SetLinesVisible(TBool aShow);
       
   239     void            SelectRangeL(TInt aStart, TInt aEnd);
       
   240     void            SelectAllL();
       
   241     void            SetFocusIndex(TInt aIndex);
       
   242     void            ShowSelection();
       
   243     CSwtPeerArray*  GetSelectionL();
       
   244     TBool           IsSelected(TInt aIndex) const;
       
   245     TInt            GetTopIndex() const;
       
   246     void            SetTopIndex(TInt aIndex);
       
   247     void            SetColumnTextL(MSwtTableColumn& aTableColumn, const TDesC& aText);
       
   248     TInt            GetColumnWidth(TInt aColumnIndex) const;
       
   249     TInt            GetColumnAlignment(TInt aColumnIndex);
       
   250     void            SetColumnWidth(TInt aColumnIndex, TInt aWidth);
       
   251     void            SetColumnAlignment(TInt aColumnIndex, TInt aAlignment);
       
   252     void            SetTableImageSizeIfNotDefined(const TSize& aSize,
       
   253             const TBool& aAddedToItem = ETrue);
       
   254     void            UpdateItemHeight(const TInt& aChangedFontHeight);
       
   255     TInt            GetGridLineWidth() const;
       
   256     TInt            GetHeaderHeight() const;
       
   257     void            ShowTableColumn(MSwtTableColumn& aTableColumn);
       
   258     void            ShowTableItem(MSwtTableItem& aTableItem);
       
   259     TInt            GetItemHeight() const;
       
   260     TSwtPeer        GetItemFromPoint(TPoint &aPoint) const;
       
   261     const TRgb&     GetDefaultForeground() const;
       
   262     const TDesC&    GetColumnText(TInt aColumnIndex) const;
       
   263     void            SetColumnImage(TInt aColumnIndex, const MSwtImage* aImage);
       
   264 
       
   265 // from base class MSwtControl
       
   266 
       
   267     CCoeControl&        CoeControl();
       
   268     const CCoeControl&  CoeControl() const;
       
   269     TBool               IsFocusable(TInt aReason = KSwtFocusByApi) const;
       
   270     TInt                FocusBackgroundPolicy() const;
       
   271     TSize               ComputeSizeL(TInt aWHint, TInt aHHint);
       
   272     TInt                GetBorderWidth() const;
       
   273     TRect               ClientRect() const;
       
   274     void                ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
       
   275     TRgb                GetBackground() const;
       
   276     TRgb                GetForeground() const;
       
   277     void                SetBackgroundL(const MSwtColor* aColor);
       
   278     void                SetForegroundL(const MSwtColor* aColor);
       
   279     void                SetFontL(const MSwtFont* aFont);
       
   280     TBool               IsKeyUsed(TUint aKeyCode) const;
       
   281     TBool               MSKSelCmdEnabled() const;
       
   282     void                UpdateDoNotDrawFlag();
       
   283 
       
   284 // from base class ASwtScrollableBase
       
   285 
       
   286     CEikScrollBarFrame* SbFrame() const;
       
   287     TRect               SbInnerRect(const TRect& aRect) const;
       
   288     TRect               SbOuterRect(const TRect& aRect) const;
       
   289     void                ComputeTrim(TRect& aRect) const;
       
   290     void                HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType);
       
   291 
       
   292 // from base class CSwtComposite
       
   293 
       
   294     void RegisterChildL(MSwtControl& aChild);
       
   295 
       
   296 // from base class MCoeControlObserver
       
   297 
       
   298     void HandleControlEventL(CCoeControl *aControl, TCoeEvent aEventType);
       
   299 
       
   300 // from base class ASwtControlBase
       
   301 
       
   302 public:
       
   303     const MSwtFont& DefaultFont() const;
       
   304 protected:
       
   305     HBufC*          MSKLabelL() const;
       
   306 
       
   307 private:
       
   308 
       
   309     /**
       
   310      * The constructor.
       
   311      * @param aDisplay  The display object.
       
   312      * @param aPeer     The java peer table object.
       
   313      * @param aParent   The parent composite.
       
   314      * @param aStyle    The style flags passed to the Java constructor.
       
   315      */
       
   316     CSwtTable(MSwtDisplay& aDisplay, TSwtPeer aPeer, MSwtComposite& aParent, TInt aStyle);
       
   317 
       
   318     /**
       
   319      * 2nd phase constructor.
       
   320      */
       
   321     void ConstructL();
       
   322 
       
   323     /**
       
   324      * Gets the currently focused item index.
       
   325      * @return The index.
       
   326      */
       
   327     TInt GetFocusIndex() const;
       
   328 
       
   329     /**
       
   330      * Recalculates the layout for the whole control and applies the new layout.
       
   331      */
       
   332     void LayoutTable();
       
   333 
       
   334     /**
       
   335      * A leaving version of HandleResourceChange
       
   336      * @param aType The type param received in HandleResourceChange
       
   337      */
       
   338     void HandleResourceChangeL(TInt aType);
       
   339 
       
   340     /**
       
   341      * Loading of the scaled layout data.
       
   342      */
       
   343     void LoadLayouts();
       
   344 
       
   345     /**
       
   346      * Loading of the scaled & skinned graphic data.
       
   347      */
       
   348     void LoadGraphicsL();
       
   349 
       
   350     /*
       
   351      * Restores the selection indexes from the given array after items have been added or removed.
       
   352      * @param aStart            The starting index after which items were added or removed.
       
   353      * @param aSelectionArray   The selection array containing the selection indexes before
       
   354                                 adding/removing items.
       
   355      * @param aItemsAdded       True if items were added, false if removed.
       
   356      */
       
   357     void UpdateSelectionIndexesL(const TInt& aStart,
       
   358                                  const TInt& aEnd,
       
   359                                  CArrayFix<TInt>* aSelectionArray,
       
   360                                  const TBool& aItemsAdded);
       
   361 
       
   362     /**
       
   363      * Updates the middle-softkey label.
       
   364      */
       
   365     void UpdateMSKLabelL();
       
   366 
       
   367 private: // data
       
   368 
       
   369     /**
       
   370      * Header visibility state.
       
   371      */
       
   372     TBool iHeaderVisible;
       
   373 
       
   374     /**
       
   375      * The grid visibility state.
       
   376      */
       
   377     TBool iLinesVisible;
       
   378 
       
   379     /**
       
   380      * The unique size for all the images.
       
   381      */
       
   382     TSize iImageSize;
       
   383 
       
   384     /**
       
   385      * If a custom background color has been set for the table.
       
   386      */
       
   387     TBool iTableBackgroundSet;
       
   388 
       
   389     /**
       
   390      * The custom background color set to table.
       
   391      */
       
   392     TRgb iTableBackground;
       
   393 
       
   394     /**
       
   395      * If a custom foreground color has been set for the table.
       
   396      */
       
   397     TBool iTableForegroundSet;
       
   398 
       
   399     /**
       
   400      * The custom foreground color set to table.
       
   401      */
       
   402     TRgb iTableForeground;
       
   403 
       
   404     /**
       
   405      * The skinned default foreground color used for unset/null.
       
   406      */
       
   407     TRgb iTableDefaultForeground;
       
   408 
       
   409     /**
       
   410      * The skinned default highlight text color used if foreground is not set.
       
   411      */
       
   412     TRgb iTableDefaultHighlightText;
       
   413 
       
   414     /**
       
   415      * This array contains the width of each column.
       
   416      */
       
   417     RArray<TInt> iColumnWidths;
       
   418 
       
   419     /**
       
   420      * This array contains the alignment of each column.
       
   421      */
       
   422     RArray<TInt> iColumnAlignments;
       
   423 
       
   424     /**
       
   425      * This array contains the number of images in the items of each column.
       
   426      * The images in the header are not included in this count.
       
   427      */
       
   428     RArray<TInt> iColumnImagesCounts;
       
   429 
       
   430     /**
       
   431      * Scaled layout data common to all items.
       
   432      */
       
   433     TInt iHighlightTopBottomMargin;
       
   434     TInt iHighlightLeftRightMargin;
       
   435     TSize iCheckBoxSize;
       
   436     TInt iGridLineWidth;
       
   437 
       
   438     /**
       
   439      * The native listbox control.
       
   440      * Own.
       
   441      */
       
   442     CSwtTableListBox* iTableListBox;
       
   443 
       
   444     /**
       
   445      * The header of the table.
       
   446      * Own.
       
   447      */
       
   448     CSwtTableHeader* iHeader;
       
   449 
       
   450     /**
       
   451      * The array of drawable listbox items.
       
   452      * Not own.
       
   453      */
       
   454     RPointerArray<CSwtImageTextItem> iImageTextItems;
       
   455 
       
   456     /**
       
   457      * The array of native TableItem peers.
       
   458      * Not own.
       
   459      */
       
   460     RPointerArray<MSwtTableItem> iTableItems;
       
   461 
       
   462     /**
       
   463      * The array of native TableColumn peers.
       
   464      * Not own.
       
   465      */
       
   466     RPointerArray<MSwtTableColumn> iTableColumns;
       
   467 
       
   468     /**
       
   469      * The Selection array for storing the selection state, for multiselection only.
       
   470      * Own.
       
   471      */
       
   472     CArrayFix<TInt>* iOldSelectionArray;
       
   473 
       
   474     /**
       
   475      * Scaled & skinned graphics common to all items.
       
   476      * Own.
       
   477      */
       
   478     CFbsBitmap* iCheckBoxOffBitmap;
       
   479     CFbsBitmap* iCheckBoxOffMask;
       
   480     CFbsBitmap* iCheckBoxOnBitmap;
       
   481     CFbsBitmap* iCheckBoxOnMask;
       
   482 };
       
   483 
       
   484 #endif // SWTTABLE_H