]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/generic/progdlgg.h
Use task dialog for wxProgressDialog implementation in wxMSW.
[wxWidgets.git] / include / wx / generic / progdlgg.h
... / ...
CommitLineData
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
17class WXDLLIMPEXP_FWD_CORE wxButton;
18class WXDLLIMPEXP_FWD_CORE wxGauge;
19class WXDLLIMPEXP_FWD_CORE wxStaticText;
20
21/*
22 Progress dialog which shows a moving progress bar.
23 Taken from the Mahogany project.
24*/
25class WXDLLIMPEXP_CORE wxGenericProgressDialog : public wxDialog
26{
27public:
28 wxGenericProgressDialog(const wxString& title, const wxString& message,
29 int maximum = 100,
30 wxWindow *parent = NULL,
31 int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE);
32
33 virtual ~wxGenericProgressDialog();
34
35 virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL);
36 virtual bool Pulse(const wxString& newmsg = wxEmptyString, bool *skip = NULL);
37
38 void Resume();
39
40 int GetValue() const;
41 int GetRange() const;
42 wxString GetMessage() const;
43
44 void SetRange(int maximum);
45
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;
50
51 // Must provide overload to avoid hiding it (and warnings about it)
52 virtual void Update() { wxDialog::Update(); }
53
54 virtual bool Show( bool show = true );
55
56 // This enum is an implementation detail and should not be used
57 // by user code.
58 enum ProgressDialogState
59 {
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
64 };
65
66protected:
67 // This ctor is used by the native MSW implementation only.
68 wxGenericProgressDialog(wxWindow *parent, int maximum, int style);
69
70 void Create(const wxString& title,
71 const wxString& message,
72 int maximum,
73 wxWindow *parent,
74 int style);
75
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:"); }
81
82
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);
89
90 // Converts seconds to HH:mm:ss format.
91 static wxString GetFormattedTime(unsigned long timeInSec);
92
93 // callback for optional abort button
94 void OnCancel(wxCommandEvent&);
95
96 // callback for optional skip button
97 void OnSkip(wxCommandEvent&);
98
99 // callback to disable "hard" window closing
100 void OnClose(wxCloseEvent&);
101
102 // called to disable the other windows while this dialog is shown
103 void DisableOtherWindows();
104
105 // must be called to reenable the other windows temporarily disabled while
106 // the dialog was shown
107 void ReenableOtherWindows();
108
109 // return the top level parent window of this dialog (may be NULL)
110 wxWindow *GetTopParent() const { return m_parentTop; }
111
112
113 // continue processing or not (return value for Update())
114 ProgressDialogState m_state;
115
116 // the maximum value
117 int m_maximum;
118
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
122 size_t m_factor;
123#endif // __WXMSW__
124
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;
131
132private:
133 // update the label to show the given time (in seconds)
134 static void SetTimeLabel(unsigned long val, wxStaticText *label);
135
136 // common part of all ctors
137 void Init(wxWindow *parent, int maximum, int style);
138
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);
142
143 // updates the label message
144 void UpdateMessage(const wxString &newmsg);
145
146 // common part of Update() and Pulse(), returns true if not cancelled
147 bool DoBeforeUpdate(bool *skip);
148
149 // common part of Update() and Pulse()
150 void DoAfterUpdate();
151
152 // shortcuts for enabling buttons
153 void EnableClose();
154 void EnableSkip(bool enable = true);
155 void EnableAbort(bool enable = true);
156 void DisableSkip() { EnableSkip(false); }
157 void DisableAbort() { EnableAbort(false); }
158
159 // the widget displaying current status (may be NULL)
160 wxGauge *m_gauge;
161 // the message displayed
162 wxStaticText *m_msg;
163 // displayed elapsed, estimated, remaining time
164 wxStaticText *m_elapsed,
165 *m_estimated,
166 *m_remaining;
167
168 // parent top level window (may be NULL)
169 wxWindow *m_parentTop;
170
171 // skip some portion
172 bool m_skip;
173
174#if !defined(__SMARTPHONE__)
175 // the abort and skip buttons (or NULL if none)
176 wxButton *m_btnAbort;
177 wxButton *m_btnSkip;
178#endif
179
180 // saves the time when elapsed time was updated so there is only one
181 // update per second
182 unsigned long m_last_timeupdate;
183
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
187 int m_delay;
188
189 // counts the confirmations
190 int m_ctdelay;
191 unsigned long m_display_estimated;
192
193 bool m_hasAbortButton,
194 m_hasSkipButton;
195
196 // for wxPD_APP_MODAL case
197 class WXDLLIMPEXP_FWD_CORE wxWindowDisabler *m_winDisabler;
198
199 DECLARE_EVENT_TABLE()
200 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog);
201};
202
203#endif // __PROGDLGH_G__