]> git.saurik.com Git - wxWidgets.git/commitdiff
wxPD_CAN_SKIP for skipping parts of progress and reintroduced wxPD_SMOOTH after remov...
authorWłodzimierz Skiba <abx@abx.art.pl>
Thu, 30 Dec 2004 15:07:28 +0000 (15:07 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Thu, 30 Dec 2004 15:07:28 +0000 (15:07 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31193 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/progdlg.tex
include/wx/defs.h
include/wx/generic/progdlgg.h
samples/dialogs/dialogs.cpp
src/generic/progdlgg.cpp

index 9883a6d83553972db9b9645bc06bf19eff4b2ab2..c40943cf5cca82270f61fc824ef8d09ac7e52bc9 100644 (file)
@@ -45,6 +45,9 @@ All (GUI):
   book control (for now wxChoicebook for MSSmartphone, wxNotebook for others).
   Necessary event macros, types and styles mapped accordingly.
 - new wxBrush::IsHatch() checking for brush type replaces IS_HATCH macro
   book control (for now wxChoicebook for MSSmartphone, wxNotebook for others).
   Necessary event macros, types and styles mapped accordingly.
 - new wxBrush::IsHatch() checking for brush type replaces IS_HATCH macro
+- wxProgressDialog accepts smooth gauge again (wxPD_SMOOTH style)
+- wxProgressDialog new style: wxPD_CAN_SKIP which provides skipping some parts
+  of the progress (with new "Skip" button in dialog)
 
 Unix:
 
 
 Unix:
 
index 0bdf7f669b3077d5c8b87ca4f11e726466f5f535..d0d74d7e247b3b0558147f46e44a6815b3611c69 100644 (file)
@@ -49,9 +49,13 @@ window is disabled, but not to the other ones.}
 \twocolitem{{\bf wxPD\_AUTO\_HIDE}}{Causes the progress dialog to disappear
 from screen as soon as the maximum value of the progress meter has been
 reached.}
 \twocolitem{{\bf wxPD\_AUTO\_HIDE}}{Causes the progress dialog to disappear
 from screen as soon as the maximum value of the progress meter has been
 reached.}
+\twocolitem{{\bf wxPD\_SMOOTH}}{Causes smooth progress of the gauge control.}
 \twocolitem{{\bf wxPD\_CAN\_ABORT}}{This flag tells the dialog that it should have a
 "Cancel" button which the user may press. If this happens, the next call to 
  \helpref{Update()}{wxprogressdialogupdate} will return false.}
 \twocolitem{{\bf wxPD\_CAN\_ABORT}}{This flag tells the dialog that it should have a
 "Cancel" button which the user may press. If this happens, the next call to 
  \helpref{Update()}{wxprogressdialogupdate} will return false.}
+\twocolitem{{\bf wxPD\_CAN\_SKIP}}{This flag tells the dialog that it should have a
+"Skip" button which the user may press. If this happens, the next call to 
+ \helpref{Update()}{wxprogressdialogupdate} will return true in its skip parameter.}
 \twocolitem{{\bf wxPD\_ELAPSED\_TIME}}{This flag tells the dialog that it should show elapsed time (since creating the dialog).}
 \twocolitem{{\bf wxPD\_ESTIMATED\_TIME}}{This flag tells the dialog that it should show estimated time.}
 \twocolitem{{\bf wxPD\_REMAINING\_TIME}}{This flag tells the dialog that it should show remaining time.}
 \twocolitem{{\bf wxPD\_ELAPSED\_TIME}}{This flag tells the dialog that it should show elapsed time (since creating the dialog).}
 \twocolitem{{\bf wxPD\_ESTIMATED\_TIME}}{This flag tells the dialog that it should show estimated time.}
 \twocolitem{{\bf wxPD\_REMAINING\_TIME}}{This flag tells the dialog that it should show remaining time.}
@@ -77,7 +81,8 @@ ABORT.
 
 \func{virtual bool}{Update}{
   \param{int }{value},\rtfsp
 
 \func{virtual bool}{Update}{
   \param{int }{value},\rtfsp
-  \param{const wxString\& }{newmsg = ""}}
+  \param{const wxString\& }{newmsg = ""},\rtfsp
+  \param{bool *}{skip = NULL}}
 
 Updates the dialog, setting the progress bar to the new value and, if
 given changes the message above it. Returns true unless the Cancel button
 
 Updates the dialog, setting the progress bar to the new value and, if
 given changes the message above it. Returns true unless the Cancel button
@@ -94,4 +99,6 @@ equal to the maximum value given to the constructor and the dialog is closed if
 it is equal to the maximum.}
 \docparam{newmsg}{The new messages for the progress dialog text, if it is
 empty (which is the default) the message is not changed.}
 it is equal to the maximum.}
 \docparam{newmsg}{The new messages for the progress dialog text, if it is
 empty (which is the default) the message is not changed.}
+\docparam{skip}{If "Skip" button was pressed since last 
+\helpref{Update}{wxprogressdialogupdate} call the skip is true.}
 
 
index 11d1711a22f7189b94bed54daec154049a280269..9f088c38327d4cc6fe830d84d40a28b29cc68efd 100644 (file)
@@ -1531,10 +1531,9 @@ enum wxBorder
 #define wxPD_AUTO_HIDE          0x0004
 #define wxPD_ELAPSED_TIME       0x0008
 #define wxPD_ESTIMATED_TIME     0x0010
 #define wxPD_AUTO_HIDE          0x0004
 #define wxPD_ELAPSED_TIME       0x0008
 #define wxPD_ESTIMATED_TIME     0x0010
-/*  wxGA_SMOOTH = 0x0020 may also be used with wxProgressDialog */
-/*  NO!!! This is wxDIALOG_MODAL and will cause the progress dialog to */
-/*  be modal. No progress will then be made at all. */
+#define wxPD_SMOOTH             0x0020
 #define wxPD_REMAINING_TIME     0x0040
 #define wxPD_REMAINING_TIME     0x0040
+#define wxPD_CAN_SKIP           0x0080
 
 /*
  * wxDirDialog styles
 
 /*
  * wxDirDialog styles
index e53d3af732a604a06717ef651ff1848d69b0206f..6444697cecc3d0be5811e33da8fb4e0c18a6d003 100644 (file)
@@ -16,7 +16,7 @@
 #pragma interface "progdlgg.h"
 #endif
 
 #pragma interface "progdlgg.h"
 #endif
 
-#include "wx/setup.h"
+#include "wx/defs.h"
 
 #if wxUSE_PROGRESSDLG
 
 
 #if wxUSE_PROGRESSDLG
 
@@ -55,7 +55,7 @@ public:
        @param newmsg if used, new message to display
        @returns true if ABORT button has not been pressed
    */
        @param newmsg if used, new message to display
        @returns true if ABORT button has not been pressed
    */
-   virtual bool Update(int value, const wxString& newmsg = wxEmptyString);
+   virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL);
 
    /* 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
 
    /* 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
@@ -69,6 +69,9 @@ protected:
    // callback for optional abort button
    void OnCancel(wxCommandEvent& event);
 
    // callback for optional abort button
    void OnCancel(wxCommandEvent& event);
 
+   // callback for optional skip button
+   void OnSkip(wxCommandEvent& event);
+
    // callback to disable "hard" window closing
    void OnClose(wxCloseEvent& event);
 
    // callback to disable "hard" window closing
    void OnClose(wxCloseEvent& event);
 
@@ -108,8 +111,14 @@ private:
       Finished             // finished, waiting to be removed from screen
    } m_state;
 
       Finished             // finished, waiting to be removed from screen
    } m_state;
 
-   // the abort button (or NULL if none)
+   // skip some portion
+   bool m_skip;
+
+#if !defined(__SMARTPHONE__)
+   // the abort and skip buttons (or NULL if none)
    wxButton *m_btnAbort;
    wxButton *m_btnAbort;
+   wxButton *m_btnSkip;
+#endif
 
    // the maximum value
    int m_maximum;
 
    // the maximum value
    int m_maximum;
index dc435891200901fc411ac00da0b75eddf6847477..8e551bdc64fa5baa2ba5eeef9d7fe50432a332a8 100644 (file)
@@ -575,7 +575,7 @@ void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
                                          _T("Password entry dialog"),
                                          wxEmptyString,
                                          this);
                                          _T("Password entry dialog"),
                                          wxEmptyString,
                                          this);
-    if ( !!pwd )
+    if ( !pwd.empty() )
     {
         wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
                      _T("Got password"), wxOK | wxICON_INFORMATION, this);
     {
         wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
                      _T("Got password"), wxOK | wxICON_INFORMATION, this);
@@ -990,14 +990,18 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
                             max,    // range
                             this,   // parent
                             wxPD_CAN_ABORT |
                             max,    // range
                             this,   // parent
                             wxPD_CAN_ABORT |
+                            wxPD_CAN_SKIP |
                             wxPD_APP_MODAL |
                             // wxPD_AUTO_HIDE | -- try this as well
                             wxPD_ELAPSED_TIME |
                             wxPD_ESTIMATED_TIME |
                             wxPD_APP_MODAL |
                             // wxPD_AUTO_HIDE | -- try this as well
                             wxPD_ELAPSED_TIME |
                             wxPD_ESTIMATED_TIME |
-                            wxPD_REMAINING_TIME);
+                            wxPD_REMAINING_TIME |
+                            wxPD_SMOOTH);
 
     bool cont = true;
 
     bool cont = true;
-    for ( int i = 0; i <= max; i++ )
+    bool skip = false;
+    // each skip will move progress about quarter forward
+    for ( int i = 0; i <= max; i = wxMin(i+(skip?int(max/4):1), max+1), skip = false )
     {
         #if wxUSE_STOPWATCH && wxUSE_LONGLONG
         // do (almost) the same operations as we did for the performance test
     {
         #if wxUSE_STOPWATCH && wxUSE_LONGLONG
         // do (almost) the same operations as we did for the performance test
@@ -1018,25 +1022,27 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
         #else
         wxSleep(1);
         #endif
         #else
         wxSleep(1);
         #endif
+
+        wxString msg;
+
         if ( i == max )
         {
         if ( i == max )
         {
-            cont = dialog.Update(i, _T("That's all, folks!"));
+            msg = _T("That's all, folks!");
         }
         }
-        else if ( i == max / 2 )
+        else if ( i > max / 2 )
         {
         {
-            cont = dialog.Update(i, _T("Only a half left (very long message)!"));
+            msg = _T("Only a half left (very long message)!");
         }
         }
-        else
+
+#if wxUSE_STOPWATCH && wxUSE_LONGLONG
+        if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster
         {
         {
-            #if wxUSE_STOPWATCH && wxUSE_LONGLONG
-            if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster
-            {
-                cont = dialog.Update(i);
-            }
-            #else
-            cont = dialog.Update(i);
-            #endif
+            cont = dialog.Update(i, msg, &skip);
         }
         }
+#else
+        cont = dialog.Update(i, msg, &skip);
+#endif
+
         if ( !cont )
         {
             if ( wxMessageBox(_T("Do you really want to cancel?"),
         if ( !cont )
         {
             if ( wxMessageBox(_T("Do you really want to cancel?"),
index 5dbc3593347e9b19c1968e9aa556a0420f4407da..c6e1ff242284803280874d2923e860693de166a7 100644 (file)
@@ -66,6 +66,8 @@
 
 #define LAYOUT_MARGIN wxLARGESMALL(8,2)
 
 
 #define LAYOUT_MARGIN wxLARGESMALL(8,2)
 
+static const int wxID_SKIP = 32000;  // whatever
+
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
@@ -79,6 +81,7 @@ static void SetTimeLabel(unsigned long val, wxStaticText *label);
 
 BEGIN_EVENT_TABLE(wxProgressDialog, wxDialog)
     EVT_BUTTON(wxID_CANCEL, wxProgressDialog::OnCancel)
 
 BEGIN_EVENT_TABLE(wxProgressDialog, wxDialog)
     EVT_BUTTON(wxID_CANCEL, wxProgressDialog::OnCancel)
+    EVT_BUTTON(wxID_SKIP, wxProgressDialog::OnSkip)
 
     EVT_CLOSE(wxProgressDialog::OnClose)
 END_EVENT_TABLE()
 
     EVT_CLOSE(wxProgressDialog::OnClose)
 END_EVENT_TABLE()
@@ -99,14 +102,15 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
                                    wxWindow *parent,
                                    int style)
                 : wxDialog(parent, wxID_ANY, title),
                                    wxWindow *parent,
                                    int style)
                 : wxDialog(parent, wxID_ANY, title),
-                  m_delay(3)
+                  m_delay(3),
+                  m_skip(false)
 {
     // we may disappear at any moment, let the others know about it
     SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
 {
     // we may disappear at any moment, let the others know about it
     SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
-
     m_windowStyle |= style;
 
     bool hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
     m_windowStyle |= style;
 
     bool hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
+    bool hasSkipButton = (style & wxPD_CAN_SKIP) != 0;
 
 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
     // we have to remove the "Close" button from the title bar then as it is
 
 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
     // we have to remove the "Close" button from the title bar then as it is
@@ -151,12 +155,12 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
 
     if ( maximum > 0 )
     {
 
     if ( maximum > 0 )
     {
-        // note that we can't use wxGA_SMOOTH because it happens to
-        // cause the dialog to be modal. Have an extra
-        // style argument to wxProgressDialog, perhaps.
+        int gauge_style = wxGA_HORIZONTAL;
+        if ( ( style & wxPD_SMOOTH ) == wxPD_SMOOTH )
+            gauge_style |= wxGA_SMOOTH;
         m_gauge = new wxGauge(this, wxID_ANY, m_maximum,
                               wxDefaultPosition, wxDefaultSize,
         m_gauge = new wxGauge(this, wxID_ANY, m_maximum,
                               wxDefaultPosition, wxDefaultSize,
-                              wxGA_HORIZONTAL);
+                              gauge_style );
 
         sizer->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN);
         m_gauge->SetValue(0);
 
         sizer->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN);
         m_gauge->SetValue(0);
@@ -209,28 +213,47 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
         sizeDlg.y += nTimeLabels * (label->GetSize().y + LAYOUT_MARGIN);
     }
 
         sizeDlg.y += nTimeLabels * (label->GetSize().y + LAYOUT_MARGIN);
     }
 
-    if ( hasAbortButton )
-    {
 #if defined(__SMARTPHONE__)
 #if defined(__SMARTPHONE__)
-        SetLeftMenu(wxID_CANCEL, _("Cancel"));
-    }
+    if ( hasSkipButton )
+        SetRightMenu(wxID_SKIP, _("Skip"));
+    if ( hasAbortButton )
+        SetLeftMenu(wxID_CANCEL);
 #else
 #else
-        m_btnAbort = new wxButton(this, wxID_CANCEL);
+    m_btnAbort = m_btnSkip = (wxButton *)NULL;
+    bool sizeDlgModified = false;
+    wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
 
 
-        // Windows dialogs usually have buttons in the lower right corner
+    const int sizerFlags = 
 #if defined(__WXMSW__) || defined(__WXPM__)
 #if defined(__WXMSW__) || defined(__WXPM__)
-        sizer->Add(m_btnAbort, 0, wxALIGN_RIGHT | wxALL, 2*LAYOUT_MARGIN);
+                           wxALIGN_RIGHT | wxALL
 #else // !MSW
 #else // !MSW
-        sizer->Add(m_btnAbort, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM | wxTOP, 2*LAYOUT_MARGIN);
+                           wxALIGN_CENTER_HORIZONTAL | wxBOTTOM | wxTOP
 #endif // MSW/!MSW
 #endif // MSW/!MSW
+                           ;
+
+    if ( hasSkipButton )
+    {
+        m_btnSkip = new wxButton(this, wxID_SKIP, _("Skip"));
+
+        // Windows dialogs usually have buttons in the lower right corner
+        buttonSizer->Add(m_btnSkip, 0, sizerFlags, LAYOUT_MARGIN);
         sizeDlg.y += 2*LAYOUT_MARGIN + wxButton::GetDefaultSize().y;
         sizeDlg.y += 2*LAYOUT_MARGIN + wxButton::GetDefaultSize().y;
+        sizeDlgModified = true;
     }
     }
-    else // no "Cancel" button
-#endif // __SMARTPHONE__/!__SMARTPHONE__
+
+    if ( hasAbortButton )
     {
     {
-        m_btnAbort = (wxButton *)NULL;
+        m_btnAbort = new wxButton(this, wxID_CANCEL);
+
+        // Windows dialogs usually have buttons in the lower right corner
+        buttonSizer->Add(m_btnAbort, 0, sizerFlags, LAYOUT_MARGIN);
+        if(!sizeDlgModified)
+            sizeDlg.y += 2*LAYOUT_MARGIN + wxButton::GetDefaultSize().y;
     }
 
     }
 
+    sizer->Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN );
+#endif // __SMARTPHONE__/!__SMARTPHONE__
+
     SetSizerAndFit(sizer);
 
     sizeDlg.y += 2*LAYOUT_MARGIN;
     SetSizerAndFit(sizer);
 
     sizeDlg.y += 2*LAYOUT_MARGIN;
@@ -302,7 +325,7 @@ wxStaticText *wxProgressDialog::CreateLabel(const wxString& text,
 // ----------------------------------------------------------------------------
 
 bool
 // ----------------------------------------------------------------------------
 
 bool
-wxProgressDialog::Update(int value, const wxString& newmsg)
+wxProgressDialog::Update(int value, const wxString& newmsg, bool *skip)
 {
     wxASSERT_MSG( value == -1 || m_gauge, wxT("cannot update non existent dialog") );
 
 {
     wxASSERT_MSG( value == -1 || m_gauge, wxT("cannot update non existent dialog") );
 
@@ -319,7 +342,7 @@ wxProgressDialog::Update(int value, const wxString& newmsg)
         m_gauge->SetValue(value == m_maximum ? value : value + 1);
     }
 
         m_gauge->SetValue(value == m_maximum ? value : value + 1);
     }
 
-    if ( !newmsg.IsEmpty() )
+    if ( !newmsg.empty() && newmsg != m_msg->GetLabel() )
     {
         m_msg->SetLabel(newmsg);
 
     {
         m_msg->SetLabel(newmsg);
 
@@ -393,7 +416,14 @@ wxProgressDialog::Update(int value, const wxString& newmsg)
         {
 #if defined(__SMARTPHONE__)
             SetLeftMenu(wxID_CANCEL, _("Close"));
         {
 #if defined(__SMARTPHONE__)
             SetLeftMenu(wxID_CANCEL, _("Close"));
+            SetRightMenu();
 #endif
 #endif
+            if ( m_btnSkip )
+            {
+                // tell the user what he should do...
+                m_btnSkip->Disable();
+            }
+
             if ( m_btnAbort )
             {
                 // tell the user what he should do...
             if ( m_btnAbort )
             {
                 // tell the user what he should do...
@@ -406,7 +436,7 @@ wxProgressDialog::Update(int value, const wxString& newmsg)
             }
 #endif // __WXMSW__
 
             }
 #endif // __WXMSW__
 
-            if ( !newmsg )
+            if ( !newmsg.empty() )
             {
                 // also provide the finishing message if the application didn't
                 m_msg->SetLabel(_("Done."));
             {
                 // also provide the finishing message if the application didn't
                 m_msg->SetLabel(_("Done."));
@@ -429,8 +459,16 @@ wxProgressDialog::Update(int value, const wxString& newmsg)
     else
     {
         // we have to yield because not only we want to update the display but
     else
     {
         // we have to yield because not only we want to update the display but
-        // also to process the clicks on the cancel button
+        // also to process the clicks on the cancel and skip buttons
         wxYieldIfNeeded() ;
         wxYieldIfNeeded() ;
+
+        if ( (m_skip) && (skip != NULL) && (*skip == false) )
+        {
+            *skip = true;
+            m_skip = false;
+            if(m_btnSkip)
+                m_btnSkip->Enable();
+        }
     }
 
     // update the display in case yielding above didn't do it
     }
 
     // update the display in case yielding above didn't do it
@@ -449,6 +487,12 @@ void wxProgressDialog::Resume()
     // user interrupt us again if needed
     if(m_btnAbort)
         m_btnAbort->Enable();
     // user interrupt us again if needed
     if(m_btnAbort)
         m_btnAbort->Enable();
+
+    // enable skipping because the one before OnCancel() is no more valid
+    m_skip = false;
+    if(m_btnSkip)
+        m_btnSkip->Enable();
+
 #if defined(__SMARTPHONE__)
     SetLeftMenu(wxID_CANCEL, _("Cancel"));
 #endif
 #if defined(__SMARTPHONE__)
     SetLeftMenu(wxID_CANCEL, _("Cancel"));
 #endif
@@ -487,6 +531,8 @@ void wxProgressDialog::OnCancel(wxCommandEvent& event)
         // request has been noticed
         if(m_btnAbort)
             m_btnAbort->Disable();
         // request has been noticed
         if(m_btnAbort)
             m_btnAbort->Disable();
+        if(m_btnSkip)
+            m_btnSkip->Disable();
 
 #if defined(__SMARTPHONE__)
         SetLeftMenu();
 
 #if defined(__SMARTPHONE__)
         SetLeftMenu();
@@ -497,6 +543,13 @@ void wxProgressDialog::OnCancel(wxCommandEvent& event)
     }
 }
 
     }
 }
 
+void wxProgressDialog::OnSkip(wxCommandEvent& WXUNUSED(event))
+{
+    if(m_btnSkip)
+        m_btnSkip->Disable();
+    m_skip = true;
+}
+
 void wxProgressDialog::OnClose(wxCloseEvent& event)
 {
     if ( m_state == Uncancelable )
 void wxProgressDialog::OnClose(wxCloseEvent& event)
 {
     if ( m_state == Uncancelable )
@@ -515,6 +568,9 @@ void wxProgressDialog::OnClose(wxCloseEvent& event)
         m_state = Canceled;
         if(m_btnAbort)
             m_btnAbort->Disable();
         m_state = Canceled;
         if(m_btnAbort)
             m_btnAbort->Disable();
+        if(m_btnSkip)
+            m_btnSkip->Disable();
+
 #if defined(__SMARTPHONE__)
         SetLeftMenu();
 #endif
 #if defined(__SMARTPHONE__)
         SetLeftMenu();
 #endif