Allow passing multi-line strings to wxDC::DrawText(), even under MSW.

Native wxMSW wxDC::DrawText() implementation doesn't support multi-line
strings so use the generic wxDC::DrawLabel() code instead. Drawing multi-line
strings now works at least in wxGTK and wxMSW, to be tested for the other
platforms.

Closes #12239.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65058 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2010-07-23 23:32:52 +00:00
parent 715e4f7e3e
commit a5bb451448
5 changed files with 28 additions and 2 deletions

View File

@ -406,7 +406,7 @@ Major new features in this release
MSW:
- Fix Cygwin 1.7 build (David Gangola).
- Allow using wxDC::DrawText() with multiline texts.
2.9.1:
------

View File

@ -596,7 +596,12 @@ public:
The coordinates refer to the top-left corner of the rectangle bounding
the string. See GetTextExtent() for how to get the dimensions of a text
string, which can be used to position the text more precisely.
string, which can be used to position the text more precisely and
DrawLabel() if you need to align the string differently.
Starting from wxWidgets 2.9.2 @a text parameter can be a multi-line
string, i.e. contain new line characters, and will be rendered
correctly.
@note The current @ref GetLogicalFunction() "logical function" is
ignored by this function.

View File

@ -789,6 +789,9 @@ void MyCanvas::DrawText(wxDC& dc)
y += height;
dc.DrawRectangle( 110, y, 100, height );
dc.DrawText( wxT("Another visible text"), 110, y );
y += height;
dc.DrawText("And\nmore\ntext on\nmultiple\nlines", 110, y);
}
static const struct

View File

@ -1205,6 +1205,12 @@ void wxDC::DrawLabel(const wxString& text,
yUnderscore = 0;
// split the string into lines and draw each of them separately
//
// NB: while wxDC::DrawText() on some platforms supports drawing multi-line
// strings natively, this is not the case for all of them, notably not
// wxMSW which uses this function for multi-line texts, so we may only
// call DrawText() for single-line strings from here to avoid infinite
// recursion.
wxString curLine;
for ( wxString::const_iterator pc = text.begin(); ; ++pc )
{

View File

@ -1303,6 +1303,18 @@ void wxMSWDCImpl::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool
void wxMSWDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
{
// For compatibility with other ports (notably wxGTK) and because it's
// genuinely useful, we allow passing multiline strings to DrawText().
// However there is no native MSW function to draw them directly so we
// instead reuse the generic DrawLabel() method to render them. Of course,
// DrawLabel() itself will call back to us but with single line strings
// only so there won't be any infinite recursion here.
if ( text.find('\n') != wxString::npos )
{
GetOwner()->DrawLabel(text, wxRect(x, y, 0, 0));
return;
}
WXMICROWIN_CHECK_HDC
DrawAnyText(text, x, y);