]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/progdlgg.h
Implement monitoring of file descriptors in wxMotif event loop.
[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 // 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();
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);
35
36 virtual ~wxGenericProgressDialog();
37
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
44 virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL);
45 virtual bool Pulse(const wxString& newmsg = wxEmptyString, bool *skip = NULL);
46
47 void Resume();
48
49 int GetValue() const;
50 int GetRange() const;
51 wxString GetMessage() const;
52
53 void SetRange(int maximum);
54
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
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
65 // This enum is an implementation detail and should not be used
66 // by user code.
67 enum State
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
72 Finished, // finished, waiting to be removed from screen
73 Dismissed // was closed by user after finishing
74 };
75
76 protected:
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
83 // Return the labels to use for showing the elapsed/estimated/remaining
84 // times respectively.
85 static wxString GetElapsedLabel() { return wxGetTranslation("Elapsed time:"); }
86 static wxString GetEstimatedLabel() { return wxGetTranslation("Estimated time:"); }
87 static wxString GetRemainingLabel() { return wxGetTranslation("Remaining time:"); }
88
89
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; }
96 void SetPDStyle(int pdStyle) { m_pdStyle = pdStyle; }
97
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
108 // callback for optional abort button
109 void OnCancel(wxCommandEvent&);
110
111 // callback for optional skip button
112 void OnSkip(wxCommandEvent&);
113
114 // callback to disable "hard" window closing
115 void OnClose(wxCloseEvent&);
116
117 // called to disable the other windows while this dialog is shown
118 void DisableOtherWindows();
119
120 // must be called to reenable the other windows temporarily disabled while
121 // the dialog was shown
122 void ReenableOtherWindows();
123
124 // Set the top level parent we store from the parent window provided when
125 // creating the dialog.
126 void SetTopParent(wxWindow* parent);
127
128 // return the top level parent window of this dialog (may be NULL)
129 wxWindow *GetTopParent() const { return m_parentTop; }
130
131
132 // continue processing or not (return value for Update())
133 State m_state;
134
135 // the maximum value
136 int m_maximum;
137
138 #if defined(__WXMSW__ ) || defined(__WXPM__)
139 // the factor we use to always keep the value in 16 bit range as the native
140 // control only supports ranges from 0 to 65,535
141 size_t m_factor;
142 #endif // __WXMSW__
143
144 // time when the dialog was created
145 unsigned long m_timeStart;
146 // time when the dialog was closed or cancelled
147 unsigned long m_timeStop;
148 // time between the moment the dialog was closed/cancelled and resume
149 unsigned long m_break;
150
151 private:
152 // update the label to show the given time (in seconds)
153 static void SetTimeLabel(unsigned long val, wxStaticText *label);
154
155 // common part of all ctors
156 void Init();
157
158 // create the label with given text and another one to show the time nearby
159 // as the next windows in the sizer, returns the created control
160 wxStaticText *CreateLabel(const wxString& text, wxSizer *sizer);
161
162 // updates the label message
163 void UpdateMessage(const wxString &newmsg);
164
165 // common part of Update() and Pulse(), returns true if not cancelled
166 bool DoBeforeUpdate(bool *skip);
167
168 // common part of Update() and Pulse()
169 void DoAfterUpdate();
170
171 // shortcuts for enabling buttons
172 void EnableClose();
173 void EnableSkip(bool enable = true);
174 void EnableAbort(bool enable = true);
175 void DisableSkip() { EnableSkip(false); }
176 void DisableAbort() { EnableAbort(false); }
177
178 // the widget displaying current status (may be NULL)
179 wxGauge *m_gauge;
180 // the message displayed
181 wxStaticText *m_msg;
182 // displayed elapsed, estimated, remaining time
183 wxStaticText *m_elapsed,
184 *m_estimated,
185 *m_remaining;
186
187 // parent top level window (may be NULL)
188 wxWindow *m_parentTop;
189
190 // Progress dialog styles: this is not the same as m_windowStyle because
191 // wxPD_XXX constants clash with the existing TLW styles so to be sure we
192 // don't have any conflicts we just use a separate variable for storing
193 // them.
194 int m_pdStyle;
195
196 // skip some portion
197 bool m_skip;
198
199 #if !defined(__SMARTPHONE__)
200 // the abort and skip buttons (or NULL if none)
201 wxButton *m_btnAbort;
202 wxButton *m_btnSkip;
203 #endif
204
205 // saves the time when elapsed time was updated so there is only one
206 // update per second
207 unsigned long m_last_timeupdate;
208
209 // tells how often a change of the estimated time has to be confirmed
210 // before it is actually displayed - this reduces the frequency of updates
211 // of estimated and remaining time
212 int m_delay;
213
214 // counts the confirmations
215 int m_ctdelay;
216 unsigned long m_display_estimated;
217
218 // for wxPD_APP_MODAL case
219 wxWindowDisabler *m_winDisabler;
220
221 // Temporary event loop created by the dialog itself if there is no
222 // currently active loop when it is created.
223 wxEventLoop *m_tempEventLoop;
224
225
226 DECLARE_EVENT_TABLE()
227 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog);
228 };
229
230 #endif // __PROGDLGH_G__