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 SW_NDARR_HXX
21 : #define SW_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 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;
67 :
68 : // --------------------
69 : // class SwNodes
70 : // --------------------
71 :
72 : typedef SwNode * SwNodePtr;
73 : typedef bool (*FnForEach_SwNodes)( const SwNodePtr&, void* pArgs );
74 : typedef struct _xmlTextWriter *xmlTextWriterPtr;
75 :
76 : struct CompareSwOutlineNodes
77 : {
78 : bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
79 : };
80 :
81 3586 : class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
82 : {
83 : public:
84 : bool Seek_Entry(SwNode* const &rP, sal_uInt16* pnPos) const;
85 : };
86 :
87 : class SW_DLLPUBLIC SwNodes
88 : : private BigPtrArray
89 : , private ::boost::noncopyable
90 : {
91 : friend class SwDoc;
92 : friend class SwNode;
93 : friend class SwNodeIndex;
94 :
95 : SwNodeIndex* pRoot; ///< List of all indices on nodes.
96 :
97 : void InsertNode( const SwNodePtr pNode,
98 : const SwNodeIndex& rPos );
99 : void InsertNode( const SwNodePtr pNode,
100 : sal_uLong nPos );
101 :
102 : SwDoc* pMyDoc; ///< This Doc contains the nodes-array.
103 :
104 : SwNode *pEndOfPostIts, *pEndOfInserts, ///< These are the fixed ranges.
105 : *pEndOfAutotext, *pEndOfRedlines,
106 : *pEndOfContent;
107 :
108 : mutable SwOutlineNodes* pOutlineNds; ///< Array of all outline nodes.
109 :
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.
114 :
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 );
119 :
120 : // Actions on the nodes.
121 : void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
122 : void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
123 :
124 : void ChgNode( SwNodeIndex& rDelPos, sal_uLong nSize,
125 : SwNodeIndex& rInsPos, sal_Bool bNewFrms );
126 :
127 : void UpdtOutlineIdx( const SwNode& ); ///< Update all OutlineNodes starting from Node.
128 :
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 );
132 :
133 : protected:
134 : SwNodes( SwDoc* pDoc );
135 :
136 : public:
137 : ~SwNodes();
138 :
139 : typedef ::std::vector<SwNodeRange> NodeRanges_t;
140 : typedef ::std::vector<NodeRanges_t> TableRanges_t;
141 :
142 713673 : SwNodePtr operator[]( sal_uLong n ) const
143 713673 : { return (SwNodePtr)BigPtrArray::operator[] ( n ); }
144 :
145 118188 : sal_uLong Count() const { return BigPtrArray::Count(); }
146 8 : void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = 0 )
147 : {
148 : BigPtrArray::ForEach( 0, BigPtrArray::Count(),
149 8 : (FnForEach) fnForEach, pArgs );
150 8 : }
151 8032 : void ForEach( sal_uLong nStt, sal_uLong nEnd, FnForEach_SwNodes fnForEach, void* pArgs = 0 )
152 : {
153 8032 : BigPtrArray::ForEach( nStt, nEnd, (FnForEach) fnForEach, pArgs );
154 8032 : }
155 : void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
156 : FnForEach_SwNodes fnForEach, void* pArgs = 0 );
157 :
158 : /// A still empty section.
159 81 : SwNode& GetEndOfPostIts() const { return *pEndOfPostIts; }
160 : /// Section fpr all footnotes.
161 1026 : SwNode& GetEndOfInserts() const { return *pEndOfInserts; }
162 : /// Section for all Flys/Header/Footers.
163 4114 : SwNode& GetEndOfAutotext() const { return *pEndOfAutotext; }
164 : /// Section for all Redlines.
165 7796 : 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 1058 : SwNode& GetEndOfExtras() const { return *pEndOfRedlines; }
169 : /// Regular ContentSection (i.e. the BodyText).
170 79148 : SwNode& GetEndOfContent() const { return *pEndOfContent; }
171 :
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;
175 :
176 : sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex) const;
177 : void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
178 :
179 : sal_Bool _MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
180 : sal_Bool bNewFrms = sal_True );
181 : void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
182 :
183 263 : void _Copy( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
184 : sal_Bool bNewFrms = sal_True ) const
185 263 : { _CopyNodes( rRg, rInsPos, bNewFrms ); }
186 :
187 : void SectionUp( SwNodeRange *);
188 : void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
189 :
190 : sal_Bool CheckNodesRange( const SwNodeIndex& rStt, const SwNodeIndex& rEnd ) const;
191 :
192 : void GoStartOfSection(SwNodeIndex *) const;
193 : void GoEndOfSection(SwNodeIndex *) const;
194 :
195 : SwCntntNode* GoNext(SwNodeIndex *) const;
196 : SwCntntNode* GoPrevious(SwNodeIndex *) const;
197 :
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;
202 :
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;
209 :
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 );
215 :
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 );
224 :
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
232 :
233 : SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
234 : const GraphicObject& rGrfObj,
235 : SwGrfFmtColl *pColl,
236 : SwAttrSet* pAutoAttr = 0 ); ///< in ndgrf.cxx
237 :
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
247 :
248 : /// Array of all OutlineNodes.
249 : const SwOutlineNodes& GetOutLineNds() const;
250 :
251 : //void UpdateOutlineNode( const SwNode&, sal_uInt8 nOldLevel, sal_uInt8 nNewLevel );//#outline level,removed by zhaojianwei
252 :
253 : /// Update all Nodes - Rule/Format-Change.
254 : void UpdateOutlineNode(SwNode & rNd);
255 :
256 : /** Insert nodes for tables. If Lines is given, create the matrix
257 : from lines and boxes, else only the count of boxes.
258 :
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. */
263 :
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);
269 :
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 );
277 :
278 : SwNodeRange * ExpandRangeForTableBox(const SwNodeRange & rRange);
279 :
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*/ );
287 :
288 :
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 );
295 :
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 );
314 :
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);
323 :
324 : /// Which Doc contains the nodes-array?
325 696972 : SwDoc* GetDoc() { return pMyDoc; }
326 738504 : const SwDoc* GetDoc() const { return pMyDoc; }
327 :
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;
334 :
335 : SwNode * DocumentSectionStartNode(SwNode * pNode) const;
336 : SwNode * DocumentSectionEndNode(SwNode * pNode) const;
337 :
338 : /**
339 : * Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by default)
340 : * @since 3.5
341 : */
342 : void dumpAsXml( xmlTextWriterPtr writer = NULL );
343 : };
344 :
345 : #endif
346 :
347 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|