+wxGridCellRenderer * wxGrid::GetDefaultRendererForCell(int row, int col) const
+{
+ wxString typeName = m_table->GetTypeName(row, col);
+ return GetDefaultRendererForType(typeName);
+}
+
+wxGridCellEditor * wxGrid::GetDefaultEditorForType(const wxString& typeName) const
+{
+ int index = m_typeRegistry->FindOrCloneDataType(typeName);
+ if ( index == wxNOT_FOUND )
+ {
+ wxFAIL_MSG(wxString::Format(wxT("Unknown data type name [%s]"), typeName.c_str()));
+
+ return NULL;
+ }
+
+ return m_typeRegistry->GetEditor(index);
+}
+
+wxGridCellRenderer * wxGrid::GetDefaultRendererForType(const wxString& typeName) const
+{
+ int index = m_typeRegistry->FindOrCloneDataType(typeName);
+ if ( index == wxNOT_FOUND )
+ {
+ wxFAIL_MSG(wxString::Format(wxT("Unknown data type name [%s]"), typeName.c_str()));
+
+ return NULL;
+ }
+
+ return m_typeRegistry->GetRenderer(index);
+}
+
+// ----------------------------------------------------------------------------
+// row/col size
+// ----------------------------------------------------------------------------
+
+void wxGrid::DoDisableLineResize(int line, wxGridFixedIndicesSet *& setFixed)
+{
+ if ( !setFixed )
+ {
+ setFixed = new wxGridFixedIndicesSet;
+ }
+
+ setFixed->insert(line);
+}
+
+bool
+wxGrid::DoCanResizeLine(int line, const wxGridFixedIndicesSet *setFixed) const
+{
+ return !setFixed || !setFixed->count(line);
+}
+
+void wxGrid::EnableDragRowSize( bool enable )
+{
+ m_canDragRowSize = enable;
+}
+
+void wxGrid::EnableDragColSize( bool enable )
+{
+ m_canDragColSize = enable;
+}
+
+void wxGrid::EnableDragGridSize( bool enable )
+{
+ m_canDragGridSize = enable;
+}
+
+void wxGrid::EnableDragCell( bool enable )
+{
+ m_canDragCell = enable;
+}
+
+void wxGrid::SetDefaultRowSize( int height, bool resizeExistingRows )
+{
+ m_defaultRowHeight = wxMax( height, m_minAcceptableRowHeight );
+
+ if ( resizeExistingRows )
+ {
+ // since we are resizing all rows to the default row size,
+ // we can simply clear the row heights and row bottoms
+ // arrays (which also allows us to take advantage of
+ // some speed optimisations)
+ m_rowHeights.Empty();
+ m_rowBottoms.Empty();
+ if ( !GetBatchCount() )
+ CalcDimensions();
+ }
+}
+
+namespace
+{
+
+// This is a common part of SetRowSize() and SetColSize() which takes care of
+// updating the height/width of a row/column depending on its current value and
+// the new one.
+//
+// Returns the difference between the new and the old size.
+int UpdateRowOrColSize(int& sizeCurrent, int sizeNew)
+{
+ // On input here sizeCurrent can be negative if it's currently hidden (the
+ // real size is its absolute value then). And sizeNew can be 0 to indicate
+ // that the row/column should be hidden or -1 to indicate that it should be
+ // shown again.
+
+ if ( sizeNew < 0 )
+ {
+ // We're showing back a previously hidden row/column.
+ wxASSERT_MSG( sizeNew == -1, wxS("New size must be positive or -1.") );
+
+ // If it's already visible, simply do nothing.
+ if ( sizeCurrent >= 0 )
+ return 0;
+
+ // Otherwise show it by restoring its old size.
+ sizeCurrent = -sizeCurrent;
+
+ // This is positive which is correct.
+ return sizeCurrent;
+ }
+ else if ( sizeNew == 0 )
+ {
+ // We're hiding a row/column.
+
+ // If it's already hidden, simply do nothing.
+ if ( sizeCurrent <= 0 )
+ return 0;
+
+ // Otherwise hide it and also remember the shown size to be able to
+ // restore it later.
+ sizeCurrent = -sizeCurrent;
+
+ // This is negative which is correct.
+ return sizeCurrent;
+ }
+ else // We're just changing the row/column size.
+ {
+ // Here it could have been hidden or not previously.
+ const int sizeOld = sizeCurrent < 0 ? 0 : sizeCurrent;
+
+ sizeCurrent = sizeNew;
+
+ return sizeCurrent - sizeOld;
+ }
+}
+
+} // anonymous namespace
+
+void wxGrid::SetRowSize( int row, int height )
+{
+ // See comment in SetColSize
+ if ( height > 0 && height < GetRowMinimalAcceptableHeight())
+ return;
+
+ // The value of -1 is special and means to fit the height to the row label.
+ // As with the columns, ignore attempts to auto-size the hidden rows.
+ if ( height == -1 && GetRowHeight(row) != 0 )
+ {
+ long w, h;
+ wxArrayString lines;
+ wxClientDC dc(m_rowLabelWin);
+ dc.SetFont(GetLabelFont());
+ StringToLines(GetRowLabelValue( row ), lines);
+ GetTextBoxSize( dc, lines, &w, &h );
+ //check that it is not less than the minimal height
+ height = wxMax(h, GetRowMinimalAcceptableHeight());
+ }
+
+ DoSetRowSize(row, height);
+}
+
+void wxGrid::DoSetRowSize( int row, int height )
+{
+ wxCHECK_RET( row >= 0 && row < m_numRows, wxT("invalid row index") );
+
+ if ( m_rowHeights.IsEmpty() )
+ {
+ // need to really create the array
+ InitRowHeights();
+ }
+
+ const int diff = UpdateRowOrColSize(m_rowHeights[row], height);
+ if ( !diff )
+ return;
+
+ for ( int i = row; i < m_numRows; i++ )
+ {
+ m_rowBottoms[i] += diff;
+ }
+
+ InvalidateBestSize();
+
+ if ( !GetBatchCount() )
+ {
+ CalcDimensions();
+ Refresh();
+ }
+}
+
+void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols )
+{
+ // we dont allow zero default column width
+ m_defaultColWidth = wxMax( wxMax( width, m_minAcceptableColWidth ), 1 );
+
+ if ( resizeExistingCols )
+ {
+ // since we are resizing all columns to the default column size,
+ // we can simply clear the col widths and col rights
+ // arrays (which also allows us to take advantage of
+ // some speed optimisations)
+ m_colWidths.Empty();
+ m_colRights.Empty();
+ if ( !GetBatchCount() )
+ CalcDimensions();
+ }
+}
+
+void wxGrid::SetColSize( int col, int width )
+{
+ // we intentionally don't test whether the width is less than
+ // GetColMinimalWidth() here but we do compare it with
+ // GetColMinimalAcceptableWidth() as otherwise things currently break (see
+ // #651) -- and we also always allow the width of 0 as it has the special
+ // sense of hiding the column
+ if ( width > 0 && width < GetColMinimalAcceptableWidth() )
+ return;
+
+ // The value of -1 is special and means to fit the width to the column label.
+ //
+ // Notice that we currently don't support auto-sizing hidden columns (we
+ // could, but it's not clear whether this is really needed and it would
+ // make the code more complex), and for them passing -1 simply means to
+ // show the column back using its old size.
+ if ( width == -1 && GetColWidth(col) != 0 )
+ {
+ long w, h;
+ wxArrayString lines;
+ wxClientDC dc(m_colWindow);
+ dc.SetFont(GetLabelFont());
+ StringToLines(GetColLabelValue(col), lines);
+ if ( GetColLabelTextOrientation() == wxHORIZONTAL )
+ GetTextBoxSize( dc, lines, &w, &h );
+ else
+ GetTextBoxSize( dc, lines, &h, &w );
+ width = w + 6;
+ //check that it is not less than the minimal width
+ width = wxMax(width, GetColMinimalAcceptableWidth());
+ }
+
+ DoSetColSize(col, width);
+}
+
+void wxGrid::DoSetColSize( int col, int width )
+{
+ wxCHECK_RET( col >= 0 && col < m_numCols, wxT("invalid column index") );
+
+ if ( m_colWidths.IsEmpty() )
+ {
+ // need to really create the array
+ InitColWidths();
+ }
+
+ const int diff = UpdateRowOrColSize(m_colWidths[col], width);
+ if ( !diff )
+ return;
+
+ if ( m_useNativeHeader )
+ GetGridColHeader()->UpdateColumn(col);
+ //else: will be refreshed when the header is redrawn
+
+ for ( int colPos = GetColPos(col); colPos < m_numCols; colPos++ )
+ {
+ m_colRights[GetColAt(colPos)] += diff;
+ }
+
+ InvalidateBestSize();
+
+ if ( !GetBatchCount() )
+ {
+ CalcDimensions();
+ Refresh();
+ }
+}
+
+void wxGrid::SetColMinimalWidth( int col, int width )