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