xref: /aoo42x/main/sw/inc/ndarr.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SW_NDARR_HXX
29 #define SW_NDARR_HXX
30 
31 #include <vector>
32 
33 #include <boost/utility.hpp>
34 
35 #include <com/sun/star/embed/XEmbeddedObject.hpp>
36 
37 #include <svl/svarray.hxx>
38 #include <svtools/embedhlp.hxx>
39 
40 #include <bparr.hxx>
41 #include <ndtyp.hxx>
42 
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 // --------------------
79 // class SwNodes
80 // --------------------
81 
82 typedef SwNode * SwNodePtr;
83 typedef sal_Bool (*FnForEach_SwNodes)( const SwNodePtr&, void* pArgs );
84 
85 SV_DECL_PTRARR_SORT( SwOutlineNodes, SwNodePtr, 0, 10 )
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;					// Liste aller Indizies auf Nodes
96 
97     // --> OD 2008-05-14 #refactorlists# - removed <bSyncNumberAndNumRule>
98     void InsertNode( const SwNodePtr pNode,
99                      const SwNodeIndex& rPos );
100     void InsertNode( const SwNodePtr pNode,
101                      sal_uLong nPos );
102     // <--
103 
104 
105 	SwDoc* pMyDoc;						// in diesem Doc ist das Nodes-Array
106 
107 	SwNode *pEndOfPostIts, *pEndOfInserts, 	// das sind die festen Bereiche
108 		   *pEndOfAutotext, *pEndOfRedlines,
109 		   *pEndOfContent;
110 
111 	mutable SwOutlineNodes* pOutlineNds;		// Array aller GliederiungsNodes
112 
113 	sal_Bool bInNodesDel : 1;				// falls rekursiv aufgerufen wird
114 										// Num/Outline nicht aktualisierem
115 	sal_Bool bInDelUpdOutl : 1;				// Flags fuers aktualisieren von Outl.
116 	sal_Bool bInDelUpdNum : 1;				// Flags fuers aktualisieren von Outl.
117 
118 	// fuer dier Verwaltung der Indizies
119 	void RegisterIndex( SwNodeIndex& rIdx );
120 	void DeRegisterIndex( SwNodeIndex& rIdx );
121 	void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, sal_Bool bDel );
122 
123 	// Aktionen auf die Nodes
124 	void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
125 	void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
126 
127 	void ChgNode( SwNodeIndex& rDelPos, sal_uLong nSize,
128 				  SwNodeIndex& rInsPos, sal_Bool bNewFrms );
129 
130 	void UpdtOutlineIdx( const SwNode& );	// Update ab Node alle OutlineNodes
131 
132 	void _CopyNodes( const SwNodeRange&, const SwNodeIndex&,
133 					sal_Bool bNewFrms = sal_True, sal_Bool bTblInsDummyNode = sal_False ) const;
134 	void _DelDummyNodes( const SwNodeRange& rRg );
135 
136 protected:
137 	SwNodes( SwDoc* pDoc );
138 
139 public:
140 	~SwNodes();
141 
142     typedef ::std::vector<SwNodeRange> NodeRanges_t;
143     typedef ::std::vector<NodeRanges_t> TableRanges_t;
144 
145 	SwNodePtr operator[]( sal_uLong n ) const
146 		{ return (SwNodePtr)BigPtrArray::operator[] ( n ); }
147 
148 	sal_uLong Count() const { return BigPtrArray::Count(); }
149 	void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = 0 )
150 	{
151 		BigPtrArray::ForEach( 0, BigPtrArray::Count(),
152 								(FnForEach) fnForEach, pArgs );
153 	}
154 	void ForEach( sal_uLong nStt, sal_uLong nEnd, FnForEach_SwNodes fnForEach, void* pArgs = 0 )
155 	{
156 		BigPtrArray::ForEach( nStt, nEnd, (FnForEach) fnForEach, pArgs );
157 	}
158 	void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
159 					FnForEach_SwNodes fnForEach, void* pArgs = 0 );
160 
161 	// eine noch leere Section
162 	SwNode& GetEndOfPostIts() const 	{ return *pEndOfPostIts; }
163 	// Section fuer alle Fussnoten
164 	SwNode& GetEndOfInserts() const 	{ return *pEndOfInserts; }
165 	// Section fuer alle Flys/Header/Footers
166 	SwNode& GetEndOfAutotext() const 	{ return *pEndOfAutotext; }
167 	// Section fuer alle Redlines
168 	SwNode& GetEndOfRedlines() const 	{ return *pEndOfRedlines; }
169 	// das ist der letzte EndNode einer SonderSection. Hier nach kommt nur
170 	// noch die normale ContentSection (also der BodyText)
171 	SwNode& GetEndOfExtras() const 		{ return *pEndOfRedlines; }
172 	// die normale ContentSection (also der BodyText)
173 	SwNode& GetEndOfContent() const		{ return *pEndOfContent; }
174 
175 	// ist das NodesArray das normale vom Doc? (nicht das UndoNds, .. )
176 	// Implementierung steht im doc.hxx (weil man dazu Doc kennen muss) !
177     sal_Bool IsDocNodes() const;
178 
179 	sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex) const;
180 	void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
181 
182 	sal_Bool _MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
183 				sal_Bool bNewFrms = sal_True );
184     void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
185 
186 	void _Copy( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
187 				sal_Bool bNewFrms = sal_True ) const
188 		{   _CopyNodes( rRg, rInsPos, bNewFrms ); }
189 
190 	void SectionUp( SwNodeRange *);
191 	void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
192 
193 	sal_Bool CheckNodesRange( const SwNodeIndex& rStt, const SwNodeIndex& rEnd ) const;
194 
195 	void GoStartOfSection(SwNodeIndex *) const;
196 	void GoEndOfSection(SwNodeIndex *) const;
197 
198 	SwCntntNode* GoNext(SwNodeIndex *) const;
199 	SwCntntNode* GoPrevious(SwNodeIndex *) const;
200 
201 	//Gehe zum naechsten/vorherigen Cntnt/Tabellennode, fuer den
202 	//es LayoutFrames gibt, dabei Kopf-/Fusszeilen/Rahmen etc. nicht verlassen
203 	SwNode* GoNextWithFrm(SwNodeIndex *) const;
204 	SwNode* GoPreviousWithFrm(SwNodeIndex *) const;
205 
206 	// zum naechsten Content-Node, der nicht geschuetzt oder versteckt ist
207 	// (beides auf sal_False ==> GoNext/GoPrevious!!!)
208 	SwCntntNode* GoNextSection( SwNodeIndex *, int bSkipHidden  = sal_True,
209 										   int bSkipProtect = sal_True ) const;
210 	SwCntntNode* GoPrevSection( SwNodeIndex *, int bSkipHidden  = sal_True,
211 										   int bSkipProtect = sal_True ) const;
212 
213 	// erzeuge ein leere Section von Start und EndNode. Darf nur gerufen
214 	// werden, wenn eine neue Section mit Inhalt erzeugt werden soll.
215 	// Zum Beispiel bei den Filtern/Undo/...
216 	SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
217 									SwStartNodeType = SwNormalStartNode );
218 
219 	// die Impl. von "Make...Node" stehen in den angegebenen .ccx-Files
220 	SwTxtNode *MakeTxtNode( const SwNodeIndex & rWhere,
221 							SwTxtFmtColl *pColl,
222 							SwAttrSet* pAutoAttr = 0 );	// in ndtxt.cxx
223 	SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
224 							SwStartNodeType eSttNdTyp,
225 							SwTxtFmtColl *pColl,
226 							SwAttrSet* pAutoAttr = 0 );
227 
228 	SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
229 							const String& rGrfName,
230 							const String& rFltName,
231 							const Graphic* pGraphic,
232 							SwGrfFmtColl *pColl,
233 							SwAttrSet* pAutoAttr = 0,
234 							sal_Bool bDelayed = sal_False );	// in ndgrf.cxx
235 
236 	SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
237 							const GraphicObject& rGrfObj,
238 							SwGrfFmtColl *pColl,
239 							SwAttrSet* pAutoAttr = 0 );	// in ndgrf.cxx
240 
241 	SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
242                             const svt::EmbeddedObjectRef&,
243 							SwGrfFmtColl *pColl,
244 							SwAttrSet* pAutoAttr = 0 );	// in ndole.cxx
245 	SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
246 							const String &rName,
247 							sal_Int64 nAspect,
248 							SwGrfFmtColl *pColl,
249 							SwAttrSet* pAutoAttr );	// in ndole.cxx
250 
251 		// Array aller GliederiungsNodes;
252 	const SwOutlineNodes& GetOutLineNds() const;
253 
254 	//void UpdateOutlineNode( const SwNode&, sal_uInt8 nOldLevel, sal_uInt8 nNewLevel );//#outline level,removed by zhaojianwei
255 		// alle Nodes Updaten - Rule/Format-Aenderung
256     void UpdateOutlineNode(SwNode & rNd);
257 
258 		// fuege die Nodes fuer die Tabelle ein
259 		// wenn Lines angegeben, erzeuge die Matrix aus Lines & Boxen
260 		// ansonsten nur die Anzahl von Boxen.
261     /* #109161#
262 
263        New parameter pAttrSet: If pAttrSet is non-null and contains an
264        adjust item it is propagated to the table cells. If there is an
265        adjust in pCntntTxtColl or pHeadlineTxtColl this adjust item
266        overrides the item in pAttrSet.
267 
268      */
269 	SwTableNode* InsertTable( const SwNodeIndex& rNdIdx,
270 						sal_uInt16 nBoxes, SwTxtFmtColl* pCntntTxtColl,
271                         sal_uInt16 nLines = 0, sal_uInt16 nRepeat = 0,
272                         SwTxtFmtColl* pHeadlineTxtColl = 0,
273                         const SwAttrSet * pAttrSet = 0);
274 
275         // erzeuge aus dem makierten Bereich eine ausgeglichene Tabelle
276 	SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
277 								SwTableFmt* pTblFmt,
278 								SwTableLineFmt* pLineFmt,
279 								SwTableBoxFmt* pBoxFmt,
280 								SwTxtFmtColl* pTxtColl,
281 								SwUndoTxtToTbl* pUndo = 0 );
282 
283     SwNodeRange * ExpandRangeForTableBox(const SwNodeRange & rRange);
284 
285     //create a table from a vector of NodeRanges - API support
286     SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
287                                 SwTableFmt* pTblFmt,
288                                 SwTableLineFmt* pLineFmt,
289                                 SwTableBoxFmt* pBoxFmt,
290                                 SwTxtFmtColl* pTxtColl
291                                 /*, SwUndo... pUndo*/ );
292 
293 		// erzeuge aus der Tabelle wieder normalen Text
294 	sal_Bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
295 						SwUndoTblToTxt* = 0 );
296 		// steht im untbl.cxx und darf nur vom Undoobject gerufen werden
297 	SwTableNode* UndoTableToText( sal_uLong nStt, sal_uLong nEnd,
298 						const SwTblToTxtSaves& rSavedData );
299 
300 		// fuege in der Line, vor der InsPos eine neue Box ein. Das Format
301 		// wird von der nachfolgenden (vorhergenden;wenn an Ende) genommen
302 		// in der Line muss schon eine Box vorhanden sein !
303 	sal_Bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFmt*,
304 						// Formate fuer den TextNode der Box
305                         SwTxtFmtColl*, const SfxItemSet* pAutoAttr,
306 						sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
307 		// Splittet eine Tabelle in der Grund-Zeile, in der der Index steht.
308 		// Alle GrundZeilen dahinter wandern in eine neue Tabelle/-Node.
309 		// Ist das Flag bCalcNewSize auf sal_True, wird fuer beide neuen Tabellen
310 		// die neue SSize aus dem Max der Boxen errechnet; vorrausgesetzt,
311 		// die SSize ist "absolut" gesetzt (LONG_MAX)
312 		// (Wird zur Zeit nur fuer den RTF-Parser benoetigt)
313 	SwTableNode* SplitTable( const SwNodeIndex& rPos, sal_Bool bAfter = sal_True,
314 								sal_Bool bCalcNewSize = sal_False );
315 		// fuegt 2 Tabellen, die hintereinander stehen, wieder zusammen
316 	sal_Bool MergeTable( const SwNodeIndex& rPos, sal_Bool bWithPrev = sal_True,
317 					sal_uInt16 nMode = 0, SwHistory* pHistory = 0 );
318 
319 		// fuege eine neue SwSection ein
320     SwSectionNode* InsertTextSection(SwNodeIndex const& rNdIdx,
321 								SwSectionFmt& rSectionFmt,
322                                 SwSectionData const&,
323                                 SwTOXBase const*const pTOXBase,
324                                 SwNodeIndex const*const pEnde,
325                                 bool const bInsAtStart = true,
326                                 bool const bCreateFrms = true);
327 
328 		// in welchem Doc steht das Nodes-Array ?
329 			SwDoc* GetDoc()			{ return pMyDoc; }
330 	const	SwDoc* GetDoc() const	{ return pMyDoc; }
331 
332 		// suche den vorhergehenden [/nachfolgenden ] ContentNode oder
333 		// TabellenNode mit Frames. Wird kein Ende angeben, dann wird mit
334 		// dem FrameIndex begonnen; ansonsten, wird mit dem vor rFrmIdx und
335 		// dem hintern pEnd die Suche gestartet. Sollte kein gueltiger Node
336 		// gefunden werden, wird 0 returnt. rFrmIdx zeigt auf dem Node mit
337 		// Frames
338 	SwNode* FindPrvNxtFrmNode( SwNodeIndex& rFrmIdx,
339 								const SwNode* pEnd = 0 ) const;
340 
341     //-> #112139#
342     SwNode * DocumentSectionStartNode(SwNode * pNode) const;
343     SwNode * DocumentSectionEndNode(SwNode * pNode) const;
344     //<- #112139#
345 };
346 
347 #endif
348