Bump version to 21.06.18.1
[LibreOffice.git] / sw / inc / ndarr.hxx
blob7e095c8fb0a6b17cd0ec08274c6790668e3d44ec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_NDARR_HXX
21 #define INCLUDED_SW_INC_NDARR_HXX
23 #include <sal/config.h>
25 #include <limits>
26 #include <vector>
27 #include <memory>
29 #include "bparr.hxx"
30 #include "ndtyp.hxx"
31 #include <rtl/ustring.hxx>
32 #include <o3tl/sorted_vector.hxx>
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;
63 namespace sw { class DocumentContentOperationsManager; }
64 namespace svt { class EmbeddedObjectRef; }
67 typedef SwNode * SwNodePtr;
68 typedef bool (*FnForEach_SwNodes)( const SwNodePtr&, void* pArgs );
69 typedef struct _xmlTextWriter *xmlTextWriterPtr;
71 struct CompareSwOutlineNodes
73 bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
76 class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
78 public:
79 static constexpr auto npos = std::numeric_limits<size_type>::max();
81 bool Seek_Entry(SwNode* rP, size_type* pnPos) const;
84 struct SwTableToTextSave;
85 using SwTableToTextSaves = std::vector<std::unique_ptr<SwTableToTextSave>>;
87 class SW_DLLPUBLIC SwNodes final
88 : private BigPtrArray
90 friend class SwDoc;
91 friend class SwNode;
92 friend class SwNodeIndex;
93 friend class SwStartNode;
94 friend class ::sw::DocumentContentOperationsManager;
96 SwNodeIndex* m_vIndices; ///< ring of all indices on nodes.
97 void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, bool bDel );
99 void InsertNode( const SwNodePtr pNode,
100 const SwNodeIndex& rPos );
101 void InsertNode( const SwNodePtr pNode,
102 sal_uLong nPos );
104 SwDoc& m_rMyDoc; ///< This Doc contains the nodes-array.
106 SwNode *m_pEndOfPostIts, *m_pEndOfInserts, ///< These are the fixed ranges.
107 *m_pEndOfAutotext, *m_pEndOfRedlines;
108 std::unique_ptr<SwNode> m_pEndOfContent;
110 mutable std::unique_ptr<SwOutlineNodes> m_pOutlineNodes; ///< Array of all outline nodes.
112 bool m_bInNodesDel : 1; /**< In Case of recursive calling.
113 Do not update Num/Outline. */
114 bool m_bInDelUpdOutline : 1; ///< Flag for updating of Outline.
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 );
120 void ChgNode( SwNodeIndex const & rDelPos, sal_uLong nSize,
121 SwNodeIndex& rInsPos, bool bNewFrames );
123 void UpdateOutlineIdx( const SwNode& ); ///< Update all OutlineNodes starting from Node.
125 void CopyNodes( const SwNodeRange&, const SwNodeIndex&,
126 bool bNewFrames, bool bTableInsDummyNode = false ) const;
127 void DelDummyNodes( const SwNodeRange& rRg );
129 SwNodes(SwNodes const&) = delete;
130 SwNodes& operator=(SwNodes const&) = delete;
132 SwNodes(SwDoc& rDoc);
134 public:
135 ~SwNodes();
137 typedef std::vector<SwNodeRange> NodeRanges_t;
138 typedef std::vector<NodeRanges_t> TableRanges_t;
140 SwNodePtr operator[]( sal_uLong n ) const; // defined in node.hxx
142 sal_uLong Count() const { return BigPtrArray::Count(); }
143 void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = nullptr )
145 ForEach( 0, BigPtrArray::Count(), fnForEach, pArgs );
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 );
151 /// A still empty section.
152 SwNode& GetEndOfPostIts() const { return *m_pEndOfPostIts; }
153 /// Section for all footnotes.
154 SwNode& GetEndOfInserts() const { return *m_pEndOfInserts; }
155 /// Section for all Flys/Header/Footers.
156 SwNode& GetEndOfAutotext() const { return *m_pEndOfAutotext; }
157 /// Section for all Redlines.
158 SwNode& GetEndOfRedlines() const { return *m_pEndOfRedlines; }
159 /** This is the last EndNode of a special section. After it
160 there is only the regular ContentSection (i.e. the BodyText). */
161 SwNode& GetEndOfExtras() const { return *m_pEndOfRedlines; }
162 /// Regular ContentSection (i.e. the BodyText).
163 SwNode& GetEndOfContent() const { return *m_pEndOfContent; }
165 /** Is the NodesArray the regular one of Doc? (and not the UndoNds, ...)
166 Implementation in doc.hxx (because one needs to know Doc for it) ! */
167 bool IsDocNodes() const;
169 static sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex);
170 void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
172 bool MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
173 bool bNewFrames = true );
174 void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
176 void Copy_( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
177 bool bNewFrames = true ) const
178 { CopyNodes( rRg, rInsPos, bNewFrames ); }
180 void SectionUp( SwNodeRange *);
181 void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
183 static void GoStartOfSection(SwNodeIndex *);
184 static void GoEndOfSection(SwNodeIndex *);
186 SwContentNode* GoNext(SwNodeIndex *) const;
187 static SwContentNode* GoPrevious(SwNodeIndex *);
189 /** Go to next content-node that is not protected or hidden
190 (Both set FALSE ==> GoNext/GoPrevious!!!). */
191 SwContentNode* GoNextSection( SwNodeIndex *, bool bSkipHidden = true,
192 bool bSkipProtect = true ) const;
193 static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden = true,
194 bool bSkipProtect = true );
196 /** Create an empty section of Start- and EndNote. It may be called
197 only if a new section with content is to be created,
198 e.g. at filters/Undo/... */
199 static SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
200 SwStartNodeType = SwNormalStartNode );
202 /// Implementations of "Make...Node" are in the given .cxx-files.
203 SwTextNode *MakeTextNode( const SwNodeIndex & rWhere,
204 SwTextFormatColl *pColl,
205 bool bNewFrames = true); ///< in ndtxt.cxx
206 SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
207 SwStartNodeType eSttNdTyp,
208 SwTextFormatColl *pColl );
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 ); ///< in ndgrf.cxx
217 static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
218 const GraphicObject& rGrfObj,
219 SwGrfFormatColl *pColl ); ///< in ndgrf.cxx
221 SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
222 const svt::EmbeddedObjectRef&,
223 SwGrfFormatColl *pColl ); ///< in ndole.cxx
224 SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
225 const OUString &rName,
226 sal_Int64 nAspect,
227 SwGrfFormatColl *pColl,
228 SwAttrSet const * pAutoAttr ); ///< in ndole.cxx
230 /// Array of all OutlineNodes.
231 const SwOutlineNodes& GetOutLineNds() const { return *m_pOutlineNodes;}
233 /// Update all Nodes - Rule/Format-Change.
234 void UpdateOutlineNode(SwNode & rNd);
236 /** Insert nodes for tables. If Lines is given, create the matrix
237 from lines and boxes, else only the count of boxes.
239 New parameter pAttrSet: If pAttrSet is non-null and contains an
240 adjust item it is propagated to the table cells. If there is an
241 adjust in pContentTextColl or pHeadlineTextColl this adjust item
242 overrides the item in pAttrSet. */
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);
250 /// Create balanced table from selected range.
251 SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
252 SwTableFormat* pTableFormat,
253 SwTableLineFormat* pLineFormat,
254 SwTableBoxFormat* pBoxFormat,
255 SwTextFormatColl* pTextColl,
256 SwUndoTextToTable* pUndo );
258 std::unique_ptr<SwNodeRange> ExpandRangeForTableBox(const SwNodeRange & rRange);
260 /// create a table from a vector of NodeRanges - API support
261 SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
262 SwTableFormat* pTableFormat,
263 SwTableLineFormat* pLineFormat,
264 SwTableBoxFormat* pBoxFormat );
266 /// Create regular text from what was table.
267 bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
268 SwUndoTableToText* );
269 /// Is in untbl.cxx and may called only by Undo-object.
270 SwTableNode* UndoTableToText( sal_uLong nStt, sal_uLong nEnd,
271 const SwTableToTextSaves& rSavedData );
273 /** Insert a new box in the line before InsPos. Its format
274 is taken from the following one (or from the previous one if we are
275 at the end). In the line there must be a box already. */
276 bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFormat*,
277 /// Formats for TextNode of box.
278 SwTextFormatColl*, const SfxItemSet* pAutoAttr,
279 sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
280 /** Splits a table at the base-line which contains the index.
281 All base lines behind it are moved to a new table/ -node.
282 Is the flag bCalcNewSize set to TRUE, the new SSize for both
283 tables is calculated from the Maximum of the boxes, provided
284 SSize is set "absolute" (LONG_MAX).
285 (Momentarily this is needed only for the RTF-parser.) */
286 SwTableNode* SplitTable( const SwNodeIndex& rPos, bool bAfter = true,
287 bool bCalcNewSize = false );
288 /// Two Tables that are following one another are merged.
289 bool MergeTable( const SwNodeIndex& rPos, bool bWithPrev = true,
290 sal_uInt16 nMode = 0 );
292 /// Insert a new SwSection.
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);
301 /// Which Doc contains the nodes-array?
302 SwDoc& GetDoc() { return m_rMyDoc; }
303 const SwDoc& GetDoc() const { return m_rMyDoc; }
305 /** Search previous / next content node or table node with frames.
306 If no end is given begin with the FrameIndex, else start search
307 with that before rFrameIdx and pEnd at the back.
308 If no valid node is found, return 0. rFrameIdx points to the node with frames. **/
309 SwNode* FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
310 const SwNode* pEnd ) const;
312 SwNode * DocumentSectionStartNode(SwNode * pNode) const;
313 SwNode * DocumentSectionEndNode(SwNode * pNode) const;
316 * Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by default)
318 void dumpAsXml( xmlTextWriterPtr pWriter ) const;
322 #endif
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */