+// ----------------------------------------------------------------------------
+// helper functions from wx/msw/private/button.h
+// ----------------------------------------------------------------------------
+
+void wxMSWButton::UpdateMultilineStyle(HWND hwnd, const wxString& label)
+{
+ // update BS_MULTILINE style depending on the new label (resetting it
+ // doesn't seem to do anything very useful but it shouldn't hurt and we do
+ // have to set it whenever the label becomes multi line as otherwise it
+ // wouldn't be shown correctly as we don't use BS_MULTILINE when creating
+ // the control unless it already has new lines in its label)
+ long styleOld = ::GetWindowLong(hwnd, GWL_STYLE),
+ styleNew;
+ if ( label.find(wxT('\n')) != wxString::npos )
+ styleNew = styleOld | BS_MULTILINE;
+ else
+ styleNew = styleOld & ~BS_MULTILINE;
+
+ if ( styleNew != styleOld )
+ ::SetWindowLong(hwnd, GWL_STYLE, styleNew);
+}
+
+wxSize wxMSWButton::GetFittingSize(wxWindow *win,
+ const wxSize& sizeLabel,
+ int flags)
+{
+ // FIXME: this is pure guesswork, need to retrieve the real button margins
+ wxSize sizeBtn = sizeLabel;
+
+ sizeBtn.x += 3*win->GetCharWidth();
+ sizeBtn.y += win->GetCharHeight()/2;
+
+ // account for the shield UAC icon if we have it
+ if ( flags & Size_AuthNeeded )
+ sizeBtn.x += wxSystemSettings::GetMetric(wxSYS_SMALLICON_X);
+
+ return sizeBtn;
+}
+
+wxSize wxMSWButton::ComputeBestFittingSize(wxControl *btn, int flags)
+{
+ wxClientDC dc(btn);
+
+ wxSize sizeBtn;
+ dc.GetMultiLineTextExtent(btn->GetLabelText(), &sizeBtn.x, &sizeBtn.y);
+
+ return GetFittingSize(btn, sizeBtn, flags);
+}
+
+wxSize wxMSWButton::IncreaseToStdSizeAndCache(wxControl *btn, const wxSize& size)
+{
+ wxSize sizeBtn(size);
+
+ // All buttons have at least the standard height and, unless the user
+ // explicitly wants them to be as small as possible and used wxBU_EXACTFIT
+ // style to indicate this, of at least the standard width too.
+ //
+ // Notice that we really want to make all buttons equally high, otherwise
+ // they look ugly and the existing code using wxBU_EXACTFIT only uses it to
+ // control width and not height.
+
+ // The 50x14 button size is documented in the "Recommended sizing and
+ // spacing" section of MSDN layout article.
+ //
+ // Note that we intentionally don't use GetDefaultSize() here, because
+ // it's inexact -- dialog units depend on this dialog's font.
+ const wxSize sizeDef = btn->ConvertDialogToPixels(wxSize(50, 14));
+ if ( !btn->HasFlag(wxBU_EXACTFIT) )
+ {
+ if ( sizeBtn.x < sizeDef.x )
+ sizeBtn.x = sizeDef.x;
+ }
+ if ( sizeBtn.y < sizeDef.y )
+ sizeBtn.y = sizeDef.y;
+
+ btn->CacheBestSize(sizeBtn);
+
+ return sizeBtn;
+}
+