]>
Commit | Line | Data |
---|---|---|
ed1288ee | 1 | /////////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/generic/progdlgg.h |
c31d9c7f | 3 | // Purpose: wxGenericProgressDialog class |
9d55bfef | 4 | // Author: Karsten Ballueder |
ed1288ee | 5 | // Modified by: Francesco Montorsi |
8fa2e6a2 KB |
6 | // Created: 09.05.1999 |
7 | // RCS-ID: $Id$ | |
9d55bfef | 8 | // Copyright: (c) Karsten Ballueder |
65571936 | 9 | // Licence: wxWindows licence |
ed1288ee | 10 | /////////////////////////////////////////////////////////////////////////////// |
8fa2e6a2 KB |
11 | |
12 | #ifndef __PROGDLGH_G__ | |
13 | #define __PROGDLGH_G__ | |
14 | ||
0655ad29 | 15 | #include "wx/dialog.h" |
8fa2e6a2 | 16 | |
b5dbe15d | 17 | class WXDLLIMPEXP_FWD_CORE wxButton; |
7ad8a38a | 18 | class WXDLLIMPEXP_FWD_CORE wxEventLoop; |
b5dbe15d VS |
19 | class WXDLLIMPEXP_FWD_CORE wxGauge; |
20 | class WXDLLIMPEXP_FWD_CORE wxStaticText; | |
79e58a40 | 21 | class WXDLLIMPEXP_FWD_CORE wxWindowDisabler; |
0655ad29 | 22 | |
ed1288ee FM |
23 | /* |
24 | Progress dialog which shows a moving progress bar. | |
25 | Taken from the Mahogany project. | |
26 | */ | |
c31d9c7f | 27 | class WXDLLIMPEXP_CORE wxGenericProgressDialog : public wxDialog |
8fa2e6a2 | 28 | { |
8fa2e6a2 | 29 | public: |
f27f9577 | 30 | wxGenericProgressDialog(); |
c31d9c7f VZ |
31 | wxGenericProgressDialog(const wxString& title, const wxString& message, |
32 | int maximum = 100, | |
33 | wxWindow *parent = NULL, | |
34 | int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE); | |
ed1288ee | 35 | |
c31d9c7f | 36 | virtual ~wxGenericProgressDialog(); |
695f550b | 37 | |
f27f9577 VZ |
38 | bool Create(const wxString& title, |
39 | const wxString& message, | |
40 | int maximum = 100, | |
41 | wxWindow *parent = NULL, | |
42 | int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE); | |
43 | ||
695f550b | 44 | virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL); |
f4aa7ec3 | 45 | virtual bool Pulse(const wxString& newmsg = wxEmptyString, bool *skip = NULL); |
fe8635a7 | 46 | |
695f550b | 47 | void Resume(); |
8fa2e6a2 | 48 | |
af237ae4 FM |
49 | int GetValue() const; |
50 | int GetRange() const; | |
51 | wxString GetMessage() const; | |
7d1dcec2 | 52 | |
ed1288ee FM |
53 | void SetRange(int maximum); |
54 | ||
f994a8ac VZ |
55 | // Return whether "Cancel" or "Skip" button was pressed, always return |
56 | // false if the corresponding button is not shown. | |
57 | bool WasCancelled() const; | |
58 | bool WasSkipped() const; | |
59 | ||
ed1288ee FM |
60 | // Must provide overload to avoid hiding it (and warnings about it) |
61 | virtual void Update() { wxDialog::Update(); } | |
62 | ||
63 | virtual bool Show( bool show = true ); | |
64 | ||
c31d9c7f VZ |
65 | // This enum is an implementation detail and should not be used |
66 | // by user code. | |
4f4d6f44 | 67 | enum State |
c31d9c7f VZ |
68 | { |
69 | Uncancelable = -1, // dialog can't be canceled | |
70 | Canceled, // can be cancelled and, in fact, was | |
71 | Continue, // can be cancelled but wasn't | |
cc31a982 VZ |
72 | Finished, // finished, waiting to be removed from screen |
73 | Dismissed // was closed by user after finishing | |
c31d9c7f VZ |
74 | }; |
75 | ||
ef8698d6 | 76 | protected: |
2de77c6a VZ |
77 | // Update just the m_maximum field, this is used by public SetRange() but, |
78 | // unlike it, doesn't update the controls state. This makes it useful for | |
79 | // both this class and its derived classes that don't use m_gauge to | |
80 | // display progress. | |
81 | void SetMaximum(int maximum); | |
82 | ||
c31d9c7f VZ |
83 | // Return the labels to use for showing the elapsed/estimated/remaining |
84 | // times respectively. | |
d20dfbf0 MB |
85 | static wxString GetElapsedLabel() { return wxGetTranslation("Elapsed time:"); } |
86 | static wxString GetEstimatedLabel() { return wxGetTranslation("Estimated time:"); } | |
87 | static wxString GetRemainingLabel() { return wxGetTranslation("Remaining time:"); } | |
c31d9c7f VZ |
88 | |
89 | ||
e77570de VZ |
90 | // Similar to wxWindow::HasFlag() but tests for a presence of a wxPD_XXX |
91 | // flag in our (separate) flags instead of using m_windowStyle. | |
92 | bool HasPDFlag(int flag) const { return (m_pdStyle & flag) != 0; } | |
93 | ||
94 | // Return the progress dialog style. Prefer to use HasPDFlag() if possible. | |
95 | int GetPDStyle() const { return m_pdStyle; } | |
f27f9577 | 96 | void SetPDStyle(int pdStyle) { m_pdStyle = pdStyle; } |
e77570de | 97 | |
c31d9c7f VZ |
98 | // Updates estimated times from a given progress bar value and stores the |
99 | // results in provided arguments. | |
100 | void UpdateTimeEstimates(int value, | |
101 | unsigned long &elapsedTime, | |
102 | unsigned long &estimatedTime, | |
103 | unsigned long &remainingTime); | |
104 | ||
105 | // Converts seconds to HH:mm:ss format. | |
106 | static wxString GetFormattedTime(unsigned long timeInSec); | |
107 | ||
695f550b VZ |
108 | // callback for optional abort button |
109 | void OnCancel(wxCommandEvent&); | |
ef8698d6 | 110 | |
695f550b VZ |
111 | // callback for optional skip button |
112 | void OnSkip(wxCommandEvent&); | |
ecda9475 | 113 | |
695f550b VZ |
114 | // callback to disable "hard" window closing |
115 | void OnClose(wxCloseEvent&); | |
8fa2e6a2 | 116 | |
c31d9c7f VZ |
117 | // called to disable the other windows while this dialog is shown |
118 | void DisableOtherWindows(); | |
119 | ||
695f550b VZ |
120 | // must be called to reenable the other windows temporarily disabled while |
121 | // the dialog was shown | |
122 | void ReenableOtherWindows(); | |
ef8698d6 | 123 | |
c31d9c7f VZ |
124 | // return the top level parent window of this dialog (may be NULL) |
125 | wxWindow *GetTopParent() const { return m_parentTop; } | |
126 | ||
127 | ||
128 | // continue processing or not (return value for Update()) | |
4f4d6f44 | 129 | State m_state; |
c31d9c7f VZ |
130 | |
131 | // the maximum value | |
132 | int m_maximum; | |
133 | ||
134 | #if defined(__WXMSW__ ) || defined(__WXPM__) | |
135 | // the factor we use to always keep the value in 16 bit range as the native | |
136 | // control only supports ranges from 0 to 65,535 | |
137 | size_t m_factor; | |
138 | #endif // __WXMSW__ | |
139 | ||
140 | // time when the dialog was created | |
141 | unsigned long m_timeStart; | |
142 | // time when the dialog was closed or cancelled | |
143 | unsigned long m_timeStop; | |
144 | // time between the moment the dialog was closed/cancelled and resume | |
145 | unsigned long m_break; | |
146 | ||
8fa2e6a2 | 147 | private: |
c31d9c7f VZ |
148 | // update the label to show the given time (in seconds) |
149 | static void SetTimeLabel(unsigned long val, wxStaticText *label); | |
150 | ||
151 | // common part of all ctors | |
f27f9577 | 152 | void Init(); |
c31d9c7f | 153 | |
695f550b VZ |
154 | // create the label with given text and another one to show the time nearby |
155 | // as the next windows in the sizer, returns the created control | |
156 | wxStaticText *CreateLabel(const wxString& text, wxSizer *sizer); | |
0655ad29 | 157 | |
fe8635a7 | 158 | // updates the label message |
695f550b VZ |
159 | void UpdateMessage(const wxString &newmsg); |
160 | ||
161 | // common part of Update() and Pulse(), returns true if not cancelled | |
86417abf VZ |
162 | bool DoBeforeUpdate(bool *skip); |
163 | ||
164 | // common part of Update() and Pulse() | |
165 | void DoAfterUpdate(); | |
695f550b VZ |
166 | |
167 | // shortcuts for enabling buttons | |
168 | void EnableClose(); | |
169 | void EnableSkip(bool enable = true); | |
170 | void EnableAbort(bool enable = true); | |
171 | void DisableSkip() { EnableSkip(false); } | |
172 | void DisableAbort() { EnableAbort(false); } | |
173 | ||
af237ae4 | 174 | // the widget displaying current status (may be NULL) |
695f550b VZ |
175 | wxGauge *m_gauge; |
176 | // the message displayed | |
177 | wxStaticText *m_msg; | |
178 | // displayed elapsed, estimated, remaining time | |
179 | wxStaticText *m_elapsed, | |
180 | *m_estimated, | |
181 | *m_remaining; | |
695f550b VZ |
182 | |
183 | // parent top level window (may be NULL) | |
184 | wxWindow *m_parentTop; | |
abceee76 | 185 | |
e77570de VZ |
186 | // Progress dialog styles: this is not the same as m_windowStyle because |
187 | // wxPD_XXX constants clash with the existing TLW styles so to be sure we | |
188 | // don't have any conflicts we just use a separate variable for storing | |
189 | // them. | |
190 | int m_pdStyle; | |
191 | ||
69c69546 WS |
192 | // skip some portion |
193 | bool m_skip; | |
ecda9475 WS |
194 | |
195 | #if !defined(__SMARTPHONE__) | |
69c69546 WS |
196 | // the abort and skip buttons (or NULL if none) |
197 | wxButton *m_btnAbort; | |
198 | wxButton *m_btnSkip; | |
ecda9475 | 199 | #endif |
cbc66a27 | 200 | |
69c69546 WS |
201 | // saves the time when elapsed time was updated so there is only one |
202 | // update per second | |
203 | unsigned long m_last_timeupdate; | |
c31d9c7f | 204 | |
69c69546 | 205 | // tells how often a change of the estimated time has to be confirmed |
c31d9c7f | 206 | // before it is actually displayed - this reduces the frequency of updates |
69c69546 | 207 | // of estimated and remaining time |
c31d9c7f VZ |
208 | int m_delay; |
209 | ||
69c69546 WS |
210 | // counts the confirmations |
211 | int m_ctdelay; | |
212 | unsigned long m_display_estimated; | |
8fa2e6a2 | 213 | |
69c69546 | 214 | // for wxPD_APP_MODAL case |
79e58a40 | 215 | wxWindowDisabler *m_winDisabler; |
cbc66a27 | 216 | |
7ad8a38a VZ |
217 | // Temporary event loop created by the dialog itself if there is no |
218 | // currently active loop when it is created. | |
219 | wxEventLoop *m_tempEventLoop; | |
220 | ||
221 | ||
69c69546 | 222 | DECLARE_EVENT_TABLE() |
c31d9c7f | 223 | wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog); |
8fa2e6a2 | 224 | }; |
ce4169a4 | 225 | |
555f645a | 226 | #endif // __PROGDLGH_G__ |