2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Popup toolbar component
20 #ifndef __AKNTOOLBAR_H__
21 #define __AKNTOOLBAR_H__
24 #include <avkon.hrh> // TAknOrientation
25 #include <AknControl.h> // CCoeControl
26 #include <coecobs.h> // MCoeControlObserver
27 #include <eikcmobs.h> // MEikCommandObserver
28 #include <AknPopupFader.h>
29 #include <babitflags.h>
30 #include <AknsItemID.h>
32 // FORWARD DECLARATIONS
34 class CAknToolbarItem;
35 class CAknToolbarExtension;
36 class MAknToolbarObserver;
37 class CEikButtonGroupContainer;
38 class TAknWindowComponentLayout;
39 class CAknsFrameBackgroundControlContext;
40 class CAknsBasicBackgroundControlContext;
43 // DisableToolbarL leaves with this value if toolbar is shown, since toolbar
44 // should not be shown when disabling/enabling toolbar.
45 const TInt KErrToolbarShown = -101;
50 * The class to provide toolbar for the application
53 * @since Series 60 3.1
55 class CAknToolbar : public CAknControl, public MCoeControlObserver,
56 public MCoeControlBackground, public MEikCommandObserver,
57 public MAknFadedComponent
59 public: //Enumerations:
61 enum TEventModifiers {
66 public: // Constructors and destructor
69 * Two-phased constructor.
71 * @param aResourceId The ID for this component's resource
72 * @return Pointer to the created toolbar object
74 IMPORT_C static CAknToolbar* NewL( const TInt aResourceId );
77 * Two-phased constructor.
79 * @param aResourceId The ID for this component's resource
80 * @return Pointer to the created toolbar object
82 IMPORT_C static CAknToolbar* NewLC( const TInt aResourceId );
89 public: // From base class
93 * Gets the number of controls contained in a compound control.
95 * @return The number of component controls contained by this control.
97 IMPORT_C TInt CountComponentControls() const;
101 * Gets the specified component of a compound control.
103 * @param aIndex The index of the control to get
104 * @return The component control with an index of aIndex.
106 IMPORT_C CCoeControl* ComponentControl( TInt aIndex ) const ;
110 * Handles pointer events.
112 * @param aPointerEvent The pointer event.
114 IMPORT_C void HandlePointerEventL( const TPointerEvent& aPointerEvent );
118 * Handles a change to the control's resources.
120 * @param aType A message UID value.
122 IMPORT_C void HandleResourceChange( TInt aType );
125 * From MCoeControlObserver.
126 * Handles an event from an observed toolbar item.
128 * @param aControl The control which sent the event
129 * @param aEventType The event type
131 IMPORT_C void HandleControlEventL( CCoeControl* aControl,
132 TCoeEvent aEventType );
136 * Responds to changes in the position of a toolbar.
138 IMPORT_C void PositionChanged();
141 * From MEikCommandObserver.
142 * Processes user commands.
144 * @param TInt aCommandId ID of the command to respond to.
146 IMPORT_C void ProcessCommandL( TInt aCommandId );
150 * Sets toolbar dimmed. Doesn't redraw.
152 * @param aDimmed is ETrue to dim the toolbar,
153 * EFalse to set the toolbar as not dimmed
155 IMPORT_C void SetDimmed( TBool aDimmed );
159 * Handles key events.
161 * @param aKeyEvent The key event
162 * @param aType The type of key event: EEventKey, EEventKeyUp
164 * @return TKeyResponse Indicates whether or not the key event was used
167 IMPORT_C TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent,
172 * Gets the control's input capabilities.
174 * @return The control's input capabilities.
176 IMPORT_C TCoeInputCapabilities InputCapabilities() const;
179 * From MCoeControlBackground.
180 * Draw the background for a given control.
181 * The text drawer that shall be used to draw text on the specific
182 * background can be fetched through the GetTextDrawer() method.
184 * @param aGc Graphics context used for drawing.
185 * @param aControl The control being drawn (may be a child of the drawer).
186 * @param aRect The area to be redrawn.
188 IMPORT_C void Draw( CWindowGc& aGc,
189 const CCoeControl& aControl,
190 const TRect& aRect ) const;
192 public: // New functions
195 * Gets a pointer to the specified control.
197 * @param aControlId The ID of the control for which a pointer is
199 * @return Pointer to the control with the specified ID.
201 IMPORT_C CCoeControl* ControlOrNull( const TInt aControlId ) const;
204 * Shows or hides toolbar. Position of the top left corner should be set
205 * in advance. Toolbar set visible with this method is by default focusing.
206 * Does nothing if toolbar is disabled.
207 * @param aVisible ETrue to show it, EFalse to hide it.
209 IMPORT_C void SetToolbarVisibility( const TBool aVisible );
212 * Shows or hides toolbar. Position of the top left corner should be set
213 * in advance. This overload of the method allows toolbar to be set
214 * non-focusing. Does nothing if toolbar is disabled.
215 * @param aVisible ETrue to show it, EFalse to hide it.
216 * @param aFocusing ETrue to set toolbar focusing, otherwise EFalse.
218 IMPORT_C void SetToolbarVisibility( const TBool aVisible,
219 const TBool aFocusing );
222 * Dims (greys out) or undims a toolbar item.
224 * @param aCommandId The command (as defined in an .hrh file)
225 * associated with this toolbar item. This identifies the toolbar
226 * item, whose text is to be dimmed or un-dimmed.
227 * @param aDimmed Use ETrue to dim this toolbar item or EFalse to
228 * un-dim this toolbar item.
229 * @param aDrawNow Should be ETrue for the item to be redrawn.
231 IMPORT_C void SetItemDimmed( const TInt aCommandId,
233 const TBool aDrawNow );
236 * Hides or unhides a toolbar item.
238 * @param aCommandId The command (as defined in an .hrh file)
239 * associated with this toolbar item. This identifies the toolbar
240 * item, which will be set to hidden or unhidden.
241 * @param aHide Use ETrue to hide this toolbar item or EFalse to
242 * unhide this toolbar item.
243 * @param aDrawNow Should be ETrue for the toolbar to be redrawn.
245 IMPORT_C void HideItem( const TInt aCommandId,
247 const TBool aDrawNow );
250 * Sets the observer for the toolbar.
252 * @param aObserver A pointer to the observer. Ownership is not changed.
254 IMPORT_C void SetToolbarObserver( MAknToolbarObserver* aObserver );
257 * Returns a pointer to the toolbar observer.
259 * @return Pointer to the toolbar observer.
261 IMPORT_C MAknToolbarObserver* ToolbarObserver();
264 * Adds one item to the end of the toolbar. Takes ownership.
265 * Leaves with value KErrNotSupported, if the control type is not
266 * supported by toolbar (see CAknToolbar::IsSupportedItemType()).
268 * @param aItem The control.
269 * @param aType The type of the new toolbar item.
270 * @param aCommandId The command ID for this item.
271 * @param aFlags The flags.
273 IMPORT_C void AddItemL( CCoeControl* aItem,
275 const TInt aCommandId,
279 * Adds one item to the specified place. Takes ownership.
280 * Leaves with value KErrNotSupported, if the control type is not
281 * supported by toolbar (see CAknToolbar::IsSupportedItemType()).
283 * @param aItem The control.
284 * @param aType The type of the new toolbar item.
285 * @param aCommandId The command ID for this item.
286 * @param aFlags The flags.
287 * @param aIndex The index in array at which item should be added.
289 IMPORT_C void AddItemL( CCoeControl* aItem,
291 const TInt aCommandId,
296 * Removes one item from the toolbar.
298 * @param aCommandId The ID of the item which should be removed.
300 IMPORT_C void RemoveItem( const TInt aCommandId );
303 * Returns ETrue if the type of the item can be included in the
306 * @return ETrue for the supported type, otherwise EFalse.
308 IMPORT_C TBool IsSupportedItemType( const TInt aType ) const;
311 * Changes the command ID for the initially focused item when toolbar is
312 * shown or gain focus. Notice that, if this item is not visible, then
313 * focus will be according default behaviour. Normally, focus will be on
314 * the first item, if KAknToolbarMiddleItemFocused flag was not used.
316 * @param aCommandId The command ID for the item to get focus.
318 IMPORT_C void SetInitialFocusedItem( const TInt aCommandId );
321 * Called by the framework to handle the emphasising or
322 * de-emphasising of a toolbar window when it is needed.
324 * @param aEmphasis ETrue to emphasize the menu, EFalse otherwise.
326 IMPORT_C void SetEmphasis( const TBool aEmphasis );
329 * Returns toolbar visibility at this moment
331 * @return ETrue, if toolbar is shown.
333 IMPORT_C TBool IsShown() const;
336 * Specifies whether toolbar should be shown with sliding effect or not.
337 * By default toolbar is shown with sliding.
339 * @param aSlide ETrue for sliding effect, EFalse without sliding.
341 IMPORT_C void SetWithSliding( const TBool aSlide );
344 * Sets whether the toolbar should be closed or remain open after the
345 * specified command is issued from the toolbar.
347 * @param aCommandId The command.
348 * @param aClose ETrue, if toolbar should be close.
350 IMPORT_C void SetCloseOnCommand( const TInt aCommandId,
351 const TBool aClose );
354 * Sets whether the toolbar should be closed after a command is issued
355 * from the toolbar. This method affects every command on the toolbar.
357 * @param aClose ETrue, if toolbar should be closed.
359 IMPORT_C void SetCloseOnAllCommands( const TBool aClose );
362 * Sets toolbar orientation.
364 * @param aOrientation Orientation that should be used for toolbar.
367 IMPORT_C void SetOrientation( const TAknOrientation aOrientation );
370 * Updates transparent toolbar's background.
373 IMPORT_C void UpdateBackground();
376 * Shows toolbar again after it has been hidden for background changing
381 void ShowToolbarForBackgroundUpdate();
384 * Disables/Enables toolbar so that it cannot/can be activated from e.g.
385 * touch pane. Needed especially if a dialog is on the screen and
386 * toolbar is not wished to be shown. Leaves with value KErrToolbarShown
387 * if called when toolbar is shown.
389 * @param aDisable ETrue if toolbar should be disabled
393 IMPORT_C void DisableToolbarL( TBool aDisable );
396 * Checks if toolbar is disabled.
398 * @return ETrue if toolbar is disabled, EFalse if not
402 IMPORT_C TBool IsToolbarDisabled() const;
405 * Moves highlight from one item to another. Leaves with
406 * value KErrNotFound if item not found.
408 * @param aCommandId command id of the item to be focused.
412 IMPORT_C void SetFocusedItemL( const TInt aCommandId );
415 * Returns command id of focused item.
417 * @return command id of focused item. Returns KErrNotFound if
418 * no item is focused.
422 IMPORT_C TInt FocusedItem() const;
425 * Takes focus away from edwin or other controls if needed. Called by
426 * AknAppUi from HandleWsEventL when a pointer event is targeted to
427 * other control than toolbar.
431 void PrepareForFocusLossL();
434 * Returns event modifiers defined in TEventModifiers in this header.
435 * This can be used by applications in OfferToolbarEventL to know if
436 * the event sent was for example a long press event. Information is
437 * valid only during OfferToolbarEventL.
439 * @return event modifiers
442 IMPORT_C TInt EventModifiers() const;
445 * Returns the flags of toolbar. Flags are defined in eikon.hrh.
446 * @return toolbar flags
449 IMPORT_C TInt ToolbarFlags() const;
452 * Count faded components
453 * @return then number of faded components
455 TInt CountFadedComponents();
458 * Returns faded components by index
459 * @return faded component
461 CCoeControl* FadedComponent( TInt aIndex );
464 * Reduces main pane rect if it intersects with toolbar's rect
465 * @param aBoundingRect the rect to reduce
467 void ReduceRect( TRect& aBoundingRect ) const;
470 * Sets the resource id for toolbar softkeys. If cba allready exists
471 * then changes the existing softkeys and redraws toolbar cba.
472 * @param aSoftkeyResourceId ID of the resource structure specifying
473 * the command buttons.
476 IMPORT_C void SetSoftkeyResourceIdL( TInt aSoftkeyResourceId );
479 * Extension notifies of its events using this method
480 * aCommandId command id of the button
482 void ExtensionEventL( TInt aCommandId );
485 * Returns the index of the toolbar item inside of the iVisibleItems
488 * @param aControl The control which index is needed.
489 * @return Index of the toolbar item.
491 TInt ToolbarVisibleIndexByControl( const CCoeControl* aControl ) const;
494 * Returns pointer to toolbar extension if available
495 * @return toolbar extension or NULL
497 IMPORT_C CAknToolbarExtension* ToolbarExtension() const;
500 * Calls DynInitToolbar with extensions commmand id
503 void DynInitExtensionL( CCoeControl* aControl );
506 * Callback for sliding toolbar.
508 static TInt ReadyToSlide( TAny* aThis );
513 void SlideWithIdle();
516 * Hides/Unhides toolbar items temporarily. When called with ETrue
517 * toolbar draws just background in landscape and is hidden in portrait.
518 * Calling with EFalse returns the situation to normal, so drawing the
519 * items normally in portrait and landscape. Use this method only with
522 * @param aHide ETrue if hiding items, EFalse if unhiding.
524 IMPORT_C void HideItemsAndDrawOnlyBackground( TBool aHide );
527 * Hides/Unhides toolbar items temporarily. When called with ETrue
528 * toolbar draws just background in landscape and is hidden in portrait.
529 * Toolbar window priority is changed to priority passed in parameter.
530 * Priority should be one of the window priority values defined in
531 * TCoeWinPriority. Default priority is ECoeWinPriorityLow.
532 * Note that if toolbar is already hidden, the toolbar window priority
533 * is still changed to priority passed in parameter.
534 * Calling the function HideItemsAndDrawOnlyBackground with EFalse returns
535 * the situation to normal, so drawing the items normally in portrait
536 * and landscape. Use this method only with fixed toolbar!
538 * @param aHide ETrue if hiding items, EFalse if unhiding.
539 * @param aPriority Ordinal priority of toolbar window.
541 IMPORT_C void HideItemsAndDrawOnlyBackground( TBool aHide, TInt aPriority );
543 * Sets the skin background for fixed toolbar. The new background is used
544 * for all the subsequent drawing operations. This method does not itself
549 * @param aIID Skin item ID of the new background. This is one of the constants
550 * defined in AknsConstants.h, and the usual values are KAknsIIDQsnBgScreen
553 IMPORT_C void SetSkinBackgroundId( const TAknsItemID& aIID );
556 protected: // From base class
560 * Responds to size changes to sets the size and position of
561 * the contents of this control.
563 IMPORT_C void SizeChanged();
567 * This function is called whenever a control gains or loses focus.
569 * @param aDrawNow Contains the value that was passed to it by SetFocus().
571 IMPORT_C void FocusChanged( TDrawNow aDrawNow );
575 * For future extensions.
577 * @param aInterface The ID for the extension interface.
579 IMPORT_C void* ExtensionInterface( TUid aInterface );
583 * Retrieves an object of the same type as that encapsulated in aId.
585 * @param aId An encapsulated object type ID.
586 * @return Encapsulated pointer to the object provided.
587 * Note that the encapsulated pointer may be NULL.
589 IMPORT_C TTypeUid::Ptr MopSupplyObject( TTypeUid aId );
591 private: // Constructors
594 * C++ default constructor.
599 * Symbian 2nd phase constructor.
603 private: // From base class
607 * Constructs controls from a resource file.
608 * Hides the one defined in base class.
610 * @param aReader The resource reader with which to access
611 * the control's resource values.
613 IMPORT_C void ConstructFromResourceL( TResourceReader& aReader );
617 * Draw a control called by window server.
619 * @param aRect The region of the control to be redrawn.
620 * Co-ordinates are relative to the control's origin (top left corner).
622 IMPORT_C void Draw( const TRect& aRect ) const;
624 private: // New functions
627 * Constructs controls from a resource file.
629 * @param aResourceId The ID for this component's resource.
631 void ConstructFromResourceL( const TInt aResourceId );
634 * Constructs one of the toolbar items.
636 * @param aReader The resource reader with which to access the control's
638 * @return Constructed toolbar item.
640 CAknToolbarItem* ConstructControlLC( TResourceReader& aReader );
643 * Calculates size and position of the toolbar depending on the
644 * number and size of the toolbar items.
646 * @return Toolbar rectangular.
648 TRect CalculateSizeAndPosition();
651 * Calculates rects that are used in calculating the size
652 * and position of the toolbar items
654 * @param aMainPaneRect main pane rect
655 * @param aToolbarRect rect for toolbar
656 * @param aGridPaneRect rect for grid pane
657 * @param aCellPaneRect rect for cell pane
659 void CalculateRects( TRect& aMainPaneRect, TRect& aToolbarRect,
660 TRect& aGridPaneRect, TRect& aCellPaneRect );
663 * Calculates the position and size of the control rect
665 * @param aCurrentCellPaneRect current cell pane rect is needed to
666 * get correct control rect from layout data.
667 * @return control rect for the toolbar item
669 TRect CalculateControlRect( TRect& aCurrentCellPaneRect );
672 * Checks the number of visible items, and if too few the toolbar CBA is
673 * deleted. If last time there were too few items then toolbar CBA is
674 * created again. Also the ordinal position of the toolbar is set if
675 * there are changes to previous situation.
677 * @return ETrue if too few items are visible, EFalse if not
679 TBool TooFewItemsVisible();
682 * Returns toolbar item object for the specified control.
684 * @param aControl Pointer to the control.
685 * @return Pointer to the toolbar item.
687 CAknToolbarItem* ToolbarItemByControl( const CCoeControl* aControl ) const;
690 * Returns toolbar item object for the specified command ID.
692 * @param aId The command ID of the item.
693 * @return Pointer to the toolbar item.
695 CAknToolbarItem* ToolbarItemById( const TInt aId ) const;
698 * Returns the index of the toolbar item inside of the iItems array.
700 * @param aId The command ID of the item
701 * @return Index of the toolbar item.
703 TInt ToolbarItemIndexById( const TInt aId ) const;
706 * Returns the index of the toolbar item inside of the iItems array.
708 * @param aControl The control which index is needed.
709 * @return Index of the toolbar item.
711 TInt ToolbarItemIndexByControl( const CCoeControl* aControl ) const;
714 * Returns the index of the toolbar item inside of the iVisibleItems
717 * @param aId The command ID of the item.
718 * @return Index of the toolbar item.
720 TInt ToolbarVisibleIndexById( const TInt aId ) const;
723 * Draws toolbar with sliding effect.
725 * @param aEndPos The position of the top left corner of toolbar at
726 * the end of animation.
728 void SlideToolbar( const TPoint& aEndPos );
731 * Changes CBA text if all items are dimmed.
733 void SetRightCbaTextL();
736 * Returns next non-dimmed and non-hidden control index.
738 * @param aStartIndex The index of the item from which the search
740 * @param aMoveForward ETrue if search is done from lower index to
742 * @return The index of next non-dimmed and non-hidden item.
744 TInt GetNextSelectableItemIndex( TInt aStartIndex,
745 TBool aMoveForward );
748 * Moves highlight from one item to another. It also will change
749 * softkey text for the focused toolbar.
751 * @param aItemIndex The index for the newly focused item.
752 * @param aDrawNow Specifies whether the item should be redrawn.
753 * @param aMoveForward Specifies whether the next item in the array
754 * should be selected when the item with aItemIndex is dimmed.
755 * @param aPrepareControl Specifies whether PrepareForFocusLossL() or
756 * PrepareForFocusGainL() functions should be called.
758 void MoveHighlightL( TInt aItemIndex,
759 const TBool aDrawNow,
760 const TBool aMoveForward = ETrue,
761 const TBool aPrepareControl = ETrue );
764 * Makes toolbar visible and activates it. Position of the top left
765 * corner should be set in advance. Also use SetFocus() to specify
766 * whether toolbar gets key events or not.
776 * Sets the focus to the middle or the first item, depending on the
779 * @param aDrawNow if the newly focused item should be redrawn.
781 void InitFocusedItemL( const TBool aDrawNow );
784 * Sets the flag to be on or off and also calls
785 * CCoeControl::MakeVisible().
787 void SetShown( const TBool aShown );
790 * Selects/deselects the toolbar item at given index.
792 void SelectItemL( const TInt aIndex, const TBool aSelect );
795 * Gets rect from layout data.
797 TRect RectFromLayout( const TRect& aParent,
798 const TAknWindowComponentLayout& aComponentLayout ) const;
801 * Callback to get notified when ready to show toolbar again
803 static TInt WaitForScreenSwitch(TAny* aThis);
806 * Hides toolbar so that screen capture can be taken from the
807 * background in order to update it.
809 void HideToolbarForBackgroundUpdate();
812 * Updates control positions so that tooltips are positioned correctly
814 void UpdateControlPositions();
817 * Shows toolbar via CIdle. As a result, toolbar's window priority is
818 * setted after the application's container window. This places toolbar
819 * to the right place in the window tree.
824 * Callback for delayed toolbar showing.
826 static TInt ShowDelayedToolbar( TAny* aThis );
830 * Fades behind toolbar
831 * @param aFade if ETrue then fade
833 void FadeBehindPopup( TBool aFade );
836 * Sets buttons to check their touchable areas when tapped
838 void CheckHitAreas( );
841 * Counts buttons of fixed tool bar and adds button(s) if needed
842 * There has to bee at leas three buttons in fixed toolbar.
844 void CheckFixedToolbarButtonsL();
847 * Draws backgrounds of fixed toolbar
848 * @param aGc Graphics context used for drawing.
849 * @param aControl The control being drawn (may be a child of the drawer).
850 * @param aRect The area to be drawn.
852 void DrawFixedBackgroundL( CWindowGc& aGc,
853 const CCoeControl& aControl,
854 const TRect& aRect ) const;
857 * Adjusts button's properties depending on the toolbar's features.
859 void AdjustButton( CAknButton& aButton );
862 * Adjusts all buttons' properties depending on the toolbar's features.
864 void AdjustAllButtons();
867 * Adjusts toolbar's and overlying dialog's window positions so that
868 * dialog is displayed on top of the toolbar.
870 void SetOrdinalPositions() const;
873 * Updates control visibility based on toolbar visibility and
874 * buttons visibility inside toolbar.
876 void UpdateControlVisibility();
879 * Update item tooltip position
881 void UpdateItemTooltipPosition();
883 private: // Member variables
885 // Array for toolbar items
886 RPointerArray<CAknToolbarItem> iItems;
888 // Array for visible toolbar items
889 RPointerArray<CAknToolbarItem> iVisibleItems;
894 // Observer to report toolbar item events, not owned
895 MAknToolbarObserver* iToolbarObserver;
897 // Index of focused item, used with focusable toolbar
900 // Index of selected item, used with focusable and non-focusable toolbar
903 // Toolbar cba, used with focusable toolbar
905 CEikButtonGroupContainer* iToolbarCba;
907 // Resource id for toolbar
908 TInt iToolbarResourceId;
910 // The default focused item
911 TInt iInitialFocusedItem;
913 // Last focused item before focus was lost
914 TInt iLastFocusedItem;
916 // Toolbar frame context
918 CAknsFrameBackgroundControlContext* iFrameContext;
920 // Toolbar background context
922 CAknsBasicBackgroundControlContext* iBgContext;
924 // Toolbar orientation
925 TAknOrientation iOrientation;
927 // Transparency bitmap
929 // this member variable is deserted
930 CFbsBitmap* iBgBitmap;
932 // This is used to call ShowToolbarForBackgroundChange after toolbar has
938 // this member variable is deserted
939 CFbsBitmap* iHighlightBitmap;
942 // this member variable is deserted
943 CFbsBitmap* iHighlightMask;
946 TInt iEventModifiers;
949 TAknPopupFader iFader;
952 TInt iSoftkeyResource;
954 // Used to store previous item that had pointerevents
957 // Item that catches point down event
960 // Step for toolbar sliding
963 // End position for toolbar sliding
966 // Internal flags used to store toolbar's properties
967 TBitFlags iInternalFlags;
969 // Background area to be drawn when not enough visible items
970 // to cover the toolbar area
973 // Toolbar window priority if set in HideItemsAndDrawOnlyBackground
974 TInt iDrawingPriority;
977 * Background theme ID user defined. And in default, its value is
978 * KAknsIIDNone is used and toolbar draw background with the current skin
983 #endif // __AKNTOOLBAR_H__