fixed Fit() to avoid showing scrollbars
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13187 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
// Name: generic/grid.cpp
|
// Name: generic/grid.cpp
|
||||||
// Purpose: wxGrid and related classes
|
// Purpose: wxGrid and related classes
|
||||||
// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
|
// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
|
||||||
// Modified by:
|
// Modified by: Robin Dunn, Vadim Zeitlin
|
||||||
// Created: 1/08/1999
|
// Created: 1/08/1999
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Michael Bedward (mbedward@ozemail.com.au)
|
// Copyright: (c) Michael Bedward (mbedward@ozemail.com.au)
|
||||||
@@ -388,13 +388,31 @@ wxRect wxGridNoCellRect( -1, -1, -1, -1 );
|
|||||||
// The scroll bars may be a little flakey once in a while, but that is
|
// The scroll bars may be a little flakey once in a while, but that is
|
||||||
// surely much less horrible than having scroll lines of only 1!!!
|
// surely much less horrible than having scroll lines of only 1!!!
|
||||||
// -- Robin
|
// -- Robin
|
||||||
static const size_t GRID_SCROLL_LINE = 15; // 1;
|
//
|
||||||
|
// Well, it's still seriously broken so it might be better but needs
|
||||||
|
// fixing anyhow
|
||||||
|
// -- Vadim
|
||||||
|
static const size_t GRID_SCROLL_LINE_X = 15; // 1;
|
||||||
|
static const size_t GRID_SCROLL_LINE_Y = GRID_SCROLL_LINE_X;
|
||||||
|
|
||||||
// the size of hash tables used a bit everywhere (the max number of elements
|
// the size of hash tables used a bit everywhere (the max number of elements
|
||||||
// in these hash tables is the number of rows/columns)
|
// in these hash tables is the number of rows/columns)
|
||||||
static const int GRID_HASH_SIZE = 100;
|
static const int GRID_HASH_SIZE = 100;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// private functions
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static inline GetScrollX(int x)
|
||||||
|
{
|
||||||
|
return (x + GRID_SCROLL_LINE_X - 1) / GRID_SCROLL_LINE_X;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline GetScrollY(int y)
|
||||||
|
{
|
||||||
|
return (y + GRID_SCROLL_LINE_Y - 1) / GRID_SCROLL_LINE_Y;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// implementation
|
// implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -3886,32 +3904,34 @@ void wxGrid::CalcDimensions()
|
|||||||
// preserve (more or less) the previous position
|
// preserve (more or less) the previous position
|
||||||
int x, y;
|
int x, y;
|
||||||
GetViewStart( &x, &y );
|
GetViewStart( &x, &y );
|
||||||
// maybe we don't need scrollbars at all? and if we do, transform w and h
|
|
||||||
// from pixels into logical units
|
// maybe we don't need scrollbars at all?
|
||||||
|
//
|
||||||
|
// also adjust the position to be valid for the new scroll rangs
|
||||||
if ( w <= cw )
|
if ( w <= cw )
|
||||||
{
|
{
|
||||||
w = 0; x= 0;
|
w = x = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
w = (w + GRID_SCROLL_LINE - 1)/GRID_SCROLL_LINE;
|
|
||||||
if ( x >= w )
|
if ( x >= w )
|
||||||
x = w - 1;
|
x = w - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( h <= ch )
|
if ( h <= ch )
|
||||||
{
|
{
|
||||||
h = 0; y = 0;
|
h = y = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
h = (h + GRID_SCROLL_LINE - 1)/GRID_SCROLL_LINE;
|
|
||||||
if ( y >= h )
|
if ( y >= h )
|
||||||
y = h - 1;
|
y = h - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do set scrollbar parameters
|
// do set scrollbar parameters
|
||||||
SetScrollbars( GRID_SCROLL_LINE, GRID_SCROLL_LINE,
|
SetScrollbars( GRID_SCROLL_LINE_X, GRID_SCROLL_LINE_Y,
|
||||||
w, h, x, y, (GetBatchCount() != 0));
|
GetScrollX(w), GetScrollY(h), x, y,
|
||||||
|
GetBatchCount() != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5497,66 +5517,62 @@ int wxGrid::SendEvent( const wxEventType type,
|
|||||||
{
|
{
|
||||||
bool claimed;
|
bool claimed;
|
||||||
bool vetoed= FALSE;
|
bool vetoed= FALSE;
|
||||||
|
|
||||||
if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
|
if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
|
||||||
{
|
{
|
||||||
int rowOrCol = (row == -1 ? col : row);
|
int rowOrCol = (row == -1 ? col : row);
|
||||||
|
|
||||||
wxGridSizeEvent gridEvt( GetId(),
|
wxGridSizeEvent gridEvt( GetId(),
|
||||||
type,
|
type,
|
||||||
this,
|
this,
|
||||||
rowOrCol,
|
rowOrCol,
|
||||||
mouseEv.GetX() + GetRowLabelSize(),
|
mouseEv.GetX() + GetRowLabelSize(),
|
||||||
mouseEv.GetY() + GetColLabelSize(),
|
mouseEv.GetY() + GetColLabelSize(),
|
||||||
mouseEv.ControlDown(),
|
mouseEv.ControlDown(),
|
||||||
mouseEv.ShiftDown(),
|
mouseEv.ShiftDown(),
|
||||||
mouseEv.AltDown(),
|
mouseEv.AltDown(),
|
||||||
mouseEv.MetaDown() );
|
mouseEv.MetaDown() );
|
||||||
|
|
||||||
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
||||||
vetoed = !gridEvt.IsAllowed();
|
vetoed = !gridEvt.IsAllowed();
|
||||||
|
}
|
||||||
}
|
|
||||||
else if ( type == wxEVT_GRID_RANGE_SELECT )
|
else if ( type == wxEVT_GRID_RANGE_SELECT )
|
||||||
{
|
{
|
||||||
// Right now, it should _never_ end up here!
|
// Right now, it should _never_ end up here!
|
||||||
wxGridRangeSelectEvent gridEvt( GetId(),
|
wxGridRangeSelectEvent gridEvt( GetId(),
|
||||||
type,
|
type,
|
||||||
this,
|
this,
|
||||||
m_selectingTopLeft,
|
m_selectingTopLeft,
|
||||||
m_selectingBottomRight,
|
m_selectingBottomRight,
|
||||||
TRUE,
|
TRUE,
|
||||||
mouseEv.ControlDown(),
|
mouseEv.ControlDown(),
|
||||||
mouseEv.ShiftDown(),
|
mouseEv.ShiftDown(),
|
||||||
mouseEv.AltDown(),
|
mouseEv.AltDown(),
|
||||||
mouseEv.MetaDown() );
|
mouseEv.MetaDown() );
|
||||||
|
|
||||||
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
||||||
vetoed = !gridEvt.IsAllowed();
|
vetoed = !gridEvt.IsAllowed();
|
||||||
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxGridEvent gridEvt( GetId(),
|
wxGridEvent gridEvt( GetId(),
|
||||||
type,
|
type,
|
||||||
this,
|
this,
|
||||||
row, col,
|
row, col,
|
||||||
mouseEv.GetX() + GetRowLabelSize(),
|
mouseEv.GetX() + GetRowLabelSize(),
|
||||||
mouseEv.GetY() + GetColLabelSize(),
|
mouseEv.GetY() + GetColLabelSize(),
|
||||||
FALSE,
|
FALSE,
|
||||||
mouseEv.ControlDown(),
|
mouseEv.ControlDown(),
|
||||||
mouseEv.ShiftDown(),
|
mouseEv.ShiftDown(),
|
||||||
mouseEv.AltDown(),
|
mouseEv.AltDown(),
|
||||||
mouseEv.MetaDown() );
|
mouseEv.MetaDown() );
|
||||||
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
||||||
vetoed = !gridEvt.IsAllowed();
|
vetoed = !gridEvt.IsAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Veto'd event may not be `claimed' so test this first
|
|
||||||
if (vetoed) return -1;
|
|
||||||
return claimed ? 1 : 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
// A Veto'd event may not be `claimed' so test this first
|
||||||
|
if (vetoed) return -1;
|
||||||
|
return claimed ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5592,10 +5608,9 @@ int wxGrid::SendEvent( const wxEventType type,
|
|||||||
vetoed = !gridEvt.IsAllowed();
|
vetoed = !gridEvt.IsAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Veto'd event may not be `claimed' so test this first
|
// A Veto'd event may not be `claimed' so test this first
|
||||||
if (vetoed) return -1;
|
if (vetoed) return -1;
|
||||||
return claimed ? 1 : 0;
|
return claimed ? 1 : 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5605,14 +5620,14 @@ void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This is just here to make sure that CalcDimensions gets called when
|
void wxGrid::OnSize( wxSizeEvent& event )
|
||||||
// the grid view is resized... then the size event is skipped to allow
|
|
||||||
// the box sizers to handle everything
|
|
||||||
//
|
|
||||||
void wxGrid::OnSize( wxSizeEvent& WXUNUSED(event) )
|
|
||||||
{
|
{
|
||||||
|
// position the child windows
|
||||||
CalcWindowSizes();
|
CalcWindowSizes();
|
||||||
CalcDimensions();
|
|
||||||
|
// don't call CalcDimensions() from here, the base class handles the size
|
||||||
|
// changes itself
|
||||||
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -6647,10 +6662,10 @@ void wxGrid::EnableCellEditControl( bool enable )
|
|||||||
{
|
{
|
||||||
if ( enable )
|
if ( enable )
|
||||||
{
|
{
|
||||||
if (SendEvent( wxEVT_GRID_EDITOR_SHOWN) <0)
|
if (SendEvent( wxEVT_GRID_EDITOR_SHOWN) <0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// this should be checked by the caller!
|
// this should be checked by the caller!
|
||||||
wxASSERT_MSG( CanEnableCellControl(),
|
wxASSERT_MSG( CanEnableCellControl(),
|
||||||
_T("can't enable editing for this cell!") );
|
_T("can't enable editing for this cell!") );
|
||||||
|
|
||||||
@@ -6661,10 +6676,10 @@ void wxGrid::EnableCellEditControl( bool enable )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//FIXME:add veto support
|
//FIXME:add veto support
|
||||||
SendEvent( wxEVT_GRID_EDITOR_HIDDEN);
|
SendEvent( wxEVT_GRID_EDITOR_HIDDEN);
|
||||||
|
|
||||||
HideCellEditControl();
|
HideCellEditControl();
|
||||||
SaveEditControlValue();
|
SaveEditControlValue();
|
||||||
|
|
||||||
// do it after HideCellEditControl()
|
// do it after HideCellEditControl()
|
||||||
@@ -6825,9 +6840,9 @@ void wxGrid::SaveEditControlValue()
|
|||||||
m_currentCellCoords.GetRow(),
|
m_currentCellCoords.GetRow(),
|
||||||
m_currentCellCoords.GetCol() ) < 0 ) {
|
m_currentCellCoords.GetCol() ) < 0 ) {
|
||||||
|
|
||||||
//Event has been veto set the data back.
|
// Event has been vetoed, set the data back.
|
||||||
SetCellValue(row,col,oldval);
|
SetCellValue(row,col,oldval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7031,7 +7046,7 @@ void wxGrid::MakeCellVisible( int row, int col )
|
|||||||
//
|
//
|
||||||
// Sometimes GRID_SCROLL_LINE/2 is not enough, so just add a full
|
// Sometimes GRID_SCROLL_LINE/2 is not enough, so just add a full
|
||||||
// scroll unit...
|
// scroll unit...
|
||||||
ypos += GRID_SCROLL_LINE;
|
ypos += GRID_SCROLL_LINE_Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( left < 0 )
|
if ( left < 0 )
|
||||||
@@ -7053,13 +7068,15 @@ void wxGrid::MakeCellVisible( int row, int col )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// see comment for ypos above
|
// see comment for ypos above
|
||||||
xpos += GRID_SCROLL_LINE;
|
xpos += GRID_SCROLL_LINE_X;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( xpos != -1 || ypos != -1 )
|
if ( xpos != -1 || ypos != -1 )
|
||||||
{
|
{
|
||||||
if ( xpos != -1 ) xpos /= GRID_SCROLL_LINE;
|
if ( xpos != -1 )
|
||||||
if ( ypos != -1 ) ypos /= GRID_SCROLL_LINE;
|
xpos /= GRID_SCROLL_LINE_X;
|
||||||
|
if ( ypos != -1 )
|
||||||
|
ypos /= GRID_SCROLL_LINE_Y;
|
||||||
Scroll( xpos, ypos );
|
Scroll( xpos, ypos );
|
||||||
AdjustScrollbars();
|
AdjustScrollbars();
|
||||||
}
|
}
|
||||||
@@ -8529,6 +8546,7 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
|
|||||||
|
|
||||||
if ( !calcOnly )
|
if ( !calcOnly )
|
||||||
BeginBatch();
|
BeginBatch();
|
||||||
|
|
||||||
for ( int col = 0; col < m_numCols; col++ )
|
for ( int col = 0; col < m_numCols; col++ )
|
||||||
{
|
{
|
||||||
if ( !calcOnly )
|
if ( !calcOnly )
|
||||||
@@ -8538,8 +8556,10 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
|
|||||||
|
|
||||||
width += GetColWidth(col);
|
width += GetColWidth(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !calcOnly )
|
if ( !calcOnly )
|
||||||
EndBatch();
|
EndBatch();
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8549,6 +8569,7 @@ int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin)
|
|||||||
|
|
||||||
if ( !calcOnly )
|
if ( !calcOnly )
|
||||||
BeginBatch();
|
BeginBatch();
|
||||||
|
|
||||||
for ( int row = 0; row < m_numRows; row++ )
|
for ( int row = 0; row < m_numRows; row++ )
|
||||||
{
|
{
|
||||||
if ( !calcOnly )
|
if ( !calcOnly )
|
||||||
@@ -8558,15 +8579,78 @@ int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin)
|
|||||||
|
|
||||||
height += GetRowHeight(row);
|
height += GetRowHeight(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !calcOnly )
|
if ( !calcOnly )
|
||||||
EndBatch();
|
EndBatch();
|
||||||
|
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGrid::AutoSize()
|
void wxGrid::AutoSize()
|
||||||
{
|
{
|
||||||
// set the size too
|
BeginBatch();
|
||||||
SetClientSize(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE));
|
|
||||||
|
wxSize size(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE));
|
||||||
|
|
||||||
|
// round up the size to a multiple of scroll step - this ensures that we
|
||||||
|
// won't get the scrollbars if we're sized exactly to this width
|
||||||
|
wxSize sizeFit(GetScrollX(size.x) * GRID_SCROLL_LINE_X,
|
||||||
|
GetScrollY(size.y) * GRID_SCROLL_LINE_Y);
|
||||||
|
|
||||||
|
// distribute the extra space between teh columns/rows to avoid having
|
||||||
|
// extra white space
|
||||||
|
wxCoord diff = sizeFit.x - size.x;
|
||||||
|
if ( diff )
|
||||||
|
{
|
||||||
|
// try to resize the columns uniformly
|
||||||
|
wxCoord diffPerCol = diff / m_numCols;
|
||||||
|
if ( diffPerCol )
|
||||||
|
{
|
||||||
|
for ( int col = 0; col < m_numCols; col++ )
|
||||||
|
{
|
||||||
|
SetColSize(col, GetColWidth(col) + diffPerCol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add remaining amount to the last columns
|
||||||
|
diff -= diffPerCol * m_numCols;
|
||||||
|
if ( diff )
|
||||||
|
{
|
||||||
|
for ( int col = m_numCols - 1; col >= m_numCols - diff; col-- )
|
||||||
|
{
|
||||||
|
SetColSize(col, GetColWidth(col) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// same for rows
|
||||||
|
diff = sizeFit.y - size.y;
|
||||||
|
if ( diff )
|
||||||
|
{
|
||||||
|
// try to resize the columns uniformly
|
||||||
|
wxCoord diffPerRow = diff / m_numRows;
|
||||||
|
if ( diffPerRow )
|
||||||
|
{
|
||||||
|
for ( int row = 0; row < m_numRows; row++ )
|
||||||
|
{
|
||||||
|
SetRowSize(row, GetRowHeight(row) + diffPerRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add remaining amount to the last rows
|
||||||
|
diff -= diffPerRow * m_numRows;
|
||||||
|
if ( diff )
|
||||||
|
{
|
||||||
|
for ( int row = m_numRows - 1; row >= m_numRows - diff; row-- )
|
||||||
|
{
|
||||||
|
SetRowSize(row, GetRowHeight(row) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EndBatch();
|
||||||
|
|
||||||
|
SetClientSize(sizeFit);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxGrid::DoGetBestSize() const
|
wxSize wxGrid::DoGetBestSize() const
|
||||||
|
Reference in New Issue
Block a user