Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svx/annotation/Annotation.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#pragma once
11
12
#include <com/sun/star/geometry/RealPoint2D.hpp>
13
#include <com/sun/star/geometry/RealSize2D.hpp>
14
#include <com/sun/star/util/DateTime.hpp>
15
16
#include <svx/svdundo.hxx>
17
#include <svx/svxdllapi.h>
18
19
#include <com/sun/star/office/XAnnotation.hpp>
20
#include <comphelper/compbase.hxx>
21
#include <cppuhelper/propertysetmixin.hxx>
22
#include <svx/annotation/TextAPI.hxx>
23
#include <tools/UniqueID.hxx>
24
#include <vcl/bitmap.hxx>
25
26
class SdrUndoAction;
27
class SfxViewShell;
28
class SdrPage;
29
30
namespace sdr::annotation
31
{
32
class Annotation;
33
34
/** Type of the annotation / comment change. */
35
enum class CommentNotificationType
36
{
37
    Add,
38
    Modify,
39
    Remove
40
};
41
42
/** LOKit notify for a view */
43
SVXCORE_DLLPUBLIC void LOKCommentNotify(CommentNotificationType nType,
44
                                        const SfxViewShell* pViewShell, Annotation& rAnnotation);
45
46
/** LOKit notify for all views */
47
SVXCORE_DLLPUBLIC void LOKCommentNotifyAll(CommentNotificationType nType, Annotation& rAnnotation);
48
49
/** Type of the annotation (that is supported) */
50
enum class AnnotationType
51
{
52
    None,
53
    Square,
54
    Polygon,
55
    Circle,
56
    Ink,
57
    Highlight,
58
    Line,
59
    FreeText,
60
    Stamp
61
};
62
63
/** Annotation data that is used at annotation creation */
64
struct CreationInfo
65
{
66
    AnnotationType meType = AnnotationType::None;
67
68
    std::vector<basegfx::B2DPolygon> maPolygons;
69
    basegfx::B2DRectangle maRectangle;
70
71
    float mnWidth = 0.0f;
72
73
    bool mbFillColor = false;
74
    Color maFillColor = COL_TRANSPARENT;
75
76
    bool mbColor = false;
77
    Color maColor = COL_TRANSPARENT;
78
79
    Bitmap maBitmap;
80
};
81
82
/** Data of an annotation */
83
struct SVXCORE_DLLPUBLIC AnnotationData
84
{
85
    css::geometry::RealPoint2D m_Position;
86
    css::geometry::RealSize2D m_Size;
87
    OUString m_Author;
88
    OUString m_Initials;
89
    css::util::DateTime m_DateTime;
90
    OUString m_Text;
91
92
    /// Threaded-comment participation. Set by filters that support
93
    /// per-annotation reply/resolve (currently only the PDF filter).
94
    bool m_Threaded = false;
95
    /// Resolved / done flag. Only meaningful when m_Threaded is true.
96
    bool m_Resolved = false;
97
    /// GetId() of the parent annotation; 0 means "thread root".
98
    /// Only meaningful when m_Threaded is true.
99
    sal_uInt64 m_ParentId = 0;
100
};
101
102
/** Annotation object, responsible for handling of the annotation.
103
 *
104
 * Implements the XAnnotation UNO API, handles undo/redo and notifications ()
105
 *
106
 **/
107
class SVXCORE_DLLPUBLIC Annotation
108
    : public ::comphelper::WeakComponentImplHelper<css::office::XAnnotation>,
109
      public ::cppu::PropertySetMixin<css::office::XAnnotation>
110
{
111
private:
112
    css::uno::Reference<css::text::XText> getTextRangeImpl(const std::unique_lock<std::mutex>& g);
113
    OUString GetTextImpl(const std::unique_lock<std::mutex>& g);
114
    void SetTextImpl(OUString const& rText, const std::unique_lock<std::mutex>& g);
115
116
protected:
117
    SdrPage* mpPage;
118
    UniqueID maUniqueID;
119
120
    css::geometry::RealPoint2D m_Position;
121
    css::geometry::RealSize2D m_Size;
122
    OUString m_Author;
123
    OUString m_Initials;
124
    css::util::DateTime m_DateTime;
125
    rtl::Reference<sdr::annotation::TextApiObject> m_TextRange;
126
127
    CreationInfo maCreationInfo;
128
129
    // Threaded-comment metadata; see AnnotationData for semantics.
130
    bool m_Threaded = false;
131
    bool m_Resolved = false;
132
    sal_uInt64 m_ParentId = 0;
133
134
    std::unique_ptr<SdrUndoAction> createUndoAnnotation();
135
136
public:
137
    Annotation(const css::uno::Reference<css::uno::XComponentContext>& context, SdrPage* pPage);
138
    Annotation(const Annotation&) = delete;
139
    Annotation& operator=(const Annotation&) = delete;
140
141
    // XInterface:
142
    virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& type) override;
143
    virtual void SAL_CALL acquire() noexcept override
144
376
    {
145
376
        comphelper::WeakComponentImplHelper<css::office::XAnnotation>::acquire();
146
376
    }
147
    virtual void SAL_CALL release() noexcept override
148
376
    {
149
376
        comphelper::WeakComponentImplHelper<css::office::XAnnotation>::release();
150
376
    }
151
152
    // Changes without triggering notification broadcast
153
    void SetPosition(const css::geometry::RealPoint2D& rValue);
154
    void SetSize(const css::geometry::RealSize2D& rValue);
155
156
    virtual css::uno::Reference<css::text::XText> SAL_CALL getTextRange() override;
157
158
    // override WeakComponentImplHelperBase::disposing()
159
    // This function is called upon disposing the component,
160
    // if your component needs special work when it becomes
161
    // disposed, do it here.
162
    virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
163
164
    OUString GetText();
165
166
    OString ToJSON(CommentNotificationType nType);
167
    void toData(AnnotationData& rData);
168
    void fromData(const AnnotationData& rData);
169
170
0
    const rtl::Reference<sdr::annotation::TextApiObject>& getTextApiObject() { return m_TextRange; }
171
172
    SdrModel* GetModel() const;
173
0
    SdrPage const* getPage() const { return mpPage; }
174
0
    SdrPage* getPage() { return mpPage; }
175
176
    // Unique ID of the annotation
177
0
    sal_uInt64 GetId() const { return maUniqueID.getID(); }
178
179
0
    CreationInfo const& getCreationInfo() { return maCreationInfo; }
180
4
    void setCreationInfo(CreationInfo const& rCreationInfo) { maCreationInfo = rCreationInfo; }
181
182
    /// Returns true if this annotation participates in the threaded-comments
183
    /// feature (currently set only by the PDF filter).
184
0
    bool IsThreaded() const { return m_Threaded; }
185
    void SetThreaded(bool bThreaded);
186
187
    /// Returns the resolved/done flag. Only meaningful if IsThreaded().
188
0
    bool IsResolved() const { return m_Resolved; }
189
    void SetResolved(bool bResolved);
190
191
    /// GetId() of the parent annotation in the thread; 0 means "root".
192
    /// Only meaningful if IsThreaded().
193
0
    sal_uInt64 GetParentId() const { return m_ParentId; }
194
    void SetParentId(sal_uInt64 nParentId);
195
196
    SdrObject* findAnnotationObject();
197
198
    virtual rtl::Reference<Annotation> clone(SdrPage* pTargetPage) = 0;
199
};
200
201
/** Vector of annotations */
202
typedef std::vector<rtl::Reference<Annotation>> AnnotationVector;
203
204
} // namespace sdr::annotation
205
206
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */