Compare commits

...
2 changed files with 14 additions and 2 deletions
+13 -2
View File
@@ -17,6 +17,7 @@
BEGIN_EVENT_TABLE(SideButton, wxWindow)
EVT_LEFT_DOWN(SideButton::mouseDown)
EVT_LEFT_UP(SideButton::mouseReleased)
EVT_MOUSE_CAPTURE_LOST(SideButton::mouseCaptureLost)
EVT_PAINT(SideButton::paintEvent)
END_EVENT_TABLE()
@@ -331,20 +332,30 @@ void SideButton::mouseDown(wxMouseEvent& event)
event.Skip();
pressedDown = true;
SetFocus();
CaptureMouse();
// Capturing twice pushes this button onto the capture stack twice, and the
// release would then hand the capture straight back to it.
if (!HasCapture())
CaptureMouse();
}
void SideButton::mouseReleased(wxMouseEvent& event)
{
event.Skip();
// A press whose release went elsewhere still holds the capture.
if (HasCapture())
ReleaseMouse();
if (pressedDown) {
pressedDown = false;
ReleaseMouse();
if (wxRect({0, 0}, GetSize()).Contains(event.GetPosition()))
sendButtonEvent();
}
}
void SideButton::mouseCaptureLost(wxMouseCaptureLostEvent&)
{
pressedDown = false;
}
void SideButton::sendButtonEvent()
{
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
+1
View File
@@ -94,6 +94,7 @@ private:
void mouseDown(wxMouseEvent& event);
void mouseReleased(wxMouseEvent& event);
void mouseCaptureLost(wxMouseCaptureLostEvent& event);
void sendButtonEvent();