/**********************************************************************
Audacity: A Digital Audio Editor
TrackPanel.cpp
Dominic Mazzoni
and lots of other contributors
Implements TrackPanel and TrackInfo.
********************************************************************//*!
\todo
Refactoring of the TrackPanel, possibly as described
in \ref TrackPanelRefactor
*//*****************************************************************//*!
\file TrackPanel.cpp
\brief
Implements TrackPanel and TrackInfo.
TrackPanel.cpp is currently some of the worst code in Audacity.
It's not really unreadable, there's just way too much stuff in this
one file. Rather than apply a quick fix, the long-term plan
is to create a GUITrack class that knows how to draw itself
and handle events. Then this class just helps coordinate
between tracks.
Plans under discussion are described in \ref TrackPanelRefactor
*//********************************************************************/
// Documentation: Rather than have a lengthy \todo section, having
// a \todo a \file and a \page in EXACTLY that order gets Doxygen to
// put the following lengthy description of refactoring on a NEW page
// and link to it from the docs.
/*****************************************************************//**
\class TrackPanel
\brief
The TrackPanel class coordinates updates and operations on the
main part of the screen which contains multiple tracks.
It uses many other classes, but in particular it uses the
TrackInfo class to draw the controls area on the left of a track,
and the TrackArtist class to draw the actual waveforms.
Note that in some of the older code here, e.g., GetLabelWidth(),
"Label" means the TrackInfo plus the vertical ruler.
Confusing relative to LabelTrack labels.
The TrackPanel manages multiple tracks and their TrackInfos.
Note that with stereo tracks there will be one TrackInfo
being used by two wavetracks.
*//*****************************************************************//**
\class TrackInfo
\brief
The TrackInfo is shown to the side of a track
It has the menus, pan and gain controls displayed in it.
So "Info" is somewhat a misnomer. Should possibly be "TrackControls".
TrackPanel and not TrackInfo takes care of the functionality for
each of the buttons in that panel.
In its current implementation TrackInfo is not derived from a
wxWindow. Following the original coding style, it has
been coded as a 'flyweight' class, which is passed
state as needed, except for the array of gains and pans.
If we'd instead coded it as a wxWindow, we would have an instance
of this class for each instance displayed.
*//**************************************************************//**
\class TrackPanelListener
\brief A now badly named class which is used to give access to a
subset of the TrackPanel methods from all over the place.
*//**************************************************************//**
\class TrackList
\brief A list of TrackListNode items.
*//**************************************************************//**
\class TrackListIterator
\brief An iterator for a TrackList.
*//**************************************************************//**
\class TrackListNode
\brief Used by TrackList, points to a Track.
*//**************************************************************//**
\class TrackPanel::AudacityTimer
\brief Timer class dedicated to infomring the TrackPanel that it
is time to refresh some aspect of the screen.
*//*****************************************************************//**
\page TrackPanelRefactor Track Panel Refactor
\brief Planned refactoring of TrackPanel.cpp
- Move menus from current TrackPanel into TrackInfo.
- Convert TrackInfo from 'flyweight' to heavyweight.
- Split GuiStereoTrack and GuiWaveTrack out from TrackPanel.
JKC: Incremental refactoring started April/2003
Possibly aiming for Gui classes something like this - it's under
discussion:
+----------------------------------------------------+
| AdornedRulerPanel |
+----------------------------------------------------+
+----------------------------------------------------+
|+------------+ +-----------------------------------+|
|| | | (L) GuiWaveTrack ||
|| TrackInfo | +-----------------------------------+|
|| | +-----------------------------------+|
|| | | (R) GuiWaveTrack ||
|+------------+ +-----------------------------------+|
+-------- GuiStereoTrack ----------------------------+
+----------------------------------------------------+
|+------------+ +-----------------------------------+|
|| | | (L) GuiWaveTrack ||
|| TrackInfo | +-----------------------------------+|
|| | +-----------------------------------+|
|| | | (R) GuiWaveTrack ||
|+------------+ +-----------------------------------+|
+-------- GuiStereoTrack ----------------------------+
With the whole lot sitting in a TrackPanel which forwards
events to the sub objects.
The GuiStereoTrack class will do the special logic for
Stereo channel grouping.
The precise names of the classes are subject to revision.
Have deliberately not created NEW files for the NEW classes
such as AdornedRulerPanel and TrackInfo - yet.
*//*****************************************************************/
#include "Audacity.h"
#include "Experimental.h"
#include "TrackPanel.h"
#include "Project.h"
#include "TrackPanelCellIterator.h"
#include "TrackPanelMouseEvent.h"
#include "TrackPanelResizeHandle.h"
//#define DEBUG_DRAW_TIMING 1
#include "AColor.h"
#include "AllThemeResources.h"
#include "AudioIO.h"
#include "float_cast.h"
#include "Prefs.h"
#include "RefreshCode.h"
#include "TrackArtist.h"
#include "TrackPanelAx.h"
#include "UIHandle.h"
#include "HitTestResult.h"
#include "WaveTrack.h"
#ifdef EXPERIMENTAL_MIDI_OUT
#include "NoteTrack.h"
#endif
#include "toolbars/ControlToolBar.h"
#include "toolbars/ToolsToolBar.h"
//This loads the appropriate set of cursors, depending on platform.
#include "../images/Cursors.h"
#include "widgets/ASlider.h"
#include "widgets/Ruler.h"
#include
DEFINE_EVENT_TYPE(EVT_TRACK_PANEL_TIMER)
/*
This is a diagram of TrackPanel's division of one (non-stereo) track rectangle.
Total height equals Track::GetHeight()'s value. Total width is the wxWindow's width.
Each charater that is not . represents one pixel.
Inset space of this track, and top inset of the next track, are used to draw the focus highlight.
Top inset of the right channel of a stereo track, and bottom shadow line of the
left channel, are used for the channel separator.
"Margin" is a term used for inset plus border (top and left) or inset plus
shadow plus border (right and bottom).
TrackInfo::GetTrackInfoWidth() == GetVRulerOffset()
counts columns from the left edge up to and including controls, and is a constant.
GetVRulerWidth() is variable -- all tracks have the same ruler width at any time,
but that width may be adjusted when tracks change their vertical scales.
GetLabelWidth() counts columns up to and including the VRuler.
GetLeftOffset() is yet one more -- it counts the "one pixel" column.
FindCell() for label returns a rectangle that OMITS left, top, and bottom
margins
FindCell() for vruler returns a rectangle right of the label,
up to and including the One Pixel column, and OMITS top and bottom margins
FindCell() for track returns a rectangle with x == GetLeftOffset(), and OMITS
right top, and bottom margins
+--------------- ... ------ ... --------------------- ... ... -------------+
| Top Inset |
| |
| +------------ ... ------ ... --------------------- ... ... ----------+ |
| L|+-Border---- ... ------ ... --------------------- ... ... -Border-+ |R |
| e||+---------- ... -++--- ... -+++----------------- ... ... -------+| |i |
| f|B| || ||| |BS|g |
| t|o| Controls || V |O| The good stuff |oh|h |
| |r| || R |n| |ra|t |
| I|d| || u |e| |dd| |
| n|e| || l | | |eo|I |
| s|r| || e |P| |rw|n |
| e||| || r |i| ||||s |
| t||| || |x| ||||e |
| ||| || |e| ||||t |
| ||| || |l| |||| |
| ||| || ||| |||| |
. ... .. ... .... .
. ... .. ... .... .
. ... .. ... .... .
| ||| || ||| |||| |
| ||+---------- -++-- ... -+++----------------- ... ... -------+||| |
| |+-Border---- ... ----- ... --------------------- ... ... -Border-+|| |
| | Shadow---- ... ----- ... --------------------- ... ... --Shadow-+| |
*/
// Is the distance between A and B less than D?
template < class A, class B, class DIST > bool within(A a, B b, DIST d)
{
return (a > b - d) && (a < b + d);
}
BEGIN_EVENT_TABLE(TrackPanel, OverlayPanel)
EVT_MOUSE_EVENTS(TrackPanel::OnMouseEvent)
EVT_MOUSE_CAPTURE_LOST(TrackPanel::OnCaptureLost)
EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, TrackPanel::OnCaptureKey)
EVT_KEY_DOWN(TrackPanel::OnKeyDown)
EVT_KEY_UP(TrackPanel::OnKeyUp)
EVT_CHAR(TrackPanel::OnChar)
EVT_PAINT(TrackPanel::OnPaint)
EVT_SET_FOCUS(TrackPanel::OnSetFocus)
EVT_KILL_FOCUS(TrackPanel::OnKillFocus)
EVT_CONTEXT_MENU(TrackPanel::OnContextMenu)
EVT_TIMER(wxID_ANY, TrackPanel::OnTimer)
END_EVENT_TABLE()
/// Makes a cursor from an XPM, uses CursorId as a fallback.
/// TODO: Move this function to some other source file for reuse elsewhere.
std::unique_ptr MakeCursor( int WXUNUSED(CursorId), const char * pXpm[36], int HotX, int HotY )
{
#ifdef CURSORS_SIZE32
const int HotAdjust =0;
#else
const int HotAdjust =8;
#endif
wxImage Image = wxImage(wxBitmap(pXpm).ConvertToImage());
Image.SetMaskColour(255,0,0);
Image.SetMask();// Enable mask.
Image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, HotX-HotAdjust );
Image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, HotY-HotAdjust );
return std::make_unique( Image );
}
// Don't warn us about using 'this' in the base member initializer list.
#ifndef __WXGTK__ //Get rid if this pragma for gtk
#pragma warning( disable: 4355 )
#endif
TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
const wxPoint & pos,
const wxSize & size,
const std::shared_ptr &tracks,
ViewInfo * viewInfo,
TrackPanelListener * listener,
AdornedRulerPanel * ruler)
: OverlayPanel(parent, id, pos, size, wxWANTS_CHARS | wxNO_BORDER),
mTrackInfo(this),
mListener(listener),
mTracks(tracks),
mViewInfo(viewInfo),
mRuler(ruler),
mTrackArtist(nullptr),
mRefreshBacking(false),
vrulerSize(36,0)
#ifndef __WXGTK__ //Get rid if this pragma for gtk
#pragma warning( default: 4355 )
#endif
{
SetLabel(_("Track Panel"));
SetName(_("Track Panel"));
SetBackgroundStyle(wxBG_STYLE_PAINT);
{
auto pAx = std::make_unique ( this );
#if wxUSE_ACCESSIBILITY
// wxWidgets owns the accessible object
SetAccessible(mAx = pAx.release());
#else
// wxWidgets does not own the object, but we need to retain it
mAx = std::move(pAx);
#endif
}
mRedrawAfterStop = false;
mTrackArtist = std::make_unique();
mTrackArtist->SetMargins(1, kTopMargin, kRightMargin, kBottomMargin);
mTimeCount = 0;
mTimer.parent = this;
// Timer is started after the window is visible
GetProject()->Bind(wxEVT_IDLE, &TrackPanel::OnIdle, this);
// Register for tracklist updates
mTracks->Connect(EVT_TRACKLIST_RESIZING,
wxCommandEventHandler(TrackPanel::OnTrackListResizing),
NULL,
this);
mTracks->Connect(EVT_TRACKLIST_DELETION,
wxCommandEventHandler(TrackPanel::OnTrackListDeletion),
NULL,
this);
wxTheApp->Connect(EVT_AUDIOIO_PLAYBACK,
wxCommandEventHandler(TrackPanel::OnPlayback),
NULL,
this);
}
TrackPanel::~TrackPanel()
{
mTimer.Stop();
// Unregister for tracklist updates
mTracks->Disconnect(EVT_TRACKLIST_DELETION,
wxCommandEventHandler(TrackPanel::OnTrackListDeletion),
NULL,
this);
mTracks->Disconnect(EVT_TRACKLIST_RESIZING,
wxCommandEventHandler(TrackPanel::OnTrackListResizing),
NULL,
this);
wxTheApp->Disconnect(EVT_AUDIOIO_PLAYBACK,
wxCommandEventHandler(TrackPanel::OnPlayback),
NULL,
this);
// This can happen if a label is being edited and the user presses
// ALT+F4 or Command+Q
if (HasCapture())
ReleaseMouse();
}
LWSlider *TrackPanel::GainSlider( const WaveTrack *wt )
{
auto rect = FindTrackRect( wt, true );
wxRect sliderRect;
TrackInfo::GetGainRect( rect.GetTopLeft(), sliderRect );
return TrackInfo::GainSlider(sliderRect, wt, false, this);
}
LWSlider *TrackPanel::PanSlider( const WaveTrack *wt )
{
auto rect = FindTrackRect( wt, true );
wxRect sliderRect;
TrackInfo::GetPanRect( rect.GetTopLeft(), sliderRect );
return TrackInfo::PanSlider(sliderRect, wt, false, this);
}
#ifdef EXPERIMENTAL_MIDI_OUT
LWSlider *TrackPanel::VelocitySlider( const NoteTrack *nt )
{
auto rect = FindTrackRect( nt, true );
wxRect sliderRect;
TrackInfo::GetVelocityRect( rect.GetTopLeft(), sliderRect );
return TrackInfo::VelocitySlider(sliderRect, nt, false, this);
}
#endif
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
void TrackPanel::UpdateVirtualStereoOrder()
{
TrackListOfKindIterator iter(Track::Wave, GetTracks());
Track *t;
int temp;
for (t = iter.First(); t; t = iter.Next()) {
const auto wt = static_cast(t);
if(t->GetChannel() == Track::MonoChannel){
if(WaveTrack::mMonoAsVirtualStereo && wt->GetPan() != 0){
temp = wt->GetHeight();
wt->SetHeight(temp*wt->GetVirtualTrackPercentage());
wt->SetHeight(temp - wt->GetHeight(),true);
}else if(!WaveTrack::mMonoAsVirtualStereo && wt->GetPan() != 0){
wt->SetHeight(wt->GetHeight() + wt->GetHeight(true));
}
}
}
t = iter.First();
if(t){
t->ReorderList(false);
}
}
#endif
wxString TrackPanel::gSoloPref;
void TrackPanel::UpdatePrefs()
{
gPrefs->Read(wxT("/GUI/AutoScroll"), &mViewInfo->bUpdateTrackIndicator,
true);
gPrefs->Read(wxT("/GUI/Solo"), &gSoloPref, wxT("Simple"));
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
bool temp = WaveTrack::mMonoAsVirtualStereo;
gPrefs->Read(wxT("/GUI/MonoAsVirtualStereo"), &WaveTrack::mMonoAsVirtualStereo,
false);
if(WaveTrack::mMonoAsVirtualStereo != temp)
UpdateVirtualStereoOrder();
#endif
mViewInfo->UpdatePrefs();
if (mTrackArtist) {
mTrackArtist->UpdatePrefs();
}
// All vertical rulers must be recalculated since the minimum and maximum
// frequences may have been changed.
UpdateVRulers();
mTrackInfo.UpdatePrefs();
Refresh();
}
void TrackPanel::ApplyUpdatedTheme()
{
mTrackInfo.ReCreateSliders();
}
void TrackPanel::GetTracksUsableArea(int *width, int *height) const
{
GetSize(width, height);
if (width) {
*width -= GetLeftOffset();
*width -= kRightMargin;
*width = std::max(0, *width);
}
}
/// Gets the pointer to the AudacityProject that
/// goes with this track panel.
AudacityProject * TrackPanel::GetProject() const
{
//JKC casting away constness here.
//Do it in two stages in case 'this' is not a wxWindow.
//when the compiler will flag the error.
wxWindow const * const pConstWind = this;
wxWindow * pWind=(wxWindow*)pConstWind;
#ifdef EXPERIMENTAL_NOTEBOOK
pWind = pWind->GetParent(); //Page
wxASSERT( pWind );
pWind = pWind->GetParent(); //Notebook
wxASSERT( pWind );
#endif
pWind = pWind->GetParent(); //MainPanel
wxASSERT( pWind );
pWind = pWind->GetParent(); //Project
wxASSERT( pWind );
return (AudacityProject*)pWind;
}
void TrackPanel::OnIdle(wxIdleEvent& event)
{
// The window must be ready when the timer fires (#1401)
if (IsShownOnScreen())
{
mTimer.Start(kTimerInterval, FALSE);
// Timer is started, we don't need the event anymore
GetProject()->Unbind(wxEVT_IDLE, &TrackPanel::OnIdle, this);
}
else
{
// Get another idle event, wx only guarantees we get one
// event after "some other normal events occur"
event.RequestMore();
}
}
/// AS: This gets called on our wx timer events.
void TrackPanel::OnTimer(wxTimerEvent& )
{
#ifdef __WXMAC__
// Unfortunate part of fix for bug 1431
// Without this, the toolbars hide only every other time that you press
// the yellow title bar button. For some reason, not every press sends
// us a deactivate event for the application.
{
auto project = GetProject();
if (project->IsIconized())
project->MacShowUndockedToolbars(false);
}
#endif
mTimeCount++;
AudacityProject *const p = GetProject();
// Check whether we were playing or recording, but the stream has stopped.
if (p->GetAudioIOToken()>0 && !IsAudioActive())
{
//the stream may have been started up after this one finished (by some other project)
//in that case reset the buttons don't stop the stream
p->GetControlToolBar()->StopPlaying(!gAudioIO->IsStreamActive());
}
// Next, check to see if we were playing or recording
// audio, but now Audio I/O is completely finished.
if (p->GetAudioIOToken()>0 &&
!gAudioIO->IsAudioTokenActive(p->GetAudioIOToken()))
{
p->FixScrollbars();
p->SetAudioIOToken(0);
p->RedrawProject();
mRedrawAfterStop = false;
//ANSWER-ME: Was DisplaySelection added to solve a repaint problem?
DisplaySelection();
}
if (mLastDrawnSelectedRegion != mViewInfo->selectedRegion) {
UpdateSelectionDisplay();
}
// Notify listeners for timer ticks
{
wxCommandEvent e(EVT_TRACK_PANEL_TIMER);
p->GetEventHandler()->ProcessEvent(e);
}
DrawOverlays(false);
mRuler->DrawOverlays(false);
if(IsAudioActive() && gAudioIO->GetNumCaptureChannels()) {
// Periodically update the display while recording
if (!mRedrawAfterStop) {
mRedrawAfterStop = true;
MakeParentRedrawScrollbars();
mListener->TP_ScrollUpDown( 99999999 );
Refresh( false );
}
else {
if ((mTimeCount % 5) == 0) {
// Must tell OnPaint() to recreate the backing bitmap
// since we've not done a full refresh.
mRefreshBacking = true;
Refresh( false );
}
}
}
if(mTimeCount > 1000)
mTimeCount = 0;
}
double TrackPanel::GetScreenEndTime() const
{
int width;
GetTracksUsableArea(&width, NULL);
return mViewInfo->PositionToTime(width, 0, true);
}
/// AS: OnPaint( ) is called during the normal course of
/// completing a repaint operation.
void TrackPanel::OnPaint(wxPaintEvent & /* event */)
{
mLastDrawnSelectedRegion = mViewInfo->selectedRegion;
#if DEBUG_DRAW_TIMING
wxStopWatch sw;
#endif
{
wxPaintDC dc(this);
// Retrieve the damage rectangle
wxRect box = GetUpdateRegion().GetBox();
// Recreate the backing bitmap if we have a full refresh
// (See TrackPanel::Refresh())
if (mRefreshBacking || (box == GetRect()))
{
// Reset (should a mutex be used???)
mRefreshBacking = false;
// Redraw the backing bitmap
DrawTracks(&GetBackingDCForRepaint());
// Copy it to the display
DisplayBitmap(dc);
}
else
{
// Copy full, possibly clipped, damage rectangle
RepairBitmap(dc, box.x, box.y, box.width, box.height);
}
// Done with the clipped DC
// Drawing now goes directly to the client area.
// DrawOverlays() may need to draw outside the clipped region.
// (Used to make a NEW, separate wxClientDC, but that risks flashing
// problems on Mac.)
dc.DestroyClippingRegion();
DrawOverlays(true, &dc);
}
#if DEBUG_DRAW_TIMING
sw.Pause();
wxLogDebug(wxT("Total: %ld milliseconds"), sw.Time());
wxPrintf(wxT("Total: %ld milliseconds\n"), sw.Time());
#endif
}
void TrackPanel::MakeParentModifyState(bool bWantsAutoSave)
{
mListener->TP_ModifyState(bWantsAutoSave);
}
void TrackPanel::MakeParentRedrawScrollbars()
{
mListener->TP_RedrawScrollbars();
}
void TrackPanel::HandleInterruptedDrag()
{
if (mUIHandle && mUIHandle->StopsOnKeystroke() ) {
// The bogus id isn't used anywhere, but may help with debugging.
// as this is sending a bogus mouse up. The mouse button is still actually down
// and may go up again.
const int idBogusUp = 2;
wxMouseEvent evt { wxEVT_LEFT_UP };
evt.SetId( idBogusUp );
evt.SetPosition(this->ScreenToClient(::wxGetMousePosition()));
this->ProcessEvent(evt);
}
}
namespace
{
void ProcessUIHandleResult
(TrackPanel *panel, AdornedRulerPanel *ruler,
Track *pClickedTrack, Track *pLatestTrack,
UIHandle::Result refreshResult)
{
// TODO: make a finer distinction between refreshing the track control area,
// and the waveform area. As it is, redraw both whenever you must redraw either.
using namespace RefreshCode;
panel->UpdateViewIfNoTracks();
if (refreshResult & DestroyedCell) {
// Beware stale pointer!
if (pLatestTrack == pClickedTrack)
pLatestTrack = NULL;
pClickedTrack = NULL;
}
if (pClickedTrack && (refreshResult & UpdateVRuler))
panel->UpdateVRuler(pClickedTrack);
if (refreshResult & DrawOverlays) {
panel->DrawOverlays(false);
ruler->DrawOverlays(false);
}
// Refresh all if told to do so, or if told to refresh a track that
// is not known.
const bool refreshAll =
( (refreshResult & RefreshAll)
|| ((refreshResult & RefreshCell) && !pClickedTrack)
|| ((refreshResult & RefreshLatestCell) && !pLatestTrack));
if (refreshAll)
panel->Refresh(false);
else {
if (refreshResult & RefreshCell)
panel->RefreshTrack(pClickedTrack);
if (refreshResult & RefreshLatestCell)
panel->RefreshTrack(pLatestTrack);
}
if (refreshResult & FixScrollbars)
panel->MakeParentRedrawScrollbars();
if (refreshResult & Resize)
panel->GetListener()->TP_HandleResize();
// This flag is superfluous if you do full refresh,
// because TrackPanel::Refresh() does this too
if (refreshResult & UpdateSelection) {
panel->DisplaySelection();
{
// Formerly in TrackPanel::UpdateSelectionDisplay():
// Make sure the ruler follows suit.
// mRuler->DrawSelection();
// ... but that too is superfluous it does nothing but refresh
// the ruler, while DisplaySelection calls TP_DisplaySelection which
// also always refreshes the ruler.
}
}
if ((refreshResult & EnsureVisible) && pClickedTrack)
panel->EnsureVisible(pClickedTrack);
}
}
void TrackPanel::Uncapture(wxMouseEvent *pEvent)
{
if (HasCapture())
ReleaseMouse();
HandleMotion( pEvent );
}
void TrackPanel::CancelDragging()
{
if (mUIHandle) {
UIHandle::Result refreshResult = mUIHandle->Cancel(GetProject());
auto pTrack = GetTracks()->Lock(mpClickedTrack);
if (pTrack)
ProcessUIHandleResult(
this, mRuler, pTrack.get(), NULL,
refreshResult | mMouseOverUpdateFlags );
mpClickedTrack.reset();
mUIHandle.reset(), ClearTargets();
Uncapture();
}
}
bool TrackPanel::HandleEscapeKey(bool down)
{
if (!down)
return false;
if (mUIHandle) {
// UIHANDLE CANCEL
CancelDragging();
return true;
}
// Not escaping from a mouse drag
return false;
}
void TrackPanel::UpdateMouseState(const wxMouseState &state)
{
mLastMouseState = state;
// Simulate a down button if none, so hit test routines can anticipate
// which button will be clicked
if (!state.ButtonIsDown(wxMOUSE_BTN_ANY)) {
#ifdef __WXOSX__
if (state.RawControlDown())
// On Mac we can distinctly anticipate "right" click (as Control+click)
mLastMouseState.SetRightDown( true ),
mLastMouseState.SetLeftDown( false );
else
#endif
// Anticipate a left click by default
mLastMouseState.SetRightDown( false ),
mLastMouseState.SetLeftDown( true );
}
}
void TrackPanel::HandleModifierKey()
{
UpdateMouseState(::wxGetMouseState());
HandleCursorForLastMouseState();
}
void TrackPanel::HandlePageUpKey()
{
mListener->TP_ScrollWindow(2 * mViewInfo->h - GetScreenEndTime());
}
void TrackPanel::HandlePageDownKey()
{
mListener->TP_ScrollWindow(GetScreenEndTime());
}
void TrackPanel::HandleCursorForLastMouseState()
{
// Come here on modifier key or mouse button transitions,
// or on starting or stopping of play or record,
// and change the cursor appropriately.
HandleMotion( &mLastMouseState );
}
bool TrackPanel::IsAudioActive()
{
AudacityProject *p = GetProject();
return p->IsAudioActive();
}
/// TrackPanel::HandleMotion( ) sets the cursor drawn at the mouse location,
/// and updates the status bar message.
/// We treat certain other changes of mouse button and key state as "motions"
/// too, and also starting and stopping of playback or recording, all of which
/// may cause the appropriate cursor and message to change.
/// As this procedure checks which region the mouse is over, it is
/// appropriate to establish the message in the status bar.
void TrackPanel::HandleMotion( wxMouseState *pState )
{
wxMouseState dummy;
if (!pState)
pState = &dummy;
else
UpdateMouseState( *pState ), pState = &mLastMouseState;
auto &state = *pState;
const auto foundCell = FindCell( state.m_x, state.m_y );
auto &track = foundCell.pTrack;
auto &rect = foundCell.rect;
auto &pCell = foundCell.pCell;
const TrackPanelMouseState tpmState{ state, rect, pCell };
HandleMotion( tpmState );
}
void TrackPanel::HandleMotion( const TrackPanelMouseState &tpmState )
{
auto handle = mUIHandle;
auto oldHandle = mLastHitTest;
auto oldCell = mLastCell.lock();
auto newCell = tpmState.pCell;
std::shared_ptr