]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/dataview.h
Some wxComboCtrlBase member functions were enclosed within incorrect compatibility...
[wxWidgets.git] / include / wx / dataview.h
index b2b9275d4f206d428b935972110a9240794f4687..66ef3ea532366714c359ec2c249b419f268f790d 100644 (file)
@@ -210,8 +210,12 @@ public:
     }
 
     // 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;
@@ -252,24 +256,78 @@ protected:
     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 );
@@ -282,7 +340,7 @@ public:
 
     // 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
@@ -292,18 +350,8 @@ public:
     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:
@@ -321,20 +369,10 @@ 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 );
@@ -347,7 +385,7 @@ public:
 
     // 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
@@ -357,19 +395,12 @@ public:
     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;
@@ -1327,17 +1358,27 @@ public:
 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(); }
@@ -1392,7 +1433,12 @@ public:
     void OnSize( wxSizeEvent &event );
 
 private:
-    wxImageList  *m_imageList;
+    void Init()
+    {
+        m_imageList = NULL;
+    }
+
+    wxImageList *m_imageList;
 
 private:
     DECLARE_EVENT_TABLE()