Fix handling mouse capture
This commit is contained in:
@@ -190,6 +190,7 @@ protected:
|
|||||||
void OnMouseMove(wxMouseEvent& event);
|
void OnMouseMove(wxMouseEvent& event);
|
||||||
void OnKeyDown(wxKeyEvent& event);
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
void OnKillFocus(wxFocusEvent& event);
|
void OnKillFocus(wxFocusEvent& event);
|
||||||
|
void OnCaptureLost(wxMouseCaptureLostEvent& event);
|
||||||
|
|
||||||
// process the mouse move event, return true if we did, false to continue
|
// process the mouse move event, return true if we did, false to continue
|
||||||
// processing as usual
|
// processing as usual
|
||||||
|
@@ -180,10 +180,11 @@ protected:
|
|||||||
virtual void DoDraw(wxControlRenderer *renderer);
|
virtual void DoDraw(wxControlRenderer *renderer);
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
void OnLeftUp(wxMouseEvent& event);
|
void OnLeftDown(wxMouseEvent& event);
|
||||||
void OnMouseMove(wxMouseEvent& event);
|
void OnMouseMove(wxMouseEvent& event);
|
||||||
void OnMouseLeave(wxMouseEvent& event);
|
void OnMouseLeave(wxMouseEvent& event);
|
||||||
void OnKeyDown(wxKeyEvent& event);
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
|
void OnCaptureLost(wxMouseCaptureLostEvent& event);
|
||||||
|
|
||||||
// reset the current item and node
|
// reset the current item and node
|
||||||
void ResetCurrent();
|
void ResetCurrent();
|
||||||
@@ -280,9 +281,10 @@ private:
|
|||||||
wxBEGIN_EVENT_TABLE(wxPopupMenuWindow, wxPopupTransientWindow)
|
wxBEGIN_EVENT_TABLE(wxPopupMenuWindow, wxPopupTransientWindow)
|
||||||
EVT_KEY_DOWN(wxPopupMenuWindow::OnKeyDown)
|
EVT_KEY_DOWN(wxPopupMenuWindow::OnKeyDown)
|
||||||
|
|
||||||
EVT_LEFT_UP(wxPopupMenuWindow::OnLeftUp)
|
EVT_LEFT_DOWN(wxPopupMenuWindow::OnLeftDown)
|
||||||
EVT_MOTION(wxPopupMenuWindow::OnMouseMove)
|
EVT_MOTION(wxPopupMenuWindow::OnMouseMove)
|
||||||
EVT_LEAVE_WINDOW(wxPopupMenuWindow::OnMouseLeave)
|
EVT_LEAVE_WINDOW(wxPopupMenuWindow::OnMouseLeave)
|
||||||
|
EVT_MOUSE_CAPTURE_LOST(wxPopupMenuWindow::OnCaptureLost)
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
EVT_IDLE(wxPopupMenuWindow::OnIdle)
|
EVT_IDLE(wxPopupMenuWindow::OnIdle)
|
||||||
#endif
|
#endif
|
||||||
@@ -290,11 +292,10 @@ wxEND_EVENT_TABLE()
|
|||||||
|
|
||||||
wxBEGIN_EVENT_TABLE(wxMenuBar, wxMenuBarBase)
|
wxBEGIN_EVENT_TABLE(wxMenuBar, wxMenuBarBase)
|
||||||
EVT_KILL_FOCUS(wxMenuBar::OnKillFocus)
|
EVT_KILL_FOCUS(wxMenuBar::OnKillFocus)
|
||||||
|
|
||||||
EVT_KEY_DOWN(wxMenuBar::OnKeyDown)
|
EVT_KEY_DOWN(wxMenuBar::OnKeyDown)
|
||||||
|
|
||||||
EVT_LEFT_DOWN(wxMenuBar::OnLeftDown)
|
EVT_LEFT_DOWN(wxMenuBar::OnLeftDown)
|
||||||
EVT_MOTION(wxMenuBar::OnMouseMove)
|
EVT_MOTION(wxMenuBar::OnMouseMove)
|
||||||
|
EVT_MOUSE_CAPTURE_LOST(wxMenuBar::OnCaptureLost)
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -471,6 +472,9 @@ void wxPopupMenuWindow::Dismiss()
|
|||||||
OnSubmenuDismiss( false );
|
OnSubmenuDismiss( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( HasCapture() )
|
||||||
|
ReleaseMouse();
|
||||||
|
|
||||||
wxPopupTransientWindow::Dismiss();
|
wxPopupTransientWindow::Dismiss();
|
||||||
|
|
||||||
ResetCurrent();
|
ResetCurrent();
|
||||||
@@ -717,13 +721,21 @@ bool wxPopupMenuWindow::ProcessLeftDown(wxMouseEvent& event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxPopupMenuWindow::OnLeftUp(wxMouseEvent& event)
|
void wxPopupMenuWindow::OnLeftDown(wxMouseEvent& event)
|
||||||
{
|
{
|
||||||
wxMenuItemIter node = GetMenuItemFromPoint(event.GetPosition());
|
wxMenuItemIter node = GetMenuItemFromPoint(event.GetPosition());
|
||||||
if ( node )
|
if ( node )
|
||||||
{
|
{
|
||||||
ActivateItem(node->GetData(), WithMouse);
|
ActivateItem(node->GetData(), WithMouse);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxMenuBar* menubar = m_menu->GetMenuBar();
|
||||||
|
if ( menubar && !ProcessLeftDown(event) )
|
||||||
|
{
|
||||||
|
menubar->ProcessEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxPopupMenuWindow::OnMouseMove(wxMouseEvent& event)
|
void wxPopupMenuWindow::OnMouseMove(wxMouseEvent& event)
|
||||||
@@ -1041,6 +1053,11 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key)
|
|||||||
return processed;
|
return processed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxPopupMenuWindow::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
DismissAndNotify();
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxMenu
|
// wxMenu
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -2104,8 +2121,10 @@ void wxMenuBar::OnLeftDown(wxMouseEvent& event)
|
|||||||
{
|
{
|
||||||
if ( HasCapture() )
|
if ( HasCapture() )
|
||||||
{
|
{
|
||||||
OnDismiss();
|
if ( IsShowingMenu() )
|
||||||
|
{
|
||||||
|
DismissMenu();
|
||||||
|
}
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
else // we didn't have mouse capture, capture it now
|
else // we didn't have mouse capture, capture it now
|
||||||
@@ -2113,9 +2132,8 @@ void wxMenuBar::OnLeftDown(wxMouseEvent& event)
|
|||||||
m_current = GetMenuFromPoint(event.GetPosition());
|
m_current = GetMenuFromPoint(event.GetPosition());
|
||||||
if ( m_current == -1 )
|
if ( m_current == -1 )
|
||||||
{
|
{
|
||||||
// unfortunately, we can't prevent wxMSW from giving us the focus,
|
DismissMenu(); // event outside menubar - dismiss
|
||||||
// so we can only give it back
|
ReleaseMouseCapture(); // we could get capture back from popup window so release it
|
||||||
GiveAwayFocus();
|
|
||||||
}
|
}
|
||||||
else // on item
|
else // on item
|
||||||
{
|
{
|
||||||
@@ -2314,6 +2332,11 @@ void wxMenuBar::OnKeyDown(wxKeyEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxMenuBar::OnCaptureLost(wxMouseCaptureLostEvent& event)
|
||||||
|
{
|
||||||
|
DismissMenu();
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxMenuBar accel handling
|
// wxMenuBar accel handling
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user