menuitem.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #ifndef _MENUITEM_H
  11. #define _MENUITEM_H
  12. // ----------------------------------------------------------------------------
  13. // headers
  14. // ----------------------------------------------------------------------------
  15. #if wxUSE_OWNER_DRAWN
  16. #include "wx/ownerdrw.h"
  17. #include "wx/bitmap.h"
  18. struct tagRECT;
  19. #endif
  20. // ----------------------------------------------------------------------------
  21. // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour
  22. // ----------------------------------------------------------------------------
  23. class WXDLLIMPEXP_CORE wxMenuItem : public wxMenuItemBase
  24. #if wxUSE_OWNER_DRAWN
  25. , public wxOwnerDrawn
  26. #endif
  27. {
  28. public:
  29. // ctor & dtor
  30. wxMenuItem(wxMenu *parentMenu = NULL,
  31. int id = wxID_SEPARATOR,
  32. const wxString& name = wxEmptyString,
  33. const wxString& help = wxEmptyString,
  34. wxItemKind kind = wxITEM_NORMAL,
  35. wxMenu *subMenu = NULL);
  36. virtual ~wxMenuItem();
  37. // override base class virtuals
  38. virtual void SetItemLabel(const wxString& strName);
  39. virtual void Enable(bool bDoEnable = true);
  40. virtual void Check(bool bDoCheck = true);
  41. virtual bool IsChecked() const;
  42. // unfortunately needed to resolve ambiguity between
  43. // wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable()
  44. bool IsCheckable() const { return wxMenuItemBase::IsCheckable(); }
  45. // the id for a popup menu is really its menu handle (as required by
  46. // ::AppendMenu() API), so this function will return either the id or the
  47. // menu handle depending on what we are
  48. //
  49. // notice that it also returns the id as an unsigned int, as required by
  50. // Win32 API
  51. WXWPARAM GetMSWId() const;
  52. #if WXWIN_COMPATIBILITY_2_8
  53. // compatibility only, don't use in new code
  54. wxDEPRECATED(
  55. wxMenuItem(wxMenu *parentMenu,
  56. int id,
  57. const wxString& text,
  58. const wxString& help,
  59. bool isCheckable,
  60. wxMenu *subMenu = NULL)
  61. );
  62. #endif
  63. #if wxUSE_OWNER_DRAWN
  64. void SetBitmaps(const wxBitmap& bmpChecked,
  65. const wxBitmap& bmpUnchecked = wxNullBitmap)
  66. {
  67. m_bmpChecked = bmpChecked;
  68. m_bmpUnchecked = bmpUnchecked;
  69. SetOwnerDrawn(true);
  70. }
  71. void SetBitmap(const wxBitmap& bmp, bool bChecked = true)
  72. {
  73. if ( bChecked )
  74. m_bmpChecked = bmp;
  75. else
  76. m_bmpUnchecked = bmp;
  77. SetOwnerDrawn(true);
  78. }
  79. void SetDisabledBitmap(const wxBitmap& bmpDisabled)
  80. {
  81. m_bmpDisabled = bmpDisabled;
  82. SetOwnerDrawn(true);
  83. }
  84. const wxBitmap& GetBitmap(bool bChecked = true) const
  85. { return (bChecked ? m_bmpChecked : m_bmpUnchecked); }
  86. const wxBitmap& GetDisabledBitmap() const
  87. { return m_bmpDisabled; }
  88. int MeasureAccelWidth() const;
  89. // override wxOwnerDrawn base class virtuals
  90. virtual wxString GetName() const;
  91. virtual bool OnMeasureItem(size_t *pwidth, size_t *pheight);
  92. virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat);
  93. protected:
  94. virtual void GetFontToUse(wxFont& font) const;
  95. virtual void GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const;
  96. private:
  97. // helper function for draw std menu check mark
  98. void DrawStdCheckMark(WXHDC hdc, const tagRECT* rc, wxODStatus stat);
  99. #else // !wxUSE_OWNER_DRAWN
  100. // Provide stubs for the public functions above to ensure that the code
  101. // still compiles without wxUSE_OWNER_DRAWN -- it makes sense to just drop
  102. // the bitmaps then instead of failing compilation.
  103. void SetBitmaps(const wxBitmap& WXUNUSED(bmpChecked),
  104. const wxBitmap& WXUNUSED(bmpUnchecked) = wxNullBitmap) { }
  105. void SetBitmap(const wxBitmap& WXUNUSED(bmp),
  106. bool WXUNUSED(bChecked) = true) { }
  107. const wxBitmap& GetBitmap() const { return wxNullBitmap; }
  108. #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
  109. private:
  110. // common part of all ctors
  111. void Init();
  112. // Return the item position in the menu containing it.
  113. //
  114. // Returns -1 if the item is not attached to a menu or if we can't find its
  115. // position (which is not really supposed to ever happen).
  116. int MSGetMenuItemPos() const;
  117. #if wxUSE_OWNER_DRAWN
  118. // item bitmaps
  119. wxBitmap m_bmpChecked, // bitmap to put near the item
  120. m_bmpUnchecked, // (checked is used also for 'uncheckable' items)
  121. m_bmpDisabled;
  122. #endif // wxUSE_OWNER_DRAWN
  123. DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem)
  124. };
  125. #endif //_MENUITEM_H