void ctlSQLGrid::OnLabelClick(wxGridEvent &event) { int row = event.GetRow(); int col = event.GetCol(); // add support for (de)selecting multiple rows and cols with Control pressed if ( row >= 0 && (event.ControlDown() || event.CmdDown()) ) { if (GetSelectedRows().Index(row) == wxNOT_FOUND) SelectRow(row, true); else DeselectRow(row); } else if ( col >= 0 && (event.ControlDown() || event.CmdDown()) ) { if (GetSelectedCols().Index(col) == wxNOT_FOUND) SelectCol(col, true); else DeselectCol(col); } else event.Skip(); }
// Change the selection mode void wxGridSelection::SetSelectionMode( wxGrid::wxGridSelectionModes selmode ) { // if selection mode is unchanged return immediately if (selmode == m_selectionMode) return; if ( m_selectionMode != wxGrid::wxGridSelectCells ) { // if changing form row to column selection // or vice versa, clear the selection. if ( selmode != wxGrid::wxGridSelectCells ) ClearSelection(); m_selectionMode = selmode; } else { // if changing from cell selection to something else, // promote selected cells/blocks to whole rows/columns. size_t n; while ( ( n = m_cellSelection.GetCount() ) > 0 ) { n--; wxGridCellCoords& coords = m_cellSelection[n]; int row = coords.GetRow(); int col = coords.GetCol(); m_cellSelection.RemoveAt(n); if (selmode == wxGrid::wxGridSelectRows) SelectRow( row ); else // selmode == wxGridSelectColumns) SelectCol( col ); } // Note that m_blockSelectionTopLeft's size may be changing! for (n = 0; n < m_blockSelectionTopLeft.GetCount(); n++) { wxGridCellCoords& coords = m_blockSelectionTopLeft[n]; int topRow = coords.GetRow(); int leftCol = coords.GetCol(); coords = m_blockSelectionBottomRight[n]; int bottomRow = coords.GetRow(); int rightCol = coords.GetCol(); if (selmode == wxGrid::wxGridSelectRows) { if (leftCol != 0 || rightCol != m_grid->GetNumberCols() - 1 ) { m_blockSelectionTopLeft.RemoveAt(n); m_blockSelectionBottomRight.RemoveAt(n); SelectBlockNoEvent( topRow, 0, bottomRow, m_grid->GetNumberCols() - 1); } } else // selmode == wxGridSelectColumns) { if (topRow != 0 || bottomRow != m_grid->GetNumberRows() - 1 ) { m_blockSelectionTopLeft.RemoveAt(n); m_blockSelectionBottomRight.RemoveAt(n); SelectBlockNoEvent(0, leftCol, m_grid->GetNumberRows() - 1, rightCol); } } } m_selectionMode = selmode; } }
void CCellView::MouseDown(BPoint where) { StPenState save(this); try { bool optional = IsOptionalClick(Window()->CurrentMessage()); if (!IsFocus() && !fEntering) MakeFocus(); ResetOffset(-1); BRect myRect, bounds(Bounds()); cell myCell = cell(fFrozen.h ? 1 : fPosition.h, fFrozen.v ? 1 : fPosition.v); if (fFirstGraphic) { if (fFirstGraphic->HandleMouseDown(where)) return; else if (fFirstGraphic->HasFocus()) fFirstGraphic->MakeFocus(false); } if (fCellBounds.Contains(where)) { if ((PointIsInSelection(where) && !fEntering) && (optional || WaitMouseMoved(where, false))) { StartDrag(where, optional); } else if (optional) GridMenu(where); else SelectCell(where); } if (!fShowBorders) return; myRect = bounds; myRect.top = fBorderHeight; myRect.left = 0.0; myRect.right = fBorderWidth; if (myRect.Contains(where)) { if (optional) BorderMenu(where); else { do { myCell.v++; GetCellRect(myCell, myRect); } while (myRect.top + 2.0 <= where.y); if (where.y >= myRect.top - 2.0 && where.y <= myRect.top + 2.0) ResizeRow(where, myCell.v - 1); else SelectRow(where, myCell.v - 1); } return; } myRect.Set(fBorderWidth, 0.0, bounds.right, fBorderHeight); if (myRect.Contains(where)) { if (optional) BorderMenu(where); else { do { myCell.h++; GetCellRect(myCell, myRect); } while (myRect.left + 2.0 <= where.x); if (where.x >= myRect.left - 2.0 && where.x <= myRect.left + 2.0) ResizeCol(where, myCell.h - 1); else SelectCol(where, myCell.h - 1); } return; } myRect.Set(0.0, 0.0, fBorderWidth, fBorderHeight); if (myRect.Contains(where)) { if (!fEntering) SetSelection(range(1, 1, kColCount, kRowCount)); else beep(); } } catch(CErr& e) { CATCHED; e.DoError(); return; } catch(...) { CATCHED; ASSERT(FALSE); } }