+ m_currentCellCoords = coords;
+
+ wxGridCellAttr *attr = GetCellAttr( coords );
+#if !defined(__WXMAC__)
+ DrawCellHighlight( dc, attr );
+#endif
+ attr->DecRef();
+
+ return true;
+}
+
+void
+wxGrid::UpdateBlockBeingSelected(int topRow, int leftCol,
+ int bottomRow, int rightCol)
+{
+ MakeCellVisible(m_selectedBlockCorner);
+ m_selectedBlockCorner = wxGridCellCoords(bottomRow, rightCol);
+
+ if ( m_selection )
+ {
+ switch ( m_selection->GetSelectionMode() )
+ {
+ default:
+ wxFAIL_MSG( "unknown selection mode" );
+ // fall through
+
+ case wxGridSelectCells:
+ // arbitrary blocks selection allowed so just use the cell
+ // coordinates as is
+ break;
+
+ case wxGridSelectRows:
+ // only full rows selection allowd, ensure that we do select
+ // full rows
+ leftCol = 0;
+ rightCol = GetNumberCols() - 1;
+ break;
+
+ case wxGridSelectColumns:
+ // same as above but for columns
+ topRow = 0;
+ bottomRow = GetNumberRows() - 1;
+ break;
+
+ case wxGridSelectRowsOrColumns:
+ // in this mode we can select only full rows or full columns so
+ // it doesn't make sense to select blocks at all (and we can't
+ // extend the block because there is no preferred direction, we
+ // could only extend it to cover the entire grid but this is
+ // not useful)
+ return;
+ }
+ }
+
+ EnsureFirstLessThanSecond(topRow, bottomRow);
+ EnsureFirstLessThanSecond(leftCol, rightCol);
+
+ wxGridCellCoords updateTopLeft = wxGridCellCoords(topRow, leftCol),
+ updateBottomRight = wxGridCellCoords(bottomRow, rightCol);
+
+ // First the case that we selected a completely new area
+ if ( m_selectedBlockTopLeft == wxGridNoCellCoords ||
+ m_selectedBlockBottomRight == wxGridNoCellCoords )
+ {
+ wxRect rect;
+ rect = BlockToDeviceRect( wxGridCellCoords ( topRow, leftCol ),
+ wxGridCellCoords ( bottomRow, rightCol ) );
+ m_gridWin->Refresh( false, &rect );
+ }
+
+ // Now handle changing an existing selection area.
+ else if ( m_selectedBlockTopLeft != updateTopLeft ||
+ m_selectedBlockBottomRight != updateBottomRight )
+ {
+ // Compute two optimal update rectangles:
+ // Either one rectangle is a real subset of the
+ // other, or they are (almost) disjoint!
+ wxRect rect[4];
+ bool need_refresh[4];
+ need_refresh[0] =
+ need_refresh[1] =
+ need_refresh[2] =
+ need_refresh[3] = false;
+ int i;
+
+ // Store intermediate values
+ wxCoord oldLeft = m_selectedBlockTopLeft.GetCol();
+ wxCoord oldTop = m_selectedBlockTopLeft.GetRow();
+ wxCoord oldRight = m_selectedBlockBottomRight.GetCol();
+ wxCoord oldBottom = m_selectedBlockBottomRight.GetRow();
+
+ // Determine the outer/inner coordinates.
+ EnsureFirstLessThanSecond(oldLeft, leftCol);
+ EnsureFirstLessThanSecond(oldTop, topRow);
+ EnsureFirstLessThanSecond(rightCol, oldRight);
+ EnsureFirstLessThanSecond(bottomRow, oldBottom);
+
+ // Now, either the stuff marked old is the outer
+ // rectangle or we don't have a situation where one
+ // is contained in the other.
+
+ if ( oldLeft < leftCol )
+ {
+ // Refresh the newly selected or deselected
+ // area to the left of the old or new selection.
+ need_refresh[0] = true;
+ rect[0] = BlockToDeviceRect(
+ wxGridCellCoords( oldTop, oldLeft ),
+ wxGridCellCoords( oldBottom, leftCol - 1 ) );
+ }
+
+ if ( oldTop < topRow )
+ {
+ // Refresh the newly selected or deselected
+ // area above the old or new selection.
+ need_refresh[1] = true;
+ rect[1] = BlockToDeviceRect(
+ wxGridCellCoords( oldTop, leftCol ),
+ wxGridCellCoords( topRow - 1, rightCol ) );
+ }
+
+ if ( oldRight > rightCol )
+ {
+ // Refresh the newly selected or deselected
+ // area to the right of the old or new selection.
+ need_refresh[2] = true;
+ rect[2] = BlockToDeviceRect(
+ wxGridCellCoords( oldTop, rightCol + 1 ),
+ wxGridCellCoords( oldBottom, oldRight ) );
+ }
+
+ if ( oldBottom > bottomRow )
+ {
+ // Refresh the newly selected or deselected
+ // area below the old or new selection.
+ need_refresh[3] = true;
+ rect[3] = BlockToDeviceRect(
+ wxGridCellCoords( bottomRow + 1, leftCol ),
+ wxGridCellCoords( oldBottom, rightCol ) );
+ }
+
+ // various Refresh() calls
+ for (i = 0; i < 4; i++ )
+ if ( need_refresh[i] && rect[i] != wxGridNoCellRect )
+ m_gridWin->Refresh( false, &(rect[i]) );
+ }
+
+ // change selection
+ m_selectedBlockTopLeft = updateTopLeft;
+ m_selectedBlockBottomRight = updateBottomRight;
+}
+
+//
+// ------ functions to get/send data (see also public functions)
+//
+
+bool wxGrid::GetModelValues()
+{
+ // Hide the editor, so it won't hide a changed value.
+ HideCellEditControl();
+
+ if ( m_table )
+ {
+ // all we need to do is repaint the grid
+ //
+ m_gridWin->Refresh();
+ return true;
+ }
+
+ return false;
+}
+
+bool wxGrid::SetModelValues()
+{
+ int row, col;
+
+ // Disable the editor, so it won't hide a changed value.
+ // Do we also want to save the current value of the editor first?
+ // I think so ...
+ DisableCellEditControl();
+
+ if ( m_table )
+ {
+ for ( row = 0; row < m_numRows; row++ )
+ {
+ for ( col = 0; col < m_numCols; col++ )
+ {
+ m_table->SetValue( row, col, GetCellValue(row, col) );
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+}