#if wxUSE_MSGDLG
-#include "wx/ptr_scpd.h"
-
// there is no hook support under CE so we can't use the code for message box
// positioning there
#ifndef __WXWINCE__
#endif
#ifndef WX_PRECOMP
+ #include "wx/msgdlg.h"
#include "wx/app.h"
#include "wx/intl.h"
#include "wx/utils.h"
- #include "wx/dialog.h"
+ #include "wx/msw/private.h"
#if wxUSE_MSGBOX_HOOK
#include "wx/hashmap.h"
#endif
#endif
+#include "wx/ptr_scpd.h"
#include "wx/dynlib.h"
-#include "wx/msw/private.h"
#include "wx/msw/private/button.h"
#include "wx/msw/private/metrics.h"
#include "wx/msw/private/msgdlg.h"
-#include "wx/msgdlg.h"
#if wxUSE_MSGBOX_HOOK
#include "wx/fontutil.h"
{
if ( *i != '\n' )
{
- // found last non-newline char, remove everything after it and stop
- text.erase(i.base() + 1, text.end());
+ // found last non-newline char, remove anything after it if
+ // necessary and stop in any case
+ if ( i != text.rbegin() )
+ text.erase(i.base() + 1, text.end());
break;
}
}
}
}
+ if ( wxStyle & wxHELP )
+ {
+ msStyle |= MB_HELP;
+ }
+
// set the icon style
switch ( GetEffectiveIcon() )
{
return MSWTranslateReturnCode(msAns);
}
-int wxMessageDialog::ShowTaskDialog()
+int wxMessageDialog::ShowModal()
{
#ifdef wxHAS_MSW_TASKDIALOG
- TaskDialogIndirect_t taskDialogIndirect = GetTaskDialogIndirectFunc();
- if ( !taskDialogIndirect )
- return wxID_CANCEL;
+ if ( HasNativeTaskDialog() )
+ {
+ TaskDialogIndirect_t taskDialogIndirect = GetTaskDialogIndirectFunc();
+ wxCHECK_MSG( taskDialogIndirect, wxID_CANCEL, wxS("no task dialog?") );
- WinStruct<TASKDIALOGCONFIG> tdc;
- wxMSWTaskDialogConfig wxTdc( *this );
- wxTdc.MSWCommonTaskDialogInit( tdc );
+ WinStruct<TASKDIALOGCONFIG> tdc;
+ wxMSWTaskDialogConfig wxTdc( *this );
+ wxTdc.MSWCommonTaskDialogInit( tdc );
- int msAns;
- HRESULT hr = taskDialogIndirect( &tdc, &msAns, NULL, NULL );
- if ( FAILED(hr) )
- {
- wxLogApiError( "TaskDialogIndirect", hr );
- return wxID_CANCEL;
- }
+ int msAns;
+ HRESULT hr = taskDialogIndirect( &tdc, &msAns, NULL, NULL );
+ if ( FAILED(hr) )
+ {
+ wxLogApiError( "TaskDialogIndirect", hr );
+ return wxID_CANCEL;
+ }
- return MSWTranslateReturnCode( msAns );
-#else
- wxFAIL_MSG( "Task dialogs are unavailable." );
+ // In case only an "OK" button was specified we actually created a
+ // "Cancel" button (see comment in MSWCommonTaskDialogInit). This
+ // results in msAns being IDCANCEL while we want IDOK (just like
+ // how the native MessageBox function does with only an "OK" button).
+ if ( (msAns == IDCANCEL)
+ && !(GetMessageDialogStyle() & (wxYES_NO|wxCANCEL)) )
+ {
+ msAns = IDOK;
+ }
- 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);
}
// ----------------------------------------------------------------------------
#ifdef wxHAS_MSW_TASKDIALOG
wxMSWTaskDialogConfig::wxMSWTaskDialogConfig(const wxMessageDialogBase& dlg)
- : buttons(new TASKDIALOG_BUTTON[3])
+ : buttons(new TASKDIALOG_BUTTON[MAX_BUTTONS])
{
parent = dlg.GetParentForModalDialog();
caption = dlg.GetCaption();
btnNoLabel = dlg.GetNoLabel();
btnOKLabel = dlg.GetOKLabel();
btnCancelLabel = dlg.GetCancelLabel();
+ btnHelpLabel = dlg.GetHelpLabel();
}
void wxMSWTaskDialogConfig::MSWCommonTaskDialogInit(TASKDIALOGCONFIG &tdc)
}
else // without Yes/No we're going to have an OK button
{
- AddTaskDialogButton(tdc, IDOK, TDCBF_OK_BUTTON, btnOKLabel);
-
if ( style & wxCANCEL )
{
+ AddTaskDialogButton(tdc, IDOK, TDCBF_OK_BUTTON, btnOKLabel);
AddTaskDialogButton(tdc, IDCANCEL,
TDCBF_CANCEL_BUTTON, btnCancelLabel);
if ( style & wxCANCEL_DEFAULT )
tdc.nDefaultButton = IDCANCEL;
}
+ else // Only "OK"
+ {
+ // We actually create a "Cancel" button instead because we want to
+ // allow closing the dialog box with Escape (and also Alt-F4 or
+ // clicking the close button in the title bar) which wouldn't work
+ // without a Cancel button.
+ if ( !useCustomLabels )
+ {
+ useCustomLabels = true;
+ btnOKLabel = _("OK");
+ }
+
+ AddTaskDialogButton(tdc, IDCANCEL, TDCBF_CANCEL_BUTTON, btnOKLabel);
+ }
+ }
+
+ if ( style & wxHELP )
+ {
+ // There is no support for "Help" button in the task dialog, it can
+ // only show "Retry" or "Close" ones.
+ useCustomLabels = true;
+
+ AddTaskDialogButton(tdc, IDHELP, 0 /* not used */, btnHelpLabel);
}
}
tdBtn.nButtonID = btnCustomId;
tdBtn.pszButtonText = customLabel.wx_str();
tdc.cButtons++;
+
+ // We should never have more than 4 buttons currently as this is the
+ // maximal number of buttons supported by the message dialog.
+ wxASSERT_MSG( tdc.cButtons <= MAX_BUTTONS, wxT("Too many buttons") );
}
else
{
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<TaskDialogIndirect_t>(-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;
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)
case IDNO:
ans = wxID_NO;
break;
+ case IDHELP:
+ ans = wxID_HELP;
+ break;
}
return ans;