예제 #1
0
파일: KGTreeCtrl.cpp 프로젝트: viticm/pap2
LRESULT KGTreeCtrl::OnStick(WPARAM wParam, LPARAM lParam)
{
	int nResult  = false;
	int nRetCode = false;

	HTREEITEM  hParentItem = NULL;
	HTREEITEM  hTempItem   = NULL;
	HTREEITEM  hNewItem    = NULL;

	m_hItemDragD = (HTREEITEM)wParam;

	KG_PROCESS_ERROR(m_hItemDragS);
	KG_PROCESS_ERROR(m_hItemDragD);

	nRetCode = BeginStick(m_hItemDragS, m_hItemDragD, m_eMoveType);
	KG_PROCESS_ERROR(nRetCode);

    hParentItem = GetParentItem(m_hItemDragD);
	hTempItem   = m_hItemDragD;

	while ((hTempItem = GetParentItem(hTempItem)) != NULL)
	{
		if( hTempItem == m_hItemDragS )
		{
			HTREEITEM  hNewItemTemp = CopyBranch(m_hItemDragS, NULL, TVI_LAST);
			HTREEITEM  hNewItem     = CopyBranch(
				hNewItemTemp, hParentItem, m_hItemDragD
			);
			DeleteItem(hNewItemTemp);
			SelectItem(hNewItem);
			KG_PROCESS_SUCCESS(true);
		}
	}

	hNewItem = CopyBranch(m_hItemDragS, hParentItem, m_hItemDragD);
	KG_PROCESS_ERROR(hNewItem);

	if (m_eMoveType == MOVE_TYPE_CUT)
	{
		OnDel((WPARAM)m_hItemDragS, 0);
		m_hItemDragS = NULL;
	}

	nRetCode = AfterStick(hNewItem, m_eMoveType);
	KG_PROCESS_ERROR(nRetCode);

	//ExpandItem(hNewItem);
	SelectItem(hNewItem);

Exit1:
	nResult = true;
Exit0:
	Invalidate();
	return nResult;
}
void EXTreeCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
    EXWaitingTreeCtrl::OnLButtonUp(nFlags, point);
    if (m_bLDragging)
    {
        m_bLDragging = FALSE;
        CImageList::DragLeave(this);
        CImageList::EndDrag();
        ReleaseCapture();

        delete m_pDragImage;

        // Remove drop target highlighting
        SelectDropTarget(NULL);

        if( m_hitemDrag == m_hitemDrop )
            return;

        // If Drag item is an ancestor of Drop item then return
        HTREEITEM htiParent = m_hitemDrop;
        while( (htiParent = GetParentItem( htiParent )) != NULL )
        {
            if( htiParent == m_hitemDrag ) return;
        }

        // Move in data...
        bool bRes = false;
        HTREEITEM htiPrevParent	= GetParentItem( m_hitemDrag );
        /*		EBaseItem * pFromParentItem = (EBaseItem *)GetItemData(htiPrevParent);
        		EBaseItem * pToParentItem = (EBaseItem *)GetItemData(m_hitemDrop);
        		EBaseItem * pDraggedItem = (EBaseItem *)GetItemData(m_hitemDrag);

        		if(pFromParentItem && pFromParentItem->m_pITreeMember &&
        		   pToParentItem && pToParentItem->m_pITreeMember &&
        		   pDraggedItem && pDraggedItem->m_pITreeMember)
        		{
        			bRes = pDraggedItem->m_pITreeMember->MoveItem(pFromParentItem->m_pITreeMember,pToParentItem->m_pITreeMember);
        		}*/
        IXTreeItem * pFromParentItem = (IXTreeItem *)GetItemData(htiPrevParent);
        IXTreeItem * pToParentItem = (IXTreeItem *)GetItemData(m_hitemDrop);
        IXTreeItem * pDraggedItem = (IXTreeItem *)GetItemData(m_hitemDrag);

        if(pFromParentItem && pToParentItem && pDraggedItem)
        {
            bRes = pDraggedItem->MoveItem(pFromParentItem,pToParentItem);
        }
        if(!bRes)
            return;

        // Move in tree
        Expand( m_hitemDrop, TVE_EXPAND ) ;
        HTREEITEM htiNew = CopyBranch( m_hitemDrag, m_hitemDrop, TVI_LAST );
        SelectItem( htiNew );

        if(m_hitemDrop)
            RefreshSubItems(m_hitemDrop);
    }
}
예제 #3
0
HTREEITEM CTreeFileCtrl::CopyBranch(HTREEITEM htiBranch, HTREEITEM htiNewParent, HTREEITEM htiAfter)
{
  HTREEITEM hNewItem = CopyItem(htiBranch, htiNewParent, htiAfter);
  HTREEITEM hChild = GetChildItem(htiBranch);
  while (hChild != NULL)
  {
    //recursively transfer all the items
    CopyBranch(hChild, hNewItem);
    hChild = GetNextSiblingItem(hChild);
  }
  return hNewItem;
}
예제 #4
0
HTREEITEM CTreeCtrlEx::CopyBranch(HTREEITEM htiBranch, HTREEITEM htiNewParent, HTREEITEM htiAfter)
{
	HTREEITEM hChild;
	HTREEITEM hNewItem = CopyItem( htiBranch,htiNewParent,htiAfter );
	hChild = GetChildItem( htiBranch );

	while( hChild != NULL )
	{
		CopyBranch( hChild,hNewItem,htiAfter );
		hChild = GetNextSiblingItem( hChild );
	}

	return hNewItem;
}
예제 #5
0
void CTreeCtrlEx::OnLButtonUp(UINT nFlags, CPoint point)
{
	CTreeCtrl::OnLButtonUp(nFlags, point);

	if(m_bLDragging)
	{
		m_bLDragging=FALSE;
		CImageList::DragLeave(this);
		CImageList::EndDrag();
		ReleaseCapture();
		delete m_pDragImage;
		SelectDropTarget(NULL);

		if(m_hitemDrop!=NULL && m_hitemDrag!=NULL)
		{
			if(GetItemData(m_hitemDrop)!=0)
			{
				if(m_pIdentify->GetGestureById((int)GetItemData(m_hitemDrop))->m_GroupStatus!=1)
				{
					m_hitemDrop=GetParentItem(m_hitemDrop);
				}
				if( (m_hitemDrag==m_hitemDrop) || (m_hitemDrop==NULL) || (GetParentItem(m_hitemDrag)==m_hitemDrop) )
				{
					SelectItem(m_hitemDrag);
					return;
				}
			}

			HTREEITEM htiParent = m_hitemDrop;
			while( (htiParent = GetParentItem( htiParent )) != NULL )
			{
				if( htiParent == m_hitemDrag ) return;
			}
			
			Expand(m_hitemDrop, TVE_EXPAND);
			
			int dataDrag=(int)GetItemData(m_hitemDrag);
			int dataDrop=(int)GetItemData(m_hitemDrop);
			// перемещаем жесты в основном массиве, там внутри модифицируется тунель
			m_pIdentify->Move(
				m_pIdentify->m_Tunnel.GetNumberById(dataDrag),
				m_pIdentify->m_Tunnel.GetNumberById(dataDrop)
				);

			HTREEITEM htiNew=CopyBranch(m_hitemDrag,m_hitemDrop,TVI_SORT);
			DeleteItem(m_hitemDrag);
			SelectItem(htiNew);
		}
	}
}
// CopyBranch           - Copies all items in a branch to a new location
// Returns              - The new branch node
// htiBranch            - The node that starts the branch
// htiNewParent - Handle of the parent for new branch
// htiAfter             - Item after which the new branch should be created
HTREEITEM EXTreeCtrl::CopyBranch( HTREEITEM htiBranch, HTREEITEM htiNewParent, HTREEITEM htiAfter /*= TVI_LAST*/ )
{
    HTREEITEM hChild;

    HTREEITEM hNewItem = CopyItem( htiBranch, htiNewParent, htiAfter );
    hChild = GetChildItem(htiBranch);
    while( hChild != NULL)
    {
        // recursively transfer all the items
        CopyBranch(hChild, hNewItem,TVI_FIRST);
        hChild = GetNextSiblingItem( hChild );
    }

    // Don't delete item data only treeitem..
    SetItemData(htiBranch, NULL);
    DeleteItem(htiBranch);

    return hNewItem;
}
예제 #7
0
void CTreeFileCtrl::EndDragging(BOOL bCancel)
{
  if (IsDragging())
  {
    KillTimer(m_nTimerID);

    CImageList::DragLeave(this);
    CImageList::EndDrag();
    ReleaseCapture();

    delete m_pilDrag;
    m_pilDrag = NULL;

    //Remove drop target highlighting
    SelectDropTarget(NULL);

    m_hItemDrop = GetDropTarget(m_hItemDrop);
    if (m_hItemDrop == NULL)
      return;

    if (!bCancel)
    {
      //Also need to make the change on disk
      CString sFromPath = ItemToPath(m_hItemDrag);
      CString sToPath = ItemToPath(m_hItemDrop);

      int nFromLength = sFromPath.GetLength();
      int nToLength = sToPath.GetLength();
      SHFILEOPSTRUCT shfo;
      ZeroMemory(&shfo, sizeof(SHFILEOPSTRUCT));
      shfo.hwnd = GetSafeHwnd();

      if ((GetKeyState(VK_CONTROL) & 0x8000))
        shfo.wFunc = FO_COPY;
      else
        shfo.wFunc = FO_MOVE;

      shfo.fFlags = FOF_SILENT | FOF_NOCONFIRMMKDIR;
      //Undo is not allowed if the SHIFT key is held down
      if (!(GetKeyState(VK_SHIFT) & 0x8000))
        shfo.fFlags |= FOF_ALLOWUNDO;

      TCHAR* pszFrom = new TCHAR[nFromLength + 2];
      _tcscpy(pszFrom, sFromPath);
      pszFrom[nFromLength+1] = _T('\0');
      shfo.pFrom = pszFrom;

      TCHAR* pszTo = new TCHAR[nToLength + 2];
      _tcscpy(pszTo, sToPath);
      pszTo[nToLength+1] = _T('\0');
      shfo.pTo = pszTo;

      //Let the shell perform the actual deletion
      BOOL bSuccess = ((SHFileOperation(&shfo) == 0) && (shfo.fAnyOperationsAborted == FALSE));

      //Free up the memory we had allocated
      delete [] pszFrom;
      delete [] pszTo;

      if (bSuccess)
      {
        //Only copy the item in the tree if there is not an item with the same
        //text under m_hItemDrop
        CString sText = GetItemText(m_hItemDrag);
        if (!HasChildWithText(m_hItemDrop, sText))
        {
          //Do the actual copy
          BOOL bHadChildren = (GetChildItem(m_hItemDrop) != NULL);
          CopyBranch(m_hItemDrag, m_hItemDrop);

          //Update the children indicator for the folder we just dropped into
          if (!bHadChildren)
          {
            TV_ITEM tvItem;
            tvItem.hItem = m_hItemDrop;
            tvItem.mask = TVIF_CHILDREN;  
            tvItem.cChildren = 1;
            SetItem(&tvItem);
          }
        }

        BOOL bExpanded = (GetChildItem(m_hItemDrop) != NULL); 
        if (shfo.wFunc == FO_MOVE)
        {
          //Get the parent of the item we moved prior to deleting it
          HTREEITEM hParent = GetParentItem(m_hItemDrag);

          //Delete the item we just moved
          DeleteItem(m_hItemDrag);

          //Update the children indicator for the item we just dragged from
          BOOL bHasChildren = (GetChildItem(hParent) != NULL);
          if (hParent && !bHasChildren)
          {
            TV_ITEM tvItem;
            tvItem.hItem = hParent;
            tvItem.mask = TVIF_CHILDREN;  
            tvItem.cChildren = 0;
            SetItem(&tvItem);
          }
        }
        SetSelectedPath(sToPath, bExpanded);
      }
    }
  }
}