Hide

SftTree/DLL 7.5 - Tree Control

Display
Print

DropHighlight

Defines the current drag & drop target location.

C

int WINAPI SftTree_GetDropHighlight(HWND hwndCtl);
int WINAPI SftTree_SetDropHighlight(HWND hwndCtl, int index, BOOL fScroll);
int WINAPI SftTreeSplit_GetDropHighlight(HWND hwndCtl);
int WINAPI SftTreeSplit_SetDropHighlight(HWND hwndCtl, int index, BOOL fScroll);

C++

int CSftTree::GetDropHighlight() const;
int CSftTree::SetDropHighlight(int index, BOOL fScroll = FALSE);
int CSftTreeSplit::GetDropHighlight() const;
int CSftTreeSplit::SetDropHighlight(int index, BOOL fScroll = FALSE);

Parameters

hwndCtl

The window handle of the tree control.

index

The zero-based index of the item which is the new drop target or -1 to clear the current drop target. If SetDropHighlightStyle is set to SFTTREE_DROPHIGHLIGHT_BETWEEN, index can be set to the index of the last item +1, which causes the drop target to be displayed beyond the last item.

fScroll

Set to TRUE to define that items should be scrolled vertically if the drop target index is the first or last item currently displayed in the tree control's client area. Set to FALSE to suppress vertical scrolling.

Returns

GetDropHighlight returns the current drop target or -1 if no drop target has been defined.

SetDropHighlight returns 0 if the function was successful, otherwise -1 is returned.

Comments

The GetDropHighlight and SetDropHighlight functions define the current drag & drop target location.

A tree control must be defined using the SFTTREESTYLE_DRAGDROP window style to support drag & drop.

SetDropHighlight is used to highlight the target of a drag & drop operation. There can be only one drop target at any one time. By calling SetDropHighlight with a new item index, the previous item is no longer a drop target and is no longer highlighted.

SetDropHighlightStyle can be used to control the appearance of the target item. Depending on the SetDropHighlightStyle settings, the index specified is the actual drop target or the insertion point. If used as an insertion point, the index value can be set to the number of items in the tree control, which moves the insertion point to the end of the list of items.

By setting SetDropHighlight to -1, the current drop target is cleared.

A drag & drop operation always starts at the current location (see GetCaretIndex). It is the application's responsibility to visually implement the drag & drop operation. When the operation involves the current tree control, this is accomplished by using CalcIndexFromPointEx and SetDropHighlight. If dragging to another tree control, CalcIndexFromPointEx and SetDropHighlight have to be used with the target tree control. If dragging to another control type (list box, edit control, etc.), other means may have to be used as implemented by the target control.

Once a drag & drop operation ends, SetDropHighlight should be called to clear the drop target by setting index to -1. This removes the highlight indicator from the target item.

If SetDropHighlight is set to the first (or last) item currently visible in the tree control's client area, the tree control automatically scrolls up (or down) by one item if fScroll is TRUE. This allows a user to drag items to a target item which has to be scrolled into view first. The contents of the tree control will scroll in the given direction until SetDropHighlight is called with index set to -1 or with index set to an item which is not the first (or last) item visible.

Examples

C

    /* Drag & drop in progress, which was started on the left side tree */
    LPSFTTREE_DRAGINFO lpInfo;
    lpInfo = SftTree_GetDragInfo(m_hwndLeftTree);

    if (lpInfo->hwnd != m_hwndLeftTree) { // The target is another window

        // clear old drop target
        if (m_hwndLastTarget) {
            SftTree_SetDropHighlight(m_hwndLastTarget, -1, FALSE);
            SftTree_StopAutoExpandTimer(m_hwndLastTarget);
        }
        m_hwndLastTarget = NULL;

        // the target is another control, we have to set the cursor and
        // also update the drop target
        // In this example the "other" control could be the right tree control

C++

    lpInfo = m_LeftTree.GetDragInfo();

    if (lpInfo->hwnd != m_LeftTree.m_hWnd) { // The target is another window

        // In this example the "other" control could be the right tree control

        if (lpInfo->hwnd == m_RightTree.m_hWnd) { // target is left tree
            index = m_RightTree.GetDropHighlight();
            text = _T("The drop target is item %d in the right tree control");
        } else {
            index = -1;
            text = _T("There is no valid drop target");
        }
    } else { // target is the right tree control
        index = m_LeftTree.GetDropHighlight();
        text = _T("The drop target is item %d in the left tree control");

See Also C/C++ API | Categories | Notifications