GME
13
|
00001 // GMEActiveBrowserDropTarget.cpp: implementation of the CGMEActiveBrowserDropTarget class. 00002 // 00004 00005 #include "stdafx.h" 00006 #include "gmeactivebrowser.h" 00007 #include "MgaMappedTreeCtrl.h" 00008 #include "GMEActiveBrowserDropTarget.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 CGMEActiveBrowserDropTarget::CGMEActiveBrowserDropTarget(CMgaMappedTreeCtrlBase* 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 CGMEActiveBrowserDropTarget::~CGMEActiveBrowserDropTarget() 00040 { 00041 00042 } 00043 00044 DROPEFFECT CGMEActiveBrowserDropTarget::OnDragEnter(CWnd *pWnd, COleDataObject *pDataObject, DWORD dwKeyState, CPoint point) 00045 { 00046 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::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 { 00053 ACTIVEBROWSERDROPTARGET_LOGEVENT(" Drag initiated by the tree control\r\n"); 00054 m_pDragImageList=&m_pParent->m_CurrentDragImage; 00055 m_ptHotSpot=m_pParent->m_ptHotSpot; 00056 00057 } 00058 00059 if(m_pDragImageList==NULL) 00060 { 00061 m_pDragImageList=ExtractGMEDataObject(pDataObject); 00062 } 00063 00064 00065 if(m_pDragImageList!=NULL) 00066 { 00067 m_pDragImageList->BeginDrag(0,m_ptHotSpot); 00068 m_pDragImageList->DragShowNolock(TRUE); 00069 } 00070 00071 return OnDragOver(pWnd,pDataObject,dwKeyState,point); 00072 } 00073 00074 00075 00076 00077 DROPEFFECT CGMEActiveBrowserDropTarget::OnDragOver(CWnd *pWnd, COleDataObject *pDataObject, DWORD dwKeyState, CPoint point) 00078 { 00079 00080 if(point.y>=0 && point.y<=2) // Upward scrolling 00081 { 00082 if(m_pDragImageList!=NULL) 00083 { 00084 m_pDragImageList->DragShowNolock(FALSE); 00085 m_pParent->ScrollUp(); 00086 m_pDragImageList->DragShowNolock(TRUE); 00087 } 00088 else 00089 { 00090 m_pParent->ScrollUp(); 00091 } 00092 00093 } 00094 00095 00096 if(m_pDragImageList!=NULL) 00097 { 00098 CRect rectWnd; 00099 m_pParent->GetWindowRect(rectWnd); 00100 m_pDragImageList->DragMove(point+rectWnd.TopLeft()); 00101 } 00102 00103 00104 if(!m_pParent->IsRelevantDropTarget(point,m_pDragImageList)) 00105 { 00106 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDragOver DROPEFFECT_NONE\r\n"); 00107 return DROPEFFECT_NONE; 00108 } 00109 00110 // PETER: Only copy is supported on XML based clipboard data 00111 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp(); 00112 CComPtr<IMgaProject> ccpMgaProject=pApp->m_CurrentProject.m_MgaContext.m_ccpProject; 00113 if(!CGMEDataSource::IsGmeNativeDataAvailable(pDataObject, ccpMgaProject)) { 00114 if (CGMEDataSource::IsXMLDataAvailable(pDataObject)) { 00115 m_doDragOperation=DRAGOP_COPY; 00116 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDragOver DROPEFFECT_COPY\r\n"); 00117 return DROPEFFECT_COPY; 00118 } 00119 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDragOver DROPEFFECT_NONE\r\n"); 00120 return DROPEFFECT_NONE; 00121 } 00122 // PETER: end 00123 00124 // No modifier: Move operation 00125 // Ctrl: Copy (signified by "plus" icon over mouse cursor) 00126 // Ctrl+Shift: Create reference (signified by link icon over mouse cursor) 00127 // Alt: Create Instance (signified by link icon over mouse cursor) 00128 // Alt+Shift: Create Sub Type (signified by link icon over mouse cursor) 00129 00130 // Getting the modifiers 00131 BOOL bControl=dwKeyState & MK_CONTROL; 00132 BOOL bShift=(dwKeyState & MK_SHIFT); 00133 BOOL bAlt(dwKeyState & MK_ALT); 00134 00135 00136 DROPEFFECT deRetVal; 00137 if(bControl&&bShift) // Reference 00138 { 00139 deRetVal=DROPEFFECT_LINK; 00140 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDragOver DROPEFFECT_LINK\r\n"); 00141 m_doDragOperation=DRAGOP_REFERENCE; 00142 } 00143 else if(bAlt&&bShift) // Create SubType 00144 { 00145 deRetVal=DROPEFFECT_COPY | DROPEFFECT_LINK; 00146 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDragOver DROPEFFECT_COPY | DROPEFFECT_LINK\r\n"); 00147 m_doDragOperation=DRAGOP_SUBTYPE; 00148 } 00149 else if(bControl) // Copy 00150 { 00151 deRetVal=DROPEFFECT_COPY; 00152 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDragOver DROPEFFECT_COPY\r\n"); 00153 m_doDragOperation=DRAGOP_COPY; 00154 } 00155 else if(bAlt) // Instance 00156 { 00157 deRetVal=DROPEFFECT_COPY | DROPEFFECT_LINK; 00158 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDragOver DROPEFFECT_COPY | DROPEFFECT_LINK\r\n"); 00159 m_doDragOperation=DRAGOP_INSTANCE; 00160 } 00161 else // Move 00162 { 00163 deRetVal=DROPEFFECT_MOVE; 00164 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDragOver DROPEFFECT_MOVE\r\n"); 00165 m_doDragOperation=DRAGOP_MOVE; 00166 } 00167 00168 return deRetVal; 00169 } 00170 00171 void CGMEActiveBrowserDropTarget::OnDragLeave(CWnd *pWnd) 00172 { 00173 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDragLeave()\r\n"); 00174 if(m_pDragImageList!=NULL) 00175 { 00176 m_pDragImageList->DragLeave(pWnd); 00177 m_pDragImageList->EndDrag(); 00178 m_pParent->Invalidate(); 00179 00180 if(m_bCreatedDragImageList) // The DragImageList was created here, so delete it! 00181 { 00182 m_pDragImageList->DeleteImageList(); 00183 delete m_pDragImageList; 00184 m_pDragImageList=NULL; 00185 m_bCreatedDragImageList=FALSE; 00186 } 00187 } 00188 00189 } 00190 00191 00192 BOOL CGMEActiveBrowserDropTarget::OnDrop(CWnd *pWnd, COleDataObject *pDataObject, DROPEFFECT, CPoint point) 00193 { 00194 ACTIVEBROWSERDROPTARGET_LOGEVENT("CGMEActiveBrowserDropTarget::OnDrop()\r\n"); 00195 OnDragLeave(pWnd); 00196 00197 return m_pParent->DoDrop(m_doDragOperation,pDataObject,point); 00198 } 00199 00200 00201 CImageList* CGMEActiveBrowserDropTarget::ExtractGMEDataObject(COleDataObject *pDataObject) 00202 { 00203 00204 CGMEDataDescriptor GMEDataDescriptor; 00205 if(GMEDataDescriptor.Load(pDataObject)) 00206 { 00207 CRect rectBoundingRect; 00208 GMEDataDescriptor.GetBoundingRect(rectBoundingRect); 00209 00210 CClientDC dcClient(m_pParent); 00211 CDC dcMem; 00212 CBitmap Bitmap; 00213 00214 if (!dcMem.CreateCompatibleDC(&dcClient)) 00215 return NULL; 00216 00217 if (!Bitmap.CreateCompatibleBitmap(&dcClient, 00218 rectBoundingRect.Width(), 00219 rectBoundingRect.Height())) 00220 return NULL; 00221 00222 CBitmap *pOldMemDCBitmap = dcMem.SelectObject(&Bitmap); 00223 00224 COLORREF cMaskColor=RGB(0,255,0); 00225 dcMem.FillSolidRect(0, 0, 00226 rectBoundingRect.Width(), 00227 rectBoundingRect.Height(), 00228 cMaskColor); 00229 00230 GMEDataDescriptor.SimpleDraw(&dcMem,-rectBoundingRect.TopLeft()); 00231 00232 00233 00234 //BitBlt(dcClient.GetSafeHdc(),0,0,rectBoundingRect.Width(),rectBoundingRect.Height(),dcMem.GetSafeHdc(),0,0,SRCCOPY); 00235 00236 dcMem.SelectObject(pOldMemDCBitmap); 00237 00238 CImageList* pImageList=new CImageList(); 00239 00240 pImageList->Create(rectBoundingRect.Width(), 00241 rectBoundingRect.Height(), 00242 ILC_COLOR | ILC_MASK, 00243 0, 1); 00244 00245 // Green is used as mask color 00246 pImageList->Add(&Bitmap, cMaskColor); 00247 00248 //pImageList->Draw(&dcClient,0,CPoint(0,0), ILD_TRANSPARENT); 00249 00250 Bitmap.DeleteObject(); 00251 m_bCreatedDragImageList=TRUE; 00252 m_ptHotSpot=-rectBoundingRect.TopLeft(); 00253 return pImageList; 00254 } 00255 return NULL; 00256 }