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
; }
110 int MeasureAccelWidth() const;
112 // override wxOwnerDrawn base class virtuals
113 virtual wxString
GetName() const;
114 virtual bool OnMeasureItem(size_t *pwidth
, size_t *pheight
);
115 virtual bool OnDrawItem(wxDC
& dc
, const wxRect
& rc
, wxODAction act
, wxODStatus stat
);
118 virtual void GetFontToUse(wxFont
& font
) const;
119 virtual void GetColourToUse(wxODStatus stat
, wxColour
& colText
, wxColour
& colBack
) const;
122 // helper function for draw std menu check mark
123 void DrawStdCheckMark(HDC hdc
, const RECT
* rc
, wxODStatus stat
);
125 #endif // wxUSE_OWNER_DRAWN
128 // common part of all ctors
131 // the positions of the first and last items of the radio group this item
132 // belongs to or -1: start is the radio group start and is valid for all
133 // but first radio group items (m_isRadioGroupStart == false), end is valid
134 // only for the first one
141 // does this item start a radio group?
142 bool m_isRadioGroupStart
;
144 #if wxUSE_OWNER_DRAWN
146 wxBitmap m_bmpChecked
, // bitmap to put near the item
147 m_bmpUnchecked
, // (checked is used also for 'uncheckable' items)
149 #endif // wxUSE_OWNER_DRAWN
151 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem
)