X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d2bc87252ae509ad755ee1d631ab994bcdb6c5be..887b919bde47aeab043506e220be25d4d293afaf:/src/msw/button.cpp diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 240e2e9813..1a9b4d6ca2 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -225,13 +225,13 @@ public: m_data.himl = GetHimagelistOf(&m_iml); - // use default margins + // no margins by default m_data.margin.left = - m_data.margin.right = btn->GetCharWidth(); + m_data.margin.right = m_data.margin.top = - m_data.margin.bottom = btn->GetCharHeight() / 2; + m_data.margin.bottom = 0; - // and default alignment + // use default alignment m_data.uAlign = BUTTON_IMAGELIST_ALIGN_LEFT; UpdateImageInfo(); @@ -388,7 +388,6 @@ wxSize wxMSWButton::GetFittingSize(wxWindow *win, wxSize sizeBtn = sizeLabel; sizeBtn.x += 3*win->GetCharWidth(); - sizeBtn.y = 11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(sizeLabel.y)/10; // account for the shield UAC icon if we have it if ( flags & Size_AuthNeeded ) @@ -397,21 +396,28 @@ wxSize wxMSWButton::GetFittingSize(wxWindow *win, return sizeBtn; } -wxSize wxMSWButton::ComputeBestSize(wxControl *btn, int flags) +wxSize wxMSWButton::ComputeBestFittingSize(wxControl *btn, int flags) { wxClientDC dc(btn); wxSize sizeBtn; dc.GetMultiLineTextExtent(btn->GetLabelText(), &sizeBtn.x, &sizeBtn.y); - sizeBtn = GetFittingSize(btn, sizeBtn, flags); + return GetFittingSize(btn, sizeBtn, flags); +} + +wxSize wxMSWButton::IncreaseToStdSizeAndCache(wxControl *btn, const wxSize& size) +{ + wxSize sizeBtn(size); // 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 // creating the button if ( !btn->HasFlag(wxBU_EXACTFIT) ) { - // The size of a standard button in the dialog units is 50x14, use it. + // 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. wxSize sizeDef = btn->ConvertDialogToPixels(wxSize(50, 14)); @@ -531,8 +537,7 @@ void wxButton::SetLabel(const wxString& label) void wxButton::AdjustForBitmapSize(wxSize &size) const { - if ( !m_imageData ) - return; + wxCHECK_RET( m_imageData, wxT("shouldn't be called if no image") ); // account for the bitmap size const wxSize sizeBmp = m_imageData->GetBitmap(State_Normal).GetSize(); @@ -596,28 +601,24 @@ void wxButton::AdjustForBitmapSize(wxSize &size) const wxSize wxButton::DoGetBestSize() const { + wxButton * const self = const_cast(this); + wxSize size; - // account for the text part if we have it or if we don't have any image at - // all (buttons initially created with empty label should still have a non - // zero size) - if ( ShowsLabel() || !m_imageData ) + // Account for the text part if we have it. + if ( ShowsLabel() ) { int flags = 0; if ( GetAuthNeeded() ) flags |= wxMSWButton::Size_AuthNeeded; - size = wxMSWButton::ComputeBestSize(const_cast(this), flags); + size = wxMSWButton::ComputeBestFittingSize(self, flags); } if ( m_imageData ) - { AdjustForBitmapSize(size); - CacheBestSize(size); - } - - return size; + return wxMSWButton::IncreaseToStdSizeAndCache(self, size); } /* static */