Also add wxGridCellEditorPtr and wxGridCellRendererPtr
This is similar to the previous commit and replaces manual calls to DecRef() on the renderers/editors with the use of smart pointers for them too.
This commit is contained in:
@@ -206,6 +206,9 @@ public:
|
|||||||
virtual wxGridCellRenderer *Clone() const = 0;
|
virtual wxGridCellRenderer *Clone() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Smart pointer to wxGridCellRenderer, calling DecRef() on it automatically.
|
||||||
|
typedef wxObjectDataPtr<wxGridCellRenderer> wxGridCellRendererPtr;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGridCellEditor: This class is responsible for providing and manipulating
|
// wxGridCellEditor: This class is responsible for providing and manipulating
|
||||||
// the in-place edit controls for the grid. Instances of wxGridCellEditor
|
// the in-place edit controls for the grid. Instances of wxGridCellEditor
|
||||||
@@ -333,6 +336,9 @@ protected:
|
|||||||
wxDECLARE_NO_COPY_CLASS(wxGridCellEditor);
|
wxDECLARE_NO_COPY_CLASS(wxGridCellEditor);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Smart pointer to wxGridCellEditor, calling DecRef() on it automatically.
|
||||||
|
typedef wxObjectDataPtr<wxGridCellEditor> wxGridCellEditorPtr;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGridHeaderRenderer and company: like wxGridCellRenderer but for headers
|
// wxGridHeaderRenderer and company: like wxGridCellRenderer but for headers
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -573,8 +579,18 @@ public:
|
|||||||
// whether the cell will draw the overflowed text to neighbour cells
|
// whether the cell will draw the overflowed text to neighbour cells
|
||||||
// currently only left aligned cells can overflow
|
// currently only left aligned cells can overflow
|
||||||
bool CanOverflow() const;
|
bool CanOverflow() const;
|
||||||
|
|
||||||
wxGridCellRenderer *GetRenderer(const wxGrid* grid, int row, int col) const;
|
wxGridCellRenderer *GetRenderer(const wxGrid* grid, int row, int col) const;
|
||||||
|
wxGridCellRendererPtr GetRendererPtr(const wxGrid* grid, int row, int col) const
|
||||||
|
{
|
||||||
|
return wxGridCellRendererPtr(GetRenderer(grid, row, col));
|
||||||
|
}
|
||||||
|
|
||||||
wxGridCellEditor *GetEditor(const wxGrid* grid, int row, int col) const;
|
wxGridCellEditor *GetEditor(const wxGrid* grid, int row, int col) const;
|
||||||
|
wxGridCellEditorPtr GetEditorPtr(const wxGrid* grid, int row, int col) const
|
||||||
|
{
|
||||||
|
return wxGridCellEditorPtr(GetEditor(grid, row, col));
|
||||||
|
}
|
||||||
|
|
||||||
bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; }
|
bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; }
|
||||||
|
|
||||||
|
@@ -95,6 +95,20 @@ protected:
|
|||||||
virtual ~wxGridCellRenderer();
|
virtual ~wxGridCellRenderer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Smart pointer wrapping wxGridCellRenderer.
|
||||||
|
|
||||||
|
wxGridCellRendererPtr takes ownership of wxGridCellRenderer passed to it on
|
||||||
|
construction and calls DecRef() on it automatically when it is destroyed.
|
||||||
|
It also provides transparent access to wxGridCellRenderer methods by allowing
|
||||||
|
to use objects of this class as if they were wxGridCellRenderer pointers.
|
||||||
|
|
||||||
|
@since 3.1.4
|
||||||
|
|
||||||
|
@category{grid}
|
||||||
|
*/
|
||||||
|
typedef wxObjectDataPtr<wxGridCellRenderer> wxGridCellRendererPtr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class wxGridCellAutoWrapStringRenderer
|
@class wxGridCellAutoWrapStringRenderer
|
||||||
|
|
||||||
@@ -591,6 +605,20 @@ protected:
|
|||||||
virtual ~wxGridCellEditor();
|
virtual ~wxGridCellEditor();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Smart pointer wrapping wxGridCellEditor.
|
||||||
|
|
||||||
|
wxGridCellEditorPtr takes ownership of wxGridCellEditor passed to it on
|
||||||
|
construction and calls DecRef() on it automatically when it is destroyed.
|
||||||
|
It also provides transparent access to wxGridCellEditor methods by allowing
|
||||||
|
to use objects of this class as if they were wxGridCellEditor pointers.
|
||||||
|
|
||||||
|
@since 3.1.4
|
||||||
|
|
||||||
|
@category{grid}
|
||||||
|
*/
|
||||||
|
typedef wxObjectDataPtr<wxGridCellEditor> wxGridCellEditorPtr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class wxGridCellAutoWrapStringEditor
|
@class wxGridCellAutoWrapStringEditor
|
||||||
|
|
||||||
@@ -1058,9 +1086,22 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the cell editor.
|
Returns the cell editor.
|
||||||
|
|
||||||
|
The caller is responsible for calling DecRef() on the returned pointer,
|
||||||
|
use GetEditorPtr() to do it automatically.
|
||||||
*/
|
*/
|
||||||
wxGridCellEditor* GetEditor(const wxGrid* grid, int row, int col) const;
|
wxGridCellEditor* GetEditor(const wxGrid* grid, int row, int col) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the cell editor.
|
||||||
|
|
||||||
|
This method is identical to GetEditor(), but returns a smart pointer,
|
||||||
|
which frees the caller from the need to call DecRef() manually.
|
||||||
|
|
||||||
|
@since 3.1.4
|
||||||
|
*/
|
||||||
|
wxGridCellEditorPtr GetEditorPtr(const wxGrid* grid, int row, int col) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the font.
|
Returns the font.
|
||||||
*/
|
*/
|
||||||
@@ -1091,9 +1132,22 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the cell renderer.
|
Returns the cell renderer.
|
||||||
|
|
||||||
|
The caller is responsible for calling DecRef() on the returned pointer,
|
||||||
|
use GetRendererPtr() to do it automatically.
|
||||||
*/
|
*/
|
||||||
wxGridCellRenderer* GetRenderer(const wxGrid* grid, int row, int col) const;
|
wxGridCellRenderer* GetRenderer(const wxGrid* grid, int row, int col) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the cell editor.
|
||||||
|
|
||||||
|
This method is identical to GetRenderer(), but returns a smart pointer,
|
||||||
|
which frees the caller from the need to call DecRef() manually.
|
||||||
|
|
||||||
|
@since 3.1.4
|
||||||
|
*/
|
||||||
|
wxGridCellRendererPtr GetRendererPtr(const wxGrid* grid, int row, int col) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the text colour.
|
Returns the text colour.
|
||||||
*/
|
*/
|
||||||
|
@@ -2838,7 +2838,7 @@ void wxGrid::CalcDimensions()
|
|||||||
|
|
||||||
// how big is the editor
|
// how big is the editor
|
||||||
wxGridCellAttrPtr attr = GetCellAttrPtr(r, c);
|
wxGridCellAttrPtr attr = GetCellAttrPtr(r, c);
|
||||||
wxGridCellEditor* editor = attr->GetEditor(this, r, c);
|
wxGridCellEditorPtr editor = attr->GetEditorPtr(this, r, c);
|
||||||
editor->GetWindow()->GetSize(&w2, &h2);
|
editor->GetWindow()->GetSize(&w2, &h2);
|
||||||
w2 += x;
|
w2 += x;
|
||||||
h2 += y;
|
h2 += y;
|
||||||
@@ -2846,7 +2846,6 @@ void wxGrid::CalcDimensions()
|
|||||||
w = w2;
|
w = w2;
|
||||||
if ( h2 > h )
|
if ( h2 > h )
|
||||||
h = h2;
|
h = h2;
|
||||||
editor->DecRef();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxPoint offset = GetGridWindowOffset(m_gridWin);
|
wxPoint offset = GetGridWindowOffset(m_gridWin);
|
||||||
@@ -4484,9 +4483,8 @@ wxGrid::DoGridCellLeftUp(wxMouseEvent& event,
|
|||||||
EnableCellEditControl();
|
EnableCellEditControl();
|
||||||
|
|
||||||
wxGridCellAttrPtr attr = GetCellAttrPtr(coords);
|
wxGridCellAttrPtr attr = GetCellAttrPtr(coords);
|
||||||
wxGridCellEditor *editor = attr->GetEditor(this, coords.GetRow(), coords.GetCol());
|
wxGridCellEditorPtr editor = attr->GetEditorPtr(this, coords.GetRow(), coords.GetCol());
|
||||||
editor->StartingClick();
|
editor->StartingClick();
|
||||||
editor->DecRef();
|
|
||||||
|
|
||||||
m_waitForSlowClick = false;
|
m_waitForSlowClick = false;
|
||||||
}
|
}
|
||||||
@@ -5728,7 +5726,7 @@ void wxGrid::OnChar( wxKeyEvent& event )
|
|||||||
int row = m_currentCellCoords.GetRow();
|
int row = m_currentCellCoords.GetRow();
|
||||||
int col = m_currentCellCoords.GetCol();
|
int col = m_currentCellCoords.GetCol();
|
||||||
wxGridCellAttrPtr attr = GetCellAttrPtr(row, col);
|
wxGridCellAttrPtr attr = GetCellAttrPtr(row, col);
|
||||||
wxGridCellEditor *editor = attr->GetEditor(this, row, col);
|
wxGridCellEditorPtr editor = attr->GetEditorPtr(this, row, col);
|
||||||
|
|
||||||
// <F2> is special and will always start editing, for
|
// <F2> is special and will always start editing, for
|
||||||
// other keys - ask the editor itself
|
// other keys - ask the editor itself
|
||||||
@@ -5750,8 +5748,6 @@ void wxGrid::OnChar( wxKeyEvent& event )
|
|||||||
{
|
{
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
editor->DecRef();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -6179,16 +6175,13 @@ void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords )
|
|||||||
// Note: However, only if it is really _shown_, i.e. not hidden!
|
// Note: However, only if it is really _shown_, i.e. not hidden!
|
||||||
if ( isCurrent && IsCellEditControlShown() )
|
if ( isCurrent && IsCellEditControlShown() )
|
||||||
{
|
{
|
||||||
wxGridCellEditor *editor = attr->GetEditor(this, row, col);
|
attr->GetEditorPtr(this, row, col)->PaintBackground(dc, rect, *attr);
|
||||||
editor->PaintBackground(dc, rect, *attr);
|
|
||||||
editor->DecRef();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// but all the rest is drawn by the cell renderer and hence may be customized
|
// but all the rest is drawn by the cell renderer and hence may be customized
|
||||||
wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col);
|
attr->GetRendererPtr(this, row, col)
|
||||||
renderer->Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords));
|
->Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords));
|
||||||
renderer->DecRef();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7084,16 +7077,13 @@ bool wxGrid::IsCellEditControlShown() const
|
|||||||
{
|
{
|
||||||
int row = m_currentCellCoords.GetRow();
|
int row = m_currentCellCoords.GetRow();
|
||||||
int col = m_currentCellCoords.GetCol();
|
int col = m_currentCellCoords.GetCol();
|
||||||
wxGridCellEditor* editor = GetCellAttrPtr(row, col)->GetEditor(this, row, col);
|
wxGridCellEditorPtr editor = GetCellAttrPtr(row, col)->GetEditorPtr(this, row, col);
|
||||||
|
|
||||||
if ( editor )
|
if ( editor )
|
||||||
{
|
{
|
||||||
if ( editor->IsCreated() )
|
if ( editor->IsCreated() )
|
||||||
{
|
{
|
||||||
isShown = editor->GetWindow()->IsShown();
|
isShown = editor->GetWindow()->IsShown();
|
||||||
}
|
}
|
||||||
|
|
||||||
editor->DecRef();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7153,11 +7143,11 @@ void wxGrid::ShowCellEditControl()
|
|||||||
rect.Deflate(1, 1);
|
rect.Deflate(1, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxGridCellEditor* editor = attr->GetEditor(this, row, col);
|
wxGridCellEditorPtr editor = attr->GetEditorPtr(this, row, col);
|
||||||
if ( !editor->IsCreated() )
|
if ( !editor->IsCreated() )
|
||||||
{
|
{
|
||||||
editor->Create(gridWindow, wxID_ANY,
|
editor->Create(gridWindow, wxID_ANY,
|
||||||
new wxGridCellEditorEvtHandler(this, editor));
|
new wxGridCellEditorEvtHandler(this, editor.get()));
|
||||||
|
|
||||||
// Ensure the editor window has wxWANTS_CHARS flag, so that it
|
// Ensure the editor window has wxWANTS_CHARS flag, so that it
|
||||||
// gets Tab, Enter and Esc keys, which need to be processed
|
// gets Tab, Enter and Esc keys, which need to be processed
|
||||||
@@ -7235,8 +7225,6 @@ void wxGrid::ShowCellEditControl()
|
|||||||
|
|
||||||
editor->BeginEdit(row, col, this);
|
editor->BeginEdit(row, col, this);
|
||||||
editor->SetCellAttr(NULL);
|
editor->SetCellAttr(NULL);
|
||||||
|
|
||||||
editor->DecRef();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7249,14 +7237,13 @@ void wxGrid::HideCellEditControl()
|
|||||||
int col = m_currentCellCoords.GetCol();
|
int col = m_currentCellCoords.GetCol();
|
||||||
|
|
||||||
wxGridCellAttrPtr attr = GetCellAttrPtr(row, col);
|
wxGridCellAttrPtr attr = GetCellAttrPtr(row, col);
|
||||||
wxGridCellEditor *editor = attr->GetEditor(this, row, col);
|
wxGridCellEditorPtr editor = attr->GetEditorPtr(this, row, col);
|
||||||
const bool editorHadFocus = editor->GetWindow()->IsDescendant(FindFocus());
|
const bool editorHadFocus = editor->GetWindow()->IsDescendant(FindFocus());
|
||||||
|
|
||||||
if ( editor->GetWindow()->GetParent() != m_gridWin )
|
if ( editor->GetWindow()->GetParent() != m_gridWin )
|
||||||
editor->GetWindow()->Reparent(m_gridWin);
|
editor->GetWindow()->Reparent(m_gridWin);
|
||||||
|
|
||||||
editor->Show( false );
|
editor->Show( false );
|
||||||
editor->DecRef();
|
|
||||||
|
|
||||||
wxGridWindow *gridWindow = CellToGridWindow(row, col);
|
wxGridWindow *gridWindow = CellToGridWindow(row, col);
|
||||||
// return the focus to the grid itself if the editor had it
|
// return the focus to the grid itself if the editor had it
|
||||||
@@ -7312,7 +7299,7 @@ void wxGrid::DoSaveEditControlValue()
|
|||||||
wxString oldval = GetCellValue(row, col);
|
wxString oldval = GetCellValue(row, col);
|
||||||
|
|
||||||
wxGridCellAttrPtr attr = GetCellAttrPtr(row, col);
|
wxGridCellAttrPtr attr = GetCellAttrPtr(row, col);
|
||||||
wxGridCellEditor* editor = attr->GetEditor(this, row, col);
|
wxGridCellEditorPtr editor = attr->GetEditorPtr(this, row, col);
|
||||||
|
|
||||||
wxString newval;
|
wxString newval;
|
||||||
bool changed = editor->EndEdit(row, col, this, oldval, &newval);
|
bool changed = editor->EndEdit(row, col, this, oldval, &newval);
|
||||||
@@ -7330,8 +7317,6 @@ void wxGrid::DoSaveEditControlValue()
|
|||||||
SetCellValue(row, col, oldval);
|
SetCellValue(row, col, oldval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
editor->DecRef();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGrid::OnHideEditor(wxCommandEvent& WXUNUSED(event))
|
void wxGrid::OnHideEditor(wxCommandEvent& WXUNUSED(event))
|
||||||
@@ -9475,7 +9460,7 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
|
|||||||
|
|
||||||
// get cell ( main cell if CellSpan_Inside ) renderer best size
|
// get cell ( main cell if CellSpan_Inside ) renderer best size
|
||||||
wxGridCellAttrPtr attr = GetCellAttrPtr(row, col);
|
wxGridCellAttrPtr attr = GetCellAttrPtr(row, col);
|
||||||
wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col);
|
wxGridCellRendererPtr renderer = attr->GetRendererPtr(this, row, col);
|
||||||
if ( renderer )
|
if ( renderer )
|
||||||
{
|
{
|
||||||
extent = column
|
extent = column
|
||||||
@@ -9498,8 +9483,6 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
|
|||||||
|
|
||||||
if ( extent > extentMax )
|
if ( extent > extentMax )
|
||||||
extentMax = extent;
|
extentMax = extent;
|
||||||
|
|
||||||
renderer->DecRef();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10396,15 +10379,11 @@ int wxGridTypeRegistry::FindOrCloneDataType(const wxString& typeName)
|
|||||||
return wxNOT_FOUND;
|
return wxNOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGridCellRenderer *renderer = GetRenderer(index);
|
wxGridCellRenderer* const
|
||||||
wxGridCellRenderer *rendererOld = renderer;
|
renderer = wxGridCellRendererPtr(GetRenderer(index))->Clone();
|
||||||
renderer = renderer->Clone();
|
|
||||||
rendererOld->DecRef();
|
|
||||||
|
|
||||||
wxGridCellEditor *editor = GetEditor(index);
|
wxGridCellEditor* const
|
||||||
wxGridCellEditor *editorOld = editor;
|
editor = wxGridCellEditorPtr(GetEditor(index))->Clone();
|
||||||
editor = editor->Clone();
|
|
||||||
editorOld->DecRef();
|
|
||||||
|
|
||||||
// do it even if there are no parameters to reset them to defaults
|
// do it even if there are no parameters to reset them to defaults
|
||||||
wxString params = typeName.AfterFirst(wxT(':'));
|
wxString params = typeName.AfterFirst(wxT(':'));
|
||||||
|
Reference in New Issue
Block a user