1999-10-25 11:51:37 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/menuitem.h
|
|
|
|
// Purpose: wxMenuItem class
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 25.10.99
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1999-10-25 11:51:37 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-09-18 17:33:46 -04:00
|
|
|
#ifndef _WX_MENUITEM_H_BASE_
|
|
|
|
#define _WX_MENUITEM_H_BASE_
|
|
|
|
|
2005-03-16 11:18:31 -05:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#if wxUSE_MENUS
|
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "wx/object.h" // base class
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// forward declarations
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxMenuItem;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxMenu;
|
1999-10-25 11:51:37 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMenuItem is an item in the menu which may be either a normal item, a sub
|
|
|
|
// menu or a separator
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxMenuItemBase : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// creation
|
|
|
|
static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL,
|
2003-03-20 21:58:55 -05:00
|
|
|
int itemid = wxID_SEPARATOR,
|
1999-10-25 11:51:37 -04:00
|
|
|
const wxString& text = wxEmptyString,
|
|
|
|
const wxString& help = wxEmptyString,
|
2002-03-22 14:18:51 -05:00
|
|
|
wxItemKind kind = wxITEM_NORMAL,
|
1999-10-25 11:51:37 -04:00
|
|
|
wxMenu *subMenu = (wxMenu *)NULL);
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// destruction: wxMenuItem will delete its submenu
|
|
|
|
virtual ~wxMenuItemBase();
|
|
|
|
|
1999-10-26 15:07:04 -04:00
|
|
|
// the menu we're in
|
|
|
|
wxMenu *GetMenu() const { return m_parentMenu; }
|
2003-06-10 19:48:46 -04:00
|
|
|
void SetMenu(wxMenu* menu) { m_parentMenu = menu; }
|
1999-10-26 15:07:04 -04:00
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
// get/set id
|
2003-03-20 21:58:55 -05:00
|
|
|
void SetId(int itemid) { m_id = itemid; }
|
1999-10-25 11:51:37 -04:00
|
|
|
int GetId() const { return m_id; }
|
|
|
|
bool IsSeparator() const { return m_id == wxID_SEPARATOR; }
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// the item's text (or name)
|
|
|
|
//
|
2007-08-11 13:54:59 -04:00
|
|
|
// NB: the item's label includes the accelerators and mnemonics info (if
|
1999-11-01 20:25:43 -05:00
|
|
|
// any), i.e. it may contain '&' or '_' or "\t..." and thus is
|
2007-08-11 13:54:59 -04:00
|
|
|
// different from the item's text which only contains the text shown
|
|
|
|
// in the menu. This used to be called SetText.
|
|
|
|
virtual void SetItemLabel(const wxString& str);
|
1999-10-25 11:51:37 -04:00
|
|
|
|
2007-08-11 13:54:59 -04:00
|
|
|
// return the item label including any mnemonics and accelerators.
|
|
|
|
// This used to be called GetText.
|
|
|
|
virtual wxString GetItemLabel() const { return m_text; }
|
|
|
|
|
|
|
|
// return just the text of the item label, without any mnemonics
|
|
|
|
// This used to be called GetLabel.
|
|
|
|
virtual wxString GetItemLabelText() const { return GetLabelText(m_text); }
|
|
|
|
|
|
|
|
// return just the text part of the given label (implemented in platform-specific code)
|
|
|
|
// This used to be called GetLabelFromText.
|
|
|
|
static wxString GetLabelText(const wxString& label);
|
2000-01-11 08:58:41 -05:00
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
// what kind of menu item we are
|
2002-03-18 14:41:35 -05:00
|
|
|
wxItemKind GetKind() const { return m_kind; }
|
2004-04-22 18:02:02 -04:00
|
|
|
void SetKind(wxItemKind kind) { m_kind = kind; }
|
2002-03-18 14:41:35 -05:00
|
|
|
|
2002-04-12 09:15:44 -04:00
|
|
|
virtual void SetCheckable(bool checkable) { m_kind = checkable ? wxITEM_CHECK : wxITEM_NORMAL; }
|
2002-03-20 21:35:08 -05:00
|
|
|
bool IsCheckable() const
|
2002-03-22 14:18:51 -05:00
|
|
|
{ return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; }
|
1999-10-25 11:51:37 -04:00
|
|
|
|
|
|
|
bool IsSubMenu() const { return m_subMenu != NULL; }
|
|
|
|
void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
|
|
|
|
wxMenu *GetSubMenu() const { return m_subMenu; }
|
|
|
|
|
|
|
|
// state
|
2004-09-17 18:23:59 -04:00
|
|
|
virtual void Enable(bool enable = true) { m_isEnabled = enable; }
|
1999-10-25 11:51:37 -04:00
|
|
|
virtual bool IsEnabled() const { return m_isEnabled; }
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2004-09-17 18:23:59 -04:00
|
|
|
virtual void Check(bool check = true) { m_isChecked = check; }
|
1999-10-25 11:51:37 -04:00
|
|
|
virtual bool IsChecked() const { return m_isChecked; }
|
1999-11-01 20:25:43 -05:00
|
|
|
void Toggle() { Check(!m_isChecked); }
|
1999-10-25 11:51:37 -04:00
|
|
|
|
|
|
|
// help string (displayed in the status bar by default)
|
2006-09-05 17:00:55 -04:00
|
|
|
void SetHelp(const wxString& str);
|
1999-10-25 11:51:37 -04:00
|
|
|
const wxString& GetHelp() const { return m_help; }
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
#if wxUSE_ACCEL
|
2001-06-26 16:59:19 -04:00
|
|
|
// extract the accelerator from the given menu string, return NULL if none
|
|
|
|
// found
|
|
|
|
static wxAcceleratorEntry *GetAccelFromString(const wxString& label);
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// get our accelerator or NULL (caller must delete the pointer)
|
2001-06-26 16:59:19 -04:00
|
|
|
virtual wxAcceleratorEntry *GetAccel() const;
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
// set the accel for this item - this may also be done indirectly with
|
|
|
|
// SetText()
|
|
|
|
virtual void SetAccel(wxAcceleratorEntry *accel);
|
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
2007-04-10 20:23:19 -04:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
1999-10-25 11:51:37 -04:00
|
|
|
// compatibility only, use new functions in the new code
|
2007-04-10 20:23:19 -04:00
|
|
|
wxDEPRECATED( void SetName(const wxString& str) );
|
2007-08-11 13:54:59 -04:00
|
|
|
wxDEPRECATED( wxString GetName() const );
|
|
|
|
|
|
|
|
// Now use GetItemLabelText
|
|
|
|
wxDEPRECATED( wxString GetLabel() const ) ;
|
|
|
|
|
|
|
|
// Now use GetItemLabel
|
|
|
|
wxDEPRECATED( const wxString& GetText() const );
|
|
|
|
|
|
|
|
// Now use GetLabelText to strip the accelerators
|
|
|
|
wxDEPRECATED( static wxString GetLabelFromText(const wxString& text) );
|
|
|
|
|
|
|
|
// Now use SetItemLabel
|
|
|
|
wxDEPRECATED( virtual void SetText(const wxString& str) );
|
2007-04-10 20:23:19 -04:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
1999-10-25 11:51:37 -04:00
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
static wxMenuItem *New(wxMenu *parentMenu,
|
2003-03-20 21:58:55 -05:00
|
|
|
int itemid,
|
2002-03-18 14:41:35 -05:00
|
|
|
const wxString& text,
|
|
|
|
const wxString& help,
|
|
|
|
bool isCheckable,
|
|
|
|
wxMenu *subMenu = (wxMenu *)NULL)
|
|
|
|
{
|
2003-03-20 21:58:55 -05:00
|
|
|
return New(parentMenu, itemid, text, help,
|
2002-03-22 14:18:51 -05:00
|
|
|
isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu);
|
2002-03-18 14:41:35 -05:00
|
|
|
}
|
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
protected:
|
2004-09-17 18:23:59 -04:00
|
|
|
int m_id; // numeric id of the item >= 0 or wxID_ANY or wxID_SEPARATOR
|
1999-10-25 11:51:37 -04:00
|
|
|
wxMenu *m_parentMenu, // the menu we belong to
|
|
|
|
*m_subMenu; // our sub menu or NULL
|
|
|
|
wxString m_text, // label of the item
|
|
|
|
m_help; // the help string for the item
|
2005-05-31 05:20:43 -04:00
|
|
|
wxItemKind m_kind; // separator/normal/check/radio item?
|
1999-10-25 11:51:37 -04:00
|
|
|
bool m_isChecked; // is checked?
|
|
|
|
bool m_isEnabled; // is enabled?
|
1999-11-24 10:11:29 -05:00
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
// this ctor is for the derived classes only, we're never created directly
|
|
|
|
wxMenuItemBase(wxMenu *parentMenu = (wxMenu *)NULL,
|
2003-03-20 21:58:55 -05:00
|
|
|
int itemid = wxID_SEPARATOR,
|
2002-03-18 14:41:35 -05:00
|
|
|
const wxString& text = wxEmptyString,
|
|
|
|
const wxString& help = wxEmptyString,
|
2002-03-22 14:18:51 -05:00
|
|
|
wxItemKind kind = wxITEM_NORMAL,
|
2002-03-18 14:41:35 -05:00
|
|
|
wxMenu *subMenu = (wxMenu *)NULL);
|
2000-01-20 17:34:48 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
// and, if we have one ctor, compiler won't generate a default copy one, so
|
|
|
|
// declare them ourselves - but don't implement as they shouldn't be used
|
|
|
|
wxMenuItemBase(const wxMenuItemBase& item);
|
|
|
|
wxMenuItemBase& operator=(const wxMenuItemBase& item);
|
1999-10-25 11:51:37 -04:00
|
|
|
};
|
|
|
|
|
2007-04-10 20:23:19 -04:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
2007-04-11 07:53:40 -04:00
|
|
|
inline void wxMenuItemBase::SetName(const wxString &str)
|
2007-08-11 13:54:59 -04:00
|
|
|
{ SetItemLabel(str); }
|
|
|
|
inline wxString wxMenuItemBase::GetName() const
|
|
|
|
{ return GetItemLabel(); }
|
|
|
|
inline wxString wxMenuItemBase::GetLabel() const
|
2007-08-11 14:02:36 -04:00
|
|
|
{ return GetLabelText(m_text); }
|
2007-08-11 13:54:59 -04:00
|
|
|
inline const wxString& wxMenuItemBase::GetText() const { return m_text; }
|
|
|
|
inline void wxMenuItemBase::SetText(const wxString& text) { SetItemLabel(text); }
|
2007-04-10 20:23:19 -04:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// include the real class declaration
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef wxUSE_BASE_CLASSES_ONLY
|
|
|
|
#define wxMenuItem wxMenuItemBase
|
|
|
|
#else // !wxUSE_BASE_CLASSES_ONLY
|
2001-06-26 16:59:19 -04:00
|
|
|
#if defined(__WXUNIVERSAL__)
|
|
|
|
#include "wx/univ/menuitem.h"
|
2004-12-20 07:44:22 -05:00
|
|
|
#elif defined(__WXPALMOS__)
|
2004-10-19 09:40:30 -04:00
|
|
|
#include "wx/palmos/menuitem.h"
|
2001-06-26 16:59:19 -04:00
|
|
|
#elif defined(__WXMSW__)
|
1999-10-25 11:51:37 -04:00
|
|
|
#include "wx/msw/menuitem.h"
|
1998-09-18 17:33:46 -04:00
|
|
|
#elif defined(__WXMOTIF__)
|
1999-10-25 11:51:37 -04:00
|
|
|
#include "wx/motif/menuitem.h"
|
2006-01-22 22:27:34 -05:00
|
|
|
#elif defined(__WXGTK20__)
|
1999-10-25 11:51:37 -04:00
|
|
|
#include "wx/gtk/menuitem.h"
|
2006-01-22 22:27:34 -05:00
|
|
|
#elif defined(__WXGTK__)
|
|
|
|
#include "wx/gtk1/menuitem.h"
|
1998-09-18 17:33:46 -04:00
|
|
|
#elif defined(__WXMAC__)
|
1999-10-25 11:51:37 -04:00
|
|
|
#include "wx/mac/menuitem.h"
|
2003-03-22 01:18:36 -05:00
|
|
|
#elif defined(__WXCOCOA__)
|
|
|
|
#include "wx/cocoa/menuitem.h"
|
1999-07-27 23:38:12 -04:00
|
|
|
#elif defined(__WXPM__)
|
1999-10-25 11:51:37 -04:00
|
|
|
#include "wx/os2/menuitem.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
1999-10-25 11:51:37 -04:00
|
|
|
#endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#endif // wxUSE_MENUS
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
1998-09-18 17:33:46 -04:00
|
|
|
// _WX_MENUITEM_H_BASE_
|