]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
Lesstif compilation fix.
[wxWidgets.git] / src / generic / grid.cpp
index f60e2bced655fa141799fc2421fa8d87f5b66099..3e38c3085c089951e875cc6dc6a3aedcce31984f 100644 (file)
@@ -458,7 +458,7 @@ void wxGridCellEditor::PaintBackground(const wxRect& rectCell,
     wxGridWindow* gridWindow = wxDynamicCast(m_control->GetParent(), wxGridWindow);
     if (gridWindow)
         gridWindow->GetOwner()->PrepareDC(dc);
-    
+
     dc.SetPen(*wxTRANSPARENT_PEN);
     dc.SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
     dc.DrawRectangle(rectCell);
@@ -2061,7 +2061,7 @@ void wxGridCellAttr::Init(wxGridCellAttr *attrDefault)
     m_attrkind = wxGridCellAttr::Cell;
 
     m_sizeRows = m_sizeCols = 1;
-    m_overflow = TRUE;
+    m_overflow = UnsetOverflow;
 
     SetDefAttr(attrDefault);
 }
@@ -2133,6 +2133,9 @@ void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom)
     if ( !HasReadWriteMode()  && mergefrom->HasReadWriteMode() )
         SetReadOnly(mergefrom->IsReadOnly());
 
+    if (!HasOverflowMode()  && mergefrom->HasOverflowMode() )
+        SetReadOnly(mergefrom->GetOverflow());
+
     SetDefAttr(mergefrom->m_defGridAttr);
 }
 
@@ -3459,7 +3462,7 @@ END_EVENT_TABLE()
 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid *parent,
                                             wxWindowID id,
                                             const wxPoint &pos, const wxSize &size )
-  : wxWindow( parent, id, pos, size, wxWANTS_CHARS )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
 {
     m_owner = parent;
 }
@@ -3525,7 +3528,7 @@ END_EVENT_TABLE()
 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid *parent,
                                             wxWindowID id,
                                             const wxPoint &pos, const wxSize &size )
-  : wxWindow( parent, id, pos, size, wxWANTS_CHARS )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
 {
     m_owner = parent;
 }
@@ -3590,7 +3593,7 @@ END_EVENT_TABLE()
 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent,
                                                   wxWindowID id,
                                                   const wxPoint &pos, const wxSize &size )
-  : wxWindow( parent, id, pos, size, wxWANTS_CHARS )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
 {
     m_owner = parent;
 }
@@ -3660,7 +3663,7 @@ wxGridWindow::wxGridWindow( wxGrid *parent,
                             wxWindowID id,
                             const wxPoint &pos,
                             const wxSize &size )
-            : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxCLIP_CHILDREN,
+            : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxCLIP_CHILDREN,
                         wxT("grid window") )
 
 {
@@ -3738,7 +3741,7 @@ void wxGridWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) )
 
 static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
                            const wxArrayInt& BorderArray, int nMax,
-                           bool maxOnOverflow);
+                           bool clipToMinMax);
 
 #define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
                                           WXGRID_MIN_COL_WIDTH, \
@@ -4791,7 +4794,11 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
         if ( row < 0 )
         {
             row = YToRow(y);
-            SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event );
+            if ( row >=0 &&
+                !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event ) )
+           {
+                // no default action at the moment
+           }
         }
         else
         {
@@ -4828,7 +4835,8 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
     else if ( event.RightDown() )
     {
         row = YToRow(y);
-        if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
+        if ( row >=0 &&
+           !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
         {
             // no default action at the moment
         }
@@ -4840,7 +4848,8 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
     else if ( event.RightDClick() )
     {
         row = YToRow(y);
-        if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
+        if ( row >= 0 &&
+            !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
         {
             // no default action at the moment
         }
@@ -5006,7 +5015,11 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
         if ( col < 0 )
         {
             col = XToCol(x);
-            SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event );
+            if ( col >= 0 &&
+                 ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event ) )
+            {
+               // no default action at the moment
+            }
         }
         else
         {
@@ -5043,7 +5056,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
     else if ( event.RightDown() )
     {
         col = XToCol(x);
-        if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
+        if ( col >= 0 &&
+            !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
         {
             // no default action at the moment
         }
@@ -5055,7 +5069,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
     else if ( event.RightDClick() )
     {
         col = XToCol(x);
-        if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
+        if ( col >= 0 &&
+            !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
         {
             // no default action at the moment
         }
@@ -5412,7 +5427,20 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
                 m_winCapture = NULL;
             }
 
-            if ( m_selectingTopLeft != wxGridNoCellCoords &&
+            if ( coords == m_currentCellCoords && m_waitForSlowClick && CanEnableCellControl())
+            {
+                ClearSelection();
+                EnableCellEditControl();
+
+                wxGridCellAttr* attr = GetCellAttr(coords);
+                wxGridCellEditor *editor = attr->GetEditor(this, coords.GetRow(), coords.GetCol());
+                editor->StartingClick();
+                editor->DecRef();
+                attr->DecRef();
+
+                m_waitForSlowClick = FALSE;
+            }
+            else if ( m_selectingTopLeft != wxGridNoCellCoords &&
                  m_selectingBottomRight != wxGridNoCellCoords )
             {
                 if ( m_selection )
@@ -5434,21 +5462,6 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
                 // drag-shrinking.
                 ShowCellEditControl();
             }
-            else
-            {
-              if( m_waitForSlowClick && CanEnableCellControl())
-              {
-                EnableCellEditControl();
-
-                wxGridCellAttr* attr = GetCellAttr(coords);
-                wxGridCellEditor *editor = attr->GetEditor(this, coords.GetRow(), coords.GetCol());
-                editor->StartingClick();
-                editor->DecRef();
-                attr->DecRef();
-
-                m_waitForSlowClick = FALSE;
-              }
-            }
         }
         else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
         {
@@ -5604,10 +5617,9 @@ void wxGrid::DoEndDragResizeRow()
             {
                 int i, cell_rows, cell_cols, subtract_rows = 0;
                 int leftCol = XToCol(left);
-                int rightCol = XToCol(left+cw);
+                int rightCol = internalXToCol(left+cw);
                 if (leftCol >= 0)
                 {
-                    if (rightCol < 0) rightCol = m_numCols;
                     for (i=leftCol; i<rightCol; i++)
                     {
                         GetCellSize(m_dragRowOrCol, i, &cell_rows, &cell_cols);
@@ -5664,10 +5676,9 @@ void wxGrid::DoEndDragResizeCol()
             {
                 int i, cell_rows, cell_cols, subtract_cols = 0;
                 int topRow = YToRow(top);
-                int bottomRow = YToRow(top+cw);
+                int bottomRow = internalYToRow(top+cw);
                 if (topRow >= 0)
                 {
-                    if (bottomRow < 0) bottomRow = m_numRows;
                     for (i=topRow; i<bottomRow; i++)
                     {
                         GetCellSize(i, m_dragRowOrCol, &cell_rows, &cell_cols);
@@ -6913,37 +6924,32 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
     bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) );
 
     // no gridlines inside multicells, clip them out
-    int leftCol   = XToCol(left);
-    int topRow    = YToRow(top);
-    int rightCol  = XToCol(right);
-    int bottomRow = YToRow(bottom);
+    int leftCol   = internalXToCol(left);
+    int topRow    = internalYToRow(top);
+    int rightCol  = internalXToCol(right);
+    int bottomRow = internalYToRow(bottom);
     wxRegion clippedcells(0, 0, cw, ch);
 
-    if ((leftCol >= 0) && (topRow >= 0))
-    {
-        if (rightCol  < 0) rightCol  = m_numCols;
-        if (bottomRow < 0) bottomRow = m_numRows;
 
-        int i, j, cell_rows, cell_cols;
-        wxRect rect;
+    int i, j, cell_rows, cell_cols;
+    wxRect rect;
 
-        for (j=topRow; j<bottomRow; j++)
+    for (j=topRow; j<bottomRow; j++)
+    {
+        for (i=leftCol; i<rightCol; i++)
         {
-            for (i=leftCol; i<rightCol; i++)
+            GetCellSize( j, i, &cell_rows, &cell_cols );
+            if ((cell_rows > 1) || (cell_cols > 1))
             {
-                GetCellSize( j, i, &cell_rows, &cell_cols );
-                if ((cell_rows > 1) || (cell_cols > 1))
-                {
-                    rect = CellToRect(j,i);
-                    CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
-                    clippedcells.Subtract(rect);
-                }
-                else if ((cell_rows < 0) || (cell_cols < 0))
-                {
-                    rect = CellToRect(j+cell_rows, i+cell_cols);
-                    CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
-                    clippedcells.Subtract(rect);
-                }
+                rect = CellToRect(j,i);
+                CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+                clippedcells.Subtract(rect);
+            }
+            else if ((cell_rows < 0) || (cell_cols < 0))
+            {
+                rect = CellToRect(j+cell_rows, i+cell_cols);
+                CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+                clippedcells.Subtract(rect);
             }
         }
     }
@@ -6953,7 +6959,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
 
     // horizontal grid lines
     //
-    int i;
+    // already declared above - int i;
     for ( i = internalYToRow(top); i < m_numRows; i++ )
     {
         int bot = GetRowBottom(i) - 1;
@@ -7098,10 +7104,10 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                                 int textOrientation )
 {
     wxArrayString lines;
-    
+
     StringToLines( value, lines );
-    
-    
+
+
     //Forward to new API.
     DrawTextRectangle(  dc,
         lines,
@@ -7109,7 +7115,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
         horizAlign,
         vertAlign,
         textOrientation );
-    
+
 }
 
 void wxGrid::DrawTextRectangle( wxDC& dc,
@@ -7122,20 +7128,20 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
     long textWidth, textHeight;
     long lineWidth, lineHeight;
     int nLines;
-    
+
     dc.SetClippingRegion( rect );
-    
+
     nLines = lines.GetCount();
     if( nLines > 0 )
     {
         int l;
         float x = 0.0, y = 0.0;
-        
+
         if( textOrientation == wxHORIZONTAL )
             GetTextBoxSize(dc, lines, &textWidth, &textHeight);
         else
             GetTextBoxSize( dc, lines, &textHeight, &textWidth );
-        
+
         switch( vertAlign )
         {
         case wxALIGN_BOTTOM:
@@ -7144,14 +7150,14 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
             else
                 x = rect.x + rect.width - textWidth;
             break;
-            
+
         case wxALIGN_CENTRE:
             if( textOrientation == wxHORIZONTAL )
                 y = rect.y + ((rect.height - textHeight)/2);
             else
                 x = rect.x + ((rect.width - textWidth)/2);
             break;
-            
+
         case wxALIGN_TOP:
         default:
             if( textOrientation == wxHORIZONTAL )
@@ -7160,12 +7166,12 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                 x = rect.x + 1;
             break;
         }
-        
+
         // Align each line of a multi-line label
         for( l = 0; l < nLines; l++ )
         {
             dc.GetTextExtent(lines[l], &lineWidth, &lineHeight);
-            
+
             switch( horizAlign )
             {
             case wxALIGN_RIGHT:
@@ -7174,14 +7180,14 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                 else
                     y = rect.y + lineWidth + 1;
                 break;
-                
+
             case wxALIGN_CENTRE:
                 if( textOrientation == wxHORIZONTAL )
                     x = rect.x + ((rect.width - lineWidth)/2);
                 else
                     y = rect.y + rect.height - ((rect.height - lineWidth)/2);
                 break;
-                
+
             case wxALIGN_LEFT:
             default:
                 if( textOrientation == wxHORIZONTAL )
@@ -7190,7 +7196,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                     y = rect.y + rect.height - 1;
                 break;
             }
-            
+
             if( textOrientation == wxHORIZONTAL )
             {
                 dc.DrawText( lines[l], (int)x, (int)y );
@@ -7594,10 +7600,16 @@ void wxGrid::XYToCell( int x, int y, wxGridCellCoords& coords )
 
 static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
                            const wxArrayInt& BorderArray, int nMax,
-                           bool maxOnOverflow)
+                           bool clipToMinMax)
 {
+
+    if (coord < 0)
+        return clipToMinMax && (nMax > 0) ? 0 : -1;
+
+
     if (!defaultDist)
         defaultDist = 1;
+
     size_t i_max = coord / defaultDist,
            i_min = 0;
 
@@ -7605,7 +7617,7 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
     {
         if((int) i_max < nMax)
             return i_max;
-        return maxOnOverflow ? nMax - 1 : -1;
+        return clipToMinMax ? nMax - 1 : -1;
     }
 
     if ( i_max >= BorderArray.GetCount())
@@ -7621,7 +7633,7 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
             i_max = BorderArray.GetCount() - 1;
     }
     if ( coord >= BorderArray[i_max])
-        return maxOnOverflow ? (int)i_max : -1;
+        return clipToMinMax ? (int)i_max : -1;
     if ( coord < BorderArray[0] )
         return 0;
 
@@ -7997,13 +8009,11 @@ bool wxGrid::MovePageUp()
         m_gridWin->GetClientSize( &cw, &ch );
 
         int y = GetRowTop(row);
-        int newRow = YToRow( y - ch + 1 );
-        if ( newRow < 0 )
-        {
-            newRow = 0;
-        }
-        else if ( newRow == row )
+        int newRow = internalYToRow( y - ch + 1 );
+
+        if ( newRow == row )
         {
+           //row > 0 , so newrow can never be less than 0 here.
             newRow = row - 1;
         }
 
@@ -8021,20 +8031,17 @@ bool wxGrid::MovePageDown()
     if ( m_currentCellCoords == wxGridNoCellCoords ) return FALSE;
 
     int row = m_currentCellCoords.GetRow();
-    if ( row < m_numRows )
+    if ( (row+1) < m_numRows )
     {
         int cw, ch;
         m_gridWin->GetClientSize( &cw, &ch );
 
         int y = GetRowTop(row);
-        int newRow = YToRow( y + ch );
-        if ( newRow == -1 )
-        {
-            newRow = m_numRows - 1;
-        }
-        else if ( newRow == row )
+        int newRow = internalYToRow( y + ch );
+        if ( newRow == row )
         {
-            newRow = row + 1;
+            // row < m_numRows , so newrow can't overflow here.
+           newRow = row + 1;
         }
 
         MakeCellVisible( newRow, m_currentCellCoords.GetCol() );