]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed wxUniv menus under wxGTK
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 24 Sep 2001 18:46:54 +0000 (18:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 24 Sep 2001 18:46:54 +0000 (18:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11692 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/univ/menu.cpp
src/univ/winuniv.cpp

index 2bcfe84777a935b6f7d5b97af0c0d569395ad1bb..46c328ebcbe305816b0dba22a700496c3d665463 100644 (file)
@@ -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());
     }
@@ -1851,7 +1853,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() )
@@ -1865,11 +1871,9 @@ void wxMenuBar::DoSelectMenu(size_t pos)
             m_shouldShowMenu = old;
         }
 
-        RefreshItem((size_t)m_current);
+        RefreshItem((size_t)posOld);
     }
 
-    m_current = pos;
-
     RefreshItem(pos);
 }
 
@@ -1989,8 +1993,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();
 
@@ -2239,10 +2259,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);
@@ -2280,9 +2296,10 @@ void wxMenuBar::OnDismiss()
 
     if ( m_current != -1 )
     {
-        RefreshItem((size_t)m_current);
-
+        size_t current = m_current;
         m_current = -1;
+
+        RefreshItem(current);
     }
 
     GiveAwayFocus();
index 16eb13ae26faacf9867b4c6b061cb1f2bf4962f9..69e3c6cd2fd219cc1f4be0c322d196122dcc4cc7 100644 (file)
@@ -975,6 +975,8 @@ struct WXDLLEXPORT wxWindowNext
 
 void wxWindow::CaptureMouse()
 {
+    wxLogTrace(_T("mousecapture"), _T("CaptureMouse(0x%08x)"), this);
+
     wxWindow *winOld = GetCapture();
     if ( winOld )
     {
@@ -1002,6 +1004,10 @@ void wxWindow::ReleaseMouse()
         delete item;
     }
     //else: stack is empty, no previous capture
+
+    wxLogTrace(_T("mousecapture"),
+               _T("After ReleaseMouse() mouse is captured by 0x%08x"),
+               GetCapture());
 }
 
 // ----------------------------------------------------------------------------