X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e3f5caa223f582b3a4bf375e200de7fb216b568f..438959cca892a7651634cc3a7aad4819ac49b23c:/include/wx/menu.h?ds=sidebyside diff --git a/include/wx/menu.h b/include/wx/menu.h index 1a5ef27737..f392729270 100644 --- a/include/wx/menu.h +++ b/include/wx/menu.h @@ -27,6 +27,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; @@ -255,11 +256,19 @@ public: wxEvtHandler *GetEventHandler() const { return m_eventHandler; } // Invoking window: this is set by wxWindow::PopupMenu() before showing a - // popup menu and reset after it's hidden. Notice that GetInvokingWindow() - // recurses upwards and will return the invoking window for any submenu of - // a popup menu as well as the menu itself. + // 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; + 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; } @@ -383,6 +392,39 @@ protected: 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 // ---------------------------------------------------------------------------- @@ -499,6 +541,13 @@ 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 @@ -511,6 +560,11 @@ 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; @@ -526,8 +580,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__) @@ -545,7 +597,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_