code cleanup in DrawTextRectangle()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39062 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-05-06 15:28:27 +00:00
parent 5637e1311b
commit 4330c974ed

View File

@@ -7551,6 +7551,8 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
textOrientation ); textOrientation );
} }
// VZ: this should be replaced with wxDC::DrawLabel() to which we just have to
// add textOrientation support
void wxGrid::DrawTextRectangle(wxDC& dc, void wxGrid::DrawTextRectangle(wxDC& dc,
const wxArrayString& lines, const wxArrayString& lines,
const wxRect& rect, const wxRect& rect,
@@ -7558,23 +7560,21 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
int vertAlign, int vertAlign,
int textOrientation) int textOrientation)
{ {
long textWidth = 0, textHeight = 0; if ( lines.empty() )
long lineWidth = 0, lineHeight = 0; return;
int nLines;
dc.SetClippingRegion( rect ); wxDCClipper clip(dc, rect);
nLines = lines.GetCount(); long textWidth,
if ( nLines > 0 ) textHeight;
{
int l;
float x = 0.0, y = 0.0;
if ( textOrientation == wxHORIZONTAL ) if ( textOrientation == wxHORIZONTAL )
GetTextBoxSize( dc, lines, &textWidth, &textHeight ); GetTextBoxSize( dc, lines, &textWidth, &textHeight );
else else
GetTextBoxSize( dc, lines, &textHeight, &textWidth ); GetTextBoxSize( dc, lines, &textHeight, &textWidth );
int x = 0,
y = 0;
switch ( vertAlign ) switch ( vertAlign )
{ {
case wxALIGN_BOTTOM: case wxALIGN_BOTTOM:
@@ -7601,9 +7601,14 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
} }
// Align each line of a multi-line label // Align each line of a multi-line label
for ( l = 0; l < nLines; l++ ) size_t nLines = lines.GetCount();
for ( size_t l = 0; l < nLines; l++ )
{ {
dc.GetTextExtent(lines[l], &lineWidth, &lineHeight); const wxString& line = lines[l];
long lineWidth,
lineHeight;
dc.GetTextExtent(line, &lineWidth, &lineHeight);
switch ( horizAlign ) switch ( horizAlign )
{ {
@@ -7632,20 +7637,17 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
if ( textOrientation == wxHORIZONTAL ) if ( textOrientation == wxHORIZONTAL )
{ {
dc.DrawText( lines[l], (int)x, (int)y ); dc.DrawText( line, x, y );
y += lineHeight; y += lineHeight;
} }
else else
{ {
dc.DrawRotatedText( lines[l], (int)x, (int)y, 90.0 ); dc.DrawRotatedText( line, x, y, 90.0 );
x += lineHeight; x += lineHeight;
} }
} }
} }
dc.DestroyClippingRegion();
}
// Split multi-line text up into an array of strings. // Split multi-line text up into an array of strings.
// Any existing contents of the string array are preserved. // Any existing contents of the string array are preserved.
// //