22#include <com/sun/star/task/InteractionHandler.hpp>
24#include <sfx2/sfxsids.hrc>
43#include <document.hxx>
54#include <tokenarray.hxx>
66 OUString aFilter, OUString aOpt,
67 sal_Int32 nRefreshDelaySeconds ):
71 aFileName(
std::move(aFile)),
72 aFilterName(
std::move(aFilter)),
73 aOptions(
std::move(aOpt)),
78 pImpl->m_pDocSh = pDocSh;
82 OUString aFilter, OUString aOpt,
83 sal_Int32 nRefreshDelaySeconds ):
87 aFileName(
std::move(aFile)),
88 aFilterName(
std::move(aFilter)),
89 aOptions(
std::move(aOpt)),
113 pImpl->m_aEndEditLink = rEndEditHdl;
116 SvBaseLink::Edit( pParent,
LINK(
this,
ScTableLink, TableEndEditHdl ) );
120 const OUString&,
const css::uno::Any& )
123 if (pLinkManager!=
nullptr)
125 OUString aFile, aFilter;
146 pImpl->m_pDocSh->GetUndoManager()->AddUndoAction(
147 std::make_unique<ScUndoRemoveLink>(
pImpl->m_pDocSh,
aFileName ) );
154 SvBaseLink::Closed();
163 const OUString* pNewOptions, sal_Int32 nNewRefreshDelaySeconds )
167 if (rNewFile.isEmpty() || rNewFilter.isEmpty())
173 std::shared_ptr<const SfxFilter> pFilter =
pImpl->m_pDocSh->GetFactory().GetFilterContainer()->GetFilter4FilterName(rNewFilter);
189 auto pSet = std::make_shared<SfxAllItemSet>(
SfxGetpApp()->GetPool() );
193 SfxMedium* pMed =
new SfxMedium(aNewUrl, StreamMode::STD_READ, pFilter, std::move(pSet));
199 ScDocShell* pSrcShell =
new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS);
205 if (aNewOpt.isEmpty())
219 bool bNotFound =
false;
240 pUndoDoc->InitUndo( rDoc, nTab, nTab,
true,
true );
242 pUndoDoc->AddUndoTab( nTab, nTab,
true,
true );
246 pUndoDoc->TransferDrawPage( rDoc, nTab, nTab );
277 if ( !aTabName.isEmpty() && !bAutoTab )
278 bFound = rSrcDoc.
GetTable( aTabName, nSrcTab );
290 bool bShowError =
true;
299 for (
bool bHas = aIter.
first(); bHas; bHas = aIter.
next())
318 size_t nRanges = aErrorCells.
size();
334 for (
SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
335 for (
SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
362 aOptions != aNewOpt || pNewOptions ||
364 rDoc.
SetLink( nTab, nMode, aNewUrl, rNewFilter, aNewOpt,
365 aTabName, nNewRefreshDelaySeconds );
385 pImpl->m_pDocSh->GetUndoManager()->AddUndoAction(
386 std::make_unique<ScUndoRefreshLink>(
pImpl->m_pDocSh, std::move(pUndoDoc) ) );
412 Refresh( aFileName, aFilterName,
nullptr, GetRefreshDelaySeconds() );
417 pImpl->m_aEndEditLink.Call( rLink );
426 return pItem->GetValue();
432 OUString& rFilter, OUString& rOptions,
433 bool bWithContent,
bool bWithInteraction )
441 if ( pMed->
GetName() == rFileName )
443 rFilter = pMed->
GetFilter()->GetFilterName();
453 if ( eProt == INetProtocol::NotValid )
458 std::shared_ptr<const SfxFilter> pSfxFilter;
459 auto pMedium = std::make_unique<SfxMedium>( rFileName, StreamMode::STD_READ );
462 if ( bWithInteraction )
476 rFilter = pSfxFilter->GetFilterName();
479 bOK = !rFilter.isEmpty();
488 if (rFilterName.startsWith( aAppPrefix))
489 rFilterName = rFilterName.copy( aAppPrefix.getLength());
493 const OUString& rOptions,
weld::Window* pInteractionParent )
496 auto pSet = std::make_shared<SfxAllItemSet>(
SfxGetpApp()->GetPool() );
497 if ( !rOptions.isEmpty() )
498 pSet->Put(
SfxStringItem( SID_FILE_FILTEROPTIONS, rOptions ) );
500 if (pInteractionParent)
503 css::uno::Reference<css::task::XInteractionHandler> xIHdl(css::task::InteractionHandler::createWithParent(xContext,
504 pInteractionParent->
GetXWindow()), css::uno::UNO_QUERY_THROW);
505 pSet->Put(
SfxUnoAnyItem(SID_INTERACTIONHANDLER, css::uno::Any(xIHdl)));
508 SfxMedium *pRet =
new SfxMedium( rFileName, StreamMode::STD_READ, pFilter, std::move(pSet) );
509 if (pInteractionParent)
515 OUString& rFilterName, OUString& rOptions,
517 css::uno::Reference<css::io::XInputStream> xInputStream)
521 if ( rFilterName.isEmpty() )
522 GetFilterName(rFileName, rFilterName, rOptions,
true, pInteractionParent !=
nullptr);
524 std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( rFilterName );
527 if (xInputStream.is())
532 pDocShell =
new ScDocShell( SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS );
547 if (!aNew.isEmpty() && aNew != rOptions)
SfxApplication * SfxGetpApp()
INetProtocol GetProtocol() const
Walk through all cells in an area.
ScFormulaCell * getFormulaCell()
Iterator for references in a formula cell.
bool GetNextRef(ScRange &rRange)
Create before modifications of the document and destroy thereafter.
void SetDocumentModified()
const ScDocument & GetDocument() const
static OUString GetOwnFilterName()
static bool HasAutomaticTableName(std::u16string_view rFilter)
static SfxMedium * CreateMedium(const OUString &rFileName, std::shared_ptr< const SfxFilter > const &pFilter, const OUString &rOptions, weld::Window *pInteractionParent=nullptr)
Create SfxMedium for stream read with SfxFilter and filter options set at the medium's SfxItemSet.
ScDocumentLoader(const OUString &rFileName, OUString &rFilterName, OUString &rOptions, sal_uInt32 nRekCnt=0, weld::Window *pInteractionParent=nullptr, css::uno::Reference< css::io::XInputStream > xInputStream=css::uno::Reference< css::io::XInputStream >())
static void RemoveAppPrefix(OUString &rFilterName)
static OUString GetOptions(const SfxMedium &rMedium)
static bool GetFilterName(const OUString &rFileName, OUString &rFilter, OUString &rOptions, bool bWithContent, bool bWithInteraction)
Returns the filter name and options from a file name.
OUString GetTitle() const
ScDocument * GetDocument()
SC_DLLPUBLIC OUString GetLinkTab(SCTAB nTab) const
SC_DLLPUBLIC sal_uLong TransferTab(ScDocument &rSrcDoc, SCTAB nSrcPos, SCTAB nDestPos, bool bInsertNew=true, bool bResultsOnly=false)
SC_DLLPUBLIC void SetFormula(const ScAddress &rPos, const ScTokenArray &rArray)
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
SC_DLLPUBLIC SCCOL MaxCol() const
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
SC_DLLPUBLIC SCROW MaxRow() const
void SetInLinkUpdate(bool bSet)
SC_DLLPUBLIC bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
ScExtDocOptions * GetExtDocOptions()
SC_DLLPUBLIC ScLinkMode GetLinkMode(SCTAB nTab) const
void CopyToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, InsertDeleteFlags nFlags, bool bMarked, ScDocument &rDestDoc, const ScMarkData *pMarks=nullptr, bool bColRowFlags=true)
void SetLink(SCTAB nTab, ScLinkMode nMode, const OUString &rDoc, const OUString &rFilter, const OUString &rOptions, const OUString &rTabName, sal_uLong nRefreshDelay)
SC_DLLPUBLIC void SetExtDocOptions(std::unique_ptr< ScExtDocOptions > pNewOptions)
SC_DLLPUBLIC void DeleteAreaTab(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab, InsertDeleteFlags nDelFlag)
SC_DLLPUBLIC OUString GetLinkDoc(SCTAB nTab) const
bool IsLinked(SCTAB nTab) const
bool IsUndoEnabled() const
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
void BroadcastUno(const SfxHint &rHint)
SC_DLLPUBLIC SCTAB GetTableCount() const
Extended options held by an ScDocument containing additional settings for filters.
const ScExtDocSettings & GetDocSettings() const
static SC_DLLPUBLIC OUString GetDocTabName(std::u16string_view rFileName, std::u16string_view rTabName)
static SC_DLLPUBLIC ::utl::TransliterationWrapper & GetTransliteration()
static SC_DLLPUBLIC OUString GetAbsDocName(const OUString &rFileName, const SfxObjectShell *pShell)
void SetSheetLink(const OUString &rSourceUrl)
void Join(const ScRange &, bool bIsInList=false)
sal_Int32 GetRefreshDelaySeconds() const
void SetRefreshHandler(const Link< Timer *, void > &rLink)
void SetRefreshControl(std::unique_ptr< ScRefreshTimerControl > const *pp)
virtual ~ScTableLink() override
virtual void Closed() override
ScTableLink(ScDocShell *pDocSh, OUString aFile, OUString aFilter, OUString aOpt, sal_Int32 nRefreshDelaySeconds)
bool Refresh(const OUString &rNewFile, const OUString &rNewFilter, const OUString *pNewOptions, sal_Int32 nNewRefreshDelaySeconds)
virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(const OUString &rMimeType, const css::uno::Any &rValue) override
virtual void Edit(weld::Window *, const Link< SvBaseLink &, void > &rEndEditHdl) override
std::unique_ptr< TableLink_Impl > pImpl
virtual formula::FormulaToken * AddOpCode(OpCode eCode) override
ErrCode GuessFilterIgnoringContent(SfxMedium const &rMedium, std::shared_ptr< const SfxFilter > &) const
ErrCode GuessFilter(SfxMedium &rMedium, std::shared_ptr< const SfxFilter > &, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const std::shared_ptr< const SfxFilter > & GetFilter() const
void setStreamToLoadFrom(const css::uno::Reference< css::io::XInputStream > &xInputStream, bool bIsReadOnly)
void UseInteractionHandler(bool)
SfxItemSet & GetItemSet() const
const OUString & GetName() const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
SfxMedium * GetMedium() const
OUString GetTitle(sal_uInt16 nMaxLen=0) const
bool DoLoad(SfxMedium *pMedium)
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
constexpr OUStringLiteral STRING_SCAPP
#define LINK(Instance, Class, Member)
Reference< XComponentContext > getProcessComponentContext()
OUString ScResId(TranslateId aId)
sal_uInt32 mnLinkCnt
Recursive counter for loading external documents.
Link< sfx2::SvBaseLink &, void > m_aEndEditLink
IMPL_LINK(ScTableLink, TableEndEditHdl, ::sfx2::SvBaseLink &, rLink, void)
IMPL_LINK_NOARG(ScTableLink, RefreshHdl, Timer *, void)