diff --git a/docs/changes.txt b/docs/changes.txt index 3ba68e3d10..40ed527a0a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -113,6 +113,7 @@ All (GUI): - Make wxDataViewCtrl::Expand() expand ancestors in native ports too. - Add wxDataViewTextRenderer::EnableMarkup(). - Add wxDataViewCtrl::SetHeaderAttr(). +- Add wxDataViewCtrl::GetTopItem() and GetCountPerPage() (Andreas Falkenhahn). - Add wxListCtrl::SetHeaderAttr(). - Add support for using markup in wxDataViewCtrl text items. - Implement auto complete in generic wxSearchCtrl (Eric Jensen). diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 687312cbfd..304864aab1 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -699,6 +699,9 @@ public: wxDataViewItem GetCurrentItem() const; void SetCurrentItem(const wxDataViewItem& item); + virtual wxDataViewItem GetTopItem() const { return wxDataViewItem(0); } + virtual int GetCountPerPage() const { return wxNOT_FOUND; } + // Currently focused column of the current item or NULL if no column has focus virtual wxDataViewColumn *GetCurrentColumn() const = 0; diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 5aeac8c8c9..f4ebc64cae 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -226,6 +226,9 @@ public: virtual wxDataViewColumn *GetSortingColumn() const wxOVERRIDE; virtual wxVector GetSortingColumns() const wxOVERRIDE; + virtual wxDataViewItem GetTopItem() const wxOVERRIDE; + virtual int GetCountPerPage() const wxOVERRIDE; + virtual int GetSelectedItemsCount() const wxOVERRIDE; virtual int GetSelections( wxDataViewItemArray & sel ) const wxOVERRIDE; virtual void SetSelections( const wxDataViewItemArray & sel ) wxOVERRIDE; diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 3f246ddfd4..a6d1d45c3b 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -169,6 +169,9 @@ public: virtual wxDataViewColumn *GetCurrentColumn() const wxOVERRIDE; + virtual wxDataViewItem GetTopItem() const wxOVERRIDE; + virtual int GetCountPerPage() const wxOVERRIDE; + static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 8b8a1422cd..6587f97bd9 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -480,8 +480,10 @@ public: virtual void EnsureVisible(const wxDataViewItem& item, wxDataViewColumn const* columnPtr); virtual unsigned int GetCount() const; + virtual int GetCountPerPage() const; virtual wxRect GetRectangle(const wxDataViewItem& item, wxDataViewColumn const* columnPtr); + virtual wxDataViewItem GetTopItem() const; virtual bool IsExpanded(const wxDataViewItem& item) const; virtual bool Reload(); virtual bool Remove(const wxDataViewItem& parent, diff --git a/include/wx/osx/core/dataview.h b/include/wx/osx/core/dataview.h index bf629c6349..30a91816e3 100644 --- a/include/wx/osx/core/dataview.h +++ b/include/wx/osx/core/dataview.h @@ -63,7 +63,9 @@ public: virtual void Collapse (wxDataViewItem const& item) = 0; // collapses the passed item in the native control virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) = 0; // ensures that the passed item's value in the passed column is visible (column pointer can be NULL) virtual unsigned int GetCount (void) const = 0; // returns the number of items in the native control + virtual int GetCountPerPage(void) const = 0; // get number of items that fit into a single page virtual wxRect GetRectangle (wxDataViewItem const& item, wxDataViewColumn const* columnPtr) = 0; // returns the rectangle that is used by the passed item and column in the native control + virtual wxDataViewItem GetTopItem (void) const = 0; // get top-most visible item virtual bool IsExpanded (wxDataViewItem const& item) const = 0; // checks if the passed item is expanded in the native control virtual bool Reload (void) = 0; // clears the native control and reloads all data virtual bool Remove (wxDataViewItem const& parent, wxDataViewItem const& item) = 0; // removes an item from the native control diff --git a/include/wx/osx/dataview.h b/include/wx/osx/dataview.h index 452a2718e3..64418110f9 100644 --- a/include/wx/osx/dataview.h +++ b/include/wx/osx/dataview.h @@ -172,11 +172,14 @@ public: virtual bool IsExpanded(const wxDataViewItem & item) const wxOVERRIDE; virtual unsigned int GetCount() const; + virtual int GetCountPerPage() const wxOVERRIDE; virtual wxRect GetItemRect(const wxDataViewItem& item, const wxDataViewColumn* columnPtr = NULL) const wxOVERRIDE; virtual int GetSelectedItemsCount() const wxOVERRIDE; virtual int GetSelections(wxDataViewItemArray& sel) const wxOVERRIDE; + virtual wxDataViewItem GetTopItem() const wxOVERRIDE; + virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const wxOVERRIDE; virtual bool SetRowHeight(int rowHeight) wxOVERRIDE; diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index 64881462de..bfc8fa8d1b 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -1647,6 +1647,28 @@ public: @since 3.1.0 */ virtual void ToggleSortByColumn(int column); + + /** + Return the number of items that can fit vertically in the visible area of + the control. + + Returns -1 if the number of items per page couldn't be determined. On + wxGTK this method can only determine the number of items per page if + there is at least one item in the control. + + @since 3.1.1 + */ + int GetCountPerPage() const; + + /** + Return the topmost visible item. + + Returns an invalid item if there is no topmost visible item or if the method + is not implemented for the current platform. + + @since 3.1.1 + */ + wxDataViewItem GetTopItem() const; }; diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 66ecc14991..d7cfe63f0d 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -751,6 +751,7 @@ public: int GetCountPerPage() const; int GetEndOfLastCol() const; unsigned int GetFirstVisibleRow() const; + wxDataViewItem GetTopItem() const; // I change this method to un const because in the tree view, // the displaying number of the tree are changing along with the @@ -2842,6 +2843,27 @@ int wxDataViewMainWindow::GetCountPerPage() const return size.y / m_lineHeight; } +wxDataViewItem wxDataViewMainWindow::GetTopItem() const +{ + unsigned int item = GetFirstVisibleRow(); + wxDataViewTreeNode *node = NULL; + wxDataViewItem dataitem; + + if ( !IsVirtualList() ) + { + node = GetTreeNodeByRow(item); + if( node == NULL ) return wxDataViewItem(0); + + dataitem = node->GetItem(); + } + else + { + dataitem = wxDataViewItem( wxUIntToPtr(item+1) ); + } + + return dataitem; +} + int wxDataViewMainWindow::GetEndOfLastCol() const { int width = 0; @@ -5386,6 +5408,16 @@ int wxDataViewCtrl::GetSelectedItemsCount() const return m_clientArea->GetSelections().GetSelectedCount(); } +wxDataViewItem wxDataViewCtrl::GetTopItem() const +{ + return m_clientArea->GetTopItem(); +} + +int wxDataViewCtrl::GetCountPerPage() const +{ + return m_clientArea->GetCountPerPage(); +} + int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const { sel.Empty(); diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index cf8e7f139f..ddea2a5928 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -4917,6 +4917,53 @@ void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item) gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, NULL, FALSE); } +wxDataViewItem wxDataViewCtrl::GetTopItem() const +{ + wxGtkTreePath start; + if ( !gtk_tree_view_get_visible_range + ( + GTK_TREE_VIEW(m_treeview), + start.ByRef(), + NULL + ) ) + { + return wxDataViewItem(); + } + + return GTKPathToItem(start); +} + +int wxDataViewCtrl::GetCountPerPage() const +{ + wxGtkTreePath path; + GtkTreeViewColumn *column; + + if ( !gtk_tree_view_get_path_at_pos + ( + GTK_TREE_VIEW(m_treeview), + 0, + 0, + path.ByRef(), + &column, + NULL, + NULL + ) ) + { + return -1; + } + + GdkRectangle rect; + gtk_tree_view_get_cell_area(GTK_TREE_VIEW(m_treeview), path, column, &rect); + + if ( !rect.height ) + return -1; + + GdkRectangle vis; + gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(m_treeview), &vis); + + return vis.height / rect.height; +} + wxDataViewColumn *wxDataViewCtrl::GetCurrentColumn() const { // The tree doesn't have any current item if it hadn't been created yet but diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index b5664ac2fa..9b0207eb92 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2313,6 +2313,27 @@ unsigned int wxCocoaDataViewControl::GetCount() const return [m_OutlineView numberOfRows]; } +int wxCocoaDataViewControl::GetCountPerPage() const +{ + NSScrollView *scrollView = [m_OutlineView enclosingScrollView]; + NSTableHeaderView *headerView = [m_OutlineView headerView]; + NSRect visibleRect = scrollView.contentView.visibleRect; + if ( headerView ) + visibleRect.size.height -= headerView.visibleRect.size.height; + return (int) (visibleRect.size.height / [m_OutlineView rowHeight]); +} + +wxDataViewItem wxCocoaDataViewControl::GetTopItem() const +{ + NSScrollView *scrollView = [m_OutlineView enclosingScrollView]; + NSTableHeaderView *headerView = [m_OutlineView headerView]; + NSRect visibleRect = scrollView.contentView.visibleRect; + if ( headerView ) + visibleRect.origin.y += headerView.visibleRect.size.height; + NSRange range = [m_OutlineView rowsInRect:visibleRect]; + return wxDataViewItem([[m_OutlineView itemAtRow:range.location] pointer]); +} + wxRect wxCocoaDataViewControl::GetRectangle(const wxDataViewItem& item, const wxDataViewColumn *columnPtr) { return wxFromNSRect([m_osxView superview],[m_OutlineView frameOfCellAtColumn:GetColumnPosition(columnPtr) diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 33ad781b33..5cbce08115 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -563,6 +563,16 @@ int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const return GetDataViewPeer()->GetSelections(sel); } +wxDataViewItem wxDataViewCtrl::GetTopItem() const +{ + return GetDataViewPeer()->GetTopItem(); +} + +int wxDataViewCtrl::GetCountPerPage() const +{ + return GetDataViewPeer()->GetCountPerPage(); +} + void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const { return GetDataViewPeer()->HitTest(point,item,columnPtr);