From 9739d9ee8090965862ba623b09a8fba731dc3d5c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 15 Nov 1999 14:04:06 +0000 Subject: [PATCH] wxMenu::callback stuff taken inside WXWIN_COMPATIBILITY_2 (everybody should be happy now) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4568 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/menu.h | 18 ++++++++++++++++++ src/common/menucmn.cpp | 3 +++ src/gtk/menu.cpp | 2 ++ src/gtk1/menu.cpp | 2 ++ src/motif/menu.cpp | 2 ++ src/msw/menu.cpp | 2 ++ 6 files changed, 29 insertions(+) diff --git a/include/wx/menu.h b/include/wx/menu.h index 8b9bccd5b8..e3521afa2c 100644 --- a/include/wx/menu.h +++ b/include/wx/menu.h @@ -35,6 +35,21 @@ class WXDLLEXPORT wxMenuItem; WX_DECLARE_LIST(wxMenu, wxMenuList); WX_DECLARE_LIST(wxMenuItem, wxMenuItemList); +// ---------------------------------------------------------------------------- +// conditional compilation +// ---------------------------------------------------------------------------- + +// having callbacks in menus is a wxWin 1.6x feature which should be replaced +// with event tables in wxWin 2.xx code - however provide it because many +// people like it a lot by default +#ifndef wxUSE_MENU_CALLBACK + #if WXWIN_COMPATIBILITY_2 + #define wxUSE_MENU_CALLBACK 1 + #else + #define wxUSE_MENU_CALLBACK 0 + #endif // WXWIN_COMPATIBILITY_2 +#endif // !defined(wxUSE_MENU_CALLBACK) + // ---------------------------------------------------------------------------- // wxMenu // ---------------------------------------------------------------------------- @@ -177,10 +192,13 @@ public: wxList& GetItems() const { return (wxList &)m_items; } #endif // WXWIN_COMPATIBILITY +#if wxUSE_MENU_CALLBACK // wxWin 1.6x compatible menu event handling wxFunction GetCallback() const { return m_callback; } void Callback(const wxFunction func) { m_callback = func; } + wxFunction m_callback; +#endif // wxUSE_MENU_CALLBACK // unlike FindItem(), this function doesn't recurse but only looks through // our direct children and also may return the index of the found child if diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 65459efdd3..5d91787665 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -125,7 +125,10 @@ void wxMenuBase::Init(long style) m_style = style; m_clientData = (void *)NULL; m_eventHandler = this; + +#if wxUSE_MENU_CALLBACK m_callback = (wxFunction) NULL; +#endif // wxUSE_MENU_CALLBACK } wxMenuBase::~wxMenuBase() diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index cc8b6b0e0c..750593b533 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -469,11 +469,13 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) event.SetEventObject( menu ); event.SetInt(id ); +#if wxUSE_MENU_CALLBACK if (menu->GetCallback()) { (void) (*(menu->GetCallback())) (*menu, event); return; } +#endif // wxUSE_MENU_CALLBACK if (menu->GetEventHandler()->ProcessEvent(event)) return; diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index cc8b6b0e0c..750593b533 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -469,11 +469,13 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) event.SetEventObject( menu ); event.SetInt(id ); +#if wxUSE_MENU_CALLBACK if (menu->GetCallback()) { (void) (*(menu->GetCallback())) (*menu, event); return; } +#endif // wxUSE_MENU_CALLBACK if (menu->GetEventHandler()->ProcessEvent(event)) return; diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index 30ca32e4cd..23b39e39ba 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -162,12 +162,14 @@ bool wxMenu::ProcessCommand(wxCommandEvent & event) { bool processed = FALSE; +#if wxUSE_MENU_CALLBACK // Try a callback if (m_callback) { (void) (*(m_callback)) (*this, event); processed = TRUE; } +#endif // wxUSE_MENU_CALLBACK // Try the menu's event handler if ( !processed && GetEventHandler()) diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 845c67a0b4..dc9f5dfba6 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -432,12 +432,14 @@ bool wxMenu::ProcessCommand(wxCommandEvent & event) { bool processed = FALSE; +#if wxUSE_MENU_CALLBACK // Try a callback if (m_callback) { (void)(*(m_callback))(*this, event); processed = TRUE; } +#endif // wxUSE_MENU_CALLBACK // Try the menu's event handler if ( !processed && GetEventHandler()) -- 2.45.2