uifw/EikStd/coctlinc/aknstyluspopupmenucontent.h
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Content that is shown inside a stylus popup menu.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CAKNSTYLUSPOPUPMENUCONTENT_H
       
    20 #define CAKNSTYLUSPOPUPMENUCONTENT_H
       
    21 
       
    22 #include <AknControl.h>
       
    23 #include <aknstyluspopupmenu.h>
       
    24 
       
    25 class CAknStylusPopUpMenuItem;
       
    26 class CAknStylusPopUpMenuExtension;
       
    27 class CAknStylusPopUpMenuPhysicsHandler;
       
    28 
       
    29 /**
       
    30  *  Class providing content for the stylus popup menu.
       
    31  *
       
    32  *  @lib eikcoctl.lib
       
    33  *  @since S60 v5.0
       
    34  */
       
    35 NONSHARABLE_CLASS( CAknStylusPopUpMenuContent ) : public CAknControl,
       
    36                                                   public MCoeForegroundObserver,
       
    37                                                   public MEikScrollBarObserver
       
    38                                                   
       
    39     {
       
    40 private: 
       
    41     enum THighlightType { ENoHighlight, EDrawHighlight, ERemoveHighlight };
       
    42     enum TScrollType { ENoScroll, EScrollUp, EScrollDown };
       
    43 
       
    44 public:
       
    45 
       
    46     static CAknStylusPopUpMenuContent* NewL( CAknStylusPopUpMenu& aPopUpMenu );
       
    47 
       
    48     static CAknStylusPopUpMenuContent* NewLC( CAknStylusPopUpMenu& aPopUpMenu );
       
    49 
       
    50     ~CAknStylusPopUpMenuContent();
       
    51 
       
    52     /**
       
    53      * Adds a new menu item.
       
    54      *
       
    55      * @param aItem Menu item to be added.
       
    56      * @param aCommandId Command ID of the menu item.
       
    57      */
       
    58     void AddMenuItemL( const TDesC& aItem, const TInt aCommandId );
       
    59 
       
    60     /**
       
    61      * Removes a menu item.
       
    62      *
       
    63      * @param aIndex Index of the menu item.
       
    64      */
       
    65     void RemoveMenuItem( const TInt aIndex );
       
    66     
       
    67     /**
       
    68      * Hides / shows a menu item.
       
    69      *
       
    70      * @param aIndex Index of the menu item.
       
    71      * @param aDimmed ETrue to hide and EFalse to show
       
    72      */
       
    73     void SetItemDimmed( const TInt aIndex, const TBool aDimmed );
       
    74         
       
    75     /**
       
    76      * Method to get the command id of currently selected item.
       
    77      *
       
    78      * @return Command id.
       
    79      */
       
    80     TInt CurrentCommandId() const;
       
    81 
       
    82     /**
       
    83      * Draws highlight again when animation frame is ready. Called by 
       
    84      * extension. 
       
    85      */
       
    86     void RepaintHighlight() const;
       
    87 
       
    88     /**
       
    89      * Returns current item's rect
       
    90      * @return current item's highlightrect
       
    91      */
       
    92     TRect HighlightRect() const;
       
    93 
       
    94     /**
       
    95      * Removes all items.
       
    96      */
       
    97     void Clear();
       
    98 
       
    99 // from base class CCoeControl
       
   100 
       
   101     /**
       
   102      * Returns the minimum size of the control.
       
   103      *
       
   104      * @return Minimum size.
       
   105      */
       
   106      TSize MinimumSize();
       
   107     
       
   108     /**
       
   109      * Handles changes to the control's resources.
       
   110      *
       
   111      * @aParam aType Type of resource change.
       
   112      */     
       
   113      void HandleResourceChange( TInt aType );
       
   114 
       
   115     /**
       
   116      * Handles pointer events.
       
   117      *
       
   118      * @param aPointerEvent The pointer event. 
       
   119      */
       
   120      void HandlePointerEventL( const TPointerEvent& aPointerEvent );
       
   121 
       
   122     /**
       
   123      * Makes item visible or hides it
       
   124      *
       
   125      * @param aVisible if to be shown
       
   126      */
       
   127      void MakeVisible( TBool aVisible );
       
   128 
       
   129    /**
       
   130      * Gets the number of controls contained in a compound control.
       
   131      *
       
   132      * @return The number of component controls contained by this control.
       
   133      */
       
   134      TInt CountComponentControls() const;
       
   135 
       
   136      /**
       
   137      * Gets the specified component of a compound control.
       
   138      *
       
   139      * @param aIndex The index of the control to get
       
   140      * @return The component control with an index of aIndex.
       
   141      */
       
   142      CCoeControl* ComponentControl( TInt aIndex ) const;
       
   143      
       
   144      
       
   145 // from base class MCoeControlObserver
       
   146 
       
   147      /**
       
   148       * Not used, but implementation is required by
       
   149       * MCoeForegroundObserver
       
   150       */
       
   151 	 void HandleGainingForeground();
       
   152 	
       
   153 	 /**
       
   154 	  * When foreground is lost, stylus popupmenu is closed,
       
   155 	  * TSW Error AJUA-79ELVM.
       
   156 	  */
       
   157 	 void HandleLosingForeground();
       
   158 
       
   159 
       
   160      // Functions related to Physics handling
       
   161 
       
   162 public:
       
   163 
       
   164     /**
       
   165      * Updates view so that aTopmostItem is topmost item.
       
   166      * Uses also offset from physics handler to locate view smoothly. 
       
   167      *
       
   168      * @aParam aTopmostItem Topmost item
       
   169      */ 
       
   170     void UpdateView( TInt aTopmostItem );
       
   171     
       
   172     /**
       
   173      * Returns index of item that contains given position. 
       
   174      *
       
   175      * @return index of item that contains given position
       
   176      */ 
       
   177     TInt ContainingItem( const TPoint& aPosition );
       
   178 
       
   179     /**
       
   180     * Sets highlight to given item
       
   181     *
       
   182     * @aParam aItem Item to be highlight
       
   183     */ 
       
   184    void SetHighlight( TInt aItem );
       
   185    
       
   186    /**
       
   187     * Return currently highlighted item's index.
       
   188     * 
       
   189     * @return Highlighted item's index or -1 if no item has highlight.
       
   190     */
       
   191    TInt CurrentItem() const;
       
   192       
       
   193     /**
       
   194      * Selects given item
       
   195      *
       
   196      * @aParam aItem Item to be selected
       
   197      */ 
       
   198     void SelectItem( TInt aItem );
       
   199     
       
   200 private:
       
   201 	
       
   202 	/**
       
   203      * Initializes physics.
       
   204      */
       
   205 	void InitPhysicsL();
       
   206     
       
   207     /**
       
   208      * Returns offset. Used to draw partial items.
       
   209      *
       
   210      * @return offset
       
   211      */
       
   212     TInt Offset() const; 
       
   213     
       
   214     /**
       
   215      * Returns height of whole list content (excluding hidden items).
       
   216      *
       
   217      * @return world height
       
   218      */
       
   219     TInt WorldHeight() const;
       
   220     
       
   221 private:
       
   222 
       
   223     /**
       
   224      * Default constructor
       
   225      */
       
   226     CAknStylusPopUpMenuContent( CAknStylusPopUpMenu& aPopUpMenu );
       
   227 
       
   228     /**
       
   229      * 2nd phase constructor
       
   230      */
       
   231     void ConstructL();
       
   232 
       
   233     /**
       
   234      * Moves the highlight to a newly selected menu item identified
       
   235      * by @c aNewSelectedItem. Redraws only the newly selected item and the currently
       
   236      * selected item if possible.
       
   237      * 
       
   238      * @param aNewSelectedItem The newly selected menu item index.
       
   239      */
       
   240     void MoveHighlightTo( TInt aNewSelectedItem );
       
   241     
       
   242     /**
       
   243      * Draws items. Draws higlight for the items 
       
   244      *
       
   245      * @param aGc The graphics context
       
   246      * @param aItem the item for which the highlight is drawn
       
   247      * @param aHighlight if the item has highlight or not
       
   248      */
       
   249     void DrawItem( CWindowGc& aGc, TInt aItem, THighlightType aHighlight ) const; 
       
   250 
       
   251     /**
       
   252      * Starts highlight animation
       
   253      *
       
   254      * @return KErrNone if successful, error code if not
       
   255      */
       
   256     TInt StartAnimation(); 
       
   257 
       
   258     /**
       
   259      * Updates scroll bar
       
   260      */
       
   261     void UpdateScrollBar();
       
   262     
       
   263     /**
       
   264      * Calculates which items are shown and sets rects for them
       
   265      *
       
   266      * @param aScroll TScrollType type of scroll
       
   267      * @return Index of the last shown item 
       
   268      */
       
   269     TInt CalculateShownItems( TScrollType aScroll );
       
   270      
       
   271         
       
   272 // from base class CCoeControl
       
   273     
       
   274     /**
       
   275      * Sets new rect for the items
       
   276      */
       
   277     void SizeChanged();
       
   278 
       
   279     /**
       
   280      * Draw a control called by window server.
       
   281      *
       
   282      * @param aRect The region of the control to be redrawn. 
       
   283      *      Co-ordinates are relative to the control's origin (top left corner).
       
   284      */
       
   285     void Draw( const TRect& aRect ) const;
       
   286 
       
   287 
       
   288     /**
       
   289      * Get's list rect from layout data
       
   290      *
       
   291      * @param aParent The region of the parent control
       
   292      * @param aLineLayout The component which to get from layout data
       
   293      * 
       
   294      * @return list rect
       
   295      */
       
   296     TRect ListRectFromLayout( const TRect& aParent,
       
   297         const TAknWindowLineLayout& aLineLayout ) const; 
       
   298 
       
   299     /**
       
   300      * Get's rect from layout data according to layout data 
       
   301      *
       
   302      * @param aParent The region of the parent control
       
   303      * @param aParent The component which to get from layout data
       
   304      * 
       
   305      * @return layout rect
       
   306      */
       
   307     TRect RectFromLayout( const TRect& aParent,
       
   308         const TAknWindowLineLayout& aLineLayout ) const; 
       
   309 
       
   310 
       
   311 // from MEikScrollBarObserver
       
   312 
       
   313     /**
       
   314      * Handles events from scrollbar
       
   315      *
       
   316      * @param aScrollBar Pointer to scrollbar
       
   317      * @param aEventType Scrollbar event
       
   318      */
       
   319     void HandleScrollEventL(CEikScrollBar* aScrollBar,TEikScrollEvent aEventType); 
       
   320 
       
   321 private: // data
       
   322 
       
   323     /**
       
   324      * Array which holds pointers to menu items. 
       
   325      */
       
   326     RPointerArray<CAknStylusPopUpMenuItem> iItems;
       
   327     
       
   328     /**
       
   329      * Current item
       
   330      */
       
   331     TInt iCurrentItem; 
       
   332 
       
   333     /**
       
   334      * Stylus PopUp menu extension which handles highlight animation 
       
   335      * own
       
   336      */
       
   337     CAknStylusPopUpMenuExtension* iExtension; 
       
   338     
       
   339     /** 
       
   340      * The scroll bar used by this control
       
   341      * own
       
   342      */ 
       
   343     CEikScrollBarFrame* iSBFrame;
       
   344     
       
   345     /**
       
   346      * First visible item on the list
       
   347      */
       
   348     TInt iFirstItem;
       
   349     
       
   350     CAknStylusPopUpMenu& iPopUpMenu;
       
   351     
       
   352     /**
       
   353      * Physics handler.
       
   354      * own.
       
   355      */
       
   356     CAknStylusPopUpMenuPhysicsHandler* iPhysicsHandler; 
       
   357     };
       
   358 
       
   359 #endif // CAKNSTYLUSPOPUPMENUCONTENT_H
       
   360