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 : // class SwNodes
68 :
69 : typedef SwNode * SwNodePtr;
70 : typedef bool (*FnForEach_SwNodes)( const SwNodePtr&, void* pArgs );
71 : typedef struct _xmlTextWriter *xmlTextWriterPtr;
72 :
73 : struct CompareSwOutlineNodes
74 : {
75 : bool operator()( SwNode* const& lhs, SwNode* const& rhs) const;
76 : };
77 :
78 0 : class SwOutlineNodes : public o3tl::sorted_vector<SwNode*, CompareSwOutlineNodes>
79 : {
80 : public:
81 : bool Seek_Entry(SwNode* const &rP, sal_uInt16* pnPos) const;
82 : };
83 :
84 : class SW_DLLPUBLIC SwNodes
85 : : private BigPtrArray
86 : , private ::boost::noncopyable
87 : {
88 : friend class SwDoc;
89 : friend class SwNode;
90 : friend class SwNodeIndex;
91 :
92 : SwNodeIndex* pRoot; ///< List of all indices on nodes.
93 :
94 : void InsertNode( const SwNodePtr pNode,
95 : const SwNodeIndex& rPos );
96 : void InsertNode( const SwNodePtr pNode,
97 : sal_uLong nPos );
98 :
99 : SwDoc* pMyDoc; ///< This Doc contains the nodes-array.
100 :
101 : SwNode *pEndOfPostIts, *pEndOfInserts, ///< These are the fixed ranges.
102 : *pEndOfAutotext, *pEndOfRedlines,
103 : *pEndOfContent;
104 :
105 : mutable SwOutlineNodes* pOutlineNds; ///< Array of all outline nodes.
106 :
107 : sal_Bool bInNodesDel : 1; /**< In Case of recursive calling.
108 : Do not update Num/Outline. */
109 : sal_Bool bInDelUpdOutl : 1; ///< Flag for updating of Outline.
110 : sal_Bool bInDelUpdNum : 1; ///< Flag for updating of Outline.
111 :
112 : /// For administering indices.
113 : void RegisterIndex( SwNodeIndex& rIdx );
114 : void DeRegisterIndex( SwNodeIndex& rIdx );
115 : void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, sal_Bool bDel );
116 :
117 : // Actions on the nodes.
118 : void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
119 : void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
120 :
121 : void ChgNode( SwNodeIndex& rDelPos, sal_uLong nSize,
122 : SwNodeIndex& rInsPos, sal_Bool bNewFrms );
123 :
124 : void UpdtOutlineIdx( const SwNode& ); ///< Update all OutlineNodes starting from Node.
125 :
126 : void _CopyNodes( const SwNodeRange&, const SwNodeIndex&,
127 : sal_Bool bNewFrms = sal_True, sal_Bool bTblInsDummyNode = sal_False ) const;
128 : void _DelDummyNodes( const SwNodeRange& rRg );
129 :
130 : protected:
131 : SwNodes( SwDoc* pDoc );
132 :
133 : public:
134 : ~SwNodes();
135 :
136 : typedef ::std::vector<SwNodeRange> NodeRanges_t;
137 : typedef ::std::vector<NodeRanges_t> TableRanges_t;
138 :
139 0 : SwNodePtr operator[]( sal_uLong n ) const
140 0 : { return (SwNodePtr)BigPtrArray::operator[] ( n ); }
141 :
142 0 : sal_uLong Count() const { return BigPtrArray::Count(); }
143 0 : void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = 0 )
144 : {
145 : BigPtrArray::ForEach( 0, BigPtrArray::Count(),
146 0 : (FnForEach) fnForEach, pArgs );
147 0 : }
148 0 : void ForEach( sal_uLong nStt, sal_uLong nEnd, FnForEach_SwNodes fnForEach, void* pArgs = 0 )
149 : {
150 0 : BigPtrArray::ForEach( nStt, nEnd, (FnForEach) fnForEach, pArgs );
151 0 : }
152 : void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
153 : FnForEach_SwNodes fnForEach, void* pArgs = 0 );
154 :
155 : /// A still empty section.
156 0 : SwNode& GetEndOfPostIts() const { return *pEndOfPostIts; }
157 : /// Section fpr all footnotes.
158 0 : SwNode& GetEndOfInserts() const { return *pEndOfInserts; }
159 : /// Section for all Flys/Header/Footers.
160 0 : SwNode& GetEndOfAutotext() const { return *pEndOfAutotext; }
161 : /// Section for all Redlines.
162 0 : 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 0 : SwNode& GetEndOfExtras() const { return *pEndOfRedlines; }
166 : /// Regular ContentSection (i.e. the BodyText).
167 0 : 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 : sal_Bool IsDocNodes() const;
172 :
173 : sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex) const;
174 : void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
175 :
176 : sal_Bool _MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
177 : sal_Bool bNewFrms = sal_True );
178 : void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
179 :
180 0 : void _Copy( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
181 : sal_Bool bNewFrms = sal_True ) const
182 0 : { _CopyNodes( rRg, rInsPos, bNewFrms ); }
183 :
184 : void SectionUp( SwNodeRange *);
185 : void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
186 :
187 : sal_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 : sal_Bool bDelayed = sal_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 : const SwOutlineNodes& GetOutLineNds() const;
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 : sal_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 : sal_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, sal_Bool bAfter = sal_True,
304 : sal_Bool bCalcNewSize = sal_False );
305 : /// Two Tables that are following one another are merged.
306 : sal_Bool MergeTable( const SwNodeIndex& rPos, sal_Bool bWithPrev = sal_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 0 : SwDoc* GetDoc() { return pMyDoc; }
320 0 : 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 );
337 : };
338 :
339 : #endif
340 :
341 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|