// headers
// ----------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "button.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/bmpbuttn.h"
#include "wx/settings.h"
#include "wx/dcscreen.h"
+ #include "wx/dcclient.h"
#endif
#include "wx/stockitem.h"
wxCoord wBtn,
hBtn;
- dc.GetMultiLineTextExtent(GetLabel(), &wBtn, &hBtn);
+ dc.GetMultiLineTextExtent(wxStripMenuCodes(GetLabel()), &wBtn, &hBtn);
// add a margin -- the button is wider than just its label
wBtn += 3*GetCharWidth();
return sz;
}
- return wxSize(wBtn, hBtn);
+ wxSize best(wBtn, hBtn);
+ CacheBestSize(best);
+ return best;
}
/* static */
COLORREF colOld = SetTextColor(hdc, col);
int modeOld = SetBkMode(hdc, TRANSPARENT);
- // Note: we must have DT_SINGLELINE for DT_VCENTER to work.
- ::DrawText(hdc, text, text.length(), pRect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
+ if ( text.find(_T('\n')) != wxString::npos )
+ {
+ // draw multiline label
+
+ // first we need to compute its bounding rect
+ RECT rc;
+ ::CopyRect(&rc, pRect);
+ ::DrawText(hdc, text, 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.right = rc.left+w;
+ rc.top = (pRect->bottom - pRect->top)/2 - h/2;
+ rc.bottom = rc.top+h;
+
+ ::DrawText(hdc, text, text.length(), &rc, DT_CENTER);
+ }
+ else // single line label
+ {
+ // Note: we must have DT_SINGLELINE for DT_VCENTER to work.
+ ::DrawText(hdc, text, text.length(), pRect,
+ DT_SINGLELINE | DT_CENTER | DT_VCENTER);
+ }
SetBkMode(hdc, modeOld);
SetTextColor(hdc, colOld);