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 
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;
62 
63 namespace sw { class DocumentContentOperationsManager; }
64 namespace svt { class EmbeddedObjectRef; }
65 
66 
67 typedef bool (*FnForEach_SwNodes)( SwNode*, void* pArgs );
68 typedef struct _xmlTextWriter *xmlTextWriterPtr;
69 
71 {
72  bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
73 };
74 
75 class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
76 {
77 public:
78  static constexpr auto npos = std::numeric_limits<size_type>::max();
79 
80  bool Seek_Entry(SwNode* rP, size_type* pnPos) const;
81 };
82 
83 struct SwTableToTextSave;
84 using SwTableToTextSaves = std::vector<std::unique_ptr<SwTableToTextSave>>;
85 
86 class SW_DLLPUBLIC SwNodes final
87  : private BigPtrArray
88 {
89  friend class SwDoc;
90  friend class SwNode;
91  friend class SwNodeIndex;
92  friend class SwStartNode;
93  friend class ::sw::DocumentContentOperationsManager;
94 
96  void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, bool bDel );
97 
98  void InsertNode( SwNode* pNode, const SwNodeIndex& rPos );
99  void InsertNode( SwNode* pNode, sal_uLong nPos );
100 
102 
103  SwNode *m_pEndOfPostIts, *m_pEndOfInserts,
104  *m_pEndOfAutotext, *m_pEndOfRedlines;
105  std::unique_ptr<SwNode> m_pEndOfContent;
106 
107  mutable std::unique_ptr<SwOutlineNodes> m_pOutlineNodes;
108 
109  bool m_bInNodesDel : 1;
111  bool m_bInDelUpdOutline : 1;
112 
113  // Actions on the nodes.
114  static void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
115  void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
116 
117  void ChgNode( SwNodeIndex const & rDelPos, sal_uLong nSize,
118  SwNodeIndex& rInsPos, bool bNewFrames );
119 
120  void UpdateOutlineIdx( const SwNode& );
121 
122  void CopyNodes( const SwNodeRange&, const SwNodeIndex&,
123  bool bNewFrames, bool bTableInsDummyNode = false ) const;
124  void DelDummyNodes( const SwNodeRange& rRg );
125 
126  SwNodes(SwNodes const&) = delete;
127  SwNodes& operator=(SwNodes const&) = delete;
128 
129  SwNodes(SwDoc& rDoc);
130 
131 public:
132  ~SwNodes();
133 
134  typedef std::vector<SwNodeRange> NodeRanges_t;
135  typedef std::vector<NodeRanges_t> TableRanges_t;
136 
137  SwNode* operator[]( sal_uLong n ) const; // defined in node.hxx
138 
139  sal_uLong Count() const { return BigPtrArray::Count(); }
140  void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = nullptr )
141  {
142  ForEach( 0, BigPtrArray::Count(), fnForEach, pArgs );
143  }
144  void ForEach( sal_uLong nStt, sal_uLong nEnd, FnForEach_SwNodes fnForEach, void* pArgs );
145  void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
146  FnForEach_SwNodes fnForEach, void* pArgs );
147 
149  SwNode& GetEndOfPostIts() const { return *m_pEndOfPostIts; }
151  SwNode& GetEndOfInserts() const { return *m_pEndOfInserts; }
153  SwNode& GetEndOfAutotext() const { return *m_pEndOfAutotext; }
155  SwNode& GetEndOfRedlines() const { return *m_pEndOfRedlines; }
158  SwNode& GetEndOfExtras() const { return *m_pEndOfRedlines; }
160  SwNode& GetEndOfContent() const { return *m_pEndOfContent; }
161 
164  bool IsDocNodes() const;
165 
166  static sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex);
167  void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
168 
169  bool MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
170  bool bNewFrames = true );
171  void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
172 
173  void Copy_( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
174  bool bNewFrames = true ) const
175  { CopyNodes( rRg, rInsPos, bNewFrames ); }
176 
177  void SectionUp( SwNodeRange *);
178  void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
179 
180  static void GoStartOfSection(SwNodeIndex *);
181  static void GoEndOfSection(SwNodeIndex *);
182 
183  SwContentNode* GoNext(SwNodeIndex *) const;
185 
188  SwContentNode* GoNextSection( SwNodeIndex *, bool bSkipHidden = true,
189  bool bSkipProtect = true ) const;
190  static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden = true,
191  bool bSkipProtect = true );
192 
196  static SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
198 
200  SwTextNode *MakeTextNode( const SwNodeIndex & rWhere,
201  SwTextFormatColl *pColl,
202  bool bNewFrames = true);
203  SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
204  SwStartNodeType eSttNdTyp,
205  SwTextFormatColl *pColl );
206 
207  static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
208  const OUString& rGrfName,
209  const OUString& rFltName,
210  const Graphic* pGraphic,
211  SwGrfFormatColl *pColl,
212  SwAttrSet const * pAutoAttr = nullptr );
213 
214  static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
215  const GraphicObject& rGrfObj,
216  SwGrfFormatColl *pColl );
217 
218  SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
219  const svt::EmbeddedObjectRef&,
220  SwGrfFormatColl *pColl );
221  SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
222  const OUString &rName,
223  sal_Int64 nAspect,
224  SwGrfFormatColl *pColl,
225  SwAttrSet const * pAutoAttr );
226 
228  const SwOutlineNodes& GetOutLineNds() const { return *m_pOutlineNodes;}
229 
231  void UpdateOutlineNode(SwNode & rNd);
232 
241  static SwTableNode* InsertTable( const SwNodeIndex& rNdIdx,
242  sal_uInt16 nBoxes, SwTextFormatColl* pContentTextColl,
243  sal_uInt16 nLines, sal_uInt16 nRepeat,
244  SwTextFormatColl* pHeadlineTextColl,
245  const SwAttrSet * pAttrSet);
246 
248  SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
249  SwTableFormat* pTableFormat,
250  SwTableLineFormat* pLineFormat,
251  SwTableBoxFormat* pBoxFormat,
252  SwTextFormatColl* pTextColl,
253  SwUndoTextToTable* pUndo );
254 
255  std::unique_ptr<SwNodeRange> ExpandRangeForTableBox(const SwNodeRange & rRange);
256 
258  SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
259  SwTableFormat* pTableFormat,
260  SwTableLineFormat* pLineFormat,
261  SwTableBoxFormat* pBoxFormat );
262 
264  bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
267  SwTableNode* UndoTableToText( sal_uLong nStt, sal_uLong nEnd,
268  const SwTableToTextSaves& rSavedData );
269 
273  bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFormat*,
275  SwTextFormatColl*, const SfxItemSet* pAutoAttr,
276  sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
283  SwTableNode* SplitTable( const SwNodeIndex& rPos, bool bAfter = true,
284  bool bCalcNewSize = false );
286  bool MergeTable( const SwNodeIndex& rPos, bool bWithPrev = true,
287  sal_uInt16 nMode = 0 );
288 
290  SwSectionNode* InsertTextSection(SwNodeIndex const& rNdIdx,
291  SwSectionFormat& rSectionFormat,
292  SwSectionData const&,
293  SwTOXBase const*const pTOXBase,
294  SwNodeIndex const*const pEnd,
295  bool const bInsAtStart = true,
296  bool const bCreateFrames = true);
297 
299  SwDoc& GetDoc() { return m_rMyDoc; }
300  const SwDoc& GetDoc() const { return m_rMyDoc; }
301 
306  SwNode* FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
307  const SwNode* pEnd ) const;
308 
309  SwNode * DocumentSectionStartNode(SwNode * pNode) const;
310  SwNode * DocumentSectionEndNode(SwNode * pNode) const;
311 
315  void dumpAsXml( xmlTextWriterPtr pWriter ) const;
316 };
317 
318 
319 #endif
320 
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Starts a section of nodes in the document model.
Definition: node.hxx:312
SwNode & GetEndOfInserts() const
Section for all footnotes.
Definition: ndarr.hxx:151
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:153
sal_uLong Count() const
Definition: ndarr.hxx:139
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
Marks a position in the document model.
Definition: pam.hxx:35
SwDoc & GetDoc()
Which Doc contains the nodes-array?
Definition: ndarr.hxx:299
sal_uIntPtr sal_uLong
Definition: doc.hxx:188
std::vector< SwNodeRange > NodeRanges_t
Definition: ndarr.hxx:134
SwTableLine is one table row in the document model.
Definition: swtable.hxx:357
Dialog to specify the properties of date form field.
SwNode & GetEndOfPostIts() const
A still empty section.
Definition: ndarr.hxx:149
void Copy_(const SwNodeRange &rRg, const SwNodeIndex &rInsPos, bool bNewFrames=true) const
Definition: ndarr.hxx:173
sal_uInt16 sal_Unicode
sal_uLong Count() const
Definition: bparr.hxx:89
std::vector< NodeRanges_t > TableRanges_t
Definition: ndarr.hxx:135
bool operator()(SwNode *const &lhs, SwNode *const &rhs) const
Definition: ndnum.cxx:27
std::unique_ptr< SwNode > m_pEndOfContent
Definition: ndarr.hxx:105
std::unique_ptr< SwOutlineNodes > m_pOutlineNodes
Array of all outline nodes.
Definition: ndarr.hxx:107
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:160
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
struct _xmlTextWriter * xmlTextWriterPtr
bool GoNext(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:291
static constexpr auto npos
Definition: ndarr.hxx:78
void ForEach(FnForEach_SwNodes fnForEach, void *pArgs=nullptr)
Definition: ndarr.hxx:140
std::vector< std::unique_ptr< SwTableToTextSave >> SwTableToTextSaves
Definition: ndarr.hxx:84
friend class SwNodes
Definition: node.hxx:315
Marks a node in the document model.
Definition: ndindex.hxx:31
const SwOutlineNodes & GetOutLineNds() const
Array of all OutlineNodes.
Definition: ndarr.hxx:228
SwNodeIndex * m_vIndices
ring of all indices on nodes.
Definition: ndarr.hxx:95
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwDoc & m_rMyDoc
This Doc contains the nodes-array.
Definition: ndarr.hxx:101
BigPtrEntry * operator[](sal_uLong) const
Definition: bparr.cxx:82
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:300
SwStartNodeType
Definition: ndtyp.hxx:50
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:270
SwNode & GetEndOfRedlines() const
Section for all Redlines.
Definition: ndarr.hxx:155
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:987
struct _xmlTextWriter * xmlTextWriterPtr
Definition: ndarr.hxx:68
std::vector< SwNode * >::size_type size_type
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
Definition: ndarr.hxx:158
bool GoPrevious(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:298
bool(* FnForEach_SwNodes)(SwNode *, void *pArgs)
Definition: ndarr.hxx:67
SwNode * m_pEndOfRedlines
Definition: ndarr.hxx:103
Base class of the Writer document model elements.
Definition: node.hxx:80