LibreOffice Module sw (master) 1
edfcol.cxx
Go to the documentation of this file.
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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <string_view>
23
24#include <editsh.hxx>
25
26#include <com/sun/star/container/XEnumerationAccess.hpp>
27#include <com/sun/star/container/XContentEnumerationAccess.hpp>
28#include <com/sun/star/document/XActionLockable.hpp>
29#include <com/sun/star/document/XDocumentProperties.hpp>
30#include <com/sun/star/drawing/FillStyle.hpp>
31#include <com/sun/star/drawing/HomogenMatrix3.hpp>
32#include <com/sun/star/drawing/LineStyle.hpp>
33#include <com/sun/star/drawing/XShape.hpp>
34#include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
35#include <com/sun/star/lang/XMultiServiceFactory.hpp>
36#include <com/sun/star/lang/XServiceInfo.hpp>
37#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
38#include <com/sun/star/text/RelOrientation.hpp>
39#include <com/sun/star/text/TextContentAnchorType.hpp>
40#include <com/sun/star/text/VertOrientation.hpp>
41#include <com/sun/star/text/WrapTextMode.hpp>
42#include <com/sun/star/text/XTextContent.hpp>
43#include <com/sun/star/text/XTextDocument.hpp>
44#include <com/sun/star/text/XTextField.hpp>
45#include <com/sun/star/text/XTextRange.hpp>
46#include <com/sun/star/text/XParagraphAppend.hpp>
47#include <com/sun/star/text/XParagraphCursor.hpp>
48#include <com/sun/star/awt/FontWeight.hpp>
49#include <com/sun/star/rdf/XMetadatable.hpp>
50#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
51#include <com/sun/star/security/XCertificate.hpp>
52
59#include <comphelper/string.hxx>
60#include <editeng/unoprnms.hxx>
64#include <svl/cryptosign.hxx>
65#include <svl/sigstruct.hxx>
66#include <utility>
67#include <vcl/svapp.hxx>
68#include <vcl/weld.hxx>
69#include <vcl/virdev.hxx>
70
71#include <redline.hxx>
72#include <poolfmt.hxx>
73#include <hintids.hxx>
74#include <doc.hxx>
75#include <IDocumentUndoRedo.hxx>
76#include <ndtxt.hxx>
77#include <paratr.hxx>
78#include <viewopt.hxx>
79#include <SwRewriter.hxx>
80#include <numrule.hxx>
81#include <swundo.hxx>
82#include <docary.hxx>
83#include <docsh.hxx>
84#include <unoprnms.hxx>
85#include <rootfrm.hxx>
86#include <pagefrm.hxx>
87#include <txtfrm.hxx>
88#include <rdfhelper.hxx>
90
91#include <unoparagraph.hxx>
92#include <strings.hrc>
93#include <undobj.hxx>
95#include <txtatr.hxx>
96#include <fmtmeta.hxx>
97#include <unotxdoc.hxx>
98#include <unotextbodyhf.hxx>
99#include <unoport.hxx>
100
103
104constexpr OUStringLiteral WATERMARK_NAME = u"PowerPlusWaterMarkObject";
105#define WATERMARK_AUTO_SIZE sal_uInt32(1)
106
107namespace
108{
109constexpr OUStringLiteral MetaFilename(u"tscp/bails.rdf");
110constexpr OUStringLiteral MetaNS(u"urn:bails");
111constexpr OUStringLiteral ParagraphSignatureRDFNamespace = u"urn:bails:loext:paragraph:signature:";
112constexpr OUStringLiteral ParagraphSignatureIdRDFName = u"urn:bails:loext:paragraph:signature:id";
113constexpr OUStringLiteral ParagraphSignatureDigestRDFName = u":digest";
114constexpr OUStringLiteral ParagraphSignatureDateRDFName = u":date";
115constexpr OUStringLiteral ParagraphSignatureUsageRDFName = u":usage";
116constexpr OUStringLiteral ParagraphSignatureLastIdRDFName = u"urn:bails:loext:paragraph:signature:lastid";
117constexpr OUStringLiteral ParagraphClassificationNameRDFName = u"urn:bails:loext:paragraph:classification:name";
118constexpr OUStringLiteral ParagraphClassificationValueRDFName = u"urn:bails:loext:paragraph:classification:value";
119constexpr OUStringLiteral ParagraphClassificationAbbrRDFName = u"urn:bails:loext:paragraph:classification:abbreviation";
120constexpr OUStringLiteral ParagraphClassificationFieldNamesRDFName = u"urn:bails:loext:paragraph:classification:fields";
121constexpr OUStringLiteral MetadataFieldServiceName = u"com.sun.star.text.textfield.MetadataField";
122constexpr OUStringLiteral DocInfoServiceName = u"com.sun.star.text.TextField.DocInfo.Custom";
123
125std::vector<OUString> lcl_getUsedPageStyles(SwViewShell const * pShell)
126{
127 std::vector<OUString> aReturn;
128
129 SwRootFrame* pLayout = pShell->GetLayout();
130 for (SwFrame* pFrame = pLayout->GetLower(); pFrame; pFrame = pFrame->GetNext())
131 {
132 SwPageFrame* pPage = static_cast<SwPageFrame*>(pFrame);
133 if (const SwPageDesc *pDesc = pPage->FindPageDesc())
134 aReturn.push_back(pDesc->GetName());
135 }
136
137 return aReturn;
138}
139
141uno::Reference<text::XTextField> lcl_findField(const uno::Reference<text::XText>& xText, const OUString& rServiceName, std::u16string_view rFieldName)
142{
143 uno::Reference<text::XTextField> xField;
144 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xText, uno::UNO_QUERY);
145 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
146 while (xParagraphs->hasMoreElements())
147 {
148 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
149 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
150 while (xTextPortions->hasMoreElements())
151 {
152 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
153 OUString aTextPortionType;
154 xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
155 if (aTextPortionType != UNO_NAME_TEXT_FIELD)
156 continue;
157
158 uno::Reference<lang::XServiceInfo> xTextField;
159 xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField;
160 if (!xTextField->supportsService(rServiceName))
161 continue;
162
163 OUString aName;
164 uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY);
165 xPropertySet->getPropertyValue(UNO_NAME_NAME) >>= aName;
166 if (aName == rFieldName)
167 {
168 xField = uno::Reference<text::XTextField>(xTextField, uno::UNO_QUERY);
169 break;
170 }
171 }
172 }
173
174 return xField;
175}
176
178bool lcl_hasField(const uno::Reference<text::XText>& xText, const OUString& rServiceName, std::u16string_view rFieldName)
179{
180 return lcl_findField(xText, rServiceName, rFieldName).is();
181}
182
184uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XText>& xText,
185 const OUString& rServiceName, OUString& rShapeName, bool& bSuccess)
186{
187 bSuccess = false;
188 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xText, uno::UNO_QUERY);
189 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
190 while (xParagraphs->hasMoreElements())
191 {
192 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
193 if (!xTextPortionEnumerationAccess.is())
194 continue;
195
196 bSuccess = true;
197
198 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
199 while (xTextPortions->hasMoreElements())
200 {
201 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
202 OUString aTextPortionType;
203 xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
204 if (aTextPortionType != "Frame")
205 continue;
206
207 uno::Reference<container::XContentEnumerationAccess> xContentEnumerationAccess(xTextPortion, uno::UNO_QUERY);
208 if (!xContentEnumerationAccess.is())
209 continue;
210
211 uno::Reference<container::XEnumeration> xEnumeration = xContentEnumerationAccess->createContentEnumeration("com.sun.star.text.TextContent");
212 if (!xEnumeration->hasMoreElements())
213 continue;
214
215 uno::Reference<lang::XServiceInfo> xWatermark(xEnumeration->nextElement(), uno::UNO_QUERY);
216 if (!xWatermark->supportsService(rServiceName))
217 continue;
218
219 uno::Reference<container::XNamed> xNamed(xWatermark, uno::UNO_QUERY);
220
221 if (!xNamed->getName().match(WATERMARK_NAME))
222 continue;
223
224 rShapeName = xNamed->getName();
225
226 uno::Reference<drawing::XShape> xShape(xWatermark, uno::UNO_QUERY);
227 return xShape;
228 }
229 }
230
231 return uno::Reference<drawing::XShape>();
232}
233
236OString lcl_getParagraphBodyText(const uno::Reference<text::XTextContent>& xText)
237{
238 OUStringBuffer strBuf;
239 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xText, uno::UNO_QUERY);
240 if (!xTextPortionEnumerationAccess.is())
241 return OString();
242
243 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
244 while (xTextPortions->hasMoreElements())
245 {
246 uno::Any elem = xTextPortions->nextElement();
247
248 //TODO: Consider including hidden and conditional texts/portions.
249 OUString aTextPortionType;
250 uno::Reference<beans::XPropertySet> xPropertySet(elem, uno::UNO_QUERY);
251 xPropertySet->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
252 if (aTextPortionType == "Text")
253 {
254 uno::Reference<text::XTextRange> xTextRange(elem, uno::UNO_QUERY);
255 if (xTextRange.is())
256 strBuf.append(xTextRange->getString());
257 }
258 }
259
260 // Cleanup the dummy characters added by fields (which we exclude).
264
265 return strBuf.makeStringAndClear().trim().toUtf8();
266}
267
268template <typename T>
269std::map<OUString, OUString> lcl_getRDFStatements(const uno::Reference<frame::XModel>& xModel,
270 const T& xRef)
271{
272 try
273 {
274 const css::uno::Reference<css::rdf::XResource> xSubject(xRef, uno::UNO_QUERY);
275 return SwRDFHelper::getStatements(xModel, MetaNS, xSubject);
276 }
277 catch (const ::css::uno::Exception&)
278 {
279 }
280
281 return std::map<OUString, OUString>();
282}
283
285std::pair<OUString, OUString> lcl_getFieldRDFByPrefix(const uno::Reference<frame::XModel>& xModel,
286 const uno::Reference<css::text::XTextField>& xField,
287 std::u16string_view sPrefix)
288{
289 for (const auto& pair : lcl_getRDFStatements(xModel, xField))
290 {
291 if (pair.first.startsWith(sPrefix))
292 return pair;
293 }
294
295 return std::make_pair(OUString(), OUString());
296}
297
299template <typename T>
300std::pair<OUString, OUString> lcl_getRDF(const uno::Reference<frame::XModel>& xModel,
301 const T& xRef,
302 const OUString& sRDFName)
303{
304 const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(xModel, xRef);
305 const auto it = aStatements.find(sRDFName);
306 return (it != aStatements.end()) ? std::make_pair(it->first, it->second) : std::make_pair(OUString(), OUString());
307}
308
311bool lcl_IsParagraphSignatureField(const uno::Reference<frame::XModel>& xModel,
312 const uno::Reference<css::text::XTextField>& xField)
313{
314 return (lcl_getRDF(xModel, xField, ParagraphSignatureIdRDFName).first == ParagraphSignatureIdRDFName);
315}
316
317uno::Reference<text::XTextField> lcl_findFieldByRDF(const uno::Reference<frame::XModel>& xModel,
318 const uno::Reference<text::XTextContent>& xParagraph,
319 const OUString& sRDFName,
320 std::u16string_view sRDFValue)
321{
322 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY);
323 if (!xTextPortionEnumerationAccess.is())
324 return uno::Reference<text::XTextField>();
325
326 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
327 if (!xTextPortions.is())
328 return uno::Reference<text::XTextField>();
329
330 while (xTextPortions->hasMoreElements())
331 {
332 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
333 OUString aTextPortionType;
334 xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
335 if (aTextPortionType != UNO_NAME_TEXT_FIELD)
336 continue;
337
338 uno::Reference<lang::XServiceInfo> xTextField;
339 xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField;
340 if (!xTextField->supportsService(MetadataFieldServiceName))
341 continue;
342
343 uno::Reference<text::XTextField> xField(xTextField, uno::UNO_QUERY);
344 const std::pair<OUString, OUString> pair = lcl_getRDF(xModel, xField, sRDFName);
345 if (pair.first == sRDFName && (sRDFValue.empty() || sRDFValue == pair.second))
346 return xField;
347 }
348
349 return uno::Reference<text::XTextField>();
350}
351
352struct SignatureDescr
353{
354 OUString msSignature;
355 OUString msUsage;
356 OUString msDate;
357
358 bool isValid() const { return !msSignature.isEmpty(); }
359};
360
361SignatureDescr lcl_getSignatureDescr(const uno::Reference<frame::XModel>& xModel,
362 const uno::Reference<css::text::XTextContent>& xParagraph,
363 std::u16string_view sFieldId)
364{
365 SignatureDescr aDescr;
366
367 const OUString prefix = ParagraphSignatureRDFNamespace + sFieldId;
368 const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(xModel, xParagraph);
369
370 const auto itSig = aStatements.find(prefix + ParagraphSignatureDigestRDFName);
371 aDescr.msSignature = (itSig != aStatements.end() ? itSig->second : OUString());
372
373 const auto itDate = aStatements.find(prefix + ParagraphSignatureDateRDFName);
374 aDescr.msDate = (itDate != aStatements.end() ? itDate->second : OUString());
375
376 const auto itUsage = aStatements.find(prefix + ParagraphSignatureUsageRDFName);
377 aDescr.msUsage = (itUsage != aStatements.end() ? itUsage->second : OUString());
378
379 return aDescr;
380}
381
382SignatureDescr lcl_getSignatureDescr(const uno::Reference<frame::XModel>& xModel,
383 const uno::Reference<css::text::XTextContent>& xParagraph,
384 const uno::Reference<css::text::XTextField>& xField)
385{
386 const OUString sFieldId = lcl_getRDF(xModel, xField, ParagraphSignatureIdRDFName).second;
387 if (!sFieldId.isEmpty())
388 return lcl_getSignatureDescr(xModel, xParagraph, sFieldId);
389
390 return SignatureDescr();
391}
392
394std::pair<bool, OUString> lcl_MakeParagraphSignatureFieldText(const SignatureDescr& aDescr,
395 const OString& utf8Text)
396{
397 OUString msg = SwResId(STR_INVALID_SIGNATURE);
398 bool valid = false;
399
400 if (aDescr.isValid())
401 {
402 const char* pData = utf8Text.getStr();
403 const std::vector<unsigned char> data(pData, pData + utf8Text.getLength());
404
405 OString encSignature;
406 if (aDescr.msSignature.convertToString(&encSignature, RTL_TEXTENCODING_UTF8, 0))
407 {
408 const std::vector<unsigned char> sig(svl::crypto::DecodeHexString(encSignature));
409 SignatureInformation aInfo(0);
410 valid = svl::crypto::Signing::Verify(data, false, sig, aInfo);
411 valid = valid
412 && aInfo.nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED;
413
414 assert(aInfo.GetSigningCertificate()); // it was valid
415 msg = SwResId(STR_SIGNED_BY) + ": " + aInfo.GetSigningCertificate()->X509Subject + ", " +
416 aDescr.msDate;
417 msg += (!aDescr.msUsage.isEmpty() ? (" (" + aDescr.msUsage + "): ") : OUString(": "));
418 msg += (valid ? SwResId(STR_VALID) : SwResId(STR_INVALID));
419 }
420 }
421
422 return std::make_pair(valid, msg);
423}
424
426std::pair<bool, OUString>
427lcl_MakeParagraphSignatureFieldText(const uno::Reference<frame::XModel>& xModel,
428 const uno::Reference<css::text::XTextContent>& xParagraph,
429 const uno::Reference<css::text::XTextField>& xField,
430 const OString& utf8Text)
431{
432 const SignatureDescr aDescr = lcl_getSignatureDescr(xModel, xParagraph, xField);
433 return lcl_MakeParagraphSignatureFieldText(aDescr, utf8Text);
434}
435
437OUString lcl_getNextSignatureId(const uno::Reference<frame::XModel>& xModel,
438 const uno::Reference<text::XTextContent>& xParagraph)
439{
440 const OUString sFieldId = lcl_getRDF(xModel, xParagraph, ParagraphSignatureLastIdRDFName).second;
441 return OUString::number(!sFieldId.isEmpty() ? sFieldId.toInt32() + 1 : 1);
442}
443
445uno::Reference<text::XTextField> lcl_InsertParagraphSignature(const uno::Reference<frame::XModel>& xModel,
446 const uno::Reference<text::XTextContent>& xParagraph,
447 const OUString& signature,
448 const OUString& usage)
449{
450 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
451 auto xField = uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName), uno::UNO_QUERY);
452
453 // Add the signature at the end.
454 xField->attach(xParagraph->getAnchor()->getEnd());
455
456 const OUString sId = lcl_getNextSignatureId(xModel, xParagraph);
457
458 const css::uno::Reference<css::rdf::XResource> xSubject(xField, uno::UNO_QUERY);
459 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xSubject, ParagraphSignatureIdRDFName, sId);
460
461 // First convert the UTC UNIX timestamp to a tools::DateTime then to local time.
462 DateTime aDateTime = DateTime::CreateFromUnixTime(time(nullptr));
463 aDateTime.ConvertToLocalTime();
464 OUStringBuffer rBuffer;
465 rBuffer.append(static_cast<sal_Int32>(aDateTime.GetYear()));
466 rBuffer.append('-');
467 if (aDateTime.GetMonth() < 10)
468 rBuffer.append('0');
469 rBuffer.append(static_cast<sal_Int32>(aDateTime.GetMonth()));
470 rBuffer.append('-');
471 if (aDateTime.GetDay() < 10)
472 rBuffer.append('0');
473 rBuffer.append(static_cast<sal_Int32>(aDateTime.GetDay()));
474
475 // Now set the RDF on the paragraph, since that's what is preserved in .doc(x).
476 const css::uno::Reference<css::rdf::XResource> xParaSubject(xParagraph, uno::UNO_QUERY);
477 const OUString prefix = ParagraphSignatureRDFNamespace + sId;
478 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, ParagraphSignatureLastIdRDFName, sId);
479 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, prefix + ParagraphSignatureDigestRDFName, signature);
480 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, prefix + ParagraphSignatureUsageRDFName, usage);
481 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, prefix + ParagraphSignatureDateRDFName, rBuffer.makeStringAndClear());
482
483 return xField;
484}
485
487bool lcl_DoUpdateParagraphSignatureField(SwDoc& rDoc,
488 const uno::Reference<css::text::XTextField>& xField,
489 const OUString& sDisplayText)
490{
491 // Disable undo to avoid introducing noise when we edit the metadata field.
492 const bool isUndoEnabled = rDoc.GetIDocumentUndoRedo().DoesUndo();
493 rDoc.GetIDocumentUndoRedo().DoUndo(false);
494 comphelper::ScopeGuard const g([&rDoc, isUndoEnabled]() {
495 rDoc.GetIDocumentUndoRedo().DoUndo(isUndoEnabled);
496 });
497
498 try
499 {
500 uno::Reference<css::text::XTextRange> xText(xField, uno::UNO_QUERY);
501 const OUString curText = xText->getString();
502 if (curText != sDisplayText)
503 {
504 xText->setString(sDisplayText);
505 return true;
506 }
507 }
508 catch (const uno::Exception&)
509 {
510 // We failed; avoid crashing.
511 DBG_UNHANDLED_EXCEPTION("sw.uno", "Failed to update paragraph signature");
512 }
513
514 return false;
515}
516
518bool lcl_UpdateParagraphSignatureField(SwDoc& rDoc,
519 const uno::Reference<frame::XModel>& xModel,
520 const uno::Reference<css::text::XTextContent>& xParagraph,
521 const uno::Reference<css::text::XTextField>& xField,
522 const OString& utf8Text)
523{
524 const OUString sDisplayText
525 = lcl_MakeParagraphSignatureFieldText(xModel, xParagraph, xField, utf8Text).second;
526 return lcl_DoUpdateParagraphSignatureField(rDoc, xField, sDisplayText);
527}
528
529void lcl_RemoveParagraphMetadataField(const uno::Reference<css::text::XTextField>& xField)
530{
531 uno::Reference<css::text::XTextRange> xParagraph(xField->getAnchor());
532 xParagraph->getText()->removeTextContent(xField);
533}
534
537bool lcl_IsParagraphClassificationField(const uno::Reference<frame::XModel>& xModel,
538 const uno::Reference<css::text::XTextField>& xField,
539 std::u16string_view sKey)
540{
541 const std::pair<OUString, OUString> rdfPair = lcl_getRDF(xModel, xField, ParagraphClassificationNameRDFName);
542 return rdfPair.first == ParagraphClassificationNameRDFName && (sKey.empty() || rdfPair.second == sKey);
543}
544
545uno::Reference<text::XTextField> lcl_FindParagraphClassificationField(const uno::Reference<frame::XModel>& xModel,
546 const rtl::Reference<SwXParagraph>& xParagraph,
547 std::u16string_view sKey = u"")
548{
549 uno::Reference<text::XTextField> xTextField;
550
551 if (!xParagraph.is())
552 return xTextField;
553
554 // Enumerate text portions to find metadata fields. This is expensive, best to enumerate fields only.
555 rtl::Reference<SwXTextPortionEnumeration> xTextPortions = xParagraph->createTextFieldsEnumeration();
556 while (xTextPortions->hasMoreElements())
557 {
558 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
559 OUString aTextPortionType;
560 xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
561 if (aTextPortionType != UNO_NAME_TEXT_FIELD)
562 continue;
563
564 uno::Reference<lang::XServiceInfo> xServiceInfo;
565 xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xServiceInfo;
566 if (!xServiceInfo->supportsService(MetadataFieldServiceName))
567 continue;
568
569 uno::Reference<text::XTextField> xField(xServiceInfo, uno::UNO_QUERY);
570 if (lcl_IsParagraphClassificationField(xModel, xField, sKey))
571 {
572 xTextField = xField;
573 break;
574 }
575 }
576
577 return xTextField;
578}
579
581uno::Reference<text::XTextField> lcl_InsertParagraphClassification(const uno::Reference<frame::XModel>& xModel,
582 const uno::Reference<text::XTextContent>& xParent)
583{
584 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
585 auto xField = uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName), uno::UNO_QUERY);
586
587 // Add the classification at the start.
588 xField->attach(xParent->getAnchor()->getStart());
589 return xField;
590}
591
593bool lcl_UpdateParagraphClassificationField(SwDoc* pDoc,
594 const uno::Reference<frame::XModel>& xModel,
595 const uno::Reference<css::text::XTextContent>& xTextNode,
596 const OUString& sKey,
597 const OUString& sValue,
598 const OUString& sDisplayText)
599{
600 // Disable undo to avoid introducing noise when we edit the metadata field.
601 const bool isUndoEnabled = pDoc->GetIDocumentUndoRedo().DoesUndo();
602 pDoc->GetIDocumentUndoRedo().DoUndo(false);
603 comphelper::ScopeGuard const g([pDoc, isUndoEnabled] () {
604 pDoc->GetIDocumentUndoRedo().DoUndo(isUndoEnabled);
605 });
606
607 uno::Reference<text::XTextField> xField = lcl_InsertParagraphClassification(xModel, xTextNode);
608
609 css::uno::Reference<css::rdf::XResource> xFieldSubject(xField, uno::UNO_QUERY);
610 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xFieldSubject, sKey, sValue);
611 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xFieldSubject, ParagraphClassificationNameRDFName, sKey);
612 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xFieldSubject, ParagraphClassificationValueRDFName, sValue);
613
614 css::uno::Reference<css::rdf::XResource> xNodeSubject(xTextNode, uno::UNO_QUERY);
615 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xNodeSubject, sKey, sValue);
616
617 return lcl_DoUpdateParagraphSignatureField(*pDoc, xField, sDisplayText);
618}
619
620void lcl_ValidateParagraphSignatures(SwDoc& rDoc, const uno::Reference<text::XTextContent>& xParagraph, const bool updateDontRemove)
621{
622 SwDocShell* pDocShell = rDoc.GetDocShell();
623 if (!pDocShell)
624 return;
625
626 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
627
628 // Check if the paragraph is signed.
629 try
630 {
631 const std::pair<OUString, OUString> pair = lcl_getRDF(xModel, xParagraph, ParagraphSignatureLastIdRDFName);
632 if (pair.second.isEmpty())
633 return;
634 }
635 catch (const ::css::uno::Exception&)
636 {
637 return;
638 }
639
640 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY);
641 if (!xTextPortionEnumerationAccess.is())
642 return;
643
644 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
645 if (!xTextPortions.is())
646 return;
647
648 // Get the text (without fields).
649 const OString utf8Text = lcl_getParagraphBodyText(xParagraph);
650 if (utf8Text.isEmpty())
651 return;
652
653 while (xTextPortions->hasMoreElements())
654 {
655 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
656 OUString aTextPortionType;
657 xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
658 if (aTextPortionType != UNO_NAME_TEXT_FIELD)
659 continue;
660
661 uno::Reference<lang::XServiceInfo> xTextField;
662 xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField;
663 if (!xTextField->supportsService(MetadataFieldServiceName))
664 continue;
665
666 uno::Reference<text::XTextField> xField(xTextField, uno::UNO_QUERY);
667 if (!lcl_IsParagraphSignatureField(xModel, xField))
668 {
669 continue;
670 }
671
672 if (updateDontRemove)
673 {
674 lcl_UpdateParagraphSignatureField(rDoc, xModel, xParagraph, xField, utf8Text);
675 }
676 else if (!lcl_MakeParagraphSignatureFieldText(xModel, xParagraph, xField, utf8Text).first)
677 {
678 rDoc.GetIDocumentUndoRedo().StartUndo(SwUndoId::PARA_SIGN_ADD, nullptr);
679 rDoc.GetIDocumentUndoRedo().AppendUndo(
680 std::make_unique<SwUndoParagraphSigning>(rDoc, xField, xParagraph, false));
681 lcl_RemoveParagraphMetadataField(xField);
682 rDoc.GetIDocumentUndoRedo().EndUndo(SwUndoId::PARA_SIGN_ADD, nullptr);
683 }
684 }
685}
686
687} // anonymous namespace
688
690{
691 return *GetDoc()->GetDfltTextFormatColl();
692}
693
695{
696 return GetDoc()->GetTextFormatColls()->size();
697}
698
700{
701 return *((*(GetDoc()->GetTextFormatColls()))[nFormatColl]);
702}
703
704static void insertFieldToDocument(uno::Reference<lang::XMultiServiceFactory> const & rxMultiServiceFactory,
705 uno::Reference<text::XText> const & rxText, uno::Reference<text::XParagraphCursor> const & rxParagraphCursor,
706 OUString const & rsKey)
707{
708 uno::Reference<beans::XPropertySet> xField(rxMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY);
709 xField->setPropertyValue(UNO_NAME_NAME, uno::Any(rsKey));
710 uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY);
711
712 rxText->insertTextContent(rxParagraphCursor, xTextContent, false);
713}
714
715static void removeAllClassificationFields(std::u16string_view rPolicy, uno::Reference<text::XText> const & rxText)
716{
717 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(rxText, uno::UNO_QUERY);
718 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
719 while (xParagraphs->hasMoreElements())
720 {
721 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
722 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
723 while (xTextPortions->hasMoreElements())
724 {
725 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
726 OUString aTextPortionType;
727 xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
728 if (aTextPortionType != UNO_NAME_TEXT_FIELD)
729 continue;
730
731 uno::Reference<lang::XServiceInfo> xTextField;
732 xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField;
733 if (!xTextField->supportsService(DocInfoServiceName))
734 continue;
735
736 OUString aName;
737 uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY);
738 xPropertySet->getPropertyValue(UNO_NAME_NAME) >>= aName;
739 if (aName.startsWith(rPolicy))
740 {
741 uno::Reference<text::XTextField> xField(xTextField, uno::UNO_QUERY);
742 rxText->removeTextContent(xField);
743 }
744 }
745 }
746}
747
748static sal_Int32 getNumberOfParagraphs(uno::Reference<text::XText> const & xText)
749{
750 uno::Reference<container::XEnumerationAccess> xParagraphEnumAccess(xText, uno::UNO_QUERY);
751 uno::Reference<container::XEnumeration> xParagraphEnum = xParagraphEnumAccess->createEnumeration();
752 sal_Int32 nResult = 0;
753 while (xParagraphEnum->hasMoreElements())
754 {
755 xParagraphEnum->nextElement();
756 nResult++;
757 }
758 return nResult;
759}
760
761static void equaliseNumberOfParagraph(std::vector<svx::ClassificationResult> const & rResults, uno::Reference<text::XText> const & xText)
762{
763 sal_Int32 nNumberOfParagraphs = 0;
764 for (svx::ClassificationResult const & rResult : rResults)
765 {
766 if (rResult.meType == svx::ClassificationType::PARAGRAPH)
767 nNumberOfParagraphs++;
768 }
769
770 while (getNumberOfParagraphs(xText) < nNumberOfParagraphs)
771 {
772 uno::Reference<text::XParagraphAppend> xParagraphAppend(xText, uno::UNO_QUERY);
773 xParagraphAppend->finishParagraph(uno::Sequence<beans::PropertyValue>());
774 }
775}
776
777void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationResult> const & rResults)
778{
779 SwDocShell* pDocShell = GetDoc()->GetDocShell();
780 if (!pDocShell)
781 return;
782
783 const SfxObjectShell* pObjSh = SfxObjectShell::Current();
784 if (!pObjSh)
785 return;
786
787 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
788 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
789 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
790 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
791
792 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
793
794 uno::Reference<document::XDocumentProperties> xDocumentProperties = pObjSh->getDocProperties();
795
797 const std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
798 for (const OUString& rPageStyleName : aUsedPageStyles)
799 {
800 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
801
802 // HEADER
803 bool bHeaderIsOn = false;
804 xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
805 uno::Reference<text::XText> xHeaderText;
806 if (bHeaderIsOn)
807 xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
808 if (xHeaderText.is())
809 removeAllClassificationFields(sPolicy, xHeaderText);
810
811 // FOOTER
812 bool bFooterIsOn = false;
813 xPageStyle->getPropertyValue(UNO_NAME_FOOTER_IS_ON) >>= bFooterIsOn;
814 uno::Reference<text::XText> xFooterText;
815 if (bFooterIsOn)
816 xPageStyle->getPropertyValue(UNO_NAME_FOOTER_TEXT) >>= xFooterText;
817 if (xFooterText.is())
818 removeAllClassificationFields(sPolicy, xFooterText);
819 }
820
821 // Clear properties
822 uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
824
825 SfxClassificationHelper aHelper(xDocumentProperties);
826
827 // Apply properties from the BA policy
828 for (svx::ClassificationResult const & rResult : rResults)
829 {
830 if (rResult.meType == svx::ClassificationType::CATEGORY)
831 {
832 aHelper.SetBACName(rResult.msName, SfxClassificationHelper::getPolicyType());
833 }
834 }
835
837
838 // Insert origin document property
840
841 // Insert full text as document property
843
844 for (const OUString& rPageStyleName : aUsedPageStyles)
845 {
846 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
847
848 // HEADER
849 bool bHeaderIsOn = false;
850 xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
851 if (!bHeaderIsOn)
852 xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_ON, uno::Any(true));
853 uno::Reference<text::XText> xHeaderText;
854 xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
855 equaliseNumberOfParagraph(rResults, xHeaderText);
856
857 // FOOTER
858 bool bFooterIsOn = false;
859 xPageStyle->getPropertyValue(UNO_NAME_FOOTER_IS_ON) >>= bFooterIsOn;
860 if (!bFooterIsOn)
861 xPageStyle->setPropertyValue(UNO_NAME_FOOTER_IS_ON, uno::Any(true));
862 uno::Reference<text::XText> xFooterText;
863 xPageStyle->getPropertyValue(UNO_NAME_FOOTER_TEXT) >>= xFooterText;
864 equaliseNumberOfParagraph(rResults, xFooterText);
865
866 // SET/DELETE WATERMARK
867 SfxWatermarkItem aWatermarkItem;
868 aWatermarkItem.SetText(aHelper.GetDocumentWatermark());
869 SetWatermark(aWatermarkItem);
870
871 uno::Reference<text::XParagraphCursor> xHeaderParagraphCursor(xHeaderText->createTextCursor(), uno::UNO_QUERY);
872 uno::Reference<text::XParagraphCursor> xFooterParagraphCursor(xFooterText->createTextCursor(), uno::UNO_QUERY);
873
874 sal_Int32 nParagraph = -1;
875
876 for (svx::ClassificationResult const & rResult : rResults)
877 {
878 switch(rResult.meType)
879 {
881 {
882 OUString sKey = aCreator.makeNumberedTextKey();
883
884 svx::classification::addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
885 insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
886 insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
887 }
888 break;
889
891 {
892 OUString sKey = aCreator.makeCategoryNameKey();
893 insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
894 insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
895 }
896 break;
897
899 {
900 OUString sKey = aCreator.makeNumberedMarkingKey();
901 svx::classification::addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
902 insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
903 insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
904 }
905 break;
906
908 {
909 OUString sKey = aCreator.makeNumberedIntellectualPropertyPartKey();
910 svx::classification::addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
911 insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
912 insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
913 }
914 break;
915
917 {
918 nParagraph++;
919
920 if (nParagraph != 0) // only jump to next paragraph, if we aren't at the first paragraph
921 {
922 xHeaderParagraphCursor->gotoNextParagraph(false);
923 xFooterParagraphCursor->gotoNextParagraph(false);
924 }
925
926 xHeaderParagraphCursor->gotoStartOfParagraph(false);
927 xFooterParagraphCursor->gotoStartOfParagraph(false);
928
929 uno::Reference<beans::XPropertySet> xHeaderPropertySet(xHeaderParagraphCursor, uno::UNO_QUERY_THROW);
930 uno::Reference<beans::XPropertySet> xFooterPropertySet(xFooterParagraphCursor, uno::UNO_QUERY_THROW);
931 if (rResult.msName == "BOLD")
932 {
933 xHeaderPropertySet->setPropertyValue("CharWeight", uno::Any(awt::FontWeight::BOLD));
934 xFooterPropertySet->setPropertyValue("CharWeight", uno::Any(awt::FontWeight::BOLD));
935 }
936 else
937 {
938 xHeaderPropertySet->setPropertyValue("CharWeight", uno::Any(awt::FontWeight::NORMAL));
939 xFooterPropertySet->setPropertyValue("CharWeight", uno::Any(awt::FontWeight::NORMAL));
940 }
941 }
942 break;
943
944 default:
945 break;
946 }
947 }
948 }
949}
950
951std::vector<svx::ClassificationResult> SwEditShell::CollectAdvancedClassification()
952{
953 std::vector<svx::ClassificationResult> aResult;
954
955 SwDocShell* pDocShell = GetDoc()->GetDocShell();
956 if (!pDocShell)
957 return aResult;
958
959 const SfxObjectShell* pObjSh = SfxObjectShell::Current();
960 if (!pObjSh)
961 return aResult;
962
963 const OUString sBlank;
964
965 uno::Reference<document::XDocumentProperties> xDocumentProperties = pObjSh->getDocProperties();
966 uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
968
969 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
970 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
971 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
972 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
973
974 std::vector<OUString> aPageStyles = lcl_getUsedPageStyles(this);
975 OUString aPageStyleString = aPageStyles.back();
976 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(aPageStyleString), uno::UNO_QUERY);
977
978 bool bHeaderIsOn = false;
979 xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
980 if (!bHeaderIsOn)
981 {
982 const OUString aValue = svx::classification::getProperty(xPropertyContainer, aCreator.makeCategoryNameKey());
983 if (!aValue.isEmpty())
984 aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, sBlank });
985
986 return aResult;
987 }
988
989 uno::Reference<text::XText> xHeaderText;
990 xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
991
992 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xHeaderText, uno::UNO_QUERY);
993 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
994
995 // set to true if category was found in the header
996 bool bFoundClassificationCategory = false;
997
998 while (xParagraphs->hasMoreElements())
999 {
1000 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
1001 if (!xTextPortionEnumerationAccess.is())
1002 continue;
1003 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
1004
1005 // Check font weight
1006 uno::Reference<beans::XPropertySet> xParagraphPropertySet(xTextPortionEnumerationAccess, uno::UNO_QUERY_THROW);
1007 uno::Any aAny = xParagraphPropertySet->getPropertyValue("CharWeight");
1008
1009 OUString sWeight = (aAny.get<float>() >= awt::FontWeight::BOLD) ? OUString("BOLD") : OUString("NORMAL");
1010
1011 aResult.push_back({ svx::ClassificationType::PARAGRAPH, sWeight, sBlank, sBlank });
1012
1013 // Process portions
1014 while (xTextPortions->hasMoreElements())
1015 {
1016 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
1017 OUString aTextPortionType;
1018 xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
1019 if (aTextPortionType != UNO_NAME_TEXT_FIELD)
1020 continue;
1021
1022 uno::Reference<lang::XServiceInfo> xTextField;
1023 xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField;
1024 if (!xTextField->supportsService(DocInfoServiceName))
1025 continue;
1026
1027 OUString aName;
1028 uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY);
1029 xPropertySet->getPropertyValue(UNO_NAME_NAME) >>= aName;
1030
1031 if (aCreator.isMarkingTextKey(aName))
1032 {
1033 const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName);
1034 if (!aValue.isEmpty())
1035 aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank, sBlank });
1036 }
1037 else if (aCreator.isCategoryNameKey(aName))
1038 {
1039 const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName);
1040 if (!aValue.isEmpty())
1041 aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, sBlank });
1042 bFoundClassificationCategory = true;
1043 }
1044 else if (aCreator.isCategoryIdentifierKey(aName))
1045 {
1046 const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName);
1047 if (!aValue.isEmpty())
1048 aResult.push_back({ svx::ClassificationType::CATEGORY, sBlank, sBlank, aValue });
1049 bFoundClassificationCategory = true;
1050 }
1051 else if (aCreator.isMarkingKey(aName))
1052 {
1053 const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName);
1054 if (!aValue.isEmpty())
1055 aResult.push_back({ svx::ClassificationType::MARKING, aValue, sBlank, sBlank });
1056 }
1057 else if (aCreator.isIntellectualPropertyPartKey(aName))
1058 {
1059 const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName);
1060 if (!aValue.isEmpty())
1061 aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, sBlank, sBlank });
1062 }
1063 }
1064 }
1065
1066 if (!bFoundClassificationCategory)
1067 {
1068 const OUString aValue = svx::classification::getProperty(xPropertyContainer, aCreator.makeCategoryNameKey());
1069 if (!aValue.isEmpty())
1070 aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, sBlank });
1071 }
1072
1073 return aResult;
1074}
1075
1077{
1078 SwDocShell* pDocShell = GetDoc()->GetDocShell();
1079 if (!pDocShell)
1080 return;
1081
1083
1084 const bool bHadWatermark = !aHelper.GetDocumentWatermark().isEmpty();
1085
1086 // This updates the infobar as well.
1087 aHelper.SetBACName(rName, eType);
1088
1089 // Insert origin document property
1090 uno::Reference<beans::XPropertyContainer> xPropertyContainer = pDocShell->getDocProperties()->getUserDefinedProperties();
1093
1094 bool bHeaderIsNeeded = aHelper.HasDocumentHeader();
1095 bool bFooterIsNeeded = aHelper.HasDocumentFooter();
1096 OUString aWatermark = aHelper.GetDocumentWatermark();
1097 bool bWatermarkIsNeeded = !aWatermark.isEmpty();
1098
1099 if (!bHeaderIsNeeded && !bFooterIsNeeded && !bWatermarkIsNeeded && !bHadWatermark)
1100 return;
1101
1102 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
1103 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
1104 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
1105 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
1106 const uno::Sequence<OUString> aStyles = xStyleFamily->getElementNames();
1107
1108 for (const OUString& rPageStyleName : aStyles)
1109 {
1110 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
1111 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
1112
1113 if (bHeaderIsNeeded || bWatermarkIsNeeded || bHadWatermark)
1114 {
1115 // If the header is off, turn it on.
1116 bool bHeaderIsOn = false;
1117 xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
1118 if (!bHeaderIsOn)
1119 xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_ON, uno::Any(true));
1120
1121 // If the header already contains a document header field, no need to do anything.
1122 uno::Reference<text::XText> xHeaderText;
1123 xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
1124
1125 if (bHeaderIsNeeded)
1126 {
1127 if (!lcl_hasField(xHeaderText, DocInfoServiceName, Concat2View(SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCHEADER())))
1128 {
1129 // Append a field to the end of the header text.
1130 uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY);
1132 uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY);
1133 xHeaderText->insertTextContent(xHeaderText->getEnd(), xTextContent, /*bAbsorb=*/false);
1134 }
1135 }
1136
1137 SfxWatermarkItem aWatermarkItem;
1138 aWatermarkItem.SetText(aWatermark);
1139 SetWatermark(aWatermarkItem);
1140 }
1141
1142 if (bFooterIsNeeded)
1143 {
1144 // If the footer is off, turn it on.
1145 bool bFooterIsOn = false;
1146 xPageStyle->getPropertyValue(UNO_NAME_FOOTER_IS_ON) >>= bFooterIsOn;
1147 if (!bFooterIsOn)
1148 xPageStyle->setPropertyValue(UNO_NAME_FOOTER_IS_ON, uno::Any(true));
1149
1150 // If the footer already contains a document header field, no need to do anything.
1151 uno::Reference<text::XText> xFooterText;
1152 xPageStyle->getPropertyValue(UNO_NAME_FOOTER_TEXT) >>= xFooterText;
1154 if (!lcl_hasField(xFooterText, DocInfoServiceName, sFooter))
1155 {
1156 // Append a field to the end of the footer text.
1157 uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY);
1158 xField->setPropertyValue(UNO_NAME_NAME, uno::Any(sFooter));
1159 uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY);
1160 xFooterText->insertTextContent(xFooterText->getEnd(), xTextContent, /*bAbsorb=*/false);
1161 }
1162 }
1163 }
1164}
1165
1166// We pass xParent and xNodeSubject even though they point to the same thing because the UNO_QUERY is
1167// on a performance-sensitive path.
1169 const uno::Reference<frame::XModel>& xModel,
1170 const rtl::Reference<SwXParagraph>& xParent,
1171 const css::uno::Reference<css::rdf::XResource>& xNodeSubject,
1172 std::vector<svx::ClassificationResult> aResults)
1173{
1174 if (!xNodeSubject.is())
1175 return;
1176
1177 // Remove all paragraph classification fields.
1178 for (;;)
1179 {
1180 uno::Reference<text::XTextField> xTextField = lcl_FindParagraphClassificationField(xModel, xParent);
1181 if (!xTextField.is())
1182 break;
1183 lcl_RemoveParagraphMetadataField(xTextField);
1184 }
1185
1186 if (aResults.empty())
1187 return;
1188
1189 // Since we always insert at the start of the paragraph,
1190 // need to insert in reverse order.
1191 std::reverse(aResults.begin(), aResults.end());
1192 // Ignore "PARAGRAPH" types
1193 aResults.erase(std::remove_if(aResults.begin(),
1194 aResults.end(),
1195 [](const svx::ClassificationResult& rResult)-> bool
1196 { return rResult.meType == svx::ClassificationType::PARAGRAPH; }),
1197 aResults.end());
1198
1200 std::vector<OUString> aFieldNames;
1201 for (size_t nIndex = 0; nIndex < aResults.size(); ++nIndex)
1202 {
1203 const svx::ClassificationResult& rResult = aResults[nIndex];
1204
1205 const bool isLast = nIndex == 0;
1206 const bool isFirst = (nIndex == aResults.size() - 1);
1207 OUString sKey;
1208 OUString sValue = rResult.msName;
1209 switch (rResult.meType)
1210 {
1212 {
1213 sKey = aKeyCreator.makeNumberedTextKey();
1214 }
1215 break;
1216
1218 {
1219 if (rResult.msIdentifier.isEmpty())
1220 {
1221 sKey = aKeyCreator.makeCategoryNameKey();
1222 }
1223 else
1224 {
1225 sValue = rResult.msIdentifier;
1226 sKey = aKeyCreator.makeCategoryIdentifierKey();
1227 }
1228 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xNodeSubject, ParagraphClassificationAbbrRDFName, rResult.msAbbreviatedName);
1229 }
1230 break;
1231
1233 {
1234 sKey = aKeyCreator.makeNumberedMarkingKey();
1235 }
1236 break;
1237
1239 {
1240 sKey = aKeyCreator.makeNumberedIntellectualPropertyPartKey();
1241 }
1242 break;
1243
1244 default:
1245 break;
1246 }
1247
1248 OUString sDisplayText = (isFirst ? ("(" + rResult.msAbbreviatedName) : rResult.msAbbreviatedName);
1249 if (isLast)
1250 sDisplayText += ")";
1251 lcl_UpdateParagraphClassificationField(pDoc, xModel, xParent, sKey, sValue, sDisplayText);
1252 aFieldNames.emplace_back(sKey);
1253 }
1254
1255 // Correct the order
1256 std::reverse(aFieldNames.begin(), aFieldNames.end());
1257 OUStringBuffer sFieldNames;
1258 bool first = true;
1259 for (const OUString& rFieldName : aFieldNames)
1260 {
1261 if (!first)
1262 sFieldNames.append("/");
1263 sFieldNames.append(rFieldName);
1264 first = false;
1265 }
1266
1267 const OUString sOldFieldNames = lcl_getRDF(xModel, xNodeSubject, ParagraphClassificationFieldNamesRDFName).second;
1268 SwRDFHelper::removeStatement(xModel, MetaNS, xNodeSubject, ParagraphClassificationFieldNamesRDFName, sOldFieldNames);
1269 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xNodeSubject, ParagraphClassificationFieldNamesRDFName, sFieldNames.makeStringAndClear());
1270}
1271
1272void SwEditShell::ApplyParagraphClassification(std::vector<svx::ClassificationResult> aResults)
1273{
1274 SwDocShell* pDocShell = GetDoc()->GetDocShell();
1275 if (!pDocShell || !GetCursor() || !GetCursor()->Start())
1276 return;
1277
1278 SwTextNode* pNode = GetCursor()->Start()->GetNode().GetTextNode();
1279 if (pNode == nullptr)
1280 return;
1281
1282 // Prevent recursive validation since this is triggered on node updates, which we do below.
1283 const bool bOldValidationFlag = SetParagraphSignatureValidation(false);
1284 comphelper::ScopeGuard const g([this, bOldValidationFlag]() {
1285 SetParagraphSignatureValidation(bOldValidationFlag);
1286 });
1287
1288 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
1290 lcl_ApplyParagraphClassification(GetDoc(), xModel, xParent, css::uno::Reference<css::rdf::XResource>(xParent), std::move(aResults));
1291}
1292
1293static std::vector<svx::ClassificationResult> lcl_CollectParagraphClassification(const uno::Reference<frame::XModel>& xModel, const uno::Reference<text::XTextContent>& xParagraph)
1294{
1295 std::vector<svx::ClassificationResult> aResult;
1296
1297 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY);
1298 if (!xTextPortionEnumerationAccess.is())
1299 return aResult;
1300
1301 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
1302
1304
1305 while (xTextPortions->hasMoreElements())
1306 {
1307 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
1308 OUString aTextPortionType;
1309 xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
1310 if (aTextPortionType != UNO_NAME_TEXT_FIELD)
1311 continue;
1312
1313 uno::Reference<lang::XServiceInfo> xField;
1314 xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xField;
1315 if (!xField->supportsService(MetadataFieldServiceName))
1316 continue;
1317
1318 uno::Reference<text::XTextField> xTextField(xField, uno::UNO_QUERY);
1320 const std::pair<OUString, OUString> rdfNamePair = lcl_getFieldRDFByPrefix(xModel, xTextField, sPolicy);
1321
1322 uno::Reference<text::XTextRange> xTextRange(xField, uno::UNO_QUERY);
1323 const OUString aName = rdfNamePair.first;
1324 const OUString aValue = rdfNamePair.second;
1325 static const OUStringLiteral sBlank(u"");
1326 if (aKeyCreator.isMarkingTextKey(aName))
1327 {
1328 aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank, sBlank });
1329 }
1330 else if (aKeyCreator.isCategoryNameKey(aName))
1331 {
1332 aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, sBlank });
1333 }
1334 else if (aKeyCreator.isCategoryIdentifierKey(aName))
1335 {
1336 aResult.push_back({ svx::ClassificationType::CATEGORY, sBlank, sBlank, aValue });
1337 }
1338 else if (aKeyCreator.isMarkingKey(aName))
1339 {
1340 aResult.push_back({ svx::ClassificationType::MARKING, aValue, sBlank, sBlank });
1341 }
1342 else if (aKeyCreator.isIntellectualPropertyPartKey(aName))
1343 {
1344 aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, xTextRange->getString(), sBlank, sBlank });
1345 }
1346 }
1347
1348 return aResult;
1349}
1350
1351std::vector<svx::ClassificationResult> SwEditShell::CollectParagraphClassification()
1352{
1353 std::vector<svx::ClassificationResult> aResult;
1354
1355 SwDocShell* pDocShell = GetDoc()->GetDocShell();
1356 if (!pDocShell || !GetCursor() || !GetCursor()->Start())
1357 return aResult;
1358
1359 SwTextNode* pNode = GetCursor()->Start()->GetNode().GetTextNode();
1360 if (pNode == nullptr)
1361 return aResult;
1362
1363 uno::Reference<text::XTextContent> xParent = SwXParagraph::CreateXParagraph(pNode->GetDoc(), pNode);
1364 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
1366}
1367
1368static sal_Int16 lcl_GetAngle(const drawing::HomogenMatrix3& rMatrix)
1369{
1370 basegfx::B2DHomMatrix aTransformation;
1371 basegfx::B2DTuple aScale;
1372 basegfx::B2DTuple aTranslate;
1373 double fRotate = 0;
1374 double fShear = 0;
1375
1376 aTransformation.set(0, 0, rMatrix.Line1.Column1);
1377 aTransformation.set(0, 1, rMatrix.Line1.Column2);
1378 aTransformation.set(0, 2, rMatrix.Line1.Column3);
1379 aTransformation.set(1, 0, rMatrix.Line2.Column1);
1380 aTransformation.set(1, 1, rMatrix.Line2.Column2);
1381 aTransformation.set(1, 2, rMatrix.Line2.Column3);
1382 aTransformation.set(2, 0, rMatrix.Line3.Column1);
1383 aTransformation.set(2, 1, rMatrix.Line3.Column2);
1384 aTransformation.set(2, 2, rMatrix.Line3.Column3);
1385
1386 aTransformation.decompose(aScale, aTranslate, fRotate, fShear);
1387 sal_Int16 nDeg = round(basegfx::rad2deg(fRotate));
1388 return nDeg < 0 ? round(nDeg) * -1 : round(360.0 - nDeg);
1389}
1390
1392{
1393 SwDocShell* pDocShell = GetDoc()->GetDocShell();
1394 if (!pDocShell)
1395 return SfxWatermarkItem();
1396
1397 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
1398 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
1399 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
1400 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
1401 std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
1402 for (const OUString& rPageStyleName : aUsedPageStyles)
1403 {
1404 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
1405
1406 bool bHeaderIsOn = false;
1407 xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
1408 if (!bHeaderIsOn)
1409 return SfxWatermarkItem();
1410
1411 uno::Reference<text::XText> xHeaderText;
1412 xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
1413
1414 OUString sWatermark = "";
1415 bool bSuccess = false;
1416 uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, "com.sun.star.drawing.CustomShape", sWatermark, bSuccess);
1417
1418 if (xWatermark.is())
1419 {
1420 SfxWatermarkItem aItem;
1421 uno::Reference<text::XTextRange> xTextRange(xWatermark, uno::UNO_QUERY);
1422 uno::Reference<beans::XPropertySet> xPropertySet(xWatermark, uno::UNO_QUERY);
1423 Color nColor;
1424 sal_Int16 nTransparency;
1425 OUString aFont;
1426 drawing::HomogenMatrix3 aMatrix;
1427
1428 aItem.SetText(xTextRange->getString());
1429
1430 if (xPropertySet->getPropertyValue(UNO_NAME_CHAR_FONT_NAME) >>= aFont)
1431 aItem.SetFont(aFont);
1432 if (xPropertySet->getPropertyValue(UNO_NAME_FILLCOLOR) >>= nColor)
1433 aItem.SetColor(nColor);
1434 if (xPropertySet->getPropertyValue("Transformation") >>= aMatrix)
1435 aItem.SetAngle(lcl_GetAngle(aMatrix));
1436 if (xPropertySet->getPropertyValue(UNO_NAME_FILL_TRANSPARENCE) >>= nTransparency)
1437 aItem.SetTransparency(nTransparency);
1438
1439 return aItem;
1440 }
1441 }
1442 return SfxWatermarkItem();
1443}
1444
1445static void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark,
1446 const uno::Reference<frame::XModel>& xModel,
1447 const uno::Reference<beans::XPropertySet>& xPageStyle,
1448 const uno::Reference<text::XText>& xHeaderText)
1449{
1450 if (!xHeaderText.is())
1451 return;
1452
1453 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
1454 OUString aShapeServiceName = "com.sun.star.drawing.CustomShape";
1455 OUString sWatermark = WATERMARK_NAME;
1456 bool bSuccess = false;
1457 uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark, bSuccess);
1458
1459 bool bDeleteWatermark = rWatermark.GetText().isEmpty();
1460 if (xWatermark.is())
1461 {
1462 drawing::HomogenMatrix3 aMatrix;
1463 Color nColor = 0xc0c0c0;
1464 sal_Int16 nTransparency = 50;
1465 sal_Int16 nAngle = 45;
1466 OUString aFont = "";
1467
1468 uno::Reference<beans::XPropertySet> xPropertySet(xWatermark, uno::UNO_QUERY);
1469 xPropertySet->getPropertyValue(UNO_NAME_CHAR_FONT_NAME) >>= aFont;
1470 xPropertySet->getPropertyValue(UNO_NAME_FILLCOLOR) >>= nColor;
1471 xPropertySet->getPropertyValue(UNO_NAME_FILL_TRANSPARENCE) >>= nTransparency;
1472 xPropertySet->getPropertyValue("Transformation") >>= aMatrix;
1473 nAngle = lcl_GetAngle(aMatrix);
1474
1475 // If the header already contains a watermark, see if it its text is up to date.
1476 uno::Reference<text::XTextRange> xTextRange(xWatermark, uno::UNO_QUERY);
1477 if (xTextRange->getString() != rWatermark.GetText()
1478 || aFont != rWatermark.GetFont()
1479 || nColor != rWatermark.GetColor()
1480 || nAngle != rWatermark.GetAngle()
1481 || nTransparency != rWatermark.GetTransparency()
1482 || bDeleteWatermark)
1483 {
1484 // No: delete it and we'll insert a replacement.
1485 uno::Reference<lang::XComponent> xComponent(xWatermark, uno::UNO_QUERY);
1486 xComponent->dispose();
1487 xWatermark.clear();
1488 }
1489 }
1490
1491 if (!bSuccess || xWatermark.is() || bDeleteWatermark)
1492 return;
1493
1494 const OUString& sFont = rWatermark.GetFont();
1495 sal_Int16 nAngle = rWatermark.GetAngle();
1496 sal_Int16 nTransparency = rWatermark.GetTransparency();
1497 Color nColor = rWatermark.GetColor();
1498
1499 // Calc the ratio.
1500 double fRatio = 0;
1501
1503 vcl::Font aFont = pDevice->GetFont();
1504 aFont.SetFamilyName(sFont);
1505 aFont.SetFontSize(Size(0, 96));
1506 pDevice->SetFont(aFont);
1507
1508 auto nTextWidth = pDevice->GetTextWidth(rWatermark.GetText());
1509 if (nTextWidth)
1510 {
1511 fRatio = pDevice->GetTextHeight();
1512 fRatio /= nTextWidth;
1513 }
1514
1515 // Calc the size.
1516 sal_Int32 nWidth = 0;
1517 awt::Size aSize;
1518 xPageStyle->getPropertyValue(UNO_NAME_SIZE) >>= aSize;
1519 if (aSize.Width < aSize.Height)
1520 {
1521 // Portrait.
1522 sal_Int32 nLeftMargin = 0;
1523 xPageStyle->getPropertyValue(UNO_NAME_LEFT_MARGIN) >>= nLeftMargin;
1524 sal_Int32 nRightMargin = 0;
1525 xPageStyle->getPropertyValue(UNO_NAME_RIGHT_MARGIN) >>= nRightMargin;
1526 nWidth = aSize.Width - nLeftMargin - nRightMargin;
1527 }
1528 else
1529 {
1530 // Landscape.
1531 sal_Int32 nTopMargin = 0;
1532 xPageStyle->getPropertyValue(UNO_NAME_TOP_MARGIN) >>= nTopMargin;
1533 sal_Int32 nBottomMargin = 0;
1534 xPageStyle->getPropertyValue(UNO_NAME_BOTTOM_MARGIN) >>= nBottomMargin;
1535 nWidth = aSize.Height - nTopMargin - nBottomMargin;
1536 }
1537 sal_Int32 nHeight = fRatio * nWidth;
1538
1539 // Create and insert the shape.
1540 uno::Reference<drawing::XShape> xShape(xMultiServiceFactory->createInstance(aShapeServiceName), uno::UNO_QUERY);
1541
1542 uno::Reference<container::XNamed> xNamed(xShape, uno::UNO_QUERY);
1543 xNamed->setName(sWatermark);
1544
1545 basegfx::B2DHomMatrix aTransformation;
1546 aTransformation.identity();
1547 aTransformation.scale(nWidth, nHeight);
1548 aTransformation.rotate(-basegfx::deg2rad(nAngle));
1549 drawing::HomogenMatrix3 aMatrix;
1550 aMatrix.Line1.Column1 = aTransformation.get(0, 0);
1551 aMatrix.Line1.Column2 = aTransformation.get(0, 1);
1552 aMatrix.Line1.Column3 = aTransformation.get(0, 2);
1553 aMatrix.Line2.Column1 = aTransformation.get(1, 0);
1554 aMatrix.Line2.Column2 = aTransformation.get(1, 1);
1555 aMatrix.Line2.Column3 = aTransformation.get(1, 2);
1556 aMatrix.Line3.Column1 = aTransformation.get(2, 0);
1557 aMatrix.Line3.Column2 = aTransformation.get(2, 1);
1558 aMatrix.Line3.Column3 = aTransformation.get(2, 2);
1559 uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
1560 xPropertySet->setPropertyValue(UNO_NAME_ANCHOR_TYPE, uno::Any(text::TextContentAnchorType_AT_CHARACTER));
1561 uno::Reference<text::XTextContent> xTextContent(xShape, uno::UNO_QUERY);
1562 xHeaderText->insertTextContent(xHeaderText->getEnd(), xTextContent, false);
1563
1564 // The remaining properties have to be set after the shape is inserted: do that in one batch to avoid flickering.
1565 uno::Reference<document::XActionLockable> xLockable(xShape, uno::UNO_QUERY);
1566 xLockable->addActionLock();
1567 xPropertySet->setPropertyValue(UNO_NAME_FILLCOLOR, uno::Any(static_cast<sal_Int32>(nColor)));
1568 xPropertySet->setPropertyValue(UNO_NAME_FILLSTYLE, uno::Any(drawing::FillStyle_SOLID));
1569 xPropertySet->setPropertyValue(UNO_NAME_FILL_TRANSPARENCE, uno::Any(nTransparency));
1570 xPropertySet->setPropertyValue(UNO_NAME_LINESTYLE, uno::Any(drawing::LineStyle_NONE));
1571 xPropertySet->setPropertyValue(UNO_NAME_OPAQUE, uno::Any(false));
1572 xPropertySet->setPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT, uno::Any(false));
1573 xPropertySet->setPropertyValue(UNO_NAME_TEXT_AUTOGROWWIDTH, uno::Any(false));
1574 xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEHEIGHT, uno::Any(nHeight));
1575 xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEWIDTH, uno::Any(nWidth));
1576 xPropertySet->setPropertyValue(UNO_NAME_TEXT_WRAP, uno::Any(text::WrapTextMode_THROUGH));
1577 xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT_RELATION, uno::Any(text::RelOrientation::PAGE_PRINT_AREA));
1578 xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT_RELATION, uno::Any(text::RelOrientation::PAGE_PRINT_AREA));
1579 xPropertySet->setPropertyValue(UNO_NAME_CHAR_FONT_NAME, uno::Any(sFont));
1580 xPropertySet->setPropertyValue(UNO_NAME_CHAR_HEIGHT, uno::Any(WATERMARK_AUTO_SIZE));
1581 xPropertySet->setPropertyValue("Transformation", uno::Any(aMatrix));
1582
1583 uno::Reference<text::XTextRange> xTextRange(xShape, uno::UNO_QUERY);
1584 xTextRange->setString(rWatermark.GetText());
1585
1586 uno::Reference<drawing::XEnhancedCustomShapeDefaulter> xDefaulter(xShape, uno::UNO_QUERY);
1587 xDefaulter->createCustomShapeDefaults("fontwork-plain-text");
1588
1589 auto aGeomPropSeq = xPropertySet->getPropertyValue("CustomShapeGeometry").get< uno::Sequence<beans::PropertyValue> >();
1590 auto aGeomPropVec = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(aGeomPropSeq);
1591 uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
1592 {
1593 {"TextPath", uno::Any(true)},
1594 }));
1595 auto it = std::find_if(aGeomPropVec.begin(), aGeomPropVec.end(), [](const beans::PropertyValue& rValue)
1596 {
1597 return rValue.Name == "TextPath";
1598 });
1599 if (it == aGeomPropVec.end())
1600 aGeomPropVec.push_back(comphelper::makePropertyValue("TextPath", aPropertyValues));
1601 else
1602 it->Value <<= aPropertyValues;
1603 xPropertySet->setPropertyValue("CustomShapeGeometry", uno::Any(comphelper::containerToSequence(aGeomPropVec)));
1604
1605 // tdf#108494, tdf#109313 the header height was switched to height of a watermark
1606 // and shape was moved to the lower part of a page, force position update
1607 xPropertySet->getPropertyValue("Transformation") >>= aMatrix;
1608 xPropertySet->setPropertyValue("Transformation", uno::Any(aMatrix));
1609
1610 xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT, uno::Any(text::HoriOrientation::CENTER));
1611 xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT, uno::Any(text::VertOrientation::CENTER));
1612
1613 xLockable->removeActionLock();
1614}
1615
1617{
1618 SwDocShell* pDocShell = GetDoc()->GetDocShell();
1619 if (!pDocShell)
1620 return;
1621 const bool bNoWatermark = rWatermark.GetText().isEmpty();
1622
1623 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
1624 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
1625 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
1626 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
1627 const uno::Sequence<OUString> aStyles = xStyleFamily->getElementNames();
1628
1629 for (const OUString& rPageStyleName : aStyles)
1630 {
1631 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
1632
1633 // If the header is off, turn it on.
1634 bool bHeaderIsOn = false;
1635 xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
1636 if (!bHeaderIsOn)
1637 {
1638 if (bNoWatermark)
1639 continue; // the style doesn't have any watermark - no need to do anything
1640
1641 xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_ON, uno::Any(true));
1642 }
1643
1644 // backup header height
1645 bool bDynamicHeight = true;
1646 sal_Int32 nOldValue;
1647 xPageStyle->getPropertyValue(UNO_NAME_HEADER_HEIGHT) >>= nOldValue;
1648 xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_DYNAMIC_HEIGHT) >>= bDynamicHeight;
1649 xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_DYNAMIC_HEIGHT, uno::Any(false));
1650
1651 // If the header already contains a document header field, no need to do anything.
1652 uno::Reference<text::XText> xHeaderText;
1653 uno::Reference<text::XText> xHeaderTextFirst;
1654 uno::Reference<text::XText> xHeaderTextLeft;
1655 uno::Reference<text::XText> xHeaderTextRight;
1656
1657 xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
1658 lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderText);
1659
1660 xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT_FIRST) >>= xHeaderTextFirst;
1661 lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderTextFirst);
1662
1663 xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT_LEFT) >>= xHeaderTextLeft;
1664 lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderTextLeft);
1665
1666 xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT_RIGHT) >>= xHeaderTextRight;
1667 lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderTextRight);
1668
1669 // tdf#108494 the header height was switched to height of a watermark
1670 // and shape was moved to the lower part of a page
1671 xPageStyle->setPropertyValue(UNO_NAME_HEADER_HEIGHT, uno::Any(sal_Int32(11)));
1672 xPageStyle->setPropertyValue(UNO_NAME_HEADER_HEIGHT, uno::Any(nOldValue));
1673 xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_DYNAMIC_HEIGHT, uno::Any(bDynamicHeight));
1674 }
1675}
1676
1678 uno::Reference<text::XTextField> xField,
1679 uno::Reference<text::XTextContent> xParent,
1680 const bool bRemove)
1681 : SwUndo(SwUndoId::PARA_SIGN_ADD, &rDoc),
1682 m_rDoc(rDoc),
1683 m_xField(std::move(xField)),
1684 m_xParent(std::move(xParent)),
1685 m_bRemove(bRemove)
1686{
1687 // Save the metadata and field content to undo/redo.
1688 uno::Reference<frame::XModel> xModel = m_rDoc.GetDocShell()->GetBaseModel();
1689 const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(xModel, m_xField);
1690 const auto it = aStatements.find(ParagraphSignatureIdRDFName);
1691 if (it != aStatements.end())
1692 m_signature = it->second;
1693
1694 const auto it2 = aStatements.find(ParagraphSignatureUsageRDFName);
1695 if (it2 != aStatements.end())
1696 m_usage = it2->second;
1697
1698 uno::Reference<css::text::XTextRange> xText(m_xField, uno::UNO_QUERY);
1699 m_display = xText->getString();
1700}
1701
1703{
1704 if (m_bRemove)
1705 Remove();
1706 else
1707 Insert();
1708}
1709
1711{
1712 if (m_bRemove)
1713 Insert();
1714 else
1715 Remove();
1716}
1717
1719{
1720}
1721
1723{
1724 // Disable undo to avoid introducing noise when we edit the metadata field.
1725 const bool isUndoEnabled = m_rDoc.GetIDocumentUndoRedo().DoesUndo();
1726 m_rDoc.GetIDocumentUndoRedo().DoUndo(false);
1727
1728 // Prevent validation since this will trigger a premature validation
1729 // upon inserting, but before setting the metadata.
1730 SwEditShell* pEditSh = m_rDoc.GetEditShell();
1731 const bool bOldValidationFlag = pEditSh && pEditSh->SetParagraphSignatureValidation(false);
1732 comphelper::ScopeGuard const g([&] () {
1733 if (pEditSh)
1734 pEditSh->SetParagraphSignatureValidation(bOldValidationFlag);
1735 m_rDoc.GetIDocumentUndoRedo().DoUndo(isUndoEnabled);
1736 });
1737
1738 m_xField = lcl_InsertParagraphSignature(m_rDoc.GetDocShell()->GetBaseModel(), m_xParent, m_signature, m_usage);
1739 lcl_DoUpdateParagraphSignatureField(m_rDoc, m_xField, m_display);
1740}
1741
1743{
1744 // Disable undo to avoid introducing noise when we edit the metadata field.
1745 const bool isUndoEnabled = m_rDoc.GetIDocumentUndoRedo().DoesUndo();
1746 m_rDoc.GetIDocumentUndoRedo().DoUndo(false);
1747
1748 // Prevent validation since this will trigger a premature validation
1749 // upon removing.
1750 SwEditShell* pEditSh = m_rDoc.GetEditShell();
1751 const bool bOldValidationFlag = pEditSh && pEditSh->SetParagraphSignatureValidation(false);
1752 comphelper::ScopeGuard const g([&] () {
1753 if (pEditSh)
1754 pEditSh->SetParagraphSignatureValidation(bOldValidationFlag);
1755 m_rDoc.GetIDocumentUndoRedo().DoUndo(isUndoEnabled);
1756 });
1757
1758 lcl_RemoveParagraphMetadataField(m_xField);
1759}
1760
1762{
1763 SwDoc& rDoc = *GetDoc();
1764 SwDocShell* pDocShell = rDoc.GetDocShell();
1765 if (!pDocShell || !GetCursor() || !GetCursor()->Start())
1766 return;
1767 const SwPosition* pPosStart = GetCursor()->Start();
1768 if (!pPosStart)
1769 return;
1770 SwTextNode* pNode = pPosStart->GetNode().GetTextNode();
1771 if (!pNode)
1772 return;
1773
1774 // Table text signing is not supported.
1775 if (pNode->FindTableNode() != nullptr)
1776 return;
1777
1778 // 1. Get the text (without fields).
1779 const uno::Reference<text::XTextContent> xParagraph = SwXParagraph::CreateXParagraph(pNode->GetDoc(), pNode);
1780 const OString utf8Text = lcl_getParagraphBodyText(xParagraph);
1781 if (utf8Text.isEmpty())
1782 return;
1783
1784 // 2. Get certificate.
1785 uno::Reference<security::XDocumentDigitalSignatures> xSigner(
1786 // here none of the version-dependent methods are called
1787 security::DocumentDigitalSignatures::createDefault(
1789
1790 uno::Sequence<css::beans::PropertyValue> aProperties;
1791 uno::Reference<security::XCertificate> xCertificate = xSigner->chooseCertificateWithProps(aProperties);
1792 if (!xCertificate.is())
1793 return;
1794
1795 // 3. Sign it.
1796 svl::crypto::Signing signing(xCertificate);
1797 signing.AddDataRange(utf8Text.getStr(), utf8Text.getLength());
1798 OStringBuffer sigBuf;
1799 if (!signing.Sign(sigBuf))
1800 return;
1801
1802 const OUString signature = OStringToOUString(sigBuf, RTL_TEXTENCODING_UTF8, 0);
1803
1804 auto it = std::find_if(std::as_const(aProperties).begin(), std::as_const(aProperties).end(), [](const beans::PropertyValue& rValue)
1805 {
1806 return rValue.Name == "Usage";
1807 });
1808
1809 OUString aUsage;
1810 if (it != std::as_const(aProperties).end())
1811 it->Value >>= aUsage;
1812
1813 // 4. Add metadata
1814 // Prevent validation since this will trigger a premature validation
1815 // upon inserting, but before setting the metadata.
1816 const bool bOldValidationFlag = SetParagraphSignatureValidation(false);
1817 comphelper::ScopeGuard const g([this, bOldValidationFlag] () {
1818 SetParagraphSignatureValidation(bOldValidationFlag);
1819 });
1820
1821 rDoc.GetIDocumentUndoRedo().StartUndo(SwUndoId::PARA_SIGN_ADD, nullptr);
1822
1823 const uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
1824 uno::Reference<css::text::XTextField> xField = lcl_InsertParagraphSignature(xModel, xParagraph, signature, aUsage);
1825
1826 lcl_UpdateParagraphSignatureField(*GetDoc(), xModel, xParagraph, xField, utf8Text);
1827
1828 rDoc.GetIDocumentUndoRedo().AppendUndo(
1829 std::make_unique<SwUndoParagraphSigning>(rDoc, xField, xParagraph, true));
1830
1831 rDoc.GetIDocumentUndoRedo().EndUndo(SwUndoId::PARA_SIGN_ADD, nullptr);
1832}
1833
1834void SwEditShell::ValidateParagraphSignatures(SwTextNode* pNode, bool updateDontRemove)
1835{
1837 return;
1838
1839 // Table text signing is not supported.
1840 if (pNode->FindTableNode() != nullptr)
1841 return;
1842
1843 // Prevent recursive validation since this is triggered on node updates, which we do below.
1844 const bool bOldValidationFlag = SetParagraphSignatureValidation(false);
1845 comphelper::ScopeGuard const g([this, bOldValidationFlag] () {
1846 SetParagraphSignatureValidation(bOldValidationFlag);
1847 });
1848
1849 uno::Reference<text::XTextContent> xParentText = SwXParagraph::CreateXParagraph(*GetDoc(), pNode);
1850 lcl_ValidateParagraphSignatures(*GetDoc(), xParentText, updateDontRemove);
1851}
1852
1854{
1855 SwDocShell* pDocShell = GetDoc()->GetDocShell();
1856 if (!pDocShell || !GetCursor() || !GetCursor()->Start() || !IsParagraphSignatureValidationEnabled())
1857 return;
1858
1859 SwPaM* pPaM = GetCursor();
1860 const SwPosition* pPosStart = pPaM->Start();
1861 SwTextNode* pNode = pPosStart->GetNode().GetTextNode();
1862 ValidateParagraphSignatures(pNode, updateDontRemove);
1863}
1864
1866{
1867 SwDocShell* pDocShell = GetDoc()->GetDocShell();
1868 if (!pDocShell || !IsParagraphSignatureValidationEnabled())
1869 return;
1870
1871 // Prevent recursive validation since this is triggered on node updates, which we do below.
1872 const bool bOldValidationFlag = SetParagraphSignatureValidation(false);
1873 comphelper::ScopeGuard const g([this, bOldValidationFlag] () {
1874 SetParagraphSignatureValidation(bOldValidationFlag);
1875 });
1876
1877 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
1878 const uno::Reference<text::XTextDocument> xDoc(xModel, uno::UNO_QUERY);
1879 uno::Reference<text::XText> xParent = xDoc->getText();
1880 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xParent, uno::UNO_QUERY);
1881 if (!xParagraphEnumerationAccess.is())
1882 return;
1883 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
1884 if (!xParagraphs.is())
1885 return;
1886 while (xParagraphs->hasMoreElements())
1887 {
1888 uno::Reference<text::XTextContent> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY);
1889 lcl_ValidateParagraphSignatures(*GetDoc(), xParagraph, updateDontRemove);
1890 }
1891}
1892
1893static uno::Reference<text::XTextField> lcl_GetParagraphMetadataFieldAtIndex(const SwDocShell* pDocSh, SwTextNode const * pNode, const sal_uLong index)
1894{
1895 uno::Reference<text::XTextField> xTextField;
1896 if (pNode != nullptr && pDocSh != nullptr)
1897 {
1899 SwTextMeta* pTextMeta = static_txtattr_cast<SwTextMeta*>(pAttr);
1900 if (pTextMeta != nullptr)
1901 {
1902 SwFormatMeta& rFormatMeta(static_cast<SwFormatMeta&>(pTextMeta->GetAttr()));
1903 if (::sw::Meta* pMeta = rFormatMeta.GetMeta())
1904 {
1905 const css::uno::Reference<css::rdf::XResource> xSubject = pMeta->MakeUnoObject();
1906 uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel();
1907 const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(xModel, xSubject);
1908 if (aStatements.find(ParagraphSignatureIdRDFName) != aStatements.end() ||
1909 aStatements.find(ParagraphClassificationNameRDFName) != aStatements.end())
1910 {
1911 xTextField = uno::Reference<text::XTextField>(xSubject, uno::UNO_QUERY);
1912 }
1913 }
1914 }
1915 }
1916
1917 return xTextField;
1918}
1919
1921{
1922 SwDocShell* pDocShell = GetDoc()->GetDocShell();
1923 if (!pDocShell || !IsParagraphSignatureValidationEnabled())
1924 return;
1925
1926 // Prevent recursive validation since this is triggered on node updates, which we do below.
1927 const bool bOldValidationFlag = SetParagraphSignatureValidation(false);
1928 comphelper::ScopeGuard const g([this, bOldValidationFlag] () {
1929 SetParagraphSignatureValidation(bOldValidationFlag);
1930 });
1931
1932 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
1933 const rtl::Reference<SwXTextDocument> xDoc(dynamic_cast<SwXTextDocument*>(xModel.get()));
1934 rtl::Reference<SwXBodyText> xBodyText = xDoc->getBodyText();
1935 if (!xBodyText.is())
1936 return;
1937 rtl::Reference<SwXParagraphEnumeration> xParagraphs = xBodyText->createParagraphEnumeration();
1938
1939 static constexpr OUStringLiteral sBlank(u"");
1941 const css::uno::Sequence<css::uno::Reference<rdf::XURI>> aGraphNames = SwRDFHelper::getGraphNames(xModel, MetaNS);
1942
1943 while (xParagraphs->hasMoreElements())
1944 {
1945 uno::Reference<text::XTextContent> xParaOrTable(xParagraphs->nextElement(), uno::UNO_QUERY);
1946 rtl::Reference<SwXParagraph> xParagraph(dynamic_cast<SwXParagraph*>(xParaOrTable.get()));
1947
1948 try
1949 {
1950 const css::uno::Reference<css::rdf::XResource> xSubject(xParagraph);
1951 const std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, aGraphNames, xSubject);
1952
1953 const auto it = aStatements.find(ParagraphClassificationFieldNamesRDFName);
1954 const OUString sFieldNames = (it != aStatements.end() ? it->second : sBlank);
1955 std::vector<svx::ClassificationResult> aResults;
1956 if (!sFieldNames.isEmpty())
1957 {
1958 assert(it != aStatements.end() && "can only be non-empty if it was valid");
1959 // Order the fields
1960 sal_Int32 nIndex = 0;
1961 do
1962 {
1963 const OUString sCurFieldName = sFieldNames.getToken(0, '/', nIndex);
1964 if (sCurFieldName.isEmpty())
1965 break;
1966
1967 const auto it2 = aStatements.find(sCurFieldName);
1968 bool bStatementFound = it2 != aStatements.end();
1969 const OUString sName = bStatementFound ? it->first : sBlank;
1970 const OUString sValue = bStatementFound ? it->second : sBlank;
1971
1972 if (aKeyCreator.isMarkingTextKey(sName))
1973 {
1974 aResults.push_back({ svx::ClassificationType::TEXT, sValue, sValue, sBlank });
1975 }
1976 else if (aKeyCreator.isCategoryNameKey(sName))
1977 {
1978 const auto it3 = aStatements.find(ParagraphClassificationAbbrRDFName);
1979 const OUString sAbbreviatedName = (it3 != aStatements.end() && !it3->second.isEmpty() ? it3->second : sValue);
1980 aResults.push_back({ svx::ClassificationType::CATEGORY, sValue, sAbbreviatedName, sBlank });
1981 }
1982 else if (aKeyCreator.isCategoryIdentifierKey(sName))
1983 {
1984 const auto it3 = aStatements.find(ParagraphClassificationAbbrRDFName);
1985 const OUString sAbbreviatedName = (it3 != aStatements.end() && !it3->second.isEmpty() ? it3->second : sValue);
1986 aResults.push_back({ svx::ClassificationType::CATEGORY, sBlank, sAbbreviatedName, sValue });
1987 }
1988 else if (aKeyCreator.isMarkingKey(sName))
1989 {
1990 aResults.push_back({ svx::ClassificationType::MARKING, sValue, sValue, sBlank });
1991 }
1992 else if (aKeyCreator.isIntellectualPropertyPartKey(sName))
1993 {
1994 aResults.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, sValue, sValue, sBlank });
1995 }
1996 }
1997 while (nIndex >= 0);
1998 }
1999
2000 // Update classification based on results.
2001 lcl_ApplyParagraphClassification(GetDoc(), xModel, xParagraph, xSubject, aResults);
2002
2003 // Get Signatures
2004 std::map<OUString, SignatureDescr> aSignatures;
2005 for (const auto& pair : lcl_getRDFStatements(xModel, uno::Reference<css::text::XTextContent>(xParagraph)))
2006 {
2007 const OUString& sName = pair.first;
2008 if (sName.startsWith(ParagraphSignatureRDFNamespace))
2009 {
2010 const OUString sSuffix = sName.copy(ParagraphSignatureRDFNamespace.getLength());
2011 const sal_Int32 index = sSuffix.indexOf(":");
2012 if (index >= 0)
2013 {
2014 const OUString id = sSuffix.copy(0, index);
2015 const OUString type = sSuffix.copy(index);
2016 const OUString& sValue = pair.second;
2017 if (type == ParagraphSignatureDateRDFName)
2018 aSignatures[id].msDate = sValue;
2019 else if (type == ParagraphSignatureUsageRDFName)
2020 aSignatures[id].msUsage = sValue;
2021 else if (type == ParagraphSignatureDigestRDFName)
2022 aSignatures[id].msSignature = sValue;
2023 }
2024 }
2025 }
2026
2027 for (const auto& pair : aSignatures)
2028 {
2029 uno::Reference<text::XTextField> xField = lcl_findFieldByRDF(xModel, xParagraph, ParagraphSignatureIdRDFName, pair.first);
2030 if (!xField.is())
2031 {
2032 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
2033 xField = uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName), uno::UNO_QUERY);
2034
2035 // Add the signature at the end.
2036 xField->attach(xParagraph->getAnchor()->getEnd());
2037
2038 const css::uno::Reference<css::rdf::XResource> xFieldSubject(xField, uno::UNO_QUERY);
2039 SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xFieldSubject, ParagraphSignatureIdRDFName, pair.first);
2040
2041 const OString utf8Text = lcl_getParagraphBodyText(xParagraph);
2042 lcl_UpdateParagraphSignatureField(*GetDoc(), xModel, xParagraph, xField, utf8Text);
2043 }
2044 }
2045
2046 lcl_ValidateParagraphSignatures(*GetDoc(), xParagraph, true); // Validate and Update signatures.
2047 }
2048 catch (const std::exception&)
2049 {
2050 }
2051 }
2052}
2053
2055{
2056 if (GetCursor() && GetCursor()->Start())
2057 {
2058 SwTextNode* pNode = GetCursor()->Start()->GetNode().GetTextNode();
2060 uno::Reference<text::XTextField> xField = lcl_GetParagraphMetadataFieldAtIndex(GetDoc()->GetDocShell(), pNode, index);
2061 return xField.is();
2062 }
2063
2064 return false;
2065}
2066
2068{
2069 if (GetCursor() && GetCursor()->Start())
2070 {
2071 SwTextNode* pNode = GetCursor()->Start()->GetNode().GetTextNode();
2073 uno::Reference<text::XTextField> xField = lcl_GetParagraphMetadataFieldAtIndex(GetDoc()->GetDocShell(), pNode, index);
2074 if (!xField.is())
2075 {
2076 // Try moving the cursor to see if we're _facing_ a metafield or not,
2077 // as opposed to being within one.
2078 index--; // Backspace moves left
2079
2080 xField = lcl_GetParagraphMetadataFieldAtIndex(GetDoc()->GetDocShell(), pNode, index);
2081 }
2082
2083 if (xField.is())
2084 {
2085 lcl_RemoveParagraphMetadataField(xField);
2086 return true;
2087 }
2088 }
2089
2090 return false;
2091}
2092
2094 const uno::Reference<frame::XModel>& xModel, const rtl::Reference<SwXParagraph>& xParagraph)
2095{
2096 uno::Reference<text::XTextField> xTextField;
2097 xTextField = lcl_FindParagraphClassificationField(xModel, xParagraph, rKeyCreator.makeCategoryIdentifierKey());
2098 if (xTextField.is())
2099 {
2100 const std::pair<OUString, OUString> rdfValuePair = lcl_getRDF(xModel, xTextField, ParagraphClassificationValueRDFName);
2101 return rHelper.GetBACNameForIdentifier(rdfValuePair.second);
2102 }
2103
2104 xTextField = lcl_FindParagraphClassificationField(xModel, xParagraph, rKeyCreator.makeCategoryNameKey());
2105 if (xTextField.is())
2106 {
2107 return lcl_getRDF(xModel, xTextField, ParagraphClassificationNameRDFName).second;
2108 }
2109
2110 return OUString();
2111}
2112
2114{
2115 OUString sHighestClass;
2116
2117 SwTextNode* pNode = pCursor->Start()->GetNode().GetTextNode();
2118 if (pNode == nullptr)
2119 return sHighestClass;
2120
2121 SwDocShell* pDocShell = pNode->GetDoc().GetDocShell();
2122 if (!pDocShell)
2123 return sHighestClass;
2124
2127
2128 uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
2129 const rtl::Reference<SwXTextDocument> xDoc(dynamic_cast<SwXTextDocument*>(xModel.get()));
2130 rtl::Reference<SwXBodyText> xBodyText = xDoc->getBodyText();
2131
2132 rtl::Reference<SwXParagraphEnumeration> xParagraphs = xBodyText->createParagraphEnumeration();
2133 while (xParagraphs->hasMoreElements())
2134 {
2135 uno::Reference<text::XTextContent> xParaOrTable(xParagraphs->nextElement(), uno::UNO_QUERY);
2136 rtl::Reference<SwXParagraph> xParagraph(dynamic_cast<SwXParagraph*>(xParaOrTable.get()));
2137 const OUString sCurrentClass = lcl_GetParagraphClassification(aHelper, aKeyCreator, xModel, xParagraph);
2138 sHighestClass = aHelper.GetHigherClass(sHighestClass, sCurrentClass);
2139 }
2140
2141 return sHighestClass;
2142}
2143
2145{
2146 SwDocShell* pDocShell = GetDoc()->GetDocShell();
2147 if (!pDocShell)
2148 return;
2149
2150 // Bail out as early as possible if we don't have paragraph classification.
2151 if (!SwRDFHelper::hasMetadataGraph(pDocShell->GetBaseModel(), MetaNS))
2152 return;
2153
2154 uno::Reference<document::XDocumentProperties> xDocumentProperties = pDocShell->getDocProperties();
2155 uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
2156
2158 SfxClassificationHelper aHelper(xDocumentProperties);
2159
2160 OUString sHighestClass = lcl_GetHighestClassificationParagraphClass(GetCursor());
2161
2162 const OUString aClassificationCategory = svx::classification::getProperty(xPropertyContainer, aKeyCreator.makeCategoryNameKey());
2163
2164 if (!aClassificationCategory.isEmpty())
2165 {
2166 sHighestClass = aHelper.GetHigherClass(sHighestClass, aClassificationCategory);
2167 }
2168
2169 if (aClassificationCategory != sHighestClass)
2170 {
2171 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(nullptr,
2172 VclMessageType::Question, VclButtonsType::Ok,
2173 SwResId(STR_CLASSIFICATION_LEVEL_CHANGED)));
2174 xQueryBox->run();
2175 }
2176
2177 const SfxClassificationPolicyType eHighestClassType = SfxClassificationHelper::stringToPolicyType(sHighestClass);
2178
2179 // Prevent paragraph signature validation since the below changes (f.e. watermarking) are benign.
2180 const bool bOldValidationFlag = SetParagraphSignatureValidation(false);
2181 comphelper::ScopeGuard const g([this, bOldValidationFlag]() {
2182 SetParagraphSignatureValidation(bOldValidationFlag);
2183 });
2184
2185 // Check the origin, if "manual" (created via advanced classification dialog),
2186 // then we just need to set the category name.
2187 if (sfx::getCreationOriginProperty(xPropertyContainer, aKeyCreator) == sfx::ClassificationCreationOrigin::MANUAL)
2188 {
2189 aHelper.SetBACName(sHighestClass, eHighestClassType);
2191 }
2192 else
2193 {
2194 SetClassification(sHighestClass, eHighestClassType);
2195 }
2196}
2197
2198// #i62675#
2200 const bool bResetListAttrs)
2201{
2202 SwTextFormatColl *pLocal = pFormat? pFormat: (*GetDoc()->GetTextFormatColls())[0];
2204
2205 SwRewriter aRewriter;
2206
2207 aRewriter.AddRule(UndoArg1, pLocal->GetName());
2208
2209 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::SETFMTCOLL, &aRewriter);
2210 for(SwPaM& rPaM : GetCursor()->GetRingContainer())
2211 {
2212 if (!rPaM.HasReadonlySel( GetViewOptions()->IsFormView(), true))
2213 {
2214 // store previous paragraph style for track changes
2215 OUString sParaStyleName;
2216 sal_uInt16 nPoolId = USHRT_MAX;
2217 SwContentNode * pCnt = rPaM.Start()->GetNode().GetContentNode();
2218 if ( pCnt && pCnt->GetTextNode() && GetDoc()->getIDocumentRedlineAccess().IsRedlineOn() )
2219 {
2220 const SwTextFormatColl* pTextFormatColl = pCnt->GetTextNode()->GetTextColl();
2221 sal_uInt16 nStylePoolId = pTextFormatColl->GetPoolFormatId();
2222 // default paragraph style
2223 if ( nStylePoolId == RES_POOLCOLL_STANDARD )
2224 nPoolId = nStylePoolId;
2225 else
2226 sParaStyleName = pTextFormatColl->GetName();
2227 }
2228
2229 // Change the paragraph style to pLocal and remove all direct paragraph formatting.
2230 GetDoc()->SetTextFormatColl(rPaM, pLocal, true, bResetListAttrs, GetLayout());
2231
2232 // If there are hints on the nodes which cover the whole node, then remove those, too.
2233 SwPaM aPaM(*rPaM.Start(), *rPaM.End());
2234 if (SwTextNode* pEndTextNode = aPaM.End()->GetNode().GetTextNode())
2235 {
2236 aPaM.Start()->SetContent(0);
2237 aPaM.End()->SetContent(pEndTextNode->GetText().getLength());
2238 }
2239 GetDoc()->RstTextAttrs(aPaM, /*bInclRefToxMark=*/false, /*bExactRange=*/true, GetLayout());
2240
2241 // add redline tracking the previous paragraph style
2243 // multi-paragraph ParagraphFormat redline ranges
2244 // haven't supported by AppendRedline(), yet
2245 // TODO handle multi-paragraph selections, too,
2246 // e.g. by breaking them to single paragraphs
2247 aPaM.Start()->GetNode() == aPaM.End()->GetNode() )
2248 {
2249 SwRangeRedline * pRedline = new SwRangeRedline( RedlineType::ParagraphFormat, aPaM );
2250 auto const result(GetDoc()->getIDocumentRedlineAccess().AppendRedline( pRedline, true));
2251 // store original paragraph style to reject formatting change
2253 ( nPoolId == RES_POOLCOLL_STANDARD || !sParaStyleName.isEmpty() ) )
2254 {
2255 std::unique_ptr<SwRedlineExtraData_FormatColl> xExtra;
2256 xExtra.reset(new SwRedlineExtraData_FormatColl(sParaStyleName, nPoolId, nullptr));
2257 if (xExtra)
2258 pRedline->SetExtraData( xExtra.get() );
2259 }
2260 }
2261 }
2262
2263 }
2264 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::SETFMTCOLL, &aRewriter);
2265 EndAllAction();
2266}
2267
2268SwTextFormatColl* SwEditShell::MakeTextFormatColl(const OUString& rFormatCollName,
2269 SwTextFormatColl* pParent)
2270{
2271 SwTextFormatColl *pColl;
2272 if ( pParent == nullptr )
2273 pParent = &GetTextFormatColl(0);
2274 pColl = GetDoc()->MakeTextFormatColl(rFormatCollName, pParent);
2275 if ( pColl == nullptr )
2276 {
2277 OSL_FAIL( "MakeTextFormatColl failed" );
2278 }
2279 return pColl;
2280
2281}
2282
2284{
2285 SwPaM * pCursor = GetCursor();
2286 SwContentNode * pCnt = pCursor->GetPointContentNode();
2287 if (pCnt->IsTextNode()) // uhm... what nonsense would happen if not?
2288 { // only need properties-node because BREAK/PAGEDESC filtered anyway!
2289 pCnt = sw::GetParaPropsNode(*GetLayout(), pCursor->GetPoint()->GetNode());
2290 }
2291 const SfxItemSet* pSet = pCnt->GetpSwAttrSet();
2292 if( !pSet )
2293 return;
2294
2295 // JP 05.10.98: Special treatment if one of the attributes Break/PageDesc/NumRule(auto) is
2296 // in the ItemSet. Otherwise there will be too much or wrong processing (NumRules!)
2297 // Bug 57568
2298
2299 // Do NOT copy AutoNumRules into the template
2300 const SwNumRuleItem* pItem;
2301 const SwNumRule* pRule = nullptr;
2302 if (SfxItemState::SET == pSet->GetItemState(RES_BREAK, false)
2303 || SfxItemState::SET == pSet->GetItemState(RES_PAGEDESC, false)
2304 || ((pItem = pSet->GetItemIfSet(RES_PARATR_NUMRULE, false))
2305 && nullptr != (pRule = GetDoc()->FindNumRulePtr(pItem->GetValue()))
2306 && pRule->IsAutoRule()))
2307 {
2308 SfxItemSet aSet( *pSet );
2309 aSet.ClearItem( RES_BREAK );
2310 aSet.ClearItem( RES_PAGEDESC );
2311
2312 if (pRule
2313 || ((pItem = pSet->GetItemIfSet(RES_PARATR_NUMRULE, false))
2314 && nullptr != (pRule = GetDoc()->FindNumRulePtr(pItem->GetValue()))
2315 && pRule->IsAutoRule()))
2317
2318 if( aSet.Count() )
2319 GetDoc()->ChgFormat(*pColl, aSet );
2320 }
2321 else
2322 GetDoc()->ChgFormat(*pColl, *pSet );
2323}
2324
2325/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertyValueVector_t aPropertyValues
@ UndoArg1
Definition: SwRewriter.hxx:29
PropertiesInfo aProperties
const char *const aFieldNames[]
Definition: authfld.cxx:748
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
const OUString & GetValue() const
static DateTime CreateFromUnixTime(const double fSecondsSinceEpoch)
void ConvertToLocalTime()
sal_Int16 GetYear() const
sal_uInt16 GetDay() const
sal_uInt16 GetMonth() const
static const OUString & PROP_DOCFOOTER()
static SfxClassificationPolicyType getPolicyType()
OUString GetBACNameForIdentifier(std::u16string_view sIdentifier)
static const OUString & PROP_DOCHEADER()
static SfxClassificationPolicyType stringToPolicyType(std::u16string_view rType)
static const OUString & policyTypeToString(SfxClassificationPolicyType eType)
static const OUString & PROP_PREFIX_INTELLECTUALPROPERTY()
sal_uInt16 Count() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
css::uno::Reference< css::document::XDocumentProperties > getDocProperties() const
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
void SetFont(const OUString &aFont)
sal_Int16 GetTransparency() const
OUString const & GetFont() const
void SetAngle(const sal_Int16 nAngle)
OUString const & GetText() const
void SetTransparency(const sal_Int16 nTransparency)
void SetColor(Color nColor)
void SetText(const OUString &aText)
sal_Int16 GetAngle() const
Color GetColor() const
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:493
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
Definition: doc.hxx:195
void RstTextAttrs(const SwPaM &rRg, bool bInclRefToxMark=false, bool bExactRange=false, SwRootFrame const *pLayout=nullptr)
Definition: docfmt.cxx:222
void ChgFormat(SwFormat &rFormat, const SfxItemSet &rSet)
Definition: docfmt.cxx:1871
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:152
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:330
const SwTextFormatColls * GetTextFormatColls() const
Definition: doc.hxx:789
const SwTextFormatColl * GetDfltTextFormatColl() const
Definition: doc.hxx:787
SwTextFormatColl * MakeTextFormatColl(const OUString &rFormatName, SwTextFormatColl *pDerivedFrom, bool bBroadcast=false)
Create the FormatCollections.
Definition: docfmt.cxx:888
bool SetTextFormatColl(const SwPaM &rRg, SwTextFormatColl *pFormat, const bool bReset=true, const bool bResetListAttrs=false, SwRootFrame const *pLayout=nullptr)
Add 4th optional parameter <bResetListAttrs>.
Definition: docfmt.cxx:1081
SwDocShell * GetDocShell()
Definition: doc.hxx:1364
std::vector< svx::ClassificationResult > CollectAdvancedClassification()
Definition: edfcol.cxx:951
void ApplyParagraphClassification(std::vector< svx::ClassificationResult > aResult)
Apply the classification to the paragraph at cursor.
Definition: edfcol.cxx:1272
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
void SetWatermark(const SfxWatermarkItem &rText)
Definition: edfcol.cxx:1616
void SignParagraph()
Sign the paragraph at the cursor.
Definition: edfcol.cxx:1761
bool IsRedlineOn() const
Definition: edredln.cxx:43
bool RemoveParagraphMetadataFieldAtCursor()
Removes the paragraph metadata field at the current cursor, if any.
Definition: edfcol.cxx:2067
void ValidateAllParagraphSignatures(bool updateDontRemove)
Validate all paragraph signatures.
Definition: edfcol.cxx:1865
bool IsCursorInParagraphMetadataField() const
Returns true iff the cursor is within a paragraph metadata field.
Definition: edfcol.cxx:2054
SwTextFormatColl & GetTextFormatColl(sal_uInt16 nTextFormatColl) const
Definition: edfcol.cxx:699
sal_uInt16 GetTextFormatCollCount() const
Definition: edfcol.cxx:694
bool SetParagraphSignatureValidation(const bool bEnable)
Enable/Disable paragraph signature validation and return the previous value.
Definition: editsh.hxx:976
void RestoreMetadataFieldsAndValidateParagraphSignatures()
Restore the metadata fields, if missing, from the RDF metadata and validate the signatures and update...
Definition: edfcol.cxx:1920
void SetTextFormatColl(SwTextFormatColl *, const bool bResetListAttrs=false)
Add 2nd optional parameter <bResetListAttrs> - see also <SwDoc::SetTextFormatColl(....
Definition: edfcol.cxx:2199
std::vector< svx::ClassificationResult > CollectParagraphClassification()
Definition: edfcol.cxx:1351
void ValidateCurrentParagraphSignatures(bool updateDontRemove)
Validate the current paragraph signatures, if any, at the cursor start.
Definition: edfcol.cxx:1853
void SetClassification(const OUString &rName, SfxClassificationPolicyType eType)
Definition: edfcol.cxx:1076
SwTextFormatColl & GetDfltTextFormatColl() const
Definition: edfcol.cxx:689
void ApplyAdvancedClassification(std::vector< svx::ClassificationResult > const &rResult)
Definition: edfcol.cxx:777
void ClassifyDocPerHighestParagraphClass()
Ensure that the classification of the doc is never lower than the paragraph with the highest classifi...
Definition: edfcol.cxx:2144
bool IsParagraphSignatureValidationEnabled() const
Returns true iff paragraph signature validation is enabled.
Definition: editsh.hxx:974
SfxWatermarkItem GetWatermark() const
Definition: edfcol.cxx:1391
SwTextFormatColl * MakeTextFormatColl(const OUString &rFormatCollName, SwTextFormatColl *pDerivedFrom=nullptr)
Definition: edfcol.cxx:2268
void FillByEx(SwCharFormat *)
Definition: edfmt.cxx:51
void ValidateParagraphSignatures(SwTextNode *pNode, bool updateDontRemove)
Validate the paragraph signatures, if any, of the current text node.
Definition: edfcol.cxx:1834
void EndAllAction()
Definition: edws.cxx:97
::sw::Meta * GetMeta()
Definition: fmtmeta.hxx:122
sal_uInt16 GetPoolFormatId() const
Get and set Pool style IDs.
Definition: format.hxx:163
const OUString & GetName() const
Definition: format.hxx:131
Base class of the Writer layout elements.
Definition: frame.hxx:315
SwFrame * GetNext()
Definition: frame.hxx:682
SwFrame * GetLower()
Definition: findfrm.cxx:196
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:903
SwDoc & GetDoc()
Definition: node.hxx:233
bool IsTextNode() const
Definition: node.hxx:687
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:380
SwContentNode * GetContentNode()
Definition: node.hxx:666
bool IsAutoRule() const
Definition: numrule.hxx:229
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
SwContentNode * GetPointContentNode() const
Definition: pam.hxx:287
const SwPosition * End() const
Definition: pam.hxx:271
const SwPosition * GetPoint() const
Definition: pam.hxx:261
const SwPosition * Start() const
Definition: pam.hxx:266
A page of the document layout.
Definition: pagefrm.hxx:59
SwPageDesc * FindPageDesc()
Definition: pagechg.cxx:755
static void removeStatement(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType, const css::uno::Reference< css::rdf::XResource > &xSubject, const OUString &rKey, const OUString &rValue)
Remove an (XResource, key, value) statement in the graph of type rType, if it exists.
Definition: rdfhelper.cxx:131
static std::map< OUString, OUString > getStatements(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Sequence< css::uno::Reference< css::rdf::XURI > > &rGraphNames, const css::uno::Reference< css::rdf::XResource > &xSubject)
Gets all (XResource, key, value) statements in RDF graphs given the graph-names.
static void addStatement(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType, const OUString &rPath, const css::uno::Reference< css::rdf::XResource > &xSubject, const OUString &rKey, const OUString &rValue)
Add an (XResource, key, value) statement in the graph of type rType – or if it does not exist,...
Definition: rdfhelper.cxx:100
static css::uno::Sequence< css::uno::Reference< css::rdf::XURI > > getGraphNames(const css::uno::Reference< css::rdf::XDocumentMetadataAccess > &xDocumentMetadataAccess, const css::uno::Reference< css::rdf::XURI > &xType)
Gets all graph-names in RDF of a given type.
static bool hasMetadataGraph(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType)
Check if a graph of type rType exists.
Definition: rdfhelper.cxx:123
void SetExtraData(const SwRedlineExtraData *pData)
ExtraData gets copied, the pointer is therefore not taken over by the RedLineObject.
Definition: redline.hxx:229
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:25
The root element of a Writer document layout.
Definition: rootfrm.hxx:83
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:167
Represents the style of a paragraph.
Definition: fmtcol.hxx:61
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
SwTextAttr * GetTextAttrAt(sal_Int32 const nIndex, sal_uInt16 const nWhich, ::sw::GetTextAttrMode const eMode=::sw::GetTextAttrMode::Default) const
get the innermost text attribute covering position nIndex.
Definition: ndtxt.cxx:1802
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:897
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: edfcol.cxx:1702
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: edfcol.cxx:1710
SwUndoParagraphSigning(SwDoc &rDoc, css::uno::Reference< css::text::XTextField > xField, css::uno::Reference< css::text::XTextContent > xParent, const bool bRemove)
Definition: edfcol.cxx:1677
css::uno::Reference< css::text::XTextField > m_xField
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: edfcol.cxx:1718
css::uno::Reference< css::text::XTextContent > m_xParent
size_t size() const
Definition: docary.hxx:87
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:434
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2159
SwDoc * GetDoc() const
Definition: viewsh.hxx:290
const IDocumentRedlineAccess & getIDocumentRedlineAccess() const
Provides access to the document redline interface.
Definition: viewsh.cxx:2817
static rtl::Reference< SwXParagraph > CreateXParagraph(SwDoc &rDoc, SwTextNode *pTextNode, css::uno::Reference< css::text::XText > const &xParentText=nullptr, const sal_Int32 nSelStart=-1, const sal_Int32 nSelEnd=- 1)
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
void rotate(double fRadiant)
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
void scale(double fX, double fY)
SfxClassificationPolicyType
bool isMarkingKey(std::u16string_view aKey) const
bool isMarkingTextKey(std::u16string_view aKey) const
OUString makeNumberedIntellectualPropertyPartKey()
bool isCategoryIdentifierKey(std::u16string_view aKey) const
bool isCategoryNameKey(std::u16string_view aKey) const
OUString makeCategoryNameKey() const
OUString makeCategoryIdentifierKey() const
bool isIntellectualPropertyPartKey(std::u16string_view aKey) const
void AddDataRange(const void *pData, sal_Int32 size)
bool Sign(OStringBuffer &rCMSHexBuffer)
static bool Verify(const std::vector< unsigned char > &aData, const bool bNonDetached, const std::vector< unsigned char > &aSignature, SignatureInformation &rInformation)
ClassificationType meType
ring_container GetRingContainer()
Definition: ring.hxx:240
void SetFontSize(const Size &)
void SetFamilyName(const OUString &rFamilyName)
#define DBG_UNHANDLED_EXCEPTION(...)
SwDoc & m_rDoc
Definition: docbm.cxx:1215
float u
static void lcl_placeWatermarkInHeader(const SfxWatermarkItem &rWatermark, const uno::Reference< frame::XModel > &xModel, const uno::Reference< beans::XPropertySet > &xPageStyle, const uno::Reference< text::XText > &xHeaderText)
Definition: edfcol.cxx:1445
static void insertFieldToDocument(uno::Reference< lang::XMultiServiceFactory > const &rxMultiServiceFactory, uno::Reference< text::XText > const &rxText, uno::Reference< text::XParagraphCursor > const &rxParagraphCursor, OUString const &rsKey)
Definition: edfcol.cxx:704
static void lcl_ApplyParagraphClassification(SwDoc *pDoc, const uno::Reference< frame::XModel > &xModel, const rtl::Reference< SwXParagraph > &xParent, const css::uno::Reference< css::rdf::XResource > &xNodeSubject, std::vector< svx::ClassificationResult > aResults)
Definition: edfcol.cxx:1168
static OUString lcl_GetParagraphClassification(SfxClassificationHelper &rHelper, sfx::ClassificationKeyCreator const &rKeyCreator, const uno::Reference< frame::XModel > &xModel, const rtl::Reference< SwXParagraph > &xParagraph)
Definition: edfcol.cxx:2093
static OUString lcl_GetHighestClassificationParagraphClass(SwPaM *pCursor)
Definition: edfcol.cxx:2113
static void equaliseNumberOfParagraph(std::vector< svx::ClassificationResult > const &rResults, uno::Reference< text::XText > const &xText)
Definition: edfcol.cxx:761
static sal_Int16 lcl_GetAngle(const drawing::HomogenMatrix3 &rMatrix)
Definition: edfcol.cxx:1368
static std::vector< svx::ClassificationResult > lcl_CollectParagraphClassification(const uno::Reference< frame::XModel > &xModel, const uno::Reference< text::XTextContent > &xParagraph)
Definition: edfcol.cxx:1293
static void removeAllClassificationFields(std::u16string_view rPolicy, uno::Reference< text::XText > const &rxText)
Definition: edfcol.cxx:715
static uno::Reference< text::XTextField > lcl_GetParagraphMetadataFieldAtIndex(const SwDocShell *pDocSh, SwTextNode const *pNode, const sal_uLong index)
Definition: edfcol.cxx:1893
constexpr OUStringLiteral WATERMARK_NAME
Definition: edfcol.cxx:104
static sal_Int32 getNumberOfParagraphs(uno::Reference< text::XText > const &xText)
Definition: edfcol.cxx:748
#define WATERMARK_AUTO_SIZE
Definition: edfcol.cxx:105
Any aHelper
DocumentType eType
#define CH_TXT_ATR_INPUTFIELDSTART
Definition: hintids.hxx:179
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(99)
constexpr TypedWhichId< SwNumRuleItem > RES_PARATR_NUMRULE(72)
constexpr TypedWhichId< SvxFormatBreakItem > RES_BREAK(100)
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_METAFIELD(49)
#define CH_TXT_ATR_INPUTFIELDEND
Definition: hintids.hxx:180
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:175
sal_Int32 nIndex
OUString aName
OUString sSuffix
OUString sPrefix
std::unique_ptr< sal_Int32[]> pData
const char * sName
tools::Long const nRightMargin
tools::Long const nBottomMargin
tools::Long const nTopMargin
tools::Long const nLeftMargin
constexpr double rad2deg(double v)
constexpr double deg2rad(double v)
OUStringBuffer & remove(OUStringBuffer &rIn, sal_Unicode c)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr OUStringLiteral first
index
enumrange< T >::Iterator begin(enumrange< T >)
end
sfx::ClassificationCreationOrigin getCreationOriginProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, sfx::ClassificationKeyCreator const &rKeyCreator)
std::vector< unsigned char > DecodeHexString(std::string_view rHex)
OUString getProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, OUString const &rName)
void insertFullTextualRepresentationAsDocumentProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, sfx::ClassificationKeyCreator const &rKeyCreator, std::vector< svx::ClassificationResult > const &rResults)
void insertCreationOrigin(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, sfx::ClassificationKeyCreator const &rKeyCreator, sfx::ClassificationCreationOrigin eOrigin)
bool addOrInsertDocumentProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, OUString const &rsKey, OUString const &rsValue)
void removeAllProperties(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer)
SwTextNode * GetParaPropsNode(SwRootFrame const &rLayout, SwNode const &rNode)
Definition: txtfrm.cxx:330
@ RES_POOLCOLL_STANDARD
Standard.
Definition: poolfmt.hxx:250
sal_uIntPtr sal_uLong
css::xml::crypto::SecurityOperationStatus nStatus
X509CertInfo const * GetSigningCertificate() const
Marks a position in the document model.
Definition: pam.hxx:37
SwNode & GetNode() const
Definition: pam.hxx:80
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:266
sal_Int32 GetContentIndex() const
Definition: pam.hxx:84
Reference< XModel > xModel
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
SwUndoId
Definition: swundo.hxx:30
Any result
ResultType type
OUString sId
constexpr OUStringLiteral UNO_NAME_FILL_TRANSPARENCE
constexpr OUStringLiteral UNO_NAME_TEXT_FIELD
Definition: unoprnms.hxx:358
constexpr OUStringLiteral UNO_NAME_FILLCOLOR
constexpr OUStringLiteral UNO_NAME_SIZE
Definition: unoprnms.hxx:321
constexpr OUStringLiteral UNO_NAME_HEADER_HEIGHT
Definition: unoprnms.hxx:400
constexpr OUStringLiteral UNO_NAME_ANCHOR_TYPE
Definition: unoprnms.hxx:243
constexpr OUStringLiteral UNO_NAME_RIGHT_MARGIN
Definition: unoprnms.hxx:81
constexpr OUStringLiteral UNO_NAME_FOOTER_TEXT
Definition: unoprnms.hxx:386
constexpr OUStringLiteral UNO_NAME_TEXT_WRAP
Definition: unoprnms.hxx:331
constexpr OUStringLiteral UNO_NAME_TEXT_MINFRAMEHEIGHT
constexpr OUStringLiteral UNO_NAME_LINESTYLE
constexpr OUStringLiteral UNO_NAME_HEADER_TEXT
Definition: unoprnms.hxx:383
constexpr OUStringLiteral UNO_NAME_HEADER_IS_ON
Definition: unoprnms.hxx:401
constexpr OUStringLiteral UNO_NAME_LEFT_MARGIN
Definition: unoprnms.hxx:80
constexpr OUStringLiteral UNO_NAME_HORI_ORIENT
Definition: unoprnms.hxx:278
constexpr OUStringLiteral UNO_NAME_VERT_ORIENT
Definition: unoprnms.hxx:347
constexpr OUStringLiteral UNO_NAME_HEADER_TEXT_LEFT
Definition: unoprnms.hxx:384
constexpr OUStringLiteral UNO_NAME_NAME
Definition: unoprnms.hxx:90
constexpr OUStringLiteral UNO_NAME_HORI_ORIENT_RELATION
Definition: unoprnms.hxx:281
constexpr OUStringLiteral UNO_NAME_TOP_MARGIN
Definition: unoprnms.hxx:338
constexpr OUStringLiteral UNO_NAME_FILLSTYLE
constexpr OUStringLiteral UNO_NAME_HEADER_TEXT_RIGHT
Definition: unoprnms.hxx:385
constexpr OUStringLiteral UNO_NAME_TEXT_PORTION_TYPE
Definition: unoprnms.hxx:500
constexpr OUStringLiteral UNO_NAME_FOOTER_IS_ON
Definition: unoprnms.hxx:418
constexpr OUStringLiteral UNO_NAME_OPAQUE
Definition: unoprnms.hxx:300
constexpr OUStringLiteral UNO_NAME_TEXT_AUTOGROWHEIGHT
constexpr OUStringLiteral UNO_NAME_HEADER_IS_DYNAMIC_HEIGHT
Definition: unoprnms.hxx:398
constexpr OUStringLiteral UNO_NAME_VERT_ORIENT_RELATION
Definition: unoprnms.hxx:350
constexpr OUStringLiteral UNO_NAME_TEXT_AUTOGROWWIDTH
constexpr OUStringLiteral UNO_NAME_BOTTOM_MARGIN
Definition: unoprnms.hxx:339
constexpr OUStringLiteral UNO_NAME_CHAR_HEIGHT
constexpr OUStringLiteral UNO_NAME_TEXT_MINFRAMEWIDTH
constexpr OUStringLiteral UNO_NAME_CHAR_FONT_NAME
Definition: unoprnms.hxx:97
constexpr OUStringLiteral UNO_NAME_HEADER_TEXT_FIRST
Definition: unoprnms.hxx:861