From aebe0d3b6c7f616355816e4f23ad7e01cdb1b0ce Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 4 Sep 2010 13:33:29 +0000 Subject: [PATCH] Improve main and extended messages handling in new wxMSW wxMessageDialog. Don't use the main message if there is no extended message: this looks bad as the main message is emphasized to contrast with the extended one which doesn't make sense visually if there is no extended message. Also recognize the common use of wxMessageBox() with a multiline text composed of the first string that plays the role of the main message with the rest being the extended one and handle this appropriately automatically. This results in a better appearance by default for a lot of message boxes, including even the one in our own minimal sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65466 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/msgdlg.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index 50191c6f77..ce8d4eafe5 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -623,6 +623,28 @@ wxMSWTaskDialogConfig::wxMSWTaskDialogConfig(const wxMessageDialogBase& dlg) caption = dlg.GetCaption(); message = dlg.GetMessage(); extendedMessage = dlg.GetExtendedMessage(); + + // Before wxMessageDialog added support for extended message it was common + // practice to have long multiline texts in the message box with the first + // line playing the role of the main message and the rest of the extended + // one. Try to detect such usage automatically here by synthesizing the + // extended message on our own if it wasn't given. + if ( extendedMessage.empty() ) + { + // Check if there is a blank separating line after the first line (this + // is not the same as searching for "\n\n" as we want the automatically + // recognized main message be single line to avoid embarrassing false + // positives). + const size_t posNL = message.find('\n'); + if ( posNL != wxString::npos && + posNL < message.length() - 1 && + message[posNL + 1 ] == '\n' ) + { + extendedMessage.assign(message, posNL + 2, wxString::npos); + message.erase(posNL); + } + } + iconId = dlg.GetEffectiveIcon(); style = dlg.GetMessageDialogStyle(); useCustomLabels = dlg.HasCustomLabels(); @@ -643,8 +665,23 @@ void wxMSWTaskDialogConfig::MSWCommonTaskDialogInit(TASKDIALOGCONFIG &tdc) if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) tdc.dwFlags |= TDF_RTL_LAYOUT; - tdc.pszMainInstruction = message.wx_str(); - tdc.pszContent = extendedMessage.wx_str(); + + // If we have both the main and extended messages, just use them as + // intended. However if only one message is given we normally use it as the + // content and not as the main instruction because the latter is supposed + // to stand out compared to the former and doesn't look good if there is + // nothing for it to contrast with. Finally, notice that the extended + // message we use here might be automatically extracted from the main + // message in our ctor, see comment there. + if ( !extendedMessage.empty() ) + { + tdc.pszMainInstruction = message.wx_str(); + tdc.pszContent = extendedMessage.wx_str(); + } + else + { + tdc.pszContent = message.wx_str(); + } // set an icon to be used, if possible switch ( iconId ) -- 2.45.2