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