Kaydet (Commit) a623b3a4 authored tarafından Pranav Kant's avatar Pranav Kant Kaydeden (comit) pranavk

lok: New commandvalues command - .uno:ViewAnnotations

Change-Id: I1c3560ab4609c64da7a77e9a65febeb569ec1a3c
Reviewed-on: https://gerrit.libreoffice.org/33468Reviewed-by: 's avatarpranavk <pranavk@collabora.co.uk>
Tested-by: 's avatarpranavk <pranavk@collabora.co.uk>
üst 6b977d5a
...@@ -1867,6 +1867,20 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis, ...@@ -1867,6 +1867,20 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis,
pViewShell->registerLibreOfficeKitViewCallback(CallbackFlushHandler::callback, pDocument->mpCallbackFlushHandlers[nView].get()); 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) static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nCharCode, int nKeyCode)
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
...@@ -2416,6 +2430,7 @@ static char* getTrackedChanges(LibreOfficeKitDocument* pThis) ...@@ -2416,6 +2430,7 @@ static char* getTrackedChanges(LibreOfficeKitDocument* pThis)
return pJson; return pJson;
} }
/// Returns the JSON representation of the redline author table. /// Returns the JSON representation of the redline author table.
static char* getTrackedChangeAuthors(LibreOfficeKitDocument* pThis) static char* getTrackedChangeAuthors(LibreOfficeKitDocument* pThis)
{ {
...@@ -2462,6 +2477,10 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo ...@@ -2462,6 +2477,10 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
{ {
return getTrackedChangeAuthors(pThis); return getTrackedChangeAuthors(pThis);
} }
else if (aCommand == ".uno:ViewAnnotations")
{
return getPostIts(pThis);
}
else if (aCommand.startsWith(aViewRowColumnHeaders)) else if (aCommand.startsWith(aViewRowColumnHeaders))
{ {
ITiledRenderable* pDoc = getTiledRenderable(pThis); ITiledRenderable* pDoc = getTiledRenderable(pThis);
......
...@@ -219,6 +219,13 @@ public: ...@@ -219,6 +219,13 @@ public:
{ {
return OUString(); return OUString();
} }
/// Implementation for
/// lok::Document::getCommandValues(".uno:ViewAnnotations");
virtual OUString getPostIts()
{
return OUString();
}
}; };
} // namespace vcl } // namespace vcl
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#ifndef INCLUDED_SW_INC_ANNOTATIONWIN_HXX #ifndef INCLUDED_SW_INC_ANNOTATIONWIN_HXX
#define INCLUDED_SW_INC_ANNOTATIONWIN_HXX #define INCLUDED_SW_INC_ANNOTATIONWIN_HXX
#include <docufld.hxx>
#include <SidebarWin.hxx> #include <SidebarWin.hxx>
class PopupMenu; class PopupMenu;
...@@ -43,6 +44,7 @@ class SwAnnotationWin : public sw::sidebarwindows::SwSidebarWin ...@@ -43,6 +44,7 @@ class SwAnnotationWin : public sw::sidebarwindows::SwSidebarWin
virtual void SetPostItText() override; virtual void SetPostItText() override;
virtual void Delete() override; virtual void Delete() override;
virtual void GotoPos() override; virtual void GotoPos() override;
inline const SwPostItField* GetPostItField() { return mpField; }
virtual OUString GetAuthor() override; virtual OUString GetAuthor() override;
virtual Date GetDate() override; virtual Date GetDate() override;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <vcl/lineinfo.hxx> #include <vcl/lineinfo.hxx>
#include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/range/b2drange.hxx>
#include <editeng/editstat.hxx> #include <editeng/editstat.hxx>
class SwPostItMgr; class SwPostItMgr;
...@@ -80,6 +81,7 @@ class SwSidebarWin : public vcl::Window ...@@ -80,6 +81,7 @@ class SwSidebarWin : public vcl::Window
void CheckMetaText(); void CheckMetaText();
inline Point GetAnchorPos() { return mAnchorRect.Pos(); } inline Point GetAnchorPos() { return mAnchorRect.Pos(); }
inline const std::vector<basegfx::B2DRange>& GetAnnotationTextRanges() { return maAnnotationTextRanges; }
SwEditWin& EditWin(); SwEditWin& EditWin();
inline OutlinerView* GetOutlinerView() { return mpOutlinerView;} inline OutlinerView* GetOutlinerView() { return mpOutlinerView;}
...@@ -240,6 +242,8 @@ class SwSidebarWin : public vcl::Window ...@@ -240,6 +242,8 @@ class SwSidebarWin : public vcl::Window
SwRect mAnchorRect; SwRect mAnchorRect;
long mPageBorder; long mPageBorder;
std::vector<basegfx::B2DRange> maAnnotationTextRanges;
bool mbMouseOver; bool mbMouseOver;
SwPostItHelper::SwLayoutStatus mLayoutStatus; SwPostItHelper::SwLayoutStatus mLayoutStatus;
......
...@@ -419,7 +419,8 @@ public: ...@@ -419,7 +419,8 @@ public:
virtual Pointer getPointer() override; virtual Pointer getPointer() override;
/// @see vcl::ITiledRenderable::getTrackedChangeAuthors(). /// @see vcl::ITiledRenderable::getTrackedChangeAuthors().
OUString getTrackedChangeAuthors() override; OUString getTrackedChangeAuthors() override;
/// @see vcl::ITiledRenderable::getPostIts().
OUString getPostIts() override;
// css::tiledrendering::XTiledRenderable // 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; 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;
......
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
#include <SidebarWin.hxx> #include <SidebarWin.hxx>
#include <SidebarWinAcc.hxx> #include <SidebarWinAcc.hxx>
#include <PostItMgr.hxx> #include <PostItMgr.hxx>
#include <basegfx/range/b2drange.hxx>
#include <comphelper/string.hxx>
#include <SidebarTxtControl.hxx> #include <SidebarTxtControl.hxx>
#include <SidebarScrollBar.hxx> #include <SidebarScrollBar.hxx>
#include <AnchorOverlayObject.hxx> #include <AnchorOverlayObject.hxx>
...@@ -356,6 +357,7 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle ...@@ -356,6 +357,7 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle
pProcessor->process(mpAnchor->getOverlayObjectPrimitive2DSequence()); pProcessor->process(mpAnchor->getOverlayObjectPrimitive2DSequence());
if (mpTextRangeOverlay) if (mpTextRangeOverlay)
pProcessor->process(mpTextRangeOverlay->getOverlayObjectPrimitive2DSequence()); pProcessor->process(mpTextRangeOverlay->getOverlayObjectPrimitive2DSequence());
rRenderContext.Push(PushFlags::NONE); rRenderContext.Push(PushFlags::NONE);
pProcessor.reset(); pProcessor.reset();
rRenderContext.Push(PushFlags::NONE); rRenderContext.Push(PushFlags::NONE);
...@@ -868,62 +870,65 @@ void SwSidebarWin::SetPosAndSize() ...@@ -868,62 +870,65 @@ void SwSidebarWin::SetPosAndSize()
} }
} }
// text range overlay // text range overlay
if ( mrMgr.ShowNotes() maAnnotationTextRanges.clear();
&& mrSidebarItem.maLayoutInfo.mnStartNodeIdx != 0 if ( mrSidebarItem.maLayoutInfo.mnStartNodeIdx != 0
&& mrSidebarItem.maLayoutInfo.mnStartContent != -1 ) && 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 = SwPosition aStartPos( *pContentNd, mrSidebarItem.maLayoutInfo.mnStartContent );
dynamic_cast< const SwTextAnnotationField* >( mrSidebarItem.GetFormatField().GetTextField() ); SwShellCursor* pTmpCursor = nullptr;
SwTextNode* pTextNode = pTextAnnotationField ? pTextAnnotationField->GetpTextNode() : nullptr; const bool bTableCursorNeeded = pTextNode->FindTableBoxStartNode() != pContentNd->FindTableBoxStartNode();
SwContentNode* pContentNd = nullptr; if ( bTableCursorNeeded )
if (pTextNode)
{ {
SwNodes& rNds = pTextNode->GetDoc()->GetNodes(); SwShellTableCursor* pTableCursor = new SwShellTableCursor( DocView().GetWrtShell(), aStartPos );
pContentNd = rNds[mrSidebarItem.maLayoutInfo.mnStartNodeIdx]->GetContentNode(); 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* pCursor = new SwShellCursor( DocView().GetWrtShell(), aStartPos );
SwShellCursor* pTmpCursor = nullptr; pCursor->SetMark();
const bool bTableCursorNeeded = pTextNode->FindTableBoxStartNode() != pContentNd->FindTableBoxStartNode(); pCursor->GetMark()->nNode = *pTextNode;
if ( bTableCursorNeeded ) pCursor->GetMark()->nContent.Assign( pTextNode, pTextAnnotationField->GetStart()+1 );
{ pTmpCursor = pCursor;
SwShellTableCursor* pTableCursor = new SwShellTableCursor( DocView().GetWrtShell(), aStartPos ); }
pTableCursor->SetMark(); std::unique_ptr<SwShellCursor> pTmpCursorForAnnotationTextRange( pTmpCursor );
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 );
pTmpCursorForAnnotationTextRange->FillRects(); pTmpCursorForAnnotationTextRange->FillRects();
SwRects* pRects(pTmpCursorForAnnotationTextRange.get()); SwRects* pRects(pTmpCursorForAnnotationTextRange.get());
for(SwRect & rNextRect : *pRects) std::vector<OString> aRects;
{ for(SwRect & rNextRect : *pRects)
const Rectangle aPntRect(rNextRect.SVRect()); {
aRects.push_back(rNextRect.SVRect().toString());
const Rectangle aPntRect(rNextRect.SVRect());
aAnnotationTextRanges.push_back(basegfx::B2DRange( maAnnotationTextRanges.push_back(basegfx::B2DRange(
aPntRect.Left(), aPntRect.Top(), aPntRect.Left(), aPntRect.Top(),
aPntRect.Right() + 1, aPntRect.Bottom() + 1)); aPntRect.Right() + 1, aPntRect.Bottom() + 1));
}
} }
} }
}
if (mrMgr.ShowNotes() && !maAnnotationTextRanges.empty())
{
if ( mpTextRangeOverlay != nullptr ) if ( mpTextRangeOverlay != nullptr )
{ {
mpTextRangeOverlay->setRanges( aAnnotationTextRanges ); mpTextRangeOverlay->setRanges( maAnnotationTextRanges );
if ( mpAnchor != nullptr && mpAnchor->getLineSolid() ) if ( mpAnchor != nullptr && mpAnchor->getLineSolid() )
{ {
mpTextRangeOverlay->ShowSolidBorder(); mpTextRangeOverlay->ShowSolidBorder();
...@@ -940,7 +945,7 @@ void SwSidebarWin::SetPosAndSize() ...@@ -940,7 +945,7 @@ void SwSidebarWin::SetPosAndSize()
sw::overlay::OverlayRanges::CreateOverlayRange( sw::overlay::OverlayRanges::CreateOverlayRange(
DocView(), DocView(),
mColorAnchor, mColorAnchor,
aAnnotationTextRanges, maAnnotationTextRanges,
mpAnchor && mpAnchor->getLineSolid() ); mpAnchor && mpAnchor->getLineSolid() );
} }
} }
......
...@@ -17,8 +17,12 @@ ...@@ -17,8 +17,12 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <boost/property_tree/json_parser.hpp>
#include <sal/config.h> #include <sal/config.h>
#include <comphelper/string.hxx>
#include <AnnotationWin.hxx>
#include <o3tl/any.hxx> #include <o3tl/any.hxx>
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <vcl/image.hxx> #include <vcl/image.hxx>
...@@ -64,6 +68,7 @@ ...@@ -64,6 +68,7 @@
#include <unodraw.hxx> #include <unodraw.hxx>
#include <svl/eitem.hxx> #include <svl/eitem.hxx>
#include <pagedesc.hxx> #include <pagedesc.hxx>
#include <unotools/datetime.hxx>
#include <unotools/textsearch.hxx> #include <unotools/textsearch.hxx>
#include <unocrsr.hxx> #include <unocrsr.hxx>
#include <unofieldcoll.hxx> #include <unofieldcoll.hxx>
...@@ -3179,6 +3184,45 @@ OUString SwXTextDocument::getTrackedChangeAuthors() ...@@ -3179,6 +3184,45 @@ OUString SwXTextDocument::getTrackedChangeAuthors()
return SW_MOD()->GetRedlineAuthorInfo(); 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() int SwXTextDocument::getPart()
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment