From d76777bef72aa8fe80d8381c9868e7f51c98909d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 29 Jul 2018 16:53:11 -0400 Subject: [PATCH] Each cell can define cursor, status, and tooltip in default of hit tests --- src/TrackPanel.cpp | 25 ++++++++++++++++++++++++- src/TrackPanelCell.h | 6 ++++++ src/tracks/ui/CommonTrackPanelCell.cpp | 7 +++++++ src/tracks/ui/CommonTrackPanelCell.h | 4 ++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index d18e473f4..5a5359312 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -937,8 +937,21 @@ void TrackPanel::HandleMotion refreshCode |= code; mMouseOverUpdateFlags |= code; } + if (newCell && + (!pCursor || status.empty() || tooltip.empty())) { + // Defaulting of cursor, tooltip, and status if there is no handle, + // or if the handle does not specify them + const auto preview = newCell->DefaultPreview( tpmState, GetProject() ); + if (!pCursor) + pCursor = preview.cursor; + if (status.empty()) + status = preview.message; + if (tooltip.empty()) + tooltip = preview.tooltip; + } if (!pCursor) { - static wxCursor defaultCursor{ wxCURSOR_ARROW }; + // Ultimate default cursor + static wxCursor defaultCursor{ wxCURSOR_DEFAULT }; pCursor = &defaultCursor; } @@ -946,11 +959,15 @@ void TrackPanel::HandleMotion /* i18n-hint Esc is a key on the keyboard */ status += wxT(" "), status += _("(Esc to cancel)"); mListener->TP_DisplayStatusMessage(status); + +#if wxUSE_TOOLTIPS if (tooltip != GetToolTipText()) { // Unset first, by analogy with AButton UnsetToolTip(); SetToolTip(tooltip); } +#endif + if (pCursor) SetCursor( *pCursor ); @@ -3531,6 +3548,12 @@ TrackPanelCell::~TrackPanelCell() { } +HitTestPreview TrackPanelCell::DefaultPreview +(const TrackPanelMouseState &, const AudacityProject *) +{ + return {}; +} + unsigned TrackPanelCell::HandleWheelRotation (const TrackPanelMouseEvent &, AudacityProject *) { diff --git a/src/TrackPanelCell.h b/src/TrackPanelCell.h index 74b96e78d..c5bf1ddd1 100644 --- a/src/TrackPanelCell.h +++ b/src/TrackPanelCell.h @@ -14,6 +14,7 @@ Paul Licameli #include "MemoryX.h" class AudacityProject; +struct HitTestPreview; struct TrackPanelMouseEvent; struct TrackPanelMouseState; class ViewInfo; @@ -34,6 +35,11 @@ class AUDACITY_DLL_API TrackPanelCell /* not final */ public: virtual ~TrackPanelCell () = 0; + // May supply default cursor, status message, and tooltip, when there is no + // handle to hit at the mouse position, or the handle does not supply them. + virtual HitTestPreview DefaultPreview + (const TrackPanelMouseState &state, const AudacityProject *pProject); + // Return pointers to objects that can be queried for a status // bar message and cursor appropriate to the point, and that dispatch // mouse button events. diff --git a/src/tracks/ui/CommonTrackPanelCell.cpp b/src/tracks/ui/CommonTrackPanelCell.cpp index 0a06188b4..45cf92253 100644 --- a/src/tracks/ui/CommonTrackPanelCell.cpp +++ b/src/tracks/ui/CommonTrackPanelCell.cpp @@ -24,6 +24,13 @@ CommonTrackPanelCell::~CommonTrackPanelCell() { } +HitTestPreview CommonTrackPanelCell::DefaultPreview +(const TrackPanelMouseState &, const AudacityProject *) +{ + static wxCursor defaultCursor{ wxCURSOR_ARROW }; + return { {}, &defaultCursor, {} }; +} + unsigned CommonTrackPanelCell::HandleWheelRotation (const TrackPanelMouseEvent &evt, AudacityProject *pProject) { diff --git a/src/tracks/ui/CommonTrackPanelCell.h b/src/tracks/ui/CommonTrackPanelCell.h index 0f92f2bfc..b90819fbd 100644 --- a/src/tracks/ui/CommonTrackPanelCell.h +++ b/src/tracks/ui/CommonTrackPanelCell.h @@ -27,6 +27,10 @@ public: virtual ~CommonTrackPanelCell() = 0; + // Default to the arrow cursor + HitTestPreview DefaultPreview + (const TrackPanelMouseState &, const AudacityProject *) override; + virtual std::shared_ptr FindTrack() = 0; protected: