mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 17:49:45 +02:00
Some uses of wxWindowRef, a weak pointer that won't become dangling
This commit is contained in:
parent
703bf2b647
commit
0dddcf44cb
@ -90,7 +90,7 @@ private:
|
||||
ToolBar *mBar;
|
||||
wxPoint mResizeOffset;
|
||||
wxSize mOrigSize;
|
||||
wxWindow *mOrigFocus{};
|
||||
wxWindowRef mOrigFocus{};
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
@ -634,15 +634,9 @@ int ToolManager::FilterEvent(wxEvent &event)
|
||||
!dynamic_cast<Grabber*>( window ) &&
|
||||
!dynamic_cast<ToolFrame*>( window ) &&
|
||||
top == mParent )
|
||||
// Note this is a dangle-proof wxWindowRef:
|
||||
mLastFocus = window;
|
||||
}
|
||||
else if (event.GetEventType() == wxEVT_DESTROY) {
|
||||
auto &closeEvent = static_cast<wxWindowDestroyEvent&>(event);
|
||||
auto window = closeEvent.GetEventObject();
|
||||
if (window == mLastFocus)
|
||||
// Avoid a dangling pointer!
|
||||
mLastFocus = nullptr;
|
||||
}
|
||||
|
||||
return Event_Skip;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class ToolManager final : public wxEvtHandler, public wxEventFilter
|
||||
void Updated();
|
||||
|
||||
AudacityProject *mParent;
|
||||
wxWindow *mLastFocus{};
|
||||
wxWindowRef mLastFocus{};
|
||||
|
||||
ToolFrame *mDragWindow;
|
||||
ToolDock *mDragDock;
|
||||
|
@ -1043,10 +1043,8 @@ ProgressDialog::~ProgressDialog()
|
||||
|
||||
// Restore saved focus, but only if the window still exists.
|
||||
//
|
||||
// It is possible that it was a deferred deletion and it was deleted since
|
||||
// we captured the focused window. So, we need to verify that the window
|
||||
// still exists by searching all of the wxWidgets windows. It's the only
|
||||
// sure way.
|
||||
// PRL: I'm conservatively preserving the old existence test, but I think
|
||||
// it's redundant now that we use wxWindowRef to avoid a dangling pointer
|
||||
if (mHadFocus && SearchForWindow(wxTopLevelWindows, mHadFocus)) {
|
||||
mHadFocus->SetFocus();
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public:
|
||||
void SetMessage(const wxString & message);
|
||||
|
||||
protected:
|
||||
wxWeakRef<wxWindow> mHadFocus;
|
||||
wxWindowRef mHadFocus;
|
||||
|
||||
wxStaticText *mElapsed;
|
||||
wxStaticText *mRemaining;
|
||||
|
Loading…
x
Reference in New Issue
Block a user