1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SW_INC_SECTION_HXX
21 #define INCLUDED_SW_INC_SECTION_HXX
23 #include <com/sun/star/uno/Sequence.h>
24 #include <com/sun/star/text/XTextSection.hpp>
26 #include <tools/ref.hxx>
27 #include <svl/hint.hxx>
28 #include <svl/listener.hxx>
29 #include <sfx2/lnkbase.hxx>
30 #include <sfx2/Metadatable.hxx>
31 #include <unotools/weakref.hxx>
36 class SwSectionFormat
;
44 typedef std::vector
<SwSection
*> SwSections
;
46 enum class SectionType
{ Content
,
49 DdeLink
= static_cast<int>(sfx2::SvBaseLinkObjectType::ClientDde
),
50 FileLink
= static_cast<int>(sfx2::SvBaseLinkObjectType::ClientFile
)
53 enum class LinkCreateType
56 Connect
, // Connect created link.
57 Update
// Connect created link and update it.
60 class SW_DLLPUBLIC SwSectionData
65 OUString m_sSectionName
;
66 OUString m_sCondition
; ///< Hide condition
67 OUString m_sLinkFileName
;
68 OUString m_sLinkFilePassword
; // Must be changed to Sequence.
69 css::uno::Sequence
<sal_Int8
> m_Password
;
71 /// It seems this flag caches the current final "hidden" state.
72 bool m_bHiddenFlag
: 1;
73 /// Flags that correspond to attributes in the format:
74 /// may have different value than format attribute:
75 /// format attr has value for this section, while flag is
76 /// effectively ORed with parent sections!
77 bool m_bProtectFlag
: 1; ///< protect flag is no longer inherited
78 // Edit in readonly sections.
79 bool m_bEditInReadonlyFlag
: 1;
81 bool m_bHidden
: 1; ///< Section is hidden, unless condition evaluates `false'
82 bool m_bCondHiddenFlag
: 1; ///< Hide condition evaluated `true'
83 bool m_bConnectFlag
: 1; // Connected to server?
87 SwSectionData(SectionType
const eType
, OUString
const& rName
);
88 explicit SwSectionData(SwSection
const&);
89 SwSectionData(SwSectionData
const&);
90 SwSectionData
& operator=(SwSectionData
const&);
91 bool operator==(SwSectionData
const&) const;
93 const OUString
& GetSectionName() const { return m_sSectionName
; }
94 void SetSectionName(OUString
const& rName
){ m_sSectionName
= rName
; }
95 SectionType
GetType() const { return m_eType
; }
96 void SetType(SectionType
const eNew
) { m_eType
= eNew
; }
98 bool IsHidden() const { return m_bHidden
; }
99 void SetHidden(bool const bFlag
) { m_bHidden
= bFlag
; }
101 bool IsHiddenFlag() const { return m_bHiddenFlag
; }
103 SetHiddenFlag(bool const bFlag
) { m_bHiddenFlag
= bFlag
; }
104 bool IsProtectFlag() const { return m_bProtectFlag
; }
106 SetProtectFlag(bool const bFlag
) { m_bProtectFlag
= bFlag
; }
107 bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag
; }
108 void SetEditInReadonlyFlag(bool const bFlag
)
109 { m_bEditInReadonlyFlag
= bFlag
; }
111 void SetCondHidden(bool const bFlag
) { m_bCondHiddenFlag
= bFlag
; }
112 bool IsCondHidden() const { return m_bCondHiddenFlag
; }
114 const OUString
& GetCondition() const { return m_sCondition
; }
115 void SetCondition(OUString
const& rNew
) { m_sCondition
= rNew
; }
117 const OUString
& GetLinkFileName() const { return m_sLinkFileName
; }
118 void SetLinkFileName(OUString
const& rNew
)
120 m_sLinkFileName
= rNew
;
123 const OUString
& GetLinkFilePassword() const { return m_sLinkFilePassword
; }
124 void SetLinkFilePassword(OUString
const& rS
){ m_sLinkFilePassword
= rS
; }
126 css::uno::Sequence
<sal_Int8
> const& GetPassword() const
127 { return m_Password
; }
128 void SetPassword(css::uno::Sequence
<sal_Int8
> const& rNew
)
129 { m_Password
= rNew
; }
130 bool IsLinkType() const
131 { return (SectionType::DdeLink
== m_eType
) || (SectionType::FileLink
== m_eType
); }
133 bool IsConnectFlag() const { return m_bConnectFlag
; }
134 void SetConnectFlag(bool const bFlag
){ m_bConnectFlag
= bFlag
; }
137 class SW_DLLPUBLIC SwSection
139 , public SvtListener
// needed for SwClientNotify to be called from SwSectionFormat
141 // In order to correctly maintain the flag when creating/deleting frames.
142 friend class SwSectionNode
;
143 // The "read CTOR" of SwSectionFrame have to change the Hiddenflag.
144 friend class SwSectionFrame
;
147 mutable SwSectionData m_Data
;
149 tools::SvRef
<SwServerObject
> m_RefObj
; // Set if DataServer.
150 tools::SvRef
<sfx2::SvBaseLink
> m_RefLink
;
152 SAL_DLLPRIVATE
void ImplSetHiddenFlag(
153 bool const bHidden
, bool const bCondition
);
156 virtual void Notify(SfxHint
const& rHint
) override
;
157 virtual void SwClientNotify(const SwModify
&, const SfxHint
&) override
;
161 SwSection(SectionType
const eType
, OUString
const& rName
,
162 SwSectionFormat
& rFormat
);
163 virtual ~SwSection() override
;
165 bool DataEquals(SwSectionData
const& rCmp
) const;
167 void SetSectionData(SwSectionData
const& rData
);
169 const OUString
& GetSectionName() const { return m_Data
.GetSectionName(); }
170 void SetSectionName(OUString
const& rName
){ m_Data
.SetSectionName(rName
); }
171 SectionType
GetType() const { return m_Data
.GetType(); }
172 void SetType(SectionType
const eType
) { return m_Data
.SetType(eType
); }
174 inline SwSectionFormat
* GetFormat();
175 inline SwSectionFormat
const * GetFormat() const;
177 // Set hidden/protected -> update the whole tree!
178 // (Attributes/flags are set/get.)
179 bool IsHidden() const { return m_Data
.IsHidden(); }
180 void SetHidden (bool const bFlag
= true);
181 bool IsProtect() const;
182 void SetProtect(bool const bFlag
= true);
183 bool IsEditInReadonly() const;
184 void SetEditInReadonly(bool const bFlag
= true);
186 // Get internal flags (state including parents, not what is
187 // currently set at section!).
188 bool IsHiddenFlag() const { return m_Data
.IsHiddenFlag(); }
189 bool IsProtectFlag() const { return m_Data
.IsProtectFlag(); }
190 bool IsEditInReadonlyFlag() const { return m_Data
.IsEditInReadonlyFlag(); }
192 void SetCondHidden(bool const bFlag
);
193 bool IsCondHidden() const { return m_Data
.IsCondHidden(); }
194 // Query (also for parents) if this section is to be hidden.
195 bool CalcHiddenFlag() const;
197 inline SwSection
* GetParent() const;
199 OUString
const & GetCondition() const { return m_Data
.GetCondition(); }
200 void SetCondition(OUString
const& rNew
) { m_Data
.SetCondition(rNew
); }
202 OUString
const & GetLinkFileName() const;
203 void SetLinkFileName(OUString
const& rNew
);
204 // Password of linked file (only valid during runtime!)
205 OUString
const & GetLinkFilePassword() const
206 { return m_Data
.GetLinkFilePassword(); }
207 void SetLinkFilePassword(OUString
const& rS
)
208 { m_Data
.SetLinkFilePassword(rS
); }
210 // Get / set password of this section
211 css::uno::Sequence
<sal_Int8
> const& GetPassword() const
212 { return m_Data
.GetPassword(); }
214 // Data server methods.
215 void SetRefObject( SwServerObject
* pObj
);
216 const SwServerObject
* GetObject() const { return m_RefObj
.get(); }
217 SwServerObject
* GetObject() { return m_RefObj
.get(); }
218 bool IsServer() const { return m_RefObj
.is(); }
220 // Methods for linked ranges.
221 SfxLinkUpdateMode
GetUpdateType() const { return m_RefLink
->GetUpdateMode(); }
222 void SetUpdateType(SfxLinkUpdateMode nType
)
223 { m_RefLink
->SetUpdateMode(nType
); }
225 bool IsConnected() const { return m_RefLink
.is(); }
226 void UpdateNow() { m_RefLink
->Update(); }
227 void Disconnect() { m_RefLink
->Disconnect(); }
229 const ::sfx2::SvBaseLink
& GetBaseLink() const { return *m_RefLink
; }
230 ::sfx2::SvBaseLink
& GetBaseLink() { return *m_RefLink
; }
232 void CreateLink( LinkCreateType eType
);
234 static void MakeChildLinksVisible( const SwSectionNode
& rSectNd
);
236 bool IsLinkType() const { return m_Data
.IsLinkType(); }
238 // Flags for UI. Did connection work?
239 bool IsConnectFlag() const { return m_Data
.IsConnectFlag(); }
240 void SetConnectFlag(bool const bFlag
= true)
241 { m_Data
.SetConnectFlag(bFlag
); }
243 // Return the TOX base class if the section is a TOX section
244 const SwTOXBase
* GetTOXBase() const;
248 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
252 class SwSectionFrameMoveAndDeleteHint final
: public SfxHint
255 SwSectionFrameMoveAndDeleteHint( const bool bSaveContent
)
256 : SfxHint( SfxHintId::SwSectionFrameMoveAndDelete
)
257 , mbSaveContent( bSaveContent
)
260 bool IsSaveContent() const
262 return mbSaveContent
;
266 const bool mbSaveContent
;
269 enum class SectionSort
{ Not
, Pos
};
271 class SW_DLLPUBLIC SwSectionFormat final
272 : public SwFrameFormat
273 , public ::sfx2::Metadatable
277 /** Why does this exist in addition to the m_wXObject in SwFrameFormat?
278 in case of an index, both a SwXDocumentIndex and a SwXTextSection
279 register at this SwSectionFormat, so we need to have two refs.
281 unotools::WeakReference
<SwXTextSection
> m_wXTextSection
;
283 SAL_DLLPRIVATE
void UpdateParent(); // Parent has been changed.
285 SwSectionFormat( SwFrameFormat
* pDrvdFrame
, SwDoc
*pDoc
);
286 virtual void SwClientNotify(const SwModify
&, const SfxHint
&) override
;
289 virtual ~SwSectionFormat() override
;
291 // Deletes all Frames in aDepend (Frames are recognized via dynamic_cast).
292 virtual void DelFrames() override
;
295 virtual void MakeFrames() override
;
297 // Get information from Format.
298 virtual bool GetInfo( SfxPoolItem
& ) const override
;
300 SwSection
* GetSection() const;
301 inline SwSectionFormat
* GetParent() const;
302 inline SwSection
* GetParentSection() const;
304 // All sections that are derived from this one:
305 // - sorted according to name or position or unsorted
306 // - all of them or only those that are in the normal Nodes-array.
307 void GetChildSections( SwSections
& rArr
,
308 SectionSort eSort
= SectionSort::Not
,
309 bool bAllSections
= true ) const;
311 // Query whether section is in Nodes-array or in UndoNodes-array.
312 bool IsInNodesArr() const;
314 SwSectionNode
* GetSectionNode();
315 const SwSectionNode
* GetSectionNode() const
316 { return const_cast<SwSectionFormat
*>(this)
317 ->GetSectionNode(); }
319 // Is section a valid one for global document?
320 const SwSection
* GetGlobalDocSection() const;
322 SAL_DLLPRIVATE
unotools::WeakReference
<SwXTextSection
> const& GetXTextSection() const
323 { return m_wXTextSection
; }
324 SAL_DLLPRIVATE
void SetXTextSection(rtl::Reference
<SwXTextSection
> const& xTextSection
);
327 virtual ::sfx2::IXmlIdRegistry
& GetRegistry() override
;
328 virtual bool IsInClipboard() const override
;
329 virtual bool IsInUndo() const override
;
330 virtual bool IsInContent() const override
;
331 virtual css::uno::Reference
< css::rdf::XMetadatable
> MakeUnoObject() override
;
332 virtual bool supportsFullDrawingLayerFillAttributeSet() const override
;
333 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
337 SwSectionFormat
* SwSection::GetFormat()
339 return static_cast<SwSectionFormat
*>(GetRegisteredIn());
342 SwSectionFormat
const * SwSection::GetFormat() const
344 return static_cast<SwSectionFormat
const *>(GetRegisteredIn());
347 inline SwSection
* SwSection::GetParent() const
349 SwSectionFormat
const * pFormat
= GetFormat();
350 SwSection
* pRet
= nullptr;
352 pRet
= pFormat
->GetParentSection();
356 inline SwSectionFormat
* SwSectionFormat::GetParent() const
358 SwSectionFormat
* pRet
= nullptr;
359 if( GetRegisteredIn() )
360 pRet
= const_cast<SwSectionFormat
*>(dynamic_cast< const SwSectionFormat
* >( GetRegisteredIn() ));
364 inline SwSection
* SwSectionFormat::GetParentSection() const
366 SwSectionFormat
* pParent
= GetParent();
367 SwSection
* pRet
= nullptr;
370 pRet
= pParent
->GetSection();
375 #endif /* _ INCLUDED_SW_INC_SECTION_HXX */
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */