X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7edcafa467269b15e0e967e9fe9ee08c6696b8a7..b78a78f779b95dc46b66e07fddac87ffb0aed1dc:/src/univ/menu.cpp diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index c87393282d..62dc90a1c8 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -123,6 +123,8 @@ class wxPopupMenuWindow : public wxPopupTransientWindow { public: wxPopupMenuWindow(wxWindow *parent, wxMenu *menu); + + ~wxPopupMenuWindow(); // override the base class version to select the first item initially virtual void Popup(wxWindow *focus = NULL); @@ -255,6 +257,8 @@ public: } else { + // return FALSE; + return wxEvtHandler::ProcessEvent(event); } } @@ -308,6 +312,16 @@ wxPopupMenuWindow::wxPopupMenuWindow(wxWindow *parent, wxMenu *menu) SetCursor(wxCURSOR_ARROW); } +wxPopupMenuWindow::~wxPopupMenuWindow() +{ + // When m_popupMenu in wxMenu is deleted because it + // is a child of an old menu bar being deleted (note: it does + // not get destroyed by the wxMenu destructor, but + // by DestroyChildren()), m_popupMenu should be reset to NULL. + + m_menu->m_popupMenu = NULL; +} + // ---------------------------------------------------------------------------- // wxPopupMenuWindow current item/node handling // ---------------------------------------------------------------------------- @@ -662,7 +676,7 @@ bool wxPopupMenuWindow::ProcessLeftDown(wxMouseEvent& event) wxPopupMenuWindow *win = menu->m_popupMenu; wxCHECK_MSG( win, FALSE, _T("parent menu not shown?") ); - + pos = ClientToScreen(pos); if ( win->GetMenuItemFromPoint(win->ScreenToClient(pos)) ) { @@ -1154,6 +1168,10 @@ wxWindow *wxMenu::GetRootWindow() const wxMenu *menu = GetParent(); while ( menu ) { + // We are a submenu of a menu of a menubar + if (menu->GetMenuBar()) + return menu->GetMenuBar(); + win = menu->GetInvokingWindow(); if ( win ) break; @@ -1164,7 +1182,7 @@ wxWindow *wxMenu::GetRootWindow() const // we're probably going to crash in the caller anyhow, but try to detect // this error as soon as possible wxASSERT_MSG( win, _T("menu without any associated window?") ); - + // also remember it in this menu so that we don't have to search for it the // next time wxConstCast(this, wxMenu)->m_invokingWindow = win; @@ -1241,7 +1259,9 @@ void wxMenu::OnDismiss(bool dismissParent) wxCHECK_RET( m_invokingWindow, _T("what kind of menu is this?") ); m_invokingWindow->DismissPopupMenu(); - SetInvokingWindow(NULL); + + // Why reset it here? We need it for sending the event to... + // SetInvokingWindow(NULL); } } } @@ -1259,7 +1279,7 @@ void wxMenu::Popup(const wxPoint& pos, const wxSize& size, bool selectFirst) { m_popupMenu->SelectFirst(); } - + // the geometry might have changed since the last time we were shown, so // always resize m_popupMenu->SetClientSize(GetGeometryInfo().GetSize()); @@ -1311,7 +1331,7 @@ bool wxMenu::ClickItem(wxMenuItem *item) // not applicabled isChecked = -1; } - + return SendEvent(item->GetId(), isChecked); } @@ -1383,20 +1403,10 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, int id, const wxString& text, const wxString& help, - bool isCheckable, + wxItemKind kind, wxMenu *subMenu) + : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu) { - m_id = id; - m_parentMenu = parentMenu; - m_subMenu = subMenu; - - m_text = text; - m_help = help; - - m_isCheckable = isCheckable; - m_isEnabled = TRUE; - m_isChecked = FALSE; - m_posY = m_height = -1; @@ -1416,10 +1426,10 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, int id, const wxString& name, const wxString& help, - bool isCheckable, + wxItemKind kind, wxMenu *subMenu) { - return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu); + return new wxMenuItem(parentMenu, id, name, help, kind, subMenu); } /* static */ @@ -1460,7 +1470,7 @@ void wxMenuItem::SetText(const wxString& text) void wxMenuItem::SetCheckable(bool checkable) { - if ( checkable != m_isCheckable ) + if ( checkable != IsCheckable() ) { wxMenuItemBase::SetCheckable(checkable); @@ -1510,6 +1520,8 @@ void wxMenuBar::Init() m_menuShown = NULL; m_shouldShowMenu = FALSE; + + m_windowStyle |= wxNO_FULL_REPAINT_ON_RESIZE; } void wxMenuBar::Attach(wxFrame *frame) @@ -1837,7 +1849,7 @@ int wxMenuBar::GetMenuFromPoint(const wxPoint& pos) const void wxMenuBar::SelectMenu(size_t pos) { SetFocus(); - wxLogDebug("Capturing mouse from wxMenuBar::SelectMenu"); + wxLogTrace(_T("mousecapture"), _T("Capturing mouse from wxMenuBar::SelectMenu")); CaptureMouse(); DoSelectMenu(pos); @@ -1926,7 +1938,7 @@ void wxMenuBar::OnLeftDown(wxMouseEvent& event) } else // on item { - wxLogDebug("Capturing mouse from wxMenuBar::OnLeftDown"); + wxLogTrace(_T("mousecapture"), _T("Capturing mouse from wxMenuBar::OnLeftDown")); CaptureMouse(); // show it as selected @@ -2236,7 +2248,7 @@ void wxMenuBar::PopupCurrentMenu(bool selectFirst) wxCHECK_RET( m_current != -1, _T("no menu to popup") ); // forgot to call DismissMenu()? - wxASSERT_MSG( !m_menuShown, _T("shouldn't show two menu at once!") ); + wxASSERT_MSG( !m_menuShown, _T("shouldn't show two menus at once!") ); // in any case, we should show it - even if we won't m_shouldShowMenu = TRUE; @@ -2289,7 +2301,7 @@ void wxMenuBar::OnDismiss() { if ( GetCapture() ) { - wxLogDebug("Releasing mouse from wxMenuBar::OnDismiss"); + wxLogTrace(_T("mousecapture"), _T("Releasing mouse from wxMenuBar::OnDismiss")); GetCapture()->ReleaseMouse(); } @@ -2345,6 +2357,9 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) #endif // 0 menu->SetInvokingWindow(this); + + // wxLogDebug( "Name of invoking window %s", menu->GetInvokingWindow()->GetName().c_str() ); + menu->Popup(ClientToScreen(wxPoint(x, y)), wxSize(0, 0)); // this is not very useful if the menu was popped up because of the mouse @@ -2379,7 +2394,7 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) void wxWindow::DismissPopupMenu() { wxCHECK_RET( ms_evtLoopPopup, _T("no popup menu shown") ); - + ms_evtLoopPopup->Exit(); }