summaryrefslogtreecommitdiff
path: root/sw/source/filter/xml/swxml.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/filter/xml/swxml.cxx')
-rw-r--r--sw/source/filter/xml/swxml.cxx131
1 files changed, 67 insertions, 64 deletions
diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx
index c3d9c50556da..16ae089113b8 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -56,6 +56,7 @@
#include <docfunc.hxx>
#include <IDocumentSettingAccess.hxx>
#include <IDocumentDrawModelAccess.hxx>
+#include <IDocumentMarkAccess.hxx>
#include <IDocumentRedlineAccess.hxx>
#include <DocumentRedlineManager.hxx>
#include <docary.hxx>
@@ -78,7 +79,7 @@
#include <istyleaccess.hxx>
#include <sfx2/DocumentMetadataAccess.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -89,18 +90,18 @@ using namespace ::com::sun::star::lang;
static void lcl_EnsureValidPam( SwPaM& rPam )
{
- if( rPam.GetContentNode() != nullptr )
+ if( rPam.GetPointContentNode() != nullptr )
{
// set proper point content
- if( rPam.GetContentNode() != rPam.GetPoint()->nContent.GetIdxReg() )
+ if( rPam.GetPointContentNode() != rPam.GetPoint()->GetContentNode() )
{
- rPam.GetPoint()->nContent.Assign( rPam.GetContentNode(), 0 );
+ rPam.GetPoint()->nContent.Assign( rPam.GetPointContentNode(), 0 );
}
// else: point was already valid
// if mark is invalid, we delete it
- if( ( rPam.GetContentNode( false ) == nullptr ) ||
- ( rPam.GetContentNode( false ) != rPam.GetMark()->nContent.GetIdxReg() ) )
+ if( ( rPam.GetMarkContentNode() == nullptr ) ||
+ ( rPam.GetMarkContentNode() != rPam.GetMark()->GetContentNode() ) )
{
rPam.DeleteMark();
}
@@ -109,9 +110,9 @@ static void lcl_EnsureValidPam( SwPaM& rPam )
{
// point is not valid, so move it into the first content
rPam.DeleteMark();
- rPam.GetPoint()->nNode =
- *rPam.GetDoc().GetNodes().GetEndOfContent().StartOfSectionNode();
- ++ rPam.GetPoint()->nNode;
+ rPam.GetPoint()->Assign(
+ *rPam.GetDoc().GetNodes().GetEndOfContent().StartOfSectionNode() );
+ rPam.GetPoint()->Adjust(SwNodeOffset(+1));
rPam.Move( fnMoveForward, GoInContent ); // go into content
}
}
@@ -129,7 +130,7 @@ namespace
{
/// read a component (file + filter version)
-ErrCode ReadThroughComponent(
+ErrCodeMsg ReadThroughComponent(
uno::Reference<io::XInputStream> const & xInputStream,
uno::Reference<XComponent> const & xModelComponent,
const OUString& rStreamName,
@@ -137,7 +138,7 @@ ErrCode ReadThroughComponent(
const char* pFilterName,
const Sequence<Any>& rFilterArguments,
const OUString& rName,
- bool bMustBeSuccessfull,
+ bool bMustBeSuccessful,
bool bEncrypted )
{
OSL_ENSURE(xInputStream.is(), "input stream missing");
@@ -218,16 +219,16 @@ ErrCode ReadThroughComponent(
if( !rStreamName.isEmpty() )
{
- return *new TwoStringErrorInfo(
- (bMustBeSuccessfull ? ERR_FORMAT_FILE_ROWCOL
+ return ErrCodeMsg(
+ (bMustBeSuccessful ? ERR_FORMAT_FILE_ROWCOL
: WARN_FORMAT_FILE_ROWCOL),
rStreamName, sErr,
DialogMask::ButtonsOk | DialogMask::MessageError );
}
else
{
- OSL_ENSURE( bMustBeSuccessfull, "Warnings are not supported" );
- return *new StringErrorInfo( ERR_FORMAT_ROWCOL, sErr,
+ OSL_ENSURE( bMustBeSuccessful, "Warnings are not supported" );
+ return ErrCodeMsg( ERR_FORMAT_ROWCOL, sErr,
DialogMask::ButtonsOk | DialogMask::MessageError );
}
}
@@ -265,7 +266,7 @@ ErrCode ReadThroughComponent(
}
// read a component (storage version)
-ErrCode ReadThroughComponent(
+ErrCodeMsg ReadThroughComponent(
uno::Reference<embed::XStorage> const & xStorage,
uno::Reference<XComponent> const & xModelComponent,
const char* pStreamName,
@@ -273,7 +274,7 @@ ErrCode ReadThroughComponent(
const char* pFilterName,
const Sequence<Any>& rFilterArguments,
const OUString& rName,
- bool bMustBeSuccessfull)
+ bool bMustBeSuccessful)
{
OSL_ENSURE(xStorage.is(), "Need storage!");
OSL_ENSURE(nullptr != pStreamName, "Please, please, give me a name!");
@@ -302,7 +303,7 @@ ErrCode ReadThroughComponent(
OSL_ENSURE( xInfoSet.is(), "missing property set" );
if( xInfoSet.is() )
{
- xInfoSet->setPropertyValue( "StreamName", makeAny( sStreamName ) );
+ xInfoSet->setPropertyValue( "StreamName", Any( sStreamName ) );
}
try
@@ -313,8 +314,8 @@ ErrCode ReadThroughComponent(
Any aAny = xProps->getPropertyValue("Encrypted");
- auto b = o3tl::tryAccess<bool>(aAny);
- bool bEncrypted = b && *b;
+ std::optional<const bool> b = o3tl::tryAccess<bool>(aAny);
+ bool bEncrypted = b.has_value() && *b;
uno::Reference <io::XInputStream> xInputStream = xStream->getInputStream();
@@ -322,7 +323,7 @@ ErrCode ReadThroughComponent(
return ReadThroughComponent(
xInputStream, xModelComponent, sStreamName, rxContext,
pFilterName, rFilterArguments,
- rName, bMustBeSuccessfull, bEncrypted );
+ rName, bMustBeSuccessful, bEncrypted );
}
catch ( packages::WrongPasswordException& )
{
@@ -411,9 +412,9 @@ static void lcl_AdjustOutlineStylesForOOo(SwDoc& _rDoc)
aCreatedDefaultOutlineStyles[ i ]->AssignToListLevelOfOutlineStyle(i);
// apply outline numbering rule, if none is set.
- const SfxPoolItem& rItem =
+ const SwNumRuleItem& rItem =
aCreatedDefaultOutlineStyles[ i ]->GetFormatAttr( RES_PARATR_NUMRULE, false );
- if ( static_cast<const SwNumRuleItem&>(rItem).GetValue().isEmpty() )
+ if ( rItem.GetValue().isEmpty() )
{
SwNumRuleItem aItem( pOutlineRule->GetName() );
aCreatedDefaultOutlineStyles[ i ]->SetFormatAttr( aItem );
@@ -449,7 +450,7 @@ static void lcl_ConvertSdrOle2ObjsToSdrGrafObjs(SwDoc& _rDoc)
pOle2Obj->Disconnect();
// create new graphic shape with the ole graphic and shape size
- SdrGrafObj* pGraphicObj = new SdrGrafObj(
+ rtl::Reference<SdrGrafObj> pGraphicObj = new SdrGrafObj(
pOle2Obj->getSdrModelFromSdrObject(),
aGraphic,
pOle2Obj->GetCurrentBoundRect());
@@ -458,13 +459,12 @@ static void lcl_ConvertSdrOle2ObjsToSdrGrafObjs(SwDoc& _rDoc)
pGraphicObj->SetLayer( pOle2Obj->GetLayer() );
// replace ole2 shape with the new graphic object and delete the ol2 shape
- SdrObject* pReplaced = pObjList->ReplaceObject( pGraphicObj, pOle2Obj->GetOrdNum() );
- SdrObject::Free( pReplaced );
+ pObjList->ReplaceObject( pGraphicObj.get(), pOle2Obj->GetOrdNum() );
}
}
}
-ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, const OUString & rName )
+ErrCodeMsg XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, const OUString & rName )
{
// needed for relative URLs, but in clipboard copy/paste there may be none
// and also there is the SwXMLTextBlocks special case
@@ -517,7 +517,7 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
// the user.
// create XPropertySet with three properties for status indicator
- comphelper::PropertyMapEntry const aInfoMap[] =
+ static comphelper::PropertyMapEntry const aInfoMap[] =
{
{ OUString("ProgressRange"), 0,
::cppu::UnoType<sal_Int32>::get(),
@@ -591,7 +591,6 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("SourceStorage"), 0, cppu::UnoType<embed::XStorage>::get(),
css::beans::PropertyAttribute::MAYBEVOID, 0 },
- { OUString(), 0, css::uno::Type(), 0, 0 }
};
uno::Reference< beans::XPropertySet > xInfoSet(
comphelper::GenericPropertySet_CreateInstance(
@@ -605,7 +604,7 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
if( xParentSet.is() )
{
uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() );
- const OUString sPropName("BuildId" );
+ static constexpr OUString sPropName(u"BuildId"_ustr );
if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(sPropName) )
{
xInfoSet->setPropertyValue( sPropName, xParentSet->getPropertyValue(sPropName) );
@@ -618,15 +617,11 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
if (pDocSh->GetMedium())
{
- SfxItemSet* pSet = pDocSh->GetMedium()->GetItemSet();
- if (pSet)
+ const SfxUnoAnyItem* pItem =
+ pDocSh->GetMedium()->GetItemSet().GetItem(SID_PROGRESS_STATUSBAR_CONTROL);
+ if (pItem)
{
- const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>(
- pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
- if (pItem)
- {
- pItem->GetValue() >>= xStatusIndicator;
- }
+ pItem->GetValue() >>= xStatusIndicator;
}
}
@@ -641,7 +636,7 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
xInfoSet->setPropertyValue("ProgressRange", aProgRange);
Reference< container::XNameAccess > xLateInitSettings( document::NamedPropertyValues::create(xContext), UNO_QUERY_THROW );
- beans::NamedValue aLateInitSettings( "LateInitSettings", makeAny( xLateInitSettings ) );
+ beans::NamedValue aLateInitSettings( "LateInitSettings", Any( xLateInitSettings ) );
xInfoSet->setPropertyValue( "SourceStorage", Any( xStorage ) );
@@ -683,16 +678,16 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
*pSeq++ = "NumberingStyles";
xInfoSet->setPropertyValue( "StyleInsertModeFamilies",
- makeAny(aFamiliesSeq) );
+ Any(aFamiliesSeq) );
- xInfoSet->setPropertyValue( "StyleInsertModeOverwrite", makeAny(!m_aOption.IsMerge()) );
+ xInfoSet->setPropertyValue( "StyleInsertModeOverwrite", Any(!m_aOption.IsMerge()) );
}
else if( m_bInsertMode )
{
- const uno::Reference<text::XTextRange> xInsertTextRange =
+ const rtl::Reference<SwXTextRange> xInsertTextRange =
SwXTextRange::CreateXTextRange(rDoc, *rPaM.GetPoint(), nullptr);
xInfoSet->setPropertyValue( "TextInsertModeRange",
- makeAny(xInsertTextRange) );
+ Any(uno::Reference<text::XTextRange>(xInsertTextRange)) );
}
else
{
@@ -702,11 +697,11 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
if( IsBlockMode() )
{
- xInfoSet->setPropertyValue( "AutoTextMode", makeAny(true) );
+ xInfoSet->setPropertyValue( "AutoTextMode", Any(true) );
}
if( IsOrganizerMode() )
{
- xInfoSet->setPropertyValue( "OrganizerMode", makeAny(true) );
+ xInfoSet->setPropertyValue( "OrganizerMode", Any(true) );
}
// Set base URI
@@ -715,16 +710,16 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
SfxMedium* pMedDescrMedium = m_pMedium ? m_pMedium : pDocSh->GetMedium();
OSL_ENSURE( pMedDescrMedium, "There is no medium to get MediaDescriptor from!" );
- xInfoSet->setPropertyValue( "BaseURI", makeAny( rBaseURL ) );
+ xInfoSet->setPropertyValue( "BaseURI", Any( rBaseURL ) );
// TODO/LATER: separate links from usual embedded objects
OUString StreamPath;
if( SfxObjectCreateMode::EMBEDDED == rDoc.GetDocShell()->GetCreateMode() )
{
- if ( pMedDescrMedium && pMedDescrMedium->GetItemSet() )
+ if (pMedDescrMedium)
{
- const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
- pMedDescrMedium->GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
+ const SfxStringItem* pDocHierarchItem =
+ pMedDescrMedium->GetItemSet().GetItem(SID_DOC_HIERARCHICALNAME);
if ( pDocHierarchItem )
StreamPath = pDocHierarchItem->GetValue();
}
@@ -735,23 +730,23 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
if( !StreamPath.isEmpty() )
{
- xInfoSet->setPropertyValue( "StreamRelPath", makeAny( StreamPath ) );
+ xInfoSet->setPropertyValue( "StreamRelPath", Any( StreamPath ) );
}
}
rtl::Reference<SwDoc> aHoldRef(&rDoc); // prevent deletion
- ErrCode nRet = ERRCODE_NONE;
+ ErrCodeMsg nRet = ERRCODE_NONE;
// save redline mode into import info property set
- const OUString sShowChanges("ShowChanges");
- const OUString sRecordChanges("RecordChanges");
- const OUString sRedlineProtectionKey("RedlineProtectionKey");
+ static constexpr OUString sShowChanges(u"ShowChanges"_ustr);
+ static constexpr OUString sRecordChanges(u"RecordChanges"_ustr);
+ static constexpr OUString sRedlineProtectionKey(u"RedlineProtectionKey"_ustr);
xInfoSet->setPropertyValue( sShowChanges,
- makeAny(IDocumentRedlineAccess::IsShowChanges(rDoc.getIDocumentRedlineAccess().GetRedlineFlags())) );
+ Any(IDocumentRedlineAccess::IsShowChanges(rDoc.getIDocumentRedlineAccess().GetRedlineFlags())) );
xInfoSet->setPropertyValue( sRecordChanges,
- makeAny(IDocumentRedlineAccess::IsRedlineOn(rDoc.getIDocumentRedlineAccess().GetRedlineFlags())) );
+ Any(IDocumentRedlineAccess::IsRedlineOn(rDoc.getIDocumentRedlineAccess().GetRedlineFlags())) );
xInfoSet->setPropertyValue( sRedlineProtectionKey,
- makeAny(rDoc.getIDocumentRedlineAccess().GetRedlinePassword()) );
+ Any(rDoc.getIDocumentRedlineAccess().GetRedlinePassword()) );
// force redline mode to "none"
rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::NONE );
@@ -762,13 +757,13 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
const bool bShapePositionInHoriL2R = !bOASIS;
xInfoSet->setPropertyValue(
"ShapePositionInHoriL2R",
- makeAny( bShapePositionInHoriL2R ) );
+ Any( bShapePositionInHoriL2R ) );
}
{
const bool bTextDocInOOoFileFormat = !bOASIS;
xInfoSet->setPropertyValue(
"TextDocInOOoFileFormat",
- makeAny( bTextDocInOOoFileFormat ) );
+ Any( bTextDocInOOoFileFormat ) );
}
ErrCode nWarnRDF = ERRCODE_NONE;
@@ -811,13 +806,13 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
// read storage streams
// #i103539#: always read meta.xml for generator
- ErrCode const nWarn = ReadThroughComponent(
+ ErrCodeMsg const nWarn = ReadThroughComponent(
xStorage, xModelComp, "meta.xml", xContext,
(bOASIS ? "com.sun.star.comp.Writer.XMLOasisMetaImporter"
: "com.sun.star.comp.Writer.XMLMetaImporter"),
aEmptyArgs, rName, false );
- ErrCode nWarn2 = ERRCODE_NONE;
+ ErrCodeMsg nWarn2 = ERRCODE_NONE;
if( !(IsOrganizerMode() || IsBlockMode() || m_aOption.IsFormatsOnly() ||
m_bInsertMode) )
{
@@ -844,7 +839,10 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
if( !IsOrganizerMode() && !IsBlockMode() && !m_bInsertMode &&
!m_aOption.IsFormatsOnly() &&
// sw_redlinehide: disable layout cache for now
- *o3tl::doAccess<bool>(xInfoSet->getPropertyValue(sShowChanges)))
+ *o3tl::doAccess<bool>(xInfoSet->getPropertyValue(sShowChanges)) &&
+ // sw_fieldmarkhide: also disable if there is a fieldmark
+ rDoc.getIDocumentMarkAccess()->getFieldmarksBegin()
+ == rDoc.getIDocumentMarkAccess()->getFieldmarksEnd())
{
try
{
@@ -866,6 +864,8 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
nRet = nRet ? nRet : (nWarn ? nWarn : (nWarn2 ? nWarn2 : nWarnRDF ) );
+ ::svx::DropUnusedNamedItems(xModelComp);
+
m_aOption.ResetAllFormatsOnly();
// redline password
@@ -946,7 +946,7 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
if( xModelSet.is() )
{
uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() );
- const OUString sName("BuildId" );
+ static constexpr OUString sName(u"BuildId"_ustr );
if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sName) )
{
xModelSet->setPropertyValue( sName, xInfoSet->getPropertyValue(sName) );
@@ -954,6 +954,9 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
}
}
+ // tdf#115815 restore annotation ranges stored in temporary bookmarks
+ rDoc.getIDocumentMarkAccess()->restoreAnnotationMarks();
+
if (xStatusIndicator.is())
{
xStatusIndicator->end();
@@ -976,7 +979,7 @@ size_t XMLReader::GetSectionList( SfxMedium& rMedium,
try
{
xml::sax::InputSource aParserInput;
- const OUString sDocName( "content.xml" );
+ static constexpr OUString sDocName( u"content.xml"_ustr );
aParserInput.sSystemId = sDocName;
uno::Reference < io::XStream > xStm = xStg2->openStreamElement( sDocName, embed::ElementModes::READ );