]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/progdlgg.h
wxRTC: fixed guidelines overwriting adjacent cell borders; corrected capitalisation...
[wxWidgets.git] / include / wx / generic / progdlgg.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/progdlgg.h
3 // Purpose: wxGenericProgressDialog class
4 // Author: Karsten Ballueder
5 // Modified by: Francesco Montorsi
6 // Created: 09.05.1999
7 // Copyright: (c) Karsten Ballueder
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef __PROGDLGH_G__
12 #define __PROGDLGH_G__
13
14 #include "wx/dialog.h"
15
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;
21
22 /*
23 Progress dialog which shows a moving progress bar.
24 Taken from the Mahogany project.
25 */
26 class WXDLLIMPEXP_CORE wxGenericProgressDialog : public wxDialog
27 {
28 public:
29 wxGenericProgressDialog();
30 wxGenericProgressDialog(const wxString& title, const wxString& message,
31 int maximum = 100,
32 wxWindow *parent = NULL,
33 int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE);
34
35 virtual ~wxGenericProgressDialog();
36
37 bool Create(const wxString& title,
38 const wxString& message,
39 int maximum = 100,
40 wxWindow *parent = NULL,
41 int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE);
42
43 virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL);
44 virtual bool Pulse(const wxString& newmsg = wxEmptyString, bool *skip = NULL);
45
46 void Resume();
47
48 int GetValue() const;
49 int GetRange() const;
50 wxString GetMessage() const;
51
52 void SetRange(int maximum);
53
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;
58
59 // Must provide overload to avoid hiding it (and warnings about it)
60 virtual void Update() { wxDialog::Update(); }
61
62 virtual bool Show( bool show = true );
63
64 // This enum is an implementation detail and should not be used
65 // by user code.
66 enum State
67 {
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
73 };
74
75 protected:
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
79 // display progress.
80 void SetMaximum(int maximum);
81
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:"); }
87
88
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; }
92
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; }
96
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);
103
104 // Converts seconds to HH:mm:ss format.
105 static wxString GetFormattedTime(unsigned long timeInSec);
106
107 // callback for optional abort button
108 void OnCancel(wxCommandEvent&);
109
110 // callback for optional skip button
111 void OnSkip(wxCommandEvent&);
112
113 // callback to disable "hard" window closing
114 void OnClose(wxCloseEvent&);
115
116 // called to disable the other windows while this dialog is shown
117 void DisableOtherWindows();
118
119 // must be called to reenable the other windows temporarily disabled while
120 // the dialog was shown
121 void ReenableOtherWindows();
122
123 // Set the top level parent we store from the parent window provided when
124 // creating the dialog.
125 void SetTopParent(wxWindow* parent);
126
127 // return the top level parent window of this dialog (may be NULL)
128 wxWindow *GetTopParent() const { return m_parentTop; }
129
130
131 // continue processing or not (return value for Update())
132 State m_state;
133
134 // the maximum value
135 int m_maximum;
136
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
140 size_t m_factor;
141 #endif // __WXMSW__
142
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;
149
150 private:
151 // update the label to show the given time (in seconds)
152 static void SetTimeLabel(unsigned long val, wxStaticText *label);
153
154 // common part of all ctors
155 void Init();
156
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);
160
161 // updates the label message
162 void UpdateMessage(const wxString &newmsg);
163
164 // common part of Update() and Pulse(), returns true if not cancelled
165 bool DoBeforeUpdate(bool *skip);
166
167 // common part of Update() and Pulse()
168 void DoAfterUpdate();
169
170 // shortcuts for enabling buttons
171 void EnableClose();
172 void EnableSkip(bool enable = true);
173 void EnableAbort(bool enable = true);
174 void DisableSkip() { EnableSkip(false); }
175 void DisableAbort() { EnableAbort(false); }
176
177 // the widget displaying current status (may be NULL)
178 wxGauge *m_gauge;
179 // the message displayed
180 wxStaticText *m_msg;
181 // displayed elapsed, estimated, remaining time
182 wxStaticText *m_elapsed,
183 *m_estimated,
184 *m_remaining;
185
186 // parent top level window (may be NULL)
187 wxWindow *m_parentTop;
188
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
192 // them.
193 int m_pdStyle;
194
195 // skip some portion
196 bool m_skip;
197
198 #if !defined(__SMARTPHONE__)
199 // the abort and skip buttons (or NULL if none)
200 wxButton *m_btnAbort;
201 wxButton *m_btnSkip;
202 #endif
203
204 // saves the time when elapsed time was updated so there is only one
205 // update per second
206 unsigned long m_last_timeupdate;
207
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
211 int m_delay;
212
213 // counts the confirmations
214 int m_ctdelay;
215 unsigned long m_display_estimated;
216
217 // for wxPD_APP_MODAL case
218 wxWindowDisabler *m_winDisabler;
219
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;
223
224
225 DECLARE_EVENT_TABLE()
226 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog);
227 };
228
229 #endif // __PROGDLGH_G__