[ENHANCE] Drag and drop feature (in progress).
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@841 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
117136e341
commit
721d283366
@ -28,8 +28,8 @@ void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID)
|
|||||||
_hSelf = CreateWindowEx(0,
|
_hSelf = CreateWindowEx(0,
|
||||||
WC_TREEVIEW,
|
WC_TREEVIEW,
|
||||||
TEXT("Tree View"),
|
TEXT("Tree View"),
|
||||||
TVS_HASBUTTONS | WS_CHILD | WS_BORDER | WS_HSCROLL |
|
WS_CHILD | WS_BORDER | WS_HSCROLL | WS_TABSTOP | TVS_LINESATROOT | TVS_HASLINES |
|
||||||
TVS_HASLINES | TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_EDITLABELS | TVS_INFOTIP | WS_TABSTOP,
|
TVS_HASBUTTONS | TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_EDITLABELS | TVS_INFOTIP,
|
||||||
0, 0, 0, 0,
|
0, 0, 0, 0,
|
||||||
_hParent,
|
_hParent,
|
||||||
NULL,
|
NULL,
|
||||||
@ -188,29 +188,13 @@ void TreeView::dragItem(HWND parentHandle, int x, int y)
|
|||||||
HTREEITEM targetItem = (HTREEITEM)::SendMessage(_hSelf, TVM_HITTEST, (WPARAM)0, (LPARAM)&hitTestInfo);
|
HTREEITEM targetItem = (HTREEITEM)::SendMessage(_hSelf, TVM_HITTEST, (WPARAM)0, (LPARAM)&hitTestInfo);
|
||||||
if(targetItem)
|
if(targetItem)
|
||||||
{
|
{
|
||||||
|
if (canBeDropped(_draggedItem, targetItem))
|
||||||
// highlight the target of drag-and-drop operation
|
// highlight the target of drag-and-drop operation
|
||||||
::SendMessage(_hSelf, TVM_SELECTITEM, (WPARAM)(TVGN_DROPHILITE), (LPARAM)targetItem);
|
::SendMessage(_hSelf, TVM_SELECTITEM, (WPARAM)(TVGN_DROPHILITE), (LPARAM)targetItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the dragged image
|
// show the dragged image
|
||||||
::ImageList_DragShowNolock(true);
|
::ImageList_DragShowNolock(true);
|
||||||
|
|
||||||
/*
|
|
||||||
ImageList_DragMove(x-32, y-25); // where to draw the drag from
|
|
||||||
|
|
||||||
ImageList_DragShowNolock(FALSE);
|
|
||||||
// the highlight items should be as
|
|
||||||
|
|
||||||
// the same points as the drag
|
|
||||||
TVHITTESTINFO tvht;
|
|
||||||
tvht.pt.x = x-20;
|
|
||||||
tvht.pt.y = y-20; //
|
|
||||||
HTREEITEM hitTarget=(HTREEITEM)SendMessage(parentHandle,TVM_HITTEST,NULL,(LPARAM)&tvht);
|
|
||||||
if (hitTarget) // if there is a hit
|
|
||||||
SendMessage(parentHandle,TVM_SELECTITEM,TVGN_DROPHILITE,(LPARAM)hitTarget); // highlight it
|
|
||||||
|
|
||||||
ImageList_DragShowNolock(TRUE);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeView::dropItem()
|
void TreeView::dropItem()
|
||||||
@ -237,17 +221,29 @@ void TreeView::dropItem()
|
|||||||
_draggedItem = 0;
|
_draggedItem = 0;
|
||||||
_draggedImageList = 0;
|
_draggedImageList = 0;
|
||||||
_isItemDragged = false;
|
_isItemDragged = false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
bool TreeView::canBeDropped(HTREEITEM draggedItem, HTREEITEM targetItem)
|
||||||
ImageList_DragLeave(_hSelf);
|
{
|
||||||
ImageList_EndDrag();
|
if (draggedItem == targetItem)
|
||||||
HTREEITEM Selected=(HTREEITEM)SendMessage(_hSelf,TVM_GETNEXTITEM,TVGN_DROPHILITE,0);
|
return false;
|
||||||
SendMessage(_hSelf,TVM_SELECTITEM,TVGN_CARET,(LPARAM)Selected);
|
if (targetItem == TreeView_GetRoot(_hSelf))
|
||||||
SendMessage(_hSelf,TVM_SELECTITEM,TVGN_DROPHILITE,0);
|
return false;
|
||||||
ReleaseCapture();
|
if (isDescendant(targetItem, draggedItem))
|
||||||
ShowCursor(TRUE);
|
return false;
|
||||||
_isItemDragged = FALSE;
|
return true;
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
bool TreeView::isDescendant(HTREEITEM targetItem, HTREEITEM draggedItem)
|
||||||
|
{
|
||||||
|
if (TreeView_GetRoot(_hSelf) == targetItem)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
HTREEITEM parent = TreeView_GetParent(_hSelf, targetItem);
|
||||||
|
if (parent == draggedItem)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return isDescendant(parent, draggedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeView::moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem)
|
void TreeView::moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem)
|
||||||
|
@ -52,13 +52,13 @@ public:
|
|||||||
};
|
};
|
||||||
void setItemImage(HTREEITEM hTreeItem, int iImage, int iSelectedImage);
|
void setItemImage(HTREEITEM hTreeItem, int iImage, int iSelectedImage);
|
||||||
|
|
||||||
|
// Drag and Drop operations
|
||||||
void beginDrag(NMTREEVIEW* tv);
|
void beginDrag(NMTREEVIEW* tv);
|
||||||
void dragItem(HWND parentHandle, int x, int y);
|
void dragItem(HWND parentHandle, int x, int y);
|
||||||
void dropItem();
|
|
||||||
bool isDragging() const {
|
bool isDragging() const {
|
||||||
return _isItemDragged;
|
return _isItemDragged;
|
||||||
};
|
};
|
||||||
void moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem);
|
void dropItem();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
WNDPROC _defaultProc;
|
WNDPROC _defaultProc;
|
||||||
@ -68,6 +68,11 @@ protected:
|
|||||||
return (((TreeView *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(hwnd, Message, wParam, lParam));
|
return (((TreeView *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(hwnd, Message, wParam, lParam));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Drag and Drop operations
|
||||||
|
bool canBeDropped(HTREEITEM draggedItem, HTREEITEM targetItem);
|
||||||
|
void moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem);
|
||||||
|
bool isDescendant(HTREEITEM targetItem, HTREEITEM draggedItem);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Drag and drop
|
// Drag and drop
|
||||||
HTREEITEM _draggedItem;
|
HTREEITEM _draggedItem;
|
||||||
|
Loading…
Reference in New Issue
Block a user