summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitEnums.h24
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx6
-rw-r--r--sw/qa/extras/tiledrendering/tiledrendering.cxx32
-rw-r--r--sw/source/core/doc/docredln.cxx43
-rw-r--r--sw/source/core/inc/unoport.hxx3
-rw-r--r--sw/source/core/unocore/unoredline.cxx8
6 files changed, 111 insertions, 5 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 651e9bc65707..2c3bcabc496c 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -406,6 +406,30 @@ typedef enum
*/
LOK_CALLBACK_VIEW_LOCK,
+ /**
+ * The size of the change tracking table has changed.
+ *
+ * The payload example:
+ * {
+ * "redline": {
+ * "action": "Remove",
+ * "index": "1",
+ * "author": "Unknown Author",
+ * "type": "Delete",
+ * "comment": "",
+ * "dateTime": "2016-08-18T12:14:00"
+ * }
+ * }
+ *
+ * The format is the same as an entry of
+ * lok::Document::getCommandValues('.uno:AcceptTrackedChanges'), extra
+ * fields:
+ *
+ * - 'action' is either 'Add' or 'Remove', depending on if this is an
+ * insertion into the table or a removal.
+ */
+ LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED,
+
}
LibreOfficeKitCallbackType;
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index f3dbc6a73017..3c8640f19ea5 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -417,6 +417,8 @@ callbackTypeToString (int nType)
return "LOK_CALLBACK_CELL_FORMULA";
case LOK_CALLBACK_VIEW_LOCK:
return "LOK_CALLBACK_VIEW_LOCK";
+ case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
+ return "LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED";
}
g_assert(false);
return nullptr;
@@ -1324,6 +1326,10 @@ callback (gpointer pData)
gtk_widget_queue_draw(GTK_WIDGET(pDocView));
break;
}
+ case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
+ {
+ break;
+ }
default:
g_assert(false);
break;
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 8cc29776b79c..e5d6f240e1d4 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -69,6 +69,7 @@ public:
void testShapeTextUndoShells();
void testShapeTextUndoGroupShells();
void testTrackChanges();
+ void testTrackChangesCallback();
CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
CPPUNIT_TEST(testRegisterCallback);
@@ -102,6 +103,7 @@ public:
CPPUNIT_TEST(testShapeTextUndoShells);
CPPUNIT_TEST(testShapeTextUndoGroupShells);
CPPUNIT_TEST(testTrackChanges);
+ CPPUNIT_TEST(testTrackChangesCallback);
CPPUNIT_TEST_SUITE_END();
private:
@@ -117,13 +119,15 @@ private:
int m_nSelectionBeforeSearchResult;
int m_nSelectionAfterSearchResult;
int m_nInvalidations;
+ int m_nRedlineTableSizeChanged;
};
SwTiledRenderingTest::SwTiledRenderingTest()
: m_bFound(true),
m_nSelectionBeforeSearchResult(0),
m_nSelectionAfterSearchResult(0),
- m_nInvalidations(0)
+ m_nInvalidations(0),
+ m_nRedlineTableSizeChanged(0)
{
}
@@ -197,6 +201,11 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
}
}
break;
+ case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
+ {
+ ++m_nRedlineTableSizeChanged;
+ }
+ break;
}
}
@@ -1170,6 +1179,27 @@ void SwTiledRenderingTest::testTrackChanges()
comphelper::LibreOfficeKit::setActive(false);
}
+void SwTiledRenderingTest::testTrackChangesCallback()
+{
+ // Load a document.
+ comphelper::LibreOfficeKit::setActive();
+ SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
+ SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+ pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback, this);
+
+ // Turn on track changes and type "x".
+ uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY);
+ xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true));
+ m_nRedlineTableSizeChanged = 0;
+ pWrtShell->Insert("x");
+
+ // Assert that we get exactly one notification about the redline insert.
+ // This was 0, as LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED wasn't sent.
+ CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableSizeChanged);
+
+ comphelper::LibreOfficeKit::setActive(false);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index df26133c26b3..b7b1c8a9cbe8 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -18,6 +18,8 @@
*/
#include <libxml/xmlwriter.h>
+#include <boost/property_tree/json_parser.hpp>
+
#include <tools/datetimeutils.hxx>
#include <hintids.hxx>
#include <svl/itemiter.hxx>
@@ -25,6 +27,10 @@
#include <editeng/colritem.hxx>
#include <editeng/udlnitem.hxx>
#include <editeng/crossedoutitem.hxx>
+#include <comphelper/lok.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <unotools/datetime.hxx>
+#include <sfx2/viewsh.hxx>
#include <swmodule.hxx>
#include <doc.hxx>
#include <docredln.hxx>
@@ -47,6 +53,7 @@
#include <rootfrm.hxx>
#include <comcore.hrc>
+#include <unoport.hxx>
using namespace com::sun::star;
@@ -291,12 +298,42 @@ bool SwExtraRedlineTable::DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox&
return bChg;
}
+/// Emits LOK notification about one addition / removal of a redline item.
+static void lcl_RedlineNotification(bool bAdd, size_t nPos, SwRangeRedline* pRedline)
+{
+ if (!comphelper::LibreOfficeKit::isActive())
+ return;
+
+ boost::property_tree::ptree aRedline;
+ aRedline.put("action", (bAdd ? "Add" : "Remove"));
+ aRedline.put("index", nPos);
+ aRedline.put("author", pRedline->GetAuthorString(1).toUtf8().getStr());
+ aRedline.put("type", SwRedlineTypeToOUString(pRedline->GetRedlineData().GetType()).toUtf8().getStr());
+ aRedline.put("comment", pRedline->GetRedlineData().GetComment().toUtf8().getStr());
+ OUString sDateTime = utl::toISO8601(pRedline->GetRedlineData().GetTimeStamp().GetUNODateTime());
+ aRedline.put("dateTime", sDateTime.toUtf8().getStr());
+ boost::property_tree::ptree aTree;
+ aTree.add_child("redline", aRedline);
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ std::string aPayload = aStream.str();
+
+ SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+ while (pViewShell)
+ {
+ pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED, aPayload.c_str());
+ pViewShell = SfxViewShell::GetNext(*pViewShell);
+ }
+}
+
+
bool SwRedlineTable::Insert( SwRangeRedline* p, bool bIns )
{
if( p->HasValidRange() )
{
std::pair<vector_type::const_iterator, bool> rv = maVector.insert( p );
size_t nP = rv.first - begin();
+ lcl_RedlineNotification(/*bAdd=*/true, nP, p);
p->CallDisplayFunc(0, nP);
return rv.second;
}
@@ -464,6 +501,7 @@ bool SwRedlineTable::Remove( const SwRangeRedline* p )
void SwRedlineTable::Remove( sal_uInt16 nP )
{
+ lcl_RedlineNotification(/*bAdd=*/false, nP, maVector[nP]);
SwDoc* pDoc = nullptr;
if( !nP && 1 == size() )
pDoc = maVector.front()->GetDoc();
@@ -487,8 +525,13 @@ void SwRedlineTable::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL )
if( !nP && nL && nL == size() )
pDoc = maVector.front()->GetDoc();
+ size_t nCount = 0;
for( vector_type::const_iterator it = maVector.begin() + nP; it != maVector.begin() + nP + nL; ++it )
+ {
+ lcl_RedlineNotification(/*bAdd=*/false, nP + nCount, *it);
delete *it;
+ ++nCount;
+ }
maVector.erase( maVector.begin() + nP, maVector.begin() + nP + nL );
SwViewShell* pSh;
diff --git a/sw/source/core/inc/unoport.hxx b/sw/source/core/inc/unoport.hxx
index 8b9e72426f1c..1003448428f5 100644
--- a/sw/source/core/inc/unoport.hxx
+++ b/sw/source/core/inc/unoport.hxx
@@ -42,6 +42,7 @@
#include <unocrsr.hxx>
#include <calbck.hxx>
#include <unobaseclass.hxx>
+#include <IDocumentRedlineAccess.hxx>
class SwFormatField;
class SwFrameFormat;
@@ -312,6 +313,8 @@ public:
css::uno::RuntimeException, std::exception) 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 bd4d51bae2a2..093d247a7850 100644
--- a/sw/source/core/unocore/unoredline.cxx
+++ b/sw/source/core/unocore/unoredline.cxx
@@ -189,7 +189,7 @@ SwXRedlinePortion::~SwXRedlinePortion()
{
}
-static OUString lcl_RedlineTypeToOUString(RedlineType_t eType)
+OUString SwRedlineTypeToOUString(RedlineType_t eType)
{
OUString sRet;
switch(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)
@@ -221,7 +221,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 <<= lcl_RedlineTypeToOUString(pNext->GetType());
+ pValues[3].Value <<= SwRedlineTypeToOUString(pNext->GetType());
}
return aValues;
}
@@ -289,7 +289,7 @@ uno::Any SwXRedlinePortion::GetPropertyValue( const OUString& rPropertyName, co
aRet <<= rRedline.GetComment();
else if(rPropertyName == UNO_NAME_REDLINE_TYPE)
{
- aRet <<= lcl_RedlineTypeToOUString(rRedline.GetType());
+ aRet <<= SwRedlineTypeToOUString(rRedline.GetType());
}
else if(rPropertyName == UNO_NAME_REDLINE_SUCCESSOR_DATA)
{
@@ -327,7 +327,7 @@ uno::Sequence< beans::PropertyValue > SwXRedlinePortion::CreateRedlineProperties
pRet[nPropIdx].Name = UNO_NAME_REDLINE_COMMENT;
pRet[nPropIdx++].Value <<= rRedline.GetComment();
pRet[nPropIdx].Name = UNO_NAME_REDLINE_TYPE;
- pRet[nPropIdx++].Value <<= lcl_RedlineTypeToOUString(rRedline.GetType());
+ pRet[nPropIdx++].Value <<= 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) ) );