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>
25 #include <tools/ref.hxx>
26 #include <svl/hint.hxx>
27 #include <sfx2/lnkbase.hxx>
28 #include <sfx2/Metadatable.hxx>
33 namespace com::sun::star
{
34 namespace text
{ class XTextSection
; }
36 class SwSectionFormat
;
43 typedef std::vector
<SwSection
*> SwSections
;
45 enum class SectionType
{ Content
,
48 DdeLink
= static_cast<int>(sfx2::SvBaseLinkObjectType::ClientDde
),
49 FileLink
= static_cast<int>(sfx2::SvBaseLinkObjectType::ClientFile
)
52 enum class LinkCreateType
55 Connect
, // Connect created link.
56 Update
// Connect created link and update it.
59 class SW_DLLPUBLIC SwSectionData
64 OUString m_sSectionName
;
65 OUString m_sCondition
;
66 OUString m_sLinkFileName
;
67 OUString m_sLinkFilePassword
; // Must be changed to Sequence.
68 css::uno::Sequence
<sal_Int8
> m_Password
;
70 /// It seems this flag caches the current final "hidden" state.
71 bool m_bHiddenFlag
: 1;
72 /// Flags that correspond to attributes in the format:
73 /// may have different value than format attribute:
74 /// format attr has value for this section, while flag is
75 /// effectively ORed with parent sections!
76 bool m_bProtectFlag
: 1;
77 // Edit in readonly sections.
78 bool m_bEditInReadonlyFlag
: 1;
80 bool m_bHidden
: 1; // All paragraphs hidden?
81 bool m_bCondHiddenFlag
: 1; // Hiddenflag for condition.
82 bool m_bConnectFlag
: 1; // Connected to server?
86 SwSectionData(SectionType
const eType
, OUString
const& rName
);
87 explicit SwSectionData(SwSection
const&);
88 SwSectionData(SwSectionData
const&);
89 SwSectionData
& operator=(SwSectionData
const&);
90 bool operator==(SwSectionData
const&) const;
92 const OUString
& GetSectionName() const { return m_sSectionName
; }
93 void SetSectionName(OUString
const& rName
){ m_sSectionName
= rName
; }
94 SectionType
GetType() const { return m_eType
; }
95 void SetType(SectionType
const eNew
) { m_eType
= eNew
; }
97 bool IsHidden() const { return m_bHidden
; }
98 void SetHidden(bool const bFlag
) { m_bHidden
= bFlag
; }
100 bool IsHiddenFlag() const { return m_bHiddenFlag
; }
102 SetHiddenFlag(bool const bFlag
) { m_bHiddenFlag
= bFlag
; }
103 bool IsProtectFlag() const { return m_bProtectFlag
; }
105 SetProtectFlag(bool const bFlag
) { m_bProtectFlag
= bFlag
; }
106 bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag
; }
107 void SetEditInReadonlyFlag(bool const bFlag
)
108 { m_bEditInReadonlyFlag
= bFlag
; }
110 void SetCondHidden(bool const bFlag
) { m_bCondHiddenFlag
= bFlag
; }
111 bool IsCondHidden() const { return m_bCondHiddenFlag
; }
113 const OUString
& GetCondition() const { return m_sCondition
; }
114 void SetCondition(OUString
const& rNew
) { m_sCondition
= rNew
; }
116 const OUString
& GetLinkFileName() const { return m_sLinkFileName
; }
117 void SetLinkFileName(OUString
const& rNew
)
119 m_sLinkFileName
= rNew
;
122 const OUString
& GetLinkFilePassword() const { return m_sLinkFilePassword
; }
123 void SetLinkFilePassword(OUString
const& rS
){ m_sLinkFilePassword
= rS
; }
125 css::uno::Sequence
<sal_Int8
> const& GetPassword() const
126 { return m_Password
; }
127 void SetPassword(css::uno::Sequence
<sal_Int8
> const& rNew
)
128 { m_Password
= rNew
; }
129 bool IsLinkType() const
130 { return (SectionType::DdeLink
== m_eType
) || (SectionType::FileLink
== m_eType
); }
132 bool IsConnectFlag() const { return m_bConnectFlag
; }
133 void SetConnectFlag(bool const bFlag
){ m_bConnectFlag
= bFlag
; }
135 static OUString
CollapseWhiteSpaces(const OUString
& sName
);
138 class SW_DLLPUBLIC SwSection
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 SwClientNotify(const SwModify
&, const SfxHint
&) override
;
160 SwSection(SectionType
const eType
, OUString
const& rName
,
161 SwSectionFormat
& rFormat
);
162 virtual ~SwSection() override
;
164 bool DataEquals(SwSectionData
const& rCmp
) const;
166 void SetSectionData(SwSectionData
const& rData
);
168 const OUString
& GetSectionName() const { return m_Data
.GetSectionName(); }
169 void SetSectionName(OUString
const& rName
){ m_Data
.SetSectionName(rName
); }
170 SectionType
GetType() const { return m_Data
.GetType(); }
171 void SetType(SectionType
const eType
) { return m_Data
.SetType(eType
); }
173 inline SwSectionFormat
* GetFormat();
174 inline SwSectionFormat
const * GetFormat() const;
176 // Set hidden/protected -> update the whole tree!
177 // (Attributes/flags are set/get.)
178 bool IsHidden() const { return m_Data
.IsHidden(); }
179 void SetHidden (bool const bFlag
= true);
180 bool IsProtect() const;
181 void SetProtect(bool const bFlag
= true);
182 bool IsEditInReadonly() const;
183 void SetEditInReadonly(bool const bFlag
= true);
185 // Get internal flags (state including parents, not what is
186 // currently set at section!).
187 bool IsHiddenFlag() const { return m_Data
.IsHiddenFlag(); }
188 bool IsProtectFlag() const { return m_Data
.IsProtectFlag(); }
189 bool IsEditInReadonlyFlag() const { return m_Data
.IsEditInReadonlyFlag(); }
191 void SetCondHidden(bool const bFlag
);
192 bool IsCondHidden() const { return m_Data
.IsCondHidden(); }
193 // Query (also for parents) if this section is to be hidden.
194 bool CalcHiddenFlag() const;
196 inline SwSection
* GetParent() const;
198 OUString
const & GetCondition() const { return m_Data
.GetCondition(); }
199 void SetCondition(OUString
const& rNew
) { m_Data
.SetCondition(rNew
); }
201 OUString
const & GetLinkFileName() const;
202 void SetLinkFileName(OUString
const& rNew
);
203 // Password of linked file (only valid during runtime!)
204 OUString
const & GetLinkFilePassword() const
205 { return m_Data
.GetLinkFilePassword(); }
206 void SetLinkFilePassword(OUString
const& rS
)
207 { m_Data
.SetLinkFilePassword(rS
); }
209 // Get / set password of this section
210 css::uno::Sequence
<sal_Int8
> const& GetPassword() const
211 { return m_Data
.GetPassword(); }
213 // Data server methods.
214 void SetRefObject( SwServerObject
* pObj
);
215 const SwServerObject
* GetObject() const { return m_RefObj
.get(); }
216 SwServerObject
* GetObject() { return m_RefObj
.get(); }
217 bool IsServer() const { return m_RefObj
.is(); }
219 // Methods for linked ranges.
220 SfxLinkUpdateMode
GetUpdateType() const { return m_RefLink
->GetUpdateMode(); }
221 void SetUpdateType(SfxLinkUpdateMode nType
)
222 { m_RefLink
->SetUpdateMode(nType
); }
224 bool IsConnected() const { return m_RefLink
.is(); }
225 void UpdateNow() { m_RefLink
->Update(); }
226 void Disconnect() { m_RefLink
->Disconnect(); }
228 const ::sfx2::SvBaseLink
& GetBaseLink() const { return *m_RefLink
; }
229 ::sfx2::SvBaseLink
& GetBaseLink() { return *m_RefLink
; }
231 void CreateLink( LinkCreateType eType
);
233 static void MakeChildLinksVisible( const SwSectionNode
& rSectNd
);
235 bool IsLinkType() const { return m_Data
.IsLinkType(); }
237 // Flags for UI. Did connection work?
238 bool IsConnectFlag() const { return m_Data
.IsConnectFlag(); }
239 void SetConnectFlag(bool const bFlag
= true)
240 { m_Data
.SetConnectFlag(bFlag
); }
242 // Return the TOX base class if the section is a TOX section
243 const SwTOXBase
* GetTOXBase() const;
250 class SwSectionFrameMoveAndDeleteHint final
: public SfxHint
253 SwSectionFrameMoveAndDeleteHint( const bool bSaveContent
)
254 : SfxHint( SfxHintId::SwSectionFrameMoveAndDelete
)
255 , mbSaveContent( bSaveContent
)
258 bool IsSaveContent() const
260 return mbSaveContent
;
264 const bool mbSaveContent
;
267 enum class SectionSort
{ Not
, Pos
};
269 class SW_DLLPUBLIC SwSectionFormat final
270 : public SwFrameFormat
271 , public ::sfx2::Metadatable
275 /** Why does this exist in addition to the m_wXObject in SwFrameFormat?
276 in case of an index, both a SwXDocumentIndex and a SwXTextSection
277 register at this SwSectionFormat, so we need to have two refs.
279 css::uno::WeakReference
<css::text::XTextSection
> m_wXTextSection
;
281 SAL_DLLPRIVATE
void UpdateParent(); // Parent has been changed.
283 SwSectionFormat( SwFrameFormat
* pDrvdFrame
, SwDoc
*pDoc
);
284 virtual void SwClientNotify(const SwModify
&, const SfxHint
&) override
;
287 virtual ~SwSectionFormat() override
;
289 // Deletes all Frames in aDepend (Frames are recognized via dynamic_cast).
290 virtual void DelFrames() override
;
293 virtual void MakeFrames() override
;
295 // Get information from Format.
296 virtual bool GetInfo( SfxPoolItem
& ) const override
;
298 SwSection
* GetSection() const;
299 inline SwSectionFormat
* GetParent() const;
300 inline SwSection
* GetParentSection() const;
302 // All sections that are derived from this one:
303 // - sorted according to name or position or unsorted
304 // - all of them or only those that are in the normal Nodes-array.
305 void GetChildSections( SwSections
& rArr
,
306 SectionSort eSort
= SectionSort::Not
,
307 bool bAllSections
= true ) const;
309 // Query whether section is in Nodes-array or in UndoNodes-array.
310 bool IsInNodesArr() const;
312 SwSectionNode
* GetSectionNode();
313 const SwSectionNode
* GetSectionNode() const
314 { return const_cast<SwSectionFormat
*>(this)
315 ->GetSectionNode(); }
317 // Is section a valid one for global document?
318 const SwSection
* GetGlobalDocSection() const;
320 SAL_DLLPRIVATE
css::uno::WeakReference
<css::text::XTextSection
> const& GetXTextSection() const
321 { return m_wXTextSection
; }
322 SAL_DLLPRIVATE
void SetXTextSection(css::uno::Reference
<css::text::XTextSection
> const& xTextSection
)
323 { m_wXTextSection
= xTextSection
; }
326 virtual ::sfx2::IXmlIdRegistry
& GetRegistry() override
;
327 virtual bool IsInClipboard() const override
;
328 virtual bool IsInUndo() const override
;
329 virtual bool IsInContent() const override
;
330 virtual css::uno::Reference
< css::rdf::XMetadatable
> MakeUnoObject() override
;
331 virtual bool supportsFullDrawingLayerFillAttributeSet() const override
;
332 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
336 SwSectionFormat
* SwSection::GetFormat()
338 return static_cast<SwSectionFormat
*>(GetRegisteredIn());
341 SwSectionFormat
const * SwSection::GetFormat() const
343 return static_cast<SwSectionFormat
const *>(GetRegisteredIn());
346 inline SwSection
* SwSection::GetParent() const
348 SwSectionFormat
const * pFormat
= GetFormat();
349 SwSection
* pRet
= nullptr;
351 pRet
= pFormat
->GetParentSection();
355 inline SwSectionFormat
* SwSectionFormat::GetParent() const
357 SwSectionFormat
* pRet
= nullptr;
358 if( GetRegisteredIn() )
359 pRet
= const_cast<SwSectionFormat
*>(dynamic_cast< const SwSectionFormat
* >( GetRegisteredIn() ));
363 inline SwSection
* SwSectionFormat::GetParentSection() const
365 SwSectionFormat
* pParent
= GetParent();
366 SwSection
* pRet
= nullptr;
369 pRet
= pParent
->GetSection();
374 #endif /* _ INCLUDED_SW_INC_SECTION_HXX */
376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */