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