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.
void LabelTrack::ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const
{
int xUsed[MAX_NUM_ROWS];
int i;
int iRow;
// 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.
/// @param dc the device context
/// @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
// 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.
/// @param dc the device context
/// @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 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.
/// @param dc the device context
/// @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
//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
//text we are about to draw.
@ -994,7 +997,8 @@ bool LabelTrack::CutSelectedText()
// copy data onto clipboard
if (wxTheClipboard->Open()) {
wxTheClipboard->SetData(new wxTextDataObject(data));
// Clipboard owns the data you give it
wxTheClipboard->SetData(safenew wxTextDataObject(data));
wxTheClipboard->Close();
}
@ -1026,7 +1030,8 @@ bool LabelTrack::CopySelectedText()
// copy the data on clipboard
if (wxTheClipboard->Open()) {
wxTheClipboard->SetData(new wxTextDataObject(data));
// Clipboard owns the data you give it
wxTheClipboard->SetData(safenew wxTextDataObject(data));
wxTheClipboard->Close();
}
@ -1200,7 +1205,6 @@ int LabelTrack::OverGlyph(int x, int y)
}
}
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
// of the same label.
@ -1211,7 +1215,6 @@ int LabelTrack::OverGlyph(int x, int y)
if(abs(pLabel->x - x) < d2 )
mbHitCenter = true;
result |= 1;
mInBox = false; // to disable the dragging for selecting the text in text box
}
// give text box better priority for selecting
@ -1273,8 +1276,9 @@ void LabelStruct::MoveLabel( int iEdge, double fNewTime)
updated = true;
}
LabelStruct::TimeRelations LabelStruct::RegionRelation(
double reg_t0, double reg_t1, const LabelTrack * WXUNUSED(parent))
auto LabelStruct::RegionRelation(
double reg_t0, double reg_t1, const LabelTrack * WXUNUSED(parent)) const
-> TimeRelations
{
bool retainLabels = false;
@ -1515,8 +1519,6 @@ void LabelTrack::HandleClick(const wxMouseEvent & evt,
// reset mouseXPos if the mouse is pressed in the text box
mMouseXPos = -1;
mInBox = false;
bool changeCursor = true;
if (mIsAdjustingLabel)
{
@ -1567,10 +1569,7 @@ void LabelTrack::HandleClick(const wxMouseEvent & evt,
if (mSelIndex != -1) {
*newSel = mLabels[mSelIndex]->selectedRegion;
// set mouseXPos to set current cursor position
if (changeCursor)
mMouseXPos = evt.m_x;
// set mInBox flag
mInBox = true;
mMouseXPos = evt.m_x;
}
// reset the highlight indicator
@ -1601,19 +1600,9 @@ void LabelTrack::HandleClick(const wxMouseEvent & evt,
}
// disable displaying if right button is down outside text box
if (mSelIndex != -1)
{
if (evt.RightDown())
{
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;
}
}
if (mSelIndex != -1 && evt.RightDown()
&& !highlightedRect.Contains(evt.m_x, evt.m_y))
mDragXPos = -1;
// Middle click on GTK: paste from primary selection
#if defined(__WXGTK__) && (HAVE_GTK)
@ -2153,7 +2142,7 @@ bool LabelTrack::IsSelected() const
}
/// 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
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)
{
// Sanity-check the arguments
if (n < 0 || t1 < t0) return false;
if (n < 0 || t1 < t0)
return false;
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;
wxString retVal;

View File

@ -51,10 +51,11 @@ public:
// Copies region but then overwrites other times
LabelStruct(const SelectedRegion& region, double t0, double t1,
const wxString &aTitle);
void DrawLines( wxDC & dc, const wxRect & r);
void DrawGlyphs( wxDC & dc, const wxRect & r, int GlyphLeft, int GlyphRight);
void DrawText( wxDC & dc, const wxRect & r);
void DrawTextBox( wxDC & dc, const wxRect & r);
void DrawLines( wxDC & dc, const wxRect & r) const;
void DrawGlyphs
( wxDC & dc, const wxRect & r, int GlyphLeft, int GlyphRight) const;
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 getXPos( wxDC & dc, int * xPos1, int cursorPos) const;
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
/// it possible to DELETE capture all labels with a Select All).
TimeRelations RegionRelation(double reg_t0, double reg_t1,
const LabelTrack *parent = NULL);
const LabelTrack *parent = NULL) const;
public:
SelectedRegion selectedRegion;
@ -182,10 +183,8 @@ class AUDACITY_DLL_API LabelTrack final : public Track
// methods to set flags
void SetDragXPos(const int d) { mDragXPos = d; }
void SetInBox(bool inTextBox) { mInBox = inTextBox; }
void SetResetCursorPos(bool resetFlag) { mResetCursorPos = resetFlag; }
void SetWrongDragging(bool rightFlag) { mRightDragging = rightFlag; }
void SetDrawCursor(bool drawCursorFlag) { mDrawCursor = drawCursorFlag; }
void HandleClick(const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo,
SelectedRegion *newSel);
@ -198,7 +197,7 @@ class AUDACITY_DLL_API LabelTrack final : public Track
bool OnChar(SelectedRegion &sel, wxKeyEvent & event);
void Import(wxTextFile & f);
void Export(wxTextFile & f);
void Export(wxTextFile & f) const;
void Unselect();
@ -218,7 +217,6 @@ class AUDACITY_DLL_API LabelTrack final : public Track
//get current cursor position
bool CalcCursorX(wxWindow * parent, int * x);
int getCurrentCursorPosition() const { return mCurrentCursorPos; }
void MayAdjustLabel( int iLabel, int iEdge, bool bAllowSwapping, 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);
// 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:
void SortLabels();
@ -262,20 +260,20 @@ class AUDACITY_DLL_API LabelTrack final : public Track
static bool mbGlyphsReady;
static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS * NUM_GLYPH_HIGHLIGHTS];
mutable int xUsed[MAX_NUM_ROWS];
static int mFontHeight;
mutable int mXPos1; /// left X pos of highlighted area
mutable int mXPos2; /// right X pos of highlighted area
mutable int mCurrentCursorPos; /// current cursor position
mutable int mInitialCursorPos; /// initial cursor position
mutable double mMouseXPos; /// mouse X pos
int mDragXPos; /// end X pos of dragging
bool mInBox; /// flag to tell if the mouse is in text box
int mDragXPos; /// end X pos of dragging
/// in text box
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
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
double mClipLen;

View File

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