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:
@@ -94,6 +94,7 @@ Major new features in 2.8 release
|
||||
All (GUI):
|
||||
|
||||
- Added wxWindow::GetNextSibling() and GetPrevSibling()
|
||||
- Support wxGRID_AUTOSIZE in wxGrid::SetRow/ColLabelSize() (Evgeniy Tarassov)
|
||||
|
||||
All (Unix):
|
||||
|
||||
|
@@ -1596,6 +1596,10 @@ Vertical alignment should be one of wxALIGN\_TOP, wxALIGN\_CENTRE or wxALIGN\_BO
|
||||
|
||||
Sets the height of the column labels.
|
||||
|
||||
If \arg{height} equals to \textt{wxGRID\_AUTOSIZE} then height is calculated
|
||||
automatically so that no label is truncated. Note that this could be slow for a
|
||||
large table. This flag is new since wxWidgets version 2.8.8.
|
||||
|
||||
|
||||
|
||||
\membersection{wxGrid::SetColLabelValue}\label{wxgridsetcollabelvalue}
|
||||
@@ -1835,6 +1839,10 @@ Vertical alignment should be one of wxALIGN\_TOP, wxALIGN\_CENTRE or wxALIGN\_BO
|
||||
|
||||
Sets the width of the row labels.
|
||||
|
||||
If \arg{width} equals \textt{wxGRID\_AUTOSIZE} then width is calculated
|
||||
automatically so that no label is truncated. Note that this could be slow for a
|
||||
large table. This flag is new since wxWidgets version 2.8.8.
|
||||
|
||||
|
||||
|
||||
\membersection{wxGrid::SetRowLabelValue}\label{wxgridsetrowlabelvalue}
|
||||
|
@@ -51,6 +51,12 @@ extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxGridNameStr[];
|
||||
#define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
|
||||
#define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
|
||||
|
||||
#if wxABI_VERSION >= 20808
|
||||
// magic constant which tells (to some functions) to automatically
|
||||
// calculate the appropriate size
|
||||
#define wxGRID_AUTOSIZE (-1)
|
||||
#endif // wxABI_VERSION >= 20808
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// forward declarations
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -1996,6 +2002,10 @@ protected:
|
||||
bool GetModelValues();
|
||||
bool SetModelValues();
|
||||
|
||||
private:
|
||||
// Calculate the minimum acceptable size for labels area
|
||||
wxCoord CalcColOrRowLabelAreaMinSize(bool column /* or row? */);
|
||||
|
||||
friend class WXDLLIMPEXP_ADV wxGridSelection;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS( wxGrid )
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user