-////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
// Name: grid.cpp
// Purpose: wxGrid and related classes
// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
bool wxGridTableBase::InsertRows( size_t pos, size_t numRows )
{
- wxLogWarning( "Called grid table class function InsertRows(pos=%d, N=%d)\n"
- "but your derived table class does not override this function",
+ wxLogWarning( wxT("Called grid table class function InsertRows(pos=%d, N=%d)\n"
+ "but your derived table class does not override this function"),
pos, numRows );
return FALSE;
bool wxGridTableBase::AppendRows( size_t numRows )
{
- wxLogWarning( "Called grid table class function AppendRows(N=%d)\n"
- "but your derived table class does not override this function",
+ wxLogWarning( wxT("Called grid table class function AppendRows(N=%d)\n"
+ "but your derived table class does not override this function"),
numRows );
return FALSE;
bool wxGridTableBase::DeleteRows( size_t pos, size_t numRows )
{
- wxLogWarning( "Called grid table class function DeleteRows(pos=%d, N=%d)\n"
- "but your derived table class does not override this function",
+ wxLogWarning( wxT("Called grid table class function DeleteRows(pos=%d, N=%d)\n"
+ "but your derived table class does not override this function"),
pos, numRows );
return FALSE;
bool wxGridTableBase::InsertCols( size_t pos, size_t numCols )
{
- wxLogWarning( "Called grid table class function InsertCols(pos=%d, N=%d)\n"
- "but your derived table class does not override this function",
+ wxLogWarning( wxT("Called grid table class function InsertCols(pos=%d, N=%d)\n"
+ "but your derived table class does not override this function"),
pos, numCols );
return FALSE;
bool wxGridTableBase::AppendCols( size_t numCols )
{
- wxLogWarning( "Called grid table class function AppendCols(N=%d)\n"
- "but your derived table class does not override this function",
+ wxLogWarning( wxT("Called grid table class function AppendCols(N=%d)\n"
+ "but your derived table class does not override this function"),
numCols );
return FALSE;
bool wxGridTableBase::DeleteCols( size_t pos, size_t numCols )
{
- wxLogWarning( "Called grid table class function DeleteCols(pos=%d, N=%d)\n"
- "but your derived table class does not override this function",
+ wxLogWarning( wxT("Called grid table class function DeleteCols(pos=%d, N=%d)\n"
+ "but your derived table class does not override this function"),
pos, numCols );
return FALSE;
// this is a magic incantation which must be done!
-#include <wx/arrimpl.cpp>
+#include "wx/arrimpl.cpp"
WX_DEFINE_OBJARRAY(wxGridStringArray)
if ( pos >= curNumRows )
{
- wxLogError( "Called wxGridStringTable::DeleteRows(pos=%d, N=%d)...\n"
- "Pos value is invalid for present table with %d rows",
+ wxLogError( wxT("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)...\n"
+ "Pos value is invalid for present table with %d rows"),
pos, numRows, curNumRows );
return FALSE;
}
{
// TODO: something better than this ?
//
- wxLogError( "Unable to append cols to a grid table with no rows.\n"
- "Call AppendRows() first" );
+ wxLogError( wxT("Unable to append cols to a grid table with no rows.\n"
+ "Call AppendRows() first") );
return FALSE;
}
if ( pos >= curNumCols )
{
- wxLogError( "Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
- "Pos value is invalid for present table with %d cols",
+ wxLogError( wxT("Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
+ "Pos value is invalid for present table with %d cols"),
pos, numCols, curNumCols );
return FALSE;
}
m_rowHeights.Alloc( m_numRows );
m_rowBottoms.Alloc( m_numRows );
+ m_sumRowHeights = 0;
for ( i = 0; i < m_numRows; i++ )
{
m_rowHeights.Add( m_defaultRowHeight );
m_rowBottoms.Add( 0 ); // set by CalcDimensions()
}
-
+ m_sumRowHeights = m_defaultRowHeight * m_numRows;
+
m_colWidths.Alloc( m_numCols );
m_colRights.Alloc( m_numRows );
+ m_sumColWidths = 0;
for ( i = 0; i < m_numCols; i++ )
{
m_colWidths.Add( m_defaultColWidth );
m_colRights.Add( 0 ); // set by CalcDimensions()
}
-
+ m_sumColWidths = m_defaultColWidth * m_numCols;
+
// TODO: improve this ?
//
m_defaultCellFont = this->GetFont();
m_top = 0;
}
- int bottom = m_top + m_colLabelHeight;
- for ( i = m_scrollPosY; i < m_numRows; i++ )
- {
- bottom += m_rowHeights[i];
- m_rowBottoms[i] = bottom;
- }
-
- int right = m_left + m_rowLabelWidth;
- for ( i = m_scrollPosX; i < m_numCols; i++ )
- {
- right += m_colWidths[i];
- m_colRights[i] = right;
- }
-
- // adjust the scroll bars
+ // check to see if either of the scroll bars are required
//
-
int cw, ch;
GetClientSize(&cw, &ch);
int check;
for ( check = 0; check < 2; check++ )
{
- if ( m_numRows > 0 &&
- m_rowBottoms[m_numRows-1] + horizScrollBarHeight > ch )
+ if ( m_top + m_colLabelHeight + m_sumRowHeights + horizScrollBarHeight > ch )
{
vertScrollBarWidth = m_scrollBarWidth;
+ }
- m_wholeRowsVisible = 0;
- for ( i = m_scrollPosY; i < m_numRows; i++ )
- {
- // A partial row doesn't count, we still have to scroll to
- // see the rest of it
- if ( m_rowBottoms[i] + horizScrollBarHeight > ch ) break;
+ if ( m_left + m_rowLabelWidth + m_sumColWidths + vertScrollBarWidth > cw)
+ {
+ horizScrollBarHeight = m_scrollBarWidth;
+ }
+ }
- m_wholeRowsVisible++ ;
- }
+
+ // if the window has been resized while scrolled then the scroll
+ // position might need to be adjusted...
+ //
+ bool adjustScrollPos = FALSE;
+ if ( !vertScrollBarWidth )
+ {
+ if ( m_scrollPosY )
+ {
+ adjustScrollPos = TRUE;
+ m_scrollPosY = 0;
}
- else
+ }
+ if ( !horizScrollBarHeight )
+ {
+ if ( m_scrollPosX )
{
- m_wholeRowsVisible = m_numRows - m_scrollPosY;
- if ( m_scrollPosY )
- {
- vertScrollBarWidth = m_scrollBarWidth;
- }
+ adjustScrollPos = TRUE;
+ m_scrollPosX = 0;
}
-
+ }
+
+
+ // calculate the coords of row bottom edges and col right edges
+ //
+ int bottom = m_top + m_colLabelHeight;
+ for ( i = m_scrollPosY; i < m_numRows; i++ )
+ {
+ bottom += m_rowHeights[i];
+ m_rowBottoms[i] = bottom;
+ }
- if ( m_numCols &&
- m_colRights[m_numCols-1] + vertScrollBarWidth > cw)
+ int right = m_left + m_rowLabelWidth;
+ for ( i = m_scrollPosX; i < m_numCols; i++ )
+ {
+ right += m_colWidths[i];
+ m_colRights[i] = right;
+ }
+
+
+ // check how many rows and cols are visible
+ //
+ m_wholeRowsVisible = 0;
+ if ( m_numRows > 0 )
+ {
+ for ( i = m_scrollPosY; i < m_numRows; i++ )
{
- horizScrollBarHeight = m_scrollBarWidth;
+ // A partial row doesn't count, we still have to scroll to
+ // see the rest of it
+ if ( m_rowBottoms[i] + horizScrollBarHeight > ch ) break;
- m_wholeColsVisible = 0;
- for ( i = m_scrollPosX; i < m_numCols; i++ )
- {
- // A partial col doesn't count, we still have to scroll to
- // see the rest of it
- if ( m_colRights[i] + vertScrollBarWidth > cw ) break;
-
- m_wholeColsVisible++ ;
- }
+ m_wholeRowsVisible++ ;
}
- else
+ }
+
+ m_wholeColsVisible = 0;
+ if ( m_numCols )
+ {
+ for ( i = m_scrollPosX; i < m_numCols; i++ )
{
- // we can see the right-most column
- //
- m_wholeColsVisible = m_numCols - m_scrollPosX;
- if ( m_scrollPosX )
- {
- horizScrollBarHeight = m_scrollBarWidth;
- }
+ // A partial col doesn't count, we still have to scroll to
+ // see the rest of it
+ if ( m_colRights[i] + vertScrollBarWidth > cw ) break;
+
+ m_wholeColsVisible++ ;
}
}
-
if ( m_vertScrollBar )
{
m_right = wxMin( m_colRights[m_numCols-1],
cw - vertScrollBarWidth );
}
+
+ // if the scroll position was adjusted (due to a window resize)
+ // ensure that the cell highlight and edit control are displayed
+ // correctly
+ //
+ if ( adjustScrollPos ) SelectCell( m_currentCellCoords );
}
{
m_rowHeights.Insert( m_defaultRowHeight, pos );
m_rowBottoms.Insert( 0, pos );
+ m_sumRowHeights += m_defaultRowHeight;
}
m_numRows += numRows;
CalcDimensions();
{
m_rowHeights.Add( m_defaultRowHeight );
m_rowBottoms.Add( 0 );
+ m_sumRowHeights += m_defaultRowHeight;
}
m_numRows += numRows;
CalcDimensions();
int numRows = msg.GetCommandInt2();
for ( i = 0; i < numRows; i++ )
{
+ m_sumRowHeights -= m_rowHeights[ pos ];
m_rowHeights.Remove( pos );
m_rowBottoms.Remove( pos );
}
{
m_colWidths.Insert( m_defaultColWidth, pos );
m_colRights.Insert( 0, pos );
+ m_sumColWidths += m_defaultColWidth;
}
m_numCols += numCols;
CalcDimensions();
{
m_colWidths.Add( m_defaultColWidth );
m_colRights.Add( 0 );
+ m_sumColWidths += m_defaultColWidth;
}
m_numCols += numCols;
CalcDimensions();
int numCols = msg.GetCommandInt2();
for ( i = 0; i < numCols; i++ )
{
+ m_sumColWidths -= m_colWidths[ pos ];
m_colWidths.Remove( pos );
m_colRights.Remove( pos );
}
int top = m_top + m_colLabelHeight;
if ( m_dragRowOrCol > 0 )
top = m_rowBottoms[m_dragRowOrCol-1];
+
+ m_sumRowHeights -= m_rowHeights[ m_dragRowOrCol ];
m_rowHeights[m_dragRowOrCol] = wxMax( ev.GetY() - top,
WXGRID_MIN_ROW_HEIGHT );
+ m_sumRowHeights += m_rowHeights[ m_dragRowOrCol ];
CalcDimensions();
ShowCellEditControl();
Refresh();
int left = m_left + m_rowLabelWidth;
if ( m_dragRowOrCol > 0 )
left = m_colRights[m_dragRowOrCol-1];
+
+ m_sumColWidths -= m_colWidths[m_dragRowOrCol];
m_colWidths[m_dragRowOrCol] = wxMax( ev.GetX() - left,
WXGRID_MIN_COL_WIDTH );
+ m_sumColWidths += m_colWidths[m_dragRowOrCol];
+
CalcDimensions();
ShowCellEditControl();
Refresh();
{
// shouldn't be here - we are going round in circles...
//
- wxLogFatalError( "wxGrid::OnKeyDown called while alread active" );
+ wxLogFatalError( wxT("wxGrid::OnKeyDown called while alread active") );
}
m_inOnKeyDown = TRUE;
// Text updated in an edit control - either a text control or a
// combo box
//
-void wxGrid::OnText( wxKeyEvent& ev )
+void wxGrid::OnText( wxCommandEvent& ev )
{
if ( !m_inOnText )
{
{
if ( m_created )
{
- wxLogError( "wxGrid::CreateGrid(numRows, numCols) called more than once" );
+ wxLogError( wxT("wxGrid::CreateGrid(numRows, numCols) called more than once") );
return FALSE;
}
else
if ( !m_created )
{
- wxLogError( "Called wxGrid::InsertRows() before calling CreateGrid()" );
+ wxLogError( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
return FALSE;
}
if ( !m_created )
{
- wxLogError( "Called wxGrid::AppendRows() before calling CreateGrid()" );
+ wxLogError( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
return FALSE;
}
if ( !m_created )
{
- wxLogError( "Called wxGrid::DeleteRows() before calling CreateGrid()" );
+ wxLogError( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
return FALSE;
}
if ( !m_created )
{
- wxLogError( "Called wxGrid::InsertCols() before calling CreateGrid()" );
+ wxLogError( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
return FALSE;
}
if ( !m_created )
{
- wxLogError( "Called wxGrid::AppendCols() before calling CreateGrid()" );
+ wxLogError( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
return FALSE;
}
if ( !m_created )
{
- wxLogError( "Called wxGrid::DeleteCols() before calling CreateGrid()" );
+ wxLogError( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
return FALSE;
}
{
m_rowHeights[row] = m_defaultRowHeight;
}
+ m_sumRowHeights = m_defaultRowHeight * m_numRows;
CalcDimensions();
if ( !GetBatchCount() ) Refresh();
}
{
if ( row >= 0 && row < m_numRows )
{
+ m_sumRowHeights -= m_rowHeights[row];
m_rowHeights[row] = wxMax( 0, height );
+ m_sumRowHeights += m_rowHeights[row];
CalcDimensions();
if ( !GetBatchCount() ) Refresh();
{
m_colWidths[col] = m_defaultColWidth;
}
+ m_sumColWidths = m_defaultColWidth * m_numCols;
CalcDimensions();
if ( !GetBatchCount() ) Refresh();
}
{
if ( col >= 0 && col < m_numCols )
{
+ m_sumColWidths -= m_colWidths[col];
m_colWidths[col] = wxMax( 0, width );
+ m_sumColWidths += m_colWidths[col];
CalcDimensions();
if ( !GetBatchCount() ) Refresh();