]> git.saurik.com Git - wxWidgets.git/commitdiff
Allow passing multi-line strings to wxDC::DrawText(), even under MSW.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 23 Jul 2010 23:32:52 +0000 (23:32 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 23 Jul 2010 23:32:52 +0000 (23:32 +0000)
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

docs/changes.txt
interface/wx/dc.h
samples/drawing/drawing.cpp
src/common/dcbase.cpp
src/msw/dc.cpp

index cd10d568e844eaa6eb01f75d267abb86dd891509..7537912008e46174664f6ea2977b195b2685667c 100644 (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:
 ------
index 71085fb263dccf4b8bb776cf927161ff81c2a11c..f95103d0639dad8f4beafbfe5157d14456acc2a6 100644 (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.
index 80437e10b4639684b24c629e63cb196d9bd77493..d48e299dab2fcaafcf0a917e8fe5ed59479e2251 100644 (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
index 415b71763a961fbec886fb005e94891e153a87ea..807c0cae30cfd062ead10c1698a73ac383546c68 100644 (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 )
     {
index 675447fe3a235d07d1d32c3c551033503dbf97fc..298e6c86137cbca20c2795c9fe9696f234250393 100644 (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);