Esempio n. 1
0
BOOL COlePasteSpecialDialog::CreateItem(COleClientItem *pNewItem)
{
	ASSERT_VALID(this);
	ASSERT(pNewItem != NULL);
	ASSERT(m_ps.lpSrcDataObj != NULL);

	CWaitCursor wait;

	COleDataObject dataObject;
	dataObject.Attach(m_ps.lpSrcDataObj, FALSE);

	UINT selType = GetSelectionType();
	BOOL bResult = TRUE;

	switch (selType)
	{
	case pasteLink:
		// paste link
		if (!pNewItem->CreateLinkFromData(&dataObject))
		{
			TRACE0("Warning: CreateLinkFromData failed.\n");
			bResult = FALSE;
		}
		break;
	case pasteStatic:
		if (!pNewItem->CreateStaticFromData(&dataObject))
		{
			TRACE0("Warning: CreateStaticFromData failed.\n");
			bResult = FALSE;
		}
		break;
	default:
		ASSERT(selType == pasteNormal);
		if (!pNewItem->CreateFromData(&dataObject))
		{
			TRACE0("Warning: CreateFromData failed.\n");
			bResult = FALSE;
		}
		break;
	}

	// deal with Display As Iconic option
	if (bResult && GetDrawAspect() == DVASPECT_ICON)
	{
		// setup iconic cache (it will draw iconic by default as well)
		if (!pNewItem->SetIconicMetafile(m_ps.hMetaPict))
		{
			TRACE0("Warning: failed to set iconic aspect.\n");
			bResult = FALSE;
		}
		else
		{
			// since picture was set OK, draw as iconic as well...
			pNewItem->SetDrawAspect(DVASPECT_ICON);
		}
	}
	return bResult;
}
Esempio n. 2
0
//-------------------------------------------------------------------//
// Paste()																				//
//-------------------------------------------------------------------//
void OleListCtrl::Paste( 
	PASTEMODE ePasteMode 
) {
	COleDataObject DataObject;

	if ( DataObject.AttachClipboard() )
	{
		// Unarchive the data into the DragData array.
		ExtractDropData( 
			&DataObject
		);

		// This allows us to manipulate the drag data 
		// before we add it as new list items.
		ProcessNewDragData( 
			DROPEFFECT_MOVE	// dropEffect
		);

		// PASTE_REPLACE_ALL, PASTE_TOP default.
		int nUnderCursor = 0;

		switch( ePasteMode )
		{
			case PASTE_BOTTOM:
				nUnderCursor = GetItemCount();
				break;
			case PASTE_REPLACE_ALL:
				DeleteAllItems();
				break;
			case PASTE_AT_SELECTION:
				nUnderCursor = GetNextItem( -1, LVNI_FOCUSED );
				if ( nUnderCursor == -1 )
					nUnderCursor = GetItemCount();
				break;
			default:
				break;
		}

		if (
			AddItemsFromDragData( 
				nUnderCursor,
				false				// bInsertAfter
			)
		) {
			// If we added anything we need to redraw.  This may also
			// e.g. update the caption and icon and mark the list "dirty"
			// in derived classes.
			UpdateAfterDrop( nUnderCursor, true );
		}
		
		// Clear the drag contents, now that we have added them.
		// Don't worry, the clipboard hasn't changed, in case we
		// wanted to add the items again!  :>
		Items.RemoveAll();

	}
}
Esempio n. 3
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. 4
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. 5
0
//-------------------------------------------------------------------//
// OnUpdatePaste()																	//
//-------------------------------------------------------------------//
// Disable paste if nothing's available.
// Nice of MultiColumnSortListCtrl::DisplayRightClickMenu() to
// force checks for ON_UPDATE_COMMAND_UI's.
//-------------------------------------------------------------------//
void OleListCtrl::OnUpdatePaste(CCmdUI* pCmdUI) 
{
	bool bHaveData = false;

	COleDataObject DataObject;
	if ( DataObject.AttachClipboard() )
	{
		// Do we have OLE data in the DragData array?
		bHaveData = bHaveValidDropData( &DataObject );
	}

	pCmdUI->Enable( bHaveData );
}
Esempio n. 6
0
void CEx27bView::OnEditPaste() 
{
	CEx27bDoc* pDoc = GetDocument();
	COleDataObject dataObject;
	VERIFY(dataObject.AttachClipboard());
	pDoc->DeleteContents();
	DoPasteObjectDescriptor(&dataObject);
	DoPasteObject(&dataObject);
	SetViewAdvise();
	GetSize();
	pDoc->SetModifiedFlag();
	pDoc->UpdateAllViews(NULL);
}
Esempio n. 7
0
STDMETHODIMP CBmpCtxMenuExt::Initialize (
                               LPCITEMIDLIST pidlFolder,
                               LPDATAOBJECT  pDO,
                               HKEY          hkeyProgID )
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

COleDataObject dataobj;
HGLOBAL        hglobal;
HDROP          hdrop;
bool           bOK = false;

    dataobj.Attach ( pDO, FALSE );      // FALSE = don't release IDataObject interface when destroyed

    // Get the first selected file name.  I'll keep this simple and just check
    // the first name to see if it's a .BMP.

    hglobal = dataobj.GetGlobalData ( CF_HDROP );

    if ( NULL == hglobal )
        return E_INVALIDARG;

    hdrop = (HDROP) GlobalLock ( hglobal );

    if ( NULL == hdrop )
        return E_INVALIDARG;

    // Get the name of the first selected file.

    if ( DragQueryFile ( hdrop, 0, m_szFile, MAX_PATH ))
        {
        // Is its extension .BMP?
        if ( PathMatchSpec ( m_szFile, _T("*.bmp") ))
            {
            // Load the bitmap and attach our CBitmap object to it.
            HBITMAP hbm = (HBITMAP) LoadImage ( NULL, m_szFile, IMAGE_BITMAP, 0, 0, 
                                                LR_LOADFROMFILE );

            if ( NULL != hbm )
                {
                // We loaded the bitmap, so attach the CBitmap to it.
                VERIFY( m_bmp.Attach ( hbm ) );
                bOK = true;
                }
            }
        }

    GlobalUnlock ( hglobal );

    return bOK ? S_OK : E_FAIL;
}
Esempio n. 8
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. 9
0
HRESULT CMainFrameDropTarget::PasteText(CLIPFORMAT cfData, COleDataObject& data)
{
    HRESULT hrPasteResult = E_FAIL;
    HANDLE hMem;
    if ((hMem = data.GetGlobalData(cfData)) != NULL)
    {
        LPCSTR pszUrlA;
        if ((pszUrlA = (LPCSTR)GlobalLock(hMem)) != NULL)
        {
            // skip white space
            while (isspace((unsigned char)*pszUrlA))
                pszUrlA++;

            hrPasteResult = S_FALSE; // default: nothing was pasted
            if (_strnicmp(pszUrlA, "ed2k://|", 8) == 0)
            {
                CString strData(pszUrlA);
                int iPos = 0;
                CString str = strData.Tokenize(_T("\r\n"), iPos);
                while (!str.IsEmpty())
                {
                    theApp.emuledlg->ProcessED2KLink(str);
                    hrPasteResult = S_OK;
                    str = strData.Tokenize(_T("\r\n"), iPos);
                }
            }

            GlobalUnlock(hMem);
        }
        GlobalFree(hMem);
    }
    return hrPasteResult;
}
Esempio n. 10
0
void CDrawView::PasteNative(COleDataObject& dataObject)
{
	// get file refering to clipboard data
	CFile* pFile = dataObject.GetFileData(m_cfDraw);
	if (pFile == NULL)
		return;

	// connect the file to the archive
	CArchive ar(pFile, CArchive::load);
	TRY
	{
		ar.m_pDocument = GetDocument(); // set back-pointer in archive

		// read the selection
		m_selection.Serialize(ar);
	}
	CATCH_ALL(e)
	{
		ar.Close();
		delete pFile;
		THROW_LAST();
	}
	END_CATCH_ALL

	ar.Close();
	delete pFile;
}
Esempio n. 11
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. 12
0
void COXMulticlipboardDlg::ClipToPocket(COXClipPocket *pPocket)
{
	//the function opens clipboard and
	//calls virtual ClipObjectToPocket()
	//to make copy of the clipboard data
	ASSERT(pPocket);

	COleDataObject clipobj;

	if (!clipobj.AttachClipboard())
	{
		TRACE0("CMulticlipboardDlg::ClipToPocket : Failed to attach to clipboard\r\n");
		return;
	}

	ClipObjectToPocket(pPocket, &clipobj);
}
Esempio n. 13
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. 14
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. 15
0
File: SITE.CPP Progetto: 0anion0/IBN
STDMETHODIMP CSite::Drop(IDataObject * pDataObject,DWORD grfKeyState, POINTL pt,DWORD * pdwEffect)
{
    COleDataObject	pData;
    pData.Attach(pDataObject,FALSE);

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

    STGMEDIUM outData =	{0};

    if(pData.GetData(CF_TEXT,&outData,&stFormatTEXT))
    {
        _bstr_t strText = (LPCTSTR)GlobalLock(outData.hGlobal);

        m_pFR->InsertTEXT(strText);

        GlobalUnlock(outData.hGlobal);
    }

    return S_OK;
}
Esempio n. 16
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. 17
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. 18
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. 19
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. 20
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. 21
0
///////////////////////////////////////////////////
// Verify that data you can handle is on the clipboard
// or in the drop buffer data object.
//
// If checking the clipboard, set pDataObject to NULL.
///////////////////////////////////////////////////
CString CDragDropMgr::AvailableDataType(COleDataObject* pDataObject)
{
    COleDataObject obj;

    //Assume caller is checking the clipboard
    //because no OLE data object was passed in
    if (pDataObject == NULL)
    {
        pDataObject = &obj;

        if (!obj.AttachClipboard())
            return "";
    }
    
    CString csFormat = "";
    
    for (int i=0;i < m_nFormats.GetSize() && csFormat.IsEmpty();i++)
    {
        if (pDataObject->IsDataAvailable(m_nFormats.GetAt(i)))
            csFormat = m_csFormats.GetAt(i);
    }

    return csFormat;
}
Esempio n. 22
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. 23
0
//IDropTarget
	STDMETHODIMP CDropT::DragEnter(IDataObject* pDataObj, DWORD grfKeyState,
														 POINTL pt, DWORD* pdwEffect)
	{
		COleDataObject dataObj;
		HGLOBAL global = NULL;
		HDROP dropFile = NULL;

		dataObj.Attach(pDataObj, FALSE);
		if(global = dataObj.GetGlobalData(CF_HDROP))
		{
			UINT numDropFile = 0;
			wchar_t buff[MAX_PATH] = {0};
			dropFile = static_cast<HDROP>(GlobalLock(global));
			numDropFile = DragQueryFile(dropFile, 0xFFFFFFFF, buff, MAX_PATH);
			for(UINT i = 0; i != numDropFile; ++i)
			{
				if(DragQueryFile(dropFile, i, buff, MAX_PATH))
				{
					m_lsDroppedFiles.push_back(buff);
				}
			}
			GlobalUnlock(global);
		}

		dataObj.Detach();

		if(!m_lsDroppedFiles.empty())
		{
			*pdwEffect = DROPEFFECT_COPY;
		}
		else
		{
			*pdwEffect = DROPEFFECT_NONE;
		}
		return S_OK;	
	}
Esempio n. 24
0
HRESULT CMainFrameDropTarget::PasteHDROP(COleDataObject &data)
{
	HRESULT hrPasteResult = E_FAIL;
	HANDLE hMem;
	if ((hMem = data.GetGlobalData(CF_HDROP)) != NULL)
	{
		LPDROPFILES lpDrop;
		if ((lpDrop = (LPDROPFILES)GlobalLock(hMem)) != NULL)
		{
			if (lpDrop->fWide)
			{
				LPCWSTR pszFileNameW = (LPCWSTR)((LPBYTE)lpDrop + lpDrop->pFiles);
				while (*pszFileNameW != L'\0')
				{
					USES_CONVERSION;
					if (FAILED(AddUrlFileContents(W2CT(pszFileNameW))))
						break;
					hrPasteResult = S_OK;
					pszFileNameW += wcslen(pszFileNameW) + 1;
				}
			}
			else
			{
				LPCSTR pszFileNameA = (LPCSTR)((LPBYTE)lpDrop + lpDrop->pFiles);
				while (*pszFileNameA != '\0')
				{
					USES_CONVERSION;
					if (FAILED(AddUrlFileContents(A2CT(pszFileNameA))))
						break;
					hrPasteResult = S_OK;
					pszFileNameA += strlen(pszFileNameA) + 1;
				}
			}
			GlobalUnlock(hMem);
		}
		GlobalFree(hMem);
	}
	return hrPasteResult;
}
Esempio n. 25
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. 26
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. 27
0
HRESULT CMainFrameDropTarget::PasteHTML(COleDataObject& data)
{
    HRESULT hrPasteResult = E_FAIL;
    HGLOBAL hMem;
    if ((hMem = data.GetGlobalData(m_cfHTML)) != NULL)
    {
        LPCSTR pszClipboard;
        if ((pszClipboard = (LPCSTR)GlobalLock(hMem)) != NULL)
        {
            hrPasteResult = S_FALSE; // default: nothing was pasted
            LPCSTR pszHTML = strchr(pszClipboard, '<');
            if (pszHTML != NULL)
            {
                CComBSTR bstrHTMLText((LPCOLESTR)CA2W(pszHTML));
                PASTEURLDATA Paste(bstrHTMLText);
                hrPasteResult = PasteHTML(&Paste);
            }
            GlobalUnlock(hMem);
        }
        GlobalFree(hMem);
    }
    return hrPasteResult;
}
Esempio n. 28
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. 29
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. 30
0
void CMyStatic::OnEditPaste()
{
	COleDataObject DataObj;
	if (DataObj.AttachClipboard())
		PutOleData(&DataObj, GetDropType(&DataObj));
}