X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5b1985a920a3e3fb457192d4bee7ea89a72a974a..2d5779d44094cf386fce5cea2d7eb2ce4c5467f7:/src/msw/msgdlg.cpp diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index f6057f7361..3a8ace4806 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -18,8 +18,6 @@ #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__ @@ -29,21 +27,21 @@ #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" @@ -255,8 +253,10 @@ void wxMessageDialog::ReplaceStaticWithEdit() { 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; } } @@ -454,12 +454,16 @@ int wxMessageDialog::ShowMessageBox() #if wxUSE_INTL // native message box always uses the current user locale but the program // may be using a different one and in this case we need to manually - // translate the button labels to avoid mismatch between the language of - // the message box text and its buttons + // translate the default button labels (if they're non default we have no + // way to translate them and so we must assume they were already + // translated) to avoid mismatch between the language of the message box + // text and its buttons wxLocale * const loc = wxGetLocale(); if ( loc && loc->GetLanguage() != wxLocale::GetSystemLanguage() ) { - if ( m_dialogStyle & wxYES_NO ) + if ( m_dialogStyle & wxYES_NO && + (GetCustomYesLabel().empty() && GetCustomNoLabel().empty()) ) + { // use the strings with mnemonics here as the native message box // does @@ -475,7 +479,8 @@ int wxMessageDialog::ShowMessageBox() // native message box (which probably doesn't use them because // Enter/Esc keys can be already used to dismiss the message box // using keyboard) - SetOKCancelLabels(_("OK"), _("Cancel")); + if ( GetCustomOKLabel().empty() && GetCustomCancelLabel().empty() ) + SetOKCancelLabels(_("OK"), _("Cancel")); } #endif // wxUSE_INTL @@ -511,6 +516,11 @@ int wxMessageDialog::ShowMessageBox() } } + if ( wxStyle & wxHELP ) + { + msStyle |= MB_HELP; + } + // set the icon style switch ( GetEffectiveIcon() ) { @@ -593,6 +603,16 @@ int wxMessageDialog::ShowModal() return wxID_CANCEL; } + // 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 MSWTranslateReturnCode( msAns ); } #endif // wxHAS_MSW_TASKDIALOG @@ -600,6 +620,19 @@ int wxMessageDialog::ShowModal() return ShowMessageBox(); } +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; +#endif // wxHAS_MSW_TASKDIALOG + + wxMessageDialogBase::DoCentre(dir); +} + // ---------------------------------------------------------------------------- // Helpers of the wxMSWMessageDialog namespace // ---------------------------------------------------------------------------- @@ -607,7 +640,7 @@ int wxMessageDialog::ShowModal() #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(); @@ -642,6 +675,7 @@ wxMSWTaskDialogConfig::wxMSWTaskDialogConfig(const wxMessageDialogBase& dlg) btnNoLabel = dlg.GetNoLabel(); btnOKLabel = dlg.GetOKLabel(); btnCancelLabel = dlg.GetCancelLabel(); + btnHelpLabel = dlg.GetHelpLabel(); } void wxMSWTaskDialogConfig::MSWCommonTaskDialogInit(TASKDIALOGCONFIG &tdc) @@ -708,16 +742,38 @@ 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); } } @@ -734,6 +790,10 @@ void wxMSWTaskDialogConfig::AddTaskDialogButton(TASKDIALOGCONFIG &tdc, 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 { @@ -803,6 +863,9 @@ int wxMSWMessageDialog::MSWTranslateReturnCode(int msAns) case IDNO: ans = wxID_NO; break; + case IDHELP: + ans = wxID_HELP; + break; } return ans;