From 92f1a59c288e0e181d2998a93220a73b89f675df Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sat, 12 Jul 2003 23:09:04 +0000 Subject: [PATCH] Use WM_INITMENUPOPUP Added wxMenu member to wxMenuEvent git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21930 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/event.h | 12 ++++--- include/wx/frame.h | 5 +-- include/wx/msw/frame.h | 10 ++++-- include/wx/platform.h | 3 +- src/common/framecmn.cpp | 12 ++++--- src/gtk/menu.cpp | 2 +- src/gtk1/menu.cpp | 2 +- src/msw/frame.cpp | 72 ++++++++++++++++++++++++++++------------- 8 files changed, 79 insertions(+), 39 deletions(-) diff --git a/include/wx/event.h b/include/wx/event.h index c881a924f2..809db844b7 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -1184,12 +1184,12 @@ private: class WXDLLIMPEXP_CORE wxMenuEvent : public wxEvent { public: - wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0) + wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0, wxMenu* menu = NULL) : wxEvent(winid, type) - { m_menuId = winid; } + { m_menuId = winid; m_menu = NULL; } wxMenuEvent(const wxMenuEvent & event) : wxEvent(event) - { m_menuId = event.m_menuId; } + { m_menuId = event.m_menuId; m_menu = event.m_menu; } // only for wxEVT_MENU_HIGHLIGHT int GetMenuId() const { return m_menuId; } @@ -1197,10 +1197,14 @@ public: // only for wxEVT_MENU_OPEN/CLOSE bool IsPopup() const { return m_menuId == -1; } + // only for wxEVT_MENU_OPEN/CLOSE + wxMenu* GetMenu() const { return m_menu; } + virtual wxEvent *Clone() const { return new wxMenuEvent(*this); } private: - int m_menuId; + int m_menuId; + wxMenu* m_menu; DECLARE_DYNAMIC_CLASS(wxMenuEvent) }; diff --git a/include/wx/frame.h b/include/wx/frame.h index be765cc7e7..9c8aa12b15 100644 --- a/include/wx/frame.h +++ b/include/wx/frame.h @@ -146,8 +146,9 @@ public: void OnMenuHighlight(wxMenuEvent& event); #if wxUSE_MENUS - // send wxUpdateUIEvents for all menu items (called from OnIdle()) - void DoMenuUpdates(); + // send wxUpdateUIEvents for all menu items in the menubar, + // or just for menu if non-NULL + void DoMenuUpdates(wxMenu* menu = NULL); #endif // wxUSE_MENUS // do the UI update processing for this window diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index 4b27759ebf..b90e37d8b0 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -102,6 +102,12 @@ public: // current size - this has an effect of refreshing the window layout virtual void SendSizeEvent(); +#ifdef __WXWINCE__ + WXHWND GetCommandBar() { return m_commandBar; } + WXHWND CreateCommandBar() ; + void RemoveCommandBar() ; +#endif + protected: // common part of all ctors void Init(); @@ -128,8 +134,8 @@ protected: // window proc for the frames long MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - // handle WM_INITMENU message - bool HandleInitMenu(); + // handle WM_INITMENUPOPUP message + bool HandleInitMenuPopup(WXHMENU hMenu); virtual bool IsMDIChild() const { return FALSE; } diff --git a/include/wx/platform.h b/include/wx/platform.h index b874db6b36..e2782e7d55 100644 --- a/include/wx/platform.h +++ b/include/wx/platform.h @@ -332,8 +332,7 @@ * Presently, only Windows and GTK+ support wxEVT_MENU_OPEN. */ #ifndef wxUSE_IDLEMENUUPDATES - #if (defined(__WXMSW__) && !defined(__WXWINCE)) ||\ - defined(__WXGTK__) + #if defined(__WXMSW__) || defined(__WXGTK__) #define wxUSE_IDLEMENUUPDATES 0 #else #define wxUSE_IDLEMENUUPDATES 1 diff --git a/src/common/framecmn.cpp b/src/common/framecmn.cpp index 3641dec49e..e4456b0da6 100644 --- a/src/common/framecmn.cpp +++ b/src/common/framecmn.cpp @@ -256,10 +256,10 @@ void wxFrameBase::OnInternalIdle() #endif } -void wxFrameBase::OnMenuOpen(wxMenuEvent& WXUNUSED(event)) +void wxFrameBase::OnMenuOpen(wxMenuEvent& event) { #if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES - DoMenuUpdates(); + DoMenuUpdates(event.GetMenu()); #endif } @@ -421,13 +421,15 @@ wxToolBar* wxFrameBase::OnCreateToolBar(long style, #if wxUSE_MENUS // update all menus -void wxFrameBase::DoMenuUpdates() +void wxFrameBase::DoMenuUpdates(wxMenu* menu) { + wxEvtHandler* source = GetEventHandler(); wxMenuBar* bar = GetMenuBar(); - if ( bar != NULL ) + if (menu) + menu->UpdateUI(source); + else if ( bar != NULL ) { - wxEvtHandler* source = GetEventHandler(); int nCount = bar->GetMenuCount(); for (int n = 0; n < nCount; n++) bar->GetMenu(n)->UpdateUI(source); diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index c3593081d8..a44c91e123 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -169,7 +169,7 @@ static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu ) { if (g_isIdle) wxapp_install_idle_handler(); - wxMenuEvent event( wxEVT_MENU_OPEN, -1 ); + wxMenuEvent event( wxEVT_MENU_OPEN, -1, menu ); event.SetEventObject( menu ); wxEvtHandler* handler = menu->GetEventHandler(); diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index c3593081d8..a44c91e123 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -169,7 +169,7 @@ static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu ) { if (g_isIdle) wxapp_install_idle_handler(); - wxMenuEvent event( wxEVT_MENU_OPEN, -1 ); + wxMenuEvent event( wxEVT_MENU_OPEN, -1, menu ); event.SetEventObject( menu ); wxEvtHandler* handler = menu->GetEventHandler(); diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index 89e9716b0b..f2dff269be 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -141,11 +141,7 @@ wxFrame::~wxFrame() m_isBeingDeleted = TRUE; DeleteAllBars(); #ifdef __WXWINCE__ - if (m_commandBar) - { - ::DestroyWindow((HWND) m_commandBar); - m_commandBar = NULL; - } + RemoveCommandBar(); #endif } @@ -300,16 +296,9 @@ void wxFrame::InternalSetMenuBar() #ifdef __WXMICROWIN__ // Nothing #elif defined(__WXWINCE__) - if (!m_commandBar) - { - // TODO: eventually have a wxCommandBar class - m_commandBar = (WXHWND) CommandBar_Create(wxGetInstance(), GetHwnd(), NewControlId()); - if (!m_commandBar) - { - wxFAIL_MSG( _T("failed to create commandbar") ); - return; - } - } + + CreateCommandBar() ; + if (m_commandBar) { if (!CommandBar_InsertMenubarEx((HWND) m_commandBar, NULL, @@ -802,6 +791,10 @@ long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) processed = HandlePaint(); break; + case WM_INITMENUPOPUP: + processed = HandleInitMenuPopup((WXHMENU) wParam); + break; + #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) case WM_MENUSELECT: { @@ -813,10 +806,6 @@ long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) } break; - case WM_INITMENU: - processed = HandleInitMenu(); - break; - case WM_EXITMENULOOP: processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam); break; @@ -839,13 +828,52 @@ long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) return rc; } -// handle WM_INITMENU message -bool wxFrame::HandleInitMenu() +// handle WM_INITMENUPOPUP message +bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu) { - wxMenuEvent event(wxEVT_MENU_OPEN, 0); + wxMenu* menu = NULL; + if (GetMenuBar()) + { + int nCount = GetMenuBar()->GetMenuCount(); + for (int n = 0; n < nCount; n++) + { + if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu) + { + menu = GetMenuBar()->GetMenu(n); + break; + } + } + } + + wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); event.SetEventObject(this); return GetEventHandler()->ProcessEvent(event); } +#ifdef __WXWINCE__ +WXHWND wxFrame::CreateCommandBar() +{ + if (m_commandBar) + return m_commandBar; + + m_commandBar = (WXHWND) CommandBar_Create(wxGetInstance(), GetHwnd(), NewControlId()); + if (!m_commandBar) + { + wxFAIL_MSG( _T("failed to create commandbar") ); + return 0; + } + return m_commandBar; +} + +void wxFrame::RemoveCommandBar() +{ + if (m_commandBar) + { + ::DestroyWindow((HWND) m_commandBar); + m_commandBar = NULL; + } +} +#endif + -- 2.45.2