unsigned int GetLastVisibleRow();
unsigned int GetRowCount();
- wxDataViewItem GetSelection() const;
const wxDataViewSelection& GetSelections() const { return m_selection; }
void SetSelections( const wxDataViewSelection & sel )
{ m_selection = sel; UpdateDisplay(); }
bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
{
- GetOwner()->InvalidateColBestWidths();
if (IsVirtualList())
{
wxDataViewVirtualListModel *list_model =
(wxDataViewVirtualListModel*) GetOwner()->GetModel();
m_count = list_model->GetCount();
- UpdateDisplay();
- return true;
}
+ else
+ {
+ SortPrepare();
- SortPrepare();
+ wxDataViewTreeNode * node;
+ node = FindNode(parent);
+
+ if( node == NULL )
+ return false;
- wxDataViewTreeNode * node;
- node = FindNode(parent);
+ node->SetHasChildren( true );
- if( node == NULL )
- return false;
+ if( g_model->IsContainer( item ) )
+ {
+ wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
+ newnode->SetItem(item);
+ newnode->SetHasChildren( true );
+ node->AddNode( newnode);
+ }
+ else
+ node->AddLeaf( item.GetID() );
- node->SetHasChildren( true );
+ node->ChangeSubTreeCount(1);
- if( g_model->IsContainer( item ) )
- {
- wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
- newnode->SetItem(item);
- newnode->SetHasChildren( true );
- node->AddNode( newnode);
+ m_count = -1;
}
- else
- node->AddLeaf( item.GetID() );
- node->ChangeSubTreeCount(1);
-
- m_count = -1;
+ GetOwner()->UpdateColBestWidths();
UpdateDisplay();
return true;
bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
const wxDataViewItem& item)
{
- GetOwner()->InvalidateColBestWidths();
-
if (IsVirtualList())
{
wxDataViewVirtualListModel *list_model =
{
const int row = GetRowByItem(item);
+ int rowIndexInSelection = wxNOT_FOUND;
+
const size_t selCount = m_selection.size();
for ( size_t i = 0; i < selCount; i++ )
{
- if ( m_selection[i] > (unsigned)row )
+ if ( m_selection[i] == (unsigned)row )
+ rowIndexInSelection = i;
+ else if ( m_selection[i] > (unsigned)row )
m_selection[i]--;
}
- int itemRow = m_selection.Index(row);
- if ( itemRow != wxNOT_FOUND )
- m_selection.RemoveAt(itemRow);
+ if ( rowIndexInSelection != wxNOT_FOUND )
+ m_selection.RemoveAt(rowIndexInSelection);
}
}
else // general case
{
wxDataViewTreeNode * node = FindNode(parent);
- int itemPosInNode = node ? node->GetChildren().Index(item.GetID()) : wxNOT_FOUND;
// Notice that it is possible that the item being deleted is not in the
// tree at all, for example we could be deleting a never shown (because
// collapsed) item in a tree model. So it's not an error if we don't know
// about this item, just return without doing anything then.
- if ( !node || itemPosInNode == wxNOT_FOUND )
+ if ( !node )
+ return false;
+
+ int itemPosInNode = node->GetChildren().Index(item.GetID());
+ if ( itemPosInNode == wxNOT_FOUND )
return false;
bool isContainer = false;
if( m_currentRow > GetRowCount() )
ChangeCurrentRow(m_count - 1);
+ GetOwner()->UpdateColBestWidths();
UpdateDisplay();
return true;
bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
{
- GetOwner()->InvalidateColBestWidths();
-
SortPrepare();
g_model->Resort();
+ GetOwner()->UpdateColBestWidths();
+
// Send event
wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
if (view_column == -1)
return false;
- GetOwner()->InvalidateColBestWidth(view_column);
-
// NOTE: to be valid, we cannot use e.g. INT_MAX - 1
/*#define MAX_VIRTUAL_WIDTH 100000
SortPrepare();
g_model->Resort();
+ GetOwner()->UpdateColBestWidth(view_column);
+
// Send event
wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
bool wxDataViewMainWindow::Cleared()
{
- GetOwner()->InvalidateColBestWidths();
-
DestroyTree();
m_selection.Clear();
SortPrepare();
BuildTree( GetOwner()->GetModel() );
+ GetOwner()->UpdateColBestWidths();
UpdateDisplay();
return true;
return;
}
- // Test whether the mouse is hovered on the tree item button
+ // Test whether the mouse is hovering over the expander (a.k.a tree "+"
+ // button) and also determine the offset of the real cell start, skipping
+ // the indentation and the expander itself.
bool hoverOverExpander = false;
+ int expanderOffset = 0;
if ((!IsList()) && (GetOwner()->GetExpanderColumn() == col))
{
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
wxRect rect( xpos + indent,
GetLineStart( current ) + (GetLineHeight(current) - m_lineHeight)/2,
m_lineHeight, m_lineHeight);
+
+ expanderOffset = indent + m_lineHeight;
+
if( rect.Contains(x, y) )
{
// So the mouse is over the expander
// notify cell about click
cell->PrepareForItem(model, item, col->GetModelColumn());
- wxRect cell_rect( xpos, GetLineStart( current ),
- col->GetWidth(), GetLineHeight( current ) );
+ wxRect cell_rect( xpos + expanderOffset,
+ GetLineStart( current ),
+ col->GetWidth() - expanderOffset,
+ GetLineHeight( current ) );
// Report position relative to the cell's custom area, i.e.
// no the entire space as given by the control but the one
event.Skip();
}
-wxDataViewItem wxDataViewMainWindow::GetSelection() const
-{
- if( m_selection.GetCount() != 1 )
- return wxDataViewItem();
-
- return GetItemByRow( m_selection.Item(0));
-}
-
//-----------------------------------------------------------------------------
// wxDataViewCtrl
//-----------------------------------------------------------------------------
return true;
}
-void wxDataViewCtrl::InvalidateColBestWidth(int idx)
+void wxDataViewCtrl::UpdateColBestWidth(int idx)
{
m_colsBestWidths[idx] = 0;
m_headerArea->UpdateColumn(idx);
}
-void wxDataViewCtrl::InvalidateColBestWidths()
+void wxDataViewCtrl::UpdateColBestWidths()
{
m_colsBestWidths.clear();
m_colsBestWidths.resize(m_cols.size());
}
}
-// Selection code with wxDataViewItem as parameters
-wxDataViewItem wxDataViewCtrl::GetSelection() const
+int wxDataViewCtrl::GetSelectedItemsCount() const
{
- return m_clientArea->GetSelection();
+ return m_clientArea->GetSelections().size();
}
int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const