]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | struct tagRECT; | |
24 | #endif | |
25 | ||
26 | // ---------------------------------------------------------------------------- | |
27 | // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour | |
28 | // ---------------------------------------------------------------------------- | |
29 | ||
30 | class WXDLLIMPEXP_CORE wxMenuItem : public wxMenuItemBase | |
31 | #if wxUSE_OWNER_DRAWN | |
32 | , public wxOwnerDrawn | |
33 | #endif | |
34 | { | |
35 | public: | |
36 | // ctor & dtor | |
37 | wxMenuItem(wxMenu *parentMenu = NULL, | |
38 | int id = wxID_SEPARATOR, | |
39 | const wxString& name = wxEmptyString, | |
40 | const wxString& help = wxEmptyString, | |
41 | wxItemKind kind = wxITEM_NORMAL, | |
42 | wxMenu *subMenu = NULL); | |
43 | virtual ~wxMenuItem(); | |
44 | ||
45 | // override base class virtuals | |
46 | virtual void SetItemLabel(const wxString& strName); | |
47 | ||
48 | virtual void Enable(bool bDoEnable = true); | |
49 | virtual void Check(bool bDoCheck = true); | |
50 | virtual bool IsChecked() const; | |
51 | ||
52 | // unfortunately needed to resolve ambiguity between | |
53 | // wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable() | |
54 | bool IsCheckable() const { return wxMenuItemBase::IsCheckable(); } | |
55 | ||
56 | // the id for a popup menu is really its menu handle (as required by | |
57 | // ::AppendMenu() API), so this function will return either the id or the | |
58 | // menu handle depending on what we are | |
59 | // | |
60 | // notice that it also returns the id as an unsigned int, as required by | |
61 | // Win32 API | |
62 | WXWPARAM GetMSWId() const; | |
63 | ||
64 | // mark item as belonging to the given radio group | |
65 | void SetAsRadioGroupStart(); | |
66 | void SetRadioGroupStart(int start); | |
67 | void SetRadioGroupEnd(int end); | |
68 | ||
69 | #if WXWIN_COMPATIBILITY_2_8 | |
70 | // compatibility only, don't use in new code | |
71 | wxDEPRECATED( | |
72 | wxMenuItem(wxMenu *parentMenu, | |
73 | int id, | |
74 | const wxString& text, | |
75 | const wxString& help, | |
76 | bool isCheckable, | |
77 | wxMenu *subMenu = NULL) | |
78 | ); | |
79 | #endif | |
80 | ||
81 | #if wxUSE_OWNER_DRAWN | |
82 | ||
83 | void SetBitmaps(const wxBitmap& bmpChecked, | |
84 | const wxBitmap& bmpUnchecked = wxNullBitmap) | |
85 | { | |
86 | m_bmpChecked = bmpChecked; | |
87 | m_bmpUnchecked = bmpUnchecked; | |
88 | SetOwnerDrawn(true); | |
89 | } | |
90 | ||
91 | void SetBitmap(const wxBitmap& bmp, bool bChecked = true) | |
92 | { | |
93 | if ( bChecked ) | |
94 | m_bmpChecked = bmp; | |
95 | else | |
96 | m_bmpUnchecked = bmp; | |
97 | SetOwnerDrawn(true); | |
98 | } | |
99 | ||
100 | void SetDisabledBitmap(const wxBitmap& bmpDisabled) | |
101 | { | |
102 | m_bmpDisabled = bmpDisabled; | |
103 | SetOwnerDrawn(true); | |
104 | } | |
105 | ||
106 | const wxBitmap& GetBitmap(bool bChecked = true) const | |
107 | { return (bChecked ? m_bmpChecked : m_bmpUnchecked); } | |
108 | ||
109 | const wxBitmap& GetDisabledBitmap() const | |
110 | { return m_bmpDisabled; } | |
111 | ||
112 | int MeasureAccelWidth() const; | |
113 | ||
114 | // override wxOwnerDrawn base class virtuals | |
115 | virtual wxString GetName() const; | |
116 | virtual bool OnMeasureItem(size_t *pwidth, size_t *pheight); | |
117 | virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat); | |
118 | ||
119 | protected: | |
120 | virtual void GetFontToUse(wxFont& font) const; | |
121 | virtual void GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const; | |
122 | ||
123 | private: | |
124 | // helper function for draw std menu check mark | |
125 | void DrawStdCheckMark(WXHDC hdc, const tagRECT* rc, wxODStatus stat); | |
126 | ||
127 | #endif // wxUSE_OWNER_DRAWN | |
128 | ||
129 | private: | |
130 | // common part of all ctors | |
131 | void Init(); | |
132 | ||
133 | // the positions of the first and last items of the radio group this item | |
134 | // belongs to or -1: start is the radio group start and is valid for all | |
135 | // but first radio group items (m_isRadioGroupStart == false), end is valid | |
136 | // only for the first one | |
137 | union | |
138 | { | |
139 | int start; | |
140 | int end; | |
141 | } m_radioGroup; | |
142 | ||
143 | // does this item start a radio group? | |
144 | bool m_isRadioGroupStart; | |
145 | ||
146 | #if wxUSE_OWNER_DRAWN | |
147 | // item bitmaps | |
148 | wxBitmap m_bmpChecked, // bitmap to put near the item | |
149 | m_bmpUnchecked, // (checked is used also for 'uncheckable' items) | |
150 | m_bmpDisabled; | |
151 | #endif // wxUSE_OWNER_DRAWN | |
152 | ||
153 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem) | |
154 | }; | |
155 | ||
156 | #endif //_MENUITEM_H |