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
This commit is contained in:
Vadim Zeitlin
2006-10-22 21:08:11 +00:00
parent 2baa2b0eef
commit f4aa7ec32b
4 changed files with 48 additions and 20 deletions

View File

@@ -70,6 +70,7 @@ All (GUI):
calling SelectObject itself if a valid bitmap is passed. calling SelectObject itself if a valid bitmap is passed.
- Reverted wxBuffered[Paint]DC to pre 2.7.1 state, added - Reverted wxBuffered[Paint]DC to pre 2.7.1 state, added
wxAutoBufferedPaintDC and wxAutoBufferedPaintDCFactory. wxAutoBufferedPaintDC and wxAutoBufferedPaintDCFactory.
- Renamed wxProgressDialog::UpdatePulse() to just Pulse()
Unix Ports: Unix Ports:

View File

@@ -56,7 +56,7 @@ public:
/* Switches the dialog to use a gauge in indeterminate mode and calls /* Switches the dialog to use a gauge in indeterminate mode and calls
wxGauge::Pulse() to show to the user a bit of progress */ 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) // Must provide overload to avoid hiding it (and warnings about it)
virtual void Update() { wxDialog::Update(); } virtual void Update() { wxDialog::Update(); }
@@ -91,6 +91,9 @@ private:
// updates the label message // updates the label message
void UpdateMessage(const wxString &newmsg); void UpdateMessage(const wxString &newmsg);
// common part of Update() and Pulse(), returns true if not cancelled
bool DoAfterUpdate(bool *skip);
// shortcuts for enabling buttons // shortcuts for enabling buttons
void EnableClose(); void EnableClose();
void EnableSkip(bool enable=true); void EnableSkip(bool enable=true);

View File

@@ -1108,8 +1108,9 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
// wxPD_AUTO_HIDE | -- try this as well // wxPD_AUTO_HIDE | -- try this as well
wxPD_ELAPSED_TIME | wxPD_ELAPSED_TIME |
wxPD_ESTIMATED_TIME | wxPD_ESTIMATED_TIME |
wxPD_REMAINING_TIME | wxPD_REMAINING_TIME
wxPD_SMOOTH); //wxPD_SMOOTH - makes indeterminate mode bar on WinXP very small
);
bool cont = true; bool cont = true;
bool skip = false; bool skip = false;
@@ -1138,15 +1139,29 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
wxString msg; 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 ) if ( i == max )
{ {
msg = _T("That's all, folks!"); msg = _T("That's all, folks!");
} }
else if ( i > max / 2 ) else if ( indeterminate )
{ {
msg = _T("Only a half left (very long message)!"); msg = _T("Now test indeterminate mode");
}
else if ( i > secondpart )
{
msg = _T("Back to determinate mode");
} }
if (determinate)
{
#if wxUSE_STOPWATCH && wxUSE_LONGLONG #if wxUSE_STOPWATCH && wxUSE_LONGLONG
if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster
{ {
@@ -1155,6 +1170,18 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
#else #else
cont = dialog.Update(i, msg, &skip); cont = dialog.Update(i, msg, &skip);
#endif #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 ) if ( !cont )
{ {

View File

@@ -438,18 +438,9 @@ wxProgressDialog::Update(int value, const wxString& newmsg, bool *skip)
Hide(); Hide();
} }
} }
else else // not at maximum yet
{ {
// we have to yield because not only we want to update the display but return DoAfterUpdate(skip);
// 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();
}
} }
// update the display in case yielding above didn't do it // 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; return m_state != Canceled;
} }
bool bool wxProgressDialog::Pulse(const wxString& newmsg, bool *skip)
wxProgressDialog::UpdatePulse(const wxString& newmsg, bool *skip)
{ {
wxASSERT_MSG( m_gauge, wxT("cannot update non existent dialog") ); 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); 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 // 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 // also to process the clicks on the cancel and skip buttons
wxYieldIfNeeded() ; wxYieldIfNeeded();
if ( (m_skip) && (skip != NULL) && (*skip == false) ) Update();
if ( m_skip && skip && !*skip )
{ {
*skip = true; *skip = true;
m_skip = false; m_skip = false;