]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
correction for Fit() which didn't handle properly windows positioned at (-1, -1)
[wxWidgets.git] / src / generic / grid.cpp
index 6101885d328f0d576fd73088b1613f7b64ac8883..00f2271e51043493535b3fca4d78d97dcbfa65b7 100644 (file)
@@ -483,7 +483,13 @@ void wxGridCellTextEditor::SetSize(const wxRect& rectOrig)
     // unix
     //
 #if defined(__WXGTK__)
-    rect.Inflate(rect.x ? 1 : 0, rect.y ? 1 : 0);
+    if (rect.x != 0)
+    {
+        rect.x += 1;
+        rect.y += 1;
+        rect.width -= 1;
+        rect.height -= 1;
+    }
 #else // !GTK
     int extra_x = ( rect.x > 2 )? 2 : 1;
     int extra_y = ( rect.y > 2 )? 2 : 1;
@@ -2937,6 +2943,11 @@ void wxGrid::Init()
 
     m_inOnKeyDown = FALSE;
     m_batchCount = 0;
+
+    m_extraWidth =
+    m_extraHeight = 50;
+
+    CalcDimensions();
 }
 
 // ----------------------------------------------------------------------------
@@ -3023,8 +3034,8 @@ void wxGrid::CalcDimensions()
 
     if ( m_numRows > 0  &&  m_numCols > 0 )
     {
-        int right = GetColRight( m_numCols-1 ) + 50;
-        int bottom = GetRowBottom( m_numRows-1 ) + 50;
+        int right = GetColRight( m_numCols-1 ) + m_extraWidth;
+        int bottom = GetRowBottom( m_numRows-1 ) + m_extraHeight;
 
         // TODO: restore the scroll position that we had before sizing
         //
@@ -4742,11 +4753,12 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
                 // Otherwise fall through to default
 
             default:
-                // alphanumeric keys enable the cell edit control
+                // alphanumeric keys or F2 (special key just for this) enable
+                // the cell edit control
                 if ( !(event.AltDown() ||
                        event.MetaDown() ||
                        event.ControlDown()) &&
-                     isalnum(event.KeyCode()) &&
+                     (isalnum(event.KeyCode()) || event.KeyCode() == WXK_F2) &&
                      !IsCellEditControlEnabled() &&
                      CanEnableCellControl() )
                 {
@@ -5455,9 +5467,10 @@ void wxGrid::ShowCellEditControl()
                                new wxGridCellEditorEvtHandler(this, editor));
             }
 
+            editor->Show( TRUE, attr );
+            
             editor->SetSize( rect );
 
-            editor->Show( TRUE, attr );
             editor->BeginEdit(row, col, this);
             attr->DecRef();
          }
@@ -6841,6 +6854,10 @@ int wxGrid::GetColMinimalWidth(int col) const
     return obj ? (int)obj : WXGRID_MIN_COL_WIDTH;
 }
 
+// ----------------------------------------------------------------------------
+// auto sizing
+// ----------------------------------------------------------------------------
+
 void wxGrid::AutoSizeColumn( int col, bool setAsMin )
 {
     wxClientDC dc(m_gridWin);
@@ -6889,17 +6906,60 @@ void wxGrid::AutoSizeColumn( int col, bool setAsMin )
     }
 }
 
-void wxGrid::AutoSizeColumns( bool setAsMin )
+int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
 {
+    int width = m_rowLabelWidth;
+
     for ( int col = 0; col < m_numCols; col++ )
     {
-        AutoSizeColumn(col, setAsMin);
+        if ( !calcOnly )
+        {
+            AutoSizeColumn(col, setAsMin);
+        }
+
+        width += GetColWidth(col);
     }
+
+    return width;
 }
 
-//
-// ------ cell value accessor functions
-//
+int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin)
+{
+    int height = m_colLabelHeight;
+
+    for ( int row = 0; row < m_numRows; row++ )
+    {
+        // if ( !calcOnly ) AutoSizeRow(row, setAsMin) -- TODO
+
+        height += GetRowHeight(row);
+    }
+
+    return height;
+}
+
+void wxGrid::AutoSize()
+{
+    // set the size too
+    SetSize(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE));
+}
+
+wxSize wxGrid::DoGetBestSize() const
+{
+    // don't set sizes, only calculate them
+    wxGrid *self = (wxGrid *)this;  // const_cast
+
+    return wxSize(self->SetOrCalcColumnSizes(TRUE),
+                  self->SetOrCalcRowSizes(TRUE));
+}
+
+void wxGrid::Fit()
+{
+    AutoSize();
+}
+
+// ----------------------------------------------------------------------------
+// cell value accessor functions
+// ----------------------------------------------------------------------------
 
 void wxGrid::SetCellValue( int row, int col, const wxString& s )
 {