]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/progdlgg.h
Don't use wxGenericProgressDialog::m_windowStyle for wxPD_XXX styles.
[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 ProgressDialogState
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 maximum, int style);
71
72 void Create(const wxString& title,
73 const wxString& message,
74 int maximum,
75 wxWindow *parent,
76 int style);
77
78 // Return the labels to use for showing the elapsed/estimated/remaining
79 // times respectively.
80 static wxString GetElapsedLabel() { return _("Elapsed time:"); }
81 static wxString GetEstimatedLabel() { return _("Estimated time:"); }
82 static wxString GetRemainingLabel() { return _("Remaining time:"); }
83
84
85 // Similar to wxWindow::HasFlag() but tests for a presence of a wxPD_XXX
86 // flag in our (separate) flags instead of using m_windowStyle.
87 bool HasPDFlag(int flag) const { return (m_pdStyle & flag) != 0; }
88
89 // Return the progress dialog style. Prefer to use HasPDFlag() if possible.
90 int GetPDStyle() const { return m_pdStyle; }
91
92
93 // Updates estimated times from a given progress bar value and stores the
94 // results in provided arguments.
95 void UpdateTimeEstimates(int value,
96 unsigned long &elapsedTime,
97 unsigned long &estimatedTime,
98 unsigned long &remainingTime);
99
100 // Converts seconds to HH:mm:ss format.
101 static wxString GetFormattedTime(unsigned long timeInSec);
102
103 // callback for optional abort button
104 void OnCancel(wxCommandEvent&);
105
106 // callback for optional skip button
107 void OnSkip(wxCommandEvent&);
108
109 // callback to disable "hard" window closing
110 void OnClose(wxCloseEvent&);
111
112 // called to disable the other windows while this dialog is shown
113 void DisableOtherWindows();
114
115 // must be called to reenable the other windows temporarily disabled while
116 // the dialog was shown
117 void ReenableOtherWindows();
118
119 // return the top level parent window of this dialog (may be NULL)
120 wxWindow *GetTopParent() const { return m_parentTop; }
121
122
123 // continue processing or not (return value for Update())
124 ProgressDialogState m_state;
125
126 // the maximum value
127 int m_maximum;
128
129 #if defined(__WXMSW__ ) || defined(__WXPM__)
130 // the factor we use to always keep the value in 16 bit range as the native
131 // control only supports ranges from 0 to 65,535
132 size_t m_factor;
133 #endif // __WXMSW__
134
135 // time when the dialog was created
136 unsigned long m_timeStart;
137 // time when the dialog was closed or cancelled
138 unsigned long m_timeStop;
139 // time between the moment the dialog was closed/cancelled and resume
140 unsigned long m_break;
141
142 private:
143 // update the label to show the given time (in seconds)
144 static void SetTimeLabel(unsigned long val, wxStaticText *label);
145
146 // common part of all ctors
147 void Init(wxWindow *parent, int maximum, int style);
148
149 // create the label with given text and another one to show the time nearby
150 // as the next windows in the sizer, returns the created control
151 wxStaticText *CreateLabel(const wxString& text, wxSizer *sizer);
152
153 // updates the label message
154 void UpdateMessage(const wxString &newmsg);
155
156 // common part of Update() and Pulse(), returns true if not cancelled
157 bool DoBeforeUpdate(bool *skip);
158
159 // common part of Update() and Pulse()
160 void DoAfterUpdate();
161
162 // shortcuts for enabling buttons
163 void EnableClose();
164 void EnableSkip(bool enable = true);
165 void EnableAbort(bool enable = true);
166 void DisableSkip() { EnableSkip(false); }
167 void DisableAbort() { EnableAbort(false); }
168
169 // the widget displaying current status (may be NULL)
170 wxGauge *m_gauge;
171 // the message displayed
172 wxStaticText *m_msg;
173 // displayed elapsed, estimated, remaining time
174 wxStaticText *m_elapsed,
175 *m_estimated,
176 *m_remaining;
177
178 // parent top level window (may be NULL)
179 wxWindow *m_parentTop;
180
181 // Progress dialog styles: this is not the same as m_windowStyle because
182 // wxPD_XXX constants clash with the existing TLW styles so to be sure we
183 // don't have any conflicts we just use a separate variable for storing
184 // them.
185 int m_pdStyle;
186
187 // skip some portion
188 bool m_skip;
189
190 #if !defined(__SMARTPHONE__)
191 // the abort and skip buttons (or NULL if none)
192 wxButton *m_btnAbort;
193 wxButton *m_btnSkip;
194 #endif
195
196 // saves the time when elapsed time was updated so there is only one
197 // update per second
198 unsigned long m_last_timeupdate;
199
200 // tells how often a change of the estimated time has to be confirmed
201 // before it is actually displayed - this reduces the frequency of updates
202 // of estimated and remaining time
203 int m_delay;
204
205 // counts the confirmations
206 int m_ctdelay;
207 unsigned long m_display_estimated;
208
209 // for wxPD_APP_MODAL case
210 wxWindowDisabler *m_winDisabler;
211
212 // Temporary event loop created by the dialog itself if there is no
213 // currently active loop when it is created.
214 wxEventLoop *m_tempEventLoop;
215
216
217 DECLARE_EVENT_TABLE()
218 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog);
219 };
220
221 #endif // __PROGDLGH_G__