1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-20 22:30:05 +02:00
audacity/src/TimeDialog.cpp
lllucius 71fde85bfe 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.
2013-10-23 21:01:52 +00:00

128 lines
2.6 KiB
C++

/**********************************************************************
Audacity: A Digital Audio Editor
TimeDialog.cpp
Dominic Mazzoni
*******************************************************************//**
\class TimeDialog
\brief Dialog used to request a time value.
*//*******************************************************************/
#include "Audacity.h"
#include <wx/defs.h>
#include <wx/dynarray.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/string.h>
#include "ShuttleGui.h"
#include "TimeDialog.h"
BEGIN_EVENT_TABLE(TimeDialog, wxDialog)
EVT_COMMAND(wxID_ANY, EVT_TIMETEXTCTRL_UPDATED, TimeDialog::OnUpdate)
END_EVENT_TABLE()
TimeDialog::TimeDialog(wxWindow *parent,
const wxString &title,
const wxString &format,
double rate,
double time,
const wxString &prompt)
: wxDialog(parent, wxID_ANY, title),
mPrompt(prompt),
mFormat(format),
mRate(rate),
mTime(time),
mTimeCtrl(NULL)
{
ShuttleGui S(this, eIsCreating);
PopulateOrExchange(S);
}
void TimeDialog::PopulateOrExchange(ShuttleGui &S)
{
S.SetBorder(5);
S.StartVerticalLay(true);
{
S.StartStatic(mPrompt, true);
{
mTimeCtrl = new
TimeTextCtrl(this,
wxID_ANY,
mFormat,
mTime,
mRate,
wxDefaultPosition,
wxDefaultSize,
true);
mTimeCtrl->SetName(mPrompt);
S.AddWindow(mTimeCtrl);
mTimeCtrl->EnableMenu();
}
S.EndStatic();
}
S.EndVerticalLay();
S.AddStandardButtons();
TransferDataToWindow();
Layout();
Fit();
SetMinSize(GetSize());
Center();
}
bool TimeDialog::TransferDataToWindow()
{
mTimeCtrl->SetFormatString(mTimeCtrl->GetBuiltinFormat(mFormat));
mTimeCtrl->SetSampleRate(mRate);
mTimeCtrl->SetTimeValue(mTime);
mTimeCtrl->SetFocus();
return true;
}
bool TimeDialog::TransferDataFromWindow()
{
mTime = mTimeCtrl->GetTimeValue();
return true;
}
const double TimeDialog::GetTimeValue()
{
return mTime;
}
void TimeDialog::SetFormatString(wxString formatString)
{
mFormat = formatString;
TransferDataToWindow();
}
void TimeDialog::SetSampleRate(double sampleRate)
{
mRate = sampleRate;
TransferDataToWindow();
}
void TimeDialog::SetTimeValue(double newTime)
{
mTime = newTime;
TransferDataToWindow();
}
void TimeDialog::OnUpdate(wxCommandEvent &event)
{
Layout();
Refresh();
event.Skip(false);
}