// Name: menu.h
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
-// Licence: wxWindows licence
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling, Julian Smart
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/object.h"
#include "wx/list.h"
#include "wx/window.h"
+#include "wx/menuitem.h"
//-----------------------------------------------------------------------------
// classes
class wxMenuItem;
class wxMenu;
+//-----------------------------------------------------------------------------
+// const
+//-----------------------------------------------------------------------------
+
+#define ID_SEPARATOR (-1)
+
//-----------------------------------------------------------------------------
// wxMenuBar
//-----------------------------------------------------------------------------
-class wxMenuBar: public wxWindow
+class wxMenuBar : public wxWindow
{
- DECLARE_DYNAMIC_CLASS(wxMenuBar)
+ DECLARE_DYNAMIC_CLASS(wxMenuBar)
- public:
+public:
+ // ctors
+ wxMenuBar();
+ wxMenuBar(long style);
+ wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
+ ~wxMenuBar();
- wxMenuBar(void);
+ // menubar construction
void Append( wxMenu *menu, const wxString &title );
- int FindMenuItem( const wxString &menuString, const wxString &itemString ) const;
+
+ // item search
+ // by menu and item names, returns wxNOT_FOUND if not found
+ virtual int FindMenuItem(const wxString& menuString,
+ const wxString& itemString) const;
+ // returns NULL if not found
+ wxMenuItem* FindItem( int id ) const;
+ // returns NULL if not found, fills menuForItem if !NULL
+ wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const;
+
+ // state control
+ void Check( int id, bool check );
+ bool IsChecked( int id ) const;
+ void Enable( int id, bool enable );
+ bool IsEnabled( int id ) const;
+
+ void SetLabel( int id, const wxString &label );
+ wxString GetLabel( int id ) const;
+ wxString GetLabel() const { return wxWindow::GetLabel(); }
+
+ void EnableTop( int pos, bool flag );
+ void SetLabelTop( int pos, const wxString& label );
+ wxString GetLabelTop( int pos ) const;
+
+ virtual void SetHelpString( int id, const wxString& helpString );
+ virtual wxString GetHelpString( int id ) const;
+
+ int GetMenuCount() const { return m_menus.Number(); }
+ wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
+
+#ifdef WXWIN_COMPATIBILITY
+ // compatibility: these functions are deprecated
+ bool Enabled(int id) const { return IsEnabled(id); }
+ bool Checked(int id) const { return IsChecked(id); }
+
+ wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); }
+#endif // WXWIN_COMPATIBILITY
+
+ // implementation only
+ wxList& GetMenus() { return m_menus; }
- wxList m_menus;
- GtkWidget *m_menubar;
+ void SetInvokingWindow( wxWindow *win );
+ void UnsetInvokingWindow( wxWindow *win );
+
+ GtkAccelGroup *m_accel;
+ GtkItemFactory *m_factory;
+ wxList m_menus;
+ GtkWidget *m_menubar;
};
//-----------------------------------------------------------------------------
// wxMenu
//-----------------------------------------------------------------------------
-class wxMenuItem: public wxObject
-{
- DECLARE_DYNAMIC_CLASS(wxMenuItem)
-
- public:
-
- wxMenuItem(void);
-
- int m_id;
- wxString m_text;
- bool m_isCheckMenu;
- bool m_checked;
- bool m_isSubMenu;
- bool m_isEnabled;
- wxMenu *m_subMenu;
- wxString m_helpStr;
-
- GtkWidget *m_menuItem; // GtkMenuItem
-
-};
-
-class wxMenu: public wxEvtHandler
+class wxMenu : public wxEvtHandler
{
- DECLARE_DYNAMIC_CLASS(wxMenu)
-
- public:
-
- wxMenu( const wxString &title = "" );
- void AppendSeparator(void);
- void Append( int id, const wxString &item,
- const wxString &helpStr = "", bool checkable = FALSE );
- void Append( int id, const wxString &item,
- wxMenu *subMenu, const wxString &helpStr = "" );
+ DECLARE_DYNAMIC_CLASS(wxMenu)
+
+public:
+ wxMenu( const wxString& title = wxEmptyString,
+ const wxFunction func = (wxFunction) NULL );
+ ~wxMenu();
+
+ // operations
+ // title
+ void SetTitle(const wxString& label);
+ const wxString GetTitle() const;
+ // menu creation
+ void AppendSeparator();
+ void Append(int id, const wxString &item,
+ const wxString &helpStr = "", bool checkable = FALSE);
+ void Append(int id, const wxString &item,
+ wxMenu *subMenu, const wxString &helpStr = "" );
+ void Append(wxMenuItem *pItem);
+ void Break() { }
+
+ // find item by name/id
int FindItem( const wxString itemString ) const;
- void Break(void) {};
+ wxMenuItem *FindItem( int id ) const;
+
+ // get/set item's state
void Enable( int id, bool enable );
- bool Enabled( int id ) const;
+ bool IsEnabled( int id ) const;
+ void Check( int id, bool check );
+ bool IsChecked( int id ) const;
+
void SetLabel( int id, const wxString &label );
+ wxString GetLabel( int id ) const;
+
+ // helpstring
+ virtual void SetHelpString(int id, const wxString& helpString);
+ virtual wxString GetHelpString(int id) const ;
+
+ // accessors
+ wxList& GetItems() { return m_items; }
- public:
-
+ void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
+ wxEvtHandler *GetEventHandler() { return m_eventHandler; }
+
+ void SetClientData( void* clientData ) { m_clientData = clientData; }
+ void* GetClientData() const { return m_clientData; }
+
+ // Updates the UI for a menu and all submenus recursively.
+ // source is the object that has the update event handlers
+ // defined for it. If NULL, the menu or associated window
+ // will be used.
+ void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
+
+ wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
+
+#ifdef WXWIN_COMPATIBILITY
+ wxFunction GetCallback() const { return m_callback; }
+ void Callback(const wxFunction func) { m_callback = func; }
+
+ // compatibility: these functions are deprecated
+ bool Enabled(int id) const { return IsEnabled(id); }
+ bool Checked(int id) const { return IsChecked(id); }
+#endif // WXWIN_COMPATIBILITY
+
+ // implementation
int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
void SetInvokingWindow( wxWindow *win );
- wxWindow *GetInvokingWindow(void);
-
- wxString m_title;
- wxList m_items;
- wxWindow *m_invokingWindow;
-
- GtkWidget *m_menu; // GtkMenu
-
+ wxWindow *GetInvokingWindow();
+
+ // implementation GTK only
+ GtkWidget *m_menu; // GtkMenu
+ GtkWidget *m_owner;
+ GtkAccelGroup *m_accel;
+ GtkItemFactory *m_factory;
+
+private:
+
+ wxString m_title;
+ wxList m_items;
+ wxWindow *m_invokingWindow;
+ wxFunction m_callback;
+ wxEvtHandler *m_eventHandler;
+ void *m_clientData;
};
#endif // __GTKMENUH__