📄 oledragdropexptreeviewctrl.h
字号:
#pragma once
#include "ExplorerTreeViewCtrl.h"
template <class T>
class COleDragDrogExplorerTreeViewCtrlImpl :
public CExplorerTreeViewCtrlImpl<T>,
public IDropTargetImpl<T>,
public IDropSourceImpl<T>
{
public:
DECLARE_WND_SUPERCLASS(NULL, CTreeViewCtrl::GetWndClassName())
typedef CExplorerTreeViewCtrlImpl<T> baseClass;
// Data members
bool m_bDragAccept;
bool m_bRButtonDown;
HTREEITEM m_hItemDragging;
UINT m_nIDTimer;
CPoint m_ptMouse;
COleDragDrogExplorerTreeViewCtrlImpl() : m_bDragAccept(false),
m_hItemDragging(NULL), m_nIDTimer(0), m_ptMouse(-1, -1), m_bRButtonDown(false)
{
}
// Overridables
HRESULT OnGetExplorerTreeViewDataObject(HTREEITEM hItem, IDataObject** ppDataObject)
{
ATLASSERT(ppDataObject != NULL);
CItemIDList idl = _GetItemIDList(hItem);
ATLASSERT(!idl.IsNull());
HRESULT hr = CHlinkDataObject::_CreatorClass::CreateInstance(NULL, IID_IDataObject, (void**)ppDataObject);
if (FAILED(hr)) {
*ppDataObject = NULL;
return E_NOTIMPL;
}
#ifdef _ATL_DEBUG_INTERFACES
ATLASSERT(FALSE && _T("_ATL_DEBUG_INTERFACES crashes the following\n"));
#endif
CHlinkDataObject* pHlinkDataObject = NULL;// this is hack, no need to release
hr = (*ppDataObject)->QueryInterface(IID_NULL, (void**)&pHlinkDataObject);
if (SUCCEEDED(hr)) {
CString strUrl = idl.GetPath();
strUrl.Replace(_T('/'), _T('\\'));
pHlinkDataObject->m_arrNameAndUrl.Add(std::make_pair(CString(),strUrl));
return S_OK;
}
return E_NOTIMPL;
}
// Overrides
void OnExplorerTreeViewInit()
{
RegisterDragDrop();
}
void OnExplorerTreeViewTerm()
{
RevokeDragDrop();
_CleanUpStayTimer();
}
// Message map and handlers
BEGIN_MSG_MAP(COleDragDrogExplorerTreeViewCtrlImpl)
MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
MESSAGE_HANDLER(WM_TIMER, OnTimer)
CHAIN_MSG_MAP(baseClass)
END_MSG_MAP()
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
HTREEITEM hItem = _HitTestForFullLow(pt);
if (hItem == NULL) {
bHandled = FALSE;
return 0;
}
EndEditLabelNow(TRUE);// cancel
// HTREEITEM hItemSelected = GetSelectedItem();
// bool bHilight = (hItem != hItemSelected);
_DoDragDrop(hItem, pt, (UINT)wParam, true);
// if (hItemExpanded == NULL && bHilight) // reset hilight
// SetItem(hItem, TVIF_STATE, NULL, 0, 0, 0, TVIS_SELECTED/*TVIS_SELECTED*/, NULL);
return 0;
}
LRESULT OnRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
HTREEITEM hItem = _HitTestForFullLow(pt);
if (hItem == NULL) {
bHandled = FALSE;
return 0;
}
EndEditLabelNow(TRUE);// cancel
// HTREEITEM hItemSelected = GetSelectedItem();
// bool bHilight = (hItem != hItemSelected);
_DoDragDrop(hItem, pt, (UINT)wParam, false);
// if (hItemExpanded == NULL && bHilight) // reset hilight
// SetItem(hItem, TVIF_STATE, NULL, 0, 0, 0, TVIS_SELECTED/*TVIS_SELECTED*/, NULL);
return 0;
}
// IDropTargetImpl
// Overrides
bool OnScroll(UINT nScrollCode, UINT nPos, bool bDoScroll = true)
{
bool bResult = false;
if (HIBYTE(nScrollCode) == SB_LINEUP) {
if (bDoScroll)
bResult = _ScrollItem(false);
else
bResult = _CanScrollItem(false);
}
else if (HIBYTE(nScrollCode) == SB_LINEDOWN) {
if (bDoScroll)
bResult = _ScrollItem(true);
else
bResult = _CanScrollItem(true);
}
return bResult;
}
DROPEFFECT OnDragEnter(IDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
m_bDragAccept = _MtlIsHlinkDataObject(pDataObject);
if (!m_bDragAccept)
return DROPEFFECT_NONE;
m_bRButtonDown = ::GetAsyncKeyState(VK_RBUTTON) < 0;
_SetUpStayTimer(point);
return _MtlStandardDropEffect(dwKeyState);
}
DROPEFFECT OnDragOver(IDataObject* pDataObject, DWORD dwKeyState, CPoint point, DROPEFFECT dropOkEffect)
{
if (!m_bDragAccept)
return DROPEFFECT_NONE;
CString strPath;
HTREEITEM hItem = _HitTest(point, strPath);
// if (hItem == NULL) {
// SelectDropTarget(NULL);
// return DROPEFFECT_NONE;
// }
SelectDropTarget(hItem);
if (hItem != NULL && hItem == m_hItemDragging) {
return DROPEFFECT_NONE;
}
if (m_hItemDragging)
return _MtlStandardDropEffect(dwKeyState);
else
return _MtlStandardDropEffect(dwKeyState) | _MtlFollowDropEffect(dropOkEffect);
}
DROPEFFECT OnDrop(IDataObject* pDataObject, DROPEFFECT dropEffect,
DROPEFFECT dropEffectList, CPoint point)
{
DROPEFFECT dropResult = DROPEFFECT_NONE;
SelectDropTarget(NULL);
_CleanUpStayTimer();
CString strPath;
HTREEITEM hItem = _HitTest(point, strPath);
// first, file dropped or not
CSimpleArray<CString> arrFiles;
if (MtlGetDropFileName(pDataObject, arrFiles)) {
if (_PreDropFile(hItem, arrFiles))
return dropResult;
if (m_bRButtonDown && MtlOnRButtonDrop(m_hWnd, dropEffect, point))
return dropResult;
if (dropEffect & DROPEFFECT_COPY) {
if (MtlCopyFile(strPath, arrFiles)) {
dropResult = DROPEFFECT_COPY;
_RefreshChildren(hItem);
}
}
else if (dropEffect & DROPEFFECT_MOVE) {
if (MtlMoveFile(strPath, arrFiles)) {
dropResult = DROPEFFECT_MOVE;
if (m_hItemDragging) {
_CLockRedrawTreeView lock(m_hItemDragging, m_hWnd);
_CleanUpChildren(m_hItemDragging);
DeleteItem(m_hItemDragging);
}
_RefreshChildren(hItem);
}
}
else if (dropEffect & DROPEFFECT_LINK) {
dropResult = DROPEFFECT_LINK;
MtlMakeSureTrailingBackSlash(strPath);
for (int i = 0; i < arrFiles.GetSize(); ++i) {
MtlCreateShortCutFile(strPath + MtlGetDisplayTextFromPath(arrFiles[i]) + _T("傊偺籍澳动
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -