1999-10-25 15:51:37 +00: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 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1999-10-25 15:51:37 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-09-18 21:33:46 +00:00
|
|
|
#ifndef _WX_MENUITEM_H_BASE_
|
|
|
|
#define _WX_MENUITEM_H_BASE_
|
|
|
|
|
2005-03-16 16:18:31 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#if wxUSE_MENUS
|
|
|
|
|
1999-10-25 15:51:37 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "wx/object.h" // base class
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// forward declarations
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxMenuItem;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxMenu;
|
1999-10-25 15:51:37 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMenuItem is an item in the menu which may be either a normal item, a sub
|
|
|
|
// menu or a separator
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxMenuItemBase : public wxObject
|
1999-10-25 15:51:37 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// creation
|
2009-01-19 13:55:27 +00:00
|
|
|
static wxMenuItem *New(wxMenu *parentMenu = NULL,
|
2003-03-21 02:58:55 +00:00
|
|
|
int itemid = wxID_SEPARATOR,
|
1999-10-25 15:51:37 +00:00
|
|
|
const wxString& text = wxEmptyString,
|
|
|
|
const wxString& help = wxEmptyString,
|
2002-03-22 19:18:51 +00:00
|
|
|
wxItemKind kind = wxITEM_NORMAL,
|
2009-01-19 13:55:27 +00:00
|
|
|
wxMenu *subMenu = NULL);
|
1999-10-25 15:51:37 +00:00
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
// destruction: wxMenuItem will delete its submenu
|
|
|
|
virtual ~wxMenuItemBase();
|
|
|
|
|
1999-10-26 19:07:04 +00:00
|
|
|
// the menu we're in
|
|
|
|
wxMenu *GetMenu() const { return m_parentMenu; }
|
2003-06-10 23:48:46 +00:00
|
|
|
void SetMenu(wxMenu* menu) { m_parentMenu = menu; }
|
1999-10-26 19:07:04 +00:00
|
|
|
|
1999-10-25 15:51:37 +00:00
|
|
|
// get/set id
|
2003-03-21 02:58:55 +00:00
|
|
|
void SetId(int itemid) { m_id = itemid; }
|
1999-10-25 15:51:37 +00:00
|
|
|
int GetId() const { return m_id; }
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
// the item's text (or name)
|
|
|
|
//
|
2007-08-11 17:54:59 +00:00
|
|
|
// NB: the item's label includes the accelerators and mnemonics info (if
|
1999-11-02 01:25:43 +00:00
|
|
|
// any), i.e. it may contain '&' or '_' or "\t..." and thus is
|
2007-08-11 17:54:59 +00: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 15:51:37 +00:00
|
|
|
|
2007-08-11 17:54:59 +00: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 13:58:41 +00:00
|
|
|
|
1999-10-25 15:51:37 +00:00
|
|
|
// what kind of menu item we are
|
2002-03-18 19:41:35 +00:00
|
|
|
wxItemKind GetKind() const { return m_kind; }
|
2004-04-22 22:02:02 +00:00
|
|
|
void SetKind(wxItemKind kind) { m_kind = kind; }
|
2008-04-06 15:55:42 +00:00
|
|
|
bool IsSeparator() const { return m_kind == wxITEM_SEPARATOR; }
|
2002-03-18 19:41:35 +00:00
|
|
|
|
2002-04-12 13:15:44 +00:00
|
|
|
virtual void SetCheckable(bool checkable) { m_kind = checkable ? wxITEM_CHECK : wxITEM_NORMAL; }
|
2002-03-21 02:35:08 +00:00
|
|
|
bool IsCheckable() const
|
2002-03-22 19:18:51 +00:00
|
|
|
{ return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; }
|
1999-10-25 15:51:37 +00: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 22:23:59 +00:00
|
|
|
virtual void Enable(bool enable = true) { m_isEnabled = enable; }
|
1999-10-25 15:51:37 +00:00
|
|
|
virtual bool IsEnabled() const { return m_isEnabled; }
|
1999-11-02 01:25:43 +00:00
|
|
|
|
2004-09-17 22:23:59 +00:00
|
|
|
virtual void Check(bool check = true) { m_isChecked = check; }
|
1999-10-25 15:51:37 +00:00
|
|
|
virtual bool IsChecked() const { return m_isChecked; }
|
1999-11-02 01:25:43 +00:00
|
|
|
void Toggle() { Check(!m_isChecked); }
|
1999-10-25 15:51:37 +00:00
|
|
|
|
|
|
|
// help string (displayed in the status bar by default)
|
2006-09-05 21:00:55 +00:00
|
|
|
void SetHelp(const wxString& str);
|
1999-10-25 15:51:37 +00:00
|
|
|
const wxString& GetHelp() const { return m_help; }
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
#if wxUSE_ACCEL
|
2001-06-26 20:59:19 +00:00
|
|
|
// extract the accelerator from the given menu string, return NULL if none
|
|
|
|
// found
|
|
|
|
static wxAcceleratorEntry *GetAccelFromString(const wxString& label);
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
// get our accelerator or NULL (caller must delete the pointer)
|
2001-06-26 20:59:19 +00:00
|
|
|
virtual wxAcceleratorEntry *GetAccel() const;
|
1999-11-02 01:25:43 +00: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-11 00:23:19 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
1999-10-25 15:51:37 +00:00
|
|
|
// compatibility only, use new functions in the new code
|
2007-04-11 00:23:19 +00:00
|
|
|
wxDEPRECATED( void SetName(const wxString& str) );
|
2007-08-11 17:54:59 +00: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
|
2011-02-19 12:32:59 +00:00
|
|
|
static wxDEPRECATED( wxString GetLabelFromText(const wxString& text) );
|
2007-08-11 17:54:59 +00:00
|
|
|
|
|
|
|
// Now use SetItemLabel
|
|
|
|
wxDEPRECATED( virtual void SetText(const wxString& str) );
|
2007-04-11 00:23:19 +00:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
1999-10-25 15:51:37 +00:00
|
|
|
|
2002-03-18 19:41:35 +00:00
|
|
|
static wxMenuItem *New(wxMenu *parentMenu,
|
2003-03-21 02:58:55 +00:00
|
|
|
int itemid,
|
2002-03-18 19:41:35 +00:00
|
|
|
const wxString& text,
|
|
|
|
const wxString& help,
|
|
|
|
bool isCheckable,
|
2009-01-19 13:55:27 +00:00
|
|
|
wxMenu *subMenu = NULL)
|
2002-03-18 19:41:35 +00:00
|
|
|
{
|
2003-03-21 02:58:55 +00:00
|
|
|
return New(parentMenu, itemid, text, help,
|
2002-03-22 19:18:51 +00:00
|
|
|
isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu);
|
2002-03-18 19:41:35 +00:00
|
|
|
}
|
|
|
|
|
1999-10-25 15:51:37 +00:00
|
|
|
protected:
|
2008-01-06 14:38:44 +00:00
|
|
|
wxWindowIDRef m_id; // numeric id of the item >= 0 or wxID_ANY or wxID_SEPARATOR
|
1999-10-25 15:51:37 +00: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 09:20:43 +00:00
|
|
|
wxItemKind m_kind; // separator/normal/check/radio item?
|
1999-10-25 15:51:37 +00:00
|
|
|
bool m_isChecked; // is checked?
|
|
|
|
bool m_isEnabled; // is enabled?
|
1999-11-24 15:11:29 +00:00
|
|
|
|
2002-03-18 19:41:35 +00:00
|
|
|
// this ctor is for the derived classes only, we're never created directly
|
2009-01-19 13:55:27 +00:00
|
|
|
wxMenuItemBase(wxMenu *parentMenu = NULL,
|
2003-03-21 02:58:55 +00:00
|
|
|
int itemid = wxID_SEPARATOR,
|
2002-03-18 19:41:35 +00:00
|
|
|
const wxString& text = wxEmptyString,
|
|
|
|
const wxString& help = wxEmptyString,
|
2002-03-22 19:18:51 +00:00
|
|
|
wxItemKind kind = wxITEM_NORMAL,
|
2009-01-19 13:55:27 +00:00
|
|
|
wxMenu *subMenu = NULL);
|
2000-01-20 22:34:48 +00: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 15:51:37 +00:00
|
|
|
};
|
|
|
|
|
2007-04-11 00:23:19 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
2007-04-11 11:53:40 +00:00
|
|
|
inline void wxMenuItemBase::SetName(const wxString &str)
|
2007-08-11 17:54:59 +00:00
|
|
|
{ SetItemLabel(str); }
|
|
|
|
inline wxString wxMenuItemBase::GetName() const
|
|
|
|
{ return GetItemLabel(); }
|
|
|
|
inline wxString wxMenuItemBase::GetLabel() const
|
2007-08-11 18:02:36 +00:00
|
|
|
{ return GetLabelText(m_text); }
|
2007-08-11 17:54:59 +00:00
|
|
|
inline const wxString& wxMenuItemBase::GetText() const { return m_text; }
|
|
|
|
inline void wxMenuItemBase::SetText(const wxString& text) { SetItemLabel(text); }
|
2007-04-11 00:23:19 +00:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
|
|
|
|
1999-10-25 15:51:37 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// include the real class declaration
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef wxUSE_BASE_CLASSES_ONLY
|
|
|
|
#define wxMenuItem wxMenuItemBase
|
|
|
|
#else // !wxUSE_BASE_CLASSES_ONLY
|
2001-06-26 20:59:19 +00:00
|
|
|
#if defined(__WXUNIVERSAL__)
|
|
|
|
#include "wx/univ/menuitem.h"
|
|
|
|
#elif defined(__WXMSW__)
|
1999-10-25 15:51:37 +00:00
|
|
|
#include "wx/msw/menuitem.h"
|
1998-09-18 21:33:46 +00:00
|
|
|
#elif defined(__WXMOTIF__)
|
1999-10-25 15:51:37 +00:00
|
|
|
#include "wx/motif/menuitem.h"
|
2006-01-23 03:27:34 +00:00
|
|
|
#elif defined(__WXGTK20__)
|
1999-10-25 15:51:37 +00:00
|
|
|
#include "wx/gtk/menuitem.h"
|
2006-01-23 03:27:34 +00:00
|
|
|
#elif defined(__WXGTK__)
|
|
|
|
#include "wx/gtk1/menuitem.h"
|
1998-09-18 21:33:46 +00:00
|
|
|
#elif defined(__WXMAC__)
|
2008-06-11 19:17:41 +00:00
|
|
|
#include "wx/osx/menuitem.h"
|
2003-03-22 06:18:36 +00:00
|
|
|
#elif defined(__WXCOCOA__)
|
|
|
|
#include "wx/cocoa/menuitem.h"
|
1999-07-28 03:38:12 +00:00
|
|
|
#elif defined(__WXPM__)
|
1999-10-25 15:51:37 +00:00
|
|
|
#include "wx/os2/menuitem.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
1999-10-25 15:51:37 +00:00
|
|
|
#endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#endif // wxUSE_MENUS
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
1998-09-18 21:33:46 +00:00
|
|
|
// _WX_MENUITEM_H_BASE_
|