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