/* -*- 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 .
*/
// check size (only if string is available in transferable)
sal_uInt16 nCols = 1;
sal_uInt16 nRows = 1; if ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) )
{
OUString aDataStr; if ( aDataHelper.GetString( SotClipboardFormatId::STRING, aDataStr ) )
{ // get size from string the same way as in ScDdeLink::DataChanged
// create formula if ( sExtra == "calc:extref" )
{ // Paste this as an external reference. Note that paste link always // uses Calc A1 syntax even when another formula syntax is specified // in the UI.
EnterMatrix("='"
+ ScGlobal::GetAbsDocName(sTopic, GetViewData().GetDocument().GetDocumentShell())
+ "'#" + sItem
, ::formula::FormulaGrammar::GRAM_NATIVE); returntrue;
} else
{ // DDE in all other cases.
// mba: BaseURL doesn't make sense for clipboard // #i43716# Medium must be allocated with "new". // DoLoad stores the pointer and deletes it with the SfxObjectShell.
SfxMedium* pMedium = new SfxMedium( xStore, OUString() );
// TODO/LATER: is it a problem that we don't support binary formats here?
ScDocShellRef xDocShRef = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT); if (xDocShRef->DoLoad(pMedium))
{
ScDocument& rSrcDoc = xDocShRef->GetDocument();
SCTAB nSrcTab = rSrcDoc.GetVisibleTab(); if (!rSrcDoc.HasTable(nSrcTab))
nSrcTab = 0;
xDocShRef->DoClose();
xDocShRef.clear();
} else
{
OUString aName;
uno::Reference < embed::XEmbeddedObject > xObj = GetViewData().GetViewShell()->GetObjectShell()->
GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName ); if ( xObj.is() )
{ // try to get the replacement image from the clipboard
Graphic aGraphic;
SotClipboardFormatId nGrFormat = SotClipboardFormatId::NONE;
// limit the size of the preview metafile to 100000 actions
GDIMetaFile aMetafile; if (rDataHelper.GetGDIMetaFile(SotClipboardFormatId::GDIMETAFILE, aMetafile, 100000))
{
nGrFormat = SotClipboardFormatId::GDIMETAFILE;
aGraphic = aMetafile;
}
// insert replacement image ( if there is one ) into the object helper if ( nGrFormat != SotClipboardFormatId::NONE )
{
datatransfer::DataFlavor aDataFlavor;
SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
PasteObject( rPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect );
} else
PasteObject( rPos, xObj, &aObjDesc.maSize );
// TODO/LATER: in future InsertedObjectInfo will be used to get container related information // for example whether the object should be an iconified one
xObj = aInfo.Object; if ( xObj.is() )
GetViewData().GetDocShell().GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
} catch( uno::Exception& )
{}
}
if ( xObj.is() )
{ // try to get the replacement image from the clipboard
Graphic aGraphic;
SotClipboardFormatId nGrFormat = SotClipboardFormatId::NONE;
// insert replacement image ( if there is one ) into the object helper if ( nGrFormat != SotClipboardFormatId::NONE )
{
datatransfer::DataFlavor aDataFlavor;
SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
PasteObject( rPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect );
} else
PasteObject( rPos, xObj, &aObjDesc.maSize );
// let object stay in loaded state after insertion
SdrOle2Obj::Unload( xObj, embed::Aspects::MSOLE_CONTENT );
bRet = true;
} else
{
OSL_FAIL("Error creating external OLE object");
}
} //TODO/LATER: if format is not available, create picture
} return bRet;
}
auto pStrBuffer = std::make_shared<OUString>(); if (std::unique_ptr<SvStream> xStream = rDataHelper.GetSotStorageStream( nFormatId ) )
{ if (nFormatId == SotClipboardFormatId::HTML &&
!comphelper::LibreOfficeKit::isActive())
{ if (useSavedPrefs)
{
ScAsciiOptions aOptions;
aOptions.SetLanguage(LanguageType(officecfg::Office::Calc::Dialogs::ClipboardHTMLImport::Language::get()));
aOptions.SetDetectSpecialNumber(officecfg::Office::Calc::Dialogs::ClipboardHTMLImport::DetectSpecialNumbers::get());
aOptions.SetDetectScientificNumber(officecfg::Office::Calc::Dialogs::ClipboardHTMLImport::DetectScientificNumbers::get());
pObj->SetExtOptions(aOptions);
} else
{ // Launch the text import options dialog. For now, we do // this for html pasting only, but in the future it may // make sense to do it for other data types too.
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
vcl::Window* pParent = GetActiveWin();
ScopedVclPtr<AbstractScTextImportOptionsDlg> pDlg(
pFact->CreateScTextImportOptionsDlg(pParent ? pParent->GetFrameWeld() : nullptr));
if (pDlg->Execute() == RET_OK)
{
ScAsciiOptions aOptions;
aOptions.SetLanguage(pDlg->GetLanguageType());
aOptions.SetDetectSpecialNumber(pDlg->IsDateConversionSet());
aOptions.SetDetectScientificNumber(pDlg->IsScientificConversionSet()); auto pChange(comphelper::ConfigurationChanges::create());
officecfg::Office::Calc::Dialogs::ClipboardHTMLImport::Language::set(pDlg->GetLanguageType().get(), pChange);
officecfg::Office::Calc::Dialogs::ClipboardHTMLImport::DetectSpecialNumbers::set(pDlg->IsDateConversionSet(), pChange);
officecfg::Office::Calc::Dialogs::ClipboardHTMLImport::DetectScientificNumbers::set(pDlg->IsScientificConversionSet(), pChange);
pChange->commit();
pObj->SetExtOptions(aOptions);
} else
{ // prevent error dialog for user cancel action
bRet = true;
}
}
} if(!bRet)
bRet = pObj->ImportStream( *xStream, OUString(), nFormatId ); // mba: clipboard always must contain absolute URLs (could be from alien source)
} elseif ((nFormatId == SotClipboardFormatId::STRING || nFormatId == SotClipboardFormatId::STRING_TSVC)
&& rDataHelper.GetString( nFormatId, *pStrBuffer ))
{ // Do CSV dialog if more than one line. But not if invoked from Automation. const SfxViewShell* pViewShell = SfxViewShell::Current();
sal_Int32 nDelim = pStrBuffer->indexOf('\n'); if (!(pViewShell && pViewShell->isLOKMobilePhone()) && !comphelper::Automation::AutomationInvokedZone::isActive()
&& nDelim >= 0 && nDelim != pStrBuffer->getLength () - 1)
{
vcl::Window* pParent = GetActiveWin();
auto pStrm = std::make_shared<ScImportStringStream>(*pStrBuffer);
// TODO: what if (aObj.IsOverflow()) // Content was partially pasted, which can be undone by // the user though.
bShowErrorDialog = bShowErrorDialog && pObj->IsOverflow();
} else
{
bShowErrorDialog = false; // Yes, no failure, don't raise a "couldn't paste" // dialog if user cancelled.
}
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.