]> git.saurik.com Git - wxWidgets.git/blame - src/generic/progdlgg.cpp
Use C locale for numbers in wx(File)Config.
[wxWidgets.git] / src / generic / progdlgg.cpp
CommitLineData
8fa2e6a2 1/////////////////////////////////////////////////////////////////////////////
9eddec69 2// Name: src/generic/progdlgg.cpp
8fa2e6a2 3// Purpose: wxProgressDialog class
9d55bfef 4// Author: Karsten Ballueder
8fa2e6a2
KB
5// Modified by:
6// Created: 09.05.1999
7// RCS-ID: $Id$
9d55bfef 8// Copyright: (c) Karsten Ballueder
65571936 9// Licence: wxWindows licence
8fa2e6a2
KB
10/////////////////////////////////////////////////////////////////////////////
11
0655ad29
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
8fa2e6a2
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
f81a6620 24 #pragma hdrstop
8fa2e6a2
KB
25#endif
26
0655ad29
VZ
27#if wxUSE_PROGRESSDLG
28
8fa2e6a2 29#ifndef WX_PRECOMP
f81a6620
VZ
30 #include "wx/utils.h"
31 #include "wx/frame.h"
32 #include "wx/button.h"
33 #include "wx/stattext.h"
0ca3b64f 34 #include "wx/sizer.h"
f81a6620
VZ
35 #include "wx/event.h"
36 #include "wx/gauge.h"
37 #include "wx/intl.h"
720dcba6 38 #include "wx/dcclient.h"
9b61f868 39 #include "wx/timer.h"
9eddec69 40 #include "wx/settings.h"
731bcffc 41 #include "wx/app.h"
8fa2e6a2
KB
42#endif
43
fe8635a7 44#include "wx/progdlg.h"
dde19c21 45#include "wx/evtloop.h"
8fa2e6a2 46
d2cdad17
WS
47// ---------------------------------------------------------------------------
48// macros
49// ---------------------------------------------------------------------------
50
51/* Macro for avoiding #ifdefs when value have to be different depending on size of
9a357011 52 device we display on - take it from something like wxDesktopPolicy in the future
d2cdad17
WS
53 */
54
55#if defined(__SMARTPHONE__)
56 #define wxLARGESMALL(large,small) small
57#else
58 #define wxLARGESMALL(large,small) large
59#endif
60
0655ad29
VZ
61// ----------------------------------------------------------------------------
62// constants
63// ----------------------------------------------------------------------------
64
d2cdad17 65#define LAYOUT_MARGIN wxLARGESMALL(8,2)
8fa2e6a2 66
ecda9475
WS
67static const int wxID_SKIP = 32000; // whatever
68
0655ad29
VZ
69// ----------------------------------------------------------------------------
70// private functions
71// ----------------------------------------------------------------------------
72
73// update the label to show the given time (in seconds)
74static void SetTimeLabel(unsigned long val, wxStaticText *label);
75
76// ----------------------------------------------------------------------------
77// event tables
78// ----------------------------------------------------------------------------
8fa2e6a2 79
1b6452df 80BEGIN_EVENT_TABLE(wxProgressDialog, wxDialog)
ef8698d6 81 EVT_BUTTON(wxID_CANCEL, wxProgressDialog::OnCancel)
ecda9475 82 EVT_BUTTON(wxID_SKIP, wxProgressDialog::OnSkip)
ef8698d6 83
ef8698d6 84 EVT_CLOSE(wxProgressDialog::OnClose)
1b6452df 85END_EVENT_TABLE()
8fa2e6a2 86
1b6452df 87IMPLEMENT_CLASS(wxProgressDialog, wxDialog)
8fa2e6a2 88
0655ad29 89// ============================================================================
db1a42b8 90// wxProgressDialog implementation
0655ad29 91// ============================================================================
8fa2e6a2 92
0655ad29 93// ----------------------------------------------------------------------------
db1a42b8 94// wxProgressDialog creation
0655ad29 95// ----------------------------------------------------------------------------
f81a6620 96
695f550b
VZ
97wxProgressDialog::wxProgressDialog(const wxString& title,
98 const wxString& message,
0655ad29
VZ
99 int maximum,
100 wxWindow *parent,
101 int style)
cdc48273 102 : wxDialog(GetParentForModalDialog(parent, style), wxID_ANY, title),
3786ce5a 103 m_skip(false),
69c69546
WS
104 m_delay(3),
105 m_hasAbortButton(false),
106 m_hasSkipButton(false)
0655ad29 107{
39cc7a0b
VZ
108 // we may disappear at any moment, let the others know about it
109 SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
96becbd8
VS
110 m_windowStyle |= style;
111
69c69546
WS
112 m_hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
113 m_hasSkipButton = (style & wxPD_CAN_SKIP) != 0;
c4d305b7 114
cff7ef89 115#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
c4d305b7
VZ
116 // we have to remove the "Close" button from the title bar then as it is
117 // confusing to have it - it doesn't work anyhow
118 //
119 // FIXME: should probably have a (extended?) window style for this
69c69546 120 if ( !m_hasAbortButton )
c4d305b7 121 {
dabbc6a5 122 EnableCloseButton(false);
c4d305b7
VZ
123 }
124#endif // wxMSW
125
d2cdad17
WS
126#if defined(__SMARTPHONE__)
127 SetLeftMenu();
128#endif
129
69c69546 130 m_state = m_hasAbortButton ? Continue : Uncancelable;
0655ad29
VZ
131 m_maximum = maximum;
132
94640e04 133#if defined(__WXMSW__) || defined(__WXPM__)
7c349adb
VZ
134 // we can't have values > 65,536 in the progress control under Windows, so
135 // scale everything down
136 m_factor = m_maximum / 65536 + 1;
137 m_maximum /= m_factor;
138#endif // __WXMSW__
139
6258e418 140 m_parentTop = wxGetTopLevelParent(parent);
abceee76 141
0655ad29 142 wxClientDC dc(this);
a756f210 143 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
e8a301af 144 wxCoord widthText = 0;
f1415824 145 dc.GetTextExtent(message, &widthText, NULL, NULL, NULL, NULL);
0655ad29 146
695f550b
VZ
147 // top-level sizerTop
148 wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
d2cdad17 149
dabbc6a5 150 m_msg = new wxStaticText(this, wxID_ANY, message);
695f550b 151 sizerTop->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN);
0655ad29 152
0655ad29
VZ
153 if ( maximum > 0 )
154 {
ecda9475 155 int gauge_style = wxGA_HORIZONTAL;
695f550b 156 if ( style & wxPD_SMOOTH )
ecda9475 157 gauge_style |= wxGA_SMOOTH;
695f550b
VZ
158 m_gauge = new wxGauge
159 (
160 this,
161 wxID_ANY,
162 m_maximum,
163 wxDefaultPosition,
164 // make the progress bar sufficiently long
165 wxSize(wxMin(wxGetClientDisplayRect().width/3, 300), -1),
166 gauge_style
167 );
168
169 sizerTop->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN);
0655ad29 170 m_gauge->SetValue(0);
0655ad29
VZ
171 }
172 else
695f550b
VZ
173 {
174 m_gauge = NULL;
175 }
0655ad29
VZ
176
177 // create the estimated/remaining/total time zones if requested
695f550b
VZ
178 m_elapsed =
179 m_estimated =
180 m_remaining = NULL;
181 m_display_estimated =
182 m_last_timeupdate =
183 m_break = 0;
2c5ef4e2 184 m_ctdelay = 0;
0655ad29 185
8d6854a6
VZ
186 // also count how many labels we really have
187 size_t nTimeLabels = 0;
188
695f550b
VZ
189 wxSizer * const sizerLabels = new wxFlexGridSizer(2);
190
0655ad29
VZ
191 if ( style & wxPD_ELAPSED_TIME )
192 {
193 nTimeLabels++;
194
695f550b 195 m_elapsed = CreateLabel(_("Elapsed time:"), sizerLabels);
0655ad29
VZ
196 }
197
198 if ( style & wxPD_ESTIMATED_TIME )
199 {
200 nTimeLabels++;
201
695f550b 202 m_estimated = CreateLabel(_("Estimated time:"), sizerLabels);
0655ad29
VZ
203 }
204
205 if ( style & wxPD_REMAINING_TIME )
206 {
207 nTimeLabels++;
208
695f550b 209 m_remaining = CreateLabel(_("Remaining time:"), sizerLabels);
0655ad29 210 }
695f550b 211 sizerTop->Add(sizerLabels, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, LAYOUT_MARGIN);
0655ad29
VZ
212
213 if ( nTimeLabels > 0 )
214 {
215 // set it to the current time
216 m_timeStart = wxGetCurrentTime();
0655ad29
VZ
217 }
218
d2cdad17 219#if defined(__SMARTPHONE__)
69c69546 220 if ( m_hasSkipButton )
ecda9475 221 SetRightMenu(wxID_SKIP, _("Skip"));
69c69546 222 if ( m_hasAbortButton )
ecda9475 223 SetLeftMenu(wxID_CANCEL);
d2cdad17 224#else
695f550b
VZ
225 m_btnAbort =
226 m_btnSkip = NULL;
227
ecda9475 228 wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
0655ad29 229
695f550b 230 // Windows dialogs usually have buttons in the lower right corner
3786ce5a 231 const int sizerFlags =
94640e04 232#if defined(__WXMSW__) || defined(__WXPM__)
ecda9475 233 wxALIGN_RIGHT | wxALL
0655ad29 234#else // !MSW
ecda9475 235 wxALIGN_CENTER_HORIZONTAL | wxBOTTOM | wxTOP
0655ad29 236#endif // MSW/!MSW
ecda9475
WS
237 ;
238
69c69546 239 if ( m_hasSkipButton )
ecda9475 240 {
695f550b 241 m_btnSkip = new wxButton(this, wxID_SKIP, _("&Skip"));
ecda9475 242
ecda9475 243 buttonSizer->Add(m_btnSkip, 0, sizerFlags, LAYOUT_MARGIN);
0655ad29 244 }
ecda9475 245
69c69546 246 if ( m_hasAbortButton )
e269a9be 247 {
ecda9475
WS
248 m_btnAbort = new wxButton(this, wxID_CANCEL);
249
ecda9475 250 buttonSizer->Add(m_btnAbort, 0, sizerFlags, LAYOUT_MARGIN);
e269a9be 251 }
0655ad29 252
695f550b 253 sizerTop->Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN );
ecda9475
WS
254#endif // __SMARTPHONE__/!__SMARTPHONE__
255
695f550b 256 SetSizerAndFit(sizerTop);
0655ad29
VZ
257
258 Centre(wxCENTER_FRAME | wxBOTH);
259
cbc66a27 260 if ( style & wxPD_APP_MODAL )
0655ad29 261 {
cbc66a27 262 m_winDisabler = new wxWindowDisabler(this);
0655ad29
VZ
263 }
264 else
265 {
cbc66a27 266 if ( m_parentTop )
dabbc6a5 267 m_parentTop->Disable();
cbc66a27 268 m_winDisabler = NULL;
0655ad29
VZ
269 }
270
dabbc6a5
DS
271 Show();
272 Enable();
33961d59 273
70f3fad6
VZ
274 // this one can be initialized even if the others are unknown for now
275 //
276 // NB: do it after calling Layout() to keep the labels correctly aligned
277 if ( m_elapsed )
278 {
279 SetTimeLabel(0, m_elapsed);
280 }
281
f89d65ea 282 Update();
8fa2e6a2
KB
283}
284
695f550b
VZ
285wxStaticText *
286wxProgressDialog::CreateLabel(const wxString& text, wxSizer *sizer)
0655ad29 287{
695f550b
VZ
288 wxStaticText *label = new wxStaticText(this, wxID_ANY, text);
289 wxStaticText *value = new wxStaticText(this, wxID_ANY, _("unknown"));
0655ad29 290
d2cdad17
WS
291 // select placement most native or nice on target GUI
292#if defined(__SMARTPHONE__)
695f550b
VZ
293 // value and time to the left in two rows
294 sizer->Add(label, 1, wxALIGN_LEFT);
295 sizer->Add(value, 1, wxALIGN_LEFT);
fe8635a7 296#elif defined(__WXMSW__) || defined(__WXPM__) || defined(__WXMAC__) || defined(__WXGTK20__)
695f550b
VZ
297 // value and time centered in one row
298 sizer->Add(label, 1, wxLARGESMALL(wxALIGN_RIGHT,wxALIGN_LEFT) | wxTOP | wxRIGHT, LAYOUT_MARGIN);
299 sizer->Add(value, 1, wxALIGN_LEFT | wxTOP, LAYOUT_MARGIN);
d2cdad17 300#else
695f550b
VZ
301 // value and time to the right in one row
302 sizer->Add(label);
303 sizer->Add(value, 0, wxLEFT, LAYOUT_MARGIN);
d2cdad17 304#endif
0655ad29 305
695f550b 306 return value;
0655ad29 307}
8fa2e6a2 308
db1a42b8
VZ
309// ----------------------------------------------------------------------------
310// wxProgressDialog operations
311// ----------------------------------------------------------------------------
312
8fa2e6a2 313bool
ecda9475 314wxProgressDialog::Update(int value, const wxString& newmsg, bool *skip)
8fa2e6a2 315{
86417abf
VZ
316 if ( !DoBeforeUpdate(skip) )
317 return false;
318
abceee76 319 wxASSERT_MSG( value == -1 || m_gauge, wxT("cannot update non existent dialog") );
7c349adb
VZ
320
321#ifdef __WXMSW__
322 value /= m_factor;
323#endif // __WXMSW__
324
abceee76
VZ
325 wxASSERT_MSG( value <= m_maximum, wxT("invalid progress value") );
326
c4c6ada9
VZ
327 if ( m_gauge )
328 m_gauge->SetValue(value);
abceee76 329
fe8635a7 330 UpdateMessage(newmsg);
abceee76
VZ
331
332 if ( (m_elapsed || m_remaining || m_estimated) && (value != 0) )
333 {
334 unsigned long elapsed = wxGetCurrentTime() - m_timeStart;
2c5ef4e2
VZ
335 if ( m_last_timeupdate < elapsed
336 || value == m_maximum
337 )
338 {
339 m_last_timeupdate = elapsed;
340 unsigned long estimated = m_break +
341 (unsigned long)(( (double) (elapsed-m_break) * m_maximum ) / ((double)value)) ;
342 if ( estimated > m_display_estimated
343 && m_ctdelay >= 0
344 )
345 {
346 ++m_ctdelay;
347 }
348 else if ( estimated < m_display_estimated
349 && m_ctdelay <= 0
350 )
351 {
352 --m_ctdelay;
353 }
354 else
355 {
356 m_ctdelay = 0;
357 }
358 if ( m_ctdelay >= m_delay // enough confirmations for a higher value
359 || m_ctdelay <= (m_delay*-1) // enough confirmations for a lower value
360 || value == m_maximum // to stay consistent
361 || elapsed > m_display_estimated // to stay consistent
362 || ( elapsed > 0 && elapsed < 4 ) // additional updates in the beginning
363 )
364 {
365 m_display_estimated = estimated;
366 m_ctdelay = 0;
367 }
368 }
369
ce07cd8a 370 long display_remaining = m_display_estimated - elapsed;
2c5ef4e2
VZ
371 if ( display_remaining < 0 )
372 {
373 display_remaining = 0;
374 }
abceee76
VZ
375
376 SetTimeLabel(elapsed, m_elapsed);
2c5ef4e2
VZ
377 SetTimeLabel(m_display_estimated, m_estimated);
378 SetTimeLabel(display_remaining, m_remaining);
abceee76
VZ
379 }
380
ff095200 381 if ( value == m_maximum )
abceee76 382 {
837adaa9
VZ
383 if ( m_state == Finished )
384 {
385 // ignore multiple calls to Update(m_maximum): it may sometimes be
386 // troublesome to ensure that Update() is not called twice with the
387 // same value (e.g. because of the rounding errors) and if we don't
388 // return now we're going to generate asserts below
389 return true;
390 }
391
dabbc6a5 392 // so that we return true below and that out [Cancel] handler knew what
1c79904b
MB
393 // to do
394 m_state = Finished;
f62c5581 395 if( !HasFlag(wxPD_AUTO_HIDE) )
abceee76 396 {
69c69546
WS
397 EnableClose();
398 DisableSkip();
cff7ef89 399#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
69c69546 400 EnableCloseButton();
c4d305b7 401#endif // __WXMSW__
abceee76 402
60ad766e 403 if ( newmsg.empty() )
1c79904b
MB
404 {
405 // also provide the finishing message if the application didn't
406 m_msg->SetLabel(_("Done."));
407 }
abceee76 408
33957ef5
FM
409 wxCHECK_MSG(wxEventLoopBase::GetActive(), false,
410 "wxProgressDialog::Update needs a running event loop");
411
977a41ec
FM
412 // allow the window to repaint:
413 // NOTE: since we yield only for UI events with this call, there
414 // should be no side-effects
dde19c21 415 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI);
ff095200 416
8f139810
FM
417 // NOTE: this call results in a new event loop being created
418 // and to a call to ProcessPendingEvents() (which may generate
419 // unwanted re-entrancies).
1c79904b
MB
420 (void)ShowModal();
421 }
ff095200 422 else // auto hide
1c79904b 423 {
ff095200
VZ
424 // reenable other windows before hiding this one because otherwise
425 // Windows wouldn't give the focus back to the window which had
426 // been previously focused because it would still be disabled
1c79904b 427 ReenableOtherWindows();
ff095200
VZ
428
429 Hide();
1c79904b 430 }
abceee76 431 }
f4aa7ec3 432 else // not at maximum yet
abceee76 433 {
86417abf 434 DoAfterUpdate();
abceee76 435 }
1b6452df 436
1d1c3a9f 437 // update the display in case yielding above didn't do it
f89d65ea 438 Update();
0655ad29 439
abceee76 440 return m_state != Canceled;
8fa2e6a2
KB
441}
442
f4aa7ec3 443bool wxProgressDialog::Pulse(const wxString& newmsg, bool *skip)
fe8635a7 444{
86417abf
VZ
445 if ( !DoBeforeUpdate(skip) )
446 return false;
447
fe8635a7
RR
448 wxASSERT_MSG( m_gauge, wxT("cannot update non existent dialog") );
449
450 // show a bit of progress
451 m_gauge->Pulse();
452
453 UpdateMessage(newmsg);
454
455 if (m_elapsed || m_remaining || m_estimated)
456 {
457 unsigned long elapsed = wxGetCurrentTime() - m_timeStart;
458
459 SetTimeLabel(elapsed, m_elapsed);
460 SetTimeLabel((unsigned long)-1, m_estimated);
461 SetTimeLabel((unsigned long)-1, m_remaining);
462 }
463
86417abf
VZ
464 DoAfterUpdate();
465
466 return m_state != Canceled;
f4aa7ec3
VZ
467}
468
86417abf 469bool wxProgressDialog::DoBeforeUpdate(bool *skip)
f4aa7ec3 470{
33957ef5 471 wxCHECK_MSG(wxEventLoopBase::GetActive(), false,
86417abf 472 "wxProgressDialog::DoBeforeUpdate needs a running event loop");
33957ef5 473
fe8635a7
RR
474 // we have to yield because not only we want to update the display but
475 // also to process the clicks on the cancel and skip buttons
977a41ec
FM
476 // NOTE: using YieldFor() this call shouldn't give re-entrancy problems
477 // for event handlers not interested to UI/user-input events.
dde19c21 478 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI|wxEVT_CATEGORY_USER_INPUT);
f4aa7ec3
VZ
479
480 Update();
fe8635a7 481
f4aa7ec3 482 if ( m_skip && skip && !*skip )
fe8635a7
RR
483 {
484 *skip = true;
485 m_skip = false;
486 EnableSkip();
487 }
488
489 return m_state != Canceled;
490}
491
86417abf
VZ
492void wxProgressDialog::DoAfterUpdate()
493{
494 wxCHECK_RET(wxEventLoopBase::GetActive(),
495 "wxProgressDialog::DoAfterUpdate needs a running event loop");
496
497 // allow the window to repaint:
498 // NOTE: since we yield only for UI events with this call, there
499 // should be no side-effects
500 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI);
501}
502
db1a42b8
VZ
503void wxProgressDialog::Resume()
504{
505 m_state = Continue;
2c5ef4e2
VZ
506 m_ctdelay = m_delay; // force an update of the elapsed/estimated/remaining time
507 m_break += wxGetCurrentTime()-m_timeStop;
db1a42b8 508
69c69546
WS
509 EnableAbort();
510 EnableSkip();
ecda9475 511 m_skip = false;
db1a42b8
VZ
512}
513
7d1dcec2
JS
514bool wxProgressDialog::Show( bool show )
515{
516 // reenable other windows before hiding this one because otherwise
517 // Windows wouldn't give the focus back to the window which had
518 // been previously focused because it would still be disabled
519 if(!show)
520 ReenableOtherWindows();
521
522 return wxDialog::Show(show);
523}
524
af237ae4
FM
525int wxProgressDialog::GetValue() const
526{
527 if (m_gauge)
528 return m_gauge->GetValue();
529 return wxNOT_FOUND;
530}
531
532int wxProgressDialog::GetRange() const
533{
534 if (m_gauge)
535 return m_gauge->GetRange();
536 return wxNOT_FOUND;
537}
538
539wxString wxProgressDialog::GetMessage() const
540{
541 return m_msg->GetLabel();
542}
543
ed1288ee
FM
544void wxProgressDialog::SetRange(int maximum)
545{
546 wxASSERT_MSG(m_gauge, "The dialog should have been constructed with a range > 0");
547 wxASSERT_MSG(maximum > 0, "Invalid range");
548
549 m_gauge->SetRange(maximum);
550 m_maximum = maximum;
551
552#if defined(__WXMSW__) || defined(__WXPM__)
553 // we can't have values > 65,536 in the progress control under Windows, so
554 // scale everything down
555 m_factor = m_maximum / 65536 + 1;
556 m_maximum /= m_factor;
557#endif // __WXMSW__
558}
559
f994a8ac
VZ
560
561bool wxProgressDialog::WasCancelled() const
562{
563 return m_hasAbortButton && m_state == Canceled;
564}
565
566bool wxProgressDialog::WasSkipped() const
567{
568 return m_hasSkipButton && m_skip;
569}
570
571
0655ad29
VZ
572// ----------------------------------------------------------------------------
573// event handlers
574// ----------------------------------------------------------------------------
575
576void wxProgressDialog::OnCancel(wxCommandEvent& event)
577{
578 if ( m_state == Finished )
579 {
580 // this means that the count down is already finished and we're being
581 // shown as a modal dialog - so just let the default handler do the job
582 event.Skip();
583 }
584 else
585 {
586 // request to cancel was received, the next time Update() is called we
587 // will handle it
588 m_state = Canceled;
1b6452df 589
69c69546 590 // update the buttons state immediately so that the user knows that the
1b6452df 591 // request has been noticed
69c69546
WS
592 DisableAbort();
593 DisableSkip();
2c5ef4e2
VZ
594
595 // save the time when the dialog was stopped
596 m_timeStop = wxGetCurrentTime();
0655ad29
VZ
597 }
598}
599
ecda9475
WS
600void wxProgressDialog::OnSkip(wxCommandEvent& WXUNUSED(event))
601{
69c69546 602 DisableSkip();
ecda9475
WS
603 m_skip = true;
604}
605
8fa2e6a2
KB
606void wxProgressDialog::OnClose(wxCloseEvent& event)
607{
0655ad29 608 if ( m_state == Uncancelable )
abceee76
VZ
609 {
610 // can't close this dialog
dabbc6a5 611 event.Veto();
abceee76
VZ
612 }
613 else if ( m_state == Finished )
614 {
615 // let the default handler close the window as we already terminated
616 event.Skip();
617 }
0655ad29 618 else
abceee76
VZ
619 {
620 // next Update() will notice it
0655ad29 621 m_state = Canceled;
69c69546
WS
622 DisableAbort();
623 DisableSkip();
ecda9475 624
2c5ef4e2 625 m_timeStop = wxGetCurrentTime();
abceee76 626 }
8fa2e6a2
KB
627}
628
0655ad29
VZ
629// ----------------------------------------------------------------------------
630// destruction
631// ----------------------------------------------------------------------------
8fa2e6a2
KB
632
633wxProgressDialog::~wxProgressDialog()
ef8698d6
VZ
634{
635 // normally this should have been already done, but just in case
636 ReenableOtherWindows();
637}
638
639void wxProgressDialog::ReenableOtherWindows()
8fa2e6a2 640{
f62c5581 641 if ( HasFlag(wxPD_APP_MODAL) )
0655ad29 642 {
cbc66a27 643 delete m_winDisabler;
d3b9f782 644 m_winDisabler = NULL;
0655ad29
VZ
645 }
646 else
647 {
cbc66a27 648 if ( m_parentTop )
dabbc6a5 649 m_parentTop->Enable();
0655ad29 650 }
8fa2e6a2 651}
ce4169a4 652
0655ad29
VZ
653// ----------------------------------------------------------------------------
654// private functions
655// ----------------------------------------------------------------------------
656
657static void SetTimeLabel(unsigned long val, wxStaticText *label)
658{
659 if ( label )
660 {
661 wxString s;
fe8635a7
RR
662
663 if (val != (unsigned long)-1)
664 {
f62c5581
FM
665 unsigned long hours = val / 3600;
666 unsigned long minutes = (val % 3600) / 60;
667 unsigned long seconds = val % 60;
668 s.Printf(wxT("%lu:%02lu:%02lu"), hours, minutes, seconds);
fe8635a7
RR
669 }
670 else
671 {
672 s = _("Unknown");
673 }
0655ad29
VZ
674
675 if ( s != label->GetLabel() )
676 label->SetLabel(s);
677 }
678}
679
69c69546
WS
680void wxProgressDialog::EnableSkip(bool enable)
681{
682 if(m_hasSkipButton)
683 {
684#ifdef __SMARTPHONE__
685 if(enable)
686 SetRightMenu(wxID_SKIP, _("Skip"));
687 else
688 SetRightMenu();
689#else
690 if(m_btnSkip)
691 m_btnSkip->Enable(enable);
692#endif
693 }
694}
695
696void wxProgressDialog::EnableAbort(bool enable)
697{
698 if(m_hasAbortButton)
699 {
700#ifdef __SMARTPHONE__
701 if(enable)
9a2256da 702 SetLeftMenu(wxID_CANCEL); // stock buttons makes Cancel label
69c69546
WS
703 else
704 SetLeftMenu();
705#else
706 if(m_btnAbort)
707 m_btnAbort->Enable(enable);
708#endif
709 }
710}
711
712void wxProgressDialog::EnableClose()
713{
714 if(m_hasAbortButton)
715 {
716#ifdef __SMARTPHONE__
717 SetLeftMenu(wxID_CANCEL, _("Close"));
718#else
719 if(m_btnAbort)
720 {
721 m_btnAbort->Enable();
722 m_btnAbort->SetLabel(_("Close"));
723 }
724#endif
725 }
726}
727
fe8635a7
RR
728void wxProgressDialog::UpdateMessage(const wxString &newmsg)
729{
33957ef5
FM
730 wxCHECK_RET(wxEventLoopBase::GetActive(),
731 "wxProgressDialog::UpdateMessage needs a running event loop");
732
fe8635a7
RR
733 if ( !newmsg.empty() && newmsg != m_msg->GetLabel() )
734 {
735 m_msg->SetLabel(newmsg);
736
977a41ec
FM
737 // allow the window to repaint:
738 // NOTE: since we yield only for UI events with this call, there
739 // should be no side-effects
dde19c21 740 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI);
fe8635a7
RR
741 }
742}
743
0655ad29 744#endif // wxUSE_PROGRESSDLG