From: Vadim Zeitlin Date: Sun, 22 Oct 2006 21:08:11 +0000 (+0000) Subject: small refactoring to avoid code duplication; renamed wxProgressDialog::UpdatePulse... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f4aa7ec32b0e9181888f1bc9b291bb21d0e16561 small refactoring to avoid code duplication; renamed wxProgressDialog::UpdatePulse() to just Pulse(); added test for it in the dialogs sample (part of the patch 1551409 which somehow wasn't applied before) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42253 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index abaf9f64fa..5afdfed18b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -70,6 +70,7 @@ All (GUI): calling SelectObject itself if a valid bitmap is passed. - Reverted wxBuffered[Paint]DC to pre 2.7.1 state, added wxAutoBufferedPaintDC and wxAutoBufferedPaintDCFactory. +- Renamed wxProgressDialog::UpdatePulse() to just Pulse() Unix Ports: diff --git a/include/wx/generic/progdlgg.h b/include/wx/generic/progdlgg.h index 44467b1836..24f25446cc 100644 --- a/include/wx/generic/progdlgg.h +++ b/include/wx/generic/progdlgg.h @@ -56,7 +56,7 @@ public: /* Switches the dialog to use a gauge in indeterminate mode and calls wxGauge::Pulse() to show to the user a bit of progress */ - virtual bool UpdatePulse(const wxString& newmsg = wxEmptyString, bool *skip = NULL); + virtual bool Pulse(const wxString& newmsg = wxEmptyString, bool *skip = NULL); // Must provide overload to avoid hiding it (and warnings about it) virtual void Update() { wxDialog::Update(); } @@ -91,6 +91,9 @@ private: // updates the label message void UpdateMessage(const wxString &newmsg); + // common part of Update() and Pulse(), returns true if not cancelled + bool DoAfterUpdate(bool *skip); + // shortcuts for enabling buttons void EnableClose(); void EnableSkip(bool enable=true); diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 8f39a054ab..605ea505a6 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -1108,8 +1108,9 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) // wxPD_AUTO_HIDE | -- try this as well wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | - wxPD_REMAINING_TIME | - wxPD_SMOOTH); + wxPD_REMAINING_TIME + //wxPD_SMOOTH - makes indeterminate mode bar on WinXP very small + ); bool cont = true; bool skip = false; @@ -1138,15 +1139,29 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) wxString msg; + // test both behaviours of wxProgressDialog: + // determinate mode for first 33% and last 33% of the time + // indeterminate mode from 33% to 66% of the progress + const int firstpart = max /3, + secondpart = 2 * max /3; + bool determinate = i < firstpart || i > secondpart; + bool indeterminate = !determinate; + if ( i == max ) { msg = _T("That's all, folks!"); } - else if ( i > max / 2 ) + else if ( indeterminate ) + { + msg = _T("Now test indeterminate mode"); + } + else if ( i > secondpart ) { - msg = _T("Only a half left (very long message)!"); + msg = _T("Back to determinate mode"); } + if (determinate) + { #if wxUSE_STOPWATCH && wxUSE_LONGLONG if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster { @@ -1155,6 +1170,18 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) #else cont = dialog.Update(i, msg, &skip); #endif + } + else + { +#if wxUSE_STOPWATCH && wxUSE_LONGLONG + if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster + { + cont = dialog.Pulse(msg, &skip); + } +#else + cont = dialog.Pulse(msg, &skip); +#endif + } if ( !cont ) { diff --git a/src/generic/progdlgg.cpp b/src/generic/progdlgg.cpp index cffe7fce24..7541a816bb 100644 --- a/src/generic/progdlgg.cpp +++ b/src/generic/progdlgg.cpp @@ -438,18 +438,9 @@ wxProgressDialog::Update(int value, const wxString& newmsg, bool *skip) Hide(); } } - else + else // not at maximum yet { - // we have to yield because not only we want to update the display but - // also to process the clicks on the cancel and skip buttons - wxYieldIfNeeded() ; - - if ( (m_skip) && (skip != NULL) && (*skip == false) ) - { - *skip = true; - m_skip = false; - EnableSkip(); - } + return DoAfterUpdate(skip); } // update the display in case yielding above didn't do it @@ -458,8 +449,7 @@ wxProgressDialog::Update(int value, const wxString& newmsg, bool *skip) return m_state != Canceled; } -bool -wxProgressDialog::UpdatePulse(const wxString& newmsg, bool *skip) +bool wxProgressDialog::Pulse(const wxString& newmsg, bool *skip) { wxASSERT_MSG( m_gauge, wxT("cannot update non existent dialog") ); @@ -477,11 +467,18 @@ wxProgressDialog::UpdatePulse(const wxString& newmsg, bool *skip) SetTimeLabel((unsigned long)-1, m_remaining); } + return DoAfterUpdate(skip); +} + +bool wxProgressDialog::DoAfterUpdate(bool *skip) +{ // we have to yield because not only we want to update the display but // also to process the clicks on the cancel and skip buttons - wxYieldIfNeeded() ; + wxYieldIfNeeded(); + + Update(); - if ( (m_skip) && (skip != NULL) && (*skip == false) ) + if ( m_skip && skip && !*skip ) { *skip = true; m_skip = false;