Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / inc / ndarr.hxx
blobb7fd0bb2e0781a579e8df2188e78d692504ef90a
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>
28 #include <optional>
30 #include "bparr.hxx"
31 #include "ndtyp.hxx"
32 #include <rtl/ustring.hxx>
33 #include <o3tl/sorted_vector.hxx>
34 #include "nodeoffset.hxx"
36 class Graphic;
37 class GraphicObject;
38 class SwAttrSet;
39 class SfxItemSet;
40 class SwContentNode;
41 class SwDoc;
42 class SwGrfFormatColl;
43 class SwGrfNode;
44 class SwNode;
45 class SwNodeIndex;
46 class SwNodeRange;
47 class SwOLENode;
48 class SwPaM;
49 class SwRootFrame;
50 class SwSectionData;
51 class SwSectionFormat;
52 class SwTOXBase;
53 class SwSectionNode;
54 class SwStartNode;
55 class SwTableBoxFormat;
56 class SwTableFormat;
57 class SwTableLine;
58 class SwTableLineFormat;
59 class SwTableNode;
60 class SwTextFormatColl;
61 class SwTextNode;
62 class SwUndoTableToText;
63 class SwUndoTextToTable;
64 struct SwPosition;
66 namespace sw { class DocumentContentOperationsManager; }
67 namespace svt { class EmbeddedObjectRef; }
70 typedef bool (*FnForEach_SwNodes)( SwNode*, void* pArgs );
71 typedef struct _xmlTextWriter *xmlTextWriterPtr;
73 struct CompareSwOutlineNodes
75 bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
78 class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
80 public:
81 static constexpr auto npos = std::numeric_limits<size_type>::max();
83 bool Seek_Entry(SwNode* rP, size_type* pnPos) const;
86 struct SwTableToTextSave;
87 using SwTableToTextSaves = std::vector<std::unique_ptr<SwTableToTextSave>>;
89 class SW_DLLPUBLIC SwNodes final
90 : private BigPtrArray
92 friend class SwDoc;
93 friend class SwNode;
94 friend class SwNodeIndex;
95 friend class SwStartNode;
96 friend class ::sw::DocumentContentOperationsManager;
98 SwNodeIndex* m_vIndices; ///< ring of all indices on nodes.
99 void RemoveNode( SwNodeOffset nDelPos, SwNodeOffset nLen, bool bDel );
101 void InsertNode( SwNode* pNode, const SwNodeIndex& rPos );
102 void InsertNode( SwNode* pNode, SwNodeOffset 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 SwOutlineNodes m_aOutlineNodes; ///< 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, SwNodeOffset nCnt = SwNodeOffset(1) );
120 void ChgNode( SwNodeIndex const & rDelPos, SwNodeOffset nSize,
121 SwNodeIndex& rInsPos, bool bNewFrames );
123 void UpdateOutlineIdx( const SwNode& ); ///< Update all OutlineNodes starting from Node.
125 void CopyNodes( const SwNodeRange&, SwNode& rPos,
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 SwNode* operator[]( SwNodeOffset n ) const; // defined in node.hxx
142 SwNodeOffset Count() const { return SwNodeOffset(BigPtrArray::Count()); }
143 void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = nullptr )
145 ForEach( SwNodeOffset(0), Count(), fnForEach, pArgs );
147 void ForEach( SwNodeOffset nStt, SwNodeOffset nEnd, FnForEach_SwNodes fnForEach, void* pArgs );
148 void ForEach( SwNode& rStart, SwNode& rEnd,
149 FnForEach_SwNodes fnForEach, void* pArgs );
150 void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
151 FnForEach_SwNodes fnForEach, void* pArgs );
153 /// A still empty section.
154 SwNode& GetEndOfPostIts() const { return *m_pEndOfPostIts; }
155 /// Section for all footnotes.
156 SwNode& GetEndOfInserts() const { return *m_pEndOfInserts; }
157 /// Section for all Flys/Header/Footers.
158 SwNode& GetEndOfAutotext() const { return *m_pEndOfAutotext; }
159 /// Section for all Redlines.
160 SwNode& GetEndOfRedlines() const { return *m_pEndOfRedlines; }
161 /** This is the last EndNode of a special section. After it
162 there is only the regular ContentSection (i.e. the BodyText). */
163 SwNode& GetEndOfExtras() const { return *m_pEndOfRedlines; }
164 /// Regular ContentSection (i.e. the BodyText).
165 SwNode& GetEndOfContent() const { return *m_pEndOfContent; }
167 /** Is the NodesArray the regular one of Doc? (and not the UndoNds, ...)
168 Implementation in doc.hxx (because one needs to know Doc for it) ! */
169 bool IsDocNodes() const;
171 static sal_uInt16 GetSectionLevel(const SwNode &rIndex);
172 void Delete(const SwNodeIndex &rPos, SwNodeOffset nNodes = SwNodeOffset(1));
173 void Delete(const SwNode& rPos, SwNodeOffset nNodes = SwNodeOffset(1));
175 bool MoveNodes( const SwNodeRange&, SwNodes& rNodes, SwNode& rPos,
176 bool bNewFrames = true );
177 void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
179 void Copy_( const SwNodeRange& rRg, SwNode& rInsPos,
180 bool bNewFrames = true ) const
181 { CopyNodes( rRg, rInsPos, bNewFrames ); }
183 void SectionUp( SwNodeRange *);
184 void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
186 static void GoStartOfSection(SwNodeIndex *);
187 static void GoEndOfSection(SwNodeIndex *);
189 SwContentNode* GoNext(SwNodeIndex *) const;
190 SwContentNode* GoNext(SwPosition *) const;
191 static SwContentNode* GoPrevious(SwNodeIndex *);
192 static SwContentNode* GoPrevious(SwPosition *);
194 /** Go to next content-node that is not protected or hidden
195 (Both set FALSE ==> GoNext/GoPrevious!!!). */
196 SwContentNode* GoNextSection( SwNodeIndex *, bool bSkipHidden = true,
197 bool bSkipProtect = true ) const;
198 SwContentNode* GoNextSection( SwPosition *, bool bSkipHidden = true,
199 bool bSkipProtect = true ) const;
200 static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden = true,
201 bool bSkipProtect = true );
202 static SwContentNode* GoPrevSection( SwPosition *, bool bSkipHidden = true,
203 bool bSkipProtect = true );
205 /** Create an empty section of Start- and EndNote. It may be called
206 only if a new section with content is to be created,
207 e.g. at filters/Undo/... */
208 static SwStartNode* MakeEmptySection( SwNode& rWhere,
209 SwStartNodeType = SwNormalStartNode );
211 /// Implementations of "Make...Node" are in the given .cxx-files.
212 SwTextNode *MakeTextNode( SwNode& rWhere,
213 SwTextFormatColl *pColl,
214 bool bNewFrames = true); ///< in ndtxt.cxx
215 SwStartNode* MakeTextSection( const SwNode & rWhere,
216 SwStartNodeType eSttNdTyp,
217 SwTextFormatColl *pColl );
219 static SwGrfNode *MakeGrfNode( SwNode& rWhere,
220 const OUString& rGrfName,
221 const OUString& rFltName,
222 const Graphic* pGraphic,
223 SwGrfFormatColl *pColl,
224 SwAttrSet const * pAutoAttr = nullptr ); ///< in ndgrf.cxx
226 static SwGrfNode *MakeGrfNode( SwNode & rWhere,
227 const GraphicObject& rGrfObj,
228 SwGrfFormatColl *pColl ); ///< in ndgrf.cxx
230 SwOLENode *MakeOLENode( SwNode& rWhere,
231 const svt::EmbeddedObjectRef&,
232 SwGrfFormatColl *pColl ); ///< in ndole.cxx
233 SwOLENode *MakeOLENode( SwNode& rWhere,
234 const OUString &rName,
235 sal_Int64 nAspect,
236 SwGrfFormatColl *pColl,
237 SwAttrSet const * pAutoAttr ); ///< in ndole.cxx
239 /// Array of all OutlineNodes.
240 const SwOutlineNodes& GetOutLineNds() const { return m_aOutlineNodes;}
242 /// Update all Nodes - Rule/Format-Change.
243 void UpdateOutlineNode(SwNode & rNd);
245 /** Insert nodes for tables. If Lines is given, create the matrix
246 from lines and boxes, else only the count of boxes.
248 New parameter pAttrSet: If pAttrSet is non-null and contains an
249 adjust item it is propagated to the table cells. If there is an
250 adjust in pContentTextColl or pHeadlineTextColl this adjust item
251 overrides the item in pAttrSet. */
253 static SwTableNode* InsertTable( SwNode& rNd,
254 sal_uInt16 nBoxes, SwTextFormatColl* pContentTextColl,
255 sal_uInt16 nLines, sal_uInt16 nRepeat,
256 SwTextFormatColl* pHeadlineTextColl,
257 const SwAttrSet * pAttrSet);
259 /// Create balanced table from selected range.
260 SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
261 SwTableFormat* pTableFormat,
262 SwTableLineFormat* pLineFormat,
263 SwTableBoxFormat* pBoxFormat,
264 SwTextFormatColl* pTextColl,
265 SwUndoTextToTable* pUndo );
267 void ExpandRangeForTableBox(const SwNodeRange & rRange,
268 std::optional<SwNodeRange>& rExpandedRange);
270 /// create a table from a vector of NodeRanges - API support
271 SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
272 SwTableFormat* pTableFormat,
273 SwTableLineFormat* pLineFormat,
274 SwTableBoxFormat* pBoxFormat );
276 /// Create regular text from what was table.
277 bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
278 SwUndoTableToText* );
279 /// Is in untbl.cxx and may called only by Undo-object.
280 SwTableNode* UndoTableToText( SwNodeOffset nStt, SwNodeOffset nEnd,
281 const SwTableToTextSaves& rSavedData );
283 /** Insert a new box in the line before InsPos. Its format
284 is taken from the following one (or from the previous one if we are
285 at the end). In the line there must be a box already. */
286 bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFormat*,
287 /// Formats for TextNode of box.
288 SwTextFormatColl*, const SfxItemSet* pAutoAttr,
289 sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
290 /** Splits a table at the base-line which contains the index.
291 All base lines behind it are moved to a new table/ -node.
292 Is the flag bCalcNewSize set to TRUE, the new SSize for both
293 tables is calculated from the Maximum of the boxes, provided
294 SSize is set "absolute" (LONG_MAX).
295 (Momentarily this is needed only for the RTF-parser.) */
296 SwTableNode* SplitTable( SwNode& rPos, bool bAfter = true,
297 bool bCalcNewSize = false );
298 /// Two Tables that are following one another are merged.
299 bool MergeTable( SwNode& rPos, bool bWithPrev = true );
301 /// Insert a new SwSection.
302 SwSectionNode* InsertTextSection(SwNode& rNd,
303 SwSectionFormat& rSectionFormat,
304 SwSectionData const&,
305 SwTOXBase const*const pTOXBase,
306 SwNode const * pEndNd,
307 bool const bInsAtStart = true,
308 bool const bCreateFrames = true);
310 /// Which Doc contains the nodes-array?
311 SwDoc& GetDoc() { return m_rMyDoc; }
312 const SwDoc& GetDoc() const { return m_rMyDoc; }
314 /** Search previous / next content node or table node with frames.
315 Search is started backward with the one before rFrameNd and
316 forward after pEnd.
317 If no valid node is found, return nullptr. **/
318 SwNode* FindPrvNxtFrameNode( const SwNode& rFrameNd,
319 const SwNode* pEnd,
320 SwRootFrame const* pLayout = nullptr) const;
322 SwNode * DocumentSectionStartNode(SwNode * pNode) const;
323 SwNode * DocumentSectionEndNode(SwNode * pNode) const;
326 * Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by default)
328 void dumpAsXml( xmlTextWriterPtr pWriter ) const;
332 #endif
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */