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 // class SwNodes
67 
68 typedef SwNode * SwNodePtr;
69 typedef bool (*FnForEach_SwNodes)( const SwNodePtr&, 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( sal_uLong nDelPos, sal_uLong nLen, bool bDel );
99 
100  void InsertNode( const SwNodePtr pNode,
101  const SwNodeIndex& rPos );
102  void InsertNode( const SwNodePtr pNode,
103  sal_uLong nPos );
104 
106 
107  SwNode *m_pEndOfPostIts, *m_pEndOfInserts,
108  *m_pEndOfAutotext, *m_pEndOfRedlines;
109  std::unique_ptr<SwNode> m_pEndOfContent;
110 
111  mutable std::unique_ptr<SwOutlineNodes> m_pOutlineNodes;
112 
113  bool m_bInNodesDel : 1;
115  bool m_bInDelUpdOutline : 1;
116 
117  // Actions on the nodes.
118  static void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
119  void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
120 
121  void ChgNode( SwNodeIndex const & rDelPos, sal_uLong nSize,
122  SwNodeIndex& rInsPos, bool bNewFrames );
123 
124  void UpdateOutlineIdx( const SwNode& );
125 
126  void CopyNodes( const SwNodeRange&, const SwNodeIndex&,
127  bool bNewFrames, bool bTableInsDummyNode = false ) const;
128  void DelDummyNodes( const SwNodeRange& rRg );
129 
130  SwNodes(SwNodes const&) = delete;
131  SwNodes& operator=(SwNodes const&) = delete;
132 
133  SwNodes( SwDoc* pDoc );
134 
135 public:
136  ~SwNodes();
137 
138  typedef std::vector<SwNodeRange> NodeRanges_t;
139  typedef std::vector<NodeRanges_t> TableRanges_t;
140 
141  SwNodePtr operator[]( sal_uLong n ) const; // defined in node.hxx
142 
143  sal_uLong Count() const { return BigPtrArray::Count(); }
144  void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = nullptr )
145  {
146  ForEach( 0, BigPtrArray::Count(), fnForEach, pArgs );
147  }
148  void ForEach( sal_uLong nStt, sal_uLong nEnd, FnForEach_SwNodes fnForEach, void* pArgs );
149  void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
150  FnForEach_SwNodes fnForEach, void* pArgs );
151 
153  SwNode& GetEndOfPostIts() const { return *m_pEndOfPostIts; }
155  SwNode& GetEndOfInserts() const { return *m_pEndOfInserts; }
157  SwNode& GetEndOfAutotext() const { return *m_pEndOfAutotext; }
159  SwNode& GetEndOfRedlines() const { return *m_pEndOfRedlines; }
162  SwNode& GetEndOfExtras() const { return *m_pEndOfRedlines; }
164  SwNode& GetEndOfContent() const { return *m_pEndOfContent; }
165 
168  bool IsDocNodes() const;
169 
170  static sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex);
171  void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
172 
173  bool MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
174  bool bNewFrames = true );
175  void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
176 
177  void Copy_( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
178  bool bNewFrames = true ) const
179  { CopyNodes( rRg, rInsPos, bNewFrames ); }
180 
181  void SectionUp( SwNodeRange *);
182  void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
183 
184  bool CheckNodesRange( const SwNodeIndex& rStt, const SwNodeIndex& rEnd ) const;
185 
186  static void GoStartOfSection(SwNodeIndex *);
187  static void GoEndOfSection(SwNodeIndex *);
188 
189  SwContentNode* GoNext(SwNodeIndex *) const;
191 
194  SwContentNode* GoNextSection( SwNodeIndex *, bool bSkipHidden = true,
195  bool bSkipProtect = true ) const;
196  static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden = true,
197  bool bSkipProtect = true );
198 
202  static SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
204 
206  SwTextNode *MakeTextNode( const SwNodeIndex & rWhere,
207  SwTextFormatColl *pColl,
208  bool bNewFrames = true);
209  SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
210  SwStartNodeType eSttNdTyp,
211  SwTextFormatColl *pColl );
212 
213  static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
214  const OUString& rGrfName,
215  const OUString& rFltName,
216  const Graphic* pGraphic,
217  SwGrfFormatColl *pColl,
218  SwAttrSet const * pAutoAttr = nullptr );
219 
220  static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
221  const GraphicObject& rGrfObj,
222  SwGrfFormatColl *pColl );
223 
224  SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
225  const svt::EmbeddedObjectRef&,
226  SwGrfFormatColl *pColl );
227  SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
228  const OUString &rName,
229  sal_Int64 nAspect,
230  SwGrfFormatColl *pColl,
231  SwAttrSet const * pAutoAttr );
232 
234  const SwOutlineNodes& GetOutLineNds() const { return *m_pOutlineNodes;}
235 
237  void UpdateOutlineNode(SwNode & rNd);
238 
247  static SwTableNode* InsertTable( const SwNodeIndex& rNdIdx,
248  sal_uInt16 nBoxes, SwTextFormatColl* pContentTextColl,
249  sal_uInt16 nLines, sal_uInt16 nRepeat,
250  SwTextFormatColl* pHeadlineTextColl,
251  const SwAttrSet * pAttrSet);
252 
254  SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
255  SwTableFormat* pTableFormat,
256  SwTableLineFormat* pLineFormat,
257  SwTableBoxFormat* pBoxFormat,
258  SwTextFormatColl* pTextColl,
259  SwUndoTextToTable* pUndo );
260 
261  std::unique_ptr<SwNodeRange> ExpandRangeForTableBox(const SwNodeRange & rRange);
262 
264  SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
265  SwTableFormat* pTableFormat,
266  SwTableLineFormat* pLineFormat,
267  SwTableBoxFormat* pBoxFormat );
268 
270  bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
273  SwTableNode* UndoTableToText( sal_uLong nStt, sal_uLong nEnd,
274  const SwTableToTextSaves& rSavedData );
275 
279  bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFormat*,
281  SwTextFormatColl*, const SfxItemSet* pAutoAttr,
282  sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
289  SwTableNode* SplitTable( const SwNodeIndex& rPos, bool bAfter = true,
290  bool bCalcNewSize = false );
292  bool MergeTable( const SwNodeIndex& rPos, bool bWithPrev = true,
293  sal_uInt16 nMode = 0 );
294 
296  SwSectionNode* InsertTextSection(SwNodeIndex const& rNdIdx,
297  SwSectionFormat& rSectionFormat,
298  SwSectionData const&,
299  SwTOXBase const*const pTOXBase,
300  SwNodeIndex const*const pEnde,
301  bool const bInsAtStart = true,
302  bool const bCreateFrames = true);
303 
305  SwDoc* GetDoc() { return m_pMyDoc; }
306  const SwDoc* GetDoc() const { return m_pMyDoc; }
307 
312  SwNode* FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
313  const SwNode* pEnd ) const;
314 
315  SwNode * DocumentSectionStartNode(SwNode * pNode) const;
316  SwNode * DocumentSectionEndNode(SwNode * pNode) const;
317 
321  void dumpAsXml( xmlTextWriterPtr pWriter ) const;
322 };
323 
324 
325 #endif
326 
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Starts a section of nodes in the document model.
Definition: node.hxx:303
SwNode & GetEndOfInserts() const
Section fpr all footnotes.
Definition: ndarr.hxx:155
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:157
sal_uLong Count() const
Definition: ndarr.hxx:143
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
Marks a position in the document model.
Definition: pam.hxx:35
sal_uIntPtr sal_uLong
Definition: doc.hxx:185
std::vector< SwNodeRange > NodeRanges_t
Definition: ndarr.hxx:138
SwTableLine is one table row in the document model.
Definition: swtable.hxx:344
bool(* FnForEach_SwNodes)(const SwNodePtr &, void *pArgs)
Definition: ndarr.hxx:69
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
SwNode & GetEndOfPostIts() const
A still empty section.
Definition: ndarr.hxx:153
void Copy_(const SwNodeRange &rRg, const SwNodeIndex &rInsPos, bool bNewFrames=true) const
Definition: ndarr.hxx:177
SwNode * SwNodePtr
Definition: ndarr.hxx:68
sal_uInt16 sal_Unicode
sal_uLong Count() const
Definition: bparr.hxx:87
std::vector< NodeRanges_t > TableRanges_t
Definition: ndarr.hxx:139
bool CheckNodesRange(const SwNodeIndex &rStt, const SwNodeIndex &rEnd, bool bChkSection)
Definition: pam.cxx:238
bool operator()(SwNode *const &lhs, SwNode *const &rhs) const
Definition: ndnum.cxx:29
std::unique_ptr< SwNode > m_pEndOfContent
Definition: ndarr.hxx:109
std::unique_ptr< SwOutlineNodes > m_pOutlineNodes
Array of all outline nodes.
Definition: ndarr.hxx:111
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:164
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
struct _xmlTextWriter * xmlTextWriterPtr
SwDoc * m_pMyDoc
This Doc contains the nodes-array.
Definition: ndarr.hxx:105
bool GoNext(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:270
static constexpr auto npos
Definition: ndarr.hxx:80
void ForEach(FnForEach_SwNodes fnForEach, void *pArgs=nullptr)
Definition: ndarr.hxx:144
std::vector< std::unique_ptr< SwTableToTextSave >> SwTableToTextSaves
Definition: ndarr.hxx:86
friend class SwNodes
Definition: node.hxx:306
Marks a node in the document model.
Definition: ndindex.hxx:31
const SwOutlineNodes & GetOutLineNds() const
Array of all OutlineNodes.
Definition: ndarr.hxx:234
SwNodeIndex * m_vIndices
ring of all indices on nodes.
Definition: ndarr.hxx:97
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
const SwDoc * GetDoc() const
Definition: ndarr.hxx:306
SwDoc * GetDoc()
Which Doc contains the nodes-array?
Definition: ndarr.hxx:305
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
SwStartNodeType
Definition: ndtyp.hxx:50
bool Seek_Entry(SwNode *rP, size_type *pnPos) const
Definition: ndnum.cxx:34
sal_uInt16 GetSectionLevel() const
Returns the section level at the position given by aIndex.
Definition: node.cxx:268
SwNode & GetEndOfRedlines() const
Section for all Redlines.
Definition: ndarr.hxx:159
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:943
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:162
bool GoPrevious(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:277
SwNode * m_pEndOfRedlines
Definition: ndarr.hxx:107
Base class of the Writer document model elements.
Definition: node.hxx:79