Beispiel #1
0
void CSharedDirsTreeCtrl::OnLvnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LPNMTREEVIEW lpnmtv = (LPNMTREEVIEW)pNMHDR;
	*pResult = 0;

	CDirectoryItem* pToDrag = (CDirectoryItem*)lpnmtv->itemNew.lParam;
	if (pToDrag == NULL || pToDrag->m_eItemType != SDI_UNSHAREDDIRECTORY || FileSystemTreeIsShared(pToDrag->m_strFullPath))
		return;

	ASSERT( m_pDraggingItem == NULL );
	delete m_pDraggingItem;
	m_pDraggingItem = pToDrag->CloneContent(); // to be safe we store a copy, as items can be deleted when collapsing the tree etc

	CImageList* piml = NULL;
	POINT ptOffset;
	RECT rcItem;
	if ((piml = CreateDragImage(lpnmtv->itemNew.hItem)) == NULL)
		return;

	/* get the bounding rectangle of the item being dragged (rel to top-left of control) */
	if (GetItemRect(lpnmtv->itemNew.hItem, &rcItem, TRUE))
	{
		CPoint ptDragBegin;
		int nX, nY;
		/* get offset into image that the mouse is at */
		/* item rect doesn't include the image */
		ptDragBegin = lpnmtv->ptDrag;
		ImageList_GetIconSize(piml->GetSafeHandle(), &nX, &nY);
		ptOffset.x = (ptDragBegin.x - rcItem.left) + (nX - (rcItem.right - rcItem.left));
		ptOffset.y = (ptDragBegin.y - rcItem.top) + (nY - (rcItem.bottom - rcItem.top));
		/* convert the item rect to screen co-ords, for use later */
		MapWindowPoints(NULL, &rcItem);
	}
	else
	{
		GetWindowRect(&rcItem);
		ptOffset.x = ptOffset.y = 8;
	}

	if (piml->BeginDrag(0, ptOffset))
	{
		CPoint ptDragEnter = lpnmtv->ptDrag;
		ClientToScreen(&ptDragEnter);
		piml->DragEnter(NULL, ptDragEnter);
	}
	delete piml;

	/* set the focus here, so we get a WM_CANCELMODE if needed */
	SetFocus();

	/* redraw item being dragged, otherwise it remains (looking) selected */
	InvalidateRect(&rcItem, TRUE);
	UpdateWindow();

	/* Hide the mouse cursor, and direct mouse input to this window */
	SetCapture(); 
}
Beispiel #2
0
void CTreeFileCtrl::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	*pResult = 0;

  SelectItem(pNMTreeView->itemNew.hItem);
  if (!IsDropSource(pNMTreeView->itemNew.hItem) || !m_bAllowDragDrop)
    return;

  m_pilDrag = CreateDragImage(pNMTreeView->itemNew.hItem);
  if (!m_pilDrag)
    return;

  m_hItemDrag = pNMTreeView->itemNew.hItem;
  m_hItemDrop = NULL;

  // Calculate the offset to the hotspot
  CPoint offsetPt(8,8);   // Initialize a default offset

  CPoint dragPt = pNMTreeView->ptDrag;    // Get the Drag point
  UINT nHitFlags = 0;
  HTREEITEM htiHit = HitTest(dragPt, &nHitFlags);
  if (htiHit != NULL)
  {
    // The drag point has Hit an item in the tree
    CRect itemRect;
    if (GetItemRect(htiHit, &itemRect, FALSE))
    {
      // Count indent levels
      HTREEITEM htiParent = htiHit;
      int nIndentCnt = 0;
      while (htiParent != NULL)
      {
        htiParent = GetParentItem(htiParent);
        nIndentCnt++;
      }

      if (!(GetStyle() & TVS_LINESATROOT)) 
        nIndentCnt--;

      // Calculate the new offset
      offsetPt.y = dragPt.y - itemRect.top;
      offsetPt.x = dragPt.x - (nIndentCnt * GetIndent()) + GetScrollPos(SB_HORZ);
    }
  }

  //Begin the dragging  
  m_pilDrag->BeginDrag(0, offsetPt);
  POINT pt = pNMTreeView->ptDrag;
  ClientToScreen(&pt);
  m_pilDrag->DragEnter(NULL, pt);
  SetCapture();

  m_nTimerID = SetTimer(1, 300, NULL);
}
Beispiel #3
0
CImageList *CSiteGroupsTree::CreateDragImageEx(HTREEITEM item, COLORREF color)
{
    if (GetImageList(TVSIL_NORMAL))
        return CreateDragImage(item);

    // Create bitmap
    
    std::auto_ptr<CClientDC> dc;
    try {
        dc.reset(new CClientDC(this));
    }
    catch (CResourceException *ex) {
        ex->Delete();
        return 0;
    }

    CDC memdc;
    if (memdc.CreateCompatibleDC(dc.get()) == FALSE)
        return 0;

    CRect rect;
    GetItemRect(item, rect, TRUE);
    rect.top = rect.left = 0;

    CBitmap bitmap;
    if (bitmap.CreateCompatibleBitmap(dc.get(), rect.Width(), rect.Height()) == FALSE)
        return 0;

    CBitmap *oldBitmap = memdc.SelectObject(&bitmap);
    CFont *oldFont = memdc.SelectObject(GetFont());

    COLORREF dragMask = m_colors->dragMask.color;

    memdc.FillSolidRect(&rect, dragMask);
    memdc.SetTextColor(color);
    memdc.TextOut(rect.left, rect.top, GetItemText(item));

    memdc.SelectObject(oldFont);
    memdc.SelectObject(oldBitmap);

    // Create image list

    std::auto_ptr<CImageList> imageList(new CImageList);
    if (imageList->Create(rect.Width(), rect.Height(), ILC_COLOR24 | ILC_MASK, 0, 1) == FALSE)
        return 0;

    if (imageList->Add(&bitmap, dragMask) == -1)
        return 0;

    return imageList.release();
}
Beispiel #4
0
void CLibraryView::StartDragging(const CPoint& ptMouse)
{
	CQuickLock oLock( Library.m_pSection );

	CPoint ptMiddle( 0, 0 );
	HBITMAP pImage = CreateDragImage( ptMouse, ptMiddle );
	if ( ! pImage )
		return;

	// Get GUID of parent folder
	Hashes::Guid oGUID;
	CLibraryListItem oHit = GetFolder();
	if ( oHit.Type == CLibraryListItem::AlbumFolder )
		oGUID = ((CAlbumFolder*)oHit)->m_oGUID;

	CEnvyDataSource::DoDragDrop( m_pSelection, pImage, oGUID, ptMiddle );
}
Beispiel #5
0
void CuListCtrlLoggedEvent::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	CPoint p, ptItem, ptAction, ptImage;

	UINT nFlags;

	GetCursorPos(&ptAction);
	p = ptAction;
	ScreenToClient(&p);
	m_iItemDrag = HitTest(p, &nFlags);
	if (!(m_iItemDrag != -1 || (nFlags&TVHT_ONITEM)))
	{
		m_iItemDrag = -1;
		m_bDragging = FALSE;
		return;
	}
	if (!m_pEventSettingFrame)
		m_pEventSettingFrame = (CfEventSetting*)GetParentFrame();
	CvEventSettingBottom* pBottomView= m_pEventSettingFrame->GetBottomView();
	CListCtrl* pListCtrl = pBottomView->GetListCtrl();; 
	CaLoggedEvent* pMsg = (CaLoggedEvent*)pListCtrl->GetItemData (m_iItemDrag);
	if (pMsg->IsNotFirstLine()) {
		m_iItemDrag = -1;
		m_bDragging = FALSE;
		return;
	}



	ASSERT(!m_bDragging);
	m_bDragging = TRUE;

	ASSERT(m_pImageListDrag == NULL);
	m_pImageListDrag = CreateDragImage(m_iItemDrag, &ptImage);
	GetItemPosition(m_iItemDrag, &ptItem);         // ptItem is relative to (0,0) and not the view origin
	m_sizeDelta = ptAction - ptImage;              // difference between cursor pos and image pos
	m_ptHotSpot = ptAction - ptItem + m_ptOrigin;  // calculate hotspot for the cursor
	m_pImageListDrag->DragShowNolock(TRUE);        // lock updates and show drag image
	m_pImageListDrag->SetDragCursorImage(0, CPoint(0, 0) /*m_ptHotSpot*/);  // define the hot spot for the new cursor image
	m_pImageListDrag->BeginDrag(0, CPoint(0, 0));

	m_pImageListDrag->DragEnter(/*this*/GetParentFrame(), ptAction);
	m_pImageListDrag->DragMove(ptAction);  // move image to overlap original icon
	SetCapture();
}
void CGameListCtrl::OnLvnBegindragList(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;
//*
    POINT pt;   
	int nOffset = 5; //offset in pixels for drag image (up and    
                         //to the left)   
    pt.x = nOffset;   
    pt.y = nOffset;   

	m_pDragImage = CreateDragImage(pNMLV->iItem, &pt);
    m_pDragImage->BeginDrag(0, CPoint(nOffset, nOffset));   
    m_pDragImage->DragEnter(GetDesktopWindow(), pNMLV->ptAction);

	this->SetCapture();
}
Beispiel #7
0
void CColumnChooserLC::OnLButtonDown(UINT nFlags, CPoint point)
{
  CListCtrl::OnLButtonDown(nFlags, point);

  // Move our text
  m_iItem = HitTest(point);
  if (m_iItem == -1)
    return;

  // Start of Drag of column (m_iItem) from Column Chooser dialog to.....
  CString cs_text;
  DWORD_PTR dw_type;

  dw_type = GetItemData(m_iItem);

  // ListView HeaderCtrl only needs the type as it uses main routine
  // to add/delete columns via SendMessage
  cs_text.Format(L"%08x%02x%02x", GetCurrentProcessId(), FROMCC, dw_type);

  // Get client window position
  CPoint currentClientPosition;
  currentClientPosition = ::GetMessagePos();
  ScreenToClient(&currentClientPosition);

  // Set drag image
  m_pDragImage = CreateDragImage(m_iItem, &currentClientPosition);
  m_pDragImage->BeginDrag(0, CPoint(8, 8));
  m_pDragImage->DragEnter(GetDesktopWindow(), point);

  // Get client rectangle
  RECT rClient;
  GetClientRect(&rClient);

  // Start dragging
  StartDragging((BYTE *)LPCWSTR(cs_text),
        cs_text.GetLength() * sizeof(wchar_t),
        m_ccddCPFID, &rClient, &point);

  // End dragging image
  m_pDragImage->DragLeave(GetDesktopWindow());
  m_pDragImage->EndDrag();
  delete m_pDragImage;
}
Beispiel #8
0
void CZoneTree::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	int i;
	*pResult = 0;
	
	// So user cant drag root node
	if (GetParentItem(pNMTreeView->itemNew.hItem) == NULL) return; 

	// Item user started dragging ...
	m_hitemDrag = pNMTreeView->itemNew.hItem;
	m_hitemDrop = NULL;
	
	GetItemImage(m_hitemDrag, i, i);
	//don't drag root items!
	switch(i){
		case CONTENTS: 
		case PEOPLE: 
		case OBJ_PARENT:
		case MOB_PARENT: 
		case ROOM_PARENT: 
		case AREA_DATA: 
		case ROOM_DATA:
			return;
	}
    
	m_pDragImage = CreateDragImage(m_hitemDrag);  // get the image list for dragging
	// CreateDragImage() returns NULL if no image list
	// associated with the tree view control
	if( !m_pDragImage )
		return;

	m_bLDragging = TRUE;
	m_pDragImage->BeginDrag(0, CPoint(-15,-15));
	
	POINT pt = pNMTreeView->ptDrag;
	
	ClientToScreen( &pt );
	
	m_pDragImage->DragEnter(NULL, pt);
	
	SetCapture();
}
Beispiel #9
0
CImageList* CLiveList::CreateDragImage(CListCtrl* pList, const CPoint& ptMouse)
{
	ASSERT_VALID( pList );

	CPoint ptOffset( 0, 0 );
	CBitmap bmDrag;
	bmDrag.Attach( CreateDragImage( pList, ptMouse, ptOffset) );
	BITMAP bmpInfo;
	bmDrag.GetBitmap( &bmpInfo );
	CImageList* pAll = new CImageList();
	pAll->Create( bmpInfo.bmWidth, bmpInfo.bmHeight, ILC_COLOR32|ILC_MASK, 1, 1 ) ||
	pAll->Create( bmpInfo.bmWidth, bmpInfo.bmHeight, ILC_COLOR24|ILC_MASK, 1, 1 ) ||
	pAll->Create( bmpInfo.bmWidth, bmpInfo.bmHeight, ILC_COLOR16|ILC_MASK, 1, 1 );
	pAll->Add( &bmDrag, DRAG_COLOR_KEY );
	bmDrag.DeleteObject();
	pAll->BeginDrag( 0, ptOffset );

	return pAll;
}
/**
 *
 * \param *pNMHDR 
 * \param *pResult 
 */
void	CUnitListBox::OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV	= reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
	if (pNMLV->iItem >= 0)
	{
		// 获取文件名
		m_szFileName		= GetItemText(pNMLV->iItem, pNMLV->iSubItem);

		POINT pt ={
			0, 0
		};

		int nOffset = 0;
		int nCount	= GetSelectedCount();
		if (nCount >= 1)
		{
			pt.x = nOffset;
			pt.y = nOffset;
		}

		m_pDragImage = CreateDragImage(pNMLV->iItem, &pt);
		if (m_pDragImage)
		{
			IMAGEINFO img;
			m_ImageList.GetImageInfo(pNMLV->iItem, &img);

			CBitmap* pBitmap = CBitmap::FromHandle(img.hbmImage);
			if (pBitmap)
			{
				m_pDragImage->Replace(0, pBitmap, NULL);
				m_pDragImage->BeginDrag(0, 
					CPoint(nOffset, nOffset));
				m_pDragImage->DragEnter(GetDesktopWindow(), pNMLV->ptAction);

				m_bDragging = TRUE;

				SetCapture ();
			}
		}
	}

	*pResult = 0;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input  : pt -
//			hItem -
//-----------------------------------------------------------------------------
void CGroupList::BeginDrag(CPoint point, HTREEITEM hItem)
{
    m_hDragItem = hItem;
    if (m_hDragItem)
    {
        m_pDragImageList = CreateDragImage(m_hDragItem);
        if (m_pDragImageList)
        {
            CPoint ptHotSpot(0, 0);
            m_pDragImageList->BeginDrag(0, ptHotSpot);
            m_pDragImageList->DragEnter(this, point);
            SelectDropTarget(NULL);
        }

        // Timer handles scrolling the list control when dragging outside the window bounds.
        SetTimer(TIMER_GROUP_DRAG_SCROLL, 300, NULL);

        SetCapture();
    }
}
void CDragDropTreeCtrl::OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult)
{
    *pResult = 0;
    NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

    HTREEITEM hItem = pNMTreeView->itemNew.hItem;

    // Create a drag image. If the assertion fails, you probably forgot
    // to assign an image list to the control with SetImageList. Create-
    // DragImage will not work if the control hasn't been assigned an
    // image list!
    m_pImageList = CreateDragImage(hItem);
    ASSERT(m_pImageList != NULL);

    if (m_pImageList != NULL)
    {
        // Compute the coordinates of the "hot spot"--the location of the
        // cursor relative to the upper left corner of the item rectangle.
        CRect rect;
        GetItemRect(hItem, rect, TRUE);
        CPoint point(pNMTreeView->ptDrag.x, pNMTreeView->ptDrag.y);
        CPoint hotSpot = point;
        hotSpot.x -= rect.left;
        hotSpot.y -= rect.top;

        // Convert the client coordinates in "point" to coordinates relative
        // to the upper left corner of the control window.
        CPoint client(0, 0);
        ClientToScreen(&client);
        GetWindowRect(rect);
        point.x += client.x - rect.left;
        point.y += client.y - rect.top;

        // Capture the mouse and begin dragging.
        SetCapture();
        m_pImageList->BeginDrag(0, hotSpot);
        m_pImageList->DragEnter(this, point);
        m_hDragItem = hItem;
        m_bDragging = TRUE;
    }
}
void EXTreeCtrl::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
    NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
    *pResult = 0;

    m_hitemDrag = pNMTreeView->itemNew.hItem;
    m_hitemDrop = NULL;

    m_pDragImage = CreateDragImage(m_hitemDrag);  // get the image list for dragging
    // CreateDragImage() returns NULL if no image list
    // associated with the tree view control
    if( !m_pDragImage )
        return;

    m_bLDragging = TRUE;
    m_pDragImage->BeginDrag(0, CPoint(-15,-15));
    POINT pt = pNMTreeView->ptDrag;
    ClientToScreen( &pt );
    m_pDragImage->DragEnter(NULL, pt);
    SetCapture();
}
Beispiel #14
0
void CNZProjectTreeCtrl::OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here

	m_htiDrag = pNMTreeView->itemNew.hItem;
	m_htiDrop = NULL;

	CXNode* pNode = (CXNode*)GetItemData(m_htiDrag);
	// disallow dragging of projects
	if (!pNode || pNode->m_enNodeType == XNODE_PROJECT)
		return;

	m_pDragImage = CreateDragImage( m_htiDrag );
	if( !m_pDragImage )
		return;

	m_bDragging = true;

	CPoint pt(0,0);
	
	IMAGEINFO ii;
	m_pDragImage->GetImageInfo( 0, &ii );
	pt.x = (ii.rcImage.right - ii.rcImage.left) / 2;
	pt.y = (ii.rcImage.bottom - ii.rcImage.top) / 2;

	m_pDragImage->BeginDrag( 0, pt );
	pt = pNMTreeView->ptDrag;
	ClientToScreen( &pt );
	m_pDragImage->DragEnter(NULL,pt);
	
	SetCapture();

	*pResult = 0;

	// Set up the scroll timer
	m_nScrollTimer = SetTimer(1, SCROLL_TIMER, NULL);
}
Beispiel #15
0
void CMyTreeCtrl::OnBeginDrag(LPNMHDR /*pnmhdr*/, LRESULT * /*pLResult*/)
{
	CPoint      ptAction;
	UINT        nFlags;

	GetCursorPos(&ptAction);
	ScreenToClient(&ptAction);
	ASSERT(!m_bDragging);
	m_bDragging = TRUE;
	m_hitemDrag = HitTest(ptAction, &nFlags);
	m_hitemDrop = NULL;

	ASSERT(m_pimagelist == NULL);
	m_pimagelist = CreateDragImage(m_hitemDrag);  // get the image list for dragging
	m_pimagelist->DragShowNolock(TRUE);
	m_pimagelist->SetDragCursorImage(1, CPoint(0, 0));
	m_pimagelist->BeginDrag(0, CPoint(0,0));
	m_pimagelist->DragMove(ptAction);
	m_pimagelist->DragEnter(this, ptAction);
	SetCapture();

	//set the timer to watch for scroll up and down
	SetTimer(1000,75,NULL);
}
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode,
                                 nsISupportsArray *anArrayTransferables,
                                 nsIScriptableRegion *aRegion,
                                 PRUint32 aActionType)
{
  nsresult rv = nsBaseDragService::InvokeDragSession(aDOMNode,
                                                     anArrayTransferables,
                                                     aRegion,
                                                     aActionType);
  NS_ENSURE_SUCCESS(rv, rv);

  // Try and get source URI of the items that are being dragged
  nsIURI *uri = nsnull;

  nsCOMPtr<nsIDocument> doc(do_QueryInterface(mSourceDocument));
  if (doc) {
    uri = doc->GetDocumentURI();
  }

  PRUint32 numItemsToDrag = 0;
  rv = anArrayTransferables->Count(&numItemsToDrag);
  if (!numItemsToDrag)
    return NS_ERROR_FAILURE;

  // The clipboard class contains some static utility methods that we
  // can use to create an IDataObject from the transferable

  // if we're dragging more than one item, we need to create a
  // "collection" object to fake out the OS. This collection contains
  // one |IDataObject| for each transferable. If there is just the one
  // (most cases), only pass around the native |IDataObject|.
  nsRefPtr<IDataObject> itemToDrag;
  if (numItemsToDrag > 1) {
    nsDataObjCollection * dataObjCollection = new nsDataObjCollection();
    if (!dataObjCollection)
      return NS_ERROR_OUT_OF_MEMORY;
    itemToDrag = dataObjCollection;
    for (PRUint32 i=0; i<numItemsToDrag; ++i) {
      nsCOMPtr<nsISupports> supports;
      anArrayTransferables->GetElementAt(i, getter_AddRefs(supports));
      nsCOMPtr<nsITransferable> trans(do_QueryInterface(supports));
      if (trans) {
        nsRefPtr<IDataObject> dataObj;
        rv = nsClipboard::CreateNativeDataObject(trans,
                                                 getter_AddRefs(dataObj), uri);
        NS_ENSURE_SUCCESS(rv, rv);
        // Add the flavors to the collection object too
        rv = nsClipboard::SetupNativeDataObject(trans, dataObjCollection);
        NS_ENSURE_SUCCESS(rv, rv);

        dataObjCollection->AddDataObject(dataObj);
      }
    }
  } // if dragging multiple items
  else {
    nsCOMPtr<nsISupports> supports;
    anArrayTransferables->GetElementAt(0, getter_AddRefs(supports));
    nsCOMPtr<nsITransferable> trans(do_QueryInterface(supports));
    if (trans) {
      rv = nsClipboard::CreateNativeDataObject(trans,
                                               getter_AddRefs(itemToDrag),
                                               uri);
      NS_ENSURE_SUCCESS(rv, rv);
    }
  } // else dragging a single object

  // Create a drag image if support is available
  IDragSourceHelper *pdsh;
  if (SUCCEEDED(CoCreateInstance(CLSID_DragDropHelper, NULL, CLSCTX_INPROC_SERVER,
                                 IID_IDragSourceHelper, (void**)&pdsh))) {
    SHDRAGIMAGE sdi;
    if (CreateDragImage(aDOMNode, aRegion, &sdi)) {
      if (FAILED(pdsh->InitializeFromBitmap(&sdi, itemToDrag)))
        DeleteObject(sdi.hbmpDragImage);
    }
    pdsh->Release();
  }

  // Kick off the native drag session
  return StartInvokingDragSession(itemToDrag, aActionType);
}
Beispiel #17
0
	void CDuiHeaderCtrl::OnMouseMove( UINT nFlags,CPoint pt )
	{
		if(m_bDragging || nFlags&MK_LBUTTON)
		{
			if(!m_bDragging)
			{
				m_bDragging=TRUE;
				if(IsItemHover(m_dwHitTest) && m_bItemSwapEnable)
				{
					m_dwDragTo=m_dwHitTest;
					CRect rcItem=GetItemRect(LOWORD(m_dwHitTest));
					DrawDraggingState(m_dwDragTo);
					m_hDragImg=CreateDragImage(LOWORD(m_dwHitTest));
					CPoint pt=m_ptClick-rcItem.TopLeft();
					CDragWnd::BeginDrag(m_hDragImg,pt,0,128,LWA_ALPHA|LWA_COLORKEY);
				}
			}
			if(IsItemHover(m_dwHitTest))
			{
				if(m_bItemSwapEnable)
				{
					DWORD dwDragTo=HitTest(pt);
					CPoint pt2(pt.x,m_ptClick.y);
					ClientToScreen(GetContainer()->GetHostHwnd(),&pt2);
					if(IsItemHover(dwDragTo) && m_dwDragTo!=dwDragTo)
					{
						m_dwDragTo=dwDragTo;
						DUITRACE(_T("\n!!! dragto %d"),LOWORD(dwDragTo));
						DrawDraggingState(dwDragTo);
					}
					CDragWnd::DragMove(pt2);
				}
			}else if(m_dwHitTest!=-1)
			{//调节宽度
				int cxNew=m_nAdjItemOldWidth+pt.x-m_ptClick.x;
				if(cxNew<0) cxNew=0;
				m_arrItems[LOWORD(m_dwHitTest)].cx=cxNew;
				NotifyInvalidate();
				GetContainer()->DuiUpdateWindow();//立即更新窗口
				//发出调节宽度消息
				DUINMHDSIZECHANGING	nm;
				nm.hdr.hDuiWnd=m_hDuiWnd;
				nm.hdr.code=DUINM_HDSIZECHANGING;
				nm.hdr.idFrom=GetCmdID();
				nm.hdr.pszNameFrom=GetName();
				nm.nWidth=cxNew;
				DuiNotify((LPDUINMHDR)&nm);
			}
		}else
		{
			DWORD dwHitTest=HitTest(pt);
			if(dwHitTest!=m_dwHitTest)
			{
				if(m_bSortHeader)
				{
					if(IsItemHover(m_dwHitTest))
					{
						WORD iHover=LOWORD(m_dwHitTest);
						m_arrItems[iHover].state=0;
						RedrawItem(iHover);
					}
					if(IsItemHover(dwHitTest))
					{
						WORD iHover=LOWORD(dwHitTest);
						m_arrItems[iHover].state=1;//hover
						RedrawItem(iHover);
					}
				}
				m_dwHitTest=dwHitTest;
			}
		}
		
	}
void CEsmSubListCtrl::OnBeginDrag (NMHDR* pNMHDR, LRESULT* pResult) {
  DEFINE_FUNCTION("CEsmSubListCtrl::OnBeginDrag()");
  NM_LISTVIEW*	  pNMListView = (NM_LISTVIEW*)pNMHDR;
  CEsmSubCellRef* pCellRef;
  CEsmSubName*    pRefName; 
  esmrecinfo_t*   pRecInfo;
  LVITEM	  ItemInfo;
  POINT		  DragPoint;
  BOOL		  Result;
  BYTE*		  pArray;
  POSITION	  SelPos;
  int		  Offset = 10;
  int		  ListIndex;
  int		  Index;
  *pResult = 0;

	/* Ignore if the dragging is disabled for the list */
  if (!m_EnableDrag) return;
  if (m_ActNormalList) return;

	/* Copy the records we wish to drag */
  CreateArrayPointer(pArray, byte, sizeof(esmrecinfo_t*)*GetSelectedCount());
  m_ppDragRecords = (esmrecinfo_t**) pArray;
  SelPos = GetFirstSelectedItemPosition();
  m_NumDragRecords = 0;
  Index = 0;

  while (SelPos != NULL) {
    ListIndex = GetNextSelectedItem(SelPos);
    pCellRef = (CEsmSubCellRef *) GetItemData(ListIndex);
    pRefName = (CEsmSubName *) pCellRef->FindSubRecord(MWESM_SUBREC_NAME);

		/* Ensure the cell reference object is valid */
    if (pRefName == NULL) continue;
    pRecInfo = m_pEsmDlgHandler->GetDocument()->FindRecord(pRefName->GetName());
    if (pRecInfo == NULL) continue;

    m_ppDragRecords[Index] = pRecInfo;
    m_NumDragRecords++;
    Index++;
   }

	/* Setup the dragging members */
  m_DragIndex  = pNMListView->iItem;
  m_IsDragging = true;
  DragPoint.x  = Offset;
  DragPoint.y  = Offset;
  m_DropIndex  = 0;
  m_pDropWnd   = this;
  m_pDropList  = NULL;
  
	/* Create the image for dragging */
  ItemInfo.mask     = LVIF_IMAGE;
  ItemInfo.iItem    = pNMListView->iItem;
  ItemInfo.iSubItem = 0;
  Result = CListCtrl::GetItem(&ItemInfo);

  m_hGoodDropCursor = GetCursor();
  SetCursor(m_hBadDropCursor);

  if (Result) {
    m_pDragImage = new CImageList();
    m_pDragImage->Create(&m_ImageList);
    m_pDragImage->Copy(0, ItemInfo.iImage, ILCF_MOVE);
   }
  else {
    m_pDragImage = CreateDragImage(m_DragIndex, &DragPoint);
   }

  ASSERT(m_pDragImage);

	/* Change the cursor to the drag image
	  (still must perform DragMove() in OnMouseMove() to show it moving) */
  m_pDragImage->BeginDrag(0, CPoint(Offset, Offset));
  m_pDragImage->DragEnter(GetDesktopWindow(), pNMListView->ptAction);

	/* Cause this control to capture all the mouse messages */
  SetCapture();
 }
// Based on code by Frank Kobs.
CImageList* CDragDropListCtrl::CreateDragImageEx(LPPOINT lpPoint)
{
	CRect rectSingle;	
	CRect rectComplete(0, 0, 0, 0);
	int	nIndex	= -1;
	BOOL bFirst	= TRUE;

	// Determine the size of the drag image.
	POSITION pos = GetFirstSelectedItemPosition();
	while (pos)
	{
		nIndex = GetNextSelectedItem(pos);
		GetItemRect(nIndex, rectSingle, LVIR_BOUNDS);
		if (bFirst)
		{
			// Initialize the CompleteRect
			GetItemRect(nIndex, rectComplete, LVIR_BOUNDS);
			bFirst = FALSE;
		}
		rectComplete.UnionRect(rectComplete, rectSingle);
	}

	// Create bitmap in memory DC
	CClientDC dcClient(this);	
	CDC dcMem;	
	CBitmap Bitmap;

	if (!dcMem.CreateCompatibleDC(&dcClient))
	{
		return NULL;
	}

	if (!Bitmap.CreateCompatibleBitmap(&dcClient, rectComplete.Width(), rectComplete.Height()))
	{
		return NULL;
	}
	
	CBitmap* pOldMemDCBitmap = dcMem.SelectObject(&Bitmap);
	// Here green is used as mask color.
	dcMem.FillSolidRect(0, 0, rectComplete.Width(), rectComplete.Height(), RGB(0, 255, 0)); 

	// Paint each DragImage in the DC.
	CImageList* pSingleImageList = NULL;
	CPoint pt;

	pos = GetFirstSelectedItemPosition();
	while (pos)
	{
		nIndex = GetNextSelectedItem(pos);
		GetItemRect(nIndex, rectSingle, LVIR_BOUNDS);

		pSingleImageList = CreateDragImage(nIndex, &pt);
		if (pSingleImageList)
		{
			// Make sure width takes into account not using LVS_EX_FULLROWSELECT style.
			IMAGEINFO ImageInfo;
			pSingleImageList->GetImageInfo(0, &ImageInfo);
			rectSingle.right = rectSingle.left + (ImageInfo.rcImage.right - ImageInfo.rcImage.left);

			pSingleImageList->DrawIndirect(
				&dcMem, 
				0, 
				CPoint(rectSingle.left - rectComplete.left, 
				rectSingle.top - rectComplete.top),
				rectSingle.Size(), 
				CPoint(0,0));

			delete pSingleImageList;
		}
	}

	dcMem.SelectObject(pOldMemDCBitmap);

	// Create the imagelist	with the merged drag images.
	CImageList* pCompleteImageList = new CImageList;
	
	pCompleteImageList->Create(rectComplete.Width(), rectComplete.Height(), ILC_COLOR | ILC_MASK, 0, 1);
	// Here green is used as mask color.
	pCompleteImageList->Add(&Bitmap, RGB(0, 255, 0)); 

	Bitmap.DeleteObject();

	// As an optional service:
	// Find the offset of the current mouse cursor to the imagelist
	// this we can use in BeginDrag().
	if (lpPoint)
	{
		CPoint ptCursor;
		GetCursorPos(&ptCursor);
		ScreenToClient(&ptCursor);
		lpPoint->x = ptCursor.x - rectComplete.left;
		lpPoint->y = ptCursor.y - rectComplete.top;
	}

	return pCompleteImageList;
}
Beispiel #20
0
CImageList* CPlayerListCtrl::CreateDragImageEx(LPPOINT lpPoint)
{
    if (GetSelectedCount() <= 0) {
        return nullptr;
    }

    CRect cSingleRect, cCompleteRect(0, 0, 0, 0);
    GetClientRect(cSingleRect);
    int nWidth = cSingleRect.Width();

    // Start and Stop index in view area
    int nIndex = GetTopIndex() - 1;
    int nBottomIndex = GetBottomIndex();

    // Determine the size of the drag image (limited for
    // rows visible and Client width)
    while ((nIndex = GetNextItem(nIndex, LVNI_SELECTED)) != -1 && nIndex <= nBottomIndex) {
        GetItemRect(nIndex, cSingleRect, LVIR_BOUNDS);
        /*
        CRect r;
        GetItemRect(nIndex, r, LVIR_LABEL);
        cSingleRect.left = r.left;
        */
        if (cSingleRect.left < 0) {
            cSingleRect.left = 0;
        }
        if (cSingleRect.right > nWidth) {
            cSingleRect.right = nWidth;
        }

        cCompleteRect |= cSingleRect;
    }

    //
    // Create bitmap in memory DC
    //
    CClientDC cDc(this);
    CDC cMemDC;
    CBitmap cBitmap;

    if (!cMemDC.CreateCompatibleDC(&cDc)) {
        return nullptr;
    }

    if (!cBitmap.CreateCompatibleBitmap(&cDc, cCompleteRect.Width(), cCompleteRect.Height())) {
        return nullptr;
    }

    CBitmap* pOldMemDCBitmap = cMemDC.SelectObject(&cBitmap);
    // Here green is used as mask color
    cMemDC.FillSolidRect(0, 0, cCompleteRect.Width(), cCompleteRect.Height(), RGB(0, 255, 0));

    // Paint each DragImage in the DC
    nIndex = GetTopIndex() - 1;
    while ((nIndex = GetNextItem(nIndex, LVNI_SELECTED)) != -1 && nIndex <= nBottomIndex) {
        CPoint pt;
        CImageList* pSingleImageList = CreateDragImage(nIndex, &pt);

        if (pSingleImageList) {
            GetItemRect(nIndex, cSingleRect, LVIR_BOUNDS);

            pSingleImageList->Draw(&cMemDC,
                                   0,
                                   CPoint(cSingleRect.left - cCompleteRect.left, cSingleRect.top - cCompleteRect.top),
                                   ILD_MASK);

            pSingleImageList->DeleteImageList();
            delete pSingleImageList;
        }
    }

    cMemDC.SelectObject(pOldMemDCBitmap);

    //
    // Create the image list with the merged drag images
    //
    CImageList* pCompleteImageList = DEBUG_NEW CImageList;

    pCompleteImageList->Create(cCompleteRect.Width(),
                               cCompleteRect.Height(),
                               ILC_COLOR | ILC_MASK, 0, 1);

    // Here green is used as mask color
    pCompleteImageList->Add(&cBitmap, RGB(0, 255, 0));

    //
    // as an optional service:
    // Find the offset of the current mouse cursor to the image list
    // this we can use in BeginDrag()
    //
    if (lpPoint) {
        lpPoint->x = cCompleteRect.left;
        lpPoint->y = cCompleteRect.top;
    }

    return pCompleteImageList;
}
Beispiel #21
0
inline void CCustomTabCtrl::BeginDrag(CPoint point)
{
	dragimg = CreateDragImage(sel);
	dragimg->BeginDrag(0, CPoint(-12, -4));
	SetCursor(AfxGetApp()->LoadCursor(IDC_DRAG_CUR));
}
void SmartListCtrl::OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult)
{
	*pResult = 0;

	if ( !eventHandler_ )
		return;

	LPNMLISTVIEW info = (LPNMLISTVIEW)pNMHDR;
	std::string text;
	int image;
	getData( info->iItem, text, image );

	POINT pt;
	GetCursorPos( &pt );
	if ( dragImgList_ )
	{
		delete dragImgList_;
		dragImgList_ = 0;
	}

	int pos = GetNextItem( -1, LVNI_SELECTED );
	bool isFirst = true;
	int xoff = 0;
	int yoff = 0;
	int xstep = 0;
	int ystep = 0;
	IMAGEINFO imf;
	int maxDragWidth = 400;
	int maxDragHeight = 350;
	while ( pos != -1 ) {
		if ( isFirst ) {
			dragImgList_ = CreateDragImage( pos, &pt );
			dragImgList_->GetImageInfo( 0, &imf );
			xstep = imf.rcImage.right - imf.rcImage.left;
			ystep = imf.rcImage.bottom - imf.rcImage.top;
			yoff = imf.rcImage.bottom;
			isFirst = false;
		}
		else
		{
			if ( yoff + ystep > maxDragHeight && xoff + xstep > maxDragWidth )
				generateDragListEndItem_ = true; // reached the max, so generate a 'more...' item in GetData
			CImageList* oneImgList = CreateDragImage( pos, &pt );
			generateDragListEndItem_ = false;
			CImageList* tempImgList = new CImageList();
			tempImgList->Attach(
				ImageList_Merge( 
					dragImgList_->GetSafeHandle(),
					0, oneImgList->GetSafeHandle(), 0, xoff, yoff ) );
			delete dragImgList_;
			delete oneImgList;
			dragImgList_ = tempImgList;
			dragImgList_->GetImageInfo( 0, &imf );
			yoff += ystep;
			if ( yoff > maxDragHeight )
			{
				xoff += xstep;
				if ( xoff > maxDragWidth )
					break;
				yoff = 0;
			}
		}
		pos = GetNextItem( pos, LVNI_SELECTED );
	}

	if ( dragImgList_ ) 
	{
		CPoint offset( thumbWidthCur_ + 16 , max( 16, thumbHeightCur_ - 14 ) );
		dragImgList_->SetBkColor( GetBkColor() );
		dragImgList_->SetDragCursorImage( 0, offset );
		dragImgList_->BeginDrag( 0, offset );
		dragImgList_->DragEnter( 0, pt );
	}

	if ( delayedSelectionPending_ )
	{
		// if a selection timer is pending, force it
		delayedSelectionNotify();
	}

	dragging_ = true;
	eventHandler_->listStartDrag( info->iItem );

}