X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/06bb8d923df9ce02e522c661a11ff685466067a6..27d7687903b04c56878597fefccf3daafd0a58fa:/src/msw/button.cpp?ds=inline diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 407981a03a..9d7fa154a7 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -45,6 +45,7 @@ #include "wx/msw/private/button.h" #include "wx/msw/private/dc.h" #include "wx/private/window.h" +#include "wx/msw/missing.h" using namespace wxMSWImpl; @@ -588,6 +589,71 @@ void wxButton::SetLabel(const wxString& label) // size management including autosizing // ---------------------------------------------------------------------------- +void wxButton::AdjustForBitmapSize(wxSize &size) const +{ + if ( !m_imageData ) + return; + + // account for the bitmap size + const wxSize sizeBmp = m_imageData->GetBitmap(State_Normal).GetSize(); + const wxDirection dirBmp = m_imageData->GetBitmapPosition(); + if ( dirBmp == wxLEFT || dirBmp == wxRIGHT ) + { + size.x += sizeBmp.x; + if ( sizeBmp.y > size.y ) + size.y = sizeBmp.y; + } + else // bitmap on top/below the text + { + size.y += sizeBmp.y; + if ( sizeBmp.x > size.x ) + size.x = sizeBmp.x; + } + + // account for the user-specified margins + size += 2*m_imageData->GetBitmapMargins(); + + // and also for the margins we always add internally (unless we have no + // border at all in which case the button has exactly the same size as + // bitmap and so no margins should be used) + if ( !HasFlag(wxBORDER_NONE) ) + { + int marginH = 0, + marginV = 0; +#if wxUSE_UXTHEME + if ( wxUxThemeEngine::GetIfActive() ) + { + wxUxThemeHandle theme(const_cast(this), L"BUTTON"); + + MARGINS margins; + wxUxThemeEngine::Get()->GetThemeMargins(theme, NULL, + BP_PUSHBUTTON, + PBS_NORMAL, + TMT_CONTENTMARGINS, + NULL, + &margins); + + // XP doesn't draw themed buttons correctly when the client + // area is smaller than 8x8 - enforce this minimum size for + // small bitmaps + size.IncTo(wxSize(8, 8)); + + marginH = margins.cxLeftWidth + margins.cxRightWidth + + 2*XP_BUTTON_EXTRA_MARGIN; + marginV = margins.cyTopHeight + margins.cyBottomHeight + + 2*XP_BUTTON_EXTRA_MARGIN; + } + else +#endif // wxUSE_UXTHEME + { + marginH = + marginV = OD_BUTTON_MARGIN; + } + + size.IncBy(marginH, marginV); + } +} + wxSize wxButton::DoGetBestSize() const { wxSize size; @@ -606,64 +672,7 @@ wxSize wxButton::DoGetBestSize() const if ( m_imageData ) { - // account for the bitmap size - const wxSize sizeBmp = m_imageData->GetBitmap(State_Normal).GetSize(); - const wxDirection dirBmp = m_imageData->GetBitmapPosition(); - if ( dirBmp == wxLEFT || dirBmp == wxRIGHT ) - { - size.x += sizeBmp.x; - if ( sizeBmp.y > size.y ) - size.y = sizeBmp.y; - } - else // bitmap on top/below the text - { - size.y += sizeBmp.y; - if ( sizeBmp.x > size.x ) - size.x = sizeBmp.x; - } - - // account for the user-specified margins - size += 2*m_imageData->GetBitmapMargins(); - - // and also for the margins we always add internally (unless we have no - // border at all in which case the button has exactly the same size as - // bitmap and so no margins should be used) - if ( !HasFlag(wxBORDER_NONE) ) - { - int marginH = 0, - marginV = 0; -#if wxUSE_UXTHEME - if ( wxUxThemeEngine::GetIfActive() ) - { - wxUxThemeHandle theme(const_cast(this), L"BUTTON"); - - MARGINS margins; - wxUxThemeEngine::Get()->GetThemeMargins(theme, NULL, - BP_PUSHBUTTON, - PBS_NORMAL, - TMT_CONTENTMARGINS, - NULL, - &margins); - - // XP doesn't draw themed buttons correctly when the client - // area is smaller than 8x8 - enforce this minimum size for - // small bitmaps - size.IncTo(wxSize(8, 8)); - - marginH = margins.cxLeftWidth + margins.cxRightWidth - + 2*XP_BUTTON_EXTRA_MARGIN; - marginV = margins.cyTopHeight + margins.cyBottomHeight - + 2*XP_BUTTON_EXTRA_MARGIN; - } - else -#endif // wxUSE_UXTHEME - { - marginH = - marginV = OD_BUTTON_MARGIN; - } - - size.IncBy(marginH, marginV); - } + AdjustForBitmapSize(size); CacheBestSize(size); } @@ -1391,33 +1400,38 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis) // for simplicity, we start with centred rectangle and then move it to // the appropriate edge wxRect rectBitmap = wxRect(sizeBmp).CentreIn(rectButton); - switch ( m_imageData->GetBitmapPosition() ) - { - default: - wxFAIL_MSG( "invalid direction" ); - // fall through - case wxLEFT: - rectBitmap.x = rectButton.x + margin.x; - rectButton.x += sizeBmpWithMargins.x; - rectButton.width -= sizeBmpWithMargins.x; - break; - - case wxRIGHT: - rectBitmap.x = rectButton.GetRight() - sizeBmp.x - margin.x; - rectButton.width -= sizeBmpWithMargins.x; - break; - - case wxTOP: - rectBitmap.y = rectButton.y + margin.y; - rectButton.y += sizeBmpWithMargins.y; - rectButton.height -= sizeBmpWithMargins.y; - break; - - case wxBOTTOM: - rectBitmap.y = rectButton.GetBottom() - sizeBmp.y - margin.y; - rectButton.height -= sizeBmpWithMargins.y; - break; + // move bitmap only if we have a label, otherwise keep it centered + if ( ShowsLabel() ) + { + switch ( m_imageData->GetBitmapPosition() ) + { + default: + wxFAIL_MSG( "invalid direction" ); + // fall through + + case wxLEFT: + rectBitmap.x = rectButton.x + margin.x; + rectButton.x += sizeBmpWithMargins.x; + rectButton.width -= sizeBmpWithMargins.x; + break; + + case wxRIGHT: + rectBitmap.x = rectButton.GetRight() - sizeBmp.x - margin.x; + rectButton.width -= sizeBmpWithMargins.x; + break; + + case wxTOP: + rectBitmap.y = rectButton.y + margin.y; + rectButton.y += sizeBmpWithMargins.y; + rectButton.height -= sizeBmpWithMargins.y; + break; + + case wxBOTTOM: + rectBitmap.y = rectButton.GetBottom() - sizeBmp.y - margin.y; + rectButton.height -= sizeBmpWithMargins.y; + break; + } } wxDCTemp dst((WXHDC)hdc);