/** Can be called to continue after the cancel button has been pressed, but
the program decided to continue the operation (e.g., user didn't
- configrm it)
+ confirm it)
*/
void Resume() { m_state = Continue; }
{
Uncancelable = -1, // dialog can't be canceled
Canceled, // can be cancelled and, in fact, was
- Continue // can be cancelled but wasn't
+ Continue, // can be cancelled but wasn't
+ Finished // finished, waiting to be removed from screen
} m_state;
+ /// the abort button (or NULL if none)
+ wxButton *m_btnAbort;
+ /// the maximum value
+ int m_maximum;
DECLARE_EVENT_TABLE()
};
"An informative message",
max, // range
this, // parent
- FALSE, // modal
- TRUE); // has abort button
+ wxPD_CAN_ABORT | wxPD_APP_MODAL);
+
bool cont = TRUE;
for ( int i = 0; i < max && cont; i++ )
{
wxSleep(1);
- if ( i == max / 2 )
+ if ( i == max - 1 )
+ {
+ cont = dialog.Update(i, "That's all, folks!");
+ }
+ else if ( i == max / 2 )
{
cont = dialog.Update(i, "Only a half left!");
}
m_state = hasAbortButton ? Continue : Uncancelable;
m_disableParentOnly = (style & wxPD_APP_MODAL) == 0;
m_parent = parent;
+ m_maximum = maximum;
int height = 70; // FIXME arbitrary numbers
if ( hasAbortButton )
m_gauge->SetValue(0);
}
else
- m_gauge = NULL;
+ m_gauge = (wxGauge *)NULL;
if ( hasAbortButton )
{
- wxControl *ctrl = new wxButton(this, -1, _("Cancel"));
+ m_btnAbort = new wxButton(this, -1, _("Cancel"));
c = new wxLayoutConstraints;
c->centreX.SameAs(this, wxCentreX);
if(m_gauge)
c->top.Below(m_gauge, 2*LAYOUT_Y_MARGIN);
else
- c->top.Below(ctrl, 2*LAYOUT_Y_MARGIN);
+ c->top.Below(m_btnAbort, 2*LAYOUT_Y_MARGIN);
c->width.AsIs();
c->height.AsIs();
- ctrl->SetConstraints(c);
+ m_btnAbort->SetConstraints(c);
}
+ else
+ m_btnAbort = (wxButton *)NULL;
SetAutoLayout(TRUE);
Show(TRUE);
wxProgressDialog::Update(int value, const wxString& newmsg)
{
wxASSERT_MSG( value == -1 || m_gauge, "can't update non existent dialog" );
+ wxASSERT_MSG( value < m_maximum, "invalid progress value" );
if( m_gauge )
- m_gauge->SetValue(value);
- if( !newmsg.IsNull() )
+ m_gauge->SetValue(value + 1);
+ if( !newmsg.IsEmpty() )
m_msg->SetLabel(newmsg);
wxYield();
+ if ( (value == m_maximum - 1) && !(GetWindowStyleFlag() & wxPD_AUTO_HIDE) )
+ {
+ if ( m_btnAbort )
+ {
+ // tell the user what he should do...
+ m_btnAbort->SetLabel(_("Close"));
+ }
+
+ if ( !newmsg )
+ {
+ // also provide the finishing message if the application didn't
+ m_msg->SetLabel(_("Done."));
+ }
+
+ m_state = Finished;
+ while ( m_state != Canceled ) // set from OnClose()
+ wxYield();
+
+ // so that we return TRUE below
+ m_state = Finished;
+ }
+
return m_state != Canceled;
}