X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5cfb6fee91e8c440a45181de8bfa5f9d14b03735..a9d859df6f433c962a9ed777d2c26da6ce714441:/include/wx/dataview.h diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 5e50b0a00e..efc9f45a71 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -23,17 +23,10 @@ #include "wx/dynarray.h" #include "wx/icon.h" #include "wx/imaglist.h" +#include "wx/weakref.h" class WXDLLIMPEXP_FWD_CORE wxDataFormat; -#if defined(__WXGTK20__) - // for testing - // #define wxUSE_GENERICDATAVIEWCTRL 1 -#elif defined(__WXMAC__) -#else - #define wxUSE_GENERICDATAVIEWCTRL 1 -#endif - // ---------------------------------------------------------------------------- // wxDataViewCtrl flags // ---------------------------------------------------------------------------- @@ -49,7 +42,7 @@ class WXDLLIMPEXP_FWD_ADV wxDataViewColumn; class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer; class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier; -extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[]; +extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[]; // the default width of new (text) columns: #define wxDVC_DEFAULT_WIDTH 80 @@ -60,8 +53,9 @@ extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[]; // the default minimal width of the columns: #define wxDVC_DEFAULT_MINWIDTH 30 -// the default alignment of wxDataViewRenderers: -#define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL) +// The default alignment of wxDataViewRenderers is to take +// the alignment from the column it owns. +#define wxDVR_DEFAULT_ALIGNMENT -1 // --------------------------------------------------------- @@ -113,7 +107,7 @@ public: virtual void Resort() = 0; void SetOwner( wxDataViewModel *owner ) { m_owner = owner; } - wxDataViewModel *GetOwner() { return m_owner; } + wxDataViewModel *GetOwner() const { return m_owner; } private: wxDataViewModel *m_owner; @@ -224,7 +218,7 @@ public: virtual bool HasDefaultCompare() const { return false; } // internal - virtual bool IsIndexListModel() const { return false; } + virtual bool IsVirtualListModel() const { return false; } protected: // the user should not delete this class directly: he should use DecRef() instead! @@ -284,16 +278,80 @@ public: virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const; // internal - virtual bool IsIndexListModel() const { return true; } + virtual bool IsVirtualListModel() const { return false; } unsigned int GetLastIndex() const { return m_lastIndex; } private: wxDataViewItemArray m_hash; unsigned int m_lastIndex; bool m_ordered; - bool m_useHash; }; +// --------------------------------------------------------- +// wxDataViewVirtualListModel +// --------------------------------------------------------- + +#ifdef __WXMAC__ +// better than nothing +typedef wxDataViewIndexListModel wxDataViewVirtualListModel; +#else + +class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewModel +{ +public: + wxDataViewVirtualListModel( unsigned int initial_size = 0 ); + ~wxDataViewVirtualListModel(); + + virtual void GetValue( wxVariant &variant, + unsigned int row, unsigned int col ) const = 0; + + virtual bool SetValue( const wxVariant &variant, + unsigned int row, unsigned int col ) = 0; + + virtual bool GetAttr( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) ) + { return false; } + + void RowPrepended(); + void RowInserted( unsigned int before ); + void RowAppended(); + void RowDeleted( unsigned int row ); + void RowsDeleted( const wxArrayInt &rows ); + void RowChanged( unsigned int row ); + void RowValueChanged( unsigned int row, unsigned int col ); + void Reset( unsigned int new_size ); + + // convert to/from row/wxDataViewItem + + unsigned int GetRow( const wxDataViewItem &item ) const; + wxDataViewItem GetItem( unsigned int row ) const; + + // compare based on index + + virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, + unsigned int column, bool ascending ); + 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 true; } + unsigned int GetLastIndex() const { return m_lastIndex; } + +private: + wxDataViewItemArray m_hash; + unsigned int m_lastIndex; + bool m_ordered; +}; +#endif //----------------------------------------------------------------------------- // wxDataViewEditorCtrlEvtHandler @@ -309,6 +367,7 @@ public: protected: void OnChar( wxKeyEvent &event ); + void OnTextEnter( wxCommandEvent &event ); void OnKillFocus( wxFocusEvent &event ); void OnIdle( wxIdleEvent &event ); @@ -347,12 +406,13 @@ 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() { return m_owner; } + wxDataViewColumn* GetOwner() const { return m_owner; } // renderer properties: @@ -390,7 +450,7 @@ public: protected: wxString m_variantType; wxDataViewColumn *m_owner; - wxControl *m_editorCtrl; + wxWeakRef m_editorCtrl; wxDataViewItem m_item; // for m_editorCtrl // internal utility: @@ -411,6 +471,7 @@ public: : 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; } @@ -517,6 +578,7 @@ protected: #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns #define wxDV_ROW_LINES 0x0010 // alternating colour in rows +#define wxDV_VARIABLE_LINE_HEIGHT 0x0020 // variable line height class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl { @@ -629,6 +691,7 @@ public: virtual bool PrependColumn( wxDataViewColumn *col ); + virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ); virtual bool AppendColumn( wxDataViewColumn *col ); virtual unsigned int GetColumnCount() const = 0; @@ -786,13 +849,13 @@ typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn) #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn) -#if defined(wxUSE_GENERICDATAVIEWCTRL) - #include "wx/generic/dataview.h" -#elif defined(__WXGTK20__) + +#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) #include "wx/gtk/dataview.h" -#elif defined(__WXMAC__) - #include "wx/mac/dataview.h" +#elif defined(__WXMAC__) && !defined(__WXUNIVERSAL__) + #include "wx/osx/dataview.h" #else + #define wxUSE_GENERICDATAVIEWCTRL #include "wx/generic/dataview.h" #endif @@ -819,6 +882,33 @@ private: long m_min,m_max; }; +#ifndef __WXGTK20__ + +// ------------------------------------- +// 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() { 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 + //----------------------------------------------------------------------------- // wxDataViewTreeStore //-----------------------------------------------------------------------------