GME
13
|
00001 // GMEActiveBrowserDropTarget.cpp: implementation of the CGMEViewDropTarget class. 00002 // 00004 00005 #include "stdafx.h" 00006 #include "GMEView.h" 00007 #include "GMEViewDropTarget.h" 00008 #include "GMEViewDlg.h" 00009 #include "..\GME\GMEOLEData.h" 00010 00011 00012 #ifdef _DEBUG 00013 #undef THIS_FILE 00014 static char THIS_FILE[]=__FILE__; 00015 #define new DEBUG_NEW 00016 #endif 00017 00018 00020 // Construction/Destruction 00022 00023 CGMEViewDropTarget::CGMEViewDropTarget(CGMEViewDlg* pParent) 00024 { 00025 m_pParent = pParent; 00026 m_bCreatedDragImageList = FALSE; 00027 m_pDragImageList = NULL; 00028 00029 try 00030 { 00031 COMTHROW(m_EventLogger.CoCreateInstance(L"Mga.MgaEventLogger")); 00032 } 00033 catch(...) 00034 { 00035 m_EventLogger = NULL; 00036 } 00037 } 00038 00039 CGMEViewDropTarget::~CGMEViewDropTarget() 00040 { 00041 00042 } 00043 00044 DROPEFFECT CGMEViewDropTarget::OnDragEnter(CWnd *pWnd, COleDataObject *pDataObject, DWORD dwKeyState, CPoint point) 00045 { 00046 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDragEnter()\r\n"); 00047 00048 m_pDragImageList = NULL; 00049 m_bCreatedDragImageList = FALSE; 00050 00051 /* if (m_pParent->m_CurrentDragImage.GetSafeHandle() != NULL) { // Drag initiated by the tree control 00052 GMEVIEWDROPTARGET_LOGEVENT(" Drag initiated by the tree control\r\n"); 00053 m_pDragImageList = &m_pParent->m_CurrentDragImage; 00054 m_ptHotSpot = m_pParent->m_ptHotSpot; 00055 }*/ 00056 00057 if (m_pDragImageList == NULL) { 00058 m_pDragImageList = ExtractGMEDataObject(pDataObject); 00059 } 00060 00061 00062 if (m_pDragImageList != NULL) { 00063 m_pDragImageList->BeginDrag(0, m_ptHotSpot); 00064 m_pDragImageList->DragShowNolock(TRUE); 00065 } 00066 00067 return OnDragOver(pWnd, pDataObject, dwKeyState, point); 00068 } 00069 00070 00071 00072 00073 DROPEFFECT CGMEViewDropTarget::OnDragOver(CWnd *pWnd, COleDataObject *pDataObject, DWORD dwKeyState, CPoint point) 00074 { 00075 00076 if (point.y >= 0 && point.y <= 2) { // Upward scrolling 00077 if (m_pDragImageList != NULL) { 00078 m_pDragImageList->DragShowNolock(FALSE); 00079 // m_pParent->ScrollUp(); 00080 m_pDragImageList->DragShowNolock(TRUE); 00081 } else { 00082 // m_pParent->ScrollUp(); 00083 } 00084 } 00085 00086 00087 if (m_pDragImageList != NULL) { 00088 CRect rectWnd; 00089 m_pParent->GetWindowRect(rectWnd); 00090 m_pDragImageList->DragMove(point + rectWnd.TopLeft()); 00091 } 00092 00093 // PETER: Only copy is supported on XML based clipboard data 00094 CComPtr<IMgaProject> ccpMgaProject = m_pParent->mgaProject; 00095 if (!CGMEDataSource::IsGmeNativeDataAvailable(pDataObject, ccpMgaProject)) { 00096 if (CGMEDataSource::IsXMLDataAvailable(pDataObject)) { 00097 m_doDragOperation = DRAGOP_COPY; 00098 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDragOver DROPEFFECT_COPY\r\n"); 00099 return DROPEFFECT_COPY; 00100 } 00101 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDragOver DROPEFFECT_NONE\r\n"); 00102 return DROPEFFECT_NONE; 00103 } 00104 // PETER: end 00105 00106 // No modifier: Move operation 00107 // Ctrl: Copy (signified by "plus" icon over mouse cursor) 00108 // Ctrl+Shift: Create reference (signified by link icon over mouse cursor) 00109 // Alt: Create Instance (signified by link icon over mouse cursor) 00110 // Alt+Shift: Create Sub Type (signified by link icon over mouse cursor) 00111 00112 // Getting the modifiers 00113 BOOL bControl = dwKeyState & MK_CONTROL; 00114 BOOL bShift = (dwKeyState & MK_SHIFT); 00115 BOOL bAlt(dwKeyState & MK_ALT); 00116 00117 00118 DROPEFFECT deRetVal; 00119 if (bControl && bShift) { // Reference 00120 deRetVal = DROPEFFECT_LINK; 00121 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDragOver DROPEFFECT_LINK\r\n"); 00122 m_doDragOperation = DRAGOP_REFERENCE; 00123 } else if (bAlt && bShift) { // Create SubType 00124 deRetVal=DROPEFFECT_COPY | DROPEFFECT_LINK; 00125 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDragOver DROPEFFECT_COPY | DROPEFFECT_LINK\r\n"); 00126 m_doDragOperation = DRAGOP_SUBTYPE; 00127 } else if (bControl) { // Copy 00128 deRetVal=DROPEFFECT_COPY; 00129 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDragOver DROPEFFECT_COPY\r\n"); 00130 m_doDragOperation = DRAGOP_COPY; 00131 } else if (bAlt) { // Instance 00132 deRetVal = DROPEFFECT_COPY | DROPEFFECT_LINK; 00133 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDragOver DROPEFFECT_COPY | DROPEFFECT_LINK\r\n"); 00134 m_doDragOperation = DRAGOP_INSTANCE; 00135 } else { // Move 00136 deRetVal = DROPEFFECT_MOVE; 00137 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDragOver DROPEFFECT_MOVE\r\n"); 00138 m_doDragOperation = DRAGOP_MOVE; 00139 } 00140 00141 return deRetVal; 00142 } 00143 00144 void CGMEViewDropTarget::OnDragLeave(CWnd *pWnd) 00145 { 00146 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDragLeave()\r\n"); 00147 if (m_pDragImageList != NULL) { 00148 m_pDragImageList->DragLeave(pWnd); 00149 m_pDragImageList->EndDrag(); 00150 m_pParent->Invalidate(); 00151 00152 if (m_bCreatedDragImageList) { // The DragImageList was created here, so delete it! 00153 m_pDragImageList->DeleteImageList(); 00154 delete m_pDragImageList; 00155 m_pDragImageList = NULL; 00156 m_bCreatedDragImageList = FALSE; 00157 } 00158 } 00159 } 00160 00161 00162 BOOL CGMEViewDropTarget::OnDrop(CWnd *pWnd, COleDataObject *pDataObject, DROPEFFECT, CPoint point) 00163 { 00164 GMEVIEWDROPTARGET_LOGEVENT("CGMEViewDropTarget::OnDrop()\r\n"); 00165 OnDragLeave(pWnd); 00166 00167 return m_pParent->DoDrop(m_doDragOperation, pDataObject, point); 00168 } 00169 00170 00171 CImageList* CGMEViewDropTarget::ExtractGMEDataObject(COleDataObject *pDataObject) 00172 { 00173 00174 CGMEDataDescriptor GMEDataDescriptor; 00175 if (GMEDataDescriptor.Load(pDataObject)) { 00176 CRect rectBoundingRect; 00177 GMEDataDescriptor.GetBoundingRect(rectBoundingRect); 00178 00179 CClientDC dcClient(m_pParent); 00180 CDC dcMem; 00181 CBitmap Bitmap; 00182 00183 if (!dcMem.CreateCompatibleDC(&dcClient)) 00184 return NULL; 00185 00186 if (!Bitmap.CreateCompatibleBitmap(&dcClient, 00187 rectBoundingRect.Width(), 00188 rectBoundingRect.Height())) 00189 return NULL; 00190 00191 CBitmap *pOldMemDCBitmap = dcMem.SelectObject(&Bitmap); 00192 00193 COLORREF cMaskColor = RGB(0, 255, 0); 00194 dcMem.FillSolidRect(0, 0, 00195 rectBoundingRect.Width(), 00196 rectBoundingRect.Height(), 00197 cMaskColor); 00198 00199 GMEDataDescriptor.SimpleDraw(&dcMem, -rectBoundingRect.TopLeft()); 00200 00201 //BitBlt(dcClient.GetSafeHdc(), 0, 0, rectBoundingRect.Width(), rectBoundingRect.Height(), dcMem.GetSafeHdc(), 0, 0, SRCCOPY); 00202 00203 dcMem.SelectObject(pOldMemDCBitmap); 00204 00205 CImageList* pImageList = new CImageList(); 00206 00207 pImageList->Create(rectBoundingRect.Width(), 00208 rectBoundingRect.Height(), 00209 ILC_COLOR | ILC_MASK, 00210 0, 1); 00211 00212 // Green is used as mask color 00213 pImageList->Add(&Bitmap, cMaskColor); 00214 00215 //pImageList->Draw(&dcClient, 0, CPoint(0, 0), ILD_TRANSPARENT); 00216 00217 Bitmap.DeleteObject(); 00218 m_bCreatedDragImageList = TRUE; 00219 m_ptHotSpot = -rectBoundingRect.TopLeft(); 00220 return pImageList; 00221 } 00222 return NULL; 00223 }