1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-23 15:50:05 +02:00

Remove dead code from SelectionBar

and add some comments.
This commit is contained in:
James Crook 2018-04-14 22:20:08 +01:00
parent c34dd3172b
commit c8a31324bc
2 changed files with 43 additions and 211 deletions

View File

@ -77,29 +77,11 @@ enum {
ChoiceID,
StartTitleID,
LengthTitleID,
CenterTitleID,
EndTitleID,
AudioTitleID,
LeftID,
CentralNameID,
RightID,
StartEndRadioID,
StartLengthRadioID,
LengthEndRadioID,
LengthCenterRadioID,
SelTBFirstButton,
SelTBMenuID = SelTBFirstButton,
id2,
StartTimeID,
LengthTimeID,
CenterTimeID,
EndTimeID,
AudioTimeID,
};
@ -113,16 +95,7 @@ BEGIN_EVENT_TABLE(SelectionBar, ToolBar)
EVT_CHOICE(ChoiceID, SelectionBar::OnChoice )
EVT_COMBOBOX(RateID, SelectionBar::OnRate)
EVT_TEXT(RateID, SelectionBar::OnRate)
EVT_RADIOBUTTON(StartEndRadioID, SelectionBar::OnFieldChoice )
EVT_RADIOBUTTON(StartLengthRadioID, SelectionBar::OnFieldChoice )
EVT_RADIOBUTTON(LengthEndRadioID, SelectionBar::OnFieldChoice )
EVT_RADIOBUTTON(LengthCenterRadioID, SelectionBar::OnFieldChoice )
EVT_COMMAND_RANGE( SelTBMenuID,
SelTBMenuID,
wxEVT_COMMAND_BUTTON_CLICKED,
SelectionBar::OnButton )
// EVT_COMMAND( OnMenuId, wxEVT_COMMAND_BUTTON_CLICKED, SelectionBar::OnButton )
EVT_COMMAND(wxID_ANY, EVT_TIMETEXTCTRL_UPDATED, SelectionBar::OnUpdate)
EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, SelectionBar::OnCaptureKey)
END_EVENT_TABLE()
@ -159,43 +132,6 @@ void SelectionBar::Create(wxWindow * parent)
ToolBar::Create(parent);
}
// Add Radio Button function is not used anymore.
// But maybe we will need it again in the future.
//
// Can't set textcolour of radio buttons.
// so instead if we want to them, we make the text empty and add in a wxStaticText
// and we can set the colour of that.
// Slight regression relative ot Audacity, in that this text is not
// clickable/active. You have to click on the actual button.
// And you can't tab between and hear the labels with voice over.
// So VI users should use blend themes (which is the default).
// Should not be a hardship for them, as themes make little difference
// for them, except Hi-Contrast, which should be used with blend thems
// and a windows theme that is close enough to actually blend.
wxRadioButton * SelectionBar::AddRadioButton( const wxString & Name,
int id, wxSizer *pSizer, long style )
{
bool bUseNativeRadioButton = theTheme.IsUsingSystemTextColour();
wxRadioButton * pBtn;
// Safenew because the button is being create dinto this window.
pBtn = safenew wxRadioButton(this, id,bUseNativeRadioButton ? Name : wxT(""),
wxDefaultPosition, wxDefaultSize, style);
pBtn->SetName(Name);
pBtn->SetForegroundColour( theTheme.Colour( clrTrackPanelText ));
pSizer->Add(pBtn, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
// Hacky code to return a second optional value via the variable mProxy.
// If not NULL, we made a NEW proxy label
mProxy = NULL;
if( !bUseNativeRadioButton )
{
mProxy = safenew wxStaticText(this, -1, Name);
mProxy->SetForegroundColour( theTheme.Colour( clrTrackPanelText ) );
pSizer->Add(mProxy, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
}
return pBtn;
}
auStaticText * SelectionBar::AddTitle( const wxString & Title, wxSizer * pSizer ){
auStaticText * pTitle = safenew auStaticText(this, Title );
@ -252,19 +188,12 @@ void SelectionBar::Populate()
// on each sizer as to what spacings it creates.
Add((mainSizer = safenew wxFlexGridSizer(SIZER_COLS, 1, 1)), 0, wxALIGN_TOP | wxLEFT | wxTOP, 5);
//
// Top row (mostly labels)
//
wxColour clrText = theTheme.Colour( clrTrackPanelText );
wxColour clrText2 = *wxBLUE;
AddTitle( _("Project Rate (Hz)"), mainSizer );
AddVLine( mainSizer );
AddTitle( _("Snap-To"), mainSizer );
#ifdef OPTIONS_BUTTON
// Not enough room to say 'Selection Options". There is a tooltip instead.
AddTitle( wxT(""), mainSizer );
#endif
AddVLine( mainSizer );
AddTitle( _("Audio Position"), mainSizer );
AddVLine( mainSizer );
@ -294,10 +223,7 @@ void SelectionBar::Populate()
mainSizer->Add(mChoice, 0, wxALIGN_TOP | wxEXPAND | wxRIGHT, 6);
}
//
// Botton row, (mostly time controls)
//
mRateBox = safenew wxComboBox(this, RateID,
wxT(""),
wxDefaultPosition, wxSize(80, -1));
@ -400,7 +326,6 @@ void SelectionBar::Populate()
mCenterTime = AddTime(_("Center"), CenterTimeID, hSizer.get() );
mEndTime = AddTime(_("End"), EndTimeID, hSizer.get() );
mainSizer->Add(hSizer.release(), 0, wxALIGN_TOP | wxRIGHT, 0);
}
mChoice->MoveBeforeInTabOrder( mStartTime );
@ -426,7 +351,6 @@ void SelectionBar::UpdatePrefs()
SetLabel(_("Selection"));
RegenerateTooltips();
// Give base class a chance
ToolBar::UpdatePrefs();
}
@ -480,6 +404,18 @@ void SelectionBar::ModifySelection(int newDriver, bool done)
if( newDriver == CenterTimeID )
mCenter = mCenterTime->GetValue();
// There are four controls, and two constraints, which are:
// mid = (start+end)/2
// length = (end-start)
// Therefore we can select any two controls as 'drivers' of
// the other two.
// Here we compute 'i' which combines the identity of the two
// driving controls, to use it as an index.
// The order of the two drivers generally does not matter much,
// except that we have want:
// start < end
// and preserve that by adjusting the least dominant driving
// control.
int i = mDrive1 + 4 * mDrive2;
switch(i){
case StartTimeID + 4 * EndTimeID:
@ -544,36 +480,6 @@ void SelectionBar::OnChangedTime(wxCommandEvent & event)
ModifySelection(event.GetId(), event.GetInt() != 0);
}
void SelectionBar::OnTitleClicked(int newDriver)
{
// Ensure newDriver is the most recent driver.
if( newDriver != mDrive2 )
SetDrivers( mDrive2, newDriver);
}
// These functions give the IDs of the associated control, NOT the ID of the title.
void SelectionBar::OnStartTitleClicked(wxMouseEvent & WXUNUSED(event)){ OnTitleClicked( StartTimeID );};
void SelectionBar::OnLengthTitleClicked(wxMouseEvent & WXUNUSED(event)){ OnTitleClicked( LengthTimeID );};
void SelectionBar::OnCenterTitleClicked(wxMouseEvent & WXUNUSED(event)){ OnTitleClicked( CenterTimeID );};
void SelectionBar::OnEndTitleClicked(wxMouseEvent & WXUNUSED(event)){ OnTitleClicked( EndTimeID );};
void SelectionBar::OnModeDecClicked(wxMouseEvent & WXUNUSED(event)){
SetSelectionMode( (mSelectionMode +3)%4 );
SelectionModeUpdated();
}
void SelectionBar::OnModeIncClicked(wxMouseEvent & WXUNUSED(event)){
SetSelectionMode( (mSelectionMode +1)%4 );
SelectionModeUpdated();
}
void SelectionBar::OnChooserTitleClicked(wxMouseEvent & WXUNUSED(event)){
wxCommandEvent evt;
OnButton( evt );
}
// Called when one of the format drop downs is changed.
void SelectionBar::OnUpdate(wxCommandEvent &evt)
{
@ -637,53 +543,12 @@ void SelectionBar::SetDrivers( int driver1, int driver2 )
wxString Title= wxString::Format( Format, Temp );
// i18n-hint: %s1 is replaced e.g by 'Length', %s2 e.g by 'Center'.
wxString VoiceOverText = wxString::Format(_("Selection %s. %s won't change."), Temp, Text[fixed]);
// i18n-hint: %s is replaced e.g by 'Length'. This is a tooltip on a numerical control.
//wxString Tooltip = wxString::Format( _(" With %s fixed. (Use context menu to change format.) "), Text[fixed] );
if( *Ctrls[i] ){
(*Ctrls[i])->SetName( Temp );
//(*Ctrls[i])->SetToolTip( Tooltip );
}
}
}
// There currently is only one clickable AButton
// so we just do what it needs.
void SelectionBar::OnButton(wxCommandEvent & WXUNUSED(event))
{
AudacityProject *p = GetActiveProject();
if (!p) return;
AButton * pBtn = mButtons[ SelTBMenuID-SelTBFirstButton];// use event.GetId();
auto cleanup = finally( [&] { pBtn->InteractionOver();}
);
SetFocus();
wxMenu Menu;
Menu.AppendRadioItem( 0, _("Start - End") );
Menu.AppendRadioItem( 1, _("Start - Length") );
Menu.AppendRadioItem( 2, _("Length - End") );
Menu.AppendRadioItem( 3, _("Length - Center") );
Menu.Check( mSelectionMode, true );
// Pop it up where the mouse is.
pBtn->PopupMenu(&Menu);//, wxPoint(0, 0));
// only one radio button should be checked.
for( int i=0;i<4;i++)
if( Menu.IsChecked(i))
SetSelectionMode( i );
SelectionModeUpdated();
}
void SelectionBar::OnFieldChoice(wxCommandEvent &event)
{
int id = event.GetId();
SetSelectionMode( id - StartEndRadioID );
SelectionModeUpdated();
}
void SelectionBar::OnChoice(wxCommandEvent & WXUNUSED(event))
{
int mode = mChoice->GetSelection();
@ -705,7 +570,9 @@ void SelectionBar::SelectionModeUpdated()
Updated();
}
// We used to have 8 modes which showed different combinations of the
// length, start, end, center controls.
// Mode 7 for example showed all four at the same time.
void SelectionBar::SetSelectionMode(int mode)
{
// Only modes 0 to 3 are now supported,
@ -735,10 +602,10 @@ void SelectionBar::SetSelectionMode(int mode)
// Our mode determines which controls are visible.
void SelectionBar::ShowHideControls(int mode)
{
// These
// The bits in these say which controls are visible.
int masks[8]= {
9, 5, 12, 6, // 2 items
13, 7, 11,// 3 items
9, 5, 12, 6, // 2 items shown
13, 7, 11,// 3 items shown
15};
int mask = masks[mode];
@ -759,6 +626,7 @@ void SelectionBar::ValuesToControls()
(*Ctrls[i])->SetValue( Values[i] );
}
// A time has been set. Update the control values.
void SelectionBar::SetTimes(double start, double end, double audio)
{
mStart = start;
@ -770,17 +638,6 @@ void SelectionBar::SetTimes(double start, double end, double audio)
ValuesToControls();
}
void SelectionBar::SetField(const wxChar *msg, int fieldNum)
{
if (fieldNum < 0 || fieldNum >= 10)
return;
if (mField[fieldNum] != msg) {
mField[fieldNum] = msg;
Refresh(false);
}
}
void SelectionBar::SetSnapTo(int snap)
{
mSnapTo->SetSelection(snap);

View File

@ -39,11 +39,6 @@ class wxStaticText;
class SelectionBarListener;
class NumericTextCtrl;
enum
{
numSelectionBarButtons = 1,
};
class SelectionBar final : public ToolBar {
public:
@ -58,17 +53,13 @@ class SelectionBar final : public ToolBar {
void UpdatePrefs() override;
void SetTimes(double start, double end, double audio);
void SetField(const wxChar *msg, int fieldNum);
void SetSnapTo(int);
void SetSelectionFormat(const NumericFormatId & format);
void SetRate(double rate);
void SetListener(SelectionBarListener *l);
void RegenerateTooltips() override;
void OnButton(wxCommandEvent & event);
private:
wxRadioButton * AddRadioButton( const wxString & Name, int id,
wxSizer * pSizer, long style);
auStaticText * AddTitle( const wxString & Title,
wxSizer * pSizer );
NumericTextCtrl * AddTime( const wxString Name, int id, wxSizer * pSizer );
@ -80,15 +71,6 @@ class SelectionBar final : public ToolBar {
void ValuesToControls();
void OnUpdate(wxCommandEvent &evt);
void OnChangedTime(wxCommandEvent &evt);
void OnTitleClicked(int newDriver );
void OnStartTitleClicked(wxMouseEvent & event);
void OnCenterTitleClicked(wxMouseEvent & event);
void OnLengthTitleClicked(wxMouseEvent & event);
void OnEndTitleClicked(wxMouseEvent & event);
void OnModeDecClicked(wxMouseEvent & event);
void OnModeIncClicked(wxMouseEvent & event);
void OnChooserTitleClicked(wxMouseEvent & event);
void OnRate(wxCommandEvent & event);
void OnSnapTo(wxCommandEvent & event);
@ -96,7 +78,6 @@ class SelectionBar final : public ToolBar {
void OnFocus(wxFocusEvent &event);
void OnCaptureKey(wxCommandEvent &event);
void OnSize(wxSizeEvent &evt);
void OnFieldChoice(wxCommandEvent &event);
void ModifySelection(int newDriver, bool done = false);
void UpdateRates();
@ -105,10 +86,6 @@ class SelectionBar final : public ToolBar {
SelectionBarListener * mListener;
double mRate;
double mStart, mEnd, mLength, mCenter, mAudio;
wxString mField[10];
// Only used if we use radio buttons.
bool mbUseNativeRadioButton;
// These two numbers say which two controls
// drive the other two.
@ -122,14 +99,12 @@ class SelectionBar final : public ToolBar {
NumericTextCtrl *mLengthTime;
NumericTextCtrl *mEndTime;
NumericTextCtrl *mAudioTime;
wxChoice * mChoice;
wxStaticText * mProxy;
wxChoice *mChoice;
wxStaticText *mProxy;
wxComboBox *mRateBox;
wxChoice *mSnapTo;
wxWindow *mRateText;
AButton * mButtons[numSelectionBarButtons];
public:
DECLARE_CLASS(SelectionBar)