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>
|
|
|
|
// Licence: wxWindows license
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-09-18 17:33:46 -04:00
|
|
|
#ifndef _WX_MENUITEM_H_BASE_
|
|
|
|
#define _WX_MENUITEM_H_BASE_
|
|
|
|
|
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
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
class WXDLLEXPORT wxAcceleratorEntry;
|
1999-10-25 11:51:37 -04:00
|
|
|
class WXDLLEXPORT wxMenuItem;
|
|
|
|
class WXDLLEXPORT wxMenu;
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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,
|
|
|
|
int id = wxID_SEPARATOR,
|
|
|
|
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; }
|
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
// get/set id
|
|
|
|
void SetId(int id) { m_id = id; }
|
|
|
|
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)
|
|
|
|
//
|
|
|
|
// NB: the item's text includes the accelerators and mnemonics info (if
|
|
|
|
// any), i.e. it may contain '&' or '_' or "\t..." and thus is
|
|
|
|
// different from the item's label which only contains the text shown
|
|
|
|
// in the menu
|
1999-10-25 11:51:37 -04:00
|
|
|
virtual void SetText(const wxString& str) { m_text = str; }
|
2000-01-11 08:58:41 -05:00
|
|
|
wxString GetLabel() const { return GetLabelFromText(m_text); }
|
1999-10-25 11:51:37 -04:00
|
|
|
const wxString& GetText() const { return m_text; }
|
|
|
|
|
2000-01-11 08:58:41 -05:00
|
|
|
// get the label from text (implemented in platform-specific code)
|
|
|
|
static wxString GetLabelFromText(const wxString& text);
|
|
|
|
|
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; }
|
|
|
|
|
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
|
|
|
|
virtual void Enable(bool enable = TRUE) { m_isEnabled = enable; }
|
|
|
|
virtual bool IsEnabled() const { return m_isEnabled; }
|
1999-11-01 20:25:43 -05:00
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
virtual void Check(bool check = TRUE) { m_isChecked = check; }
|
|
|
|
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)
|
|
|
|
void SetHelp(const wxString& str) { m_help = str; }
|
|
|
|
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
|
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
// compatibility only, use new functions in the new code
|
|
|
|
void SetName(const wxString& str) { SetText(str); }
|
|
|
|
const wxString& GetName() const { return GetText(); }
|
|
|
|
|
2002-03-18 14:41:35 -05:00
|
|
|
static wxMenuItem *New(wxMenu *parentMenu,
|
|
|
|
int id,
|
|
|
|
const wxString& text,
|
|
|
|
const wxString& help,
|
|
|
|
bool isCheckable,
|
|
|
|
wxMenu *subMenu = (wxMenu *)NULL)
|
|
|
|
{
|
|
|
|
return New(parentMenu, id, 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:
|
|
|
|
int m_id; // numeric id of the item >= 0 or -1
|
|
|
|
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
|
2002-03-18 14:41:35 -05:00
|
|
|
wxItemKind m_kind; // seperator/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,
|
|
|
|
int id = wxID_SEPARATOR,
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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"
|
|
|
|
#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"
|
1998-09-18 17:33:46 -04:00
|
|
|
#elif defined(__WXGTK__)
|
1999-10-25 11:51:37 -04:00
|
|
|
#include "wx/gtk/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"
|
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-09-18 17:33:46 -04:00
|
|
|
#elif defined(__WXSTUBS__)
|
1999-10-25 11:51:37 -04:00
|
|
|
#include "wx/stubs/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_
|