72 m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK,
74 m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK,
76 m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK,
78 m_grid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK,
80 m_grid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK,
84 m_grid->Connect( wxEVT_CHAR_HOOK,
86 m_grid->Connect( wxEVT_KEY_DOWN,
88 m_grid->Connect( wxEVT_UPDATE_UI,
92 m_grid->GetGridWindow()->Connect( wxEVT_MOTION,
142 if( !aPreserveSelection )
145 m_grid->SetGridCursor( aRow, aCol );
150 if(
model->CanGetValueAs( aRow, aCol, wxGRID_VALUE_BOOL )
151 &&
model->CanSetValueAs( aRow, aCol, wxGRID_VALUE_BOOL ) )
153 model->SetValueAsBool( aRow, aCol, !
model->GetValueAsBool( aRow, aCol ) );
157 if(
model->GetValue( aRow, aCol ) == wxT(
"1" ) )
158 model->SetValue( aRow, aCol, wxT(
"0" ) );
160 model->SetValue( aRow, aCol, wxT(
"1" ) );
167 wxGridEvent event(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, aRow, aCol );
168 event.SetString(
model->GetValue( aRow, aCol ) );
169 m_grid->GetEventHandler()->ProcessEvent( event );
279 wxPoint pt = aEvent.GetPosition();
280 wxPoint pos =
m_grid->CalcScrolledPosition( wxPoint( pt.x, pt.y ) );
282 int col =
m_grid->XToCol( pos.x );
283 int row =
m_grid->YToRow( pos.y );
286 if( ( col == wxNOT_FOUND ) || ( row == wxNOT_FOUND ) || !
m_tooltipEnabled[col] )
288 m_grid->GetGridWindow()->SetToolTip( wxS(
"" ) );
293 m_grid->GetGridWindow()->SetToolTip(
m_grid->GetCellValue( row, col ) );
346 m_grid->CommitPendingChanges(
true );
349 int row = aEvent.GetRow();
351 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
353 wxArrayInt selectedRows =
m_grid->GetSelectedRows();
355 if( selectedRows.Index( row ) == wxNOT_FOUND )
360 if( !
m_grid->IsInSelection( row, aEvent.GetCol() ) )
361 m_grid->SetGridCursor( row, aEvent.GetCol() );
512 bool handled =
false;
514 if( ( ev.GetKeyCode() == WXK_RETURN || ev.GetKeyCode() == WXK_NUMPAD_ENTER )
515 && ev.GetModifiers() == wxMOD_NONE
516 &&
m_grid->GetGridCursorRow() ==
m_grid->GetNumberRows() - 1 )
518 if(
m_grid->IsCellEditControlShown() )
520 if(
m_grid->CommitPendingChanges() )
525 wxCommandEvent
dummy;
530 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'C' )
532 if(
m_grid->IsCellEditControlShown() )
534 wxTextEntry* te =
dynamic_cast<wxTextEntry*
>( ev.GetEventObject() );
538 wxString selectedText = te->GetStringSelection();
540 if( !selectedText.IsEmpty() )
544 if( wxTheClipboard->Open() )
546 wxTheClipboard->SetData(
new wxTextDataObject( selectedText ) );
547 wxTheClipboard->Flush();
548 wxTheClipboard->Close();
556 m_grid->CancelPendingChanges();
563 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' )
565 if(
m_grid->IsCellEditControlShown() )
569 if( wxTheClipboard->Open() )
571 if( wxTheClipboard->IsSupported( wxDF_TEXT )
572 || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
574 wxTextDataObject data;
575 wxTheClipboard->GetData( data );
576 wxString
text = data.GetText();
580 if( hasMultipleCells )
587 wxTextEntry* te =
dynamic_cast<wxTextEntry*
>( ev.GetEventObject() );
589 if( te && te->IsEditable() )
591 te->WriteText(
text );
596 m_grid->CancelPendingChanges();
603 wxTheClipboard->Close();
608 else if( ev.GetKeyCode() == WXK_ESCAPE )
610 if(
m_grid->IsCellEditControlShown() )
612 m_grid->CancelPendingChanges();
624 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'A' )
629 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'C' )
635 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' )
641 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'X' )
647 else if( !ev.GetModifiers() && ev.GetKeyCode() == WXK_DELETE )
655 if(
m_grid->IsEditable() && ev.GetKeyCode() ==
' ' )
660 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
662 wxArrayInt rowSel =
m_grid->GetSelectedRows();
664 for(
unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
665 retVal |=
toggleCell( rowSel[rowInd], 0,
true );
669 else if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectColumns )
671 wxArrayInt colSel =
m_grid->GetSelectedCols();
673 for(
unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
674 retVal |=
toggleCell( 0, colSel[colInd],
true );
678 else if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectCells )
680 wxArrayInt rowSel =
m_grid->GetSelectedRows();
681 wxArrayInt colSel =
m_grid->GetSelectedCols();
682 wxGridCellCoordsArray cellSel =
m_grid->GetSelectedCells();
683 wxGridCellCoordsArray topLeft =
m_grid->GetSelectionBlockTopLeft();
684 wxGridCellCoordsArray botRight =
m_grid->GetSelectionBlockBottomRight();
687 for(
unsigned int cellInd = 0; cellInd < cellSel.GetCount(); cellInd++ )
689 retVal |=
toggleCell( cellSel[cellInd].GetRow(), cellSel[cellInd].GetCol(),
true );
693 for(
unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
695 for(
int row = 0; row <
m_grid->GetNumberRows(); row++ )
696 retVal |=
toggleCell( row, colSel[colInd],
true );
700 for(
unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
702 for(
int col = 0; col <
m_grid->GetNumberCols(); col++ )
703 retVal |=
toggleCell( rowSel[rowInd], col,
true );
707 for(
unsigned int blockInd = 0; blockInd < topLeft.GetCount(); blockInd++ )
709 wxGridCellCoords start = topLeft[blockInd];
710 wxGridCellCoords
end = botRight[blockInd];
712 for(
int row = start.GetRow(); row <=
end.GetRow(); row++ )
714 for(
int col = start.GetCol(); col <=
end.GetCol(); col++ )
727 bool ctrl = ev.RawControlDown();
729 bool ctrl = ev.ControlDown();
732 if( ctrl && ev.GetKeyCode() == WXK_TAB )
739 while(
test && !
test->IsTopLevel() )
743 if(
test->HasFocus() )
746 if( !
test->GetChildren().empty() )
750 else if(
test->GetNextSibling() )
764 else if(
test &&
test->GetNextSibling() )
814 wxGridTableBase* tbl =
m_grid->GetTable();
816 const int cur_row =
m_grid->GetGridCursorRow();
817 const int cur_col =
m_grid->GetGridCursorCol();
822 bool is_selection =
false;
824 if( cur_row < 0 || cur_col < 0 )
830 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
840 wxStringTokenizer rows( cb_text,
ROW_SEP, wxTOKEN_RET_EMPTY );
856 end_row = cur_row + rows.CountTokens();
858 if( end_row > tbl->GetNumberRows() )
862 for(
int ii = end_row - tbl->GetNumberRows(); ii > 0; --ii )
864 wxCommandEvent
dummy;
869 end_row = tbl->GetNumberRows();
876 for(
int row = start_row; row < end_row; ++row )
880 if( !rows.HasMoreTokens() )
881 rows.SetString( cb_text,
ROW_SEP, wxTOKEN_RET_EMPTY );
883 wxString rowTxt = rows.GetNextToken();
885 wxStringTokenizer cols( rowTxt,
COL_SEP, wxTOKEN_RET_EMPTY );
888 end_col = cur_col + cols.CountTokens();
890 for(
int col = start_col; col < end_col && col < tbl->GetNumberCols(); ++col )
893 if( !
m_grid->IsColShown( col ) )
901 if( !cols.HasMoreTokens() )
902 cols.SetString( rowTxt,
COL_SEP, wxTOKEN_RET_EMPTY );
904 wxString cellTxt = cols.GetNextToken();
908 if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) && !
isReadOnly( row, col ) )
910 tbl->SetValue( row, col, cellTxt );
912 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, row, col );
913 m_grid->GetEventHandler()->ProcessEvent( evt );
916 else if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_BOOL ) )
918 tbl->SetValueAsBool( row, col, cellTxt == wxT(
"1" ) );
920 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, row, col );
921 m_grid->GetEventHandler()->ProcessEvent( evt );