mirror of
https://github.com/cookiengineer/audacity
synced 2026-03-04 21:50:51 +01:00
Bug 115 - Snap-to causes spurious 'toolbar' to appear momentarily at start of dragging.
Completes James' TimeConverter work
This completes the work that James started. It moves most of the non-GUI
related processing from TimeTextCtrl to James' TimeConverter class.
Other changes include:
1) TimeTextCtrl now expects the format name instead of the format string to be
passed when creating a new instance. I found that almost all cases created the
instance with a blank format string and then set the string after creation.
2) To simplify maintenance and prevent a possible discrepancy between the two,
Increase() and Decrease() were merged into a single routine.
As a result:
1) All cases where a TimeTextCtrl was being used to extract information and
not actually display a control have been changed to use TimeConverter instead.
2) All cases where TimeTextCtrl was being created with an empty format and
then immediately followed by something like this:
tt.SetFormatString(tt.GetBuiltinFormat(c->GetFormat()))
have been changed to pass the format name instead of the format string when
creating the TimeTextCtrl instance.
This commit is contained in:
@@ -46,18 +46,12 @@ void TimeEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler)
|
||||
{
|
||||
m_control = new TimeTextCtrl(parent,
|
||||
wxID_ANY,
|
||||
wxT(""),
|
||||
mFormat,
|
||||
mOld,
|
||||
mRate,
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize,
|
||||
true);
|
||||
/* look up provided format string name to a format string, then set that as
|
||||
* the format string for the control. Unfortunately m_control is a base
|
||||
* class pointer not a TimeTextCtrl pointer, so we have to cast it. It can't
|
||||
* fail to cast, however unless the preceeding new operation failed, so it's
|
||||
* reasonably safe. */
|
||||
((TimeTextCtrl *)m_control)->SetFormatString(((TimeTextCtrl *)m_control)->GetBuiltinFormat(mFormat));
|
||||
|
||||
wxGridCellEditor::Create(parent, id, handler);
|
||||
}
|
||||
@@ -164,13 +158,12 @@ void TimeRenderer::Draw(wxGrid &grid,
|
||||
|
||||
TimeTextCtrl tt(&grid,
|
||||
wxID_ANY,
|
||||
wxT(""),
|
||||
te->GetFormat(),
|
||||
value,
|
||||
te->GetRate(),
|
||||
wxPoint(10000, 10000), // create offscreen
|
||||
wxDefaultSize,
|
||||
true);
|
||||
tt.SetFormatString(tt.GetBuiltinFormat(te->GetFormat()));
|
||||
tstr = tt.GetTimeString();
|
||||
|
||||
te->DecRef();
|
||||
@@ -221,13 +214,12 @@ wxSize TimeRenderer::GetBestSize(wxGrid &grid,
|
||||
table->GetValue(row, col).ToDouble(&value);
|
||||
TimeTextCtrl tt(&grid,
|
||||
wxID_ANY,
|
||||
wxT(""),
|
||||
te->GetFormat(),
|
||||
value,
|
||||
te->GetRate(),
|
||||
wxPoint(10000, 10000), // create offscreen
|
||||
wxDefaultSize,
|
||||
true);
|
||||
tt.SetFormatString(tt.GetBuiltinFormat(te->GetFormat()));
|
||||
sz = tt.GetSize();
|
||||
|
||||
te->DecRef();
|
||||
@@ -742,13 +734,12 @@ wxAccStatus GridAx::GetName(int childId, wxString *name)
|
||||
|
||||
TimeTextCtrl tt(mGrid,
|
||||
wxID_ANY,
|
||||
wxT(""),
|
||||
c->GetFormat(),
|
||||
value,
|
||||
c->GetRate(),
|
||||
wxPoint(10000, 10000), // create offscreen
|
||||
wxDefaultSize,
|
||||
true);
|
||||
tt.SetFormatString(tt.GetBuiltinFormat(c->GetFormat()));
|
||||
v = tt.GetTimeString();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,8 @@ DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TIMETEXTCTRL_UPDATED, -1);
|
||||
/** \brief struct to hold a formatting control string and it's user facing name
|
||||
* Used in an array to hold the built-in time formats that are always available
|
||||
* to the user */
|
||||
struct BuiltinFormatString {
|
||||
struct BuiltinFormatString
|
||||
{
|
||||
wxString name;
|
||||
wxString formatStr;
|
||||
};
|
||||
@@ -46,7 +47,49 @@ WX_DECLARE_OBJARRAY(DigitInfo, DigitInfoArray);
|
||||
class TimeConverter
|
||||
{
|
||||
public:
|
||||
TimeConverter();
|
||||
TimeConverter::TimeConverter(const wxString & formatName = wxEmptyString,
|
||||
double timeValue = 0.0f,
|
||||
double sampleRate = 1.0f /* to prevent div by 0 */);
|
||||
|
||||
virtual void ValueToControls();
|
||||
virtual void ValueToControls(double RawTime, bool nearest = true);
|
||||
virtual void ControlsToValue();
|
||||
virtual void ParseFormatString(const wxString & format);
|
||||
|
||||
void PrintDebugInfo();
|
||||
void SetFormatString(const wxString & formatName);
|
||||
void SetSampleRate(double sampleRate);
|
||||
void SetTimeValue(double newTime);
|
||||
double GetTimeValue();
|
||||
|
||||
wxString GetTimeString();
|
||||
|
||||
wxString GetFormatString();
|
||||
int GetFormatIndex();
|
||||
|
||||
int GetNumBuiltins();
|
||||
wxString GetBuiltinName(const int index);
|
||||
wxString GetBuiltinFormat(const int index);
|
||||
wxString GetBuiltinFormat(const wxString & name);
|
||||
|
||||
// Adjust the value by the number "steps" in the active format.
|
||||
// Increment if "dir" is 1, descrement if "dir" is -1.
|
||||
void Adjust(int steps, int dir);
|
||||
|
||||
void Increment();
|
||||
void Decrement();
|
||||
|
||||
protected:
|
||||
/** \brief array of formats the control knows about internally
|
||||
* array of string pairs for name of the format and the format string
|
||||
* needed to create that format output. This is used for the pop-up
|
||||
* list of formats to choose from in the control. Note that the size will
|
||||
* need adjusting if new time formats are added */
|
||||
BuiltinFormatString BuiltinFormatStrings[16];
|
||||
double mTimeValue;
|
||||
|
||||
wxString mFormatString;
|
||||
|
||||
TimeFieldArray mFields;
|
||||
wxString mPrefix;
|
||||
wxString mValueTemplate;
|
||||
@@ -57,13 +100,12 @@ public:
|
||||
double mSampleRate;
|
||||
bool mNtscDrop;
|
||||
|
||||
void ParseFormatString( const wxString & format );
|
||||
void PrintDebugInfo();
|
||||
void ValueToControls( double RawTime );
|
||||
double ControlsToValue();
|
||||
int mFocusedDigit;
|
||||
DigitInfoArray mDigits;
|
||||
};
|
||||
|
||||
class TimeTextCtrl: public wxControl{
|
||||
class TimeTextCtrl: public wxControl, public TimeConverter
|
||||
{
|
||||
friend class TimeTextCtrlAx;
|
||||
|
||||
public:
|
||||
@@ -71,7 +113,7 @@ class TimeTextCtrl: public wxControl{
|
||||
|
||||
TimeTextCtrl(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
wxString formatString = wxT(""),
|
||||
wxString formatName = wxT(""),
|
||||
double timeValue = 0.0,
|
||||
double sampleRate = 44100,
|
||||
const wxPoint &pos = wxDefaultPosition,
|
||||
@@ -83,23 +125,11 @@ class TimeTextCtrl: public wxControl{
|
||||
virtual bool Layout();
|
||||
virtual void Fit();
|
||||
|
||||
void SetFieldFocus(int digit);
|
||||
void SetFormatString(wxString formatString);
|
||||
void SetSampleRate(double sampleRate);
|
||||
void SetTimeValue(double newTime);
|
||||
void Increment();
|
||||
void Decrement();
|
||||
const double GetTimeValue();
|
||||
void SetFormatString(const wxString & formatString);
|
||||
|
||||
wxString GetTimeString();
|
||||
|
||||
wxString GetFormatString();
|
||||
int GetFormatIndex();
|
||||
|
||||
int GetNumBuiltins();
|
||||
wxString GetBuiltinName(const int index);
|
||||
wxString GetBuiltinFormat(const int index);
|
||||
wxString GetBuiltinFormat(const wxString &name);
|
||||
void SetFieldFocus(int digit);
|
||||
|
||||
void EnableMenu(bool enable = true);
|
||||
|
||||
@@ -121,24 +151,13 @@ private:
|
||||
void ValueToControls();
|
||||
void ControlsToValue();
|
||||
|
||||
void PrintDebugInfo();
|
||||
|
||||
// If autoPos was enabled, focus the first non-zero digit
|
||||
void UpdateAutoFocus();
|
||||
|
||||
void Updated(bool keyup = false);
|
||||
void Increase(int steps);
|
||||
void Decrease(int steps);
|
||||
|
||||
/** \brief array of formats the control knows about internally
|
||||
* array of string pairs for name of the format and the format string
|
||||
* needed to create that format output. This is used for the pop-up
|
||||
* list of formats to choose from in the control. Note that the size will
|
||||
* need adjusting if new time formats are added */
|
||||
BuiltinFormatString BuiltinFormatStrings[16];
|
||||
double mTimeValue;
|
||||
private:
|
||||
|
||||
wxString mFormatString;
|
||||
bool mMenuEnabled;
|
||||
|
||||
wxBitmap *mBackgroundBitmap;
|
||||
@@ -157,16 +176,11 @@ private:
|
||||
int mHeight;
|
||||
int mButtonWidth;
|
||||
|
||||
int mFocusedDigit;
|
||||
int mLastField;
|
||||
|
||||
// If true, the focus will be set to the first non-zero digit
|
||||
bool mAutoPos;
|
||||
|
||||
DigitInfoArray mDigits;
|
||||
TimeConverter mConverter;
|
||||
|
||||
|
||||
// Keeps track of extra fractional scrollwheel steps
|
||||
double mScrollRemainder;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user