Rebased ref, commits from common ancestor: commit 7b673a8524e43cfd2b445d386465d71d82e97dc5 Author: Rosemary Sebastian <rosemary.s...@gmail.com> Date: Mon Jul 11 19:58:40 2016 +0530
WIP Insert redline into document Change-Id: I477ef0dc0e62b83059dc5877746c16071a88507b diff --git a/include/xmloff/XMLTrackedChangesImportContext.hxx b/include/xmloff/XMLTrackedChangesImportContext.hxx index c3a4414..f19052a 100644 --- a/include/xmloff/XMLTrackedChangesImportContext.hxx +++ b/include/xmloff/XMLTrackedChangesImportContext.hxx @@ -57,6 +57,15 @@ public: /// redline date OUString sDate; + /// redline date + OUString sStart; + + /// redline date + OUString sEnd; + + /// redline date + OUString sType; + /// merge-last-paragraph flag bool bMergeLastPara; @@ -79,7 +88,8 @@ public: void SetChangeInfo(const OUString& rType, const OUString& rAuthor, const OUString& rComment, - const OUString& rDate); + const OUString& rDate, + const sal_uInt32); /// create redline XText/XTextCursor on demand and register with /// XMLTextImportHelper diff --git a/include/xmloff/txtimp.hxx b/include/xmloff/txtimp.hxx index 92f2bf9..12825dd 100644 --- a/include/xmloff/txtimp.hxx +++ b/include/xmloff/txtimp.hxx @@ -389,6 +389,8 @@ private: std::shared_ptr<BackpatcherImpl> m_xBackpatcherImpl; static std::shared_ptr<BackpatcherImpl> MakeBackpatcherImpl(); + sal_Int16 nParaIdx = 0; + bool bInsertRedline = false; protected: virtual SvXMLImportContext *CreateTableChildContext( SvXMLImport& rImport, @@ -665,7 +667,8 @@ public: /// date+time const css::util::DateTime& rDateTime, /// merge last paras - bool bMergeLastParagraph); + bool bMergeLastParagraph, + const sal_uInt32 nStartParaPos); virtual css::uno::Reference< css::text::XTextCursor> RedlineCreateText( /// needed to get the document @@ -673,6 +676,10 @@ public: /// ID used to RedlineAdd() call const OUString& rId); + virtual bool CheckRedlineExists( + /// ID used to RedlineAdd() call + const OUString& rId); + virtual void RedlineSetCursor( /// ID used to RedlineAdd() call const OUString& rId, diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx index 0952c46..7a8d992 100644 --- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx +++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx @@ -195,6 +195,7 @@ public: OUString sComment; // change comment string util::DateTime aDateTime; // change DateTime bool bMergeLastParagraph; // the SwRangeRedline::IsDelLastPara flag + sal_uInt32 nStartParagraphPos; // each position can may be either empty, an XTextRange, or an SwNodeIndex @@ -373,7 +374,8 @@ void XMLRedlineImportHelper::Add( const OUString& rAuthor, const OUString& rComment, const util::DateTime& rDateTime, - bool bMergeLastPara) + bool bMergeLastPara, + const sal_uInt32 nStartParaPos) { // we need to do the following: // 1) parse type string @@ -411,6 +413,7 @@ void XMLRedlineImportHelper::Add( pInfo->sComment = rComment; pInfo->aDateTime = rDateTime; pInfo->bMergeLastParagraph = bMergeLastPara; + pInfo->nStartParagraphPos = nStartParaPos; // ad 3) if (aRedlineMap.end() == aRedlineMap.find(rId)) @@ -487,6 +490,17 @@ Reference<XTextCursor> XMLRedlineImportHelper::CreateRedlineTextSection( return xReturn; } +bool XMLRedlineImportHelper::Check( + const OUString& rId) +{ + RedlineMapType::iterator aFind = aRedlineMap.find(rId); + if (aRedlineMap.end() != aFind) + { + return true; + } + return false; +} + void XMLRedlineImportHelper::SetCursor( const OUString& rId, bool bStart, diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.hxx b/sw/source/filter/xml/XMLRedlineImportHelper.hxx index f78866b..240c36c 100644 --- a/sw/source/filter/xml/XMLRedlineImportHelper.hxx +++ b/sw/source/filter/xml/XMLRedlineImportHelper.hxx @@ -76,7 +76,8 @@ public: const OUString& rAuthor, // name of the author const OUString& rComment, // redline comment const css::util::DateTime& rDateTime, // date+time - bool bMergeLastParagraph); // merge last paragraph? + bool bMergeLastParagraph, // merge last paragraph? + const sal_uInt32 nStartParaPos); // start paragraph position // create a text section for the redline, and return an // XText/XTextCursor that may be used to write into it. @@ -84,6 +85,9 @@ public: css::uno::Reference<css::text::XTextCursor> xOldCursor, // needed to get the document const OUString& rId); // ID used to RedlineAdd() call + bool Check( + const OUString& rId); // ID used in RedlineAdd() call + // Set start or end position for a redline in the text body. // Accepts XTextRange objects. void SetCursor( diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx index 95708ad..07de8e9 100644 --- a/sw/source/filter/xml/swxml.cxx +++ b/sw/source/filter/xml/swxml.cxx @@ -870,17 +870,17 @@ sal_uLong XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, c if( !nRet && !(IsOrganizerMode() || aOpt.IsFormatsOnly()) ) nRet = ReadThroughComponent( - xStorage, xModelComp, "content.xml", "Content.xml", xContext, - (bOASIS ? "com.sun.star.comp.Writer.XMLOasisContentImporter" - : "com.sun.star.comp.Writer.XMLContentImporter"), + xStorage, xModelComp, "undo.xml", nullptr, xContext, + (bOASIS ? "com.sun.star.comp.Writer.XMLOasisUndoImporter" + : "com.sun.star.comp.Writer.XMLUndoImporter"), aFilterArgs, rName, true ); if( !nRet && !(IsOrganizerMode() || aOpt.IsFormatsOnly()) ) nRet = ReadThroughComponent( - xStorage, xModelComp, "undo.xml", nullptr, xContext, - (bOASIS ? "com.sun.star.comp.Writer.XMLOasisUndoImporter" - : "com.sun.star.comp.Writer.XMLUndoImporter"), - aEmptyArgs, rName, true ); + xStorage, xModelComp, "content.xml", "Content.xml", xContext, + (bOASIS ? "com.sun.star.comp.Writer.XMLOasisContentImporter" + : "com.sun.star.comp.Writer.XMLContentImporter"), + aFilterArgs, rName, true ); if( !(IsOrganizerMode() || IsBlockMode() || bInsertMode || aOpt.IsFormatsOnly() ) ) diff --git a/sw/source/filter/xml/xmltexti.cxx b/sw/source/filter/xml/xmltexti.cxx index 710f010..d103310 100644 --- a/sw/source/filter/xml/xmltexti.cxx +++ b/sw/source/filter/xml/xmltexti.cxx @@ -976,13 +976,14 @@ void SwXMLTextImportHelper::RedlineAdd( const OUString& rAuthor, const OUString& rComment, const util::DateTime& rDateTime, - bool bMergeLastPara) + bool bMergeLastPara, + const sal_uInt32 nStartParaPos) { // create redline helper on demand OSL_ENSURE(nullptr != pRedlineHelper, "helper should have been created in constructor"); if (nullptr != pRedlineHelper) pRedlineHelper->Add(rType, rId, rAuthor, rComment, rDateTime, - bMergeLastPara); + bMergeLastPara, nStartParaPos); } uno::Reference<XTextCursor> SwXMLTextImportHelper::RedlineCreateText( @@ -999,6 +1000,15 @@ uno::Reference<XTextCursor> SwXMLTextImportHelper::RedlineCreateText( return xRet; } +bool SwXMLTextImportHelper::CheckRedlineExists( + const OUString& rId) +{ + if(pRedlineHelper != nullptr) + return pRedlineHelper->Check(rId); + return false; + // else: ignore redline (wasn't added before, else we'd have a helper) +} + void SwXMLTextImportHelper::RedlineSetCursor( const OUString& rId, bool bStart, diff --git a/sw/source/filter/xml/xmltexti.hxx b/sw/source/filter/xml/xmltexti.hxx index 1d19ebf..57d334f 100644 --- a/sw/source/filter/xml/xmltexti.hxx +++ b/sw/source/filter/xml/xmltexti.hxx @@ -91,10 +91,13 @@ public: const OUString& rAuthor, /// name of the author const OUString& rComment, /// redline comment const css::util::DateTime& rDateTime, /// date+time - bool bMergeLastPara) override; /// merge last paragraph + bool bMergeLastPara, /// merge last paragraph + const sal_uInt32 nStartParaPos) override; virtual css::uno::Reference<css::text::XTextCursor> RedlineCreateText( css::uno::Reference<css::text::XTextCursor> & rOldCursor, /// needed to get the document const OUString& rId) override; /// ID used to RedlineAdd() call + virtual bool CheckRedlineExists( + const OUString& rId) override; /// ID used to RedlineAdd() call virtual void RedlineSetCursor( const OUString& rId, /// ID used to RedlineAdd() call bool bStart, /// start or end Cursor diff --git a/xmloff/source/text/XMLChangeInfoContext.cxx b/xmloff/source/text/XMLChangeInfoContext.cxx index 48ec705..f6848f7 100644 --- a/xmloff/source/text/XMLChangeInfoContext.cxx +++ b/xmloff/source/text/XMLChangeInfoContext.cxx @@ -89,10 +89,6 @@ SvXMLImportContext* XMLChangeInfoContext::CreateChildContext( void XMLChangeInfoContext::EndElement() { - // set values at changed region context - rChangedRegion.SetChangeInfo(rType, sAuthorBuffer.makeStringAndClear(), - sCommentBuffer.makeStringAndClear(), - sDateTimeBuffer.makeStringAndClear()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/XMLChangedRegionImportContext.cxx b/xmloff/source/text/XMLChangedRegionImportContext.cxx index 3622eb3..a0b2dc0 100644 --- a/xmloff/source/text/XMLChangedRegionImportContext.cxx +++ b/xmloff/source/text/XMLChangedRegionImportContext.cxx @@ -149,18 +149,4 @@ void XMLChangedRegionImportContext::EndElement() } } -void XMLChangedRegionImportContext::SetChangeInfo( - const OUString& rType, - const OUString& rAuthor, - const OUString& rComment, - const OUString& rDate) -{ - util::DateTime aDateTime; - if (::sax::Converter::parseDateTime(aDateTime, nullptr, rDate)) - { - GetImport().GetTextImport()->RedlineAdd( - rType, sID, rAuthor, rComment, aDateTime, bMergeLastPara); - } -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/XMLChangedRegionImportContext.hxx b/xmloff/source/text/XMLChangedRegionImportContext.hxx index d858118..398bedc 100644 --- a/xmloff/source/text/XMLChangedRegionImportContext.hxx +++ b/xmloff/source/text/XMLChangedRegionImportContext.hxx @@ -71,12 +71,6 @@ public: virtual void EndElement() override; - /// change info: To be called from change-info context - void SetChangeInfo(const OUString& rType, - const OUString& rAuthor, - const OUString& rComment, - const OUString& rDate); - /// create redline XText/XTextCursor on demand and register with /// XMLTextImportHelper void UseRedlineText(); diff --git a/xmloff/source/text/XMLTrackedChangesImportContext.cxx b/xmloff/source/text/XMLTrackedChangesImportContext.cxx index a0f6861..ffe4659 100644 --- a/xmloff/source/text/XMLTrackedChangesImportContext.cxx +++ b/xmloff/source/text/XMLTrackedChangesImportContext.cxx @@ -101,6 +101,7 @@ SvXMLImportContext* XMLTrackedChangesImportContext::CreateChildContext( const Reference<XAttributeList> & xAttrList) { SvXMLImportContext* pContext = nullptr; + sal_uInt32 nStartParaPos, nEndParaPos, nStartTextPos, nEndTextPos; if (XML_NAMESPACE_TEXT == nPrefix) { @@ -122,11 +123,32 @@ SvXMLImportContext* XMLTrackedChangesImportContext::CreateChildContext( { if (IsXMLToken(sLocalName, xmloff::token::XML_START)) { - sID = sValue; + sStart = sValue.pData->buffer + 1; + } + if (IsXMLToken(sLocalName, XML_END)) + { + sEnd = sValue; + } + } + if (XML_NAMESPACE_DC == nPrefix) + { + if (IsXMLToken(sLocalName, XML_TYPE)) + { + sType = sValue; } } } - SetChangeInfo( rLocalName, sAuthor, sComment, sDate ); + if(sStart.indexOf('/') != -1) + { + sID = OUString(sStart.getStr(), sStart.indexOf('/')); + nStartParaPos = sID.toUInt32(); + } + else + { + nStartParaPos = sStart.toUInt32(); + sID = sStart; + } + SetChangeInfo( rLocalName, sAuthor, sComment, sDate, nStartParaPos ); // create XMLChangeElementImportContext for all kinds of changes pContext = new XMLChangeElementImportContext( @@ -156,13 +178,13 @@ SvXMLImportContext* XMLTrackedChangesImportContext::CreateChildContext( return pContext; } -void XMLTrackedChangesImportContext::SetChangeInfo(const OUString& rType, const OUString& rAuthor, const OUString& rComment, const OUString& rDate) +void XMLTrackedChangesImportContext::SetChangeInfo(const OUString& rType, const OUString& rAuthor, const OUString& rComment, const OUString& rDate, const sal_uInt32 nStartParaPos) { util::DateTime aDateTime; if (::sax::Converter::parseDateTime(aDateTime, nullptr, rDate)) { GetImport().GetTextImport()->RedlineAdd( - rType, sID, rAuthor, rComment, aDateTime, bMergeLastPara); + rType, sID, rAuthor, rComment, aDateTime, bMergeLastPara, nStartParaPos); } } diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx index 44fd180..11fed00 100644 --- a/xmloff/source/text/txtimp.cxx +++ b/xmloff/source/text/txtimp.cxx @@ -2146,14 +2146,16 @@ SvXMLImportContext *XMLTextImportHelper::CreateTextChildContext( bool bHeading = false; bool bContent = true; sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName ); + OUString sParaIdx; switch( nToken ) { case XML_TOK_TEXT_H: bHeading = true; case XML_TOK_TEXT_P: + sParaIdx = OUString::number(++nParaIdx); pContext = new XMLParaContext( rImport, nPrefix, rLocalName, - xAttrList, bHeading ); + xAttrList, bHeading, bInsertRedline ); if (m_xImpl->m_bProgress && XML_TEXT_TYPE_SHAPE != eType) { rImport.GetProgressBarHelper()->Increment(); @@ -2732,7 +2734,8 @@ void XMLTextImportHelper::RedlineAdd( const OUString& /*rType*/, const OUString& /*rAuthor*/, const OUString& /*rComment*/, const util::DateTime& /*rDateTime*/, - bool /*bMergeLastPara*/) + bool /*bMergeLastPara*/, + const sal_uInt32 /*nStartParaPos*/) { // dummy implementation: do nothing } @@ -2747,6 +2750,12 @@ Reference<XTextCursor> XMLTextImportHelper::RedlineCreateText( return xRet; } +bool XMLTextImportHelper::CheckRedlineExists( + const OUString& rId) +{ + return true; +} + void XMLTextImportHelper::RedlineSetCursor( const OUString& /*rId*/, bool /*bStart*/, diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx index 5570bf3..cb3b7b1 100644 --- a/xmloff/source/text/txtparai.cxx +++ b/xmloff/source/text/txtparai.cxx @@ -1819,7 +1819,8 @@ XMLParaContext::XMLParaContext( sal_uInt16 nPrfx, const OUString& rLName, const Reference< xml::sax::XAttributeList > & xAttrList, - bool bHead ) : + bool bHead, + bool bInsertRedln) : SvXMLImportContext( rImport, nPrfx, rLName ), xStart( rImport.GetTextImport()->GetCursorAsRange()->getStart() ), m_bHaveAbout(false), @@ -1829,6 +1830,7 @@ XMLParaContext::XMLParaContext( mbOutlineLevelAttrFound( false ), bIgnoreLeadingSpace( true ), bHeading( bHead ), + bInsertRedline( bInsertRedln ), bIsListHeader( false ), bIsRestart (false), nStartValue(0), diff --git a/xmloff/source/text/txtparai.hxx b/xmloff/source/text/txtparai.hxx index 7c59418..8124806 100644 --- a/xmloff/source/text/txtparai.hxx +++ b/xmloff/source/text/txtparai.hxx @@ -49,6 +49,7 @@ class XMLParaContext : public SvXMLImportContext bool mbOutlineLevelAttrFound; bool bIgnoreLeadingSpace; bool bHeading; + bool bInsertRedline; bool bIsListHeader; bool bIsRestart; sal_Int16 nStartValue; @@ -61,7 +62,8 @@ public: sal_uInt16 nPrfx, const OUString& rLName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, - bool bHeading ); + bool bHeading, + bool bInsertRedln = false ); virtual ~XMLParaContext(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits