// EIKMENUB.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#if !defined(__EIKMENUB_H__)
#define __EIKMENUB_H__

#if !defined(__EIKDEF_H__)
#include <eikdef.h>
#endif

#if !defined(__EIKBCTRL_H__)
#include <eikbctrl.h>
#endif

#if !defined(__EIKMENUP_H__)
#include <eikmenup.h>
#endif

class CEikHotKeyTable;

class CEikMenuBar : public CEikBorderedControl
	{
public:
	struct SCursor
		{
		TInt iMenuPaneIndex;
		TInt iMenuItemIndex;
		};
	struct SPosition
		{
		TInt iMenuId;
		SCursor iMenuCursorPos;
		};
	friend class CEikMenuPaneTitle;
private:
	enum {ENothingSelected=-1};
public:
	IMPORT_C ~CEikMenuBar();
	IMPORT_C CEikMenuBar();
private: // framework
	IMPORT_C TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
	IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
	IMPORT_C void Draw(const TRect& aRect) const;
public:
	class TTitle
		{
	public:
		struct SData
			{
			enum { ENominalTextLength=40 };
			TInt iMenuPaneResourceId;
			TBuf<ENominalTextLength> iText; // less than this actually stored
			};
	public:
		//void CheckForMnemonic();
	public:
		TInt iPos;
		TInt iWidth;
		//TInt iMnemonicCode;
		//TInt iMnemonicOffset;
		SData iData;
		};
	class CTitleArray : public CArrayVarFlat<TTitle>
		{
	public:
		IMPORT_C ~CTitleArray();
		IMPORT_C CTitleArray();
		IMPORT_C void AddTitleL(TTitle& aMenuTitle);
		};
public: // new functions
	IMPORT_C void ConstructL(MEikMenuObserver* aMenuObserver,TInt aHotKeyResourceId=0,TInt aMenuTitleResourceId=0);
	IMPORT_C void ConstructFromResourceL(TResourceReader& aReader);
	IMPORT_C void ChangeMenuBarL(TInt aHotKeyResourceId=0,TInt aMenuTitleResourceId=0,TInt aDisplayNow=ETrue);
	IMPORT_C CEikHotKeyTable* SetHotKeyTable(CEikHotKeyTable* aHotKeyTable);
	IMPORT_C void SetMenuTitleResourceId(TInt aMenuTitleResourceId);
	IMPORT_C void SetMenuTitleArray(CTitleArray* aTitleArray);
	IMPORT_C void SetTitleArrayOwnedExternally(TBool aOwnedExternally);
	IMPORT_C SCursor SetMenuCursor(const SCursor& aCursor);
	IMPORT_C void StopDisplayingMenuBar();
	IMPORT_C void TryDisplayMenuBarL();
	IMPORT_C void MoveHighlightToL(TInt aNewSelectedTitle,TInt aNewSelectedItem=0);
	IMPORT_C void DrawItem(TInt aItem) const;
	CEikHotKeyTable* HotKeyTable() const { return(iHotKeyTable); }
	IMPORT_C TInt SelectedTitle();
	IMPORT_C TInt SelectedItem();
	IMPORT_C virtual void FindCommandIdInResourceL(TInt aCommandId,TInt& aPaneindex,TInt& aItemindex);
	CEikMenuPane* MenuPane();
private: // from CCoeControl
	IMPORT_C void Reserved_1();
	IMPORT_C void Reserved_2();
private:
	void DisplayL();
	void MoveHighlightToCurrentMenuPaneFirstItem();
	void StartDisplayingMenuBarL();
	void CalculateSizeAndPosition();
	void HideMenuPane();
	void HideMenuPaneTitle();
	TKeyResponse TryNavigateAlongMenuBarL(TInt aKeyCode);
	void SaveCurrentMenuPositionL();
	void SetCursorPositionFromArray();
	TBool MenuHasItems();
	void SetMenuHasItems();
	TBool MenuHasPane();
	void SetMenuHasPane();
	TBool TitleArrayOwnedExternally();
private:
	enum TEikMenuFlags {ETitleArrayOwnedExternally=0x01,EMenuHasItems=0x02,EMenuHasPane=0x04};
	CEikMenuPaneTitle* iMenuPaneTitle;
	MEikMenuObserver* iMenuObserver;
	CEikMenuPane* iMenuPane;
 	CEikHotKeyTable* iHotKeyTable;
	SCursor iCursor;
	TInt iMenuTitleResourceId;
	TInt iMenuHotKeyResourceId;
	TInt iSelectedTitle;
	TInt iBaseLine;
	TInt iMenuTitleLeftSpace;
	TInt iMenuFlags;
	CTitleArray* iTitleArray;
	CArrayFixFlat<SPosition>* iPastMenuPosArray;
	};

class CEikMenuPaneTitle : public CEikBorderedControl
	{
public:
	IMPORT_C CEikMenuPaneTitle(CEikMenuBar* aMenuBar);
	IMPORT_C void ConstructL();
	IMPORT_C void SetSelectedTitle(TInt aSelectedTitle);
	IMPORT_C void Draw(const TRect& aRect) const;
    IMPORT_C TMargins Margins() const;
	IMPORT_C void Close();
public:// framework
	IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
private:
	CEikMenuBar* const iMenuBar;
	TInt iSelectedTitle;
	};
#endif
