X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e685e57bbd1eb01843ddda92e5825613be0971ca..1a787c5dc89b1cb6a9ddb4ebef3ad2fb24b49c8c:/src/generic/grid.cpp?ds=sidebyside diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 02484668f6..f473853134 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -1,4 +1,4 @@ -//////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// // Name: grid.cpp // Purpose: wxGrid and related classes // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn) @@ -9,13 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// - -#include "wx/defs.h" - -#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) -#include "gridg.cpp" -#else - #ifdef __GNUG__ #pragma implementation "grid.h" #endif @@ -23,10 +16,16 @@ // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" +#include "wx/defs.h" + #ifdef __BORLANDC__ #pragma hdrstop #endif +#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) +#include "gridg.cpp" +#else + #ifndef WX_PRECOMP #include "wx/utils.h" #include "wx/dcclient.h" @@ -64,55 +63,55 @@ wxGridTableBase::~wxGridTableBase() 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; } @@ -185,9 +184,9 @@ wxGridTableMessage::wxGridTableMessage( wxGridTableBase *table, int id, // this is a magic incantation which must be done! -#include +#include "wx/arrimpl.cpp" -WX_DEFINE_OBJARRAY(wxGridStringArray); +WX_DEFINE_OBJARRAY(wxGridStringArray) IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase ) @@ -200,7 +199,7 @@ wxGridStringTable::wxGridStringTable( int numRows, int numCols ) : wxGridTableBase() { int row, col; - + m_data.Alloc( numRows ); wxArrayString sa; @@ -209,7 +208,7 @@ wxGridStringTable::wxGridStringTable( int numRows, int numCols ) { sa.Add( wxEmptyString ); } - + for ( row = 0; row < numRows; row++ ) { m_data.Add( sa ); @@ -259,7 +258,7 @@ void wxGridStringTable::Clear() { int row, col; int numRows, numCols; - + numRows = m_data.GetCount(); if ( numRows > 0 ) { @@ -282,12 +281,12 @@ bool wxGridStringTable::InsertRows( size_t pos, size_t numRows ) size_t curNumRows = m_data.GetCount(); size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 ); - + if ( pos >= curNumRows ) { return AppendRows( numRows ); } - + wxArrayString sa; sa.Alloc( curNumCols ); for ( col = 0; col < curNumCols; col++ ) @@ -306,7 +305,7 @@ bool wxGridStringTable::InsertRows( size_t pos, size_t numRows ) wxGRIDTABLE_NOTIFY_ROWS_INSERTED, pos, numRows ); - + GetView()->ProcessTableMessage( msg ); } @@ -319,7 +318,7 @@ bool wxGridStringTable::AppendRows( size_t numRows ) size_t curNumRows = m_data.GetCount(); size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 ); - + wxArrayString sa; if ( curNumCols > 0 ) { @@ -329,7 +328,7 @@ bool wxGridStringTable::AppendRows( size_t numRows ) sa.Add( wxEmptyString ); } } - + for ( row = 0; row < numRows; row++ ) { m_data.Add( sa ); @@ -340,11 +339,11 @@ bool wxGridStringTable::AppendRows( size_t numRows ) wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, numRows ); - + GetView()->ProcessTableMessage( msg ); } - return TRUE; + return TRUE; } bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows ) @@ -352,11 +351,11 @@ bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows ) size_t n; size_t curNumRows = m_data.GetCount(); - + 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; } @@ -365,7 +364,7 @@ bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows ) { numRows = curNumRows - pos; } - + if ( numRows >= curNumRows ) { m_data.Empty(); // don't release memory just yet @@ -384,11 +383,11 @@ bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows ) wxGRIDTABLE_NOTIFY_ROWS_DELETED, pos, numRows ); - + GetView()->ProcessTableMessage( msg ); } - return TRUE; + return TRUE; } bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) @@ -397,7 +396,7 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) size_t curNumRows = m_data.GetCount(); size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 ); - + if ( pos >= curNumCols ) { return AppendCols( numCols ); @@ -417,7 +416,7 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) wxGRIDTABLE_NOTIFY_COLS_INSERTED, pos, numCols ); - + GetView()->ProcessTableMessage( msg ); } @@ -433,11 +432,11 @@ bool wxGridStringTable::AppendCols( size_t numCols ) { // 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; } - + for ( row = 0; row < curNumRows; row++ ) { for ( n = 0; n < numCols; n++ ) @@ -451,7 +450,7 @@ bool wxGridStringTable::AppendCols( size_t numCols ) wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_COLS_APPENDED, numCols ); - + GetView()->ProcessTableMessage( msg ); } @@ -464,18 +463,18 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols ) size_t curNumRows = m_data.GetCount(); size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 ); - + if ( pos >= curNumCols ) { - wxLogError( "Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n" - "Pos value is invalid for present table with %d cols", - pos, numCols, curNumCols ); - return FALSE; + 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; } if ( numCols > curNumCols - pos ) { - numCols = curNumCols - pos; + numCols = curNumCols - pos; } for ( row = 0; row < curNumRows; row++ ) @@ -499,11 +498,11 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols ) wxGRIDTABLE_NOTIFY_COLS_DELETED, pos, numCols ); - + GetView()->ProcessTableMessage( msg ); } - return TRUE; + return TRUE; } wxString wxGridStringTable::GetRowLabelValue( int row ) @@ -570,7 +569,7 @@ void wxGridStringTable::SetColLabelValue( int col, const wxString& value ) ////////////////////////////////////////////////////////////////////// IMPLEMENT_DYNAMIC_CLASS( wxGridTextCtrl, wxTextCtrl ) - + BEGIN_EVENT_TABLE( wxGridTextCtrl, wxTextCtrl ) EVT_KEY_DOWN( wxGridTextCtrl::OnKeyDown ) END_EVENT_TABLE() @@ -602,6 +601,8 @@ void wxGridTextCtrl::OnKeyDown( wxKeyEvent& ev ) case WXK_DOWN: case WXK_LEFT: case WXK_RIGHT: + case WXK_PRIOR: + case WXK_NEXT: case WXK_RETURN: if ( m_isCellControl ) { @@ -636,7 +637,7 @@ void wxGridTextCtrl::OnKeyDown( wxKeyEvent& ev ) ev.Skip(); } break; - + default: ev.Skip(); } @@ -653,7 +654,7 @@ void wxGridTextCtrl::SetStartValue( const wxString& s ) IMPLEMENT_DYNAMIC_CLASS( wxGrid, wxPanel ) - + BEGIN_EVENT_TABLE( wxGrid, wxPanel ) EVT_PAINT( wxGrid::OnPaint ) EVT_SIZE( wxGrid::OnSize ) @@ -664,7 +665,7 @@ BEGIN_EVENT_TABLE( wxGrid, wxPanel ) EVT_COMMAND_SCROLL( wxGRID_HORIZSCROLL, wxGrid::OnGridScroll) EVT_COMMAND_SCROLL( wxGRID_VERTSCROLL, wxGrid::OnGridScroll) END_EVENT_TABLE() - + wxGrid::~wxGrid() { @@ -700,14 +701,14 @@ void wxGrid::Init() // m_topEditCtrlEnabled = FALSE; m_topEditCtrl = new wxGridTextCtrl( this, - FALSE, - wxGRID_TOPCTRL, - "", - wxPoint(10, 10), - wxSize(WXGRID_DEFAULT_TOPEDIT_WIDTH, + FALSE, + wxGRID_TOPCTRL, + "", + wxPoint(10, 10), + wxSize(WXGRID_DEFAULT_TOPEDIT_WIDTH, WXGRID_DEFAULT_TOPEDIT_HEIGHT), - wxTE_MULTILINE ); - m_topEditCtrl->Show( FALSE ); + wxTE_MULTILINE ); + m_topEditCtrl->Show( FALSE ); if ( m_numRows <= 0 ) m_numRows = WXGRID_DEFAULT_NUMBER_ROWS; @@ -727,7 +728,7 @@ void wxGrid::Init() // m_labelFont = this->GetFont(); m_labelFont.SetWeight( m_labelFont.GetWeight() + 2 ); - + m_rowLabelHorizAlign = wxLEFT; m_rowLabelVertAlign = wxCENTRE; @@ -739,27 +740,31 @@ void wxGrid::Init() 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_gridLineColour = wxColour( 0, 0, 255 ); m_gridLinesEnabled = TRUE; - + m_scrollBarWidth = WXGRID_DEFAULT_SCROLLBAR_WIDTH; m_horizScrollBar = new wxScrollBar( this, @@ -767,7 +772,7 @@ void wxGrid::Init() wxPoint(0, 0), wxSize(10, 10), wxHORIZONTAL); - + m_vertScrollBar = new wxScrollBar( this, wxGRID_VERTSCROLL, wxPoint(0, 0), @@ -776,12 +781,12 @@ void wxGrid::Init() m_scrollPosX = 0; m_scrollPosY = 0; m_wholeColsVisible = 0; - m_wholeRowsVisible = 0; + m_wholeRowsVisible = 0; m_firstPaint = TRUE; m_inOnKeyDown = FALSE; m_batchCount = 0; - + m_cursorMode = WXGRID_CURSOR_DEFAULT; m_dragLastPos = -1; m_dragRowOrCol = -1; @@ -795,7 +800,7 @@ void wxGrid::Init() m_selectedTopLeft = wxGridNoCellCoords; m_selectedBottomRight = wxGridNoCellCoords; - + m_editable = TRUE; // default for whole grid // TODO: extend this to other types of controls @@ -805,20 +810,20 @@ void wxGrid::Init() wxGRID_CELLCTRL, "", wxPoint(1,1), - wxSize(1,1), - wxNO_BORDER + wxSize(1,1) #ifdef __WXMSW__ - | wxTE_MULTILINE | wxTE_NO_VSCROLL + , wxTE_MULTILINE | wxTE_NO_VSCROLL #endif ); - - m_cellEditCtrl->Show( FALSE ); + + m_cellEditCtrl->Show( FALSE ); m_cellEditCtrlEnabled = TRUE; - m_editCtrlType = wxGRID_TEXTCTRL; - - // Not really needed here, it gets called by OnSize() + m_editCtrlType = wxGRID_TEXTCTRL; + + // This is here in case OnSize does not get called when the grid is + // displayed // - // CalcDimensions(); + CalcDimensions(); } @@ -830,7 +835,7 @@ void wxGrid::CalcDimensions() { int ctrlW, ctrlH; m_topEditCtrl->GetSize( &ctrlW, &ctrlH ); - + m_top = ctrlH + 20; } else @@ -838,23 +843,8 @@ void wxGrid::CalcDimensions() 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); @@ -870,59 +860,85 @@ void wxGrid::CalcDimensions() 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; + } + + int right = m_left + m_rowLabelWidth; + for ( i = m_scrollPosX; i < m_numCols; i++ ) + { + right += m_colWidths[i]; + m_colRights[i] = right; + } - if ( m_numCols && - m_colRights[m_numCols-1] + vertScrollBarWidth > cw) + + // 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 ) { if ( !vertScrollBarWidth ) @@ -937,14 +953,14 @@ void wxGrid::CalcDimensions() wxMax(m_wholeRowsVisible, 1), (m_wholeRowsVisible == 0 ? 1 : m_numRows), wxMax(m_wholeRowsVisible, 1) ); - + m_vertScrollBar->SetSize( cw - m_scrollBarWidth, m_top, m_scrollBarWidth, ch - m_top - horizScrollBarHeight); } } - + if ( m_horizScrollBar ) { if ( !horizScrollBarHeight ) @@ -979,6 +995,12 @@ void wxGrid::CalcDimensions() 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 ); } @@ -996,7 +1018,7 @@ bool wxGrid::IsOnScreen() bool wxGrid::Redimension( wxGridTableMessage& msg ) { int i; - + switch ( msg.GetId() ) { case wxGRIDTABLE_NOTIFY_ROWS_INSERTED: @@ -1007,6 +1029,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) { m_rowHeights.Insert( m_defaultRowHeight, pos ); m_rowBottoms.Insert( 0, pos ); + m_sumRowHeights += m_defaultRowHeight; } m_numRows += numRows; CalcDimensions(); @@ -1020,6 +1043,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) { m_rowHeights.Add( m_defaultRowHeight ); m_rowBottoms.Add( 0 ); + m_sumRowHeights += m_defaultRowHeight; } m_numRows += numRows; CalcDimensions(); @@ -1032,6 +1056,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) int numRows = msg.GetCommandInt2(); for ( i = 0; i < numRows; i++ ) { + m_sumRowHeights -= m_rowHeights[ pos ]; m_rowHeights.Remove( pos ); m_rowBottoms.Remove( pos ); } @@ -1065,6 +1090,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) { m_colWidths.Insert( m_defaultColWidth, pos ); m_colRights.Insert( 0, pos ); + m_sumColWidths += m_defaultColWidth; } m_numCols += numCols; CalcDimensions(); @@ -1078,6 +1104,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) { m_colWidths.Add( m_defaultColWidth ); m_colRights.Add( 0 ); + m_sumColWidths += m_defaultColWidth; } m_numCols += numCols; CalcDimensions(); @@ -1090,6 +1117,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) int numCols = msg.GetCommandInt2(); for ( i = 0; i < numCols; i++ ) { + m_sumColWidths -= m_colWidths[ pos ]; m_colWidths.Remove( pos ); m_colRights.Remove( pos ); } @@ -1106,7 +1134,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) m_numRows = 0; m_rowHeights.Clear(); m_rowBottoms.Clear(); -#endif +#endif m_currentCellCoords = wxGridNoCellCoords; } else if ( m_currentCellCoords.GetCol() >= m_numCols ) @@ -1126,57 +1154,57 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) // ----- event handlers // -// Generate a grid event based on a mouse event and +// Generate a grid event based on a mouse event and // return the result of ProcessEvent() // bool wxGrid::SendEvent( const wxEventType type, - int row, int col, - wxMouseEvent& mouseEv ) + int row, int col, + wxMouseEvent& mouseEv ) { - if ( type == EVT_WXGRID_ROW_SIZE || - type == EVT_WXGRID_COL_SIZE ) + if ( type == EVT_GRID_ROW_SIZE || + type == EVT_GRID_COL_SIZE ) { - int rowOrCol = (row == -1 ? col : row); + int rowOrCol = (row == -1 ? col : row); - wxGridSizeEvent gridEvt( GetId(), - type, - this, - rowOrCol, - mouseEv.GetX(), mouseEv.GetY(), - mouseEv.ControlDown(), - mouseEv.ShiftDown(), - mouseEv.AltDown(), - mouseEv.MetaDown() ); + wxGridSizeEvent gridEvt( GetId(), + type, + this, + rowOrCol, + mouseEv.GetX(), mouseEv.GetY(), + mouseEv.ControlDown(), + mouseEv.ShiftDown(), + mouseEv.AltDown(), + mouseEv.MetaDown() ); - return GetEventHandler()->ProcessEvent(gridEvt); + return GetEventHandler()->ProcessEvent(gridEvt); } - else if ( type == EVT_WXGRID_RANGE_SELECT ) + else if ( type == EVT_GRID_RANGE_SELECT ) { - wxGridRangeSelectEvent gridEvt( GetId(), - type, - this, - m_selectedTopLeft, - m_selectedBottomRight, - mouseEv.ControlDown(), - mouseEv.ShiftDown(), - mouseEv.AltDown(), - mouseEv.MetaDown() ); + wxGridRangeSelectEvent gridEvt( GetId(), + type, + this, + m_selectedTopLeft, + m_selectedBottomRight, + mouseEv.ControlDown(), + mouseEv.ShiftDown(), + mouseEv.AltDown(), + mouseEv.MetaDown() ); - return GetEventHandler()->ProcessEvent(gridEvt); + return GetEventHandler()->ProcessEvent(gridEvt); } else { - wxGridEvent gridEvt( GetId(), - type, - this, - row, col, - mouseEv.GetX(), mouseEv.GetY(), - mouseEv.ControlDown(), - mouseEv.ShiftDown(), - mouseEv.AltDown(), - mouseEv.MetaDown() ); + wxGridEvent gridEvt( GetId(), + type, + this, + row, col, + mouseEv.GetX(), mouseEv.GetY(), + mouseEv.ControlDown(), + mouseEv.ShiftDown(), + mouseEv.AltDown(), + mouseEv.MetaDown() ); - return GetEventHandler()->ProcessEvent(gridEvt); + return GetEventHandler()->ProcessEvent(gridEvt); } } @@ -1185,33 +1213,33 @@ bool wxGrid::SendEvent( const wxEventType type, // of ProcessEvent(). // bool wxGrid::SendEvent( const wxEventType type, - int row, int col ) + int row, int col ) { - if ( type == EVT_WXGRID_ROW_SIZE || - type == EVT_WXGRID_COL_SIZE ) + if ( type == EVT_GRID_ROW_SIZE || + type == EVT_GRID_COL_SIZE ) { - int rowOrCol = (row == -1 ? col : row); + int rowOrCol = (row == -1 ? col : row); - wxGridSizeEvent gridEvt( GetId(), - type, - this, - rowOrCol ); + wxGridSizeEvent gridEvt( GetId(), + type, + this, + rowOrCol ); - return GetEventHandler()->ProcessEvent(gridEvt); + return GetEventHandler()->ProcessEvent(gridEvt); } else { - wxGridEvent gridEvt( GetId(), - type, - this, - row, col ); + wxGridEvent gridEvt( GetId(), + type, + this, + row, col ); - return GetEventHandler()->ProcessEvent(gridEvt); + return GetEventHandler()->ProcessEvent(gridEvt); } } -void wxGrid::OnPaint( wxPaintEvent& ev ) +void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(ev) ) { wxPaintDC dc( this ); @@ -1230,9 +1258,9 @@ void wxGrid::OnPaint( wxPaintEvent& ev ) int cw, ch; GetClientSize( &cw, &ch ); dc.SetClippingRegion( 0, 0, cw - vs, ch - hs ); - + HideCurrentCellHighlight( dc ); - + DrawLabelAreas( dc ); DrawColLabels( dc ); DrawRowLabels( dc ); @@ -1246,7 +1274,7 @@ void wxGrid::OnPaint( wxPaintEvent& ev ) { if ( m_currentCellCoords == wxGridNoCellCoords ) m_currentCellCoords.Set(0, 0); - + SetEditControlValue(); ShowCellEditControl(); m_firstPaint = FALSE; @@ -1259,9 +1287,9 @@ void wxGrid::OnPaint( wxPaintEvent& ev ) } -void wxGrid::OnSize( wxSizeEvent& ev ) +void wxGrid::OnSize( wxSizeEvent& WXUNUSED(ev) ) { - CalcDimensions(); + if ( m_created ) CalcDimensions(); } @@ -1270,7 +1298,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) int x = ev.GetX(); int y = ev.GetY(); int row, col; - + // ------------------------------------------------------------ // // Mouse dragging @@ -1278,7 +1306,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) if ( ev.Dragging() ) { m_isDragging = TRUE; - + if ( ev.LeftIsDown() ) { switch( m_cursorMode ) @@ -1291,12 +1319,32 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) { if ( !IsSelection() ) { - SelectBlock( cellCoords, cellCoords ); - } - else if ( !IsInSelection( cellCoords ) ) - { - SelectBlock( m_currentCellCoords, cellCoords ); - } + SelectBlock( cellCoords, cellCoords ); + } + else + { + // check for the mouse being outside the cell area + // (we still want to let the user grow the selected block) + // + if ( cellCoords.GetCol() == -1 ) + { + if ( x >= m_right ) + cellCoords.SetCol( m_numCols-1 ); + else + cellCoords.SetCol( m_scrollPosX ); + } + + if ( cellCoords.GetRow() == -1 ) + { + if ( y >= m_bottom ) + cellCoords.SetRow( m_numRows-1 ); + else + cellCoords.SetRow( m_scrollPosY ); + } + + if ( !IsInSelection( cellCoords ) ) + SelectBlock( m_currentCellCoords, cellCoords ); + } } } break; @@ -1312,11 +1360,11 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) } dc.DrawLine( m_left, ev.GetY(), m_right, ev.GetY()); - + m_dragLastPos = ev.GetY(); } break; - + case WXGRID_CURSOR_RESIZE_COL: { wxClientDC dc(this); @@ -1328,7 +1376,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) } dc.DrawLine( ev.GetX(), m_top, ev.GetX(), m_bottom ); - + m_dragLastPos = ev.GetX(); } break; @@ -1358,7 +1406,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) } m_isDragging = FALSE; - + // ------------------------------------------------------------ // // Left mouse button down @@ -1368,7 +1416,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) row = -1; col = -1; wxGridCellCoords cellCoords; - + switch( XYToArea( x, y ) ) { case WXGRID_ROWLABEL: @@ -1380,7 +1428,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) if ( YToEdgeOfRow(y) < 0 ) { row = YToRow(y); - if ( !SendEvent( EVT_WXGRID_LABEL_LEFT_CLICK, row, col, ev ) ) + if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, col, ev ) ) { SelectRow( row, ev.ShiftDown() ); m_cursorMode = WXGRID_CURSOR_SELECT_ROW; @@ -1398,7 +1446,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) if ( XToEdgeOfCol(x) < 0 ) { col = XToCol(x); - if ( !SendEvent( EVT_WXGRID_LABEL_LEFT_CLICK, row, col, ev ) ) + if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, col, ev ) ) { SelectCol( col, ev.ShiftDown() ); m_cursorMode = WXGRID_CURSOR_SELECT_COL; @@ -1411,7 +1459,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) { // leave both row and col as -1 // - if ( !SendEvent( EVT_WXGRID_LABEL_LEFT_CLICK, row, col, ev ) ) + if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, col, ev ) ) { SelectAll(); } @@ -1421,7 +1469,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) case WXGRID_CELL: { XYToCell( x, y, cellCoords ); - if ( !SendEvent( EVT_WXGRID_CELL_LEFT_CLICK, + if ( !SendEvent( EVT_GRID_CELL_LEFT_CLICK, cellCoords.GetRow(), cellCoords.GetCol(), ev ) ) @@ -1433,9 +1481,9 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) break; default: -#if 0 +#if 0 wxLogMessage( "outside grid area" ); -#endif +#endif break; } } @@ -1448,7 +1496,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) row = -1; col = -1; wxGridCellCoords cellCoords; - + switch( XYToArea( x, y ) ) { case WXGRID_ROWLABEL: @@ -1460,7 +1508,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) if ( YToEdgeOfRow(y) < 0 ) { row = YToRow(y); - SendEvent( EVT_WXGRID_LABEL_LEFT_DCLICK, row, col, ev ); + SendEvent( EVT_GRID_LABEL_LEFT_DCLICK, row, col, ev ); } } break; @@ -1474,7 +1522,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) if ( XToEdgeOfCol(x) < 0 ) { col = XToCol(x); - SendEvent( EVT_WXGRID_LABEL_LEFT_DCLICK, row, col, ev ); + SendEvent( EVT_GRID_LABEL_LEFT_DCLICK, row, col, ev ); } } break; @@ -1483,14 +1531,14 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) { // leave both row and col as -1 // - SendEvent( EVT_WXGRID_LABEL_LEFT_DCLICK, row, col, ev ); + SendEvent( EVT_GRID_LABEL_LEFT_DCLICK, row, col, ev ); } break; case WXGRID_CELL: { XYToCell( x, y, cellCoords ); - SendEvent( EVT_WXGRID_CELL_LEFT_DCLICK, + SendEvent( EVT_GRID_CELL_LEFT_DCLICK, cellCoords.GetRow(), cellCoords.GetCol(), ev ); @@ -1498,9 +1546,9 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) break; default: -#if 0 +#if 0 wxLogMessage( "outside grid area" ); -#endif +#endif break; } } @@ -1510,78 +1558,85 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) // else if ( ev.LeftUp() ) { - switch ( m_cursorMode ) - { - case WXGRID_CURSOR_RESIZE_ROW: - { - if ( m_dragLastPos >= 0 ) - { - // erase the last line and resize the row - // - wxClientDC dc( this ); - dc.SetLogicalFunction( wxINVERT ); - dc.DrawLine( m_left, m_dragLastPos, - m_right, m_dragLastPos ); - HideCellEditControl(); - int top = m_top + m_colLabelHeight; - if ( m_dragRowOrCol > 0 ) - top = m_rowBottoms[m_dragRowOrCol-1]; - m_rowHeights[m_dragRowOrCol] = wxMax( ev.GetY() - top, - WXGRID_MIN_ROW_HEIGHT ); - CalcDimensions(); - ShowCellEditControl(); - Refresh(); - - // Note: we are ending the event *after* doing - // default processing in this case - // - SendEvent( EVT_WXGRID_ROW_SIZE, m_dragRowOrCol, -1, ev ); - } - } - break; - - case WXGRID_CURSOR_RESIZE_COL: - { - if ( m_dragLastPos >= 0 ) - { - // erase the last line and resize the col - // - wxClientDC dc( this ); - dc.SetLogicalFunction( wxINVERT ); - dc.DrawLine( m_left, m_dragLastPos, - m_right, m_dragLastPos ); - HideCellEditControl(); - int left = m_left + m_rowLabelWidth; - if ( m_dragRowOrCol > 0 ) - left = m_colRights[m_dragRowOrCol-1]; - m_colWidths[m_dragRowOrCol] = wxMax( ev.GetX() - left, - WXGRID_MIN_COL_WIDTH ); - CalcDimensions(); - ShowCellEditControl(); - Refresh(); - - // Note: we are ending the event *after* doing - // default processing in this case - // - SendEvent( EVT_WXGRID_COL_SIZE, -1, m_dragRowOrCol, ev ); - } - } - break; - - case WXGRID_CURSOR_SELECT_CELL: - { - if ( IsSelection() ) - { - // Note: we are ending the event *after* doing - // default processing in this case - // - SendEvent( EVT_WXGRID_RANGE_SELECT, -1, -1, ev ); - } - } - break; - } - - m_dragLastPos = -1; + switch ( m_cursorMode ) + { + case WXGRID_CURSOR_RESIZE_ROW: + { + if ( m_dragLastPos >= 0 ) + { + // erase the last line and resize the row + // + wxClientDC dc( this ); + dc.SetLogicalFunction( wxINVERT ); + dc.DrawLine( m_left, m_dragLastPos, + m_right, m_dragLastPos ); + HideCellEditControl(); + 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(); + + // Note: we are ending the event *after* doing + // default processing in this case + // + SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, ev ); + } + } + break; + + case WXGRID_CURSOR_RESIZE_COL: + { + if ( m_dragLastPos >= 0 ) + { + // erase the last line and resize the col + // + wxClientDC dc( this ); + dc.SetLogicalFunction( wxINVERT ); + dc.DrawLine( m_left, m_dragLastPos, + m_right, m_dragLastPos ); + HideCellEditControl(); + 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(); + + // Note: we are ending the event *after* doing + // default processing in this case + // + SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, ev ); + } + } + break; + + case WXGRID_CURSOR_SELECT_CELL: + { + if ( IsSelection() ) + { + // Note: we are ending the event *after* doing + // default processing in this case + // + SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, ev ); + } + } + break; + } + + m_dragLastPos = -1; } // ------------------------------------------------------------ // @@ -1589,18 +1644,18 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) // else if ( ev.RightDown() ) { - row = -1; - col = -1; - wxGridCellCoords cellCoords; - - switch( XYToArea( x, y ) ) - { - - case WXGRID_ROWLABEL: - { - row = YToRow(y); - if ( !SendEvent( EVT_WXGRID_LABEL_RIGHT_CLICK, row, col, ev ) ) - { + row = -1; + col = -1; + wxGridCellCoords cellCoords; + + switch( XYToArea( x, y ) ) + { + + case WXGRID_ROWLABEL: + { + row = YToRow(y); + if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) ) + { // TODO: default processing ? } } @@ -1609,7 +1664,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) case WXGRID_COLLABEL: { col = XToCol(x); - if ( !SendEvent( EVT_WXGRID_LABEL_RIGHT_CLICK, row, col, ev ) ) + if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) ) { // TODO: default processing ? } @@ -1620,7 +1675,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) { // leave both row and col as -1 // - if ( !SendEvent( EVT_WXGRID_LABEL_RIGHT_CLICK, row, col, ev ) ) + if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) ) { // TODO: default processing ? } @@ -1630,7 +1685,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) case WXGRID_CELL: { XYToCell( x, y, cellCoords ); - if ( !SendEvent( EVT_WXGRID_CELL_RIGHT_CLICK, + if ( !SendEvent( EVT_GRID_CELL_RIGHT_CLICK, cellCoords.GetRow(), cellCoords.GetCol(), ev ) ) @@ -1641,9 +1696,9 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) break; default: -#if 0 +#if 0 wxLogMessage( "outside grid area" ); -#endif +#endif break; } } @@ -1653,24 +1708,24 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) // else if ( ev.RightDClick() ) { - row = -1; - col = -1; - wxGridCellCoords cellCoords; - - switch( XYToArea( x, y ) ) - { - - case WXGRID_ROWLABEL: - { - row = YToRow(y); - SendEvent( EVT_WXGRID_LABEL_RIGHT_DCLICK, row, col, ev ); + row = -1; + col = -1; + wxGridCellCoords cellCoords; + + switch( XYToArea( x, y ) ) + { + + case WXGRID_ROWLABEL: + { + row = YToRow(y); + SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev ); } break; case WXGRID_COLLABEL: { col = XToCol(x); - SendEvent( EVT_WXGRID_LABEL_RIGHT_DCLICK, row, col, ev ); + SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev ); } break; @@ -1678,14 +1733,14 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) { // leave both row and col as -1 // - SendEvent( EVT_WXGRID_LABEL_RIGHT_DCLICK, row, col, ev ); + SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev ); } break; case WXGRID_CELL: { XYToCell( x, y, cellCoords ); - SendEvent( EVT_WXGRID_CELL_RIGHT_DCLICK, + SendEvent( EVT_GRID_CELL_RIGHT_DCLICK, cellCoords.GetRow(), cellCoords.GetCol(), ev ); @@ -1693,9 +1748,9 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) break; default: -#if 0 +#if 0 wxLogMessage( "outside grid area" ); -#endif +#endif break; } } @@ -1760,7 +1815,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) } } break; - } + } } } @@ -1771,17 +1826,17 @@ void wxGrid::OnKeyDown( wxKeyEvent& ev ) { // 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; - + // propagate the event up and see if it gets processed // wxWindow *parent = GetParent(); wxKeyEvent keyEvt( ev ); keyEvt.SetEventObject( parent ); - + if ( !parent->GetEventHandler()->ProcessEvent( keyEvt ) ) { // try local handlers @@ -1798,7 +1853,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& ev ) MoveCursorUp(); } break; - + case WXK_DOWN: if ( ev.ControlDown() ) { @@ -1847,7 +1902,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& ev ) ev.Skip(); } break; - + case WXK_END: if ( ev.ControlDown() ) { @@ -1859,7 +1914,15 @@ void wxGrid::OnKeyDown( wxKeyEvent& ev ) ev.Skip(); } break; - + + case WXK_PRIOR: + MovePageUp(); + break; + + case WXK_NEXT: + MovePageDown(); + break; + default: // now try the cell edit control // @@ -1879,7 +1942,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& ev ) // 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 ) { @@ -1897,27 +1960,45 @@ void wxGrid::OnText( wxKeyEvent& ev ) ((wxTextCtrl *)m_topEditCtrl)-> SetValue(((wxTextCtrl *)ctrl)->GetValue()); break; - + case wxGRID_COMBOBOX: ((wxComboBox *)m_topEditCtrl)-> SetValue(((wxComboBox *)ctrl)->GetValue()); break; } } - else if ( ctrl == m_topEditCtrl && - IsCellEditControlEnabled() ) + else if ( ctrl == m_topEditCtrl ) { - switch ( m_editCtrlType ) + if ( IsCellEditControlEnabled() ) { - case wxGRID_TEXTCTRL: - ((wxTextCtrl *)m_cellEditCtrl)-> - SetValue(((wxTextCtrl *)ctrl)->GetValue()); - break; - - case wxGRID_COMBOBOX: - ((wxComboBox *)m_cellEditCtrl)-> - SetValue(((wxComboBox *)ctrl)->GetValue()); - break; + switch ( m_editCtrlType ) + { + case wxGRID_TEXTCTRL: + ((wxTextCtrl *)m_cellEditCtrl)-> + SetValue(((wxTextCtrl *)ctrl)->GetValue()); + break; + + case wxGRID_COMBOBOX: + ((wxComboBox *)m_cellEditCtrl)-> + SetValue(((wxComboBox *)ctrl)->GetValue()); + break; + } + } + else + { + // in the case when in-place editing is turned off we just want to + // echo the text changes in the cell but not yet update the grid table + // + switch ( m_editCtrlType ) + { + case wxGRID_TEXTCTRL: + DrawCellValue( m_currentCellCoords, ((wxTextCtrl *)ctrl)->GetValue() ); + break; + + case wxGRID_COMBOBOX: + DrawCellValue( m_currentCellCoords, ((wxComboBox *)ctrl)->GetValue() ); + break; + } } } } @@ -1932,7 +2013,7 @@ void wxGrid::OnGridScroll( wxScrollEvent& ev ) wxWindow *parent = GetParent(); wxScrollEvent scrollEvt( ev ); if (parent->GetEventHandler()->ProcessEvent( scrollEvt )) return; - + HideCellEditControl(); if ( ev.GetEventObject() == m_horizScrollBar ) @@ -1956,6 +2037,12 @@ void wxGrid::OnGridScroll( wxScrollEvent& ev ) void wxGrid::SelectCell( const wxGridCellCoords& coords ) { + if ( SendEvent( EVT_GRID_SELECT_CELL, coords.GetRow(), coords.GetCol() ) ) + { + // the event has been intercepted - do nothing + return; + } + wxClientDC dc( this ); if ( m_currentCellCoords != wxGridNoCellCoords ) @@ -1985,8 +2072,8 @@ void wxGrid::SelectCell( const wxGridCellCoords& coords ) void wxGrid::ShowCellEditControl() { wxRect rect; - - if ( IsCellEditControlEnabled() ) + + if ( IsCellEditControlEnabled() ) { if ( !IsVisible( m_currentCellCoords ) ) { @@ -1995,7 +2082,7 @@ void wxGrid::ShowCellEditControl() else { rect = CellToRect( m_currentCellCoords ); - + m_cellEditCtrl->SetSize( rect ); m_cellEditCtrl->Show( TRUE ); @@ -2014,7 +2101,7 @@ void wxGrid::ShowCellEditControl() // TODO: anything ??? // break; - + case wxGRID_COMBOBOX: // TODO: anything ??? // @@ -2040,7 +2127,10 @@ void wxGrid::SetEditControlValue( const wxString& value ) if ( m_table ) { wxString s; - s = ( value == wxEmptyString ? GetCellValue(m_currentCellCoords) : value ); + if ( !value ) + s = GetCellValue(m_currentCellCoords); + else + s = value; if ( IsTopEditControlEnabled() ) { @@ -2059,7 +2149,7 @@ void wxGrid::SetEditControlValue( const wxString& value ) // TODO: implement this // break; - + case wxGRID_COMBOBOX: // TODO: implement this // @@ -2084,7 +2174,7 @@ void wxGrid::SetEditControlValue( const wxString& value ) // TODO: implement this // break; - + case wxGRID_COMBOBOX: // TODO: implement this // @@ -2098,7 +2188,7 @@ void wxGrid::SaveEditControlValue() { if ( m_table ) { - wxWindow *ctrl = (wxWindow *)NULL; + wxWindow *ctrl = (wxWindow *)NULL; if ( IsCellEditControlEnabled() ) { @@ -2112,9 +2202,9 @@ void wxGrid::SaveEditControlValue() { return; } - + bool valueChanged = FALSE; - + switch ( m_editCtrlType ) { case wxGRID_TEXTCTRL: @@ -2133,16 +2223,16 @@ void wxGrid::SaveEditControlValue() // TODO: implement this // break; - + case wxGRID_COMBOBOX: // TODO: implement this // break; } - + if ( valueChanged ) { - SendEvent( EVT_WXGRID_CELL_CHANGE, + SendEvent( EVT_GRID_CELL_CHANGE, m_currentCellCoords.GetRow(), m_currentCellCoords.GetCol() ); } @@ -2190,7 +2280,7 @@ void wxGrid::XYToCell( int x, int y, wxGridCellCoords& coords ) int wxGrid::YToRow( int y ) { int i; - + if ( y > m_top + m_colLabelHeight ) { for ( i = m_scrollPosY; i < m_numRows; i++ ) @@ -2209,7 +2299,7 @@ int wxGrid::YToRow( int y ) int wxGrid::XToCol( int x ) { int i; - + if ( x > m_left + m_rowLabelWidth ) { for ( i = m_scrollPosX; i < m_numCols; i++ ) @@ -2231,7 +2321,7 @@ int wxGrid::XToCol( int x ) int wxGrid::YToEdgeOfRow( int y ) { int i, d; - + if ( y > m_top + m_colLabelHeight ) { for ( i = m_scrollPosY; i < m_numRows; i++ ) @@ -2247,7 +2337,7 @@ int wxGrid::YToEdgeOfRow( int y ) } return -1; - + } @@ -2257,7 +2347,7 @@ int wxGrid::YToEdgeOfRow( int y ) int wxGrid::XToEdgeOfCol( int x ) { int i, d; - + if ( x > m_left + m_rowLabelWidth ) { for ( i = m_scrollPosX; i < m_numCols; i++ ) @@ -2273,7 +2363,7 @@ int wxGrid::XToEdgeOfCol( int x ) } return -1; - + } @@ -2290,7 +2380,7 @@ wxRect wxGrid::CellToRect( int row, int col ) } return rect; -} +} bool wxGrid::MoveCursorUp() @@ -2322,7 +2412,7 @@ bool wxGrid::MoveCursorDown() if ( !IsVisible( m_currentCellCoords ) ) MakeCellVisible( m_currentCellCoords ); - + return TRUE; } @@ -2339,7 +2429,7 @@ bool wxGrid::MoveCursorLeft() if ( !IsVisible( m_currentCellCoords ) ) MakeCellVisible( m_currentCellCoords ); - + return TRUE; } @@ -2356,7 +2446,55 @@ bool wxGrid::MoveCursorRight() if ( !IsVisible( m_currentCellCoords ) ) MakeCellVisible( m_currentCellCoords ); - + + return TRUE; + } + + return FALSE; +} + +bool wxGrid::MovePageUp() +{ + if ( m_currentCellCoords != wxGridNoCellCoords && + m_scrollPosY > 0 ) + { + int row = m_currentCellCoords.GetRow(); + int y = m_rowBottoms[ row ] - m_rowHeights[ row ]; + while ( row > 0 ) + { + if ( y + m_rowHeights[row-1] > m_bottom ) break; + y += m_rowHeights[ --row ]; + } + SetVerticalScrollPos( row ); + + SelectCell( row, m_currentCellCoords.GetCol() ); + return TRUE; + } + + return FALSE; +} + +bool wxGrid::MovePageDown() +{ + if ( m_currentCellCoords != wxGridNoCellCoords && + m_scrollPosY + m_wholeRowsVisible < m_numRows ) + { + if ( m_wholeRowsVisible > 0 ) + { + SetVerticalScrollPos( m_scrollPosY + m_wholeRowsVisible ); + } + else if ( m_scrollPosY < m_numRows - 1 ) + { + SetVerticalScrollPos( m_scrollPosY + 1 ); + } + else + { + return FALSE; + } + + // m_scrollPosY will have been updated + // + SelectCell( m_scrollPosY, m_currentCellCoords.GetCol() ); return TRUE; } @@ -2371,7 +2509,7 @@ bool wxGrid::MoveCursorUpBlock() { int row = m_currentCellCoords.GetRow(); int col = m_currentCellCoords.GetCol(); - + if ( m_table->IsEmptyCell(row, col) ) { // starting in an empty cell: find the next block of @@ -2408,7 +2546,7 @@ bool wxGrid::MoveCursorUpBlock() } } } - + SelectCell( row, col ); if ( !IsVisible( m_currentCellCoords ) ) @@ -2428,7 +2566,7 @@ bool wxGrid::MoveCursorDownBlock() { int row = m_currentCellCoords.GetRow(); int col = m_currentCellCoords.GetCol(); - + if ( m_table->IsEmptyCell(row, col) ) { // starting in an empty cell: find the next block of @@ -2465,7 +2603,7 @@ bool wxGrid::MoveCursorDownBlock() } } } - + SelectCell( row, col ); if ( !IsVisible( m_currentCellCoords ) ) @@ -2485,7 +2623,7 @@ bool wxGrid::MoveCursorLeftBlock() { int row = m_currentCellCoords.GetRow(); int col = m_currentCellCoords.GetCol(); - + if ( m_table->IsEmptyCell(row, col) ) { // starting in an empty cell: find the next block of @@ -2522,7 +2660,7 @@ bool wxGrid::MoveCursorLeftBlock() } } } - + SelectCell( row, col ); if ( !IsVisible( m_currentCellCoords ) ) @@ -2542,7 +2680,7 @@ bool wxGrid::MoveCursorRightBlock() { int row = m_currentCellCoords.GetRow(); int col = m_currentCellCoords.GetCol(); - + if ( m_table->IsEmptyCell(row, col) ) { // starting in an empty cell: find the next block of @@ -2579,7 +2717,7 @@ bool wxGrid::MoveCursorRightBlock() } } } - + SelectCell( row, col ); if ( !IsVisible( m_currentCellCoords ) ) @@ -2604,10 +2742,10 @@ void wxGrid::DrawLabelAreas( wxDC& dc ) dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush( wxBrush(GetLabelBackgroundColour(), wxSOLID) ); - + dc.DrawRectangle( m_left, m_top, cw - m_left, m_colLabelHeight ); - + dc.DrawRectangle( m_left, m_top, m_rowLabelWidth, ch - m_top ); } @@ -2628,7 +2766,7 @@ void wxGrid::DrawColLabels( wxDC& dc ) int labelLeft = m_left + m_rowLabelWidth; int i; - + for ( i = m_scrollPosX; i < m_numCols; i++ ) { if ( labelLeft > cw) break; @@ -2636,7 +2774,7 @@ void wxGrid::DrawColLabels( wxDC& dc ) rect.x = 1 + labelLeft; rect.width = m_colWidths[i]; DrawColLabel( dc, rect, i ); - + labelLeft += m_colWidths[i]; } } @@ -2651,7 +2789,7 @@ void wxGrid::DrawColLabelBorders( wxDC& dc ) GetClientSize( &cw, &ch ); dc.SetPen( *wxBLACK_PEN ); - + // horizontal lines // dc.DrawLine( m_left, m_top, cw, m_top ); @@ -2686,7 +2824,7 @@ void wxGrid::DrawColLabelBorders( wxDC& dc ) dc.DrawLine(colLeft + 1, m_top + 1, colLeft + 1, m_top + m_colLabelHeight); - + colLeft += m_colWidths[i]; } } @@ -2700,12 +2838,12 @@ void wxGrid::DrawColLabel( wxDC& dc, const wxRect& rect, int col ) rect2.y += 2; rect2.width -= 5; rect2.height -= 4; - + dc.SetBackgroundMode( wxTRANSPARENT ); dc.SetTextBackground( GetLabelBackgroundColour() ); dc.SetTextForeground( GetLabelTextColour() ); dc.SetFont( GetLabelFont() ); - + int hAlign, vAlign; GetColLabelAlignment( &hAlign, &vAlign ); DrawTextRectangle( dc, GetColLabelValue( col ), rect2, hAlign, vAlign ); @@ -2727,7 +2865,7 @@ void wxGrid::DrawRowLabels( wxDC& dc ) int labelTop = m_top + m_colLabelHeight; int i; - + for ( i = m_scrollPosY; i < m_numRows; i++ ) { if ( labelTop > ch ) break; @@ -2735,7 +2873,7 @@ void wxGrid::DrawRowLabels( wxDC& dc ) rect.y = 1 + labelTop; rect.height = m_rowHeights[i]; DrawRowLabel( dc, rect, i ); - + labelTop += m_rowHeights[i]; } } @@ -2750,7 +2888,7 @@ void wxGrid::DrawRowLabelBorders( wxDC& dc ) GetClientSize( &cw, &ch ); dc.SetPen( *wxBLACK_PEN ); - + // vertical lines // dc.DrawLine( m_left, m_top, m_left, ch ); @@ -2785,7 +2923,7 @@ void wxGrid::DrawRowLabelBorders( wxDC& dc ) dc.DrawLine( m_left + 1, rowTop + 1, m_left + 1, rowTop + m_rowHeights[i] ); - + rowTop += m_rowHeights[i]; } } @@ -2799,12 +2937,12 @@ void wxGrid::DrawRowLabel( wxDC& dc, const wxRect& rect, int row ) rect2.y += 2; rect2.width -= 5; rect2.height -= 4; - + dc.SetBackgroundMode( wxTRANSPARENT ); dc.SetTextBackground( GetLabelBackgroundColour() ); dc.SetTextForeground( GetLabelTextColour() ); dc.SetFont( GetLabelFont() ); - + int hAlign, vAlign; GetRowLabelAlignment( &hAlign, &vAlign ); DrawTextRectangle( dc, GetRowLabelValue( row ), rect2, hAlign, vAlign ); @@ -2829,7 +2967,7 @@ void wxGrid::DrawCellArea( wxDC& dc ) void wxGrid::DrawGridLines( wxDC& dc ) { if ( !m_gridLinesEnabled || !m_numRows || !m_numCols ) return; - + int i; int cw, ch; GetClientSize(&cw, &ch); @@ -2868,12 +3006,12 @@ void wxGrid::DrawGridLines( wxDC& dc ) void wxGrid::DrawCells( wxDC& dc ) { if ( !m_numRows || !m_numCols ) return; - + int row, col; - + int cw, ch; GetClientSize( &cw, &ch ); - + wxRect rect; if ( m_table ) @@ -2909,9 +3047,9 @@ void wxGrid::DrawCellBackground( wxDC& dc, const wxRect& rect, int row, int col rect2.y += 1; rect2.width -= 2; rect2.height -= 2; - + dc.SetBackgroundMode( wxSOLID ); - + if ( IsInSelection( row, col ) ) { // TODO: improve this @@ -2927,7 +3065,11 @@ void wxGrid::DrawCellBackground( wxDC& dc, const wxRect& rect, int row, int col } -void wxGrid::DrawCellValue( wxDC& dc, const wxRect& rect, int row, int col ) +// This draws a text value in the given cell. If useValueArg is FALSE +// (the default) then the grid table value will be used +// +void wxGrid::DrawCellValue( wxDC& dc, const wxRect& rect, int row, int col, + const wxString& value, bool useValueArg ) { wxRect rect2; rect2 = rect; @@ -2935,7 +3077,7 @@ void wxGrid::DrawCellValue( wxDC& dc, const wxRect& rect, int row, int col ) rect2.y += 2; rect2.width -= 5; rect2.height -= 4; - + dc.SetBackgroundMode( wxTRANSPARENT ); if ( IsInSelection( row, col ) ) @@ -2951,10 +3093,40 @@ void wxGrid::DrawCellValue( wxDC& dc, const wxRect& rect, int row, int col ) dc.SetTextForeground( GetCellTextColour(row, col) ); } dc.SetFont( GetCellFont(row, col) ); - + int hAlign, vAlign; GetCellAlignment( row, col, &hAlign, &vAlign ); - DrawTextRectangle( dc, GetCellValue( row, col ), rect2, hAlign, vAlign ); + + if ( useValueArg ) + { + DrawTextRectangle( dc, value, rect2, hAlign, vAlign ); + } + else + { + DrawTextRectangle( dc, GetCellValue( row, col ), rect2, hAlign, vAlign ); + } +} + + +// this is used to echo text being entered into the top edit control when +// in-place editing is turned off +// +void wxGrid::DrawCellValue( const wxGridCellCoords& coords, const wxString& value ) +{ + if ( IsVisible( coords ) ) + { + int row = coords.GetRow(); + int col = coords.GetCol(); + wxRect rect; + rect.x = m_colRights[ col ] - m_colWidths[ col ]; + rect.y = m_rowBottoms[ row ] - m_rowHeights[ row ]; + rect.width = m_colWidths[ col ]; + rect.height = m_rowHeights[ row ]; + + wxClientDC dc( this ); + DrawCellBackground( dc, rect, row, col ); + DrawCellValue( dc, rect, row, col, value, TRUE ); + } } @@ -2969,20 +3141,20 @@ void wxGrid::DrawCellHighlight( wxDC& dc, int row, int col ) int cw, ch; GetClientSize( &cw, &ch ); - + x = m_colRights[col] - m_colWidths[col]; if ( x >= cw ) return; - + y = m_rowBottoms[row] - m_rowHeights[row]; if ( y >= ch ) return; - dc.SetLogicalFunction( wxXOR ); + dc.SetLogicalFunction( wxINVERT ); dc.SetPen( wxPen(GetCellHighlightColour(), 2, wxSOLID) ); dc.SetBrush( *wxTRANSPARENT_BRUSH ); - dc.DrawRectangle( x, y, - m_colWidths[col] + 2, - m_rowHeights[row] + 2 ); + dc.DrawRectangle( x-2, y-2, + m_colWidths[col] + 6, + m_rowHeights[row] + 6 ); dc.SetLogicalFunction( wxCOPY ); } @@ -2997,10 +3169,10 @@ void wxGrid::DrawCell( int row, int col ) if ( !GetBatchCount() ) { if ( !IsVisible( wxGridCellCoords(row, col) ) ) return; - + int cw, ch; GetClientSize( &cw, &ch ); - + wxRect rect( CellToRect( row, col ) ); if ( m_table ) @@ -3045,11 +3217,10 @@ void wxGrid::DrawTextRectangle( wxDC& dc, int horizAlign, int vertAlign ) { - int i; long textWidth, textHeight; long lineWidth, lineHeight; wxArrayString lines; - + // see if we are already clipping // wxRect clipRect; @@ -3089,21 +3260,21 @@ void wxGrid::DrawTextRectangle( wxDC& dc, { GetTextBoxSize( dc, lines, &textWidth, &textHeight ); dc.GetTextExtent( lines[0], &lineWidth, &lineHeight ); - + float x, y; switch ( horizAlign ) { case wxRIGHT: - x = rect.x + (rect.width - textWidth - 1.0); + x = rect.x + (rect.width - textWidth - 1); break; case wxCENTRE: - x = rect.x + ((rect.width - textWidth)/2.0); + x = rect.x + ((rect.width - textWidth)/2); break; case wxLEFT: default: - x = rect.x + 1.0; + x = rect.x + 1; break; } @@ -3114,22 +3285,22 @@ void wxGrid::DrawTextRectangle( wxDC& dc, break; case wxCENTRE: - y = rect.y + ((rect.height - textHeight)/2.0); + y = rect.y + ((rect.height - textHeight)/2); break; case wxTOP: default: - y = rect.y + 1.0; + y = rect.y + 1; break; } - for ( i = 0; i < lines.GetCount(); i++ ) + for ( size_t i = 0; i < lines.GetCount(); i++ ) { dc.DrawText( lines[i], (long)x, (long)y ); y += lineHeight; } } - + dc.DestroyClippingRegion(); if (alreadyClipping) dc.SetClippingRegion( clipRect ); } @@ -3141,10 +3312,10 @@ void wxGrid::DrawTextRectangle( wxDC& dc, void wxGrid::StringToLines( const wxString& value, wxArrayString& lines ) { // TODO: this won't work for WXMAC ? (lines end with '\r') - // + // => use wxTextFile functions then (VZ) int startPos = 0; int pos; - while ( startPos < value.Length() ) + while ( startPos < (int)value.Length() ) { pos = value.Mid(startPos).Find( '\n' ); if ( pos < 0 ) @@ -3168,7 +3339,7 @@ void wxGrid::StringToLines( const wxString& value, wxArrayString& lines ) } startPos += pos+1; } - if ( startPos < value.Length() ) + if ( startPos < (int)value.Length() ) { lines.Add( value.Mid( startPos ) ); } @@ -3183,7 +3354,7 @@ void wxGrid::GetTextBoxSize( wxDC& dc, long h = 0; long lineW, lineH; - int i; + size_t i; for ( i = 0; i < lines.GetCount(); i++ ) { dc.GetTextExtent( lines[i], &lineW, &lineH ); @@ -3217,7 +3388,7 @@ bool wxGrid::GetModelValues() bool wxGrid::SetModelValues() { int row, col; - + if ( m_table ) { for ( row = m_scrollPosY; row < m_numRows; row++ ) @@ -3230,7 +3401,7 @@ bool wxGrid::SetModelValues() return TRUE; } - + return FALSE; } @@ -3243,20 +3414,20 @@ bool wxGrid::CreateGrid( int numRows, int numCols ) { 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 { m_numRows = numRows; m_numCols = numCols; - + m_table = new wxGridStringTable( m_numRows, m_numCols ); m_table->SetView( this ); Init(); m_created = TRUE; } - + return m_created; } @@ -3283,10 +3454,10 @@ bool wxGrid::InsertRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) if ( !m_created ) { - wxLogError( "Called wxGrid::InsertRows() before calling CreateGrid()" ); + wxLogError( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") ); return FALSE; } - + if ( m_table ) { bool ok = m_table->InsertRows( pos, numRows ); @@ -3296,8 +3467,26 @@ bool wxGrid::InsertRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) // if ( ok ) { + if ( m_numCols == 0 ) + { + m_table->AppendCols( WXGRID_DEFAULT_NUMBER_COLS ); + // + // TODO: perhaps instead of appending the default number of cols + // we should remember what the last non-zero number of cols was ? + // + } + + if ( m_currentCellCoords == wxGridNoCellCoords ) + { + // if we have just inserted cols into an empty grid the current + // cell will be undefined... + // + SelectCell( 0, 0 ); + } + if ( !GetBatchCount() ) Refresh(); } + SetEditControlValue(); return ok; } @@ -3310,15 +3499,23 @@ bool wxGrid::InsertRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) bool wxGrid::AppendRows( int numRows, bool WXUNUSED(updateLabels) ) { // TODO: something with updateLabels flag - + if ( !m_created ) { - wxLogError( "Called wxGrid::AppendRows() before calling CreateGrid()" ); + wxLogError( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") ); return FALSE; } - + if ( m_table && m_table->AppendRows( numRows ) ) { + if ( m_currentCellCoords == wxGridNoCellCoords ) + { + // if we have just inserted cols into an empty grid the current + // cell will be undefined... + // + SelectCell( 0, 0 ); + } + // the table will have sent the results of the append row // operation to this view object as a grid table message // @@ -3337,10 +3534,10 @@ bool wxGrid::DeleteRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) if ( !m_created ) { - wxLogError( "Called wxGrid::DeleteRows() before calling CreateGrid()" ); + wxLogError( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") ); return FALSE; } - + if ( m_table && m_table->DeleteRows( pos, numRows ) ) { // the table will have sent the results of the delete row @@ -3350,7 +3547,7 @@ bool wxGrid::DeleteRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) SetEditControlValue(); else HideCellEditControl(); - + if ( !GetBatchCount() ) Refresh(); return TRUE; } @@ -3363,10 +3560,10 @@ bool wxGrid::DeleteRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) bool wxGrid::InsertCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) { // TODO: something with updateLabels flag - + if ( !m_created ) { - wxLogError( "Called wxGrid::InsertCols() before calling CreateGrid()" ); + wxLogError( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") ); return FALSE; } @@ -3374,13 +3571,23 @@ bool wxGrid::InsertCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) { HideCellEditControl(); bool ok = m_table->InsertCols( pos, numCols ); + + // the table will have sent the results of the insert col + // operation to this view object as a grid table message + // if ( ok ) { - // the table will have sent the results of the insert col - // operation to this view object as a grid table message - // + if ( m_currentCellCoords == wxGridNoCellCoords ) + { + // if we have just inserted cols into an empty grid the current + // cell will be undefined... + // + SelectCell( 0, 0 ); + } + if ( !GetBatchCount() ) Refresh(); } + SetEditControlValue(); return ok; } @@ -3396,34 +3603,41 @@ bool wxGrid::AppendCols( int numCols, bool WXUNUSED(updateLabels) ) if ( !m_created ) { - wxLogError( "Called wxGrid::AppendCols() before calling CreateGrid()" ); - return FALSE; + wxLogError( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") ); + return FALSE; } if ( m_table && m_table->AppendCols( numCols ) ) { - // the table will have sent the results of the append col - // operation to this view object as a grid table message - // - if ( !GetBatchCount() ) Refresh(); - return TRUE; + // the table will have sent the results of the append col + // operation to this view object as a grid table message + // + if ( m_currentCellCoords == wxGridNoCellCoords ) + { + // if we have just inserted cols into an empty grid the current + // cell will be undefined... + // + SelectCell( 0, 0 ); + } + if ( !GetBatchCount() ) Refresh(); + return TRUE; } else { - return FALSE; + return FALSE; } } bool wxGrid::DeleteCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) { // TODO: something with updateLabels flag - + if ( !m_created ) { - wxLogError( "Called wxGrid::DeleteCols() before calling CreateGrid()" ); + wxLogError( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") ); return FALSE; } - + if ( m_table && m_table->DeleteCols( pos, numCols ) ) { // the table will have sent the results of the delete col @@ -3433,7 +3647,7 @@ bool wxGrid::DeleteCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) SetEditControlValue(); else HideCellEditControl(); - + if ( !GetBatchCount() ) Refresh(); return TRUE; } @@ -3442,7 +3656,7 @@ bool wxGrid::DeleteCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) return FALSE; } } - + @@ -3459,7 +3673,7 @@ void wxGrid::EnableEditing( bool edit ) if ( !m_editable ) HideCellEditControl(); m_topEditCtrlEnabled = m_editable; m_cellEditCtrlEnabled = m_editable; - if ( !m_editable ) ShowCellEditControl(); + if ( !m_editable ) ShowCellEditControl(); } } @@ -3475,7 +3689,7 @@ void wxGrid::EnableTopEditControl( bool enable ) if ( m_currentCellCoords != wxGridNoCellCoords ) SetEditControlValue(); - + ShowCellEditControl(); if ( !GetBatchCount() ) Refresh(); } @@ -3486,13 +3700,17 @@ void wxGrid::EnableCellEditControl( bool enable ) if ( m_cellEditCtrl && enable != m_cellEditCtrlEnabled ) { + wxClientDC dc( this ); + + HideCurrentCellHighlight( dc ); HideCellEditControl(); SaveEditControlValue(); - + m_cellEditCtrlEnabled = enable; SetEditControlValue(); ShowCellEditControl(); + ShowCurrentCellHighlight( dc ); } } @@ -3581,7 +3799,7 @@ void wxGrid::SetRowLabelAlignment( int horiz, int vert ) { m_rowLabelHorizAlign = horiz; } - + if ( vert == wxTOP || vert == wxCENTRE || vert == wxBOTTOM ) { m_rowLabelVertAlign = vert; @@ -3596,7 +3814,7 @@ void wxGrid::SetColLabelAlignment( int horiz, int vert ) { m_colLabelHorizAlign = horiz; } - + if ( vert == wxTOP || vert == wxCENTRE || vert == wxBOTTOM ) { m_colLabelVertAlign = vert; @@ -3626,7 +3844,7 @@ void wxGrid::SetColLabelValue( int col, const wxString& s ) void wxGrid::SetGridLineColour( const wxColour& colour ) { m_gridLineColour = colour; - + wxClientDC dc( this ); DrawGridLines( dc ); } @@ -3674,25 +3892,25 @@ wxColour wxGrid::GetDefaultCellBackgroundColour() return wxColour( 255, 255, 255 ); } -wxColour wxGrid::GetCellBackgroundColour( int row, int col ) +wxColour wxGrid::GetCellBackgroundColour( int WXUNUSED(row), int WXUNUSED(col) ) { // TODO: replace this temp test code // - return wxColour( 255, 255, 255 ); + return wxColour( 255, 255, 255 ); } wxColour wxGrid::GetDefaultCellTextColour() { // TODO: replace this temp test code // - return wxColour( 0, 0, 0 ); + return wxColour( 0, 0, 0 ); } -wxColour wxGrid::GetCellTextColour( int row, int col ) +wxColour wxGrid::GetCellTextColour( int WXUNUSED(row), int WXUNUSED(col) ) { // TODO: replace this temp test code // - return wxColour( 0, 0, 0 ); + return wxColour( 0, 0, 0 ); } @@ -3700,7 +3918,7 @@ wxColour wxGrid::GetCellHighlightColour() { // TODO: replace this temp test code // - return wxColour( 0, 0, 0 ); + return wxColour( 0, 0, 0 ); } @@ -3709,7 +3927,7 @@ wxFont wxGrid::GetDefaultCellFont() return m_defaultCellFont; } -wxFont wxGrid::GetCellFont( int row, int col ) +wxFont wxGrid::GetCellFont( int WXUNUSED(row), int WXUNUSED(col) ) { // TODO: replace this temp test code // @@ -3724,7 +3942,7 @@ void wxGrid::GetDefaultCellAlignment( int *horiz, int *vert ) *vert = wxTOP; } -void wxGrid::GetCellAlignment( int row, int col, int *horiz, int *vert ) +void wxGrid::GetCellAlignment( int WXUNUSED(row), int WXUNUSED(col), int *horiz, int *vert ) { // TODO: replace this temp test code // @@ -3746,6 +3964,7 @@ void wxGrid::SetDefaultRowSize( int height, bool resizeExistingRows ) { m_rowHeights[row] = m_defaultRowHeight; } + m_sumRowHeights = m_defaultRowHeight * m_numRows; CalcDimensions(); if ( !GetBatchCount() ) Refresh(); } @@ -3755,14 +3974,16 @@ void wxGrid::SetRowSize( int row, int height ) { 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(); // Note: we are ending the event *after* doing // default processing in this case // - SendEvent( EVT_WXGRID_ROW_SIZE, + SendEvent( EVT_GRID_ROW_SIZE, row, -1 ); } else @@ -3785,6 +4006,7 @@ void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols ) { m_colWidths[col] = m_defaultColWidth; } + m_sumColWidths = m_defaultColWidth * m_numCols; CalcDimensions(); if ( !GetBatchCount() ) Refresh(); } @@ -3794,14 +4016,16 @@ void wxGrid::SetColSize( int col, int width ) { 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(); // Note: we are ending the event *after* doing // default processing in this case // - SendEvent( EVT_WXGRID_COL_SIZE, + SendEvent( EVT_GRID_COL_SIZE, -1, col ); } else @@ -3816,7 +4040,7 @@ void wxGrid::SetDefaultCellBackgroundColour( const wxColour& ) // } -void wxGrid::SetCellBackgroundColour( int row, int col, const wxColour& ) +void wxGrid::SetCellBackgroundColour( int WXUNUSED(row), int WXUNUSED(col), const wxColour& ) { // TODO: everything !!! // @@ -3828,7 +4052,7 @@ void wxGrid::SetDefaultCellTextColour( const wxColour& ) // } -void wxGrid::SetCellTextColour( int row, int col, const wxColour& ) +void wxGrid::SetCellTextColour( int WXUNUSED(row), int WXUNUSED(col), const wxColour& ) { // TODO: everything !!! // @@ -3846,19 +4070,19 @@ void wxGrid::SetDefaultCellFont( const wxFont& ) // } -void wxGrid::SetCellFont( int row, int col, const wxFont& ) +void wxGrid::SetCellFont( int WXUNUSED(row), int WXUNUSED(col), const wxFont& ) { // TODO: everything !!! // } -void wxGrid::SetDefaultCellAlignment( int horiz, int vert ) +void wxGrid::SetDefaultCellAlignment( int WXUNUSED(horiz), int WXUNUSED(vert) ) { // TODO: everything !!! // } -void wxGrid::SetCellAlignment( int row, int col, int horiz, int vert ) +void wxGrid::SetCellAlignment( int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(horiz), int WXUNUSED(vert) ) { // TODO: everything !!! // @@ -3881,7 +4105,7 @@ void wxGrid::SetCellValue( int row, int col, const wxString& s ) SetEditControlValue( s ); } } -} +} @@ -3936,7 +4160,7 @@ void wxGrid::MakeCellVisible( int row, int col ) { int lastX = m_scrollPosX; int lastY = m_scrollPosY; - + if ( row >= 0 && row < m_numRows && col >= 0 && col < m_numCols ) { @@ -4018,12 +4242,12 @@ void wxGrid::SelectRow( int row, bool addToSelected ) { if ( m_selectedTopLeft.GetRow() > row ) m_selectedTopLeft.SetRow( row ); - + m_selectedTopLeft.SetCol( 0 ); - + if ( m_selectedBottomRight.GetRow() < row ) m_selectedBottomRight.SetRow( row ); - + m_selectedBottomRight.SetCol( m_numCols - 1 ); } else @@ -4038,9 +4262,9 @@ void wxGrid::SelectRow( int row, bool addToSelected ) wxRect rect( SelectionToRect() ); if ( rect != wxGridNoCellRect ) Refresh( TRUE, &rect ); } - + wxGridRangeSelectEvent gridEvt( GetId(), - EVT_WXGRID_RANGE_SELECT, + EVT_GRID_RANGE_SELECT, this, m_selectedTopLeft, m_selectedBottomRight ); @@ -4077,7 +4301,7 @@ void wxGrid::SelectCol( int col, bool addToSelected ) } wxGridRangeSelectEvent gridEvt( GetId(), - EVT_WXGRID_RANGE_SELECT, + EVT_GRID_RANGE_SELECT, this, m_selectedTopLeft, m_selectedBottomRight ); @@ -4089,7 +4313,7 @@ void wxGrid::SelectCol( int col, bool addToSelected ) void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol ) { int temp; - + if ( topRow > bottomRow ) { temp = topRow; @@ -4119,11 +4343,11 @@ void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol ) if ( !m_isDragging ) { wxGridRangeSelectEvent gridEvt( GetId(), - EVT_WXGRID_RANGE_SELECT, + EVT_GRID_RANGE_SELECT, this, m_selectedTopLeft, m_selectedBottomRight ); - + GetEventHandler()->ProcessEvent(gridEvt); } } @@ -4150,7 +4374,7 @@ void wxGrid::ClearSelection() m_selectedTopLeft = wxGridNoCellCoords; m_selectedBottomRight = wxGridNoCellCoords; } -} +} wxRect wxGrid::SelectionToRect() @@ -4169,7 +4393,7 @@ wxRect wxGrid::SelectionToRect() { rect = wxRect( m_left, m_top, 0, 0 ); } - + cellRect = CellToRect( m_selectedBottomRight ); if ( cellRect != wxGridNoCellRect ) { @@ -4206,7 +4430,7 @@ wxGridEvent::wxGridEvent( int id, wxEventType type, wxObject* obj, m_shift = shift; m_alt = alt; m_meta = meta; - + SetEventObject(obj); } @@ -4225,7 +4449,7 @@ wxGridSizeEvent::wxGridSizeEvent( int id, wxEventType type, wxObject* obj, m_shift = shift; m_alt = alt; m_meta = meta; - + SetEventObject(obj); } @@ -4233,10 +4457,10 @@ wxGridSizeEvent::wxGridSizeEvent( int id, wxEventType type, wxObject* obj, IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent, wxEvent ) wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj, - const wxGridCellCoords& topLeft, - const wxGridCellCoords& bottomRight, - bool control, bool shift, bool alt, bool meta ) - : wxNotifyEvent( type, id ) + const wxGridCellCoords& topLeft, + const wxGridCellCoords& bottomRight, + bool control, bool shift, bool alt, bool meta ) + : wxNotifyEvent( type, id ) { m_topLeft = topLeft; m_bottomRight = bottomRight;