menuitem.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/cocoa/menuitem.h
  3. // Purpose: wxMenuItem class
  4. // Author: David Elliott
  5. // Modified by:
  6. // Created: 2002/12/13
  7. // Copyright: (c) 2002 David Elliott
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_COCOA_MENUITEM_H_
  11. #define _WX_COCOA_MENUITEM_H_
  12. #include "wx/hashmap.h"
  13. #include "wx/bitmap.h"
  14. #include "wx/cocoa/ObjcRef.h"
  15. // ========================================================================
  16. // wxMenuItem
  17. // ========================================================================
  18. #define wxMenuItemCocoa wxMenuItem
  19. class wxMenuItemCocoa;
  20. WX_DECLARE_HASH_MAP(WX_NSMenuItem,wxMenuItem*,wxPointerHash,wxPointerEqual,wxMenuItemCocoaHash);
  21. class WXDLLIMPEXP_CORE wxMenuItemCocoa : public wxMenuItemBase
  22. {
  23. public:
  24. // ------------------------------------------------------------------------
  25. // initialization
  26. // ------------------------------------------------------------------------
  27. wxMenuItemCocoa(wxMenu *parentMenu = NULL,
  28. int id = wxID_SEPARATOR,
  29. const wxString& name = wxEmptyString,
  30. const wxString& help = wxEmptyString,
  31. wxItemKind kind = wxITEM_NORMAL,
  32. wxMenu *subMenu = NULL);
  33. virtual ~wxMenuItemCocoa();
  34. // ------------------------------------------------------------------------
  35. // Cocoa specifics
  36. // ------------------------------------------------------------------------
  37. public:
  38. inline WX_NSMenuItem GetNSMenuItem() { return m_cocoaNSMenuItem; }
  39. static inline wxMenuItem* GetFromCocoa(WX_NSMenuItem cocoaNSMenuItem)
  40. {
  41. wxMenuItemCocoaHash::iterator iter=sm_cocoaHash.find(cocoaNSMenuItem);
  42. if(iter!=sm_cocoaHash.end())
  43. return iter->second;
  44. return NULL;
  45. }
  46. void CocoaItemSelected();
  47. bool Cocoa_validateMenuItem();
  48. protected:
  49. void CocoaSetKeyEquivalent();
  50. WX_NSMenuItem m_cocoaNSMenuItem;
  51. static wxMenuItemCocoaHash sm_cocoaHash;
  52. static wxObjcAutoRefFromAlloc<struct objc_object *> sm_cocoaTarget;
  53. // ------------------------------------------------------------------------
  54. // Implementation
  55. // ------------------------------------------------------------------------
  56. public:
  57. // override base class virtuals to update the item appearance on screen
  58. virtual void SetItemLabel(const wxString& text);
  59. virtual void SetCheckable(bool checkable);
  60. virtual void Enable(bool enable = TRUE);
  61. virtual void Check(bool check = TRUE);
  62. // we add some extra functions which are also available under MSW from
  63. // wxOwnerDrawn class - they will be moved to wxMenuItemBase later
  64. // hopefully
  65. void SetBitmaps(const wxBitmap& bmpChecked,
  66. const wxBitmap& bmpUnchecked = wxNullBitmap);
  67. void SetBitmap(const wxBitmap& bmp) { SetBitmaps(bmp); }
  68. const wxBitmap& GetBitmap(bool checked = TRUE) const
  69. { return checked ? m_bmpChecked : m_bmpUnchecked; }
  70. protected:
  71. // notify the menu about the change in this item
  72. inline void NotifyMenu();
  73. // set the accel index and string from text
  74. void UpdateAccelInfo();
  75. // the bitmaps (may be invalid, then they're not used)
  76. wxBitmap m_bmpChecked,
  77. m_bmpUnchecked;
  78. // the accel string (i.e. "Ctrl-Q" or "Alt-F1")
  79. wxString m_strAccel;
  80. private:
  81. DECLARE_DYNAMIC_CLASS(wxMenuItem)
  82. };
  83. #endif // _WX_COCOA_MENUITEM_H_