]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/progdlgg.h
9c957e7ebfa0e75d182f0e1274de3cfb20c4a4d4
[wxWidgets.git] / include / wx / generic / progdlgg.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: progdlgg.h
3 // Purpose: wxGenericProgressDialog class
4 // Author: Karsten Ballueder
5 // Modified by: Francesco Montorsi
6 // Created: 09.05.1999
7 // RCS-ID: $Id$
8 // Copyright: (c) Karsten Ballueder
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __PROGDLGH_G__
13 #define __PROGDLGH_G__
14
15 #include "wx/dialog.h"
16
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;
22
23 /*
24 Progress dialog which shows a moving progress bar.
25 Taken from the Mahogany project.
26 */
27 class WXDLLIMPEXP_CORE wxGenericProgressDialog : public wxDialog
28 {
29 public:
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 virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL);
38 virtual bool Pulse(const wxString& newmsg = wxEmptyString, bool *skip = NULL);
39
40 void Resume();
41
42 int GetValue() const;
43 int GetRange() const;
44 wxString GetMessage() const;
45
46 void SetRange(int maximum);
47
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;
52
53 // Must provide overload to avoid hiding it (and warnings about it)
54 virtual void Update() { wxDialog::Update(); }
55
56 virtual bool Show( bool show = true );
57
58 // This enum is an implementation detail and should not be used
59 // by user code.
60 enum State
61 {
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 };
67
68 protected:
69 // This ctor is used by the native MSW implementation only.
70 wxGenericProgressDialog(wxWindow *parent, int style);
71
72 void Create(const wxString& title,
73 const wxString& message,
74 int maximum,
75 wxWindow *parent,
76 int style);
77
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
81 // display progress.
82 void SetMaximum(int maximum);
83
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:"); }
89
90
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; }
94
95 // Return the progress dialog style. Prefer to use HasPDFlag() if possible.
96 int GetPDStyle() const { return m_pdStyle; }
97
98
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);
105
106 // Converts seconds to HH:mm:ss format.
107 static wxString GetFormattedTime(unsigned long timeInSec);
108
109 // callback for optional abort button
110 void OnCancel(wxCommandEvent&);
111
112 // callback for optional skip button
113 void OnSkip(wxCommandEvent&);
114
115 // callback to disable "hard" window closing
116 void OnClose(wxCloseEvent&);
117
118 // called to disable the other windows while this dialog is shown
119 void DisableOtherWindows();
120
121 // must be called to reenable the other windows temporarily disabled while
122 // the dialog was shown
123 void ReenableOtherWindows();
124
125 // return the top level parent window of this dialog (may be NULL)
126 wxWindow *GetTopParent() const { return m_parentTop; }
127
128
129 // continue processing or not (return value for Update())
130 State m_state;
131
132 // the maximum value
133 int m_maximum;
134
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
138 size_t m_factor;
139 #endif // __WXMSW__
140
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;
147
148 private:
149 // update the label to show the given time (in seconds)
150 static void SetTimeLabel(unsigned long val, wxStaticText *label);
151
152 // common part of all ctors
153 void Init(wxWindow *parent, int style);
154
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);
158
159 // updates the label message
160 void UpdateMessage(const wxString &newmsg);
161
162 // common part of Update() and Pulse(), returns true if not cancelled
163 bool DoBeforeUpdate(bool *skip);
164
165 // common part of Update() and Pulse()
166 void DoAfterUpdate();
167
168 // shortcuts for enabling buttons
169 void EnableClose();
170 void EnableSkip(bool enable = true);
171 void EnableAbort(bool enable = true);
172 void DisableSkip() { EnableSkip(false); }
173 void DisableAbort() { EnableAbort(false); }
174
175 // the widget displaying current status (may be NULL)
176 wxGauge *m_gauge;
177 // the message displayed
178 wxStaticText *m_msg;
179 // displayed elapsed, estimated, remaining time
180 wxStaticText *m_elapsed,
181 *m_estimated,
182 *m_remaining;
183
184 // parent top level window (may be NULL)
185 wxWindow *m_parentTop;
186
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
190 // them.
191 int m_pdStyle;
192
193 // skip some portion
194 bool m_skip;
195
196 #if !defined(__SMARTPHONE__)
197 // the abort and skip buttons (or NULL if none)
198 wxButton *m_btnAbort;
199 wxButton *m_btnSkip;
200 #endif
201
202 // saves the time when elapsed time was updated so there is only one
203 // update per second
204 unsigned long m_last_timeupdate;
205
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
209 int m_delay;
210
211 // counts the confirmations
212 int m_ctdelay;
213 unsigned long m_display_estimated;
214
215 // for wxPD_APP_MODAL case
216 wxWindowDisabler *m_winDisabler;
217
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;
221
222
223 DECLARE_EVENT_TABLE()
224 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog);
225 };
226
227 #endif // __PROGDLGH_G__