X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/517166e678f9e70f94ea6970356c12550bedadc5..13d843f1c15fe721f03d933c600cd5ca62944003:/include/wx/dataview.h diff --git a/include/wx/dataview.h b/include/wx/dataview.h index fbfc5dce44..39ab01c92f 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -22,6 +22,10 @@ #include "wx/variant.h" #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 @@ -57,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 // --------------------------------------------------------- @@ -95,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; @@ -110,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; @@ -128,8 +133,8 @@ class WXDLLIMPEXP_ADV wxDataViewItemAttr { public: // ctors - wxDataViewItemAttr() - { + wxDataViewItemAttr() + { m_bold = false; m_italic = false; } @@ -138,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; } @@ -190,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,6 +225,9 @@ public: unsigned int column, bool ascending ); virtual bool HasDefaultCompare() const { return false; } + // internal + virtual bool IsVirtualListModel() const { return false; } + protected: // the user should not delete this class directly: he should use DecRef() instead! virtual ~wxDataViewModel() { } @@ -228,8 +245,6 @@ public: wxDataViewIndexListModel( unsigned int initial_size = 0 ); ~wxDataViewIndexListModel(); - virtual unsigned int GetRowCount() = 0; - virtual void GetValue( wxVariant &variant, unsigned int row, unsigned int col ) const = 0; @@ -238,13 +253,15 @@ 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(); 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 @@ -268,12 +285,81 @@ public: 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 GetLastIndex() const { return m_lastIndex; } + private: wxDataViewItemArray m_hash; unsigned int m_lastIndex; bool m_ordered; }; +// --------------------------------------------------------- +// 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 @@ -327,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: @@ -370,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: @@ -388,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; } @@ -415,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 @@ -438,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; @@ -460,16 +551,17 @@ 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; } unsigned int GetModelColumn() const { return static_cast(m_model_column); } - wxDataViewCtrl *GetOwner() { return m_owner; } - wxDataViewRenderer* GetRenderer() { return m_renderer; } + wxDataViewCtrl *GetOwner() const { return m_owner; } + wxDataViewRenderer* GetRenderer() const { return m_renderer; } protected: wxDataViewRenderer *m_renderer; @@ -492,6 +584,9 @@ protected: #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows #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 { public: @@ -500,6 +595,7 @@ public: virtual bool AssociateModel( wxDataViewModel *model ); wxDataViewModel* GetModel(); + const wxDataViewModel* GetModel() const; // short cuts wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column, @@ -602,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; @@ -617,7 +714,7 @@ public: { return m_expander_column; } virtual wxDataViewColumn *GetSortingColumn() const = 0; - + void SetIndent( int indent ) { m_indent = indent ; DoSetIndent(); } int GetIndent() const @@ -667,7 +764,8 @@ public: m_col(-1), m_model(NULL), m_value(wxNullVariant), - m_column(NULL) + m_column(NULL), + m_pos(-1,-1) { } wxDataViewEvent(const wxDataViewEvent& event) @@ -676,7 +774,8 @@ public: m_col(event.m_col), m_model(event.m_model), m_value(event.m_value), - m_column(event.m_column) + m_column(event.m_column), + m_pos(m_pos) { } wxDataViewItem GetItem() const { return m_item; } @@ -695,6 +794,10 @@ public: void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; } wxDataViewColumn *GetDataViewColumn() const { return m_column; } + // for wxEVT_DATAVIEW_CONTEXT_MENU only + 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); } protected: @@ -703,27 +806,29 @@ protected: wxDataViewModel *m_model; wxVariant m_value; wxDataViewColumn *m_column; + wxPoint m_pos; private: DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent) }; -BEGIN_DECLARE_EVENT_TYPES() - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, -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; - 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) +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&); @@ -744,9 +849,12 @@ typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn) #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn) +#define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn) + #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" @@ -842,12 +950,18 @@ public: const wxIcon &GetExpandedIcon() const { return m_iconExpanded; } + void SetExpanded( bool expanded = true ) + { m_isExpanded = expanded; } + bool IsExpanded() const + { return m_isExpanded; } + virtual bool IsContainer() { return true; } private: wxDataViewTreeStoreNodeList m_children; wxIcon m_iconExpanded; + bool m_isExpanded; }; //----------------------------------------------------------------------------- @@ -909,7 +1023,7 @@ public: virtual unsigned int GetColumnCount() const { return 1; }; virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const - { return "wxDataViewIconText"; } + { return wxT("wxDataViewIconText"); } wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const; wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const; @@ -919,30 +1033,86 @@ public: wxDataViewTreeStoreNode *m_root; }; -#if 0 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl { public: - wxDataViewCtrl( wxWindow *parent, wxWindowID id, + wxDataViewTreeCtrl(); + wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER, + const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES, const wxValidator& validator = wxDefaultValidator ); + ~wxDataViewTreeCtrl(); bool Create( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER, + const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES, const wxValidator& validator = wxDefaultValidator ); wxDataViewTreeStore *GetStore() { return (wxDataViewTreeStore*) GetModel(); } + const wxDataViewTreeStore *GetStore() const + { return (const wxDataViewTreeStore*) GetModel(); } + + void SetImageList( wxImageList *imagelist ); + wxImageList* GetImageList() { return m_imageList; } - void OnExpand( wxDataViewCtrl &event ); - void OnCollapse( wxDataViewCtrl &event ); + wxDataViewItem AppendItem( const wxDataViewItem& parent, + const wxString &text, int icon = -1, wxClientData *data = NULL ); + wxDataViewItem PrependItem( const wxDataViewItem& parent, + const wxString &text, int icon = -1, wxClientData *data = NULL ); + wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous, + const wxString &text, int icon = -1, wxClientData *data = NULL ); + + wxDataViewItem PrependContainer( const wxDataViewItem& parent, + const wxString &text, int icon = -1, int expanded = -1, + wxClientData *data = NULL ); + wxDataViewItem AppendContainer( const wxDataViewItem& parent, + const wxString &text, int icon = -1, int expanded = -1, + wxClientData *data = NULL ); + wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous, + const wxString &text, int icon = -1, int expanded = -1, + wxClientData *data = NULL ); + + wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const + { return GetStore()->GetNthChild(parent, pos); } + int GetChildCount( const wxDataViewItem& parent ) const + { return GetStore()->GetChildCount(parent); } + + void SetItemText( const wxDataViewItem& item, const wxString &text ) + { GetStore()->SetItemText(item,text); } + wxString GetItemText( const wxDataViewItem& item ) const + { return GetStore()->GetItemText(item); } + void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ) + { GetStore()->SetItemIcon(item,icon); } + const wxIcon &GetItemIcon( const wxDataViewItem& item ) const + { return GetStore()->GetItemIcon(item); } + void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ) + { GetStore()->SetItemExpandedIcon(item,icon); } + const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const + { return GetStore()->GetItemExpandedIcon(item); } + void SetItemData( const wxDataViewItem& item, wxClientData *data ) + { GetStore()->SetItemData(item,data); } + wxClientData *GetItemData( const wxDataViewItem& item ) const + { return GetStore()->GetItemData(item); } + + void DeleteItem( const wxDataViewItem& item ) + { GetStore()->DeleteItem(item); } + void DeleteChildren( const wxDataViewItem& item ) + { GetStore()->DeleteChildren(item); } + void DeleteAllItems() + { GetStore()->DeleteAllItems(); } + + void OnExpanded( wxDataViewEvent &event ); + void OnCollapsed( wxDataViewEvent &event ); + void OnSize( wxSizeEvent &event ); + +private: + wxImageList *m_imageList; private: + DECLARE_EVENT_TABLE() DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl) }; -#endif #endif // wxUSE_DATAVIEWCTRL