LibreOffice Module sw (master)  1
ndarr.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_NDARR_HXX
21 #define INCLUDED_SW_INC_NDARR_HXX
22 
23 #include <sal/config.h>
24 
25 #include <limits>
26 #include <vector>
27 #include <memory>
28 
29 #include "bparr.hxx"
30 #include "ndtyp.hxx"
31 #include <rtl/ustring.hxx>
32 #include <o3tl/sorted_vector.hxx>
33 
34 class Graphic;
35 class GraphicObject;
36 class SwAttrSet;
37 class SfxItemSet;
38 class SwContentNode;
39 class SwDoc;
40 class SwGrfFormatColl;
41 class SwGrfNode;
42 class SwNode;
43 class SwNodeIndex;
44 class SwNodeRange;
45 class SwOLENode;
46 class SwPaM;
47 class SwSectionData;
48 class SwSectionFormat;
49 class SwTOXBase;
50 class SwSectionNode;
51 class SwStartNode;
52 class SwTableBoxFormat;
53 class SwTableFormat;
54 class SwTableLine;
55 class SwTableLineFormat;
56 class SwTableNode;
57 class SwTextFormatColl;
58 class SwTextNode;
59 class SwUndoTableToText;
60 class SwUndoTextToTable;
61 struct SwPosition;
62 
63 namespace sw { class DocumentContentOperationsManager; }
64 namespace svt { class EmbeddedObjectRef; }
65 
66 
67 typedef SwNode * SwNodePtr;
68 typedef bool (*FnForEach_SwNodes)( const SwNodePtr&, void* pArgs );
69 typedef struct _xmlTextWriter *xmlTextWriterPtr;
70 
72 {
73  bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
74 };
75 
76 class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
77 {
78 public:
79  static constexpr auto npos = std::numeric_limits<size_type>::max();
80 
81  bool Seek_Entry(SwNode* rP, size_type* pnPos) const;
82 };
83 
84 struct SwTableToTextSave;
85 using SwTableToTextSaves = std::vector<std::unique_ptr<SwTableToTextSave>>;
86 
87 class SW_DLLPUBLIC SwNodes final
88  : private BigPtrArray
89 {
90  friend class SwDoc;
91  friend class SwNode;
92  friend class SwNodeIndex;
93  friend class SwStartNode;
94  friend class ::sw::DocumentContentOperationsManager;
95 
97  void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, bool bDel );
98 
99  void InsertNode( const SwNodePtr pNode,
100  const SwNodeIndex& rPos );
101  void InsertNode( const SwNodePtr pNode,
102  sal_uLong nPos );
103 
105 
106  SwNode *m_pEndOfPostIts, *m_pEndOfInserts,
107  *m_pEndOfAutotext, *m_pEndOfRedlines;
108  std::unique_ptr<SwNode> m_pEndOfContent;
109 
110  mutable std::unique_ptr<SwOutlineNodes> m_pOutlineNodes;
111 
112  bool m_bInNodesDel : 1;
114  bool m_bInDelUpdOutline : 1;
115 
116  // Actions on the nodes.
117  static void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
118  void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
119 
120  void ChgNode( SwNodeIndex const & rDelPos, sal_uLong nSize,
121  SwNodeIndex& rInsPos, bool bNewFrames );
122 
123  void UpdateOutlineIdx( const SwNode& );
124 
125  void CopyNodes( const SwNodeRange&, const SwNodeIndex&,
126  bool bNewFrames, bool bTableInsDummyNode = false ) const;
127  void DelDummyNodes( const SwNodeRange& rRg );
128 
129  SwNodes(SwNodes const&) = delete;
130  SwNodes& operator=(SwNodes const&) = delete;
131 
132  SwNodes( SwDoc* pDoc );
133 
134 public:
135  ~SwNodes();
136 
137  typedef std::vector<SwNodeRange> NodeRanges_t;
138  typedef std::vector<NodeRanges_t> TableRanges_t;
139 
140  SwNodePtr operator[]( sal_uLong n ) const; // defined in node.hxx
141 
142  sal_uLong Count() const { return BigPtrArray::Count(); }
143  void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = nullptr )
144  {
145  ForEach( 0, BigPtrArray::Count(), fnForEach, pArgs );
146  }
147  void ForEach( sal_uLong nStt, sal_uLong nEnd, FnForEach_SwNodes fnForEach, void* pArgs );
148  void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
149  FnForEach_SwNodes fnForEach, void* pArgs );
150 
152  SwNode& GetEndOfPostIts() const { return *m_pEndOfPostIts; }
154  SwNode& GetEndOfInserts() const { return *m_pEndOfInserts; }
156  SwNode& GetEndOfAutotext() const { return *m_pEndOfAutotext; }
158  SwNode& GetEndOfRedlines() const { return *m_pEndOfRedlines; }
161  SwNode& GetEndOfExtras() const { return *m_pEndOfRedlines; }
163  SwNode& GetEndOfContent() const { return *m_pEndOfContent; }
164 
167  bool IsDocNodes() const;
168 
169  static sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex);
170  void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
171 
172  bool MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
173  bool bNewFrames = true );
174  void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
175 
176  void Copy_( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
177  bool bNewFrames = true ) const
178  { CopyNodes( rRg, rInsPos, bNewFrames ); }
179 
180  void SectionUp( SwNodeRange *);
181  void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
182 
183  static void GoStartOfSection(SwNodeIndex *);
184  static void GoEndOfSection(SwNodeIndex *);
185 
186  SwContentNode* GoNext(SwNodeIndex *) const;
188 
191  SwContentNode* GoNextSection( SwNodeIndex *, bool bSkipHidden = true,
192  bool bSkipProtect = true ) const;
193  static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden = true,
194  bool bSkipProtect = true );
195 
199  static SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
201 
203  SwTextNode *MakeTextNode( const SwNodeIndex & rWhere,
204  SwTextFormatColl *pColl,
205  bool bNewFrames = true);
206  SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
207  SwStartNodeType eSttNdTyp,
208  SwTextFormatColl *pColl );
209 
210  static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
211  const OUString& rGrfName,
212  const OUString& rFltName,
213  const Graphic* pGraphic,
214  SwGrfFormatColl *pColl,
215  SwAttrSet const * pAutoAttr = nullptr );
216 
217  static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
218  const GraphicObject& rGrfObj,
219  SwGrfFormatColl *pColl );
220 
221  SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
222  const svt::EmbeddedObjectRef&,
223  SwGrfFormatColl *pColl );
224  SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
225  const OUString &rName,
226  sal_Int64 nAspect,
227  SwGrfFormatColl *pColl,
228  SwAttrSet const * pAutoAttr );
229 
231  const SwOutlineNodes& GetOutLineNds() const { return *m_pOutlineNodes;}
232 
234  void UpdateOutlineNode(SwNode & rNd);
235 
244  static SwTableNode* InsertTable( const SwNodeIndex& rNdIdx,
245  sal_uInt16 nBoxes, SwTextFormatColl* pContentTextColl,
246  sal_uInt16 nLines, sal_uInt16 nRepeat,
247  SwTextFormatColl* pHeadlineTextColl,
248  const SwAttrSet * pAttrSet);
249 
251  SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
252  SwTableFormat* pTableFormat,
253  SwTableLineFormat* pLineFormat,
254  SwTableBoxFormat* pBoxFormat,
255  SwTextFormatColl* pTextColl,
256  SwUndoTextToTable* pUndo );
257 
258  std::unique_ptr<SwNodeRange> ExpandRangeForTableBox(const SwNodeRange & rRange);
259 
261  SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
262  SwTableFormat* pTableFormat,
263  SwTableLineFormat* pLineFormat,
264  SwTableBoxFormat* pBoxFormat );
265 
267  bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
270  SwTableNode* UndoTableToText( sal_uLong nStt, sal_uLong nEnd,
271  const SwTableToTextSaves& rSavedData );
272 
276  bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFormat*,
278  SwTextFormatColl*, const SfxItemSet* pAutoAttr,
279  sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
286  SwTableNode* SplitTable( const SwNodeIndex& rPos, bool bAfter = true,
287  bool bCalcNewSize = false );
289  bool MergeTable( const SwNodeIndex& rPos, bool bWithPrev = true,
290  sal_uInt16 nMode = 0 );
291 
293  SwSectionNode* InsertTextSection(SwNodeIndex const& rNdIdx,
294  SwSectionFormat& rSectionFormat,
295  SwSectionData const&,
296  SwTOXBase const*const pTOXBase,
297  SwNodeIndex const*const pEnd,
298  bool const bInsAtStart = true,
299  bool const bCreateFrames = true);
300 
302  SwDoc* GetDoc() { return m_pMyDoc; }
303  const SwDoc* GetDoc() const { return m_pMyDoc; }
304 
309  SwNode* FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
310  const SwNode* pEnd ) const;
311 
312  SwNode * DocumentSectionStartNode(SwNode * pNode) const;
313  SwNode * DocumentSectionEndNode(SwNode * pNode) const;
314 
318  void dumpAsXml( xmlTextWriterPtr pWriter ) const;
319 };
320 
321 
322 #endif
323 
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Starts a section of nodes in the document model.
Definition: node.hxx:303
SwNode & GetEndOfInserts() const
Section for all footnotes.
Definition: ndarr.hxx:154
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:156
sal_uLong Count() const
Definition: ndarr.hxx:142
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
Marks a position in the document model.
Definition: pam.hxx:35
sal_uIntPtr sal_uLong
Definition: doc.hxx:186
std::vector< SwNodeRange > NodeRanges_t
Definition: ndarr.hxx:137
SwTableLine is one table row in the document model.
Definition: swtable.hxx:344
bool(* FnForEach_SwNodes)(const SwNodePtr &, void *pArgs)
Definition: ndarr.hxx:68
Dialog to specify the properties of date form field.
SwNode & GetEndOfPostIts() const
A still empty section.
Definition: ndarr.hxx:152
void Copy_(const SwNodeRange &rRg, const SwNodeIndex &rInsPos, bool bNewFrames=true) const
Definition: ndarr.hxx:176
SwNode * SwNodePtr
Definition: ndarr.hxx:67
sal_uInt16 sal_Unicode
sal_uLong Count() const
Definition: bparr.hxx:87
std::vector< NodeRanges_t > TableRanges_t
Definition: ndarr.hxx:138
bool operator()(SwNode *const &lhs, SwNode *const &rhs) const
Definition: ndnum.cxx:27
std::unique_ptr< SwNode > m_pEndOfContent
Definition: ndarr.hxx:108
std::unique_ptr< SwOutlineNodes > m_pOutlineNodes
Array of all outline nodes.
Definition: ndarr.hxx:110
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:163
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
struct _xmlTextWriter * xmlTextWriterPtr
SwDoc * m_pMyDoc
This Doc contains the nodes-array.
Definition: ndarr.hxx:104
bool GoNext(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:283
static constexpr auto npos
Definition: ndarr.hxx:79
void ForEach(FnForEach_SwNodes fnForEach, void *pArgs=nullptr)
Definition: ndarr.hxx:143
std::vector< std::unique_ptr< SwTableToTextSave >> SwTableToTextSaves
Definition: ndarr.hxx:85
friend class SwNodes
Definition: node.hxx:306
Marks a node in the document model.
Definition: ndindex.hxx:31
const SwOutlineNodes & GetOutLineNds() const
Array of all OutlineNodes.
Definition: ndarr.hxx:231
SwNodeIndex * m_vIndices
ring of all indices on nodes.
Definition: ndarr.hxx:96
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
const SwDoc * GetDoc() const
Definition: ndarr.hxx:303
SwDoc * GetDoc()
Which Doc contains the nodes-array?
Definition: ndarr.hxx:302
BigPtrEntry * operator[](sal_uLong) const
Definition: bparr.cxx:82
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
SwStartNode & operator=(const SwStartNode &rNode)=delete
SwStartNodeType
Definition: ndtyp.hxx:50
bool Seek_Entry(SwNode *rP, size_type *pnPos) const
Definition: ndnum.cxx:32
sal_uInt16 GetSectionLevel() const
Returns the section level at the position given by aIndex.
Definition: node.cxx:267
SwNode & GetEndOfRedlines() const
Section for all Redlines.
Definition: ndarr.hxx:158
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Dumps the node structure to the given destination (file nodes.xml in the current directory by default...
Definition: node.cxx:940
struct _xmlTextWriter * xmlTextWriterPtr
Definition: ndarr.hxx:69
std::vector< SwNode * >::size_type size_type
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
Definition: ndarr.hxx:161
bool GoPrevious(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:290
SwNode * m_pEndOfRedlines
Definition: ndarr.hxx:106
Base class of the Writer document model elements.
Definition: node.hxx:79