menu.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/osx/menu.h
  3. // Purpose: wxMenu, wxMenuBar classes
  4. // Author: Stefan Csomor
  5. // Modified by:
  6. // Created: 1998-01-01
  7. // Copyright: (c) Stefan Csomor
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MENU_H_
  11. #define _WX_MENU_H_
  12. class WXDLLIMPEXP_FWD_CORE wxFrame;
  13. #include "wx/arrstr.h"
  14. // ----------------------------------------------------------------------------
  15. // Menu
  16. // ----------------------------------------------------------------------------
  17. class WXDLLIMPEXP_FWD_CORE wxMenuImpl ;
  18. class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase
  19. {
  20. public:
  21. // ctors & dtor
  22. wxMenu(const wxString& title, long style = 0)
  23. : wxMenuBase(title, style) { Init(); }
  24. wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
  25. virtual ~wxMenu();
  26. virtual void Break();
  27. virtual void SetTitle(const wxString& title);
  28. bool ProcessCommand(wxCommandEvent& event);
  29. // get the menu handle
  30. WXHMENU GetHMenu() const ;
  31. // implementation only from now on
  32. // -------------------------------
  33. bool HandleCommandUpdateStatus( wxMenuItem* menuItem, wxWindow* senderWindow = NULL);
  34. bool HandleCommandProcess( wxMenuItem* menuItem, wxWindow* senderWindow = NULL);
  35. void HandleMenuItemHighlighted( wxMenuItem* menuItem );
  36. void HandleMenuOpened();
  37. void HandleMenuClosed();
  38. wxMenuImpl* GetPeer() { return m_peer; }
  39. // make sure we can veto
  40. void SetAllowRearrange( bool allow );
  41. bool AllowRearrange() const { return m_allowRearrange; }
  42. // if a menu is used purely for internal implementation reasons (eg wxChoice)
  43. // we don't want native menu events being triggered
  44. void SetNoEventsMode( bool noEvents );
  45. bool GetNoEventsMode() const { return m_noEventsMode; }
  46. protected:
  47. // hide special menu items like exit, preferences etc
  48. // that are expected in the app menu
  49. void DoRearrange() ;
  50. bool DoHandleMenuEvent( wxEvent& evt );
  51. virtual wxMenuItem* DoAppend(wxMenuItem *item);
  52. virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
  53. virtual wxMenuItem* DoRemove(wxMenuItem *item);
  54. private:
  55. // common part of all ctors
  56. void Init();
  57. // common part of Do{Append,Insert}(): behaves as Append if pos == -1
  58. bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
  59. // Common part of HandleMenu{Opened,Closed}().
  60. void DoHandleMenuOpenedOrClosed(wxEventType evtType);
  61. // if TRUE, insert a break before appending the next item
  62. bool m_doBreak;
  63. // in this menu rearranging of menu items (esp hiding) is allowed
  64. bool m_allowRearrange;
  65. // don't trigger native events
  66. bool m_noEventsMode;
  67. wxMenuImpl* m_peer;
  68. DECLARE_DYNAMIC_CLASS(wxMenu)
  69. };
  70. #if wxOSX_USE_COCOA_OR_CARBON
  71. // the iphone only has popup-menus
  72. // ----------------------------------------------------------------------------
  73. // Menu Bar (a la Windows)
  74. // ----------------------------------------------------------------------------
  75. class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
  76. {
  77. public:
  78. // ctors & dtor
  79. // default constructor
  80. wxMenuBar();
  81. // unused under MSW
  82. wxMenuBar(long style);
  83. // menubar takes ownership of the menus arrays but copies the titles
  84. wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
  85. virtual ~wxMenuBar();
  86. // menubar construction
  87. virtual bool Append( wxMenu *menu, const wxString &title );
  88. virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
  89. virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
  90. virtual wxMenu *Remove(size_t pos);
  91. virtual void EnableTop( size_t pos, bool flag );
  92. virtual bool IsEnabledTop(size_t pos) const;
  93. virtual void SetMenuLabel( size_t pos, const wxString& label );
  94. virtual wxString GetMenuLabel( size_t pos ) const;
  95. virtual bool Enable( bool enable = true );
  96. // for virtual function hiding
  97. virtual void Enable( int itemid, bool enable )
  98. {
  99. wxMenuBarBase::Enable( itemid, enable );
  100. }
  101. // implementation from now on
  102. void Detach();
  103. // returns TRUE if we're attached to a frame
  104. bool IsAttached() const { return m_menuBarFrame != NULL; }
  105. // get the frame we live in
  106. wxFrame *GetFrame() const { return m_menuBarFrame; }
  107. // attach to a frame
  108. void Attach(wxFrame *frame);
  109. // if the menubar is modified, the display is not updated automatically,
  110. // call this function to update it (m_menuBarFrame should be !NULL)
  111. void Refresh(bool eraseBackground = true, const wxRect *rect = NULL);
  112. #if wxABI_VERSION >= 30001
  113. wxMenu *OSXGetAppleMenu() const { return m_appleMenu; }
  114. #endif
  115. static void SetAutoWindowMenu( bool enable ) { s_macAutoWindowMenu = enable ; }
  116. static bool GetAutoWindowMenu() { return s_macAutoWindowMenu ; }
  117. void MacInstallMenuBar() ;
  118. static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
  119. static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; }
  120. static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; }
  121. static WXHMENU MacGetWindowMenuHMenu() { return s_macWindowMenuHandle ; }
  122. protected:
  123. // common part of all ctors
  124. void Init();
  125. static bool s_macAutoWindowMenu ;
  126. static WXHMENU s_macWindowMenuHandle ;
  127. private:
  128. static wxMenuBar* s_macInstalledMenuBar ;
  129. static wxMenuBar* s_macCommonMenuBar ;
  130. wxMenu* m_rootMenu;
  131. wxMenu* m_appleMenu;
  132. DECLARE_DYNAMIC_CLASS(wxMenuBar)
  133. };
  134. #endif
  135. #endif // _WX_MENU_H_