20#include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
21#include <com/sun/star/embed/Aspects.hpp>
22#include <com/sun/star/embed/MSOLEObjectSystemCreator.hpp>
44#include <osl/thread.h>
54#include <viewfunc.hxx>
56#include <drawview.hxx>
65#include <compiler.hxx>
79 const uno::Reference<datatransfer::XTransferable>& rxTransferable,
80 SCCOL nPosX,
SCROW nPosY,
const Point* pLogicPos,
bool bLink,
bool bAllowDialogs )
92 nFormatId == SotClipboardFormatId::RTF );
114 if ( nFormatId == SotClipboardFormatId::EMBED_SOURCE ||
115 nFormatId == SotClipboardFormatId::LINK_SOURCE ||
116 nFormatId == SotClipboardFormatId::EMBED_SOURCE_OLE ||
117 nFormatId == SotClipboardFormatId::LINK_SOURCE_OLE ||
118 nFormatId == SotClipboardFormatId::EMBEDDED_OBJ_OLE )
120 uno::Reference < io::XInputStream > xStm;
139 if (xDocShRef->DoLoad(pMedium))
141 ScDocument& rSrcDoc = xDocShRef->GetDocument();
150 SCCOL nFirstCol, nLastCol;
151 SCROW nFirstRow, nLastRow;
152 if ( rSrcDoc.
GetDataStart( nSrcTab, nFirstCol, nFirstRow ) )
154 rSrcDoc.
GetCellArea( nSrcTab, nLastCol, nLastRow );
155 if (nLastCol < nFirstCol)
156 nLastCol = nFirstCol;
157 if (nLastRow < nFirstRow)
158 nLastRow = nFirstRow;
162 nFirstCol = nLastCol = 0;
163 nFirstRow = nLastRow = 0;
166 bool bIncludeObjects =
false;
168 if (nFormatId == SotClipboardFormatId::EMBED_SOURCE)
171 SCCOL nPrintEndCol = nFirstCol;
172 SCROW nPrintEndRow = nFirstRow;
173 bool bHasObjects = pDraw && pDraw->
HasObjects();
175 if (bHasObjects && rSrcDoc.
GetPrintArea(nSrcTab, nPrintEndCol, nPrintEndRow,
true))
177 nLastCol = std::max<SCCOL>(nLastCol, nPrintEndCol);
178 nLastRow = std::max<SCROW>(nLastRow, nPrintEndRow);
181 bIncludeObjects = bHasObjects;
184 ScClipParam aClipParam(
ScRange(nFirstCol, nFirstRow, nSrcTab, nLastCol, nLastRow, nSrcTab),
false);
185 rSrcDoc.
CopyToClip(aClipParam, pClipDoc.get(), &aSrcMark,
false, bIncludeObjects);
196 xDocShRef->DoClose();
203 GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm,
aName );
212 if (aDataHelper.
GetGDIMetaFile(SotClipboardFormatId::GDIMETAFILE, aMetafile, 100000))
214 nGrFormat = SotClipboardFormatId::GDIMETAFILE;
215 aGraphic = aMetafile;
219 if ( nGrFormat != SotClipboardFormatId::NONE )
221 datatransfer::DataFlavor aDataFlavor;
232 OSL_FAIL(
"Error in CreateAndLoad");
241 uno::Reference < embed::XEmbeddedObject > xObj;
242 xStm = aDataHelper.
GetInputStream(SotClipboardFormatId::EMBED_SOURCE_OLE, OUString());
244 aDataHelper.
GetInputStream(SotClipboardFormatId::EMBEDDED_OBJ_OLE, OUString());
255 uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator =
256 embed::MSOLEObjectSystemCreator::create( ::comphelper::getProcessComponentContext() );
258 embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
261 uno::Sequence< beans::PropertyValue >() );
269 catch( uno::Exception& )
281 if( aDataHelper.
GetGraphic( SotClipboardFormatId::SVXB, aGraphic ) )
282 nGrFormat = SotClipboardFormatId::SVXB;
283 else if( aDataHelper.
GetGraphic( SotClipboardFormatId::GDIMETAFILE, aGraphic ) )
284 nGrFormat = SotClipboardFormatId::GDIMETAFILE;
285 else if( aDataHelper.
GetGraphic( SotClipboardFormatId::BITMAP, aGraphic ) )
286 nGrFormat = SotClipboardFormatId::BITMAP;
290 if ( nGrFormat != SotClipboardFormatId::NONE )
292 datatransfer::DataFlavor aDataFlavor;
305 OSL_FAIL(
"Error creating external OLE object");
311 else if ( nFormatId == SotClipboardFormatId::LINK )
316 nFormatId == SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT )
318 if ( nFormatId == SotClipboardFormatId::RTF && ( aDataHelper.
HasFormat( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT ) ) )
321 PasteRTF( nPosX, nPosY, rxTransferable );
327 auto pObj = std::make_shared<ScImportExport>(
GetViewData().GetDocument(), aCellPos);
328 pObj->SetOverwriting(
true );
331 auto pStrBuffer = std::make_shared<OUString>();
337 static bool bHaveSavedPreferences =
false;
339 static bool bSavedDateConversion;
340 static bool bSavedScientificConversion;
342 if (nFormatId == SotClipboardFormatId::HTML &&
345 if (bHaveSavedPreferences)
351 pObj->SetExtOptions(aOptions);
363 if (pDlg->Execute() ==
RET_OK)
369 if (!pDlg->IsKeepAskingSet())
371 bHaveSavedPreferences =
true;
372 eSavedLanguage = pDlg->GetLanguageType();
373 bSavedDateConversion = pDlg->IsDateConversionSet();
374 bSavedScientificConversion = pDlg->IsScientificConversionSet();
376 pObj->SetExtOptions(aOptions);
386 bRet = pObj->ImportStream( *
xStream, OUString(), nFormatId );
389 else if ((nFormatId == SotClipboardFormatId::STRING || nFormatId == SotClipboardFormatId::STRING_TSVC)
390 && aDataHelper.
GetString( nFormatId, *pStrBuffer ))
394 sal_Int32 nDelim = pStrBuffer->indexOf(
'\n');
396 && nDelim >= 0 && nDelim != pStrBuffer->getLength () - 1)
400 auto pStrm = std::make_shared<ScImportStringStream>(*pStrBuffer);
406 bAllowDialogs = bAllowDialogs && !
SC_MOD()->IsInExecuteDrop();
408 pDlg->StartExecuteAsync([
this, pDlg, &rDoc, pStrm, nFormatId, pStrBuffer, pObj, bAllowDialogs](sal_Int32 nResult){
409 bool bShowErrorDialog = bAllowDialogs;
413 pDlg->GetOptions( aOptions );
414 pDlg->SaveParameters();
415 pObj->SetExtOptions( aOptions );
416 pObj->ImportString( *pStrBuffer, nFormatId );
421 bShowErrorDialog = bShowErrorDialog && pObj->IsOverflow();
425 bShowErrorDialog =
false;
435 if (bShowErrorDialog)
442 bRet = pObj->ImportString( *pStrBuffer, nFormatId );
444 else if ((nFormatId != SotClipboardFormatId::STRING && nFormatId != SotClipboardFormatId::STRING_TSVC)
445 && aDataHelper.
GetString( nFormatId, *pStrBuffer ))
446 bRet = pObj->ImportString( *pStrBuffer, nFormatId );
452 else if (nFormatId == SotClipboardFormatId::SBA_DATAEXCHANGE)
485 bool bAreaIsNew = !pDBData;
490 rDisp.
ExecuteList(SID_SBA_IMPORT, SfxCallMode::ASYNCHRON,
491 { &aDataDesc, &aTarget, &aAreaNew });
496 else if (nFormatId == SotClipboardFormatId::SBA_FIELDDATAEXCHANGE)
507 Point aInsPos = aPos;
511 if ( aInsPos.
X() < 0 ) aInsPos.
setX( 0 );
512 if ( aInsPos.
Y() < 0 ) aInsPos.
setY( 0 );
514 pObj->SetLogicRect(aRect);
516 if (
dynamic_cast<const SdrUnoObj*
>( pObj.get() ) !=
nullptr )
520 if (
dynamic_cast<const SdrObjGroup*
>( pObj.get() ) !=
nullptr)
526 if (
dynamic_cast<const SdrUnoObj*
>( pSubObj) !=
nullptr )
530 pSubObj = aIter.
Next();
541 else if (nFormatId == SotClipboardFormatId::BITMAP || nFormatId == SotClipboardFormatId::PNG || nFormatId == SotClipboardFormatId::JPEG)
544 if( aDataHelper.
GetBitmapEx( SotClipboardFormatId::BITMAP, aBmpEx ) )
547 else if (nFormatId == SotClipboardFormatId::GDIMETAFILE)
550 if( aDataHelper.
GetGDIMetaFile( SotClipboardFormatId::GDIMETAFILE, aMtf ) )
553 else if (nFormatId == SotClipboardFormatId::SVXB)
564 else if ( nFormatId == SotClipboardFormatId::DRAWING )
572 aDragShellRef->MakeDrawLayer();
573 aDragShellRef->DoInitNew();
575 ScDrawLayer* pModel = aDragShellRef->GetDocument().GetDrawLayer();
583 size_t nObjCount = 0;
585 for (sal_uInt16
i=0;
i<nPages;
i++)
602 PasteDraw(aPos, pModel, (nObjCount > 1),
u"A",
u"B");
603 aDragShellRef->DoClose();
607 else if ( (nFormatId == SotClipboardFormatId::BIFF_5) || (nFormatId == SotClipboardFormatId::BIFF_8) )
611 uno::Reference <io::XInputStream> xStm = aDataHelper.
GetInputStream(nFormatId, OUString());
637 OSL_FAIL(
"no dimension");
638 SCCOL nFirstCol, nLastCol;
639 SCROW nFirstRow, nLastRow;
640 if ( aInsDoc.
GetDataStart( nSrcTab, nFirstCol, nFirstRow ) )
641 aInsDoc.
GetCellArea( nSrcTab, nLastCol, nLastRow );
644 nFirstCol = nLastCol = 0;
645 nFirstRow = nLastRow = 0;
647 aSource =
ScRange( nFirstCol, nFirstRow, nSrcTab,
648 nLastCol, nLastRow, nSrcTab );
666 else if ( nFormatId == SotClipboardFormatId::SIMPLE_FILE )
669 if ( aDataHelper.
GetString( nFormatId, aFile ) )
672 else if ( nFormatId == SotClipboardFormatId::FILE_LIST )
675 if ( aDataHelper.
GetFileList( nFormatId, aFileList ) )
680 OUString aFile = aFileList.
GetFile(
i );
690 else if ( nFormatId == SotClipboardFormatId::SOLK ||
691 nFormatId == SotClipboardFormatId::UNIFORMRESOURCELOCATOR ||
692 nFormatId == SotClipboardFormatId::NETSCAPE_BOOKMARK ||
693 nFormatId == SotClipboardFormatId::FILEGRPDESCRIPTOR )
695 bRet =
PasteBookmark( nFormatId, rxTransferable, nPosX, nPosY );
710 uno::Sequence<sal_Int8> aSequence = aDataHelper.
GetSequence(SotClipboardFormatId::LINK, OUString());
711 if (!aSequence.hasElements())
713 OSL_FAIL(
"DDE Data not found.");
719 sal_uInt16 nCols = 1;
720 sal_uInt16 nRows = 1;
721 if ( aDataHelper.
HasFormat( SotClipboardFormatId::STRING ) )
724 if ( aDataHelper.
GetString( SotClipboardFormatId::STRING, aDataStr ) )
729 sal_Int32 nLen = aDataStr.getLength();
730 if (nLen && aDataStr[nLen-1] ==
'\n')
731 aDataStr = aDataStr.copy(0, nLen-1);
733 if (!aDataStr.isEmpty())
745 sal_Int32 nSeqLen = aSequence.getLength();
746 const char*
p =
reinterpret_cast<const char*
>(aSequence.getConstArray());
748 rtl_TextEncoding eSysEnc = osl_getThreadTextEncoding();
752 ::std::vector<OUString> aStrs;
753 const char* pStart =
p;
754 sal_Int32 nStart = 0;
755 for (sal_Int32
i = 0;
i < nSeqLen; ++
i, ++
p)
759 sal_Int32 nLen =
i - nStart;
760 aStrs.emplace_back(pStart, nLen, eSysEnc);
766 if (aStrs.size() < 3)
769 const OUString& pApp = aStrs[0];
770 const OUString& pTopic = aStrs[1];
771 const OUString& pItem = aStrs[2];
772 const OUString* pExtra =
nullptr;
773 if (aStrs.size() > 3)
776 if ( pExtra && *pExtra ==
"calc:extref" )
796 +
"\"" + pTopic +
"\""
798 +
"\"" + pItem +
"\""
PropertiesInfo aProperties
OUString GetFile(size_t nIndex) const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long X() const
virtual VclPtr< AbstractScTextImportOptionsDlg > CreateScTextImportOptionsDlg(weld::Window *pParent)=0
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
virtual VclPtr< AbstractScImportAsciiDlg > CreateScImportAsciiDlg(weld::Window *pParent, const OUString &aDatName, SvStream *pInStream, ScImportAsciiCall eCall)=0
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
void SetLanguage(LanguageType e)
void SetDetectScientificNumber(bool bSet)
void SetDetectSpecialNumber(bool bSet)
const OUString & GetName() const
ScDBData * GetDBData(const ScRange &rMarked, ScGetDBMode eMode, ScGetDBSelection eSel)
ScSheetLimits & GetSheetLimits() const
SCTAB GetVisibleTab() const
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
void SetClipArea(const ScRange &rArea, bool bCut=false)
SC_DLLPUBLIC void CopyToClip(const ScClipParam &rClipParam, ScDocument *pClipDoc, const ScMarkData *pMarks, bool bKeepScenarioFlags, bool bIncludeObjects)
ScExtDocOptions * GetExtDocOptions()
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
SC_DLLPUBLIC void ResetClip(ScDocument *pSourceDoc, const ScMarkData *pMarks)
SC_DLLPUBLIC bool GetCellArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow) const
SC_DLLPUBLIC bool GetPrintArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow, bool bNotes=true) const
void SetPastingDrawFromOtherDoc(bool bVal)
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
SC_DLLPUBLIC bool GetDataStart(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow) const
bool InsertObjectSafe(SdrObject *pObj, SdrPageView &rPV)
Extended options held by an ScDocument containing additional settings for filters.
const ScExtTabSettings * GetTabSettings(SCTAB nTab) const
static SC_DLLPUBLIC OUString GetAbsDocName(const OUString &rFileName, const SfxObjectShell *pShell)
static void SetClipDocName(const OUString &rNew)
static bool IsFormatSupported(SotClipboardFormatId nFormat)
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
void SelectOneTable(SCTAB nTab)
void SetDrawShell(bool bActive)
void InitBlockMode(SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, bool bTestNeg=false, bool bCols=false, bool bRows=false, bool bForceNeg=false)
void DoneBlockMode(bool bContinue=false)
void ErrorMessage(TranslateId pGlobStrId)
void MarkCursor(SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, bool bCols=false, bool bRows=false, bool bCellSelection=false)
SC_DLLPUBLIC void MoveCursorAbs(SCCOL nCurX, SCROW nCurY, ScFollowMode eMode, bool bShift, bool bControl, bool bKeepOld=false, bool bKeepSel=false)
ScViewData & GetViewData()
ScGridWindow * GetActiveWin()
SC_DLLPUBLIC void SetCursor(SCCOL nPosX, SCROW nPosY, bool bNew=false)
void ClickCursor(SCCOL nPosX, SCROW nPosY, bool bControl)
ScDrawView * GetScDrawView()
SfxDispatcher & GetDispatcher()
ScDocument & GetDocument() const
void UpdateInputHandler(bool bForce=false)
ScDocShell * GetDocShell() const
ScTabViewShell * GetViewShell() const
bool PasteGraphic(const Point &rPos, const Graphic &rGraphic, const OUString &rFile)
bool PasteBookmark(SotClipboardFormatId nFormatId, const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable, SCCOL nPosX, SCROW nPosY)
bool PasteLink(const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable)
void PasteRTF(SCCOL nCol, SCROW nStartRow, const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable)
bool PasteDataFormat(SotClipboardFormatId nFormatId, const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable, SCCOL nPosX, SCROW nPosY, const Point *pLogicPos, bool bLink=false, bool bAllowDialogs=false)
void EnterMatrix(const OUString &rString, ::formula::FormulaGrammar::Grammar eGram)
bool PasteMetaFile(const Point &, const GDIMetaFile &)
SC_DLLPUBLIC bool PasteFromClip(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction=ScPasteFunc::NONE, bool bSkipEmptyCells=false, bool bTranspose=false, bool bAsLink=false, InsCellCmd eMoveMode=INS_NONE, InsertDeleteFlags nUndoExtraFlags=InsertDeleteFlags::NONE, bool bAllowDialogs=false)
bool PasteBitmapEx(const Point &, const BitmapEx &)
bool PasteObject(const Point &, const css::uno::Reference< css::embed::XEmbeddedObject > &, const Size *, const Graphic *=nullptr, const OUString &=OUString(), sal_Int64 nAspect=css::embed::Aspects::MSOLE_CONTENT)
bool PasteFile(const Point &, const OUString &, bool bLink)
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
size_t GetObjCount() const
virtual void NbcSetLayer(SdrLayerID nLayer)
SdrPageView * GetSdrPageView() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemSet & GetItemSet() const
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
bool isLOKMobilePhone() const
virtual SfxObjectShell * GetObjectShell() override
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
css::uno::Sequence< sal_Int8 > GetSequence(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool GetTransferableObjectDescriptor(SotClipboardFormatId nFormat, TransferableObjectDescriptor &rDesc)
bool GetString(SotClipboardFormatId nFormat, OUString &rStr) const
const DataFlavorExVector & GetDataFlavorExVector() const
bool GetFileList(SotClipboardFormatId nFormat, FileList &rFileList) const
css::uno::Reference< css::io::XInputStream > GetInputStream(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotTempStream > &rStreamRef) const
bool GetGDIMetaFile(SotClipboardFormatId nFormat, GDIMetaFile &rMtf, size_t nMaxActions=0) const
bool HasFormat(SotClipboardFormatId nFormat) const
bool GetBitmapEx(SotClipboardFormatId nFormat, BitmapEx &rBmp) const
bool GetGraphic(SotClipboardFormatId nFormat, Graphic &rGraphic) const
void readGraphic(Graphic &rGraphic)
bool InsertEmbeddedObject(const css::uno::Reference< css::embed::XEmbeddedObject > &, OUString &)
static css::uno::Reference< css::embed::XStorage > GetStorageFromInputStream(const css::uno::Reference< css::io::XInputStream > &xStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
#define SO3_SC_CLASSID_60
static bool extractColumnDescriptor(const TransferableDataHelper &_rData, OUString &_rDatasource, OUString &_rDatabaseLocation, OUString &_rConnectionResource, sal_Int32 &_nCommandType, OUString &_rCommand, OUString &_rFieldName)
static bool canExtractColumnDescriptor(const DataFlavorExVector &_rFlavors, ColumnTransferFormatFlags _nFormats)
css::uno::Sequence< css::beans::PropertyValue > const & createPropertyValueSequence()
static bool canExtractObjectDescriptor(const DataFlavorExVector &_rFlavors)
static ODataAccessDescriptor extractObjectDescriptor(const TransferableDataHelper &_rData)
weld::Window * GetFrameWeld() const
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
EmbeddedObjectRef * pObject
::std::vector< DataFlavorEx > DataFlavorExVector
constexpr SdrLayerID SC_LAYER_FRONT(0)
@ Keep
Keep selection as is, expand to used data area if no selection.
constexpr SdrLayerID SC_LAYER_CONTROLS(3)
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
#define SFX_TITLE_FULLNAME
This struct stores general clipboard parameters associated with a ScDocument instance created in clip...
Extended settings for a sheet, used in import/export filters.
ScRange maUsedArea
Used area in the sheet (columns/rows only).
SVXCORE_DLLPUBLIC bool SvxDrawingLayerImport(SdrModel *pModel, const css::uno::Reference< css::io::XInputStream > &xInputStream)