示例#1
0
HTREEITEM CTreeViewEx::GetDropItem(eTYPE_DROPPING & eDroppingPos) 
{
	CTreeCtrl &omTreeCtrl = GetTreeCtrl();
	CPoint omCurrentPoint;
	GetCursorPos(&omCurrentPoint);
	ScreenToClient(&omCurrentPoint);

	UINT flags;
	HTREEITEM hDroppingItem = omTreeCtrl.HitTest(omCurrentPoint, &flags);

	eDroppingPos = GetDroppingPosition(flags);
    
    if(IsItemCanDropOn(m_hDraggingItemgedItem, hDroppingItem) == FALSE)
    {
         eDroppingPos = NO_DROPPING;
    }
	if(hDroppingItem) 
    {
        m_pomDragImageList->DragLeave(&omTreeCtrl);
		omTreeCtrl.SelectDropTarget(hDroppingItem);

		// Make sure the surrounding items are visible, too
		// This will scroll the tree if necessary.
		HTREEITEM hPrev = omTreeCtrl.GetPrevVisibleItem(hDroppingItem);
		if(hPrev)
        {
		    omTreeCtrl.EnsureVisible(hPrev);
        }

		HTREEITEM hNext = omTreeCtrl.GetNextVisibleItem(hDroppingItem);
		if(hNext)
        {
		    omTreeCtrl.EnsureVisible(hNext);
        }
		
        CPoint omCurPoint;
	    GetCursorPos(&omCurPoint);
	    ScreenToClient(&omCurPoint);
        m_pomDragImageList->DragEnter(&omTreeCtrl, omCurPoint);
	} 
    else if(eDroppingPos != NO_DROPPING && !IsItemCanDropOn(m_hDraggingItemgedItem, hDroppingItem))
    {
	    eDroppingPos = NO_DROPPING;
    }

	return hDroppingItem;
}
示例#2
0
HTREEITEM CTreeViewEx::DragMoveItem(HTREEITEM hDraggingItem, HTREEITEM hDroppingItem, eTYPE_DROPPING eDropping)
{
    CTreeCtrl& omTreeCtrl = GetTreeCtrl();

    if(eDropping == NO_DROPPING)
    {
        return NULL;
    }

    if(bAnscestor(hDraggingItem, hDroppingItem) || !IsItemCanDropOn(hDraggingItem, hDroppingItem))
    {
        return NULL;
    }

    if(bSuccessor(hDraggingItem, hDroppingItem) && (eDropping == DROPPING_ABOVE))
    {
        return NULL;
    }

    if(hDraggingItem == hDroppingItem)
    {
        return NULL;
    }

    if(!hDroppingItem && eDropping == DROPPING_BELOW)
        for(hDroppingItem = omTreeCtrl.GetRootItem(); omTreeCtrl.GetNextSiblingItem(hDroppingItem) != 0; hDroppingItem = omTreeCtrl.GetNextSiblingItem(hDroppingItem));

    // Setup insertion parameters
    HTREEITEM hInsertAfter = 0;
    HTREEITEM hParent = 0;

    switch(eDropping)
    {
        case DROPPING_BELOW:
            hInsertAfter = hDroppingItem;
            hParent = omTreeCtrl.GetParentItem(hDroppingItem);
            break;

        case DROPPING_ABOVE:
            hInsertAfter = omTreeCtrl.GetPrevSiblingItem(hDroppingItem);

            if(!hInsertAfter)
            {
                hInsertAfter = TVI_FIRST;
            }

            hParent = omTreeCtrl.GetParentItem(hDroppingItem);
            break;

        default:
            ASSERT(false);
            break;
    }

    m_hDraggingItemgedItem = CopyTotalBranch(hDraggingItem, hParent, hInsertAfter);
    omTreeCtrl.DeleteItem(hDraggingItem);
    return hInsertAfter;
}