Esempio n. 1
0
void CHexEdit::OnEditPaste() 
{
	COleDataObject	obj;	
	if (obj.AttachClipboard()) 
	{
		HGLOBAL hmem = NULL;
		if (obj.IsDataAvailable(RegisterClipboardFormat("BinaryData"))) 
		{
			hmem = obj.GetGlobalData(RegisterClipboardFormat("BinaryData"));
		}	
		else if (obj.IsDataAvailable(CF_TEXT)) 
		{
			hmem = obj.GetGlobalData(CF_TEXT);
		}
		if(hmem)
		{
			LPBYTE	p = (BYTE*)::GlobalLock(hmem);
			DWORD	dwSizeMem=::GlobalSize(hmem);
			DWORD	dwSizeSel=GetSelLength();
			DWORD	dwLen =dwSizeMem>dwSizeSel?dwSizeSel:dwSizeMem;
			int		insert;
			
			NormalizeSel();
			if(m_selStart == 0xffffffff)
			{
				if(m_currentMode == EDIT_LOW)
					m_currentAddress++;
				insert = m_currentAddress;
				SelInsert(m_currentAddress, dwLen);
			}
			else
			{
				insert = m_selStart;
				SelDelete(m_selStart,m_selStart+dwLen-1);
				SelInsert(insert, dwLen);
			}
			memcpy(m_pData+insert, p, dwLen);
			
			m_currentAddress = insert+dwLen;
//			RepositionCaret(m_currentAddress);
			ResetPos();
			Invalidate(FALSE);
			::GlobalUnlock(hmem);
		}
	}
}
Esempio n. 2
0
void CHexEdit::OnEditPaste() 
{
	COleDataObject	obj;	
	if (obj.AttachClipboard()) 
	{
		HGLOBAL hmem = NULL;
		if (obj.IsDataAvailable(RegisterClipboardFormat(L"BinaryData"))) 
		{
			hmem = obj.GetGlobalData(RegisterClipboardFormat(L"BinaryData"));
		}	
		else if (obj.IsDataAvailable(CF_TEXT)) 
		{
			hmem = obj.GetGlobalData(CF_TEXT);
		}
		if(hmem)
		{
			LPBYTE	p = (BYTE*)::GlobalLock(hmem);
			DWORD	dwLen = ::GlobalSize(hmem);
			int		insert;
			int		oa = m_currentAddress;
			
			NormalizeSel();
			if(m_selStart == 0xffffffff)
			{
				if(m_currentMode == EDIT_LOW)
					m_currentAddress++;
				insert = m_currentAddress;
				SelInsert(m_currentAddress, dwLen);
			}
			else
			{
				insert = m_selStart;
				SelDelete(m_selStart, m_selEnd);
				SelInsert(insert, dwLen);
				SetSel(-1, -1);
			}

			memcpy(m_pData+insert, p, dwLen);

			m_currentAddress = oa;
			RedrawWindow();
			::GlobalUnlock(hmem);
		}
	}
}
Esempio n. 3
0
void CHexEdit::OnContextMenu(CWnd*, CPoint point)
{
    // by latelee
	#if 0
	// CG: This block was added by the Pop-up Menu component
	{
		if (point.x == -1 && point.y == -1)
		{
			//keystroke invocation
			CRect rect;
			GetClientRect(rect);
			ClientToScreen(rect);
			
			point = rect.TopLeft();
			point.Offset(5, 5);
		}
		
		CMenu menu;
		VERIFY(menu.LoadMenu(CG_IDR_POPUP_HEX_EDIT));
		
		CMenu* pPopup = menu.GetSubMenu(0);
		ASSERT(pPopup != NULL);
		
		pPopup->EnableMenuItem(ID_EDIT_UNDO, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
		if(!IsSelected())
		{
			pPopup->EnableMenuItem(ID_EDIT_CLEAR, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
			pPopup->EnableMenuItem(ID_EDIT_CUT, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
			pPopup->EnableMenuItem(ID_EDIT_COPY, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
		}
		{
			COleDataObject	obj;	
			if (obj.AttachClipboard()) 
			{
				if(!obj.IsDataAvailable(CF_TEXT) && !obj.IsDataAvailable(RegisterClipboardFormat("BinaryData")))
					pPopup->EnableMenuItem(ID_EDIT_PASTE, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
			}
		}
		
		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
			this);
	}
    #endif
}
Esempio n. 4
0
CLIPFORMAT CRulerRichEdit::GetAcceptableClipFormat(LPDATAOBJECT lpDataOb, CLIPFORMAT format) 
{ 
	if (m_bPasteSimple)
#ifndef _UNICODE
		return CF_TEXT;
#else
		return CF_UNICODETEXT;
#endif
	
	static CLIPFORMAT cfRtf = (CLIPFORMAT)::RegisterClipboardFormat(CF_RTF);
	static CLIPFORMAT cfRtfObj = (CLIPFORMAT)::RegisterClipboardFormat(CF_RETEXTOBJ); 
	
	CLIPFORMAT formats[] = 
	{ 
		COutlookHelper::CF_OUTLOOK,
		CF_HDROP,
		cfRtf,
		cfRtfObj, 
		CF_BITMAP,

#ifndef _UNICODE
		CF_TEXT,
#else
		CF_UNICODETEXT,
#endif
		CF_METAFILEPICT,    
		CF_SYLK,            
		CF_DIF,             
		CF_TIFF,            
		CF_OEMTEXT,         
		CF_DIB,             
		CF_PALETTE,         
		CF_PENDATA,         
		CF_RIFF,            
		CF_WAVE,            
		CF_ENHMETAFILE
	};
	
	const long nNumFmts = sizeof(formats) / sizeof(CLIPFORMAT);
	
	COleDataObject dataobj;
    dataobj.Attach(lpDataOb, FALSE);
    
	for (int nFmt = 0; nFmt < nNumFmts; nFmt++)
	{
		if (format && format == formats[nFmt])
			return format;
		
		if (dataobj.IsDataAvailable(formats[nFmt]))
			return formats[nFmt];
	}
	
	// all else
	return CF_HDROP; 
}
Esempio n. 5
0
void CEx27bView::OnUpdateEditPaste(CCmdUI* pCmdUI) 
{
    // Make sure that object data is available
	COleDataObject dataObject;
	if (dataObject.AttachClipboard() &&
    	dataObject.IsDataAvailable(m_cfEmbedded)) {
        pCmdUI->Enable(TRUE);
    } else {
    	pCmdUI->Enable(FALSE);
    }
}
Esempio n. 6
0
void kGUISystemWin::Paste(kGUIString *s)
{
	COleDataObject	obj;

	if (obj.AttachClipboard())
	{
#if 0
		if (obj.IsDataAvailable(CF_UNICODETEXT))
		{
			HGLOBAL hmem = obj.GetGlobalData(CF_UNICODETEXT);
			CMemFile sf((BYTE*) ::GlobalLock(hmem),(UINT) ::GlobalSize(hmem));
			CString buffer;

			LPSTR str = buffer.GetBufferSetLength((int)::GlobalSize(hmem));
			sf.Read(str,(UINT) ::GlobalSize(hmem));
			::GlobalUnlock(hmem);

			s->SetEncoding(ENCODING_UTF8);
			s->SetString(buffer);
		}
		else if (obj.IsDataAvailable(CF_TEXT))
#else
		if (obj.IsDataAvailable(CF_TEXT))
#endif
		{
			HGLOBAL hmem = obj.GetGlobalData(CF_TEXT);
			CMemFile sf((BYTE*) ::GlobalLock(hmem),(UINT) ::GlobalSize(hmem));
			CString buffer;

			LPSTR str = buffer.GetBufferSetLength((int)::GlobalSize(hmem));
			sf.Read(str,(UINT) ::GlobalSize(hmem));
			::GlobalUnlock(hmem);

//			s->SetEncoding(ENCODING_UTF8);
			s->SetEncoding(ENCODING_8BIT);
			s->SetString(buffer);
		}
	}
}
Esempio n. 7
0
// without this, idiot will paste files and other objects into window
HRESULT
mfc_edit_view::QueryAcceptData(LPDATAOBJECT lpdataobj,
                               CLIPFORMAT* lpcfFormat, DWORD reco,
                               BOOL fReally, HGLOBAL hMetaPict)
{
  if (*lpcfFormat == CF_TEXT) return S_OK;
  COleDataObject dataobj;
  dataobj.Attach(lpdataobj, FALSE);
  if (*lpcfFormat==0 && dataobj.IsDataAvailable(CF_TEXT)) {
    *lpcfFormat = CF_TEXT;
    return S_OK;
  }
  return S_FALSE;
}
Esempio n. 8
0
void CEditEx::OnContextMenu(CWnd* pWnd, CPoint point)
{
	if (point.x == -1 && point.y == -1)
	{
		//keystroke invocation
		CRect rect;
		GetClientRect(rect);
		ClientToScreen(rect);

		point = rect.TopLeft();
		point.Offset(5, 5);
	}

	CMenu menu;
	VERIFY(menu.LoadMenu(RIGHTBUTTON));

	CMenu* pPopup = menu.GetSubMenu(0);
	ASSERT(pPopup != NULL);

	//pPopup->EnableMenuItem(ID_EDIT_UNDO, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
	//pPopup->EnableMenuItem(ID_EDIT_CLEAR, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
	//pPopup->EnableMenuItem(ID_EDIT_CUT, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
	//pPopup->EnableMenuItem(ID_EDIT_COPY, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
	
	COleDataObject	obj;	
	if (obj.AttachClipboard()) 
	{
		if(!obj.IsDataAvailable(CF_TEXT) && !obj.IsDataAvailable(RegisterClipboardFormat(L"BinaryData")))
				pPopup->EnableMenuItem(ID_EDIT_PASTE, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
	}
	

	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
		this);
    return;
}
Esempio n. 9
0
///////////////////////////////////////////////////
// Verify that data you can handle is on the clipboard.
///////////////////////////////////////////////////
BOOL CDragDropMgr::OkToPaste()
{
    COleDataObject obj;

    BOOL bOk = FALSE;

    if (!obj.AttachClipboard())
        return FALSE;
    
    for (int i=0;i < m_nFormats.GetSize() && !bOk;i++)
    {
        UINT nF = m_nFormats.GetAt(i);
        bOk = obj.IsDataAvailable(m_nFormats.GetAt(i));
    }

    return bOk;
}
Esempio n. 10
0
	bool zstringEx::tools_getClipboardText()
	{    
		COleDataObject obj;

		if (obj.AttachClipboard()) 
		{
				if (obj.IsDataAvailable(CF_TEXT)) 
				{
					HGLOBAL hmem = obj.GetGlobalData(CF_TEXT);                  
					CMemFile sf((BYTE*) ::GlobalLock(hmem), (UINT)::GlobalSize(hmem));
					mem_data.mem_resizenull((UINT)::GlobalSize(hmem));
					sf.Read(mem_data.mem_string, (UINT)::GlobalSize(hmem));
					::GlobalUnlock(hmem);
					sf.Close();	
					return true;
				}
		}
		return false;
	}
Esempio n. 11
0
File: SITE.CPP Progetto: 0anion0/IBN
STDMETHODIMP CSite::DragEnter(IDataObject * pDataObject, WORD grfKeyState, POINTL pt,DWORD * pdwEffect)
{
    if(!pDataObject||!pdwEffect)
        return E_INVALIDARG;

    COleDataObject	pData;
    pData.Attach(pDataObject,FALSE);

    FORMATETC stFormatTEXT = {CF_TEXT,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL};

    if(pData.IsDataAvailable(CF_HDROP))
    {

        *pdwEffect = DROPEFFECT_NONE;
        return E_INVALIDARG;
    }

    *pdwEffect = DROPEFFECT_COPY;

    return S_OK;
}
Esempio n. 12
0
void CUIDesignerView::OnEditPaste()
{
	COleDataObject dataObject;
	dataObject.AttachClipboard();

	if(dataObject.IsDataAvailable(m_cfUI))
	{
		CFile* pFile = dataObject.GetFileData(m_cfUI);
		if (pFile == NULL)
			return;

		int len = (int)pFile->GetLength();
		char* pstrXML  = new char[len];
		pFile->Read(pstrXML, len);

		PasteUI(StringConvertor::Utf8ToWide(pstrXML));

		delete[] pstrXML;
		delete pFile;
	}
}
Esempio n. 13
0
BOOL CEx27bView::MakeMetafilePict(COleDataSource* pSource)
{
	CEx27bDoc* pDoc = GetDocument();
	COleDataObject dataObject;
	LPDATAOBJECT pDataObj; // OLE object's IDataObject interface
	VERIFY(pDoc->m_lpOleObj->QueryInterface(IID_IDataObject,
		  (void**) &pDataObj) == S_OK);
	dataObject.Attach(pDataObj);
    FORMATETC fmtem;
    SETFORMATETC(fmtem, CF_METAFILEPICT, DVASPECT_CONTENT, NULL,
        TYMED_MFPICT, -1);
    if (!dataObject.IsDataAvailable(CF_METAFILEPICT, &fmtem)) {
		TRACE("CF_METAFILEPICT format is unavailable\n");
    	return FALSE;
    }
	// Just copy the metafile handle from the OLE object
	//  to the clipboard data object
    STGMEDIUM stgmm;
	VERIFY(dataObject.GetData(CF_METAFILEPICT, &stgmm, &fmtem));
	pSource->CacheData(CF_METAFILEPICT, &stgmm, &fmtem);
	return TRUE;
}
Esempio n. 14
0
HRESULT CvSqlQueryRichEditView::QueryAcceptData(LPDATAOBJECT lpdataobj, CLIPFORMAT* lpcfFormat, DWORD dwReco, BOOL bReally, HGLOBAL hMetaPict)
{
	ASSERT(lpcfFormat != NULL);
	if (!bReally) // not actually pasting
		return S_OK;
	// if direct pasting a particular native format allow it
	if (IsRichEditFormat(*lpcfFormat))
		return S_OK;

	COleDataObject dataobj;
	dataobj.Attach(lpdataobj, FALSE);
	// if format is 0, then force particular formats if available
	if (*lpcfFormat == 0 && (m_nPasteType == 0))
	{
		if (dataobj.IsDataAvailable(CF_TEXT))
		{
			*lpcfFormat = CF_TEXT;
			return S_OK;
		}
	}
	return S_FALSE;
}
Esempio n. 15
0
CLIPFORMAT CUrlRichEditCtrl::GetAcceptableClipFormat(LPDATAOBJECT lpDataOb, CLIPFORMAT format)
{ 
	CLIPFORMAT formats[] = 
	{ 
		CF_HDROP,
			
#ifndef _UNICODE
		CF_TEXT,
#else
		CF_UNICODETEXT,
#endif
	};
	
	const long nNumFmts = sizeof(formats) / sizeof(CLIPFORMAT);
	
	// check for outlook first
	if (COutlookHelper::IsOutlookObject(lpDataOb))
		return COutlookHelper::CF_OUTLOOK;
    
	// else
	COleDataObject dataobj;
    dataobj.Attach(lpDataOb, FALSE);

	for (int nFmt = 0; nFmt < nNumFmts; nFmt++)
	{
		if (format && format == formats[nFmt])
			return format;
		
		if (dataobj.IsDataAvailable(formats[nFmt]))
			return formats[nFmt];
	}
	
#ifndef _UNICODE
	return CF_TEXT;
#else
	return CF_UNICODETEXT;
#endif
}
Esempio n. 16
0
////////////////////////////////////////////////////////
//This function loads data from the clipboard
//or drag/drop into a local object of the proper
//type for use.
//
//If pasting from clipboard, pDataObject should be NULL.
//
//You usually call this function from:
//
//1) Your view class's OnDrop() method when a drag-
//   drop operation ends, to load the data for use.
//
//2) Your view (or document) class's OnEditPaste()
//   method when doing a paste from the clipboard.
////////////////////////////////////////////////////////
BOOL CDragDropMgr::DoDrop(
                   CObject*        pO,
                   COleDataObject* pDataObject,
                   LPCTSTR         lpstrFormat)
{
//	try
	{
		UINT format = ::RegisterClipboardFormat(lpstrFormat);

		COleDataObject* pObj = NULL;

		// If from clipboard, then there is no
		// data object passed in, so use a local copy
		if (pDataObject == NULL)
			pObj = new COleDataObject();

 		else
			pObj = pDataObject;

		// Make sure basic data is OK
    	if (pObj == NULL)
    	    return FALSE;

		else if (pDataObject == NULL &&
 			!pObj->AttachClipboard())
			return FALSE;

		else if (format == 0 || pO == NULL)
			return FALSE;

		else if (!pObj->IsDataAvailable(format))
			return FALSE;

		FORMATETC fe;

		fe.cfFormat = format;
		fe.tymed    = TYMED_HGLOBAL;
		fe.lindex   = -1;
		fe.dwAspect = DVASPECT_CONTENT;
		fe.ptd      = NULL;

		// Fetch the data from the OLE data object
		HGLOBAL hMem = pObj->GetGlobalData(format,&fe);

		if (hMem == NULL)
			return FALSE;

	//	TRY
		{
			CMemFile mf((BYTE*)::GlobalLock(hMem), ::GlobalSize(hMem));

			CArchive ar(&mf, CArchive::load);
			pO->Serialize(ar); 
			 ar.Close();

			::GlobalUnlock(hMem);

			pObj->Release();

			if (pDataObject == NULL)
				delete pObj;

			return TRUE;
		}

	/*	CATCH_ALL(ce)
		{
			pObj->Release();

			if (pDataObject == NULL)
				delete pObj;

		return FALSE;
		}

		END_CATCH_ALL*/
	}

/*	catch(...)
	{
		CErrorDlg error;
		error.Error("Drag/drop error", "A serious error occured while dropping objects. Please report this to the Construct team.");
		return FALSE;
	}*/

	return TRUE;
}
Esempio n. 17
0
void SourceEdit::OnConvertPaste(NMHDR* hdr, LRESULT* res)
{
  SCNXConvertPaste* cp = (SCNXConvertPaste*)hdr;
  *res = 0;

  // Get the source of the data
  COleDataObject data;
  if (cp->source)
    data.Attach((LPDATAOBJECT)(cp->source),FALSE);
  else
    data.AttachClipboard();

  // Try to interpret tables and leading white space
  if (data.IsDataAvailable(CF_UNICODETEXT))
  {
    CStringW theText(cp->utext,cp->ulen);
    CStringW newText, line;
    newText.Preallocate(theText.GetLength());

    bool foundTable = false;
    bool inTable = false;

    int charPos = 0, lineCount = 0;
    while (GetNextLine(theText,line,charPos))
    {
      if (inTable)
      {
        CArray<CStringW> tokens;
        TokenizeLine(line,tokens);

        // Separate multiple tokens with tabs: if less than two tokens,
        // we're at the end of the table
        if (tokens.GetSize() > 1)
        {
          line.Empty();
          for (int j = 0; j < tokens.GetSize(); j++)
          {
            if (j > 0)
              line.AppendChar(L'\t');
            line.Append(tokens.GetAt(j));
          }
        }
        else
          inTable = false;
      }
      else
      {
        // Look for the start of a table
        if (line.Left(6).CompareNoCase(L"table ") == 0)
        {
          inTable = true;
          foundTable = true;
        }

        // Replace any leading blocks of 4 spaces
        int i = 0;
        while (i >= 0)
        {
          if (line.Mid(i,4).Compare(L"    ") == 0)
          {
            line.Delete(i,3);
            line.SetAt(i,L'\t');
            i++;
          }
          else
            i = -1;
        }
      }

      if (lineCount > 0)
        newText.AppendChar(L'\n');
      newText.Append(line);
      lineCount++;
    }

    CString newTextUtf = TextFormat::UnicodeToUTF8(newText);
		cp->text = new char[newTextUtf.GetLength() + 1];
    strcpy(cp->text,newTextUtf);
    *res = 1;
  }
}
Esempio n. 18
0
void BookmarkToolBar::OnDrop(COleDataObject *aOleDataObject, DROPEFFECT aDropEffect, CPoint aPoint)
{
    CToolBarCtrl &sToolBarCtrl = GetToolBarCtrl();

    DragImage &sDragImage = DragImage::instance();

    if (sDragImage.isMyDragging() == XPR_TRUE)
    {
        CImageList *sMyDragImage = sDragImage.getMyDragImage();
        if (XPR_IS_NOT_NULL(sMyDragImage))
        {
            sMyDragImage->EndDrag();
            sMyDragImage->DragShowNolock(XPR_FALSE);
        }
    }
    else
    {
        if (mDropTarget.isUseDropHelper() == XPR_TRUE)
            mDropTarget.getDropHelper()->DragLeave();
    }

    if (mOldInsert >= 0)
    {
        TBINSERTMARK sTbInsertMark = {0};
        sTbInsertMark.iButton = -1;
        sToolBarCtrl.SetInsertMark(&sTbInsertMark);
    }

    if (mOldBookmark >= 0)
    {
        TBBUTTON sTbButton = {0};
        sToolBarCtrl.GetButton(mOldBookmark, &sTbButton);
        sToolBarCtrl.SetState(sTbButton.idCommand, TBSTATE_ENABLED);
    }

    if (XPR_IS_NOT_NULL(mObserver))
    {
        mObserver->onBookmarkToolBarStatus(*this, -1, -1, DROPEFFECT_NONE);
    }

    COleDataObject *sOleDataObject = aOleDataObject;
    if (sOleDataObject->IsDataAvailable(mShellIDListClipFormat) == XPR_FALSE)
        return;

    // 3 Operation
    //--------------------------------------------------
    // 1. Insert Bookmark Item
    // 2. Run Program & Bookmark File
    // 3. File Operation

    STGMEDIUM sStgMedium = {0};
    FORMATETC sFormatEtc = {(CLIPFORMAT)mShellIDListClipFormat, XPR_NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
    if (sOleDataObject->GetData(mShellIDListClipFormat, &sStgMedium, &sFormatEtc) == XPR_FALSE)
        return;

    if (mOldBookmark < 0)
    {
        OnDropInsertBookmark(&sStgMedium, mOldInsert);
    }
    else
    {
        xpr_bool_t sFileOperation = XPR_FALSE;

        BookmarkItem *sBookmarkItem = BookmarkMgr::instance().getBookmark(mOldBookmark);
        if (mOldBookmark >= 0 && sBookmarkItem != XPR_NULL)
        {
            LPITEMIDLIST sFullPidl = Path2Pidl(sBookmarkItem->mPath);
            sFileOperation = (sFullPidl != XPR_NULL && IsFileSystemFolder(sFullPidl));
            COM_FREE(sFullPidl);
        }

        if (sFileOperation == XPR_TRUE)
        {
            if (aDropEffect == DROPEFFECT_LINK)
                OnDropShortcut(&sStgMedium, mOldBookmark);
            else
                OnDropFileOperation(&sStgMedium, aDropEffect, mOldBookmark);
        }
        else
        {
            OnDropTarget(sOleDataObject, aDropEffect, aPoint, mOldBookmark);
        }
    }

    if (XPR_IS_NOT_NULL(sStgMedium.pUnkForRelease))
    {
        ::ReleaseStgMedium(&sStgMedium);
    }
}
//********************************************************************************
void CBCGPImageEditDlg::OnBcgToolPaste() 
{
	CBCGPLocalResource locaRes;

	COleDataObject data;
	if (!data.AttachClipboard ())
	{
		AfxMessageBox (IDP_BCGBARRES_CANT_PASTE_BITMAP);
		return;
	}

	if (!data.IsDataAvailable (CF_BITMAP))
	{
		AfxMessageBox (IDP_BCGBARRES_CANT_PASTE_BITMAP);
		return;
	}

	tagSTGMEDIUM dataMedium;
	if (!data.GetData (CF_BITMAP, &dataMedium))
	{
		AfxMessageBox (IDP_BCGBARRES_CANT_PASTE_BITMAP);
		return;
	}

	CBitmap* pBmpClip = CBitmap::FromHandle (dataMedium.hBitmap);
	if (pBmpClip == NULL)
	{
		AfxMessageBox (IDP_BCGBARRES_CANT_PASTE_BITMAP);
		return;
	}

	BITMAP bmp;
	pBmpClip->GetBitmap (&bmp);

	CDC memDCDst;
	CDC memDCSrc;

	memDCSrc.CreateCompatibleDC (NULL);
	memDCDst.CreateCompatibleDC (NULL);
	
	CBitmap* pSrcOldBitmap = memDCSrc.SelectObject (pBmpClip);
	if (pSrcOldBitmap == NULL)
	{
		AfxMessageBox (IDP_BCGBARRES_CANT_PASTE_BITMAP);
		return;
	}

	CBitmap* pDstOldBitmap = memDCDst.SelectObject (m_pBitmap);
	if (pDstOldBitmap == NULL)
	{
		AfxMessageBox (IDP_BCGBARRES_CANT_PASTE_BITMAP);
		
		memDCSrc.SelectObject (pSrcOldBitmap);
		return;
	}

	memDCDst.FillRect (CRect (0, 0, m_sizeImage.cx, m_sizeImage.cy), 
						&globalData.brBtnFace);

	int x = max (0, (m_sizeImage.cx - bmp.bmWidth) / 2);
	int y = max (0, (m_sizeImage.cy - bmp.bmHeight) / 2);

	CBCGPToolBarImages::TransparentBlt (memDCDst.GetSafeHdc (),
		x, y, m_sizeImage.cx, m_sizeImage.cy,
		&memDCSrc, 0, 0, RGB (192, 192, 192));

	memDCDst.SelectObject (pDstOldBitmap);
	memDCSrc.SelectObject (pSrcOldBitmap);

	InvalidateRect (m_rectPreviewImage);
	m_wndLargeDrawArea.Invalidate ();
}
Esempio n. 20
0
////////////////////////////////////////////////////////
//This function loads CF_TEXT data from the clipboard
//or drag/drop into a CStringArray, one line of text
//per array entry. A null in the input text
//denotes a new line.
//
//If pasting from clipboard, pDataObject should be NULL.
//
//You usually call this function from:
//
//1) Your view class's OnDrop() method when a drag-
//   drop operation ends, to load the data for use.
//
//2) Your view (or document) class's OnEditPaste()
//   method when doing a paste from the clipboard.
////////////////////////////////////////////////////////
BOOL CDragDropMgr::GetCFText(
                   CStringArray*   pcsText,
                   COleDataObject* pDataObject)
{
    BOOL bOk = FALSE;

    CString csLine = "";

    COleDataObject* pObj = NULL;

    //If from clipboard, then there is no
    //data object passed in, so use a local copy
    if (pDataObject == NULL)
        pObj = new COleDataObject();

    else
        pObj = pDataObject;

    //Make sure basic data is OK
    if (pObj == NULL)
        return FALSE;

    else if ((pDataObject == NULL &&
              !pObj->AttachClipboard())       ||
              pcsText== NULL                  ||
              !pObj->IsDataAvailable(CF_TEXT))
    {
        pObj->Release();

        if (pDataObject == NULL)
            delete pObj;

        return FALSE;
    }

    //The format etc struct tells how the data
    //should be transferred.
    //Do NOT use the MFC defaults here - they are no good
    FORMATETC fe;

    fe.cfFormat = CF_TEXT;
    fe.tymed    = TYMED_HGLOBAL;
    fe.lindex   = -1;
    fe.dwAspect = DVASPECT_CONTENT;
    fe.ptd      = NULL;

    //Fetch the data from the OLE data object
    HGLOBAL hMem = pObj->GetGlobalData(CF_TEXT,&fe);

    if (hMem != NULL)
    {
        char* pchT = (char*)::GlobalLock(hMem);

        if (pchT != NULL)
        {
            DWORD dwSize = ::GlobalSize(hMem);

            int  i     = 0;
            BOOL bDone = FALSE;

            while (!bDone)
            {
               //Hit a crlf: Add current line
               if (pchT[i+1] == '\n' && pchT[i] == '\r')
               {
                  pcsText->Add(csLine);
                  csLine = "";
                  i += 2;
               }

               //End of the block: Add final line
               else if (pchT[i] == '\0' || i >= DD_MAXCHARS)
               {
                  pcsText->Add(csLine);
                  bDone = TRUE;;
               }

               //Normal character: Add to line being built
               else
               {
                  csLine += pchT[i];
                  i++;
               }
            }

            ::GlobalUnlock(hMem);

            bOk = TRUE;
        }
    }   //hmem not null

    pObj->Release();

    if (pDataObject == NULL)
        delete pObj;

    return bOk;
}
Esempio n. 21
0
void FileScrapDropDlg::OnDrop(COleDataObject *aOleDataObject, DROPEFFECT aDropEffect, CPoint aPoint)
{
    DragImage &sDragImage = DragImage::instance();

    if (sDragImage.isMyDragging() == XPR_TRUE)
    {
        CImageList *sMyDragImage = sDragImage.getMyDragImage();
        if (XPR_IS_NOT_NULL(sMyDragImage))
        {
            sMyDragImage->EndDrag();
            sMyDragImage->DragShowNolock(XPR_FALSE);
        }
    }
    else
    {
        if (mDropTarget.isUseDropHelper() == XPR_TRUE)
        {
            mDropTarget.getDropHelper()->DragLeave();
        }
    }

    COleDataObject *sOleDataObject = aOleDataObject;
    if (sOleDataObject->IsDataAvailable(mShellIDListClipFormat) == XPR_FALSE)
        return;

    xpr_uint_t sGroupId = FileScrap::instance().getCurGroupId();

    if (mDropTarget.isRightDrag() == XPR_TRUE)
    {
        cmd::FileScrapGroupDlg sDlg;
        if (sDlg.DoModal() != IDOK)
            return;

        xpr_uint_t sSelGroupId = sDlg.getSelGroupId();
        if (sSelGroupId != FileScrap::InvalidGroupId)
            sGroupId = sSelGroupId;
    }

    STGMEDIUM sStgMedium = {0};
    FORMATETC sFormatEtc = {mShellIDListClipFormat, XPR_NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
    if (sOleDataObject->GetData(mShellIDListClipFormat, &sStgMedium, &sFormatEtc) == XPR_FALSE)
        return;

    LPIDA sIda = (LPIDA)::GlobalLock(sStgMedium.hGlobal);
    if (XPR_IS_NOT_NULL(sIda))
    {
        xpr_sint_t sCount = sIda->cidl;
        LPCITEMIDLIST sPidl1 = XPR_NULL; // folder PIDL
        LPCITEMIDLIST sPidl2 = XPR_NULL; // item PIDL

        // get folder PIDL
        sPidl1 = (LPITEMIDLIST)(((xpr_byte_t *)sIda)+(sIda)->aoffset[0]);

        LPSHELLFOLDER sShellFolder = XPR_NULL, sShellFolderDesktop = XPR_NULL;
        ::SHGetDesktopFolder(&sShellFolderDesktop);
        HRESULT sHResult = sShellFolderDesktop->BindToObject(sPidl1, XPR_NULL, IID_IShellFolder, (LPVOID *)&sShellFolder);
        if (FAILED(sHResult) || XPR_IS_NULL(sShellFolder))
        {
            sShellFolder = sShellFolderDesktop;
            sShellFolderDesktop = XPR_NULL;
        }

        LPCITEMIDLIST *sPidls = new LPCITEMIDLIST[sCount];

        xpr_sint_t i;
        xpr_sint_t sCount2 = 0;
        for (i = 0; i < sCount; ++i)
        {
            // get item PIDL and get full-qualified PIDL
            sPidl2 = (LPCITEMIDLIST)(((xpr_byte_t *)sIda)+(sIda)->aoffset[i+1]);

            if (IsFileSystem(sShellFolder, sPidl2))
            {
                sPidls[sCount2] = sPidl2;
                sCount2++;
            }
        }

        FileScrap &sFileScrap = FileScrap::instance();

        sFileScrap.addItem(sGroupId, sShellFolder, sPidls, sCount2);

        XPR_SAFE_DELETE_ARRAY(sPidls);

        COM_RELEASE(sShellFolder);
        COM_RELEASE(sShellFolderDesktop);
        ::GlobalUnlock(sStgMedium.hGlobal);
    }

    if (XPR_IS_NOT_NULL(sStgMedium.pUnkForRelease))
    {
        ::ReleaseStgMedium(&sStgMedium);
    }
}
Esempio n. 22
0
void CDataView::OnUpdateEditPaste(CCmdUI* pCmdUI) 
{
    // Attach a COleDataObject to the clipboard see if there is any data
    COleDataObject obj;
    pCmdUI->Enable(obj.AttachClipboard() && obj.IsDataAvailable(CF_TEXT)); 
}