2 * Copyright (c) 1997-1999 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.
19 #if !defined(__EIKMENUB_H__)
20 #define __EIKMENUB_H__
22 #if !defined(__EIKDEF_H__)
26 #if !defined(__EIKBCTRL_H__)
30 #if !defined(__EIKMENUP_H__)
36 #include <aknintermediate.h>
38 class CEikHotKeyTable;
39 class CEikMenuBarExtension;
40 class CAknItemActionMenu;
44 * The CEikMenuBarTitle class encapsulates the data needed to define a menu bar title and
45 * provides some of the functionality required to display the title.
49 class CEikMenuBarTitle : public CBase
53 * Defines a menu bar. See also @c MEikMenuObserver::DynInitMenuPaneL().
54 * See also @c MENU_TITLE for details of the resource interface to menu
60 /** Nominal legth of the text. */
64 * The resource ID from which the menu pane is constructed.
66 TInt iMenuPaneResourceId;
68 * The text to display on the menu pane.
70 TBuf<ENominalTextLength> iText; // less than this actually stored
74 * C++ default constructor.
76 IMPORT_C CEikMenuBarTitle();
80 IMPORT_C ~CEikMenuBarTitle();
82 * Sets the title icon.
84 * @param aIcon The icon to set.
86 IMPORT_C void SetIcon(CGulIcon* aIcon);
89 * Sets whether the bitmap and mask are owned externally or not.
91 * @param aOwnedExternally @c ETrue if bitmaps are set as externally owned.
92 * @c EFalse if bitmaps are set as not being externally owned.
94 IMPORT_C void SetBitmapsOwnedExternally(TBool aOwnedExternally);
97 * Draws the title icon to the graphics context @c aGc, inside the rect @c
98 * aRect with an offset from the left side of the rectangle of size @c
101 * @param aGc Window graphic context.
102 * @param aRect Rectangle area.
103 * @param aLeftMargin Left margin.
105 IMPORT_C void DrawIcon(CWindowGc& aGc, TRect aRect, TInt aLeftMargin) const;
108 * Constructs a new icon for the title, taking ownership of the picture
109 * bitmap and the mask bitmap unless they are externally owned.
111 * @param aBitmap Bitmap.
112 * @param aMask Mask of the bitmap.
114 IMPORT_C void CreateIconL(CFbsBitmap* aBitmap, CFbsBitmap* aMask);
117 * Sets the bitmap for the icon. Transfers
118 * ownership unless the bitmaps are owned externally.
120 * @param aBitmap Bitmap
122 IMPORT_C void SetIconBitmapL(CFbsBitmap* aBitmap);
125 * Sets the bitmap mask for the icon. Transfers ownership
126 * unless the bitmaps are owned externally.
128 * @param aMask Mask of a bitmap.
130 IMPORT_C void SetIconMaskL(CFbsBitmap* aMask);
133 * Gets a pointer to the title icon’s bitmap. Does not imply transfer of
136 * @return Pointer to the title icon’s bitmap.
138 IMPORT_C CFbsBitmap* IconBitmap() const;
141 * Gets a pointer to the title icon’s bitmap mask. Does not imply transfer
144 * @return Pointer to the title icon’s bitmap mask.
146 IMPORT_C CFbsBitmap* IconMask() const;
148 public: // other functions
151 * Gets the value of the extra left margin for the title text which will
152 * take into account the width of the title icon.
154 * @return Value of extra left margin.
156 TInt ExtraLeftMargin() const;
159 * Adjusts the value of the title text baseline offset @c aBaseLine to take
160 * into account any size of the title icon.
162 * @param[in,out] aBaseLine Gets result of baseline.
163 * @param[in,out] aTitleHeight Gets result of height.
165 void CalculateBaseLine(TInt& aBaseLine, TInt& aTitleHeight);
169 /** The title’s position on the menu bar. */
172 /** The title’s width. */
175 /** The menu bar title text. */
178 /** Flags used internally by the menu bar title. */
186 * Menu bars are constructed from @c MENU_BAR resources and issue application
187 * commands which should be handled by overriding @c
188 * CEikAppUi::HandleCommandL().
190 class CEikMenuBar : public CEikBorderedControl,
191 public MEikCommandObserver,
192 public MAknIntermediateState
198 * Declares an object type for a class, in order to allow the object
199 * provider mechanism to locate and provide objects from the class.
201 DECLARE_TYPE_ID(0x101F4106)
203 /** Specifies the menu item within the menu pane. */
206 /** Index of a title in the menu bar. */
209 /** Index of an item in a menu pane. */
220 SCursor iMenuCursorPos;
225 * Options menu launched from the Options softkey.
226 * This is the default value.
231 * Context sensitive menu that is launched from selection key
232 * when the application supports it.
237 * Edit menu containing editing specific items.
242 * Options menu launched from the Options softkey. Task swapper item
245 EMenuOptionsNoTaskSwapper = 3
248 friend class CEikMenuPaneTitle;
252 enum {ENothingSelected=-1};
259 IMPORT_C ~CEikMenuBar();
262 * C++ default constructor.
264 IMPORT_C CEikMenuBar();
269 * From @c CCoeControl
271 * Handles key events offered to the menu by the control environment and
272 * provides an appropriate implementation of
273 * @c CCoeControl::OfferKeyEventL().
275 * @param aKeyEvent The key event.
276 * @param aType The type of key event: @c EEventKey, @c EEventKeyUp or @c
279 * @return Indicates whether or not the key event was used by this control.
281 IMPORT_C TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,
285 * From @c CCoeControl
287 * Handles pointer events. This function gets called whenever a pointer
288 * event occurs in the control, i.e. when the pointer is within the
289 * control's extent, or when the control has grabbed the pointer. The
290 * control should implement this function to handle pointer events.
292 * Note: events of type @c EButton1Down are processed before @c
293 * HandlePointerEventL() is called, in order to transfer keyboard focus to
294 * the control in which the @c EButton1Down event occurred.
296 * If overriding @c HandlePointerEventL(), the implementation must include
297 * a base call to @c CCoeControl's @c HandlePointerEventL().
299 * @param aPointerEvent The pointer event.
301 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
304 * From @c CCoeControl
310 IMPORT_C void Draw(const TRect& aRect) const;
317 IMPORT_C void* ExtensionInterface( TUid aInterface );
319 private: // from MCoeInputObserver
321 IMPORT_C TCoeInputCapabilities InputCapabilities() const;
326 * This class enables construction, and destruction of an array of
327 * information about menu bar titles.
329 class CTitleArray : public CArrayPtrFlat<CEikMenuBarTitle>
337 IMPORT_C ~CTitleArray();
340 * C++ default constructor.
342 IMPORT_C CTitleArray();
345 * Adds the menu bar title @c aMenuTitle to the end of the array owned
346 * by the menu bar and transfers ownership.
348 * @param aMenuTitle Append object to flat array.
350 IMPORT_C void AddTitleL(CEikMenuBarTitle* aMenuTitle);
353 * Deletes selected index into array.
355 * @param aResource Array index that will be delete.
357 void DeleteResource(TInt aResource);
360 public: // new functions
363 * Second phase constructor for a menu bar.
365 * @param aMenuObserver The menu's observer.
366 * @param aHotKeyResourceId The ID of the resource, of type HOTKEY from
367 * which the hotkey table is created. This is optional. By default
369 * @param aMenuTitleResourceId The ID of the resource, of type @c MENU_BAR
370 * from which the menu title array is created. This is optional. By
374 IMPORT_C void ConstructL(MEikMenuObserver* aMenuObserver,
375 TInt aHotKeyResourceId=0,
376 TInt aMenuTitleResourceId=0);
379 * Second phase constructor for a menu bar which builds the menu bar from
380 * the given resource file.
382 * @param aReader The resource reader.
384 IMPORT_C void ConstructFromResourceL(TResourceReader& aReader);
389 * @param aHotKeyResourceId Not used.
390 * @param aMenuTitleResourceId Not used.
391 * @param aDisplayNow Not used.
393 IMPORT_C void ChangeMenuBarL(TInt aHotKeyResourceId=0,
394 TInt aMenuTitleResourceId=0,
395 TInt aDisplayNow=ETrue);
400 * @param aHotKeyTable Not used.
403 IMPORT_C CEikHotKeyTable* SetHotKeyTable(CEikHotKeyTable* aHotKeyTable);
406 * Sets the menu’s resource ID.
408 * @param aMenuTitleResourceId The ID of the resource to use.
410 IMPORT_C void SetMenuTitleResourceId(TInt aMenuTitleResourceId);
415 * @param aMenuTitleResourceId
417 IMPORT_C void SetContextMenuTitleResourceId(TInt aMenuTitleResourceId);
422 * @param aTitleArray Not used.
424 IMPORT_C void SetMenuTitleArray(CTitleArray* aTitleArray);
429 * @param aOwnedExternally Not used.
431 IMPORT_C void SetTitleArrayOwnedExternally(TBool aOwnedExternally);
434 * Sets the cursor to the specifed menu pane and menu item.
436 * @param aCursor The menu pane and menu item to which the cursor is set.
437 * @return A @c SCursor structure holding the menu item within the menu
440 IMPORT_C SCursor SetMenuCursor(const SCursor& aCursor);
443 * Stops displaying the menu bar.
445 * This function causes the menu bar to disappear from the screen until it
446 * is invoked again by the user. In most circumstances this is done by the
447 * @c Uikon framework, so an application program will not normally need to
450 IMPORT_C void StopDisplayingMenuBar();
453 * Displays the menu bar.
455 * If the menu is not already displayed, this function displays the menu
456 * bar and allows the user to make a selection. In most circumstances this
457 * is done by the @c Uikon framework, so an application program will not
458 * normally need to use this function.
460 IMPORT_C void TryDisplayMenuBarL();
461 IMPORT_C void TryDisplayContextMenuBarL();
463 * If the menu is not already displayed, this function displays the menu
464 * bar without fep menu and allows the user to make a selection. In most
465 * circumstances this is done by the @c Uikon framework, so an application
466 * program will not normally need to use this function.
468 IMPORT_C void TryDisplayMenuBarWithoutFepMenusL();
473 * @param aNewSelectedTitle Not used
474 * @param aNewSelectedItem Not used.
476 IMPORT_C void MoveHighlightToL(TInt aNewSelectedTitle,
477 TInt aNewSelectedItem=0);
482 * @param aItem Not used.
484 IMPORT_C void DrawItem(TInt aItem) const;
487 * Gets a pointer to the menu’s hot key table.
489 CEikHotKeyTable* HotKeyTable() const { return(iHotKeyTable); }
492 * Gets the index of the menu pane selected by the cursor.
494 * @return The index of the selected menu pane.
496 IMPORT_C TInt SelectedTitle();
499 * Gets the index of the menu item selected by the cursor.
501 * @return The index of the selected menu item.
503 IMPORT_C TInt SelectedItem();
506 * Searches for the menu item that corresponds to the specified command.
508 * @param aCommandId The ID to search for.
509 * @param aPaneindex Menu pane index.
510 * @param aItemindex Menu item index.
512 IMPORT_C virtual void FindCommandIdInResourceL(TInt aCommandId,
517 * Gets a menu pane resource.
519 * @return The pointer to @c CEikMenuPane object containing a menu pane
522 IMPORT_C CEikMenuPane* MenuPane();
525 * If the menu bar is visible, removes the menu bar height from the top of
526 * @c aRect and returns the new rectangle in a new value of @c aRect.
528 * @param[in,out] aRect A rectangle that on return is reduced in height by
529 * the height of the menu bar.
531 IMPORT_C void ReduceRect(TRect& aRect) const;
534 * Gets array of information about the menu bar titles.
536 * @return Pointer to @c CTitleArray object containing array of information
537 * about menu bar titles.
539 IMPORT_C CTitleArray* TitleArray();
542 * Sets menu observer interface.
544 * @param aEditMenuObserver Menu observer interface.
546 IMPORT_C void SetEditMenuObserver(MEikMenuObserver* aEditMenuObserver);
549 * Sets the menu observer interface to @c NULL.
551 * @param aEditMenuObserver Menu observer interface that will be set to @c
554 IMPORT_C void RemoveEditMenuObserver(MEikMenuObserver* aEditMenuObserver);
557 * Allows the client to determine if the menubar instance is displayed.
559 * @return @c Etrue if displayed and @c EFalse if not.
561 IMPORT_C TBool IsDisplayed();
564 * Sets type of the menu. Menu can be for example Options menu launched from
565 * Options softkey or context sensitive menu launched from the selection key.
566 * By default the launched menu is options menu.
568 * @param aMenuType One of values of CEikMenuBar::TMenuType enumeration.
570 IMPORT_C void SetMenuType(TMenuType aMenuType);
573 * Gets type of the menu.
576 * @return the type defined in CEikMenuBar::TMenuType of menu.
578 IMPORT_C CEikMenuBar::TMenuType GetMenuType() const;
581 * Returns ETrue when item specific commands are enabled in menu
582 * bar (main pane collection has a highlight) and EFalse when they are
583 * disabled (main pane collection does not have a highlight).
586 * @return ETrue when item specific commands are enabled.
588 IMPORT_C TBool ItemSpecificCommandsEnabled() const;
591 * Sets item action menu instance to menu bar.
595 * @param aItemActionMenu Pointer to item action menu.
597 void SetItemActionMenu( CAknItemActionMenu* aItemActionMenu );
600 * Provides pointer to item action menu.
604 * @return Pointer to item action menu.
606 CAknItemActionMenu* ItemActionMenu() const;
609 * Populates item action menu.
613 * @param aItemActionMenu Reference to item action menu.
614 * @return Created menu pane. Ownership transfers to caller.
616 CEikMenuPane* PopulateItemActionMenuL( CAknItemActionMenu& aItemActionMenu );
618 private: // from MAknIntermediateState
622 public: // from CCoeControl
625 * From @c CCoeControl.
627 * Gets the list of logical colours used to draw the control.
629 * The list includes an explanation of how each colour is used. By default,
630 * this function has an empty implementation.
633 * @param aColorUseList The colour list.
635 IMPORT_C virtual void GetColorUseListL(
636 CArrayFix<TCoeColorUse>& aColorUseList) const;
639 * From @c CCoeControl.
641 * Handles a change to the control's resources.
643 * The types of resources handled are those which are shared across the
644 * environment, e.g. colours or fonts.
647 * @param aType A message UID value. The most common is @c
648 * KEikMessageColorSchemeChange which controls get when the colour
649 * scheme is changed. Other examples include: @c
650 * KEikMessageFadeAllWindows, @c KEikMessageUnfadeWindows, @c
651 * KEikMessageZoomChange, @c KEikMessageVirtualCursorStateChange, @c
652 * KEikMessageCapsLock, @c KEikMessagePrepareForSave.
654 IMPORT_C virtual void HandleResourceChange(TInt aType);
656 private: // from CCoeControl
657 IMPORT_C void Reserved_1();
658 IMPORT_C void Reserved_2();
659 // from MEikCommandObserver
660 void ProcessCommandL(TInt aCommandId);
661 private: // from MObjectProvider
662 TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
664 void StartDisplayingMenuBarL();
666 void SaveCurrentMenuPositionL();
667 void SetCursorPositionFromArray();
668 TBool MenuHasItems() const;
669 void SetMenuHasItems();
670 TBool MenuHasPane() const;
671 void SetMenuHasPane();
672 TBool TitleArrayOwnedExternally() const;
673 void ResetTitleArray();
674 void CreateTitleArrayL();
675 void SetMenuPaneFlag(TInt aFlag);
677 void AddMenuIfNotPresentL(TInt aResourceId);
678 void UpdateTitleTextBaseline();
680 enum TEikMenuFlags {ETitleArrayOwnedExternally=0x01,EMenuHasItems=0x02,EMenuHasPane=0x04,EBackgroundFaded=0x08, ESoundsInstalled=0x10};
681 CEikButtonGroupContainer* iMenuCba;
682 MEikMenuObserver* iMenuObserver;
683 MEikMenuObserver* iEditMenuObserver;
684 MEikMenuObserver* iActiveEditMenuObserver;
685 CEikMenuPane* iMenuPane;
686 CEikHotKeyTable* iHotKeyTable;
688 TInt iMenuTitleResourceId;
689 TInt iMenuPaneResourceId;
690 TInt iMenuHotKeyResourceId;
693 TInt iMenuTitleLeftSpace;
695 CTitleArray* iTitleArray;
696 CArrayFixFlat<SPosition>* iPastMenuPosArray;
697 TBool iPreventFepMenu;
698 friend class CEikMenuBarExtension;
699 CEikMenuBarExtension* iExt;
703 * This class is not intended to be used by application programmers.
705 class CEikMenuPaneTitle : public CEikBorderedControl
711 * Default C++ constructor
713 IMPORT_C CEikMenuPaneTitle(CEikMenuBar* aMenuBar);
716 * Second phase constructor for a menu bar. By default Symbian 2nd phase
717 * constructor is private.
719 IMPORT_C void ConstructL();
724 * @param aSelectedTitle Not used.
726 IMPORT_C void SetSelectedTitle(TInt aSelectedTitle);
731 * @param aRect Not used.
733 IMPORT_C void Draw(const TRect& aRect) const;
736 * Gets the menu pane title’s margins.
738 * @return The menu pane title’s margins.
740 IMPORT_C TMargins Margins() const;
745 IMPORT_C void Close();
752 * @param aPointerEvent Not used.
754 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
757 * From @c CCoeControl.
759 * Gets the list of logical colours used to draw the control.
761 * The list includes an explanation of how each colour is used. By default,
762 * this function has an empty implementation.
766 * @param aColorUseList The colour list.
768 IMPORT_C virtual void GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList) const; // not available before Release 005u
773 * @param aType Not used.
775 IMPORT_C virtual void HandleResourceChange(TInt aType); // not available before Release 005u
781 IMPORT_C void* ExtensionInterface( TUid aInterface );
783 CEikMenuBar* const iMenuBar;