Refactor owner-drawing code.
[wxWidgets.git] / include / wx / msw / menuitem.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: menuitem.h
3 // Purpose: wxMenuItem class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 11.11.97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _MENUITEM_H
13 #define _MENUITEM_H
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #if wxUSE_OWNER_DRAWN
20 #include "wx/ownerdrw.h"
21 #include "wx/bitmap.h"
22 #endif
23
24 // ----------------------------------------------------------------------------
25 // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour
26 // ----------------------------------------------------------------------------
27
28 class WXDLLIMPEXP_CORE wxMenuItem : public wxMenuItemBase
29 #if wxUSE_OWNER_DRAWN
30 , public wxOwnerDrawn
31 #endif
32 {
33 public:
34 // ctor & dtor
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();
42
43 // override base class virtuals
44 virtual void SetItemLabel(const wxString& strName);
45
46 virtual void Enable(bool bDoEnable = true);
47 virtual void Check(bool bDoCheck = true);
48 virtual bool IsChecked() const;
49
50 // unfortunately needed to resolve ambiguity between
51 // wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable()
52 bool IsCheckable() const { return wxMenuItemBase::IsCheckable(); }
53
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
57 //
58 // notice that it also returns the id as an unsigned int, as required by
59 // Win32 API
60 WXWPARAM GetMSWId() const;
61
62 // mark item as belonging to the given radio group
63 void SetAsRadioGroupStart();
64 void SetRadioGroupStart(int start);
65 void SetRadioGroupEnd(int end);
66
67 #if WXWIN_COMPATIBILITY_2_8
68 // compatibility only, don't use in new code
69 wxDEPRECATED(
70 wxMenuItem(wxMenu *parentMenu,
71 int id,
72 const wxString& text,
73 const wxString& help,
74 bool isCheckable,
75 wxMenu *subMenu = NULL)
76 );
77 #endif
78
79 #if wxUSE_OWNER_DRAWN
80
81 void SetBitmaps(const wxBitmap& bmpChecked,
82 const wxBitmap& bmpUnchecked = wxNullBitmap)
83 {
84 m_bmpChecked = bmpChecked;
85 m_bmpUnchecked = bmpUnchecked;
86 SetOwnerDrawn(true);
87 }
88
89 void SetBitmap(const wxBitmap& bmp, bool bChecked = true)
90 {
91 if ( bChecked )
92 m_bmpChecked = bmp;
93 else
94 m_bmpUnchecked = bmp;
95 SetOwnerDrawn(true);
96 }
97
98 void SetDisabledBitmap(const wxBitmap& bmpDisabled)
99 {
100 m_bmpDisabled = bmpDisabled;
101 SetOwnerDrawn(true);
102 }
103
104 const wxBitmap& GetBitmap(bool bChecked = true) const
105 { return (bChecked ? m_bmpChecked : m_bmpUnchecked); }
106
107 const wxBitmap& GetDisabledBitmap() const
108 { return m_bmpDisabled; }
109
110
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);
115
116 protected:
117 virtual void GetFontToUse(wxFont& font) const;
118
119 #endif // wxUSE_OWNER_DRAWN
120
121 private:
122 // common part of all ctors
123 void Init();
124
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
129 union
130 {
131 int start;
132 int end;
133 } m_radioGroup;
134
135 // does this item start a radio group?
136 bool m_isRadioGroupStart;
137
138 #if wxUSE_OWNER_DRAWN
139 // item bitmaps
140 wxBitmap m_bmpChecked, // bitmap to put near the item
141 m_bmpUnchecked, // (checked is used also for 'uncheckable' items)
142 m_bmpDisabled;
143
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
149
150 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem)
151 };
152
153 #endif //_MENUITEM_H