lok: avoid expensive fetching of a property.
[LibreOffice.git] / sd / inc / Annotation.hxx
blob2f36761a9accbf8e336d2f74a3c6676a0f08c0a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <sal/config.h>
23 #include <sal/types.h>
24 #include <memory>
26 #include <com/sun/star/office/XAnnotation.hpp>
27 #include <cppuhelper/basemutex.hxx>
28 #include <cppuhelper/compbase.hxx>
29 #include <cppuhelper/propertysetmixin.hxx>
31 #include "sdpage.hxx"
32 #include "textapi.hxx"
33 #include "sddllapi.h"
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <tools/color.hxx>
38 class SdrUndoAction;
40 namespace com::sun::star::office {
41 class XAnnotation;
44 namespace com::sun::star::uno { template <typename > class Reference; }
46 class SfxViewShell;
48 namespace sd {
50 enum class CommentNotificationType { Add, Modify, Remove };
52 void createAnnotation( css::uno::Reference< css::office::XAnnotation >& xAnnotation, SdPage* pPage );
54 std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const css::uno::Reference< css::office::XAnnotation >& xAnnotation, bool bInsert );
56 void CreateChangeUndo(const css::uno::Reference< css::office::XAnnotation >& xAnnotation);
58 sal_uInt32 getAnnotationId(const css::uno::Reference <css::office::XAnnotation>& xAnnotation);
60 const SdPage* getAnnotationPage(const css::uno::Reference<css::office::XAnnotation>& xAnnotation);
62 void LOKCommentNotify(CommentNotificationType nType, const SfxViewShell* pViewShell,
63 css::uno::Reference<css::office::XAnnotation> const & rxAnnotation);
65 void LOKCommentNotifyAll(CommentNotificationType nType,
66 css::uno::Reference<css::office::XAnnotation> const & rxAnnotation);
68 struct SD_DLLPUBLIC CustomAnnotationMarker
70 Color maLineColor;
71 Color maFillColor;
72 float mnLineWidth;
73 std::vector<basegfx::B2DPolygon> maPolygons;
76 class Annotation : private ::cppu::BaseMutex,
77 public ::cppu::WeakComponentImplHelper<css::office::XAnnotation>,
78 public ::cppu::PropertySetMixin<css::office::XAnnotation>
80 public:
81 explicit Annotation( const css::uno::Reference<css::uno::XComponentContext>& context, SdPage* pPage );
82 Annotation(const Annotation&) = delete;
83 Annotation& operator=(const Annotation&) = delete;
85 static sal_uInt32 m_nLastId;
87 SdPage* GetPage() const { return mpPage; }
88 SdrModel* GetModel() { return (mpPage != nullptr) ? &mpPage->getSdrModelFromSdrPage() : nullptr; }
89 sal_uInt32 GetId() const { return m_nId; }
91 // XInterface:
92 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) override;
93 virtual void SAL_CALL acquire() throw () override { ::cppu::WeakComponentImplHelper<css::office::XAnnotation>::acquire(); }
94 virtual void SAL_CALL release() throw () override { ::cppu::WeakComponentImplHelper<css::office::XAnnotation>::release(); }
96 // css::beans::XPropertySet:
97 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
98 virtual void SAL_CALL setPropertyValue(const OUString & aPropertyName, const css::uno::Any & aValue) override;
99 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString & PropertyName) override;
100 virtual void SAL_CALL addPropertyChangeListener(const OUString & aPropertyName, const css::uno::Reference<css::beans::XPropertyChangeListener> & xListener) override;
101 virtual void SAL_CALL removePropertyChangeListener(const OUString & aPropertyName, const css::uno::Reference<css::beans::XPropertyChangeListener> & aListener) override;
102 virtual void SAL_CALL addVetoableChangeListener(const OUString & PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener> & aListener) override;
103 virtual void SAL_CALL removeVetoableChangeListener(const OUString & PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener> & aListener) override;
105 // css::office::XAnnotation:
106 virtual css::uno::Any SAL_CALL getAnchor() override;
107 virtual css::geometry::RealPoint2D SAL_CALL getPosition() override;
108 virtual void SAL_CALL setPosition(const css::geometry::RealPoint2D & the_value) override;
109 virtual css::geometry::RealSize2D SAL_CALL getSize() override;
110 virtual void SAL_CALL setSize(const css::geometry::RealSize2D& _size) override;
111 virtual OUString SAL_CALL getAuthor() override;
112 virtual void SAL_CALL setAuthor(const OUString & the_value) override;
113 virtual OUString SAL_CALL getInitials() override;
114 virtual void SAL_CALL setInitials(const OUString & the_value) override;
115 virtual css::util::DateTime SAL_CALL getDateTime() override;
116 virtual void SAL_CALL setDateTime(const css::util::DateTime & the_value) override;
117 virtual css::uno::Reference<css::text::XText> SAL_CALL getTextRange() override;
119 void createChangeUndo();
121 void createCustomAnnotationMarker()
123 m_pCustomAnnotationMarker = std::make_unique<CustomAnnotationMarker>();
126 CustomAnnotationMarker& getCustomAnnotationMarker()
128 return *m_pCustomAnnotationMarker;
131 bool hasCustomAnnotationMarker()
133 return bool(m_pCustomAnnotationMarker);
136 private:
137 // destructor is private and will be called indirectly by the release call virtual ~Annotation() {}
139 // override WeakComponentImplHelperBase::disposing()
140 // This function is called upon disposing the component,
141 // if your component needs special work when it becomes
142 // disposed, do it here.
143 virtual void SAL_CALL disposing() override;
145 sal_uInt32 m_nId;
146 SdPage* mpPage;
147 css::geometry::RealPoint2D m_Position;
148 css::geometry::RealSize2D m_Size;
149 OUString m_Author;
150 OUString m_Initials;
151 css::util::DateTime m_DateTime;
152 rtl::Reference<TextApiObject> m_TextRange;
154 std::unique_ptr<CustomAnnotationMarker> m_pCustomAnnotationMarker;
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */