fixed long standing bug with Fit() still showing the scrollbars: the old code for rounding up the grid size to a multiple of scroll step was wrong as it did for the grid itself and not just the scrollable area (and also assorted off by 1 errors and a workaround for a bug in wxMSW SetClientSize() implementation whihc may sometimes leave space for unneeded scrollbar)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43776 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -4485,8 +4485,9 @@ void wxGrid::Init()
|
|||||||
// default widths/heights are used for all rows/columns, we may not use these
|
// default widths/heights are used for all rows/columns, we may not use these
|
||||||
// arrays at all
|
// arrays at all
|
||||||
//
|
//
|
||||||
// with some extra code, it should be possible to only store the
|
// with some extra code, it should be possible to only store the widths/heights
|
||||||
// widths/heights different from default ones but this will be done later...
|
// different from default ones (resulting in space savings for huge grids) but
|
||||||
|
// this is not done currently
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxGrid::InitRowHeights()
|
void wxGrid::InitRowHeights()
|
||||||
@@ -4497,10 +4498,9 @@ void wxGrid::InitRowHeights()
|
|||||||
m_rowHeights.Alloc( m_numRows );
|
m_rowHeights.Alloc( m_numRows );
|
||||||
m_rowBottoms.Alloc( m_numRows );
|
m_rowBottoms.Alloc( m_numRows );
|
||||||
|
|
||||||
int rowBottom = 0;
|
|
||||||
|
|
||||||
m_rowHeights.Add( m_defaultRowHeight, m_numRows );
|
m_rowHeights.Add( m_defaultRowHeight, m_numRows );
|
||||||
|
|
||||||
|
int rowBottom = 0;
|
||||||
for ( int i = 0; i < m_numRows; i++ )
|
for ( int i = 0; i < m_numRows; i++ )
|
||||||
{
|
{
|
||||||
rowBottom += m_defaultRowHeight;
|
rowBottom += m_defaultRowHeight;
|
||||||
@@ -4515,10 +4515,10 @@ void wxGrid::InitColWidths()
|
|||||||
|
|
||||||
m_colWidths.Alloc( m_numCols );
|
m_colWidths.Alloc( m_numCols );
|
||||||
m_colRights.Alloc( m_numCols );
|
m_colRights.Alloc( m_numCols );
|
||||||
int colRight = 0;
|
|
||||||
|
|
||||||
m_colWidths.Add( m_defaultColWidth, m_numCols );
|
m_colWidths.Add( m_defaultColWidth, m_numCols );
|
||||||
|
|
||||||
|
int colRight = 0;
|
||||||
for ( int i = 0; i < m_numCols; i++ )
|
for ( int i = 0; i < m_numCols; i++ )
|
||||||
{
|
{
|
||||||
colRight = ( GetColPos( i ) + 1 ) * m_defaultColWidth;
|
colRight = ( GetColPos( i ) + 1 ) * m_defaultColWidth;
|
||||||
@@ -4562,17 +4562,12 @@ int wxGrid::GetRowBottom(int row) const
|
|||||||
|
|
||||||
void wxGrid::CalcDimensions()
|
void wxGrid::CalcDimensions()
|
||||||
{
|
{
|
||||||
int cw, ch;
|
// compute the size of the scrollable area
|
||||||
GetClientSize( &cw, &ch );
|
int w = m_numCols > 0 ? GetColRight(GetColAt(m_numCols - 1)) : 0;
|
||||||
|
int h = m_numRows > 0 ? GetRowBottom(m_numRows - 1) : 0;
|
||||||
|
|
||||||
if ( m_rowLabelWin->IsShown() )
|
w += m_extraWidth;
|
||||||
cw -= m_rowLabelWidth;
|
h += m_extraHeight;
|
||||||
if ( m_colLabelWin->IsShown() )
|
|
||||||
ch -= m_colLabelHeight;
|
|
||||||
|
|
||||||
// grid total size
|
|
||||||
int w = m_numCols > 0 ? GetColRight(GetColAt( m_numCols - 1 )) + m_extraWidth + 1 : 0;
|
|
||||||
int h = m_numRows > 0 ? GetRowBottom(m_numRows - 1) + m_extraHeight + 1 : 0;
|
|
||||||
|
|
||||||
// take into account editor if shown
|
// take into account editor if shown
|
||||||
if ( IsCellEditControlShown() )
|
if ( IsCellEditControlShown() )
|
||||||
@@ -4609,7 +4604,8 @@ void wxGrid::CalcDimensions()
|
|||||||
|
|
||||||
// do set scrollbar parameters
|
// do set scrollbar parameters
|
||||||
SetScrollbars( m_scrollLineX, m_scrollLineY,
|
SetScrollbars( m_scrollLineX, m_scrollLineY,
|
||||||
GetScrollX(w), GetScrollY(h), x, y,
|
GetScrollX(w), GetScrollY(h),
|
||||||
|
x, y,
|
||||||
GetBatchCount() != 0);
|
GetBatchCount() != 0);
|
||||||
|
|
||||||
// if our OnSize() hadn't been called (it would if we have scrollbars), we
|
// if our OnSize() hadn't been called (it would if we have scrollbars), we
|
||||||
@@ -10243,8 +10239,7 @@ void wxGrid::SetRowSize( int row, int height )
|
|||||||
int diff = h - m_rowHeights[row];
|
int diff = h - m_rowHeights[row];
|
||||||
|
|
||||||
m_rowHeights[row] = h;
|
m_rowHeights[row] = h;
|
||||||
int i;
|
for ( int i = row; i < m_numRows; i++ )
|
||||||
for ( i = row; i < m_numRows; i++ )
|
|
||||||
{
|
{
|
||||||
m_rowBottoms[i] += diff;
|
m_rowBottoms[i] += diff;
|
||||||
}
|
}
|
||||||
@@ -10307,12 +10302,9 @@ void wxGrid::SetColSize( int col, int width )
|
|||||||
int diff = w - m_colWidths[col];
|
int diff = w - m_colWidths[col];
|
||||||
m_colWidths[col] = w;
|
m_colWidths[col] = w;
|
||||||
|
|
||||||
int i;
|
for ( int colPos = GetColPos(col); colPos < m_numCols; colPos++ )
|
||||||
int colPos;
|
|
||||||
for ( colPos = GetColPos( col ); colPos < m_numCols; colPos++ )
|
|
||||||
{
|
{
|
||||||
i = GetColAt( colPos );
|
m_colRights[GetColAt(colPos)] += diff;
|
||||||
m_colRights[i] += diff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !GetBatchCount() )
|
if ( !GetBatchCount() )
|
||||||
@@ -10541,21 +10533,17 @@ void wxGrid::AutoSize()
|
|||||||
{
|
{
|
||||||
BeginBatch();
|
BeginBatch();
|
||||||
|
|
||||||
wxSize size(SetOrCalcColumnSizes(false), SetOrCalcRowSizes(false));
|
// we need to round up the size of the scrollable area to a multiple of
|
||||||
|
// scroll step to ensure that we don't get the scrollbars when we're sized
|
||||||
// round up the size to a multiple of scroll step - this ensures that we
|
// exactly to fit our contents
|
||||||
// won't get the scrollbars if we're sized exactly to this width
|
wxSize size(SetOrCalcColumnSizes(false) - m_rowLabelWidth + m_extraWidth,
|
||||||
// CalcDimension adds m_extraWidth + 1 etc. to calculate the necessary
|
SetOrCalcRowSizes(false) - m_colLabelHeight + m_extraHeight);
|
||||||
// scrollbar steps
|
wxSize sizeFit(GetScrollX(size.x) * GetScrollLineX(),
|
||||||
wxSize sizeFit(
|
GetScrollY(size.y) * GetScrollLineY());
|
||||||
GetScrollX(size.x + m_extraWidth + 1) * m_scrollLineX,
|
|
||||||
GetScrollY(size.y + m_extraHeight + 1) * m_scrollLineY );
|
|
||||||
|
|
||||||
// distribute the extra space between the columns/rows to avoid having
|
// distribute the extra space between the columns/rows to avoid having
|
||||||
// extra white space
|
// extra white space
|
||||||
|
wxCoord diff = sizeFit.x - size.x;
|
||||||
// Remove the extra m_extraWidth + 1 added above
|
|
||||||
wxCoord diff = sizeFit.x - size.x + (m_extraWidth + 1);
|
|
||||||
if ( diff && m_numCols )
|
if ( diff && m_numCols )
|
||||||
{
|
{
|
||||||
// try to resize the columns uniformly
|
// try to resize the columns uniformly
|
||||||
@@ -10580,7 +10568,7 @@ void wxGrid::AutoSize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// same for rows
|
// same for rows
|
||||||
diff = sizeFit.y - size.y - (m_extraHeight + 1);
|
diff = sizeFit.y - size.y;
|
||||||
if ( diff && m_numRows )
|
if ( diff && m_numRows )
|
||||||
{
|
{
|
||||||
// try to resize the columns uniformly
|
// try to resize the columns uniformly
|
||||||
@@ -10604,9 +10592,13 @@ void wxGrid::AutoSize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EndBatch();
|
// we know that we're not going to have scrollbars so disable them now to
|
||||||
|
// avoid trouble in SetClientSize() which can otherwise set the correct
|
||||||
|
// client size but also leave space for (not needed any more) scrollbars
|
||||||
|
SetScrollbars(0, 0, 0, 0, 0, true);
|
||||||
|
SetClientSize(sizeFit.x + m_rowLabelWidth, sizeFit.y + m_colLabelHeight);
|
||||||
|
|
||||||
SetClientSize(sizeFit);
|
EndBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGrid::AutoSizeRowLabelSize( int row )
|
void wxGrid::AutoSizeRowLabelSize( int row )
|
||||||
|
Reference in New Issue
Block a user