protected void drawCells( GC gc, Rectangle clipRect, int fromCol, int toCol, int fromRow, int toRow) { int cnt = 0; Rectangle r; if (m_CellEditor != null) { if (!isCellVisible(m_CellEditor.m_Col, m_CellEditor.m_Row)) { Rectangle hide = new Rectangle(-101, -101, 100, 100); m_CellEditor.setBounds(hide); } else { m_CellEditor.setBounds(getCellRect(m_CellEditor.m_Col, m_CellEditor.m_Row)); } } for (int row = fromRow; row < toRow; row++) { r = getCellRect(0, row); if (r.y + r.height < clipRect.y) { continue; } if (r.y > clipRect.y + clipRect.height) { break; } for (int col = fromCol; col < toCol; col++) { r = getCellRect(col, row); if (r.x > clipRect.x + clipRect.width) { break; } if (canDrawCell(col, row, clipRect)) { drawCell(gc, col, row); cnt++; } } } }
/** * This method activated the cell editor on the current focus cell, if the table model allows cell * editing for this cell. */ public void openEditorInFocus() { m_CellEditor = m_Model.getCellEditor(m_FocusCol, m_FocusRow); if (m_CellEditor != null) { Rectangle r = getCellRect(m_FocusCol, m_FocusRow); m_CellEditor.open(this, m_FocusCol, m_FocusRow, r); } }
/* * Focusses the given Cell. Assumes that the given cell is in the viewable * area. Does all neccessary redraws. */ protected void focusCell(int col, int row, int stateMask) { GC gc = new GC(this); // close cell editor if active if (m_CellEditor != null) m_CellEditor.close(true); /* * Special rule: in row selection mode the selection if a fixed cell in * a non-fixed row is allowed and handled as a selection of a non-fixed * cell. */ if (row >= m_Model.getFixedRowCount() && (col >= m_Model.getFixedColumnCount() || m_RowSelectionMode)) { if ((stateMask & SWT.CTRL) == 0 && (stateMask & SWT.SHIFT) == 0) { // case: no modifier key boolean redrawAll = (m_Selection.size() > 1); int oldFocusRow = m_FocusRow; int oldFocusCol = m_FocusCol; clearSelectionWithoutRedraw(); addToSelection(col, row); m_FocusRow = row; m_FocusCol = col; if (redrawAll) redraw(); else if (m_RowSelectionMode) { if (isRowVisible(oldFocusRow)) drawRow(gc, oldFocusRow); if (isRowVisible(m_FocusRow)) drawRow(gc, m_FocusRow); } else { if (isCellVisible(oldFocusCol, oldFocusRow)) drawCell(gc, oldFocusCol, oldFocusRow); if (isCellVisible(m_FocusCol, m_FocusRow)) drawCell(gc, m_FocusCol, m_FocusRow); } } else if ((stateMask & SWT.CTRL) != 0) { // case: CTRL key pressed if (toggleSelection(col, row)) { m_FocusCol = col; m_FocusRow = row; } if (m_RowSelectionMode) { drawRow(gc, row); } else { drawCell(gc, col, row); } } else if ((stateMask & SWT.SHIFT) != 0) { // case: SHIFT key pressed if (m_RowSelectionMode) { if (row < m_FocusRow) { // backword selection while (row != m_FocusRow) { addToSelection(0, --m_FocusRow); } } else { // foreward selection while (row != m_FocusRow) { addToSelection(0, ++m_FocusRow); } } } else // cell selection mode { if (row < m_FocusRow || (row == m_FocusRow && col < m_FocusCol)) { // backword selection while (row != m_FocusRow || col != m_FocusCol) { m_FocusCol--; if (m_FocusCol < m_Model.getFixedColumnCount()) { m_FocusCol = m_Model.getColumnCount(); m_FocusRow--; } addToSelection(m_FocusCol, m_FocusRow); } } else { // foreward selection while (row != m_FocusRow || col != m_FocusCol) { m_FocusCol++; if (m_FocusCol == m_Model.getColumnCount()) { m_FocusCol = m_Model.getFixedColumnCount(); m_FocusRow++; } addToSelection(m_FocusCol, m_FocusRow); } } } redraw(); } // notify non-fixed cell listeners fireCellSelection(col, row, stateMask); } else { // a fixed cell was focused drawCell(gc, col, row); // notify fixed cell listeners fireFixedCellSelection(col, row, stateMask); } gc.dispose(); }