[Libreoffice-commits] core.git: 2 commits - libreofficekit/qa sc/source

Pranav Kant pranavk at collabora.co.uk
Thu Feb 16 06:01:45 UTC 2017


 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |    2 
 sc/source/core/data/column2.cxx                     |   43 ++++++++++-----
 sc/source/ui/docshell/docfunc.cxx                   |   11 +++
 sc/source/ui/docshell/docsh4.cxx                    |   56 ++++++++++++++++++++
 sc/source/ui/inc/docsh.hxx                          |    3 +
 5 files changed, 98 insertions(+), 17 deletions(-)

New commits:
commit 748361ada42ffef774a7cb68f704de0e9edb5639
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Feb 16 00:54:48 2017 +0530

    gtktiledviewer: Different UNO command for calc
    
    Change-Id: I229451bac7cf4c223efd3fa18c177d650d3f9954
    Reviewed-on: https://gerrit.libreoffice.org/34327
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: pranavk <pranavk at collabora.co.uk>

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 28a1f6b..3115fd4 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -347,7 +347,7 @@ static void deleteCommentButtonClicked(GtkWidget* pWidget, gpointer userdata)
     boost::property_tree::write_json(aStream, aTree);
     std::string aArguments = aStream.str();
 
-    lok_doc_view_post_command(LOK_DOC_VIEW(rWindow.m_pDocView), ".uno:DeleteComment", aArguments.c_str(), false);
+    lok_doc_view_post_command(LOK_DOC_VIEW(rWindow.m_pDocView), rWindow.m_aToolItemCommandNames[rWindow.m_pDeleteComment].c_str(), aArguments.c_str(), false);
 }
 
 GtkWidget* CommentsSidebar::createCommentBox(const boost::property_tree::ptree& aComment)
commit 57056e5d6032ff1ce0a91c078ebaa1deeaa9dc6f
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Wed Feb 15 23:55:38 2017 +0530

    sc lok: implement comment callbacks
    
    Change-Id: I1253138aa530ecb2b63bf6cda658d480ac62ada5
    Reviewed-on: https://gerrit.libreoffice.org/34326
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: pranavk <pranavk at collabora.co.uk>

diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index b11a297..1fda6e2 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 dde0818..6c5dbe7 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 6b2ee92..207b37b 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 e2a75c3..a9349b4 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 );
 


More information about the Libreoffice-commits mailing list