X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8b6cf9bf10a43343734d1bb22f2fae3ade2f4a67..ea276239125ab295122820c6d6a03b729431f7e7:/include/wx/dataview.h diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 0f64e7f156..39ab01c92f 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -23,6 +23,9 @@ #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 @@ -58,8 +61,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 // --------------------------------------------------------- @@ -96,7 +100,7 @@ WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray); class WXDLLIMPEXP_ADV wxDataViewModelNotifier { public: - wxDataViewModelNotifier() { } + wxDataViewModelNotifier() { m_owner = NULL; } virtual ~wxDataViewModelNotifier() { m_owner = NULL; } virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0; @@ -111,7 +115,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; @@ -129,8 +133,8 @@ class WXDLLIMPEXP_ADV wxDataViewItemAttr { public: // ctors - wxDataViewItemAttr() - { + wxDataViewItemAttr() + { m_bold = false; m_italic = false; } @@ -139,11 +143,11 @@ public: void SetColour(const wxColour& colour) { m_colour = colour; } void SetBold( bool set ) { m_bold = set; } void SetItalic( bool set ) { m_italic = set; } - + // accessors bool HasColour() const { return m_colour.Ok(); } const wxColour& GetColour() const { return m_colour; } - + bool GetBold() const { return m_bold; } bool GetItalic() const { return m_italic; } @@ -191,6 +195,15 @@ public: { return false; } virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0; + // define DnD capabilities + virtual bool IsDraggable( const wxDataViewItem &WXUNUSED(item) ) + { return false; } + virtual size_t GetDragDataSize( const wxDataViewItem &WXUNUSED(item), const wxDataFormat &WXUNUSED(format) ) + { return 0; } + virtual bool GetDragData( const wxDataViewItem &WXUNUSED(item), const wxDataFormat &WXUNUSED(format), + void* WXUNUSED(data), size_t WXUNUSED(size) ) + { return FALSE; } + // delegated notifiers virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ); virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ); @@ -211,9 +224,9 @@ public: virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, unsigned int column, bool ascending ); 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! @@ -240,7 +253,7 @@ public: 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(); @@ -248,6 +261,7 @@ public: 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 @@ -272,16 +286,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 @@ -335,12 +413,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: @@ -378,7 +457,7 @@ public: protected: wxString m_variantType; wxDataViewColumn *m_owner; - wxControl *m_editorCtrl; + wxWeakRef m_editorCtrl; wxDataViewItem m_item; // for m_editorCtrl // internal utility: @@ -396,8 +475,10 @@ class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject { public: wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon ) - { m_icon = icon; m_text = text; } + : 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; } @@ -423,9 +504,10 @@ DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV) enum wxDataViewColumnFlags { - wxDATAVIEW_COL_RESIZABLE = 1, - wxDATAVIEW_COL_SORTABLE = 2, - wxDATAVIEW_COL_HIDDEN = 4 + wxDATAVIEW_COL_RESIZABLE = 1, + wxDATAVIEW_COL_SORTABLE = 2, + wxDATAVIEW_COL_REORDERABLE = 4, + wxDATAVIEW_COL_HIDDEN = 8 }; class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject @@ -446,6 +528,7 @@ public: virtual void SetTitle( const wxString &title ) = 0; virtual void SetAlignment( wxAlignment align ) = 0; virtual void SetSortable( bool sortable ) = 0; + virtual void SetReorderable(bool reorderable) = 0; virtual void SetResizeable( bool resizeable ) = 0; virtual void SetHidden( bool hidden ) = 0; virtual void SetSortOrder( bool ascending ) = 0; @@ -468,9 +551,10 @@ public: virtual int GetFlags() const; - virtual bool IsSortable() const = 0; - virtual bool IsResizeable() const = 0; virtual bool IsHidden() const = 0; + virtual bool IsReorderable() const = 0; + virtual bool IsResizeable() const = 0; + virtual bool IsSortable() const = 0; virtual bool IsSortOrderAscending() const = 0; const wxBitmap &GetBitmap() const { return m_bitmap; } @@ -501,6 +585,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 { @@ -613,6 +698,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; @@ -628,7 +714,7 @@ public: { return m_expander_column; } virtual wxDataViewColumn *GetSortingColumn() const = 0; - + void SetIndent( int indent ) { m_indent = indent ; DoSetIndent(); } int GetIndent() const @@ -707,9 +793,9 @@ public: // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; } wxDataViewColumn *GetDataViewColumn() const { return m_column; } - + // for wxEVT_DATAVIEW_CONTEXT_MENU only - wxPoint GetPosition() const; + wxPoint GetPosition() const { return m_pos; } void SetPosition( int x, int y ) { m_pos.x = x; m_pos.y = y; } virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); } @@ -726,24 +812,23 @@ private: DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent) }; -BEGIN_DECLARE_EVENT_TYPES() - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, -1) - - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, -1) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, -1) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, -1) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, -1) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, -1) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, -1) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, -1) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, -1) - - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, -1) +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED; + +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED; + +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU; - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, -1) -END_DECLARE_EVENT_TYPES() +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED; +extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED; typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); @@ -769,6 +854,7 @@ typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn) #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn) #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" @@ -969,7 +1055,7 @@ public: void SetImageList( wxImageList *imagelist ); wxImageList* GetImageList() { return m_imageList; } - + wxDataViewItem AppendItem( const wxDataViewItem& parent, const wxString &text, int icon = -1, wxClientData *data = NULL ); wxDataViewItem PrependItem( const wxDataViewItem& parent,