1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/menuitem.h
3 // Purpose: wxMenuItem class
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
19 #include "wx/ownerdrw.h"
20 #include "wx/bitmap.h"
25 // ----------------------------------------------------------------------------
26 // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour
27 // ----------------------------------------------------------------------------
29 class WXDLLIMPEXP_CORE wxMenuItem
: public wxMenuItemBase
36 wxMenuItem(wxMenu
*parentMenu
= NULL
,
37 int id
= wxID_SEPARATOR
,
38 const wxString
& name
= wxEmptyString
,
39 const wxString
& help
= wxEmptyString
,
40 wxItemKind kind
= wxITEM_NORMAL
,
41 wxMenu
*subMenu
= NULL
);
42 virtual ~wxMenuItem();
44 // override base class virtuals
45 virtual void SetItemLabel(const wxString
& strName
);
47 virtual void Enable(bool bDoEnable
= true);
48 virtual void Check(bool bDoCheck
= true);
49 virtual bool IsChecked() const;
51 // unfortunately needed to resolve ambiguity between
52 // wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable()
53 bool IsCheckable() const { return wxMenuItemBase::IsCheckable(); }
55 // the id for a popup menu is really its menu handle (as required by
56 // ::AppendMenu() API), so this function will return either the id or the
57 // menu handle depending on what we are
59 // notice that it also returns the id as an unsigned int, as required by
61 WXWPARAM
GetMSWId() const;
63 #if WXWIN_COMPATIBILITY_2_8
64 // compatibility only, don't use in new code
66 wxMenuItem(wxMenu
*parentMenu
,
71 wxMenu
*subMenu
= NULL
)
77 void SetBitmaps(const wxBitmap
& bmpChecked
,
78 const wxBitmap
& bmpUnchecked
= wxNullBitmap
)
80 m_bmpChecked
= bmpChecked
;
81 m_bmpUnchecked
= bmpUnchecked
;
85 void SetBitmap(const wxBitmap
& bmp
, bool bChecked
= true)
94 void SetDisabledBitmap(const wxBitmap
& bmpDisabled
)
96 m_bmpDisabled
= bmpDisabled
;
100 const wxBitmap
& GetBitmap(bool bChecked
= true) const
101 { return (bChecked
? m_bmpChecked
: m_bmpUnchecked
); }
103 const wxBitmap
& GetDisabledBitmap() const
104 { return m_bmpDisabled
; }
106 int MeasureAccelWidth() const;
108 // override wxOwnerDrawn base class virtuals
109 virtual wxString
GetName() const;
110 virtual bool OnMeasureItem(size_t *pwidth
, size_t *pheight
);
111 virtual bool OnDrawItem(wxDC
& dc
, const wxRect
& rc
, wxODAction act
, wxODStatus stat
);
114 virtual void GetFontToUse(wxFont
& font
) const;
115 virtual void GetColourToUse(wxODStatus stat
, wxColour
& colText
, wxColour
& colBack
) const;
118 // helper function for draw std menu check mark
119 void DrawStdCheckMark(WXHDC hdc
, const tagRECT
* rc
, wxODStatus stat
);
121 #else // !wxUSE_OWNER_DRAWN
122 // Provide stubs for the public functions above to ensure that the code
123 // still compiles without wxUSE_OWNER_DRAWN -- it makes sense to just drop
124 // the bitmaps then instead of failing compilation.
125 void SetBitmaps(const wxBitmap
& WXUNUSED(bmpChecked
),
126 const wxBitmap
& WXUNUSED(bmpUnchecked
) = wxNullBitmap
) { }
127 void SetBitmap(const wxBitmap
& WXUNUSED(bmp
),
128 bool WXUNUSED(bChecked
) = true) { }
129 const wxBitmap
& GetBitmap() const { return wxNullBitmap
; }
130 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
133 // common part of all ctors
137 #if wxUSE_OWNER_DRAWN
139 wxBitmap m_bmpChecked
, // bitmap to put near the item
140 m_bmpUnchecked
, // (checked is used also for 'uncheckable' items)
142 #endif // wxUSE_OWNER_DRAWN
144 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem
)