void DataGrid::onKeyDown(wxKeyEvent &event) { bool modified = false; if (event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) { if (event.ControlDown()) { if (!IsCellEditControlEnabled()) { insertRowToDataUp(GetGridCursorRow()); modified = true; } } else { insertRowToData(GetGridCursorRow()); modified = true; } } else if (event.GetKeyCode() == WXK_DELETE) { if (IsSelection()) { wxArrayInt rows = GetSelectedRows(); if (rows.Count() > 0) { modified = deleteRowsFromData(rows); } else { unsigned int i; int row, col; wxGridCellCoordsArray cells = GetSelectedCells(); for (i = 0; i < cells.Count(); i++) { clearCellData(cells[i].GetRow(), cells[i].GetCol()); } wxGridCellCoordsArray topLeft = GetSelectionBlockTopLeft(); wxGridCellCoordsArray bottomRight = GetSelectionBlockBottomRight(); for (i = 0; i < topLeft.Count(); i++) { for (row = topLeft[i].GetRow(); row <= bottomRight[i].GetRow(); row++) { for (col = topLeft[i].GetCol(); col <= bottomRight[i].GetCol(); col++) { clearCellData(row, col); } } } wxArrayInt cols = GetSelectedCols(); for (i = 0; i < cols.Count(); i++) { for (row = 1; row < GetNumberRows(); row++) { clearCellData(row, cols[i]); } } } ClearSelection(); } else { clearCellData(GetGridCursorRow(), GetGridCursorCol()); } } wxGrid::OnKeyDown(event); if (modified) updateData(true); }
int ctlSQLGrid::Copy() { wxString str; int copied = 0; size_t i; if (GetSelectedRows().GetCount()) { AppendColumnHeader(str, 0, (GetNumberCols() - 1)); wxArrayInt rows = GetSelectedRows(); for (i = 0 ; i < rows.GetCount() ; i++) { str.Append(GetExportLine(rows.Item(i))); if (rows.GetCount() > 1) str.Append(END_OF_LINE); } copied = rows.GetCount(); } else if (GetSelectedCols().GetCount()) { wxArrayInt cols = GetSelectedCols(); size_t numRows = GetNumberRows(); AppendColumnHeader(str, cols); for (i = 0 ; i < numRows ; i++) { str.Append(GetExportLine(i, cols)); if (numRows > 1) str.Append(END_OF_LINE); } copied = numRows; } else if (GetSelectionBlockTopLeft().GetCount() > 0 && GetSelectionBlockBottomRight().GetCount() > 0) { unsigned int x1, x2, y1, y2; x1 = GetSelectionBlockTopLeft()[0].GetCol(); x2 = GetSelectionBlockBottomRight()[0].GetCol(); y1 = GetSelectionBlockTopLeft()[0].GetRow(); y2 = GetSelectionBlockBottomRight()[0].GetRow(); AppendColumnHeader(str, x1, x2); for (i = y1; i <= y2; i++) { str.Append(GetExportLine(i, x1, x2)); if (y2 > y1) str.Append(END_OF_LINE); } copied = y2 - y1 + 1; } else { int row, col; row = GetGridCursorRow(); col = GetGridCursorCol(); AppendColumnHeader(str, col, col); str.Append(GetExportLine(row, col, col)); copied = 1; } if (copied && wxTheClipboard->Open()) { wxTheClipboard->SetData(new wxTextDataObject(str)); wxTheClipboard->Close(); } else { copied = 0; } return copied; }