70 m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK,
72 m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK,
74 m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK,
76 m_grid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK,
78 m_grid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK,
82 m_grid->Connect( wxEVT_CHAR_HOOK,
84 m_grid->Connect( wxEVT_KEY_DOWN,
86 m_grid->Connect( wxEVT_UPDATE_UI,
90 m_grid->GetGridWindow()->Connect( wxEVT_MOTION,
128 if( !aPreserveSelection )
131 m_grid->SetGridCursor( aRow, aCol );
136 if(
model->CanGetValueAs( aRow, aCol, wxGRID_VALUE_BOOL )
137 &&
model->CanSetValueAs( aRow, aCol, wxGRID_VALUE_BOOL ) )
139 model->SetValueAsBool( aRow, aCol, !
model->GetValueAsBool( aRow, aCol ) );
143 if(
model->GetValue( aRow, aCol ) == wxT(
"1" ) )
144 model->SetValue( aRow, aCol, wxT(
"0" ) );
146 model->SetValue( aRow, aCol, wxT(
"1" ) );
153 wxGridEvent event(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, aRow, aCol );
154 event.SetString(
model->GetValue( aRow, aCol ) );
155 m_grid->GetEventHandler()->ProcessEvent( event );
265 wxPoint pt = aEvent.GetPosition();
266 wxPoint pos =
m_grid->CalcScrolledPosition( wxPoint( pt.x, pt.y ) );
268 int col =
m_grid->XToCol( pos.x );
269 int row =
m_grid->YToRow( pos.y );
272 if( ( col == wxNOT_FOUND ) || ( row == wxNOT_FOUND ) || !
m_tooltipEnabled[col] )
274 m_grid->GetGridWindow()->SetToolTip( wxS(
"" ) );
279 m_grid->GetGridWindow()->SetToolTip(
m_grid->GetCellValue( row, col ) );
477 bool handled =
false;
479 if( ( ev.GetKeyCode() == WXK_RETURN || ev.GetKeyCode() == WXK_NUMPAD_ENTER )
480 && ev.GetModifiers() == wxMOD_NONE
481 &&
m_grid->GetGridCursorRow() ==
m_grid->GetNumberRows() - 1 )
483 if(
m_grid->IsCellEditControlShown() )
485 if(
m_grid->CommitPendingChanges() )
490 wxCommandEvent
dummy;
495 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' )
497 if(
m_grid->IsCellEditControlShown() && wxTheClipboard->Open() )
499 if( wxTheClipboard->IsSupported( wxDF_TEXT )
500 || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
502 wxTextDataObject data;
503 wxTheClipboard->GetData( data );
505 if( data.GetText().Contains(
COL_SEP ) || data.GetText().Contains(
ROW_SEP ) )
507 wxString stripped( data.GetText() );
508 stripped.Replace(
ROW_SEP,
" " );
510 stripped.Replace(
COL_SEP,
" " );
513 wxTextEntry* te =
dynamic_cast<wxTextEntry*
>( ev.GetEventObject() );
515 if( te && te->IsEditable() )
516 te->WriteText( stripped );
524 wxTheClipboard->Close();
528 else if( ev.GetKeyCode() == WXK_ESCAPE )
530 if(
m_grid->IsCellEditControlShown() )
532 m_grid->CancelPendingChanges();
544 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'A' )
549 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'C' )
555 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' )
561 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'X' )
567 else if( !ev.GetModifiers() && ev.GetKeyCode() == WXK_DELETE )
575 if(
m_grid->IsEditable() && ev.GetKeyCode() ==
' ' )
580 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
582 wxArrayInt rowSel =
m_grid->GetSelectedRows();
584 for(
unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
585 retVal |=
toggleCell( rowSel[rowInd], 0,
true );
589 else if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectColumns )
591 wxArrayInt colSel =
m_grid->GetSelectedCols();
593 for(
unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
594 retVal |=
toggleCell( 0, colSel[colInd],
true );
598 else if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectCells )
600 wxArrayInt rowSel =
m_grid->GetSelectedRows();
601 wxArrayInt colSel =
m_grid->GetSelectedCols();
602 wxGridCellCoordsArray cellSel =
m_grid->GetSelectedCells();
603 wxGridCellCoordsArray topLeft =
m_grid->GetSelectionBlockTopLeft();
604 wxGridCellCoordsArray botRight =
m_grid->GetSelectionBlockBottomRight();
607 for(
unsigned int cellInd = 0; cellInd < cellSel.GetCount(); cellInd++ )
609 retVal |=
toggleCell( cellSel[cellInd].GetRow(), cellSel[cellInd].GetCol(),
true );
613 for(
unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
615 for(
int row = 0; row <
m_grid->GetNumberRows(); row++ )
616 retVal |=
toggleCell( row, colSel[colInd],
true );
620 for(
unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
622 for(
int col = 0; col <
m_grid->GetNumberCols(); col++ )
623 retVal |=
toggleCell( rowSel[rowInd], col,
true );
627 for(
unsigned int blockInd = 0; blockInd < topLeft.GetCount(); blockInd++ )
629 wxGridCellCoords start = topLeft[blockInd];
630 wxGridCellCoords
end = botRight[blockInd];
632 for(
int row = start.GetRow(); row <=
end.GetRow(); row++ )
634 for(
int col = start.GetCol(); col <=
end.GetCol(); col++ )
647 bool ctrl = ev.RawControlDown();
649 bool ctrl = ev.ControlDown();
652 if( ctrl && ev.GetKeyCode() == WXK_TAB )
659 while(
test && !
test->IsTopLevel() )
663 if(
test->HasFocus() )
666 if( !
test->GetChildren().empty() )
670 else if(
test->GetNextSibling() )
684 else if(
test &&
test->GetNextSibling() )
734 wxGridTableBase* tbl =
m_grid->GetTable();
736 const int cur_row =
m_grid->GetGridCursorRow();
737 const int cur_col =
m_grid->GetGridCursorCol();
742 bool is_selection =
false;
744 if( cur_row < 0 || cur_col < 0 )
750 if(
m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
760 wxStringTokenizer rows( cb_text,
ROW_SEP, wxTOKEN_RET_EMPTY );
776 end_row = cur_row + rows.CountTokens();
778 if( end_row > tbl->GetNumberRows() )
782 for(
int ii = end_row - tbl->GetNumberRows(); ii > 0; --ii )
784 wxCommandEvent
dummy;
789 end_row = tbl->GetNumberRows();
796 for(
int row = start_row; row < end_row; ++row )
800 if( !rows.HasMoreTokens() )
801 rows.SetString( cb_text,
ROW_SEP, wxTOKEN_RET_EMPTY );
803 wxString rowTxt = rows.GetNextToken();
805 wxStringTokenizer cols( rowTxt,
COL_SEP, wxTOKEN_RET_EMPTY );
808 end_col = cur_col + cols.CountTokens();
810 for(
int col = start_col; col < end_col && col < tbl->GetNumberCols(); ++col )
813 if( !
m_grid->IsColShown( col ) )
821 if( !cols.HasMoreTokens() )
822 cols.SetString( rowTxt,
COL_SEP, wxTOKEN_RET_EMPTY );
824 wxString cellTxt = cols.GetNextToken();
828 if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) && !
isReadOnly( row, col ) )
830 tbl->SetValue( row, col, cellTxt );
832 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, row, col );
833 m_grid->GetEventHandler()->ProcessEvent( evt );
836 else if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_BOOL ) )
838 tbl->SetValueAsBool( row, col, cellTxt == wxT(
"1" ) );
840 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, row, col );
841 m_grid->GetEventHandler()->ProcessEvent( evt );