1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-10 09:01:13 +02:00

Enable hit tests; let base class manage capture & release of mouse...

... also make popup menus at right up, not down, for consistency with other
popup menus in TrackPanel

Base class also does the event propagation "hack" for ScrubPoller
This commit is contained in:
Paul Licameli 2018-07-27 11:18:57 -04:00
parent a853b7a3b4
commit ce48ac6307

View File

@ -2159,7 +2159,8 @@ std::vector<UIHandlePtr> AdornedRulerPanel::QPCell::HitTest
std::vector<UIHandlePtr> results; std::vector<UIHandlePtr> results;
if (false) { // Disable mouse actions on Timeline while recording.
if (!mParent->mIsRecording) {
auto result = std::make_shared<QPHandle>( mParent ); auto result = std::make_shared<QPHandle>( mParent );
result = AssignUIHandlePtr( mHolder, result ); result = AssignUIHandlePtr( mHolder, result );
@ -2252,7 +2253,8 @@ std::vector<UIHandlePtr> AdornedRulerPanel::ScrubbingCell::HitTest
std::vector<UIHandlePtr> results; std::vector<UIHandlePtr> results;
if (false) { // Disable mouse actions on Timeline while recording.
if (!mParent->mIsRecording) {
auto result = std::make_shared<ScrubbingHandle>( mParent ); auto result = std::make_shared<ScrubbingHandle>( mParent );
result = AssignUIHandlePtr( mHolder, result ); result = AssignUIHandlePtr( mHolder, result );
@ -2327,8 +2329,6 @@ AdornedRulerPanel::AdornedRulerPanel(AudacityProject* project,
AdornedRulerPanel::~AdornedRulerPanel() AdornedRulerPanel::~AdornedRulerPanel()
{ {
if(HasCapture())
ReleaseMouse();
} }
#if 1 #if 1
@ -2550,18 +2550,21 @@ void AdornedRulerPanel::OnRecordStartStop(wxCommandEvent & evt)
if (evt.GetInt() != 0) if (evt.GetInt() != 0)
{ {
mIsRecording = true;
this->CellularPanel::CancelDragging();
this->CellularPanel::ClearTargets();
// Set cursor immediately because OnMouseEvents is not called // Set cursor immediately because OnMouseEvents is not called
// if recording is initiated by a modal window (Timer Record). // if recording is initiated by a modal window (Timer Record).
SetCursor(mCursorDefault); SetCursor(mCursorDefault);
mIsRecording = true;
UpdateButtonStates(); UpdateButtonStates();
// The quick play indicator is useless during recording // The quick play indicator is useless during recording
CallAfter( [this]{ DrawBothOverlays(); } ); CallAfter( [this]{ DrawBothOverlays(); } );
} }
else { else {
SetCursor(mCursorHand);
mIsRecording = false; mIsRecording = false;
SetCursor(mCursorHand);
UpdateButtonStates(); UpdateButtonStates();
} }
RegenerateTooltips(mPrevZone); RegenerateTooltips(mPrevZone);
@ -2691,12 +2694,8 @@ bool AdornedRulerPanel::IsWithinMarker(int mousePosX, double markerTime)
void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt) void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
{ {
// Disable mouse actions on Timeline while recording. // Will always fall through to base class handling
if (mIsRecording) { evt.Skip();
if (HasCapture())
ReleaseMouse();
return;
}
const auto position = evt.GetPosition(); const auto position = evt.GetPosition();
@ -2736,47 +2735,6 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
mPrevZone = zone; mPrevZone = zone;
auto &scrubber = mProject->GetScrubber(); auto &scrubber = mProject->GetScrubber();
if (scrubber.HasMark()) {
if (evt.RightDown() )
// Fall through to context menu handling
;
else if ( evt.LeftUp() && inScrubZone)
// Fall through to seeking changes to scrubbing
;
// else if ( evt.LeftDown() && inScrubZone)
// // Fall through to ready to seek
// ;
else {
bool switchToQP = (zone == StatusChoice::EnteringQP && mQuickPlayEnabled);
if (switchToQP && evt.LeftDown()) {
// We can't stop scrubbing yet (see comments in Bug 1391), but we can pause it.
mProject->OnPause(*mProject);
// Don't return, fall through
}
else if (scrubber.IsPaused())
// Just fall through
;
else {
// If already clicked for scrub, preempt the usual event handling,
// no matter what the y coordinate.
// Do this hack so scrubber can detect mouse drags anywhere
evt.ResumePropagation(wxEVENT_PROPAGATE_MAX);
//if (scrubber.IsScrubbing())
evt.Skip();
//else
//evt.Skip();
// Don't do this, it slows down drag-scrub on Mac.
// Timer updates of display elsewhere make it unnecessary.
// Done here, it's too frequent.
// DrawBothOverlays();
return;
}
}
}
// Store the initial play region state // Store the initial play region state
if(mMouseEventState == mesNone) { if(mMouseEventState == mesNone) {
@ -2808,14 +2766,16 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
return; return;
} }
auto clicked = mQPCell->Clicked();
// Handle popup menus // Handle popup menus
if (!HasCapture() && evt.RightDown() && !(evt.LeftIsDown())) { if (evt.RightUp() && !(evt.LeftIsDown())) {
ShowContextMenu ShowContextMenu
(inScrubZone ? MenuChoice::Scrub : MenuChoice::QuickPlay, (inScrubZone ? MenuChoice::Scrub : MenuChoice::QuickPlay,
&position); &position);
return; return;
} }
else if( !HasCapture() && evt.LeftUp() && inScrubZone ) { else if( !clicked && evt.LeftUp() && inScrubZone ) {
if( scrubber.IsOneShotSeeking() ){ if( scrubber.IsOneShotSeeking() ){
scrubber.mInOneShotMode = false; scrubber.mInOneShotMode = false;
return; return;
@ -2828,9 +2788,9 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
DrawBothOverlays(); DrawBothOverlays();
return; return;
} }
else if ( !HasCapture() && inScrubZone) { else if ( !clicked && inScrubZone) {
// mouse going down => we are (probably) seeking // mouse going down => we are (probably) seeking
if (evt.LeftDown()) { if (evt.LeftDown() && !scrubber.HasMark()) {
//wxLogDebug("down"); //wxLogDebug("down");
scrubber.mInOneShotMode = !scrubber.IsScrubbing(); scrubber.mInOneShotMode = !scrubber.IsScrubbing();
scrubber.MarkScrubStart(evt.m_x, scrubber.MarkScrubStart(evt.m_x,
@ -2865,11 +2825,11 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
DrawBothOverlays(); DrawBothOverlays();
} }
} }
else if (evt.LeftIsDown() && HasCapture()) { else if (evt.LeftIsDown() && clicked) {
HandleQPDrag(evt, mousePosX); HandleQPDrag(evt, mousePosX);
DrawBothOverlays(); DrawBothOverlays();
} }
else if (evt.LeftUp() && HasCapture()) { else if (evt.LeftUp() && clicked) {
HandleQPRelease(evt); HandleQPRelease(evt);
DrawBothOverlays(); DrawBothOverlays();
} }
@ -2883,7 +2843,17 @@ auto AdornedRulerPanel::QPHandle::Click
{ {
auto result = CommonRulerHandle::Click(event, pProject); auto result = CommonRulerHandle::Click(event, pProject);
if (!( result & RefreshCode::Cancelled )) { if (!( result & RefreshCode::Cancelled )) {
if (mClicked == Button::Left) {
auto &scrubber = pProject->GetScrubber();
if(scrubber.HasMark()) {
// We can't stop scrubbing yet (see comments in Bug 1391),
// but we can pause it.
pProject->OnPause( *pProject );
}
}
} }
return result; return result;
} }
@ -2924,8 +2894,6 @@ void AdornedRulerPanel::HandleQPClick(wxMouseEvent &evt, wxCoord mousePosX)
// Check if we are dragging BEFORE CaptureMouse. // Check if we are dragging BEFORE CaptureMouse.
if (mMouseEventState != mesNone) if (mMouseEventState != mesNone)
SetCursor(mCursorSizeWE); SetCursor(mCursorSizeWE);
if ( !HasCapture() )
CaptureMouse();
} }
auto AdornedRulerPanel::QPHandle::Drag auto AdornedRulerPanel::QPHandle::Drag
@ -3043,9 +3011,7 @@ auto AdornedRulerPanel::QPHandle::Release
void AdornedRulerPanel::HandleQPRelease(wxMouseEvent &evt) void AdornedRulerPanel::HandleQPRelease(wxMouseEvent &evt)
{ {
if (HasCapture()) if (!mQPCell->Clicked())
ReleaseMouse();
else
return; return;
if (mPlayRegionEnd < mPlayRegionStart) { if (mPlayRegionEnd < mPlayRegionStart) {
@ -3488,9 +3454,6 @@ void AdornedRulerPanel::ShowContextMenu( MenuChoice choice, const wxPoint *pPosi
// dismiss and clear Quick-Play indicator // dismiss and clear Quick-Play indicator
mPrevZone = StatusChoice::Leaving; mPrevZone = StatusChoice::Leaving;
DrawBothOverlays(); DrawBothOverlays();
if (HasCapture())
ReleaseMouse();
} }
void AdornedRulerPanel::DoDrawBackground(wxDC * dc) void AdornedRulerPanel::DoDrawBackground(wxDC * dc)