Bug Summary

File:home/maarten/src/libreoffice/core/sw/source/core/unocore/unosect.cxx
Warning:line 1044, column 51
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name unosect.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SW_DLLIMPLEMENTATION -D SWUI_DLL_NAME="libswuilo.so" -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sw/source/core/inc -I /home/maarten/src/libreoffice/core/sw/source/filter/inc -I /home/maarten/src/libreoffice/core/sw/source/uibase/inc -I /home/maarten/src/libreoffice/core/sw/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sw/sdi -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/sw/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/oovbaapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sw/source/core/unocore/unosect.cxx
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 <memory>
21#include <unosection.hxx>
22
23#include <com/sun/star/beans/PropertyAttribute.hpp>
24#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
25#include <com/sun/star/text/SectionFileLink.hpp>
26
27#include <comphelper/interfacecontainer2.hxx>
28#include <cppuhelper/exc_hlp.hxx>
29#include <cppuhelper/supportsservice.hxx>
30
31#include <cmdid.h>
32#include <hintids.hxx>
33#include <svl/urihelper.hxx>
34#include <svl/listener.hxx>
35#include <editeng/brushitem.hxx>
36#include <editeng/xmlcnitm.hxx>
37#include <sfx2/linkmgr.hxx>
38#include <sfx2/lnkbase.hxx>
39#include <osl/mutex.hxx>
40#include <osl/diagnose.h>
41#include <vcl/svapp.hxx>
42#include <fmtclds.hxx>
43#include <unotextrange.hxx>
44#include <TextCursorHelper.hxx>
45#include <unoport.hxx>
46#include <redline.hxx>
47#include <unomap.hxx>
48#include <section.hxx>
49#include <doc.hxx>
50#include <IDocumentUndoRedo.hxx>
51#include <docsh.hxx>
52#include <sfx2/docfile.hxx>
53#include <docary.hxx>
54#include <swundo.hxx>
55#include <tox.hxx>
56#include <unoidx.hxx>
57#include <doctxm.hxx>
58#include <fmtftntx.hxx>
59#include <fmtclbl.hxx>
60#include <editeng/frmdiritem.hxx>
61#include <fmtcntnt.hxx>
62#include <editeng/lrspitem.hxx>
63#include <comphelper/servicehelper.hxx>
64#include <comphelper/string.hxx>
65
66using namespace ::com::sun::star;
67
68namespace {
69
70struct SwTextSectionProperties_Impl
71{
72 uno::Sequence<sal_Int8> m_Password;
73 OUString m_sCondition;
74 OUString m_sLinkFileName;
75 OUString m_sSectionFilter;
76 OUString m_sSectionRegion;
77
78 std::unique_ptr<SwFormatCol> m_pColItem;
79 std::unique_ptr<SvxBrushItem> m_pBrushItem;
80 std::unique_ptr<SwFormatFootnoteAtTextEnd> m_pFootnoteItem;
81 std::unique_ptr<SwFormatEndAtTextEnd> m_pEndItem;
82 std::unique_ptr<SvXMLAttrContainerItem> m_pXMLAttr;
83 std::unique_ptr<SwFormatNoBalancedColumns> m_pNoBalanceItem;
84 std::unique_ptr<SvxFrameDirectionItem> m_pFrameDirItem;
85 std::unique_ptr<SvxLRSpaceItem> m_pLRSpaceItem;
86
87 bool m_bDDE;
88 bool m_bHidden;
89 bool m_bCondHidden;
90 bool m_bProtect;
91 bool m_bEditInReadonly;
92 bool m_bUpdateType;
93
94 SwTextSectionProperties_Impl()
95 : m_bDDE(false)
96 , m_bHidden(false)
97 , m_bCondHidden(false)
98 , m_bProtect(false)
99 , m_bEditInReadonly(false)
100 , m_bUpdateType(true)
101 {
102 }
103
104};
105
106}
107
108class SwXTextSection::Impl
109 : public SvtListener
110{
111private:
112 ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
113
114public:
115 SwXTextSection & m_rThis;
116 uno::WeakReference<uno::XInterface> m_wThis;
117 const SfxItemPropertySet & m_rPropSet;
118 ::comphelper::OInterfaceContainerHelper2 m_EventListeners;
119 const bool m_bIndexHeader;
120 bool m_bIsDescriptor;
121 OUString m_sName;
122 std::unique_ptr<SwTextSectionProperties_Impl> m_pProps;
123 SwSectionFormat* m_pFormat;
124
125 Impl( SwXTextSection& rThis,
126 SwSectionFormat* const pFormat, const bool bIndexHeader)
127 : SvtListener()
128 , m_rThis(rThis)
129 , m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_SECTION6))
130 , m_EventListeners(m_Mutex)
131 , m_bIndexHeader(bIndexHeader)
132 , m_bIsDescriptor(nullptr == pFormat)
133 , m_pProps(pFormat ? nullptr : new SwTextSectionProperties_Impl())
134 , m_pFormat(pFormat)
135 {
136 if(m_pFormat)
137 StartListening(m_pFormat->GetNotifier());
138 }
139
140 void Attach(SwSectionFormat* pFormat)
141 {
142 EndListeningAll();
143 StartListening(pFormat->GetNotifier());
144 m_pFormat = pFormat;
145 }
146
147 SwSectionFormat* GetSectionFormat() const
148 { return m_pFormat; }
149
150 SwSectionFormat & GetSectionFormatOrThrow() const {
151 SwSectionFormat *const pFormat( GetSectionFormat() );
152 if (!pFormat) {
153 throw uno::RuntimeException("SwXTextSection: disposed or invalid", nullptr);
154 }
155 return *pFormat;
156 }
157
158 /// @throws beans::UnknownPropertyException
159 /// @throws beans::PropertyVetoException,
160 /// @throws lang::IllegalArgumentException
161 /// @throws lang::WrappedTargetException,
162 /// @throws uno::RuntimeException
163 void SetPropertyValues_Impl(
164 const uno::Sequence< OUString >& rPropertyNames,
165 const uno::Sequence< uno::Any >& aValues);
166 /// @throws beans::UnknownPropertyException
167 /// @throws lang::WrappedTargetException,
168 /// @throws uno::RuntimeException
169 uno::Sequence< uno::Any >
170 GetPropertyValues_Impl(
171 const uno::Sequence< OUString >& rPropertyNames);
172 virtual void Notify(const SfxHint& rHint) override;
173};
174
175void SwXTextSection::Impl::Notify(const SfxHint& rHint)
176{
177 if(rHint.GetId() == SfxHintId::Dying)
178 {
179 m_pFormat = nullptr;
180 uno::Reference<uno::XInterface> const xThis(m_wThis);
181 if (!xThis.is())
182 { // fdo#72695: if UNO object is already dead, don't revive it with event
183 return;
184 }
185 lang::EventObject const ev(xThis);
186 m_EventListeners.disposeAndClear(ev);
187 }
188}
189
190SwSectionFormat * SwXTextSection::GetFormat() const
191{
192 return m_pImpl->GetSectionFormat();
193}
194
195uno::Reference< text::XTextSection >
196SwXTextSection::CreateXTextSection(
197 SwSectionFormat *const pFormat, const bool bIndexHeader)
198{
199 // re-use existing SwXTextSection
200 // #i105557#: do not iterate over the registered clients: race condition
201 uno::Reference< text::XTextSection > xSection;
202 if (pFormat)
203 {
204 xSection.set(pFormat->GetXTextSection());
205 }
206 if ( !xSection.is() )
207 {
208 SwXTextSection *const pNew = new SwXTextSection(pFormat, bIndexHeader);
209 xSection.set(pNew);
210 if (pFormat)
211 {
212 pFormat->SetXTextSection(xSection);
213 }
214 // need a permanent Reference to initialize m_wThis
215 pNew->m_pImpl->m_wThis = xSection;
216 }
217 return xSection;
218}
219
220SwXTextSection::SwXTextSection(
221 SwSectionFormat *const pFormat, const bool bIndexHeader)
222 : m_pImpl( new SwXTextSection::Impl(*this, pFormat, bIndexHeader) )
223{
224}
225
226SwXTextSection::~SwXTextSection()
227{
228}
229
230namespace
231{
232 class theSwXTextSectionUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextSectionUnoTunnelId > {};
233}
234
235const uno::Sequence< sal_Int8 > & SwXTextSection::getUnoTunnelId()
236{
237 return theSwXTextSectionUnoTunnelId::get().getSeq();
238}
239
240sal_Int64 SAL_CALL
241SwXTextSection::getSomething(const uno::Sequence< sal_Int8 >& rId)
242{
243 return ::sw::UnoTunnelImpl<SwXTextSection>(rId, this);
244}
245
246uno::Reference< text::XTextSection > SAL_CALL
247SwXTextSection::getParentSection()
248{
249 SolarMutexGuard aGuard;
250
251 SwSectionFormat & rSectionFormat( m_pImpl->GetSectionFormatOrThrow() );
252
253 SwSectionFormat *const pParentFormat = rSectionFormat.GetParent();
254 const uno::Reference< text::XTextSection > xRet =
255 pParentFormat ? CreateXTextSection(pParentFormat) : nullptr;
256 return xRet;
257}
258
259uno::Sequence< uno::Reference< text::XTextSection > > SAL_CALL
260SwXTextSection::getChildSections()
261{
262 SolarMutexGuard aGuard;
263
264 SwSectionFormat & rSectionFormat( m_pImpl->GetSectionFormatOrThrow() );
265
266 SwSections aChildren;
267 rSectionFormat.GetChildSections(aChildren, SectionSort::Not, false);
268 uno::Sequence<uno::Reference<text::XTextSection> > aSeq(aChildren.size());
269 uno::Reference< text::XTextSection > * pArray = aSeq.getArray();
270 for (size_t i = 0; i < aChildren.size(); ++i)
271 {
272 SwSectionFormat *const pChild = aChildren[i]->GetFormat();
273 pArray[i] = CreateXTextSection(pChild);
274 }
275 return aSeq;
276}
277
278void SAL_CALL
279SwXTextSection::attach(const uno::Reference< text::XTextRange > & xTextRange)
280{
281 SolarMutexGuard g;
282
283 if (!m_pImpl->m_bIsDescriptor)
284 {
285 throw uno::RuntimeException();
286 }
287
288 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
289 SwXTextRange* pRange = nullptr;
290 OTextCursorHelper* pCursor = nullptr;
291 if(xRangeTunnel.is())
292 {
293 pRange = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
294 pCursor =
295 ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
296 }
297
298 SwDoc *const pDoc =
299 pRange ? &pRange->GetDoc() : (pCursor ? pCursor->GetDoc() : nullptr);
300 if (!pDoc)
301 {
302 throw lang::IllegalArgumentException();
303 }
304
305 SwUnoInternalPaM aPam(*pDoc);
306 // this has to return true now
307 ::sw::XTextRangeToSwPaM(aPam, xTextRange);
308 UnoActionContext aCont(pDoc);
309 pDoc->GetIDocumentUndoRedo().StartUndo( SwUndoId::INSSECTION, nullptr );
310
311 if (m_pImpl->m_sName.isEmpty())
312 {
313 m_pImpl->m_sName = "TextSection";
314 }
315 SectionType eType(SectionType::FileLink);
316 if( m_pImpl->m_pProps->m_bDDE )
317 eType = SectionType::DdeLink;
318 else if( m_pImpl->m_pProps->m_sLinkFileName.isEmpty() && m_pImpl->m_pProps->m_sSectionRegion.isEmpty() )
319 eType = SectionType::Content;
320 // index header section?
321 if (m_pImpl->m_bIndexHeader)
322 {
323 // caller wants an index header section, but will only
324 // give him one if a) we are inside an index, and b) said
325 // index doesn't yet have a header section.
326 const SwTOXBase* pBase = SwDoc::GetCurTOX(*aPam.Start());
327
328 // are we inside an index?
329 if (pBase)
330 {
331 // get all child sections
332 SwSections aSectionsArr;
333 static_cast<const SwTOXBaseSection*>(pBase)->GetFormat()->
334 GetChildSections(aSectionsArr);
335
336 // and search for current header section
337 const size_t nCount = aSectionsArr.size();
338 bool bHeaderPresent = false;
339 for(size_t i = 0; i < nCount; ++i)
340 {
341 if (aSectionsArr[i]->GetType() == SectionType::ToxHeader)
342 bHeaderPresent = true;
343 }
344 if (! bHeaderPresent)
345 {
346 eType = SectionType::ToxHeader;
347 }
348 }
349 }
350
351 SwSectionData aSect(eType, pDoc->GetUniqueSectionName(&m_pImpl->m_sName));
352 aSect.SetCondition(m_pImpl->m_pProps->m_sCondition);
353 aSect.SetLinkFileName(m_pImpl->m_pProps->m_sLinkFileName +
354 OUStringChar(sfx2::cTokenSeparator) +
355 m_pImpl->m_pProps->m_sSectionFilter +
356 OUStringChar(sfx2::cTokenSeparator) +
357 m_pImpl->m_pProps->m_sSectionRegion);
358
359 aSect.SetHidden(m_pImpl->m_pProps->m_bHidden);
360 aSect.SetProtectFlag(m_pImpl->m_pProps->m_bProtect);
361 aSect.SetEditInReadonlyFlag(m_pImpl->m_pProps->m_bEditInReadonly);
362
363 SfxItemSet aSet(
364 pDoc->GetAttrPool(),
365 svl::Items<
366 RES_LR_SPACE, RES_LR_SPACE,
367 RES_BACKGROUND, RES_BACKGROUND,
368 RES_COL, RES_COL,
369 RES_FTN_AT_TXTEND, RES_FRAMEDIR,
370 RES_UNKNOWNATR_CONTAINER,RES_UNKNOWNATR_CONTAINER>{});
371 if (m_pImpl->m_pProps->m_pBrushItem)
372 {
373 aSet.Put(*m_pImpl->m_pProps->m_pBrushItem);
374 }
375 if (m_pImpl->m_pProps->m_pColItem)
376 {
377 aSet.Put(*m_pImpl->m_pProps->m_pColItem);
378 }
379 if (m_pImpl->m_pProps->m_pFootnoteItem)
380 {
381 aSet.Put(*m_pImpl->m_pProps->m_pFootnoteItem);
382 }
383 if (m_pImpl->m_pProps->m_pEndItem)
384 {
385 aSet.Put(*m_pImpl->m_pProps->m_pEndItem);
386 }
387 if (m_pImpl->m_pProps->m_pXMLAttr)
388 {
389 aSet.Put(*m_pImpl->m_pProps->m_pXMLAttr);
390 }
391 if (m_pImpl->m_pProps->m_pNoBalanceItem)
392 {
393 aSet.Put(*m_pImpl->m_pProps->m_pNoBalanceItem);
394 }
395 if (m_pImpl->m_pProps->m_pFrameDirItem)
396 {
397 aSet.Put(*m_pImpl->m_pProps->m_pFrameDirItem);
398 }
399 if (m_pImpl->m_pProps->m_pLRSpaceItem)
400 {
401 aSet.Put(*m_pImpl->m_pProps->m_pLRSpaceItem);
402 }
403 // section password
404 if (m_pImpl->m_pProps->m_Password.hasElements())
405 {
406 aSect.SetPassword(m_pImpl->m_pProps->m_Password);
407 }
408
409 SwSection *const pRet =
410 pDoc->InsertSwSection( aPam, aSect, nullptr, aSet.Count() ? &aSet : nullptr );
411 if (!pRet) // fdo#42450 text range could partially overlap existing section
412 {
413 // shouldn't have created an undo object yet
414 pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::INSSECTION, nullptr );
415 throw lang::IllegalArgumentException(
416 "SwXTextSection::attach(): invalid TextRange",
417 static_cast< ::cppu::OWeakObject*>(this), 0);
418 }
419 m_pImpl->Attach(pRet->GetFormat());
420 pRet->GetFormat()->SetXObject(static_cast< ::cppu::OWeakObject*>(this));
421
422 // XML import must hide sections depending on their old
423 // condition status
424 if (!m_pImpl->m_pProps->m_sCondition.isEmpty())
425 {
426 pRet->SetCondHidden(m_pImpl->m_pProps->m_bCondHidden);
427 }
428
429 // set update type if DDE link (and connect, if necessary)
430 if (m_pImpl->m_pProps->m_bDDE)
431 {
432 if (! pRet->IsConnected())
433 {
434 pRet->CreateLink(LinkCreateType::Connect);
435 }
436 pRet->SetUpdateType( m_pImpl->m_pProps->m_bUpdateType ?
437 SfxLinkUpdateMode::ALWAYS : SfxLinkUpdateMode::ONCALL );
438 }
439
440 // end the Undo bracketing here
441 pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::INSSECTION, nullptr );
442 m_pImpl->m_pProps.reset();
443 m_pImpl->m_bIsDescriptor = false;
444}
445
446uno::Reference< text::XTextRange > SAL_CALL
447SwXTextSection::getAnchor()
448{
449 SolarMutexGuard aGuard;
450
451 uno::Reference< text::XTextRange > xRet;
452 SwSectionFormat *const pSectFormat = m_pImpl->GetSectionFormat();
453 if(pSectFormat)
454 {
455 const SwNodeIndex* pIdx;
456 if( nullptr != ( pSectFormat->GetSection() ) &&
457 nullptr != ( pIdx = pSectFormat->GetContent().GetContentIdx() ) &&
458 pIdx->GetNode().GetNodes().IsDocNodes() )
459 {
460 SwPaM aPaM(*pIdx);
461 aPaM.Move( fnMoveForward, GoInContent );
462
463 const SwEndNode* pEndNode = pIdx->GetNode().EndOfSectionNode();
464 SwPaM aEnd(*pEndNode);
465 aEnd.Move( fnMoveBackward, GoInContent );
466 xRet = SwXTextRange::CreateXTextRange(*pSectFormat->GetDoc(),
467 *aPaM.Start(), aEnd.Start());
468 }
469 }
470 return xRet;
471}
472
473void SAL_CALL SwXTextSection::dispose()
474{
475 SolarMutexGuard aGuard;
476
477 SwSectionFormat *const pSectFormat = m_pImpl->GetSectionFormat();
478 if (pSectFormat)
479 {
480 pSectFormat->GetDoc()->DelSectionFormat( pSectFormat );
481 }
482}
483
484void SAL_CALL SwXTextSection::addEventListener(
485 const uno::Reference< lang::XEventListener > & xListener)
486{
487 // no need to lock here as m_pImpl is const and container threadsafe
488 m_pImpl->m_EventListeners.addInterface(xListener);
489}
490
491void SAL_CALL SwXTextSection::removeEventListener(
492 const uno::Reference< lang::XEventListener > & xListener)
493{
494 // no need to lock here as m_pImpl is const and container threadsafe
495 m_pImpl->m_EventListeners.removeInterface(xListener);
496}
497
498uno::Reference< beans::XPropertySetInfo > SAL_CALL
499SwXTextSection::getPropertySetInfo()
500{
501 SolarMutexGuard g;
502 return m_pImpl->m_rPropSet.getPropertySetInfo();
503}
504
505static void
506lcl_UpdateLinkType(SwSection & rSection, bool const bLinkUpdateAlways)
507{
508 if (rSection.GetType() == SectionType::DdeLink)
509 {
510 // set update type; needs an established link
511 if (!rSection.IsConnected())
512 {
513 rSection.CreateLink(LinkCreateType::Connect);
514 }
515 rSection.SetUpdateType( bLinkUpdateAlways
516 ? SfxLinkUpdateMode::ALWAYS : SfxLinkUpdateMode::ONCALL );
517 }
518}
519
520static void
521lcl_UpdateSection(SwSectionFormat *const pFormat,
522 std::unique_ptr<SwSectionData> const& pSectionData,
523 std::unique_ptr<SfxItemSet> const& pItemSet,
524 bool const bLinkModeChanged, bool const bLinkUpdateAlways = true)
525{
526 if (!pFormat)
527 return;
528
529 SwSection & rSection = *pFormat->GetSection();
530 SwDoc *const pDoc = pFormat->GetDoc();
531 SwSectionFormats const& rFormats = pDoc->GetSections();
532 UnoActionContext aContext(pDoc);
533 for (size_t i = 0; i < rFormats.size(); ++i)
534 {
535 if (rFormats[i]->GetSection()->GetSectionName()
536 == rSection.GetSectionName())
537 {
538 pDoc->UpdateSection(i, *pSectionData, pItemSet.get(),
539 pDoc->IsInReading());
540 {
541 // temporarily remove actions to allow cursor update
542 // TODO: why? no table cursor here!
543 UnoActionRemoveContext aRemoveContext( pDoc );
544 }
545
546 if (bLinkModeChanged)
547 {
548 lcl_UpdateLinkType(rSection, bLinkUpdateAlways);
549 }
550 // section found and processed: break from loop
551 break;
552 }
553 }
554}
555
556void SwXTextSection::Impl::SetPropertyValues_Impl(
557 const uno::Sequence< OUString >& rPropertyNames,
558 const uno::Sequence< uno::Any >& rValues)
559{
560 if(rPropertyNames.getLength() != rValues.getLength())
561 {
562 throw lang::IllegalArgumentException();
563 }
564 SwSectionFormat *const pFormat = GetSectionFormat();
565 if (!pFormat && !m_bIsDescriptor)
566 {
567 throw uno::RuntimeException();
568 }
569
570 std::unique_ptr<SwSectionData> const pSectionData(
571 pFormat ? new SwSectionData(*pFormat->GetSection()) : nullptr);
572
573 OUString const*const pPropertyNames = rPropertyNames.getConstArray();
574 uno::Any const*const pValues = rValues.getConstArray();
575 std::unique_ptr<SfxItemSet> pItemSet;
576 bool bLinkModeChanged = false;
577 bool bLinkMode = false;
578
579 for (sal_Int32 nProperty = 0; nProperty < rPropertyNames.getLength();
580 nProperty++)
581 {
582 SfxItemPropertySimpleEntry const*const pEntry =
583 m_rPropSet.getPropertyMap().getByName(pPropertyNames[nProperty]);
584 if (!pEntry)
585 {
586 throw beans::UnknownPropertyException(
587 "Unknown property: " + pPropertyNames[nProperty],
588 static_cast<cppu::OWeakObject *>(& m_rThis));
589 }
590 if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
591 {
592 throw beans::PropertyVetoException(
593 "Property is read-only: " + pPropertyNames[nProperty],
594 static_cast<cppu::OWeakObject *>(& m_rThis));
595 }
596 switch (pEntry->nWID)
597 {
598 case WID_SECT_CONDITION8000:
599 {
600 OUString uTmp;
601 pValues[nProperty] >>= uTmp;
602 if (m_bIsDescriptor)
603 {
604 m_pProps->m_sCondition = uTmp;
605 }
606 else
607 {
608 pSectionData->SetCondition(uTmp);
609 }
610 }
611 break;
612 case WID_SECT_DDE_TYPE8001:
613 case WID_SECT_DDE_FILE8002:
614 case WID_SECT_DDE_ELEMENT8003:
615 {
616 OUString sTmp;
617 pValues[nProperty] >>= sTmp;
618 if (m_bIsDescriptor)
619 {
620 if (!m_pProps->m_bDDE)
621 {
622 m_pProps->m_sLinkFileName =
623 OUStringChar(sfx2::cTokenSeparator) + OUStringChar(sfx2::cTokenSeparator);
624 m_pProps->m_bDDE = true;
625 }
626 m_pProps->m_sLinkFileName = comphelper::string::setToken(
627 m_pProps->m_sLinkFileName,
628 pEntry->nWID - WID_SECT_DDE_TYPE8001, sfx2::cTokenSeparator, sTmp);
629 }
630 else
631 {
632 OUString sLinkFileName(pSectionData->GetLinkFileName());
633 if (pSectionData->GetType() != SectionType::DdeLink)
634 {
635 sLinkFileName = OUStringChar(sfx2::cTokenSeparator) + OUStringChar(sfx2::cTokenSeparator);
636 pSectionData->SetType(SectionType::DdeLink);
637 }
638 sLinkFileName = comphelper::string::setToken(sLinkFileName,
639 pEntry->nWID - WID_SECT_DDE_TYPE8001,
640 sfx2::cTokenSeparator, sTmp);
641 pSectionData->SetLinkFileName(sLinkFileName);
642 }
643 }
644 break;
645 case WID_SECT_DDE_AUTOUPDATE8008:
646 {
647 bool bVal(false);
648 if (!(pValues[nProperty] >>= bVal))
649 {
650 throw lang::IllegalArgumentException();
651 }
652 if (m_bIsDescriptor)
653 {
654 m_pProps->m_bUpdateType = bVal;
655 }
656 else
657 {
658 bLinkModeChanged = true;
659 bLinkMode = bVal;
660 }
661 }
662 break;
663 case WID_SECT_LINK8004:
664 {
665 text::SectionFileLink aLink;
666 if (!(pValues[nProperty] >>= aLink))
667 {
668 throw lang::IllegalArgumentException();
669 }
670 if (m_bIsDescriptor)
671 {
672 m_pProps->m_bDDE = false;
673 m_pProps->m_sLinkFileName = aLink.FileURL;
674 m_pProps->m_sSectionFilter = aLink.FilterName;
675 }
676 else
677 {
678 if (pSectionData->GetType() != SectionType::FileLink &&
679 !aLink.FileURL.isEmpty())
680 {
681 pSectionData->SetType(SectionType::FileLink);
682 }
683 const OUString sTmp(!aLink.FileURL.isEmpty()
684 ? URIHelper::SmartRel2Abs(
685 pFormat->GetDoc()->GetDocShell()->GetMedium()->GetURLObject(),
686 aLink.FileURL, URIHelper::GetMaybeFileHdl())
687 : OUString());
688 const OUString sFileName(
689 sTmp + OUStringChar(sfx2::cTokenSeparator) +
690 aLink.FilterName + OUStringChar(sfx2::cTokenSeparator) +
691 pSectionData->GetLinkFileName().getToken(2, sfx2::cTokenSeparator));
692 pSectionData->SetLinkFileName(sFileName);
693 if (sFileName.getLength() < 3)
694 {
695 pSectionData->SetType(SectionType::Content);
696 }
697 }
698 }
699 break;
700 case WID_SECT_REGION8007:
701 {
702 OUString sLink;
703 pValues[nProperty] >>= sLink;
704 if (m_bIsDescriptor)
705 {
706 m_pProps->m_bDDE = false;
707 m_pProps->m_sSectionRegion = sLink;
708 }
709 else
710 {
711 if (pSectionData->GetType() != SectionType::FileLink &&
712 !sLink.isEmpty())
713 {
714 pSectionData->SetType(SectionType::FileLink);
715 }
716 OUString sSectLink(pSectionData->GetLinkFileName());
717 for (sal_Int32 i = comphelper::string::getTokenCount(sSectLink, sfx2::cTokenSeparator);
718 i < 3; ++i)
719 {
720 sSectLink += OUStringChar(sfx2::cTokenSeparator);
721 }
722 sSectLink = comphelper::string::setToken(sSectLink, 2, sfx2::cTokenSeparator, sLink);
723 pSectionData->SetLinkFileName(sSectLink);
724 if (sSectLink.getLength() < 3)
725 {
726 pSectionData->SetType(SectionType::Content);
727 }
728 }
729 }
730 break;
731 case WID_SECT_VISIBLE8005:
732 {
733 bool bVal(false);
734 if (!(pValues[nProperty] >>= bVal))
735 {
736 throw lang::IllegalArgumentException();
737 }
738 if (m_bIsDescriptor)
739 {
740 m_pProps->m_bHidden = !bVal;
741 }
742 else
743 {
744 pSectionData->SetHidden(!bVal);
745 }
746 }
747 break;
748 case WID_SECT_CURRENTLY_VISIBLE8012:
749 {
750 bool bVal(false);
751 if (!(pValues[nProperty] >>= bVal))
752 {
753 throw lang::IllegalArgumentException();
754 }
755 if (m_bIsDescriptor)
756 {
757 m_pProps->m_bCondHidden = !bVal;
758 }
759 else
760 {
761 if (!pSectionData->GetCondition().isEmpty())
762 {
763 pSectionData->SetCondHidden(!bVal);
764 }
765 }
766 }
767 break;
768 case WID_SECT_PROTECTED8006:
769 {
770 bool bVal(false);
771 if (!(pValues[nProperty] >>= bVal))
772 {
773 throw lang::IllegalArgumentException();
774 }
775 if (m_bIsDescriptor)
776 {
777 m_pProps->m_bProtect = bVal;
778 }
779 else
780 {
781 pSectionData->SetProtectFlag(bVal);
782 }
783 }
784 break;
785 case WID_SECT_EDIT_IN_READONLY8013:
786 {
787 bool bVal(false);
788 if (!(pValues[nProperty] >>= bVal))
789 {
790 throw lang::IllegalArgumentException();
791 }
792 if (m_bIsDescriptor)
793 {
794 m_pProps->m_bEditInReadonly = bVal;
795 }
796 else
797 {
798 pSectionData->SetEditInReadonlyFlag(bVal);
799 }
800 }
801 break;
802 case WID_SECT_PASSWORD8011:
803 {
804 uno::Sequence<sal_Int8> aSeq;
805 pValues[nProperty] >>= aSeq;
806 if (m_bIsDescriptor)
807 {
808 m_pProps->m_Password = aSeq;
809 }
810 else
811 {
812 pSectionData->SetPassword(aSeq);
813 }
814 }
815 break;
816 default:
817 {
818 if (pFormat)
819 {
820 const SfxItemSet& rOldAttrSet = pFormat->GetAttrSet();
821 pItemSet.reset( new SfxItemSet(*rOldAttrSet.GetPool(), {{pEntry->nWID, pEntry->nWID}}));
822 pItemSet->Put(rOldAttrSet);
823 m_rPropSet.setPropertyValue(*pEntry,
824 pValues[nProperty], *pItemSet);
825 }
826 else
827 {
828 SfxPoolItem* pPutItem = nullptr;
829 if (RES_COL == pEntry->nWID)
830 {
831 if (!m_pProps->m_pColItem)
832 {
833 m_pProps->m_pColItem.reset(new SwFormatCol);
834 }
835 pPutItem = m_pProps->m_pColItem.get();
836 }
837 else if (RES_BACKGROUND == pEntry->nWID)
838 {
839 if (!m_pProps->m_pBrushItem)
840 {
841 m_pProps->m_pBrushItem.reset(
842 new SvxBrushItem(RES_BACKGROUND));
843 }
844 pPutItem = m_pProps->m_pBrushItem.get();
845 }
846 else if (RES_FTN_AT_TXTEND == pEntry->nWID)
847 {
848 if (!m_pProps->m_pFootnoteItem)
849 {
850 m_pProps->m_pFootnoteItem.reset(new SwFormatFootnoteAtTextEnd);
851 }
852 pPutItem = m_pProps->m_pFootnoteItem.get();
853 }
854 else if (RES_END_AT_TXTEND == pEntry->nWID)
855 {
856 if (!m_pProps->m_pEndItem)
857 {
858 m_pProps->m_pEndItem.reset(new SwFormatEndAtTextEnd);
859 }
860 pPutItem = m_pProps->m_pEndItem.get();
861 }
862 else if (RES_UNKNOWNATR_CONTAINER== pEntry->nWID)
863 {
864 if (!m_pProps->m_pXMLAttr)
865 {
866 m_pProps->m_pXMLAttr.reset(
867 new SvXMLAttrContainerItem(
868 RES_UNKNOWNATR_CONTAINER));
869 }
870 pPutItem = m_pProps->m_pXMLAttr.get();
871 }
872 else if (RES_COLUMNBALANCE== pEntry->nWID)
873 {
874 if (!m_pProps->m_pNoBalanceItem)
875 {
876 m_pProps->m_pNoBalanceItem.reset(
877 new SwFormatNoBalancedColumns(true));
878 }
879 pPutItem = m_pProps->m_pNoBalanceItem.get();
880 }
881 else if (RES_FRAMEDIR == pEntry->nWID)
882 {
883 if (!m_pProps->m_pFrameDirItem)
884 {
885 m_pProps->m_pFrameDirItem.reset(
886 new SvxFrameDirectionItem(
887 SvxFrameDirection::Horizontal_LR_TB, RES_FRAMEDIR));
888 }
889 pPutItem = m_pProps->m_pFrameDirItem.get();
890 }
891 else if (RES_LR_SPACE == pEntry->nWID)
892 {
893 if (!m_pProps->m_pLRSpaceItem)
894 {
895 m_pProps->m_pLRSpaceItem.reset(
896 new SvxLRSpaceItem( RES_LR_SPACE ));
897 }
898 pPutItem = m_pProps->m_pLRSpaceItem.get();
899 }
900 if (pPutItem)
901 {
902 pPutItem->PutValue(pValues[nProperty],
903 pEntry->nMemberId);
904 }
905 }
906 }
907 }
908 }
909
910 lcl_UpdateSection(pFormat, pSectionData, pItemSet, bLinkModeChanged,
911 bLinkMode);
912}
913
914void SAL_CALL
915SwXTextSection::setPropertyValues(
916 const uno::Sequence< OUString >& rPropertyNames,
917 const uno::Sequence< uno::Any >& rValues)
918{
919 SolarMutexGuard aGuard;
920
921 // workaround for bad designed API
922 try
923 {
924 m_pImpl->SetPropertyValues_Impl( rPropertyNames, rValues );
925 }
926 catch (const beans::UnknownPropertyException &rException)
927 {
928 // wrap the original (here not allowed) exception in
929 // a WrappedTargetException that gets thrown instead.
930 lang::WrappedTargetException aWExc;
931 aWExc.TargetException <<= rException;
932 throw aWExc;
933 }
934}
935
936void SwXTextSection::setPropertyValue(
937 const OUString& rPropertyName, const uno::Any& rValue)
938{
939 SolarMutexGuard aGuard;
940
941 uno::Sequence< OUString > aPropertyNames { rPropertyName };
942 uno::Sequence< uno::Any > aValues(1);
943 aValues.getArray()[0] = rValue;
944 m_pImpl->SetPropertyValues_Impl( aPropertyNames, aValues );
945}
946
947uno::Sequence< uno::Any >
948SwXTextSection::Impl::GetPropertyValues_Impl(
949 const uno::Sequence< OUString > & rPropertyNames )
950{
951 SwSectionFormat *const pFormat = GetSectionFormat();
952 if (!pFormat && !m_bIsDescriptor)
1
Assuming 'pFormat' is non-null
953 {
954 throw uno::RuntimeException( "non-descriptor section without format");
955 }
956
957 uno::Sequence< uno::Any > aRet(rPropertyNames.getLength());
958 uno::Any* pRet = aRet.getArray();
959 SwSection *const pSect = pFormat
1.1
'pFormat' is non-null
? pFormat->GetSection() : nullptr;
2
'?' condition is true
3
'pSect' initialized here
960 const OUString* pPropertyNames = rPropertyNames.getConstArray();
961
962 for (sal_Int32 nProperty = 0; nProperty < rPropertyNames.getLength();
4
Assuming the condition is true
5
Loop condition is true. Entering loop body
11
Assuming the condition is true
12
Loop condition is true. Entering loop body
963 nProperty++)
964 {
965 SfxItemPropertySimpleEntry const*const pEntry =
966 m_rPropSet.getPropertyMap().getByName(pPropertyNames[nProperty]);
967 if (!pEntry)
6
Assuming 'pEntry' is non-null
7
Taking false branch
13
Assuming 'pEntry' is non-null
14
Taking false branch
968 {
969 throw beans::UnknownPropertyException(
970 "Unknown property: " + pPropertyNames[nProperty],
971 static_cast<cppu::OWeakObject *>(& m_rThis));
972 }
973 switch(pEntry->nWID)
8
Control jumps to 'case 8008:' at line 1003
15
Control jumps to 'case 8007:' at line 1037
974 {
975 case WID_SECT_CONDITION8000:
976 {
977 const OUString uTmp( m_bIsDescriptor
978 ? m_pProps->m_sCondition
979 : pSect->GetCondition());
980 pRet[nProperty] <<= uTmp;
981 }
982 break;
983 case WID_SECT_DDE_TYPE8001:
984 case WID_SECT_DDE_FILE8002:
985 case WID_SECT_DDE_ELEMENT8003:
986 {
987 OUString sRet;
988 if (m_bIsDescriptor)
989 {
990 if (m_pProps->m_bDDE)
991 {
992 sRet = m_pProps->m_sLinkFileName;
993 }
994 }
995 else if (SectionType::DdeLink == pSect->GetType())
996 {
997 sRet = pSect->GetLinkFileName();
998 }
999 pRet[nProperty] <<= sRet.getToken(pEntry->nWID - WID_SECT_DDE_TYPE8001,
1000 sfx2::cTokenSeparator);
1001 }
1002 break;
1003 case WID_SECT_DDE_AUTOUPDATE8008:
1004 {
1005 // GetUpdateType() returns .._ALWAYS or .._ONCALL
1006 if (pSect && pSect->IsLinkType() && pSect->IsConnected()) // #i73247#
9
Assuming 'pSect' is null
1007 {
1008 const bool bTemp =
1009 (pSect->GetUpdateType() == SfxLinkUpdateMode::ALWAYS);
1010 pRet[nProperty] <<= bTemp;
1011 }
1012 }
1013 break;
10
Execution continues on line 963
1014 case WID_SECT_LINK8004 :
1015 {
1016 text::SectionFileLink aLink;
1017 if (m_bIsDescriptor)
1018 {
1019 if (!m_pProps->m_bDDE)
1020 {
1021 aLink.FileURL = m_pProps->m_sLinkFileName;
1022 aLink.FilterName = m_pProps->m_sSectionFilter;
1023 }
1024 }
1025 else if (SectionType::FileLink == pSect->GetType())
1026 {
1027 const OUString& sRet( pSect->GetLinkFileName() );
1028 sal_Int32 nIndex(0);
1029 aLink.FileURL =
1030 sRet.getToken(0, sfx2::cTokenSeparator, nIndex);
1031 aLink.FilterName =
1032 sRet.getToken(0, sfx2::cTokenSeparator, nIndex);
1033 }
1034 pRet[nProperty] <<= aLink;
1035 }
1036 break;
1037 case WID_SECT_REGION8007 :
1038 {
1039 OUString sRet;
1040 if (m_bIsDescriptor)
16
Assuming field 'm_bIsDescriptor' is false
17
Taking false branch
1041 {
1042 sRet = m_pProps->m_sSectionRegion;
1043 }
1044 else if (SectionType::FileLink == pSect->GetType())
18
Called C++ object pointer is null
1045 {
1046 sRet = pSect->GetLinkFileName().getToken(2,
1047 sfx2::cTokenSeparator);
1048 }
1049 pRet[nProperty] <<= sRet;
1050 }
1051 break;
1052 case WID_SECT_VISIBLE8005 :
1053 {
1054 const bool bTemp = m_bIsDescriptor
1055 ? !m_pProps->m_bHidden : !pSect->IsHidden();
1056 pRet[nProperty] <<= bTemp;
1057 }
1058 break;
1059 case WID_SECT_CURRENTLY_VISIBLE8012:
1060 {
1061 const bool bTemp = m_bIsDescriptor
1062 ? !m_pProps->m_bCondHidden : !pSect->IsCondHidden();
1063 pRet[nProperty] <<= bTemp;
1064 }
1065 break;
1066 case WID_SECT_PROTECTED8006:
1067 {
1068 const bool bTemp = m_bIsDescriptor
1069 ? m_pProps->m_bProtect : pSect->IsProtect();
1070 pRet[nProperty] <<= bTemp;
1071 }
1072 break;
1073 case WID_SECT_EDIT_IN_READONLY8013:
1074 {
1075 const bool bTemp = m_bIsDescriptor
1076 ? m_pProps->m_bEditInReadonly : pSect->IsEditInReadonly();
1077 pRet[nProperty] <<= bTemp;
1078 }
1079 break;
1080 case FN_PARAM_LINK_DISPLAY_NAME((20000 + 2400)+15):
1081 {
1082 if (pFormat)
1083 {
1084 pRet[nProperty] <<= pFormat->GetSection()->GetSectionName();
1085 }
1086 }
1087 break;
1088 case WID_SECT_DOCUMENT_INDEX8009:
1089 {
1090 // search enclosing index
1091 SwSection* pEnclosingSection = pSect;
1092 while ((pEnclosingSection != nullptr) &&
1093 (SectionType::ToxContent != pEnclosingSection->GetType()))
1094 {
1095 pEnclosingSection = pEnclosingSection->GetParent();
1096 }
1097 SwTOXBaseSection* const pTOXBaseSect = pEnclosingSection ?
1098 dynamic_cast<SwTOXBaseSection*>( pEnclosingSection ) : nullptr;
1099 if (pTOXBaseSect)
1100 {
1101 // convert section to TOXBase and get SwXDocumentIndex
1102 const uno::Reference<text::XDocumentIndex> xIndex =
1103 SwXDocumentIndex::CreateXDocumentIndex(
1104 *pTOXBaseSect->GetFormat()->GetDoc(), pTOXBaseSect);
1105 pRet[nProperty] <<= xIndex;
1106 }
1107 // else: no enclosing index found -> empty return value
1108 }
1109 break;
1110 case WID_SECT_IS_GLOBAL_DOC_SECTION8010:
1111 {
1112 const bool bRet = pFormat && (nullptr != pFormat->GetGlobalDocSection());
1113 pRet[nProperty] <<= bRet;
1114 }
1115 break;
1116 case FN_UNO_ANCHOR_TYPES((20000 + 2200) + 65):
1117 case FN_UNO_TEXT_WRAP((20000 + 2200) + 70):
1118 case FN_UNO_ANCHOR_TYPE((20000 + 2200) + 71):
1119 ::sw::GetDefaultTextContentValue(
1120 pRet[nProperty], OUString(), pEntry->nWID);
1121 break;
1122 case FN_UNO_REDLINE_NODE_START((20000 + 2200) + 75):
1123 case FN_UNO_REDLINE_NODE_END((20000 + 2200) + 76):
1124 {
1125 if (!pFormat)
1126 break; // #i73247#
1127 SwNode* pSectNode = pFormat->GetSectionNode();
1128 if (FN_UNO_REDLINE_NODE_END((20000 + 2200) + 76) == pEntry->nWID)
1129 {
1130 pSectNode = pSectNode->EndOfSectionNode();
1131 }
1132 const SwRedlineTable& rRedTable =
1133 pFormat->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
1134 for (SwRangeRedline* pRedline : rRedTable)
1135 {
1136 const SwNode& rRedPointNode = pRedline->GetNode();
1137 const SwNode& rRedMarkNode = pRedline->GetNode(false);
1138 if ((&rRedPointNode == pSectNode) ||
1139 (&rRedMarkNode == pSectNode))
1140 {
1141 const SwNode& rStartOfRedline =
1142 (SwNodeIndex(rRedPointNode) <=
1143 SwNodeIndex(rRedMarkNode))
1144 ? rRedPointNode : rRedMarkNode;
1145 const bool bIsStart = (&rStartOfRedline == pSectNode);
1146 pRet[nProperty] <<=
1147 SwXRedlinePortion::CreateRedlineProperties(
1148 *pRedline, bIsStart);
1149 break;
1150 }
1151 }
1152 }
1153 break;
1154 case WID_SECT_PASSWORD8011:
1155 {
1156 pRet[nProperty] <<= m_bIsDescriptor
1157 ? m_pProps->m_Password : pSect->GetPassword();
1158 }
1159 break;
1160 default:
1161 {
1162 if (pFormat)
1163 {
1164 m_rPropSet.getPropertyValue(*pEntry,
1165 pFormat->GetAttrSet(), pRet[nProperty]);
1166 }
1167 else
1168 {
1169 const SfxPoolItem* pQueryItem = nullptr;
1170 if (RES_COL == pEntry->nWID)
1171 {
1172 if (!m_pProps->m_pColItem)
1173 {
1174 m_pProps->m_pColItem.reset(new SwFormatCol);
1175 }
1176 pQueryItem = m_pProps->m_pColItem.get();
1177 }
1178 else if (RES_BACKGROUND == pEntry->nWID)
1179 {
1180 if (!m_pProps->m_pBrushItem)
1181 {
1182 m_pProps->m_pBrushItem.reset(
1183 new SvxBrushItem(RES_BACKGROUND));
1184 }
1185 pQueryItem = m_pProps->m_pBrushItem.get();
1186 }
1187 else if (RES_FTN_AT_TXTEND == pEntry->nWID)
1188 {
1189 if (!m_pProps->m_pFootnoteItem)
1190 {
1191 m_pProps->m_pFootnoteItem.reset(new SwFormatFootnoteAtTextEnd);
1192 }
1193 pQueryItem = m_pProps->m_pFootnoteItem.get();
1194 }
1195 else if (RES_END_AT_TXTEND == pEntry->nWID)
1196 {
1197 if (!m_pProps->m_pEndItem)
1198 {
1199 m_pProps->m_pEndItem.reset(new SwFormatEndAtTextEnd);
1200 }
1201 pQueryItem = m_pProps->m_pEndItem.get();
1202 }
1203 else if (RES_UNKNOWNATR_CONTAINER== pEntry->nWID)
1204 {
1205 if (!m_pProps->m_pXMLAttr)
1206 {
1207 m_pProps->m_pXMLAttr.reset(
1208 new SvXMLAttrContainerItem);
1209 }
1210 pQueryItem = m_pProps->m_pXMLAttr.get();
1211 }
1212 else if (RES_COLUMNBALANCE== pEntry->nWID)
1213 {
1214 if (!m_pProps->m_pNoBalanceItem)
1215 {
1216 m_pProps->m_pNoBalanceItem.reset(
1217 new SwFormatNoBalancedColumns);
1218 }
1219 pQueryItem = m_pProps->m_pNoBalanceItem.get();
1220 }
1221 else if (RES_FRAMEDIR == pEntry->nWID)
1222 {
1223 if (!m_pProps->m_pFrameDirItem)
1224 {
1225 m_pProps->m_pFrameDirItem.reset(
1226 new SvxFrameDirectionItem(
1227 SvxFrameDirection::Environment, RES_FRAMEDIR));
1228 }
1229 pQueryItem = m_pProps->m_pFrameDirItem.get();
1230 }
1231 else if (RES_LR_SPACE == pEntry->nWID)
1232 {
1233 if (!m_pProps->m_pLRSpaceItem)
1234 {
1235 m_pProps->m_pLRSpaceItem.reset(
1236 new SvxLRSpaceItem( RES_LR_SPACE ));
1237 }
1238 pQueryItem = m_pProps->m_pLRSpaceItem.get();
1239 }
1240 if (pQueryItem)
1241 {
1242 pQueryItem->QueryValue(pRet[nProperty],
1243 pEntry->nMemberId);
1244 }
1245 }
1246 }
1247 }
1248 }
1249 return aRet;
1250}
1251
1252uno::Sequence< uno::Any > SAL_CALL
1253SwXTextSection::getPropertyValues(
1254 const uno::Sequence< OUString >& rPropertyNames)
1255{
1256 SolarMutexGuard aGuard;
1257 uno::Sequence< uno::Any > aValues;
1258
1259 // workaround for bad designed API
1260 try
1261 {
1262 aValues = m_pImpl->GetPropertyValues_Impl( rPropertyNames );
1263 }
1264 catch (beans::UnknownPropertyException &)
1265 {
1266 css::uno::Any anyEx = cppu::getCaughtException();
1267 throw lang::WrappedTargetRuntimeException("Unknown property exception caught",
1268 static_cast < cppu::OWeakObject * > ( this ), anyEx );
1269 }
1270 catch (lang::WrappedTargetException &)
1271 {
1272 css::uno::Any anyEx = cppu::getCaughtException();
1273 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught",
1274 static_cast < cppu::OWeakObject * > ( this ), anyEx );
1275 }
1276
1277 return aValues;
1278}
1279
1280uno::Any SAL_CALL
1281SwXTextSection::getPropertyValue(const OUString& rPropertyName)
1282{
1283 SolarMutexGuard aGuard;
1284
1285 uno::Sequence< OUString > aPropertyNames { rPropertyName };
1286 return m_pImpl->GetPropertyValues_Impl(aPropertyNames).getConstArray()[0];
1287}
1288
1289void SAL_CALL SwXTextSection::addPropertiesChangeListener(
1290 const uno::Sequence< OUString >& /*aPropertyNames*/,
1291 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
1292{
1293 OSL_FAIL("SwXTextSection::addPropertiesChangeListener(): not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/unocore/unosect.cxx"
":" "1293" ": "), "%s", "SwXTextSection::addPropertiesChangeListener(): not implemented"
); } } while (false)
;
1294}
1295
1296void SAL_CALL SwXTextSection::removePropertiesChangeListener(
1297 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
1298{
1299 OSL_FAIL("SwXTextSection::removePropertiesChangeListener(): not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/unocore/unosect.cxx"
":" "1299" ": "), "%s", "SwXTextSection::removePropertiesChangeListener(): not implemented"
); } } while (false)
;
1300}
1301
1302void SAL_CALL SwXTextSection::firePropertiesChangeEvent(
1303 const uno::Sequence< OUString >& /*aPropertyNames*/,
1304 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
1305{
1306 OSL_FAIL("SwXTextSection::firePropertiesChangeEvent(): not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/unocore/unosect.cxx"
":" "1306" ": "), "%s", "SwXTextSection::firePropertiesChangeEvent(): not implemented"
); } } while (false)
;
1307}
1308
1309void SAL_CALL
1310SwXTextSection::addPropertyChangeListener(
1311 const OUString& /*rPropertyName*/,
1312 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1313{
1314 OSL_FAIL("SwXTextSection::addPropertyChangeListener(): not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/unocore/unosect.cxx"
":" "1314" ": "), "%s", "SwXTextSection::addPropertyChangeListener(): not implemented"
); } } while (false)
;
1315}
1316
1317void SAL_CALL
1318SwXTextSection::removePropertyChangeListener(
1319 const OUString& /*rPropertyName*/,
1320 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1321{
1322 OSL_FAIL("SwXTextSection::removePropertyChangeListener(): not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/unocore/unosect.cxx"
":" "1322" ": "), "%s", "SwXTextSection::removePropertyChangeListener(): not implemented"
); } } while (false)
;
1323}
1324
1325void SAL_CALL
1326SwXTextSection::addVetoableChangeListener(
1327 const OUString& /*rPropertyName*/,
1328 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1329{
1330 OSL_FAIL("SwXTextSection::addVetoableChangeListener(): not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/unocore/unosect.cxx"
":" "1330" ": "), "%s", "SwXTextSection::addVetoableChangeListener(): not implemented"
); } } while (false)
;
1331}
1332
1333void SAL_CALL
1334SwXTextSection::removeVetoableChangeListener(
1335 const OUString& /*rPropertyName*/,
1336 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1337{
1338 OSL_FAIL("SwXTextSection::removeVetoableChangeListener(): not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/core/unocore/unosect.cxx"
":" "1338" ": "), "%s", "SwXTextSection::removeVetoableChangeListener(): not implemented"
); } } while (false)
;
1339}
1340
1341beans::PropertyState SAL_CALL
1342SwXTextSection::getPropertyState(const OUString& rPropertyName)
1343{
1344 SolarMutexGuard aGuard;
1345
1346 uno::Sequence< OUString > aNames { rPropertyName };
1347 return getPropertyStates(aNames).getConstArray()[0];
1348}
1349
1350uno::Sequence< beans::PropertyState > SAL_CALL
1351SwXTextSection::getPropertyStates(
1352 const uno::Sequence< OUString >& rPropertyNames)
1353{
1354 SolarMutexGuard aGuard;
1355
1356 SwSectionFormat *const pFormat = m_pImpl->GetSectionFormat();
1357 if (!pFormat && !m_pImpl->m_bIsDescriptor)
1358 {
1359 throw uno::RuntimeException();
1360 }
1361
1362 uno::Sequence< beans::PropertyState > aStates(rPropertyNames.getLength());
1363 beans::PropertyState *const pStates = aStates.getArray();
1364 const OUString* pNames = rPropertyNames.getConstArray();
1365 for (sal_Int32 i = 0; i < rPropertyNames.getLength(); i++)
1366 {
1367 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
1368 SfxItemPropertySimpleEntry const*const pEntry =
1369 m_pImpl->m_rPropSet.getPropertyMap().getByName( pNames[i]);
1370 if (!pEntry)
1371 {
1372 throw beans::UnknownPropertyException(
1373 "Unknown property: " + pNames[i],
1374 static_cast< cppu::OWeakObject* >(this));
1375 }
1376 switch (pEntry->nWID)
1377 {
1378 case WID_SECT_CONDITION8000:
1379 case WID_SECT_DDE_TYPE8001:
1380 case WID_SECT_DDE_FILE8002:
1381 case WID_SECT_DDE_ELEMENT8003:
1382 case WID_SECT_DDE_AUTOUPDATE8008:
1383 case WID_SECT_LINK8004:
1384 case WID_SECT_REGION8007 :
1385 case WID_SECT_VISIBLE8005:
1386 case WID_SECT_PROTECTED8006:
1387 case WID_SECT_EDIT_IN_READONLY8013:
1388 case FN_PARAM_LINK_DISPLAY_NAME((20000 + 2400)+15):
1389 case FN_UNO_ANCHOR_TYPES((20000 + 2200) + 65):
1390 case FN_UNO_TEXT_WRAP((20000 + 2200) + 70):
1391 case FN_UNO_ANCHOR_TYPE((20000 + 2200) + 71):
1392 pStates[i] = beans::PropertyState_DIRECT_VALUE;
1393 break;
1394 default:
1395 {
1396 if (pFormat)
1397 {
1398 pStates[i] = m_pImpl->m_rPropSet.getPropertyState(
1399 pNames[i], pFormat->GetAttrSet());
1400 }
1401 else
1402 {
1403 if (RES_COL == pEntry->nWID)
1404 {
1405 if (!m_pImpl->m_pProps->m_pColItem)
1406 {
1407 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
1408 }
1409 else
1410 {
1411 pStates[i] = beans::PropertyState_DIRECT_VALUE;
1412 }
1413 }
1414 else
1415 {
1416 if (!m_pImpl->m_pProps->m_pBrushItem)
1417 {
1418 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
1419 }
1420 else
1421 {
1422 pStates[i] = beans::PropertyState_DIRECT_VALUE;
1423 }
1424 }
1425 }
1426 }
1427 }
1428 }
1429 return aStates;
1430}
1431
1432void SAL_CALL
1433SwXTextSection::setPropertyToDefault(const OUString& rPropertyName)
1434{
1435 SolarMutexGuard aGuard;
1436
1437 SwSectionFormat *const pFormat = m_pImpl->GetSectionFormat();
1438 if (!pFormat && !m_pImpl->m_bIsDescriptor)
1439 {
1440 throw uno::RuntimeException();
1441 }
1442
1443 SfxItemPropertySimpleEntry const*const pEntry =
1444 m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
1445 if (!pEntry)
1446 {
1447 throw beans::UnknownPropertyException(
1448 "Unknown property: " + rPropertyName,
1449 static_cast< cppu::OWeakObject* >(this));
1450 }
1451 if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
1452 {
1453 throw uno::RuntimeException(
1454 "Property is read-only: " + rPropertyName,
1455 static_cast<cppu::OWeakObject *>(this));
1456 }
1457
1458 std::unique_ptr<SwSectionData> const pSectionData(
1459 pFormat ? new SwSectionData(*pFormat->GetSection()) : nullptr);
1460
1461 std::unique_ptr<SfxItemSet> pNewAttrSet;
1462 bool bLinkModeChanged = false;
1463
1464 switch (pEntry->nWID)
1465 {
1466 case WID_SECT_CONDITION8000:
1467 {
1468 if (m_pImpl->m_bIsDescriptor)
1469 {
1470 m_pImpl->m_pProps->m_sCondition.clear();
1471 }
1472 else
1473 {
1474 pSectionData->SetCondition(OUString());
1475 }
1476 }
1477 break;
1478 case WID_SECT_DDE_TYPE8001 :
1479 case WID_SECT_DDE_FILE8002 :
1480 case WID_SECT_DDE_ELEMENT8003 :
1481 case WID_SECT_LINK8004 :
1482 case WID_SECT_REGION8007 :
1483 if (m_pImpl->m_bIsDescriptor)
1484 {
1485 m_pImpl->m_pProps->m_bDDE = false;
1486 m_pImpl->m_pProps->m_sLinkFileName.clear();
1487 m_pImpl->m_pProps->m_sSectionRegion.clear();
1488 m_pImpl->m_pProps->m_sSectionFilter.clear();
1489 }
1490 else
1491 {
1492 pSectionData->SetType(SectionType::Content);
1493 }
1494 break;
1495 case WID_SECT_DDE_AUTOUPDATE8008:
1496 if (m_pImpl->m_bIsDescriptor)
1497 {
1498 m_pImpl->m_pProps->m_bUpdateType = true;
1499 }
1500 else
1501 {
1502 bLinkModeChanged = true;
1503 }
1504 break;
1505 case WID_SECT_VISIBLE8005 :
1506 {
1507 if (m_pImpl->m_bIsDescriptor)
1508 {
1509 m_pImpl->m_pProps->m_bHidden = false;
1510 }
1511 else
1512 {
1513 pSectionData->SetHidden(false);
1514 }
1515 }
1516 break;
1517 case WID_SECT_PROTECTED8006:
1518 {
1519 if (m_pImpl->m_bIsDescriptor)
1520 {
1521 m_pImpl->m_pProps->m_bProtect = false;
1522 }
1523 else
1524 {
1525 pSectionData->SetProtectFlag(false);
1526 }
1527 }
1528 break;
1529 case WID_SECT_EDIT_IN_READONLY8013:
1530 {
1531 if (m_pImpl->m_bIsDescriptor)
1532 {
1533 m_pImpl->m_pProps->m_bEditInReadonly = false;
1534 }
1535 else
1536 {
1537 pSectionData->SetEditInReadonlyFlag(false);
1538 }
1539 }
1540 break;
1541
1542 case FN_UNO_ANCHOR_TYPES((20000 + 2200) + 65):
1543 case FN_UNO_TEXT_WRAP((20000 + 2200) + 70):
1544 case FN_UNO_ANCHOR_TYPE((20000 + 2200) + 71):
1545 break;
1546 default:
1547 {
1548 if (SfxItemPool::IsWhich(pEntry->nWID))
1549 {
1550 if (pFormat)
1551 {
1552 const SfxItemSet& rOldAttrSet = pFormat->GetAttrSet();
1553 pNewAttrSet.reset( new SfxItemSet(*rOldAttrSet.GetPool(), {{pEntry->nWID, pEntry->nWID}}));
1554 pNewAttrSet->ClearItem(pEntry->nWID);
1555 }
1556 else
1557 {
1558 if (RES_COL == pEntry->nWID)
1559 {
1560 m_pImpl->m_pProps->m_pColItem.reset();
1561 }
1562 else if (RES_BACKGROUND == pEntry->nWID)
1563 {
1564 m_pImpl->m_pProps->m_pBrushItem.reset();
1565 }
1566 }
1567 }
1568 }
1569 }
1570
1571 lcl_UpdateSection(pFormat, pSectionData, pNewAttrSet, bLinkModeChanged);
1572}
1573
1574uno::Any SAL_CALL
1575SwXTextSection::getPropertyDefault(const OUString& rPropertyName)
1576{
1577 SolarMutexGuard aGuard;
1578
1579 uno::Any aRet;
1580 SwSectionFormat *const pFormat = m_pImpl->GetSectionFormat();
1581 SfxItemPropertySimpleEntry const*const pEntry =
1582 m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
1583 if (!pEntry)
1584 {
1585 throw beans::UnknownPropertyException(
1586 "Unknown property: " + rPropertyName,
1587 static_cast<cppu::OWeakObject *>(this));
1588 }
1589
1590 switch(pEntry->nWID)
1591 {
1592 case WID_SECT_CONDITION8000:
1593 case WID_SECT_DDE_TYPE8001 :
1594 case WID_SECT_DDE_FILE8002 :
1595 case WID_SECT_DDE_ELEMENT8003 :
1596 case WID_SECT_REGION8007 :
1597 case FN_PARAM_LINK_DISPLAY_NAME((20000 + 2400)+15):
1598 aRet <<= OUString();
1599 break;
1600 case WID_SECT_LINK8004 :
1601 aRet <<= text::SectionFileLink();
1602 break;
1603 case WID_SECT_DDE_AUTOUPDATE8008:
1604 case WID_SECT_VISIBLE8005 :
1605 aRet <<= true;
1606 break;
1607 case WID_SECT_PROTECTED8006:
1608 case WID_SECT_EDIT_IN_READONLY8013:
1609 aRet <<= false;
1610 break;
1611 case FN_UNO_ANCHOR_TYPES((20000 + 2200) + 65):
1612 case FN_UNO_TEXT_WRAP((20000 + 2200) + 70):
1613 case FN_UNO_ANCHOR_TYPE((20000 + 2200) + 71):
1614 ::sw::GetDefaultTextContentValue(aRet, OUString(), pEntry->nWID);
1615 break;
1616 default:
1617 if(pFormat && SfxItemPool::IsWhich(pEntry->nWID))
1618 {
1619 SwDoc *const pDoc = pFormat->GetDoc();
1620 const SfxPoolItem& rDefItem =
1621 pDoc->GetAttrPool().GetDefaultItem(pEntry->nWID);
1622 rDefItem.QueryValue(aRet, pEntry->nMemberId);
1623 }
1624 }
1625 return aRet;
1626}
1627
1628OUString SAL_CALL SwXTextSection::getName()
1629{
1630 SolarMutexGuard aGuard;
1631
1632 OUString sRet;
1633 SwSectionFormat const*const pFormat = m_pImpl->GetSectionFormat();
1634 if(pFormat)
1635 {
1636 sRet = pFormat->GetSection()->GetSectionName();
1637 }
1638 else if (m_pImpl->m_bIsDescriptor)
1639 {
1640 sRet = m_pImpl->m_sName;
1641 }
1642 else
1643 {
1644 throw uno::RuntimeException();
1645 }
1646 return sRet;
1647}
1648
1649void SAL_CALL SwXTextSection::setName(const OUString& rName)
1650{
1651 SolarMutexGuard aGuard;
1652
1653 SwSectionFormat *const pFormat = m_pImpl->GetSectionFormat();
1654 if(pFormat)
1655 {
1656 SwSection *const pSect = pFormat->GetSection();
1657 SwSectionData aSection(*pSect);
1658 aSection.SetSectionName(rName);
1659
1660 const SwSectionFormats& rFormats = pFormat->GetDoc()->GetSections();
1661 size_t nApplyPos = SIZE_MAX(18446744073709551615UL);
1662 for( size_t i = 0; i < rFormats.size(); ++i )
1663 {
1664 if(rFormats[i]->GetSection() == pSect)
1665 {
1666 nApplyPos = i;
1667 }
1668 else if (rName == rFormats[i]->GetSection()->GetSectionName())
1669 {
1670 throw uno::RuntimeException();
1671 }
1672 }
1673 if (nApplyPos != SIZE_MAX(18446744073709551615UL))
1674 {
1675 {
1676 UnoActionContext aContext(pFormat->GetDoc());
1677 pFormat->GetDoc()->UpdateSection(nApplyPos, aSection);
1678 }
1679 {
1680 // temporarily remove actions to allow cursor update
1681 // TODO: why? no table cursor here!
1682 UnoActionRemoveContext aRemoveContext( pFormat->GetDoc() );
1683 }
1684 }
1685 }
1686 else if (m_pImpl->m_bIsDescriptor)
1687 {
1688 m_pImpl->m_sName = rName;
1689 }
1690 else
1691 {
1692 throw uno::RuntimeException();
1693 }
1694}
1695
1696OUString SAL_CALL
1697SwXTextSection::getImplementationName()
1698{
1699 return "SwXTextSection";
1700}
1701
1702sal_Bool SAL_CALL SwXTextSection::supportsService(const OUString& rServiceName)
1703{
1704 return cppu::supportsService(this, rServiceName);
1705}
1706
1707uno::Sequence< OUString > SAL_CALL
1708SwXTextSection::getSupportedServiceNames()
1709{
1710 return {
1711 "com.sun.star.text.TextContent",
1712 "com.sun.star.text.TextSection",
1713 "com.sun.star.document.LinkTarget"
1714 };
1715}
1716
1717// MetadatableMixin
1718::sfx2::Metadatable* SwXTextSection::GetCoreObject()
1719{
1720 SwSectionFormat *const pSectionFormat( m_pImpl->GetSectionFormat() );
1721 return pSectionFormat;
1722}
1723
1724uno::Reference<frame::XModel> SwXTextSection::GetModel()
1725{
1726 SwSectionFormat *const pSectionFormat( m_pImpl->GetSectionFormat() );
1727 if (pSectionFormat)
1728 {
1729 SwDocShell const*const pShell( pSectionFormat->GetDoc()->GetDocShell() );
1730 return pShell ? pShell->GetModel() : nullptr;
1731 }
1732 return nullptr;
1733}
1734
1735/* vim:set shiftwidth=4 softtabstop=4 expandtab: */