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 #include "wx/bitmap.h" 19 20 #if wxUSE_OWNER_DRAWN 21 #include "wx/ownerdrw.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) wxOVERRIDE; 47 48 virtual void Enable(bool bDoEnable = true) wxOVERRIDE; 49 virtual void Check(bool bDoCheck = true) wxOVERRIDE; 50 virtual bool IsChecked() const wxOVERRIDE; 51 52 // unfortunately needed to resolve ambiguity between 53 // wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable() 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 #if WXWIN_COMPATIBILITY_2_8 65 // compatibility only, don't use in new code 66 wxDEPRECATED( 67 wxMenuItem(wxMenu *parentMenu, 68 int id, 69 const wxString& text, 70 const wxString& help, 71 bool isCheckable, 72 wxMenu *subMenu = NULL) 73 ); 74 #endif 75 76 void SetBitmaps(const wxBitmap& bmpChecked, 77 const wxBitmap& bmpUnchecked = wxNullBitmap) 78 { 79 DoSetBitmap(bmpChecked, true); 80 DoSetBitmap(bmpUnchecked, false); 81 } 82 83 void SetBitmap(const wxBitmap& bmp, bool bChecked = true) 84 { 85 DoSetBitmap(bmp, bChecked); 86 } 87 88 const wxBitmap& GetBitmap(bool bChecked = true) const 89 { return (bChecked ? m_bmpChecked : m_bmpUnchecked); } 90 91 #if wxUSE_OWNER_DRAWN SetDisabledBitmap(const wxBitmap & bmpDisabled)92 void SetDisabledBitmap(const wxBitmap& bmpDisabled) 93 { 94 m_bmpDisabled = bmpDisabled; 95 SetOwnerDrawn(true); 96 } 97 GetDisabledBitmap()98 const wxBitmap& GetDisabledBitmap() const 99 { return m_bmpDisabled; } 100 101 int MeasureAccelWidth() const; 102 103 // override wxOwnerDrawn base class virtuals 104 virtual wxString GetName() const wxOVERRIDE; 105 virtual bool OnMeasureItem(size_t *pwidth, size_t *pheight) wxOVERRIDE; 106 virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat) wxOVERRIDE; 107 108 protected: 109 virtual void GetFontToUse(wxFont& font) const wxOVERRIDE; 110 virtual void GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const wxOVERRIDE; 111 112 private: 113 // helper function for draw std menu check mark 114 void DrawStdCheckMark(WXHDC hdc, const tagRECT* rc, wxODStatus stat); 115 116 // helper function to determine if the item must be owner-drawn 117 bool MSWMustUseOwnerDrawn(); 118 #endif // wxUSE_OWNER_DRAWN 119 120 enum BitmapKind 121 { 122 Normal, 123 Checked, 124 Unchecked 125 }; 126 127 // helper function to get a handle for bitmap associated with item 128 WXHBITMAP GetHBitmapForMenu(BitmapKind kind) const; 129 130 // helper function to set/change the bitmap 131 void DoSetBitmap(const wxBitmap& bmp, bool bChecked); 132 133 private: 134 // common part of all ctors 135 void Init(); 136 137 // Return the item position in the menu containing it. 138 // 139 // Returns -1 if the item is not attached to a menu or if we can't find its 140 // position (which is not really supposed to ever happen). 141 int MSGetMenuItemPos() const; 142 143 // item bitmaps 144 wxBitmap m_bmpChecked, // bitmap to put near the item 145 m_bmpUnchecked; // (checked is used also for 'uncheckable' items) 146 #if wxUSE_OWNER_DRAWN 147 wxBitmap m_bmpDisabled; 148 #endif // wxUSE_OWNER_DRAWN 149 150 // Give wxMenu access to our MSWMustUseOwnerDrawn() and GetHBitmapForMenu(). 151 friend class wxMenu; 152 153 wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem); 154 }; 155 156 #endif //_MENUITEM_H 157