]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
Updated makewx... scripts
[wxWidgets.git] / src / generic / grid.cpp
index b2ca536bfa6cfc84ad1b28d32578990de2cf05fa..8e541e67f2bcc62a24c703b6f5fbe1c2b5351356 100644 (file)
@@ -1556,6 +1556,15 @@ void wxGridCellStringRenderer::Draw(wxGrid& grid,
                                     bool isSelected)
 {
     wxRect rect = rectCell;
+    rect.Inflate(-1);
+
+    // erase only this cells background, overflow cells should have been erased
+    wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
+
+    int hAlign, vAlign;
+    attr.GetAlignment(&hAlign, &vAlign);
+
+    int overflowCols = 0;
 
     if (attr.GetOverflow())
     {
@@ -1568,30 +1577,64 @@ void wxGridCellStringRenderer::Draw(wxGrid& grid,
             int i, c_cols, c_rows;
             for (i = col+cell_cols; i < cols; i++)
             {
-                // check w/ anchor cell for multicell block
-                grid.GetCellSize(row, i, &c_rows, &c_cols);
-                if (c_rows > 0) c_rows = 0;
-                if (grid.GetTable()->IsEmptyCell(row+c_rows, i))
+               bool is_empty = TRUE;
+                for (int j=row; j<row+cell_rows; j++)
                 {
+                    // check w/ anchor cell for multicell block
+                    grid.GetCellSize(row, i, &c_rows, &c_cols);
+                    if (c_rows > 0) c_rows = 0;
+                    if (grid.GetTable()->IsEmptyCell(row+c_rows, i))
+                    {
+                       is_empty = FALSE;
+                       break;
+                    }
+                }
+                if (is_empty)
                     rect.width += grid.GetColSize(i);
-                    if (rect.width >= best_width) break;
+                else
+                {
+                    i--;
+                    break;
                 }
-                else break;
+                if (rect.width >= best_width) break;
+           }
+            overflowCols = i - col - cell_cols + 1;
+           if (overflowCols >= cols) overflowCols = cols - 1;
+        }
+
+        if (overflowCols > 0) // redraw overflow cells w/ proper hilight
+        {
+            hAlign = wxALIGN_LEFT; // if oveflowed then it's left aligned
+            wxRect clip = rect; 
+            clip.x += rectCell.width;
+            // draw each overflow cell individually
+            int col_end = col+cell_cols+overflowCols;
+            if (col_end >= grid.GetNumberCols())
+               col_end = grid.GetNumberCols() - 1;
+            for (int i = col+cell_cols; i <= col_end; i++)
+            {
+                clip.width = grid.GetColSize(i) - 1;
+                dc.DestroyClippingRegion();
+                dc.SetClippingRegion(clip);
+
+                SetTextColoursAndFont(grid, attr, dc,
+                                     grid.IsInSelection(row,i));
+
+                grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
+                                       rect, hAlign, vAlign);
+                clip.x += grid.GetColSize(i) - 1;
             }
+
+            rect = rectCell;
+           rect.Inflate(-1);
+            rect.width++;
+            dc.DestroyClippingRegion();
         }
     }
 
-    // erase only this cells background, overflow cells should have been erased
-    wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
-
     // now we only have to draw the text
     SetTextColoursAndFont(grid, attr, dc, isSelected);
 
-    int hAlign, vAlign;
-    attr.GetAlignment(&hAlign, &vAlign);
-
-    rect.Inflate(-1);
-
     grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
                            rect, hAlign, vAlign);
 }
@@ -3092,8 +3135,7 @@ bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows )
 
     if ( numRows >= curNumRows )
     {
-        for (size_t i=0; i< m_data.GetCount(); i++) m_data[i].Clear();
-        m_data.Empty();  // don't release memory just yet
+        m_data.Clear();
     }
     else
     {
@@ -5309,6 +5351,13 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
     //
     else if ( event.Moving() && !event.IsButton() )
     {
+        if( coords.GetRow() < 0 || coords.GetCol() < 0 )
+        {
+            // out of grid cell area
+            ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
+            return;
+        }
+
         int dragRow = YToEdgeOfRow( y );
         int dragCol = XToEdgeOfCol( x );
 
@@ -5321,7 +5370,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
             return;
         }
 
-        if ( dragRow >= 0 && dragRow < GetNumberRows())
+        if ( dragRow >= 0 )
         {
             m_dragRowOrCol = dragRow;
 
@@ -5339,7 +5388,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
             return;
         }
 
-        if ( dragCol >= 0 && dragCol < GetNumberCols())
+        if ( dragCol >= 0 )
         {
             m_dragRowOrCol = dragCol;
 
@@ -6372,7 +6421,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells )
 {
     if ( !m_numRows || !m_numCols ) return;
 
-    int i, j, k, l, numCells = cells.GetCount();
+    int i, numCells = cells.GetCount();
     int row, col, cell_rows, cell_cols;
     wxGridCellCoordsArray redrawCells;
 
@@ -6387,7 +6436,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells )
         {
             wxGridCellCoords cell(row+cell_rows, col+cell_cols);
             bool marked = FALSE;
-            for ( j = 0;  j < numCells;  j++ )
+            for ( int j = 0;  j < numCells;  j++ )
             {
                 if ( cell == cells[j] )
                 {
@@ -6398,7 +6447,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells )
             if (!marked)
             {
                 int count = redrawCells.GetCount();
-                for (j = 0; j < count; j++)
+                for (int j = 0; j < count; j++)
                 {
                     if ( cell == redrawCells[j] )
                     {
@@ -6414,9 +6463,18 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells )
         // If this cell is empty, find cell to left that might want to overflow
         if (m_table && m_table->IsEmptyCell(row, col))
         {
-            for ( l = 0; l < cell_rows; l++ )
+            for ( int l = 0; l < cell_rows; l++ )
             {
-                for (j = col-1; j >= 0; j--)
+                // find a cell in this row to left alreay marked for repaint
+                int left = col;
+                for (int k = 0; k < int(redrawCells.GetCount()); k++)
+                    if ((redrawCells[k].GetCol() < left) &&
+                        (redrawCells[k].GetRow() == row))
+                        left=redrawCells[k].GetCol();
+
+                if (left == col) left = 0; // oh well
+
+                for (int j = col-1; j >= left; j--)
                 {
                     if (!m_table->IsEmptyCell(row+l, j))
                     {
@@ -6425,7 +6483,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells )
                             wxGridCellCoords cell(row+l, j);
                             bool marked = FALSE;
 
-                            for (k = 0; k < numCells; k++)
+                            for (int k = 0; k < numCells; k++)
                             {
                                 if ( cell == cells[k] )
                                 {
@@ -6436,7 +6494,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells )
                             if (!marked)
                             {
                                 int count = redrawCells.GetCount();
-                                for (k = 0; k < count; k++)
+                                for (int k = 0; k < count; k++)
                                 {
                                     if ( cell == redrawCells[k] )
                                     {
@@ -7207,31 +7265,36 @@ void wxGrid::ShowCellEditControl()
             editor->Show( TRUE, attr );
 
             // resize editor to overflow into righthand cells if allowed
+            int maxWidth = rect.width;
             wxString value = GetCellValue(row, col);
             if ( (value != wxEmptyString) && (attr->GetOverflow()) )
             {
-                wxClientDC dc(m_gridWin);
-                wxCoord y = 0, best_width = 0;
-                dc.SetFont(attr->GetFont());
-                dc.GetTextExtent(value, &best_width, &y);
-
-                int cell_rows, cell_cols;
-                attr->GetSize( &cell_rows, &cell_cols );
-
-                if ((best_width > rect.width) && (col < m_numCols) && m_table)
-                {
-                    int i;
-                    for (i = col+cell_cols; i < m_numCols; i++)
-                    {
-                        if (m_table->IsEmptyCell(row,i))
-                        {
-                            rect.width += GetColWidth(i);
-                            if (rect.width >= best_width) break;
-                        }
-                        else
-                            break;
-                    }
-                }
+                int y;
+                GetTextExtent(value, &maxWidth, &y,
+                             NULL, NULL, &attr->GetFont());
+                if (maxWidth < rect.width) maxWidth = rect.width;
+            }
+            int client_right = m_gridWin->GetClientSize().GetWidth();
+            if (rect.x+maxWidth > client_right)
+               maxWidth = client_right - rect.x;
+
+           if ((maxWidth > rect.width) && (col < m_numCols) && m_table)
+           {
+                GetCellSize( row, col, &cell_rows, &cell_cols );
+               // may have changed earlier
+               for (int i = col+cell_cols; i < m_numCols; i++)
+               {
+                    int c_rows, c_cols;
+                    GetCellSize( row, i, &c_rows, &c_cols );
+                   // looks weird going over a multicell
+                   if (m_table->IsEmptyCell(row,i) &&
+                       (rect.width < maxWidth) && (c_rows == 1))
+                       rect.width += GetColWidth(i);
+                   else
+                     break;
+               }
+                if (rect.GetRight() > client_right)
+                   rect.SetRight(client_right-1);
             }
             editor->SetSize( rect );
 
@@ -7332,11 +7395,12 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
         defaultDist = 1;
     size_t i_max = coord / defaultDist,
            i_min = 0;
+
     if (BorderArray.IsEmpty())
     {
-        if((int) i_max <= nMax)
+        if((int) i_max < nMax)
             return i_max;
-        return maxOnOverflow ? (int)i_max : -1;
+        return maxOnOverflow ? nMax - 1 : -1;
     }
 
     if ( i_max >= BorderArray.GetCount())
@@ -9465,7 +9529,7 @@ wxGridCellCoordsArray wxGrid::GetSelectionBlockTopLeft() const
 wxGridCellCoordsArray wxGrid::GetSelectionBlockBottomRight() const
 {
     if (!m_selection) { wxGridCellCoordsArray a; return a; }
-    return m_selection->m_blockSelectionTopLeft;
+    return m_selection->m_blockSelectionBottomRight;
 }
 wxArrayInt wxGrid::GetSelectedRows() const
 {