1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGenericProgressDialog class
4 // Author: Karsten Ballueder
5 // Modified by: Francesco Montorsi
8 // Copyright: (c) Karsten Ballueder
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef __PROGDLGH_G__
13 #define __PROGDLGH_G__
15 #include "wx/dialog.h"
17 class WXDLLIMPEXP_FWD_CORE wxButton
;
18 class WXDLLIMPEXP_FWD_CORE wxGauge
;
19 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
22 Progress dialog which shows a moving progress bar.
23 Taken from the Mahogany project.
25 class WXDLLIMPEXP_CORE wxGenericProgressDialog
: public wxDialog
28 wxGenericProgressDialog(const wxString
& title
, const wxString
& message
,
30 wxWindow
*parent
= NULL
,
31 int style
= wxPD_APP_MODAL
| wxPD_AUTO_HIDE
);
33 virtual ~wxGenericProgressDialog();
35 virtual bool Update(int value
, const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
36 virtual bool Pulse(const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
42 wxString
GetMessage() const;
44 void SetRange(int maximum
);
46 // Return whether "Cancel" or "Skip" button was pressed, always return
47 // false if the corresponding button is not shown.
48 bool WasCancelled() const;
49 bool WasSkipped() const;
51 // Must provide overload to avoid hiding it (and warnings about it)
52 virtual void Update() { wxDialog::Update(); }
54 virtual bool Show( bool show
= true );
56 // This enum is an implementation detail and should not be used
58 enum ProgressDialogState
60 Uncancelable
= -1, // dialog can't be canceled
61 Canceled
, // can be cancelled and, in fact, was
62 Continue
, // can be cancelled but wasn't
63 Finished
// finished, waiting to be removed from screen
67 // This ctor is used by the native MSW implementation only.
68 wxGenericProgressDialog(wxWindow
*parent
, int maximum
, int style
);
70 void Create(const wxString
& title
,
71 const wxString
& message
,
76 // Return the labels to use for showing the elapsed/estimated/remaining
77 // times respectively.
78 static wxString
GetElapsedLabel() { return _("Elapsed time:"); }
79 static wxString
GetEstimatedLabel() { return _("Estimated time:"); }
80 static wxString
GetRemainingLabel() { return _("Remaining time:"); }
83 // Updates estimated times from a given progress bar value and stores the
84 // results in provided arguments.
85 void UpdateTimeEstimates(int value
,
86 unsigned long &elapsedTime
,
87 unsigned long &estimatedTime
,
88 unsigned long &remainingTime
);
90 // Converts seconds to HH:mm:ss format.
91 static wxString
GetFormattedTime(unsigned long timeInSec
);
93 // callback for optional abort button
94 void OnCancel(wxCommandEvent
&);
96 // callback for optional skip button
97 void OnSkip(wxCommandEvent
&);
99 // callback to disable "hard" window closing
100 void OnClose(wxCloseEvent
&);
102 // called to disable the other windows while this dialog is shown
103 void DisableOtherWindows();
105 // must be called to reenable the other windows temporarily disabled while
106 // the dialog was shown
107 void ReenableOtherWindows();
109 // return the top level parent window of this dialog (may be NULL)
110 wxWindow
*GetTopParent() const { return m_parentTop
; }
113 // continue processing or not (return value for Update())
114 ProgressDialogState m_state
;
119 #if defined(__WXMSW__ ) || defined(__WXPM__)
120 // the factor we use to always keep the value in 16 bit range as the native
121 // control only supports ranges from 0 to 65,535
125 // time when the dialog was created
126 unsigned long m_timeStart
;
127 // time when the dialog was closed or cancelled
128 unsigned long m_timeStop
;
129 // time between the moment the dialog was closed/cancelled and resume
130 unsigned long m_break
;
133 // update the label to show the given time (in seconds)
134 static void SetTimeLabel(unsigned long val
, wxStaticText
*label
);
136 // common part of all ctors
137 void Init(wxWindow
*parent
, int maximum
, int style
);
139 // create the label with given text and another one to show the time nearby
140 // as the next windows in the sizer, returns the created control
141 wxStaticText
*CreateLabel(const wxString
& text
, wxSizer
*sizer
);
143 // updates the label message
144 void UpdateMessage(const wxString
&newmsg
);
146 // common part of Update() and Pulse(), returns true if not cancelled
147 bool DoBeforeUpdate(bool *skip
);
149 // common part of Update() and Pulse()
150 void DoAfterUpdate();
152 // shortcuts for enabling buttons
154 void EnableSkip(bool enable
= true);
155 void EnableAbort(bool enable
= true);
156 void DisableSkip() { EnableSkip(false); }
157 void DisableAbort() { EnableAbort(false); }
159 // the widget displaying current status (may be NULL)
161 // the message displayed
163 // displayed elapsed, estimated, remaining time
164 wxStaticText
*m_elapsed
,
168 // parent top level window (may be NULL)
169 wxWindow
*m_parentTop
;
174 #if !defined(__SMARTPHONE__)
175 // the abort and skip buttons (or NULL if none)
176 wxButton
*m_btnAbort
;
180 // saves the time when elapsed time was updated so there is only one
182 unsigned long m_last_timeupdate
;
184 // tells how often a change of the estimated time has to be confirmed
185 // before it is actually displayed - this reduces the frequency of updates
186 // of estimated and remaining time
189 // counts the confirmations
191 unsigned long m_display_estimated
;
193 bool m_hasAbortButton
,
196 // for wxPD_APP_MODAL case
197 class WXDLLIMPEXP_FWD_CORE wxWindowDisabler
*m_winDisabler
;
199 DECLARE_EVENT_TABLE()
200 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog
);
203 #endif // __PROGDLGH_G__