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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.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>
31 // FORWARD DECLARATIONS
33 class CAknToolbarItem;
34 class CAknToolbarExtension;
35 class MAknToolbarObserver;
36 class CEikButtonGroupContainer;
37 class TAknWindowComponentLayout;
38 class CAknsFrameBackgroundControlContext;
39 class CAknsBasicBackgroundControlContext;
42 // DisableToolbarL leaves with this value if toolbar is shown, since toolbar
43 // should not be shown when disabling/enabling toolbar.
44 const TInt KErrToolbarShown = -101;
49 * The class to provide toolbar for the application
52 * @since Series 60 3.1
54 class CAknToolbar : public CAknControl, public MCoeControlObserver,
55 public MCoeControlBackground, public MEikCommandObserver,
56 public MAknFadedComponent
58 public: //Enumerations:
60 enum TEventModifiers {
65 public: // Constructors and destructor
68 * Two-phased constructor.
70 * @param aResourceId The ID for this component's resource
71 * @return Pointer to the created toolbar object
73 IMPORT_C static CAknToolbar* NewL( const TInt aResourceId );
76 * Two-phased constructor.
78 * @param aResourceId The ID for this component's resource
79 * @return Pointer to the created toolbar object
81 IMPORT_C static CAknToolbar* NewLC( const TInt aResourceId );
88 public: // From base class
92 * Gets the number of controls contained in a compound control.
94 * @return The number of component controls contained by this control.
96 IMPORT_C TInt CountComponentControls() const;
100 * Gets the specified component of a compound control.
102 * @param aIndex The index of the control to get
103 * @return The component control with an index of aIndex.
105 IMPORT_C CCoeControl* ComponentControl( TInt aIndex ) const ;
109 * Handles pointer events.
111 * @param aPointerEvent The pointer event.
113 IMPORT_C void HandlePointerEventL( const TPointerEvent& aPointerEvent );
117 * Handles a change to the control's resources.
119 * @param aType A message UID value.
121 IMPORT_C void HandleResourceChange( TInt aType );
124 * From MCoeControlObserver.
125 * Handles an event from an observed toolbar item.
127 * @param aControl The control which sent the event
128 * @param aEventType The event type
130 IMPORT_C void HandleControlEventL( CCoeControl* aControl,
131 TCoeEvent aEventType );
135 * Responds to changes in the position of a toolbar.
137 IMPORT_C void PositionChanged();
140 * From MEikCommandObserver.
141 * Processes user commands.
143 * @param TInt aCommandId ID of the command to respond to.
145 IMPORT_C void ProcessCommandL( TInt aCommandId );
149 * Sets toolbar dimmed. Doesn't redraw.
151 * @param aDimmed is ETrue to dim the toolbar,
152 * EFalse to set the toolbar as not dimmed
154 IMPORT_C void SetDimmed( TBool aDimmed );
158 * Handles key events.
160 * @param aKeyEvent The key event
161 * @param aType The type of key event: EEventKey, EEventKeyUp
163 * @return TKeyResponse Indicates whether or not the key event was used
166 IMPORT_C TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent,
171 * Gets the control's input capabilities.
173 * @return The control's input capabilities.
175 IMPORT_C TCoeInputCapabilities InputCapabilities() const;
178 * From MCoeControlBackground.
179 * Draw the background for a given control.
180 * The text drawer that shall be used to draw text on the specific
181 * background can be fetched through the GetTextDrawer() method.
183 * @param aGc Graphics context used for drawing.
184 * @param aControl The control being drawn (may be a child of the drawer).
185 * @param aRect The area to be redrawn.
187 IMPORT_C void Draw( CWindowGc& aGc,
188 const CCoeControl& aControl,
189 const TRect& aRect ) const;
191 public: // New functions
194 * Gets a pointer to the specified control.
196 * @param aControlId The ID of the control for which a pointer is
198 * @return Pointer to the control with the specified ID.
200 IMPORT_C CCoeControl* ControlOrNull( const TInt aControlId ) const;
203 * Shows or hides toolbar. Position of the top left corner should be set
204 * in advance. Toolbar set visible with this method is by default focusing.
205 * Does nothing if toolbar is disabled.
206 * @param aVisible ETrue to show it, EFalse to hide it.
208 IMPORT_C void SetToolbarVisibility( const TBool aVisible );
211 * Shows or hides toolbar. Position of the top left corner should be set
212 * in advance. This overload of the method allows toolbar to be set
213 * non-focusing. Does nothing if toolbar is disabled.
214 * @param aVisible ETrue to show it, EFalse to hide it.
215 * @param aFocusing ETrue to set toolbar focusing, otherwise EFalse.
217 IMPORT_C void SetToolbarVisibility( const TBool aVisible,
218 const TBool aFocusing );
221 * Dims (greys out) or undims a toolbar item.
223 * @param aCommandId The command (as defined in an .hrh file)
224 * associated with this toolbar item. This identifies the toolbar
225 * item, whose text is to be dimmed or un-dimmed.
226 * @param aDimmed Use ETrue to dim this toolbar item or EFalse to
227 * un-dim this toolbar item.
228 * @param aDrawNow Should be ETrue for the item to be redrawn.
230 IMPORT_C void SetItemDimmed( const TInt aCommandId,
232 const TBool aDrawNow );
235 * Hides or unhides a toolbar item.
237 * @param aCommandId The command (as defined in an .hrh file)
238 * associated with this toolbar item. This identifies the toolbar
239 * item, which will be set to hidden or unhidden.
240 * @param aHide Use ETrue to hide this toolbar item or EFalse to
241 * unhide this toolbar item.
242 * @param aDrawNow Should be ETrue for the toolbar to be redrawn.
244 IMPORT_C void HideItem( const TInt aCommandId,
246 const TBool aDrawNow );
249 * Sets the observer for the toolbar.
251 * @param aObserver A pointer to the observer. Ownership is not changed.
253 IMPORT_C void SetToolbarObserver( MAknToolbarObserver* aObserver );
256 * Returns a pointer to the toolbar observer.
258 * @return Pointer to the toolbar observer.
260 IMPORT_C MAknToolbarObserver* ToolbarObserver();
263 * Adds one item to the end of the toolbar. Takes ownership.
264 * Leaves with value KErrNotSupported, if the control type is not
265 * supported by toolbar (see CAknToolbar::IsSupportedItemType()).
267 * @param aItem The control.
268 * @param aType The type of the new toolbar item.
269 * @param aCommandId The command ID for this item.
270 * @param aFlags The flags.
272 IMPORT_C void AddItemL( CCoeControl* aItem,
274 const TInt aCommandId,
278 * Adds one item to the specified place. Takes ownership.
279 * Leaves with value KErrNotSupported, if the control type is not
280 * supported by toolbar (see CAknToolbar::IsSupportedItemType()).
282 * @param aItem The control.
283 * @param aType The type of the new toolbar item.
284 * @param aCommandId The command ID for this item.
285 * @param aFlags The flags.
286 * @param aIndex The index in array at which item should be added.
288 IMPORT_C void AddItemL( CCoeControl* aItem,
290 const TInt aCommandId,
295 * Removes one item from the toolbar.
297 * @param aCommandId The ID of the item which should be removed.
299 IMPORT_C void RemoveItem( const TInt aCommandId );
302 * Returns ETrue if the type of the item can be included in the
305 * @return ETrue for the supported type, otherwise EFalse.
307 IMPORT_C TBool IsSupportedItemType( const TInt aType ) const;
310 * Changes the command ID for the initially focused item when toolbar is
311 * shown or gain focus. Notice that, if this item is not visible, then
312 * focus will be according default behaviour. Normally, focus will be on
313 * the first item, if KAknToolbarMiddleItemFocused flag was not used.
315 * @param aCommandId The command ID for the item to get focus.
317 IMPORT_C void SetInitialFocusedItem( const TInt aCommandId );
320 * Called by the framework to handle the emphasising or
321 * de-emphasising of a toolbar window when it is needed.
323 * @param aEmphasis ETrue to emphasize the menu, EFalse otherwise.
325 IMPORT_C void SetEmphasis( const TBool aEmphasis );
328 * Returns toolbar visibility at this moment
330 * @return ETrue, if toolbar is shown.
332 IMPORT_C TBool IsShown() const;
335 * Specifies whether toolbar should be shown with sliding effect or not.
336 * By default toolbar is shown with sliding.
338 * @param aSlide ETrue for sliding effect, EFalse without sliding.
340 IMPORT_C void SetWithSliding( const TBool aSlide );
343 * Sets whether the toolbar should be closed or remain open after the
344 * specified command is issued from the toolbar.
346 * @param aCommandId The command.
347 * @param aClose ETrue, if toolbar should be close.
349 IMPORT_C void SetCloseOnCommand( const TInt aCommandId,
350 const TBool aClose );
353 * Sets whether the toolbar should be closed after a command is issued
354 * from the toolbar. This method affects every command on the toolbar.
356 * @param aClose ETrue, if toolbar should be closed.
358 IMPORT_C void SetCloseOnAllCommands( const TBool aClose );
361 * Sets toolbar orientation.
363 * @param aOrientation Orientation that should be used for toolbar.
366 IMPORT_C void SetOrientation( const TAknOrientation aOrientation );
369 * Updates transparent toolbar's background.
372 IMPORT_C void UpdateBackground();
375 * Shows toolbar again after it has been hidden for background changing
380 void ShowToolbarForBackgroundUpdate();
383 * Disables/Enables toolbar so that it cannot/can be activated from e.g.
384 * touch pane. Needed especially if a dialog is on the screen and
385 * toolbar is not wished to be shown. Leaves with value KErrToolbarShown
386 * if called when toolbar is shown.
388 * @param aDisable ETrue if toolbar should be disabled
392 IMPORT_C void DisableToolbarL( TBool aDisable );
395 * Checks if toolbar is disabled.
397 * @return ETrue if toolbar is disabled, EFalse if not
401 IMPORT_C TBool IsToolbarDisabled() const;
404 * Moves highlight from one item to another. Leaves with
405 * value KErrNotFound if item not found.
407 * @param aCommandId command id of the item to be focused.
411 IMPORT_C void SetFocusedItemL( const TInt aCommandId );
414 * Returns command id of focused item.
416 * @return command id of focused item. Returns KErrNotFound if
417 * no item is focused.
421 IMPORT_C TInt FocusedItem() const;
424 * Takes focus away from edwin or other controls if needed. Called by
425 * AknAppUi from HandleWsEventL when a pointer event is targeted to
426 * other control than toolbar.
430 void PrepareForFocusLossL();
433 * Returns event modifiers defined in TEventModifiers in this header.
434 * This can be used by applications in OfferToolbarEventL to know if
435 * the event sent was for example a long press event. Information is
436 * valid only during OfferToolbarEventL.
438 * @return event modifiers
441 IMPORT_C TInt EventModifiers() const;
444 * Returns the flags of toolbar. Flags are defined in eikon.hrh.
445 * @return toolbar flags
448 IMPORT_C TInt ToolbarFlags() const;
451 * Count faded components
452 * @return then number of faded components
454 TInt CountFadedComponents();
457 * Returns faded components by index
458 * @return faded component
460 CCoeControl* FadedComponent( TInt aIndex );
463 * Reduces main pane rect if it intersects with toolbar's rect
464 * @param aBoundingRect the rect to reduce
466 void ReduceRect( TRect& aBoundingRect ) const;
469 * Sets the resource id for toolbar softkeys. If cba allready exists
470 * then changes the existing softkeys and redraws toolbar cba.
471 * @param aSoftkeyResourceId ID of the resource structure specifying
472 * the command buttons.
475 IMPORT_C void SetSoftkeyResourceIdL( TInt aSoftkeyResourceId );
478 * Extension notifies of its events using this method
479 * aCommandId command id of the button
481 void ExtensionEventL( TInt aCommandId );
484 * Returns the index of the toolbar item inside of the iVisibleItems
487 * @param aControl The control which index is needed.
488 * @return Index of the toolbar item.
490 TInt ToolbarVisibleIndexByControl( const CCoeControl* aControl ) const;
493 * Returns pointer to toolbar extension if available
494 * @return toolbar extension or NULL
496 IMPORT_C CAknToolbarExtension* ToolbarExtension() const;
499 * Calls DynInitToolbar with extensions commmand id
502 void DynInitExtensionL( CCoeControl* aControl );
505 * Callback for sliding toolbar.
507 static TInt ReadyToSlide( TAny* aThis );
512 void SlideWithIdle();
515 * Hides/Unhides toolbar items temporarily. When called with ETrue
516 * toolbar draws just background in landscape and is hidden in portrait.
517 * Calling with EFalse returns the situation to normal, so drawing the
518 * items normally in portrait and landscape. Use this method only with
521 * @param aHide ETrue if hiding items, EFalse if unhiding.
523 IMPORT_C void HideItemsAndDrawOnlyBackground( TBool aHide );
526 * Hides/Unhides toolbar items temporarily. When called with ETrue
527 * toolbar draws just background in landscape and is hidden in portrait.
528 * Toolbar window priority is changed to priority passed in parameter.
529 * Priority should be one of the window priority values defined in
530 * TCoeWinPriority. Default priority is ECoeWinPriorityLow.
531 * Note that if toolbar is already hidden, the toolbar window priority
532 * is still changed to priority passed in parameter.
533 * Calling the function HideItemsAndDrawOnlyBackground with EFalse returns
534 * the situation to normal, so drawing the items normally in portrait
535 * and landscape. Use this method only with fixed toolbar!
537 * @param aHide ETrue if hiding items, EFalse if unhiding.
538 * @param aPriority Ordinal priority of toolbar window.
540 IMPORT_C void HideItemsAndDrawOnlyBackground( TBool aHide, TInt aPriority );
543 protected: // From base class
547 * Responds to size changes to sets the size and position of
548 * the contents of this control.
550 IMPORT_C void SizeChanged();
554 * This function is called whenever a control gains or loses focus.
556 * @param aDrawNow Contains the value that was passed to it by SetFocus().
558 IMPORT_C void FocusChanged( TDrawNow aDrawNow );
562 * For future extensions.
564 * @param aInterface The ID for the extension interface.
566 IMPORT_C void* ExtensionInterface( TUid aInterface );
570 * Retrieves an object of the same type as that encapsulated in aId.
572 * @param aId An encapsulated object type ID.
573 * @return Encapsulated pointer to the object provided.
574 * Note that the encapsulated pointer may be NULL.
576 IMPORT_C TTypeUid::Ptr MopSupplyObject( TTypeUid aId );
578 private: // Constructors
581 * C++ default constructor.
586 * Symbian 2nd phase constructor.
590 private: // From base class
594 * Constructs controls from a resource file.
595 * Hides the one defined in base class.
597 * @param aReader The resource reader with which to access
598 * the control's resource values.
600 IMPORT_C void ConstructFromResourceL( TResourceReader& aReader );
604 * Draw a control called by window server.
606 * @param aRect The region of the control to be redrawn.
607 * Co-ordinates are relative to the control's origin (top left corner).
609 IMPORT_C void Draw( const TRect& aRect ) const;
611 private: // New functions
614 * Constructs controls from a resource file.
616 * @param aResourceId The ID for this component's resource.
618 void ConstructFromResourceL( const TInt aResourceId );
621 * Constructs one of the toolbar items.
623 * @param aReader The resource reader with which to access the control's
625 * @return Constructed toolbar item.
627 CAknToolbarItem* ConstructControlLC( TResourceReader& aReader );
630 * Calculates size and position of the toolbar depending on the
631 * number and size of the toolbar items.
633 * @return Toolbar rectangular.
635 TRect CalculateSizeAndPosition();
638 * Calculates rects that are used in calculating the size
639 * and position of the toolbar items
641 * @param aMainPaneRect main pane rect
642 * @param aToolbarRect rect for toolbar
643 * @param aGridPaneRect rect for grid pane
644 * @param aCellPaneRect rect for cell pane
646 void CalculateRects( TRect& aMainPaneRect, TRect& aToolbarRect,
647 TRect& aGridPaneRect, TRect& aCellPaneRect );
650 * Calculates the position and size of the control rect
652 * @param aCurrentCellPaneRect current cell pane rect is needed to
653 * get correct control rect from layout data.
654 * @return control rect for the toolbar item
656 TRect CalculateControlRect( TRect& aCurrentCellPaneRect );
659 * Checks the number of visible items, and if too few the toolbar CBA is
660 * deleted. If last time there were too few items then toolbar CBA is
661 * created again. Also the ordinal position of the toolbar is set if
662 * there are changes to previous situation.
664 * @return ETrue if too few items are visible, EFalse if not
666 TBool TooFewItemsVisible();
669 * Returns toolbar item object for the specified control.
671 * @param aControl Pointer to the control.
672 * @return Pointer to the toolbar item.
674 CAknToolbarItem* ToolbarItemByControl( const CCoeControl* aControl ) const;
677 * Returns toolbar item object for the specified command ID.
679 * @param aId The command ID of the item.
680 * @return Pointer to the toolbar item.
682 CAknToolbarItem* ToolbarItemById( const TInt aId ) const;
685 * Returns the index of the toolbar item inside of the iItems array.
687 * @param aId The command ID of the item
688 * @return Index of the toolbar item.
690 TInt ToolbarItemIndexById( const TInt aId ) const;
693 * Returns the index of the toolbar item inside of the iItems array.
695 * @param aControl The control which index is needed.
696 * @return Index of the toolbar item.
698 TInt ToolbarItemIndexByControl( const CCoeControl* aControl ) const;
701 * Returns the index of the toolbar item inside of the iVisibleItems
704 * @param aId The command ID of the item.
705 * @return Index of the toolbar item.
707 TInt ToolbarVisibleIndexById( const TInt aId ) const;
710 * Draws toolbar with sliding effect.
712 * @param aEndPos The position of the top left corner of toolbar at
713 * the end of animation.
715 void SlideToolbar( const TPoint& aEndPos );
718 * Changes CBA text if all items are dimmed.
720 void SetRightCbaTextL();
723 * Returns next non-dimmed and non-hidden control index.
725 * @param aStartIndex The index of the item from which the search
727 * @param aMoveForward ETrue if search is done from lower index to
729 * @return The index of next non-dimmed and non-hidden item.
731 TInt GetNextSelectableItemIndex( TInt aStartIndex,
732 TBool aMoveForward );
735 * Moves highlight from one item to another. It also will change
736 * softkey text for the focused toolbar.
738 * @param aItemIndex The index for the newly focused item.
739 * @param aDrawNow Specifies whether the item should be redrawn.
740 * @param aMoveForward Specifies whether the next item in the array
741 * should be selected when the item with aItemIndex is dimmed.
742 * @param aPrepareControl Specifies whether PrepareForFocusLossL() or
743 * PrepareForFocusGainL() functions should be called.
745 void MoveHighlightL( TInt aItemIndex,
746 const TBool aDrawNow,
747 const TBool aMoveForward = ETrue,
748 const TBool aPrepareControl = ETrue );
751 * Makes toolbar visible and activates it. Position of the top left
752 * corner should be set in advance. Also use SetFocus() to specify
753 * whether toolbar gets key events or not.
763 * Sets the focus to the middle or the first item, depending on the
766 * @param aDrawNow if the newly focused item should be redrawn.
768 void InitFocusedItemL( const TBool aDrawNow );
771 * Sets the flag to be on or off and also calls
772 * CCoeControl::MakeVisible().
774 void SetShown( const TBool aShown );
777 * Selects/deselects the toolbar item at given index.
779 void SelectItemL( const TInt aIndex, const TBool aSelect );
782 * Gets rect from layout data.
784 TRect RectFromLayout( const TRect& aParent,
785 const TAknWindowComponentLayout& aComponentLayout ) const;
788 * Callback to get notified when ready to show toolbar again
790 static TInt WaitForScreenSwitch(TAny* aThis);
793 * Hides toolbar so that screen capture can be taken from the
794 * background in order to update it.
796 void HideToolbarForBackgroundUpdate();
799 * Updates control positions so that tooltips are positioned correctly
801 void UpdateControlPositions();
804 * Shows toolbar via CIdle. As a result, toolbar's window priority is
805 * setted after the application's container window. This places toolbar
806 * to the right place in the window tree.
811 * Callback for delayed toolbar showing.
813 static TInt ShowDelayedToolbar( TAny* aThis );
816 * Modifies highlight bitmap that is 50% transparent to use when drawing
817 * highlight for small transparent toolbar.
819 void ModifyHighlightMaskL( TBool aCreateBitmaps );
822 * Fades behind toolbar
823 * @param aFade if ETrue then fade
825 void FadeBehindPopup( TBool aFade );
828 * Sets buttons to check their touchable areas when tapped
830 void CheckHitAreas( );
833 * Counts buttons of fixed tool bar and adds button(s) if needed
834 * There has to bee at leas three buttons in fixed toolbar.
836 void CheckFixedToolbarButtonsL();
839 * Draws backgrounds of fixed toolbar
840 * @param aGc Graphics context used for drawing.
841 * @param aControl The control being drawn (may be a child of the drawer).
842 * @param aRect The area to be drawn.
844 void DrawFixedBackgroundL( CWindowGc& aGc,
845 const CCoeControl& aControl,
846 const TRect& aRect ) const;
849 * Adjusts button's properties depending on the toolbar's features.
851 void AdjustButton( CAknButton& aButton );
854 * Adjusts all buttons' properties depending on the toolbar's features.
856 void AdjustAllButtons();
859 * Adjusts toolbar's and overlying dialog's window positions so that
860 * dialog is displayed on top of the toolbar.
862 void SetOrdinalPositions() const;
865 * Updates control visibility based on toolbar visibility and
866 * buttons visibility inside toolbar.
868 void UpdateControlVisibility();
870 private: // Member variables
872 // Array for toolbar items
873 RPointerArray<CAknToolbarItem> iItems;
875 // Array for visible toolbar items
876 RPointerArray<CAknToolbarItem> iVisibleItems;
881 // Observer to report toolbar item events, not owned
882 MAknToolbarObserver* iToolbarObserver;
884 // Index of focused item, used with focusable toolbar
887 // Index of selected item, used with focusable and non-focusable toolbar
890 // Toolbar cba, used with focusable toolbar
892 CEikButtonGroupContainer* iToolbarCba;
894 // Resource id for toolbar
895 TInt iToolbarResourceId;
897 // The default focused item
898 TInt iInitialFocusedItem;
900 // Last focused item before focus was lost
901 TInt iLastFocusedItem;
903 // Toolbar frame context
905 CAknsFrameBackgroundControlContext* iFrameContext;
907 // Toolbar background context
909 CAknsBasicBackgroundControlContext* iBgContext;
911 // Toolbar orientation
912 TAknOrientation iOrientation;
914 // Transparency bitmap
916 CFbsBitmap* iBgBitmap;
918 // This is used to call ShowToolbarForBackgroundChange after toolbar has
924 CFbsBitmap* iHighlightBitmap;
927 CFbsBitmap* iHighlightMask;
930 TInt iEventModifiers;
933 TAknPopupFader iFader;
936 TInt iSoftkeyResource;
938 // Used to store previous item that had pointerevents
941 // Step for toolbar sliding
944 // End position for toolbar sliding
947 // Internal flags used to store toolbar's properties
948 TBitFlags iInternalFlags;
950 // Background area to be drawn when not enough visible items
951 // to cover the toolbar area
954 // Toolbar window priority if set in HideItemsAndDrawOnlyBackground
955 TInt iDrawingPriority;
959 #endif // __AKNTOOLBAR_H__