From dc05b94fd18af2543c1b43c1ee54df06665a83f7 Mon Sep 17 00:00:00 2001 From: James Crook Date: Sat, 12 Aug 2017 21:49:38 +0100 Subject: [PATCH] Bug 1701 - Mac: Text descriptors in Selection Toolbar become invisible after Open command Problem was that on mac enable/disable clears the colour back to black. The easiest workaround was to create a new class auStaticText that does all that we need for wxStaticText. --- src/AColor.cpp | 4 ++-- src/MixerBoard.cpp | 11 +++++++---- src/MixerBoard.h | 3 ++- src/Theme.cpp | 33 +++++++++++++++++++++++++++++++++ src/Theme.h | 15 +++++++++++++++ src/TrackPanel.cpp | 4 +++- src/toolbars/SelectionBar.cpp | 26 ++++++++------------------ src/toolbars/SelectionBar.h | 2 +- 8 files changed, 71 insertions(+), 27 deletions(-) diff --git a/src/AColor.cpp b/src/AColor.cpp index 1192026a6..eecc39c3b 100644 --- a/src/AColor.cpp +++ b/src/AColor.cpp @@ -18,14 +18,14 @@ It is also a place to document colour usage policy in Audacity *//********************************************************************/ #include "Audacity.h" -#include "AColor.h" - +#include #include #include #include #include #include +#include "AColor.h" #include "Theme.h" #include "Experimental.h" #include "AllThemeResources.h" diff --git a/src/MixerBoard.cpp b/src/MixerBoard.cpp index 2311a3213..148966589 100644 --- a/src/MixerBoard.cpp +++ b/src/MixerBoard.cpp @@ -10,8 +10,6 @@ **********************************************************************/ #include "Audacity.h" -#include "Experimental.h" -#include "MixerBoard.h" #include #include @@ -21,6 +19,9 @@ #include #include // for wxSystemSettings::GetColour and wxSystemSettings::GetMetric +#include "Theme.h" +#include "Experimental.h" +#include "MixerBoard.h" #include "AColor.h" #include "AllThemeResources.h" #include "AudioIO.h" @@ -187,11 +188,13 @@ MixerTrackCluster::MixerTrackCluster(wxWindow* parent, wxPoint ctrlPos(kDoubleInset, kDoubleInset); wxSize ctrlSize(size.GetWidth() - kQuadrupleInset, TRACK_NAME_HEIGHT); mStaticText_TrackName = - safenew wxStaticText(this, -1, mTrack->GetName(), ctrlPos, ctrlSize, - wxALIGN_CENTRE | wxST_NO_AUTORESIZE | wxSUNKEN_BORDER); + safenew auStaticText(this, mTrack->GetName()); //v Useful when different tracks are different colors, but not now. // mStaticText_TrackName->SetBackgroundColour(this->GetTrackColor()); + mStaticText_TrackName->SetForegroundColour(theTheme.Colour(clrMedium)); mStaticText_TrackName->SetForegroundColour(theTheme.Colour(clrTrackPanelText)); + mStaticText_TrackName->SetSize( ctrlSize ); + mStaticText_TrackName->SetPosition( ctrlPos ); // gain and velocity sliders at left (both in same place) diff --git a/src/MixerBoard.h b/src/MixerBoard.h index 7bb050de6..d2a8a229e 100644 --- a/src/MixerBoard.h +++ b/src/MixerBoard.h @@ -70,6 +70,7 @@ class NoteTrack; class PlayableTrack; class WaveTrack; +class auStaticText; class MixerTrackCluster final : public wxPanelWrapper { @@ -140,7 +141,7 @@ private: AudacityProject* mProject; // controls - wxStaticText* mStaticText_TrackName; + auStaticText* mStaticText_TrackName; wxBitmapButton* mBitmapButton_MusicalInstrument; AButton* mToggleButton_Mute; AButton* mToggleButton_Solo; diff --git a/src/Theme.cpp b/src/Theme.cpp index 5fbb8506e..136b181a7 100644 --- a/src/Theme.cpp +++ b/src/Theme.cpp @@ -1265,3 +1265,36 @@ void ThemeBase::RotateImageInto( int iTo, int iFrom, bool bClockwise ) wxImage img2 = img.Rotate90( bClockwise ); ReplaceImage( iTo, &img2 ); } + +BEGIN_EVENT_TABLE(auStaticText, wxWindow) + EVT_PAINT(auStaticText::OnPaint) +END_EVENT_TABLE() + + +auStaticText::auStaticText(wxWindow* parent, wxString textIn) : + wxWindow(parent, wxID_ANY) +{ + int textWidth, textHeight; + + int fontSize = 11; + #ifdef __WXMSW__ + fontSize = 9; + #endif + wxFont font(fontSize, wxDEFAULT, wxNORMAL, wxNORMAL); + GetTextExtent(textIn, &textWidth, &textHeight, NULL, NULL, &font); + + SetFont( font ); + SetMinSize( wxSize(textWidth, textHeight) ); + SetBackgroundColour( theTheme.Colour( clrMedium)); + SetForegroundColour( theTheme.Colour( clrTrackPanelText)); + SetName(textIn); +} + +void auStaticText::OnPaint(wxPaintEvent & evt) +{ + wxPaintDC dc(this); + //dc.SetTextForeground( theTheme.Colour( clrTrackPanelText)); + dc.DrawText( GetName(), 0,0); +} + + diff --git a/src/Theme.h b/src/Theme.h index 375747493..e41213dad 100644 --- a/src/Theme.h +++ b/src/Theme.h @@ -16,6 +16,7 @@ #include "Audacity.h" +#include #include #include #include @@ -174,6 +175,20 @@ public: bool mbInitialised; }; +// A bit cheeky - putting a themable wxStaticText control into +// theme, rather than in a new file. Saves sorting out makefiles (for now). +class wxWindow; +class wxString; +class wxPaintEvent; + +class auStaticText : public wxWindow +{ +public: + auStaticText(wxWindow* parent, wxString text); + void OnPaint(wxPaintEvent & evt); + DECLARE_EVENT_TABLE(); +}; + extern AUDACITY_DLL_API Theme theTheme; #endif // __AUDACITY_THEME__ diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 6f873a945..1916897d0 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -1159,7 +1159,9 @@ void TrackPanel::OnPlayback(wxCommandEvent &e) void TrackPanel::OnTrackListResizing(wxCommandEvent & e) { Track *t = (Track *) e.GetClientData(); - UpdateVRuler(t); + // A deleted track can trigger the event. In which case do nothing here. + if( t ) + UpdateVRuler(t); e.Skip(); } diff --git a/src/toolbars/SelectionBar.cpp b/src/toolbars/SelectionBar.cpp index 1a76376c4..f9cd166aa 100644 --- a/src/toolbars/SelectionBar.cpp +++ b/src/toolbars/SelectionBar.cpp @@ -208,8 +208,9 @@ wxRadioButton * SelectionBar::AddRadioButton( const wxString & Name, return pBtn; } -wxStaticText * SelectionBar::AddTitle( const wxString & Title, int id, wxSizer * pSizer ){ - wxStaticText * pTitle = safenew wxStaticText(this, id,Title ); +auStaticText * SelectionBar::AddTitle( const wxString & Title, wxSizer * pSizer ){ + auStaticText * pTitle = safenew auStaticText(this, Title ); + pTitle->SetBackgroundColour( theTheme.Colour( clrMedium )); pTitle->SetForegroundColour( theTheme.Colour( clrTrackPanelText ) ); pSizer->Add( pTitle,0, wxALIGN_CENTER_VERTICAL | wxRIGHT, (Title.Length() == 1 ) ? 0:5); return pTitle; @@ -222,7 +223,6 @@ NumericTextCtrl * SelectionBar::AddTime( const wxString Name, int id, wxSizer * NumericTextCtrl * pCtrl = safenew NumericTextCtrl( NumericConverter::TIME, this, id, formatName, 0.0, mRate); pCtrl->SetName(Name); - pCtrl->SetForegroundColour( theTheme.Colour( clrTrackPanelText ) ); pCtrl->EnableMenu(); pSizer->Add(pCtrl, 0, wxALIGN_TOP | wxRIGHT, 5); return pCtrl; @@ -238,6 +238,7 @@ void SelectionBar::AddVLine( wxSizer * pSizer ){ void SelectionBar::Populate() { SetBackgroundColour( theTheme.Colour( clrMedium ) ); + mStartTime = mEndTime = mLengthTime = mCenterTime = mAudioTime = nullptr; #ifdef SEL_RADIO_TITLE mStartEndProxy = mStartLengthProxy = mLengthEndProxy = mLengthCenterProxy = nullptr; @@ -273,26 +274,15 @@ void SelectionBar::Populate() wxColour clrText = theTheme.Colour( clrTrackPanelText ); wxColour clrText2 = *wxBLUE; - wxStaticText * pProjRate = safenew wxStaticText(this, -1, _("Project Rate (Hz):"), - // LLL: On my Ubuntu 7.04 install, the label wraps to two lines - // and I could not figure out why. Thus...hackage. -#if defined(__WXGTK__) - wxDefaultPosition, wxSize(110, -1)); -#else - wxDefaultPosition, wxDefaultSize); -#endif - pProjRate->SetForegroundColour( clrText ); - mainSizer->Add(pProjRate,0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5); + AddTitle( _("Project Rate (Hz):"), mainSizer ); AddVLine( mainSizer ); - - AddTitle( _("Snap-To"), -1, mainSizer ); + AddTitle( _("Snap-To"), mainSizer ); #ifdef OPTIONS_BUTTON // Not enough room to say 'Selection Options". There is a tooltip instead. - AddTitle( wxT(""), -1, mainSizer ); + AddTitle( wxT(""), mainSizer ); #endif AddVLine( mainSizer ); - - AddTitle( _("Audio Position"), -1, mainSizer ); + AddTitle( _("Audio Position"), mainSizer ); AddVLine( mainSizer ); { diff --git a/src/toolbars/SelectionBar.h b/src/toolbars/SelectionBar.h index 1348c337a..b2343adb9 100644 --- a/src/toolbars/SelectionBar.h +++ b/src/toolbars/SelectionBar.h @@ -83,7 +83,7 @@ class SelectionBar final : public ToolBar { private: wxRadioButton * AddRadioButton( const wxString & Name, int id, wxSizer * pSizer, long style); - wxStaticText * AddTitle( const wxString & Title, int id, + auStaticText * AddTitle( const wxString & Title, wxSizer * pSizer ); NumericTextCtrl * AddTime( const wxString Name, int id, wxSizer * pSizer ); void AddVLine( wxSizer * pSizer );