Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

CtrlDragList.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlDragList.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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         //{{AFX_MSG_MAP(CDragListCtrl)
00037         ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag)
00038         ON_WM_MOUSEMOVE()
00039         ON_WM_LBUTTONUP()
00040         //}}AFX_MSG_MAP
00041 END_MESSAGE_MAP()
00042 
00043 
00045 // CDragListCtrl construction
00046 
00047 CDragListCtrl::CDragListCtrl()
00048 {
00049         m_pDragImage            = NULL;
00050         m_bCreateDragImage      = FALSE;
00051 }
00052 
00053 CDragListCtrl::~CDragListCtrl()
00054 {
00055 }
00056 
00058 // CDragListCtrl message handlers
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         //else
00129         //      m_nDragDrop = GetItemCount();
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 }

Generated on Thu Dec 15 10:39:35 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2