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 { namespace sun { namespace star {
34  namespace text { class XTextSection; }
35 } } }
36 
37 class SwSectionFormat;
38 class SwDoc;
39 class SwSection;
40 class SwSectionNode;
41 class SwTOXBase;
43 
44 typedef std::vector<SwSection*> SwSections;
45 
51  };
52 
54 {
55  CREATE_NONE, // Do nothing.
56  CREATE_CONNECT, // Connect created link.
57  CREATE_UPDATE // Connect created link and update it.
58 };
59 
61 {
62 private:
64 
65  OUString m_sSectionName;
66  OUString m_sCondition;
67  OUString m_sLinkFileName;
68  OUString m_sLinkFilePassword; // Must be changed to Sequence.
69  css::uno::Sequence <sal_Int8> m_Password;
70 
72  bool m_bHiddenFlag : 1;
77  bool m_bProtectFlag : 1;
78  // Edit in readonly sections.
79  bool m_bEditInReadonlyFlag : 1;
80 
81  bool m_bHidden : 1; // All paragraphs hidden?
82  bool m_bCondHiddenFlag : 1; // Hiddenflag for condition.
83  bool m_bConnectFlag : 1; // Connected to server?
84 
85 public:
86 
87  SwSectionData(SectionType const eType, OUString const& rName);
88  explicit SwSectionData(SwSection const&);
90  SwSectionData & operator=(SwSectionData const&);
91  bool operator==(SwSectionData const&) const;
92 
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; }
97 
98  bool IsHidden() const { return m_bHidden; }
99  void SetHidden(bool const bFlag) { m_bHidden = bFlag; }
100 
101  bool IsHiddenFlag() const { return m_bHiddenFlag; }
102  SAL_DLLPRIVATE void
103  SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
104  bool IsProtectFlag() const { return m_bProtectFlag; }
105  SAL_DLLPRIVATE void
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; }
110 
111  void SetCondHidden(bool const bFlag) { m_bCondHiddenFlag = bFlag; }
112  bool IsCondHidden() const { return m_bCondHiddenFlag; }
113 
114  const OUString& GetCondition() const { return m_sCondition; }
115  void SetCondition(OUString const& rNew) { m_sCondition = rNew; }
116 
117  const OUString& GetLinkFileName() const { return m_sLinkFileName; }
118  void SetLinkFileName(OUString const& rNew)
119  {
120  m_sLinkFileName = rNew;
121  }
122 
123  const OUString& GetLinkFilePassword() const { return m_sLinkFilePassword; }
124  void SetLinkFilePassword(OUString const& rS){ m_sLinkFilePassword = rS; }
125 
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 (DDE_LINK_SECTION == m_eType) || (FILE_LINK_SECTION == m_eType); }
132 
133  bool IsConnectFlag() const { return m_bConnectFlag; }
134  void SetConnectFlag(bool const bFlag){ m_bConnectFlag = bFlag; }
135 
136  static OUString CollapseWhiteSpaces(const OUString& sName);
137 };
138 
140  : public SwClient
141 {
142  // In order to correctly maintain the flag when creating/deleting frames.
143  friend class SwSectionNode;
144  // The "read CTOR" of SwSectionFrame have to change the Hiddenflag.
145  friend class SwSectionFrame;
146 
147 private:
149 
150  tools::SvRef<SwServerObject> m_RefObj; // Set if DataServer.
152 
153  SAL_DLLPRIVATE void ImplSetHiddenFlag(
154  bool const bHidden, bool const bCondition);
155 
156 protected:
157  virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) override;
158 
159 public:
160 
161  SwSection(SectionType const eType, OUString const& rName,
162  SwSectionFormat & rFormat);
163  virtual ~SwSection() override;
164 
165  bool DataEquals(SwSectionData const& rCmp) const;
166 
167  void SetSectionData(SwSectionData const& rData);
168 
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); }
173 
174  inline SwSectionFormat* GetFormat();
175  inline SwSectionFormat const * GetFormat() const;
176 
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);
185 
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(); }
191 
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;
196 
197  inline SwSection* GetParent() const;
198 
199  OUString const & GetCondition() const { return m_Data.GetCondition(); }
200  void SetCondition(OUString const& rNew) { m_Data.SetCondition(rNew); }
201 
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); }
209 
210  // Get / set password of this section
211  css::uno::Sequence<sal_Int8> const& GetPassword() const
212  { return m_Data.GetPassword(); }
213 
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(); }
219 
220  // Methods for linked ranges.
221  SfxLinkUpdateMode GetUpdateType() const { return m_RefLink->GetUpdateMode(); }
223  { m_RefLink->SetUpdateMode(nType); }
224 
225  bool IsConnected() const { return m_RefLink.is(); }
226  void UpdateNow() { m_RefLink->Update(); }
227  void Disconnect() { m_RefLink->Disconnect(); }
228 
229  const ::sfx2::SvBaseLink& GetBaseLink() const { return *m_RefLink; }
230  ::sfx2::SvBaseLink& GetBaseLink() { return *m_RefLink; }
231 
232  void CreateLink( LinkCreateType eType );
233 
234  static void MakeChildLinksVisible( const SwSectionNode& rSectNd );
235 
236  bool IsLinkType() const { return m_Data.IsLinkType(); }
237 
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); }
242 
243  // Return the TOX base class if the section is a TOX section
244  const SwTOXBase* GetTOXBase() const;
245 
246  void BreakLink();
247 
248 };
249 
250 // #i117863#
252 {
253  public:
254  SwSectionFrameMoveAndDeleteHint( const bool bSaveContent )
256  , mbSaveContent( bSaveContent )
257  {}
258 
259  bool IsSaveContent() const
260  {
261  return mbSaveContent;
262  }
263 
264  private:
265  const bool mbSaveContent;
266 };
267 
268 enum class SectionSort { Not, Pos };
269 
271  : public SwFrameFormat
272  , public ::sfx2::Metadatable
273 {
274  friend class SwDoc;
275 
280  css::uno::WeakReference<css::text::XTextSection> m_wXTextSection;
281 
282  SAL_DLLPRIVATE void UpdateParent(); // Parent has been changed.
283 
284 protected:
285  SwSectionFormat( SwFrameFormat* pDrvdFrame, SwDoc *pDoc );
286  virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) override;
287 
288 public:
289  virtual ~SwSectionFormat() override;
290 
291  // Deletes all Frames in aDepend (Frames are recognized via dynamic_cast).
292  virtual void DelFrames() override;
293 
294  // Creates views.
295  virtual void MakeFrames() override;
296 
297  // Get information from Format.
298  virtual bool GetInfo( SfxPoolItem& ) const override;
299 
300  SwSection* GetSection() const;
301  inline SwSectionFormat* GetParent() const;
302  inline SwSection* GetParentSection() const;
303 
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,
309  bool bAllSections = true ) const;
310 
311  // Query whether section is in Nodes-array or in UndoNodes-array.
312  bool IsInNodesArr() const;
313 
314  SwSectionNode* GetSectionNode();
316  { return const_cast<SwSectionFormat *>(this)
317  ->GetSectionNode(); }
318 
319  // Is section a valid one for global document?
320  const SwSection* GetGlobalDocSection() const;
321 
322  SAL_DLLPRIVATE css::uno::WeakReference<css::text::XTextSection> const& GetXTextSection() const
323  { return m_wXTextSection; }
324  SAL_DLLPRIVATE void SetXTextSection(css::uno::Reference<css::text::XTextSection> const& xTextSection)
325  { m_wXTextSection = xTextSection; }
326 
327  // sfx2::Metadatable
328  virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
329  virtual bool IsInClipboard() const override;
330  virtual bool IsInUndo() const override;
331  virtual bool IsInContent() const override;
332  virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
333  void dumpAsXml(xmlTextWriterPtr pWriter) const;
334 
335 };
336 
338 {
339  return static_cast<SwSectionFormat*>(GetRegisteredIn());
340 }
341 
343 {
344  return static_cast<SwSectionFormat const *>(GetRegisteredIn());
345 }
346 
348 {
349  SwSectionFormat const * pFormat = GetFormat();
350  SwSection* pRet = nullptr;
351  if( pFormat )
352  pRet = pFormat->GetParentSection();
353  return pRet;
354 }
355 
357 {
358  SwSectionFormat* pRet = nullptr;
359  if( GetRegisteredIn() )
360  pRet = const_cast<SwSectionFormat*>(dynamic_cast< const SwSectionFormat* >( GetRegisteredIn() ));
361  return pRet;
362 }
363 
365 {
366  SwSectionFormat* pParent = GetParent();
367  SwSection* pRet = nullptr;
368  if( pParent )
369  {
370  pRet = pParent->GetSection();
371  }
372  return pRet;
373 }
374 
375 #endif /* _ INCLUDED_SW_INC_SECTION_HXX */
376 
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool is() const
SAL_DLLPRIVATE void SetHiddenFlag(bool const bFlag)
Definition: section.hxx:103
tools::SvRef< SwServerObject > m_RefObj
Definition: section.hxx:150
std::vector< SwSection * > SwSections
Definition: section.hxx:42
SfxHintId
css::uno::Sequence< sal_Int8 > const & GetPassword() const
Definition: section.hxx:126
void SetType(SectionType const eNew)
Definition: section.hxx:96
void SetType(SectionType const eType)
Definition: section.hxx:172
tools::SvRef< sfx2::SvBaseLink > m_RefLink
Definition: section.hxx:151
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject()=0
void SetHidden(bool const bFlag)
Definition: section.hxx:99
SAL_DLLPRIVATE void SetProtectFlag(bool const bFlag)
Definition: section.hxx:106
void SetLinkFileName(OUString const &rNew)
Definition: section.hxx:118
css::uno::Sequence< sal_Int8 > const & GetPassword() const
Definition: section.hxx:211
const OUString & GetCondition() const
Definition: section.hxx:114
void SetSectionName(OUString const &rName)
Definition: section.hxx:170
#define OBJECT_CLIENT_FILE
bool IsEditInReadonlyFlag() const
Definition: section.hxx:190
bool IsEditInReadonlyFlag() const
Definition: section.hxx:107
Definition: doc.hxx:185
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNewValue) override
Definition: atrfrm.cxx:2507
bool IsConnected() const
Definition: section.hxx:225
SAL_DLLPRIVATE void SetXTextSection(css::uno::Reference< css::text::XTextSection > const &xTextSection)
Definition: section.hxx:324
const SwServerObject * GetObject() const
Definition: section.hxx:216
SwSectionFormat * GetFormat()
Definition: section.hxx:337
SwSection * GetParent() const
Definition: section.hxx:347
::sfx2::SvBaseLink & GetBaseLink()
Definition: section.hxx:230
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:148
bool IsCondHidden() const
Definition: section.hxx:193
SfxLinkUpdateMode GetUpdateType() const
Definition: section.hxx:221
SectionSort
Definition: section.hxx:268
LinkCreateType
Definition: section.hxx:53
OUString const & GetCondition() const
Definition: section.hxx:199
SAL_DLLPRIVATE css::uno::WeakReference< css::text::XTextSection > const & GetXTextSection() const
Definition: section.hxx:322
bool IsLinkType() const
Definition: section.hxx:130
bool IsServer() const
Definition: section.hxx:218
void SetLinkFilePassword(OUString const &rS)
Definition: section.hxx:207
const ::sfx2::SvBaseLink & GetBaseLink() const
Definition: section.hxx:229
OUString m_sLinkFilePassword
Definition: section.hxx:68
const OUString & GetLinkFilePassword() const
Definition: section.hxx:123
bool IsProtectFlag() const
Definition: section.hxx:189
const OUString & GetSectionName() const
Definition: section.hxx:93
const SwSectionNode * GetSectionNode() const
Definition: section.hxx:315
void UpdateNow()
Definition: section.hxx:226
void MakeFrames(SwDoc *pDoc, const SwNodeIndex &rSttIdx, const SwNodeIndex &rEndIdx)
Definition: frmtool.cxx:1770
OUString m_sCondition
Definition: section.hxx:66
bool IsConnectFlag() const
Definition: section.hxx:133
struct _xmlTextWriter * xmlTextWriterPtr
T * get() const
Style of a layout element.
Definition: frmfmt.hxx:57
void SetConnectFlag(bool const bFlag=true)
Definition: section.hxx:240
void Disconnect()
Definition: section.hxx:227
bool IsHidden() const
Definition: section.hxx:98
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:1950
const OUString & GetSectionName() const
Definition: section.hxx:169
OUString m_sSectionName
Definition: section.hxx:65
bool IsHidden() const
Definition: section.hxx:179
css::uno::Sequence< sal_Int8 > m_Password
Definition: section.hxx:69
bool IsHiddenFlag() const
Definition: section.hxx:188
bool IsProtectFlag() const
Definition: section.hxx:104
virtual void DelFrames()
Destroys all Frames in aDepend (Frames are identified via dynamic_cast).
Definition: atrfrm.cxx:2617
virtual bool IsInUndo() const =0
void SetCondHidden(bool const bFlag)
Definition: section.hxx:111
SwServerObject * GetObject()
Definition: section.hxx:217
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:280
SectionType
Definition: section.hxx:46
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwSectionFrameMoveAndDeleteHint(const bool bSaveContent)
Definition: section.hxx:254
void SetCondition(OUString const &rNew)
Definition: section.hxx:115
bool IsLinkType() const
Definition: section.hxx:236
SwSectionFormat * GetParent() const
Definition: section.hxx:356
void SetConnectFlag(bool const bFlag)
Definition: section.hxx:134
const OUString & GetLinkFileName() const
Definition: section.hxx:117
void SetLinkFilePassword(OUString const &rS)
Definition: section.hxx:124
void SetUpdateType(SfxLinkUpdateMode nType)
Definition: section.hxx:222
#define OBJECT_CLIENT_DDE
void SetEditInReadonlyFlag(bool const bFlag)
Definition: section.hxx:108
virtual ::sfx2::IXmlIdRegistry & GetRegistry()=0
bool IsConnectFlag() const
Definition: section.hxx:239
const SwModify * GetRegisteredIn() const
Definition: calbck.hxx:157
bool IsHiddenFlag() const
Definition: section.hxx:101
SectionType GetType() const
Definition: section.hxx:95
SwSection * GetParentSection() const
Definition: section.hxx:364
SectionType m_eType
Definition: section.hxx:63
def text(shape, st)
SectionType GetType() const
Definition: section.hxx:171
SwSection * GetSection() const
Definition: section.cxx:675
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
OUString const & GetLinkFilePassword() const
Definition: section.hxx:205
bool IsCondHidden() const
Definition: section.hxx:112
OUString m_sLinkFileName
Definition: section.hxx:67
virtual void Modify(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.cxx:130
SfxLinkUpdateMode
void SetCondition(OUString const &rNew)
Definition: section.hxx:200
virtual const SwFrameFormat * GetFormat() const
Definition: ssfrm.cxx:393
void SetPassword(css::uno::Sequence< sal_Int8 > const &rNew)
Definition: section.hxx:128
void SetSectionName(OUString const &rName)
Definition: section.hxx:94