summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranav Kant <pranavk@collabora.co.uk>2017-02-15 23:55:38 +0530
committerAndras Timar <andras.timar@collabora.com>2017-02-18 00:59:13 +0100
commit5feb8be8e3a7f42b7a1482f90fe8ff5d35706767 (patch)
tree9525029d2803cb42c2de6a180f609ec7d09c07e7
parentf64995d49740622c744a82be9906ab594416d01e (diff)
sc lok: implement comment callbacks
Change-Id: I1253138aa530ecb2b63bf6cda658d480ac62ada5 Reviewed-on: https://gerrit.libreoffice.org/34326 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: pranavk <pranavk@collabora.co.uk> (cherry picked from commit 57056e5d6032ff1ce0a91c078ebaa1deeaa9dc6f)
-rw-r--r--sc/source/core/data/column2.cxx43
-rw-r--r--sc/source/ui/docshell/docfunc.cxx11
-rw-r--r--sc/source/ui/docshell/docsh4.cxx56
-rw-r--r--sc/source/ui/inc/docsh.hxx3
4 files changed, 97 insertions, 16 deletions
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index b11a297e3b5c..1fda6e22c81e 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -18,6 +18,7 @@
*/
#include "column.hxx"
+#include "docsh.hxx"
#include "scitems.hxx"
#include "formulacell.hxx"
#include "document.hxx"
@@ -1875,26 +1876,38 @@ void ScColumn::SetCellNote(SCROW nRow, ScPostIt* pNote)
}
namespace {
-class ForgetCellNoteCaptionsHandler
-{
+ class CellNoteHandler
+ {
+ const ScDocument* m_pDocument;
+ const ScAddress m_aAddress; // 'incomplete' address consisting of tab, column
+ const bool m_bForgetCaptionOwnership;
-public:
- ForgetCellNoteCaptionsHandler() {}
+ public:
+ CellNoteHandler(const ScDocument* pDocument, const ScAddress& rPos, bool bForgetCaptionOwnership) :
+ m_pDocument(pDocument),
+ m_aAddress(rPos),
+ m_bForgetCaptionOwnership(bForgetCaptionOwnership) {}
- void operator() ( size_t /*nRow*/, ScPostIt* p )
- {
- p->ForgetCaption();
- }
-};
-}
+ void operator() ( size_t nRow, ScPostIt* p )
+ {
+ if (m_bForgetCaptionOwnership)
+ p->ForgetCaption();
+
+ // Create a 'complete' address object
+ ScAddress aAddr(m_aAddress);
+ aAddr.SetRow(nRow);
+ // Notify our LOK clients
+ ScDocShell::LOKCommentNotify(LOKCommentNotificationType::Remove, m_pDocument, aAddr, p);
+ }
+ };
+} // anonymous namespace
void ScColumn::DeleteCellNotes( sc::ColumnBlockPosition& rBlockPos, SCROW nRow1, SCROW nRow2, bool bForgetCaptionOwnership )
{
- if (bForgetCaptionOwnership)
- {
- ForgetCellNoteCaptionsHandler aFunc;
- sc::ParseNote(maCellNotes.begin(), maCellNotes, nRow1, nRow2, aFunc);
- }
+ ScAddress aAddr(nCol, 0, nTab);
+ CellNoteHandler aFunc(pDocument, aAddr, bForgetCaptionOwnership);
+ sc::ParseNote(maCellNotes.begin(), maCellNotes, nRow1, nRow2, aFunc);
+
rBlockPos.miCellNotePos =
maCellNotes.set_empty(rBlockPos.miCellNotePos, nRow1, nRow2);
}
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 47fa09f5754e..2ecad6937505 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -1287,10 +1287,12 @@ void ScDocFunc::ReplaceNote( const ScAddress& rPos, const OUString& rNoteText, c
// create new note (creates drawing undo action for the new caption object)
ScNoteData aNewData;
- if( ScPostIt* pNewNote = ScNoteUtil::CreateNoteFromString( rDoc, rPos, rNoteText, false, true ) )
+ ScPostIt* pNewNote = nullptr;
+ if( (pNewNote = ScNoteUtil::CreateNoteFromString( rDoc, rPos, rNoteText, false, true )) )
{
if( pAuthor ) pNewNote->SetAuthor( *pAuthor );
if( pDate ) pNewNote->SetDate( *pDate );
+
// rescue note data for undo
aNewData = pNewNote->GetNoteData();
}
@@ -1306,6 +1308,13 @@ void ScDocFunc::ReplaceNote( const ScAddress& rPos, const OUString& rNoteText, c
rDoc.SetStreamValid(rPos.Tab(), false);
aModificator.SetDocumentModified();
+
+ // Let our LOK clients know about the new/modified note
+ if (pNewNote)
+ {
+ ScDocShell::LOKCommentNotify(pOldNote ? LOKCommentNotificationType::Modify : LOKCommentNotificationType::Add,
+ &rDoc, rPos, pNewNote);
+ }
}
else if (!bApi)
{
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 63a2db5e8f32..fa6db5aea6c8 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -19,6 +19,8 @@
#include <config_features.h>
+#include <boost/property_tree/json_parser.hpp>
+
#include <com/sun/star/embed/XEmbeddedObject.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
@@ -51,7 +53,9 @@ using namespace ::com::sun::star;
#include <svl/documentlockfile.hxx>
#include <svl/sharecontrolfile.hxx>
#include <unotools/securityoptions.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include "docuno.hxx"
@@ -2238,6 +2242,58 @@ bool ScDocShell::DdeSetData( const OUString& rItem,
return pObj;
}
+void ScDocShell::LOKCommentNotify(LOKCommentNotificationType nType, const ScDocument* pDocument, const ScAddress& rPos, const ScPostIt* pNote)
+{
+ if ( !pDocument->IsDocVisible() || // don't want callbacks until document load
+ !comphelper::LibreOfficeKit::isActive() ||
+ comphelper::LibreOfficeKit::isTiledAnnotations() )
+ return;
+
+ boost::property_tree::ptree aAnnotation;
+ aAnnotation.put("action", (nType == LOKCommentNotificationType::Add ? "Add" :
+ (nType == LOKCommentNotificationType::Remove ? "Remove" :
+ (nType == LOKCommentNotificationType::Modify ? "Modify" : "???"))));
+ OUString aCellId = rPos.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, pDocument,
+ ScAddress::Details(formula::FormulaGrammar::AddressConvention::CONV_ODF, rPos));
+ aAnnotation.put("id", aCellId.toUtf8().getStr());
+ if (nType != LOKCommentNotificationType::Remove && pNote)
+ {
+ aAnnotation.put("author", pNote->GetAuthor());
+ aAnnotation.put("dateTime", pNote->GetDate());
+ aAnnotation.put("text", pNote->GetText());
+
+ // Calculating the cell cursor position
+ ScViewData* pViewData = GetViewData();
+ if (pViewData && pViewData->GetActiveWin())
+ {
+ Point aScrPos = pViewData->GetScrPos(rPos.Col(), rPos.Row(), pViewData->GetActivePart(), true);
+ long nSizeXPix;
+ long nSizeYPix;
+ pViewData->GetMergeSizePixel(rPos.Col(), rPos.Row(), nSizeXPix, nSizeYPix);
+
+ const double fPPTX = pViewData->GetPPTX();
+ const double fPPTY = pViewData->GetPPTY();
+ Rectangle aRect(Point(aScrPos.getX() / fPPTX, aScrPos.getY() / fPPTY),
+ Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY));
+
+ aAnnotation.put("cellPos", aRect.toString());
+ }
+ }
+
+ boost::property_tree::ptree aTree;
+ aTree.add_child("comment", aAnnotation);
+ 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_COMMENT, aPayload.c_str());
+ pViewShell = SfxViewShell::GetNext(*pViewShell);
+ }
+}
+
ScViewData* ScDocShell::GetViewData()
{
SfxViewShell* pCur = SfxViewShell::Current();
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 0abc2890f02a..e87ebcce2db1 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -75,6 +75,8 @@ typedef std::unordered_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
//enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
+enum class LOKCommentNotificationType { Add, Modify, Remove };
+
// Extra flags for Repaint
#define SC_PF_LINES 1
#define SC_PF_TESTMERGE 2
@@ -398,6 +400,7 @@ public:
static OUString GetDBaseFilterName();
static OUString GetDifFilterName();
static bool HasAutomaticTableName( const OUString& rFilter );
+ static void LOKCommentNotify(LOKCommentNotificationType nType, const ScDocument* pDocument, const ScAddress& rPos, const ScPostIt* pNote);
DECL_LINK( RefreshDBDataHdl, Timer*, void );