+ parent->GetEventHandler()->ProcessEvent(le);
+ return le;
+}
+
+bool wxDataViewMainWindow::IsExpanded( unsigned int row ) const
+{
+ if (IsList())
+ return false;
+
+ wxDataViewTreeNode * node = GetTreeNodeByRow(row);
+ if (!node)
+ return false;
+
+ if (!node->HasChildren())
+ {
+ delete node;
+ return false;
+ }
+
+ return node->IsOpen();
+}
+
+bool wxDataViewMainWindow::HasChildren( unsigned int row ) const
+{
+ if (IsList())
+ return false;
+
+ wxDataViewTreeNode * node = GetTreeNodeByRow(row);
+ if (!node)
+ return false;
+
+ if (!node->HasChildren())
+ {
+ delete node;
+ return false;
+ }
+
+ return true;
+}
+
+void wxDataViewMainWindow::Expand( unsigned int row )
+{
+ if (IsList())
+ return;
+
+ wxDataViewTreeNode * node = GetTreeNodeByRow(row);
+ if (!node)
+ return;
+
+ if (!node->HasChildren())
+ {
+ delete node;
+ return;
+ }
+
+ if (!node->IsOpen())
+ {
+ wxDataViewEvent e =
+ SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, node->GetItem());
+
+ // Check if the user prevent expanding
+ if( e.GetSkipped() )
+ return;
+
+ node->ToggleOpen();
+
+ // build the children of current node
+ if( node->GetChildrenNumber() == 0 )
+ {
+ SortPrepare();
+ ::BuildTreeHelper(GetOwner()->GetModel(), node->GetItem(), node);
+ }
+
+ // By expanding the node all row indices that are currently in the selection list
+ // and are greater than our node have become invalid. So we have to correct that now.
+ const unsigned rowAdjustment = node->GetSubTreeCount();
+ for(unsigned i=0; i<m_selection.size(); ++i)
+ {
+ const unsigned testRow = m_selection[i];
+ // all rows above us are not affected, so skip them
+ if(testRow <= row)
+ continue;
+
+ m_selection[i] += rowAdjustment;
+ }
+
+ if(m_currentRow > row)
+ ChangeCurrentRow(m_currentRow + rowAdjustment);
+
+ m_count = -1;
+ UpdateDisplay();
+ // Send the expanded event
+ SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,node->GetItem());
+ }
+}
+
+void wxDataViewMainWindow::Collapse(unsigned int row)
+{
+ if (IsList())
+ return;
+
+ wxDataViewTreeNode *node = GetTreeNodeByRow(row);
+ if (!node)
+ return;
+
+ if (!node->HasChildren())
+ {
+ delete node;
+ return;
+ }
+
+ if (node->IsOpen())
+ {
+ wxDataViewEvent e =
+ SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,node->GetItem());
+ if( e.GetSkipped() )
+ return;
+
+ // Find out if there are selected items below the current node.
+ bool selectCollapsingRow = false;
+ const unsigned rowAdjustment = node->GetSubTreeCount();
+ unsigned maxRowToBeTested = row + rowAdjustment;
+ for(unsigned i=0; i<m_selection.size(); ++i)
+ {
+ const unsigned testRow = m_selection[i];
+ if(testRow > row && testRow <= maxRowToBeTested)
+ {
+ selectCollapsingRow = true;
+ // get out as soon as we have found a node that is selected
+ break;
+ }
+ }
+
+ node->ToggleOpen();
+
+ // If the node to be closed has selected items the user won't see those any longer.
+ // We select the collapsing node in this case.
+ if(selectCollapsingRow)
+ {
+ SelectAllRows(false);
+ ChangeCurrentRow(row);
+ SelectRow(row, true);
+ SendSelectionChangedEvent(GetItemByRow(row));
+ }
+ else
+ {
+ // if there were no selected items below our node we still need to "fix" the
+ // selection list to adjust for the changing of the row indices.
+ // We actually do the opposite of what we are doing in Expand().
+ for(unsigned i=0; i<m_selection.size(); ++i)
+ {
+ const unsigned testRow = m_selection[i];
+ // all rows above us are not affected, so skip them
+ if(testRow <= row)
+ continue;
+
+ m_selection[i] -= rowAdjustment;
+ }
+
+ // if the "current row" is being collapsed away we change it to the current row ;-)
+ if(m_currentRow > row && m_currentRow <= maxRowToBeTested)
+ ChangeCurrentRow(row);
+ else if(m_currentRow > row)
+ ChangeCurrentRow(m_currentRow - rowAdjustment);
+ }
+
+ m_count = -1;
+ UpdateDisplay();
+ SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,node->GetItem());
+ }
+}
+
+wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item )
+{
+ const wxDataViewModel * model = GetOwner()->GetModel();
+ if( model == NULL )
+ return NULL;
+
+ if (!item.IsOk())
+ return m_root;
+
+ // Compose the parent-chain for the item we are looking for
+ wxVector<wxDataViewItem> parentChain;
+ wxDataViewItem it( item );
+ while( it.IsOk() )
+ {
+ parentChain.push_back(it);
+ it = model->GetParent(it);
+ }
+
+ // Find the item along the parent-chain.
+ // This algorithm is designed to speed up the node-finding method
+ wxDataViewTreeNode* node = m_root;
+ for( unsigned iter = parentChain.size()-1; iter>=0; --iter )
+ {
+ if( node->HasChildren() )
+ {
+ if( node->GetChildrenNumber() == 0 )
+ {
+ SortPrepare();
+ ::BuildTreeHelper(model, node->GetItem(), node);
+ }
+
+ const wxDataViewTreeNodes& nodes = node->GetNodes();
+ bool found = false;
+
+ for (unsigned i = 0; i < nodes.GetCount(); ++i)
+ {
+ wxDataViewTreeNode* currentNode = nodes[i];
+ if (currentNode->GetItem() == parentChain[iter])
+ {
+ if (currentNode->GetItem() == item)
+ return currentNode;
+
+ node = currentNode;
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ return NULL;
+ }
+ else
+ return NULL;
+ }
+ return NULL;
+}
+
+void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item,
+ wxDataViewColumn* &column )
+{
+ wxDataViewColumn *col = NULL;
+ unsigned int cols = GetOwner()->GetColumnCount();
+ unsigned int colnum = 0;
+ int x, y;
+ m_owner->CalcUnscrolledPosition( point.x, point.y, &x, &y );
+ for (unsigned x_start = 0; colnum < cols; colnum++)
+ {
+ col = GetOwner()->GetColumnAt(colnum);
+ if (col->IsHidden())
+ continue; // skip it!
+
+ unsigned int w = col->GetWidth();
+ if (x_start+w >= (unsigned int)x)
+ break;
+
+ x_start += w;
+ }
+
+ column = col;
+ item = GetItemByRow( GetLineAt( y ) );
+}
+
+wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item,
+ const wxDataViewColumn* column )
+{
+ int xpos = 0;
+ int width = 0;
+
+ unsigned int cols = GetOwner()->GetColumnCount();
+ // If column is null the loop will compute the combined width of all columns.
+ // Otherwise, it will compute the x position of the column we are looking for.
+ for (unsigned int i = 0; i < cols; i++)
+ {
+ wxDataViewColumn* col = GetOwner()->GetColumnAt( i );
+
+ if (col == column)
+ break;
+
+ if (col->IsHidden())
+ continue; // skip it!
+
+ xpos += col->GetWidth();
+ width += col->GetWidth();
+ }
+
+ if(column != 0)
+ {
+ // If we have a column, we need can get its width directly.
+ if(column->IsHidden())
+ width = 0;
+ else
+ width = column->GetWidth();
+
+ }
+ else
+ {
+ // If we have no column, we reset the x position back to zero.
+ xpos = 0;
+ }
+
+ // we have to take an expander column into account and compute its indentation
+ // to get the correct x position where the actual text is
+ int indent = 0;
+ int row = GetRowByItem(item);
+ if (!IsList() && (column == 0 || GetOwner()->GetExpanderColumn() == column) )
+ {
+ wxDataViewTreeNode* node = GetTreeNodeByRow(row);
+ indent = GetOwner()->GetIndent() * node->GetIndentLevel();
+ indent = indent + m_lineHeight; // use m_lineHeight as the width of the expander
+
+ if(!node->HasChildren())
+ delete node;
+ }
+
+ wxRect itemRect( xpos + indent,
+ GetLineStart( row ),
+ width - indent,
+ GetLineHeight( row ) );
+
+ GetOwner()->CalcScrolledPosition( itemRect.x, itemRect.y,
+ &itemRect.x, &itemRect.y );
+
+ return itemRect;
+}
+
+int wxDataViewMainWindow::RecalculateCount()
+{
+ if (IsVirtualList())
+ {
+ wxDataViewVirtualListModel *list_model =
+ (wxDataViewVirtualListModel*) GetOwner()->GetModel();
+
+ return list_model->GetCount();
+ }
+ else
+ {
+ return m_root->GetSubTreeCount();
+ }
+}
+
+class ItemToRowJob : public DoJob
+{
+public:
+ ItemToRowJob(const wxDataViewItem& item_, wxVector<wxDataViewItem>::reverse_iterator iter)
+ : m_iter(iter),
+ item(item_)
+ {
+ ret = -1;
+ }
+
+ // Maybe binary search will help to speed up this process
+ virtual int operator() ( wxDataViewTreeNode * node)
+ {
+ ret ++;
+ if( node->GetItem() == item )
+ {
+ return DoJob::OK;
+ }
+
+ if( node->GetItem() == *m_iter )
+ {
+ m_iter++;
+ return DoJob::CONT;
+ }
+ else
+ {
+ ret += node->GetSubTreeCount();
+ return DoJob::IGR;
+ }
+
+ }
+
+ virtual int operator() ( void * n )
+ {
+ ret ++;
+ if( n == item.GetID() )
+ return DoJob::OK;
+ return DoJob::CONT;
+ }
+
+ // the row number is begin from zero
+ int GetResult() const
+ { return ret -1; }
+
+private:
+ wxVector<wxDataViewItem>::reverse_iterator m_iter;
+ wxDataViewItem item;
+ int ret;
+
+};
+
+int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) const
+{
+ const wxDataViewModel * model = GetOwner()->GetModel();
+ if( model == NULL )
+ return -1;
+
+ if (IsVirtualList())
+ {
+ return wxPtrToUInt( item.GetID() ) -1;
+ }
+ else
+ {
+ if( !item.IsOk() )
+ return -1;
+
+ // Compose the parent-chain of the item we are looking for
+ wxVector<wxDataViewItem> parentChain;
+ wxDataViewItem it( item );
+ while( it.IsOk() )
+ {
+ parentChain.push_back(it);
+ it = model->GetParent(it);
+ }
+
+ // add an 'invalid' item to represent our 'invisible' root node
+ parentChain.push_back(wxDataViewItem());
+
+ // the parent chain was created by adding the deepest parent first.
+ // so if we want to start at the root node, we have to iterate backwards through the vector
+ ItemToRowJob job( item, parentChain.rbegin() );
+ Walker( m_root, job );
+ return job.GetResult();
+ }
+}
+
+static void BuildTreeHelper( const wxDataViewModel * model, const wxDataViewItem & item,
+ wxDataViewTreeNode * node)
+{
+ if( !model->IsContainer( item ) )
+ return;
+
+ wxDataViewItemArray children;
+ unsigned int num = model->GetChildren( item, children);
+
+ unsigned int index = 0;
+ while( index < num )
+ {
+ if( model->IsContainer( children[index] ) )
+ {
+ wxDataViewTreeNode * n = new wxDataViewTreeNode( node );
+ n->SetItem(children[index]);
+ n->SetHasChildren( true );
+ node->AddNode( n );
+ }
+ else
+ {
+ node->AddLeaf( children[index].GetID() );
+ }
+ index ++;
+ }
+ node->SetSubTreeCount( num );
+ wxDataViewTreeNode * n = node->GetParent();
+ if( n != NULL)
+ n->ChangeSubTreeCount(num);
+
+}
+
+void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)
+{
+ DestroyTree();
+
+ if (GetOwner()->GetModel()->IsVirtualListModel())
+ {
+ m_count = -1;
+ return;
+ }
+
+ m_root = new wxDataViewTreeNode( NULL );
+ m_root->SetHasChildren(true);
+
+ // First we define a invalid item to fetch the top-level elements
+ wxDataViewItem item;
+ SortPrepare();
+ BuildTreeHelper( model, item, m_root);
+ m_count = -1;
+}
+
+static void DestroyTreeHelper( wxDataViewTreeNode * node )
+{
+ if( node->GetNodeNumber() != 0 )
+ {
+ int len = node->GetNodeNumber();
+ wxDataViewTreeNodes& nodes = node->GetNodes();
+ for (int i = 0; i < len; i++)
+ DestroyTreeHelper(nodes[i]);
+ }
+ delete node;
+}
+
+void wxDataViewMainWindow::DestroyTree()
+{
+ if (!IsVirtualList())
+ {
+ ::DestroyTreeHelper(m_root);
+ m_count = 0;
+ m_root = NULL;
+ }
+}
+
+void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
+{
+ wxWindow * const parent = GetParent();
+
+ // propagate the char event upwards
+ wxKeyEvent eventForParent(event);
+ eventForParent.SetEventObject(parent);
+ if ( parent->ProcessWindowEvent(eventForParent) )
+ return;
+
+ if ( parent->HandleAsNavigationKey(event) )
+ return;
+
+ // no item -> nothing to do
+ if (!HasCurrentRow())
+ {
+ event.Skip();
+ return;
+ }
+
+ // don't use m_linesPerPage directly as it might not be computed yet
+ const int pageSize = GetCountPerPage();
+ wxCHECK_RET( pageSize, wxT("should have non zero page size") );
+
+ switch ( event.GetKeyCode() )
+ {
+ case WXK_RETURN:
+ {
+ wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,
+ parent->GetId());
+ le.SetItem( GetItemByRow(m_currentRow) );
+ le.SetEventObject(parent);
+ le.SetModel(GetOwner()->GetModel());
+
+ parent->GetEventHandler()->ProcessEvent(le);
+ }
+ break;
+
+ case WXK_UP:
+ if ( m_currentRow > 0 )
+ OnArrowChar( m_currentRow - 1, event );
+ break;
+
+ case WXK_DOWN:
+ if ( m_currentRow < GetRowCount() - 1 )
+ OnArrowChar( m_currentRow + 1, event );
+ break;
+ // Add the process for tree expanding/collapsing
+ case WXK_LEFT:
+ {
+ if (IsList())
+ break;
+
+ wxDataViewTreeNode* node = GetTreeNodeByRow(m_currentRow);
+ if (!node)
+ break;
+
+ if (node->HasChildren() && node->IsOpen())
+ {
+ Collapse(m_currentRow);
+ }
+ else // if the node is already closed we move the selection to its parent
+ {
+ wxDataViewTreeNode *parent_node = node->GetParent();
+
+ if(!node->HasChildren())
+ delete node;
+
+ if (parent_node)
+ {
+ int parent = GetRowByItem( parent_node->GetItem() );
+ if ( parent >= 0 )
+ {
+ unsigned int row = m_currentRow;
+ SelectRow( row, false);
+ SelectRow( parent, true );
+ ChangeCurrentRow( parent );
+ GetOwner()->EnsureVisible( parent, -1 );
+ SendSelectionChangedEvent( parent_node->GetItem() );
+ }
+ }
+ }
+ break;
+ }
+ case WXK_RIGHT:
+ {
+ if (!IsExpanded( m_currentRow ))
+ Expand( m_currentRow );
+ else
+ {
+ unsigned int row = m_currentRow;
+ SelectRow( row, false );
+ SelectRow( row + 1, true );
+ ChangeCurrentRow( row + 1 );
+ GetOwner()->EnsureVisible( row + 1, -1 );
+ SendSelectionChangedEvent( GetItemByRow(row+1) );
+ }
+ break;
+ }
+ case WXK_END:
+ {
+ if (!IsEmpty())
+ OnArrowChar( GetRowCount() - 1, event );
+ break;
+ }
+ case WXK_HOME:
+ if (!IsEmpty())
+ OnArrowChar( 0, event );
+ break;
+
+ case WXK_PAGEUP:
+ {
+ int steps = pageSize - 1;
+ int index = m_currentRow - steps;
+ if (index < 0)
+ index = 0;
+
+ OnArrowChar( index, event );
+ }
+ break;
+
+ case WXK_PAGEDOWN:
+ {
+ int steps = pageSize - 1;
+ unsigned int index = m_currentRow + steps;
+ unsigned int count = GetRowCount();
+ if ( index >= count )
+ index = count - 1;
+
+ OnArrowChar( index, event );
+ }
+ break;
+
+ case WXK_F2:
+ {
+ if(m_selection.size() == 1)
+ {
+ // TODO: we need to revise that when we have a concept for a 'current column'
+ GetOwner()->StartEditor(GetItemByRow(m_selection[0]), 0);
+ }
+ }
+ break;
+
+ default:
+ event.Skip();
+ }
+}
+
+void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
+{
+ if (event.GetEventType() == wxEVT_MOUSEWHEEL)
+ {
+ // let the base handle mouse wheel events.
+ event.Skip();
+ return;
+ }
+
+ // set the focus to ourself if any of the mouse buttons are pressed
+ if(event.ButtonDown() && !HasFocus())
+ SetFocus();
+
+ int x = event.GetX();
+ int y = event.GetY();
+ m_owner->CalcUnscrolledPosition( x, y, &x, &y );
+ wxDataViewColumn *col = NULL;
+
+ int xpos = 0;
+ unsigned int cols = GetOwner()->GetColumnCount();
+ unsigned int i;
+ for (i = 0; i < cols; i++)
+ {
+ wxDataViewColumn *c = GetOwner()->GetColumnAt( i );
+ if (c->IsHidden())
+ continue; // skip it!
+
+ if (x < xpos + c->GetWidth())
+ {
+ col = c;
+ break;
+ }
+ xpos += c->GetWidth();
+ }
+ if (!col)
+ {
+ event.Skip();
+ return;
+ }
+
+ wxDataViewRenderer *cell = col->GetRenderer();
+ unsigned int current = GetLineAt( y );
+ if ((current >= GetRowCount()) || (x > GetEndOfLastCol()))
+ {
+ // Unselect all if below the last row ?
+ event.Skip();
+ return;
+ }
+
+ // Test whether the mouse is hovered on the tree item button
+ bool hoverOverExpander = false;
+ if ((!IsList()) && (GetOwner()->GetExpanderColumn() == col))
+ {
+ wxDataViewTreeNode * node = GetTreeNodeByRow(current);
+ if( node!=NULL && node->HasChildren() )
+ {
+ int indent = node->GetIndentLevel();
+ indent = GetOwner()->GetIndent()*indent;
+
+ // we make the rectangle we are looking in a bit bigger than the actual
+ // visual expander so the user can hit that little thing reliably
+ wxRect rect( xpos + indent,
+ GetLineStart( current ) + (GetLineHeight(current) - m_lineHeight)/2,
+ m_lineHeight, m_lineHeight);
+ if( rect.Contains(x, y) )
+ {
+ // So the mouse is over the expander
+ hoverOverExpander = true;
+ if (m_underMouse && m_underMouse != node)
+ {
+ // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
+ RefreshRow(GetRowByItem(m_underMouse->GetItem()));
+ }
+ if (m_underMouse != node)
+ {
+ // wxLogMessage("Do the row: %d", current);
+ RefreshRow(current);
+ }
+ m_underMouse = node;
+ }
+ }
+ if (node!=NULL && !node->HasChildren())
+ delete node;
+ }
+ if (!hoverOverExpander)
+ {
+ if (m_underMouse != NULL)
+ {
+ // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
+ RefreshRow(GetRowByItem(m_underMouse->GetItem()));
+ m_underMouse = NULL;
+ }
+ }
+
+ wxDataViewModel *model = GetOwner()->GetModel();
+
+#if wxUSE_DRAG_AND_DROP
+ if (event.Dragging())
+ {
+ if (m_dragCount == 0)
+ {
+ // we have to report the raw, physical coords as we want to be
+ // able to call HitTest(event.m_pointDrag) from the user code to
+ // get the item being dragged
+ m_dragStart = event.GetPosition();
+ }
+
+ m_dragCount++;
+
+ if (m_dragCount != 3)
+ return;
+
+ if (event.LeftIsDown())
+ {
+ m_owner->CalcUnscrolledPosition( m_dragStart.x, m_dragStart.y,
+ &m_dragStart.x, &m_dragStart.y );
+ unsigned int drag_item_row = GetLineAt( m_dragStart.y );
+ wxDataViewItem item = GetItemByRow( drag_item_row );
+
+ // Notify cell about drag
+ wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() );
+ event.SetEventObject( m_owner );
+ event.SetItem( item );
+ event.SetModel( model );
+ if (!m_owner->HandleWindowEvent( event ))
+ return;
+
+ if (!event.IsAllowed())
+ return;
+
+ wxDataObject *obj = event.GetDataObject();
+ if (!obj)
+ return;
+
+ wxDataViewDropSource drag( this, drag_item_row );
+ drag.SetData( *obj );
+ /* wxDragResult res = */ drag.DoDragDrop();
+ delete obj;
+ }
+ return;
+ }
+ else
+ {
+ m_dragCount = 0;
+ }
+#endif // wxUSE_DRAG_AND_DROP
+
+ bool simulateClick = false;
+
+ if (event.ButtonDClick())
+ {
+ m_renameTimer->Stop();
+ m_lastOnSame = false;
+ }
+
+ wxDataViewItem item = GetItemByRow(current);
+ bool ignore_other_columns =
+ ((GetOwner()->GetExpanderColumn() != col) &&
+ (model->IsContainer(item)) &&
+ (!model->HasContainerColumns(item)));
+
+ if (event.LeftDClick())
+ {
+ if(hoverOverExpander)
+ {
+ // a double click on the expander will be converted into a "simulated" normal click
+ simulateClick = true;
+ }
+ else if ( current == m_lineLastClicked )
+ {
+ if ((!ignore_other_columns) && (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE))
+ {
+ const unsigned colIdx = col->GetModelColumn();
+
+ wxVariant value;
+ model->GetValue( value, item, colIdx );
+
+ cell->WXOnActivate(model, value, item, colIdx);
+
+ if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
+ {
+ cell->SetValue( value );
+
+ wxRect cell_rect( xpos, GetLineStart( current ),
+ col->GetWidth(), GetLineHeight( current ) );
+ custom->Activate( cell_rect, model, item, colIdx );
+ }
+ }
+ else
+ {
+ wxWindow *parent = GetParent();
+ wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, parent->GetId());
+ le.SetItem( item );
+ le.SetColumn( col->GetModelColumn() );
+ le.SetDataViewColumn( col );
+ le.SetEventObject(parent);
+ le.SetModel(GetOwner()->GetModel());
+
+ parent->GetEventHandler()->ProcessEvent(le);
+ }
+ return;
+ }
+ else
+ {
+ // The first click was on another item, so don't interpret this as
+ // a double click, but as a simple click instead
+ simulateClick = true;
+ }
+ }
+
+ if (event.LeftUp() && !hoverOverExpander)
+ {
+ if (m_lineSelectSingleOnUp != (unsigned int)-1)
+ {
+ // select single line
+ SelectAllRows( false );
+ SelectRow( m_lineSelectSingleOnUp, true );
+ SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp) );
+ }
+
+ // If the user click the expander, we do not do editing even if the column
+ // with expander are editable
+ if (m_lastOnSame && !ignore_other_columns)
+ {
+ if ((col == m_currentCol) && (current == m_currentRow) &&
+ (cell->GetMode() & wxDATAVIEW_CELL_EDITABLE) )
+ {
+ m_renameTimer->Start( 100, true );
+ }
+ }
+
+ m_lastOnSame = false;
+ m_lineSelectSingleOnUp = (unsigned int)-1;
+ }
+ else if(!event.LeftUp())
+ {
+ // This is necessary, because after a DnD operation in
+ // from and to ourself, the up event is swallowed by the
+ // DnD code. So on next non-up event (which means here and
+ // now) m_lineSelectSingleOnUp should be reset.
+ m_lineSelectSingleOnUp = (unsigned int)-1;
+ }
+
+ if (event.RightDown())
+ {
+ m_lineBeforeLastClicked = m_lineLastClicked;
+ m_lineLastClicked = current;
+
+ // If the item is already selected, do not update the selection.
+ // Multi-selections should not be cleared if a selected item is clicked.
+ if (!IsRowSelected(current))
+ {
+ SelectAllRows(false);
+ ChangeCurrentRow(current);
+ SelectRow(m_currentRow,true);
+ SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
+ }
+ }
+ else if (event.RightUp())
+ {
+ wxVariant value;
+ model->GetValue( value, item, col->GetModelColumn() );
+ wxWindow *parent = GetParent();
+ wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId());
+ le.SetItem( item );
+ le.SetColumn( col->GetModelColumn() );
+ le.SetDataViewColumn( col );
+ le.SetEventObject(parent);
+ le.SetModel(GetOwner()->GetModel());
+ le.SetValue(value);
+ parent->GetEventHandler()->ProcessEvent(le);
+ }
+ else if (event.MiddleDown())
+ {
+ }
+
+ if((event.LeftDown() || simulateClick) && hoverOverExpander)
+ {
+ wxDataViewTreeNode* node = GetTreeNodeByRow(current);
+
+ // hoverOverExpander being true tells us that our node must be
+ // valid and have children.
+ // So we don't need any extra checks.
+ if( node->IsOpen() )
+ Collapse(current);
+ else
+ Expand(current);
+ }
+ else if ((event.LeftDown() || simulateClick) && !hoverOverExpander)
+ {
+ m_lineBeforeLastClicked = m_lineLastClicked;
+ m_lineLastClicked = current;
+
+ unsigned int oldCurrentRow = m_currentRow;
+ bool oldWasSelected = IsRowSelected(m_currentRow);
+
+ bool cmdModifierDown = event.CmdDown();
+ if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
+ {
+ if ( IsSingleSel() || !IsRowSelected(current) )
+ {
+ SelectAllRows( false );
+ ChangeCurrentRow(current);
+ SelectRow(m_currentRow,true);
+ SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
+ }
+ else // multi sel & current is highlighted & no mod keys
+ {
+ m_lineSelectSingleOnUp = current;
+ ChangeCurrentRow(current); // change focus
+ }
+ }
+ else // multi sel & either ctrl or shift is down
+ {
+ if (cmdModifierDown)
+ {
+ ChangeCurrentRow(current);
+ ReverseRowSelection(m_currentRow);
+ SendSelectionChangedEvent(GetItemByRow(m_currentRow));
+ }
+ else if (event.ShiftDown())
+ {
+ ChangeCurrentRow(current);
+
+ unsigned int lineFrom = oldCurrentRow,
+ lineTo = current;
+
+ if ( lineTo < lineFrom )
+ {
+ lineTo = lineFrom;
+ lineFrom = m_currentRow;
+ }
+
+ SelectRows(lineFrom, lineTo, true);
+ SendSelectionChangedEvent(GetItemByRow(m_selection[0]) );
+ }
+ else // !ctrl, !shift
+ {
+ // test in the enclosing if should make it impossible
+ wxFAIL_MSG( wxT("how did we get here?") );
+ }
+ }
+
+ if (m_currentRow != oldCurrentRow)
+ RefreshRow( oldCurrentRow );
+
+ wxDataViewColumn *oldCurrentCol = m_currentCol;
+
+ // Update selection here...
+ m_currentCol = col;
+
+ m_lastOnSame = !simulateClick && ((col == oldCurrentCol) &&
+ (current == oldCurrentRow)) && oldWasSelected;
+
+ // Call LeftClick after everything else as under GTK+
+ if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE)
+ {
+ if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
+ {
+ // notify cell about click
+ custom->PrepareForItem(model, item, col->GetModelColumn());
+
+ wxRect cell_rect( xpos, GetLineStart( current ),
+ col->GetWidth(), 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
+ // used by the renderer after calculation of alignment etc.
+
+ // adjust the rectangle ourselves to account for the alignment
+ wxRect rectItem = cell_rect;
+ const int align = custom->GetAlignment();
+ if ( align != wxDVR_DEFAULT_ALIGNMENT )
+ {
+ const wxSize size = custom->GetSize();
+
+ if ( size.x >= 0 && size.x < cell_rect.width )
+ {
+ if ( align & wxALIGN_CENTER_HORIZONTAL )
+ rectItem.x += (cell_rect.width - size.x)/2;
+ else if ( align & wxALIGN_RIGHT )
+ rectItem.x += cell_rect.width - size.x;
+ // else: wxALIGN_LEFT is the default
+ }
+
+ if ( size.y >= 0 && size.y < cell_rect.height )
+ {
+ if ( align & wxALIGN_CENTER_VERTICAL )
+ rectItem.y += (cell_rect.height - size.y)/2;
+ else if ( align & wxALIGN_BOTTOM )
+ rectItem.y += cell_rect.height - size.y;
+ // else: wxALIGN_TOP is the default
+ }
+ }
+
+ wxPoint pos( event.GetPosition() );
+ pos.x -= rectItem.x;
+ pos.y -= rectItem.y;
+
+ m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y );
+
+ /* ignore ret */ custom->LeftClick( pos, cell_rect,
+ model, item, col->GetModelColumn());
+ }
+ }