[Libreoffice-commits] core.git: desktop/source sw/inc sw/source

Pranav Kant pranavk at collabora.co.uk
Wed Mar 8 06:45:33 UTC 2017


 desktop/source/lib/init.cxx           |    5 ++-
 sw/inc/IDocumentRedlineAccess.hxx     |   15 ++++++++++
 sw/inc/unotxdoc.hxx                   |    2 +
 sw/source/core/doc/docredln.cxx       |    2 -
 sw/source/core/inc/unoport.hxx        |    2 -
 sw/source/core/unocore/unoredline.cxx |   21 ++-------------
 sw/source/uibase/uno/unotxdoc.cxx     |   47 ++++++++++++++++++++++++++++++++++
 7 files changed, 72 insertions(+), 22 deletions(-)

New commits:
commit e6cca48bc9deb1049f8d501406269b71f91511ca
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Mar 3 14:57:39 2017 +0530

    lok: Do not use UNO for fetching tracked changes
    
    See inline comment for reasons.
    
    Also, move the SwRedlineTypeToOUString function as inline to same header
    file containing redline types.
    
    Change-Id: I9b4be4f104c095b2ccd8287d935347c81fd25974
    Reviewed-on: https://gerrit.libreoffice.org/34950
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: pranavk <pranavk at collabora.co.uk>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 5ba852e..5d0dfc2 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2484,7 +2484,10 @@ static char* getTrackedChanges(LibreOfficeKitDocument* pThis)
 
     uno::Reference<document::XRedlinesSupplier> xRedlinesSupplier(pDocument->mxComponent, uno::UNO_QUERY);
     std::stringstream aStream;
-    if (xRedlinesSupplier.is())
+    // We want positions of the track changes also which is not possible from
+    // UNO. Enable positioning information for text documents only for now, so
+    // construct the tracked changes JSON from inside the sw/, not here using UNO
+    if (doc_getDocumentType(pThis) != LOK_DOCTYPE_TEXT && xRedlinesSupplier.is())
     {
         uno::Reference<container::XEnumeration> xRedlines = xRedlinesSupplier->getRedlines()->createEnumeration();
         boost::property_tree::ptree aRedlines;
diff --git a/sw/inc/IDocumentRedlineAccess.hxx b/sw/inc/IDocumentRedlineAccess.hxx
index 7165032..47fab85 100644
--- a/sw/inc/IDocumentRedlineAccess.hxx
+++ b/sw/inc/IDocumentRedlineAccess.hxx
@@ -82,6 +82,21 @@ namespace nsRedlineType_t
     // When larger than 128, flags can be inserted.
     const RedlineType_t REDLINE_NO_FLAG_MASK = 0x7F;
     const RedlineType_t REDLINE_FORM_AUTOFMT = 0x80;// Can be a flag in RedlineType.
+
+    inline OUString SwRedlineTypeToOUString(RedlineType_t eType)
+    {
+        OUString sRet;
+        switch(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)
+        {
+            case nsRedlineType_t::REDLINE_INSERT: sRet = "Insert"; break;
+            case nsRedlineType_t::REDLINE_DELETE: sRet = "Delete"; break;
+            case nsRedlineType_t::REDLINE_FORMAT: sRet = "Format"; break;
+            case nsRedlineType_t::REDLINE_PARAGRAPH_FORMAT: sRet = "ParagraphFormat"; break;
+            case nsRedlineType_t::REDLINE_TABLE:  sRet = "TextTable"; break;
+            case nsRedlineType_t::REDLINE_FMTCOLL:sRet = "Style"; break;
+        }
+        return sRet;
+    }
 }
 
 class IDocumentRedlineAccess
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index aeb5561..8e9e2209 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -417,6 +417,8 @@ public:
     virtual void setClientVisibleArea(const Rectangle& rRectangle) override;
     /// @see vcl::ITiledRenderable::getPointer().
     virtual Pointer getPointer() override;
+    /// @see vcl::ITiledRenderable::getTrackedChanges().
+    OUString getTrackedChanges() override;
     /// @see vcl::ITiledRenderable::getTrackedChangeAuthors().
     OUString getTrackedChangeAuthors() override;
     /// @see vcl::ITiledRenderable::getPostIts().
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index c9f329b..d6cf1c9 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -315,7 +315,7 @@ static void lcl_RedlineNotification(RedlineNotification nType, SwRedlineTable::s
                              (nType == RedlineNotification::Modify ? "Modify" : "???"))));
     aRedline.put("index", nPos);
     aRedline.put("author", pRedline->GetAuthorString(1).toUtf8().getStr());
-    aRedline.put("type", SwRedlineTypeToOUString(pRedline->GetRedlineData().GetType()).toUtf8().getStr());
+    aRedline.put("type", nsRedlineType_t::SwRedlineTypeToOUString(pRedline->GetRedlineData().GetType()).toUtf8().getStr());
     aRedline.put("comment", pRedline->GetRedlineData().GetComment().toUtf8().getStr());
     aRedline.put("description", pRedline->GetDescr().toUtf8().getStr());
     OUString sDateTime = utl::toISO8601(pRedline->GetRedlineData().GetTimeStamp().GetUNODateTime());
diff --git a/sw/source/core/inc/unoport.hxx b/sw/source/core/inc/unoport.hxx
index 5eed389..539d6b9 100644
--- a/sw/source/core/inc/unoport.hxx
+++ b/sw/source/core/inc/unoport.hxx
@@ -303,8 +303,6 @@ public:
             const OUString& rPropertyName) override;
 };
 
-OUString SwRedlineTypeToOUString(RedlineType_t eType);
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unoredline.cxx b/sw/source/core/unocore/unoredline.cxx
index d1b5b08..eb153b6 100644
--- a/sw/source/core/unocore/unoredline.cxx
+++ b/sw/source/core/unocore/unoredline.cxx
@@ -183,21 +183,6 @@ SwXRedlinePortion::~SwXRedlinePortion()
 {
 }
 
-OUString SwRedlineTypeToOUString(RedlineType_t eType)
-{
-    OUString sRet;
-    switch(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)
-    {
-        case nsRedlineType_t::REDLINE_INSERT: sRet = "Insert"; break;
-        case nsRedlineType_t::REDLINE_DELETE: sRet = "Delete"; break;
-        case nsRedlineType_t::REDLINE_FORMAT: sRet = "Format"; break;
-        case nsRedlineType_t::REDLINE_PARAGRAPH_FORMAT: sRet = "ParagraphFormat"; break;
-        case nsRedlineType_t::REDLINE_TABLE:  sRet = "TextTable"; break;
-        case nsRedlineType_t::REDLINE_FMTCOLL:sRet = "Style"; break;
-    }
-    return sRet;
-}
-
 static uno::Sequence<beans::PropertyValue> lcl_GetSuccessorProperties(const SwRangeRedline& rRedline)
 {
     uno::Sequence<beans::PropertyValue> aValues(4);
@@ -215,7 +200,7 @@ static uno::Sequence<beans::PropertyValue> lcl_GetSuccessorProperties(const SwRa
         pValues[2].Name = UNO_NAME_REDLINE_COMMENT;
         pValues[2].Value <<= pNext->GetComment();
         pValues[3].Name = UNO_NAME_REDLINE_TYPE;
-        pValues[3].Value <<= SwRedlineTypeToOUString(pNext->GetType());
+        pValues[3].Value <<= nsRedlineType_t::SwRedlineTypeToOUString(pNext->GetType());
     }
     return aValues;
 }
@@ -284,7 +269,7 @@ uno::Any  SwXRedlinePortion::GetPropertyValue( const OUString& rPropertyName, co
         aRet <<= const_cast<SwRangeRedline&>(rRedline).GetDescr();
     else if(rPropertyName == UNO_NAME_REDLINE_TYPE)
     {
-        aRet <<= SwRedlineTypeToOUString(rRedline.GetType());
+        aRet <<= nsRedlineType_t::SwRedlineTypeToOUString(rRedline.GetType());
     }
     else if(rPropertyName == UNO_NAME_REDLINE_SUCCESSOR_DATA)
     {
@@ -324,7 +309,7 @@ uno::Sequence< beans::PropertyValue > SwXRedlinePortion::CreateRedlineProperties
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_DESCRIPTION;
     pRet[nPropIdx++].Value <<= const_cast<SwRangeRedline&>(rRedline).GetDescr();
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_TYPE;
-    pRet[nPropIdx++].Value <<= SwRedlineTypeToOUString(rRedline.GetType());
+    pRet[nPropIdx++].Value <<= nsRedlineType_t::SwRedlineTypeToOUString(rRedline.GetType());
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_IDENTIFIER;
     pRet[nPropIdx++].Value <<= OUString::number(
         sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(&rRedline) ) );
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 6c76474..66e26a1 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -144,6 +144,7 @@
 #include <svl/stylepool.hxx>
 #include <swatrset.hxx>
 #include <view.hxx>
+#include <viscrs.hxx>
 #include <srcview.hxx>
 #include <edtwin.hxx>
 #include <swdtflvr.hxx>
@@ -3179,6 +3180,52 @@ Pointer SwXTextDocument::getPointer()
     return pWrtShell->GetView().GetEditWin().GetPointer();
 }
 
+OUString SwXTextDocument::getTrackedChanges()
+{
+    const SwRedlineTable& rRedlineTable = pDocShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
+    boost::property_tree::ptree aTrackedChanges;
+    for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
+    {
+        boost::property_tree::ptree aTrackedChange;
+        aTrackedChange.put("index", i);
+        aTrackedChange.put("author", rRedlineTable[i]->GetAuthorString(1).toUtf8().getStr());
+        aTrackedChange.put("type", nsRedlineType_t::SwRedlineTypeToOUString(rRedlineTable[i]->GetRedlineData().GetType()).toUtf8().getStr());
+        aTrackedChange.put("comment", rRedlineTable[i]->GetRedlineData().GetComment().toUtf8().getStr());
+        aTrackedChange.put("description", rRedlineTable[i]->GetDescr().toUtf8().getStr());
+        OUString sDateTime = utl::toISO8601(rRedlineTable[i]->GetRedlineData().GetTimeStamp().GetUNODateTime());
+        aTrackedChange.put("dateTime", sDateTime.toUtf8().getStr());
+
+        SwContentNode* pContentNd = rRedlineTable[i]->GetContentNode();
+        SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
+        if (pView && pContentNd)
+        {
+            std::unique_ptr<SwShellCursor> pCursor(new SwShellCursor(pView->GetWrtShell(), *(rRedlineTable[i]->Start()) ));
+            pCursor->SetMark();
+            pCursor->GetMark()->nNode = *pContentNd;
+            pCursor->GetMark()->nContent.Assign(pContentNd, rRedlineTable[i]->End()->nContent.GetIndex());
+
+            pCursor->FillRects();
+
+            SwRects* pRects(pCursor.get());
+            std::vector<OString> aRects;
+            for(SwRect& rNextRect : *pRects)
+                aRects.push_back(rNextRect.SVRect().toString());
+
+            const OString sRects = comphelper::string::join("; ", aRects);
+            aTrackedChange.put("textRange", sRects.getStr());
+        }
+
+        aTrackedChanges.push_back(std::make_pair("", aTrackedChange));
+    }
+
+    boost::property_tree::ptree aTree;
+    aTree.add_child("redlines", aTrackedChanges);
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aTree);
+
+    return OUString::fromUtf8(aStream.str().c_str());
+}
+
 OUString SwXTextDocument::getTrackedChangeAuthors()
 {
     return SW_MOD()->GetRedlineAuthorInfo();


More information about the Libreoffice-commits mailing list