]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menuitem.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / msw / menuitem.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/menuitem.h
3 // Purpose: wxMenuItem class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 11.11.97
7 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _MENUITEM_H
12 #define _MENUITEM_H
13
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17
18 #if wxUSE_OWNER_DRAWN
19 #include "wx/ownerdrw.h"
20 #include "wx/bitmap.h"
21
22 struct tagRECT;
23 #endif
24
25 // ----------------------------------------------------------------------------
26 // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour
27 // ----------------------------------------------------------------------------
28
29 class WXDLLIMPEXP_CORE wxMenuItem : public wxMenuItemBase
30 #if wxUSE_OWNER_DRAWN
31 , public wxOwnerDrawn
32 #endif
33 {
34 public:
35 // ctor & dtor
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();
43
44 // override base class virtuals
45 virtual void SetItemLabel(const wxString& strName);
46
47 virtual void Enable(bool bDoEnable = true);
48 virtual void Check(bool bDoCheck = true);
49 virtual bool IsChecked() const;
50
51 // unfortunately needed to resolve ambiguity between
52 // wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable()
53 bool IsCheckable() const { return wxMenuItemBase::IsCheckable(); }
54
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
58 //
59 // notice that it also returns the id as an unsigned int, as required by
60 // Win32 API
61 WXWPARAM GetMSWId() const;
62
63 #if WXWIN_COMPATIBILITY_2_8
64 // compatibility only, don't use in new code
65 wxDEPRECATED(
66 wxMenuItem(wxMenu *parentMenu,
67 int id,
68 const wxString& text,
69 const wxString& help,
70 bool isCheckable,
71 wxMenu *subMenu = NULL)
72 );
73 #endif
74
75 #if wxUSE_OWNER_DRAWN
76
77 void SetBitmaps(const wxBitmap& bmpChecked,
78 const wxBitmap& bmpUnchecked = wxNullBitmap)
79 {
80 m_bmpChecked = bmpChecked;
81 m_bmpUnchecked = bmpUnchecked;
82 SetOwnerDrawn(true);
83 }
84
85 void SetBitmap(const wxBitmap& bmp, bool bChecked = true)
86 {
87 if ( bChecked )
88 m_bmpChecked = bmp;
89 else
90 m_bmpUnchecked = bmp;
91 SetOwnerDrawn(true);
92 }
93
94 void SetDisabledBitmap(const wxBitmap& bmpDisabled)
95 {
96 m_bmpDisabled = bmpDisabled;
97 SetOwnerDrawn(true);
98 }
99
100 const wxBitmap& GetBitmap(bool bChecked = true) const
101 { return (bChecked ? m_bmpChecked : m_bmpUnchecked); }
102
103 const wxBitmap& GetDisabledBitmap() const
104 { return m_bmpDisabled; }
105
106 int MeasureAccelWidth() const;
107
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);
112
113 protected:
114 virtual void GetFontToUse(wxFont& font) const;
115 virtual void GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const;
116
117 private:
118 // helper function for draw std menu check mark
119 void DrawStdCheckMark(WXHDC hdc, const tagRECT* rc, wxODStatus stat);
120
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
131
132 private:
133 // common part of all ctors
134 void Init();
135
136
137 #if wxUSE_OWNER_DRAWN
138 // item bitmaps
139 wxBitmap m_bmpChecked, // bitmap to put near the item
140 m_bmpUnchecked, // (checked is used also for 'uncheckable' items)
141 m_bmpDisabled;
142 #endif // wxUSE_OWNER_DRAWN
143
144 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem)
145 };
146
147 #endif //_MENUITEM_H