Branch libreoffice-5-0-4
[LibreOffice.git] / sw / inc / ndarr.hxx
blob4ff30a8749be43cf80406c94596025942fe71170
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 <vector>
24 #include <memory>
26 #include <boost/utility.hpp>
28 #include <com/sun/star/embed/XEmbeddedObject.hpp>
30 #include <svtools/embedhlp.hxx>
32 #include <bparr.hxx>
33 #include <ndtyp.hxx>
34 #include <o3tl/sorted_vector.hxx>
35 #include <ring.hxx>
37 class Graphic;
38 class GraphicObject;
39 class SwAttrSet;
40 class SfxItemSet;
41 class SwContentNode;
42 class SwDoc;
43 class SwGrfFormatColl;
44 class SwGrfNode;
45 class SwHistory;
46 class SwNode;
47 class SwNodeIndex;
48 class SwNodeRange;
49 class SwOLENode;
50 class SwOutlineNodes;
51 class SwPaM;
52 class SwSectionData;
53 class SwSectionFormat;
54 class SwTOXBase;
55 class SwSectionNode;
56 class SwStartNode;
57 class SwTableBoxFormat;
58 class SwTableFormat;
59 class SwTableLine;
60 class SwTableLineFormat;
61 class SwTableNode;
62 class SwTableToTextSaves;
63 class SwTextFormatColl;
64 class SwTextNode;
65 class SwUndoTableToText;
66 class SwUndoTextToTable;
67 struct SwPosition;
69 namespace sw { class DocumentContentOperationsManager; }
71 // class SwNodes
73 typedef SwNode * SwNodePtr;
74 typedef bool (*FnForEach_SwNodes)( const SwNodePtr&, void* pArgs );
75 typedef struct _xmlTextWriter *xmlTextWriterPtr;
77 struct CompareSwOutlineNodes
79 bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
82 class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
84 public:
85 bool Seek_Entry(SwNode* rP, sal_uInt16* pnPos) const;
88 class SW_DLLPUBLIC SwNodes
89 : private BigPtrArray
90 , private ::boost::noncopyable
92 friend class SwDoc;
93 friend class SwNode;
94 friend class SwNodeIndex;
95 friend class SwStartNode;
96 friend class ::sw::DocumentContentOperationsManager;
98 SwNodeIndex* vIndices; ///< ring of all indices on nodes.
99 void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, bool bDel );
101 void InsertNode( const SwNodePtr pNode,
102 const SwNodeIndex& rPos );
103 void InsertNode( const SwNodePtr pNode,
104 sal_uLong nPos );
106 SwDoc* pMyDoc; ///< This Doc contains the nodes-array.
108 SwNode *pEndOfPostIts, *pEndOfInserts, ///< These are the fixed ranges.
109 *pEndOfAutotext, *pEndOfRedlines,
110 *pEndOfContent;
112 mutable SwOutlineNodes* pOutlineNds; ///< Array of all outline nodes.
114 bool bInNodesDel : 1; /**< In Case of recursive calling.
115 Do not update Num/Outline. */
116 bool bInDelUpdOutl : 1; ///< Flag for updating of Outline.
117 bool bInDelUpdNum : 1; ///< Flag for updating of Outline.
119 // Actions on the nodes.
120 static void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
121 void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
123 void ChgNode( SwNodeIndex& rDelPos, sal_uLong nSize,
124 SwNodeIndex& rInsPos, bool bNewFrms );
126 void UpdateOutlineIdx( const SwNode& ); ///< Update all OutlineNodes starting from Node.
128 void _CopyNodes( const SwNodeRange&, const SwNodeIndex&,
129 bool bNewFrms = true, bool bTableInsDummyNode = false ) const;
130 void _DelDummyNodes( const SwNodeRange& rRg );
132 protected:
133 SwNodes( SwDoc* pDoc );
135 public:
136 ~SwNodes();
138 typedef ::std::vector<SwNodeRange> NodeRanges_t;
139 typedef ::std::vector<NodeRanges_t> TableRanges_t;
141 SwNodePtr operator[]( sal_uLong n ) const; // defined in node.hxx
143 sal_uLong Count() const { return BigPtrArray::Count(); }
144 void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = 0 )
146 ForEach( 0, BigPtrArray::Count(), fnForEach, pArgs );
148 void ForEach( sal_uLong nStt, sal_uLong nEnd, FnForEach_SwNodes fnForEach, void* pArgs = 0 );
149 void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
150 FnForEach_SwNodes fnForEach, void* pArgs = 0 );
152 /// A still empty section.
153 SwNode& GetEndOfPostIts() const { return *pEndOfPostIts; }
154 /// Section fpr all footnotes.
155 SwNode& GetEndOfInserts() const { return *pEndOfInserts; }
156 /// Section for all Flys/Header/Footers.
157 SwNode& GetEndOfAutotext() const { return *pEndOfAutotext; }
158 /// Section for all Redlines.
159 SwNode& GetEndOfRedlines() const { return *pEndOfRedlines; }
160 /** This is the last EndNode of a special section. After it
161 there is only the regular ContentSection (i.e. the BodyText). */
162 SwNode& GetEndOfExtras() const { return *pEndOfRedlines; }
163 /// Regular ContentSection (i.e. the BodyText).
164 SwNode& GetEndOfContent() const { return *pEndOfContent; }
166 /** Is the NodesArray the regular one of Doc? (and not the UndoNds, ...)
167 Implementation in doc.hxx (because one needs to know Doc for it) ! */
168 bool IsDocNodes() const;
170 static sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex);
171 void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
173 bool _MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
174 bool bNewFrms = true );
175 void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
177 void _Copy( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
178 bool bNewFrms = true ) const
179 { _CopyNodes( rRg, rInsPos, bNewFrms ); }
181 void SectionUp( SwNodeRange *);
182 void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
184 bool CheckNodesRange( const SwNodeIndex& rStt, const SwNodeIndex& rEnd ) const;
186 static void GoStartOfSection(SwNodeIndex *);
187 static void GoEndOfSection(SwNodeIndex *);
189 SwContentNode* GoNext(SwNodeIndex *) const;
190 static SwContentNode* GoPrevious(SwNodeIndex *);
192 /** Go to next/previous Content/Table-node for which LayoutFrames exist.
193 While doing this do not leave Header/Footer/Frame etc. */
194 SwNode* GoNextWithFrm(SwNodeIndex *) const;
195 SwNode* GoPreviousWithFrm(SwNodeIndex *) const;
197 /** Go to next content-node that is not protected or hidden
198 (Both set FALSE ==> GoNext/GoPrevious!!!). */
199 SwContentNode* GoNextSection( SwNodeIndex *, bool bSkipHidden = true,
200 bool bSkipProtect = true ) const;
201 static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden = true,
202 bool bSkipProtect = true );
204 /** Create an empty section of Start- and EndNote. It may be called
205 only if a new section with content is to be created,
206 e.g. at filters/Undo/... */
207 static SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
208 SwStartNodeType = SwNormalStartNode );
210 /// Implementations of "Make...Node" are in the given .cxx-files.
211 SwTextNode *MakeTextNode( const SwNodeIndex & rWhere,
212 SwTextFormatColl *pColl,
213 SwAttrSet* pAutoAttr = 0 ); ///< in ndtxt.cxx
214 SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
215 SwStartNodeType eSttNdTyp,
216 SwTextFormatColl *pColl,
217 SwAttrSet* pAutoAttr = 0 );
219 static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
220 const OUString& rGrfName,
221 const OUString& rFltName,
222 const Graphic* pGraphic,
223 SwGrfFormatColl *pColl,
224 SwAttrSet* pAutoAttr = 0,
225 bool bDelayed = false ); ///< in ndgrf.cxx
227 static SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
228 const GraphicObject& rGrfObj,
229 SwGrfFormatColl *pColl,
230 SwAttrSet* pAutoAttr = 0 ); ///< in ndgrf.cxx
232 SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
233 const svt::EmbeddedObjectRef&,
234 SwGrfFormatColl *pColl,
235 SwAttrSet* pAutoAttr = 0 ); ///< in ndole.cxx
236 SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
237 const OUString &rName,
238 sal_Int64 nAspect,
239 SwGrfFormatColl *pColl,
240 SwAttrSet* pAutoAttr ); ///< in ndole.cxx
242 /// Array of all OutlineNodes.
243 const SwOutlineNodes& GetOutLineNds() const { return *pOutlineNds;}
245 /// Update all Nodes - Rule/Format-Change.
246 void UpdateOutlineNode(SwNode & rNd);
248 /** Insert nodes for tables. If Lines is given, create the matrix
249 from lines and boxes, else only the count of boxes.
251 New parameter pAttrSet: If pAttrSet is non-null and contains an
252 adjust item it is propagated to the table cells. If there is an
253 adjust in pContentTextColl or pHeadlineTextColl this adjust item
254 overrides the item in pAttrSet. */
256 static SwTableNode* InsertTable( const SwNodeIndex& rNdIdx,
257 sal_uInt16 nBoxes, SwTextFormatColl* pContentTextColl,
258 sal_uInt16 nLines = 0, sal_uInt16 nRepeat = 0,
259 SwTextFormatColl* pHeadlineTextColl = 0,
260 const SwAttrSet * pAttrSet = 0);
262 /// Create balanced table from selected range.
263 SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
264 SwTableFormat* pTableFormat,
265 SwTableLineFormat* pLineFormat,
266 SwTableBoxFormat* pBoxFormat,
267 SwTextFormatColl* pTextColl,
268 SwUndoTextToTable* pUndo = 0 );
270 static SwNodeRange * ExpandRangeForTableBox(const SwNodeRange & rRange);
272 /// create a table from a vector of NodeRanges - API support
273 SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
274 SwTableFormat* pTableFormat,
275 SwTableLineFormat* pLineFormat,
276 SwTableBoxFormat* pBoxFormat,
277 SwTextFormatColl* pTextColl
278 /*, SwUndo... pUndo*/ );
280 /// Create regular text from what was table.
281 bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
282 SwUndoTableToText* = 0 );
283 /// Is in untbl.cxx and may called only by Undo-object.
284 SwTableNode* UndoTableToText( sal_uLong nStt, sal_uLong nEnd,
285 const SwTableToTextSaves& rSavedData );
287 /** Insert a new box in the line before InsPos. Its format
288 is taken from the following one (or from the previous one if we are
289 at the end). In the line there must be a box already. */
290 bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFormat*,
291 /// Formats for TextNode of box.
292 SwTextFormatColl*, const SfxItemSet* pAutoAttr,
293 sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
294 /** Splits a table at the base-line which contains the index.
295 All base lines behind it are moved to a new table/ -node.
296 Is the flag bCalcNewSize set to TRUE, the new SSize for both
297 tables is calculated from the Maximum of the boxes, provided
298 SSize is set "absolute" (LONG_MAX).
299 (Momentarily this is needed only for the RTF-parser.) */
300 SwTableNode* SplitTable( const SwNodeIndex& rPos, bool bAfter = true,
301 bool bCalcNewSize = false );
302 /// Two Tables that are following one another are merged.
303 bool MergeTable( const SwNodeIndex& rPos, bool bWithPrev = true,
304 sal_uInt16 nMode = 0, SwHistory* pHistory = 0 );
306 /// Insert a new SwSection.
307 SwSectionNode* InsertTextSection(SwNodeIndex const& rNdIdx,
308 SwSectionFormat& rSectionFormat,
309 SwSectionData const&,
310 SwTOXBase const*const pTOXBase,
311 SwNodeIndex const*const pEnde,
312 bool const bInsAtStart = true,
313 bool const bCreateFrms = true);
315 /// Which Doc contains the nodes-array?
316 SwDoc* GetDoc() { return pMyDoc; }
317 const SwDoc* GetDoc() const { return pMyDoc; }
319 /** Search previous / next content node or table node with frames.
320 If no end is given begin with the FrameIndex, else start search
321 with that before rFrmIdx and pEnd at the back.
322 If no valid node is found, return 0. rFrmIdx points to the node with frames. **/
323 SwNode* FindPrvNxtFrmNode( SwNodeIndex& rFrmIdx,
324 const SwNode* pEnd = 0 ) const;
326 SwNode * DocumentSectionStartNode(SwNode * pNode) const;
327 SwNode * DocumentSectionEndNode(SwNode * pNode) const;
330 * Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by default)
331 * @since 3.5
333 void dumpAsXml( xmlTextWriterPtr pWriter ) const;
337 #endif
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */