From: Karsten Ballüder Date: Sun, 9 May 1999 15:19:45 +0000 (+0000) Subject: Added a generic wxProgressDialog and made wxPostscriptPrinter use it. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/8fa2e6a209ab83319bbc4d652067c9123deaa335 Added a generic wxProgressDialog and made wxPostscriptPrinter use it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2375 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/classes.tex b/docs/latex/wx/classes.tex index b5160bd8b9..ffcdd15e89 100644 --- a/docs/latex/wx/classes.tex +++ b/docs/latex/wx/classes.tex @@ -138,6 +138,7 @@ \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 index 0000000000..2c243409d3 --- /dev/null +++ b/docs/latex/wx/progdlg.tex @@ -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} + + + +\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 index 0000000000..2401275d14 --- /dev/null +++ b/include/wx/generic/progdlgg.h @@ -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__ diff --git a/include/wx/prntbase.h b/include/wx/prntbase.h index 04ad68da24..9e3cd730bc 100644 --- a/include/wx/prntbase.h +++ b/include/wx/prntbase.h @@ -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 index 0000000000..38e3b0d18d --- /dev/null +++ b/include/wx/progdlg.h @@ -0,0 +1,7 @@ +#ifndef _WX_PROGDLG_H_BASE_ +#define _WX_PROGDLG_H_BASE_ + +#include "wx/generic/progdlgg.h" + +#endif + // _WX_PROGDLG_H_BASE_ diff --git a/src/generic/printps.cpp b/src/generic/printps.cpp index 389fb5c7e1..053b00b275 100644 --- a/src/generic/printps.cpp +++ b/src/generic/printps.cpp @@ -35,7 +35,8 @@ #include "wx/dc.h" #include "wx/app.h" #include "wx/msgdlg.h" - #include + #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 index 0000000000..c156b612b0 --- /dev/null +++ b/src/generic/progdlgg.cpp @@ -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); +} diff --git a/src/gtk.inc b/src/gtk.inc index 7ef8880f5b..d89c7468d4 100644 --- a/src/gtk.inc +++ b/src/gtk.inc @@ -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 \ diff --git a/src/motif.inc b/src/motif.inc index f320372d6e..6918486cd7 100644 --- a/src/motif.inc +++ b/src/motif.inc @@ -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=\ \ diff --git a/src/stubs.inc b/src/stubs.inc index 79bec90696..0084a5cba6 100644 --- a/src/stubs.inc +++ b/src/stubs.inc @@ -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 \