TreeViewItem getPositionWithinTreeView issue


#1

Hi

i am trying to make simple drag and drop in the TreeView between TreeViewItems. i have attached a MouseListener to the TreeView to check change the cursor and validate the dragging.
My problem is to define where in the TreeView i am during the dragging, because in some cases the dragging should not be allowed depending on the initial (item to drag)item and the item i’m over with the cursor.

To identify where i am in the treeView during the drag and drop i try to use getPositionWithinTreeView
but the Rectangle always gives me the initial position of the teeItem.
If i scroll the treeView this position is not the correct rectangle of the treeItem, because it still gives back the treeViewItem’s original rectangle

Is there a more effective way to define the possible destination TreeViewItem or there is an other way then getPositionWithinTreeView to identify the TreeViewItem im am over with the mouse

thanks


#2

Good point. I’ll rework that method to let you specify whether it’s relative to the treeview comp itself or not - something like this:

[code]const Rectangle TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const
{
const int indentX = getIndentX();

int width = itemWidth;

if (ownerView != 0 && width < 0)
    width = ownerView->viewport->getViewWidth() - indentX;

Rectangle r (indentX, y, jmax (0, width), totalHeight);

if (relativeToTreeViewTopLeft)
    r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
                   r.getY() - ownerView->viewport->getViewPositionY());

return r;

}[/code]


#3

While you’re there :slight_smile: - please could you have an option to account for the viewport, in case it’s scrolled, and also check whether the root item being visible affects the returned position. Currently, I suspect the root item being hidden makes everything shifted down one place.

Bruce


#4

True, when the root item is not visible, the positions returned by getItemPosition() are not correct anymore.


#5