virtual void GetValue( wxVariant &variant,
const wxDataViewItem &item, unsigned int col ) const = 0;
- // set value, call ValueChanged() afterwards!
- virtual bool SetValue( const wxVariant &variant,
- const wxDataViewItem &item, unsigned int col ) = 0;
+ // return true if the given item has a value to display in the given
+ // column: this is always true except for container items which by default
+ // only show their label in the first column (but see HasContainerColumns())
+ bool HasValue(const wxDataViewItem& item, unsigned col) const
+ {
+ return col == 0 || !IsContainer(item) || HasContainerColumns(item);
+ }
+
+ // usually ValueChanged() should be called after changing the value in the
+ // model to update the control, ChangeValue() does it on its own while
+ // SetValue() does not -- so while you will override SetValue(), you should
+ // be usually calling ChangeValue()
+ virtual bool SetValue(const wxVariant &variant,
+ const wxDataViewItem &item,
+ unsigned int col) = 0;
+
+ bool ChangeValue(const wxVariant& variant,
+ const wxDataViewItem& item,
+ unsigned int col)
+ {
+ return SetValue(variant, item, col) && ValueChanged(item, col);
+ }
// Get text attribute, return false of default attributes should be used
- virtual bool GetAttr( const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
- { return false; }
+ virtual bool GetAttr(const wxDataViewItem &WXUNUSED(item),
+ unsigned int WXUNUSED(col),
+ wxDataViewItemAttr &WXUNUSED(attr)) const
+ {
+ return false;
+ }
// define hierachy
virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
wxDataViewModelNotifiers m_notifiers;
};
+// ----------------------------------------------------------------------------
+// wxDataViewListModel: a model of a list, i.e. flat data structure without any
+// branches/containers, used as base class by wxDataViewIndexListModel and
+// wxDataViewVirtualListModel
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_ADV wxDataViewListModel : public wxDataViewModel
+{
+public:
+ // derived classes should override these methods instead of
+ // {Get,Set}Value() and GetAttr() inherited from the base class
+
+ virtual void GetValueByRow(wxVariant &variant,
+ unsigned row, unsigned col) const = 0;
+
+ virtual bool SetValueByRow(const wxVariant &variant,
+ unsigned row, unsigned col) = 0;
+
+ virtual bool
+ GetAttrByRow(unsigned WXUNUSED(row), unsigned WXUNUSED(col),
+ wxDataViewItemAttr &WXUNUSED(attr)) const
+ {
+ return false;
+ }
+
+
+ // helper methods provided by list models only
+ virtual unsigned GetRow( const wxDataViewItem &item ) const = 0;
+
+
+ // implement some base class pure virtual directly
+ virtual wxDataViewItem
+ GetParent( const wxDataViewItem & WXUNUSED(item) ) const
+ {
+ // items never have valid parent in this model
+ return wxDataViewItem();
+ }
+
+ virtual bool IsContainer( const wxDataViewItem &item ) const
+ {
+ // only the invisible (and invalid) root item has children
+ return !item.IsOk();
+ }
+
+ // and implement some others by forwarding them to our own ones
+ virtual void GetValue( wxVariant &variant,
+ const wxDataViewItem &item, unsigned int col ) const
+ {
+ GetValueByRow(variant, GetRow(item), col);
+ }
+
+ virtual bool SetValue( const wxVariant &variant,
+ const wxDataViewItem &item, unsigned int col )
+ {
+ return SetValueByRow( variant, GetRow(item), col );
+ }
+
+ virtual bool GetAttr(const wxDataViewItem &item, unsigned int col,
+ wxDataViewItemAttr &attr) const
+ {
+ return GetAttrByRow( GetRow(item), col, attr );
+ }
+};
+
// ---------------------------------------------------------
// wxDataViewIndexListModel
// ---------------------------------------------------------
-class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewModel
+class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewListModel
{
public:
wxDataViewIndexListModel( unsigned int initial_size = 0 );
- ~wxDataViewIndexListModel();
-
- virtual void GetValueByRow( wxVariant &variant,
- unsigned int row, unsigned int col ) const = 0;
-
- virtual bool SetValueByRow( const wxVariant &variant,
- unsigned int row, unsigned int col ) = 0;
-
- virtual bool GetAttrByRow( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
- { return false; }
void RowPrepended();
void RowInserted( unsigned int before );
// convert to/from row/wxDataViewItem
- unsigned int GetRow( const wxDataViewItem &item ) const;
+ virtual unsigned GetRow( const wxDataViewItem &item ) const;
wxDataViewItem GetItem( unsigned int row ) const;
// compare based on index
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 false; }
unsigned int GetCount() const { return m_hash.GetCount(); }
private:
typedef wxDataViewIndexListModel wxDataViewVirtualListModel;
#else
-class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewModel
+class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewListModel
{
public:
wxDataViewVirtualListModel( unsigned int initial_size = 0 );
- ~wxDataViewVirtualListModel();
-
- virtual void GetValueByRow( wxVariant &variant,
- unsigned int row, unsigned int col ) const = 0;
-
- virtual bool SetValueByRow( const wxVariant &variant,
- unsigned int row, unsigned int col ) = 0;
-
- virtual bool GetAttrByRow( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
- { return false; }
void RowPrepended();
void RowInserted( unsigned int before );
// convert to/from row/wxDataViewItem
- unsigned int GetRow( const wxDataViewItem &item ) const;
+ virtual unsigned GetRow( const wxDataViewItem &item ) const;
wxDataViewItem GetItem( unsigned int row ) const;
// compare based on index
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;
+ unsigned int GetCount() const { return m_size; }
+
// internal
virtual bool IsVirtualListModel() const { return true; }
- unsigned int GetCount() const { return m_size; }
private:
unsigned int m_size;
wxDataViewRendererBase( const wxString &varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
- ~wxDataViewRendererBase();
+ virtual ~wxDataViewRendererBase();
virtual bool Validate( wxVariant& WXUNUSED(value) )
{ return true; }
virtual void SetAlignment( int align ) = 0;
virtual int GetAlignment() const = 0;
+ // enable or disable (if called with wxELLIPSIZE_NONE) replacing parts of
+ // the item text (hence this only makes sense for renderers showing
+ // text...) with ellipsis in order to make it fit the column width
+ virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE) = 0;
+ void DisableEllipsize() { EnableEllipsize(wxELLIPSIZE_NONE); }
+
+ virtual wxEllipsizeMode GetEllipsizeMode() const = 0;
+
// in-place editing
virtual bool HasEditorCtrl() const
{ return false; }
class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
{
public:
- wxDataViewTreeCtrl();
- wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id,
- const wxPoint& pos = wxDefaultPosition,
- const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
- const wxValidator& validator = wxDefaultValidator );
- ~wxDataViewTreeCtrl();
+ wxDataViewTreeCtrl() { Init(); }
+ wxDataViewTreeCtrl(wxWindow *parent,
+ wxWindowID id,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
+ const wxValidator& validator = wxDefaultValidator)
+ {
+ Init();
- 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 );
+ Create(parent, id, pos, size, style, validator);
+ }
+
+ 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()
{ return (wxDataViewTreeStore*) GetModel(); }
void OnSize( wxSizeEvent &event );
private:
- wxImageList *m_imageList;
+ void Init()
+ {
+ m_imageList = NULL;
+ }
+
+ wxImageList *m_imageList;
private:
DECLARE_EVENT_TABLE()