Create model and column in wxDataViewTreeCtrl::Create(), not ctor.
Old code created the tree model and its unique built-in column only in wxDataViewTreeCtrl ctor but not in Create(), meaning that the behaviour was very different depending on whether you used base class ctor call or Create() in a derived class. This was confusing and completely inconsistent with wx API in which using the default ctor and Create() is supposed to always have exactly the same effect as using non-default ctor so change this to create the model in Create() so that it's always done. Slightly update the documentation and also add wxDataViewTreeCtrl::Init() for consistency. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62498 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1327,17 +1327,27 @@ public:
|
|||||||
class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
|
class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDataViewTreeCtrl();
|
wxDataViewTreeCtrl() { Init(); }
|
||||||
wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id,
|
wxDataViewTreeCtrl(wxWindow *parent,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
wxWindowID id,
|
||||||
const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxValidator& validator = wxDefaultValidator );
|
const wxSize& size = wxDefaultSize,
|
||||||
~wxDataViewTreeCtrl();
|
long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
|
||||||
|
const wxValidator& validator = wxDefaultValidator)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
bool Create( wxWindow *parent, wxWindowID id,
|
Create(parent, id, pos, size, style, validator);
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
}
|
||||||
const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
|
|
||||||
const wxValidator& validator = wxDefaultValidator );
|
virtual ~wxDataViewTreeCtrl();
|
||||||
|
|
||||||
|
bool Create(wxWindow *parent,
|
||||||
|
wxWindowID id,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
|
||||||
|
const wxValidator& validator = wxDefaultValidator);
|
||||||
|
|
||||||
wxDataViewTreeStore *GetStore()
|
wxDataViewTreeStore *GetStore()
|
||||||
{ return (wxDataViewTreeStore*) GetModel(); }
|
{ return (wxDataViewTreeStore*) GetModel(); }
|
||||||
@@ -1392,7 +1402,12 @@ public:
|
|||||||
void OnSize( wxSizeEvent &event );
|
void OnSize( wxSizeEvent &event );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxImageList *m_imageList;
|
void Init()
|
||||||
|
{
|
||||||
|
m_imageList = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxImageList *m_imageList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
@@ -71,7 +71,7 @@
|
|||||||
wxDataViewModel *musicModel = new MyMusicModel;
|
wxDataViewModel *musicModel = new MyMusicModel;
|
||||||
m_musicCtrl->AssociateModel( musicModel );
|
m_musicCtrl->AssociateModel( musicModel );
|
||||||
musicModel->DecRef(); // avoid memory leak !!
|
musicModel->DecRef(); // avoid memory leak !!
|
||||||
|
|
||||||
// add columns now
|
// add columns now
|
||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
@@ -1611,11 +1611,11 @@ public:
|
|||||||
data.push_back( wxVariant("row 3") );
|
data.push_back( wxVariant("row 3") );
|
||||||
listctrl->AppendItem( data );
|
listctrl->AppendItem( data );
|
||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
@beginStyleTable
|
@beginStyleTable
|
||||||
See wxDataViewCtrl for the list of supported styles.
|
See wxDataViewCtrl for the list of supported styles.
|
||||||
@endStyleTable
|
@endStyleTable
|
||||||
|
|
||||||
@beginEventEmissionTable
|
@beginEventEmissionTable
|
||||||
See wxDataViewCtrl for the list of events emitted by this class.
|
See wxDataViewCtrl for the list of events emitted by this class.
|
||||||
@endEventTable
|
@endEventTable
|
||||||
@@ -1664,7 +1664,7 @@ public:
|
|||||||
@name Column management functions
|
@name Column management functions
|
||||||
*/
|
*/
|
||||||
//@{
|
//@{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Appends a column to the control and additionally appends a
|
Appends a column to the control and additionally appends a
|
||||||
column to the store with the type string.
|
column to the store with the type string.
|
||||||
@@ -1679,24 +1679,24 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Appends a text column to the control and the store.
|
Appends a text column to the control and the store.
|
||||||
|
|
||||||
See wxDataViewColumn::wxDataViewColumn for more info about
|
See wxDataViewColumn::wxDataViewColumn for more info about
|
||||||
the parameters.
|
the parameters.
|
||||||
*/
|
*/
|
||||||
wxDataViewColumn *AppendTextColumn( const wxString &label,
|
wxDataViewColumn *AppendTextColumn( const wxString &label,
|
||||||
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
||||||
int width = -1, wxAlignment align = wxALIGN_LEFT,
|
int width = -1, wxAlignment align = wxALIGN_LEFT,
|
||||||
int flags = wxDATAVIEW_COL_RESIZABLE );
|
int flags = wxDATAVIEW_COL_RESIZABLE );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Appends a toggle column to the control and the store.
|
Appends a toggle column to the control and the store.
|
||||||
|
|
||||||
See wxDataViewColumn::wxDataViewColumn for more info about
|
See wxDataViewColumn::wxDataViewColumn for more info about
|
||||||
the parameters.
|
the parameters.
|
||||||
*/
|
*/
|
||||||
wxDataViewColumn *AppendToggleColumn( const wxString &label,
|
wxDataViewColumn *AppendToggleColumn( const wxString &label,
|
||||||
wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
|
||||||
int width = -1, wxAlignment align = wxALIGN_LEFT,
|
int width = -1, wxAlignment align = wxALIGN_LEFT,
|
||||||
int flags = wxDATAVIEW_COL_RESIZABLE );
|
int flags = wxDATAVIEW_COL_RESIZABLE );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1707,7 +1707,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
wxDataViewColumn *AppendProgressColumn( const wxString &label,
|
wxDataViewColumn *AppendProgressColumn( const wxString &label,
|
||||||
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
||||||
int width = -1, wxAlignment align = wxALIGN_LEFT,
|
int width = -1, wxAlignment align = wxALIGN_LEFT,
|
||||||
int flags = wxDATAVIEW_COL_RESIZABLE );
|
int flags = wxDATAVIEW_COL_RESIZABLE );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1718,7 +1718,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
wxDataViewColumn *AppendIconTextColumn( const wxString &label,
|
wxDataViewColumn *AppendIconTextColumn( const wxString &label,
|
||||||
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
||||||
int width = -1, wxAlignment align = wxALIGN_LEFT,
|
int width = -1, wxAlignment align = wxALIGN_LEFT,
|
||||||
int flags = wxDATAVIEW_COL_RESIZABLE );
|
int flags = wxDATAVIEW_COL_RESIZABLE );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1731,7 +1731,7 @@ public:
|
|||||||
Inserts a column to the control and additionally inserts a
|
Inserts a column to the control and additionally inserts a
|
||||||
column to the list store with the type @a varianttype.
|
column to the list store with the type @a varianttype.
|
||||||
*/
|
*/
|
||||||
void InsertColumn( unsigned int pos, wxDataViewColumn *column,
|
void InsertColumn( unsigned int pos, wxDataViewColumn *column,
|
||||||
const wxString &varianttype );
|
const wxString &varianttype );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1747,13 +1747,13 @@ public:
|
|||||||
void PrependColumn( wxDataViewColumn *column, const wxString &varianttype );
|
void PrependColumn( wxDataViewColumn *column, const wxString &varianttype );
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@name Item management functions
|
@name Item management functions
|
||||||
*/
|
*/
|
||||||
//@{
|
//@{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Appends an item (=row) to the control and store.
|
Appends an item (=row) to the control and store.
|
||||||
*/
|
*/
|
||||||
@@ -1820,7 +1820,7 @@ public:
|
|||||||
respective column.
|
respective column.
|
||||||
*/
|
*/
|
||||||
bool GetToggleValue( unsigned int row, unsigned int col ) const;
|
bool GetToggleValue( unsigned int row, unsigned int col ) const;
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1832,13 +1832,13 @@ public:
|
|||||||
and forwards most of its API to that class.
|
and forwards most of its API to that class.
|
||||||
Additionally, it uses a wxImageList to store a list of icons.
|
Additionally, it uses a wxImageList to store a list of icons.
|
||||||
|
|
||||||
The main purpose of this class is to represent a possible replacement for
|
The main purpose of this class is to provide a simple upgrade path for code
|
||||||
wxTreeCtrl.
|
using wxTreeCtrl.
|
||||||
|
|
||||||
@beginStyleTable
|
@beginStyleTable
|
||||||
See wxDataViewCtrl for the list of supported styles.
|
See wxDataViewCtrl for the list of supported styles.
|
||||||
@endStyleTable
|
@endStyleTable
|
||||||
|
|
||||||
@beginEventEmissionTable
|
@beginEventEmissionTable
|
||||||
See wxDataViewCtrl for the list of events emitted by this class.
|
See wxDataViewCtrl for the list of events emitted by this class.
|
||||||
@endEventTable
|
@endEventTable
|
||||||
@@ -1856,12 +1856,14 @@ public:
|
|||||||
wxDataViewTreeCtrl();
|
wxDataViewTreeCtrl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructor. Calls Create().
|
Constructor.
|
||||||
|
|
||||||
|
Calls Create().
|
||||||
*/
|
*/
|
||||||
wxDataViewTreeCtrl(wxWindow* parent, wxWindowID id,
|
wxDataViewTreeCtrl(wxWindow* parent, wxWindowID id,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
long style = wxDV_NO_HEADER,
|
long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
|
||||||
const wxValidator& validator = wxDefaultValidator);
|
const wxValidator& validator = wxDefaultValidator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1888,11 +1890,14 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the control and a wxDataViewTreeStore as its internal model.
|
Creates the control and a wxDataViewTreeStore as its internal model.
|
||||||
|
|
||||||
|
The default tree column created by this method is an editable column
|
||||||
|
using wxDataViewIconTextRenderer as its renderer.
|
||||||
*/
|
*/
|
||||||
bool Create(wxWindow* parent, wxWindowID id,
|
bool Create(wxWindow* parent, wxWindowID id,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
long style = wxDV_NO_HEADER,
|
long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
|
||||||
const wxValidator& validator = wxDefaultValidator);
|
const wxValidator& validator = wxDefaultValidator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2375,7 +2380,7 @@ public:
|
|||||||
@event{EVT_DATAVIEW_CACHE_HINT(id, func)}
|
@event{EVT_DATAVIEW_CACHE_HINT(id, func)}
|
||||||
Process a @c wxEVT_COMMAND_DATAVIEW_CACHE_HINT event.
|
Process a @c wxEVT_COMMAND_DATAVIEW_CACHE_HINT event.
|
||||||
@endEventTable
|
@endEventTable
|
||||||
|
|
||||||
@library{wxadv}
|
@library{wxadv}
|
||||||
@category{events,dvc}
|
@category{events,dvc}
|
||||||
*/
|
*/
|
||||||
|
@@ -2011,40 +2011,30 @@ BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl)
|
|||||||
EVT_SIZE( wxDataViewTreeCtrl::OnSize )
|
EVT_SIZE( wxDataViewTreeCtrl::OnSize )
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
wxDataViewTreeCtrl::wxDataViewTreeCtrl()
|
|
||||||
{
|
|
||||||
m_imageList = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id,
|
|
||||||
const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
|
|
||||||
{
|
|
||||||
m_imageList = NULL;
|
|
||||||
Create( parent, id, pos, size, style, validator );
|
|
||||||
|
|
||||||
wxDataViewTreeStore *store = new wxDataViewTreeStore;
|
|
||||||
AssociateModel( store );
|
|
||||||
store->DecRef();
|
|
||||||
|
|
||||||
AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT,-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
|
wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
|
||||||
{
|
{
|
||||||
if (m_imageList)
|
delete m_imageList;
|
||||||
delete m_imageList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id,
|
bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id,
|
||||||
const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
|
const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
|
||||||
{
|
{
|
||||||
return wxDataViewCtrl::Create( parent, id, pos, size, style, validator );
|
if ( !wxDataViewCtrl::Create( parent, id, pos, size, style, validator ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// create the standard model and a column in the tree
|
||||||
|
wxDataViewTreeStore *store = new wxDataViewTreeStore;
|
||||||
|
AssociateModel( store );
|
||||||
|
store->DecRef();
|
||||||
|
|
||||||
|
AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_EDITABLE,-1);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewTreeCtrl::SetImageList( wxImageList *imagelist )
|
void wxDataViewTreeCtrl::SetImageList( wxImageList *imagelist )
|
||||||
{
|
{
|
||||||
if (m_imageList)
|
delete m_imageList;
|
||||||
delete m_imageList;
|
|
||||||
|
|
||||||
m_imageList = imagelist;
|
m_imageList = imagelist;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user