[Libreoffice-commits] core.git: desktop/qa desktop/source include/vcl sc/inc sc/qa sc/source
Marco Cecchetti
marco.cecchetti at collabora.com
Tue May 16 11:15:53 UTC 2017
desktop/qa/desktop_lib/test_desktop_lib.cxx | 4 -
desktop/source/lib/init.cxx | 16 +++++++
include/vcl/ITiledRenderable.hxx | 7 +++
sc/inc/docuno.hxx | 3 +
sc/inc/postit.hxx | 15 ++++---
sc/qa/unit/tiledrendering/tiledrendering.cxx | 20 +++++----
sc/source/core/data/postit.cxx | 21 ++++++----
sc/source/ui/docshell/docfunc.cxx | 4 +
sc/source/ui/docshell/docsh4.cxx | 6 +-
sc/source/ui/unoobj/docuno.cxx | 55 +++++++++++++++++++++++++--
sc/source/ui/view/cellsh1.cxx | 45 ++++++++++++++--------
11 files changed, 150 insertions(+), 46 deletions(-)
New commits:
commit cb33a0fb8b7d9fcdf7ef26ac690842574d359f4b
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date: Tue Apr 25 19:25:11 2017 +0200
lok: sc: misplaced comment mark on inserting/deleting/resizing row/col
A unique id has been introduced, in a similar way of what occurs in
Writer.
Change-Id: I7b2ef694867fb4184c4cfc616fe1c8f12da3b676
Reviewed-on: https://gerrit.libreoffice.org/36962
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 8d85a078efc0..79ec0ba54e3b 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -1933,14 +1933,14 @@ void DesktopLOKTest::testCommentsCalc()
{
case 0:
{
- CPPUNIT_ASSERT_EQUAL(std::string("Sheet5.G15"), rComment.second.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(std::string("4"), rComment.second.get<std::string>("tab"));
CPPUNIT_ASSERT_EQUAL(std::string("Comment1"), rComment.second.get<std::string>("text"));
CPPUNIT_ASSERT_EQUAL(std::string("7650, 3570, 1274, 254"), rComment.second.get<std::string>("cellPos"));
}
break;
case 1:
{
- CPPUNIT_ASSERT_EQUAL(std::string("Sheet5.H18"), rComment.second.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(std::string("4"), rComment.second.get<std::string>("tab"));
CPPUNIT_ASSERT_EQUAL(std::string("Comment2"), rComment.second.get<std::string>("text"));
CPPUNIT_ASSERT_EQUAL(std::string("8925, 4335, 1274, 254"), rComment.second.get<std::string>("cellPos"));
}
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index b090ae4e377c..ebfe46a7efe3 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2049,6 +2049,18 @@ static char* getPostIts(LibreOfficeKitDocument* pThis)
return strdup(aComments.toUtf8().getStr());
}
+/// Returns the JSON representation of the positions of all the comments in the document
+static char* getPostItsPos(LibreOfficeKitDocument* pThis)
+{
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+ return nullptr;
+ }
+ OUString aComments = pDoc->getPostItsPos();
+ return strdup(aComments.toUtf8().getStr());
+}
static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nCharCode, int nKeyCode)
{
@@ -2653,6 +2665,10 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
{
return getPostIts(pThis);
}
+ else if (aCommand == ".uno:ViewAnnotationsPosition")
+ {
+ return getPostItsPos(pThis);
+ }
else if (aCommand.startsWith(aViewRowColumnHeaders))
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 9645d2392743..5c5d8339b8a1 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -226,6 +226,13 @@ public:
{
return OUString();
}
+
+ /// Implementation for
+ /// lok::Document::getCommandValues(".uno:ViewAnnotationsPosition");
+ virtual OUString getPostItsPos()
+ {
+ return OUString();
+ }
};
} // namespace vcl
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index 55f6afb99858..00ff88999bd0 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -359,6 +359,9 @@ public:
/// @see vcl::ITiledRenderable::getPostIts().
OUString getPostIts() override;
+
+ /// @see vcl::ITiledRenderable::getPostItsPos().
+ OUString getPostItsPos() override;
};
class ScDrawPagesObj : public cppu::WeakImplHelper<
diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index d9584e1e7005..ba7d2705fb04 100644
--- a/sc/inc/postit.hxx
+++ b/sc/inc/postit.hxx
@@ -160,13 +160,14 @@ struct SC_DLLPUBLIC ScNoteData
class SC_DLLPUBLIC ScPostIt
{
public:
+ static sal_uInt32 mnLastPostItId;
/** Creates an empty note and its caption object and places it according to
the passed cell position. */
- explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos );
+ explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, sal_uInt32 nPostItId = 0 );
/** Copy constructor. Clones the note and its caption to a new document. */
- explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote );
+ explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote, sal_uInt32 nPostItId = 0 );
/** Creates a note from the passed note data with existing caption object.
@@ -180,7 +181,7 @@ public:
*/
explicit ScPostIt(
ScDocument& rDoc, const ScAddress& rPos,
- const ScNoteData& rNoteData, bool bAlwaysCreateCaption );
+ const ScNoteData& rNoteData, bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
/** Removes the caption object from drawing layer, if this note is its owner. */
~ScPostIt();
@@ -198,6 +199,9 @@ public:
ScDocument& rDestDoc, const ScAddress& rDestPos,
bool bCloneCaption ) const;
+ /** Returns the note id. */
+ sal_uInt32 GetId() const { return mnPostItId; }
+
/** Returns the data struct containing all note settings. */
const ScNoteData& GetNoteData() const { return maNoteData;}
@@ -270,6 +274,7 @@ private:
private:
ScDocument& mrDoc; /// Parent document containing the note.
mutable ScNoteData maNoteData; /// Note data with pointer to caption object.
+ sal_uInt32 mnPostItId;
};
class SC_DLLPUBLIC ScNoteUtil
@@ -336,7 +341,7 @@ public:
ScDocument& rDoc, const ScAddress& rPos,
SfxItemSet* pItemSet, OutlinerParaObject* pOutlinerObj,
const tools::Rectangle& rCaptionRect, bool bShown,
- bool bAlwaysCreateCaption );
+ bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
/** Creates a cell note based on the passed string and inserts it into the
document.
@@ -357,7 +362,7 @@ public:
static ScPostIt* CreateNoteFromString(
ScDocument& rDoc, const ScAddress& rPos,
const OUString& rNoteText, bool bShown,
- bool bAlwaysCreateCaption );
+ bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
};
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index 49b5c5da220d..565aa3bfe08c 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -1087,8 +1087,10 @@ void ScTiledRenderingTest::testCommentCallback()
// We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action
CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView1.m_aCommentCallbackResult.get<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView2.m_aCommentCallbackResult.get<std::string>("action"));
- CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView1.m_aCommentCallbackResult.get<std::string>("id"));
- CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView2.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(std::string("1"), aView1.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(std::string("1"), aView2.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(std::string("0"), aView1.m_aCommentCallbackResult.get<std::string>("tab"));
+ CPPUNIT_ASSERT_EQUAL(std::string("0"), aView2.m_aCommentCallbackResult.get<std::string>("tab"));
CPPUNIT_ASSERT_EQUAL(std::string("LOK User1"), aView1.m_aCommentCallbackResult.get<std::string>("author"));
CPPUNIT_ASSERT_EQUAL(std::string("LOK User1"), aView2.m_aCommentCallbackResult.get<std::string>("author"));
CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text"));
@@ -1096,6 +1098,8 @@ void ScTiledRenderingTest::testCommentCallback()
CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView1.m_aCommentCallbackResult.get<std::string>("cellPos"));
CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos"));
+ std::string aCommentId = aView1.m_aCommentCallbackResult.get<std::string>("id");
+
// Edit a comment
// Select some random cell, we should be able to edit the cell note without
// selecting the cell
@@ -1104,7 +1108,7 @@ void ScTiledRenderingTest::testCommentCallback()
pTabViewShell->SetCursor(3, 100);
aArgs = comphelper::InitPropertySequence(
{
- {"Id", uno::makeAny(OUString("Sheet1.A2"))},
+ {"Id", uno::makeAny(OUString::createFromAscii(aCommentId.c_str()))},
{"Text", uno::makeAny(OUString("Edited comment"))},
{"Author", uno::makeAny(OUString("LOK User2"))},
});
@@ -1114,8 +1118,8 @@ void ScTiledRenderingTest::testCommentCallback()
// We received a LOK_CALLBACK_COMMENT callback with comment 'Modify' action
CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView2.m_aCommentCallbackResult.get<std::string>("action"));
- CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView1.m_aCommentCallbackResult.get<std::string>("id"));
- CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView2.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(aCommentId, aView1.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(aCommentId, aView2.m_aCommentCallbackResult.get<std::string>("id"));
CPPUNIT_ASSERT_EQUAL(std::string("LOK User2"), aView1.m_aCommentCallbackResult.get<std::string>("author"));
CPPUNIT_ASSERT_EQUAL(std::string("LOK User2"), aView2.m_aCommentCallbackResult.get<std::string>("author"));
CPPUNIT_ASSERT_EQUAL(std::string("Edited comment"), aView1.m_aCommentCallbackResult.get<std::string>("text"));
@@ -1128,7 +1132,7 @@ void ScTiledRenderingTest::testCommentCallback()
pTabViewShell->SetCursor(4, 43);
aArgs = comphelper::InitPropertySequence(
{
- {"Id", uno::makeAny(OUString("Sheet1.A2"))}
+ {"Id", uno::makeAny(OUString::createFromAscii(aCommentId.c_str()))}
});
comphelper::dispatchCommand(".uno:DeleteNote", aArgs);
Scheduler::ProcessEventsToIdle();
@@ -1136,8 +1140,8 @@ void ScTiledRenderingTest::testCommentCallback()
// We received a LOK_CALLBACK_COMMENT callback with comment 'Remove' action
CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView1.m_aCommentCallbackResult.get<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView2.m_aCommentCallbackResult.get<std::string>("action"));
- CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView1.m_aCommentCallbackResult.get<std::string>("id"));
- CPPUNIT_ASSERT_EQUAL(std::string("Sheet1.A2"), aView2.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(aCommentId, aView1.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(aCommentId, aView2.m_aCommentCallbackResult.get<std::string>("id"));
mxComponent->dispose();
mxComponent.clear();
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index d06072cc3ef1..ec88cb534bac 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -840,26 +840,31 @@ ScNoteData::~ScNoteData()
{
}
-ScPostIt::ScPostIt( ScDocument& rDoc, const ScAddress& rPos ) :
+sal_uInt32 ScPostIt::mnLastPostItId = 1;
+
+ScPostIt::ScPostIt( ScDocument& rDoc, const ScAddress& rPos, sal_uInt32 nPostItId ) :
mrDoc( rDoc ),
maNoteData( false )
{
+ mnPostItId = nPostItId == 0 ? mnLastPostItId++ : nPostItId;
AutoStamp();
CreateCaption( rPos );
}
-ScPostIt::ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote ) :
+ScPostIt::ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote, sal_uInt32 nPostItId ) :
mrDoc( rDoc ),
maNoteData( rNote.maNoteData )
{
+ mnPostItId = nPostItId == 0 ? mnLastPostItId++ : nPostItId;
maNoteData.mxCaption.reset(nullptr);
CreateCaption( rPos, rNote.maNoteData.mxCaption.get() );
}
-ScPostIt::ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScNoteData& rNoteData, bool bAlwaysCreateCaption ) :
+ScPostIt::ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScNoteData& rNoteData, bool bAlwaysCreateCaption, sal_uInt32 nPostItId ) :
mrDoc( rDoc ),
maNoteData( rNoteData )
{
+ mnPostItId = nPostItId == 0 ? mnLastPostItId++ : nPostItId;
if( bAlwaysCreateCaption || maNoteData.mbShown )
CreateCaptionFromInitData( rPos );
}
@@ -872,7 +877,7 @@ ScPostIt::~ScPostIt()
ScPostIt* ScPostIt::Clone( const ScAddress& rOwnPos, ScDocument& rDestDoc, const ScAddress& rDestPos, bool bCloneCaption ) const
{
CreateCaptionFromInitData( rOwnPos );
- return bCloneCaption ? new ScPostIt( rDestDoc, rDestPos, *this ) : new ScPostIt( rDestDoc, rDestPos, maNoteData, false );
+ return bCloneCaption ? new ScPostIt( rDestDoc, rDestPos, *this, mnPostItId ) : new ScPostIt( rDestDoc, rDestPos, maNoteData, false, mnPostItId );
}
void ScPostIt::SetDate( const OUString& rDate )
@@ -1233,7 +1238,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromCaption(
ScPostIt* ScNoteUtil::CreateNoteFromObjectData(
ScDocument& rDoc, const ScAddress& rPos, SfxItemSet* pItemSet,
OutlinerParaObject* pOutlinerObj, const tools::Rectangle& rCaptionRect,
- bool bShown, bool bAlwaysCreateCaption )
+ bool bShown, bool bAlwaysCreateCaption, sal_uInt32 nPostItId )
{
OSL_ENSURE( pItemSet && pOutlinerObj, "ScNoteUtil::CreateNoteFromObjectData - item set and outliner object expected" );
ScNoteData aNoteData( bShown );
@@ -1255,7 +1260,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromObjectData(
/* Create the note and insert it into the document. If the note is
visible, the caption object will be created automatically. */
- ScPostIt* pNote = new ScPostIt( rDoc, rPos, aNoteData, bAlwaysCreateCaption );
+ ScPostIt* pNote = new ScPostIt( rDoc, rPos, aNoteData, bAlwaysCreateCaption, nPostItId );
pNote->AutoStamp();
rDoc.SetNote(rPos, pNote);
@@ -1265,7 +1270,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromObjectData(
ScPostIt* ScNoteUtil::CreateNoteFromString(
ScDocument& rDoc, const ScAddress& rPos, const OUString& rNoteText,
- bool bShown, bool bAlwaysCreateCaption )
+ bool bShown, bool bAlwaysCreateCaption, sal_uInt32 nPostItId )
{
ScPostIt* pNote = nullptr;
if( !rNoteText.isEmpty() )
@@ -1278,7 +1283,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromString(
/* Create the note and insert it into the document. If the note is
visible, the caption object will be created automatically. */
- pNote = new ScPostIt( rDoc, rPos, aNoteData, bAlwaysCreateCaption );
+ pNote = new ScPostIt( rDoc, rPos, aNoteData, bAlwaysCreateCaption, nPostItId );
pNote->AutoStamp();
//insert takes ownership
rDoc.SetNote(rPos, pNote);
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index acf6ec9692b5..5e686ca56a90 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -1264,8 +1264,10 @@ void ScDocFunc::ReplaceNote( const ScAddress& rPos, const OUString& rNoteText, c
ScNoteData aOldData;
ScPostIt* pOldNote = rDoc.ReleaseNote( rPos );
+ sal_uInt32 nNoteId = 0;
if( pOldNote )
{
+ nNoteId = pOldNote->GetId();
// ensure existing caption object before draw undo tracking starts
pOldNote->GetOrCreateCaption( rPos );
// rescue note data for undo
@@ -1282,7 +1284,7 @@ void ScDocFunc::ReplaceNote( const ScAddress& rPos, const OUString& rNoteText, c
// create new note (creates drawing undo action for the new caption object)
ScNoteData aNewData;
ScPostIt* pNewNote = nullptr;
- if( (pNewNote = ScNoteUtil::CreateNoteFromString( rDoc, rPos, rNoteText, false, true )) )
+ if( (pNewNote = ScNoteUtil::CreateNoteFromString( rDoc, rPos, rNoteText, false, true, nNoteId )) )
{
if( pAuthor ) pNewNote->SetAuthor( *pAuthor );
if( pDate ) pNewNote->SetDate( *pDate );
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 8c08b1ad3b7e..a4bc25827e4e 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -2236,9 +2236,9 @@ void ScDocShell::LOKCommentNotify(LOKCommentNotificationType nType, const ScDocu
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());
+
+ aAnnotation.put("id", pNote->GetId());
+ aAnnotation.put("tab", rPos.Tab());
if (nType != LOKCommentNotificationType::Remove && pNote)
{
aAnnotation.put("author", pNote->GetAuthor());
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 7cfd874a354c..0e5c0ab6bb84 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -989,11 +989,9 @@ OUString ScModelObj::getPostIts()
for (const sc::NoteEntry& aNote : aNotes)
{
boost::property_tree::ptree aAnnotation;
- OStringBuffer aBuf;
- aNote.maPos.Format(aBuf, ScRefFlags::VALID | ScRefFlags::TAB_3D, &rDoc,
- ScAddress::Details(formula::FormulaGrammar::AddressConvention::CONV_ODF, aNote.maPos));
- aAnnotation.put("id", aBuf.toString());
+ aAnnotation.put("id", aNote.mpNote->GetId());
+ aAnnotation.put("tab", aNote.maPos.Tab());
aAnnotation.put("author", aNote.mpNote->GetAuthor());
aAnnotation.put("dateTime", aNote.mpNote->GetDate());
aAnnotation.put("text", aNote.mpNote->GetText());
@@ -1028,6 +1026,55 @@ OUString ScModelObj::getPostIts()
return OUString::fromUtf8(aStream.str().c_str());
}
+
+OUString ScModelObj::getPostItsPos()
+{
+ if (!pDocShell)
+ return OUString();
+
+ ScDocument& rDoc = pDocShell->GetDocument();
+ std::vector<sc::NoteEntry> aNotes;
+ rDoc.GetAllNoteEntries(aNotes);
+
+ boost::property_tree::ptree aAnnotations;
+ for (const sc::NoteEntry& aNote : aNotes)
+ {
+ boost::property_tree::ptree aAnnotation;
+
+ aAnnotation.put("id", aNote.mpNote->GetId());
+ aAnnotation.put("tab", aNote.maPos.Tab());
+
+ // Calculating the cell cursor position
+ ScViewData* pViewData = ScDocShell::GetViewData();
+ ScGridWindow* pGridWindow = pViewData->GetActiveWin();
+ if (pGridWindow)
+ {
+ SCCOL nX = aNote.maPos.Col();
+ SCROW nY = aNote.maPos.Row();
+ Point aScrPos = pViewData->GetScrPos(nX, nY, pViewData->GetActivePart(), true);
+ long nSizeXPix;
+ long nSizeYPix;
+ pViewData->GetMergeSizePixel(nX, nY, nSizeXPix, nSizeYPix);
+
+ double fPPTX = pViewData->GetPPTX();
+ double fPPTY = pViewData->GetPPTY();
+ tools::Rectangle aRect(Point(aScrPos.getX() / fPPTX, aScrPos.getY() / fPPTY),
+ Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY));
+
+ aAnnotation.put("cellPos", aRect.toString());
+ }
+
+ aAnnotations.push_back(std::make_pair("", aAnnotation));
+ }
+
+ boost::property_tree::ptree aTree;
+ aTree.add_child("commentsPos", aAnnotations);
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+
+ return OUString::fromUtf8(aStream.str().c_str());
+}
+
void ScModelObj::initializeForTiledRendering(const css::uno::Sequence<css::beans::PropertyValue>& /*rArguments*/)
{
SolarMutexGuard aGuard;
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index c4a580f9be4c..0b3603ade2d1 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2211,14 +2211,20 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
if (!aCellId.isEmpty())
{
- ScAddress aParsedPos;
- ScRefFlags nRes = aParsedPos.Parse(aCellId,
- GetViewData()->GetDocument(),
- ScAddress::Details(formula::FormulaGrammar::AddressConvention::CONV_ODF));
- if (nRes & ScRefFlags::VALID)
+
+ ScDocument& rDoc = GetViewData()->GetDocShell()->GetDocument();
+ std::vector<sc::NoteEntry> aNotes;
+ rDoc.GetAllNoteEntries(aNotes);
+
+ sal_uInt32 nId = aCellId.toUInt32();
+ auto lComp = [nId](const sc::NoteEntry& rNote) { return rNote.mpNote->GetId() == nId; };
+
+ const auto& aFoundNoteIt = std::find_if(aNotes.begin(), aNotes.end(), lComp);
+ if (aFoundNoteIt != aNotes.end())
{
- pTabViewShell->SetTabNo(aParsedPos.Tab());
- pTabViewShell->SetCursor(aParsedPos.Col(), aParsedPos.Row());
+ ScAddress aFoundPos = aFoundNoteIt->maPos;
+ pTabViewShell->SetTabNo(aFoundPos.Tab());
+ pTabViewShell->SetCursor(aFoundPos.Col(), aFoundPos.Row());
}
}
@@ -2397,14 +2403,23 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
if ( pReqArgs && pReqArgs->HasItem( SID_ATTR_POSTIT_ID, &pId) )
{
const SvxPostItIdItem* pIdItem = static_cast<const SvxPostItIdItem*>(pId);
- ScAddress aPos;
- ScRefFlags nRes = aPos.Parse(pIdItem->GetValue(),
- GetViewData()->GetDocument(),
- ScAddress::Details(formula::FormulaGrammar::AddressConvention::CONV_ODF));
- if (nRes & ScRefFlags::VALID)
- {
- pTabViewShell->SetTabNo(aPos.Tab());
- pTabViewShell->SetCursor(aPos.Col(), aPos.Row());
+ OUString aCellId = pIdItem->GetValue();
+ if (!aCellId.isEmpty())
+ {
+ ScDocument& rDoc = GetViewData()->GetDocShell()->GetDocument();
+ std::vector<sc::NoteEntry> aNotes;
+ rDoc.GetAllNoteEntries(aNotes);
+
+ sal_uInt32 nId = aCellId.toUInt32();
+ auto lComp = [nId](const sc::NoteEntry& rNote) { return rNote.mpNote->GetId() == nId; };
+
+ const auto& aFoundNoteIt = std::find_if(aNotes.begin(), aNotes.end(), lComp);
+ if (aFoundNoteIt != aNotes.end())
+ {
+ ScAddress aFoundPos = aFoundNoteIt->maPos;
+ pTabViewShell->SetTabNo(aFoundPos.Tab());
+ pTabViewShell->SetCursor(aFoundPos.Col(), aFoundPos.Row());
+ }
}
}
More information about the Libreoffice-commits
mailing list