diff --git a/include/wx/mac/menu.h b/include/wx/mac/menu.h index 6ed7985df9..6c39c96fc0 100644 --- a/include/wx/mac/menu.h +++ b/include/wx/mac/menu.h @@ -162,6 +162,11 @@ public: // attach to a frame void Attach(wxFrame *frame); + // clear the invoking window for all menus and submenus + void UnsetInvokingWindow() ; + + // set the invoking window for all menus and submenus + void SetInvokingWindow( wxFrame* frame ) ; #if wxUSE_ACCEL // get the accel table for all the menus const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; } diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 58ee010fa4..c10922c3a9 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -2330,13 +2330,16 @@ void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum ) { item->Check( !item->IsChecked() ) ; } - + + menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; + /* wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ; wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, id ); event.m_timeStamp = ((EventRecord*) MacGetCurrentEvent())->when ; event.SetEventObject(menu); event.SetInt(item->IsCheckable() ? item->IsChecked() : -1); frontwindow->GetEventHandler()->ProcessEvent(event); + */ } HiliteMenu(0); } diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 58ee010fa4..c10922c3a9 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -2330,13 +2330,16 @@ void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum ) { item->Check( !item->IsChecked() ) ; } - + + menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; + /* wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ; wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, id ); event.m_timeStamp = ((EventRecord*) MacGetCurrentEvent())->when ; event.SetEventObject(menu); event.SetInt(item->IsCheckable() ? item->IsChecked() : -1); frontwindow->GetEventHandler()->ProcessEvent(event); + */ } HiliteMenu(0); } diff --git a/src/mac/carbon/frame.cpp b/src/mac/carbon/frame.cpp index 09544ddd4d..7f1860a837 100644 --- a/src/mac/carbon/frame.cpp +++ b/src/mac/carbon/frame.cpp @@ -240,6 +240,26 @@ void wxFrame::OnActivate(wxActivateEvent& event) } } +void wxFrame::DetachMenuBar() +{ + if ( m_frameMenuBar ) + { + m_frameMenuBar->UnsetInvokingWindow(); + } + + wxFrameBase::DetachMenuBar(); +} + +void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) +{ + wxFrameBase::AttachMenuBar(menuBar); + + if (m_frameMenuBar) + { + m_frameMenuBar->SetInvokingWindow( this ); + } +} + void wxFrame::DoGetClientSize(int *x, int *y) const { wxWindow::DoGetClientSize( x , y ) ; diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index 0ded39739c..0e62af9b77 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -864,6 +864,56 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title) return TRUE; } +static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) +{ + menu->SetInvokingWindow( (wxWindow*) NULL ); + + wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); + while (node) + { + wxMenuItem *menuitem = node->GetData(); + if (menuitem->IsSubMenu()) + wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu() ); + node = node->GetNext(); + } +} + +static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) +{ + menu->SetInvokingWindow( win ); + + wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); + while (node) + { + wxMenuItem *menuitem = node->GetData(); + if (menuitem->IsSubMenu()) + wxMenubarSetInvokingWindow( menuitem->GetSubMenu() , win ); + node = node->GetNext(); + } +} + +void wxMenuBar::UnsetInvokingWindow() +{ + wxMenuList::Node *node = m_menus.GetFirst(); + while (node) + { + wxMenu *menu = node->GetData(); + wxMenubarUnsetInvokingWindow( menu ); + node = node->GetNext(); + } +} + +void wxMenuBar::SetInvokingWindow(wxFrame *frame) +{ + wxMenuList::Node *node = m_menus.GetFirst(); + while (node) + { + wxMenu *menu = node->GetData(); + wxMenubarSetInvokingWindow( menu, frame ); + node = node->GetNext(); + } +} + void wxMenuBar::Detach() { wxMenuBarBase::Detach() ; @@ -872,7 +922,6 @@ void wxMenuBar::Detach() void wxMenuBar::Attach(wxFrame *frame) { wxMenuBarBase::Attach( frame ) ; - #if wxUSE_ACCEL RebuildAccelTable(); #endif // wxUSE_ACCEL diff --git a/src/mac/frame.cpp b/src/mac/frame.cpp index 09544ddd4d..7f1860a837 100644 --- a/src/mac/frame.cpp +++ b/src/mac/frame.cpp @@ -240,6 +240,26 @@ void wxFrame::OnActivate(wxActivateEvent& event) } } +void wxFrame::DetachMenuBar() +{ + if ( m_frameMenuBar ) + { + m_frameMenuBar->UnsetInvokingWindow(); + } + + wxFrameBase::DetachMenuBar(); +} + +void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) +{ + wxFrameBase::AttachMenuBar(menuBar); + + if (m_frameMenuBar) + { + m_frameMenuBar->SetInvokingWindow( this ); + } +} + void wxFrame::DoGetClientSize(int *x, int *y) const { wxWindow::DoGetClientSize( x , y ) ; diff --git a/src/mac/menu.cpp b/src/mac/menu.cpp index 0ded39739c..0e62af9b77 100644 --- a/src/mac/menu.cpp +++ b/src/mac/menu.cpp @@ -864,6 +864,56 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title) return TRUE; } +static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) +{ + menu->SetInvokingWindow( (wxWindow*) NULL ); + + wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); + while (node) + { + wxMenuItem *menuitem = node->GetData(); + if (menuitem->IsSubMenu()) + wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu() ); + node = node->GetNext(); + } +} + +static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) +{ + menu->SetInvokingWindow( win ); + + wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); + while (node) + { + wxMenuItem *menuitem = node->GetData(); + if (menuitem->IsSubMenu()) + wxMenubarSetInvokingWindow( menuitem->GetSubMenu() , win ); + node = node->GetNext(); + } +} + +void wxMenuBar::UnsetInvokingWindow() +{ + wxMenuList::Node *node = m_menus.GetFirst(); + while (node) + { + wxMenu *menu = node->GetData(); + wxMenubarUnsetInvokingWindow( menu ); + node = node->GetNext(); + } +} + +void wxMenuBar::SetInvokingWindow(wxFrame *frame) +{ + wxMenuList::Node *node = m_menus.GetFirst(); + while (node) + { + wxMenu *menu = node->GetData(); + wxMenubarSetInvokingWindow( menu, frame ); + node = node->GetNext(); + } +} + void wxMenuBar::Detach() { wxMenuBarBase::Detach() ; @@ -872,7 +922,6 @@ void wxMenuBar::Detach() void wxMenuBar::Attach(wxFrame *frame) { wxMenuBarBase::Attach( frame ) ; - #if wxUSE_ACCEL RebuildAccelTable(); #endif // wxUSE_ACCEL