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 #include "nodeoffset.hxx"
34 
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;
64 
65 namespace sw { class DocumentContentOperationsManager; }
66 namespace svt { class EmbeddedObjectRef; }
67 
68 
69 typedef bool (*FnForEach_SwNodes)( SwNode*, void* pArgs );
70 typedef struct _xmlTextWriter *xmlTextWriterPtr;
71 
73 {
74  bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
75 };
76 
77 class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
78 {
79 public:
80  static constexpr auto npos = std::numeric_limits<size_type>::max();
81 
82  bool Seek_Entry(SwNode* rP, size_type* pnPos) const;
83 };
84 
85 struct SwTableToTextSave;
86 using SwTableToTextSaves = std::vector<std::unique_ptr<SwTableToTextSave>>;
87 
88 class SW_DLLPUBLIC SwNodes final
89  : private BigPtrArray
90 {
91  friend class SwDoc;
92  friend class SwNode;
93  friend class SwNodeIndex;
94  friend class SwStartNode;
95  friend class ::sw::DocumentContentOperationsManager;
96 
98  void RemoveNode( SwNodeOffset nDelPos, SwNodeOffset nLen, bool bDel );
99 
100  void InsertNode( SwNode* pNode, const SwNodeIndex& rPos );
101  void InsertNode( SwNode* pNode, SwNodeOffset nPos );
102 
104 
105  SwNode *m_pEndOfPostIts, *m_pEndOfInserts,
106  *m_pEndOfAutotext, *m_pEndOfRedlines;
107  std::unique_ptr<SwNode> m_pEndOfContent;
108 
109  mutable std::unique_ptr<SwOutlineNodes> m_pOutlineNodes;
110 
111  bool m_bInNodesDel : 1;
113  bool m_bInDelUpdOutline : 1;
114 
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) );
118 
119  void ChgNode( SwNodeIndex const & rDelPos, SwNodeOffset nSize,
120  SwNodeIndex& rInsPos, bool bNewFrames );
121 
122  void UpdateOutlineIdx( const SwNode& );
123 
124  void CopyNodes( const SwNodeRange&, const SwNodeIndex&,
125  bool bNewFrames, bool bTableInsDummyNode = false ) const;
126  void DelDummyNodes( const SwNodeRange& rRg );
127 
128  SwNodes(SwNodes const&) = delete;
129  SwNodes& operator=(SwNodes const&) = delete;
130 
131  SwNodes(SwDoc& rDoc);
132 
133 public:
134  ~SwNodes();
135 
136  typedef std::vector<SwNodeRange> NodeRanges_t;
137  typedef std::vector<NodeRanges_t> TableRanges_t;
138 
139  SwNode* operator[]( SwNodeOffset n ) const; // defined in node.hxx
140 
142  void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = nullptr )
143  {
144  ForEach( SwNodeOffset(0), Count(), fnForEach, pArgs );
145  }
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 );
149 
151  SwNode& GetEndOfPostIts() const { return *m_pEndOfPostIts; }
153  SwNode& GetEndOfInserts() const { return *m_pEndOfInserts; }
155  SwNode& GetEndOfAutotext() const { return *m_pEndOfAutotext; }
157  SwNode& GetEndOfRedlines() const { return *m_pEndOfRedlines; }
160  SwNode& GetEndOfExtras() const { return *m_pEndOfRedlines; }
162  SwNode& GetEndOfContent() const { return *m_pEndOfContent; }
163 
166  bool IsDocNodes() const;
167 
168  static sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex);
169  void Delete(const SwNodeIndex &rPos, SwNodeOffset nNodes = SwNodeOffset(1));
170 
171  bool MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
172  bool bNewFrames = true );
173  void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
174 
175  void Copy_( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
176  bool bNewFrames = true ) const
177  { CopyNodes( rRg, rInsPos, bNewFrames ); }
178 
179  void SectionUp( SwNodeRange *);
180  void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
181 
182  static void GoStartOfSection(SwNodeIndex *);
183  static void GoEndOfSection(SwNodeIndex *);
184 
185  SwContentNode* GoNext(SwNodeIndex *) const;
187 
190  SwContentNode* GoNextSection( SwNodeIndex *, bool bSkipHidden = true,
191  bool bSkipProtect = true ) const;
192  static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden = true,
193  bool bSkipProtect = true );
194 
198  static SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
200 
202  SwTextNode *MakeTextNode( const SwNodeIndex & rWhere,
203  SwTextFormatColl *pColl,
204  bool bNewFrames = true);
205  SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
206  SwStartNodeType eSttNdTyp,
207  SwTextFormatColl *pColl );
208 
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 );
215 
216  static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
217  const GraphicObject& rGrfObj,
218  SwGrfFormatColl *pColl );
219 
220  SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
221  const svt::EmbeddedObjectRef&,
222  SwGrfFormatColl *pColl );
223  SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
224  const OUString &rName,
225  sal_Int64 nAspect,
226  SwGrfFormatColl *pColl,
227  SwAttrSet const * pAutoAttr );
228 
230  const SwOutlineNodes& GetOutLineNds() const { return *m_pOutlineNodes;}
231 
233  void UpdateOutlineNode(SwNode & rNd);
234 
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);
248 
250  SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
251  SwTableFormat* pTableFormat,
252  SwTableLineFormat* pLineFormat,
253  SwTableBoxFormat* pBoxFormat,
254  SwTextFormatColl* pTextColl,
255  SwUndoTextToTable* pUndo );
256 
257  std::unique_ptr<SwNodeRange> ExpandRangeForTableBox(const SwNodeRange & rRange);
258 
260  SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
261  SwTableFormat* pTableFormat,
262  SwTableLineFormat* pLineFormat,
263  SwTableBoxFormat* pBoxFormat );
264 
266  bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
269  SwTableNode* UndoTableToText( SwNodeOffset nStt, SwNodeOffset nEnd,
270  const SwTableToTextSaves& rSavedData );
271 
275  bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFormat*,
277  SwTextFormatColl*, const SfxItemSet* pAutoAttr,
278  sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
285  SwTableNode* SplitTable( const SwNodeIndex& rPos, bool bAfter = true,
286  bool bCalcNewSize = false );
288  bool MergeTable( const SwNodeIndex& rPos, bool bWithPrev = true,
289  sal_uInt16 nMode = 0 );
290 
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);
299 
301  SwDoc& GetDoc() { return m_rMyDoc; }
302  const SwDoc& GetDoc() const { return m_rMyDoc; }
303 
308  SwNode* FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
309  const SwNode* pEnd,
310  SwRootFrame const* pLayout = nullptr) 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:313
SwNode & GetEndOfInserts() const
Section for all footnotes.
Definition: ndarr.hxx:153
BigPtrEntry * operator[](sal_Int32) const
Definition: bparr.cxx:82
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:155
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
Marks a position in the document model.
Definition: pam.hxx:36
SwDoc & GetDoc()
Which Doc contains the nodes-array?
Definition: ndarr.hxx:301
Definition: doc.hxx:188
std::vector< SwNodeRange > NodeRanges_t
Definition: ndarr.hxx:136
SwTableLine is one table row in the document model.
Definition: swtable.hxx:358
Dialog to specify the properties of date form field.
SwNode & GetEndOfPostIts() const
A still empty section.
Definition: ndarr.hxx:151
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
void Copy_(const SwNodeRange &rRg, const SwNodeIndex &rInsPos, bool bNewFrames=true) const
Definition: ndarr.hxx:175
sal_uInt16 sal_Unicode
std::vector< NodeRanges_t > TableRanges_t
Definition: ndarr.hxx:137
bool operator()(SwNode *const &lhs, SwNode *const &rhs) const
Definition: ndnum.cxx:27
std::unique_ptr< SwNode > m_pEndOfContent
Definition: ndarr.hxx:107
std::unique_ptr< SwOutlineNodes > m_pOutlineNodes
Array of all outline nodes.
Definition: ndarr.hxx:109
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:162
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
bool GoNext(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:291
static constexpr auto npos
Definition: ndarr.hxx:80
void ForEach(FnForEach_SwNodes fnForEach, void *pArgs=nullptr)
Definition: ndarr.hxx:142
std::vector< std::unique_ptr< SwTableToTextSave >> SwTableToTextSaves
Definition: ndarr.hxx:86
friend class SwNodes
Definition: node.hxx:316
Marks a node in the document model.
Definition: ndindex.hxx:32
const SwOutlineNodes & GetOutLineNds() const
Array of all OutlineNodes.
Definition: ndarr.hxx:230
SwNodeIndex * m_vIndices
ring of all indices on nodes.
Definition: ndarr.hxx:97
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
sal_Int32 Count() const
Definition: bparr.hxx:89
SwDoc & m_rMyDoc
This Doc contains the nodes-array.
Definition: ndarr.hxx:103
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
SwStartNode & operator=(const SwStartNode &rNode)=delete
const SwDoc & GetDoc() const
Definition: ndarr.hxx:302
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
SwStartNodeType
Definition: ndtyp.hxx:50
SwNodeOffset Count() const
Definition: ndarr.hxx:141
struct _xmlTextWriter * xmlTextWriterPtr
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:272
SwNode & GetEndOfRedlines() const
Section for all Redlines.
Definition: ndarr.hxx:157
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:989
struct _xmlTextWriter * xmlTextWriterPtr
Definition: ndarr.hxx:70
std::vector< SwNode * >::size_type size_type
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
Definition: ndarr.hxx:160
bool GoPrevious(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:298
bool(* FnForEach_SwNodes)(SwNode *, void *pArgs)
Definition: ndarr.hxx:69
SwNode * m_pEndOfRedlines
Definition: ndarr.hxx:105
Base class of the Writer document model elements.
Definition: node.hxx:81