bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / ndarr.hxx
blob4acccc34125f3c28fc13b5a34820932f374eba0f
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 SW_NDARR_HXX
21 #define SW_NDARR_HXX
23 #include <vector>
25 #include <boost/utility.hpp>
27 #include <com/sun/star/embed/XEmbeddedObject.hpp>
29 #include <svtools/embedhlp.hxx>
31 #include <bparr.hxx>
32 #include <ndtyp.hxx>
33 #include <o3tl/sorted_vector.hxx>
35 class Graphic;
36 class GraphicObject;
37 class String;
38 class SwAttrSet;
39 class SfxItemSet;
40 class SwCntntNode;
41 class SwDoc;
42 class SwGrfFmtColl;
43 class SwGrfNode;
44 class SwHistory;
45 class SwNode;
46 class SwNodeIndex;
47 class SwNodeRange;
48 class SwOLENode;
49 class SwOutlineNodes;
50 class SwPaM;
51 class SwSectionData;
52 class SwSectionFmt;
53 class SwTOXBase;
54 class SwSectionNode;
55 class SwStartNode;
56 class SwTableBoxFmt;
57 class SwTableFmt;
58 class SwTableLine;
59 class SwTableLineFmt;
60 class SwTableNode;
61 class SwTblToTxtSaves;
62 class SwTxtFmtColl;
63 class SwTxtNode;
64 class SwUndoTblToTxt;
65 class SwUndoTxtToTbl;
66 struct SwPosition;
68 // --------------------
69 // class SwNodes
70 // --------------------
72 typedef SwNode * SwNodePtr;
73 typedef bool (*FnForEach_SwNodes)( const SwNodePtr&, void* pArgs );
74 typedef struct _xmlTextWriter *xmlTextWriterPtr;
76 struct CompareSwOutlineNodes
78 bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
81 class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
83 public:
84 bool Seek_Entry(SwNode* const &rP, sal_uInt16* pnPos) const;
87 class SW_DLLPUBLIC SwNodes
88 : private BigPtrArray
89 , private ::boost::noncopyable
91 friend class SwDoc;
92 friend class SwNode;
93 friend class SwNodeIndex;
95 SwNodeIndex* pRoot; ///< List of all indices on nodes.
97 void InsertNode( const SwNodePtr pNode,
98 const SwNodeIndex& rPos );
99 void InsertNode( const SwNodePtr pNode,
100 sal_uLong nPos );
102 SwDoc* pMyDoc; ///< This Doc contains the nodes-array.
104 SwNode *pEndOfPostIts, *pEndOfInserts, ///< These are the fixed ranges.
105 *pEndOfAutotext, *pEndOfRedlines,
106 *pEndOfContent;
108 mutable SwOutlineNodes* pOutlineNds; ///< Array of all outline nodes.
110 sal_Bool bInNodesDel : 1; /**< In Case of recursive calling.
111 Do not update Num/Outline. */
112 sal_Bool bInDelUpdOutl : 1; ///< Flag for updating of Outline.
113 sal_Bool bInDelUpdNum : 1; ///< Flag for updating of Outline.
115 /// For administering indices.
116 void RegisterIndex( SwNodeIndex& rIdx );
117 void DeRegisterIndex( SwNodeIndex& rIdx );
118 void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, sal_Bool bDel );
120 // Actions on the nodes.
121 void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
122 void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
124 void ChgNode( SwNodeIndex& rDelPos, sal_uLong nSize,
125 SwNodeIndex& rInsPos, sal_Bool bNewFrms );
127 void UpdtOutlineIdx( const SwNode& ); ///< Update all OutlineNodes starting from Node.
129 void _CopyNodes( const SwNodeRange&, const SwNodeIndex&,
130 sal_Bool bNewFrms = sal_True, sal_Bool bTblInsDummyNode = sal_False ) const;
131 void _DelDummyNodes( const SwNodeRange& rRg );
133 protected:
134 SwNodes( SwDoc* pDoc );
136 public:
137 ~SwNodes();
139 typedef ::std::vector<SwNodeRange> NodeRanges_t;
140 typedef ::std::vector<NodeRanges_t> TableRanges_t;
142 SwNodePtr operator[]( sal_uLong n ) const
143 { return (SwNodePtr)BigPtrArray::operator[] ( n ); }
145 sal_uLong Count() const { return BigPtrArray::Count(); }
146 void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = 0 )
148 BigPtrArray::ForEach( 0, BigPtrArray::Count(),
149 (FnForEach) fnForEach, pArgs );
151 void ForEach( sal_uLong nStt, sal_uLong nEnd, FnForEach_SwNodes fnForEach, void* pArgs = 0 )
153 BigPtrArray::ForEach( nStt, nEnd, (FnForEach) fnForEach, pArgs );
155 void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
156 FnForEach_SwNodes fnForEach, void* pArgs = 0 );
158 /// A still empty section.
159 SwNode& GetEndOfPostIts() const { return *pEndOfPostIts; }
160 /// Section fpr all footnotes.
161 SwNode& GetEndOfInserts() const { return *pEndOfInserts; }
162 /// Section for all Flys/Header/Footers.
163 SwNode& GetEndOfAutotext() const { return *pEndOfAutotext; }
164 /// Section for all Redlines.
165 SwNode& GetEndOfRedlines() const { return *pEndOfRedlines; }
166 /** This is the last EndNode of a special section. After it
167 there is only the regular ContentSection (i.e. the BodyText). */
168 SwNode& GetEndOfExtras() const { return *pEndOfRedlines; }
169 /// Regular ContentSection (i.e. the BodyText).
170 SwNode& GetEndOfContent() const { return *pEndOfContent; }
172 /** Is the NodesArray the regular one of Doc? (and not the UndoNds, ...)
173 Implementation in doc.hxx (because one needs to know Doc for it) ! */
174 sal_Bool IsDocNodes() const;
176 sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex) const;
177 void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
179 sal_Bool _MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
180 sal_Bool bNewFrms = sal_True );
181 void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
183 void _Copy( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
184 sal_Bool bNewFrms = sal_True ) const
185 { _CopyNodes( rRg, rInsPos, bNewFrms ); }
187 void SectionUp( SwNodeRange *);
188 void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
190 sal_Bool CheckNodesRange( const SwNodeIndex& rStt, const SwNodeIndex& rEnd ) const;
192 void GoStartOfSection(SwNodeIndex *) const;
193 void GoEndOfSection(SwNodeIndex *) const;
195 SwCntntNode* GoNext(SwNodeIndex *) const;
196 SwCntntNode* GoPrevious(SwNodeIndex *) const;
198 /** Go to next/previous Cntnt/Table-node for which LayoutFrames exist.
199 While doing this do not leave Header/Footer/Frame etc. */
200 SwNode* GoNextWithFrm(SwNodeIndex *) const;
201 SwNode* GoPreviousWithFrm(SwNodeIndex *) const;
203 /** Go to next content-node that is not protected or hidden
204 (Both set FALSE ==> GoNext/GoPrevious!!!). */
205 SwCntntNode* GoNextSection( SwNodeIndex *, int bSkipHidden = sal_True,
206 int bSkipProtect = sal_True ) const;
207 SwCntntNode* GoPrevSection( SwNodeIndex *, int bSkipHidden = sal_True,
208 int bSkipProtect = sal_True ) const;
210 /** Create an empty section of Start- and EndNote. It may be called
211 only if a new section with content is to be created,
212 e.g. at filters/Undo/... */
213 SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
214 SwStartNodeType = SwNormalStartNode );
216 /// Implementations of "Make...Node" are in the given .cxx-files.
217 SwTxtNode *MakeTxtNode( const SwNodeIndex & rWhere,
218 SwTxtFmtColl *pColl,
219 SwAttrSet* pAutoAttr = 0 ); ///< in ndtxt.cxx
220 SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
221 SwStartNodeType eSttNdTyp,
222 SwTxtFmtColl *pColl,
223 SwAttrSet* pAutoAttr = 0 );
225 SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
226 const String& rGrfName,
227 const String& rFltName,
228 const Graphic* pGraphic,
229 SwGrfFmtColl *pColl,
230 SwAttrSet* pAutoAttr = 0,
231 sal_Bool bDelayed = sal_False ); ///< in ndgrf.cxx
233 SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
234 const GraphicObject& rGrfObj,
235 SwGrfFmtColl *pColl,
236 SwAttrSet* pAutoAttr = 0 ); ///< in ndgrf.cxx
238 SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
239 const svt::EmbeddedObjectRef&,
240 SwGrfFmtColl *pColl,
241 SwAttrSet* pAutoAttr = 0 ); ///< in ndole.cxx
242 SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
243 const String &rName,
244 sal_Int64 nAspect,
245 SwGrfFmtColl *pColl,
246 SwAttrSet* pAutoAttr ); ///< in ndole.cxx
248 /// Array of all OutlineNodes.
249 const SwOutlineNodes& GetOutLineNds() const;
251 //void UpdateOutlineNode( const SwNode&, sal_uInt8 nOldLevel, sal_uInt8 nNewLevel );//#outline level,removed by zhaojianwei
253 /// Update all Nodes - Rule/Format-Change.
254 void UpdateOutlineNode(SwNode & rNd);
256 /** Insert nodes for tables. If Lines is given, create the matrix
257 from lines and boxes, else only the count of boxes.
259 New parameter pAttrSet: If pAttrSet is non-null and contains an
260 adjust item it is propagated to the table cells. If there is an
261 adjust in pCntntTxtColl or pHeadlineTxtColl this adjust item
262 overrides the item in pAttrSet. */
264 SwTableNode* InsertTable( const SwNodeIndex& rNdIdx,
265 sal_uInt16 nBoxes, SwTxtFmtColl* pCntntTxtColl,
266 sal_uInt16 nLines = 0, sal_uInt16 nRepeat = 0,
267 SwTxtFmtColl* pHeadlineTxtColl = 0,
268 const SwAttrSet * pAttrSet = 0);
270 /// Create balanced table from selected range.
271 SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
272 SwTableFmt* pTblFmt,
273 SwTableLineFmt* pLineFmt,
274 SwTableBoxFmt* pBoxFmt,
275 SwTxtFmtColl* pTxtColl,
276 SwUndoTxtToTbl* pUndo = 0 );
278 SwNodeRange * ExpandRangeForTableBox(const SwNodeRange & rRange);
280 /// create a table from a vector of NodeRanges - API support
281 SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
282 SwTableFmt* pTblFmt,
283 SwTableLineFmt* pLineFmt,
284 SwTableBoxFmt* pBoxFmt,
285 SwTxtFmtColl* pTxtColl
286 /*, SwUndo... pUndo*/ );
289 /// Create regular text from what was table.
290 sal_Bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
291 SwUndoTblToTxt* = 0 );
292 /// Is in untbl.cxx and may called only by Undo-object.
293 SwTableNode* UndoTableToText( sal_uLong nStt, sal_uLong nEnd,
294 const SwTblToTxtSaves& rSavedData );
296 /** Insert a new box in the line before InsPos. Its format
297 is taken from the following one (or from the previous one if we are
298 at the end). In the line there must be a box already. */
299 sal_Bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFmt*,
300 /// Formats for TextNode of box.
301 SwTxtFmtColl*, const SfxItemSet* pAutoAttr,
302 sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
303 /** Splits a table at the base-line which contains the index.
304 All base lines behind it are moved to a new table/ -node.
305 Is the flag bCalcNewSize set to TRUE, the new SSize for both
306 tables is calculated from the Maximum of the boxes, provided
307 SSize is set "absolute" (LONG_MAX).
308 (Momentarily this is needed only for the RTF-parser.) */
309 SwTableNode* SplitTable( const SwNodeIndex& rPos, sal_Bool bAfter = sal_True,
310 sal_Bool bCalcNewSize = sal_False );
311 /// Two Tables that are following one another are merged.
312 sal_Bool MergeTable( const SwNodeIndex& rPos, sal_Bool bWithPrev = sal_True,
313 sal_uInt16 nMode = 0, SwHistory* pHistory = 0 );
315 /// Insert a new SwSection.
316 SwSectionNode* InsertTextSection(SwNodeIndex const& rNdIdx,
317 SwSectionFmt& rSectionFmt,
318 SwSectionData const&,
319 SwTOXBase const*const pTOXBase,
320 SwNodeIndex const*const pEnde,
321 bool const bInsAtStart = true,
322 bool const bCreateFrms = true);
324 /// Which Doc contains the nodes-array?
325 SwDoc* GetDoc() { return pMyDoc; }
326 const SwDoc* GetDoc() const { return pMyDoc; }
328 /** Search previous / next content node or table node with frames.
329 If no end is given begin with the FrameIndex, else start search
330 with that before rFrmIdx and pEnd at the back.
331 If no valid node is found, return 0. rFrmIdx points to the node with frames. **/
332 SwNode* FindPrvNxtFrmNode( SwNodeIndex& rFrmIdx,
333 const SwNode* pEnd = 0 ) const;
335 SwNode * DocumentSectionStartNode(SwNode * pNode) const;
336 SwNode * DocumentSectionEndNode(SwNode * pNode) const;
339 * Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by default)
340 * @since 3.5
342 void dumpAsXml( xmlTextWriterPtr writer = NULL );
345 #endif
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */