Cleanup restoring last position
[LibreOffice.git] / sw / inc / ndarr.hxx
blob87c78c5172b1607a42d37d9a3170ff4f8b1cb908
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>
33 #include "nodeoffset.hxx"
35 class Graphic;
36 class GraphicObject;
37 class SwAttrSet;
38 class SfxItemSet;
39 class SwContentNode;
40 class SwDoc;
41 class SwGrfFormatColl;
42 class SwGrfNode;
43 class SwNode;
44 class SwNodeIndex;
45 class SwNodeRange;
46 class SwOLENode;
47 class SwPaM;
48 class SwRootFrame;
49 class SwSectionData;
50 class SwSectionFormat;
51 class SwTOXBase;
52 class SwSectionNode;
53 class SwStartNode;
54 class SwTableBoxFormat;
55 class SwTableFormat;
56 class SwTableLine;
57 class SwTableLineFormat;
58 class SwTableNode;
59 class SwTextFormatColl;
60 class SwTextNode;
61 class SwUndoTableToText;
62 class SwUndoTextToTable;
63 struct SwPosition;
65 namespace sw { class DocumentContentOperationsManager; }
66 namespace svt { class EmbeddedObjectRef; }
69 typedef bool (*FnForEach_SwNodes)( SwNode*, void* pArgs );
70 typedef struct _xmlTextWriter *xmlTextWriterPtr;
72 struct CompareSwOutlineNodes
74 bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
77 class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
79 public:
80 static constexpr auto npos = std::numeric_limits<size_type>::max();
82 bool Seek_Entry(SwNode* rP, size_type* pnPos) const;
85 struct SwTableToTextSave;
86 using SwTableToTextSaves = std::vector<std::unique_ptr<SwTableToTextSave>>;
88 class SW_DLLPUBLIC SwNodes final
89 : private BigPtrArray
91 friend class SwDoc;
92 friend class SwNode;
93 friend class SwNodeIndex;
94 friend class SwStartNode;
95 friend class ::sw::DocumentContentOperationsManager;
97 SwNodeIndex* m_vIndices; ///< ring of all indices on nodes.
98 void RemoveNode( SwNodeOffset nDelPos, SwNodeOffset nLen, bool bDel );
100 void InsertNode( SwNode* pNode, const SwNodeIndex& rPos );
101 void InsertNode( SwNode* pNode, SwNodeOffset nPos );
103 SwDoc& m_rMyDoc; ///< This Doc contains the nodes-array.
105 SwNode *m_pEndOfPostIts, *m_pEndOfInserts, ///< These are the fixed ranges.
106 *m_pEndOfAutotext, *m_pEndOfRedlines;
107 std::unique_ptr<SwNode> m_pEndOfContent;
109 mutable std::unique_ptr<SwOutlineNodes> m_pOutlineNodes; ///< Array of all outline nodes.
111 bool m_bInNodesDel : 1; /**< In Case of recursive calling.
112 Do not update Num/Outline. */
113 bool m_bInDelUpdOutline : 1; ///< Flag for updating of Outline.
115 // Actions on the nodes.
116 static void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
117 void DelNodes( const SwNodeIndex& rStart, SwNodeOffset nCnt = SwNodeOffset(1) );
119 void ChgNode( SwNodeIndex const & rDelPos, SwNodeOffset nSize,
120 SwNodeIndex& rInsPos, bool bNewFrames );
122 void UpdateOutlineIdx( const SwNode& ); ///< Update all OutlineNodes starting from Node.
124 void CopyNodes( const SwNodeRange&, const SwNodeIndex&,
125 bool bNewFrames, bool bTableInsDummyNode = false ) const;
126 void DelDummyNodes( const SwNodeRange& rRg );
128 SwNodes(SwNodes const&) = delete;
129 SwNodes& operator=(SwNodes const&) = delete;
131 SwNodes(SwDoc& rDoc);
133 public:
134 ~SwNodes();
136 typedef std::vector<SwNodeRange> NodeRanges_t;
137 typedef std::vector<NodeRanges_t> TableRanges_t;
139 SwNode* operator[]( SwNodeOffset n ) const; // defined in node.hxx
141 SwNodeOffset Count() const { return SwNodeOffset(BigPtrArray::Count()); }
142 void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = nullptr )
144 ForEach( SwNodeOffset(0), Count(), fnForEach, pArgs );
146 void ForEach( SwNodeOffset nStt, SwNodeOffset nEnd, FnForEach_SwNodes fnForEach, void* pArgs );
147 void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
148 FnForEach_SwNodes fnForEach, void* pArgs );
150 /// A still empty section.
151 SwNode& GetEndOfPostIts() const { return *m_pEndOfPostIts; }
152 /// Section for all footnotes.
153 SwNode& GetEndOfInserts() const { return *m_pEndOfInserts; }
154 /// Section for all Flys/Header/Footers.
155 SwNode& GetEndOfAutotext() const { return *m_pEndOfAutotext; }
156 /// Section for all Redlines.
157 SwNode& GetEndOfRedlines() const { return *m_pEndOfRedlines; }
158 /** This is the last EndNode of a special section. After it
159 there is only the regular ContentSection (i.e. the BodyText). */
160 SwNode& GetEndOfExtras() const { return *m_pEndOfRedlines; }
161 /// Regular ContentSection (i.e. the BodyText).
162 SwNode& GetEndOfContent() const { return *m_pEndOfContent; }
164 /** Is the NodesArray the regular one of Doc? (and not the UndoNds, ...)
165 Implementation in doc.hxx (because one needs to know Doc for it) ! */
166 bool IsDocNodes() const;
168 static sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex);
169 void Delete(const SwNodeIndex &rPos, SwNodeOffset nNodes = SwNodeOffset(1));
171 bool MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
172 bool bNewFrames = true );
173 void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
175 void Copy_( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
176 bool bNewFrames = true ) const
177 { CopyNodes( rRg, rInsPos, bNewFrames ); }
179 void SectionUp( SwNodeRange *);
180 void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
182 static void GoStartOfSection(SwNodeIndex *);
183 static void GoEndOfSection(SwNodeIndex *);
185 SwContentNode* GoNext(SwNodeIndex *) const;
186 static SwContentNode* GoPrevious(SwNodeIndex *);
188 /** Go to next content-node that is not protected or hidden
189 (Both set FALSE ==> GoNext/GoPrevious!!!). */
190 SwContentNode* GoNextSection( SwNodeIndex *, bool bSkipHidden = true,
191 bool bSkipProtect = true ) const;
192 static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden = true,
193 bool bSkipProtect = true );
195 /** Create an empty section of Start- and EndNote. It may be called
196 only if a new section with content is to be created,
197 e.g. at filters/Undo/... */
198 static SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
199 SwStartNodeType = SwNormalStartNode );
201 /// Implementations of "Make...Node" are in the given .cxx-files.
202 SwTextNode *MakeTextNode( const SwNodeIndex & rWhere,
203 SwTextFormatColl *pColl,
204 bool bNewFrames = true); ///< in ndtxt.cxx
205 SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
206 SwStartNodeType eSttNdTyp,
207 SwTextFormatColl *pColl );
209 static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
210 const OUString& rGrfName,
211 const OUString& rFltName,
212 const Graphic* pGraphic,
213 SwGrfFormatColl *pColl,
214 SwAttrSet const * pAutoAttr = nullptr ); ///< in ndgrf.cxx
216 static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
217 const GraphicObject& rGrfObj,
218 SwGrfFormatColl *pColl ); ///< in ndgrf.cxx
220 SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
221 const svt::EmbeddedObjectRef&,
222 SwGrfFormatColl *pColl ); ///< in ndole.cxx
223 SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
224 const OUString &rName,
225 sal_Int64 nAspect,
226 SwGrfFormatColl *pColl,
227 SwAttrSet const * pAutoAttr ); ///< in ndole.cxx
229 /// Array of all OutlineNodes.
230 const SwOutlineNodes& GetOutLineNds() const { return *m_pOutlineNodes;}
232 /// Update all Nodes - Rule/Format-Change.
233 void UpdateOutlineNode(SwNode & rNd);
235 /** Insert nodes for tables. If Lines is given, create the matrix
236 from lines and boxes, else only the count of boxes.
238 New parameter pAttrSet: If pAttrSet is non-null and contains an
239 adjust item it is propagated to the table cells. If there is an
240 adjust in pContentTextColl or pHeadlineTextColl this adjust item
241 overrides the item in pAttrSet. */
243 static SwTableNode* InsertTable( const SwNodeIndex& rNdIdx,
244 sal_uInt16 nBoxes, SwTextFormatColl* pContentTextColl,
245 sal_uInt16 nLines, sal_uInt16 nRepeat,
246 SwTextFormatColl* pHeadlineTextColl,
247 const SwAttrSet * pAttrSet);
249 /// Create balanced table from selected range.
250 SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
251 SwTableFormat* pTableFormat,
252 SwTableLineFormat* pLineFormat,
253 SwTableBoxFormat* pBoxFormat,
254 SwTextFormatColl* pTextColl,
255 SwUndoTextToTable* pUndo );
257 std::unique_ptr<SwNodeRange> ExpandRangeForTableBox(const SwNodeRange & rRange);
259 /// create a table from a vector of NodeRanges - API support
260 SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
261 SwTableFormat* pTableFormat,
262 SwTableLineFormat* pLineFormat,
263 SwTableBoxFormat* pBoxFormat );
265 /// Create regular text from what was table.
266 bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
267 SwUndoTableToText* );
268 /// Is in untbl.cxx and may called only by Undo-object.
269 SwTableNode* UndoTableToText( SwNodeOffset nStt, SwNodeOffset nEnd,
270 const SwTableToTextSaves& rSavedData );
272 /** Insert a new box in the line before InsPos. Its format
273 is taken from the following one (or from the previous one if we are
274 at the end). In the line there must be a box already. */
275 bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFormat*,
276 /// Formats for TextNode of box.
277 SwTextFormatColl*, const SfxItemSet* pAutoAttr,
278 sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
279 /** Splits a table at the base-line which contains the index.
280 All base lines behind it are moved to a new table/ -node.
281 Is the flag bCalcNewSize set to TRUE, the new SSize for both
282 tables is calculated from the Maximum of the boxes, provided
283 SSize is set "absolute" (LONG_MAX).
284 (Momentarily this is needed only for the RTF-parser.) */
285 SwTableNode* SplitTable( const SwNodeIndex& rPos, bool bAfter = true,
286 bool bCalcNewSize = false );
287 /// Two Tables that are following one another are merged.
288 bool MergeTable( const SwNodeIndex& rPos, bool bWithPrev = true,
289 sal_uInt16 nMode = 0 );
291 /// Insert a new SwSection.
292 SwSectionNode* InsertTextSection(SwNodeIndex const& rNdIdx,
293 SwSectionFormat& rSectionFormat,
294 SwSectionData const&,
295 SwTOXBase const*const pTOXBase,
296 SwNodeIndex const*const pEnd,
297 bool const bInsAtStart = true,
298 bool const bCreateFrames = true);
300 /// Which Doc contains the nodes-array?
301 SwDoc& GetDoc() { return m_rMyDoc; }
302 const SwDoc& GetDoc() const { return m_rMyDoc; }
304 /** Search previous / next content node or table node with frames.
305 Search is started backward with the one before rFrameIdx and
306 forward after pEnd.
307 If no valid node is found, return 0. rFrameIdx points to the node with frames. **/
308 SwNode* FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
309 const SwNode* pEnd,
310 SwRootFrame const* pLayout = nullptr) 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: */