+// helper of AdjustButtonLabels(): move the given window by dx
+//
+// works for both child and top level windows
+void OffsetWindow(HWND hwnd, int dx)
+{
+ RECT rc = wxGetWindowRect(hwnd);
+
+ rc.left += dx;
+ rc.right += dx;
+
+ MoveWindowToScreenRect(hwnd, rc);
+}
+
+} // anonymous namespace
+
+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 hence the size of the message box itself) if they are not
+
+ // TODO-RTL: check whether this works correctly in RTL
+
+ // the order in this array is the one in which buttons appear in the
+ // message box
+ const static struct ButtonAccessors
+ {
+ int id;
+ wxString (wxMessageDialog::*getter)() const;
+ }
+ buttons[] =
+ {
+ { IDYES, &wxMessageDialog::GetYesLabel },
+ { IDNO, &wxMessageDialog::GetNoLabel },
+ { IDOK, &wxMessageDialog::GetOKLabel },
+ { IDCANCEL, &wxMessageDialog::GetCancelLabel },
+ };
+
+ // this contains the amount by which we increased the message box width
+ int dx = 0;
+
+ const NONCLIENTMETRICS& ncm = wxMSWImpl::GetNonClientMetrics();
+ const wxFont fontMsgBox(wxNativeFontInfo(ncm.lfMessageFont));
+
+ // 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(fontMsgBox);
+
+ for ( unsigned n = 0; n < WXSIZEOF(buttons); n++ )
+ {
+ const HWND hwndBtn = ::GetDlgItem(GetHwnd(), buttons[n].id);
+ if ( !hwndBtn )
+ continue; // it's ok, not all buttons are always present
+
+ const wxString label = (this->*buttons[n].getter)();
+ const wxSize sizeLabel = wxWindowBase::GetTextExtent(label);
+
+ // check if the button is big enough for this label
+ RECT rc = wxGetWindowRect(hwndBtn);
+ const int widthOld = rc.right - rc.left;
+ const int widthNew = wxMSWButton::GetFittingSize(this, sizeLabel).x;
+ const int dw = widthNew - widthOld;
+ if ( dw > 0 )
+ {
+ // we need to resize the button
+ rc.right += dw;
+ MoveWindowToScreenRect(hwndBtn, rc);
+
+ // and also move all the other buttons
+ for ( unsigned m = n + 1; m < WXSIZEOF(buttons); m++ )
+ {
+ const HWND hwndBtnNext = ::GetDlgItem(GetHwnd(), buttons[m].id);
+ if ( hwndBtnNext )
+ OffsetWindow(hwndBtnNext, dw);
+ }
+
+ dx += dw;
+ }
+
+ ::SetWindowText(hwndBtn, label.wx_str());
+ }
+
+
+ // resize the message box itself if needed
+ if ( dx )
+ OffsetWindow(GetHwnd(), dx);
+
+ // 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)
+}
+
+#endif // wxUSE_MSGBOX_HOOK
+
+