// Name : wxIDropTarget::DragEnter // Purpose : Called when the mouse enters the window (dragging something) // Returns : S_OK // Params : [in] IDataObject *pIDataSource : source data // [in] DWORD grfKeyState : kbd & mouse state // [in] POINTL pt : mouse coordinates // [in/out]DWORD *pdwEffect : effect flag // In: Supported effects // Out: Resulting effect // Notes : STDMETHODIMP wxIDropTarget::DragEnter(IDataObject *pIDataSource, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) { wxLogTrace(wxTRACE_OleCalls, wxT("IDropTarget::DragEnter")); wxASSERT_MSG( m_pIDataObject == NULL, wxT("drop target must have data object") ); // show the list of formats supported by the source data object for the // debugging purposes, this is quite useful sometimes - please don't remove #if 0 IEnumFORMATETC *penumFmt; if ( SUCCEEDED(pIDataSource->EnumFormatEtc(DATADIR_GET, &penumFmt)) ) { FORMATETC fmt; while ( penumFmt->Next(1, &fmt, NULL) == S_OK ) { wxLogDebug(wxT("Drop source supports format %s"), wxDataObject::GetFormatName(fmt.cfFormat)); } penumFmt->Release(); } else { wxLogLastError(wxT("IDataObject::EnumFormatEtc")); } #endif // 0 if ( !m_pTarget->MSWIsAcceptedData(pIDataSource) ) { // we don't accept this kind of data *pdwEffect = DROPEFFECT_NONE; return S_OK; } // for use in OnEnter and OnDrag calls m_pTarget->MSWSetDataSource(pIDataSource); // get hold of the data object m_pIDataObject = pIDataSource; m_pIDataObject->AddRef(); // we need client coordinates to pass to wxWin functions if ( !ScreenToClient(m_hwnd, (POINT *)&pt) ) { wxLogLastError(wxT("ScreenToClient")); } // give some visual feedback *pdwEffect = ConvertDragResultToEffect( m_pTarget->OnEnter(pt.x, pt.y, ConvertDragEffectToResult( GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction(), *pdwEffect)) ) ); return S_OK; }
//TODO: Review and clean code void CProjectHierarchyWnd::DoDrag() { if(m_pTarget) { m_bDrag = true; BaseTreeItem<loadngo::data::Entity> *pTreeItem = reinterpret_cast<BaseTreeItem<loadngo::data::Entity> *>(m_pTarget); IDataObject *pDataObject = pTreeItem->GetDataObject(); if(pDataObject) { pDataObject->AddRef(); DWORD outEffect = 0; DWORD dropEffect = DROPEFFECT_LINK | DROPEFFECT_COPY | DROPEFFECT_MOVE; DoDragDrop(pDataObject, this, dropEffect, &outEffect); delete pDataObject; } m_bDrag = false; } m_pTarget = NULL; }