1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        src/msw/richmsgdlg.cpp
3 // Purpose:     wxRichMessageDialog
4 // Author:      Rickard Westerlund
5 // Created:     2010-07-04
6 // Copyright:   (c) 2010 wxWidgets team
7 // Licence:     wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9 
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #if wxUSE_RICHMSGDLG
18 
19 #include "wx/richmsgdlg.h"
20 #include "wx/modalhook.h"
21 
22 #ifndef WX_PRECOMP
23     #include "wx/msw/private.h"
24 #endif
25 
26 // This will define wxHAS_MSW_TASKDIALOG if we have support for it in the
27 // headers we use.
28 #include "wx/msw/private/msgdlg.h"
29 
30 // ----------------------------------------------------------------------------
31 // wxRichMessageDialog
32 // ----------------------------------------------------------------------------
33 
ShowModal()34 int wxRichMessageDialog::ShowModal()
35 {
36     WX_HOOK_MODAL_DIALOG();
37 
38 #ifdef wxHAS_MSW_TASKDIALOG
39     using namespace wxMSWMessageDialog;
40 
41     if ( HasNativeTaskDialog() )
42     {
43         // create a task dialog
44         WinStruct<TASKDIALOGCONFIG> tdc;
45         wxMSWTaskDialogConfig wxTdc(*this);
46 
47         wxTdc.MSWCommonTaskDialogInit( tdc );
48 
49         // add a checkbox
50         if ( !m_checkBoxText.empty() )
51         {
52             tdc.pszVerificationText = m_checkBoxText.t_str();
53             if ( m_checkBoxValue )
54                 tdc.dwFlags |= TDF_VERIFICATION_FLAG_CHECKED;
55         }
56 
57         // add collapsible footer
58         if ( !m_detailedText.empty() )
59             tdc.pszExpandedInformation = m_detailedText.t_str();
60 
61         TaskDialogIndirect_t taskDialogIndirect = GetTaskDialogIndirectFunc();
62         if ( !taskDialogIndirect )
63             return wxID_CANCEL;
64 
65         // create the task dialog, process the answer and return it.
66         BOOL checkBoxChecked;
67         int msAns;
68         HRESULT hr = taskDialogIndirect( &tdc, &msAns, NULL, &checkBoxChecked );
69         if ( FAILED(hr) )
70         {
71             wxLogApiError( "TaskDialogIndirect", hr );
72             return wxID_CANCEL;
73         }
74         m_checkBoxValue = checkBoxChecked != FALSE;
75 
76         // In case only an "OK" button was specified we actually created a
77         // "Cancel" button (see comment in MSWCommonTaskDialogInit). This
78         // results in msAns being IDCANCEL while we want IDOK (just like
79         // how the native MessageBox function does with only an "OK" button).
80         if ( (msAns == IDCANCEL)
81             && !(GetMessageDialogStyle() & (wxYES_NO|wxCANCEL)) )
82         {
83             msAns = IDOK;
84         }
85 
86         return MSWTranslateReturnCode( msAns );
87     }
88 #endif // wxHAS_MSW_TASKDIALOG
89 
90     // use the generic version when task dialog is't available at either
91     // compile or run-time.
92     return wxGenericRichMessageDialog::ShowModal();
93 }
94 
95 #endif // wxUSE_RICHMSGDLG
96