]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
1. more test code for drawing with ROPs/masks/bg brushes in drawing
[wxWidgets.git] / src / generic / grid.cpp
index 41b3053e088457f60c9d14d4e9d34346f1a5634c..1af51feba4cce20a5e32cdbb89a2e335622409c3 100644 (file)
@@ -36,8 +36,8 @@
 
 #include "wx/generic/grid.h"
 
-#ifndef DRAW_LINES
-#define DRAW_LINES 1
+#ifndef WXGRID_DRAW_LINES
+#define WXGRID_DRAW_LINES 1
 #endif
 
 //////////////////////////////////////////////////////////////////////
@@ -710,7 +710,7 @@ void wxGridRowLabelWindow::OnPaint( wxPaintEvent &event )
     //
     // m_owner->PrepareDC( dc );
 
-    wxCoord x, y;
+    int x, y;
     m_owner->CalcUnscrolledPosition( 0, 0, &x, &y );
     dc.SetDeviceOrigin( 0, -y );
 
@@ -763,7 +763,7 @@ void wxGridColLabelWindow::OnPaint( wxPaintEvent &event )
     //
     // m_owner->PrepareDC( dc );
 
-    wxCoord x, y;
+    int x, y;
     m_owner->CalcUnscrolledPosition( 0, 0, &x, &y );
     dc.SetDeviceOrigin( -x, 0 );
 
@@ -876,7 +876,7 @@ void wxGridWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
     wxRegion reg = GetUpdateRegion();
     m_owner->CalcCellsExposed( reg );
     m_owner->DrawGridCellArea( dc );
-#if DRAW_LINES
+#if WXGRID_DRAW_LINES
     m_owner->DrawAllGridLines( dc, reg );
 #endif
 }
@@ -1595,6 +1595,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
                   // Only needed to get the correct rect.y:
                   wxRect rect ( CellToRect( m_dragRowOrCol, 0 ) );
                   rect.x = 0;
+                  CalcScrolledPosition(0, rect.y, &dummy, &rect.y);
                   rect.width = m_rowLabelWidth;
                   rect.height = ch - rect.y;
                   m_rowLabelWin->Refresh( TRUE, &rect );
@@ -1611,6 +1612,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
             }
         }
 
+        m_cursorMode  = WXGRID_CURSOR_SELECT_CELL;
         m_dragLastPos  = -1;
     }
 
@@ -1782,6 +1784,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
                   // Only needed to get the correct rect.x:
                   wxRect rect ( CellToRect( 0, m_dragRowOrCol ) );
                   rect.y = 0;
+                  CalcScrolledPosition(rect.x, 0, &rect.x, &dummy);
                   rect.width = cw - rect.x;
                   rect.height = m_colLabelHeight;
                   m_colLabelWin->Refresh( TRUE, &rect );
@@ -1798,6 +1801,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
             }
         }
 
+        m_cursorMode  = WXGRID_CURSOR_SELECT_CELL;
         m_dragLastPos  = -1;
     }
 
@@ -2003,6 +2007,13 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
                 // no default action at the moment
             }
         }
+
+        // ------------ Moving and no button action
+        //
+        else if ( event.Moving() && !event.IsButton() )
+        {
+            m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
+        }
     }
 }
 
@@ -2619,7 +2630,7 @@ void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords )
     if ( m_colWidths[coords.GetCol()] <=0  ||
          m_rowHeights[coords.GetRow()] <= 0 ) return;
 
-#if !DRAW_LINES
+#if !WXGRID_DRAW_LINES
     if ( m_gridLinesEnabled )
         DrawCellBorder( dc, coords );
 #endif
@@ -2750,12 +2761,17 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & reg )
       CalcUnscrolledPosition( x + w, y + h, &right, &bottom );
     }
 
+    // avoid drawing grid lines past the last row and col
+    //
+    right = wxMin( right, m_colRights[m_numCols-1] );
+    bottom = wxMin( bottom, m_rowBottoms[m_numRows-1] );
+
     dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) );
 
     // horizontal grid lines
     //
     int i;
-    for ( i = 0; i <= m_numRows; i++ )
+    for ( i = 0; i < m_numRows; i++ )
     {
         if ( m_rowBottoms[i] > bottom )
         {
@@ -2770,7 +2786,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & reg )
 
     // vertical grid lines
     //
-    for ( i = 0; i <= m_numCols; i++ )
+    for ( i = 0; i < m_numCols; i++ )
     {
         if ( m_colRights[i] > right )
         {
@@ -3963,6 +3979,7 @@ void wxGrid::SetRowLabelValue( int row, const wxString& s )
             wxRect rect = CellToRect( row, 0);
             if ( rect.height > 0 )
             {
+                CalcScrolledPosition(0, rect.y, &rect.x, &rect.y);
                 rect.x = m_left;
                 rect.width = m_rowLabelWidth;
                 m_rowLabelWin->Refresh( TRUE, &rect );
@@ -3981,6 +3998,7 @@ void wxGrid::SetColLabelValue( int col, const wxString& s )
             wxRect rect = CellToRect( 0, col );
             if ( rect.width > 0 )
             {
+                CalcScrolledPosition(rect.x, 0, &rect.x, &rect.y);
                 rect.y = m_top;
                 rect.height = m_colLabelHeight;
                 m_colLabelWin->Refresh( TRUE, &rect );
@@ -4483,65 +4501,65 @@ void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol )
             temp = oldLeft;
             oldLeft = leftCol;
             leftCol = temp;
-       }
+        }
         if (oldTop > topRow )
         {
             temp = oldTop;
             oldTop = topRow;
             topRow = temp;
-       }
-       if (oldRight < rightCol )
+        }
+        if (oldRight < rightCol )
         {
             temp = oldRight;
             oldRight = rightCol;
             rightCol = temp;
-       }
-       if (oldBottom < bottomRow)
-       {
+        }
+        if (oldBottom < bottomRow)
+        {
             temp = oldBottom;
             oldBottom = bottomRow;
             bottomRow = temp;
-       }
+        }
 
         // 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 )
-       {
-           need_refresh[0] = TRUE;
-           rect[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
-                                                           oldLeft ),
-                                        wxGridCellCoords ( oldBottom, 
-                                                           leftCol - 1 ) );
-       }
-
-       if ( oldTop  < topRow )
-       {
-           need_refresh[1] = TRUE;
-           rect[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
-                                                           leftCol ),
-                                        wxGridCellCoords ( topRow - 1, 
-                                                           rightCol ) );
-       }
-
-       if ( oldRight > rightCol )
-       {
-           need_refresh[2] = TRUE;
-           rect[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
-                                                           rightCol + 1 ),
-                                        wxGridCellCoords ( oldBottom,
-                                                           oldRight ) );
-       }
-
-       if ( oldBottom > bottomRow )
-       {
-           need_refresh[3] = TRUE;
-           rect[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow + 1,
-                                                           leftCol ),
-                                        wxGridCellCoords ( oldBottom,
-                                                           rightCol ) );
-       }
+        if ( oldLeft < leftCol )
+        {
+            need_refresh[0] = TRUE;
+            rect[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
+                                                            oldLeft ),
+                                         wxGridCellCoords ( oldBottom, 
+                                                            leftCol - 1 ) );
+        }
+
+        if ( oldTop  < topRow )
+        {
+            need_refresh[1] = TRUE;
+            rect[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
+                                                            leftCol ),
+                                         wxGridCellCoords ( topRow - 1, 
+                                                            rightCol ) );
+        }
+
+        if ( oldRight > rightCol )
+        {
+            need_refresh[2] = TRUE;
+            rect[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
+                                                            rightCol + 1 ),
+                                         wxGridCellCoords ( oldBottom,
+                                                            oldRight ) );
+        }
+
+        if ( oldBottom > bottomRow )
+        {
+            need_refresh[3] = TRUE;
+            rect[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow + 1,
+                                                            leftCol ),
+                                         wxGridCellCoords ( oldBottom,
+                                                            rightCol ) );
+        }
 
 
         // Change Selection