/src/libreoffice/svx/source/annotation/AnnotationObject.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column:100 -*- */ |
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 | | #include <config_features.h> |
11 | | #include <rtl/ustring.hxx> |
12 | | #include <rtl/ustrbuf.hxx> |
13 | | |
14 | | #include <comphelper/lok.hxx> |
15 | | |
16 | | #include <sal/log.hxx> |
17 | | #include <svx/svdmodel.hxx> |
18 | | #include <svx/annotation/AnnotationObject.hxx> |
19 | | #include <svx/annotation/ObjectAnnotationData.hxx> |
20 | | #include <sdr/properties/rectangleproperties.hxx> |
21 | | #include <svx/xfillit0.hxx> |
22 | | #include <svx/xflclit.hxx> |
23 | | #include <svx/xlineit0.hxx> |
24 | | #include <svx/xlnclit.hxx> |
25 | | #include <svx/xlnwtit.hxx> |
26 | | #include <svx/sdtfsitm.hxx> |
27 | | #include <svx/sdooitm.hxx> |
28 | | #include <svx/sdtagitm.hxx> |
29 | | #include <svx/sdasitm.hxx> |
30 | | #include <svx/sdtditm.hxx> |
31 | | #include <svtools/colorcfg.hxx> |
32 | | |
33 | | #include <vcl/settings.hxx> |
34 | | #include <vcl/svapp.hxx> |
35 | | #include <editeng/fhgtitem.hxx> |
36 | | #include <editeng/colritem.hxx> |
37 | | #include <o3tl/unit_conversion.hxx> |
38 | | |
39 | | using namespace css; |
40 | | |
41 | | namespace sdr::annotation |
42 | | { |
43 | | namespace |
44 | | { |
45 | | OUString createInitials(OUString const& rName) |
46 | 0 | { |
47 | 0 | OUStringBuffer sInitials; |
48 | |
|
49 | 0 | const sal_Unicode* pStr = rName.getStr(); |
50 | 0 | sal_Int32 nLength = rName.getLength(); |
51 | |
|
52 | 0 | while (nLength) |
53 | 0 | { |
54 | | // skip whitespace |
55 | 0 | while (nLength && (*pStr <= ' ')) |
56 | 0 | { |
57 | 0 | nLength--; |
58 | 0 | pStr++; |
59 | 0 | } |
60 | | |
61 | | // take letter |
62 | 0 | if (nLength) |
63 | 0 | { |
64 | 0 | sInitials.append(*pStr); |
65 | 0 | nLength--; |
66 | 0 | pStr++; |
67 | 0 | } |
68 | | |
69 | | // skip letters until whitespace |
70 | 0 | while (nLength && (*pStr > ' ')) |
71 | 0 | { |
72 | 0 | nLength--; |
73 | 0 | pStr++; |
74 | 0 | } |
75 | 0 | } |
76 | |
|
77 | 0 | return sInitials.makeStringAndClear(); |
78 | 0 | } |
79 | | |
80 | | Color getColorLight(sal_uInt16 aAuthorIndex) |
81 | 0 | { |
82 | 0 | if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode()) |
83 | 0 | { |
84 | 0 | svtools::ColorConfig aColorConfig; |
85 | 0 | switch (aAuthorIndex % 9) |
86 | 0 | { |
87 | 0 | case 0: |
88 | 0 | return aColorConfig.GetColorValue(svtools::AUTHOR1).nColor; |
89 | 0 | case 1: |
90 | 0 | return aColorConfig.GetColorValue(svtools::AUTHOR2).nColor; |
91 | 0 | case 2: |
92 | 0 | return aColorConfig.GetColorValue(svtools::AUTHOR3).nColor; |
93 | 0 | case 3: |
94 | 0 | return aColorConfig.GetColorValue(svtools::AUTHOR4).nColor; |
95 | 0 | case 4: |
96 | 0 | return aColorConfig.GetColorValue(svtools::AUTHOR5).nColor; |
97 | 0 | case 5: |
98 | 0 | return aColorConfig.GetColorValue(svtools::AUTHOR6).nColor; |
99 | 0 | case 6: |
100 | 0 | return aColorConfig.GetColorValue(svtools::AUTHOR7).nColor; |
101 | 0 | case 7: |
102 | 0 | return aColorConfig.GetColorValue(svtools::AUTHOR8).nColor; |
103 | 0 | case 8: |
104 | 0 | return aColorConfig.GetColorValue(svtools::AUTHOR9).nColor; |
105 | 0 | } |
106 | 0 | } |
107 | | |
108 | 0 | return COL_WHITE; |
109 | 0 | } |
110 | | } |
111 | | |
112 | | AnnotationObject::AnnotationObject(SdrModel& rSdrModel, AnnotationObject const& rSource) |
113 | 0 | : SdrRectObj(rSdrModel, rSource) |
114 | 0 | { |
115 | 0 | setup(); |
116 | 0 | } |
117 | | |
118 | | AnnotationObject::AnnotationObject(SdrModel& rSdrModel, tools::Rectangle const& rRectangle, |
119 | | sdr::annotation::AnnotationViewData const& rAnnotationViewData) |
120 | 0 | : SdrRectObj(rSdrModel, rRectangle) |
121 | 0 | , maViewData(rAnnotationViewData) |
122 | 0 | { |
123 | 0 | osl_atomic_increment(&m_refCount); |
124 | |
|
125 | 0 | const bool bUndo(rSdrModel.IsUndoEnabled()); |
126 | 0 | rSdrModel.EnableUndo(false); |
127 | 0 | MakeNameUnique(); |
128 | 0 | rSdrModel.EnableUndo(bUndo); |
129 | |
|
130 | 0 | osl_atomic_decrement(&m_refCount); |
131 | 0 | setup(); |
132 | 0 | } |
133 | | |
134 | | void AnnotationObject::setup() |
135 | 0 | { |
136 | 0 | setAsAnnotationObject(); |
137 | 0 | mbTextFrame = true; // need this so the frame can be adjusted to the text |
138 | 0 | bool bLOK = comphelper::LibreOfficeKit::isActive(); |
139 | 0 | SetVisible(getSdrModelFromSdrObject().IsPDFDocument() || !bLOK); |
140 | 0 | } |
141 | | |
142 | | void AnnotationObject::ApplyAnnotationName() |
143 | 0 | { |
144 | 0 | if (mpAnnotationData->mxAnnotation) |
145 | 0 | { |
146 | 0 | OUString sInitials(mpAnnotationData->mxAnnotation->getInitials()); |
147 | 0 | if (sInitials.isEmpty()) |
148 | 0 | sInitials = createInitials(mpAnnotationData->mxAnnotation->getAuthor()); |
149 | 0 | SetText(sInitials + u" "_ustr + OUString::number(maViewData.nIndex)); |
150 | 0 | } |
151 | 0 | else |
152 | 0 | { |
153 | 0 | SetText(u"🗅"_ustr); |
154 | 0 | } |
155 | |
|
156 | 0 | Color aColor(getColorLight(maViewData.nAuthorIndex)); |
157 | |
|
158 | 0 | SfxItemSet aItemSet = GetMergedItemSet(); |
159 | 0 | aItemSet.Put(XFillStyleItem(drawing::FillStyle_SOLID)); |
160 | 0 | aItemSet.Put(XFillColorItem(OUString(), aColor)); |
161 | |
|
162 | 0 | Color aBorderColor(aColor); |
163 | 0 | if (aColor.IsDark()) |
164 | 0 | aBorderColor.IncreaseLuminance(32); |
165 | 0 | else |
166 | 0 | aBorderColor.DecreaseLuminance(32); |
167 | |
|
168 | 0 | aItemSet.Put(XLineStyleItem(drawing::LineStyle_SOLID)); |
169 | 0 | aItemSet.Put(XLineColorItem(OUString(), aBorderColor)); |
170 | 0 | aItemSet.Put(XLineWidthItem(o3tl::convert(0, o3tl::Length::pt, o3tl::Length::mm100))); |
171 | |
|
172 | 0 | aItemSet.Put(SvxFontHeightItem(o3tl::convert(10, o3tl::Length::pt, o3tl::Length::mm100), 100, |
173 | 0 | EE_CHAR_FONTHEIGHT)); |
174 | |
|
175 | 0 | aItemSet.Put(SvxColorItem(aColor.IsDark() ? COL_WHITE : COL_BLACK, EE_CHAR_COLOR)); |
176 | |
|
177 | 0 | aItemSet.Put(SdrTextFitToSizeTypeItem(drawing::TextFitToSizeType_NONE)); |
178 | |
|
179 | 0 | aItemSet.Put(makeSdrTextWordWrapItem(false)); |
180 | 0 | aItemSet.Put(makeSdrTextAutoGrowWidthItem(true)); |
181 | 0 | aItemSet.Put(makeSdrTextAutoGrowHeightItem(true)); |
182 | 0 | aItemSet.Put(makeSdrTextLeftDistItem(50)); |
183 | 0 | aItemSet.Put(makeSdrTextRightDistItem(50)); |
184 | 0 | aItemSet.Put(makeSdrTextUpperDistItem(50)); |
185 | 0 | aItemSet.Put(makeSdrTextLowerDistItem(50)); |
186 | |
|
187 | 0 | SetMergedItemSet(aItemSet); |
188 | | |
189 | | // Update the annotation size after the auto-sizing the frame to content does its magic |
190 | 0 | auto& xAnnotationData = getAnnotationData(); |
191 | 0 | css::geometry::RealSize2D aRealSize2D{ GetLogicRect().GetWidth() / 100.0, |
192 | 0 | GetLogicRect().GetHeight() / 100.0 }; |
193 | 0 | xAnnotationData->mxAnnotation->SetSize(aRealSize2D); |
194 | 0 | } |
195 | | |
196 | 0 | AnnotationObject::~AnnotationObject() {} |
197 | | |
198 | | void AnnotationObject::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const |
199 | 0 | { |
200 | 0 | rInfo.bMoveAllowed = true; |
201 | 0 | rInfo.bResizeFreeAllowed = false; |
202 | 0 | rInfo.bResizePropAllowed = false; |
203 | 0 | rInfo.bRotateFreeAllowed = false; |
204 | 0 | rInfo.bRotate90Allowed = false; |
205 | 0 | rInfo.bMirrorFreeAllowed = false; |
206 | 0 | rInfo.bMirror45Allowed = false; |
207 | 0 | rInfo.bMirror90Allowed = false; |
208 | 0 | rInfo.bTransparenceAllowed = false; |
209 | 0 | rInfo.bShearAllowed = false; |
210 | 0 | rInfo.bEdgeRadiusAllowed = false; |
211 | 0 | rInfo.bNoOrthoDesired = false; |
212 | 0 | rInfo.bNoContortion = false; |
213 | 0 | rInfo.bCanConvToPath = false; |
214 | 0 | rInfo.bCanConvToPoly = false; |
215 | 0 | rInfo.bCanConvToContour = false; |
216 | 0 | rInfo.bCanConvToPathLineToArea = false; |
217 | 0 | rInfo.bCanConvToPolyLineToArea = false; |
218 | 0 | } |
219 | | |
220 | 0 | SdrObjKind AnnotationObject::GetObjIdentifier() const { return SdrObjKind::Annotation; } |
221 | | |
222 | | OUString AnnotationObject::TakeObjNameSingul() const |
223 | 0 | { |
224 | 0 | OUString sOutName(u"Annotation"_ustr); |
225 | 0 | OUString aName(GetName()); |
226 | |
|
227 | 0 | if (!aName.isEmpty()) |
228 | 0 | sOutName += u" '"_ustr + aName + u"'"_ustr; |
229 | |
|
230 | 0 | return sOutName; |
231 | 0 | } |
232 | | |
233 | 0 | OUString AnnotationObject::TakeObjNamePlural() const { return u"Annotations"_ustr; } |
234 | | |
235 | | rtl::Reference<SdrObject> AnnotationObject::CloneSdrObject(SdrModel& rTargetModel) const |
236 | 0 | { |
237 | 0 | return new AnnotationObject(rTargetModel, *this); |
238 | 0 | } |
239 | | |
240 | 0 | bool AnnotationObject::HasTextEdit() const { return false; } |
241 | | |
242 | | } // end sdr::annotation |
243 | | |
244 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |