X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/27bb2c8cb78e39d8a4def1c349e0677fd32a2c06..a188ac2988b6fedeead7a809124b8eaa2290c020:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index c11346662e..dccf054460 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -197,8 +197,6 @@ wxGridCellWorker::~wxGridCellWorker() void wxGridCellAttr::Init(wxGridCellAttr *attrDefault) { - m_nRef = 1; - m_isReadOnly = Unset; m_renderer = NULL; @@ -645,30 +643,30 @@ void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr *attr, int rowOrCol) { if ( attr ) { - // add the attribute - no need to do anything to reference count - // since we take ownership of the attribute. + // store the new attribute, taking its ownership m_rowsOrCols.Add(rowOrCol); m_attrs.Add(attr); } // nothing to remove } - else + else // we have an attribute for this row or column { size_t n = (size_t)i; - if ( m_attrs[n] == attr ) - // nothing to do - return; + + // notice that this code works correctly even when the old attribute is + // the same as the new one: as we own of it, we must call DecRef() on + // it in any case and this won't result in destruction of the new + // attribute if it's the same as old one because it must have ref count + // of at least 2 to be passed to us while we keep a reference to it too + m_attrs[n]->DecRef(); + if ( attr ) { - // change the attribute, handling reference count manually, - // taking ownership of the new attribute. - m_attrs[n]->DecRef(); + // replace the attribute with the new one m_attrs[n] = attr; } - else + else // remove the attribute { - // remove this attribute, handling reference count manually - m_attrs[n]->DecRef(); m_rowsOrCols.RemoveAt(n); m_attrs.RemoveAt(n); } @@ -1127,11 +1125,14 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase ) wxGridStringTable::wxGridStringTable() : wxGridTableBase() { + m_numCols = 0; } wxGridStringTable::wxGridStringTable( int numRows, int numCols ) : wxGridTableBase() { + m_numCols = numCols; + m_data.Alloc( numRows ); wxArrayString sa; @@ -1141,23 +1142,6 @@ wxGridStringTable::wxGridStringTable( int numRows, int numCols ) m_data.Add( sa, numRows ); } -wxGridStringTable::~wxGridStringTable() -{ -} - -int wxGridStringTable::GetNumberRows() -{ - return m_data.GetCount(); -} - -int wxGridStringTable::GetNumberCols() -{ - if ( m_data.GetCount() > 0 ) - return m_data[0].GetCount(); - else - return 0; -} - wxString wxGridStringTable::GetValue( int row, int col ) { wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()), @@ -1327,6 +1311,8 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) } } + m_numCols += numCols; + if ( GetView() ) { wxGridTableMessage msg( this, @@ -1351,6 +1337,8 @@ bool wxGridStringTable::AppendCols( size_t numCols ) m_data[row].Add( wxEmptyString, numCols ); } + m_numCols += numCols; + if ( GetView() ) { wxGridTableMessage msg( this, @@ -1404,16 +1392,23 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols ) m_colLabels.RemoveAt( colID, nToRm ); } - for ( row = 0; row < curNumRows; row++ ) + if ( numCols >= curNumCols ) { - if ( numCols >= curNumCols ) + for ( row = 0; row < curNumRows; row++ ) { m_data[row].Clear(); } - else + + m_numCols = 0; + } + else // something will be left + { + for ( row = 0; row < curNumRows; row++ ) { m_data[row].RemoveAt( colID, numCols ); } + + m_numCols -= numCols; } if ( GetView() ) @@ -2973,7 +2968,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event ) // TODO: generate RESIZING event, see #10754 AutoSizeRowLabelSize( row ); - SendSizeEvent(wxEVT_GRID_ROW_SIZE, row, -1, event); + SendGridSizeEvent(wxEVT_GRID_ROW_SIZE, row, -1, event); ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow()); m_dragLastPos = -1; @@ -3319,7 +3314,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event ) // TODO: generate RESIZING event, see #10754 AutoSizeColLabelSize( colEdge ); - SendSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event); + SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event); ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow()); m_dragLastPos = -1; @@ -3995,7 +3990,7 @@ void wxGrid::DoEndDragResizeRow(const wxMouseEvent& event) // TODO: generate RESIZING event, see #10754 if ( DoEndDragResizeLine(wxGridRowOperations()) ) - SendSizeEvent(wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event); + SendGridSizeEvent(wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event); } void wxGrid::DoEndDragResizeCol(const wxMouseEvent& event) @@ -4003,7 +3998,7 @@ void wxGrid::DoEndDragResizeCol(const wxMouseEvent& event) // TODO: generate RESIZING event, see #10754 if ( DoEndDragResizeLine(wxGridColumnOperations()) ) - SendSizeEvent(wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event); + SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event); } void wxGrid::DoStartMoveCol(int col) @@ -4182,7 +4177,7 @@ wxGrid::DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t), // ---------------------------------------------------------------------------- void -wxGrid::SendSizeEvent(wxEventType type, +wxGrid::SendGridSizeEvent(wxEventType type, int row, int col, const wxMouseEvent& mouseEv) { @@ -4204,7 +4199,7 @@ wxGrid::SendSizeEvent(wxEventType type, // +1 if the event was processed (but not vetoed) // 0 if the event wasn't handled int -wxGrid::SendEvent(wxEventType type, +wxGrid::SendEvent(const wxEventType type, int row, int col, const wxMouseEvent& mouseEv) {