// Author: Karsten Ballueder
// Modified by:
// Created: 09.05.1999
-// RCS-ID: $Id$
// Copyright: (c) Karsten Ballueder
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// wxGenericProgressDialog creation
// ----------------------------------------------------------------------------
-void wxGenericProgressDialog::Init(wxWindow *parent, int maximum, int style)
+void wxGenericProgressDialog::Init()
{
- // 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
SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
- m_pdStyle = style;
-
- m_parentTop = wxGetTopLevelParent(parent);
+ // Initialize all our members that we always use (even when we don't
+ // create a valid window in this class).
- // Initialize our own members.
- m_state = Uncancelable;
- m_maximum = maximum;
+ m_pdStyle = 0;
+ m_parentTop = NULL;
-#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_gauge = NULL;
+ m_msg = NULL;
+ m_elapsed =
+ m_estimated =
+ m_remaining = NULL;
+ m_state = Uncancelable;
+ m_maximum = 0;
m_timeStart = wxGetCurrentTime();
m_timeStop = (unsigned long)-1;
m_skip = false;
+#if !defined(__SMARTPHONE__)
+ m_btnAbort =
+ m_btnSkip = NULL;
+#endif
+
m_display_estimated =
m_last_timeupdate =
m_ctdelay = 0;
m_tempEventLoop = NULL;
}
-wxGenericProgressDialog::wxGenericProgressDialog(wxWindow *parent,
- int maximum,
- int style)
+wxGenericProgressDialog::wxGenericProgressDialog()
: wxDialog()
{
- Init(parent, maximum, style);
+ Init();
}
wxGenericProgressDialog::wxGenericProgressDialog(const wxString& title,
int style)
: wxDialog()
{
- Init(parent, maximum, style);
+ Init();
Create( title, message, maximum, parent, style );
}
-void wxGenericProgressDialog::Create( const wxString& title,
+void wxGenericProgressDialog::SetTopParent(wxWindow* parent)
+{
+ m_parentTop = GetParentForModalDialog(parent, GetWindowStyle());
+}
+
+bool wxGenericProgressDialog::Create( const wxString& title,
const wxString& message,
int maximum,
wxWindow *parent,
int style )
{
- wxDialog::Create(GetParentForModalDialog(parent, style), wxID_ANY, title);
+ SetTopParent(parent);
+
+ m_parentTop = wxGetTopLevelParent(parent);
+ m_pdStyle = style;
+
+ wxWindow* const
+ realParent = GetParentForModalDialog(parent, GetWindowStyle());
+
+ if (!wxDialog::Create(realParent, wxID_ANY, title))
+ return false;
- SetParent( GetParentForModalDialog(parent, style) );
- SetTitle( title );
+ SetMaximum(maximum);
// 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
m_msg = new wxStaticText(this, wxID_ANY, message);
sizerTop->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN);
- if ( maximum > 0 )
- {
- int gauge_style = wxGA_HORIZONTAL;
- 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);
- m_gauge->SetValue(0);
- }
- else
- {
- m_gauge = NULL;
- }
+ int gauge_style = wxGA_HORIZONTAL;
+ if ( style & wxPD_SMOOTH )
+ gauge_style |= wxGA_SMOOTH;
+
+#ifdef __WXMSW__
+ maximum /= m_factor;
+#endif
+
+ m_gauge = new wxGauge
+ (
+ 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
m_elapsed =
// Windows dialogs usually have buttons in the lower right corner
const int sizerFlags =
-#if defined(__WXMSW__) || defined(__WXPM__)
+#if defined(__WXMSW__) || defined(__WXPM__) || defined(__WXOSX__)
wxALIGN_RIGHT | wxALL
#else // !MSW
wxALIGN_CENTER_HORIZONTAL | wxBOTTOM | wxTOP
}
Update();
+ return true;
}
void wxGenericProgressDialog::UpdateTimeEstimates(int value,
if ( !DoBeforeUpdate(skip) )
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__
value /= m_factor;
wxASSERT_MSG( value <= m_maximum, wxT("invalid progress value") );
- if ( m_gauge )
- m_gauge->SetValue(value);
+ m_gauge->SetValue(value);
UpdateMessage(newmsg);
if ( !DoBeforeUpdate(skip) )
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
m_gauge->Pulse();
int wxGenericProgressDialog::GetValue() const
{
- if (m_gauge)
- return m_gauge->GetValue();
- return wxNOT_FOUND;
+ wxCHECK_MSG( m_gauge, -1, "dialog should be fully created" );
+
+ return m_gauge->GetValue();
}
int wxGenericProgressDialog::GetRange() const
{
- if (m_gauge)
- return m_gauge->GetRange();
- return wxNOT_FOUND;
+ return m_maximum;
}
wxString wxGenericProgressDialog::GetMessage() const
void wxGenericProgressDialog::SetRange(int maximum)
{
- wxASSERT_MSG(m_gauge, "The dialog should have been constructed with a range > 0");
- wxASSERT_MSG(maximum > 0, "Invalid range");
+ wxCHECK_RET( m_gauge, "dialog should be fully created" );
+
+ wxCHECK_RET( maximum > 0, "Invalid range" );
m_gauge->SetRange(maximum);
+
+ SetMaximum(maximum);
+}
+
+void wxGenericProgressDialog::SetMaximum(int maximum)
+{
m_maximum = maximum;
#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__
}