X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c937344c8f4bbd14b96ddba8adcdd15341c06ffd..3427bc784ec7dae7d3830e8f2c61565587e8f791:/include/wx/generic/dataview.h diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 35bee5a82a..a9c57e1c4e 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -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() const { 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,21 @@ 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() const; - virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, + virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); @@ -146,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 // --------------------------------------------------------- @@ -225,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: @@ -251,16 +289,23 @@ 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() const { return true; } - virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, + virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); @@ -288,8 +333,8 @@ public: virtual bool Render( wxRect cell, wxDC *dc, int state ); virtual wxSize GetSize() const; virtual bool Activate( wxRect cell, - wxDataViewModel *model, - const wxDataViewItem& item, + wxDataViewModel *model, + const wxDataViewItem& item, unsigned int col ); private: @@ -445,9 +490,9 @@ public: virtual void EnsureVisible( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ); - virtual void HitTest( const wxPoint & point, wxDataViewItem & item, + virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const; - virtual wxRect GetItemRect( const wxDataViewItem & item, + virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const; virtual void Expand( const wxDataViewItem & item );