+ // do create the new control
+ HWND hwndEdit = ::CreateWindow
+ (
+ _T("EDIT"),
+ wxTextBuffer::Translate(text).wx_str(),
+ WS_CHILD | WS_VSCROLL | WS_VISIBLE |
+ ES_MULTILINE | ES_READONLY | ES_AUTOVSCROLL,
+ rc.left, rc.top,
+ rc.right - rc.left, rc.bottom - rc.top,
+ GetHwnd(),
+ NULL,
+ wxhInstance,
+ NULL
+ );
+
+ if ( !hwndEdit )
+ {
+ wxLogDebug("Creation of replacement edit control failed in message box");
+ return;
+ }
+
+ // copy the font from the original control
+ LRESULT hfont = ::SendMessage(hwndStatic, WM_GETFONT, 0, 0);
+ ::SendMessage(hwndEdit, WM_SETFONT, hfont, 0);
+
+ // and get rid of it
+ ::DestroyWindow(hwndStatic);
+
+
+ // shrink and centre the message box vertically and widen it box to account
+ // for the extra scrollbar
+ RECT rcBox = wxGetWindowRect(GetHwnd());
+ const int hMsgBox = rcBox.bottom - rcBox.top - dh;
+ rcBox.top = (rectDisplay.height - hMsgBox)/2;
+ rcBox.bottom = rcBox.top + hMsgBox + (rectDisplay.height - hMsgBox)%2;
+ rcBox.left -= dw/2;
+ rcBox.right += dw - dw/2;
+ SetWindowRect(GetHwnd(), rcBox);
+
+ // and adjust all the buttons positions
+ for ( unsigned n = 0; n < WXSIZEOF(ms_buttons); n++ )
+ {
+ const HWND hwndBtn = ::GetDlgItem(GetHwnd(), ms_buttons[n].id);
+ if ( !hwndBtn )
+ continue; // it's ok, not all buttons are always present
+
+ RECT rc = wxGetWindowRect(hwndBtn);
+ rc.top -= dh;
+ rc.bottom -= dh;
+ rc.left += dw/2;
+ rc.right += dw/2;
+ MoveWindowToScreenRect(hwndBtn, rc);
+ }
+}
+
+void wxMessageDialog::AdjustButtonLabels()
+{
+ // changing the button labels is the easy part but we also need to ensure
+ // that the buttons are big enough for the label strings and increase their
+ // size (and maybe the size of the message box itself) if they are not
+
+ // TODO-RTL: check whether this works correctly in RTL
+
+ // we want to use this font in GetTextExtent() calls below but we don't
+ // want to send WM_SETFONT to the message box, who knows how is it going to
+ // react to it (right now it doesn't seem to do anything but what if this
+ // changes)
+ wxWindowBase::SetFont(GetMessageFont());
+
+ // first iteration: find the widest button and update the buttons labels
+ int wBtnOld = 0, // current buttons width
+ wBtnNew = 0; // required new buttons width
+ RECT rcBtn; // stores the button height and y positions
+ unsigned numButtons = 0; // total number of buttons in the message box
+ unsigned n;
+ for ( n = 0; n < WXSIZEOF(ms_buttons); n++ )
+ {
+ const HWND hwndBtn = ::GetDlgItem(GetHwnd(), ms_buttons[n].id);
+ if ( !hwndBtn )
+ continue; // it's ok, not all buttons are always present
+
+ numButtons++;
+
+ const wxString label = (this->*ms_buttons[n].getter)();
+ const wxSize sizeLabel = wxWindowBase::GetTextExtent(label);
+
+ // check if the button is big enough for this label
+ const RECT rc = wxGetWindowRect(hwndBtn);
+ if ( !wBtnOld )
+ {
+ // initialize wBtnOld using the first button width, all the other
+ // ones should have the same one
+ wBtnOld = rc.right - rc.left;
+
+ rcBtn = rc; // remember for use below when we reposition the buttons
+ }
+ else
+ {
+ wxASSERT_MSG( wBtnOld == rc.right - rc.left,
+ "all buttons are supposed to be of same width" );
+ }
+
+ const int widthNeeded = wxMSWButton::GetFittingSize(this, sizeLabel).x;
+ if ( widthNeeded > wBtnNew )
+ wBtnNew = widthNeeded;
+
+ ::SetWindowText(hwndBtn, label.wx_str());
+ }
+
+ if ( wBtnNew <= wBtnOld )
+ {
+ // all buttons fit, nothing else to do
+ return;
+ }
+
+ // resize the message box to be wider if needed
+ const int wBoxOld = wxGetClientRect(GetHwnd()).right;
+
+ const int CHAR_WIDTH = GetCharWidth();
+ const int MARGIN_OUTER = 2*CHAR_WIDTH; // margin between box and buttons
+ const int MARGIN_INNER = CHAR_WIDTH; // margin between buttons
+
+ RECT rcBox = wxGetWindowRect(GetHwnd());
+
+ const int wAllButtons = numButtons*(wBtnNew + MARGIN_INNER) - MARGIN_INNER;
+ int wBoxNew = 2*MARGIN_OUTER + wAllButtons;
+ if ( wBoxNew > wBoxOld )
+ {
+ const int dw = wBoxNew - wBoxOld;
+ rcBox.left -= dw/2;
+ rcBox.right += dw - dw/2;
+
+ SetWindowRect(GetHwnd(), rcBox);
+
+ // surprisingly, we don't need to resize the static text control, it
+ // seems to adjust itself to the new size, at least under Windows 2003
+ // (TODO: test if this happens on older Windows versions)
+ }
+ else // the current width is big enough
+ {
+ wBoxNew = wBoxOld;
+ }
+
+
+ // finally position all buttons
+
+ // notice that we have to take into account the difference between window
+ // and client width
+ rcBtn.left = (rcBox.left + rcBox.right - wxGetClientRect(GetHwnd()).right +
+ wBoxNew - wAllButtons) / 2;
+ rcBtn.right = rcBtn.left + wBtnNew;
+
+ for ( n = 0; n < WXSIZEOF(ms_buttons); n++ )
+ {
+ const HWND hwndBtn = ::GetDlgItem(GetHwnd(), ms_buttons[n].id);
+ if ( !hwndBtn )
+ continue;
+
+ MoveWindowToScreenRect(hwndBtn, rcBtn);
+
+ rcBtn.left += wBtnNew + MARGIN_INNER;
+ rcBtn.right += wBtnNew + MARGIN_INNER;
+ }
+}
+
+#endif // wxUSE_MSGBOX_HOOK
+
+/* static */
+wxFont wxMessageDialog::GetMessageFont()
+{
+ const NONCLIENTMETRICS& ncm = wxMSWImpl::GetNonClientMetrics();
+ return wxNativeFontInfo(ncm.lfMessageFont);