1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/progdlgg.h
3 // Purpose: wxGenericProgressDialog class
4 // Author: Karsten Ballueder
5 // Modified by: Francesco Montorsi
7 // Copyright: (c) Karsten Ballueder
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef __PROGDLGH_G__
12 #define __PROGDLGH_G__
14 #include "wx/dialog.h"
16 class WXDLLIMPEXP_FWD_CORE wxButton
;
17 class WXDLLIMPEXP_FWD_CORE wxEventLoop
;
18 class WXDLLIMPEXP_FWD_CORE wxGauge
;
19 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
20 class WXDLLIMPEXP_FWD_CORE wxWindowDisabler
;
23 Progress dialog which shows a moving progress bar.
24 Taken from the Mahogany project.
26 class WXDLLIMPEXP_CORE wxGenericProgressDialog
: public wxDialog
29 wxGenericProgressDialog();
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 bool Create(const wxString
& title
,
38 const wxString
& message
,
40 wxWindow
*parent
= NULL
,
41 int style
= wxPD_APP_MODAL
| wxPD_AUTO_HIDE
);
43 virtual bool Update(int value
, const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
44 virtual bool Pulse(const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
50 wxString
GetMessage() const;
52 void SetRange(int maximum
);
54 // Return whether "Cancel" or "Skip" button was pressed, always return
55 // false if the corresponding button is not shown.
56 bool WasCancelled() const;
57 bool WasSkipped() const;
59 // Must provide overload to avoid hiding it (and warnings about it)
60 virtual void Update() { wxDialog::Update(); }
62 virtual bool Show( bool show
= true );
64 // This enum is an implementation detail and should not be used
68 Uncancelable
= -1, // dialog can't be canceled
69 Canceled
, // can be cancelled and, in fact, was
70 Continue
, // can be cancelled but wasn't
71 Finished
, // finished, waiting to be removed from screen
72 Dismissed
// was closed by user after finishing
76 // Update just the m_maximum field, this is used by public SetRange() but,
77 // unlike it, doesn't update the controls state. This makes it useful for
78 // both this class and its derived classes that don't use m_gauge to
80 void SetMaximum(int maximum
);
82 // Return the labels to use for showing the elapsed/estimated/remaining
83 // times respectively.
84 static wxString
GetElapsedLabel() { return wxGetTranslation("Elapsed time:"); }
85 static wxString
GetEstimatedLabel() { return wxGetTranslation("Estimated time:"); }
86 static wxString
GetRemainingLabel() { return wxGetTranslation("Remaining time:"); }
89 // Similar to wxWindow::HasFlag() but tests for a presence of a wxPD_XXX
90 // flag in our (separate) flags instead of using m_windowStyle.
91 bool HasPDFlag(int flag
) const { return (m_pdStyle
& flag
) != 0; }
93 // Return the progress dialog style. Prefer to use HasPDFlag() if possible.
94 int GetPDStyle() const { return m_pdStyle
; }
95 void SetPDStyle(int pdStyle
) { m_pdStyle
= pdStyle
; }
97 // Updates estimated times from a given progress bar value and stores the
98 // results in provided arguments.
99 void UpdateTimeEstimates(int value
,
100 unsigned long &elapsedTime
,
101 unsigned long &estimatedTime
,
102 unsigned long &remainingTime
);
104 // Converts seconds to HH:mm:ss format.
105 static wxString
GetFormattedTime(unsigned long timeInSec
);
107 // callback for optional abort button
108 void OnCancel(wxCommandEvent
&);
110 // callback for optional skip button
111 void OnSkip(wxCommandEvent
&);
113 // callback to disable "hard" window closing
114 void OnClose(wxCloseEvent
&);
116 // called to disable the other windows while this dialog is shown
117 void DisableOtherWindows();
119 // must be called to reenable the other windows temporarily disabled while
120 // the dialog was shown
121 void ReenableOtherWindows();
123 // Set the top level parent we store from the parent window provided when
124 // creating the dialog.
125 void SetTopParent(wxWindow
* parent
);
127 // return the top level parent window of this dialog (may be NULL)
128 wxWindow
*GetTopParent() const { return m_parentTop
; }
131 // continue processing or not (return value for Update())
137 #if defined(__WXMSW__ ) || defined(__WXPM__)
138 // the factor we use to always keep the value in 16 bit range as the native
139 // control only supports ranges from 0 to 65,535
143 // time when the dialog was created
144 unsigned long m_timeStart
;
145 // time when the dialog was closed or cancelled
146 unsigned long m_timeStop
;
147 // time between the moment the dialog was closed/cancelled and resume
148 unsigned long m_break
;
151 // update the label to show the given time (in seconds)
152 static void SetTimeLabel(unsigned long val
, wxStaticText
*label
);
154 // common part of all ctors
157 // create the label with given text and another one to show the time nearby
158 // as the next windows in the sizer, returns the created control
159 wxStaticText
*CreateLabel(const wxString
& text
, wxSizer
*sizer
);
161 // updates the label message
162 void UpdateMessage(const wxString
&newmsg
);
164 // common part of Update() and Pulse(), returns true if not cancelled
165 bool DoBeforeUpdate(bool *skip
);
167 // common part of Update() and Pulse()
168 void DoAfterUpdate();
170 // shortcuts for enabling buttons
172 void EnableSkip(bool enable
= true);
173 void EnableAbort(bool enable
= true);
174 void DisableSkip() { EnableSkip(false); }
175 void DisableAbort() { EnableAbort(false); }
177 // the widget displaying current status (may be NULL)
179 // the message displayed
181 // displayed elapsed, estimated, remaining time
182 wxStaticText
*m_elapsed
,
186 // parent top level window (may be NULL)
187 wxWindow
*m_parentTop
;
189 // Progress dialog styles: this is not the same as m_windowStyle because
190 // wxPD_XXX constants clash with the existing TLW styles so to be sure we
191 // don't have any conflicts we just use a separate variable for storing
198 #if !defined(__SMARTPHONE__)
199 // the abort and skip buttons (or NULL if none)
200 wxButton
*m_btnAbort
;
204 // saves the time when elapsed time was updated so there is only one
206 unsigned long m_last_timeupdate
;
208 // tells how often a change of the estimated time has to be confirmed
209 // before it is actually displayed - this reduces the frequency of updates
210 // of estimated and remaining time
213 // counts the confirmations
215 unsigned long m_display_estimated
;
217 // for wxPD_APP_MODAL case
218 wxWindowDisabler
*m_winDisabler
;
220 // Temporary event loop created by the dialog itself if there is no
221 // currently active loop when it is created.
222 wxEventLoop
*m_tempEventLoop
;
225 DECLARE_EVENT_TABLE()
226 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog
);
229 #endif // __PROGDLGH_G__