/* -*- 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 .
*/
bool SwDoc::SplitDoc( sal_uInt16 eDocType, const OUString& rPath, bool bOutline, const SwTextFormatColl* pSplitColl, int nOutlineLevel )
{ // Iterate over all the template's Nodes, creating an own // document for every single one and replace linked sections (GlobalDoc) for links (HTML). // Finally, we save this document as a GlobalDoc/HTMLDoc. if( !mpDocShell || !mpDocShell->GetMedium() ||
( SPLITDOC_TO_GLOBALDOC == eDocType && GetDocumentSettingManager().get(DocumentSettingId::GLOBAL_DOCUMENT) ) ) returnfalse;
// Deactivate Undo/Redline in any case
GetIDocumentUndoRedo().DoUndo(false);
getIDocumentRedlineAccess().SetRedlineFlags_intern( getIDocumentRedlineAccess().GetRedlineFlags() & ~RedlineFlags::On );
// Write out the Nodes completely
OUString sFileName; if( pStartNd->GetIndex() + 1 < aEndIdx.GetIndex() )
{
SfxObjectShellLock xDocSh( new SwDocShell( SfxObjectCreateMode::INTERNAL )); if( xDocSh->DoInitNew() )
{
SwDoc* pDoc = static_cast<SwDocShell*>(&xDocSh)->GetDoc();
uno::Reference<document::XDocumentPropertiesSupplier> xDPS( static_cast<SwDocShell*>(&xDocSh)->GetModel(),
uno::UNO_QUERY_THROW);
uno::Reference<document::XDocumentProperties> xDocProps(
xDPS->getDocumentProperties());
OSL_ENSURE(xDocProps.is(), "Doc has no DocumentProperties"); // the GlobalDoc is the template
xDocProps->setTemplateName(OUString());
::util::DateTime uDT = aTmplDate.GetUNODateTime();
xDocProps->setTemplateDate(uDT);
xDocProps->setTemplateURL(rPath); // Set the new doc's title to the text of the "split para". // If the current doc has a title, insert it at the begin.
OUString sTitle( xDocProps->getTitle() ); if (!sTitle.isEmpty())
sTitle += ": ";
sTitle += pStartNd->GetTextNode()->GetExpandText(nullptr);
xDocProps->setTitle( sTitle );
// Replace template
pDoc->ReplaceStyles( *this );
// Take over chapter numbering if( mpOutlineRule )
pDoc->SetOutlineNumRule( *mpOutlineRule );
// We need to have a Layout for the HTMLFilter, so that // TextFrames/Controls/OLE objects can be exported correctly as graphics. if( SPLITDOC_TO_HTML == eDocType &&
!pDoc->GetSpzFrameFormats()->empty() )
{
SfxViewFrame::LoadHiddenDocument( *xDocSh, SFX_INTERFACE_NONE );
}
xDocSh->DoSaveAs( *pTmpMed );
xDocSh->DoSaveCompleted( pTmpMed );
// do not insert a FileLinkSection in case of error if( xDocSh->GetErrorIgnoreWarning() )
sFileName.clear();
}
xDocSh->DoClose();
}
// We can now insert the section if( !sFileName.isEmpty() )
{ switch( eDocType )
{ case SPLITDOC_TO_HTML:
{ // Delete all nodes in the section and, in the "start node", // set the Link to the saved document.
SwNodeOffset nNodeDiff = aEndIdx.GetIndex() -
pStartNd->GetIndex() - 1; if( nNodeDiff )
{
SwPaM aTmp( *pStartNd, aEndIdx.GetNode(), SwNodeOffset(1), SwNodeOffset(-1) );
SwNodeIndex aSIdx( aTmp.GetMark()->GetNode() );
SwNodeIndex aEIdx( aTmp.GetPoint()->GetNode() );
// Try to move past the end if( !aTmp.Move( fnMoveForward, GoInNode ) )
{ // well then, back to the beginning
aTmp.Exchange(); if( !aTmp.Move( fnMoveBackward, GoInNode ))
{
OSL_FAIL( "no more Nodes!" );
}
} // Move Bookmarks and so forth
CorrAbs( aSIdx, aEIdx, *aTmp.GetPoint(), true);
// If FlyFrames are still around, delete these too auto& rSpzs = *GetSpzFrameFormats(); for(sw::FrameFormats<sw::SpzFrameFormat*>::size_type n = 0; n < GetSpzFrameFormats()->size(); )
{ auto pFly = rSpzs[n]; const SwFormatAnchor* pAnchor = &pFly->GetAnchor();
SwNode const*const pAnchorNode =
pAnchor->GetAnchorNode(); if (pAnchorNode &&
((RndStdIds::FLY_AT_PARA == pAnchor->GetAnchorId()) ||
(RndStdIds::FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
aSIdx <= *pAnchorNode &&
*pAnchorNode < aEIdx.GetNode() )
{
getIDocumentLayoutAccess().DelLayoutFormat( pFly );
} else
++n;
}
GetNodes().Delete( aSIdx, nNodeDiff );
}
// set the link in the StartNode
SwFormatINetFormat aINet( sFileName , OUString() );
SwTextNode* pTNd = pStartNd->GetTextNode();
pTNd->InsertItem(aINet, 0, pTNd->GetText().getLength());
// If the link cannot be found anymore, // it has to be a bug! if( !pOutlNds->Seek_Entry( pStartNd, &nOutl ))
pStartNd = nullptr;
++nOutl ;
} break;
default: // save the Globaldoc
GetDocumentSettingManager().set(DocumentSettingId::GLOBAL_DOCUMENT, true);
GetDocumentSettingManager().set(DocumentSettingId::GLOBAL_DOCUMENT_SAVE_LINKS, 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.