68 m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK,
70 m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK,
72 m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK,
74 m_grid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK,
76 m_grid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK,
80 m_grid->Connect( wxEVT_CHAR_HOOK,
82 m_grid->Connect( wxEVT_KEY_DOWN,
84 m_grid->Connect( wxEVT_UPDATE_UI,
88 m_grid->GetGridWindow()->Connect( wxEVT_MOTION,
138 if( !aPreserveSelection )
141 m_grid->SetGridCursor( aRow, aCol );
146 if(
model->CanGetValueAs( aRow, aCol, wxGRID_VALUE_BOOL )
147 &&
model->CanSetValueAs( aRow, aCol, wxGRID_VALUE_BOOL ) )
149 model->SetValueAsBool( aRow, aCol, !
model->GetValueAsBool( aRow, aCol ) );
153 if(
model->GetValue( aRow, aCol ) == wxT(
"1" ) )
154 model->SetValue( aRow, aCol, wxT(
"0" ) );
156 model->SetValue( aRow, aCol, wxT(
"1" ) );
163 wxGridEvent event(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, aRow, aCol );
164 event.SetString(
model->GetValue( aRow, aCol ) );
165 m_grid->GetEventHandler()->ProcessEvent( event );
275 wxPoint pt = aEvent.GetPosition();
276 wxPoint pos =
m_grid->CalcScrolledPosition( wxPoint( pt.x, pt.y ) );
278 int col =
m_grid->XToCol( pos.x );
279 int row =
m_grid->YToRow( pos.y );
282 if( ( col == wxNOT_FOUND ) || ( row == wxNOT_FOUND ) || !
m_tooltipEnabled[col] )
284 m_grid->GetGridWindow()->SetToolTip( wxS(
"" ) );
289 m_grid->GetGridWindow()->SetToolTip(
m_grid->GetCellValue( row, col ) );
342 m_grid->CommitPendingChanges(
true );
345 int row = aEvent.GetRow();
347 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
349 wxArrayInt selectedRows =
m_grid->GetSelectedRows();
351 if( selectedRows.Index( row ) == wxNOT_FOUND )
356 if( !
m_grid->IsInSelection( row, aEvent.GetCol() ) )
357 m_grid->SetGridCursor( row, aEvent.GetCol() );
508 bool handled =
false;
510 if( ( ev.GetKeyCode() == WXK_RETURN || ev.GetKeyCode() == WXK_NUMPAD_ENTER )
511 && ev.GetModifiers() == wxMOD_NONE
512 &&
m_grid->GetGridCursorRow() ==
m_grid->GetNumberRows() - 1 )
514 if(
m_grid->IsCellEditControlShown() )
516 if(
m_grid->CommitPendingChanges() )
521 wxCommandEvent
dummy;
526 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'C' )
528 if(
m_grid->IsCellEditControlShown() )
530 wxTextEntry* te =
dynamic_cast<wxTextEntry*
>( ev.GetEventObject() );
534 wxString selectedText = te->GetStringSelection();
536 if( !selectedText.IsEmpty() )
540 if( wxTheClipboard->Open() )
542 wxTheClipboard->SetData(
new wxTextDataObject( selectedText ) );
543 wxTheClipboard->Flush();
544 wxTheClipboard->Close();
552 m_grid->CancelPendingChanges();
559 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' )
561 if(
m_grid->IsCellEditControlShown() )
565 if( wxTheClipboard->Open() )
567 if( wxTheClipboard->IsSupported( wxDF_TEXT )
568 || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
570 wxTextDataObject data;
571 wxTheClipboard->GetData( data );
572 wxString
text = data.GetText();
576 if( hasMultipleCells )
583 wxTextEntry* te =
dynamic_cast<wxTextEntry*
>( ev.GetEventObject() );
585 if( te && te->IsEditable() )
587 te->WriteText(
text );
592 m_grid->CancelPendingChanges();
599 wxTheClipboard->Close();
604 else if( ev.GetKeyCode() == WXK_ESCAPE )
606 if(
m_grid->IsCellEditControlShown() )
608 m_grid->CancelPendingChanges();
620 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'A' )
625 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'C' )
631 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' )
637 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'X' )
643 else if( !ev.GetModifiers() && ev.GetKeyCode() == WXK_DELETE )
651 if(
m_grid->IsEditable() && ev.GetKeyCode() ==
' ' )
656 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
658 wxArrayInt rowSel =
m_grid->GetSelectedRows();
660 for(
unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
661 retVal |=
toggleCell( rowSel[rowInd], 0,
true );
665 else if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectColumns )
667 wxArrayInt colSel =
m_grid->GetSelectedCols();
669 for(
unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
670 retVal |=
toggleCell( 0, colSel[colInd],
true );
674 else if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectCells )
676 wxArrayInt rowSel =
m_grid->GetSelectedRows();
677 wxArrayInt colSel =
m_grid->GetSelectedCols();
678 wxGridCellCoordsArray cellSel =
m_grid->GetSelectedCells();
679 wxGridCellCoordsArray topLeft =
m_grid->GetSelectionBlockTopLeft();
680 wxGridCellCoordsArray botRight =
m_grid->GetSelectionBlockBottomRight();
683 for(
unsigned int cellInd = 0; cellInd < cellSel.GetCount(); cellInd++ )
685 retVal |=
toggleCell( cellSel[cellInd].GetRow(), cellSel[cellInd].GetCol(),
true );
689 for(
unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
691 for(
int row = 0; row <
m_grid->GetNumberRows(); row++ )
692 retVal |=
toggleCell( row, colSel[colInd],
true );
696 for(
unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
698 for(
int col = 0; col <
m_grid->GetNumberCols(); col++ )
699 retVal |=
toggleCell( rowSel[rowInd], col,
true );
703 for(
unsigned int blockInd = 0; blockInd < topLeft.GetCount(); blockInd++ )
705 wxGridCellCoords start = topLeft[blockInd];
706 wxGridCellCoords
end = botRight[blockInd];
708 for(
int row = start.GetRow(); row <=
end.GetRow(); row++ )
710 for(
int col = start.GetCol(); col <=
end.GetCol(); col++ )
723 bool ctrl = ev.RawControlDown();
725 bool ctrl = ev.ControlDown();
728 if( ctrl && ev.GetKeyCode() == WXK_TAB )
735 while(
test && !
test->IsTopLevel() )
739 if(
test->HasFocus() )
742 if( !
test->GetChildren().empty() )
746 else if(
test->GetNextSibling() )
760 else if(
test &&
test->GetNextSibling() )
810 wxGridTableBase* tbl =
m_grid->GetTable();
812 const int cur_row =
m_grid->GetGridCursorRow();
813 const int cur_col =
m_grid->GetGridCursorCol();
818 bool is_selection =
false;
820 if( cur_row < 0 || cur_col < 0 )
826 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
836 wxStringTokenizer rows( cb_text,
ROW_SEP, wxTOKEN_RET_EMPTY );
852 end_row = cur_row + rows.CountTokens();
854 if( end_row > tbl->GetNumberRows() )
858 for(
int ii = end_row - tbl->GetNumberRows(); ii > 0; --ii )
860 wxCommandEvent
dummy;
865 end_row = tbl->GetNumberRows();
872 for(
int row = start_row; row < end_row; ++row )
876 if( !rows.HasMoreTokens() )
877 rows.SetString( cb_text,
ROW_SEP, wxTOKEN_RET_EMPTY );
879 wxString rowTxt = rows.GetNextToken();
881 wxStringTokenizer cols( rowTxt,
COL_SEP, wxTOKEN_RET_EMPTY );
884 end_col = cur_col + cols.CountTokens();
886 for(
int col = start_col; col < end_col && col < tbl->GetNumberCols(); ++col )
889 if( !
m_grid->IsColShown( col ) )
897 if( !cols.HasMoreTokens() )
898 cols.SetString( rowTxt,
COL_SEP, wxTOKEN_RET_EMPTY );
900 wxString cellTxt = cols.GetNextToken();
904 if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) && !
isReadOnly( row, col ) )
906 tbl->SetValue( row, col, cellTxt );
908 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, row, col );
909 m_grid->GetEventHandler()->ProcessEvent( evt );
912 else if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_BOOL ) )
914 tbl->SetValueAsBool( row, col, cellTxt == wxT(
"1" ) );
916 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, row, col );
917 m_grid->GetEventHandler()->ProcessEvent( evt );