X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f752a2282fb36bb5e429c8c83e589b9ac66d7cb..e044f6001e70d815f72d3911ce6bd01255847ecd:/src/univ/menu.cpp diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index 1d819ad0fe..967fa78da4 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -326,9 +326,13 @@ void wxPopupMenuWindow::ChangeCurrent(wxMenuItemList::Node *node) { if ( node != m_nodeCurrent ) { - if ( m_nodeCurrent ) + wxMenuItemList::Node *nodeOldCurrent = m_nodeCurrent; + + m_nodeCurrent = node; + + if ( nodeOldCurrent ) { - wxMenuItem *item = m_nodeCurrent->GetData(); + wxMenuItem *item = nodeOldCurrent->GetData(); wxCHECK_RET( item, _T("no current item?") ); // if it was the currently opened menu, close it @@ -341,8 +345,6 @@ void wxPopupMenuWindow::ChangeCurrent(wxMenuItemList::Node *node) RefreshItem(item); } - m_nodeCurrent = node; - if ( m_nodeCurrent ) RefreshItem(m_nodeCurrent->GetData()); } @@ -1546,6 +1548,9 @@ void wxMenuBar::Attach(wxFrame *frame) SetCursor(wxCURSOR_ARROW); SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT)); + + // calculate and set our height (it won't be changed any more) + SetSize(-1, GetBestSize().y); } // remember the last frame which had us to avoid unnecessarily reparenting @@ -1682,6 +1687,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); @@ -1692,6 +1703,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)); } @@ -1760,6 +1777,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 = @@ -1838,7 +1856,11 @@ void wxMenuBar::DoSelectMenu(size_t pos) { wxCHECK_RET( pos < GetCount(), _T("invalid menu index in DoSelectMenu") ); - if ( m_current != -1 ) + int posOld = m_current; + + m_current = pos; + + if ( posOld != -1 ) { // close the previous menu if ( IsShowingMenu() ) @@ -1852,11 +1874,9 @@ void wxMenuBar::DoSelectMenu(size_t pos) m_shouldShowMenu = old; } - RefreshItem((size_t)m_current); + RefreshItem((size_t)posOld); } - m_current = pos; - RefreshItem(pos); } @@ -1976,8 +1996,24 @@ bool wxMenuBar::ProcessMouseEvent(const wxPoint& pt) void wxMenuBar::OnKeyDown(wxKeyEvent& event) { - // the current item must have been set before - wxCHECK_RET( m_current != -1, _T("where is current item?") ); + // ensure that we have a current item - we might not have it if we're + // given the focus with Alt or F10 press (and under GTK+ the menubar + // somehow gets the keyboard events even when it doesn't have focus...) + if ( m_current == -1 ) + { + if ( !HasCapture() ) + { + SelectMenu(0); + } + else // we do have capture + { + // we always maintain a valid current item while we're in modal + // state (i.e. have the capture) + wxFAIL_MSG( _T("how did we manage to lose current item?") ); + + return; + } + } int key = event.GetKeyCode(); @@ -2038,7 +2074,7 @@ void wxMenuBar::OnKeyDown(wxKeyEvent& event) } else // right { - if ( ++currentNew == (int)count ) + if ( ++currentNew == count ) currentNew = 0; } @@ -2226,10 +2262,6 @@ void wxMenuBar::PopupCurrentMenu(bool selectFirst) // 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); @@ -2263,13 +2295,15 @@ void wxMenuBar::OnDismissMenu(bool dismissMenuBar) void wxMenuBar::OnDismiss() { - ReleaseCapture(); + if ( GetCapture() ) + GetCapture()->ReleaseMouse(); if ( m_current != -1 ) { - RefreshItem((size_t)m_current); - + size_t current = m_current; m_current = -1; + + RefreshItem(current); } GiveAwayFocus();