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