1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/progdlg.cpp
3 // Purpose: wxProgressDialog
4 // Author: Rickard Westerlund
7 // Copyright: (c) 2010 wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_PROGRESSDLG && wxUSE_THREADS
28 #include "wx/progdlg.h"
32 #include "wx/msgdlg.h"
33 #include "wx/stopwatch.h"
34 #include "wx/msw/private.h"
37 #include "wx/msw/private/msgdlg.h"
38 #include "wx/evtloop.h"
40 using namespace wxMSWMessageDialog
;
42 #ifdef wxHAS_MSW_TASKDIALOG
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
51 // Notification values of wxProgressDialogSharedData::m_notifications
52 const int wxSPDD_VALUE_CHANGED
= 0x0001;
53 const int wxSPDD_RANGE_CHANGED
= 0x0002;
54 const int wxSPDD_PBMARQUEE_CHANGED
= 0x0004;
55 const int wxSPDD_TITLE_CHANGED
= 0x0008;
56 const int wxSPDD_MESSAGE_CHANGED
= 0x0010;
57 const int wxSPDD_EXPINFO_CHANGED
= 0x0020;
58 const int wxSPDD_ENABLE_SKIP
= 0x0040;
59 const int wxSPDD_ENABLE_ABORT
= 0x0080;
60 const int wxSPDD_DISABLE_SKIP
= 0x0100;
61 const int wxSPDD_DISABLE_ABORT
= 0x0200;
62 const int wxSPDD_FINISHED
= 0x0400;
63 const int wxSPDD_DESTROYED
= 0x0800;
65 const int Id_SkipBtn
= wxID_HIGHEST
+ 1;
67 } // anonymous namespace
69 // ============================================================================
71 // ============================================================================
73 // Class used to share data between the main thread and the task dialog runner.
74 class wxProgressDialogSharedData
77 wxProgressDialogSharedData()
81 m_progressBarMarquee
= false;
87 wxCriticalSection m_cs
;
89 wxWindow
*m_parent
; // Parent window only used to center us over it.
90 HWND m_hwnd
; // Task dialog handler
91 long m_style
; // wxProgressDialog style
96 wxString m_expandedInformation
;
97 wxString m_labelCancel
; // Privately used by callback.
98 unsigned long m_timeStop
;
100 wxProgressDialog::State m_state
;
101 bool m_progressBarMarquee
;
104 // Bit field that indicates fields that have been modified by the
105 // main thread so the task dialog runner knows what to update.
109 // Runner thread that takes care of displaying and updating the
111 class wxProgressDialogTaskRunner
: public wxThread
114 wxProgressDialogTaskRunner()
115 : wxThread(wxTHREAD_JOINABLE
)
118 wxProgressDialogSharedData
* GetSharedDataObject()
119 { return &m_sharedData
; }
122 wxProgressDialogSharedData m_sharedData
;
124 virtual void* Entry();
126 static HRESULT CALLBACK
TaskDialogCallbackProc(HWND hwnd
,
136 // A custom event loop which runs until the state of the dialog becomes
138 class wxProgressDialogModalLoop
: public wxEventLoop
141 wxProgressDialogModalLoop(wxProgressDialogSharedData
& data
)
147 virtual void OnNextIteration()
149 wxCriticalSectionLocker
locker(m_data
.m_cs
);
151 if ( m_data
.m_state
== wxProgressDialog::Dismissed
)
155 wxProgressDialogSharedData
& m_data
;
157 wxDECLARE_NO_COPY_CLASS(wxProgressDialogModalLoop
);
160 // ============================================================================
162 // ============================================================================
164 BOOL CALLBACK
DisplayCloseButton(HWND hwnd
, LPARAM lParam
)
166 wxProgressDialogSharedData
*sharedData
=
167 (wxProgressDialogSharedData
*) lParam
;
169 if ( wxGetWindowText( hwnd
) == sharedData
->m_labelCancel
)
171 sharedData
->m_labelCancel
= _("Close");
172 SendMessage( hwnd
, WM_SETTEXT
, 0,
173 (LPARAM
) sharedData
->m_labelCancel
.wx_str() );
181 void PerformNotificationUpdates(HWND hwnd
,
182 wxProgressDialogSharedData
*sharedData
)
184 // Update the appropriate dialog fields.
185 if ( sharedData
->m_notifications
& wxSPDD_RANGE_CHANGED
)
188 TDM_SET_PROGRESS_BAR_RANGE
,
190 MAKELPARAM(0, sharedData
->m_range
) );
193 if ( sharedData
->m_notifications
& wxSPDD_VALUE_CHANGED
)
196 TDM_SET_PROGRESS_BAR_POS
,
201 if ( sharedData
->m_notifications
& wxSPDD_PBMARQUEE_CHANGED
)
203 BOOL val
= sharedData
->m_progressBarMarquee
? TRUE
: FALSE
;
205 TDM_SET_MARQUEE_PROGRESS_BAR
,
209 TDM_SET_PROGRESS_BAR_MARQUEE
,
214 if ( sharedData
->m_notifications
& wxSPDD_TITLE_CHANGED
)
215 ::SetWindowText( hwnd
, sharedData
->m_title
.wx_str() );
217 if ( sharedData
->m_notifications
& wxSPDD_MESSAGE_CHANGED
)
219 // Split the message in the title string and the rest if it has
222 title
= sharedData
->m_message
,
225 const size_t posNL
= title
.find('\n');
226 if ( posNL
!= wxString::npos
)
228 // There can an extra new line between the first and subsequent
229 // lines to separate them as it looks better with the generic
230 // version -- but in this one, they're already separated by the use
231 // of different dialog elements, so suppress the extra new line.
233 if ( posNL
< title
.length() - 1 && title
[posNL
+ 1] == '\n' )
236 body
.assign(title
, posNL
+ numNLs
, wxString::npos
);
241 TDM_SET_ELEMENT_TEXT
,
242 TDE_MAIN_INSTRUCTION
,
243 (LPARAM
) title
.wx_str() );
246 TDM_SET_ELEMENT_TEXT
,
248 (LPARAM
) body
.wx_str() );
251 if ( sharedData
->m_notifications
& wxSPDD_EXPINFO_CHANGED
)
253 const wxString
& expandedInformation
=
254 sharedData
->m_expandedInformation
;
255 if ( !expandedInformation
.empty() )
258 TDM_SET_ELEMENT_TEXT
,
259 TDE_EXPANDED_INFORMATION
,
260 (LPARAM
) expandedInformation
.wx_str() );
264 if ( sharedData
->m_notifications
& wxSPDD_ENABLE_SKIP
)
265 ::SendMessage( hwnd
, TDM_ENABLE_BUTTON
, Id_SkipBtn
, TRUE
);
267 if ( sharedData
->m_notifications
& wxSPDD_ENABLE_ABORT
)
268 ::SendMessage( hwnd
, TDM_ENABLE_BUTTON
, IDCANCEL
, TRUE
);
270 if ( sharedData
->m_notifications
& wxSPDD_DISABLE_SKIP
)
271 ::SendMessage( hwnd
, TDM_ENABLE_BUTTON
, Id_SkipBtn
, FALSE
);
273 if ( sharedData
->m_notifications
& wxSPDD_DISABLE_ABORT
)
274 ::SendMessage( hwnd
, TDM_ENABLE_BUTTON
, IDCANCEL
, FALSE
);
276 // Is the progress finished?
277 if ( sharedData
->m_notifications
& wxSPDD_FINISHED
)
279 sharedData
->m_state
= wxProgressDialog::Finished
;
281 if ( !(sharedData
->m_style
& wxPD_AUTO_HIDE
) )
283 // Change Cancel into Close and activate the button.
284 ::SendMessage( hwnd
, TDM_ENABLE_BUTTON
, Id_SkipBtn
, FALSE
);
285 ::SendMessage( hwnd
, TDM_ENABLE_BUTTON
, IDCANCEL
, TRUE
);
286 ::EnumChildWindows( hwnd
, DisplayCloseButton
,
287 (LPARAM
) sharedData
);
292 } // anonymous namespace
294 #endif // wxHAS_MSW_TASKDIALOG
296 // ============================================================================
297 // wxProgressDialog implementation
298 // ============================================================================
300 wxProgressDialog::wxProgressDialog( const wxString
& title
,
301 const wxString
& message
,
305 : wxGenericProgressDialog(parent
, style
),
306 m_taskDialogRunner(NULL
),
311 #ifdef wxHAS_MSW_TASKDIALOG
312 if ( HasNativeTaskDialog() )
317 DisableOtherWindows();
321 #endif // wxHAS_MSW_TASKDIALOG
323 Create(title
, message
, maximum
, parent
, style
);
326 wxProgressDialog::~wxProgressDialog()
328 #ifdef wxHAS_MSW_TASKDIALOG
329 if ( !m_taskDialogRunner
)
334 wxCriticalSectionLocker
locker(m_sharedData
->m_cs
);
335 m_sharedData
->m_notifications
|= wxSPDD_DESTROYED
;
338 m_taskDialogRunner
->Wait();
340 delete m_taskDialogRunner
;
342 ReenableOtherWindows();
344 if ( GetTopParent() )
345 GetTopParent()->Raise();
346 #endif // wxHAS_MSW_TASKDIALOG
349 bool wxProgressDialog::Update(int value
, const wxString
& newmsg
, bool *skip
)
351 #ifdef wxHAS_MSW_TASKDIALOG
352 if ( HasNativeTaskDialog() )
355 wxCriticalSectionLocker
locker(m_sharedData
->m_cs
);
357 // Do nothing in canceled state.
358 if ( !DoNativeBeforeUpdate(skip
) )
363 wxASSERT_MSG( value
<= m_maximum
, wxT("invalid progress value") );
365 m_sharedData
->m_value
= value
;
366 m_sharedData
->m_notifications
|= wxSPDD_VALUE_CHANGED
;
368 if ( !newmsg
.empty() )
371 m_sharedData
->m_message
= newmsg
;
372 m_sharedData
->m_notifications
|= wxSPDD_MESSAGE_CHANGED
;
375 if ( m_sharedData
->m_progressBarMarquee
)
377 m_sharedData
->m_progressBarMarquee
= false;
378 m_sharedData
->m_notifications
|= wxSPDD_PBMARQUEE_CHANGED
;
381 UpdateExpandedInformation( value
);
383 // If we didn't just reach the finish, all we have to do is to
384 // return true if the dialog wasn't cancelled and false otherwise.
385 if ( value
!= m_maximum
|| m_state
== Finished
)
386 return m_sharedData
->m_state
!= Canceled
;
389 // On finishing, the dialog without wxPD_AUTO_HIDE style becomes a
390 // modal one meaning that we must block here until the user
393 m_sharedData
->m_state
= Finished
;
394 m_sharedData
->m_notifications
|= wxSPDD_FINISHED
;
395 if ( HasPDFlag(wxPD_AUTO_HIDE
) )
398 if ( newmsg
.empty() )
400 // Provide the finishing message if the application didn't.
401 m_message
= _("Done.");
402 m_sharedData
->m_message
= m_message
;
403 m_sharedData
->m_notifications
|= wxSPDD_MESSAGE_CHANGED
;
405 } // unlock m_sharedData->m_cs
407 // We only get here when we need to wait for the dialog to terminate so
408 // do just this by running a custom event loop until the dialog is
410 wxProgressDialogModalLoop
loop(*m_sharedData
);
414 #endif // wxHAS_MSW_TASKDIALOG
416 return wxGenericProgressDialog::Update( value
, newmsg
, skip
);
419 bool wxProgressDialog::Pulse(const wxString
& newmsg
, bool *skip
)
421 #ifdef wxHAS_MSW_TASKDIALOG
422 if ( HasNativeTaskDialog() )
424 wxCriticalSectionLocker
locker(m_sharedData
->m_cs
);
426 // Do nothing in canceled state.
427 if ( !DoNativeBeforeUpdate(skip
) )
430 if ( !m_sharedData
->m_progressBarMarquee
)
432 m_sharedData
->m_progressBarMarquee
= true;
433 m_sharedData
->m_notifications
|= wxSPDD_PBMARQUEE_CHANGED
;
436 if ( !newmsg
.empty() )
439 m_sharedData
->m_message
= newmsg
;
440 m_sharedData
->m_notifications
|= wxSPDD_MESSAGE_CHANGED
;
443 // The value passed here doesn't matter, only elapsed time makes sense
444 // in indeterminate mode anyhow.
445 UpdateExpandedInformation(0);
447 return m_sharedData
->m_state
!= Canceled
;
449 #endif // wxHAS_MSW_TASKDIALOG
451 return wxGenericProgressDialog::Pulse( newmsg
, skip
);
454 bool wxProgressDialog::DoNativeBeforeUpdate(bool *skip
)
456 #ifdef wxHAS_MSW_TASKDIALOG
457 if ( HasNativeTaskDialog() )
459 if ( m_sharedData
->m_skipped
)
461 if ( skip
&& !*skip
)
464 m_sharedData
->m_skipped
= false;
465 m_sharedData
->m_notifications
|= wxSPDD_ENABLE_SKIP
;
469 if ( m_sharedData
->m_state
== Canceled
)
470 m_timeStop
= m_sharedData
->m_timeStop
;
472 return m_sharedData
->m_state
!= Canceled
;
474 #endif // wxHAS_MSW_TASKDIALOG
477 wxFAIL_MSG( "unreachable" );
482 void wxProgressDialog::Resume()
484 wxGenericProgressDialog::Resume();
486 #ifdef wxHAS_MSW_TASKDIALOG
487 if ( HasNativeTaskDialog() )
492 wxCriticalSectionLocker
locker(m_sharedData
->m_cs
);
493 m_sharedData
->m_state
= m_state
;
495 // "Skip" was disabled when "Cancel" had been clicked, so re-enable
497 m_sharedData
->m_notifications
|= wxSPDD_ENABLE_SKIP
;
499 // Also re-enable "Cancel" itself
500 if ( HasPDFlag(wxPD_CAN_ABORT
) )
501 m_sharedData
->m_notifications
|= wxSPDD_ENABLE_ABORT
;
503 hwnd
= m_sharedData
->m_hwnd
;
504 } // Unlock m_cs, we can't call any function operating on a dialog with
505 // it locked as it can result in a deadlock if the dialog callback is
506 // called by Windows.
508 // After resuming we need to bring the window on top of the Z-order as
509 // it could be hidden by another window shown from the main thread,
510 // e.g. a confirmation dialog asking whether the user really wants to
513 // Notice that this must be done from the main thread as it owns the
514 // currently active window and attempts to do this from the task dialog
515 // thread would simply fail.
516 ::BringWindowToTop(hwnd
);
518 #endif // wxHAS_MSW_TASKDIALOG
521 int wxProgressDialog::GetValue() const
523 #ifdef wxHAS_MSW_TASKDIALOG
524 if ( HasNativeTaskDialog() )
526 wxCriticalSectionLocker
locker(m_sharedData
->m_cs
);
527 return m_sharedData
->m_value
;
529 #endif // wxHAS_MSW_TASKDIALOG
531 return wxGenericProgressDialog::GetValue();
534 wxString
wxProgressDialog::GetMessage() const
536 #ifdef wxHAS_MSW_TASKDIALOG
537 if ( HasNativeTaskDialog() )
539 #endif // wxHAS_MSW_TASKDIALOG
541 return wxGenericProgressDialog::GetMessage();
544 void wxProgressDialog::SetRange(int maximum
)
546 #ifdef wxHAS_MSW_TASKDIALOG
547 if ( HasNativeTaskDialog() )
551 wxCriticalSectionLocker
locker(m_sharedData
->m_cs
);
553 m_sharedData
->m_range
= maximum
;
554 m_sharedData
->m_notifications
|= wxSPDD_RANGE_CHANGED
;
558 #endif // wxHAS_MSW_TASKDIALOG
560 wxGenericProgressDialog::SetRange( maximum
);
563 bool wxProgressDialog::WasSkipped() const
565 #ifdef wxHAS_MSW_TASKDIALOG
566 if ( HasNativeTaskDialog() )
570 // Couldn't be skipped before being shown.
574 wxCriticalSectionLocker
locker(m_sharedData
->m_cs
);
575 return m_sharedData
->m_skipped
;
577 #endif // wxHAS_MSW_TASKDIALOG
579 return wxGenericProgressDialog::WasSkipped();
582 bool wxProgressDialog::WasCancelled() const
584 #ifdef wxHAS_MSW_TASKDIALOG
585 if ( HasNativeTaskDialog() )
587 wxCriticalSectionLocker
locker(m_sharedData
->m_cs
);
588 return m_sharedData
->m_state
== Canceled
;
590 #endif // wxHAS_MSW_TASKDIALOG
592 return wxGenericProgressDialog::WasCancelled();
595 void wxProgressDialog::SetTitle(const wxString
& title
)
597 #ifdef wxHAS_MSW_TASKDIALOG
598 if ( HasNativeTaskDialog() )
604 wxCriticalSectionLocker
locker(m_sharedData
->m_cs
);
605 m_sharedData
->m_title
= title
;
606 m_sharedData
->m_notifications
= wxSPDD_TITLE_CHANGED
;
609 #endif // wxHAS_MSW_TASKDIALOG
611 wxGenericProgressDialog::SetTitle(title
);
614 wxString
wxProgressDialog::GetTitle() const
616 #ifdef wxHAS_MSW_TASKDIALOG
617 if ( HasNativeTaskDialog() )
619 #endif // wxHAS_MSW_TASKDIALOG
621 return wxGenericProgressDialog::GetTitle();
624 bool wxProgressDialog::Show(bool show
)
626 #ifdef wxHAS_MSW_TASKDIALOG
627 if ( HasNativeTaskDialog() )
629 // The dialog can't be hidden at all and showing it again after it had
630 // been shown before doesn't do anything.
631 if ( !show
|| m_taskDialogRunner
)
634 // We're showing the dialog for the first time, create the thread that
636 m_taskDialogRunner
= new wxProgressDialogTaskRunner
;
637 m_sharedData
= m_taskDialogRunner
->GetSharedDataObject();
639 // Initialize shared data.
640 m_sharedData
->m_title
= m_title
;
641 m_sharedData
->m_message
= m_message
;
642 m_sharedData
->m_range
= m_maximum
;
643 m_sharedData
->m_state
= Uncancelable
;
644 m_sharedData
->m_style
= GetPDStyle();
645 m_sharedData
->m_parent
= GetTopParent();
647 if ( HasPDFlag(wxPD_CAN_ABORT
) )
649 m_sharedData
->m_state
= Continue
;
650 m_sharedData
->m_labelCancel
= _("Cancel");
652 else // Dialog can't be cancelled.
654 // We still must have at least a single button in the dialog so
655 // just don't call it "Cancel" in this case.
656 m_sharedData
->m_labelCancel
= _("Close");
659 if ( HasPDFlag(wxPD_ELAPSED_TIME
|
660 wxPD_ESTIMATED_TIME
|
661 wxPD_REMAINING_TIME
) )
663 // Use a non-empty string just to have the collapsible pane shown.
664 m_sharedData
->m_expandedInformation
= " ";
667 // Do launch the thread.
668 if ( m_taskDialogRunner
->Create() != wxTHREAD_NO_ERROR
)
670 wxLogError( "Unable to create thread!" );
674 if ( m_taskDialogRunner
->Run() != wxTHREAD_NO_ERROR
)
676 wxLogError( "Unable to start thread!" );
680 // Do not show the underlying dialog.
683 #endif // wxHAS_MSW_TASKDIALOG
685 return wxGenericProgressDialog::Show( show
);
688 void wxProgressDialog::UpdateExpandedInformation(int value
)
690 #ifdef wxHAS_MSW_TASKDIALOG
691 unsigned long elapsedTime
;
692 unsigned long estimatedTime
;
693 unsigned long remainingTime
;
694 UpdateTimeEstimates(value
, elapsedTime
, estimatedTime
, remainingTime
);
696 int realEstimatedTime
= estimatedTime
,
697 realRemainingTime
= remainingTime
;
698 if ( m_sharedData
->m_progressBarMarquee
)
700 // In indeterminate mode we don't have any estimation neither for the
701 // remaining nor for estimated time.
703 realRemainingTime
= -1;
706 wxString expandedInformation
;
708 // Calculate the three different timing values.
709 if ( HasPDFlag(wxPD_ELAPSED_TIME
) )
711 expandedInformation
<< GetElapsedLabel()
713 << GetFormattedTime(elapsedTime
);
716 if ( HasPDFlag(wxPD_ESTIMATED_TIME
) )
718 if ( !expandedInformation
.empty() )
719 expandedInformation
+= "\n";
721 expandedInformation
<< GetEstimatedLabel()
723 << GetFormattedTime(realEstimatedTime
);
726 if ( HasPDFlag(wxPD_REMAINING_TIME
) )
728 if ( !expandedInformation
.empty() )
729 expandedInformation
+= "\n";
731 expandedInformation
<< GetRemainingLabel()
733 << GetFormattedTime(realRemainingTime
);
736 // Update with new timing information.
737 if ( expandedInformation
!= m_sharedData
->m_expandedInformation
)
739 m_sharedData
->m_expandedInformation
= expandedInformation
;
740 m_sharedData
->m_notifications
|= wxSPDD_EXPINFO_CHANGED
;
742 #else // !wxHAS_MSW_TASKDIALOG
744 #endif // wxHAS_MSW_TASKDIALOG/!wxHAS_MSW_TASKDIALOG
747 // ----------------------------------------------------------------------------
748 // wxProgressDialogTaskRunner and related methods
749 // ----------------------------------------------------------------------------
751 #ifdef wxHAS_MSW_TASKDIALOG
753 void* wxProgressDialogTaskRunner::Entry()
755 WinStruct
<TASKDIALOGCONFIG
> tdc
;
756 wxMSWTaskDialogConfig wxTdc
;
759 wxCriticalSectionLocker
locker(m_sharedData
.m_cs
);
761 wxTdc
.caption
= m_sharedData
.m_title
.wx_str();
762 wxTdc
.message
= m_sharedData
.m_message
.wx_str();
764 // MSWCommonTaskDialogInit() will add an IDCANCEL button but we need to
765 // give it the correct label.
766 wxTdc
.btnOKLabel
= m_sharedData
.m_labelCancel
;
767 wxTdc
.useCustomLabels
= true;
769 wxTdc
.MSWCommonTaskDialogInit( tdc
);
770 tdc
.pfCallback
= TaskDialogCallbackProc
;
771 tdc
.lpCallbackData
= (LONG_PTR
) &m_sharedData
;
773 // Undo some of the effects of MSWCommonTaskDialogInit().
774 tdc
.dwFlags
&= ~TDF_EXPAND_FOOTER_AREA
; // Expand in content area.
775 tdc
.dwCommonButtons
= 0; // Don't use common buttons.
777 if ( m_sharedData
.m_style
& wxPD_CAN_SKIP
)
778 wxTdc
.AddTaskDialogButton( tdc
, Id_SkipBtn
, 0, _("Skip") );
780 tdc
.dwFlags
|= TDF_CALLBACK_TIMER
| TDF_SHOW_PROGRESS_BAR
;
782 if ( !m_sharedData
.m_expandedInformation
.empty() )
784 tdc
.pszExpandedInformation
=
785 m_sharedData
.m_expandedInformation
.wx_str();
789 TaskDialogIndirect_t taskDialogIndirect
= GetTaskDialogIndirectFunc();
790 if ( !taskDialogIndirect
)
794 HRESULT hr
= taskDialogIndirect(&tdc
, &msAns
, NULL
, NULL
);
796 wxLogApiError( "TaskDialogIndirect", hr
);
798 // If the main thread is waiting for us to exit inside the event loop in
799 // Update(), wake it up so that it checks our status again.
807 wxProgressDialogTaskRunner::TaskDialogCallbackProc
812 LPARAM
WXUNUSED(lParam
),
816 wxProgressDialogSharedData
* const sharedData
=
817 (wxProgressDialogSharedData
*) dwRefData
;
819 wxCriticalSectionLocker
locker(sharedData
->m_cs
);
821 switch ( uNotification
)
824 // Store the HWND for the main thread use.
825 sharedData
->m_hwnd
= hwnd
;
827 // Set the maximum value and disable Close button.
829 TDM_SET_PROGRESS_BAR_RANGE
,
831 MAKELPARAM(0, sharedData
->m_range
) );
833 // We always create this task dialog with NULL parent because our
834 // parent in wx sense is a window created from a different thread
835 // and so can't be used as our real parent. However we still center
836 // this window on the parent one as the task dialogs do with their
837 // real parent usually.
838 if ( sharedData
->m_parent
)
840 wxRect
rect(wxRectFromRECT(wxGetWindowRect(hwnd
)));
841 rect
= rect
.CentreIn(sharedData
->m_parent
->GetRect());
854 // If we can't be aborted, the "Close" button will only be enabled
855 // when the progress ends (and not even then with wxPD_AUTO_HIDE).
856 if ( !(sharedData
->m_style
& wxPD_CAN_ABORT
) )
857 ::SendMessage( hwnd
, TDM_ENABLE_BUTTON
, IDCANCEL
, FALSE
);
860 case TDN_BUTTON_CLICKED
:
864 ::SendMessage(hwnd
, TDM_ENABLE_BUTTON
, Id_SkipBtn
, FALSE
);
865 sharedData
->m_skipped
= true;
869 if ( sharedData
->m_state
== wxProgressDialog::Finished
)
871 // If the main thread is waiting for us, tell it that
872 // we're gone (and if it doesn't wait, it's harmless).
873 sharedData
->m_state
= wxProgressDialog::Dismissed
;
875 // Let Windows close the dialog.
879 // Close button on the window triggers an IDCANCEL press,
880 // don't allow it when it should only be possible to close
881 // a finished dialog.
882 if ( sharedData
->m_style
& wxPD_CAN_ABORT
)
886 sharedData
->m_state
== wxProgressDialog::Continue
,
888 "Dialog not in a cancelable state!"
891 ::SendMessage(hwnd
, TDM_ENABLE_BUTTON
, Id_SkipBtn
, FALSE
);
892 ::SendMessage(hwnd
, TDM_ENABLE_BUTTON
, IDCANCEL
, FALSE
);
894 sharedData
->m_timeStop
= wxGetCurrentTime();
895 sharedData
->m_state
= wxProgressDialog::Canceled
;
903 PerformNotificationUpdates(hwnd
, sharedData
);
906 Decide whether we should end the dialog. This is done if either
907 the dialog object itself was destroyed or if the progress
908 finished and we were configured to hide automatically without
909 waiting for the user to dismiss us.
911 Notice that we do not close the dialog if it was cancelled
912 because it's up to the user code in the main thread to decide
913 whether it really wants to cancel the dialog.
915 if ( (sharedData
->m_notifications
& wxSPDD_DESTROYED
) ||
916 (sharedData
->m_state
== wxProgressDialog::Finished
&&
917 sharedData
->m_style
& wxPD_AUTO_HIDE
) )
919 ::EndDialog( hwnd
, IDCLOSE
);
922 sharedData
->m_notifications
= 0;
931 #endif // wxHAS_MSW_TASKDIALOG
933 #endif // wxUSE_PROGRESSDLG && wxUSE_THREADS