From 255be8cfe778372e56f8c7f54e1ccd42422dace9 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Mon, 20 Jul 2015 02:10:05 -0500 Subject: [PATCH] Reworked the TipPanel used with ASliders It was producing "ghost" windows on OSX in wx3. These were supposed to be hidden, but they weren't any longer and after reviewing TipPanel, I realized that there was a separate code path for OSX entirely...must've gone back to some of the earliest versions. Now all platforms use the same bit of code. --- src/AudacityApp.cpp | 2 - src/Project.cpp | 9 -- src/TrackPanel.cpp | 14 ++- src/toolbars/DeviceToolBar.cpp | 4 - src/toolbars/DeviceToolBar.h | 1 - src/toolbars/MixerToolBar.cpp | 7 -- src/toolbars/MixerToolBar.h | 1 - src/widgets/ASlider.cpp | 222 +++++++++------------------------ src/widgets/ASlider.h | 12 +- 9 files changed, 69 insertions(+), 203 deletions(-) diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index 5688ba592..76a34b898 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -296,8 +296,6 @@ void QuitAudacity(bool bForce) } } - LWSlider::DeleteSharedTipPanel(); - ModuleManager::Get().Dispatch(AppQuiting); #ifdef EXPERIMENTAL_SCOREALIGN diff --git a/src/Project.cpp b/src/Project.cpp index 7447ba94e..9183ec52e 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -842,15 +842,6 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, #endif mToolManager->LayoutToolBars(); - // Fix the sliders on the mixer toolbar so that the tip windows - // actually pop-up on top of everything else. Sorry for the hack - - // it's necessary to do it this way to avoid flicker. -#if 0 - MixerToolBar *mtb = GetMixerToolBar(); - if (mtb) - mtb->RecreateTipWindows(); -#endif - // // Create the horizontal ruler // diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 05d36fa36..9e34813b6 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -892,7 +892,6 @@ void TrackPanel::SetCapturedTrack( Track * t, enum MouseCaptureEnum MouseCapture wxASSERT(MouseCapture != IsUncaptured); } #endif - mCapturedTrack = t; mMouseCapture = MouseCapture; } @@ -6514,13 +6513,16 @@ void TrackPanel::OnMouseEvent(wxMouseEvent & event) if (event.Leaving() && !event.ButtonIsDown(wxMOUSE_BTN_ANY)) { - SetCapturedTrack(NULL); + if (mMouseCapture != IsPanSliding && mMouseCapture != IsGainSliding) + { + SetCapturedTrack(NULL); #if defined(__WXMAC__) - // We must install the cursor ourselves since the window under - // the mouse is no longer this one and wx2.8.12 makes that check. - // Should re-evaluate with wx3. - wxSTANDARD_CURSOR->MacInstall(); + // We must install the cursor ourselves since the window under + // the mouse is no longer this one and wx2.8.12 makes that check. + // Should re-evaluate with wx3. + wxSTANDARD_CURSOR->MacInstall(); #endif + } } switch( mMouseCapture ) diff --git a/src/toolbars/DeviceToolBar.cpp b/src/toolbars/DeviceToolBar.cpp index ab5862f84..c7b3a206e 100644 --- a/src/toolbars/DeviceToolBar.cpp +++ b/src/toolbars/DeviceToolBar.cpp @@ -86,10 +86,6 @@ void DeviceToolBar::Create(wxWindow *parent) #endif } -void DeviceToolBar::RecreateTipWindows() -{ -} - void DeviceToolBar::DeinitChildren() { mInput = NULL; diff --git a/src/toolbars/DeviceToolBar.h b/src/toolbars/DeviceToolBar.h index 165e2a644..ba5374984 100644 --- a/src/toolbars/DeviceToolBar.h +++ b/src/toolbars/DeviceToolBar.h @@ -30,7 +30,6 @@ class DeviceToolBar:public ToolBar { void Create(wxWindow * parent); - void RecreateTipWindows(); void UpdatePrefs(); void DeinitChildren(); diff --git a/src/toolbars/MixerToolBar.cpp b/src/toolbars/MixerToolBar.cpp index e95cd52d1..5b3986013 100644 --- a/src/toolbars/MixerToolBar.cpp +++ b/src/toolbars/MixerToolBar.cpp @@ -75,13 +75,6 @@ void MixerToolBar::Create(wxWindow *parent) ToolBar::Create(parent); } -void MixerToolBar::RecreateTipWindows() -{ - // Hack to make sure they appear on top of other windows - mInputSlider->RecreateTipWin(); - mOutputSlider->RecreateTipWin(); -} - void MixerToolBar::Populate() { if( mRecordBitmap == NULL ) diff --git a/src/toolbars/MixerToolBar.h b/src/toolbars/MixerToolBar.h index 450a92a61..a9cbd6a8e 100644 --- a/src/toolbars/MixerToolBar.h +++ b/src/toolbars/MixerToolBar.h @@ -30,7 +30,6 @@ class MixerToolBar:public ToolBar { void Create(wxWindow * parent); - void RecreateTipWindows(); void UpdatePrefs(); void UpdateControls(); void SetMixer(wxCommandEvent &event); diff --git a/src/widgets/ASlider.cpp b/src/widgets/ASlider.cpp index 9a632f047..bd76aa21a 100644 --- a/src/widgets/ASlider.cpp +++ b/src/widgets/ASlider.cpp @@ -29,19 +29,11 @@ have a window permanently associated with it. *//****************************************************************//** \class TipPanel -\brief A wxPanel or a wxPopupWindow used to give the numerical value -of an LWSlider or ASlider. +\brief A wxPopupWindow used to give the numerical value of an LWSlider +or ASlider. *//*******************************************************************/ -// For compilers that support precompilation, includes "wx/wx.h". -#include - -#ifndef WX_PRECOMP -// Include your minimal set of headers here, or wx.h -#include -#endif - #include "../Audacity.h" @@ -63,18 +55,8 @@ of an LWSlider or ASlider. #include #include #include - -#ifndef __WXMAC__ -#define USE_POPUPWIN 1 -#endif - -#if USE_POPUPWIN #include -#endif - -#if defined(__WXMAC__) -#include -#endif +#include #include "../Experimental.h" #include "ASlider.h" @@ -102,128 +84,71 @@ const int sliderFontSize = 10; const int sliderFontSize = 12; #endif -wxWindow* LWSlider::sharedTipPanel; // // TipPanel // -#if USE_POPUPWIN class TipPanel : public wxPopupWindow -#else -// On the Mac we use a wxFrame since wxPopWindow isn't supported yet -class TipPanel : public wxFrame -#endif { public: - TipPanel(wxWindow * parent, wxWindowID id, - wxString label, - const wxPoint &pos); - virtual ~TipPanel(){} - void SetPos(const wxPoint &pos, wxString maxLabel); + TipPanel(const wxString & label); + virtual ~TipPanel() {} + void SetLabel(const wxString & label); + void SetPos(const wxPoint & pos); + +private: void OnPaint(wxPaintEvent & event); - void SetTargetParent( wxWindowBase *newParent ){mParent = (wxWindow*)newParent;} - - wxString label; - - wxWindow *mParent; -#ifdef USE_POPUPWIN - //wxwin won't let you create a wxPopupWindow without a parent frame. - //so we use a permanent offscreen dummy since projects can be deleted and their childs go with them. - static wxFrame* sharedDummyParent; -#endif +private: + wxString mMaxLabel; + wxString mLabel; + int mWidth; + int mHeight; DECLARE_EVENT_TABLE() }; -#if USE_POPUPWIN -#define kDummyOffsetX -32000 -#define kDummyOffsetY -32000 -wxFrame* TipPanel::sharedDummyParent; - BEGIN_EVENT_TABLE(TipPanel, wxPopupWindow) EVT_PAINT(TipPanel::OnPaint) END_EVENT_TABLE() -TipPanel::TipPanel(wxWindow *parent, wxWindowID WXUNUSED(id), - wxString label, const wxPoint &pos): -wxPopupWindow(TipPanel::sharedDummyParent) +TipPanel::TipPanel(const wxString & maxLabel) +: wxPopupWindow(NULL) { - this->label = label; - mParent = parent; - SetPos(pos, label); -} + mMaxLabel = maxLabel; -void TipPanel::SetPos(const wxPoint& pos, wxString maxLabel) -{ - int x = pos.x; - int y = pos.y; - -// if (mParent) -// mParent->ClientToScreen(&x,&y); - - wxClientDC dc(this); wxFont labelFont(sliderFontSize, wxSWISS, wxNORMAL, wxNORMAL); - dc.SetFont(labelFont); - int width, height; - dc.GetTextExtent(maxLabel, &width, &height); - height += 4; - SetSize(x - width/2, y, width, height); + + GetTextExtent(mMaxLabel, &mWidth, &mHeight, NULL, NULL, &labelFont); + + mWidth += 8; + mHeight += 8; } -#else - -BEGIN_EVENT_TABLE(TipPanel, wxFrame) - EVT_PAINT(TipPanel::OnPaint) -END_EVENT_TABLE() - -TipPanel::TipPanel(wxWindow *parent, wxWindowID id, - wxString label, - const wxPoint &pos): - wxFrame(NULL, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, - wxNO_BORDER | wxFRAME_NO_TASKBAR) +void TipPanel::SetPos(const wxPoint & pos) { - mParent = parent; - this->label = label; - SetPos(pos, label); + SetSize(pos.x - mWidth/2, pos.y, mWidth, mHeight); } -void TipPanel::SetPos(const wxPoint& pos, wxString maxLabel) +void TipPanel::SetLabel(const wxString & label) { - wxClientDC dc(this); - wxFont labelFont(sliderFontSize, wxSWISS, wxNORMAL, wxNORMAL); - dc.SetFont(labelFont); - int width, height; - dc.GetTextExtent(maxLabel, &width, &height); - width += 4; - height += 4; - int left = pos.x - width/2; - if (left < 0) - left = 0; - SetSize(left, pos.y, width, height); - Raise(); + mLabel = label; } -#endif - void TipPanel::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); - int width, height, textWidth, textHeight; - wxFont labelFont(sliderFontSize, wxSWISS, wxNORMAL, wxNORMAL); - dc.SetFont(labelFont); - GetClientSize(&width, &height); -#if defined(__WXMAC__) - dc.SetPen(AColor::tooltipBrush.GetColour()); -#else + dc.SetFont(wxFont(sliderFontSize, wxSWISS, wxNORMAL, wxNORMAL)); + dc.SetPen(*wxBLACK_PEN); -#endif dc.SetBrush(AColor::tooltipBrush); - dc.DrawRectangle(0, 0, width, height); - dc.GetTextExtent(label, &textWidth, &textHeight); - dc.DrawText(label, (width-textWidth)/2, (height-textHeight)/2); + dc.DrawRectangle(0, 0, mWidth, mHeight); + + int textWidth, textHeight; + dc.GetTextExtent(mLabel, &textWidth, &textHeight); + dc.DrawText(mLabel, (mWidth - textWidth) / 2, (mHeight - textHeight) / 2); } // @@ -486,12 +411,11 @@ void LWSlider::Init(wxWindow * parent, mThumbBitmapAllocated = false; mScrollLine = 1.0f; mScrollPage = 5.0f; + mTipPanel = NULL; mpRuler = NULL; // Do this and Move() before Draw(). Move(pos); Draw(); - - CreatePopWin(); } LWSlider::~LWSlider() @@ -501,6 +425,9 @@ LWSlider::~LWSlider() delete mThumbBitmap; } delete mpRuler; + if (mTipPanel) { + delete mTipPanel; + } } wxWindowID LWSlider::GetId() @@ -536,19 +463,9 @@ void LWSlider::SetScroll(float line, float page) mScrollPage = page; } -wxWindow* LWSlider::GetToolTipParent() const -{ - wxWindow *top = mParent; - while(top && top->GetParent()) { - top = top->GetParent(); - } - - return top; -} - void LWSlider::CreatePopWin() { - maxTipLabel = mName + wxT(": 000000"); + wxString maxTipLabel = mName + wxT(": 000000"); if (mStyle == PAN_SLIDER || mStyle == DB_SLIDER || mStyle == SPEED_SLIDER #ifdef EXPERIMENTAL_MIDI_OUT @@ -557,14 +474,7 @@ void LWSlider::CreatePopWin() ) maxTipLabel += wxT("000"); - - if(!LWSlider::sharedTipPanel) { -#ifdef USE_POPUPWIN - TipPanel::sharedDummyParent = new wxFrame(NULL, -1, wxT("offscreentip"), wxPoint(kDummyOffsetX, kDummyOffsetY)); -#endif - LWSlider::sharedTipPanel = new TipPanel(mParent, -1, maxTipLabel, wxDefaultPosition); - LWSlider::sharedTipPanel->Hide(); - } + mTipPanel = new TipPanel(maxTipLabel); } void LWSlider::SetPopWinPosition() @@ -576,8 +486,8 @@ void LWSlider::SetPopWinPosition() pt = wxPoint(mWidth + mLeft + 1, mHeight/2 + mTop); pt = mParent->ClientToScreen(pt); - if (LWSlider::sharedTipPanel) - ((TipPanel *)LWSlider::sharedTipPanel)->SetPos(pt, maxTipLabel); + if (mTipPanel) + mTipPanel->SetPos(pt); } void LWSlider::Move(const wxPoint &newpos) @@ -586,13 +496,6 @@ void LWSlider::Move(const wxPoint &newpos) mTop = newpos.y; } -void LWSlider::RecreateTipWin() -{ - LWSlider::sharedTipPanel->Destroy(); - LWSlider::sharedTipPanel = NULL; - CreatePopWin(); -} - void LWSlider::OnPaint(wxDC &dc, bool WXUNUSED(selected)) { //thumbPos should be in pixels @@ -623,8 +526,8 @@ void LWSlider::OnPaint(wxDC &dc, bool WXUNUSED(selected)) else dc.DrawBitmap(*mThumbBitmap, mLeft+thumbOrtho, mTop+thumbPos, true); - if (LWSlider::sharedTipPanel) - LWSlider::sharedTipPanel->Refresh(); + if (mTipPanel) + mTipPanel->Refresh(); } void LWSlider::OnSize( wxSizeEvent & event ) @@ -937,7 +840,7 @@ void LWSlider::FormatPopWin() #endif } - ((TipPanel *)LWSlider::sharedTipPanel)->label = label; + mTipPanel->SetLabel(label); } bool LWSlider::ShowDialog() @@ -981,17 +884,6 @@ bool LWSlider::DoShowDialog(wxPoint pos) return changed; } -void LWSlider::DeleteSharedTipPanel() -{ - if(LWSlider::sharedTipPanel) { - ((TipPanel*)LWSlider::sharedTipPanel)->Destroy(); -#ifdef USE_POPUPWIN - TipPanel::sharedDummyParent->Destroy(); -#endif - } - LWSlider::sharedTipPanel = NULL; -} - void LWSlider::OnMouseEvent(wxMouseEvent & event) { if (event.Entering()) { @@ -1076,11 +968,14 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event) if (!mParent->HasCapture()) { mParent->CaptureMouse(); } - // wxSetCursor(wxCURSOR_BLANK); - ((TipPanel*)LWSlider::sharedTipPanel)->SetTargetParent(mParent); + + wxASSERT(mTipPanel == NULL); + + CreatePopWin(); FormatPopWin(); SetPopWinPosition(); - LWSlider::sharedTipPanel->Show(); + mTipPanel->Show(); + //hide mouseover tooltip wxToolTip::Enable(false); } @@ -1089,10 +984,14 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event) mIsDragging = false; if (mParent->HasCapture()) mParent->ReleaseMouse(); - LWSlider::sharedTipPanel->Hide(); + + wxASSERT(mTipPanel != NULL); + + delete mTipPanel; + mTipPanel = NULL; + //restore normal tooltip behavor for mouseovers wxToolTip::Enable(true); - // wxSetCursor(wxNullCursor); } else if (event.Dragging() && mIsDragging) { @@ -1225,8 +1124,10 @@ void LWSlider::OnKeyEvent(wxKeyEvent & event) void LWSlider::SendUpdate( float newValue ) { mCurrentValue = newValue; + FormatPopWin(); - LWSlider::sharedTipPanel->Refresh(); + mTipPanel->Refresh(); + Refresh(); wxCommandEvent e( wxEVT_COMMAND_SLIDER_UPDATED, mID ); @@ -1546,11 +1447,6 @@ void ASlider::OnKillFocus(wxFocusEvent & WXUNUSED(event)) Refresh(); } -void ASlider::RecreateTipWin() -{ - mLWSlider->RecreateTipWin(); -} - void ASlider::GetScroll(float & line, float & page) { mLWSlider->GetScroll(line, page); diff --git a/src/widgets/ASlider.h b/src/widgets/ASlider.h index df52fdc1f..706d81cbb 100644 --- a/src/widgets/ASlider.h +++ b/src/widgets/ASlider.h @@ -31,6 +31,7 @@ class wxTextCtrl; class wxButton; class Ruler; +class TipPanel; // // Predefined slider types (mStyle) @@ -141,8 +142,6 @@ class LWSlider void OnKeyEvent(wxKeyEvent & event); void Refresh(); - void RecreateTipWin(); - bool ShowDialog(); bool ShowDialog(wxPoint pos); @@ -166,12 +165,8 @@ class LWSlider float DragPositionToValue(int fromPos, bool shiftDown); float ClickPositionToValue(int fromPos, bool shiftDown); - wxWindow* GetToolTipParent() const; - wxWindow *mParent; - wxString maxTipLabel; //string with the max num of chars for tip - int mStyle; int mOrientation; // wxHORIZONTAL or wxVERTICAL. wxVERTICAL is currently only for DB_SLIDER. @@ -222,8 +217,7 @@ class LWSlider wxWindowID mID; - //since we only need to show one tip at a time, just share one instance over all sliders. - static wxWindow* sharedTipPanel; + TipPanel *mTipPanel; Ruler* mpRuler; @@ -284,8 +278,6 @@ class ASlider :public wxPanel void OnSetFocus(wxFocusEvent & event); void OnKillFocus(wxFocusEvent & event); - void RecreateTipWin(); - // Overrides of the wxWindow functions with the same semantics bool Enable(bool enable = true); bool IsEnabled() const;