X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a756f210019dd5b51331b7181c816d3882146a30..d99937cdd8f235561c1f5358478878111826a317:/src/univ/menu.cpp?ds=sidebyside diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index ac728688b9..1a70ef1eb4 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,10 @@ wxPopupMenuWindow::wxPopupMenuWindow(wxWindow *parent, wxMenu *menu) SetCursor(wxCURSOR_ARROW); } +wxPopupMenuWindow::~wxPopupMenuWindow() +{ +} + // ---------------------------------------------------------------------------- // wxPopupMenuWindow current item/node handling // ---------------------------------------------------------------------------- @@ -352,14 +360,9 @@ void wxPopupMenuWindow::ChangeCurrent(wxMenuItemList::Node *node) wxMenuItemList::Node *wxPopupMenuWindow::GetPrevNode() const { - wxMenuItemList::Node *node = m_nodeCurrent; - if ( !node ) - { - // start from the end if no current item - node = m_menu->GetMenuItems().GetLast(); - } - - return GetPrevNode(node); + // return the last node if there had been no previously selected one + return m_nodeCurrent ? GetPrevNode(m_nodeCurrent) + : m_menu->GetMenuItems().GetLast(); } wxMenuItemList::Node * @@ -380,14 +383,9 @@ wxPopupMenuWindow::GetPrevNode(wxMenuItemList::Node *node) const wxMenuItemList::Node *wxPopupMenuWindow::GetNextNode() const { - wxMenuItemList::Node *node = m_nodeCurrent; - if ( !node ) - { - // start from the beginning if no current item - node = m_menu->GetMenuItems().GetFirst(); - } - - return GetNextNode(node); + // return the first node if there had been no previously selected one + return m_nodeCurrent ? GetNextNode(m_nodeCurrent) + : m_menu->GetMenuItems().GetFirst(); } wxMenuItemList::Node * @@ -672,7 +670,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)) ) { @@ -1164,6 +1162,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; @@ -1174,7 +1176,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; @@ -1251,7 +1253,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); } } } @@ -1269,7 +1273,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()); @@ -1321,7 +1325,7 @@ bool wxMenu::ClickItem(wxMenuItem *item) // not applicabled isChecked = -1; } - + return SendEvent(item->GetId(), isChecked); } @@ -1393,20 +1397,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; @@ -1426,10 +1420,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 */ @@ -1470,7 +1464,7 @@ void wxMenuItem::SetText(const wxString& text) void wxMenuItem::SetCheckable(bool checkable) { - if ( checkable != m_isCheckable ) + if ( checkable != IsCheckable() ) { wxMenuItemBase::SetCheckable(checkable); @@ -1520,6 +1514,8 @@ void wxMenuBar::Init() m_menuShown = NULL; m_shouldShowMenu = FALSE; + + m_windowStyle |= wxNO_FULL_REPAINT_ON_RESIZE; } void wxMenuBar::Attach(wxFrame *frame) @@ -1847,6 +1843,7 @@ int wxMenuBar::GetMenuFromPoint(const wxPoint& pos) const void wxMenuBar::SelectMenu(size_t pos) { SetFocus(); + wxLogTrace(_T("mousecapture"), _T("Capturing mouse from wxMenuBar::SelectMenu")); CaptureMouse(); DoSelectMenu(pos); @@ -1935,6 +1932,7 @@ void wxMenuBar::OnLeftDown(wxMouseEvent& event) } else // on item { + wxLogTrace(_T("mousecapture"), _T("Capturing mouse from wxMenuBar::OnLeftDown")); CaptureMouse(); // show it as selected @@ -2244,7 +2242,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; @@ -2296,7 +2294,10 @@ void wxMenuBar::OnDismissMenu(bool dismissMenuBar) void wxMenuBar::OnDismiss() { if ( GetCapture() ) + { + wxLogTrace(_T("mousecapture"), _T("Releasing mouse from wxMenuBar::OnDismiss")); GetCapture()->ReleaseMouse(); + } if ( m_current != -1 ) { @@ -2350,6 +2351,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 @@ -2384,7 +2388,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(); }