summaryrefslogtreecommitdiff
path: root/svx/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-04-18 22:41:04 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-04-26 10:43:56 +0200
commitd126f57fd4bbba7ac0e4218ed30524cb9bbb5859 (patch)
treeed2ee1488dc018be981613fea88a9313e3acbd89 /svx/source
parentd119f504bf279a1bbe2e5840cfd5cbfa295fca8f (diff)
annot: move UndoAnnotation and deps. to svx, adapt svx Annotation
This moves UndoAnnotation and dependent classes to svx, refactor the code to in sdr::annotaion::Annotation so annotations in sd module still work as they have before. Change-Id: I3769069a636c30c55bc1fcf2406d990f1b44baa6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166493 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx/source')
-rw-r--r--svx/source/annotation/Annotation.cxx130
1 files changed, 130 insertions, 0 deletions
diff --git a/svx/source/annotation/Annotation.cxx b/svx/source/annotation/Annotation.cxx
index df6e2175cef6..afa8d0f525dd 100644
--- a/svx/source/annotation/Annotation.cxx
+++ b/svx/source/annotation/Annotation.cxx
@@ -8,11 +8,141 @@
*/
#include <svx/annotation/Annotation.hxx>
+#include <tools/json_writer.hxx>
+#include <sfx2/viewsh.hxx>
+#include <unotools/datetime.hxx>
+#include <comphelper/lok.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+
+using namespace css;
namespace sdr::annotation
{
+namespace
+{
+OString lcl_LOKGetCommentPayload(CommentNotificationType nType, Annotation& rAnnotation)
+{
+ tools::JsonWriter aJsonWriter;
+ {
+ auto aCommentNode = aJsonWriter.startNode("comment");
+
+ aJsonWriter.put(
+ "action",
+ (nType == CommentNotificationType::Add
+ ? "Add"
+ : (nType == CommentNotificationType::Remove
+ ? "Remove"
+ : (nType == CommentNotificationType::Modify ? "Modify" : "???"))));
+ aJsonWriter.put("id", rAnnotation.GetId());
+
+ if (nType != CommentNotificationType::Remove)
+ {
+ aJsonWriter.put("id", rAnnotation.GetId());
+ aJsonWriter.put("author", rAnnotation.GetAuthor());
+ aJsonWriter.put("dateTime", utl::toISO8601(rAnnotation.GetDateTime()));
+ aJsonWriter.put("text", rAnnotation.GetText());
+ SdrPage const* pPage = rAnnotation.getPage();
+ sal_Int64 nHash = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pPage));
+ aJsonWriter.put("parthash", pPage ? OString::number(nHash) : OString());
+ geometry::RealPoint2D const& rPoint = rAnnotation.GetPosition();
+ geometry::RealSize2D const& rSize = rAnnotation.GetSize();
+ tools::Rectangle aRectangle(
+ Point(std::round(o3tl::toTwips(rPoint.X, o3tl::Length::mm)),
+ std::round(o3tl::toTwips(rPoint.Y, o3tl::Length::mm))),
+ Size(std::round(o3tl::toTwips(rSize.Width, o3tl::Length::mm)),
+ std::round(o3tl::toTwips(rSize.Height, o3tl::Length::mm))));
+ aJsonWriter.put("rectangle", aRectangle.toString());
+ }
+ }
+ return aJsonWriter.finishAndGetAsOString();
+}
+
+class UndoAnnotation : public SdrUndoAction
+{
+public:
+ explicit UndoAnnotation(Annotation& rAnnotation)
+ : SdrUndoAction(*rAnnotation.GetModel())
+ , mrAnnotation(rAnnotation)
+ {
+ maUndoData.get(mrAnnotation);
+ }
+
+ void Undo() override
+ {
+ maRedoData.get(mrAnnotation);
+ maUndoData.set(mrAnnotation);
+ LOKCommentNotifyAll(CommentNotificationType::Modify, mrAnnotation);
+ }
+
+ void Redo() override
+ {
+ maUndoData.get(mrAnnotation);
+ maRedoData.set(mrAnnotation);
+ LOKCommentNotifyAll(CommentNotificationType::Modify, mrAnnotation);
+ }
+
+protected:
+ Annotation& mrAnnotation;
+ AnnotationData maUndoData;
+ AnnotationData maRedoData;
+};
+
+} // anonymous ns
+
+void LOKCommentNotify(CommentNotificationType nType, const SfxViewShell* pViewShell,
+ Annotation& rAnnotation)
+{
+ // callbacks only if tiled annotations are explicitly turned off by LOK client
+ if (!comphelper::LibreOfficeKit::isActive() || comphelper::LibreOfficeKit::isTiledAnnotations())
+ return;
+
+ OString aPayload = lcl_LOKGetCommentPayload(nType, rAnnotation);
+ pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload);
+}
+
+void LOKCommentNotifyAll(CommentNotificationType nType, Annotation& rAnnotation)
+{
+ // callbacks only if tiled annotations are explicitly turned off by LOK client
+ if (!comphelper::LibreOfficeKit::isActive() || comphelper::LibreOfficeKit::isTiledAnnotations())
+ return;
+
+ OString aPayload = lcl_LOKGetCommentPayload(nType, rAnnotation);
+
+ const SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+ while (pViewShell)
+ {
+ pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload);
+ pViewShell = SfxViewShell::GetNext(*pViewShell);
+ }
+}
+
+void AnnotationData::get(Annotation& rAnnotation)
+{
+ m_Position = rAnnotation.GetPosition();
+ m_Size = rAnnotation.GetSize();
+ m_Author = rAnnotation.GetAuthor();
+ m_Initials = rAnnotation.GetInitials();
+ m_DateTime = rAnnotation.GetDateTime();
+ m_Text = rAnnotation.GetText();
+}
+
+void AnnotationData::set(Annotation& rAnnotation)
+{
+ rAnnotation.SetPosition(m_Position);
+ rAnnotation.SetSize(m_Size);
+ rAnnotation.SetAuthor(m_Author);
+ rAnnotation.SetInitials(m_Initials);
+ rAnnotation.SetDateTime(m_DateTime);
+ rAnnotation.SetText(m_Text);
+}
+
sal_uInt32 Annotation::m_nLastId = 1;
+std::unique_ptr<SdrUndoAction> Annotation::createUndoAnnotation()
+{
+ return std::make_unique<UndoAnnotation>(*this);
+}
+
} // namespace sdr::annotation
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */