backported wxGrid labels autosizing patch (r44835) to 2.8

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@50201 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2007-11-23 21:21:25 +00:00
parent 6144cede54
commit c25ddfa8a3
4 changed files with 85 additions and 2 deletions

View File

@@ -9374,7 +9374,13 @@ wxString wxGrid::GetColLabelValue( int col )
void wxGrid::SetRowLabelSize( int width )
{
width = wxMax( width, 0 );
wxASSERT( width >= 0 || width == wxGRID_AUTOSIZE );
if ( width == wxGRID_AUTOSIZE )
{
width = CalcColOrRowLabelAreaMinSize(false/*row*/);
}
if ( width != m_rowLabelWidth )
{
if ( width == 0 )
@@ -9397,7 +9403,13 @@ void wxGrid::SetRowLabelSize( int width )
void wxGrid::SetColLabelSize( int height )
{
height = wxMax( height, 0 );
wxASSERT( height >=0 || height == wxGRID_AUTOSIZE );
if ( height == wxGRID_AUTOSIZE )
{
height = CalcColOrRowLabelAreaMinSize(true/*column*/);
}
if ( height != m_colLabelHeight )
{
if ( height == 0 )
@@ -10555,6 +10567,58 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column )
}
}
wxCoord wxGrid::CalcColOrRowLabelAreaMinSize(bool column)
{
// calculate size for the rows or columns?
const bool calcRows = !column;
wxClientDC dc(calcRows ? GetGridRowLabelWindow()
: GetGridColLabelWindow());
dc.SetFont(GetLabelFont());
// which dimension should we take into account for calculations?
//
// for columns, the text can be only horizontal so it's easy but for rows
// we also have to take into account the text orientation
const bool
useWidth = calcRows || (GetColLabelTextOrientation() == wxVERTICAL);
wxArrayString lines;
wxCoord extentMax = 0;
const int numRowsOrCols = calcRows ? m_numRows : m_numCols;
for ( int rowOrCol = 0; rowOrCol < numRowsOrCols; rowOrCol++ )
{
lines.Clear();
StringToLines(calcRows ? GetRowLabelValue(rowOrCol)
: GetColLabelValue(rowOrCol),
lines);
long w, h;
GetTextBoxSize(dc, lines, &w, &h);
const wxCoord extent = useWidth ? w : h;
if ( extent > extentMax )
extentMax = extent;
}
if ( !extentMax )
{
// empty column - give default extent (notice that if extentMax is less
// than default extent but != 0, it's OK)
extentMax = calcRows ? GetDefaultRowLabelSize()
: GetDefaultColLabelSize();
}
// leave some space around text (taken from AutoSizeColOrRow)
if ( calcRows )
extentMax += 10;
else
extentMax += 6;
return extentMax;
}
int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
{
int width = m_rowLabelWidth;