diff options
-rw-r--r-- | desktop/source/lib/init.cxx | 19 | ||||
-rw-r--r-- | include/vcl/ITiledRenderable.hxx | 7 | ||||
-rw-r--r-- | sw/inc/AnnotationWin.hxx | 2 | ||||
-rw-r--r-- | sw/inc/SidebarWin.hxx | 4 | ||||
-rw-r--r-- | sw/inc/unotxdoc.hxx | 3 | ||||
-rw-r--r-- | sw/source/uibase/docvw/SidebarWin.cxx | 93 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 44 |
7 files changed, 127 insertions, 45 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index c7ee9afecac1..7492d1378c05 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1862,6 +1862,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; @@ -2412,6 +2426,7 @@ static char* getTrackedChanges(LibreOfficeKitDocument* pThis) return pJson; } + /// Returns the JSON representation of the redline author table. static char* getTrackedChangeAuthors(LibreOfficeKitDocument* pThis) { @@ -2458,6 +2473,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 a6cb988226b0..abe4979058c8 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 8d41b587871c..07dde376b880 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 adfb47c16118..742e2f29c5b3 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 47e29addbb9e..03a338e4ed37 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -440,7 +440,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 ) throw (::css::uno::RuntimeException, std::exception) override; diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx index a1a8224c8342..8b06d005b752 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 3cfaa2a497a7..de34c18dacb5 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> @@ -3232,6 +3237,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; |