Add wxDataViewCtrl::GetTopItem() and GetCountPerPage()

Add methods doing the same thing for wxDataViewCtrl as the existing wxListBox
methods.

Closes #17498.
This commit is contained in:
Andreas Falkenhahn
2017-04-07 00:04:27 +02:00
committed by Vadim Zeitlin
parent e77cb6f31f
commit eb035485d7
12 changed files with 149 additions and 0 deletions

View File

@@ -113,6 +113,7 @@ All (GUI):
- Make wxDataViewCtrl::Expand() expand ancestors in native ports too. - Make wxDataViewCtrl::Expand() expand ancestors in native ports too.
- Add wxDataViewTextRenderer::EnableMarkup(). - Add wxDataViewTextRenderer::EnableMarkup().
- Add wxDataViewCtrl::SetHeaderAttr(). - Add wxDataViewCtrl::SetHeaderAttr().
- Add wxDataViewCtrl::GetTopItem() and GetCountPerPage() (Andreas Falkenhahn).
- Add wxListCtrl::SetHeaderAttr(). - Add wxListCtrl::SetHeaderAttr().
- Add support for using markup in wxDataViewCtrl text items. - Add support for using markup in wxDataViewCtrl text items.
- Implement auto complete in generic wxSearchCtrl (Eric Jensen). - Implement auto complete in generic wxSearchCtrl (Eric Jensen).

View File

@@ -699,6 +699,9 @@ public:
wxDataViewItem GetCurrentItem() const; wxDataViewItem GetCurrentItem() const;
void SetCurrentItem(const wxDataViewItem& item); 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 // Currently focused column of the current item or NULL if no column has focus
virtual wxDataViewColumn *GetCurrentColumn() const = 0; virtual wxDataViewColumn *GetCurrentColumn() const = 0;

View File

@@ -226,6 +226,9 @@ public:
virtual wxDataViewColumn *GetSortingColumn() const wxOVERRIDE; virtual wxDataViewColumn *GetSortingColumn() const wxOVERRIDE;
virtual wxVector<wxDataViewColumn *> GetSortingColumns() const wxOVERRIDE; virtual wxVector<wxDataViewColumn *> GetSortingColumns() const wxOVERRIDE;
virtual wxDataViewItem GetTopItem() const wxOVERRIDE;
virtual int GetCountPerPage() const wxOVERRIDE;
virtual int GetSelectedItemsCount() const wxOVERRIDE; virtual int GetSelectedItemsCount() const wxOVERRIDE;
virtual int GetSelections( wxDataViewItemArray & sel ) const wxOVERRIDE; virtual int GetSelections( wxDataViewItemArray & sel ) const wxOVERRIDE;
virtual void SetSelections( const wxDataViewItemArray & sel ) wxOVERRIDE; virtual void SetSelections( const wxDataViewItemArray & sel ) wxOVERRIDE;

View File

@@ -169,6 +169,9 @@ public:
virtual wxDataViewColumn *GetCurrentColumn() const wxOVERRIDE; virtual wxDataViewColumn *GetCurrentColumn() const wxOVERRIDE;
virtual wxDataViewItem GetTopItem() const wxOVERRIDE;
virtual int GetCountPerPage() const wxOVERRIDE;
static wxVisualAttributes static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);

View File

@@ -480,8 +480,10 @@ public:
virtual void EnsureVisible(const wxDataViewItem& item, virtual void EnsureVisible(const wxDataViewItem& item,
wxDataViewColumn const* columnPtr); wxDataViewColumn const* columnPtr);
virtual unsigned int GetCount() const; virtual unsigned int GetCount() const;
virtual int GetCountPerPage() const;
virtual wxRect GetRectangle(const wxDataViewItem& item, virtual wxRect GetRectangle(const wxDataViewItem& item,
wxDataViewColumn const* columnPtr); wxDataViewColumn const* columnPtr);
virtual wxDataViewItem GetTopItem() const;
virtual bool IsExpanded(const wxDataViewItem& item) const; virtual bool IsExpanded(const wxDataViewItem& item) const;
virtual bool Reload(); virtual bool Reload();
virtual bool Remove(const wxDataViewItem& parent, virtual bool Remove(const wxDataViewItem& parent,

View File

@@ -63,7 +63,9 @@ public:
virtual void Collapse (wxDataViewItem const& item) = 0; // collapses the passed item in the native control 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 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 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 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 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 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 virtual bool Remove (wxDataViewItem const& parent, wxDataViewItem const& item) = 0; // removes an item from the native control

View File

@@ -172,11 +172,14 @@ public:
virtual bool IsExpanded(const wxDataViewItem & item) const wxOVERRIDE; virtual bool IsExpanded(const wxDataViewItem & item) const wxOVERRIDE;
virtual unsigned int GetCount() const; virtual unsigned int GetCount() const;
virtual int GetCountPerPage() const wxOVERRIDE;
virtual wxRect GetItemRect(const wxDataViewItem& item, virtual wxRect GetItemRect(const wxDataViewItem& item,
const wxDataViewColumn* columnPtr = NULL) const wxOVERRIDE; const wxDataViewColumn* columnPtr = NULL) const wxOVERRIDE;
virtual int GetSelectedItemsCount() const wxOVERRIDE; virtual int GetSelectedItemsCount() const wxOVERRIDE;
virtual int GetSelections(wxDataViewItemArray& sel) 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 void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const wxOVERRIDE;
virtual bool SetRowHeight(int rowHeight) wxOVERRIDE; virtual bool SetRowHeight(int rowHeight) wxOVERRIDE;

View File

@@ -1647,6 +1647,28 @@ public:
@since 3.1.0 @since 3.1.0
*/ */
virtual void ToggleSortByColumn(int column); 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;
}; };

View File

@@ -751,6 +751,7 @@ public:
int GetCountPerPage() const; int GetCountPerPage() const;
int GetEndOfLastCol() const; int GetEndOfLastCol() const;
unsigned int GetFirstVisibleRow() const; unsigned int GetFirstVisibleRow() const;
wxDataViewItem GetTopItem() const;
// I change this method to un const because in the tree view, // I change this method to un const because in the tree view,
// the displaying number of the tree are changing along with the // the displaying number of the tree are changing along with the
@@ -2842,6 +2843,27 @@ int wxDataViewMainWindow::GetCountPerPage() const
return size.y / m_lineHeight; 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 wxDataViewMainWindow::GetEndOfLastCol() const
{ {
int width = 0; int width = 0;
@@ -5386,6 +5408,16 @@ int wxDataViewCtrl::GetSelectedItemsCount() const
return m_clientArea->GetSelections().GetSelectedCount(); 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 int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
{ {
sel.Empty(); sel.Empty();

View File

@@ -4917,6 +4917,53 @@ void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item)
gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, NULL, FALSE); 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 wxDataViewColumn *wxDataViewCtrl::GetCurrentColumn() const
{ {
// The tree doesn't have any current item if it hadn't been created yet but // The tree doesn't have any current item if it hadn't been created yet but

View File

@@ -2313,6 +2313,27 @@ unsigned int wxCocoaDataViewControl::GetCount() const
return [m_OutlineView numberOfRows]; 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) wxRect wxCocoaDataViewControl::GetRectangle(const wxDataViewItem& item, const wxDataViewColumn *columnPtr)
{ {
return wxFromNSRect([m_osxView superview],[m_OutlineView frameOfCellAtColumn:GetColumnPosition(columnPtr) return wxFromNSRect([m_osxView superview],[m_OutlineView frameOfCellAtColumn:GetColumnPosition(columnPtr)

View File

@@ -563,6 +563,16 @@ int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
return GetDataViewPeer()->GetSelections(sel); 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 void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
{ {
return GetDataViewPeer()->HitTest(point,item,columnPtr); return GetDataViewPeer()->HitTest(point,item,columnPtr);