LibreOffice Module sw (master)  1
section.hxx
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 #ifndef INCLUDED_SW_INC_SECTION_HXX
21 #define INCLUDED_SW_INC_SECTION_HXX
22 
23 #include <com/sun/star/uno/Sequence.h>
24 
25 #include <tools/ref.hxx>
26 #include <svl/hint.hxx>
27 #include <sfx2/lnkbase.hxx>
28 #include <sfx2/Metadatable.hxx>
29 
30 #include "frmfmt.hxx"
31 #include <vector>
32 
33 namespace com::sun::star {
34  namespace text { class XTextSection; }
35 }
36 class SwSectionFormat;
37 class SwDoc;
38 class SwSection;
39 class SwSectionNode;
40 class SwTOXBase;
42 
43 typedef std::vector<SwSection*> SwSections;
44 
45 enum class SectionType { Content,
46  ToxHeader,
47  ToxContent,
50  };
51 
52 enum class LinkCreateType
53 {
54  NONE, // Do nothing.
55  Connect, // Connect created link.
56  Update // Connect created link and update it.
57 };
58 
60 {
61 private:
63 
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;
69 
71  bool m_bHiddenFlag : 1;
76  bool m_bProtectFlag : 1;
77  // Edit in readonly sections.
78  bool m_bEditInReadonlyFlag : 1;
79 
80  bool m_bHidden : 1; // All paragraphs hidden?
81  bool m_bCondHiddenFlag : 1; // Hiddenflag for condition.
82  bool m_bConnectFlag : 1; // Connected to server?
83 
84 public:
85 
86  SwSectionData(SectionType const eType, OUString const& rName);
87  explicit SwSectionData(SwSection const&);
89  SwSectionData & operator=(SwSectionData const&);
90  bool operator==(SwSectionData const&) const;
91 
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; }
96 
97  bool IsHidden() const { return m_bHidden; }
98  void SetHidden(bool const bFlag) { m_bHidden = bFlag; }
99 
100  bool IsHiddenFlag() const { return m_bHiddenFlag; }
101  SAL_DLLPRIVATE void
102  SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
103  bool IsProtectFlag() const { return m_bProtectFlag; }
104  SAL_DLLPRIVATE void
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; }
109 
110  void SetCondHidden(bool const bFlag) { m_bCondHiddenFlag = bFlag; }
111  bool IsCondHidden() const { return m_bCondHiddenFlag; }
112 
113  const OUString& GetCondition() const { return m_sCondition; }
114  void SetCondition(OUString const& rNew) { m_sCondition = rNew; }
115 
116  const OUString& GetLinkFileName() const { return m_sLinkFileName; }
117  void SetLinkFileName(OUString const& rNew)
118  {
119  m_sLinkFileName = rNew;
120  }
121 
122  const OUString& GetLinkFilePassword() const { return m_sLinkFilePassword; }
123  void SetLinkFilePassword(OUString const& rS){ m_sLinkFilePassword = rS; }
124 
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); }
131 
132  bool IsConnectFlag() const { return m_bConnectFlag; }
133  void SetConnectFlag(bool const bFlag){ m_bConnectFlag = bFlag; }
134 
135  static OUString CollapseWhiteSpaces(const OUString& sName);
136 };
137 
139  : public SwClient
140 {
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;
145 
146 private:
148 
149  tools::SvRef<SwServerObject> m_RefObj; // Set if DataServer.
151 
152  SAL_DLLPRIVATE void ImplSetHiddenFlag(
153  bool const bHidden, bool const bCondition);
154 
155 protected:
156  virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) override;
157 
158 public:
159 
160  SwSection(SectionType const eType, OUString const& rName,
161  SwSectionFormat & rFormat);
162  virtual ~SwSection() override;
163 
164  bool DataEquals(SwSectionData const& rCmp) const;
165 
166  void SetSectionData(SwSectionData const& rData);
167 
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); }
172 
173  inline SwSectionFormat* GetFormat();
174  inline SwSectionFormat const * GetFormat() const;
175 
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);
184 
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(); }
190 
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;
195 
196  inline SwSection* GetParent() const;
197 
198  OUString const & GetCondition() const { return m_Data.GetCondition(); }
199  void SetCondition(OUString const& rNew) { m_Data.SetCondition(rNew); }
200 
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); }
208 
209  // Get / set password of this section
210  css::uno::Sequence<sal_Int8> const& GetPassword() const
211  { return m_Data.GetPassword(); }
212 
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(); }
218 
219  // Methods for linked ranges.
220  SfxLinkUpdateMode GetUpdateType() const { return m_RefLink->GetUpdateMode(); }
222  { m_RefLink->SetUpdateMode(nType); }
223 
224  bool IsConnected() const { return m_RefLink.is(); }
225  void UpdateNow() { m_RefLink->Update(); }
226  void Disconnect() { m_RefLink->Disconnect(); }
227 
228  const ::sfx2::SvBaseLink& GetBaseLink() const { return *m_RefLink; }
229  ::sfx2::SvBaseLink& GetBaseLink() { return *m_RefLink; }
230 
231  void CreateLink( LinkCreateType eType );
232 
233  static void MakeChildLinksVisible( const SwSectionNode& rSectNd );
234 
235  bool IsLinkType() const { return m_Data.IsLinkType(); }
236 
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); }
241 
242  // Return the TOX base class if the section is a TOX section
243  const SwTOXBase* GetTOXBase() const;
244 
245  void BreakLink();
246 
247 };
248 
249 // #i117863#
251 {
252  public:
253  SwSectionFrameMoveAndDeleteHint( const bool bSaveContent )
255  , mbSaveContent( bSaveContent )
256  {}
257 
258  bool IsSaveContent() const
259  {
260  return mbSaveContent;
261  }
262 
263  private:
264  const bool mbSaveContent;
265 };
266 
267 enum class SectionSort { Not, Pos };
268 
270  : public SwFrameFormat
271  , public ::sfx2::Metadatable
272 {
273  friend class SwDoc;
274 
279  css::uno::WeakReference<css::text::XTextSection> m_wXTextSection;
280 
281  SAL_DLLPRIVATE void UpdateParent(); // Parent has been changed.
282 
283  SwSectionFormat( SwFrameFormat* pDrvdFrame, SwDoc *pDoc );
284  virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) override;
285 
286 public:
287  virtual ~SwSectionFormat() override;
288 
289  // Deletes all Frames in aDepend (Frames are recognized via dynamic_cast).
290  virtual void DelFrames() override;
291 
292  // Creates views.
293  virtual void MakeFrames() override;
294 
295  // Get information from Format.
296  virtual bool GetInfo( SfxPoolItem& ) const override;
297 
298  SwSection* GetSection() const;
299  inline SwSectionFormat* GetParent() const;
300  inline SwSection* GetParentSection() const;
301 
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,
307  bool bAllSections = true ) const;
308 
309  // Query whether section is in Nodes-array or in UndoNodes-array.
310  bool IsInNodesArr() const;
311 
312  SwSectionNode* GetSectionNode();
314  { return const_cast<SwSectionFormat *>(this)
315  ->GetSectionNode(); }
316 
317  // Is section a valid one for global document?
318  const SwSection* GetGlobalDocSection() const;
319 
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; }
324 
325  // sfx2::Metadatable
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;
333 
334 };
335 
337 {
338  return static_cast<SwSectionFormat*>(GetRegisteredIn());
339 }
340 
342 {
343  return static_cast<SwSectionFormat const *>(GetRegisteredIn());
344 }
345 
347 {
348  SwSectionFormat const * pFormat = GetFormat();
349  SwSection* pRet = nullptr;
350  if( pFormat )
351  pRet = pFormat->GetParentSection();
352  return pRet;
353 }
354 
356 {
357  SwSectionFormat* pRet = nullptr;
358  if( GetRegisteredIn() )
359  pRet = const_cast<SwSectionFormat*>(dynamic_cast< const SwSectionFormat* >( GetRegisteredIn() ));
360  return pRet;
361 }
362 
364 {
365  SwSectionFormat* pParent = GetParent();
366  SwSection* pRet = nullptr;
367  if( pParent )
368  {
369  pRet = pParent->GetSection();
370  }
371  return pRet;
372 }
373 
374 #endif /* _ INCLUDED_SW_INC_SECTION_HXX */
375 
376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool is() const
SAL_DLLPRIVATE void SetHiddenFlag(bool const bFlag)
Definition: section.hxx:102
tools::SvRef< SwServerObject > m_RefObj
Definition: section.hxx:149
std::vector< SwSection * > SwSections
Definition: section.hxx:41
SfxHintId
css::uno::Sequence< sal_Int8 > const & GetPassword() const
Definition: section.hxx:125
void SetType(SectionType const eNew)
Definition: section.hxx:95
void SetType(SectionType const eType)
Definition: section.hxx:171
tools::SvRef< sfx2::SvBaseLink > m_RefLink
Definition: section.hxx:150
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject()=0
void SetHidden(bool const bFlag)
Definition: section.hxx:98
SAL_DLLPRIVATE void SetProtectFlag(bool const bFlag)
Definition: section.hxx:105
void SetLinkFileName(OUString const &rNew)
Definition: section.hxx:117
css::uno::Sequence< sal_Int8 > const & GetPassword() const
Definition: section.hxx:210
const OUString & GetCondition() const
Definition: section.hxx:113
void SetSectionName(OUString const &rName)
Definition: section.hxx:169
bool IsEditInReadonlyFlag() const
Definition: section.hxx:189
bool IsEditInReadonlyFlag() const
Definition: section.hxx:106
Definition: doc.hxx:184
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNewValue) override
Definition: atrfrm.cxx:2560
bool IsConnected() const
Definition: section.hxx:224
SAL_DLLPRIVATE void SetXTextSection(css::uno::Reference< css::text::XTextSection > const &xTextSection)
Definition: section.hxx:322
const SwServerObject * GetObject() const
Definition: section.hxx:215
SwSectionFormat * GetFormat()
Definition: section.hxx:336
SwSection * GetParent() const
Definition: section.hxx:346
::sfx2::SvBaseLink & GetBaseLink()
Definition: section.hxx:229
virtual bool IsInContent() const =0
virtual bool IsInClipboard() const =0
virtual bool GetInfo(SfxPoolItem &) const override
Definition: calbck.cxx:206
SwSectionData m_Data
Definition: section.hxx:147
bool IsCondHidden() const
Definition: section.hxx:192
SfxLinkUpdateMode GetUpdateType() const
Definition: section.hxx:220
SectionSort
Definition: section.hxx:267
LinkCreateType
Definition: section.hxx:52
OUString const & GetCondition() const
Definition: section.hxx:198
SAL_DLLPRIVATE css::uno::WeakReference< css::text::XTextSection > const & GetXTextSection() const
Definition: section.hxx:320
bool IsLinkType() const
Definition: section.hxx:129
bool IsServer() const
Definition: section.hxx:217
void SetLinkFilePassword(OUString const &rS)
Definition: section.hxx:206
const ::sfx2::SvBaseLink & GetBaseLink() const
Definition: section.hxx:228
OUString m_sLinkFilePassword
Definition: section.hxx:67
const OUString & GetLinkFilePassword() const
Definition: section.hxx:122
bool IsProtectFlag() const
Definition: section.hxx:188
const OUString & GetSectionName() const
Definition: section.hxx:92
const SwSectionNode * GetSectionNode() const
Definition: section.hxx:313
void UpdateNow()
Definition: section.hxx:225
void MakeFrames(SwDoc *pDoc, const SwNodeIndex &rSttIdx, const SwNodeIndex &rEndIdx)
Definition: frmtool.cxx:1936
OUString m_sCondition
Definition: section.hxx:65
exports com.sun.star. text
bool IsConnectFlag() const
Definition: section.hxx:132
struct _xmlTextWriter * xmlTextWriterPtr
T * get() const
Style of a layout element.
Definition: frmfmt.hxx:57
void SetConnectFlag(bool const bFlag=true)
Definition: section.hxx:239
void Disconnect()
Definition: section.hxx:226
bool IsHidden() const
Definition: section.hxx:97
void dumpAsXml(xmlTextWriterPtr=nullptr) const
Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by...
Definition: docfmt.cxx:1932
const OUString & GetSectionName() const
Definition: section.hxx:168
OUString m_sSectionName
Definition: section.hxx:64
bool IsHidden() const
Definition: section.hxx:178
css::uno::Sequence< sal_Int8 > m_Password
Definition: section.hxx:68
bool IsHiddenFlag() const
Definition: section.hxx:187
bool IsProtectFlag() const
Definition: section.hxx:103
virtual void DelFrames()
Destroys all Frames in aDepend (Frames are identified via dynamic_cast).
Definition: atrfrm.cxx:2670
virtual bool IsInUndo() const =0
void SetCondHidden(bool const bFlag)
Definition: section.hxx:110
SwServerObject * GetObject()
Definition: section.hxx:216
css::uno::WeakReference< css::text::XTextSection > m_wXTextSection
Why does this exist in addition to the m_wXObject in SwFrameFormat? in case of an index...
Definition: section.hxx:279
SectionType
Definition: section.hxx:45
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwSectionFrameMoveAndDeleteHint(const bool bSaveContent)
Definition: section.hxx:253
void SetCondition(OUString const &rNew)
Definition: section.hxx:114
bool IsLinkType() const
Definition: section.hxx:235
SwSectionFormat * GetParent() const
Definition: section.hxx:355
void SetConnectFlag(bool const bFlag)
Definition: section.hxx:133
const OUString & GetLinkFileName() const
Definition: section.hxx:116
void SetLinkFilePassword(OUString const &rS)
Definition: section.hxx:123
void SetUpdateType(SfxLinkUpdateMode nType)
Definition: section.hxx:221
void SetEditInReadonlyFlag(bool const bFlag)
Definition: section.hxx:107
virtual ::sfx2::IXmlIdRegistry & GetRegistry()=0
bool IsConnectFlag() const
Definition: section.hxx:238
const SwModify * GetRegisteredIn() const
Definition: calbck.hxx:159
bool IsHiddenFlag() const
Definition: section.hxx:100
SectionType GetType() const
Definition: section.hxx:94
virtual bool supportsFullDrawingLayerFillAttributeSet() const override
Definition: atrfrm.cxx:2555
SwSection * GetParentSection() const
Definition: section.hxx:363
SectionType m_eType
Definition: section.hxx:62
SectionType GetType() const
Definition: section.hxx:170
SwSection * GetSection() const
Definition: section.cxx:672
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
OUString const & GetLinkFilePassword() const
Definition: section.hxx:204
bool IsCondHidden() const
Definition: section.hxx:111
OUString m_sLinkFileName
Definition: section.hxx:66
virtual void Modify(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.cxx:130
SfxLinkUpdateMode
void SetCondition(OUString const &rNew)
Definition: section.hxx:199
virtual const SwFrameFormat * GetFormat() const
Definition: ssfrm.cxx:393
void SetPassword(css::uno::Sequence< sal_Int8 > const &rNew)
Definition: section.hxx:127
void SetSectionName(OUString const &rName)
Definition: section.hxx:93