mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-10 14:46:24 +01:00
Split base class CellularPanel out of TrackPanel...
... To be reused with the Ruler too. The new base class does all the handling of hit tests on cells and managing of UIHandles, and keyboard events and focus. It has no knowledge of tracks -- that all resides in overriding functions in TrackPanel. Still to do, of course, is reorganizing drawing with callbacks to the cell objects.
This commit is contained in:
199
src/TrackPanel.h
199
src/TrackPanel.h
@@ -242,9 +242,126 @@ private:
|
||||
const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
|
||||
|
||||
|
||||
class AUDACITY_DLL_API TrackPanel final : public OverlayPanel {
|
||||
public:
|
||||
// This class manages a panel divided into a number of sub-rectangles called
|
||||
// cells, that each implement hit tests returning click-drag-release handler
|
||||
// objects, and other services.
|
||||
// It has no dependency on the Track class.
|
||||
class AUDACITY_DLL_API CellularPanel : public OverlayPanel {
|
||||
public:
|
||||
CellularPanel(wxWindow * parent, wxWindowID id,
|
||||
const wxPoint & pos,
|
||||
const wxSize & size,
|
||||
ViewInfo *viewInfo,
|
||||
// default as for wxPanel:
|
||||
long style = wxTAB_TRAVERSAL | wxNO_BORDER)
|
||||
: OverlayPanel(parent, id, pos, size, style)
|
||||
, mViewInfo( viewInfo )
|
||||
{}
|
||||
|
||||
// Overridables:
|
||||
|
||||
virtual AudacityProject *GetProject() const = 0;
|
||||
|
||||
// Find track info by coordinate
|
||||
struct FoundCell {
|
||||
std::shared_ptr<TrackPanelCell> pCell;
|
||||
wxRect rect;
|
||||
};
|
||||
virtual FoundCell FindCell(int mouseX, int mouseY) = 0;
|
||||
virtual TrackPanelCell *GetFocusedCell() = 0;
|
||||
virtual void SetFocusedCell() = 0;
|
||||
|
||||
virtual void ProcessUIHandleResult
|
||||
(TrackPanelCell *pClickedCell, TrackPanelCell *pLatestCell,
|
||||
unsigned refreshResult) = 0;
|
||||
|
||||
virtual void UpdateStatusMessage( const wxString & ) = 0;
|
||||
|
||||
public:
|
||||
UIHandlePtr Target()
|
||||
{
|
||||
if (mTargets.size())
|
||||
return mTargets[mTarget];
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
bool IsMouseCaptured();
|
||||
|
||||
wxCoord MostRecentXCoord() const { return mMouseMostRecentX; }
|
||||
|
||||
void HandleCursorForPresentMouseState(bool doHit = true);
|
||||
|
||||
protected:
|
||||
bool HasEscape();
|
||||
bool CancelDragging();
|
||||
void ClearTargets()
|
||||
{
|
||||
// Forget the rotation of hit test candidates when the mouse moves from
|
||||
// cell to cell or outside of the panel entirely.
|
||||
mLastCell.reset();
|
||||
mTargets.clear();
|
||||
mTarget = 0;
|
||||
mMouseOverUpdateFlags = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
bool HasRotation();
|
||||
bool ChangeTarget(bool forward, bool cycle);
|
||||
|
||||
void OnMouseEvent(wxMouseEvent & event);
|
||||
void OnCaptureLost(wxMouseCaptureLostEvent & event);
|
||||
void OnCaptureKey(wxCommandEvent & event);
|
||||
void OnKeyDown(wxKeyEvent & event);
|
||||
void OnChar(wxKeyEvent & event);
|
||||
void OnKeyUp(wxKeyEvent & event);
|
||||
|
||||
void OnSetFocus(wxFocusEvent & event);
|
||||
void OnKillFocus(wxFocusEvent & event);
|
||||
|
||||
void HandleInterruptedDrag();
|
||||
void Uncapture( wxMouseState *pState = nullptr );
|
||||
bool HandleEscapeKey(bool down);
|
||||
void UpdateMouseState(const wxMouseState &state);
|
||||
void HandleModifierKey();
|
||||
|
||||
void HandleClick( const TrackPanelMouseEvent &tpmEvent );
|
||||
void HandleWheelRotation( TrackPanelMouseEvent &tpmEvent );
|
||||
|
||||
void HandleMotion( wxMouseState &state, bool doHit = true );
|
||||
void HandleMotion
|
||||
( const TrackPanelMouseState &tpmState, bool doHit = true );
|
||||
|
||||
|
||||
protected:
|
||||
ViewInfo *mViewInfo;
|
||||
|
||||
private:
|
||||
UIHandlePtr mUIHandle;
|
||||
|
||||
std::weak_ptr<TrackPanelCell> mLastCell;
|
||||
std::vector<UIHandlePtr> mTargets;
|
||||
size_t mTarget {};
|
||||
unsigned mMouseOverUpdateFlags{};
|
||||
|
||||
protected:
|
||||
// To do: make a drawing method and make this private
|
||||
wxMouseState mLastMouseState;
|
||||
|
||||
private:
|
||||
int mMouseMostRecentX;
|
||||
int mMouseMostRecentY;
|
||||
|
||||
std::weak_ptr<TrackPanelCell> mpClickedCell;
|
||||
|
||||
bool mEnableTab{};
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class AUDACITY_DLL_API TrackPanel final : public CellularPanel {
|
||||
|
||||
public:
|
||||
TrackPanel(wxWindow * parent,
|
||||
wxWindowID id,
|
||||
const wxPoint & pos,
|
||||
@@ -263,14 +380,7 @@ class AUDACITY_DLL_API TrackPanel final : public OverlayPanel {
|
||||
|
||||
void OnPaint(wxPaintEvent & event);
|
||||
void OnMouseEvent(wxMouseEvent & event);
|
||||
void OnCaptureLost(wxMouseCaptureLostEvent & event);
|
||||
void OnCaptureKey(wxCommandEvent & event);
|
||||
void OnKeyDown(wxKeyEvent & event);
|
||||
void OnChar(wxKeyEvent & event);
|
||||
void OnKeyUp(wxKeyEvent & event);
|
||||
|
||||
void OnSetFocus(wxFocusEvent & event);
|
||||
void OnKillFocus(wxFocusEvent & event);
|
||||
|
||||
void OnContextMenu(wxContextMenuEvent & event);
|
||||
|
||||
@@ -302,31 +412,24 @@ class AUDACITY_DLL_API TrackPanel final : public OverlayPanel {
|
||||
// void SetSelectionFormat(int iformat)
|
||||
// void SetSnapTo(int snapto)
|
||||
|
||||
void HandleInterruptedDrag();
|
||||
void Uncapture( wxMouseState *pState = nullptr );
|
||||
bool CancelDragging();
|
||||
bool HandleEscapeKey(bool down);
|
||||
void UpdateMouseState(const wxMouseState &state);
|
||||
void HandleModifierKey();
|
||||
void HandlePageUpKey();
|
||||
void HandlePageDownKey();
|
||||
AudacityProject * GetProject() const;
|
||||
AudacityProject * GetProject() const override;
|
||||
|
||||
void ScrollIntoView(double pos);
|
||||
void ScrollIntoView(int x);
|
||||
|
||||
void OnTrackMenu(Track *t = NULL);
|
||||
Track * GetFirstSelectedTrack();
|
||||
bool IsMouseCaptured();
|
||||
|
||||
void EnsureVisible(Track * t);
|
||||
void VerticalScroll( float fracPosition);
|
||||
|
||||
TrackPanelCell *GetFocusedCell() override;
|
||||
void SetFocusedCell() override;
|
||||
Track *GetFocusedTrack();
|
||||
void SetFocusedTrack(Track *t);
|
||||
|
||||
void HandleCursorForPresentMouseState(bool doHit = true);
|
||||
|
||||
void UpdateVRulers();
|
||||
void UpdateVRuler(Track *t);
|
||||
void UpdateTrackVRuler(const Track *t);
|
||||
@@ -338,7 +441,6 @@ class AUDACITY_DLL_API TrackPanel final : public OverlayPanel {
|
||||
|
||||
protected:
|
||||
bool IsAudioActive();
|
||||
void HandleClick( const TrackPanelMouseEvent &tpmEvent );
|
||||
|
||||
public:
|
||||
size_t GetTrackCount() const;
|
||||
@@ -351,9 +453,6 @@ public:
|
||||
void UpdateAccessibility();
|
||||
void MessageForScreenReader(const wxString& message);
|
||||
|
||||
// MM: Handle mouse wheel rotation
|
||||
void HandleWheelRotation( TrackPanelMouseEvent &tpmEvent );
|
||||
|
||||
void MakeParentRedrawScrollbars();
|
||||
|
||||
// If label, rectangle includes track control panel only.
|
||||
@@ -366,15 +465,7 @@ protected:
|
||||
// a crash, as it can take many seconds for large (eg. 10 track-hours) projects
|
||||
|
||||
// Find track info by coordinate
|
||||
struct FoundCell {
|
||||
std::shared_ptr<TrackPanelCell> pCell;
|
||||
wxRect rect;
|
||||
};
|
||||
FoundCell FindCell(int mouseX, int mouseY);
|
||||
|
||||
void HandleMotion( wxMouseState &state, bool doHit = true );
|
||||
void HandleMotion
|
||||
( const TrackPanelMouseState &tpmState, bool doHit = true );
|
||||
FoundCell FindCell(int mouseX, int mouseY) override;
|
||||
|
||||
int GetVRulerWidth() const;
|
||||
int GetVRulerOffset() const { return mTrackInfo.GetTrackInfoWidth(); }
|
||||
@@ -447,7 +538,6 @@ protected:
|
||||
TrackPanelListener *mListener;
|
||||
|
||||
std::shared_ptr<TrackList> mTracks;
|
||||
ViewInfo *mViewInfo;
|
||||
|
||||
AdornedRulerPanel *mRuler;
|
||||
|
||||
@@ -481,11 +571,6 @@ protected:
|
||||
|
||||
bool mRedrawAfterStop;
|
||||
|
||||
wxMouseState mLastMouseState;
|
||||
|
||||
int mMouseMostRecentX;
|
||||
int mMouseMostRecentY;
|
||||
|
||||
friend class TrackPanelAx;
|
||||
|
||||
#if wxUSE_ACCESSIBILITY
|
||||
@@ -510,48 +595,16 @@ protected:
|
||||
wxSize vrulerSize;
|
||||
|
||||
protected:
|
||||
std::weak_ptr<TrackPanelCell> mLastCell;
|
||||
std::vector<UIHandlePtr> mTargets;
|
||||
size_t mTarget {};
|
||||
unsigned mMouseOverUpdateFlags{};
|
||||
|
||||
public:
|
||||
UIHandlePtr Target()
|
||||
{
|
||||
if (mTargets.size())
|
||||
return mTargets[mTarget];
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
protected:
|
||||
void ClearTargets()
|
||||
{
|
||||
// Forget the rotation of hit test candidates when the mouse moves from
|
||||
// cell to cell or outside of the TrackPanel entirely.
|
||||
mLastCell.reset();
|
||||
mTargets.clear();
|
||||
mTarget = 0;
|
||||
mMouseOverUpdateFlags = 0;
|
||||
}
|
||||
|
||||
bool HasRotation();
|
||||
bool HasEscape();
|
||||
|
||||
bool ChangeTarget(bool forward, bool cycle);
|
||||
|
||||
std::weak_ptr<TrackPanelCell> mpClickedCell;
|
||||
UIHandlePtr mUIHandle;
|
||||
|
||||
std::shared_ptr<TrackPanelCell> mpBackground;
|
||||
|
||||
bool mEnableTab{};
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
void ProcessUIHandleResult
|
||||
(TrackPanelCell *pClickedCell, TrackPanelCell *pLatestCell,
|
||||
unsigned refreshResult);
|
||||
unsigned refreshResult) override;
|
||||
|
||||
void UpdateStatusMessage( const wxString &status ) override;
|
||||
|
||||
// friending GetInfoCommand allow automation to get sizes of the
|
||||
// tracks, track control panel and such.
|
||||
|
||||
Reference in New Issue
Block a user