X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f85afd4e46af8d5432aefa584bb3e54a8eac5522..314260fbd07ecebb43c60d147e1f4580a7159e42:/src/generic/grid.cpp?ds=sidebyside diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 6f9512c5af..80abb681cb 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -9,6 +9,8 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" #include "wx/defs.h" @@ -20,8 +22,6 @@ #pragma implementation "grid.h" #endif -// For compilers that support precompilation, includes "wx/wx.h". -#include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop @@ -187,7 +187,7 @@ wxGridTableMessage::wxGridTableMessage( wxGridTableBase *table, int id, // this is a magic incantation which must be done! #include -WX_DEFINE_OBJARRAY(wxGridStringArray); +WX_DEFINE_OBJARRAY(wxGridStringArray) IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase ) @@ -602,6 +602,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 ) { @@ -805,10 +807,9 @@ 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 ); @@ -1133,8 +1134,8 @@ bool wxGrid::SendEvent( const wxEventType type, 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); @@ -1150,7 +1151,7 @@ bool wxGrid::SendEvent( const wxEventType type, return GetEventHandler()->ProcessEvent(gridEvt); } - else if ( type == EVT_WXGRID_RANGE_SELECT ) + else if ( type == EVT_GRID_RANGE_SELECT ) { wxGridRangeSelectEvent gridEvt( GetId(), type, @@ -1187,8 +1188,8 @@ bool wxGrid::SendEvent( const wxEventType type, bool wxGrid::SendEvent( const wxEventType type, 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); @@ -1380,7 +1381,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 +1399,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 +1412,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 +1422,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 ) ) @@ -1460,7 +1461,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 +1475,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 +1484,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 ); @@ -1535,7 +1536,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) // Note: we are ending the event *after* doing // default processing in this case // - SendEvent( EVT_WXGRID_ROW_SIZE, m_dragRowOrCol, -1, ev ); + SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, ev ); } } break; @@ -1563,7 +1564,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) // Note: we are ending the event *after* doing // default processing in this case // - SendEvent( EVT_WXGRID_COL_SIZE, -1, m_dragRowOrCol, ev ); + SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, ev ); } } break; @@ -1575,7 +1576,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) // Note: we are ending the event *after* doing // default processing in this case // - SendEvent( EVT_WXGRID_RANGE_SELECT, -1, -1, ev ); + SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, ev ); } } break; @@ -1599,7 +1600,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) case WXGRID_ROWLABEL: { row = YToRow(y); - if ( !SendEvent( EVT_WXGRID_LABEL_RIGHT_CLICK, row, col, ev ) ) + if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) ) { // TODO: default processing ? } @@ -1609,7 +1610,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 +1621,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 +1631,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 ) ) @@ -1663,14 +1664,14 @@ void wxGrid::OnMouse( wxMouseEvent& ev ) case WXGRID_ROWLABEL: { row = YToRow(y); - SendEvent( EVT_WXGRID_LABEL_RIGHT_DCLICK, row, col, ev ); + 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 +1679,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 ); @@ -1860,6 +1861,14 @@ void wxGrid::OnKeyDown( wxKeyEvent& ev ) } break; + case WXK_PRIOR: + MovePageUp(); + break; + + case WXK_NEXT: + MovePageDown(); + break; + default: // now try the cell edit control // @@ -2021,7 +2030,7 @@ void wxGrid::ShowCellEditControl() break; } - // m_cellEditCtrl->SetFocus(); + m_cellEditCtrl->SetFocus(); } } } @@ -2040,7 +2049,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() ) { @@ -2142,7 +2154,7 @@ void wxGrid::SaveEditControlValue() if ( valueChanged ) { - SendEvent( EVT_WXGRID_CELL_CHANGE, + SendEvent( EVT_GRID_CELL_CHANGE, m_currentCellCoords.GetRow(), m_currentCellCoords.GetCol() ); } @@ -2363,6 +2375,54 @@ bool wxGrid::MoveCursorRight() 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; + } + + return FALSE; +} + bool wxGrid::MoveCursorUpBlock() { if ( m_table && @@ -2976,13 +3036,13 @@ void wxGrid::DrawCellHighlight( wxDC& dc, int row, int col ) 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 ); } @@ -3017,7 +3077,8 @@ void wxGrid::DrawCell( int row, int col ) // void wxGrid::HideCurrentCellHighlight( wxDC& dc ) { - if ( m_currentCellHighlighted && + if ( !m_cellEditCtrlEnabled && + m_currentCellHighlighted && m_currentCellCoords != wxGridNoCellCoords ) { DrawCellHighlight( dc, m_currentCellCoords ); @@ -3030,7 +3091,8 @@ void wxGrid::HideCurrentCellHighlight( wxDC& dc ) // void wxGrid::ShowCurrentCellHighlight( wxDC& dc ) { - if ( !m_currentCellHighlighted && + if ( !m_cellEditCtrlEnabled && + !m_currentCellHighlighted && m_currentCellCoords != wxGridNoCellCoords ) { DrawCellHighlight( dc, m_currentCellCoords ); @@ -3045,7 +3107,6 @@ void wxGrid::DrawTextRectangle( wxDC& dc, int horizAlign, int vertAlign ) { - int i; long textWidth, textHeight; long lineWidth, lineHeight; wxArrayString lines; @@ -3123,7 +3184,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc, 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; @@ -3141,10 +3202,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 +3229,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 +3244,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 ); @@ -3296,8 +3357,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; } @@ -3319,6 +3398,14 @@ bool wxGrid::AppendRows( int numRows, bool WXUNUSED(updateLabels) ) 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 // @@ -3374,13 +3461,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; } @@ -3405,6 +3502,13 @@ bool wxGrid::AppendCols( int numCols, bool WXUNUSED(updateLabels) ) // 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; } @@ -3486,6 +3590,9 @@ void wxGrid::EnableCellEditControl( bool enable ) if ( m_cellEditCtrl && enable != m_cellEditCtrlEnabled ) { + wxClientDC dc( this ); + + HideCurrentCellHighlight( dc ); HideCellEditControl(); SaveEditControlValue(); @@ -3493,6 +3600,7 @@ void wxGrid::EnableCellEditControl( bool enable ) SetEditControlValue(); ShowCellEditControl(); + ShowCurrentCellHighlight( dc ); } } @@ -3762,7 +3870,7 @@ void wxGrid::SetRowSize( int row, int height ) // 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 @@ -3801,7 +3909,7 @@ void wxGrid::SetColSize( int col, int width ) // 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 @@ -4040,7 +4148,7 @@ void wxGrid::SelectRow( int row, bool addToSelected ) } wxGridRangeSelectEvent gridEvt( GetId(), - EVT_WXGRID_RANGE_SELECT, + EVT_GRID_RANGE_SELECT, this, m_selectedTopLeft, m_selectedBottomRight ); @@ -4077,7 +4185,7 @@ void wxGrid::SelectCol( int col, bool addToSelected ) } wxGridRangeSelectEvent gridEvt( GetId(), - EVT_WXGRID_RANGE_SELECT, + EVT_GRID_RANGE_SELECT, this, m_selectedTopLeft, m_selectedBottomRight ); @@ -4119,7 +4227,7 @@ 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 );