Remove unnecessary duplicate code dealing with invoking window from wxOSX.
This is roughly the same as r64127 for wxGTK but for wxOSX: don't duplicate the functionality already present in the base class in Mac-specific way. Just use wxMenu::GetWindow() instead of painstakingly propagating invoking window changes via the entire menu hierarchy. Also attach the root menu used in wxOSX to the menu bar to ensure that the correct window can be found for all its menus. Closes #11990. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64136 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -41,10 +41,6 @@ public:
|
||||
|
||||
bool ProcessCommand(wxCommandEvent& event);
|
||||
|
||||
// semi-private accessors
|
||||
|
||||
// get the window which contains this menu
|
||||
wxWindow *GetWindow() const;
|
||||
// get the menu handle
|
||||
WXHMENU GetHMenu() const ;
|
||||
|
||||
@@ -155,12 +151,6 @@ 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 the menubar is modified, the display is not updated automatically,
|
||||
// call this function to update it (m_menuBarFrame should be !NULL)
|
||||
void Refresh(bool eraseBackground = true, const wxRect *rect = NULL);
|
||||
@@ -178,7 +168,6 @@ public:
|
||||
protected:
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
wxWindow *m_invokingWindow;
|
||||
|
||||
wxArrayString m_titles;
|
||||
static bool s_macAutoWindowMenu ;
|
||||
|
@@ -231,9 +231,6 @@ void wxFrame::HandleResized( double timestampsec )
|
||||
#if wxUSE_MENUS
|
||||
void wxFrame::DetachMenuBar()
|
||||
{
|
||||
if ( m_frameMenuBar )
|
||||
m_frameMenuBar->UnsetInvokingWindow();
|
||||
|
||||
wxFrameBase::DetachMenuBar();
|
||||
}
|
||||
|
||||
@@ -257,7 +254,6 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
|
||||
|
||||
if (m_frameMenuBar)
|
||||
{
|
||||
m_frameMenuBar->SetInvokingWindow( this );
|
||||
if (makeCurrent)
|
||||
m_frameMenuBar->MacInstallMenuBar();
|
||||
}
|
||||
|
@@ -52,8 +52,6 @@ static const int idMenuTitle = -3;
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) ;
|
||||
static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win );
|
||||
|
||||
// Menus
|
||||
|
||||
@@ -266,7 +264,7 @@ bool wxMenu::ProcessCommand(wxCommandEvent & event)
|
||||
|
||||
// Try the window the menu was popped up from
|
||||
// (and up through the hierarchy)
|
||||
wxWindow *win = GetInvokingWindow();
|
||||
wxWindow *win = GetWindow();
|
||||
if ( !processed && win )
|
||||
processed = win->HandleWindowEvent(event);
|
||||
|
||||
@@ -277,16 +275,6 @@ bool wxMenu::ProcessCommand(wxCommandEvent & event)
|
||||
// other
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
wxWindow *wxMenu::GetWindow() const
|
||||
{
|
||||
if ( m_invokingWindow != NULL )
|
||||
return m_invokingWindow;
|
||||
else if ( GetMenuBar() != NULL)
|
||||
return (wxWindow *) GetMenuBar()->GetFrame();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// MacOS needs to know about submenus somewhere within this menu
|
||||
// before it can be displayed, also hide special menu items
|
||||
// like preferences that are handled by the OS
|
||||
@@ -381,18 +369,9 @@ bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow
|
||||
// (and up through the hierarchy)
|
||||
if ( !processed )
|
||||
{
|
||||
const wxMenuBase *menu = this;
|
||||
while ( menu )
|
||||
{
|
||||
wxWindow *win = menu->GetInvokingWindow();
|
||||
wxWindow *win = GetWindow();
|
||||
if ( win )
|
||||
{
|
||||
processed = win->HandleWindowEvent(event);
|
||||
break;
|
||||
}
|
||||
|
||||
menu = menu->GetParent();
|
||||
}
|
||||
}
|
||||
|
||||
if ( !processed && senderWindow != NULL)
|
||||
@@ -493,7 +472,7 @@ bool wxMenu::DoHandleMenuEvent(wxEvent& wxevent)
|
||||
}
|
||||
else
|
||||
{
|
||||
wxWindow *win = GetInvokingWindow();
|
||||
wxWindow *win = GetWindow();
|
||||
if (win)
|
||||
{
|
||||
if ( win->HandleWindowEvent(wxevent) )
|
||||
@@ -531,8 +510,9 @@ void wxMenuBar::Init()
|
||||
{
|
||||
m_eventHandler = this;
|
||||
m_menuBarFrame = NULL;
|
||||
m_invokingWindow = NULL;
|
||||
m_rootMenu = new wxMenu();
|
||||
m_rootMenu->Attach(this);
|
||||
|
||||
m_appleMenu = new wxMenu();
|
||||
m_appleMenu->SetAllowRearrange(false);
|
||||
m_appleMenu->Append( wxApp::s_macAboutMenuItemId, "About..." );
|
||||
@@ -865,9 +845,6 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
|
||||
m_rootMenu->Remove(item);
|
||||
m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
|
||||
|
||||
if (m_invokingWindow)
|
||||
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
|
||||
|
||||
return menuOld;
|
||||
}
|
||||
|
||||
@@ -880,9 +857,6 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
|
||||
|
||||
m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
|
||||
|
||||
if (m_invokingWindow)
|
||||
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -912,79 +886,9 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
|
||||
|
||||
m_rootMenu->AppendSubMenu(menu, title);
|
||||
|
||||
// m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
|
||||
// adding menu later on.
|
||||
if (m_invokingWindow)
|
||||
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void wxMenubarUnsetInvokingWindow( wxMenu *menu )
|
||||
{
|
||||
menu->SetInvokingWindow( NULL );
|
||||
wxMenuItemList::compatibility_iterator 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 );
|
||||
wxMenuItem *menuitem;
|
||||
wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
|
||||
|
||||
while (node)
|
||||
{
|
||||
menuitem = node->GetData();
|
||||
if (menuitem->IsSubMenu())
|
||||
wxMenubarSetInvokingWindow( menuitem->GetSubMenu() , win );
|
||||
|
||||
node = node->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
void wxMenuBar::UnsetInvokingWindow()
|
||||
{
|
||||
m_invokingWindow = NULL;
|
||||
wxMenubarUnsetInvokingWindow(m_appleMenu);
|
||||
|
||||
wxMenu *menu;
|
||||
wxMenuList::compatibility_iterator node = m_menus.GetFirst();
|
||||
|
||||
while (node)
|
||||
{
|
||||
menu = node->GetData();
|
||||
wxMenubarUnsetInvokingWindow( menu );
|
||||
|
||||
node = node->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
void wxMenuBar::SetInvokingWindow(wxFrame *frame)
|
||||
{
|
||||
m_invokingWindow = frame;
|
||||
wxMenubarSetInvokingWindow(m_appleMenu, frame);
|
||||
|
||||
wxMenu *menu;
|
||||
wxMenuList::compatibility_iterator node = m_menus.GetFirst();
|
||||
|
||||
while (node)
|
||||
{
|
||||
menu = node->GetData();
|
||||
wxMenubarSetInvokingWindow( menu, frame );
|
||||
|
||||
node = node->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
void wxMenuBar::Detach()
|
||||
{
|
||||
wxMenuBarBase::Detach() ;
|
||||
|
Reference in New Issue
Block a user