]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/progdlgg.cpp
compialtion fixes
[wxWidgets.git] / src / generic / progdlgg.cpp
index c43494211f21aa720e6fbdf57c3da22f24e553ba..137a4be73c3f39b4a850ca5a0642d929a97e09c1 100644 (file)
 // wxTextEntryDialog
 
 #if !USE_SHARED_LIBRARY
-BEGIN_EVENT_TABLE(wxProgressDialog, wxFrame)
-   EVT_BUTTON(-1, wxProgressDialog::OnCancel)
-   EVT_CLOSE(wxProgressDialog::OnClose)
-END_EVENT_TABLE()
+    BEGIN_EVENT_TABLE(wxProgressDialog, wxFrame)
+       EVT_BUTTON(-1, wxProgressDialog::OnCancel)
+       EVT_CLOSE(wxProgressDialog::OnClose)
+    END_EVENT_TABLE()
 
-   IMPLEMENT_CLASS(wxProgressDialog, wxFrame)
+    IMPLEMENT_CLASS(wxProgressDialog, wxFrame)
 #endif
 
 wxProgressDialog::wxProgressDialog(wxString const &title,
                                  wxString const &message,
                                  int maximum,
                                  wxWindow *parent,
-                                 bool parentOnly,
-                                 bool abortButton)
+                                 int style)
 {
-   m_state = abortButton ? Continue : Uncancelable;
-   m_disableParentOnly = parentOnly;
+   bool hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
+   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 ( abortButton )
+   if ( hasAbortButton )
       height += 35;
    wxFrame::Create(m_parent, -1, title,
                    wxPoint(0, 0), wxSize(220, height),
@@ -75,7 +76,7 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
    c->height.AsIs();
    m_msg->SetConstraints(c);
 
-   if(maximum > 0)
+   if ( maximum > 0 )
    {
       m_gauge = new wxGauge(this, -1, maximum);
       c = new wxLayoutConstraints;
@@ -87,31 +88,33 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
       m_gauge->SetValue(0);
    }
    else
-      m_gauge = NULL;
+      m_gauge = (wxGauge *)NULL;
    
-   if ( abortButton )
+   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);
    Centre(wxCENTER_FRAME | wxBOTH);
 
    if(m_disableParentOnly)
-      m_parent->Enable(false);
+      m_parent->Enable(FALSE);
    else
-      wxEnableTopLevelWindows(false);
-   Enable(true); // enable this window
+      wxEnableTopLevelWindows(FALSE);
+   Enable(TRUE); // enable this window
    wxYield();
 }
 
@@ -119,12 +122,37 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
 bool
 wxProgressDialog::Update(int value, const wxString& newmsg)
 {
-   wxASSERT(value == -1 || m_gauge);
-   if(m_gauge)
-      m_gauge->SetValue(value);
-   if(!newmsg.IsNull())
+   wxASSERT_MSG( value == -1 || m_gauge, _T("can't update non existent dialog") );
+   wxASSERT_MSG( value < m_maximum, _T("invalid progress value") );
+
+   if( m_gauge )
+      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;
 }
 
@@ -139,8 +167,8 @@ void wxProgressDialog::OnClose(wxCloseEvent& event)
 
 wxProgressDialog::~wxProgressDialog()
 {
-   if(m_disableParentOnly)
-      m_parent->Enable(true);
+   if ( m_disableParentOnly )
+      m_parent->Enable(TRUE);
    else
-      wxEnableTopLevelWindows(true);
+      wxEnableTopLevelWindows(TRUE);
 }