]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
allow building wxXRC with wxUSE_HTML=0: make linking work in absence of wxHTML library
[wxWidgets.git] / src / generic / grid.cpp
index f712e23b4dbe7b4d5b64d7cedef918d7cda31121..035334b56a9ba8bc6b58a282cf43b859b8fca275 100644 (file)
@@ -627,7 +627,11 @@ void wxGridCellTextEditor::Create(wxWindow* parent,
     m_control = new wxTextCtrl(parent, id, wxEmptyString,
                                wxDefaultPosition, wxDefaultSize
 #if defined(__WXMSW__)
-                               , wxTE_PROCESS_TAB | wxTE_AUTO_SCROLL | wxNO_BORDER
+                               ,
+                               wxTE_PROCESS_ENTER |
+                               wxTE_PROCESS_TAB |
+                               wxTE_AUTO_SCROLL |
+                               wxNO_BORDER
 #endif
                               );
 
@@ -4353,24 +4357,33 @@ wxGrid::wxGridSelectionModes wxGrid::GetSelectionMode() const
 bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership,
                        wxGrid::wxGridSelectionModes selmode )
 {
+    bool checkSelection = false;
     if ( m_created )
     {
         // stop all processing
         m_created = false;
 
-        if (m_ownTable)
+        if (m_table) 
         {
-            wxGridTableBase *t = m_table;
+            m_table->SetView(0);
+            if( m_ownTable )
+                delete m_table;
             m_table = NULL;
-            delete t;
         }
 
         delete m_selection;
-
-        m_table = NULL;
         m_selection = NULL;
+
+        m_ownTable = false;
         m_numRows = 0;
         m_numCols = 0;
+        checkSelection = true;
+
+        // kill row and column size arrays
+        m_colWidths.Empty();
+        m_colRights.Empty();
+        m_rowHeights.Empty();
+        m_rowBottoms.Empty();
     }
 
     if (table)
@@ -4382,7 +4395,28 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership,
         m_table->SetView( this );
         m_ownTable = takeOwnership;
         m_selection = new wxGridSelection( this, selmode );
-
+        if (checkSelection)
+        {
+            // If the newly set table is smaller than the
+            // original one current cell and selection regions
+            // might be invalid,
+            m_selectingKeyboard = wxGridNoCellCoords;
+            m_currentCellCoords = 
+              wxGridCellCoords(wxMin(m_numRows, m_currentCellCoords.GetRow()),
+                               wxMin(m_numCols, m_currentCellCoords.GetCol()));
+            if (m_selectingTopLeft.GetRow() >= m_numRows ||
+                m_selectingTopLeft.GetCol() >= m_numCols)
+            {
+                m_selectingTopLeft = wxGridNoCellCoords;
+                m_selectingBottomRight = wxGridNoCellCoords;
+            }
+            else
+                m_selectingBottomRight =
+                  wxGridCellCoords(wxMin(m_numRows,
+                                         m_selectingBottomRight.GetRow()),
+                                   wxMin(m_numCols,
+                                         m_selectingBottomRight.GetCol()));
+        }
         CalcDimensions();
 
         m_created = true;
@@ -4623,6 +4657,33 @@ void wxGrid::CalcWindowSizes()
     int cw, ch;
     GetClientSize( &cw, &ch );
 
+    // this block of code tries to work around the following problem: the grid
+    // could have been just resized to have enough space to show the full grid
+    // window contents without the scrollbars, but its client size could be
+    // not big enough because the grid has the scrollbars right now and so the
+    // scrollbars would remain even though we don't need them any more
+    //
+    // to prevent this from happening, check if we have enough space for
+    // everything without the scrollbars and explicitly disable them then
+    wxSize size = GetSize() - GetWindowBorderSize();
+    if ( size != wxSize(cw, ch) )
+    {
+        // check if we have enough space for grid window after accounting for
+        // the fixed size elements
+        size.x -= m_rowLabelWidth;
+        size.y -= m_colLabelHeight;
+
+        const wxSize vsize = m_gridWin->GetVirtualSize();
+
+        if ( size.x >= vsize.x && size.y >= vsize.y )
+        {
+            // yes, we do, so remove the scrollbars and use the new client size
+            // (which should be the same as full window size - borders now)
+            SetScrollbars(0, 0, 0, 0);
+            GetClientSize(&cw, &ch);
+        }
+    }
+
     if ( m_cornerLabelWin && m_cornerLabelWin->IsShown() )
         m_cornerLabelWin->SetSize( 0, 0, m_rowLabelWidth, m_colLabelHeight );
 
@@ -8282,7 +8343,8 @@ void wxGrid::ShowCellEditControl()
             // might not cover the entire cell
             wxClientDC dc( m_gridWin );
             PrepareDC( dc );
-            dc.SetBrush(wxBrush(GetCellAttr(row, col)->GetBackgroundColour(), wxSOLID));
+            wxGridCellAttr* attr = GetCellAttr(row, col);
+            dc.SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
             dc.SetPen(*wxTRANSPARENT_PEN);
             dc.DrawRectangle(rect);
 
@@ -8302,7 +8364,6 @@ void wxGrid::ShowCellEditControl()
             if (rect.y > 0)
                 rect.y--;
 
-            wxGridCellAttr* attr = GetCellAttr(row, col);
             wxGridCellEditor* editor = attr->GetEditor(this, row, col);
             if ( !editor->IsCreated() )
             {
@@ -10652,46 +10713,22 @@ void wxGrid::AutoSizeColLabelSize( int col )
 
 wxSize wxGrid::DoGetBestSize() const
 {
-    // don't set sizes, only calculate them
     wxGrid *self = (wxGrid *)this;  // const_cast
 
-    int width, height;
-    width = self->SetOrCalcColumnSizes(true);
-    height = self->SetOrCalcRowSizes(true);
-
-    if (!width)
-        width = 100;
-    if (!height)
-        height = 80;
-
-    // Round up to a multiple the scroll rate
-    // NOTE: this still doesn't get rid of the scrollbars;
-    // is there any magic incantation for that?
-    int xpu, ypu;
-    GetScrollPixelsPerUnit(&xpu, &ypu);
-    if (xpu)
-        width  += 1 + xpu - (width  % xpu);
-    if (ypu)
-        height += 1 + ypu - (height % ypu);
-
-    // limit to 1/4 of the screen size
-    int maxwidth, maxheight;
-    wxDisplaySize( &maxwidth, &maxheight );
-    maxwidth /= 2;
-    maxheight /= 2;
-    if ( width > maxwidth )
-        width = maxwidth;
-    if ( height > maxheight )
-        height = maxheight;
-
-    wxSize best(width, height);
+    // we do the same as in AutoSize() here with the exception that we don't
+    // change the column/row sizes, only calculate them
+    wxSize size(self->SetOrCalcColumnSizes(true) - m_rowLabelWidth + m_extraWidth,
+                self->SetOrCalcRowSizes(true) - m_colLabelHeight + m_extraHeight);
+    wxSize sizeFit(GetScrollX(size.x) * GetScrollLineX(),
+                   GetScrollY(size.y) * GetScrollLineY());
 
     // NOTE: This size should be cached, but first we need to add calls to
     // InvalidateBestSize everywhere that could change the results of this
     // calculation.
     // CacheBestSize(size);
 
-    return best;
+    return wxSize(sizeFit.x + m_rowLabelWidth, sizeFit.y + m_colLabelHeight)
+            + GetWindowBorderSize();
 }
 
 void wxGrid::Fit()