widgetmanager/inc/wmlistbox.h
changeset 1 5315654608de
parent 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
0:f72a12da539e 1:5315654608de
     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 * Declares widget listbox for WidgetManager
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef ___WMLISTBOX_H__
       
    20 #define ___WMLISTBOX_H__
       
    21 
       
    22 // INCLUDES
       
    23 #include <eiklbi.h>
       
    24 #include <eiktxlbx.h>
       
    25 #include <eiktxlbm.h>
       
    26 #include <eikfrlb.h>
       
    27 #include <eiktxlbm.h>
       
    28 #include <aknlists.h>
       
    29 
       
    30 #include <touchfeedback.h>
       
    31 #include <touchlogicalfeedback.h>
       
    32 #include <aknlongtapdetector.h> 
       
    33 #include "wmwidgetdataobserver.h"
       
    34 #include "wmwidgetdata.h"
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 class CWmListBox;
       
    38 class CWmPlugin;
       
    39 class CListBoxView;
       
    40 class CFormattedCellListBoxData;
       
    41 class CAknLongTapDetector;
       
    42 class CWmListModel;
       
    43 class CWmWidgetData;
       
    44 class CAknStylusPopUpMenu;
       
    45 class MEikMenuObserver;
       
    46 
       
    47 // CLASS DECLARATIONS
       
    48 
       
    49 /**
       
    50  * CWmListItemDrawer
       
    51  */
       
    52 NONSHARABLE_CLASS( CWmListItemDrawer ): public CFormattedCellListBoxItemDrawer
       
    53 	{
       
    54 public:
       
    55     /** Two-phased constructor. */
       
    56 	static CWmListItemDrawer* NewL(
       
    57                 CWmPlugin& aWmPlugin,
       
    58                 MTextListBoxModel* aTextListBoxModel,
       
    59                 const CFont* aFont,
       
    60                 CFormattedCellListBoxData* aFormattedCellData,
       
    61                 CWmListBox* aListBox  );
       
    62 
       
    63     /** Destructor. */
       
    64     ~CWmListItemDrawer();
       
    65     
       
    66     /** Default logo image. */
       
    67     const CFbsBitmap* DefaultLogoImage();
       
    68     /** Default logo mask. */
       
    69     const CFbsBitmap* DefaultLogoMask();
       
    70     
       
    71 public:
       
    72 
       
    73     /**
       
    74      * from CFormattedCellListBoxItemDrawer:
       
    75      * draws a single list box item
       
    76      */
       
    77     void DrawItem(
       
    78                 TInt aItemIndex, TPoint aItemRectPos, 
       
    79                 TBool aItemIsSelected, TBool aItemIsCurrent, 
       
    80                 TBool aViewIsEmphasized, TBool aViewIsDimmed ) const;
       
    81     
       
    82 private:
       
    83     /** Constructor for performing 1st stage construction */
       
    84     CWmListItemDrawer( 
       
    85                 CWmPlugin& aWmPlugin,
       
    86                 MTextListBoxModel* aTextListBoxModel,  
       
    87                 const CFont* aFont,  
       
    88                 CFormattedCellListBoxData* aFormattedCellData,
       
    89                 CWmListBox* aListBox );
       
    90 
       
    91     /** 2nd phase constructor */
       
    92     void ConstructL();
       
    93 
       
    94     /**
       
    95      * re-calculates all rects, sizes and resizes bitmaps, that are
       
    96      * stored as members. Called from DrawItem if it is found that the
       
    97      * draw area size has changed from previous, resulting all stored
       
    98      * rectangles and bitmaps to invalidate.
       
    99      * @param aSize requested size of the item being drawn.
       
   100      */
       
   101     void CalculateRectangles( const TSize& aSize);
       
   102 
       
   103 	/**
       
   104 	* Draws a frame rectangle for an item.
       
   105 	* @param aOutterRect outter rectangle.
       
   106 	* @param aInnerRect inner rectangle.
       
   107 	* @param aID Skin item id. 
       
   108 	*/
       
   109 	void DrawFrame(
       
   110             const TRect& aOutterRect,
       
   111             const TRect& aInnerRect,
       
   112             const TAknsItemID& aID,
       
   113 			const TAknsItemID& aCenterID ) const;
       
   114 
       
   115 	/**
       
   116 	* Draws a rectangle for an item.
       
   117 	* @param aActualItemRect the rectangular area to be drawn.
       
   118 	*/
       
   119 	void DrawItemRect( const TRect& aActualItemRect ) const;
       
   120 
       
   121 private: // data members
       
   122 
       
   123     /** 
       
   124      * the plugin root (not owned) 
       
   125      */
       
   126     CWmPlugin& iWmPlugin;
       
   127 
       
   128     /** 
       
   129      * pointer to the list box data (not owned) 
       
   130      */
       
   131     CFormattedCellListBoxData* iCellData;
       
   132 
       
   133     /** 
       
   134      * pointer to the listbox (not owned) 
       
   135      */
       
   136     CWmListBox* iListBox;
       
   137 
       
   138     /** 
       
   139      * current font used in drawing (not owned) 
       
   140      */
       
   141     const CFont*    iFont;
       
   142 
       
   143     /** 
       
   144      * item size used in calculating all the rects and bitmaps 
       
   145      */
       
   146     TSize iCurrentSize;
       
   147 
       
   148     /** 
       
   149      * logo area (relative to item upper left corner) 
       
   150      */
       
   151     TRect iRelativeLogoRect;
       
   152     
       
   153     /** 
       
   154      * add button area (relative to item upper left corner) 
       
   155      */
       
   156     TRect iRelativeAddButtonRect;
       
   157     
       
   158     /** 
       
   159      * title area (relative to item upper left corner) 
       
   160      */
       
   161     TRect iRelativeTitleRect;
       
   162 
       
   163     /** 
       
   164      * add-button bitmap
       
   165      */
       
   166     CFbsBitmap*         iAddWidgetBtnImage;
       
   167     
       
   168     /** 
       
   169      * add-button mask 
       
   170      */
       
   171     CFbsBitmap*         iAddWidgetBtnMask;
       
   172     
       
   173     /** 
       
   174      * default logo (when widget does not have one) bitmap 
       
   175      */
       
   176     CFbsBitmap*         iDefaultLogoImage;
       
   177     
       
   178     /** 
       
   179      * default logo (when widget does not have one) mask 
       
   180      */
       
   181     CFbsBitmap*         iDefaultLogoImageMask;
       
   182     
       
   183 	};
       
   184 
       
   185 
       
   186 
       
   187 // CLASS DECLARATIONS
       
   188 /**
       
   189  * CWmListBox
       
   190  */
       
   191 NONSHARABLE_CLASS( CWmListBox ): public CAknDouble2LargeStyleListBox,
       
   192                       public MWmWidgetDataObserver
       
   193 	{
       
   194 public:
       
   195     
       
   196     /**
       
   197      * Two-phased constructor.
       
   198      */
       
   199 	static CWmListBox* NewL(
       
   200 	        CWmPlugin& aWmPlugin,
       
   201             const TRect& aRect,
       
   202             const CCoeControl* aParent,  
       
   203             TInt aFlags = 0 );
       
   204 
       
   205     /** Destructor. */
       
   206     ~CWmListBox();
       
   207 
       
   208 public: // API for manipulating list content
       
   209     
       
   210     /** Default Logo. */
       
   211     const CFbsBitmap* DefaultLogo();
       
   212     /** Default Logo mask. */
       
   213     const CFbsBitmap* DefaultMask();
       
   214 
       
   215     /** 
       
   216      * Findbox visibility
       
   217      * 
       
   218      * @param aVisibility sets find pane visibility
       
   219      */
       
   220     inline void SetFindPaneIsVisible( TBool aVisibility );
       
   221     
       
   222     /** 
       
   223      * Currently selected item index 
       
   224      * 
       
   225      * @return return currently selected item 
       
   226      */
       
   227     TInt CurrentListBoxItemIndex();
       
   228     
       
   229     /** 
       
   230      * real index for listbox item if findbox is active 
       
   231      * 
       
   232      * @return return index from original list for currently selected item
       
   233      */
       
   234     TInt RealIndex( TInt aIndex );
       
   235     
       
   236     /** 
       
   237      * number of items in the widget data array (also items on the list) 
       
   238      * 
       
   239      * @return count of widget data array
       
   240      */
       
   241     inline TInt WidgetDataCount();
       
   242     
       
   243     /** 
       
   244      * currently selected item
       
   245      * @return the selected item, or NULL if nothing selected
       
   246      */
       
   247     CWmWidgetData* WidgetData();
       
   248     
       
   249     /** 
       
   250      * gets an item by index 
       
   251      * 
       
   252      * @param aItemIndex index for item to return
       
   253      */
       
   254     CWmWidgetData& WidgetData( TInt aItemIndex );
       
   255 
       
   256     /**
       
   257      * gets the constant widget data array
       
   258      */
       
   259     inline const RWidgetDataValues& WidgetDataArray();
       
   260 
       
   261     /** 
       
   262      * inserts widget data to the model. Takes ownership of the object.
       
   263      * The widget data will appear to correct location in natural order:
       
   264      * - in previously saved position, if it has been viewed before
       
   265      *   (widget data must have a pointer to persistent widget order)
       
   266      * - in case this is a new widget, it will appear topmost
       
   267      * - in case there is no persistent widgets order or it is empty,
       
   268      *   the widget is added in alphabetical order
       
   269      * 
       
   270      * NOTE: caller must call HandleItemAdditionL() for the listbox after
       
   271      * adding all widget datas to update the listbox correctly!
       
   272      * 
       
   273      * @param aWidget Data data to add
       
   274      */
       
   275     void AddWidgetDataL( CWmWidgetData* aWidgetData );
       
   276     
       
   277     /** 
       
   278      * removes widget data from given index in the model
       
   279      * The method reorganises the list model and size.
       
   280      * Drawing is still needed to update the appearance.
       
   281      * 
       
   282      * @param aItemIndex index to remove
       
   283      * */
       
   284     void RemoveWidgetData( TInt aItemIndex/*, TBool aRedraw = ETrue*/ );
       
   285     
       
   286     /** 
       
   287      * requests to redraw item in given index position 
       
   288      * 
       
   289      * @param aItemIndex index to redraw
       
   290      */
       
   291     void RedrawItem( TInt aItemIndex );
       
   292 
       
   293     /** sort order of widgets in the list */
       
   294     enum TSortOrder
       
   295         {
       
   296         /** sort list as it was on last run */
       
   297         EStoredOrder,
       
   298         /** sort alphabetically */
       
   299         EAlphabetical,
       
   300         /** show latest installed first */
       
   301         ELatestFirst
       
   302         };
       
   303 
       
   304     /** 
       
   305      * sets the list sort order 
       
   306      * 
       
   307      * @param aOrder sort order
       
   308      */
       
   309     void SetSortOrderL( TSortOrder aOrder );
       
   310     
       
   311     /**
       
   312      * Responds to layout switched.
       
   313      */
       
   314     void HandleLayoutChanged();
       
   315 	
       
   316 	/** 
       
   317      * State of pointer down event 
       
   318      * 
       
   319      * @return ETrue if pointer is down
       
   320      */
       
   321     inline TBool PressedDown();
       
   322 
       
   323     /**
       
   324      * Returns size of logo 
       
   325      * 
       
   326      * @return Size of logo rect
       
   327      */
       
   328     TSize LogoSize();
       
   329 
       
   330 private: // from CEikTextListBox
       
   331     /**
       
   332      * Creates the item drawer.
       
   333      * 
       
   334      * @see CEikTextListBox::CreateItemDrawerL
       
   335      */
       
   336 	void CreateItemDrawerL();
       
   337 	
       
   338 protected: // from base class CCoeControl
       
   339     
       
   340     /**
       
   341      * Sets the control's extent, specifying a rectangle.
       
   342      * 
       
   343      * @see CCoeControl::SizeChanged
       
   344      */
       
   345     void SizeChanged();
       
   346 
       
   347 private: // from base class CCoeControl
       
   348 
       
   349     /*
       
   350      * Draws the control.
       
   351      * 
       
   352      * @see CCoeControl::Draw
       
   353      */
       
   354     void Draw( const TRect& aRect ) const;
       
   355 
       
   356 	/**
       
   357 	 * Handles pointer events.
       
   358 	 * 
       
   359 	 * @see CCoeControl::HandlePointerEventL
       
   360 	 */
       
   361 	void HandlePointerEventL( const TPointerEvent& aPointerEvent );
       
   362 	
       
   363 private:
       
   364   	 /** Constructor for performing 1st stage construction */
       
   365     CWmListBox( CWmPlugin& aWmPlugin );
       
   366 
       
   367     /** 2nd phase constructor */
       
   368     void ConstructL(
       
   369             const TRect& aRect,
       
   370             const CCoeControl* aParent,
       
   371             TInt aFlags );
       
   372     
       
   373 
       
   374 protected: // from MWmWidgetDataObserver
       
   375 
       
   376     /** 
       
   377      * widget needs redrawing 
       
   378      * 
       
   379      * @param aWidgetData item to redraw
       
   380      */
       
   381     void HandleWidgetDataChanged( CWmWidgetData* aWidgetData );
       
   382 
       
   383 private: // own methods
       
   384 
       
   385     /** 
       
   386      * linear order for sorting, depending on the sort type being used 
       
   387      */
       
   388     TLinearOrder<CWmWidgetData> SortOrder( TSortOrder aOrder );
       
   389 
       
   390 private:
       
   391 
       
   392     /** 
       
   393      * the plugin root (not owned) 
       
   394      */
       
   395     CWmPlugin&          iWmPlugin;
       
   396 
       
   397     /** 
       
   398      * array of widget data objects (the list model) 
       
   399      */
       
   400     RWidgetDataValues   iWidgetDatas;
       
   401 
       
   402     /** 
       
   403      * the currently active item ADD button's rectangle, for push recognition 
       
   404      */
       
   405     TRect               iButtonRect;
       
   406 
       
   407     /** 
       
   408      * state of list box find pane 
       
   409      */
       
   410     TBool               iFindPaneIsVisible;
       
   411 	
       
   412 	/** 
       
   413      * state of pointer pressed down and hold 
       
   414      */
       
   415     TBool               iPressedDown;
       
   416 	
       
   417 	};
       
   418 #include "wmlistbox.inl"
       
   419 
       
   420 #endif ___WMLISTBOX_H__
       
   421 
       
   422 // End of File