Split wxDataViewVirtualModel fork wxDataViewIndexModel to make the code clearer and let wxDataViewIndexModel behave the same on all platforms
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53077 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
2edac25b2e
commit
e39de7022c
@ -224,7 +224,7 @@ public:
|
||||
virtual bool HasDefaultCompare() const { return false; }
|
||||
|
||||
// internal
|
||||
virtual bool IsIndexListModel() const { return false; }
|
||||
virtual bool IsVirtualListModel() const { return false; }
|
||||
|
||||
protected:
|
||||
// the user should not delete this class directly: he should use DecRef() instead!
|
||||
@ -284,7 +284,7 @@ public:
|
||||
virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
|
||||
|
||||
// internal
|
||||
virtual bool IsIndexListModel() const { return true; }
|
||||
virtual bool IsVirtualListModel() const { return false; }
|
||||
unsigned int GetLastIndex() const { return m_lastIndex; }
|
||||
|
||||
private:
|
||||
@ -294,6 +294,71 @@ private:
|
||||
bool m_useHash;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// wxDataViewVirtualListModel
|
||||
// ---------------------------------------------------------
|
||||
|
||||
#ifdef __WXMAC__
|
||||
// better than nothing
|
||||
typedef wxDataViewVirtualListModel wxDataViewIndexListModel
|
||||
#else
|
||||
|
||||
class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewModel
|
||||
{
|
||||
public:
|
||||
wxDataViewVirtualListModel( unsigned int initial_size = 0 );
|
||||
~wxDataViewVirtualListModel();
|
||||
|
||||
virtual void GetValue( wxVariant &variant,
|
||||
unsigned int row, unsigned int col ) const = 0;
|
||||
|
||||
virtual bool SetValue( const wxVariant &variant,
|
||||
unsigned int row, unsigned int col ) = 0;
|
||||
|
||||
virtual bool GetAttr( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
|
||||
{ return false; }
|
||||
|
||||
void RowPrepended();
|
||||
void RowInserted( unsigned int before );
|
||||
void RowAppended();
|
||||
void RowDeleted( unsigned int row );
|
||||
void RowsDeleted( const wxArrayInt &rows );
|
||||
void RowChanged( unsigned int row );
|
||||
void RowValueChanged( unsigned int row, unsigned int col );
|
||||
void Reset( unsigned int new_size );
|
||||
|
||||
// convert to/from row/wxDataViewItem
|
||||
|
||||
unsigned int GetRow( const wxDataViewItem &item ) const;
|
||||
wxDataViewItem GetItem( unsigned int row ) const;
|
||||
|
||||
// compare based on index
|
||||
|
||||
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
||||
unsigned int column, bool ascending );
|
||||
virtual bool HasDefaultCompare() const;
|
||||
|
||||
// implement base methods
|
||||
|
||||
virtual void GetValue( wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col ) const;
|
||||
virtual bool SetValue( const wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col );
|
||||
virtual bool GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr );
|
||||
virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
|
||||
virtual bool IsContainer( const wxDataViewItem &item ) const;
|
||||
virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
|
||||
|
||||
// internal
|
||||
virtual bool IsVirtualListModel() const { return true; }
|
||||
unsigned int GetLastIndex() const { return m_lastIndex; }
|
||||
|
||||
private:
|
||||
wxDataViewItemArray m_hash;
|
||||
unsigned int m_lastIndex;
|
||||
bool m_ordered;
|
||||
};
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDataViewEditorCtrlEvtHandler
|
||||
|
@ -136,13 +136,6 @@ public:
|
||||
unsigned int WXUNUSED(col) )
|
||||
{ return false; }
|
||||
|
||||
virtual bool RightClick( wxPoint WXUNUSED(cursor),
|
||||
wxRect WXUNUSED(cell),
|
||||
wxDataViewModel *WXUNUSED(model),
|
||||
const wxDataViewItem & WXUNUSED(item),
|
||||
unsigned int WXUNUSED(col) )
|
||||
{ return false; }
|
||||
|
||||
virtual bool StartDrag( wxPoint WXUNUSED(cursor),
|
||||
wxRect WXUNUSED(cell),
|
||||
wxDataViewModel *WXUNUSED(model),
|
||||
|
@ -155,127 +155,6 @@ public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@class wxDataViewIndexListModel
|
||||
@wxheader{dataview.h}
|
||||
|
||||
wxDataViewIndexListModel is a specialized data model which lets
|
||||
you address an item by its position (row) rather than its
|
||||
wxDataViewItem (which you can obtain from this class).
|
||||
This model also provides its own
|
||||
wxDataViewIndexListModel::Compare method
|
||||
which sorts the model's data by the index.
|
||||
|
||||
This model is special in the it is implemented differently under OS X
|
||||
and other platforms. Under OS X a wxDataViewItem is always persistent
|
||||
and this is also the case for this class. Under other platforms, the
|
||||
meaning of a wxDataViewItem is changed to reflect a row number for
|
||||
wxDataViewIndexListModel. The consequence of this is that
|
||||
wxDataViewIndexListModel can be used as a virtual model with an
|
||||
almost infinate number of items on platforms other than OS X.
|
||||
|
||||
@library{wxbase}
|
||||
@category{FIXME}
|
||||
*/
|
||||
class wxDataViewIndexListModel : public wxDataViewModel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
*/
|
||||
wxDataViewIndexListModel(unsigned int initial_size = 0);
|
||||
|
||||
/**
|
||||
Destructor.
|
||||
*/
|
||||
~wxDataViewIndexListModel();
|
||||
|
||||
/**
|
||||
Compare method that sorts the items by their index.
|
||||
*/
|
||||
int Compare(const wxDataViewItem& item1,
|
||||
const wxDataViewItem& item2,
|
||||
unsigned int column, bool ascending);
|
||||
|
||||
/**
|
||||
Oberride this to indicate that the row has special font attributes.
|
||||
This only affects the
|
||||
wxDataViewTextRendererText() renderer.
|
||||
See also wxDataViewItemAttr.
|
||||
*/
|
||||
bool GetAttr(unsigned int row, unsigned int col,
|
||||
wxDataViewItemAttr& attr);
|
||||
|
||||
/**
|
||||
Returns the wxDataViewItem at the given @e row.
|
||||
*/
|
||||
wxDataViewItem GetItem(unsigned int row) const;
|
||||
|
||||
/**
|
||||
Returns the position of given @e item.
|
||||
*/
|
||||
unsigned int GetRow(const wxDataViewItem& item) const;
|
||||
|
||||
/**
|
||||
Override this to allow getting values from the model.
|
||||
*/
|
||||
void GetValue(wxVariant& variant, unsigned int row,
|
||||
unsigned int col) const;
|
||||
|
||||
/**
|
||||
Call this after if the data has to be read again from
|
||||
the model. This is useful after major changes when
|
||||
calling the methods below (possibly thousands of times)
|
||||
doesn't make sense.
|
||||
*/
|
||||
void Reset(unsigned int new_size);
|
||||
|
||||
/**
|
||||
Call this after a row has been appended to the model.
|
||||
*/
|
||||
void RowAppended();
|
||||
|
||||
/**
|
||||
Call this after a row has been changed.
|
||||
*/
|
||||
void RowChanged(unsigned int row);
|
||||
|
||||
/**
|
||||
Call this after a row has been deleted.
|
||||
*/
|
||||
void RowDeleted(unsigned int row);
|
||||
|
||||
/**
|
||||
Call this after a row has been inserted at the given position.
|
||||
*/
|
||||
void RowInserted(unsigned int before);
|
||||
|
||||
/**
|
||||
Call this after a row has been prepended to the model.
|
||||
*/
|
||||
void RowPrepended();
|
||||
|
||||
/**
|
||||
Call this after a value has been changed.
|
||||
*/
|
||||
void RowValueChanged(unsigned int row, unsigned int col);
|
||||
|
||||
/**
|
||||
Call this after rows have been deleted. The array will internally
|
||||
get copied and sorted in descending order so that the rows with
|
||||
the highest position will be deleted first.
|
||||
*/
|
||||
void RowsDeleted(const wxArrayInt& rows);
|
||||
|
||||
/**
|
||||
Called in order to set a value in the model.
|
||||
*/
|
||||
bool SetValue(const wxVariant& variant, unsigned int row,
|
||||
unsigned int col);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@class wxDataViewModel
|
||||
@wxheader{dataview.h}
|
||||
@ -341,6 +220,7 @@ public:
|
||||
Currently wxWidgets provides the following models apart
|
||||
from the base model:
|
||||
wxDataViewIndexListModel,
|
||||
wxDataViewVirtualListModel,
|
||||
wxDataViewTreeStore.
|
||||
|
||||
Note that wxDataViewModel is reference counted, derives from
|
||||
@ -542,6 +422,154 @@ public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@class wxDataViewIndexListModel
|
||||
@wxheader{dataview.h}
|
||||
|
||||
wxDataViewIndexListModel is a specialized data model which lets
|
||||
you address an item by its position (row) rather than its
|
||||
wxDataViewItem (which you can obtain from this class).
|
||||
This model also provides its own wxDataViewIndexListModel::Compare
|
||||
method which sorts the model's data by the index.
|
||||
|
||||
This model is not a virtual model since the control stores
|
||||
each wxDataViewItem. Use wxDataViewVirtualListModel if you
|
||||
need to display millions of items or have other reason to
|
||||
use a virtual control.
|
||||
|
||||
@library{wxbase}
|
||||
@category{FIXME}
|
||||
*/
|
||||
class wxDataViewIndexListModel : public wxDataViewModel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
*/
|
||||
wxDataViewIndexListModel(unsigned int initial_size = 0);
|
||||
|
||||
/**
|
||||
Destructor.
|
||||
*/
|
||||
~wxDataViewIndexListModel();
|
||||
|
||||
/**
|
||||
Compare method that sorts the items by their index.
|
||||
*/
|
||||
int Compare(const wxDataViewItem& item1,
|
||||
const wxDataViewItem& item2,
|
||||
unsigned int column, bool ascending);
|
||||
|
||||
/**
|
||||
Oberride this to indicate that the row has special font attributes.
|
||||
This only affects the
|
||||
wxDataViewTextRendererText() renderer.
|
||||
See also wxDataViewItemAttr.
|
||||
*/
|
||||
bool GetAttr(unsigned int row, unsigned int col,
|
||||
wxDataViewItemAttr& attr);
|
||||
|
||||
/**
|
||||
Returns the wxDataViewItem at the given @e row.
|
||||
*/
|
||||
wxDataViewItem GetItem(unsigned int row) const;
|
||||
|
||||
/**
|
||||
Returns the position of given @e item.
|
||||
*/
|
||||
unsigned int GetRow(const wxDataViewItem& item) const;
|
||||
|
||||
/**
|
||||
Override this to allow getting values from the model.
|
||||
*/
|
||||
void GetValue(wxVariant& variant, unsigned int row,
|
||||
unsigned int col) const;
|
||||
|
||||
/**
|
||||
Call this after if the data has to be read again from
|
||||
the model. This is useful after major changes when
|
||||
calling the methods below (possibly thousands of times)
|
||||
doesn't make sense.
|
||||
*/
|
||||
void Reset(unsigned int new_size);
|
||||
|
||||
/**
|
||||
Call this after a row has been appended to the model.
|
||||
*/
|
||||
void RowAppended();
|
||||
|
||||
/**
|
||||
Call this after a row has been changed.
|
||||
*/
|
||||
void RowChanged(unsigned int row);
|
||||
|
||||
/**
|
||||
Call this after a row has been deleted.
|
||||
*/
|
||||
void RowDeleted(unsigned int row);
|
||||
|
||||
/**
|
||||
Call this after a row has been inserted at the given position.
|
||||
*/
|
||||
void RowInserted(unsigned int before);
|
||||
|
||||
/**
|
||||
Call this after a row has been prepended to the model.
|
||||
*/
|
||||
void RowPrepended();
|
||||
|
||||
/**
|
||||
Call this after a value has been changed.
|
||||
*/
|
||||
void RowValueChanged(unsigned int row, unsigned int col);
|
||||
|
||||
/**
|
||||
Call this after rows have been deleted. The array will internally
|
||||
get copied and sorted in descending order so that the rows with
|
||||
the highest position will be deleted first.
|
||||
*/
|
||||
void RowsDeleted(const wxArrayInt& rows);
|
||||
|
||||
/**
|
||||
Called in order to set a value in the model.
|
||||
*/
|
||||
bool SetValue(const wxVariant& variant, unsigned int row,
|
||||
unsigned int col);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@class wxDataViewVirtualListModel
|
||||
@wxheader{dataview.h}
|
||||
|
||||
wxDataViewVirtualListModel is a specialized data model which lets
|
||||
you address an item by its position (row) rather than its
|
||||
wxDataViewItem and as such offers the exact same interface as
|
||||
wxDataViewIndexListModel. The important difference is that under
|
||||
platforms other than OS X, using this model will result in a
|
||||
truely virtual control able to handle millions of items as the
|
||||
control doesn't store any item (a feature not supported by the
|
||||
Carbon API under OS X).
|
||||
|
||||
@see wxDataViewIndexListModel for the API.
|
||||
|
||||
@library{wxbase}
|
||||
@category{FIXME}
|
||||
*/
|
||||
class wxDataViewVirtualListModel : public wxDataViewModel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
*/
|
||||
wxDataViewVirtualListModel(unsigned int initial_size = 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@class wxDataViewItemAttr
|
||||
@wxheader{dataview.h}
|
||||
@ -703,6 +731,14 @@ public:
|
||||
*/
|
||||
~wxDataViewCtrl();
|
||||
|
||||
/**
|
||||
Add a wxDataViewColumn to the control. Returns
|
||||
@e @true on success.
|
||||
Note that there is a number of short cut methods which implicitly create
|
||||
a wxDataViewColumn and a wxDataViewRenderer for it (see below).
|
||||
*/
|
||||
virtual bool AppendColumn(wxDataViewColumn* col);
|
||||
|
||||
//@{
|
||||
/**
|
||||
Appends a column for rendering a bitmap. Returns the wxDataViewColumn
|
||||
@ -722,19 +758,13 @@ public:
|
||||
int flags = wxDATAVIEW_COL_RESIZABLE);
|
||||
//@}
|
||||
|
||||
/**
|
||||
Add a wxDataViewColumn to the control. Returns
|
||||
@e @true on success.
|
||||
Note that there is a number of short cut methods which implicitly create
|
||||
a wxDataViewColumn and a
|
||||
wxDataViewRenderer for it (see below).
|
||||
*/
|
||||
virtual bool AppendColumn(wxDataViewColumn* col);
|
||||
|
||||
//@{
|
||||
/**
|
||||
Appends a column for rendering a date. Returns the wxDataViewColumn
|
||||
created in the function or @NULL on failure.
|
||||
|
||||
NB: The @e align parameter is applied to both the column header and
|
||||
the column renderer.
|
||||
*/
|
||||
wxDataViewColumn* AppendDateColumn(const wxString& label,
|
||||
unsigned int model_column,
|
||||
@ -753,8 +783,11 @@ public:
|
||||
//@{
|
||||
/**
|
||||
Appends a column for rendering text with an icon. Returns the wxDataViewColumn
|
||||
created in the function or @NULL on failure. This uses the
|
||||
wxDataViewIconTextRenderer.
|
||||
created in the function or @NULL on failure. This method uses the
|
||||
wxDataViewIconTextRenderer class.
|
||||
|
||||
NB: The @e align parameter is applied to both the column header and
|
||||
the column renderer.
|
||||
*/
|
||||
wxDataViewColumn* AppendIconTextColumn(const wxString& label,
|
||||
unsigned int model_column,
|
||||
@ -773,8 +806,10 @@ public:
|
||||
//@{
|
||||
/**
|
||||
Appends a column for rendering a progress indicator. Returns the
|
||||
wxDataViewColumn
|
||||
created in the function or @NULL on failure.
|
||||
wxDataViewColumn created in the function or @NULL on failure.
|
||||
|
||||
NB: The @e align parameter is applied to both the column header and
|
||||
the column renderer.
|
||||
*/
|
||||
wxDataViewColumn* AppendProgressColumn(const wxString& label,
|
||||
unsigned int model_column,
|
||||
@ -794,6 +829,9 @@ public:
|
||||
/**
|
||||
Appends a column for rendering text. Returns the wxDataViewColumn
|
||||
created in the function or @NULL on failure.
|
||||
|
||||
NB: The @e align parameter is applied to both the column header and
|
||||
the column renderer.
|
||||
*/
|
||||
wxDataViewColumn* AppendTextColumn(const wxString& label,
|
||||
unsigned int model_column,
|
||||
@ -813,6 +851,9 @@ public:
|
||||
/**
|
||||
Appends a column for rendering a toggle. Returns the wxDataViewColumn
|
||||
created in the function or @NULL on failure.
|
||||
|
||||
NB: The @e align parameter is applied to both the column header and
|
||||
the column renderer.
|
||||
*/
|
||||
wxDataViewColumn* AppendToggleColumn(const wxString& label,
|
||||
unsigned int model_column,
|
||||
@ -829,8 +870,8 @@ public:
|
||||
//@}
|
||||
|
||||
/**
|
||||
Associates a wxDataViewModel with the
|
||||
control. This increases the reference count of the model by 1.
|
||||
Associates a wxDataViewModel with the control. This increases the reference
|
||||
count of the model by 1.
|
||||
*/
|
||||
virtual bool AssociateModel(wxDataViewModel* model);
|
||||
|
||||
|
@ -402,14 +402,14 @@ static int my_sort( int *v1, int *v2 )
|
||||
return *v1-*v2;
|
||||
}
|
||||
|
||||
class MyListModel: public wxDataViewIndexListModel
|
||||
class MyListModel: public wxDataViewVirtualListModel
|
||||
{
|
||||
public:
|
||||
MyListModel() :
|
||||
#ifdef __WXMAC__
|
||||
wxDataViewIndexListModel( 1000 + 100 )
|
||||
wxDataViewVirtualListModel( 1000 + 100 )
|
||||
#else
|
||||
wxDataViewIndexListModel( 100000 + 100 )
|
||||
wxDataViewVirtualListModel( 100000 + 100 )
|
||||
#endif
|
||||
{
|
||||
#ifdef __WXMAC__
|
||||
@ -825,7 +825,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
||||
m_listCtrl->AssociateModel( m_list_model.get() );
|
||||
|
||||
#if 1
|
||||
m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE, 120 );
|
||||
m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE, 120, wxALIGN_RIGHT );
|
||||
m_listCtrl->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT, 60 );
|
||||
#else
|
||||
m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE );
|
||||
|
@ -297,29 +297,22 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem
|
||||
// wxDataViewIndexListModel
|
||||
// ---------------------------------------------------------
|
||||
|
||||
static int my_sort( int *v1, int *v2 )
|
||||
{
|
||||
return *v2-*v1;
|
||||
}
|
||||
|
||||
|
||||
wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
|
||||
{
|
||||
#ifndef __WXMAC__
|
||||
m_useHash = false;
|
||||
#else
|
||||
m_useHash = true;
|
||||
#endif
|
||||
|
||||
if (m_useHash)
|
||||
{
|
||||
// IDs are ordered until an item gets deleted or inserted
|
||||
m_ordered = true;
|
||||
|
||||
// build initial index
|
||||
unsigned int i;
|
||||
for (i = 1; i < initial_size+1; i++)
|
||||
// IDs are ordered until an item gets deleted or inserted
|
||||
m_ordered = true;
|
||||
|
||||
// build initial index
|
||||
unsigned int i;
|
||||
for (i = 1; i < initial_size+1; i++)
|
||||
m_hash.Add( (void*) i );
|
||||
m_lastIndex = initial_size + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lastIndex = initial_size-1;
|
||||
}
|
||||
m_lastIndex = initial_size + 1;
|
||||
}
|
||||
|
||||
wxDataViewIndexListModel::~wxDataViewIndexListModel()
|
||||
@ -328,103 +321,55 @@ wxDataViewIndexListModel::~wxDataViewIndexListModel()
|
||||
|
||||
void wxDataViewIndexListModel::Reset( unsigned int new_size )
|
||||
{
|
||||
if (m_useHash)
|
||||
{
|
||||
m_hash.Clear();
|
||||
m_hash.Clear();
|
||||
|
||||
// IDs are ordered until an item gets deleted or inserted
|
||||
m_ordered = true;
|
||||
// IDs are ordered until an item gets deleted or inserted
|
||||
m_ordered = true;
|
||||
|
||||
// build initial index
|
||||
unsigned int i;
|
||||
for (i = 1; i < new_size+1; i++)
|
||||
// build initial index
|
||||
unsigned int i;
|
||||
for (i = 1; i < new_size+1; i++)
|
||||
m_hash.Add( (void*) i );
|
||||
m_lastIndex = new_size + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lastIndex = new_size-1;
|
||||
}
|
||||
m_lastIndex = new_size + 1;
|
||||
|
||||
wxDataViewModel::Cleared();
|
||||
}
|
||||
|
||||
void wxDataViewIndexListModel::RowPrepended()
|
||||
{
|
||||
if (m_useHash)
|
||||
{
|
||||
m_ordered = false;
|
||||
m_ordered = false;
|
||||
|
||||
unsigned int id = m_lastIndex++;
|
||||
m_hash.Insert( (void*) id, 0 );
|
||||
wxDataViewItem item( (void*) id );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lastIndex++;
|
||||
wxDataViewItem item( (void*) 0 );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
unsigned int id = m_lastIndex++;
|
||||
m_hash.Insert( (void*) id, 0 );
|
||||
wxDataViewItem item( (void*) id );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
|
||||
void wxDataViewIndexListModel::RowInserted( unsigned int before )
|
||||
{
|
||||
if (m_useHash)
|
||||
{
|
||||
m_ordered = false;
|
||||
m_ordered = false;
|
||||
|
||||
unsigned int id = m_lastIndex++;
|
||||
m_hash.Insert( (void*) id, before );
|
||||
wxDataViewItem item( (void*) id );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lastIndex++;
|
||||
wxDataViewItem item( (void*) before );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
unsigned int id = m_lastIndex++;
|
||||
m_hash.Insert( (void*) id, before );
|
||||
wxDataViewItem item( (void*) id );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
|
||||
void wxDataViewIndexListModel::RowAppended()
|
||||
{
|
||||
if (m_useHash)
|
||||
{
|
||||
unsigned int id = m_lastIndex++;
|
||||
m_hash.Add( (void*) id );
|
||||
wxDataViewItem item( (void*) id );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lastIndex++;
|
||||
wxDataViewItem item( (void*) m_lastIndex );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
unsigned int id = m_lastIndex++;
|
||||
m_hash.Add( (void*) id );
|
||||
wxDataViewItem item( (void*) id );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
|
||||
void wxDataViewIndexListModel::RowDeleted( unsigned int row )
|
||||
{
|
||||
if (m_useHash)
|
||||
{
|
||||
m_ordered = false;
|
||||
m_ordered = false;
|
||||
|
||||
wxDataViewItem item( m_hash[row] );
|
||||
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
|
||||
m_hash.RemoveAt( row );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxDataViewItem item( (void*) row );
|
||||
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
|
||||
m_lastIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
static int my_sort( int *v1, int *v2 )
|
||||
{
|
||||
return *v2-*v1;
|
||||
wxDataViewItem item( m_hash[row] );
|
||||
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
|
||||
m_hash.RemoveAt( row );
|
||||
}
|
||||
|
||||
void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows )
|
||||
@ -432,35 +377,19 @@ void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows )
|
||||
wxArrayInt sorted = rows;
|
||||
sorted.Sort( my_sort );
|
||||
|
||||
if (m_useHash)
|
||||
{
|
||||
m_ordered = false;
|
||||
m_ordered = false;
|
||||
|
||||
wxDataViewItemArray array;
|
||||
unsigned int i;
|
||||
for (i = 0; i < rows.GetCount(); i++)
|
||||
{
|
||||
wxDataViewItemArray array;
|
||||
unsigned int i;
|
||||
for (i = 0; i < rows.GetCount(); i++)
|
||||
{
|
||||
wxDataViewItem item( m_hash[rows[i]] );
|
||||
array.Add( item );
|
||||
}
|
||||
wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
|
||||
}
|
||||
wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
|
||||
|
||||
for (i = 0; i < sorted.GetCount(); i++)
|
||||
for (i = 0; i < sorted.GetCount(); i++)
|
||||
m_hash.RemoveAt( sorted[i] );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxDataViewItemArray array;
|
||||
unsigned int i;
|
||||
for (i = 0; i < sorted.GetCount(); i++)
|
||||
{
|
||||
wxDataViewItem item( (void*) sorted[i] );
|
||||
array.Add( item );
|
||||
}
|
||||
wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
|
||||
|
||||
m_lastIndex -= rows.GetCount();
|
||||
}
|
||||
}
|
||||
|
||||
void wxDataViewIndexListModel::RowChanged( unsigned int row )
|
||||
@ -475,34 +404,20 @@ void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int c
|
||||
|
||||
unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
|
||||
{
|
||||
if (m_useHash)
|
||||
if (m_ordered)
|
||||
{
|
||||
if (m_ordered)
|
||||
{
|
||||
unsigned int pos = wxPtrToUInt( item.GetID() );
|
||||
return pos-1;
|
||||
}
|
||||
}
|
||||
|
||||
// assert for not found
|
||||
return (unsigned int) m_hash.Index( item.GetID() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return wxPtrToUInt( item.GetID() );
|
||||
}
|
||||
// assert for not found
|
||||
return (unsigned int) m_hash.Index( item.GetID() );
|
||||
}
|
||||
|
||||
wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
|
||||
{
|
||||
if (m_useHash)
|
||||
{
|
||||
wxASSERT( row < m_hash.GetCount() );
|
||||
return wxDataViewItem( m_hash[row] );
|
||||
}
|
||||
else
|
||||
{
|
||||
return wxDataViewItem( (void*) row );
|
||||
}
|
||||
wxASSERT( row < m_hash.GetCount() );
|
||||
return wxDataViewItem( m_hash[row] );
|
||||
}
|
||||
|
||||
bool wxDataViewIndexListModel::HasDefaultCompare() const
|
||||
@ -515,7 +430,7 @@ int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
|
||||
unsigned int WXUNUSED(column),
|
||||
bool ascending)
|
||||
{
|
||||
if (m_ordered || !m_useHash)
|
||||
if (m_ordered)
|
||||
{
|
||||
unsigned int pos1 = wxPtrToUInt(item1.GetID());
|
||||
unsigned int pos2 = wxPtrToUInt(item2.GetID());
|
||||
@ -565,9 +480,6 @@ bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const
|
||||
|
||||
unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
|
||||
{
|
||||
if (!m_useHash)
|
||||
return 0; // error
|
||||
|
||||
if (item.IsOk())
|
||||
return 0;
|
||||
|
||||
@ -576,6 +488,150 @@ unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item,
|
||||
return m_hash.GetCount();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// wxDataViewVirtualListModel
|
||||
// ---------------------------------------------------------
|
||||
|
||||
#ifndef __WXMAC__
|
||||
|
||||
wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
|
||||
{
|
||||
m_lastIndex = initial_size-1;
|
||||
}
|
||||
|
||||
wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
|
||||
{
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::Reset( unsigned int new_size )
|
||||
{
|
||||
m_lastIndex = new_size-1;
|
||||
|
||||
wxDataViewModel::Cleared();
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::RowPrepended()
|
||||
{
|
||||
m_lastIndex++;
|
||||
wxDataViewItem item( (void*) 0 );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::RowInserted( unsigned int before )
|
||||
{
|
||||
m_lastIndex++;
|
||||
wxDataViewItem item( (void*) before );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::RowAppended()
|
||||
{
|
||||
m_lastIndex++;
|
||||
wxDataViewItem item( (void*) m_lastIndex );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::RowDeleted( unsigned int row )
|
||||
{
|
||||
wxDataViewItem item( (void*) row );
|
||||
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
|
||||
m_lastIndex++;
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
|
||||
{
|
||||
wxArrayInt sorted = rows;
|
||||
sorted.Sort( my_sort );
|
||||
|
||||
wxDataViewItemArray array;
|
||||
unsigned int i;
|
||||
for (i = 0; i < sorted.GetCount(); i++)
|
||||
{
|
||||
wxDataViewItem item( (void*) sorted[i] );
|
||||
array.Add( item );
|
||||
}
|
||||
wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
|
||||
|
||||
m_lastIndex -= rows.GetCount();
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::RowChanged( unsigned int row )
|
||||
{
|
||||
wxDataViewModel::ItemChanged( GetItem(row) );
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::RowValueChanged( unsigned int row, unsigned int col )
|
||||
{
|
||||
wxDataViewModel::ValueChanged( GetItem(row), col );
|
||||
}
|
||||
|
||||
unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem &item ) const
|
||||
{
|
||||
return wxPtrToUInt( item.GetID() );
|
||||
}
|
||||
|
||||
wxDataViewItem wxDataViewVirtualListModel::GetItem( unsigned int row ) const
|
||||
{
|
||||
return wxDataViewItem( (void*) row );
|
||||
}
|
||||
|
||||
bool wxDataViewVirtualListModel::HasDefaultCompare() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1,
|
||||
const wxDataViewItem& item2,
|
||||
unsigned int WXUNUSED(column),
|
||||
bool ascending)
|
||||
{
|
||||
unsigned int pos1 = wxPtrToUInt(item1.GetID());
|
||||
unsigned int pos2 = wxPtrToUInt(item2.GetID());
|
||||
|
||||
if (ascending)
|
||||
return pos1 - pos2;
|
||||
else
|
||||
return pos2 - pos1;
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::GetValue( wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col ) const
|
||||
{
|
||||
GetValue( variant, GetRow(item), col );
|
||||
}
|
||||
|
||||
bool wxDataViewVirtualListModel::SetValue( const wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col )
|
||||
{
|
||||
return SetValue( variant, GetRow(item), col );
|
||||
}
|
||||
|
||||
bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
|
||||
{
|
||||
return GetAttr( GetRow(item), col, attr );
|
||||
}
|
||||
|
||||
wxDataViewItem wxDataViewVirtualListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
|
||||
{
|
||||
return wxDataViewItem(0);
|
||||
}
|
||||
|
||||
bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem &item ) const
|
||||
{
|
||||
// only the invisible root item has children
|
||||
if (!item.IsOk())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem &WXUNUSED(item), wxDataViewItemArray &WXUNUSED(children) ) const
|
||||
{
|
||||
return 0; // should we report an error ?
|
||||
}
|
||||
|
||||
#endif // __WXMAC__
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDataViewIconText
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -3351,7 +3351,7 @@ void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)
|
||||
{
|
||||
DestroyTree();
|
||||
|
||||
if (GetOwner()->GetModel()->IsIndexListModel())
|
||||
if (GetOwner()->GetModel()->IsVirtualListModel())
|
||||
{
|
||||
m_count = -1 ;
|
||||
return;
|
||||
|
@ -1080,7 +1080,7 @@ gtk_wx_cell_renderer_render (GtkCellRenderer *renderer,
|
||||
rect.y += cell_area->y;
|
||||
rect.width -= renderer->xpad * 2;
|
||||
rect.height -= renderer->ypad * 2;
|
||||
|
||||
|
||||
GdkRectangle dummy;
|
||||
if (gdk_rectangle_intersect (expose_area, &rect, &dummy))
|
||||
{
|
||||
@ -2262,7 +2262,7 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column),
|
||||
|
||||
wxDataViewModel *wx_model = tree_model->internal->GetDataViewModel();
|
||||
|
||||
if (!wx_model->IsIndexListModel())
|
||||
if (!wx_model->IsVirtualListModel())
|
||||
{
|
||||
|
||||
if (wx_model->IsContainer( item ))
|
||||
@ -2752,7 +2752,7 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner,
|
||||
m_sort_column = -1;
|
||||
m_dataview_sort_column = NULL;
|
||||
|
||||
if (!m_wx_model->IsIndexListModel())
|
||||
if (!m_wx_model->IsVirtualListModel())
|
||||
InitTree();
|
||||
}
|
||||
|
||||
@ -2871,13 +2871,13 @@ bool wxDataViewCtrlInternal::Cleared()
|
||||
|
||||
void wxDataViewCtrlInternal::Resort()
|
||||
{
|
||||
if (!m_wx_model->IsIndexListModel())
|
||||
if (!m_wx_model->IsVirtualListModel())
|
||||
m_root->Resort();
|
||||
}
|
||||
|
||||
bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
|
||||
{
|
||||
if (!m_wx_model->IsIndexListModel())
|
||||
if (!m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
wxGtkTreeModelNode *parent_node = FindNode( parent );
|
||||
if (m_wx_model->IsContainer( item ))
|
||||
@ -2891,7 +2891,7 @@ bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDa
|
||||
|
||||
bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
|
||||
{
|
||||
if (!m_wx_model->IsIndexListModel())
|
||||
if (!m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
wxGtkTreeModelNode *parent_node = FindNode( parent );
|
||||
parent_node->DeleteChild( item.GetID() );
|
||||
@ -2928,7 +2928,7 @@ bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned
|
||||
|
||||
GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
|
||||
{
|
||||
if (m_wx_model->IsIndexListModel())
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
return GTK_TREE_MODEL_LIST_ONLY;
|
||||
else
|
||||
return GTK_TREE_MODEL_ITERS_PERSIST;
|
||||
@ -2936,7 +2936,7 @@ GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
|
||||
|
||||
gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
|
||||
{
|
||||
if (m_wx_model->IsIndexListModel())
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
||||
|
||||
@ -2996,7 +2996,7 @@ GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
|
||||
{
|
||||
GtkTreePath *retval = gtk_tree_path_new ();
|
||||
|
||||
if (m_wx_model->IsIndexListModel())
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
// user_data is just the index
|
||||
int i = (wxUIntPtr) iter->user_data;
|
||||
@ -3023,7 +3023,7 @@ GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
|
||||
|
||||
gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
||||
{
|
||||
if (m_wx_model->IsIndexListModel())
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
||||
|
||||
@ -3057,7 +3057,7 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
||||
|
||||
gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent )
|
||||
{
|
||||
if (m_wx_model->IsIndexListModel())
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
// this is a list, nodes have no children
|
||||
if (parent)
|
||||
@ -3090,7 +3090,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *
|
||||
|
||||
gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
|
||||
{
|
||||
if (m_wx_model->IsIndexListModel())
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
// this is a list, nodes have no children
|
||||
return FALSE;
|
||||
@ -3113,7 +3113,7 @@ gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
|
||||
|
||||
gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
|
||||
{
|
||||
if (m_wx_model->IsIndexListModel())
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
||||
|
||||
@ -3140,7 +3140,7 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
|
||||
|
||||
gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n )
|
||||
{
|
||||
if (m_wx_model->IsIndexListModel())
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
||||
|
||||
@ -3181,7 +3181,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
|
||||
|
||||
gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child )
|
||||
{
|
||||
if (m_wx_model->IsIndexListModel())
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user