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,32 +7551,32 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
textOrientation ); textOrientation );
} }
void wxGrid::DrawTextRectangle( wxDC& dc, // VZ: this should be replaced with wxDC::DrawLabel() to which we just have to
// add textOrientation support
void wxGrid::DrawTextRectangle(wxDC& dc,
const wxArrayString& lines, const wxArrayString& lines,
const wxRect& rect, const wxRect& rect,
int horizAlign, int horizAlign,
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;
if ( textOrientation == wxHORIZONTAL )
GetTextBoxSize( dc, lines, &textWidth, &textHeight );
else
GetTextBoxSize( dc, lines, &textHeight, &textWidth );
int x = 0,
y = 0;
switch ( vertAlign )
{ {
int l;
float x = 0.0, y = 0.0;
if ( textOrientation == wxHORIZONTAL )
GetTextBoxSize( dc, lines, &textWidth, &textHeight );
else
GetTextBoxSize( dc, lines, &textHeight, &textWidth );
switch ( vertAlign )
{
case wxALIGN_BOTTOM: case wxALIGN_BOTTOM:
if ( textOrientation == wxHORIZONTAL ) if ( textOrientation == wxHORIZONTAL )
y = rect.y + (rect.height - textHeight - 1); y = rect.y + (rect.height - textHeight - 1);
@@ -7598,15 +7598,20 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
else else
x = rect.x + 1; x = rect.x + 1;
break; break;
} }
// 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++ )
{
const wxString& line = lines[l];
long lineWidth,
lineHeight;
dc.GetTextExtent(line, &lineWidth, &lineHeight);
switch ( horizAlign )
{ {
dc.GetTextExtent(lines[l], &lineWidth, &lineHeight);
switch ( horizAlign )
{
case wxALIGN_RIGHT: case wxALIGN_RIGHT:
if ( textOrientation == wxHORIZONTAL ) if ( textOrientation == wxHORIZONTAL )
x = rect.x + (rect.width - lineWidth - 1); x = rect.x + (rect.width - lineWidth - 1);
@@ -7628,22 +7633,19 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
else else
y = rect.y + rect.height - 1; y = rect.y + rect.height - 1;
break; break;
} }
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.