Add wxDataViewCtrl::ExpandAncestors() and call it from both EnsureVisible() and Select()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57511 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2008-12-23 14:56:07 +00:00
parent 311c1be9ed
commit 4219d8b027
6 changed files with 69 additions and 18 deletions

View File

@ -713,11 +713,12 @@ public:
virtual void UnselectAll() = 0;
virtual void Expand( const wxDataViewItem & item ) = 0;
virtual void ExpandAncestors( const wxDataViewItem & item );
virtual void Collapse( const wxDataViewItem & item ) = 0;
virtual bool IsExpanded( const wxDataViewItem & item ) const = 0;
virtual void EnsureVisible( const wxDataViewItem & item,
const wxDataViewColumn *column = NULL );
const wxDataViewColumn *column = NULL ) = 0;
virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;

View File

@ -887,6 +887,13 @@ public:
*/
virtual void Expand(const wxDataViewItem& item);
/**
Expands all ancestors of the @a item. This method also
ensures that the item itself as well as all ancestor
items have been read from the model by the control.
*/
virtual void ExpandAncestors( const wxDataViewItem & item );
/**
Returns pointer to the column. @a pos refers to the position in the
control which may change after reordering columns by the user.

View File

@ -896,10 +896,11 @@ const wxDataViewModel* wxDataViewCtrlBase::GetModel() const
return m_model;
}
void wxDataViewCtrlBase::EnsureVisible( const wxDataViewItem & item,
const wxDataViewColumn *WXUNUSED(column) )
void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
{
if (!m_model) return;
if (!item.IsOk()) return;
wxVector<wxDataViewItem> parentChain;
@ -919,7 +920,6 @@ void wxDataViewCtrlBase::EnsureVisible( const wxDataViewItem & item,
}
}
wxDataViewColumn *
wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
wxDataViewCellMode mode, int width, wxAlignment align, int flags )

View File

@ -3524,18 +3524,33 @@ int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
{
wxDataViewSelection selection(wxDataViewSelectionCmp);
wxDataViewItem last_parent;
int len = sel.GetCount();
for( int i = 0; i < len; i ++ )
{
int row = m_clientArea->GetRowByItem( sel[i] );
wxDataViewItem item = sel[i];
wxDataViewItem parent = GetModel()->GetParent( item );
if (parent)
{
if (parent != last_parent)
ExpandAncestors(item);
}
last_parent = parent;
int row = m_clientArea->GetRowByItem( item );
if( row >= 0 )
selection.Add( static_cast<unsigned int>(row) );
}
m_clientArea->SetSelections( selection );
}
void wxDataViewCtrl::Select( const wxDataViewItem & item )
{
ExpandAncestors( item );
int row = m_clientArea->GetRowByItem( item );
if( row >= 0 )
{
@ -3659,7 +3674,7 @@ void wxDataViewCtrl::EnsureVisible( int row, int column )
void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataViewColumn * column )
{
wxDataViewCtrlBase::EnsureVisible( item, column );
ExpandAncestors( item );
m_clientArea->RecalculateDisplay();

View File

@ -4113,12 +4113,23 @@ void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
gtk_tree_selection_unselect_all( selection );
wxDataViewItem last_parent;
size_t i;
for (i = 0; i < sel.GetCount(); i++)
{
wxDataViewItem item = sel[i];
wxDataViewItem parent = GetModel()->GetParent( item );
if (parent)
{
if (parent != last_parent)
ExpandAncestors(item);
}
last_parent = parent;
GtkTreeIter iter;
iter.stamp = m_internal->GetGtkModel()->stamp;
iter.user_data = (gpointer) sel[i].GetID();
iter.user_data = (gpointer) item.GetID();
gtk_tree_selection_select_iter( selection, &iter );
}
@ -4127,6 +4138,8 @@ void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
void wxDataViewCtrl::Select( const wxDataViewItem & item )
{
ExpandAncestors(item);
GtkDisableSelectionEvents();
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
@ -4187,9 +4200,9 @@ void wxDataViewCtrl::UnselectAll()
}
void wxDataViewCtrl::EnsureVisible(const wxDataViewItem& item,
const wxDataViewColumn *column)
const wxDataViewColumn *WXUNUSED(column))
{
wxDataViewCtrlBase::EnsureVisible(item,column);
ExpandAncestors(item);
GtkTreeIter iter;
iter.user_data = (gpointer) item.GetID();

View File

@ -1183,7 +1183,7 @@ void wxDataViewCtrl::Collapse(wxDataViewItem const& item)
void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
{
wxDataViewCtrlBase::EnsureVisible(item,columnPtr);
ExpandAncestors(item);
if (item.IsOk())
{
@ -1334,6 +1334,8 @@ void wxDataViewCtrl::Select(wxDataViewItem const& item)
{
if (item.IsOk())
{
ExpandAncestors(item);
DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(m_peer));
@ -1343,18 +1345,31 @@ void wxDataViewCtrl::Select(wxDataViewItem const& item)
void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
{
size_t const NoOfSelections = sel.GetCount();
size_t const NoOfSelections = sel.GetCount();
DataBrowserItemID* itemIDs;
wxDataViewItem last_parent;
wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(m_peer));
size_t i;
for (i = 0; i < NoOfSelections; i++)
{
wxDataViewItem item = sel[i];
wxDataViewItem parent = GetModel()->GetParent( item );
if (parent)
{
if (parent != last_parent)
ExpandAncestors(item);
}
last_parent = parent;
}
DataBrowserItemID* itemIDs;
wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(m_peer));
itemIDs = new DataBrowserItemID[NoOfSelections];
for (size_t i=0; i<NoOfSelections; ++i)
itemIDs[i] = reinterpret_cast<DataBrowserItemID>(sel[i].GetID());
MacDataViewListCtrlPtr->SetSelectedItems(NoOfSelections,itemIDs,kDataBrowserItemsAssign);
delete[] itemIDs;
itemIDs = new DataBrowserItemID[NoOfSelections];
for (i=0; i<NoOfSelections; ++i)
itemIDs[i] = reinterpret_cast<DataBrowserItemID>(sel[i].GetID());
MacDataViewListCtrlPtr->SetSelectedItems(NoOfSelections,itemIDs,kDataBrowserItemsAssign);
delete[] itemIDs;
}
void wxDataViewCtrl::Unselect(wxDataViewItem const& item)