]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menuitem.h
Fixed dialog units <-> pixels conversion.
[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 int MeasureAccelWidth() const;
111
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);
116
117 protected:
118 virtual void GetFontToUse(wxFont& font) const;
119 virtual void GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const;
120
121 private:
122 // helper function for draw std menu check mark
123 void DrawStdCheckMark(HDC hdc, const RECT* rc, wxODStatus stat);
124
125 #endif // wxUSE_OWNER_DRAWN
126
127 private:
128 // common part of all ctors
129 void Init();
130
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
135 union
136 {
137 int start;
138 int end;
139 } m_radioGroup;
140
141 // does this item start a radio group?
142 bool m_isRadioGroupStart;
143
144 #if wxUSE_OWNER_DRAWN
145 // item bitmaps
146 wxBitmap m_bmpChecked, // bitmap to put near the item
147 m_bmpUnchecked, // (checked is used also for 'uncheckable' items)
148 m_bmpDisabled;
149 #endif // wxUSE_OWNER_DRAWN
150
151 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem)
152 };
153
154 #endif //_MENUITEM_H