menuitem.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/os2/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. #include "wx/defs.h"
  16. #include "wx/os2/private.h" // for MENUITEM
  17. // an exception to the general rule that a normal header doesn't include other
  18. // headers - only because ownerdrw.h is not always included and I don't want
  19. // to write #ifdef's everywhere...
  20. #if wxUSE_OWNER_DRAWN
  21. #include "wx/ownerdrw.h"
  22. #include "wx/bitmap.h"
  23. #endif
  24. // ----------------------------------------------------------------------------
  25. // constants
  26. // ----------------------------------------------------------------------------
  27. // ----------------------------------------------------------------------------
  28. // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour
  29. // ----------------------------------------------------------------------------
  30. class WXDLLIMPEXP_CORE wxMenuItem: public wxMenuItemBase
  31. #if wxUSE_OWNER_DRAWN
  32. , public wxOwnerDrawn
  33. #endif
  34. {
  35. public:
  36. //
  37. // ctor & dtor
  38. //
  39. wxMenuItem( wxMenu* pParentMenu = NULL
  40. ,int nId = wxID_SEPARATOR
  41. ,const wxString& rStrName = wxEmptyString
  42. ,const wxString& rWxHelp = wxEmptyString
  43. ,wxItemKind eKind = wxITEM_NORMAL
  44. ,wxMenu* pSubMenu = NULL
  45. );
  46. //
  47. // Depricated, do not use in new code
  48. //
  49. wxMenuItem( wxMenu* pParentMenu
  50. ,int vId
  51. ,const wxString& rsText
  52. ,const wxString& rsHelp
  53. ,bool bIsCheckable
  54. ,wxMenu* pSubMenu = NULL
  55. );
  56. virtual ~wxMenuItem();
  57. //
  58. // Override base class virtuals
  59. //
  60. virtual void SetItemLabel(const wxString& rStrName);
  61. virtual void Enable(bool bDoEnable = true);
  62. virtual void Check(bool bDoCheck = true);
  63. virtual bool IsChecked(void) const;
  64. //
  65. // Unfortunately needed to resolve ambiguity between
  66. // wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable()
  67. //
  68. bool IsCheckable(void) const { return wxMenuItemBase::IsCheckable(); }
  69. //
  70. // The id for a popup menu is really its menu handle (as required by
  71. // ::AppendMenu() API), so this function will return either the id or the
  72. // menu handle depending on what we're
  73. //
  74. int GetRealId(void) const;
  75. //
  76. // Mark item as belonging to the given radio group
  77. //
  78. void SetAsRadioGroupStart(void);
  79. void SetRadioGroupStart(int nStart);
  80. void SetRadioGroupEnd(int nEnd);
  81. //
  82. // All OS/2PM Submenus and menus have one of these
  83. //
  84. MENUITEM m_vMenuData;
  85. #if wxUSE_OWNER_DRAWN
  86. void SetBitmaps(const wxBitmap& bmpChecked,
  87. const wxBitmap& bmpUnchecked = wxNullBitmap)
  88. {
  89. m_bmpChecked = bmpChecked;
  90. m_bmpUnchecked = bmpUnchecked;
  91. SetOwnerDrawn(true);
  92. }
  93. void SetBitmap(const wxBitmap& bmp, bool bChecked = true)
  94. {
  95. if ( bChecked )
  96. m_bmpChecked = bmp;
  97. else
  98. m_bmpUnchecked = bmp;
  99. SetOwnerDrawn(true);
  100. }
  101. void SetDisabledBitmap(const wxBitmap& bmpDisabled)
  102. {
  103. m_bmpDisabled = bmpDisabled;
  104. SetOwnerDrawn(true);
  105. }
  106. const wxBitmap& GetBitmap(bool bChecked = true) const
  107. { return (bChecked ? m_bmpChecked : m_bmpUnchecked); }
  108. const wxBitmap& GetDisabledBitmap() const
  109. { return m_bmpDisabled; }
  110. // override wxOwnerDrawn base class virtuals
  111. virtual wxString GetName() const;
  112. virtual bool OnMeasureItem(size_t *pwidth, size_t *pheight);
  113. virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat);
  114. protected:
  115. virtual void GetFontToUse(wxFont& font) const;
  116. #endif // wxUSE_OWNER_DRAWN
  117. private:
  118. void Init();
  119. //
  120. // The positions of the first and last items of the radio group this item
  121. // belongs to or -1: start is the radio group start and is valid for all
  122. // but first radio group items (m_isRadioGroupStart == FALSE), end is valid
  123. // only for the first one
  124. //
  125. union
  126. {
  127. int m_nStart;
  128. int m_nEnd;
  129. } m_vRadioGroup;
  130. //
  131. // Does this item start a radio group?
  132. //
  133. bool m_bIsRadioGroupStart;
  134. #if wxUSE_OWNER_DRAWN
  135. // item bitmaps
  136. wxBitmap m_bmpChecked, // bitmap to put near the item
  137. m_bmpUnchecked, // (checked is used also for 'uncheckable' items)
  138. m_bmpDisabled;
  139. #endif // wxUSE_OWNER_DRAWN
  140. DECLARE_DYNAMIC_CLASS(wxMenuItem)
  141. }; // end of CLASS wxMenuItem
  142. #endif //_MENUITEM_H