summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-08-19 15:27:59 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-08-19 16:21:32 +0200
commit0bc553f3ef3c188a96ea4875f4722ad4d40da4a3 (patch)
treead8252ca75b12743b7148487273151672401db4d /sw
parent3196e949bb23a33bdb8700dbe27782e0e6c8f1e6 (diff)
sw lok: add callbacks for redline table insertion / removal
An alternative would be to follow the Manage Changes dialog approach and subscribe to the SFX_HINT_DOCCHANGED notification in SwDocShell, cache the old redline table and find out the differences to the current one, but that way sound much more complex without benefits. Change-Id: I20a45285b88255ccea9d6646c0b5288ac1c91879
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/tiledrendering/tiledrendering.cxx32
-rw-r--r--sw/source/core/doc/docredln.cxx42
-rw-r--r--sw/source/core/inc/unoport.hxx3
-rw-r--r--sw/source/core/unocore/unoredline.cxx8
4 files changed, 80 insertions, 5 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index ad8deaf383a6..a8b7bf916f2d 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -68,6 +68,7 @@ public:
void testShapeTextUndoShells();
void testShapeTextUndoGroupShells();
void testTrackChanges();
+ void testTrackChangesCallback();
CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
CPPUNIT_TEST(testRegisterCallback);
@@ -101,6 +102,7 @@ public:
CPPUNIT_TEST(testShapeTextUndoShells);
CPPUNIT_TEST(testShapeTextUndoGroupShells);
CPPUNIT_TEST(testTrackChanges);
+ CPPUNIT_TEST(testTrackChangesCallback);
CPPUNIT_TEST_SUITE_END();
private:
@@ -116,13 +118,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)
{
}
@@ -196,6 +200,11 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
}
}
break;
+ case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
+ {
+ ++m_nRedlineTableSizeChanged;
+ }
+ break;
}
}
@@ -1169,6 +1178,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 da3b7733cbf7..b93a39be749a 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,41 @@ 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 )
{
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(nP);
return rv.second;
}
@@ -456,6 +492,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();
@@ -479,8 +516,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 d229d8589208..32b5e8e87a39 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;
@@ -309,6 +310,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 20b9f4cfd470..dc99aaf2bd91 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) ) );