]> git.saurik.com Git - wxWidgets.git/blame - src/generic/progdlgg.cpp
Playing with wxgrid, adding optionnally native columns labels
[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"
8fa2e6a2
KB
41#endif
42
fe8635a7 43#include "wx/progdlg.h"
8fa2e6a2 44
d2cdad17
WS
45// ---------------------------------------------------------------------------
46// macros
47// ---------------------------------------------------------------------------
48
49/* Macro for avoiding #ifdefs when value have to be different depending on size of
9a357011 50 device we display on - take it from something like wxDesktopPolicy in the future
d2cdad17
WS
51 */
52
53#if defined(__SMARTPHONE__)
54 #define wxLARGESMALL(large,small) small
55#else
56 #define wxLARGESMALL(large,small) large
57#endif
58
0655ad29
VZ
59// ----------------------------------------------------------------------------
60// constants
61// ----------------------------------------------------------------------------
62
d2cdad17 63#define LAYOUT_MARGIN wxLARGESMALL(8,2)
8fa2e6a2 64
ecda9475
WS
65static const int wxID_SKIP = 32000; // whatever
66
0655ad29
VZ
67// ----------------------------------------------------------------------------
68// private functions
69// ----------------------------------------------------------------------------
70
71// update the label to show the given time (in seconds)
72static void SetTimeLabel(unsigned long val, wxStaticText *label);
73
74// ----------------------------------------------------------------------------
75// event tables
76// ----------------------------------------------------------------------------
8fa2e6a2 77
1b6452df 78BEGIN_EVENT_TABLE(wxProgressDialog, wxDialog)
ef8698d6 79 EVT_BUTTON(wxID_CANCEL, wxProgressDialog::OnCancel)
ecda9475 80 EVT_BUTTON(wxID_SKIP, wxProgressDialog::OnSkip)
ef8698d6 81
ef8698d6 82 EVT_CLOSE(wxProgressDialog::OnClose)
1b6452df 83END_EVENT_TABLE()
8fa2e6a2 84
1b6452df 85IMPLEMENT_CLASS(wxProgressDialog, wxDialog)
8fa2e6a2 86
0655ad29 87// ============================================================================
db1a42b8 88// wxProgressDialog implementation
0655ad29 89// ============================================================================
8fa2e6a2 90
0655ad29 91// ----------------------------------------------------------------------------
db1a42b8 92// wxProgressDialog creation
0655ad29 93// ----------------------------------------------------------------------------
f81a6620 94
0655ad29
VZ
95wxProgressDialog::wxProgressDialog(wxString const &title,
96 wxString const &message,
97 int maximum,
98 wxWindow *parent,
99 int style)
2229243b 100 : wxDialog(GetParentForModalDialog(parent), wxID_ANY, title),
3786ce5a 101 m_skip(false),
69c69546
WS
102 m_delay(3),
103 m_hasAbortButton(false),
104 m_hasSkipButton(false)
0655ad29 105{
39cc7a0b
VZ
106 // we may disappear at any moment, let the others know about it
107 SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
96becbd8
VS
108 m_windowStyle |= style;
109
69c69546
WS
110 m_hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
111 m_hasSkipButton = (style & wxPD_CAN_SKIP) != 0;
c4d305b7 112
94f53923 113 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
60ad766e 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
0ca3b64f 147 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
d2cdad17 148
dabbc6a5 149 m_msg = new wxStaticText(this, wxID_ANY, message);
0ca3b64f 150 sizer->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN);
0655ad29 151
8d6854a6
VZ
152 wxSize sizeDlg,
153 sizeLabel = m_msg->GetSize();
0ca3b64f 154 sizeDlg.y = 2*LAYOUT_MARGIN + sizeLabel.y;
0655ad29 155
0655ad29
VZ
156 if ( maximum > 0 )
157 {
ecda9475
WS
158 int gauge_style = wxGA_HORIZONTAL;
159 if ( ( style & wxPD_SMOOTH ) == wxPD_SMOOTH )
160 gauge_style |= wxGA_SMOOTH;
dabbc6a5 161 m_gauge = new wxGauge(this, wxID_ANY, m_maximum,
c4d305b7 162 wxDefaultPosition, wxDefaultSize,
ecda9475 163 gauge_style );
c4d305b7 164
0ca3b64f 165 sizer->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN);
0655ad29 166 m_gauge->SetValue(0);
0655ad29
VZ
167
168 wxSize sizeGauge = m_gauge->GetSize();
0ca3b64f 169 sizeDlg.y += 2*LAYOUT_MARGIN + sizeGauge.y;
0655ad29
VZ
170 }
171 else
172 m_gauge = (wxGauge *)NULL;
173
174 // create the estimated/remaining/total time zones if requested
33961d59 175 m_elapsed = m_estimated = m_remaining = (wxStaticText*)NULL;
2c5ef4e2
VZ
176 m_display_estimated = m_last_timeupdate = m_break = 0;
177 m_ctdelay = 0;
0655ad29 178
6f457a77 179 // if we are going to have at least one label, remember it in this var
8d6854a6
VZ
180 wxStaticText *label = NULL;
181
182 // also count how many labels we really have
183 size_t nTimeLabels = 0;
184
0655ad29
VZ
185 if ( style & wxPD_ELAPSED_TIME )
186 {
187 nTimeLabels++;
188
8d6854a6 189 label =
0ca3b64f 190 m_elapsed = CreateLabel(_("Elapsed time : "), sizer);
0655ad29
VZ
191 }
192
193 if ( style & wxPD_ESTIMATED_TIME )
194 {
195 nTimeLabels++;
196
8d6854a6 197 label =
0ca3b64f 198 m_estimated = CreateLabel(_("Estimated time : "), sizer);
0655ad29
VZ
199 }
200
201 if ( style & wxPD_REMAINING_TIME )
202 {
203 nTimeLabels++;
204
8d6854a6 205 label =
0ca3b64f 206 m_remaining = CreateLabel(_("Remaining time : "), sizer);
0655ad29
VZ
207 }
208
209 if ( nTimeLabels > 0 )
210 {
211 // set it to the current time
212 m_timeStart = wxGetCurrentTime();
0ca3b64f 213 sizeDlg.y += nTimeLabels * (label->GetSize().y + LAYOUT_MARGIN);
0655ad29
VZ
214 }
215
d2cdad17 216#if defined(__SMARTPHONE__)
69c69546 217 if ( m_hasSkipButton )
ecda9475 218 SetRightMenu(wxID_SKIP, _("Skip"));
69c69546 219 if ( m_hasAbortButton )
ecda9475 220 SetLeftMenu(wxID_CANCEL);
d2cdad17 221#else
ecda9475
WS
222 m_btnAbort = m_btnSkip = (wxButton *)NULL;
223 bool sizeDlgModified = false;
224 wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
0655ad29 225
3786ce5a 226 const int sizerFlags =
94640e04 227#if defined(__WXMSW__) || defined(__WXPM__)
ecda9475 228 wxALIGN_RIGHT | wxALL
0655ad29 229#else // !MSW
ecda9475 230 wxALIGN_CENTER_HORIZONTAL | wxBOTTOM | wxTOP
0655ad29 231#endif // MSW/!MSW
ecda9475
WS
232 ;
233
69c69546 234 if ( m_hasSkipButton )
ecda9475
WS
235 {
236 m_btnSkip = new wxButton(this, wxID_SKIP, _("Skip"));
237
238 // Windows dialogs usually have buttons in the lower right corner
239 buttonSizer->Add(m_btnSkip, 0, sizerFlags, LAYOUT_MARGIN);
0ca3b64f 240 sizeDlg.y += 2*LAYOUT_MARGIN + wxButton::GetDefaultSize().y;
ecda9475 241 sizeDlgModified = true;
0655ad29 242 }
ecda9475 243
69c69546 244 if ( m_hasAbortButton )
e269a9be 245 {
ecda9475
WS
246 m_btnAbort = new wxButton(this, wxID_CANCEL);
247
248 // Windows dialogs usually have buttons in the lower right corner
249 buttonSizer->Add(m_btnAbort, 0, sizerFlags, LAYOUT_MARGIN);
250 if(!sizeDlgModified)
251 sizeDlg.y += 2*LAYOUT_MARGIN + wxButton::GetDefaultSize().y;
e269a9be 252 }
0655ad29 253
ecda9475
WS
254 sizer->Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN );
255#endif // __SMARTPHONE__/!__SMARTPHONE__
256
0ca3b64f 257 SetSizerAndFit(sizer);
0655ad29 258
94f53923
JS
259 if (!isPda)
260 {
261 sizeDlg.y += 2*LAYOUT_MARGIN;
0655ad29 262
94f53923 263 // try to make the dialog not square but rectangular of reasonable width
6f457a77 264 sizeDlg.x = (wxCoord)wxMax(3*widthText/2, 4*sizeDlg.y/3);
94f53923
JS
265 SetClientSize(sizeDlg);
266 }
0655ad29
VZ
267
268 Centre(wxCENTER_FRAME | wxBOTH);
269
cbc66a27 270 if ( style & wxPD_APP_MODAL )
0655ad29 271 {
cbc66a27 272 m_winDisabler = new wxWindowDisabler(this);
0655ad29
VZ
273 }
274 else
275 {
cbc66a27 276 if ( m_parentTop )
dabbc6a5 277 m_parentTop->Disable();
cbc66a27 278 m_winDisabler = NULL;
0655ad29
VZ
279 }
280
dabbc6a5
DS
281 Show();
282 Enable();
33961d59 283
70f3fad6
VZ
284 // this one can be initialized even if the others are unknown for now
285 //
286 // NB: do it after calling Layout() to keep the labels correctly aligned
287 if ( m_elapsed )
288 {
289 SetTimeLabel(0, m_elapsed);
290 }
291
f89d65ea 292 Update();
8fa2e6a2
KB
293}
294
0655ad29 295wxStaticText *wxProgressDialog::CreateLabel(const wxString& text,
0ca3b64f 296 wxSizer *sizer)
0655ad29 297{
d2cdad17 298 wxBoxSizer *locsizer = new wxBoxSizer(wxLARGESMALL(wxHORIZONTAL,wxVERTICAL));
0655ad29 299
d2cdad17 300 wxStaticText *dummy = new wxStaticText(this, wxID_ANY, text);
dabbc6a5 301 wxStaticText *label = new wxStaticText(this, wxID_ANY, _("unknown"));
0655ad29 302
d2cdad17
WS
303 // select placement most native or nice on target GUI
304#if defined(__SMARTPHONE__)
305 // label and time to the left in two rows
306 locsizer->Add(dummy, 1, wxALIGN_LEFT);
307 locsizer->Add(label, 1, wxALIGN_LEFT);
308 sizer->Add(locsizer, 0, wxALIGN_LEFT | wxTOP | wxLEFT, LAYOUT_MARGIN);
fe8635a7 309#elif defined(__WXMSW__) || defined(__WXPM__) || defined(__WXMAC__) || defined(__WXGTK20__)
d2cdad17
WS
310 // label and time centered in one row
311 locsizer->Add(dummy, 1, wxLARGESMALL(wxALIGN_RIGHT,wxALIGN_LEFT));
0ca3b64f
VS
312 locsizer->Add(label, 1, wxALIGN_LEFT | wxLEFT, LAYOUT_MARGIN);
313 sizer->Add(locsizer, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, LAYOUT_MARGIN);
d2cdad17
WS
314#else
315 // label and time to the right in one row
0ca3b64f
VS
316 sizer->Add(locsizer, 0, wxALIGN_RIGHT | wxRIGHT | wxTOP, LAYOUT_MARGIN);
317 locsizer->Add(dummy);
318 locsizer->Add(label, 0, wxLEFT, LAYOUT_MARGIN);
d2cdad17 319#endif
0655ad29
VZ
320
321 return label;
322}
8fa2e6a2 323
db1a42b8
VZ
324// ----------------------------------------------------------------------------
325// wxProgressDialog operations
326// ----------------------------------------------------------------------------
327
8fa2e6a2 328bool
ecda9475 329wxProgressDialog::Update(int value, const wxString& newmsg, bool *skip)
8fa2e6a2 330{
abceee76 331 wxASSERT_MSG( value == -1 || m_gauge, wxT("cannot update non existent dialog") );
7c349adb
VZ
332
333#ifdef __WXMSW__
334 value /= m_factor;
335#endif // __WXMSW__
336
abceee76
VZ
337 wxASSERT_MSG( value <= m_maximum, wxT("invalid progress value") );
338
c4c6ada9
VZ
339 if ( m_gauge )
340 m_gauge->SetValue(value);
abceee76 341
fe8635a7 342 UpdateMessage(newmsg);
abceee76
VZ
343
344 if ( (m_elapsed || m_remaining || m_estimated) && (value != 0) )
345 {
346 unsigned long elapsed = wxGetCurrentTime() - m_timeStart;
2c5ef4e2
VZ
347 if ( m_last_timeupdate < elapsed
348 || value == m_maximum
349 )
350 {
351 m_last_timeupdate = elapsed;
352 unsigned long estimated = m_break +
353 (unsigned long)(( (double) (elapsed-m_break) * m_maximum ) / ((double)value)) ;
354 if ( estimated > m_display_estimated
355 && m_ctdelay >= 0
356 )
357 {
358 ++m_ctdelay;
359 }
360 else if ( estimated < m_display_estimated
361 && m_ctdelay <= 0
362 )
363 {
364 --m_ctdelay;
365 }
366 else
367 {
368 m_ctdelay = 0;
369 }
370 if ( m_ctdelay >= m_delay // enough confirmations for a higher value
371 || m_ctdelay <= (m_delay*-1) // enough confirmations for a lower value
372 || value == m_maximum // to stay consistent
373 || elapsed > m_display_estimated // to stay consistent
374 || ( elapsed > 0 && elapsed < 4 ) // additional updates in the beginning
375 )
376 {
377 m_display_estimated = estimated;
378 m_ctdelay = 0;
379 }
380 }
381
ce07cd8a 382 long display_remaining = m_display_estimated - elapsed;
2c5ef4e2
VZ
383 if ( display_remaining < 0 )
384 {
385 display_remaining = 0;
386 }
abceee76
VZ
387
388 SetTimeLabel(elapsed, m_elapsed);
2c5ef4e2
VZ
389 SetTimeLabel(m_display_estimated, m_estimated);
390 SetTimeLabel(display_remaining, m_remaining);
abceee76
VZ
391 }
392
ff095200 393 if ( value == m_maximum )
abceee76 394 {
837adaa9
VZ
395 if ( m_state == Finished )
396 {
397 // ignore multiple calls to Update(m_maximum): it may sometimes be
398 // troublesome to ensure that Update() is not called twice with the
399 // same value (e.g. because of the rounding errors) and if we don't
400 // return now we're going to generate asserts below
401 return true;
402 }
403
dabbc6a5 404 // so that we return true below and that out [Cancel] handler knew what
1c79904b
MB
405 // to do
406 m_state = Finished;
407 if( !(GetWindowStyle() & wxPD_AUTO_HIDE) )
abceee76 408 {
69c69546
WS
409 EnableClose();
410 DisableSkip();
cff7ef89 411#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
69c69546 412 EnableCloseButton();
c4d305b7 413#endif // __WXMSW__
abceee76 414
60ad766e 415 if ( newmsg.empty() )
1c79904b
MB
416 {
417 // also provide the finishing message if the application didn't
418 m_msg->SetLabel(_("Done."));
419 }
abceee76 420
822fc380 421 wxYieldIfNeeded() ;
ff095200 422
1c79904b
MB
423 (void)ShowModal();
424 }
ff095200 425 else // auto hide
1c79904b 426 {
ff095200
VZ
427 // reenable other windows before hiding this one because otherwise
428 // Windows wouldn't give the focus back to the window which had
429 // been previously focused because it would still be disabled
1c79904b 430 ReenableOtherWindows();
ff095200
VZ
431
432 Hide();
1c79904b 433 }
abceee76 434 }
f4aa7ec3 435 else // not at maximum yet
abceee76 436 {
f4aa7ec3 437 return DoAfterUpdate(skip);
abceee76 438 }
1b6452df 439
1d1c3a9f 440 // update the display in case yielding above didn't do it
f89d65ea 441 Update();
0655ad29 442
abceee76 443 return m_state != Canceled;
8fa2e6a2
KB
444}
445
f4aa7ec3 446bool wxProgressDialog::Pulse(const wxString& newmsg, bool *skip)
fe8635a7
RR
447{
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
f4aa7ec3
VZ
464 return DoAfterUpdate(skip);
465}
466
467bool wxProgressDialog::DoAfterUpdate(bool *skip)
468{
fe8635a7
RR
469 // we have to yield because not only we want to update the display but
470 // also to process the clicks on the cancel and skip buttons
f4aa7ec3
VZ
471 wxYieldIfNeeded();
472
473 Update();
fe8635a7 474
f4aa7ec3 475 if ( m_skip && skip && !*skip )
fe8635a7
RR
476 {
477 *skip = true;
478 m_skip = false;
479 EnableSkip();
480 }
481
482 return m_state != Canceled;
483}
484
db1a42b8
VZ
485void wxProgressDialog::Resume()
486{
487 m_state = Continue;
2c5ef4e2
VZ
488 m_ctdelay = m_delay; // force an update of the elapsed/estimated/remaining time
489 m_break += wxGetCurrentTime()-m_timeStop;
db1a42b8 490
69c69546
WS
491 EnableAbort();
492 EnableSkip();
ecda9475 493 m_skip = false;
db1a42b8
VZ
494}
495
7d1dcec2
JS
496bool wxProgressDialog::Show( bool show )
497{
498 // reenable other windows before hiding this one because otherwise
499 // Windows wouldn't give the focus back to the window which had
500 // been previously focused because it would still be disabled
501 if(!show)
502 ReenableOtherWindows();
503
504 return wxDialog::Show(show);
505}
506
0655ad29
VZ
507// ----------------------------------------------------------------------------
508// event handlers
509// ----------------------------------------------------------------------------
510
511void wxProgressDialog::OnCancel(wxCommandEvent& event)
512{
513 if ( m_state == Finished )
514 {
515 // this means that the count down is already finished and we're being
516 // shown as a modal dialog - so just let the default handler do the job
517 event.Skip();
518 }
519 else
520 {
521 // request to cancel was received, the next time Update() is called we
522 // will handle it
523 m_state = Canceled;
1b6452df 524
69c69546 525 // update the buttons state immediately so that the user knows that the
1b6452df 526 // request has been noticed
69c69546
WS
527 DisableAbort();
528 DisableSkip();
2c5ef4e2
VZ
529
530 // save the time when the dialog was stopped
531 m_timeStop = wxGetCurrentTime();
0655ad29
VZ
532 }
533}
534
ecda9475
WS
535void wxProgressDialog::OnSkip(wxCommandEvent& WXUNUSED(event))
536{
69c69546 537 DisableSkip();
ecda9475
WS
538 m_skip = true;
539}
540
8fa2e6a2
KB
541void wxProgressDialog::OnClose(wxCloseEvent& event)
542{
0655ad29 543 if ( m_state == Uncancelable )
abceee76
VZ
544 {
545 // can't close this dialog
dabbc6a5 546 event.Veto();
abceee76
VZ
547 }
548 else if ( m_state == Finished )
549 {
550 // let the default handler close the window as we already terminated
551 event.Skip();
552 }
0655ad29 553 else
abceee76
VZ
554 {
555 // next Update() will notice it
0655ad29 556 m_state = Canceled;
69c69546
WS
557 DisableAbort();
558 DisableSkip();
ecda9475 559
2c5ef4e2 560 m_timeStop = wxGetCurrentTime();
abceee76 561 }
8fa2e6a2
KB
562}
563
0655ad29
VZ
564// ----------------------------------------------------------------------------
565// destruction
566// ----------------------------------------------------------------------------
8fa2e6a2
KB
567
568wxProgressDialog::~wxProgressDialog()
ef8698d6
VZ
569{
570 // normally this should have been already done, but just in case
571 ReenableOtherWindows();
572}
573
574void wxProgressDialog::ReenableOtherWindows()
8fa2e6a2 575{
cbc66a27 576 if ( GetWindowStyle() & wxPD_APP_MODAL )
0655ad29 577 {
cbc66a27 578 delete m_winDisabler;
ef8698d6 579 m_winDisabler = (wxWindowDisabler *)NULL;
0655ad29
VZ
580 }
581 else
582 {
cbc66a27 583 if ( m_parentTop )
dabbc6a5 584 m_parentTop->Enable();
0655ad29 585 }
8fa2e6a2 586}
ce4169a4 587
0655ad29
VZ
588// ----------------------------------------------------------------------------
589// private functions
590// ----------------------------------------------------------------------------
591
592static void SetTimeLabel(unsigned long val, wxStaticText *label)
593{
594 if ( label )
595 {
596 wxString s;
fe8635a7
RR
597
598 if (val != (unsigned long)-1)
599 {
0655ad29
VZ
600 unsigned long hours = val / 3600;
601 unsigned long minutes = (val % 3600) / 60;
602 unsigned long seconds = val % 60;
223d09f6 603 s.Printf(wxT("%lu:%02lu:%02lu"), hours, minutes, seconds);
fe8635a7
RR
604 }
605 else
606 {
607 s = _("Unknown");
608 }
0655ad29
VZ
609
610 if ( s != label->GetLabel() )
611 label->SetLabel(s);
612 }
613}
614
69c69546
WS
615void wxProgressDialog::EnableSkip(bool enable)
616{
617 if(m_hasSkipButton)
618 {
619#ifdef __SMARTPHONE__
620 if(enable)
621 SetRightMenu(wxID_SKIP, _("Skip"));
622 else
623 SetRightMenu();
624#else
625 if(m_btnSkip)
626 m_btnSkip->Enable(enable);
627#endif
628 }
629}
630
631void wxProgressDialog::EnableAbort(bool enable)
632{
633 if(m_hasAbortButton)
634 {
635#ifdef __SMARTPHONE__
636 if(enable)
9a2256da 637 SetLeftMenu(wxID_CANCEL); // stock buttons makes Cancel label
69c69546
WS
638 else
639 SetLeftMenu();
640#else
641 if(m_btnAbort)
642 m_btnAbort->Enable(enable);
643#endif
644 }
645}
646
647void wxProgressDialog::EnableClose()
648{
649 if(m_hasAbortButton)
650 {
651#ifdef __SMARTPHONE__
652 SetLeftMenu(wxID_CANCEL, _("Close"));
653#else
654 if(m_btnAbort)
655 {
656 m_btnAbort->Enable();
657 m_btnAbort->SetLabel(_("Close"));
658 }
659#endif
660 }
661}
662
fe8635a7
RR
663void wxProgressDialog::UpdateMessage(const wxString &newmsg)
664{
665 if ( !newmsg.empty() && newmsg != m_msg->GetLabel() )
666 {
667 m_msg->SetLabel(newmsg);
668
669 wxYieldIfNeeded() ;
670 }
671}
672
0655ad29 673#endif // wxUSE_PROGRESSDLG