X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aebe0d3b6c7f616355816e4f23ad7e01cdb1b0ce..66f75561893ea7b4bf429d1882d9cc0407ba932d:/src/msw/msgdlg.cpp diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index ce8d4eafe5..9b8440932a 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -573,41 +573,44 @@ int wxMessageDialog::ShowMessageBox() return MSWTranslateReturnCode(msAns); } -int wxMessageDialog::ShowTaskDialog() +int wxMessageDialog::ShowModal() { #ifdef wxHAS_MSW_TASKDIALOG - TaskDialogIndirect_t taskDialogIndirect = GetTaskDialogIndirectFunc(); - if ( !taskDialogIndirect ) - return wxID_CANCEL; - - WinStruct tdc; - wxMSWTaskDialogConfig wxTdc( *this ); - wxTdc.MSWCommonTaskDialogInit( tdc ); - - int msAns; - HRESULT hr = taskDialogIndirect( &tdc, &msAns, NULL, NULL ); - if ( FAILED(hr) ) + if ( HasNativeTaskDialog() ) { - wxLogApiError( "TaskDialogIndirect", hr ); - return wxID_CANCEL; - } + TaskDialogIndirect_t taskDialogIndirect = GetTaskDialogIndirectFunc(); + wxCHECK_MSG( taskDialogIndirect, wxID_CANCEL, wxS("no task dialog?") ); - return MSWTranslateReturnCode( msAns ); -#else - wxFAIL_MSG( "Task dialogs are unavailable." ); + WinStruct tdc; + wxMSWTaskDialogConfig wxTdc( *this ); + wxTdc.MSWCommonTaskDialogInit( tdc ); - return wxID_CANCEL; -#endif // wxHAS_MSW_TASKDIALOG -} + int msAns; + HRESULT hr = taskDialogIndirect( &tdc, &msAns, NULL, NULL ); + if ( FAILED(hr) ) + { + wxLogApiError( "TaskDialogIndirect", hr ); + return wxID_CANCEL; + } + return MSWTranslateReturnCode( msAns ); + } +#endif // wxHAS_MSW_TASKDIALOG + return ShowMessageBox(); +} -int wxMessageDialog::ShowModal() +void wxMessageDialog::DoCentre(int dir) { +#ifdef wxHAS_MSW_TASKDIALOG + // Task dialog is always centered on its parent window and trying to center + // it manually doesn't work because its HWND is not created yet so don't + // even try as this would only result in (debug) error messages. if ( HasNativeTaskDialog() ) - return ShowTaskDialog(); + return; +#endif // wxHAS_MSW_TASKDIALOG - return ShowMessageBox(); + wxMessageDialogBase::DoCentre(dir); } // ---------------------------------------------------------------------------- @@ -758,19 +761,20 @@ wxCRIT_SECT_DECLARE(gs_csTaskDialogIndirect); TaskDialogIndirect_t wxMSWMessageDialog::GetTaskDialogIndirectFunc() { - static TaskDialogIndirect_t s_TaskDialogIndirect = NULL; + // Initialize the function pointer to an invalid value different from NULL + // to avoid reloading comctl32.dll and trying to resolve it every time + // we're called if task dialog is not available (notice that this may + // happen even under Vista+ if we don't use comctl32.dll v6). + static const TaskDialogIndirect_t + INVALID_TASKDIALOG_FUNC = reinterpret_cast(-1); + static TaskDialogIndirect_t s_TaskDialogIndirect = INVALID_TASKDIALOG_FUNC; wxCRIT_SECT_LOCKER(lock, gs_csTaskDialogIndirect); - if ( !s_TaskDialogIndirect ) + if ( s_TaskDialogIndirect == INVALID_TASKDIALOG_FUNC ) { wxLoadedDLL dllComCtl32("comctl32.dll"); wxDL_INIT_FUNC(s_, TaskDialogIndirect, dllComCtl32); - - // We must always succeed as this code is only executed under Vista and - // later which must have task dialog support. - wxASSERT_MSG( s_TaskDialogIndirect, - "Task dialog support unexpectedly not available" ); } return s_TaskDialogIndirect; @@ -781,10 +785,14 @@ TaskDialogIndirect_t wxMSWMessageDialog::GetTaskDialogIndirectFunc() bool wxMSWMessageDialog::HasNativeTaskDialog() { #ifdef wxHAS_MSW_TASKDIALOG - return wxGetWinVersion() >= wxWinVersion_6; -#else + if ( wxGetWinVersion() >= wxWinVersion_6 ) + { + if ( wxMSWMessageDialog::GetTaskDialogIndirectFunc() ) + return true; + } +#endif // wxHAS_MSW_TASKDIALOG + return false; -#endif } int wxMSWMessageDialog::MSWTranslateReturnCode(int msAns)