X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b4354db179f5b9f3107cc532bb5232deccab90d0..739c5499fcab1c165b8dd0591c9fd9e2329b3cf9:/src/msw/anybutton.cpp diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index 6869aec1e3..2bf1b41f4c 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -3,7 +3,7 @@ // Purpose: wxAnyButton // Author: Julian Smart // Created: 1998-01-04 (extracted from button.cpp) -// RCS-ID: $Id: anybutton.cpp 67384 2011-04-03 20:31:32Z DS $ +// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -150,8 +150,9 @@ public: wxODButtonImageData(wxAnyButton *btn, const wxBitmap& bitmap) { SetBitmap(bitmap, wxAnyButton::State_Normal); +#if wxUSE_IMAGE SetBitmap(bitmap.ConvertToDisabled(), wxAnyButton::State_Disabled); - +#endif m_dir = wxLEFT; // we use margins when we have both bitmap and text, but when we have @@ -222,8 +223,12 @@ public: // initialize all bitmaps except for the disabled one to normal state for ( int n = 0; n < wxAnyButton::State_Max; n++ ) { +#if wxUSE_IMAGE m_iml.Add(n == wxAnyButton::State_Disabled ? bitmap.ConvertToDisabled() : bitmap); +#else + m_iml.Add(bitmap); +#endif } m_data.himl = GetHimagelistOf(&m_iml); @@ -387,11 +392,21 @@ 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; + // FIXME: The numbers here are pure guesswork, no idea how should the + // button margins be really calculated. + if ( flags & Size_ExactFit ) + { + // We still need some margin or the text would be overwritten, just + // make it as small as possible. + sizeBtn.x += (3*win->GetCharWidth()); + } + else + { + sizeBtn.x += 3*win->GetCharWidth(); + sizeBtn.y += win->GetCharHeight()/2; + } // account for the shield UAC icon if we have it if ( flags & Size_AuthNeeded ) @@ -555,6 +570,8 @@ wxSize wxAnyButton::DoGetBestSize() const if ( ShowsLabel() ) { int flags = 0; + if ( HasFlag(wxBU_EXACTFIT) ) + flags |= wxMSWButton::Size_ExactFit; if ( DoGetAuthNeeded() ) flags |= wxMSWButton::Size_AuthNeeded; @@ -644,7 +661,7 @@ void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which) if ( m_imageData && bitmap.GetSize() != m_imageData->GetBitmap(State_Normal).GetSize() ) { - wxASSERT_MSG( which == State_Normal, + wxASSERT_MSG( (which == State_Normal) || bitmap.IsNull(), "Must set normal bitmap with the new size first" ); #if wxUSE_UXTHEME @@ -801,18 +818,18 @@ void DrawButtonText(HDC hdc, // first we need to compute its bounding rect RECT rc; ::CopyRect(&rc, pRect); - ::DrawText(hdc, text.wx_str(), text.length(), &rc, + ::DrawText(hdc, text.t_str(), text.length(), &rc, DT_CENTER | DT_CALCRECT); // now center this rect inside the entire button area const LONG w = rc.right - rc.left; const LONG h = rc.bottom - rc.top; - rc.left = (pRect->right - pRect->left)/2 - w/2; + rc.left = pRect->left + (pRect->right - pRect->left)/2 - w/2; rc.right = rc.left+w; - rc.top = (pRect->bottom - pRect->top)/2 - h/2; + rc.top = pRect->top + (pRect->bottom - pRect->top)/2 - h/2; rc.bottom = rc.top+h; - ::DrawText(hdc, text.wx_str(), text.length(), &rc, flags); + ::DrawText(hdc, text.t_str(), text.length(), &rc, flags); } else // single line label { @@ -839,7 +856,7 @@ void DrawButtonText(HDC hdc, // notice that we must have DT_SINGLELINE for vertical alignment flags // to work - ::DrawText(hdc, text.wx_str(), text.length(), pRect, + ::DrawText(hdc, text.t_str(), text.length(), pRect, flags | DT_SINGLELINE ); } } @@ -1142,7 +1159,7 @@ bool wxAnyButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis) { wxBitmap bmp = m_imageData->GetBitmap(GetButtonState(this, state)); if ( !bmp.IsOk() ) - bmp = m_imageData->GetBitmap(GetNormalState()); + bmp = m_imageData->GetBitmap(State_Normal); const wxSize sizeBmp = bmp.GetSize(); const wxSize margin = m_imageData->GetBitmapMargins();