From 046d3be2156e28e332019e532b74d9d84b8db2f7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 28 Oct 2017 19:31:30 +0200 Subject: [PATCH] Don't require calling DoNativeBeforeUpdate() with locked CS Acquire the lock in wxProgressDialog::DoNativeBeforeUpdate() itself instead of relying on the caller to do it. This is just a refactoring in preparation for further changes. --- include/wx/msw/progdlg.h | 5 +++-- src/msw/progdlg.cpp | 28 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/wx/msw/progdlg.h b/include/wx/msw/progdlg.h index f073c66060..46650bd9c3 100644 --- a/include/wx/msw/progdlg.h +++ b/include/wx/msw/progdlg.h @@ -54,8 +54,9 @@ public: virtual WXWidget GetHandle() const wxOVERRIDE; private: - // Performs common routines to Update() and Pulse(). Requires the - // shared object to have been entered. + // Common part of Update() and Pulse(). + // + // Returns false if the user requested cancelling the dialog. bool DoNativeBeforeUpdate(bool *skip); // Updates the various timing informations for both determinate diff --git a/src/msw/progdlg.cpp b/src/msw/progdlg.cpp index cfb9338bd0..dd497efd93 100644 --- a/src/msw/progdlg.cpp +++ b/src/msw/progdlg.cpp @@ -404,17 +404,19 @@ bool wxProgressDialog::Update(int value, const wxString& newmsg, bool *skip) #ifdef wxHAS_MSW_TASKDIALOG if ( HasNativeTaskDialog() ) { + if ( !DoNativeBeforeUpdate(skip) ) + { + // Dialog was cancelled. + return false; + } + + value /= m_factor; + + wxASSERT_MSG( value <= m_maximum, wxT("invalid progress value") ); + { wxCriticalSectionLocker locker(m_sharedData->m_cs); - // Do nothing in canceled state. - if ( !DoNativeBeforeUpdate(skip) ) - return false; - - value /= m_factor; - - wxASSERT_MSG( value <= m_maximum, wxT("invalid progress value") ); - m_sharedData->m_value = value; m_sharedData->m_notifications |= wxSPDD_VALUE_CHANGED; @@ -474,11 +476,13 @@ bool wxProgressDialog::Pulse(const wxString& newmsg, bool *skip) #ifdef wxHAS_MSW_TASKDIALOG if ( HasNativeTaskDialog() ) { - wxCriticalSectionLocker locker(m_sharedData->m_cs); - - // Do nothing in canceled state. if ( !DoNativeBeforeUpdate(skip) ) + { + // Dialog was cancelled. return false; + } + + wxCriticalSectionLocker locker(m_sharedData->m_cs); if ( !m_sharedData->m_progressBarMarquee ) { @@ -509,6 +513,8 @@ bool wxProgressDialog::DoNativeBeforeUpdate(bool *skip) #ifdef wxHAS_MSW_TASKDIALOG if ( HasNativeTaskDialog() ) { + wxCriticalSectionLocker locker(m_sharedData->m_cs); + if ( m_sharedData->m_skipped ) { if ( skip && !*skip )