menuitem.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/menuitem.h
  3. // Purpose: wxMenuItem class for wxUniversal
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 05.05.01
  7. // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UNIV_MENUITEM_H_
  11. #define _WX_UNIV_MENUITEM_H_
  12. // ----------------------------------------------------------------------------
  13. // wxMenuItem implements wxMenuItemBase
  14. // ----------------------------------------------------------------------------
  15. class WXDLLIMPEXP_CORE wxMenuItem : public wxMenuItemBase
  16. {
  17. public:
  18. // ctor & dtor
  19. wxMenuItem(wxMenu *parentMenu = NULL,
  20. int id = wxID_SEPARATOR,
  21. const wxString& name = wxEmptyString,
  22. const wxString& help = wxEmptyString,
  23. wxItemKind kind = wxITEM_NORMAL,
  24. wxMenu *subMenu = NULL);
  25. virtual ~wxMenuItem();
  26. // override base class virtuals to update the item appearance on screen
  27. virtual void SetItemLabel(const wxString& text);
  28. virtual void SetCheckable(bool checkable);
  29. virtual void Enable(bool enable = true);
  30. virtual void Check(bool check = true);
  31. // we add some extra functions which are also available under MSW from
  32. // wxOwnerDrawn class - they will be moved to wxMenuItemBase later
  33. // hopefully
  34. void SetBitmaps(const wxBitmap& bmpChecked,
  35. const wxBitmap& bmpUnchecked = wxNullBitmap);
  36. void SetBitmap(const wxBitmap& bmp) { SetBitmaps(bmp); }
  37. const wxBitmap& GetBitmap(bool checked = true) const
  38. { return checked ? m_bmpChecked : m_bmpUnchecked; }
  39. void SetDisabledBitmap( const wxBitmap& bmpDisabled )
  40. { m_bmpDisabled = bmpDisabled; }
  41. const wxBitmap& GetDisabledBitmap() const
  42. { return m_bmpDisabled; }
  43. // mark item as belonging to the given radio group
  44. void SetAsRadioGroupStart();
  45. void SetRadioGroupStart(int start);
  46. void SetRadioGroupEnd(int end);
  47. // wxUniv-specific methods for implementation only starting from here
  48. // get the accel index of our label or -1 if none
  49. int GetAccelIndex() const { return m_indexAccel; }
  50. // get the accel string (displayed to the right of the label)
  51. const wxString& GetAccelString() const { return m_strAccel; }
  52. // set/get the y coord and the height of this item: note that it must be
  53. // set first and retrieved later, the item doesn't calculate it itself
  54. void SetGeometry(wxCoord y, wxCoord height)
  55. {
  56. m_posY = y;
  57. m_height = height;
  58. }
  59. wxCoord GetPosition() const
  60. {
  61. wxASSERT_MSG( m_posY != wxDefaultCoord, wxT("must call SetHeight first!") );
  62. return m_posY;
  63. }
  64. wxCoord GetHeight() const
  65. {
  66. wxASSERT_MSG( m_height != wxDefaultCoord, wxT("must call SetHeight first!") );
  67. return m_height;
  68. }
  69. protected:
  70. // notify the menu about the change in this item
  71. inline void NotifyMenu();
  72. // set the accel index and string from text
  73. void UpdateAccelInfo();
  74. // the bitmaps (may be invalid, then they're not used)
  75. wxBitmap m_bmpChecked,
  76. m_bmpUnchecked,
  77. m_bmpDisabled;
  78. // the positions of the first and last items of the radio group this item
  79. // belongs to or -1: start is the radio group start and is valid for all
  80. // but first radio group items (m_isRadioGroupStart == false), end is valid
  81. // only for the first one
  82. union
  83. {
  84. int start;
  85. int end;
  86. } m_radioGroup;
  87. // does this item start a radio group?
  88. bool m_isRadioGroupStart;
  89. // the position of the accelerator in our label, -1 if none
  90. int m_indexAccel;
  91. // the accel string (i.e. "Ctrl-Q" or "Alt-F1")
  92. wxString m_strAccel;
  93. // the position and height of the displayed item
  94. wxCoord m_posY,
  95. m_height;
  96. private:
  97. DECLARE_DYNAMIC_CLASS(wxMenuItem)
  98. };
  99. #endif // _WX_UNIV_MENUITEM_H_