]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/generic/dataview.h
Document wxRendererNative::DrawTitleBarBitmap() and use it properly.
[wxWidgets.git] / include / wx / generic / dataview.h
index 953c2931427478ebdfa2376f7fc3eec5b47855f7..a9c57e1c4e6f7a7cfa4f11e70742e5be2c0b9685 100644 (file)
@@ -38,12 +38,30 @@ public:
                         int align = wxDVR_DEFAULT_ALIGNMENT );
     virtual ~wxDataViewRenderer();
 
+    // these methods are used to draw the cell contents, Render() doesn't care
+    // about the attributes while RenderWithAttr() does -- override it if you
+    // want to take the attributes defined for this cell into account, otherwise
+    // overriding Render() is enough
     virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
+
+    // NB: RenderWithAttr() also has more standard parameter order and types
+    virtual bool
+    RenderWithAttr(wxDC& dc,
+                   const wxRect& rect,
+                   int align,   // combination of horizontal and vertical
+                   const wxDataViewItemAttr *attr, // may be NULL if none
+                   int state);
+
     virtual wxSize GetSize() const = 0;
 
     virtual void SetAlignment( int align );
     virtual int GetAlignment() const;
 
+    virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE)
+        { m_ellipsizeMode = mode; }
+    virtual wxEllipsizeMode GetEllipsizeMode() const
+        { return m_ellipsizeMode; }
+
     virtual void SetMode( wxDataViewCellMode mode )
         { m_mode=mode; }
     virtual wxDataViewCellMode GetMode() const
@@ -77,24 +95,28 @@ public:
     // Create DC on request
     virtual wxDC *GetDC();
 
-    void SetHasAttr( bool set )  { m_hasAttr = set; }
-    void SetAttr( const wxDataViewItemAttr &attr ) { m_attr = attr; }
-    bool GetWantsAttr() { return m_wantsAttr; }
-
     // implementation
     int CalculateAlignment() const;
 
+protected:
+    // This is just a convenience for the derived classes overriding
+    // RenderWithAttr() to avoid repeating the same wxFAIL_MSG() in all of them
+    bool DummyRender(wxRect WXUNUSED(cell),
+                     wxDC * WXUNUSED(dc),
+                     int WXUNUSED(state))
+    {
+        wxFAIL_MSG("shouldn't be called at all, use RenderWithAttr() instead");
+
+        return false;
+    }
+
 private:
     wxDC                        *m_dc;
     int                          m_align;
     wxDataViewCellMode           m_mode;
 
-protected:
-    bool                         m_wantsAttr;
-    bool                         m_hasAttr;
-    wxDataViewItemAttr           m_attr;
+    wxEllipsizeMode m_ellipsizeMode;
 
-protected:
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
 };
 
@@ -109,7 +131,24 @@ public:
                               wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
                               int align = wxDVR_DEFAULT_ALIGNMENT );
 
-    void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
+    // Draw the text using the provided attributes
+    void RenderText(wxDC& dc,
+                    const wxRect& rect,
+                    int align,
+                    const wxString& text,
+                    const wxDataViewItemAttr *attr, // may be NULL if none
+                    int state,
+                    int xoffset = 0);
+
+    // Overload using standard attributes
+    void RenderText(const wxString& text,
+                    int xoffset,
+                    wxRect cell,
+                    wxDC *dc,
+                    int state)
+    {
+        RenderText(*dc, cell, wxALIGN_NOT, text, NULL, state, xoffset);
+    }
 
 protected:
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
@@ -130,12 +169,22 @@ public:
     bool SetValue( const wxVariant &value );
     bool GetValue( wxVariant &value ) const;
 
-    bool Render( wxRect cell, wxDC *dc, int state );
+    virtual bool RenderWithAttr(wxDC& dc,
+                                const wxRect& rect,
+                                int align,
+                                const wxDataViewItemAttr *attr,
+                                int state);
+    virtual bool Render(wxRect cell, wxDC *dc, int state)
+    {
+        return DummyRender(cell, dc, state);
+    }
+
     wxSize GetSize() const;
 
     // in-place editing
-    virtual bool HasEditorCtrl();
-    virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
+    virtual bool HasEditorCtrl() const;
+    virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect,
+                                         const wxVariant &value );
     virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
 
 protected:
@@ -145,23 +194,6 @@ protected:
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
 };
 
-// ---------------------------------------------------------
-// wxDataViewTextRendererAttr
-// ---------------------------------------------------------
-
-class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
-{
-public:
-    wxDataViewTextRendererAttr( const wxString &varianttype = wxT("string"),
-                            wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
-                            int align = wxDVR_DEFAULT_ALIGNMENT );
-
-    bool Render( wxRect cell, wxDC *dc, int state );
-
-protected:
-    DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
-};
-
 // ---------------------------------------------------------
 // wxDataViewBitmapRenderer
 // ---------------------------------------------------------
@@ -224,12 +256,19 @@ public:
                                 const wxString &varianttype = wxT("long"),
                                 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
                                 int align = wxDVR_DEFAULT_ALIGNMENT );
-    virtual ~wxDataViewProgressRenderer();
 
     bool SetValue( const wxVariant &value );
     bool GetValue( wxVariant& value ) const;
 
-    virtual bool Render( wxRect cell, wxDC *dc, int state );
+    virtual bool RenderWithAttr(wxDC& dc,
+                                const wxRect& rect,
+                                int align,
+                                const wxDataViewItemAttr *attr,
+                                int state);
+    virtual bool Render(wxRect cell, wxDC *dc, int state)
+    {
+        return DummyRender(cell, dc, state);
+    }
     virtual wxSize GetSize() const;
 
 private:
@@ -250,16 +289,24 @@ public:
     wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
                                 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
                                 int align = wxDVR_DEFAULT_ALIGNMENT );
-    virtual ~wxDataViewIconTextRenderer();
 
     bool SetValue( const wxVariant &value );
     bool GetValue( wxVariant &value ) const;
 
-    virtual bool Render( wxRect cell, wxDC *dc, int state );
+    virtual bool RenderWithAttr(wxDC& dc,
+                                const wxRect& rect,
+                                int align,
+                                const wxDataViewItemAttr *attr,
+                                int state);
+    virtual bool Render(wxRect cell, wxDC *dc, int state)
+    {
+        return DummyRender(cell, dc, state);
+    }
     virtual wxSize GetSize() const;
 
-    virtual bool HasEditorCtrl() { return true; }
-    virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
+    virtual bool HasEditorCtrl() const { return true; }
+    virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect,
+                                         const wxVariant &value );
     virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
 
 private:
@@ -286,7 +333,9 @@ public:
     virtual bool Render( wxRect cell, wxDC *dc, int state );
     virtual wxSize GetSize() const;
     virtual bool Activate( wxRect cell,
-                           wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
+                           wxDataViewModel *model,
+                           const wxDataViewItem& item,
+                           unsigned int col );
 
 private:
     wxDateTime    m_date;
@@ -379,8 +428,8 @@ private:
 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
                           class WXDLLIMPEXP_ADV);
 
-class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
-                                       public wxScrollHelperNative
+class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase,
+                                       public wxScrollHelper
 {
     friend class wxDataViewMainWindow;
     friend class wxDataViewHeaderWindowBase;
@@ -389,7 +438,7 @@ class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
     friend class wxDataViewColumn;
 
 public:
-    wxDataViewCtrl() : wxScrollHelperNative(this)
+    wxDataViewCtrl() : wxScrollHelper(this)
     {
         Init();
     }
@@ -398,7 +447,7 @@ public:
            const wxPoint& pos = wxDefaultPosition,
            const wxSize& size = wxDefaultSize, long style = 0,
            const wxValidator& validator = wxDefaultValidator )
-             : wxScrollHelperNative(this)
+             : wxScrollHelper(this)
     {
         Create(parent, id, pos, size, style, validator );
     }
@@ -408,9 +457,9 @@ public:
     void Init();
 
     bool Create(wxWindow *parent, wxWindowID id,
-           const wxPoint& pos = wxDefaultPosition,
-           const wxSize& size = wxDefaultSize, long style = 0,
-           const wxValidator& validator = wxDefaultValidator );
+                const wxPoint& pos = wxDefaultPosition,
+                const wxSize& size = wxDefaultSize, long style = 0,
+                const wxValidator& validator = wxDefaultValidator );
 
     virtual bool AssociateModel( wxDataViewModel *model );
 
@@ -441,14 +490,26 @@ public:
 
     virtual void EnsureVisible( const wxDataViewItem & item,
                                 const wxDataViewColumn *column = NULL );
-    virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const;
-    virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const;
+    virtual void HitTest( const wxPoint & point, wxDataViewItem & item,
+                          wxDataViewColumn* &column ) const;
+    virtual wxRect GetItemRect( const wxDataViewItem & item,
+                                const wxDataViewColumn *column = NULL ) const;
 
     virtual void Expand( const wxDataViewItem & item );
     virtual void Collapse( const wxDataViewItem & item );
+    virtual bool IsExpanded( const wxDataViewItem & item ) const;
 
     virtual void SetFocus();
 
+#if wxUSE_DRAG_AND_DROP
+    virtual bool EnableDragSource( const wxDataFormat &format );
+    virtual bool EnableDropTarget( const wxDataFormat &format );
+#endif // wxUSE_DRAG_AND_DROP
+
+    virtual wxBorder GetDefaultBorder() const;
+
+    void StartEditor( const wxDataViewItem & item, unsigned int column );
+
 protected:
     virtual int GetSelections( wxArrayInt & sel ) const;
     virtual void SetSelections( const wxArrayInt & sel );
@@ -463,8 +524,8 @@ protected:
     virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
     virtual int GetRowByItem( const wxDataViewItem & item ) const;
 
-    wxDataViewColumn* GetSortingColumn() { return m_sortingColumn; }
-    void SetSortingColumn( wxDataViewColumn* column ) { m_sortingColumn = column; }
+    int GetSortingColumnIndex() const { return m_sortingColumnIdx; }
+    void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; }
 
 public:     // utility functions not part of the API
 
@@ -485,12 +546,20 @@ public:     // utility functions not part of the API
 
     wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
 
+    // return the index of the given column in m_cols
+    int GetColumnIndex(const wxDataViewColumn *column) const;
+
+    // return the column displayed at the given position in the control
+    wxDataViewColumn *GetColumnAt(unsigned int pos) const;
+
 private:
     wxDataViewColumnList      m_cols;
     wxDataViewModelNotifier  *m_notifier;
     wxDataViewMainWindow     *m_clientArea;
     wxDataViewHeaderWindow   *m_headerArea;
-    wxDataViewColumn         *m_sortingColumn;
+
+    // the index of the column currently used for sorting or -1
+    int m_sortingColumnIdx;
 
 private:
     void OnSize( wxSizeEvent &event );
@@ -506,7 +575,7 @@ private:
 
 private:
     DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
-    DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
+    wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl);
     DECLARE_EVENT_TABLE()
 };