williamr@2: /*
williamr@2: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2: * All rights reserved.
williamr@2: * This component and the accompanying materials are made available
williamr@2: * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
williamr@2: * which accompanies this distribution, and is available
williamr@2: * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2: *
williamr@2: * Initial Contributors:
williamr@2: * Nokia Corporation - initial contribution.
williamr@2: *
williamr@2: * Contributors:
williamr@2: *
williamr@2: * Description:  Interface for controlling stylus specific popup menu.
williamr@2: *
williamr@2: */
williamr@2: 
williamr@2: 
williamr@2: #ifndef CAKNSTYLUSPOPUPMENU_H
williamr@2: #define CAKNSTYLUSPOPUPMENU_H
williamr@2: 
williamr@2: 
williamr@2: #include <e32base.h>
williamr@2: #include <coecobs.h> // MCoeControlObserver
williamr@2: 
williamr@2: class CAknPreviewPopUpController;
williamr@2: class CAknStylusPopUpMenuContent;
williamr@2: class MEikMenuObserver;
williamr@2: class TResourceReader;
williamr@2: 
williamr@2: /**
williamr@2:  *  Stylus specific popup menu
williamr@2:  *
williamr@2:  *  A floating popup menu which is meant for stylus usage only.
williamr@2:  *  The menu appears near to the tapping position. When an item is 
williamr@2:  *  tapped the menu calls its observer's (iMenuObserver) ProcessCommandL. 
williamr@2:  *  Typically the observer is application's AppUi. It is then the
williamr@2:  *  observer's responsibility to handle the command appropriately.
williamr@2:  *  The observer is informed with KErrCancel if the menu is closed without 
williamr@2:  *  making a selection. 
williamr@2:  *
williamr@2:  *  @lib eikcoctl.lib
williamr@2:  *  @since S60 v5.0
williamr@2:  */
williamr@2: NONSHARABLE_CLASS( CAknStylusPopUpMenu ) : public CBase, 
williamr@2:                                            public MCoeControlObserver
williamr@2:     {
williamr@2: public:
williamr@2:     enum TPositionType
williamr@2:         {
williamr@2:         EPositionTypeRightTop = 0,
williamr@2:         EPositionTypeLeftTop,
williamr@2:         EPositionTypeRightBottom,
williamr@2:         EPositionTypeLeftBottom      
williamr@2:         };
williamr@2:     /**
williamr@2:      * Two-phased constructor
williamr@2:      *
williamr@2:      * @param aObserver Menu observer (not owned) that handles 
williamr@2:      *                  stylus popup events.
williamr@2:      * @param aPoint The position where stylus was tapped
williamr@2:      * @param aPopup Preview popup from which stylus popup
williamr@2:      *               menu was launched, can be NULL.
williamr@2:      */
williamr@2:     IMPORT_C static CAknStylusPopUpMenu* NewL( MEikMenuObserver* aObserver, 
williamr@2:                                          const TPoint& aPoint,
williamr@2:                                          CAknPreviewPopUpController* aPopup );
williamr@2:     
williamr@2:     /**
williamr@2:      * Two-phased constructor
williamr@2:      *
williamr@2:      * @param aObserver Menu observer (not owned) that handles 
williamr@2:      *                  stylus popup events.
williamr@2:      * @param aPoint The position where stylus was tapped
williamr@2:      */
williamr@2:     IMPORT_C static CAknStylusPopUpMenu* NewL( MEikMenuObserver* aObserver, 
williamr@2:                                          const TPoint& aPoint );
williamr@2: 
williamr@2:     /**
williamr@2:      * Two-phased constructor
williamr@2:      *
williamr@2:      * @param aObserver Menu observer (not owned) that handles 
williamr@2:      *                  stylus popup events.
williamr@2:      * @param aPoint The position where stylus was tapped
williamr@2:      * @param aPopup Preview popup from which stylus popup
williamr@2:      *               menu was launched, can be NULL.
williamr@2:      */
williamr@2:     IMPORT_C static CAknStylusPopUpMenu* NewLC( MEikMenuObserver* aObserver, 
williamr@2:                                          const TPoint& aPoint,
williamr@2:                                          CAknPreviewPopUpController* aPopup );
williamr@2:     /**
williamr@2:      * Destructor
williamr@2:      */    
williamr@2:     ~CAknStylusPopUpMenu();
williamr@2:     
williamr@2:     /**
williamr@2:      * Adds a menu item. If the menu contains maximum amount of
williamr@2:      * items, the function will do nothing. Inserted item will be
williamr@2:      * placed last.
williamr@2:      *
williamr@2:      * @param aItem The menu item to be added.
williamr@2:      * @param aCommandId Item's command id.
williamr@2:      */
williamr@2:     IMPORT_C void AddMenuItemL( const TDesC& aItem, const TInt aCommandId );
williamr@2:     
williamr@2:     /**
williamr@2:      * Removes a menu item.
williamr@2:      *
williamr@2:      * @param aCommandId Command id of the item to be removed.
williamr@2:      */
williamr@2:     IMPORT_C void RemoveMenuItem( const TInt aCommandId );
williamr@2: 
williamr@2:     /**
williamr@2:      * Hides / shows a menu item.
williamr@2:      *
williamr@2:      * @param aCommandId Command id of the item to be hidden / shown.
williamr@2:      * @param aDimmed ETrue to hide item and EFalse to show item
williamr@2:      */
williamr@2:     IMPORT_C void SetItemDimmed( const TInt aCommandId, const TBool aDimmed );
williamr@2: 
williamr@2:     /**
williamr@2:      * Shows the stylus popup menu. If it's already visible,
williamr@2:      * nothing happens.
williamr@2:      */
williamr@2:     IMPORT_C void ShowMenu();
williamr@2:         
williamr@2:     /**
williamr@2:      * Sets the position of the stylus popup menu. 
williamr@2:      * Position will be adjusted if the menu doesn't fit on the screen
williamr@2:      * properly.
williamr@2:      *
williamr@2:      * @param aPoint Position of the left-top corner of the stylus popup menu.
williamr@2:      */
williamr@2:     IMPORT_C void SetPosition( const TPoint& aPoint );    
williamr@2:     /**
williamr@2:      * Sets the position of the stylus popup menu. 
williamr@2:      * Position will be adjusted if the menu doesn't fit on the screen
williamr@2:      * properly.
williamr@2:      *
williamr@2:      * @param aPoint Position of the stylus popup menu.
williamr@2:      * @param aPosType  Position type e.g. left-top corner or right-top corner  
williamr@2:      */
williamr@2:     IMPORT_C void SetPosition( const TPoint& aPoint, TPositionType aPosType );    
williamr@2:     
williamr@2:     /**
williamr@2:      * Tells the popup menu to recalculate its position. This can be used e.g.
williamr@2:      * after layout transition.
williamr@2:      */
williamr@2:     void UpdatePosition();
williamr@2: // from base class CCoeControl
williamr@2: 
williamr@2:     /**
williamr@2:      * Constructs the menu from resource.
williamr@2:      *
williamr@2:      * @param aReader Resource reader.
williamr@2:      */
williamr@2:     IMPORT_C void ConstructFromResourceL( TResourceReader& aReader );
williamr@2: 
williamr@2: // from base class MCoeControlObserver
williamr@2:     
williamr@2:     /**
williamr@2:      * Method to handle events that occur when user selects a menu item.
williamr@2:      *
williamr@2:      * @param aControl The control that sent the event.
williamr@2:      * @param aEventType The event type.
williamr@2:      */
williamr@2:     IMPORT_C void HandleControlEventL( CCoeControl* aControl,
williamr@2:                                        TCoeEvent aEventType );
williamr@2: 
williamr@2: public:
williamr@2: 
williamr@2:     /**
williamr@2:      * Resets timer that hides popup.
williamr@2:      */
williamr@2:     void ResetTimer(); 
williamr@2: 
williamr@2: private:
williamr@2: 
williamr@2:     /**
williamr@2:      * Default constructor
williamr@2:      *
williamr@2:      * @param aObserver Menu observer (not owned) that handles 
williamr@2:      *                  stylus popup events.
williamr@2:      * @param aPoint The position where stylus was tapped
williamr@2:      * @param aPopup Preview popup from which stylus popup
williamr@2:      *               menu was launched, can be NULL.
williamr@2:      */
williamr@2:     CAknStylusPopUpMenu( MEikMenuObserver* aObserver, const TPoint& aPoint,
williamr@2:                          CAknPreviewPopUpController* aPopup );
williamr@2: 
williamr@2:     /**
williamr@2:      * 2nd phase constructor
williamr@2:      */
williamr@2:     void ConstructL();
williamr@2: 
williamr@2: private: // data
williamr@2: 
williamr@2:     /**
williamr@2:      * Screen relative position where stylus was tapped.
williamr@2:      */
williamr@2:     TPoint iPosition;
williamr@2:     
williamr@2:     /**
williamr@2:      * Controller for the actual popup.
williamr@2:      * Own.
williamr@2:      */
williamr@2:     CAknPreviewPopUpController* iController;
williamr@2:     
williamr@2:     /**
williamr@2:      * Popup's content.
williamr@2:      * Own.
williamr@2:      */
williamr@2:     CAknStylusPopUpMenuContent* iContent;
williamr@2:     
williamr@2:     /**
williamr@2:      * Observer which will be used to forward selected menu command id.
williamr@2:      * Not own.
williamr@2:      */
williamr@2:     MEikMenuObserver* iMenuObserver;
williamr@2:     
williamr@2:     /**
williamr@2:      * Preview popup which launches stylus popup menu.
williamr@2:      * If NULL, menu wasn't launched from a preview popup.
williamr@2:      * If not NULL, stylus popup menu will close also the preview popup
williamr@2:      * when an option is selected in the stylus popup menu.
williamr@2:      * Not own.
williamr@2:      */
williamr@2:     CAknPreviewPopUpController* iPreviewPopup;
williamr@2:     
williamr@2:     };
williamr@2: 
williamr@2: 
williamr@2: #endif // CAKNSTYLUSPOPUPMENU_H