Replace macros with wxVector<> for wxDataViewModelNotifiers

Don't use deprecated macro-based linked list class, use wxVector<>
instead for m_notifiers.

Also make it private, as it should have been from the beginning.
This commit is contained in:
Vadim Zeitlin 2018-02-03 20:00:08 +01:00
parent 30f73aea6a
commit bb0a2952b1
2 changed files with 29 additions and 10 deletions

View File

@ -27,6 +27,7 @@
#include "wx/dataobj.h"
#include "wx/withimages.h"
#include "wx/systhemectrl.h"
#include "wx/vector.h"
class WXDLLIMPEXP_FWD_CORE wxImageList;
class wxItemAttr;
@ -179,8 +180,7 @@ private:
// wxDataViewModel
// ---------------------------------------------------------
WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier, wxDataViewModelNotifiers,
class WXDLLIMPEXP_ADV);
typedef wxVector<wxDataViewModelNotifier*> wxDataViewModelNotifiers;
class WXDLLIMPEXP_ADV wxDataViewModel: public wxRefCounter
{
@ -273,8 +273,9 @@ public:
virtual bool IsVirtualListModel() const { return false; }
protected:
// the user should not delete this class directly: he should use DecRef() instead!
virtual ~wxDataViewModel() { }
// Dtor is protected because the objects of this class must not be deleted,
// DecRef() must be used instead.
virtual ~wxDataViewModel();
// Helper function used by the default Compare() implementation to compare
// values of types it is not aware about. Can be overridden in the derived
@ -285,7 +286,7 @@ protected:
return 0;
}
private:
wxDataViewModelNotifiers m_notifiers;
};

View File

@ -95,9 +95,6 @@ wxFont wxDataViewItemAttr::GetEffectiveFont(const wxFont& font) const
// wxDataViewModelNotifier
// ---------------------------------------------------------
#include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxDataViewModelNotifiers)
bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
{
size_t count = items.GetCount();
@ -134,7 +131,15 @@ bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray &items )
wxDataViewModel::wxDataViewModel()
{
m_notifiers.DeleteContents( true );
}
wxDataViewModel::~wxDataViewModel()
{
wxDataViewModelNotifiers::const_iterator iter;
for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
{
delete *iter;
}
}
bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
@ -305,7 +310,20 @@ void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier )
void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
{
m_notifiers.DeleteObject( notifier );
wxDataViewModelNotifiers::iterator iter;
for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
{
if ( *iter == notifier )
{
delete notifier;
m_notifiers.erase(iter);
// Skip the assert below.
return;
}
}
wxFAIL_MSG(wxS("Removing non-registered notifier"));
}
int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,