1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGenericProgressDialog class
4 // Author: Karsten Ballueder
5 // Modified by: Francesco Montorsi
8 // Copyright: (c) Karsten Ballueder
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef __PROGDLGH_G__
13 #define __PROGDLGH_G__
15 #include "wx/dialog.h"
17 class WXDLLIMPEXP_FWD_CORE wxButton
;
18 class WXDLLIMPEXP_FWD_CORE wxEventLoop
;
19 class WXDLLIMPEXP_FWD_CORE wxGauge
;
20 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
21 class WXDLLIMPEXP_FWD_CORE wxWindowDisabler
;
24 Progress dialog which shows a moving progress bar.
25 Taken from the Mahogany project.
27 class WXDLLIMPEXP_CORE wxGenericProgressDialog
: public wxDialog
30 wxGenericProgressDialog(const wxString
& title
, const wxString
& message
,
32 wxWindow
*parent
= NULL
,
33 int style
= wxPD_APP_MODAL
| wxPD_AUTO_HIDE
);
35 virtual ~wxGenericProgressDialog();
37 virtual bool Update(int value
, const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
38 virtual bool Pulse(const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
44 wxString
GetMessage() const;
46 void SetRange(int maximum
);
48 // Return whether "Cancel" or "Skip" button was pressed, always return
49 // false if the corresponding button is not shown.
50 bool WasCancelled() const;
51 bool WasSkipped() const;
53 // Must provide overload to avoid hiding it (and warnings about it)
54 virtual void Update() { wxDialog::Update(); }
56 virtual bool Show( bool show
= true );
58 // This enum is an implementation detail and should not be used
62 Uncancelable
= -1, // dialog can't be canceled
63 Canceled
, // can be cancelled and, in fact, was
64 Continue
, // can be cancelled but wasn't
65 Finished
// finished, waiting to be removed from screen
69 // This ctor is used by the native MSW implementation only.
70 wxGenericProgressDialog(wxWindow
*parent
, int style
);
72 void Create(const wxString
& title
,
73 const wxString
& message
,
78 // Update just the m_maximum field, this is used by public SetRange() but,
79 // unlike it, doesn't update the controls state. This makes it useful for
80 // both this class and its derived classes that don't use m_gauge to
82 void SetMaximum(int maximum
);
84 // Return the labels to use for showing the elapsed/estimated/remaining
85 // times respectively.
86 static wxString
GetElapsedLabel() { return _("Elapsed time:"); }
87 static wxString
GetEstimatedLabel() { return _("Estimated time:"); }
88 static wxString
GetRemainingLabel() { return _("Remaining time:"); }
91 // Similar to wxWindow::HasFlag() but tests for a presence of a wxPD_XXX
92 // flag in our (separate) flags instead of using m_windowStyle.
93 bool HasPDFlag(int flag
) const { return (m_pdStyle
& flag
) != 0; }
95 // Return the progress dialog style. Prefer to use HasPDFlag() if possible.
96 int GetPDStyle() const { return m_pdStyle
; }
99 // Updates estimated times from a given progress bar value and stores the
100 // results in provided arguments.
101 void UpdateTimeEstimates(int value
,
102 unsigned long &elapsedTime
,
103 unsigned long &estimatedTime
,
104 unsigned long &remainingTime
);
106 // Converts seconds to HH:mm:ss format.
107 static wxString
GetFormattedTime(unsigned long timeInSec
);
109 // callback for optional abort button
110 void OnCancel(wxCommandEvent
&);
112 // callback for optional skip button
113 void OnSkip(wxCommandEvent
&);
115 // callback to disable "hard" window closing
116 void OnClose(wxCloseEvent
&);
118 // called to disable the other windows while this dialog is shown
119 void DisableOtherWindows();
121 // must be called to reenable the other windows temporarily disabled while
122 // the dialog was shown
123 void ReenableOtherWindows();
125 // return the top level parent window of this dialog (may be NULL)
126 wxWindow
*GetTopParent() const { return m_parentTop
; }
129 // continue processing or not (return value for Update())
135 #if defined(__WXMSW__ ) || defined(__WXPM__)
136 // the factor we use to always keep the value in 16 bit range as the native
137 // control only supports ranges from 0 to 65,535
141 // time when the dialog was created
142 unsigned long m_timeStart
;
143 // time when the dialog was closed or cancelled
144 unsigned long m_timeStop
;
145 // time between the moment the dialog was closed/cancelled and resume
146 unsigned long m_break
;
149 // update the label to show the given time (in seconds)
150 static void SetTimeLabel(unsigned long val
, wxStaticText
*label
);
152 // common part of all ctors
153 void Init(wxWindow
*parent
, int style
);
155 // create the label with given text and another one to show the time nearby
156 // as the next windows in the sizer, returns the created control
157 wxStaticText
*CreateLabel(const wxString
& text
, wxSizer
*sizer
);
159 // updates the label message
160 void UpdateMessage(const wxString
&newmsg
);
162 // common part of Update() and Pulse(), returns true if not cancelled
163 bool DoBeforeUpdate(bool *skip
);
165 // common part of Update() and Pulse()
166 void DoAfterUpdate();
168 // shortcuts for enabling buttons
170 void EnableSkip(bool enable
= true);
171 void EnableAbort(bool enable
= true);
172 void DisableSkip() { EnableSkip(false); }
173 void DisableAbort() { EnableAbort(false); }
175 // the widget displaying current status (may be NULL)
177 // the message displayed
179 // displayed elapsed, estimated, remaining time
180 wxStaticText
*m_elapsed
,
184 // parent top level window (may be NULL)
185 wxWindow
*m_parentTop
;
187 // Progress dialog styles: this is not the same as m_windowStyle because
188 // wxPD_XXX constants clash with the existing TLW styles so to be sure we
189 // don't have any conflicts we just use a separate variable for storing
196 #if !defined(__SMARTPHONE__)
197 // the abort and skip buttons (or NULL if none)
198 wxButton
*m_btnAbort
;
202 // saves the time when elapsed time was updated so there is only one
204 unsigned long m_last_timeupdate
;
206 // tells how often a change of the estimated time has to be confirmed
207 // before it is actually displayed - this reduces the frequency of updates
208 // of estimated and remaining time
211 // counts the confirmations
213 unsigned long m_display_estimated
;
215 // for wxPD_APP_MODAL case
216 wxWindowDisabler
*m_winDisabler
;
218 // Temporary event loop created by the dialog itself if there is no
219 // currently active loop when it is created.
220 wxEventLoop
*m_tempEventLoop
;
223 DECLARE_EVENT_TABLE()
224 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog
);
227 #endif // __PROGDLGH_G__