Fix errors in handling of maximum field in wxGenericProgressDialog.
Provide a SetMaximum() function for setting just m_maximum and return its value from GetRange() instead of using m_gauge->GetRange() which doesn't work when the native MSW version is used nor when the range is > USHRT_MAX under MSW in any case. More generally, this should fix a lot of bugs for progress dialogs using such range as the values were not interpreted correctly in many places. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65506 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -67,7 +67,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// This ctor is used by the native MSW implementation only.
|
// This ctor is used by the native MSW implementation only.
|
||||||
wxGenericProgressDialog(wxWindow *parent, int maximum, int style);
|
wxGenericProgressDialog(wxWindow *parent, int style);
|
||||||
|
|
||||||
void Create(const wxString& title,
|
void Create(const wxString& title,
|
||||||
const wxString& message,
|
const wxString& message,
|
||||||
@@ -75,6 +75,12 @@ protected:
|
|||||||
wxWindow *parent,
|
wxWindow *parent,
|
||||||
int style);
|
int style);
|
||||||
|
|
||||||
|
// Update just the m_maximum field, this is used by public SetRange() but,
|
||||||
|
// unlike it, doesn't update the controls state. This makes it useful for
|
||||||
|
// both this class and its derived classes that don't use m_gauge to
|
||||||
|
// display progress.
|
||||||
|
void SetMaximum(int maximum);
|
||||||
|
|
||||||
// Return the labels to use for showing the elapsed/estimated/remaining
|
// Return the labels to use for showing the elapsed/estimated/remaining
|
||||||
// times respectively.
|
// times respectively.
|
||||||
static wxString GetElapsedLabel() { return _("Elapsed time:"); }
|
static wxString GetElapsedLabel() { return _("Elapsed time:"); }
|
||||||
@@ -144,7 +150,7 @@ private:
|
|||||||
static void SetTimeLabel(unsigned long val, wxStaticText *label);
|
static void SetTimeLabel(unsigned long val, wxStaticText *label);
|
||||||
|
|
||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init(wxWindow *parent, int maximum, int style);
|
void Init(wxWindow *parent, int style);
|
||||||
|
|
||||||
// create the label with given text and another one to show the time nearby
|
// create the label with given text and another one to show the time nearby
|
||||||
// as the next windows in the sizer, returns the created control
|
// as the next windows in the sizer, returns the created control
|
||||||
|
@@ -87,29 +87,26 @@ wxIMPLEMENT_CLASS(wxProgressDialog, wxDialog)
|
|||||||
// wxGenericProgressDialog creation
|
// wxGenericProgressDialog creation
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxGenericProgressDialog::Init(wxWindow *parent, int maximum, int style)
|
void wxGenericProgressDialog::Init(wxWindow *parent, int style)
|
||||||
{
|
{
|
||||||
// Initialize the inherited members that we always use (even when we don't
|
|
||||||
// create a valid window here).
|
|
||||||
|
|
||||||
// we may disappear at any moment, let the others know about it
|
// we may disappear at any moment, let the others know about it
|
||||||
SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
|
SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
|
||||||
|
|
||||||
|
// Initialize all our members that we always use (even when we don't
|
||||||
|
// create a valid window in this class).
|
||||||
|
|
||||||
m_pdStyle = style;
|
m_pdStyle = style;
|
||||||
|
|
||||||
m_parentTop = wxGetTopLevelParent(parent);
|
m_parentTop = wxGetTopLevelParent(parent);
|
||||||
|
|
||||||
|
m_gauge = NULL;
|
||||||
|
m_msg = NULL;
|
||||||
|
m_elapsed =
|
||||||
|
m_estimated =
|
||||||
|
m_remaining = NULL;
|
||||||
|
|
||||||
// Initialize our own members.
|
|
||||||
m_state = Uncancelable;
|
m_state = Uncancelable;
|
||||||
m_maximum = maximum;
|
m_maximum = 0;
|
||||||
|
|
||||||
#if defined(__WXMSW__) || defined(__WXPM__)
|
|
||||||
// we can't have values > 65,536 in the progress control under Windows, so
|
|
||||||
// scale everything down
|
|
||||||
m_factor = m_maximum / 65536 + 1;
|
|
||||||
m_maximum /= m_factor;
|
|
||||||
#endif // __WXMSW__
|
|
||||||
|
|
||||||
|
|
||||||
m_timeStart = wxGetCurrentTime();
|
m_timeStart = wxGetCurrentTime();
|
||||||
m_timeStop = (unsigned long)-1;
|
m_timeStop = (unsigned long)-1;
|
||||||
@@ -127,12 +124,10 @@ void wxGenericProgressDialog::Init(wxWindow *parent, int maximum, int style)
|
|||||||
m_tempEventLoop = NULL;
|
m_tempEventLoop = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGenericProgressDialog::wxGenericProgressDialog(wxWindow *parent,
|
wxGenericProgressDialog::wxGenericProgressDialog(wxWindow *parent, int style)
|
||||||
int maximum,
|
|
||||||
int style)
|
|
||||||
: wxDialog()
|
: wxDialog()
|
||||||
{
|
{
|
||||||
Init(parent, maximum, style);
|
Init(parent, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGenericProgressDialog::wxGenericProgressDialog(const wxString& title,
|
wxGenericProgressDialog::wxGenericProgressDialog(const wxString& title,
|
||||||
@@ -142,7 +137,7 @@ wxGenericProgressDialog::wxGenericProgressDialog(const wxString& title,
|
|||||||
int style)
|
int style)
|
||||||
: wxDialog()
|
: wxDialog()
|
||||||
{
|
{
|
||||||
Init(parent, maximum, style);
|
Init(parent, style);
|
||||||
|
|
||||||
Create( title, message, maximum, parent, style );
|
Create( title, message, maximum, parent, style );
|
||||||
}
|
}
|
||||||
@@ -158,6 +153,8 @@ void wxGenericProgressDialog::Create( const wxString& title,
|
|||||||
SetParent( GetParentForModalDialog(parent, style) );
|
SetParent( GetParentForModalDialog(parent, style) );
|
||||||
SetTitle( title );
|
SetTitle( title );
|
||||||
|
|
||||||
|
SetMaximum(maximum);
|
||||||
|
|
||||||
// We need a running event loop in order to update the dialog and be able
|
// We need a running event loop in order to update the dialog and be able
|
||||||
// to process clicks on its buttons, so ensure that there is one running
|
// to process clicks on its buttons, so ensure that there is one running
|
||||||
// even if this means we have to start it ourselves (this happens most
|
// even if this means we have to start it ourselves (this happens most
|
||||||
@@ -192,29 +189,27 @@ void wxGenericProgressDialog::Create( const wxString& title,
|
|||||||
m_msg = new wxStaticText(this, wxID_ANY, message);
|
m_msg = new wxStaticText(this, wxID_ANY, message);
|
||||||
sizerTop->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN);
|
sizerTop->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN);
|
||||||
|
|
||||||
if ( maximum > 0 )
|
int gauge_style = wxGA_HORIZONTAL;
|
||||||
{
|
if ( style & wxPD_SMOOTH )
|
||||||
int gauge_style = wxGA_HORIZONTAL;
|
gauge_style |= wxGA_SMOOTH;
|
||||||
if ( style & wxPD_SMOOTH )
|
|
||||||
gauge_style |= wxGA_SMOOTH;
|
|
||||||
m_gauge = new wxGauge
|
|
||||||
(
|
|
||||||
this,
|
|
||||||
wxID_ANY,
|
|
||||||
m_maximum,
|
|
||||||
wxDefaultPosition,
|
|
||||||
// make the progress bar sufficiently long
|
|
||||||
wxSize(wxMin(wxGetClientDisplayRect().width/3, 300), -1),
|
|
||||||
gauge_style
|
|
||||||
);
|
|
||||||
|
|
||||||
sizerTop->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN);
|
#ifdef __WXMSW__
|
||||||
m_gauge->SetValue(0);
|
maximum /= m_factor;
|
||||||
}
|
#endif
|
||||||
else
|
|
||||||
{
|
m_gauge = new wxGauge
|
||||||
m_gauge = NULL;
|
(
|
||||||
}
|
this,
|
||||||
|
wxID_ANY,
|
||||||
|
maximum,
|
||||||
|
wxDefaultPosition,
|
||||||
|
// make the progress bar sufficiently long
|
||||||
|
wxSize(wxMin(wxGetClientDisplayRect().width/3, 300), -1),
|
||||||
|
gauge_style
|
||||||
|
);
|
||||||
|
|
||||||
|
sizerTop->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN);
|
||||||
|
m_gauge->SetValue(0);
|
||||||
|
|
||||||
// create the estimated/remaining/total time zones if requested
|
// create the estimated/remaining/total time zones if requested
|
||||||
m_elapsed =
|
m_elapsed =
|
||||||
@@ -416,7 +411,7 @@ wxGenericProgressDialog::Update(int value, const wxString& newmsg, bool *skip)
|
|||||||
if ( !DoBeforeUpdate(skip) )
|
if ( !DoBeforeUpdate(skip) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wxASSERT_MSG( value == -1 || m_gauge, wxT("cannot update non existent dialog") );
|
wxCHECK_MSG( m_gauge, false, "dialog should be fully created" );
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
value /= m_factor;
|
value /= m_factor;
|
||||||
@@ -424,8 +419,7 @@ wxGenericProgressDialog::Update(int value, const wxString& newmsg, bool *skip)
|
|||||||
|
|
||||||
wxASSERT_MSG( value <= m_maximum, wxT("invalid progress value") );
|
wxASSERT_MSG( value <= m_maximum, wxT("invalid progress value") );
|
||||||
|
|
||||||
if ( m_gauge )
|
m_gauge->SetValue(value);
|
||||||
m_gauge->SetValue(value);
|
|
||||||
|
|
||||||
UpdateMessage(newmsg);
|
UpdateMessage(newmsg);
|
||||||
|
|
||||||
@@ -508,7 +502,7 @@ bool wxGenericProgressDialog::Pulse(const wxString& newmsg, bool *skip)
|
|||||||
if ( !DoBeforeUpdate(skip) )
|
if ( !DoBeforeUpdate(skip) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wxASSERT_MSG( m_gauge, wxT("cannot update non existent dialog") );
|
wxCHECK_MSG( m_gauge, false, "dialog should be fully created" );
|
||||||
|
|
||||||
// show a bit of progress
|
// show a bit of progress
|
||||||
m_gauge->Pulse();
|
m_gauge->Pulse();
|
||||||
@@ -581,16 +575,14 @@ bool wxGenericProgressDialog::Show( bool show )
|
|||||||
|
|
||||||
int wxGenericProgressDialog::GetValue() const
|
int wxGenericProgressDialog::GetValue() const
|
||||||
{
|
{
|
||||||
if (m_gauge)
|
wxCHECK_MSG( m_gauge, -1, "dialog should be fully created" );
|
||||||
return m_gauge->GetValue();
|
|
||||||
return wxNOT_FOUND;
|
return m_gauge->GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxGenericProgressDialog::GetRange() const
|
int wxGenericProgressDialog::GetRange() const
|
||||||
{
|
{
|
||||||
if (m_gauge)
|
return m_maximum;
|
||||||
return m_gauge->GetRange();
|
|
||||||
return wxNOT_FOUND;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxGenericProgressDialog::GetMessage() const
|
wxString wxGenericProgressDialog::GetMessage() const
|
||||||
@@ -600,17 +592,23 @@ wxString wxGenericProgressDialog::GetMessage() const
|
|||||||
|
|
||||||
void wxGenericProgressDialog::SetRange(int maximum)
|
void wxGenericProgressDialog::SetRange(int maximum)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG(m_gauge, "The dialog should have been constructed with a range > 0");
|
wxCHECK_RET( m_gauge, "dialog should be fully created" );
|
||||||
wxASSERT_MSG(maximum > 0, "Invalid range");
|
|
||||||
|
wxCHECK_RET( maximum > 0, "Invalid range" );
|
||||||
|
|
||||||
m_gauge->SetRange(maximum);
|
m_gauge->SetRange(maximum);
|
||||||
|
|
||||||
|
SetMaximum(maximum);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGenericProgressDialog::SetMaximum(int maximum)
|
||||||
|
{
|
||||||
m_maximum = maximum;
|
m_maximum = maximum;
|
||||||
|
|
||||||
#if defined(__WXMSW__) || defined(__WXPM__)
|
#if defined(__WXMSW__) || defined(__WXPM__)
|
||||||
// we can't have values > 65,536 in the progress control under Windows, so
|
// we can't have values > 65,536 in the progress control under Windows, so
|
||||||
// scale everything down
|
// scale everything down
|
||||||
m_factor = m_maximum / 65536 + 1;
|
m_factor = m_maximum / 65536 + 1;
|
||||||
m_maximum /= m_factor;
|
|
||||||
#endif // __WXMSW__
|
#endif // __WXMSW__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -275,7 +275,7 @@ wxProgressDialog::wxProgressDialog( const wxString& title,
|
|||||||
int maximum,
|
int maximum,
|
||||||
wxWindow *parent,
|
wxWindow *parent,
|
||||||
int style )
|
int style )
|
||||||
: wxGenericProgressDialog(parent, maximum, style),
|
: wxGenericProgressDialog(parent, style),
|
||||||
m_taskDialogRunner(NULL),
|
m_taskDialogRunner(NULL),
|
||||||
m_sharedData(NULL),
|
m_sharedData(NULL),
|
||||||
m_message(message),
|
m_message(message),
|
||||||
@@ -284,6 +284,8 @@ wxProgressDialog::wxProgressDialog( const wxString& title,
|
|||||||
#ifdef wxHAS_MSW_TASKDIALOG
|
#ifdef wxHAS_MSW_TASKDIALOG
|
||||||
if ( HasNativeProgressDialog() )
|
if ( HasNativeProgressDialog() )
|
||||||
{
|
{
|
||||||
|
SetMaximum(maximum);
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
DisableOtherWindows();
|
DisableOtherWindows();
|
||||||
|
|
||||||
@@ -501,17 +503,21 @@ wxString wxProgressDialog::GetMessage() const
|
|||||||
|
|
||||||
void wxProgressDialog::SetRange(int maximum)
|
void wxProgressDialog::SetRange(int maximum)
|
||||||
{
|
{
|
||||||
wxGenericProgressDialog::SetRange( maximum );
|
|
||||||
|
|
||||||
#ifdef wxHAS_MSW_TASKDIALOG
|
#ifdef wxHAS_MSW_TASKDIALOG
|
||||||
if ( HasNativeProgressDialog() )
|
if ( HasNativeProgressDialog() )
|
||||||
{
|
{
|
||||||
|
SetMaximum(maximum);
|
||||||
|
|
||||||
wxCriticalSectionLocker locker(m_sharedData->m_cs);
|
wxCriticalSectionLocker locker(m_sharedData->m_cs);
|
||||||
|
|
||||||
m_sharedData->m_range = maximum;
|
m_sharedData->m_range = maximum;
|
||||||
m_sharedData->m_notifications |= wxSPDD_RANGE_CHANGED;
|
m_sharedData->m_notifications |= wxSPDD_RANGE_CHANGED;
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
#endif // wxHAS_MSW_TASKDIALOG
|
#endif // wxHAS_MSW_TASKDIALOG
|
||||||
|
|
||||||
|
wxGenericProgressDialog::SetRange( maximum );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxProgressDialog::WasSkipped() const
|
bool wxProgressDialog::WasSkipped() const
|
||||||
|
Reference in New Issue
Block a user