X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2376eee2483911ac454f16313a48da5740457765..2b9a7d4cc2f5f55df3d83f7cf2160cf9a509a4f2:/src/msw/button.cpp diff --git a/src/msw/button.cpp b/src/msw/button.cpp index ba86e1650b..b50d0c6bd8 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -132,7 +132,18 @@ bool wxButton::Create(wxWindow *parent, { wxString label(lbl); if (label.empty() && wxIsStockID(id)) - label = wxGetStockLabel(id); + { + // On Windows, some buttons aren't supposed to have + // mnemonics, so strip them out. + + label = wxGetStockLabel(id +#if defined(__WXMSW__) || defined(__WXWINCE__) + , ( id != wxID_OK && + id != wxID_CANCEL && + id != wxID_CLOSE ) +#endif + ); + } if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return false; @@ -205,38 +216,16 @@ WXDWORD wxButton::MSWGetStyle(long style, WXDWORD *exstyle) const wxSize wxButton::DoGetBestSize() const { - int wBtn = 0; - int wChar, hChar, hBtn; - wxGetCharSize(GetHWND(), &wChar, &hChar, GetFont()); + wxClientDC dc(wx_const_cast(wxButton *, this)); + dc.SetFont(GetFont()); - wxString label = wxGetWindowText(GetHWND()); - if ( label.find(_T('\n')) != wxString::npos ) - { - wxStringTokenizer tokens( label, wxT("\n") ); + wxCoord wBtn, + hBtn; + dc.GetMultiLineTextExtent(GetLabel(), &wBtn, &hBtn); - // the button height is proportional to the height of the font used - hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); - hBtn += hChar*(tokens.CountTokens()-1); - - while (tokens.HasMoreTokens()) - { - wxString sub = tokens.GetNextToken(); - int w; - GetTextExtent( sub, &w, NULL); - if (w > wBtn) - wBtn = w; - } - } - else - { - GetTextExtent( label, &wBtn, NULL); - - // the button height is proportional to the height of the font used - hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); - } - // add a margin -- the button is wider than just its label - wBtn += 3*wChar; + wBtn += 3*GetCharWidth(); + hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hBtn); // all buttons have at least the standard size unless the user explicitly // wants them to be of smaller size and used wxBU_EXACTFIT style when