/* -*- 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 .
*/
// Loading bool SwDocShell::ConvertFrom( SfxMedium& rMedium )
{
SwReaderPtr pRdr;
Reader* pRead = StartConvertFrom(rMedium, pRdr); if (!pRead) returnfalse; // #129881# return if no reader is found
rtl::Reference<SotStorage> pStg=pRead->getSotStorageRef(); // #i45333# save sot storage ref in case of recursive calls
SwModule* mod = SwModule::get(); // Suppress SfxProgress, when we are Embedded
mod->SetEmbeddedLoadSave(SfxObjectCreateMode::EMBEDDED == GetCreateMode());
pRdr->GetDoc().getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE, dynamic_cast< const SwWebDocShell *>( this ) != nullptr);
// Restore the pool default if reading a saved document.
m_xDoc->RemoveAllFormatLanguageDependencies();
ErrCodeMsg nErr = pRdr->Read( *pRead );
// Maybe put away one old Doc if (m_xDoc.get() != &pRdr->GetDoc())
{
RemoveLink();
m_xDoc = &pRdr->GetDoc();
AddLink();
if (!m_xBasePool.is())
m_xBasePool = new SwDocStyleSheetPool( *m_xDoc, SfxObjectCreateMode::ORGANIZER == GetCreateMode() );
}
if (bOk && !m_xDoc->IsInLoadAsynchron())
{
LoadingFinished();
}
pRead->setSotStorageRef(pStg); // #i45333# save sot storage ref in case of recursive calls
return bOk;
}
// Saving the Default-Format, Stg present bool SwDocShell::Save()
{ //#i3370# remove quick help to prevent saving of autocorrection suggestions if (m_pView)
m_pView->GetEditWin().StopQuickHelp();
SwWait aWait( *this, true );
CalcLayoutForOLEObjects(); // format for OLE objects // #i62875# // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible if (m_pWrtShell && m_xDoc &&
m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
docfunc::AllDrawObjsOnPage(*m_xDoc))
{
m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
}
// Save using the Defaultformat bool SwDocShell::SaveAs( SfxMedium& rMedium )
{
SwWait aWait( *this, true ); //#i3370# remove quick help to prevent saving of autocorrection suggestions if (m_pView)
m_pView->GetEditWin().StopQuickHelp();
//#i91811# mod if we have an active margin window, write back the text if (m_pView &&
m_pView->GetPostItMgr() &&
m_pView->GetPostItMgr()->HasActiveSidebarWin())
{
m_pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin();
}
if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT) &&
!m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT_SAVE_LINKS))
RemoveOLEObjects();
if (GetMedium())
{ // Task 75666 - is the Document imported by our Microsoft-Filters?
std::shared_ptr<const SfxFilter> pOldFilter = GetMedium()->GetFilter(); if( pOldFilter &&
( pOldFilter->GetUserData() == FILTER_WW8 ||
pOldFilter->GetUserData() == "CWW6" ||
pOldFilter->GetUserData() == "WW6" ) )
{ // when saving it in our own fileformat, then remove the template // name from the docinfo.
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
GetModel(), uno::UNO_QUERY_THROW);
uno::Reference<document::XDocumentProperties> xDocProps
= xDPS->getDocumentProperties();
xDocProps->setTemplateName(OUString());
xDocProps->setTemplateURL(OUString());
xDocProps->setTemplateDate(::util::DateTime());
}
}
CalcLayoutForOLEObjects(); // format for OLE objects
constbool bURLChanged = GetMedium() && GetMedium()->GetURLObject() != rMedium.GetURLObject(); const SwDBManager* const pMgr = m_xDoc->GetDBManager(); constbool bHasEmbedded = pMgr && !pMgr->getEmbeddedName().isEmpty(); bool bSaveDS = bHasEmbedded && bURLChanged; if (bSaveDS)
{ // Don't save data source in case a temporary is being saved for preview in MM wizard if (const SfxBoolItem* pNoEmbDS
= rMedium.GetItemSet().GetItem(SID_NO_EMBEDDED_DS, false))
bSaveDS = !pNoEmbDS->GetValue();
} if (bSaveDS)
{ // We have an embedded data source definition, need to re-store it, // otherwise relative references will break when the new file is in a // different directory.
OUString aURL(GetMedium()->GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE)); if (aURL.isEmpty())
{ // No old URL - is this a new document created from a template with embedded DS? // Try to get the template URL to reconstruct the embedded data source URL const css::beans::PropertyValues& rArgs = GetMedium()->GetArgs(); constauto aURLIter = std::find_if(rArgs.begin(), rArgs.end(),
[](constauto& v) { return v.Name == "URL"; }); if (aURLIter != rArgs.end())
aURLIter->Value >>= aURL;
}
// #i62875# // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible if (m_pWrtShell &&
m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
docfunc::AllDrawObjsOnPage(*m_xDoc))
{
m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
}
ErrCodeMsg nErr = ERR_SWG_WRITE_ERROR;
ErrCode nVBWarning = ERRCODE_NONE;
uno::Reference < embed::XStorage > xStor = rMedium.GetOutputStorage(); if( SfxObjectShell::SaveAs( rMedium ) )
{ if( GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT) && dynamic_cast< const SwGlobalDocShell *>( this ) == nullptr )
{ // The document is closed explicitly, but using SfxObjectShellLock is still more correct here
SfxObjectShellLock xDocSh = new SwGlobalDocShell( SfxObjectCreateMode::INTERNAL ); // the global document can not be a template
xDocSh->SetupStorage( xStor, SotStorage::GetVersion( xStor ), false );
xDocSh->DoClose();
}
if (m_xDoc->ContainsMSVBasic())
{ if (officecfg::Office::Writer::Filter::Import::VBA::Save::get())
nVBWarning = GetSaveWarningOfMSVBAStorage( static_cast<SfxObjectShell&>(*this) );
m_xDoc->SetContainsMSVBasic( false );
}
if (m_pWrtShell)
{ // End TableBox Edit!
m_pWrtShell->EndAllTableBoxEdit();
// Remember and preserve Modified-Flag without calling the Link // (for OLE; after Statement from MM) constbool bIsModified = m_xDoc->getIDocumentState().IsModified();
m_xDoc->GetIDocumentUndoRedo().LockUndoNoModifiedPosition();
Link<bool,void> aOldOLELnk( m_xDoc->GetOle2Link() );
m_xDoc->SetOle2Link( Link<bool,void>() );
SwModule* mod = SwModule::get(); // Suppress SfxProgress when we are Embedded
mod->SetEmbeddedLoadSave(SfxObjectCreateMode::EMBEDDED == GetCreateMode());
//#i3370# remove quick help to prevent saving of autocorrection suggestions if (m_pView)
m_pView->GetEditWin().StopQuickHelp();
//#i91811# mod if we have an active margin window, write back the text if (m_pView &&
m_pView->GetPostItMgr() &&
m_pView->GetPostItMgr()->HasActiveSidebarWin())
{
m_pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin();
}
CalcLayoutForOLEObjects(); // format for OLE objects // #i62875# // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible if (m_pWrtShell &&
m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
docfunc::AllDrawObjsOnPage(*m_xDoc))
{
m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
}
// if the target format is storage based, then the output storage must be already created if ( rMedium.IsStorage() )
{ // set MediaType on target storage // (MediaType will be queried during SaveAs) try
{ // TODO/MBA: testing
uno::Reference < beans::XPropertySet > xSet( rMedium.GetStorage(), uno::UNO_QUERY ); if ( xSet.is() )
xSet->setPropertyValue(u"MediaType"_ustr, uno::Any( SotExchange::GetFormatMimeType( nSaveClipId ) ) );
} catch (const uno::Exception&)
{
}
}
// Now normally save the Document bool bRet = SaveAs( rMedium );
SwModule* mod = SwModule::get(); // Suppress SfxProgress when we are Embedded
mod->SetEmbeddedLoadSave(SfxObjectCreateMode::EMBEDDED == GetCreateMode());
// Span Context in order to suppress the Selection's View
ErrCodeMsg nErrno; const OUString aFileName( rMedium.GetName() );
// Hands off // do not yet activate, must deliver TRUE bool SwDocShell::SaveCompleted( const uno::Reference < embed::XStorage >& xStor )
{ bool bRet = SfxObjectShell::SaveCompleted( xStor ); if( bRet )
{ // Do not decide until here, whether Saving was successful or not if( IsModified() )
m_xDoc->getIDocumentState().SetModified(); else
m_xDoc->getIDocumentState().ResetModified();
}
// Draw()-Override for OLE2 (Sfx) void SwDocShell::Draw( OutputDevice* pDev, const JobSetup& rSetup,
sal_uInt16 nAspect, bool bOutputForScreen )
{ //fix #25341# Draw should not affect the Modified bool bResetModified = IsEnableSetModified(); if ( bResetModified )
EnableSetModified( false );
// When there is a JobSetup connected to the Document, we copy it to // reconnect it after PrtOle2. We don't use an empty JobSetup because // that would only lead to questionable results after expensive // reformatting (Preview!)
std::unique_ptr<JobSetup> pOrig; if ( !rSetup.GetPrinterName().isEmpty() && ASPECT_THUMBNAIL != nAspect )
{ const JobSetup* pCurrentJobSetup = m_xDoc->getIDocumentDeviceAccess().getJobsetup(); if( pCurrentJobSetup ) // then we copy that
pOrig.reset(new JobSetup( *pCurrentJobSetup ));
m_xDoc->getIDocumentDeviceAccess().setJobsetup( rSetup );
}
// #i20883# Digital Signatures and Encryption
HiddenInformation SwDocShell::GetHiddenInformationState( HiddenInformation nStates )
{ // get global state like HiddenInformation::DOCUMENTVERSIONS
HiddenInformation nState = SfxObjectShell::GetHiddenInformationState( nStates );
if ( nStates & HiddenInformation::RECORDEDCHANGES )
{ if ( !GetDoc()->getIDocumentRedlineAccess().GetRedlineTable().empty() )
nState |= HiddenInformation::RECORDEDCHANGES;
} if ( nStates & HiddenInformation::NOTES )
{
OSL_ENSURE( GetWrtShell(), "No SwWrtShell, no information" ); if(GetWrtShell() && GetWrtShell()->GetFieldType(SwFieldIds::Postit, OUString())->HasHiddenInformationNotes())
nState |= HiddenInformation::NOTES;
}
// Set view-specific redline author. const OUString& rRedlineAuthor = m_pView->GetRedlineAuthor(); if (!rRedlineAuthor.isEmpty())
SwModule::get()->SetRedlineAuthor(m_pView->GetRedlineAuthor());
} else
m_pWrtShell = nullptr;
}
// #i59688# // linked graphics are now loaded on demand. // Thus, loading of linked graphics no longer needed and necessary for // the load of document being finished. void SwDocShell::LoadingFinished()
{ // #i38810# // Original fix fails after integration of cws xmlsec11: // interface <SfxObjectShell::EnableSetModified(..)> no longer works, because // <SfxObjectShell::FinishedLoading(..)> doesn't care about its status and // enables the document modification again. // Thus, manual modify the document, if it's modified and its links are updated // before <FinishedLoading(..)> is called. constbool bHasDocToStayModified( m_xDoc->getIDocumentState().IsModified() && m_xDoc->getIDocumentLinksAdministration().LinksUpdated() );
#if ENABLE_YRS #if 0 // this doesn't even filter as advertised! autoconst args{GetBaseModel()->getArgs2({u"YrsConnect"_ustr})}; #endif // when loading, it is only available from SfxMedium, not SfxBaseModel for (autoconst& rArg : GetMedium()->GetArgs())
{ if (rArg.Name == "YrsConnect")
{
m_xDoc->getIDocumentState().YrsInitConnector(rArg.Value); break;
}
} #endif
// a Transfer is cancelled (is called from SFX) void SwDocShell::CancelTransfers()
{ // Cancel all links from LinkManager
m_xDoc->getIDocumentLinksAdministration().GetLinkManager().CancelTransfers();
SfxObjectShell::CancelTransfers();
}
// When a document is loaded, SwDoc::PrtOLENotify is called to update // the sizes of math objects. However, for objects that do not have a // SwFrame at this time, only a flag is set (bIsOLESizeInvalid) and the // size change takes place later, while calculating the layout in the // idle handler. If this document is saved now, it is saved with invalid // sizes. For this reason, the layout has to be calculated before a document is // saved, but of course only id there are OLE objects with bOLESizeInvalid set. void SwDocShell::CalcLayoutForOLEObjects()
{ if (!m_pWrtShell) return;
if (m_pView && m_pView->GetIPClient())
{ // We have an active OLE edit: allow link updates, so an up to date replacement graphic can // be created.
comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
}
// #i42634# Overwrites SfxObjectShell::UpdateLinks // This new function is necessary to trigger update of links in docs // read by the binary filter: void SwDocShell::UpdateLinks()
{
GetDoc()->getIDocumentLinksAdministration().UpdateLinks(); // #i50703# Update footnote numbers
SwTextFootnote::SetUniqueSeqRefNo( *GetDoc() );
SwNodeIndex aTmp( GetDoc()->GetNodes() );
GetDoc()->GetFootnoteIdxs().UpdateFootnote( aTmp.GetNode() );
}
uno::Reference< frame::XController >
SwDocShell::GetController()
{
css::uno::Reference< css::frame::XController > aRet; // #i82346# No view in page preview if ( GetView() )
aRet = GetView()->GetController(); return aRet;
}
bool SwDocShell::IsChangeRecording(SfxViewShell* pViewShell, bool bRecordAllViews) const
{
SwWrtShell* pWrtShell = nullptr; auto pView = dynamic_cast<SwView*>(pViewShell); if (pView)
{
pWrtShell = pView->GetWrtShellPtr();
} if (!pWrtShell)
{
pWrtShell = m_pWrtShell;
}
if (!pWrtShell) returnfalse;
auto bOn = bool(pWrtShell->GetRedlineFlags() & RedlineFlags::On); if (bOn)
{ if (bRecordAllViews)
{ for (SwViewShell& rSh : pWrtShell->GetRingContainer())
{ if (!rSh.GetViewOptions()->IsRedlineRecordingOn())
{ returnfalse;
}
}
}
returntrue;
}
returnfalse;
}
bool SwDocShell::HasChangeRecordProtection() const
{ if (!m_pWrtShell) returnfalse; return m_pWrtShell->getIDocumentRedlineAccess().GetRedlinePassword().hasElements();
}
void SwDocShell::SetChangeRecording( bool bActivate, bool bLockAllViews, SfxRedlineRecordingMode eRedlineRecordingMode)
{
RedlineFlags nOn = bActivate ? RedlineFlags::On : RedlineFlags::NONE;
RedlineFlags nMode = m_pWrtShell->GetRedlineFlags(); if (bLockAllViews)
{ // tdf#107870: prevent jumping to cursor auto aViewGuard(LockAllViews());
m_pWrtShell->SetRedlineFlagsAndCheckInsMode( (nMode & ~RedlineFlags::On) | nOn, eRedlineRecordingMode );
} else
{
m_pWrtShell->SetRedlineFlagsAndCheckInsMode( (nMode & ~RedlineFlags::On) | nOn, eRedlineRecordingMode );
}
}
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.