1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: menu.h
|
|
|
|
// Purpose:
|
|
|
|
// Author: Robert Roebling
|
1998-10-29 18:03:18 +00:00
|
|
|
// Id: $Id$
|
|
|
|
// Copyright: (c) 1998 Robert Roebling, Julian Smart
|
1998-07-23 16:07:05 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __GTKMENUH__
|
|
|
|
#define __GTKMENUH__
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
#include "wx/object.h"
|
|
|
|
#include "wx/list.h"
|
|
|
|
#include "wx/window.h"
|
1998-11-03 11:19:58 +00:00
|
|
|
#include "wx/menuitem.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// classes
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxMenuBar;
|
|
|
|
class wxMenuItem;
|
|
|
|
class wxMenu;
|
|
|
|
|
1998-07-20 18:05:48 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// const
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define ID_SEPARATOR (-1)
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxMenuBar
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1999-03-24 19:05:19 +00:00
|
|
|
class wxMenuBar : public wxWindow
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-03-24 19:05:19 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxMenuBar)
|
1998-07-23 16:07:05 +00:00
|
|
|
|
|
|
|
public:
|
1999-03-24 19:05:19 +00:00
|
|
|
// ctors
|
|
|
|
wxMenuBar();
|
|
|
|
wxMenuBar(long style);
|
|
|
|
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
|
1999-04-25 15:10:52 +00:00
|
|
|
~wxMenuBar();
|
1999-03-24 19:05:19 +00:00
|
|
|
|
|
|
|
// menubar construction
|
|
|
|
void Append( wxMenu *menu, const wxString &title );
|
|
|
|
|
|
|
|
// 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 );
|
1999-05-12 20:26:54 +00:00
|
|
|
wxString GetLabel( int id ) const;
|
|
|
|
wxString GetLabel() const { return wxWindow::GetLabel(); }
|
1999-03-24 19:05:19 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
1999-04-25 15:10:52 +00:00
|
|
|
// implementation only
|
1999-03-24 19:05:19 +00:00
|
|
|
wxList& GetMenus() { return m_menus; }
|
1999-07-19 22:17:40 +00:00
|
|
|
|
1999-06-06 16:07:39 +00:00
|
|
|
void SetInvokingWindow( wxWindow *win );
|
|
|
|
void UnsetInvokingWindow( wxWindow *win );
|
1999-03-24 19:05:19 +00:00
|
|
|
|
1999-04-25 15:10:52 +00:00
|
|
|
GtkAccelGroup *m_accel;
|
|
|
|
GtkItemFactory *m_factory;
|
|
|
|
wxList m_menus;
|
|
|
|
GtkWidget *m_menubar;
|
1999-06-17 14:08:00 +00:00
|
|
|
long m_style;
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxMenu
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1999-03-24 19:05:19 +00:00
|
|
|
class wxMenu : public wxEvtHandler
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-03-24 19:05:19 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxMenu)
|
1998-07-23 16:07:05 +00:00
|
|
|
|
|
|
|
public:
|
1999-07-19 22:17:40 +00:00
|
|
|
#ifdef WXWIN_COMPATIBILITY
|
|
|
|
wxMenu( const wxString& title, const wxFunction func)
|
|
|
|
{
|
|
|
|
Init(title, 0, func);
|
|
|
|
}
|
|
|
|
#endif
|
1999-07-22 15:05:52 +00:00
|
|
|
wxMenu( long style )
|
|
|
|
{
|
|
|
|
Init( wxEmptyString, style );
|
|
|
|
}
|
1999-07-19 22:17:40 +00:00
|
|
|
wxMenu( const wxString& title = wxEmptyString, long style = 0 )
|
|
|
|
{
|
1999-07-19 22:54:55 +00:00
|
|
|
Init(title, style);
|
1999-07-19 22:17:40 +00:00
|
|
|
}
|
|
|
|
|
1999-04-09 18:01:17 +00:00
|
|
|
~wxMenu();
|
1999-03-24 19:05:19 +00:00
|
|
|
|
|
|
|
// 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() { }
|
1998-07-23 16:07:05 +00:00
|
|
|
|
|
|
|
// find item by name/id
|
1999-03-24 19:05:19 +00:00
|
|
|
int FindItem( const wxString itemString ) const;
|
|
|
|
wxMenuItem *FindItem( int id ) const;
|
1998-07-23 16:07:05 +00:00
|
|
|
|
|
|
|
// get/set item's state
|
1999-03-24 19:05:19 +00:00
|
|
|
void Enable( int id, bool enable );
|
|
|
|
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; }
|
|
|
|
|
|
|
|
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); }
|
1999-07-19 22:17:40 +00:00
|
|
|
|
|
|
|
wxFunction m_callback;
|
1999-03-24 19:05:19 +00:00
|
|
|
#endif // WXWIN_COMPATIBILITY
|
|
|
|
|
|
|
|
// implementation
|
|
|
|
int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
|
|
|
|
void SetInvokingWindow( wxWindow *win );
|
|
|
|
wxWindow *GetInvokingWindow();
|
|
|
|
|
1999-04-25 15:10:52 +00:00
|
|
|
// implementation GTK only
|
1999-04-09 18:01:17 +00:00
|
|
|
GtkWidget *m_menu; // GtkMenu
|
|
|
|
GtkWidget *m_owner;
|
|
|
|
GtkAccelGroup *m_accel;
|
|
|
|
GtkItemFactory *m_factory;
|
1999-03-24 19:05:19 +00:00
|
|
|
|
1999-06-17 14:08:00 +00:00
|
|
|
// used by wxMenuBar
|
1999-07-19 22:17:40 +00:00
|
|
|
long GetStyle(void) const { return m_style; }
|
|
|
|
|
|
|
|
private:
|
1999-06-17 14:08:00 +00:00
|
|
|
// common code for both constructors:
|
|
|
|
void Init( const wxString& title,
|
1999-07-19 22:17:40 +00:00
|
|
|
long style
|
|
|
|
#ifdef WXWIN_COMPATIBILITY
|
1999-07-19 22:54:55 +00:00
|
|
|
, const wxFunction func = (wxFunction) NULL
|
1999-07-19 22:17:40 +00:00
|
|
|
#endif
|
|
|
|
);
|
1999-04-25 15:10:52 +00:00
|
|
|
|
1999-03-24 19:05:19 +00:00
|
|
|
wxString m_title;
|
|
|
|
wxList m_items;
|
|
|
|
wxWindow *m_invokingWindow;
|
|
|
|
wxEvtHandler *m_eventHandler;
|
|
|
|
void *m_clientData;
|
1999-06-17 14:08:00 +00:00
|
|
|
long m_style;
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __GTKMENUH__
|