[Libreoffice-commits] core.git: desktop/source include/vcl sw/inc sw/source

Pranav Kant pranavk at collabora.co.uk
Fri Jan 27 11:49:40 UTC 2017


 desktop/source/lib/init.cxx           |   19 ++++++
 include/vcl/ITiledRenderable.hxx      |    7 ++
 sw/inc/AnnotationWin.hxx              |    2 
 sw/inc/SidebarWin.hxx                 |    4 +
 sw/inc/unotxdoc.hxx                   |    3 -
 sw/source/uibase/docvw/SidebarWin.cxx |   93 +++++++++++++++++-----------------
 sw/source/uibase/uno/unotxdoc.cxx     |   44 ++++++++++++++++
 7 files changed, 127 insertions(+), 45 deletions(-)

New commits:
commit a623b3a449dfcddaad5b621ff1c0b7a520edf4d6
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Jan 19 10:34:17 2017 +0530

    lok: New commandvalues command - .uno:ViewAnnotations
    
    Change-Id: I1c3560ab4609c64da7a77e9a65febeb569ec1a3c
    Reviewed-on: https://gerrit.libreoffice.org/33468
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 4d2dc02a..2403ff6 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1867,6 +1867,20 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis,
         pViewShell->registerLibreOfficeKitViewCallback(CallbackFlushHandler::callback, pDocument->mpCallbackFlushHandlers[nView].get());
 }
 
+/// Returns the JSON representation of all the comments in the document
+static char* getPostIts(LibreOfficeKitDocument* pThis)
+{
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
+    if (!pDoc)
+    {
+        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+        return nullptr;
+    }
+    OUString aComments = pDoc->getPostIts();
+    return strdup(aComments.toUtf8().getStr());
+}
+
+
 static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nCharCode, int nKeyCode)
 {
     SolarMutexGuard aGuard;
@@ -2416,6 +2430,7 @@ static char* getTrackedChanges(LibreOfficeKitDocument* pThis)
     return pJson;
 }
 
+
 /// Returns the JSON representation of the redline author table.
 static char* getTrackedChangeAuthors(LibreOfficeKitDocument* pThis)
 {
@@ -2462,6 +2477,10 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
     {
         return getTrackedChangeAuthors(pThis);
     }
+    else if (aCommand == ".uno:ViewAnnotations")
+    {
+        return getPostIts(pThis);
+    }
     else if (aCommand.startsWith(aViewRowColumnHeaders))
     {
         ITiledRenderable* pDoc = getTiledRenderable(pThis);
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index a6cb988..abe4979 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -219,6 +219,13 @@ public:
     {
         return OUString();
     }
+
+    /// Implementation for
+    /// lok::Document::getCommandValues(".uno:ViewAnnotations");
+    virtual OUString getPostIts()
+    {
+        return OUString();
+    }
 };
 
 } // namespace vcl
diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx
index 8d41b58..07dde37 100644
--- a/sw/inc/AnnotationWin.hxx
+++ b/sw/inc/AnnotationWin.hxx
@@ -20,6 +20,7 @@
 #ifndef INCLUDED_SW_INC_ANNOTATIONWIN_HXX
 #define INCLUDED_SW_INC_ANNOTATIONWIN_HXX
 
+#include <docufld.hxx>
 #include <SidebarWin.hxx>
 
 class PopupMenu;
@@ -43,6 +44,7 @@ class SwAnnotationWin : public sw::sidebarwindows::SwSidebarWin
         virtual void    SetPostItText() override;
         virtual void    Delete() override;
         virtual void    GotoPos() override;
+        inline const SwPostItField* GetPostItField() { return mpField; }
 
         virtual OUString GetAuthor() override;
         virtual Date    GetDate() override;
diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
index adfb47c..742e2f2 100644
--- a/sw/inc/SidebarWin.hxx
+++ b/sw/inc/SidebarWin.hxx
@@ -30,6 +30,7 @@
 
 #include <vcl/lineinfo.hxx>
 #include <basegfx/polygon/b2dpolygon.hxx>
+#include <basegfx/range/b2drange.hxx>
 #include <editeng/editstat.hxx>
 
 class SwPostItMgr;
@@ -80,6 +81,7 @@ class SwSidebarWin : public vcl::Window
         void CheckMetaText();
 
         inline Point GetAnchorPos() { return mAnchorRect.Pos(); }
+        inline const std::vector<basegfx::B2DRange>& GetAnnotationTextRanges() { return maAnnotationTextRanges; }
         SwEditWin& EditWin();
 
         inline OutlinerView* GetOutlinerView() { return mpOutlinerView;}
@@ -240,6 +242,8 @@ class SwSidebarWin : public vcl::Window
         SwRect          mAnchorRect;
         long            mPageBorder;
 
+        std::vector<basegfx::B2DRange> maAnnotationTextRanges;
+
         bool            mbMouseOver;
         SwPostItHelper::SwLayoutStatus mLayoutStatus;
 
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index e358cbd..aeb5561 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -419,7 +419,8 @@ public:
     virtual Pointer getPointer() override;
     /// @see vcl::ITiledRenderable::getTrackedChangeAuthors().
     OUString getTrackedChangeAuthors() override;
-
+    /// @see vcl::ITiledRenderable::getPostIts().
+    OUString getPostIts() override;
     // css::tiledrendering::XTiledRenderable
     virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) override;
 
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 6f739cc..f71b6b6 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -24,7 +24,8 @@
 #include <SidebarWin.hxx>
 #include <SidebarWinAcc.hxx>
 #include <PostItMgr.hxx>
-
+#include <basegfx/range/b2drange.hxx>
+#include <comphelper/string.hxx>
 #include <SidebarTxtControl.hxx>
 #include <SidebarScrollBar.hxx>
 #include <AnchorOverlayObject.hxx>
@@ -356,6 +357,7 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle
         pProcessor->process(mpAnchor->getOverlayObjectPrimitive2DSequence());
     if (mpTextRangeOverlay)
         pProcessor->process(mpTextRangeOverlay->getOverlayObjectPrimitive2DSequence());
+
     rRenderContext.Push(PushFlags::NONE);
     pProcessor.reset();
     rRenderContext.Push(PushFlags::NONE);
@@ -868,62 +870,65 @@ void SwSidebarWin::SetPosAndSize()
         }
     }
 
+
     // text range overlay
-    if ( mrMgr.ShowNotes()
-         && mrSidebarItem.maLayoutInfo.mnStartNodeIdx != 0
+    maAnnotationTextRanges.clear();
+    if ( mrSidebarItem.maLayoutInfo.mnStartNodeIdx != 0
          && mrSidebarItem.maLayoutInfo.mnStartContent != -1 )
     {
-        std::vector< basegfx::B2DRange > aAnnotationTextRanges;
+        const SwTextAnnotationField* pTextAnnotationField =
+            dynamic_cast< const SwTextAnnotationField* >( mrSidebarItem.GetFormatField().GetTextField() );
+        SwTextNode* pTextNode = pTextAnnotationField ? pTextAnnotationField->GetpTextNode() : nullptr;
+        SwContentNode* pContentNd = nullptr;
+        if (pTextNode)
+        {
+            SwNodes& rNds = pTextNode->GetDoc()->GetNodes();
+            pContentNd = rNds[mrSidebarItem.maLayoutInfo.mnStartNodeIdx]->GetContentNode();
+        }
+        if (pContentNd)
         {
-            const SwTextAnnotationField* pTextAnnotationField =
-                dynamic_cast< const SwTextAnnotationField* >( mrSidebarItem.GetFormatField().GetTextField() );
-            SwTextNode* pTextNode = pTextAnnotationField ? pTextAnnotationField->GetpTextNode() : nullptr;
-            SwContentNode* pContentNd = nullptr;
-            if (pTextNode)
+            SwPosition aStartPos( *pContentNd, mrSidebarItem.maLayoutInfo.mnStartContent );
+            SwShellCursor* pTmpCursor = nullptr;
+            const bool bTableCursorNeeded = pTextNode->FindTableBoxStartNode() != pContentNd->FindTableBoxStartNode();
+            if ( bTableCursorNeeded )
             {
-                SwNodes& rNds = pTextNode->GetDoc()->GetNodes();
-                pContentNd = rNds[mrSidebarItem.maLayoutInfo.mnStartNodeIdx]->GetContentNode();
+                SwShellTableCursor* pTableCursor = new SwShellTableCursor( DocView().GetWrtShell(), aStartPos );
+                pTableCursor->SetMark();
+                pTableCursor->GetMark()->nNode = *pTextNode;
+                pTableCursor->GetMark()->nContent.Assign( pTextNode, pTextAnnotationField->GetStart()+1 );
+                pTableCursor->NewTableSelection();
+                pTmpCursor = pTableCursor;
             }
-            if (pContentNd)
+            else
             {
-                SwPosition aStartPos( *pContentNd, mrSidebarItem.maLayoutInfo.mnStartContent );
-                SwShellCursor* pTmpCursor = nullptr;
-                const bool bTableCursorNeeded = pTextNode->FindTableBoxStartNode() != pContentNd->FindTableBoxStartNode();
-                if ( bTableCursorNeeded )
-                {
-                    SwShellTableCursor* pTableCursor = new SwShellTableCursor( DocView().GetWrtShell(), aStartPos );
-                    pTableCursor->SetMark();
-                    pTableCursor->GetMark()->nNode = *pTextNode;
-                    pTableCursor->GetMark()->nContent.Assign( pTextNode, pTextAnnotationField->GetStart()+1 );
-                    pTableCursor->NewTableSelection();
-                    pTmpCursor = pTableCursor;
-                }
-                else
-                {
-                    SwShellCursor* pCursor = new SwShellCursor( DocView().GetWrtShell(), aStartPos );
-                    pCursor->SetMark();
-                    pCursor->GetMark()->nNode = *pTextNode;
-                    pCursor->GetMark()->nContent.Assign( pTextNode, pTextAnnotationField->GetStart()+1 );
-                    pTmpCursor = pCursor;
-                }
-                std::unique_ptr<SwShellCursor> pTmpCursorForAnnotationTextRange( pTmpCursor );
+                SwShellCursor* pCursor = new SwShellCursor( DocView().GetWrtShell(), aStartPos );
+                pCursor->SetMark();
+                pCursor->GetMark()->nNode = *pTextNode;
+                pCursor->GetMark()->nContent.Assign( pTextNode, pTextAnnotationField->GetStart()+1 );
+                pTmpCursor = pCursor;
+            }
+            std::unique_ptr<SwShellCursor> pTmpCursorForAnnotationTextRange( pTmpCursor );
 
-                pTmpCursorForAnnotationTextRange->FillRects();
-                SwRects* pRects(pTmpCursorForAnnotationTextRange.get());
-                for(SwRect & rNextRect : *pRects)
-                {
-                    const Rectangle aPntRect(rNextRect.SVRect());
+            pTmpCursorForAnnotationTextRange->FillRects();
+            SwRects* pRects(pTmpCursorForAnnotationTextRange.get());
+            std::vector<OString> aRects;
+            for(SwRect & rNextRect : *pRects)
+            {
+                aRects.push_back(rNextRect.SVRect().toString());
+                const Rectangle aPntRect(rNextRect.SVRect());
 
-                    aAnnotationTextRanges.push_back(basegfx::B2DRange(
-                        aPntRect.Left(), aPntRect.Top(),
-                        aPntRect.Right() + 1, aPntRect.Bottom() + 1));
-                }
+                maAnnotationTextRanges.push_back(basegfx::B2DRange(
+                    aPntRect.Left(), aPntRect.Top(),
+                    aPntRect.Right() + 1, aPntRect.Bottom() + 1));
             }
         }
+    }
 
+    if (mrMgr.ShowNotes() && !maAnnotationTextRanges.empty())
+    {
         if ( mpTextRangeOverlay != nullptr )
         {
-            mpTextRangeOverlay->setRanges( aAnnotationTextRanges );
+            mpTextRangeOverlay->setRanges( maAnnotationTextRanges );
             if ( mpAnchor != nullptr && mpAnchor->getLineSolid() )
             {
                 mpTextRangeOverlay->ShowSolidBorder();
@@ -940,7 +945,7 @@ void SwSidebarWin::SetPosAndSize()
                 sw::overlay::OverlayRanges::CreateOverlayRange(
                     DocView(),
                     mColorAnchor,
-                    aAnnotationTextRanges,
+                    maAnnotationTextRanges,
                     mpAnchor && mpAnchor->getLineSolid() );
         }
     }
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 81519d9..a436583 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -17,8 +17,12 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <boost/property_tree/json_parser.hpp>
+
 #include <sal/config.h>
 
+#include <comphelper/string.hxx>
+#include <AnnotationWin.hxx>
 #include <o3tl/any.hxx>
 #include <osl/mutex.hxx>
 #include <vcl/image.hxx>
@@ -64,6 +68,7 @@
 #include <unodraw.hxx>
 #include <svl/eitem.hxx>
 #include <pagedesc.hxx>
+#include <unotools/datetime.hxx>
 #include <unotools/textsearch.hxx>
 #include <unocrsr.hxx>
 #include <unofieldcoll.hxx>
@@ -3179,6 +3184,45 @@ OUString SwXTextDocument::getTrackedChangeAuthors()
     return SW_MOD()->GetRedlineAuthorInfo();
 }
 
+OUString SwXTextDocument::getPostIts()
+{
+    SolarMutexGuard aGuard;
+    boost::property_tree::ptree aAnnotations;
+    for (std::list<SwSidebarItem*>::const_iterator i = pDocShell->GetView()->GetPostItMgr()->begin();
+         i != pDocShell->GetView()->GetPostItMgr()->end(); i++ )
+    {
+        sw::annotation::SwAnnotationWin* pWin = static_cast<sw::annotation::SwAnnotationWin*>((*i)->pPostIt.get());
+
+        const SwPostItField* pField = pWin->GetPostItField();
+        const std::string aAnchorPos = std::to_string(pWin->GetAnchorPos().X()) + ", " + std::to_string(pWin->GetAnchorPos().Y());
+        std::vector<OString> aRects;
+        for (const basegfx::B2DRange& aRange : pWin->GetAnnotationTextRanges())
+        {
+            const SwRect rect(aRange.getMinX(), aRange.getMinY(), aRange.getWidth(), aRange.getHeight());
+            aRects.push_back(rect.SVRect().toString());
+        }
+        const OString sRects = comphelper::string::join("; ", aRects);
+
+        boost::property_tree::ptree aAnnotation;
+        aAnnotation.put("id", pField->GetPostItId());
+        aAnnotation.put("reply", pWin->IsFollow());
+        aAnnotation.put("author", pField->GetPar1().toUtf8().getStr());
+        aAnnotation.put("text", pField->GetPar2().toUtf8().getStr());
+        aAnnotation.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime()));
+        aAnnotation.put("anchorPos", aAnchorPos.c_str());
+        aAnnotation.put("textRange", sRects.getStr());
+
+        aAnnotations.push_back(std::make_pair("", aAnnotation));
+    }
+
+    boost::property_tree::ptree aTree;
+    aTree.add_child("comments", aAnnotations);
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aTree);
+
+    return OUString::createFromAscii(aStream.str().c_str());
+}
+
 int SwXTextDocument::getPart()
 {
     SolarMutexGuard aGuard;


More information about the Libreoffice-commits mailing list