/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
if (pStream)
{ // We have a stream, read from it.
STATSTG aStat;
HRESULT hr = pStream->Stat(&aStat, STATFLAG_NONAME); if (FAILED(hr))
{
SAL_WARN("vcl.win.dtrans", "clipDataToByteStream: Stat() failed"); return;
}
try
{
clipDataStream = getClipboardData( fetc );
} catch( UnsupportedFlavorException& )
{ if ( CDataFormatTranslator::isUnicodeTextFormat( fetc.getClipformat( ) ) &&
m_bUnicodeRegistered )
{
OUString aUnicodeText = synthesizeUnicodeText( );
Any aAny( aUnicodeText ); return aAny;
} // #i124085# CF_DIBV5 should not be possible, but keep for reading from the // clipboard for being on the safe side elseif(CF_DIBV5 == fetc.getClipformat())
{ // #i123407# CF_DIBV5 has priority; if the try to fetch this failed, // check CF_DIB availability as an alternative
fetc.setClipformat(CF_DIB);
clipDataStream = getClipboardData( fetc ); // pass UnsupportedFlavorException out, tried all possibilities
} else throw; // pass through exception
}
for (DataFlavor const& df : m_FlavorList) if ( compareDataFlavors( aFlavor, df ) ) returntrue;
returnfalse;
}
// the list of dataflavors currently on the clipboard will be initialized // only once; if the client of this Transferable will hold a reference // to it and the underlying clipboard content changes, the client does // possible operate on an invalid list // if there is only text on the clipboard we will also offer unicode text // an synthesize this format on the fly if requested, to accomplish this // we save the first offered text format which we will later use for the // conversion
void CDOTransferable::initFlavorListFromFormatList(const std::vector<sal_uInt32>& rFormats)
{ for (sal_uInt32 cfFormat : rFormats)
{ // we use locales only to determine the // charset if there is text on the clipboard // we don't offer this format if (CF_LOCALE == cfFormat) continue;
// if text or oemtext is offered we pretend to have unicode text if (CDataFormatTranslator::isTextFormat(cfFormat))
{ if (!m_bUnicodeRegistered)
{
m_TxtFormatOnClipboard = cfFormat;
m_bUnicodeRegistered = true;
// register unicode text as format
addSupportedFlavor(formatEtcToDataFlavor(CF_UNICODETEXT));
}
} else
addSupportedFlavor(formatEtcToDataFlavor(cfFormat));
}
}
inline void CDOTransferable::addSupportedFlavor( const DataFlavor& aFlavor )
{ // we ignore all formats that couldn't be translated if ( aFlavor.MimeType.getLength( ) )
{
OSL_ASSERT( isValidFlavor( aFlavor ) );
// because of a Win95/98 Bug; there the high word // of a locale has the same value as the // low word e.g. 0x07040704 that's not right // correct is 0x00000704
lcid &= 0x0000FFFF;
} catch(...)
{ // we take the default locale
}
return lcid;
}
void CDOTransferable::tryToGetIDataObjectIfAbsent()
{ if (!m_rDataObject.is())
{ auto xClipboard = m_xClipboard.get(); // holding the reference while we get the object if (CWinClipboard* pWinClipboard = dynamic_cast<CWinClipboard*>(xClipboard.get()))
{
m_rDataObject = pWinClipboard->getIDataObject();
}
}
}
// I think it's not necessary to call ReleaseStgMedium // in case of failures because nothing should have been // allocated etc.
CDOTransferable::ByteSequence_t CDOTransferable::getClipboardData( CFormatEtc& aFormatEtc )
{
STGMEDIUM stgmedium;
tryToGetIDataObjectIfAbsent(); if (!m_rDataObject.is()) // Maybe we are shutting down, and clipboard is already destroyed? throw RuntimeException();
HRESULT hr = m_rDataObject->GetData( aFormatEtc, &stgmedium );
// in case of failure to get a WMF metafile handle, try to get a memory block if( FAILED( hr ) &&
( CF_METAFILEPICT == aFormatEtc.getClipformat() ) &&
( TYMED_MFPICT == aFormatEtc.getTymed() ) )
{
CFormatEtc aTempFormat( aFormatEtc );
aTempFormat.setTymed( TYMED_HGLOBAL );
hr = m_rDataObject->GetData( aTempFormat, &stgmedium );
}
if (FAILED(hr) && aFormatEtc.getTymed() == TYMED_HGLOBAL)
{ // Handle type is not memory, try stream.
CFormatEtc aTempFormat(aFormatEtc);
aTempFormat.setTymed(TYMED_ISTREAM);
hr = m_rDataObject->GetData(aTempFormat, &stgmedium);
}
// format conversion if necessary // #i124085# DIBV5 should not happen currently, but keep as a hint here if(CF_DIBV5 == aFormatEtc.getClipformat() || CF_DIB == aFormatEtc.getClipformat())
{
byteStream = WinDIBToOOBMP(byteStream);
} elseif(CF_METAFILEPICT == aFormatEtc.getClipformat())
{
byteStream = WinMFPictToOOMFPict(byteStream);
}
}
// determine the codepage used for text conversion
cpForTxtCnvt = getWinCPFromLocaleId( lcid, LOCALE_IDEFAULTANSICODEPAGE ).toInt32( );
} elseif ( CF_OEMTEXT == m_TxtFormatOnClipboard )
{
fetc = CDataFormatTranslator::getFormatEtcForClipformat( CF_OEMTEXT );
aTextSequence = getClipboardData( fetc );
// determine the codepage used for text conversion
cpForTxtCnvt = getWinCPFromLocaleId( lcid, LOCALE_IDEFAULTCODEPAGE ).toInt32( );
} else
OSL_ASSERT( false );
CStgTransferHelper stgTransferHelper;
// convert the text
MultiByteToWideCharEx( cpForTxtCnvt, reinterpret_cast<char*>( aTextSequence.getArray( ) ),
-1,
stgTransferHelper, false);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.