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 #include <com/sun/star/text/XTextSection.hpp>
25 
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 
32 #include "frmfmt.hxx"
33 #include <vector>
34 
35 class SwSectionFormat;
36 class SwDoc;
37 class SwSection;
38 class SwSectionNode;
39 class SwTOXBase;
41 
42 typedef std::vector<SwSection*> SwSections;
43 
44 enum class SectionType { Content,
45  ToxHeader,
46  ToxContent,
49  };
50 
51 enum class LinkCreateType
52 {
53  NONE, // Do nothing.
54  Connect, // Connect created link.
55  Update // Connect created link and update it.
56 };
57 
59 {
60 private:
62 
63  OUString m_sSectionName;
64  OUString m_sCondition;
65  OUString m_sLinkFileName;
66  OUString m_sLinkFilePassword; // Must be changed to Sequence.
67  css::uno::Sequence <sal_Int8> m_Password;
68 
70  bool m_bHiddenFlag : 1;
75  bool m_bProtectFlag : 1;
76  // Edit in readonly sections.
77  bool m_bEditInReadonlyFlag : 1;
78 
79  bool m_bHidden : 1;
80  bool m_bCondHiddenFlag : 1;
81  bool m_bConnectFlag : 1; // Connected to server?
82 
83 public:
84 
85  SwSectionData(SectionType const eType, OUString const& rName);
86  explicit SwSectionData(SwSection const&);
88  SwSectionData & operator=(SwSectionData const&);
89  bool operator==(SwSectionData const&) const;
90 
91  const OUString& GetSectionName() const { return m_sSectionName; }
92  void SetSectionName(OUString const& rName){ m_sSectionName = rName; }
93  SectionType GetType() const { return m_eType; }
94  void SetType(SectionType const eNew) { m_eType = eNew; }
95 
96  bool IsHidden() const { return m_bHidden; }
97  void SetHidden(bool const bFlag) { m_bHidden = bFlag; }
98 
99  bool IsHiddenFlag() const { return m_bHiddenFlag; }
100  SAL_DLLPRIVATE void
101  SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
102  bool IsProtectFlag() const { return m_bProtectFlag; }
103  SAL_DLLPRIVATE void
104  SetProtectFlag(bool const bFlag) { m_bProtectFlag = bFlag; }
105  bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag; }
106  void SetEditInReadonlyFlag(bool const bFlag)
107  { m_bEditInReadonlyFlag = bFlag; }
108 
109  void SetCondHidden(bool const bFlag) { m_bCondHiddenFlag = bFlag; }
110  bool IsCondHidden() const { return m_bCondHiddenFlag; }
111 
112  const OUString& GetCondition() const { return m_sCondition; }
113  void SetCondition(OUString const& rNew) { m_sCondition = rNew; }
114 
115  const OUString& GetLinkFileName() const { return m_sLinkFileName; }
116  void SetLinkFileName(OUString const& rNew)
117  {
118  m_sLinkFileName = rNew;
119  }
120 
121  const OUString& GetLinkFilePassword() const { return m_sLinkFilePassword; }
122  void SetLinkFilePassword(OUString const& rS){ m_sLinkFilePassword = rS; }
123 
124  css::uno::Sequence<sal_Int8> const& GetPassword() const
125  { return m_Password; }
126  void SetPassword(css::uno::Sequence<sal_Int8> const& rNew)
127  { m_Password = rNew; }
128  bool IsLinkType() const
129  { return (SectionType::DdeLink == m_eType) || (SectionType::FileLink == m_eType); }
130 
131  bool IsConnectFlag() const { return m_bConnectFlag; }
132  void SetConnectFlag(bool const bFlag){ m_bConnectFlag = bFlag; }
133 };
134 
136  : public SwClient
137  , public SvtListener // needed for SwClientNotify to be called from SwSectionFormat
138 {
139  // In order to correctly maintain the flag when creating/deleting frames.
140  friend class SwSectionNode;
141  // The "read CTOR" of SwSectionFrame have to change the Hiddenflag.
142  friend class SwSectionFrame;
143 
144 private:
146 
147  tools::SvRef<SwServerObject> m_RefObj; // Set if DataServer.
149 
150  SAL_DLLPRIVATE void ImplSetHiddenFlag(
151  bool const bHidden, bool const bCondition);
152 
153 protected:
154  virtual void Notify(SfxHint const& rHint) override;
155  virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
156 
157 public:
158 
159  SwSection(SectionType const eType, OUString const& rName,
160  SwSectionFormat & rFormat);
161  virtual ~SwSection() override;
162 
163  bool DataEquals(SwSectionData const& rCmp) const;
164 
165  void SetSectionData(SwSectionData const& rData);
166 
167  const OUString& GetSectionName() const { return m_Data.GetSectionName(); }
168  void SetSectionName(OUString const& rName){ m_Data.SetSectionName(rName); }
169  SectionType GetType() const { return m_Data.GetType(); }
170  void SetType(SectionType const eType) { return m_Data.SetType(eType); }
171 
172  inline SwSectionFormat* GetFormat();
173  inline SwSectionFormat const * GetFormat() const;
174 
175  // Set hidden/protected -> update the whole tree!
176  // (Attributes/flags are set/get.)
177  bool IsHidden() const { return m_Data.IsHidden(); }
178  void SetHidden (bool const bFlag = true);
179  bool IsProtect() const;
180  void SetProtect(bool const bFlag = true);
181  bool IsEditInReadonly() const;
182  void SetEditInReadonly(bool const bFlag = true);
183 
184  // Get internal flags (state including parents, not what is
185  // currently set at section!).
186  bool IsHiddenFlag() const { return m_Data.IsHiddenFlag(); }
187  bool IsProtectFlag() const { return m_Data.IsProtectFlag(); }
188  bool IsEditInReadonlyFlag() const { return m_Data.IsEditInReadonlyFlag(); }
189 
190  void SetCondHidden(bool const bFlag);
191  bool IsCondHidden() const { return m_Data.IsCondHidden(); }
192  // Query (also for parents) if this section is to be hidden.
193  bool CalcHiddenFlag() const;
194 
195  inline SwSection* GetParent() const;
196 
197  OUString const & GetCondition() const { return m_Data.GetCondition(); }
198  void SetCondition(OUString const& rNew) { m_Data.SetCondition(rNew); }
199 
200  OUString const & GetLinkFileName() const;
201  void SetLinkFileName(OUString const& rNew);
202  // Password of linked file (only valid during runtime!)
203  OUString const & GetLinkFilePassword() const
204  { return m_Data.GetLinkFilePassword(); }
205  void SetLinkFilePassword(OUString const& rS)
206  { m_Data.SetLinkFilePassword(rS); }
207 
208  // Get / set password of this section
209  css::uno::Sequence<sal_Int8> const& GetPassword() const
210  { return m_Data.GetPassword(); }
211 
212  // Data server methods.
213  void SetRefObject( SwServerObject* pObj );
214  const SwServerObject* GetObject() const { return m_RefObj.get(); }
215  SwServerObject* GetObject() { return m_RefObj.get(); }
216  bool IsServer() const { return m_RefObj.is(); }
217 
218  // Methods for linked ranges.
219  SfxLinkUpdateMode GetUpdateType() const { return m_RefLink->GetUpdateMode(); }
221  { m_RefLink->SetUpdateMode(nType); }
222 
223  bool IsConnected() const { return m_RefLink.is(); }
224  void UpdateNow() { m_RefLink->Update(); }
225  void Disconnect() { m_RefLink->Disconnect(); }
226 
227  const ::sfx2::SvBaseLink& GetBaseLink() const { return *m_RefLink; }
228  ::sfx2::SvBaseLink& GetBaseLink() { return *m_RefLink; }
229 
230  void CreateLink( LinkCreateType eType );
231 
232  static void MakeChildLinksVisible( const SwSectionNode& rSectNd );
233 
234  bool IsLinkType() const { return m_Data.IsLinkType(); }
235 
236  // Flags for UI. Did connection work?
237  bool IsConnectFlag() const { return m_Data.IsConnectFlag(); }
238  void SetConnectFlag(bool const bFlag = true)
239  { m_Data.SetConnectFlag(bFlag); }
240 
241  // Return the TOX base class if the section is a TOX section
242  const SwTOXBase* GetTOXBase() const;
243 
244  void BreakLink();
245 
246  void dumpAsXml(xmlTextWriterPtr pWriter) const;
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 SwClientNotify(const SwModify&, const SfxHint&) 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
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: atrfrm.cxx:2588
SAL_DLLPRIVATE void SetHiddenFlag(bool const bFlag)
Definition: section.hxx:101
tools::SvRef< SwServerObject > m_RefObj
Definition: section.hxx:147
std::vector< SwSection * > SwSections
Definition: section.hxx:40
SfxHintId
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: sectfrm.cxx:2585
css::uno::Sequence< sal_Int8 > const & GetPassword() const
Definition: section.hxx:124
void SetType(SectionType const eNew)
Definition: section.hxx:94
void SetType(SectionType const eType)
Definition: section.hxx:170
tools::SvRef< sfx2::SvBaseLink > m_RefLink
Definition: section.hxx:148
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject()=0
void SetHidden(bool const bFlag)
Definition: section.hxx:97
SAL_DLLPRIVATE void SetProtectFlag(bool const bFlag)
Definition: section.hxx:104
void SetLinkFileName(OUString const &rNew)
Definition: section.hxx:116
css::uno::Sequence< sal_Int8 > const & GetPassword() const
Definition: section.hxx:209
const OUString & GetCondition() const
Definition: section.hxx:112
void SetSectionName(OUString const &rName)
Definition: section.hxx:168
bool IsEditInReadonlyFlag() const
Definition: section.hxx:188
bool IsEditInReadonlyFlag() const
Definition: section.hxx:105
Definition: doc.hxx:187
bool IsConnected() const
Definition: section.hxx:223
SAL_DLLPRIVATE void SetXTextSection(css::uno::Reference< css::text::XTextSection > const &xTextSection)
Definition: section.hxx:322
const SwServerObject * GetObject() const
Definition: section.hxx:214
virtual void dumpAsXml(xmlTextWriterPtr writer=nullptr) const
Definition: xmldump.cxx:313
SwSectionFormat * GetFormat()
Definition: section.hxx:336
SwSection * GetParent() const
Definition: section.hxx:346
::sfx2::SvBaseLink & GetBaseLink()
Definition: section.hxx:228
virtual bool IsInContent() const =0
virtual bool IsInClipboard() const =0
virtual bool GetInfo(SfxPoolItem &) const override
Definition: calbck.cxx:161
SwSectionData m_Data
Definition: section.hxx:145
bool IsCondHidden() const
Definition: section.hxx:191
SfxLinkUpdateMode GetUpdateType() const
Definition: section.hxx:219
SectionSort
Definition: section.hxx:267
LinkCreateType
Definition: section.hxx:51
OUString const & GetCondition() const
Definition: section.hxx:197
SAL_DLLPRIVATE css::uno::WeakReference< css::text::XTextSection > const & GetXTextSection() const
Definition: section.hxx:320
bool IsLinkType() const
Definition: section.hxx:128
bool IsServer() const
Definition: section.hxx:216
void SetLinkFilePassword(OUString const &rS)
Definition: section.hxx:205
const ::sfx2::SvBaseLink & GetBaseLink() const
Definition: section.hxx:227
OUString m_sLinkFilePassword
Definition: section.hxx:66
const OUString & GetLinkFilePassword() const
Definition: section.hxx:121
bool IsProtectFlag() const
Definition: section.hxx:187
const OUString & GetSectionName() const
Definition: section.hxx:91
const SwSectionNode * GetSectionNode() const
Definition: section.hxx:313
void UpdateNow()
Definition: section.hxx:224
void MakeFrames(SwDoc *pDoc, const SwNodeIndex &rSttIdx, const SwNodeIndex &rEndIdx)
Definition: frmtool.cxx:2014
OUString m_sCondition
Hide condition.
Definition: section.hxx:64
bool IsConnectFlag() const
Definition: section.hxx:131
T * get() const
Style of a layout element.
Definition: frmfmt.hxx:59
void SetConnectFlag(bool const bFlag=true)
Definition: section.hxx:238
void Disconnect()
Definition: section.hxx:225
bool IsHidden() const
Definition: section.hxx:96
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:1947
const OUString & GetSectionName() const
Definition: section.hxx:167
OUString m_sSectionName
Definition: section.hxx:63
bool IsHidden() const
Definition: section.hxx:177
css::uno::Sequence< sal_Int8 > m_Password
Definition: section.hxx:67
bool IsHiddenFlag() const
Definition: section.hxx:186
bool IsProtectFlag() const
Definition: section.hxx:102
virtual void DelFrames()
Destroys all Frames in aDepend (Frames are identified via dynamic_cast).
Definition: atrfrm.cxx:2694
virtual bool IsInUndo() const =0
void SetCondHidden(bool const bFlag)
Definition: section.hxx:109
SwServerObject * GetObject()
Definition: section.hxx:215
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:44
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwSectionFrameMoveAndDeleteHint(const bool bSaveContent)
Definition: section.hxx:253
void SetCondition(OUString const &rNew)
Definition: section.hxx:113
bool IsLinkType() const
Definition: section.hxx:234
SwSectionFormat * GetParent() const
Definition: section.hxx:355
void SetConnectFlag(bool const bFlag)
Definition: section.hxx:132
const OUString & GetLinkFileName() const
Definition: section.hxx:115
void SetLinkFilePassword(OUString const &rS)
Definition: section.hxx:122
void SetUpdateType(SfxLinkUpdateMode nType)
Definition: section.hxx:220
virtual void Notify(const SfxHint &rHint)
void SetEditInReadonlyFlag(bool const bFlag)
Definition: section.hxx:106
virtual ::sfx2::IXmlIdRegistry & GetRegistry()=0
bool IsConnectFlag() const
Definition: section.hxx:237
const SwModify * GetRegisteredIn() const
Definition: calbck.hxx:164
bool IsHiddenFlag() const
Definition: section.hxx:99
SectionType GetType() const
Definition: section.hxx:93
virtual bool supportsFullDrawingLayerFillAttributeSet() const override
Definition: atrfrm.cxx:2583
SwSection * GetParentSection() const
Definition: section.hxx:363
SectionType m_eType
Definition: section.hxx:61
struct _xmlTextWriter * xmlTextWriterPtr
SectionType GetType() const
Definition: section.hxx:169
SwSection * GetSection() const
Definition: section.cxx:640
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
OUString const & GetLinkFilePassword() const
Definition: section.hxx:203
bool IsCondHidden() const
Definition: section.hxx:110
OUString m_sLinkFileName
Definition: section.hxx:65
SfxLinkUpdateMode
void SetCondition(OUString const &rNew)
Definition: section.hxx:198
virtual const SwFrameFormat * GetFormat() const
Definition: ssfrm.cxx:399
void SetPassword(css::uno::Sequence< sal_Int8 > const &rNew)
Definition: section.hxx:126
void SetSectionName(OUString const &rName)
Definition: section.hxx:92