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,
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);
......
......@@ -219,6 +219,13 @@ public:
{
return OUString();
}
/// Implementation for
/// lok::Document::getCommandValues(".uno:ViewAnnotations");
virtual OUString getPostIts()
{
return OUString();
}
};
} // namespace vcl
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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() );
}
}
......
......@@ -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;
......
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