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