]> git.saurik.com Git - wxWidgets.git/commitdiff
Added a generic wxProgressDialog and made wxPostscriptPrinter use it.
authorKarsten Ballüder <ballueder@usa.net>
Sun, 9 May 1999 15:19:45 +0000 (15:19 +0000)
committerKarsten Ballüder <ballueder@usa.net>
Sun, 9 May 1999 15:19:45 +0000 (15:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2375 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/classes.tex
docs/latex/wx/progdlg.tex [new file with mode: 0644]
include/wx/generic/progdlgg.h [new file with mode: 0644]
include/wx/prntbase.h
include/wx/progdlg.h [new file with mode: 0644]
src/generic/printps.cpp
src/generic/progdlgg.cpp [new file with mode: 0644]
src/gtk.inc
src/motif.inc
src/stubs.inc

index b5160bd8b9f4ea379d1611c07a951a9fc7ba1e5f..ffcdd15e89447982ceef0264f931dda0c5a1635f 100644 (file)
 \input prvdatob.tex
 \input prvtdrpt.tex
 \input process.tex
+\input progdlg.tex
 \input procevt.tex
 \input protocol.tex
 \input query.tex
diff --git a/docs/latex/wx/progdlg.tex b/docs/latex/wx/progdlg.tex
new file mode 100644 (file)
index 0000000..2c24340
--- /dev/null
@@ -0,0 +1,75 @@
+\section{\class{wxProgressDialog}}\label{wxprogressdialog}
+
+This class represents a dialog that shows a short message and a
+progress bar. Optionally, it can display an ABORT button.
+
+\wxheading{Derived from}
+
+\helpref{wxFrame}{wxframe}\\
+\helpref{wxWindow}{wxwindow}\\
+\helpref{wxEvtHandler}{wxevthandler}\\
+\helpref{wxObject}{wxobject}
+
+\wxheading{Include files}
+
+<wx/progdlg.h>
+
+\latexignore{\rtfignore{\wxheading{Members}}}
+
+\membersection{wxProgressDialog::wxProgressDialog}\label{wxprogressdialogconstr}
+
+\func{}{wxProgressDialog}
+{\param{const wxString\& }{title},
+  \param{const wxString\& }{message},\rtfsp
+  \param{int }{maximum = 100},
+  \param{wxWindow * }{parent = NULL},\rtfsp
+  \param{bool }{disableParentOnly = FALSE},\rtfsp
+  \param{bool }{abortButton = FALSE}
+  }
+
+Constructor. Creates the dialog, displays it and disables user input
+for other windows, or, if disableParentOnly = TRUE, for its parent
+window only.
+
+\wxheading{Parameters}
+
+\docparam{title}{Dialog title to show in titlebar.}
+
+\docparam{message}{Message displayed above the progress bar.}
+
+\docparam{maximum}{Maximum value for the progress bar.}
+
+\docparam{parent}{Parent window.}
+
+\docparam{message}{Message to show on the dialog.}
+
+\docparam{disableParentOnly}{By default, the dialog disables user
+  input for all other top level windows. If this parameter is TRUE, it 
+  will only disable the window passes as parent.}
+
+\docparam{abortButton}{If TRUE, will display an ABORT button.}
+
+\membersection{wxProgressDialog::\destruct{wxProgressDialog}}
+
+\func{}{\destruct{wxMessageDialog}}{\void}
+Destructor.
+Deletes the dialog and enables all top level windows.
+
+\membersection{wxProgressDialog::Update}\label{wxprogressdialogupdate}
+
+\func{bool}{Update}{
+  \param{int }{value = -1},\rtfsp
+  \param{const char * }{newmsg = NULL},  }
+
+Updates the dialog, setting the progress bar to the new value and, if
+given exchanges the message above it. Returns TRUE if the ABORT button 
+has \emph{not} been pressed.
+
+
+\membersection{wxProgressDialog::Resume}\label{wxprogressdialogresume}
+
+\func{void}{Resume}{\void}
+Can be used to continue with the dialog, after the user had chosen
+ABORT.
+
+
diff --git a/include/wx/generic/progdlgg.h b/include/wx/generic/progdlgg.h
new file mode 100644 (file)
index 0000000..2401275
--- /dev/null
@@ -0,0 +1,90 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        progdlgg.h
+// Purpose:     wxProgressDialog class
+// Author:      Karsten Ballüder
+// Modified by:
+// Created:     09.05.1999
+// RCS-ID:      $Id$
+// Copyright:   (c) Karsten Ballüder
+// Licence:    wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __PROGDLGH_G__
+#define __PROGDLGH_G__
+
+#ifdef __GNUG__
+#pragma interface "progdlgg.h"
+#endif
+
+#include "wx/setup.h"
+#include "wx/frame.h"
+
+
+
+/** Progress dialog which shows a moving progress bar.
+    Taken from the Mahogany project.*/
+
+class WXDLLEXPORT wxProgressDialog : public wxFrame
+{
+DECLARE_DYNAMIC_CLASS(wxProgressDialog)
+public:
+   /** Creates and displays dialog, disables event handling for other
+       frames or parent frame to avoid recursion problems.
+       @param title title for window
+       @param message message to display in window
+       @param maximum maximum value for status bar, if <= 0, no bar is shown
+       @param parent window or NULL
+       @param disableParentOnly if true, only disable parent window's
+       event handling
+       @param abortButton if true, dialog will show an abort button
+   */
+   wxProgressDialog(const wxString &title, wxString const &message,
+                   int maximum = 100,
+                   wxWindow *parent = NULL,
+                   bool disableParentOnly = FALSE,
+                   bool abortButton = FALSE);
+   /** Destructor.
+       Re-enables event handling for other windows.
+   */
+   ~wxProgressDialog();
+
+   /** Update the status bar to the new value.
+       @param value new value
+       @param newmsg if used, new message to display
+       @returns true if ABORT button has not been pressed
+   */
+   bool Update(int value = -1, const char *newmsg = 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
+       configrm it)
+   */
+   void Resume() { m_state = Continue; }
+
+   /// Callback for optional abort button
+   void OnCancel(wxEvent& WXUNUSED(event)) { m_state = Canceled; }
+
+   /// callback to disable "hard" window closing
+   void OnClose(wxCloseEvent& event);
+
+private:
+   /// the status bar
+   class wxGauge *m_gauge;
+   /// the message displayed
+   class wxStaticText *m_msg;
+   /// disable all or parent window only
+   bool m_disableParentOnly;
+   /// parent window
+   class wxWindow *m_parent;
+   /// continue processing or not (return value for Update())
+   enum
+   {
+      Uncancelable = -1,   // dialog can't be canceled
+      Canceled,            // can be cancelled and, in fact, was
+      Continue             // can be cancelled but wasn't
+   } m_state;
+
+   DECLARE_EVENT_TABLE()
+};
+#endif
+    // __PROGDLGH_G__
index 04ad68da24122c0e358ed4d3e21d3a482ed6c6e5..9e3cd730bcd07c982fb6b7beed21d3eaac78e6ec 100644 (file)
@@ -64,7 +64,6 @@ public:
 protected:
     wxPrintDialogData     m_printDialogData;
     wxPrintout*           m_currentPrintout;
-
 public:
     static wxWindow*      sm_abortWindow;
     static bool           sm_abortIt;
diff --git a/include/wx/progdlg.h b/include/wx/progdlg.h
new file mode 100644 (file)
index 0000000..38e3b0d
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _WX_PROGDLG_H_BASE_
+#define _WX_PROGDLG_H_BASE_
+
+#include "wx/generic/progdlgg.h"
+
+#endif
+    // _WX_PROGDLG_H_BASE_
index 389fb5c7e152b395cdf08e4c0ff5298a650f2cce..053b00b275444c7b096a1bd6db2d3f95ffd2234f 100644 (file)
@@ -35,7 +35,8 @@
     #include "wx/dc.h"
     #include "wx/app.h"
     #include "wx/msgdlg.h"
-    #include <wx/intl.h>
+    #include "wx/intl.h"
+    #include "wx/progdlg.h"
 #endif
 
 #include "wx/generic/printps.h"
@@ -113,6 +114,7 @@ bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool pro
     else
         m_printDialogData.EnablePageNumbers(FALSE);
 
+
     // Create a suitable device context
     wxDC *dc = (wxDC *) NULL;
     if (prompt)
@@ -165,6 +167,15 @@ bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool pro
     // Create an abort window
     wxBeginBusyCursor();
 
+    // Open the progress bar dialog
+    wxProgressDialog *progressDialog = new wxProgressDialog (
+       printout->GetTitle(),
+       _("Printing..."),
+       maxPage-minPage,
+       parent,
+       /* disable parent only */ true,
+       /* show abort button */ true);
+    
     printout->OnBeginPrinting();
 
     bool keepGoing = TRUE;
@@ -192,11 +203,22 @@ bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool pro
             }
             else
             {
-                dc->StartPage();
-                printout->OnPrintPage(pn);
-                dc->EndPage();
+               wxString msg;
+               msg.Printf(_("Printing page %d..."), pn);
+               if(progressDialog->Update(pn-minPage, msg))
+               {
+                  dc->StartPage();
+                  printout->OnPrintPage(pn);
+                  dc->EndPage();
+               }
+               else
+               {
+                  sm_abortIt = true;
+                  keepGoing = false; //FIXME: do we need both?
+               }
             }
         }
+        delete progressDialog;
         printout->OnEndDocument();
     }
 
diff --git a/src/generic/progdlgg.cpp b/src/generic/progdlgg.cpp
new file mode 100644 (file)
index 0000000..c156b61
--- /dev/null
@@ -0,0 +1,146 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        progdlgg.h
+// Purpose:     wxProgressDialog class
+// Author:      Karsten Ballüder
+// Modified by:
+// Created:     09.05.1999
+// RCS-ID:      $Id$
+// Copyright:   (c) Karsten Ballüder
+// Licence:    wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "progdlgg.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include "wx/utils.h"
+#include "wx/frame.h"
+#include "wx/button.h"
+#include "wx/stattext.h"
+#include "wx/layout.h"
+#include "wx/event.h"
+#include "wx/gauge.h"
+#include "wx/intl.h"
+#endif
+
+#include "wx/generic/progdlgg.h"
+
+#define LAYOUT_X_MARGIN 8
+#define LAYOUT_Y_MARGIN 8
+
+// wxTextEntryDialog
+
+#if !USE_SHARED_LIBRARY
+BEGIN_EVENT_TABLE(wxProgressDialog, wxFrame)
+   EVT_BUTTON(-1, wxProgressDialog::OnCancel)
+   EVT_CLOSE(wxProgressDialog::OnClose)
+END_EVENT_TABLE()
+
+   IMPLEMENT_CLASS(wxProgressDialog, wxFrame)
+#endif
+
+wxProgressDialog::wxProgressDialog(wxString const &title,
+                                 wxString const &message,
+                                 int maximum,
+                                 wxWindow *parent,
+                                 bool parentOnly,
+                                 bool abortButton)
+{
+   m_state = abortButton ? Continue : Uncancelable;
+   m_disableParentOnly = parentOnly;
+   m_parent = parent;
+   
+   int height = 70;     // FIXME arbitrary numbers
+   if ( abortButton )
+      height += 35;
+   wxFrame::Create(m_parent, -1, title,
+                   wxPoint(0, 0), wxSize(220, height),
+                   wxDEFAULT_DIALOG_STYLE);
+
+   wxLayoutConstraints *c;
+
+   m_msg = new wxStaticText(this, -1, message);
+   c = new wxLayoutConstraints;
+   c->left.SameAs(this, wxLeft, 10);
+   c->top.SameAs(this, wxTop, 10);
+   c->width.AsIs();
+   c->height.AsIs();
+   m_msg->SetConstraints(c);
+
+   if(maximum > 0)
+   {
+      m_gauge = new wxGauge(this, -1, maximum);
+      c = new wxLayoutConstraints;
+      c->left.SameAs(this, wxLeft, 2*LAYOUT_X_MARGIN);
+      c->top.Below(m_msg, 2*LAYOUT_Y_MARGIN);
+      c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
+      c->height.AsIs();
+      m_gauge->SetConstraints(c);
+      m_gauge->SetValue(0);
+   }
+   else
+      m_gauge = NULL;
+   
+   if ( abortButton )
+   {
+      wxControl *ctrl = 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->width.AsIs();
+      c->height.AsIs();
+      ctrl->SetConstraints(c);
+   }
+
+   SetAutoLayout(TRUE);
+   Show(TRUE);
+   Centre(wxCENTER_FRAME | wxBOTH);
+
+   if(m_disableParentOnly)
+      m_parent->Enable(false);
+   else
+      wxEnableTopLevelWindows(false);
+   Enable(true); // enable this window
+   wxYield();
+}
+
+
+bool
+wxProgressDialog::Update(int value, const char *newmsg)
+{
+   wxASSERT(value == -1 || m_gauge);
+   if(m_gauge)
+      m_gauge->SetValue(value);
+   if(newmsg)
+      m_msg->SetLabel(newmsg);
+   wxYield();
+   return m_state != Canceled;
+}
+
+void wxProgressDialog::OnClose(wxCloseEvent& event)
+{
+   if ( m_state == Uncancelable )
+      event.Veto(TRUE);
+   else
+      m_state = Canceled;
+}
+
+
+wxProgressDialog::~wxProgressDialog()
+{
+   if(m_disableParentOnly)
+      m_parent->Enable(true);
+   else
+      wxEnableTopLevelWindows(true);
+}
index 7ef8880f5b65dbc07632e46f3d53fa75677dad2e..d89c7468d44ea20759f9a61044d0a77e7baa210a 100644 (file)
@@ -158,7 +158,8 @@ LIB_CPP_SRC=\
  generic/textdlgg.cpp \
  generic/treectrl.cpp \
  generic/helpext.cpp \
- generic/helphtml.cpp
+ generic/helphtml.cpp \
+ generic/progdlgg.cpp
 
 LIB_C_SRC=\
  common/extended.c \
index f320372d6ee591af7b3ec545a2b012a4d2b93047..6918486cd78bb5c544111a9eff4d157117ea992e 100644 (file)
@@ -160,7 +160,8 @@ LIB_CPP_SRC=\
  generic/textdlgg.cpp \
  generic/treectrl.cpp \
 \
- unix/utilsunx.cpp
+ unix/utilsunx.cpp \
+ generic/progdlgg.cpp
   
 LIB_C_SRC=\
 \
index 79bec90696aa6f7edd9832640d71fb01f8c222fa..0084a5cba6e9e6f53534136f3bb8229f1cff6628 100644 (file)
@@ -151,8 +151,8 @@ LIB_CPP_SRC=\
  generic/statusbr.cpp \
  generic/tabg.cpp \
  generic/textdlgg.cpp \
- generic/treectrl.cpp
+ generic/treectrl.cpp \
+ generic/progdlgg.cpp 
  
 LIB_C_SRC=\
  common/extended.c \