From 57056e5d6032ff1ce0a91c078ebaa1deeaa9dc6f Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Wed, 15 Feb 2017 23:55:38 +0530 Subject: sc lok: implement comment callbacks Change-Id: I1253138aa530ecb2b63bf6cda658d480ac62ada5 Reviewed-on: https://gerrit.libreoffice.org/34326 Tested-by: Jenkins Reviewed-by: pranavk --- sc/source/ui/docshell/docfunc.cxx | 11 +++++++- sc/source/ui/docshell/docsh4.cxx | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) (limited to 'sc/source/ui/docshell') diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index dde081810341..6c5dbe721ad2 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -1290,10 +1290,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(); } @@ -1309,6 +1311,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 6b2ee929d124..207b37b61941 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -19,6 +19,8 @@ #include +#include + #include #include #include @@ -51,7 +53,9 @@ using namespace ::com::sun::star; #include #include #include +#include +#include #include #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(); -- cgit