1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-08 16:37:44 +02:00

More safenew, const functions, remove unnecessary members

This commit is contained in:
Paul Licameli 2016-06-23 15:03:30 -04:00
parent d6fb30538f
commit f01fc64a2d
3 changed files with 36 additions and 49 deletions

View File

@ -463,6 +463,8 @@ void LabelTrack::ComputeTextPosition(const wxRect & r, int index) const
/// Function assumes that the labels are sorted. /// Function assumes that the labels are sorted.
void LabelTrack::ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const void LabelTrack::ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const
{ {
int xUsed[MAX_NUM_ROWS];
int i; int i;
int iRow; int iRow;
// Rows are the 'same' height as icons or as the text, // Rows are the 'same' height as icons or as the text,
@ -564,7 +566,7 @@ LabelStruct::LabelStruct(const SelectedRegion &region,
/// of the start or end of a label. /// of the start or end of a label.
/// @param dc the device context /// @param dc the device context
/// @param r the LabelTrack rectangle. /// @param r the LabelTrack rectangle.
void LabelStruct::DrawLines(wxDC & dc, const wxRect & r) void LabelStruct::DrawLines(wxDC & dc, const wxRect & r) const
{ {
// How far out from the centre line should the vertical lines // How far out from the centre line should the vertical lines
// start, i.e. what is the y position of the icon? // start, i.e. what is the y position of the icon?
@ -601,7 +603,8 @@ void LabelStruct::DrawLines(wxDC & dc, const wxRect & r)
/// DrawGlyphs draws the wxIcons at the start and end of a label. /// DrawGlyphs draws the wxIcons at the start and end of a label.
/// @param dc the device context /// @param dc the device context
/// @param r the LabelTrack rectangle. /// @param r the LabelTrack rectangle.
void LabelStruct::DrawGlyphs(wxDC & dc, const wxRect & r, int GlyphLeft, int GlyphRight) void LabelStruct::DrawGlyphs
(wxDC & dc, const wxRect & r, int GlyphLeft, int GlyphRight) const
{ {
const int xHalfWidth=LabelTrack::mIconWidth/2; const int xHalfWidth=LabelTrack::mIconWidth/2;
const int yStart=y-LabelTrack::mIconHeight/2+(LabelTrack::mTextHeight+3)/2; const int yStart=y-LabelTrack::mIconHeight/2+(LabelTrack::mTextHeight+3)/2;
@ -624,7 +627,7 @@ void LabelStruct::DrawGlyphs(wxDC & dc, const wxRect & r, int GlyphLeft, int Gly
/// behind the text itself. /// behind the text itself.
/// @param dc the device context /// @param dc the device context
/// @param r the LabelTrack rectangle. /// @param r the LabelTrack rectangle.
void LabelStruct::DrawText(wxDC & dc, const wxRect & r) void LabelStruct::DrawText(wxDC & dc, const wxRect & r) const
{ {
//If y is positive then it is the center line for the //If y is positive then it is the center line for the
//text we are about to draw. //text we are about to draw.
@ -649,7 +652,7 @@ void LabelStruct::DrawText(wxDC & dc, const wxRect & r)
} }
void LabelStruct::DrawTextBox(wxDC & dc, const wxRect & r) void LabelStruct::DrawTextBox(wxDC & dc, const wxRect & r) const
{ {
//If y is positive then it is the center line for the //If y is positive then it is the center line for the
//text we are about to draw. //text we are about to draw.
@ -994,7 +997,8 @@ bool LabelTrack::CutSelectedText()
// copy data onto clipboard // copy data onto clipboard
if (wxTheClipboard->Open()) { if (wxTheClipboard->Open()) {
wxTheClipboard->SetData(new wxTextDataObject(data)); // Clipboard owns the data you give it
wxTheClipboard->SetData(safenew wxTextDataObject(data));
wxTheClipboard->Close(); wxTheClipboard->Close();
} }
@ -1026,7 +1030,8 @@ bool LabelTrack::CopySelectedText()
// copy the data on clipboard // copy the data on clipboard
if (wxTheClipboard->Open()) { if (wxTheClipboard->Open()) {
wxTheClipboard->SetData(new wxTextDataObject(data)); // Clipboard owns the data you give it
wxTheClipboard->SetData(safenew wxTextDataObject(data));
wxTheClipboard->Close(); wxTheClipboard->Close();
} }
@ -1200,7 +1205,6 @@ int LabelTrack::OverGlyph(int x, int y)
} }
} }
result |= 2; result |= 2;
mInBox = false; // to disable the dragging for selecting the text in text box
} }
// Use else-if here rather than else to avoid detecting left and right // Use else-if here rather than else to avoid detecting left and right
// of the same label. // of the same label.
@ -1211,7 +1215,6 @@ int LabelTrack::OverGlyph(int x, int y)
if(abs(pLabel->x - x) < d2 ) if(abs(pLabel->x - x) < d2 )
mbHitCenter = true; mbHitCenter = true;
result |= 1; result |= 1;
mInBox = false; // to disable the dragging for selecting the text in text box
} }
// give text box better priority for selecting // give text box better priority for selecting
@ -1273,8 +1276,9 @@ void LabelStruct::MoveLabel( int iEdge, double fNewTime)
updated = true; updated = true;
} }
LabelStruct::TimeRelations LabelStruct::RegionRelation( auto LabelStruct::RegionRelation(
double reg_t0, double reg_t1, const LabelTrack * WXUNUSED(parent)) double reg_t0, double reg_t1, const LabelTrack * WXUNUSED(parent)) const
-> TimeRelations
{ {
bool retainLabels = false; bool retainLabels = false;
@ -1515,8 +1519,6 @@ void LabelTrack::HandleClick(const wxMouseEvent & evt,
// reset mouseXPos if the mouse is pressed in the text box // reset mouseXPos if the mouse is pressed in the text box
mMouseXPos = -1; mMouseXPos = -1;
mInBox = false;
bool changeCursor = true;
if (mIsAdjustingLabel) if (mIsAdjustingLabel)
{ {
@ -1567,10 +1569,7 @@ void LabelTrack::HandleClick(const wxMouseEvent & evt,
if (mSelIndex != -1) { if (mSelIndex != -1) {
*newSel = mLabels[mSelIndex]->selectedRegion; *newSel = mLabels[mSelIndex]->selectedRegion;
// set mouseXPos to set current cursor position // set mouseXPos to set current cursor position
if (changeCursor) mMouseXPos = evt.m_x;
mMouseXPos = evt.m_x;
// set mInBox flag
mInBox = true;
} }
// reset the highlight indicator // reset the highlight indicator
@ -1601,19 +1600,9 @@ void LabelTrack::HandleClick(const wxMouseEvent & evt,
} }
// disable displaying if right button is down outside text box // disable displaying if right button is down outside text box
if (mSelIndex != -1) if (mSelIndex != -1 && evt.RightDown()
{ && !highlightedRect.Contains(evt.m_x, evt.m_y))
if (evt.RightDown()) mDragXPos = -1;
{
if (!highlightedRect.Contains(evt.m_x, evt.m_y))
{
mDragXPos = -1;
}
else
// if it's in text box, don't need to reset the current cursor position
changeCursor = false;
}
}
// Middle click on GTK: paste from primary selection // Middle click on GTK: paste from primary selection
#if defined(__WXGTK__) && (HAVE_GTK) #if defined(__WXGTK__) && (HAVE_GTK)
@ -2153,7 +2142,7 @@ bool LabelTrack::IsSelected() const
} }
/// Export labels including label start and end-times. /// Export labels including label start and end-times.
void LabelTrack::Export(wxTextFile & f) void LabelTrack::Export(wxTextFile & f) const
{ {
// PRL: to do: export other selection fields // PRL: to do: export other selection fields
for (int i = 0; i < (int)mLabels.Count(); i++) { for (int i = 0; i < (int)mLabels.Count(); i++) {
@ -2532,7 +2521,8 @@ bool LabelTrack::Paste(double t, const Track *src)
bool LabelTrack::Repeat(double t0, double t1, int n) bool LabelTrack::Repeat(double t0, double t1, int n)
{ {
// Sanity-check the arguments // Sanity-check the arguments
if (n < 0 || t1 < t0) return false; if (n < 0 || t1 < t0)
return false;
double tLen = t1 - t0; double tLen = t1 - t0;
@ -2921,7 +2911,7 @@ void LabelTrack::SortLabels()
} }
} }
wxString LabelTrack::GetTextOfLabels(double t0, double t1) wxString LabelTrack::GetTextOfLabels(double t0, double t1) const
{ {
bool firstLabel = true; bool firstLabel = true;
wxString retVal; wxString retVal;

View File

@ -51,10 +51,11 @@ public:
// Copies region but then overwrites other times // Copies region but then overwrites other times
LabelStruct(const SelectedRegion& region, double t0, double t1, LabelStruct(const SelectedRegion& region, double t0, double t1,
const wxString &aTitle); const wxString &aTitle);
void DrawLines( wxDC & dc, const wxRect & r); void DrawLines( wxDC & dc, const wxRect & r) const;
void DrawGlyphs( wxDC & dc, const wxRect & r, int GlyphLeft, int GlyphRight); void DrawGlyphs
void DrawText( wxDC & dc, const wxRect & r); ( wxDC & dc, const wxRect & r, int GlyphLeft, int GlyphRight) const;
void DrawTextBox( wxDC & dc, const wxRect & r); void DrawText( wxDC & dc, const wxRect & r) const;
void DrawTextBox( wxDC & dc, const wxRect & r) const;
void DrawHighlight( wxDC & dc, int xPos1, int xPos2, int charHeight); void DrawHighlight( wxDC & dc, int xPos1, int xPos2, int charHeight);
void getXPos( wxDC & dc, int * xPos1, int cursorPos) const; void getXPos( wxDC & dc, int * xPos1, int cursorPos) const;
const SelectedRegion &getSelectedRegion() const { return selectedRegion; } const SelectedRegion &getSelectedRegion() const { return selectedRegion; }
@ -81,7 +82,7 @@ public:
/// and end of parent to be within a region that borders them (this makes /// and end of parent to be within a region that borders them (this makes
/// it possible to DELETE capture all labels with a Select All). /// it possible to DELETE capture all labels with a Select All).
TimeRelations RegionRelation(double reg_t0, double reg_t1, TimeRelations RegionRelation(double reg_t0, double reg_t1,
const LabelTrack *parent = NULL); const LabelTrack *parent = NULL) const;
public: public:
SelectedRegion selectedRegion; SelectedRegion selectedRegion;
@ -182,10 +183,8 @@ class AUDACITY_DLL_API LabelTrack final : public Track
// methods to set flags // methods to set flags
void SetDragXPos(const int d) { mDragXPos = d; } void SetDragXPos(const int d) { mDragXPos = d; }
void SetInBox(bool inTextBox) { mInBox = inTextBox; }
void SetResetCursorPos(bool resetFlag) { mResetCursorPos = resetFlag; } void SetResetCursorPos(bool resetFlag) { mResetCursorPos = resetFlag; }
void SetWrongDragging(bool rightFlag) { mRightDragging = rightFlag; } void SetWrongDragging(bool rightFlag) { mRightDragging = rightFlag; }
void SetDrawCursor(bool drawCursorFlag) { mDrawCursor = drawCursorFlag; }
void HandleClick(const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo, void HandleClick(const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo,
SelectedRegion *newSel); SelectedRegion *newSel);
@ -198,7 +197,7 @@ class AUDACITY_DLL_API LabelTrack final : public Track
bool OnChar(SelectedRegion &sel, wxKeyEvent & event); bool OnChar(SelectedRegion &sel, wxKeyEvent & event);
void Import(wxTextFile & f); void Import(wxTextFile & f);
void Export(wxTextFile & f); void Export(wxTextFile & f) const;
void Unselect(); void Unselect();
@ -218,7 +217,6 @@ class AUDACITY_DLL_API LabelTrack final : public Track
//get current cursor position //get current cursor position
bool CalcCursorX(wxWindow * parent, int * x); bool CalcCursorX(wxWindow * parent, int * x);
int getCurrentCursorPosition() const { return mCurrentCursorPos; }
void MayAdjustLabel( int iLabel, int iEdge, bool bAllowSwapping, double fNewTime); void MayAdjustLabel( int iLabel, int iEdge, bool bAllowSwapping, double fNewTime);
void MayMoveLabel( int iLabel, int iEdge, double fNewTime); void MayMoveLabel( int iLabel, int iEdge, double fNewTime);
@ -237,7 +235,7 @@ class AUDACITY_DLL_API LabelTrack final : public Track
void WarpLabels(const TimeWarper &warper); void WarpLabels(const TimeWarper &warper);
// Returns tab-separated text of all labels completely within given region // Returns tab-separated text of all labels completely within given region
wxString GetTextOfLabels(double t0, double t1); wxString GetTextOfLabels(double t0, double t1) const;
public: public:
void SortLabels(); void SortLabels();
@ -262,20 +260,20 @@ class AUDACITY_DLL_API LabelTrack final : public Track
static bool mbGlyphsReady; static bool mbGlyphsReady;
static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS * NUM_GLYPH_HIGHLIGHTS]; static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS * NUM_GLYPH_HIGHLIGHTS];
mutable int xUsed[MAX_NUM_ROWS];
static int mFontHeight; static int mFontHeight;
mutable int mXPos1; /// left X pos of highlighted area mutable int mXPos1; /// left X pos of highlighted area
mutable int mXPos2; /// right X pos of highlighted area mutable int mXPos2; /// right X pos of highlighted area
mutable int mCurrentCursorPos; /// current cursor position mutable int mCurrentCursorPos; /// current cursor position
mutable int mInitialCursorPos; /// initial cursor position mutable int mInitialCursorPos; /// initial cursor position
mutable double mMouseXPos; /// mouse X pos mutable double mMouseXPos; /// mouse X pos
int mDragXPos; /// end X pos of dragging int mDragXPos; /// end X pos of dragging
bool mInBox; /// flag to tell if the mouse is in text box /// in text box
mutable bool mResetCursorPos; /// flag to reset cursor position(used in the dragging the glygh) mutable bool mResetCursorPos; /// flag to reset cursor position(used in the dragging the glygh)
bool mRightDragging; /// flag to tell if it's a valid dragging
bool mRightDragging; /// flag to tell if it's a valid dragging
mutable bool mDrawCursor; /// flag to tell if drawing the cursor or not mutable bool mDrawCursor; /// flag to tell if drawing the cursor or not
int mRestoreFocus; /// Restore focus to this track when done editing int mRestoreFocus; /// Restore focus to this track
/// when done editing
// Set in copied label tracks // Set in copied label tracks
double mClipLen; double mClipLen;

View File

@ -6317,7 +6317,6 @@ bool TrackPanel::HandleLabelTrackClick(LabelTrack * lTrack, wxRect &rect, wxMous
if (event.ShiftDown() && event.ButtonDown()) { if (event.ShiftDown() && event.ButtonDown()) {
// if the mouse is clicked in text box, set flags // if the mouse is clicked in text box, set flags
if (lTrack->OverTextBox(lTrack->GetLabel(lTrack->getSelectedIndex()), event.m_x, event.m_y)) { if (lTrack->OverTextBox(lTrack->GetLabel(lTrack->getSelectedIndex()), event.m_x, event.m_y)) {
lTrack->SetInBox(true);
lTrack->SetDragXPos(event.m_x); lTrack->SetDragXPos(event.m_x);
lTrack->SetResetCursorPos(true); lTrack->SetResetCursorPos(true);
RefreshTrack(lTrack); RefreshTrack(lTrack);