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