Complete wxEVT_MENU_{OPEN,CLOSE} implementation in wxMSW and wxOSX.

Set the wxMenu correctly for wxEVT_MENU_CLOSE events in wxMSW.

Set the menu id correctly to allow wxMenuEvent::IsPopup() to work for both
wxEVT_MENU_OPEN and wxEVT_MENU_CLOSE in wxOSX.

Closes #11313.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70151 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-12-28 13:51:17 +00:00
parent c2cd367f7d
commit 7f3f059ac5
6 changed files with 39 additions and 24 deletions

View File

@@ -468,6 +468,7 @@ MSW:
- Fixed regression with initial focus in the dialogs in 2.9.3. - Fixed regression with initial focus in the dialogs in 2.9.3.
- Added support for wxEXEC_MAKE_GROUP_LEADER to wxExecute (tteras). - Added support for wxEXEC_MAKE_GROUP_LEADER to wxExecute (tteras).
- Set wxMenu being closed in wxEVT_MENU_CLOSE events (Marcin Malich).
OSX: OSX:

View File

@@ -79,7 +79,6 @@ public:
bool HandleSize(int x, int y, WXUINT flag); bool HandleSize(int x, int y, WXUINT flag);
bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control); bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
bool HandleMenuSelect(WXWORD nItem, WXWORD nFlags, WXHMENU hMenu); bool HandleMenuSelect(WXWORD nItem, WXWORD nFlags, WXHMENU hMenu);
bool HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup);
// tooltip management // tooltip management
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
@@ -133,8 +132,8 @@ protected:
// wxMDIChildFrame // wxMDIChildFrame
bool MSWDoTranslateMessage(wxFrame *frame, WXMSG *msg); bool MSWDoTranslateMessage(wxFrame *frame, WXMSG *msg);
// handle WM_INITMENUPOPUP message to generate wxEVT_MENU_OPEN // handle WM_(UN)INITMENUPOPUP message to generate wxEVT_MENU_OPEN/CLOSE
bool HandleInitMenuPopup(WXHMENU hMenu); bool HandleMenuPopup(wxEventType evtType, WXHMENU hMenu);
virtual bool IsMDIChild() const { return false; } virtual bool IsMDIChild() const { return false; }

View File

@@ -83,6 +83,10 @@ private:
// terminate the current radio group, if any // terminate the current radio group, if any
void EndRadioGroup(); void EndRadioGroup();
// Common part of HandleMenu{Opened,Closed}().
void DoHandleMenuOpenedOrClosed(wxEventType evtType);
// if TRUE, insert a breal before appending the next item // if TRUE, insert a breal before appending the next item
bool m_doBreak; bool m_doBreak;

View File

@@ -3870,9 +3870,12 @@ public:
wxMenuEvent(wxEventType type = wxEVT_NULL, int id = 0, wxMenu* menu = NULL); wxMenuEvent(wxEventType type = wxEVT_NULL, int id = 0, wxMenu* menu = NULL);
/** /**
Returns the menu which is being opened or closed. This method should only be Returns the menu which is being opened or closed.
used with the @c OPEN and @c CLOSE events and even for them the
returned pointer may be @NULL in some ports. This method can only be used with the @c OPEN and @c CLOSE events.
The returned value is never @NULL in the ports implementing this
function, which currently includes all the major ones.
*/ */
wxMenu* GetMenu() const; wxMenu* GetMenu() const;

View File

@@ -61,9 +61,9 @@
// globals // globals
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if wxUSE_MENUS_NATIVE #if wxUSE_MENUS || wxUSE_MENUS_NATIVE
extern wxMenu *wxCurrentPopupMenu; extern wxMenu *wxCurrentPopupMenu;
#endif // wxUSE_MENUS_NATIVE #endif // wxUSE_MENUS || wxUSE_MENUS_NATIVE
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// event tables // event tables
@@ -849,25 +849,24 @@ wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu))
return false; return false;
} }
bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup) bool wxFrame::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu)
{ {
// we don't have the menu id here, so we use the id to specify if the event // we don't have the menu id here, so we use the id to specify if the event
// was from a popup menu or a normal one // was from a popup menu or a normal one
wxMenuEvent event(evtType, isPopup ? -1 : 0);
event.SetEventObject(this);
return HandleWindowEvent(event); int menuid = 0;
}
bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
{
wxMenu* menu = NULL; wxMenu* menu = NULL;
if (GetMenuBar()) if (GetMenuBar())
{ {
menu = GetMenuBar()->MSWGetMenu(hMenu); menu = GetMenuBar()->MSWGetMenu(hMenu);
} }
else if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu )
{
menu = wxCurrentPopupMenu;
menuid = wxID_ANY;
}
wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); wxMenuEvent event(evtType, menuid, menu);
event.SetEventObject(this); event.SetEventObject(this);
return HandleWindowEvent(event); return HandleWindowEvent(event);
@@ -917,7 +916,7 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
#if wxUSE_MENUS #if wxUSE_MENUS
case WM_INITMENUPOPUP: case WM_INITMENUPOPUP:
processed = HandleInitMenuPopup((WXHMENU) wParam); processed = HandleMenuPopup(wxEVT_MENU_OPEN, (WXHMENU)wParam);
break; break;
case WM_MENUSELECT: case WM_MENUSELECT:
@@ -930,8 +929,8 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
} }
break; break;
case WM_EXITMENULOOP: case WM_UNINITMENUPOPUP:
processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam); processed = HandleMenuPopup(wxEVT_MENU_CLOSE, (WXHMENU)wParam);
break; break;
#endif // wxUSE_MENUS #endif // wxUSE_MENUS

View File

@@ -452,16 +452,25 @@ void wxMenu::HandleMenuItemHighlighted( wxMenuItem* item )
DoHandleMenuEvent( wxevent ); DoHandleMenuEvent( wxevent );
} }
void wxMenu::DoHandleMenuOpenedOrClosed(wxEventType evtType)
{
// Popup menu being currently shown or NULL, defined in wincmn.cpp.
extern wxMenu *wxCurrentPopupMenu;
// Set the id to allow wxMenuEvent::IsPopup() to work correctly.
int menuid = this == wxCurrentPopupMenu ? wxID_ANY : 0;
wxMenuEvent wxevent(evtType, menuid, this);
DoHandleMenuEvent( wxevent );
}
void wxMenu::HandleMenuOpened() void wxMenu::HandleMenuOpened()
{ {
wxMenuEvent wxevent(wxEVT_MENU_OPEN, 0, this); DoHandleMenuOpenedOrClosed(wxEVT_MENU_OPEN);
DoHandleMenuEvent( wxevent );
} }
void wxMenu::HandleMenuClosed() void wxMenu::HandleMenuClosed()
{ {
wxMenuEvent wxevent(wxEVT_MENU_CLOSE, 0, this); DoHandleMenuOpenedOrClosed(wxEVT_MENU_CLOSE);
DoHandleMenuEvent( wxevent );
} }
bool wxMenu::DoHandleMenuEvent(wxEvent& wxevent) bool wxMenu::DoHandleMenuEvent(wxEvent& wxevent)