00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "CtrlDragList.h"
00025 #include "LiveList.h"
00026
00027 #ifdef _DEBUG
00028 #define new DEBUG_NEW
00029 #undef THIS_FILE
00030 static char THIS_FILE[] = __FILE__;
00031 #endif
00032
00033 IMPLEMENT_DYNAMIC(CDragListCtrl, CListCtrl)
00034
00035 BEGIN_MESSAGE_MAP(CDragListCtrl, CListCtrl)
00036
00037 ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag)
00038 ON_WM_MOUSEMOVE()
00039 ON_WM_LBUTTONUP()
00040
00041 END_MESSAGE_MAP()
00042
00043
00045
00046
00047 CDragListCtrl::CDragListCtrl()
00048 {
00049 m_pDragImage = NULL;
00050 m_bCreateDragImage = FALSE;
00051 }
00052
00053 CDragListCtrl::~CDragListCtrl()
00054 {
00055 }
00056
00058
00059
00060 void CDragListCtrl::OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult)
00061 {
00062 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
00063 *pResult = 0;
00064
00065 CPoint ptAction( pNMListView->ptAction );
00066
00067 m_bCreateDragImage = TRUE;
00068 m_pDragImage = CLiveList::CreateDragImage( this, ptAction );
00069 m_bCreateDragImage = FALSE;
00070
00071 if ( m_pDragImage == NULL ) return;
00072 m_nDragDrop = -1;
00073
00074 UpdateWindow();
00075
00076 CRect rcClient;
00077 GetClientRect( &rcClient );
00078 ClientToScreen( &rcClient );
00079 ClipCursor( &rcClient );
00080 SetCapture();
00081
00082 SetFocus();
00083 UpdateWindow();
00084
00085 m_pDragImage->DragEnter( this, ptAction );
00086 }
00087
00088 void CDragListCtrl::OnMouseMove(UINT nFlags, CPoint point)
00089 {
00090 if ( m_pDragImage != NULL )
00091 {
00092 int nHit = HitTest( point );
00093
00094 m_pDragImage->DragMove( point );
00095
00096 if ( nHit != m_nDragDrop )
00097 {
00098 CImageList::DragShowNolock( FALSE );
00099 if ( m_nDragDrop >= 0 ) SetItemState( m_nDragDrop, 0, LVIS_DROPHILITED );
00100 m_nDragDrop = nHit;
00101 if ( m_nDragDrop >= 0 ) SetItemState( m_nDragDrop, LVIS_DROPHILITED, LVIS_DROPHILITED );
00102 UpdateWindow();
00103 CImageList::DragShowNolock( TRUE );
00104 }
00105 }
00106
00107 CListCtrl::OnMouseMove( nFlags, point );
00108 }
00109
00110 void CDragListCtrl::OnLButtonUp(UINT nFlags, CPoint point)
00111 {
00112 if ( m_pDragImage == NULL )
00113 {
00114 CListCtrl::OnLButtonUp( nFlags, point );
00115 return;
00116 }
00117
00118 ClipCursor( NULL );
00119 ReleaseCapture();
00120
00121 m_pDragImage->DragLeave( this );
00122 m_pDragImage->EndDrag();
00123 delete m_pDragImage;
00124 m_pDragImage = NULL;
00125
00126 if ( m_nDragDrop >= 0 )
00127 SetItemState( m_nDragDrop, 0, LVIS_DROPHILITED );
00128
00129
00130
00131 OnDragDrop( m_nDragDrop );
00132 }
00133
00134 void CDragListCtrl::OnDragDrop(int nDrop)
00135 {
00136 NM_LISTVIEW pNotify;
00137 pNotify.hdr.hwndFrom = GetSafeHwnd();
00138 pNotify.hdr.idFrom = GetDlgCtrlID();
00139 pNotify.hdr.code = LVN_DRAGDROP;
00140 pNotify.iItem = nDrop;
00141 GetOwner()->SendMessage( WM_NOTIFY, pNotify.hdr.idFrom, (LPARAM)&pNotify );
00142 }