1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/progdlgg.h
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
66 Dismissed
// was closed by user after finishing
70 // This ctor is used by the native MSW implementation only.
71 wxGenericProgressDialog(wxWindow
*parent
, int style
);
73 void Create(const wxString
& title
,
74 const wxString
& message
,
79 // Update just the m_maximum field, this is used by public SetRange() but,
80 // unlike it, doesn't update the controls state. This makes it useful for
81 // both this class and its derived classes that don't use m_gauge to
83 void SetMaximum(int maximum
);
85 // Return the labels to use for showing the elapsed/estimated/remaining
86 // times respectively.
87 static wxString
GetElapsedLabel() { return wxGetTranslation("Elapsed time:"); }
88 static wxString
GetEstimatedLabel() { return wxGetTranslation("Estimated time:"); }
89 static wxString
GetRemainingLabel() { return wxGetTranslation("Remaining time:"); }
92 // Similar to wxWindow::HasFlag() but tests for a presence of a wxPD_XXX
93 // flag in our (separate) flags instead of using m_windowStyle.
94 bool HasPDFlag(int flag
) const { return (m_pdStyle
& flag
) != 0; }
96 // Return the progress dialog style. Prefer to use HasPDFlag() if possible.
97 int GetPDStyle() const { return m_pdStyle
; }
100 // Updates estimated times from a given progress bar value and stores the
101 // results in provided arguments.
102 void UpdateTimeEstimates(int value
,
103 unsigned long &elapsedTime
,
104 unsigned long &estimatedTime
,
105 unsigned long &remainingTime
);
107 // Converts seconds to HH:mm:ss format.
108 static wxString
GetFormattedTime(unsigned long timeInSec
);
110 // callback for optional abort button
111 void OnCancel(wxCommandEvent
&);
113 // callback for optional skip button
114 void OnSkip(wxCommandEvent
&);
116 // callback to disable "hard" window closing
117 void OnClose(wxCloseEvent
&);
119 // called to disable the other windows while this dialog is shown
120 void DisableOtherWindows();
122 // must be called to reenable the other windows temporarily disabled while
123 // the dialog was shown
124 void ReenableOtherWindows();
126 // return the top level parent window of this dialog (may be NULL)
127 wxWindow
*GetTopParent() const { return m_parentTop
; }
130 // continue processing or not (return value for Update())
136 #if defined(__WXMSW__ ) || defined(__WXPM__)
137 // the factor we use to always keep the value in 16 bit range as the native
138 // control only supports ranges from 0 to 65,535
142 // time when the dialog was created
143 unsigned long m_timeStart
;
144 // time when the dialog was closed or cancelled
145 unsigned long m_timeStop
;
146 // time between the moment the dialog was closed/cancelled and resume
147 unsigned long m_break
;
150 // update the label to show the given time (in seconds)
151 static void SetTimeLabel(unsigned long val
, wxStaticText
*label
);
153 // common part of all ctors
154 void Init(wxWindow
*parent
, int style
);
156 // create the label with given text and another one to show the time nearby
157 // as the next windows in the sizer, returns the created control
158 wxStaticText
*CreateLabel(const wxString
& text
, wxSizer
*sizer
);
160 // updates the label message
161 void UpdateMessage(const wxString
&newmsg
);
163 // common part of Update() and Pulse(), returns true if not cancelled
164 bool DoBeforeUpdate(bool *skip
);
166 // common part of Update() and Pulse()
167 void DoAfterUpdate();
169 // shortcuts for enabling buttons
171 void EnableSkip(bool enable
= true);
172 void EnableAbort(bool enable
= true);
173 void DisableSkip() { EnableSkip(false); }
174 void DisableAbort() { EnableAbort(false); }
176 // the widget displaying current status (may be NULL)
178 // the message displayed
180 // displayed elapsed, estimated, remaining time
181 wxStaticText
*m_elapsed
,
185 // parent top level window (may be NULL)
186 wxWindow
*m_parentTop
;
188 // Progress dialog styles: this is not the same as m_windowStyle because
189 // wxPD_XXX constants clash with the existing TLW styles so to be sure we
190 // don't have any conflicts we just use a separate variable for storing
197 #if !defined(__SMARTPHONE__)
198 // the abort and skip buttons (or NULL if none)
199 wxButton
*m_btnAbort
;
203 // saves the time when elapsed time was updated so there is only one
205 unsigned long m_last_timeupdate
;
207 // tells how often a change of the estimated time has to be confirmed
208 // before it is actually displayed - this reduces the frequency of updates
209 // of estimated and remaining time
212 // counts the confirmations
214 unsigned long m_display_estimated
;
216 // for wxPD_APP_MODAL case
217 wxWindowDisabler
*m_winDisabler
;
219 // Temporary event loop created by the dialog itself if there is no
220 // currently active loop when it is created.
221 wxEventLoop
*m_tempEventLoop
;
224 DECLARE_EVENT_TABLE()
225 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog
);
228 #endif // __PROGDLGH_G__