textinput/peninputarc/inc/peninputlayoutcontrolinc/peninputlayoutchoicelist.h
changeset 0 eb1f2e154e89
child 9 e6a39382bb9c
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  header file of choice list window
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_FEPLAYOUTCHOICELIST_H
       
    19 #define C_FEPLAYOUTCHOICELIST_H
       
    20 
       
    21 #include <AknsConstants.h>
       
    22 #include "peninputlayoutpopupwnd.h"
       
    23 
       
    24 /**
       
    25  *  The constant for max text length of 
       
    26  *  choice list item title.
       
    27  */
       
    28 const TInt KMaxItemTextLength = 100;
       
    29 
       
    30 /**
       
    31  *  class CFepLayoutChoiceList
       
    32  *
       
    33  *  Popup choick list control. This class could be used directly by user.
       
    34  *
       
    35  *  @lib feplayoutcontrol.lib
       
    36  *  @since S60 V4.0
       
    37  */
       
    38 class CFepLayoutChoiceList : public CFepLayoutPopupWnd
       
    39     {
       
    40 public:
       
    41     enum TListHitPosition
       
    42         {
       
    43         EListInsideNoneListItem = -2,
       
    44         EListOutside = -1,
       
    45         EListItemFirst = 0
       
    46         };
       
    47     /**
       
    48      * struct SEvent
       
    49      * Event data structure reported by choice list control
       
    50      * 
       
    51      */
       
    52     struct SEvent
       
    53         {
       
    54         /*
       
    55          * selected item index, -1 if user cancel
       
    56          * popup list by click outside popup list
       
    57          */
       
    58         TInt iIndex;
       
    59         /*
       
    60          * selected item command
       
    61          */
       
    62         TInt iCommand;
       
    63         };
       
    64 
       
    65     /**
       
    66      * struct SItem
       
    67      * Choice list item data structure.
       
    68      * 
       
    69      */
       
    70     struct SItem
       
    71         {
       
    72         /*
       
    73          * Command of choice list item.
       
    74          */
       
    75         TInt iCommand;
       
    76 
       
    77         /*
       
    78          * Title of choice list item.
       
    79          */
       
    80         TBuf<KMaxItemTextLength> iText;
       
    81         };
       
    82         
       
    83 public:
       
    84     /**
       
    85      * Factory function.        
       
    86      *
       
    87      * @since S60 V4.0        
       
    88      * @param aUiLayout Ui layout who contains this control.Ownership not transferred
       
    89      * @param aControlId control Id
       
    90      * @return An instance of CFepLayoutChoiceList class        
       
    91      */                               
       
    92     IMPORT_C static CFepLayoutChoiceList* NewL(CFepUiLayout* aUiLayout,
       
    93                                                TInt aControlId);
       
    94 
       
    95 
       
    96     /**
       
    97      * Destructor.        
       
    98      *
       
    99      * @since S60 V4.0        
       
   100      */                  
       
   101     IMPORT_C  ~CFepLayoutChoiceList();
       
   102     
       
   103     /**
       
   104      * Set choice list item rectangle.        
       
   105      *
       
   106      * @since S60 V4.0        
       
   107      * @param aItemRect Single item rect, top left should be (0,0)
       
   108      * @param aFocusRect Focused rect, the coordinate is in aItemRect.
       
   109      * @return None        
       
   110      */                                       
       
   111     IMPORT_C void SetItemRect(const TRect& aItemRect, const TRect& aFocusRect);
       
   112 
       
   113     /**
       
   114      * Set choice list item text display position, relative to
       
   115      * iItemRect.        
       
   116      *
       
   117      * @since S60 V4.0        
       
   118      * @param aMargin Offset to add to the position as calculated
       
   119                       using specified rectangle
       
   120      * @param aBaseLine An offset in pixels for the baseline from
       
   121                         the normal position.
       
   122      * @return None        
       
   123      */                                       
       
   124     inline void SetMarginAndBaseline(TInt16 aMargin, TInt16 aBaseLine);
       
   125 
       
   126     /**
       
   127      * Set choice list item text display font.        
       
   128      *
       
   129      * @since S60 V4.0        
       
   130      * @param aFont Font used to display text. Ownership not transferred.
       
   131      */                                       
       
   132     inline void SetFont(const CFont* aFont);
       
   133 
       
   134 
       
   135     /**
       
   136      * Set choice list item text display color.        
       
   137      *
       
   138      * @since S60 V4.0        
       
   139      * @param aCol Font color.
       
   140      * @return None        
       
   141      */                                       
       
   142     inline void SetFontColor(const TRgb& aCol);
       
   143 
       
   144     /**
       
   145      * Set bitmap for focus.        
       
   146      *
       
   147      * @since S60 V4.0        
       
   148      * @param aItemFocusBmp The bitmap. Ownership transferred to choice list.
       
   149      * @return None        
       
   150      */                                 
       
   151     IMPORT_C void SetFocusBmp(CFbsBitmap* aItemFocusBmp);
       
   152 
       
   153     /**
       
   154      * Set mask bitmap for focus.
       
   155      *
       
   156      * @since S60 V4.0        
       
   157      * @param aItemFocusBmpMask The bitmap. Ownership transferred to choice list.
       
   158      * @return None        
       
   159      */                                 
       
   160     IMPORT_C void SetFocusBmpMask(CFbsBitmap *aItemFocusBmpMask);
       
   161     
       
   162     /**
       
   163      * Get bitmap for focus .        
       
   164      *
       
   165      * @since S60 V4.0        
       
   166      * @return The bitmap        
       
   167      */                                 
       
   168     inline const CFbsBitmap* FocusBmp();
       
   169 
       
   170     /**
       
   171      * Set mask bitmap for focus .        
       
   172      *
       
   173      * @since S60 V4.0        
       
   174      * @return The bitmap        
       
   175      */                                 
       
   176     inline const CFbsBitmap* FocusBmpMask();
       
   177 
       
   178     inline const RPointerArray<CFepLayoutChoiceList::SItem>& ItemArray();
       
   179 
       
   180     /**
       
   181      * Set choice list items.
       
   182      *
       
   183      * @since S60 V4.0        
       
   184      * @param aItemList Item list array. The function copies them internally.
       
   185      * @return None        
       
   186      */                                 
       
   187     IMPORT_C void SetItemsL(const RPointerArray<CFepLayoutChoiceList::SItem>& aItemList);
       
   188 
       
   189     /**
       
   190      * Append a choice list item.
       
   191      *
       
   192      * @since S60 V4.0        
       
   193      * @param aItem Item to add.
       
   194      * @return None        
       
   195      */                                 
       
   196     IMPORT_C void AddItemL(const CFepLayoutChoiceList::SItem& aItem);
       
   197 
       
   198     /**
       
   199      * Insert a choice list item at specified postion.
       
   200      *
       
   201      * @since S60 V4.0        
       
   202      * @param aPostion The position is to be inserted.
       
   203      * @param aItem Item to insert.
       
   204      * @return None        
       
   205      */                                 
       
   206     IMPORT_C void InsertItemL(TInt aPostion, const CFepLayoutChoiceList::SItem& aItem);
       
   207 
       
   208     /**
       
   209      * Remove a choice list item by command
       
   210      * Only the first found item is removed.
       
   211      *
       
   212      * @since S60 V4.0        
       
   213      * @param aCommand Item command.
       
   214      * @return None        
       
   215      */                                 
       
   216     IMPORT_C void RemoveItemByCommand(TInt aCommand);
       
   217 
       
   218     /**
       
   219      * Remove a choice list item by index
       
   220      *
       
   221      * @since S60 V4.0        
       
   222      * @param aIndex Item index
       
   223      * @return None        
       
   224      */                                 
       
   225     IMPORT_C void RemoveItemByIndex(TInt aIndex);
       
   226 
       
   227     /**
       
   228      * Clear all choice list items
       
   229      *
       
   230      * @since S60 V4.0        
       
   231      * @return None        
       
   232      */                                 
       
   233     IMPORT_C void ClearItemsL();
       
   234     
       
   235     /**
       
   236      * Clear all choice list items
       
   237      *
       
   238      * @since S60 V4.0        
       
   239      * @return None        
       
   240      */                                 
       
   241     IMPORT_C TInt ItemsCount();
       
   242     
       
   243     /**
       
   244      * Retrieve a choice list item by index
       
   245      *
       
   246      * @since S60 V4.0        
       
   247      * @param aIndex Item index
       
   248      * @return choice list item pointer of specified index
       
   249      */                                 
       
   250     const CFepLayoutChoiceList::SItem* ItemByIndex(TInt aIndex);
       
   251 
       
   252     /**
       
   253      * Retrieve a choice list item by item's command
       
   254      * Only first found item is returned.
       
   255      *
       
   256      * @since S60 V4.0        
       
   257      * @param aCommand Item command
       
   258      * @return choice list item pointer. NULL if not found.
       
   259      */                                 
       
   260     const CFepLayoutChoiceList::SItem*  ItemByCommand(TInt aCommand);
       
   261     
       
   262     /**
       
   263      * Report event to observer
       
   264      *
       
   265      * @since S60 V4.0
       
   266      * @param aEvent Event to report
       
   267      * @return None.      
       
   268      */                  
       
   269     IMPORT_C void ReportChoiceEvent(CFepLayoutChoiceList::SEvent& aEvent);
       
   270 
       
   271 
       
   272     //inline CEikListBox* ListBox();
       
   273     /**
       
   274      * Find the position for given command
       
   275     /**
       
   276      * Get item whose region contains the point.
       
   277      *
       
   278      * @since S60 V5.0
       
   279      * @param aCmd The command to be found
       
   280      * @return The index of choice item. -1 if no item contains
       
   281      *         the command
       
   282      */                                      
       
   283      IMPORT_C TInt FindCommand(TInt aCmd);    
       
   284 
       
   285     /**
       
   286      * Set skin ID of subitem and background
       
   287      *
       
   288      * @since S60 V4.0
       
   289      * @param aSubItemID 	Skin ID of sub item
       
   290      * @param aBackgroundID Skin ID of background
       
   291      * @return None.     
       
   292      */                  
       
   293     IMPORT_C void SetSkinID( TAknsItemID aSubItemID, TAknsItemID aBackgroundID );
       
   294     
       
   295     /**
       
   296      * Get current selected item index
       
   297      *
       
   298      * @since S60 V4.0
       
   299      * @return index.     
       
   300      */   
       
   301     IMPORT_C TInt CurrentFocusedIndex( ) const;
       
   302 
       
   303     /**
       
   304      * Set current selected item index
       
   305      *
       
   306      * @since S60 V4.0
       
   307      * @param aIndex selected item index
       
   308      * @return None.     
       
   309      */       
       
   310     IMPORT_C void SetCurrentFocusedIndex(const TInt aIndex);
       
   311     
       
   312 protected:
       
   313 
       
   314     /**
       
   315      * Constructor.        
       
   316      *
       
   317      * @since S60 V4.0        
       
   318      * @param aUiLayout Ui layout who contains this control.Ownership not transferred
       
   319      * @param aControlId control Id
       
   320      */                  
       
   321     IMPORT_C CFepLayoutChoiceList(CFepUiLayout* aUiLayout, 
       
   322                                   TInt aControlId);
       
   323     
       
   324     /**
       
   325      * Get item whose region contains the point.
       
   326      *
       
   327      * @since S60 V4.0
       
   328      * @param aPoint The point position the layout
       
   329      * @return The index of choice item. -1 if no item contains
       
   330      *         the point
       
   331      */                                        
       
   332      IMPORT_C virtual TInt HitTest(const TPoint& aPoint);
       
   333 
       
   334     /**
       
   335      * Handle pointer down event
       
   336      *
       
   337      * @since S60 V4.0
       
   338      * @param aPoint The point position relative the layout
       
   339      * @return The control which handles the event.
       
   340      */                                        
       
   341     IMPORT_C virtual CFepUiBaseCtrl* HandlePointerDownEventL(const TPoint& aPoint);
       
   342     
       
   343     /**
       
   344      * Handle pointer move event
       
   345      *
       
   346      * @since S60 V4.0
       
   347      * @param aPoint The point position relative the layout
       
   348      * @return The control which handles the event.     
       
   349      */                  
       
   350     IMPORT_C virtual CFepUiBaseCtrl* HandlePointerMoveEventL(const TPoint& aPoint);
       
   351     
       
   352     /**
       
   353      * Handle pointer up event
       
   354      *
       
   355      * @since S60 V4.0
       
   356      * @param aPoint The point position relative the layout
       
   357      * @return The control which handles the event.     
       
   358      */                  
       
   359     IMPORT_C virtual CFepUiBaseCtrl* HandlePointerUpEventL(const TPoint& aPoint);
       
   360     
       
   361     IMPORT_C void AfterDisplayed();
       
   362 private:
       
   363     /**
       
   364      * Draw a choice list item by index.
       
   365      *
       
   366      * @since S60 V4.0
       
   367      * @param aIndex The index of item to draw.
       
   368      * @param aErase ETrue, draw background 
       
   369                      EFalse, don't draw background
       
   370      * @return None.     
       
   371      */                  
       
   372     void DrawItem(TInt aIndex, TBool aErase);
       
   373 
       
   374     /**
       
   375      * Draw a choice list item.
       
   376      *
       
   377      * @since S60 V4.0
       
   378      * @param aRect The position of the item.
       
   379      * @param aItem The item to draw.
       
   380      * @param aFocus Whether the item is focused or not
       
   381      * @param aErase ETrue, draw background 
       
   382                      EFalse, don't draw background
       
   383      * @return None.     
       
   384      */                  
       
   385     void DrawItem(const TRect& aRect, const CFepLayoutChoiceList::SItem& aItem, 
       
   386                   TBool aErase, TBool aFocus);
       
   387 
       
   388     /**
       
   389      * Draw choice list background
       
   390      *
       
   391      * @since S60 V4.0
       
   392      * @param aRect The area to draw
       
   393      * @param aDrawBorder ETrue, draw border 
       
   394                           EFalse, don't draw border
       
   395      * @return None.     
       
   396      */                  
       
   397     void DrawChoiceListBackground(const TRect& aRect);//, TBool aDrawBorder = ETrue);
       
   398 
       
   399     /**
       
   400      * Draw bitmap helper function
       
   401      *
       
   402      * @since S60 V4.0
       
   403      * @param aDestRect The destination rect to draw
       
   404      * @param aSrcRect  The source rect of bitmap
       
   405      * @param aFast ETrue, use Bitblt to draw bitmap
       
   406                     EFalse, use DrawBitmap to draw
       
   407      * @return None.     
       
   408      */                  
       
   409     void DrawBitmap(const TRect& aDestRect, const TRect& aSrcRect, CFbsBitmap* aBmp, TBool aFast);
       
   410 
       
   411 
       
   412     /**
       
   413      * Choice list draw function
       
   414      *
       
   415      * @since S60 V4.0
       
   416      * @return None.     
       
   417      */
       
   418     IMPORT_C virtual void Draw();
       
   419 
       
   420     /**
       
   421      * Prepare display.
       
   422      *
       
   423      * @since S60 V4.0
       
   424      * @return None.     
       
   425      */
       
   426     IMPORT_C void OnDisplay();
       
   427     
       
   428     /**
       
   429      * Calculate rect based on item count.
       
   430      *
       
   431      * @since S60 V4.0
       
   432      * @return None.     
       
   433      */
       
   434     IMPORT_C virtual void ReCalcLayout();
       
   435     
       
   436     static TInt FreezeCallBack( TAny *aPtr );    
       
   437     
       
   438     void AfterDisplayedL();
       
   439     
       
   440 protected:
       
   441     /**
       
   442      * Single item rect
       
   443      */
       
   444     TRect iItemRect;
       
   445 
       
   446     /**
       
   447      * Focus item rect
       
   448      */
       
   449     TRect iItemFocusRect;
       
   450 
       
   451     /**
       
   452      * Draw text left side margin
       
   453      */
       
   454     TInt16 iMargin;
       
   455 
       
   456     /**
       
   457      * Draw text baseline
       
   458      */
       
   459     TInt16 iBaseline;
       
   460 
       
   461     /**
       
   462      * Current selecting item
       
   463      */
       
   464     TInt   iCurFocusItem;
       
   465 
       
   466     /**
       
   467      * Focus bitmap.
       
   468      */
       
   469     CFbsBitmap* iItemFocusBmp; 
       
   470 
       
   471     /**
       
   472      * Focus mask bitmap.
       
   473      */
       
   474     CFbsBitmap* iItemFocusBmpMask; 
       
   475 
       
   476     /**
       
   477      * Choice list items array.
       
   478      */
       
   479     RPointerArray<CFepLayoutChoiceList::SItem> iItemList;
       
   480 
       
   481     /**
       
   482      * Item text display font. Not Own.
       
   483      */
       
   484     const CFont* iFont;
       
   485 
       
   486     /**
       
   487      * Item text display color.
       
   488      */
       
   489     TRgb  iFontColor;
       
   490     
       
   491     /**
       
   492      * Update editor cursor timer
       
   493      */
       
   494     CPeriodic* iFreezeTimer;
       
   495      
       
   496     /**
       
   497      * The last selected item index
       
   498      */
       
   499      TInt iLastSelIndex;
       
   500     
       
   501     /**
       
   502      * The skin ID of sub item and background
       
   503      */
       
   504      TAknsItemID iSubItemSkinID;
       
   505      TAknsItemID iBackgroundSkinID;
       
   506     };
       
   507 
       
   508 #include "peninputlayoutchoicelist.inl"
       
   509 #endif //C_FEPLAYOUTCHOICELIST_H
       
   510 //End Of File