X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1e6feb95a79834836e88143b15d9f424ebe79621..bcd3d8d9e26e41615d26d457ba0e2b84b80a0356:/src/univ/menu.cpp diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index 0c9f850aa5..2bcfe84777 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -5,7 +5,7 @@ // Modified by: // Created: 25.08.00 // RCS-ID: $Id$ -// Copyright: (c) 2000 Vadim Zeitlin +// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// @@ -41,6 +41,8 @@ #include "wx/popupwin.h" #include "wx/evtloop.h" +#include "wx/dcclient.h" +#include "wx/frame.h" #include "wx/univ/renderer.h" @@ -599,10 +601,12 @@ void wxPopupMenuWindow::ClickItem(wxMenuItem *item) wxASSERT_MSG( !item->IsSeparator() && !item->IsSubMenu(), _T("can't click this item") ); - m_menu->ClickItem(item); + wxMenu* menu = m_menu; // close all menus DismissAndNotify(); + + menu->ClickItem(item); } void wxPopupMenuWindow::OpenSubmenu(wxMenuItem *item, InputMethod how) @@ -1678,6 +1682,12 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const void wxMenuBar::RefreshAllItemsAfter(size_t pos) { + if ( !IsCreated() ) + { + // no need to refresh if nothing is shown yet + return; + } + wxRect rect = GetItemRect(pos); rect.width = GetClientSize().x - rect.x; RefreshRect(rect); @@ -1688,6 +1698,12 @@ void wxMenuBar::RefreshItem(size_t pos) wxCHECK_RET( pos != (size_t)-1, _T("invalid item in wxMenuBar::RefreshItem") ); + if ( !IsCreated() ) + { + // no need to refresh if nothing is shown yet + return; + } + RefreshRect(GetItemRect(pos)); } @@ -1756,6 +1772,7 @@ void wxMenuBar::DoDraw(wxControlRenderer *renderer) wxRect wxMenuBar::GetItemRect(size_t pos) const { wxASSERT_MSG( pos < GetCount(), _T("invalid menu bar item index") ); + wxASSERT_MSG( IsCreated(), _T("can't call this method yet") ); wxRect rect; rect.x = @@ -1961,7 +1978,7 @@ bool wxMenuBar::ProcessMouseEvent(const wxPoint& pt) // show the menu if we know that we should, even if we hadn't been showing // it before (this may happen if the previous menu was disabled) - if ( m_shouldShowMenu ) + if ( m_shouldShowMenu && !m_menuShown) { // open the new menu if the old one we closed had been opened PopupCurrentMenu(FALSE /* don't select first item - as Windows does */); @@ -2034,7 +2051,7 @@ void wxMenuBar::OnKeyDown(wxKeyEvent& event) } else // right { - if ( ++currentNew == (int)count ) + if ( ++currentNew == count ) currentNew = 0; } @@ -2221,6 +2238,11 @@ void wxMenuBar::PopupCurrentMenu(bool selectFirst) // that we pass 0 as width to position the menu exactly below the // item, not to the right of it wxRect rectItem = GetItemRect(m_current); + + // Release mouse, because the menu will get the capture. + if (HasCapture()) + ReleaseMouse(); + m_menuShown->Popup(ClientToScreen(rectItem.GetPosition()), wxSize(0, rectItem.GetHeight()), selectFirst); @@ -2254,7 +2276,7 @@ void wxMenuBar::OnDismissMenu(bool dismissMenuBar) void wxMenuBar::OnDismiss() { - ReleaseCapture(); + ReleaseMouse(); if ( m_current != -1 ) {