#define wxHAS_GENERIC_DATAVIEWCTRL
#endif
+#ifdef wxHAS_GENERIC_DATAVIEWCTRL
+ // this symbol doesn't follow the convention for wxUSE_XXX symbols which
+ // are normally always defined as either 0 or 1, so its use is deprecated
+ // and it only exists for backwards compatibility, don't use it any more
+ // and use wxHAS_GENERIC_DATAVIEWCTRL instead
+ #define wxUSE_GENERICDATAVIEWCTRL
+#endif
+
// ----------------------------------------------------------------------------
// wxDataViewCtrl globals
// ----------------------------------------------------------------------------
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;
DECLARE_EVENT_TABLE()
};
-// ---------------------------------------------------------
-// wxDataViewRendererBase
-// ---------------------------------------------------------
-
-enum wxDataViewCellMode
-{
- wxDATAVIEW_CELL_INERT,
- wxDATAVIEW_CELL_ACTIVATABLE,
- wxDATAVIEW_CELL_EDITABLE
-};
-
-enum wxDataViewCellRenderState
-{
- wxDATAVIEW_CELL_SELECTED = 1,
- wxDATAVIEW_CELL_PRELIT = 2,
- wxDATAVIEW_CELL_INSENSITIVE = 4,
- wxDATAVIEW_CELL_FOCUSED = 8
-};
-
-class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
-{
-public:
- wxDataViewRendererBase( const wxString &varianttype,
- wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
- int alignment = wxDVR_DEFAULT_ALIGNMENT );
- ~wxDataViewRendererBase();
-
- virtual bool Validate( wxVariant& WXUNUSED(value) )
- { return true; }
-
- void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
- wxDataViewColumn* GetOwner() const { return m_owner; }
-
- // renderer properties:
-
- virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
- virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
-
- wxString GetVariantType() const { return m_variantType; }
-
- virtual void SetMode( wxDataViewCellMode mode ) = 0;
- virtual wxDataViewCellMode GetMode() const = 0;
-
- // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
- // rather an "int"; that's because for rendering cells it's allowed
- // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
- virtual void SetAlignment( int align ) = 0;
- virtual int GetAlignment() const = 0;
-
- // in-place editing
- virtual bool HasEditorCtrl() const
- { return false; }
- virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
- wxRect WXUNUSED(labelRect),
- const wxVariant& WXUNUSED(value))
- { return NULL; }
- virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
- wxVariant& WXUNUSED(value))
- { return false; }
-
- virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
- virtual void CancelEditing();
- virtual bool FinishEditing();
-
- wxControl *GetEditorCtrl() { return m_editorCtrl; }
-
-protected:
- wxString m_variantType;
- wxDataViewColumn *m_owner;
- wxWeakRef<wxControl> m_editorCtrl;
- wxDataViewItem m_item; // for m_editorCtrl
-
- // internal utility:
- const wxDataViewCtrl* GetView() const;
-
-protected:
- DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
-};
-
-//-----------------------------------------------------------------------------
-// wxDataViewIconText
-//-----------------------------------------------------------------------------
-
-class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject
-{
-public:
- wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon )
- : m_text(text), m_icon(icon)
- { }
- wxDataViewIconText( const wxDataViewIconText &other )
- : wxObject()
- { m_icon = other.m_icon; m_text = other.m_text; }
-
- void SetText( const wxString &text ) { m_text = text; }
- wxString GetText() const { return m_text; }
- void SetIcon( const wxIcon &icon ) { m_icon = icon; }
- const wxIcon &GetIcon() const { return m_icon; }
-
-private:
- wxString m_text;
- wxIcon m_icon;
-
-private:
- DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
-};
-
-inline
-bool operator==(const wxDataViewIconText& left, const wxDataViewIconText& right)
-{
- return left.GetText() == right.GetText() &&
- left.GetIcon().IsSameAs(right.GetIcon());
-}
-
-inline
-bool operator!=(const wxDataViewIconText& left, const wxDataViewIconText& right)
-{
- return !(left == right);
-}
+// ----------------------------------------------------------------------------
+// wxDataViewRenderer and related classes
+// ----------------------------------------------------------------------------
-DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
+#include "wx/dvrenderers.h"
// ---------------------------------------------------------
// wxDataViewColumnBase
#define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn)
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
- // this symbol doesn't follow the convention for wxUSE_XXX symbols which
- // are normally always defined as either 0 or 1, so its use is deprecated
- // and it only exists for backwards compatibility, don't use it any more
- // and use wxHAS_GENERIC_DATAVIEWCTRL instead
- #define wxUSE_GENERICDATAVIEWCTRL
-
#include "wx/generic/dataview.h"
#elif defined(__WXGTK20__)
#include "wx/gtk/dataview.h"
#error "unknown native wxDataViewCtrl implementation"
#endif
-// -------------------------------------
-// wxDataViewSpinRenderer
-// -------------------------------------
-
-class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer
-{
-public:
- wxDataViewSpinRenderer( int min, int max,
- wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
- int alignment = wxDVR_DEFAULT_ALIGNMENT );
- virtual bool HasEditorCtrl() const { return true; }
- virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
- virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
- virtual bool Render( wxRect rect, wxDC *dc, int state );
- virtual wxSize GetSize() const;
- virtual bool SetValue( const wxVariant &value );
- virtual bool GetValue( wxVariant &value ) const;
-
-private:
- long m_data;
- long m_min,m_max;
-};
-
-#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
-
-// -------------------------------------
-// wxDataViewChoiceRenderer
-// -------------------------------------
-
-class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
-{
-public:
- wxDataViewChoiceRenderer( const wxArrayString &choices,
- wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
- int alignment = wxDVR_DEFAULT_ALIGNMENT );
- virtual bool HasEditorCtrl() const { return true; }
- virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
- virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
- virtual bool Render( wxRect rect, wxDC *dc, int state );
- virtual wxSize GetSize() const;
- virtual bool SetValue( const wxVariant &value );
- virtual bool GetValue( wxVariant &value ) const;
-
-private:
- wxArrayString m_choices;
- wxString m_data;
-};
-
-#endif
-
-// this class is obsolete, its functionality was merged in
-// wxDataViewTextRenderer itself now, don't use it any more
-#define wxDataViewTextRendererAttr wxDataViewTextRenderer
-
//-----------------------------------------------------------------------------
// wxDataViewListStore
//-----------------------------------------------------------------------------
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()