X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fa7134b05abb0d8df4b800762aa9d040bfd689a4..092162bc12858d6912ea6d5371d271ceebd18c49:/include/wx/menu.h diff --git a/include/wx/menu.h b/include/wx/menu.h index 8cae2e1255..e4dedcf2dd 100644 --- a/include/wx/menu.h +++ b/include/wx/menu.h @@ -4,7 +4,6 @@ // Author: Vadim Zeitlin // Modified by: // Created: 26.10.99 -// RCS-ID: $Id$ // Copyright: (c) wxWidgets team // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -27,6 +26,7 @@ // included wx/menu.h #include "wx/menuitem.h" +class WXDLLIMPEXP_FWD_CORE wxFrame; class WXDLLIMPEXP_FWD_CORE wxMenu; class WXDLLIMPEXP_FWD_CORE wxMenuBarBase; class WXDLLIMPEXP_FWD_CORE wxMenuBar; @@ -248,16 +248,27 @@ public: // the title virtual void SetTitle(const wxString& title) { m_title = title; } - const wxString GetTitle() const { return m_title; } + const wxString& GetTitle() const { return m_title; } // event handler void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } wxEvtHandler *GetEventHandler() const { return m_eventHandler; } - // invoking window - void SetInvokingWindow(wxWindow *win) { m_invokingWindow = win; } + // Invoking window: this is set by wxWindow::PopupMenu() before showing a + // popup menu and reset after it's hidden. Notice that you probably want to + // use GetWindow() below instead of GetInvokingWindow() as the latter only + // returns non-NULL for the top level menus + // + // NB: avoid calling SetInvokingWindow() directly if possible, use + // wxMenuInvokingWindowSetter class below instead + void SetInvokingWindow(wxWindow *win); wxWindow *GetInvokingWindow() const { return m_invokingWindow; } + // the window associated with this menu: this is the invoking window for + // popup menus or the top level window to which the menu bar is attached + // for menus which are part of a menu bar + wxWindow *GetWindow() const; + // style long GetStyle() const { return m_style; } @@ -267,7 +278,7 @@ public: // Updates the UI for a menu and all submenus recursively. source is the // object that has the update event handlers defined for it. If NULL, the // menu or associated window will be used. - void UpdateUI(wxEvtHandler* source = (wxEvtHandler*)NULL); + void UpdateUI(wxEvtHandler* source = NULL); // get the menu bar this menu is attached to (may be NULL, always NULL for // popup menus). Traverse up the menu hierarchy to find it. @@ -377,9 +388,42 @@ protected: static bool ms_locked; - DECLARE_NO_COPY_CLASS(wxMenuBase) + wxDECLARE_NO_COPY_CLASS(wxMenuBase); +}; + +#if wxUSE_EXTENDED_RTTI + +// ---------------------------------------------------------------------------- +// XTI accessor +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxMenuInfoHelper : public wxObject +{ +public: + wxMenuInfoHelper() { m_menu = NULL; } + virtual ~wxMenuInfoHelper() { } + + bool Create( wxMenu *menu, const wxString &title ) + { + m_menu = menu; + m_title = title; + return true; + } + + wxMenu* GetMenu() const { return m_menu; } + wxString GetTitle() const { return m_title; } + +private: + wxMenu *m_menu; + wxString m_title; + + DECLARE_DYNAMIC_CLASS(wxMenuInfoHelper) }; +WX_DECLARE_EXPORTED_LIST(wxMenuInfoHelper, wxMenuInfoHelperList ); + +#endif + // ---------------------------------------------------------------------------- // wxMenuBar // ---------------------------------------------------------------------------- @@ -496,9 +540,18 @@ public: virtual bool CanBeOutsideClientArea() const { return true; } +#if wxUSE_EXTENDED_RTTI + // XTI helpers: + bool AppendMenuInfo( const wxMenuInfoHelper *info ) + { return Append( info->GetMenu(), info->GetTitle() ); } + const wxMenuInfoHelperList& GetMenuInfos() const; +#endif + #if WXWIN_COMPATIBILITY_2_8 // get or change the label of the menu at given position + // Deprecated in favour of SetMenuLabel wxDEPRECATED( void SetLabelTop(size_t pos, const wxString& label) ); + // Deprecated in favour of GetMenuLabelText wxDEPRECATED( wxString GetLabelTop(size_t pos) const ); #endif @@ -506,10 +559,15 @@ protected: // the list of all our menus wxMenuList m_menus; +#if wxUSE_EXTENDED_RTTI + // used by XTI + wxMenuInfoHelperList m_menuInfos; +#endif + // the frame we are attached to (may be NULL) wxFrame *m_menuBarFrame; - DECLARE_NO_COPY_CLASS(wxMenuBarBase) + wxDECLARE_NO_COPY_CLASS(wxMenuBarBase); }; // ---------------------------------------------------------------------------- @@ -521,8 +579,6 @@ protected: #else // !wxUSE_BASE_CLASSES_ONLY #if defined(__WXUNIVERSAL__) #include "wx/univ/menu.h" -#elif defined(__WXPALMOS__) - #include "wx/palmos/menu.h" #elif defined(__WXMSW__) #include "wx/msw/menu.h" #elif defined(__WXMOTIF__) @@ -532,7 +588,7 @@ protected: #elif defined(__WXGTK__) #include "wx/gtk1/menu.h" #elif defined(__WXMAC__) - #include "wx/mac/menu.h" + #include "wx/osx/menu.h" #elif defined(__WXCOCOA__) #include "wx/cocoa/menu.h" #elif defined(__WXPM__) @@ -540,7 +596,35 @@ protected: #endif #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY +// ---------------------------------------------------------------------------- +// Helper class used in the implementation only: sets the invoking window of +// the given menu in its ctor and resets it in dtor. +// ---------------------------------------------------------------------------- + +class wxMenuInvokingWindowSetter +{ +public: + // Ctor sets the invoking window for the given menu. + // + // The menu lifetime must be greater than that of this class. + wxMenuInvokingWindowSetter(wxMenu& menu, wxWindow *win) + : m_menu(menu) + { + menu.SetInvokingWindow(win); + } + + // Dtor resets the invoking window. + ~wxMenuInvokingWindowSetter() + { + m_menu.SetInvokingWindow(NULL); + } + +private: + wxMenu& m_menu; + + wxDECLARE_NO_COPY_CLASS(wxMenuInvokingWindowSetter); +}; + #endif // wxUSE_MENUS -#endif - // _WX_MENU_H_BASE_ +#endif // _WX_MENU_H_BASE_