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
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
class WXDLLEXPORT wxAcceleratorEntry;
|
1999-10-25 15:51:37 +00: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,
|
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,
|
1999-10-25 15:51:37 +00:00
|
|
|
wxMenu *subMenu = (wxMenu *)NULL);
|
|
|
|
|
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; }
|
|
|
|
bool IsSeparator() const { return m_id == wxID_SEPARATOR; }
|
|
|
|
|
1999-11-02 01:25:43 +00: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
|
2006-09-05 21:00:55 +00:00
|
|
|
virtual void SetText(const wxString& str);
|
2000-01-11 13:58:41 +00:00
|
|
|
wxString GetLabel() const { return GetLabelFromText(m_text); }
|
1999-10-25 15:51:37 +00:00
|
|
|
const wxString& GetText() const { return m_text; }
|
|
|
|
|
2000-01-11 13:58:41 +00:00
|
|
|
// get the label from text (implemented in platform-specific code)
|
|
|
|
static wxString GetLabelFromText(const wxString& text);
|
|
|
|
|
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; }
|
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
|
|
|
|
|
1999-10-25 15:51:37 +00: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 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,
|
|
|
|
wxMenu *subMenu = (wxMenu *)NULL)
|
|
|
|
{
|
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:
|
2004-09-17 22:23:59 +00:00
|
|
|
int 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
|
|
|
|
wxMenuItemBase(wxMenu *parentMenu = (wxMenu *)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,
|
2002-03-18 19:41:35 +00:00
|
|
|
wxMenu *subMenu = (wxMenu *)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
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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"
|
2004-12-20 12:44:22 +00:00
|
|
|
#elif defined(__WXPALMOS__)
|
2004-10-19 13:40:30 +00:00
|
|
|
#include "wx/palmos/menuitem.h"
|
2001-06-26 20:59:19 +00:00
|
|
|
#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__)
|
1999-10-25 15:51:37 +00:00
|
|
|
#include "wx/mac/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_
|