1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
32 #include <rtl/ustring.hxx>
33 #include <o3tl/sorted_vector.hxx>
34 #include "nodeoffset.hxx"
42 class SwGrfFormatColl
;
51 class SwSectionFormat
;
55 class SwTableBoxFormat
;
58 class SwTableLineFormat
;
60 class SwTextFormatColl
;
62 class SwUndoTableToText
;
63 class SwUndoTextToTable
;
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()(const SwNode
* lhs
, const SwNode
* rhs
) const;
78 class SwOutlineNodes
: public o3tl::sorted_vector
<SwNode
*, CompareSwOutlineNodes
>
81 static constexpr auto npos
= std::numeric_limits
<size_type
>::max();
83 bool Seek_Entry(const SwNode
* rP
, size_type
* pnPos
) const;
84 static const SwNode
* GetRootNode(const SwNode
* pNode
, bool bCheckInlineHeading
= true);
87 struct CompareSwOutlineNodesInline
89 bool operator()(const SwNode
* lhs
, const SwNode
* rhs
) const;
92 class SwOutlineNodesInline
: public o3tl::sorted_vector
<SwNode
*, CompareSwOutlineNodesInline
>
95 static constexpr auto npos
= std::numeric_limits
<size_type
>::max();
97 bool Seek_Entry(const SwNode
* rP
, size_type
* pnPos
) const;
98 bool Seek_Entry_By_Anchor(const SwNode
* rAnchor
, size_type
* pnPos
) const;
101 struct SwTableToTextSave
;
102 using SwTableToTextSaves
= std::vector
<std::unique_ptr
<SwTableToTextSave
>>;
105 : private BigPtrArray
109 friend class SwNodeIndex
;
110 friend class SwStartNode
;
111 friend class ::sw::DocumentContentOperationsManager
;
113 void RemoveNode( SwNodeOffset nDelPos
, SwNodeOffset nLen
, bool bDel
);
115 void InsertNode( SwNode
* pNode
, const SwNodeIndex
& rPos
);
116 void InsertNode( SwNode
* pNode
, SwNodeOffset nPos
);
118 SwDoc
& m_rMyDoc
; ///< This Doc contains the nodes-array.
120 SwNode
*m_pEndOfPostIts
, *m_pEndOfInserts
, ///< These are the fixed ranges.
121 *m_pEndOfAutotext
, *m_pEndOfRedlines
;
122 std::unique_ptr
<SwNode
> m_pEndOfContent
;
124 mutable SwOutlineNodes m_aOutlineNodes
; ///< Array of all outline nodes.
126 bool m_bInNodesDel
: 1; /**< In Case of recursive calling.
127 Do not update Num/Outline. */
128 bool m_bInDelUpdOutline
: 1; ///< Flag for updating of Outline.
130 // Actions on the nodes.
131 static void SectionUpDown( const SwNodeIndex
& aStart
, const SwNodeIndex
& aEnd
);
132 void DelNodes( const SwNodeIndex
& rStart
, SwNodeOffset nCnt
= SwNodeOffset(1) );
134 void ChgNode( SwNodeIndex
const & rDelPos
, SwNodeOffset nSize
,
135 SwNodeIndex
& rInsPos
, bool bNewFrames
);
137 void UpdateOutlineIdx( const SwNode
& ); ///< Update all OutlineNodes starting from Node.
139 void CopyNodes( const SwNodeRange
&, SwNode
& rPos
,
140 bool bNewFrames
, bool bTableInsDummyNode
= false ) const;
141 void DelDummyNodes( const SwNodeRange
& rRg
);
143 SwNodes(SwNodes
const&) = delete;
144 SwNodes
& operator=(SwNodes
const&) = delete;
146 SwNodes(SwDoc
& rDoc
);
151 typedef std::vector
<SwNodeRange
> NodeRanges_t
;
152 typedef std::vector
<NodeRanges_t
> TableRanges_t
;
154 SwNode
* operator[]( SwNodeOffset n
) const; // defined in node.hxx
156 SwNodeOffset
Count() const { return SwNodeOffset(BigPtrArray::Count()); }
157 void ForEach( FnForEach_SwNodes fnForEach
, void* pArgs
= nullptr )
159 ForEach( SwNodeOffset(0), Count(), fnForEach
, pArgs
);
161 void ForEach( SwNodeOffset nStt
, SwNodeOffset nEnd
, FnForEach_SwNodes fnForEach
, void* pArgs
);
162 void ForEach( SwNode
& rStart
, SwNode
& rEnd
,
163 FnForEach_SwNodes fnForEach
, void* pArgs
);
164 void ForEach( const SwNodeIndex
& rStart
, const SwNodeIndex
& rEnd
,
165 FnForEach_SwNodes fnForEach
, void* pArgs
);
167 /// A still empty section.
168 SwNode
& GetEndOfPostIts() const { return *m_pEndOfPostIts
; }
169 /// Section for all footnotes.
170 SwNode
& GetEndOfInserts() const { return *m_pEndOfInserts
; }
171 /// Section for all Flys/Header/Footers.
172 SwNode
& GetEndOfAutotext() const { return *m_pEndOfAutotext
; }
173 /// Section for all Redlines.
174 SwNode
& GetEndOfRedlines() const { return *m_pEndOfRedlines
; }
175 /** This is the last EndNode of a special section. After it
176 there is only the regular ContentSection (i.e. the BodyText). */
177 SwNode
& GetEndOfExtras() const { return *m_pEndOfRedlines
; }
178 /// Regular ContentSection (i.e. the BodyText).
179 SwNode
& GetEndOfContent() const { return *m_pEndOfContent
; }
181 /** Is the NodesArray the regular one of Doc? (and not the UndoNds, ...)
182 Implementation in doc.hxx (because one needs to know Doc for it) ! */
183 SW_DLLPUBLIC
bool IsDocNodes() const;
185 static sal_uInt16
GetSectionLevel(const SwNode
&rIndex
);
186 void Delete(const SwNodeIndex
&rPos
, SwNodeOffset nNodes
= SwNodeOffset(1));
187 void Delete(const SwNode
& rPos
, SwNodeOffset nNodes
= SwNodeOffset(1));
189 bool MoveNodes( const SwNodeRange
&, SwNodes
& rNodes
, SwNode
& rPos
,
190 bool bNewFrames
= true );
191 void MoveRange( SwPaM
&, SwPosition
&, SwNodes
& rNodes
);
193 void Copy_( const SwNodeRange
& rRg
, SwNode
& rInsPos
,
194 bool bNewFrames
= true ) const
195 { CopyNodes( rRg
, rInsPos
, bNewFrames
); }
197 void SectionUp( SwNodeRange
*);
198 void SectionDown( SwNodeRange
*pRange
, SwStartNodeType
= SwNormalStartNode
);
200 static void GoStartOfSection(SwNodeIndex
*);
201 static void GoEndOfSection(SwNodeIndex
*);
203 SW_DLLPUBLIC
static SwContentNode
* GoNext(SwNodeIndex
*);
204 static SwContentNode
* GoNext(SwPosition
*);
205 static SwContentNode
* GoPrevious(SwNodeIndex
*, bool canCrossBoundary
= false);
206 static SwContentNode
* GoPrevious(SwPosition
*, bool canCrossBoundary
= false);
208 /** Go to next content-node that is not protected or hidden
209 (Both set FALSE ==> GoNext/GoPrevious!!!). */
210 static SwContentNode
* GoNextSection( SwNodeIndex
*, bool bSkipHidden
= true,
211 bool bSkipProtect
= true );
212 static SwContentNode
* GoNextSection( SwPosition
*, bool bSkipHidden
= true,
213 bool bSkipProtect
= true );
214 static SwContentNode
* GoPrevSection( SwNodeIndex
*, bool bSkipHidden
= true,
215 bool bSkipProtect
= true );
216 static SwContentNode
* GoPrevSection( SwPosition
*, bool bSkipHidden
= true,
217 bool bSkipProtect
= true );
219 /** Create an empty section of Start- and EndNote. It may be called
220 only if a new section with content is to be created,
221 e.g. at filters/Undo/... */
222 static SwStartNode
* MakeEmptySection( SwNode
& rWhere
,
223 SwStartNodeType
= SwNormalStartNode
);
225 /// Implementations of "Make...Node" are in the given .cxx-files.
226 SW_DLLPUBLIC SwTextNode
*MakeTextNode( SwNode
& rWhere
,
227 SwTextFormatColl
*pColl
,
228 bool bNewFrames
= true); ///< in ndtxt.cxx
229 SW_DLLPUBLIC SwStartNode
* MakeTextSection( const SwNode
& rWhere
,
230 SwStartNodeType eSttNdTyp
,
231 SwTextFormatColl
*pColl
);
233 static SwGrfNode
*MakeGrfNode( SwNode
& rWhere
,
234 const OUString
& rGrfName
,
235 const OUString
& rFltName
,
236 const Graphic
* pGraphic
,
237 SwGrfFormatColl
*pColl
,
238 SwAttrSet
const * pAutoAttr
= nullptr ); ///< in ndgrf.cxx
240 SwOLENode
*MakeOLENode( SwNode
& rWhere
,
241 const svt::EmbeddedObjectRef
&,
242 SwGrfFormatColl
*pColl
); ///< in ndole.cxx
243 SwOLENode
*MakeOLENode( SwNode
& rWhere
,
244 const OUString
&rName
,
246 SwGrfFormatColl
*pColl
,
247 SwAttrSet
const * pAutoAttr
); ///< in ndole.cxx
249 /// Array of all OutlineNodes.
250 const SwOutlineNodes
& GetOutLineNds() const { return m_aOutlineNodes
;}
252 /// Update all Nodes - Rule/Format-Change.
253 void UpdateOutlineNode(SwNode
& rNd
);
255 /** Insert nodes for tables. If Lines is given, create the matrix
256 from lines and boxes, else only the count of boxes.
258 New parameter pAttrSet: If pAttrSet is non-null and contains an
259 adjust item it is propagated to the table cells. If there is an
260 adjust in pContentTextColl or pHeadlineTextColl this adjust item
261 overrides the item in pAttrSet. */
263 static SwTableNode
* InsertTable( SwNode
& rNd
,
264 sal_uInt16 nBoxes
, SwTextFormatColl
* pContentTextColl
,
265 sal_uInt16 nLines
, sal_uInt16 nRepeat
,
266 SwTextFormatColl
* pHeadlineTextColl
,
267 const SwAttrSet
* pAttrSet
);
269 /// Create balanced table from selected range.
270 SwTableNode
* TextToTable( const SwNodeRange
& rRange
, sal_Unicode cCh
,
271 SwTableFormat
* pTableFormat
,
272 SwTableLineFormat
* pLineFormat
,
273 SwTableBoxFormat
* pBoxFormat
,
274 SwTextFormatColl
* pTextColl
,
275 SwUndoTextToTable
* pUndo
);
277 void ExpandRangeForTableBox(const SwNodeRange
& rRange
,
278 std::optional
<SwNodeRange
>& rExpandedRange
);
280 /// create a table from a vector of NodeRanges - API support
281 SwTableNode
* TextToTable( const TableRanges_t
& rTableNodes
,
282 SwTableFormat
* pTableFormat
,
283 SwTableLineFormat
* pLineFormat
,
284 SwTableBoxFormat
* pBoxFormat
);
286 /// Create regular text from what was table.
287 bool TableToText( const SwNodeRange
& rRange
, sal_Unicode cCh
,
288 SwUndoTableToText
* );
289 /// Is in untbl.cxx and may called only by Undo-object.
290 SwTableNode
* UndoTableToText( SwNodeOffset nStt
, SwNodeOffset nEnd
,
291 const SwTableToTextSaves
& rSavedData
);
293 /** Insert a new box in the line before InsPos. Its format
294 is taken from the following one (or from the previous one if we are
295 at the end). In the line there must be a box already. */
296 SW_DLLPUBLIC
bool InsBoxen( SwTableNode
*, SwTableLine
*, SwTableBoxFormat
*,
297 /// Formats for TextNode of box.
298 SwTextFormatColl
*, const SfxItemSet
* pAutoAttr
,
299 sal_uInt16 nInsPos
, sal_uInt16 nCnt
= 1 );
300 /** Splits a table at the base-line which contains the index.
301 All base lines behind it are moved to a new table/ -node.
302 Is the flag bCalcNewSize set to TRUE, the new SSize for both
303 tables is calculated from the Maximum of the boxes, provided
304 SSize is set "absolute" (LONG_MAX).
305 (Momentarily this is needed only for the RTF-parser.) */
306 SwTableNode
* SplitTable( SwNode
& rPos
, bool bAfter
= true,
307 bool bCalcNewSize
= false );
308 /// Two Tables that are following one another are merged.
309 bool MergeTable( SwNode
& rPos
, bool bWithPrev
= true );
311 /// Insert a new SwSection.
312 SwSectionNode
* InsertTextSection(SwNode
& rNd
,
313 SwSectionFormat
& rSectionFormat
,
314 SwSectionData
const&,
315 SwTOXBase
const*const pTOXBase
,
316 SwNode
const * pEndNd
,
317 bool const bInsAtStart
= true,
318 bool const bCreateFrames
= true);
320 /// Which Doc contains the nodes-array?
321 SwDoc
& GetDoc() { return m_rMyDoc
; }
322 const SwDoc
& GetDoc() const { return m_rMyDoc
; }
324 /** Search previous / next content node or table node with frames.
325 Search is started backward with the one before rFrameNd and
327 If no valid node is found, return nullptr. **/
328 SwNode
* FindPrvNxtFrameNode( const SwNode
& rFrameNd
,
330 SwRootFrame
const* pLayout
= nullptr) const;
332 SwNode
* DocumentSectionStartNode(SwNode
* pNode
) const;
333 SwNode
* DocumentSectionEndNode(SwNode
* pNode
) const;
336 * Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by default)
338 void dumpAsXml( xmlTextWriterPtr pWriter
) const;
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */