69 m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK,
71 m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK,
73 m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK,
75 m_grid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK,
77 m_grid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK,
81 m_grid->Connect( wxEVT_CHAR_HOOK,
83 m_grid->Connect( wxEVT_KEY_DOWN,
85 m_grid->Connect( wxEVT_UPDATE_UI,
89 m_grid->GetGridWindow()->Connect( wxEVT_MOTION,
126 if( !aPreserveSelection )
129 m_grid->SetGridCursor( aRow, aCol );
132 wxGridTableBase* model =
m_grid->GetTable();
134 if( model->CanGetValueAs( aRow, aCol, wxGRID_VALUE_BOOL )
135 && model->CanSetValueAs( aRow, aCol, wxGRID_VALUE_BOOL ) )
137 model->SetValueAsBool( aRow, aCol, !model->GetValueAsBool( aRow, aCol ) );
141 if( model->GetValue( aRow, aCol ) == wxT(
"1" ) )
142 model->SetValue( aRow, aCol, wxT(
"0" ) );
144 model->SetValue( aRow, aCol, wxT(
"1" ) );
151 wxGridEvent event(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, aRow, aCol );
152 event.SetString( model->GetValue( aRow, aCol ) );
153 m_grid->GetEventHandler()->ProcessEvent( event );
263 wxPoint pt = aEvent.GetPosition();
264 wxPoint pos =
m_grid->CalcScrolledPosition( wxPoint( pt.x, pt.y ) );
266 int col =
m_grid->XToCol( pos.x );
267 int row =
m_grid->YToRow( pos.y );
270 if( ( col == wxNOT_FOUND ) || ( row == wxNOT_FOUND ) || !
m_tooltipEnabled[col] )
272 m_grid->GetGridWindow()->SetToolTip( wxS(
"" ) );
277 m_grid->GetGridWindow()->SetToolTip(
m_grid->GetCellValue( row, col ) );
475 bool handled =
false;
477 if( ( ev.GetKeyCode() == WXK_RETURN || ev.GetKeyCode() == WXK_NUMPAD_ENTER )
478 && ev.GetModifiers() == wxMOD_NONE
479 &&
m_grid->GetGridCursorRow() ==
m_grid->GetNumberRows() - 1 )
481 if(
m_grid->IsCellEditControlShown() )
483 if(
m_grid->CommitPendingChanges() )
488 wxCommandEvent
dummy;
493 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' )
495 if(
m_grid->IsCellEditControlShown() && wxTheClipboard->Open() )
497 if( wxTheClipboard->IsSupported( wxDF_TEXT )
498 || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
500 wxTextDataObject data;
501 wxTheClipboard->GetData( data );
503 if( data.GetText().Contains(
COL_SEP ) || data.GetText().Contains(
ROW_SEP ) )
505 wxString stripped( data.GetText() );
506 stripped.Replace(
ROW_SEP,
" " );
508 stripped.Replace(
COL_SEP,
" " );
511 wxTextEntry* te =
dynamic_cast<wxTextEntry*
>( ev.GetEventObject() );
513 if( te && te->IsEditable() )
514 te->WriteText( stripped );
522 wxTheClipboard->Close();
526 else if( ev.GetKeyCode() == WXK_ESCAPE )
528 if(
m_grid->IsCellEditControlShown() )
530 m_grid->CancelPendingChanges();
542 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'A' )
547 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'C' )
553 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' )
559 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'X' )
565 else if( !ev.GetModifiers() && ev.GetKeyCode() == WXK_DELETE )
573 if(
m_grid->IsEditable() && ev.GetKeyCode() ==
' ' )
578 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
580 wxArrayInt rowSel =
m_grid->GetSelectedRows();
582 for(
unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
583 retVal |=
toggleCell( rowSel[rowInd], 0,
true );
587 else if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectColumns )
589 wxArrayInt colSel =
m_grid->GetSelectedCols();
591 for(
unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
592 retVal |=
toggleCell( 0, colSel[colInd],
true );
596 else if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectCells )
598 wxArrayInt rowSel =
m_grid->GetSelectedRows();
599 wxArrayInt colSel =
m_grid->GetSelectedCols();
600 wxGridCellCoordsArray cellSel =
m_grid->GetSelectedCells();
601 wxGridCellCoordsArray topLeft =
m_grid->GetSelectionBlockTopLeft();
602 wxGridCellCoordsArray botRight =
m_grid->GetSelectionBlockBottomRight();
605 for(
unsigned int cellInd = 0; cellInd < cellSel.GetCount(); cellInd++ )
607 retVal |=
toggleCell( cellSel[cellInd].GetRow(), cellSel[cellInd].GetCol(),
true );
611 for(
unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
613 for(
int row = 0; row <
m_grid->GetNumberRows(); row++ )
614 retVal |=
toggleCell( row, colSel[colInd],
true );
618 for(
unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
620 for(
int col = 0; col <
m_grid->GetNumberCols(); col++ )
621 retVal |=
toggleCell( rowSel[rowInd], col,
true );
625 for(
unsigned int blockInd = 0; blockInd < topLeft.GetCount(); blockInd++ )
627 wxGridCellCoords start = topLeft[blockInd];
628 wxGridCellCoords
end = botRight[blockInd];
630 for(
int row = start.GetRow(); row <=
end.GetRow(); row++ )
632 for(
int col = start.GetCol(); col <=
end.GetCol(); col++ )
645 bool ctrl = ev.RawControlDown();
647 bool ctrl = ev.ControlDown();
650 if( ctrl && ev.GetKeyCode() == WXK_TAB )
657 while(
test && !
test->IsTopLevel() )
661 if(
test->HasFocus() )
664 if( !
test->GetChildren().empty() )
668 else if(
test->GetNextSibling() )
682 else if(
test &&
test->GetNextSibling() )
732 wxGridTableBase* tbl =
m_grid->GetTable();
734 const int cur_row =
m_grid->GetGridCursorRow();
735 const int cur_col =
m_grid->GetGridCursorCol();
740 bool is_selection =
false;
742 if( cur_row < 0 || cur_col < 0 )
748 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
758 wxStringTokenizer rows( cb_text,
ROW_SEP, wxTOKEN_RET_EMPTY );
774 end_row = cur_row + rows.CountTokens();
776 if( end_row > tbl->GetNumberRows() )
780 for(
int ii = end_row - tbl->GetNumberRows(); ii > 0; --ii )
782 wxCommandEvent
dummy;
787 end_row = tbl->GetNumberRows();
794 for(
int row = start_row; row < end_row; ++row )
798 if( !rows.HasMoreTokens() )
799 rows.SetString( cb_text,
ROW_SEP, wxTOKEN_RET_EMPTY );
801 wxString rowTxt = rows.GetNextToken();
803 wxStringTokenizer cols( rowTxt,
COL_SEP, wxTOKEN_RET_EMPTY );
806 end_col = cur_col + cols.CountTokens();
808 for(
int col = start_col; col < end_col && col < tbl->GetNumberCols(); ++col )
811 if( !
m_grid->IsColShown( col ) )
819 if( !cols.HasMoreTokens() )
820 cols.SetString( rowTxt,
COL_SEP, wxTOKEN_RET_EMPTY );
822 wxString cellTxt = cols.GetNextToken();
826 if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) && !
isReadOnly( row, col ) )
828 tbl->SetValue( row, col, cellTxt );
830 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, row, col );
831 m_grid->GetEventHandler()->ProcessEvent( evt );
834 else if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_BOOL ) )
836 tbl->SetValueAsBool( row, col, cellTxt == wxT(
"1" ) );
838 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, row, col );
839 m_grid->GetEventHandler()->ProcessEvent( evt );