1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenuItem class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #include "wx/ownerdrw.h"
21 #include "wx/bitmap.h"
24 // ----------------------------------------------------------------------------
25 // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour
26 // ----------------------------------------------------------------------------
28 class WXDLLIMPEXP_CORE wxMenuItem
: public wxMenuItemBase
35 wxMenuItem(wxMenu
*parentMenu
= NULL
,
36 int id
= wxID_SEPARATOR
,
37 const wxString
& name
= wxEmptyString
,
38 const wxString
& help
= wxEmptyString
,
39 wxItemKind kind
= wxITEM_NORMAL
,
40 wxMenu
*subMenu
= NULL
);
41 virtual ~wxMenuItem();
43 // override base class virtuals
44 virtual void SetItemLabel(const wxString
& strName
);
46 virtual void Enable(bool bDoEnable
= true);
47 virtual void Check(bool bDoCheck
= true);
48 virtual bool IsChecked() const;
50 // unfortunately needed to resolve ambiguity between
51 // wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable()
52 bool IsCheckable() const { return wxMenuItemBase
::IsCheckable(); }
54 // the id for a popup menu is really its menu handle (as required by
55 // ::AppendMenu() API), so this function will return either the id or the
56 // menu handle depending on what we are
58 // notice that it also returns the id as an unsigned int, as required by
60 WXWPARAM
GetMSWId() const;
62 // mark item as belonging to the given radio group
63 void SetAsRadioGroupStart();
64 void SetRadioGroupStart(int start
);
65 void SetRadioGroupEnd(int end
);
67 #if WXWIN_COMPATIBILITY_2_8
68 // compatibility only, don't use in new code
70 wxMenuItem(wxMenu
*parentMenu
,
75 wxMenu
*subMenu
= NULL
)
81 void SetBitmaps(const wxBitmap
& bmpChecked
,
82 const wxBitmap
& bmpUnchecked
= wxNullBitmap
)
84 m_bmpChecked
= bmpChecked
;
85 m_bmpUnchecked
= bmpUnchecked
;
89 void SetBitmap(const wxBitmap
& bmp
, bool bChecked
= true)
98 void SetDisabledBitmap(const wxBitmap
& bmpDisabled
)
100 m_bmpDisabled
= bmpDisabled
;
104 const wxBitmap
& GetBitmap(bool bChecked
= true) const
105 { return (bChecked ? m_bmpChecked
: m_bmpUnchecked
); }
107 const wxBitmap
& GetDisabledBitmap() const
108 { return m_bmpDisabled
; }
111 // override wxOwnerDrawn base class virtuals
112 virtual wxString
GetName() const;
113 virtual bool OnMeasureItem(size_t *pwidth
, size_t *pheight
);
114 virtual bool OnDrawItem(wxDC
& dc
, const wxRect
& rc
, wxODAction act
, wxODStatus stat
);
117 virtual void GetFontToUse(wxFont
& font
) const;
119 #endif // wxUSE_OWNER_DRAWN
122 // common part of all ctors
125 // the positions of the first and last items of the radio group this item
126 // belongs to or -1: start is the radio group start and is valid for all
127 // but first radio group items (m_isRadioGroupStart == false), end is valid
128 // only for the first one
135 // does this item start a radio group?
136 bool m_isRadioGroupStart
;
138 #if wxUSE_OWNER_DRAWN
140 wxBitmap m_bmpChecked
, // bitmap to put near the item
141 m_bmpUnchecked
, // (checked is used also for 'uncheckable' items)
144 // static variables for cache some system settings
145 static wxFont ms_systemMenuFont
;
146 static size_t ms_systemMenuHeight
;
147 static bool ms_alwaysShowCues
;
148 #endif // wxUSE_OWNER_DRAWN
150 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem
)