xref: /AOO41X/main/sw/inc/ndarr.hxx (revision 1d2dbeb0b7301723c6d13094e87a8714ef81a328)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SW_NDARR_HXX
25 #define SW_NDARR_HXX
26 
27 #include <vector>
28 
29 #include <boost/utility.hpp>
30 
31 #include <com/sun/star/embed/XEmbeddedObject.hpp>
32 
33 #include <svl/svarray.hxx>
34 #include <svtools/embedhlp.hxx>
35 
36 #include <bparr.hxx>
37 #include <ndtyp.hxx>
38 
39 
40 class Graphic;
41 class GraphicObject;
42 class String;
43 class SwAttrSet;
44 class SfxItemSet;
45 class SwCntntNode;
46 class SwDoc;
47 class SwGrfFmtColl;
48 class SwGrfNode;
49 class SwHistory;
50 class SwNode;
51 class SwNodeIndex;
52 class SwNodeRange;
53 class SwOLENode;
54 class SwOutlineNodes;
55 class SwPaM;
56 class SwSectionData;
57 class SwSectionFmt;
58 class SwTOXBase;
59 class SwSectionNode;
60 class SwStartNode;
61 class SwTableBoxFmt;
62 class SwTableFmt;
63 class SwTableLine;
64 class SwTableLineFmt;
65 class SwTableNode;
66 class SwTblToTxtSaves;
67 class SwTxtFmtColl;
68 class SwTxtNode;
69 class SwUndoTblToTxt;
70 class SwUndoTxtToTbl;
71 struct SwPosition;
72 
73 
74 // --------------------
75 // class SwNodes
76 // --------------------
77 
78 typedef SwNode * SwNodePtr;
79 typedef sal_Bool (*FnForEach_SwNodes)( const SwNodePtr&, void* pArgs );
80 
81 SV_DECL_PTRARR_SORT( SwOutlineNodes, SwNodePtr, 0, 10 )
82 
83 class SW_DLLPUBLIC SwNodes
84     : private BigPtrArray
85     , private ::boost::noncopyable
86 {
87     friend class SwDoc;
88     friend class SwNode;
89     friend class SwNodeIndex;
90 
91     SwNodeIndex* pRoot;                 // Liste aller Indizies auf Nodes
92 
93     // --> OD 2008-05-14 #refactorlists# - removed <bSyncNumberAndNumRule>
94     void InsertNode( const SwNodePtr pNode,
95                      const SwNodeIndex& rPos );
96     void InsertNode( const SwNodePtr pNode,
97                      sal_uLong nPos );
98     // <--
99 
100 
101     SwDoc* pMyDoc;                      // in diesem Doc ist das Nodes-Array
102 
103     SwNode *pEndOfPostIts, *pEndOfInserts,  // das sind die festen Bereiche
104            *pEndOfAutotext, *pEndOfRedlines,
105            *pEndOfContent;
106 
107     mutable SwOutlineNodes* pOutlineNds;        // Array aller GliederiungsNodes
108 
109     sal_Bool bInNodesDel : 1;               // falls rekursiv aufgerufen wird
110                                         // Num/Outline nicht aktualisierem
111     sal_Bool bInDelUpdOutl : 1;             // Flags fuers aktualisieren von Outl.
112     sal_Bool bInDelUpdNum : 1;              // Flags fuers aktualisieren von Outl.
113 
114     // fuer dier Verwaltung der Indizies
115     void RegisterIndex( SwNodeIndex& rIdx );
116     void DeRegisterIndex( SwNodeIndex& rIdx );
117     void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, sal_Bool bDel );
118 
119     // Aktionen auf die Nodes
120     void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
121     void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
122 
123     void ChgNode( SwNodeIndex& rDelPos, sal_uLong nSize,
124                   SwNodeIndex& rInsPos, sal_Bool bNewFrms );
125 
126     void UpdtOutlineIdx( const SwNode& );   // Update ab Node alle OutlineNodes
127 
128     void _CopyNodes( const SwNodeRange&, const SwNodeIndex&,
129                     sal_Bool bNewFrms = sal_True, sal_Bool bTblInsDummyNode = sal_False ) const;
130     void _DelDummyNodes( const SwNodeRange& rRg );
131 
132 protected:
133     SwNodes( SwDoc* pDoc );
134 
135 public:
136     ~SwNodes();
137 
138     typedef ::std::vector<SwNodeRange> NodeRanges_t;
139     typedef ::std::vector<NodeRanges_t> TableRanges_t;
140 
operator [](sal_uLong n) const141     SwNodePtr operator[]( sal_uLong n ) const
142         { return (SwNodePtr)BigPtrArray::operator[] ( n ); }
143 
Count() const144     sal_uLong Count() const { return BigPtrArray::Count(); }
ForEach(FnForEach_SwNodes fnForEach,void * pArgs=0)145     void ForEach( FnForEach_SwNodes fnForEach, void* pArgs = 0 )
146     {
147         BigPtrArray::ForEach( 0, BigPtrArray::Count(),
148                                 (FnForEach) fnForEach, pArgs );
149     }
ForEach(sal_uLong nStt,sal_uLong nEnd,FnForEach_SwNodes fnForEach,void * pArgs=0)150     void ForEach( sal_uLong nStt, sal_uLong nEnd, FnForEach_SwNodes fnForEach, void* pArgs = 0 )
151     {
152         BigPtrArray::ForEach( nStt, nEnd, (FnForEach) fnForEach, pArgs );
153     }
154     void ForEach( const SwNodeIndex& rStart, const SwNodeIndex& rEnd,
155                     FnForEach_SwNodes fnForEach, void* pArgs = 0 );
156 
157     // eine noch leere Section
GetEndOfPostIts() const158     SwNode& GetEndOfPostIts() const     { return *pEndOfPostIts; }
159     // Section fuer alle Fussnoten
GetEndOfInserts() const160     SwNode& GetEndOfInserts() const     { return *pEndOfInserts; }
161     // Section fuer alle Flys/Header/Footers
GetEndOfAutotext() const162     SwNode& GetEndOfAutotext() const    { return *pEndOfAutotext; }
163     // Section fuer alle Redlines
GetEndOfRedlines() const164     SwNode& GetEndOfRedlines() const    { return *pEndOfRedlines; }
165     // das ist der letzte EndNode einer SonderSection. Hier nach kommt nur
166     // noch die normale ContentSection (also der BodyText)
GetEndOfExtras() const167     SwNode& GetEndOfExtras() const      { return *pEndOfRedlines; }
168     // die normale ContentSection (also der BodyText)
GetEndOfContent() const169     SwNode& GetEndOfContent() const     { return *pEndOfContent; }
170 
171     // ist das NodesArray das normale vom Doc? (nicht das UndoNds, .. )
172     // Implementierung steht im doc.hxx (weil man dazu Doc kennen muss) !
173     sal_Bool IsDocNodes() const;
174 
175     sal_uInt16 GetSectionLevel(const SwNodeIndex &rIndex) const;
176     void Delete(const SwNodeIndex &rPos, sal_uLong nNodes = 1);
177 
178     sal_Bool _MoveNodes( const SwNodeRange&, SwNodes& rNodes, const SwNodeIndex&,
179                 sal_Bool bNewFrms = sal_True );
180     void MoveRange( SwPaM&, SwPosition&, SwNodes& rNodes );
181 
_Copy(const SwNodeRange & rRg,const SwNodeIndex & rInsPos,sal_Bool bNewFrms=sal_True) const182     void _Copy( const SwNodeRange& rRg, const SwNodeIndex& rInsPos,
183                 sal_Bool bNewFrms = sal_True ) const
184         {   _CopyNodes( rRg, rInsPos, bNewFrms ); }
185 
186     void SectionUp( SwNodeRange *);
187     void SectionDown( SwNodeRange *pRange, SwStartNodeType = SwNormalStartNode );
188 
189     sal_Bool CheckNodesRange( const SwNodeIndex& rStt, const SwNodeIndex& rEnd ) const;
190 
191     void GoStartOfSection(SwNodeIndex *) const;
192     void GoEndOfSection(SwNodeIndex *) const;
193 
194     SwCntntNode* GoNext(SwNodeIndex *) const;
195     SwCntntNode* GoPrevious(SwNodeIndex *) const;
196 
197     //Gehe zum naechsten/vorherigen Cntnt/Tabellennode, fuer den
198     //es LayoutFrames gibt, dabei Kopf-/Fusszeilen/Rahmen etc. nicht verlassen
199     SwNode* GoNextWithFrm(SwNodeIndex *) const;
200     SwNode* GoPreviousWithFrm(SwNodeIndex *) const;
201 
202     // zum naechsten Content-Node, der nicht geschuetzt oder versteckt ist
203     // (beides auf sal_False ==> GoNext/GoPrevious!!!)
204     SwCntntNode* GoNextSection( SwNodeIndex *, int bSkipHidden  = sal_True,
205                                            int bSkipProtect = sal_True ) const;
206     SwCntntNode* GoPrevSection( SwNodeIndex *, int bSkipHidden  = sal_True,
207                                            int bSkipProtect = sal_True ) const;
208 
209     // erzeuge ein leere Section von Start und EndNode. Darf nur gerufen
210     // werden, wenn eine neue Section mit Inhalt erzeugt werden soll.
211     // Zum Beispiel bei den Filtern/Undo/...
212     SwStartNode* MakeEmptySection( const SwNodeIndex& rIdx,
213                                     SwStartNodeType = SwNormalStartNode );
214 
215     // die Impl. von "Make...Node" stehen in den angegebenen .ccx-Files
216     SwTxtNode *MakeTxtNode( const SwNodeIndex & rWhere,
217                             SwTxtFmtColl *pColl,
218                             SwAttrSet* pAutoAttr = 0 ); // in ndtxt.cxx
219     SwStartNode* MakeTextSection( const SwNodeIndex & rWhere,
220                             SwStartNodeType eSttNdTyp,
221                             SwTxtFmtColl *pColl,
222                             SwAttrSet* pAutoAttr = 0 );
223 
224     SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
225                             const String& rGrfName,
226                             const String& rFltName,
227                             const Graphic* pGraphic,
228                             SwGrfFmtColl *pColl,
229                             SwAttrSet* pAutoAttr = 0,
230                             sal_Bool bDelayed = sal_False );    // in ndgrf.cxx
231 
232     SwGrfNode *MakeGrfNode( const SwNodeIndex & rWhere,
233                             const GraphicObject& rGrfObj,
234                             SwGrfFmtColl *pColl,
235                             SwAttrSet* pAutoAttr = 0 ); // in ndgrf.cxx
236 
237     SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
238                             const svt::EmbeddedObjectRef&,
239                             SwGrfFmtColl *pColl,
240                             SwAttrSet* pAutoAttr = 0 ); // in ndole.cxx
241     SwOLENode *MakeOLENode( const SwNodeIndex & rWhere,
242                             const String &rName,
243                             sal_Int64 nAspect,
244                             SwGrfFmtColl *pColl,
245                             SwAttrSet* pAutoAttr ); // in ndole.cxx
246 
247         // Array aller GliederiungsNodes;
248     const SwOutlineNodes& GetOutLineNds() const;
249 
250     //void UpdateOutlineNode( const SwNode&, sal_uInt8 nOldLevel, sal_uInt8 nNewLevel );//#outline level,removed by zhaojianwei
251         // alle Nodes Updaten - Rule/Format-Aenderung
252     void UpdateOutlineNode(SwNode & rNd);
253 
254         // fuege die Nodes fuer die Tabelle ein
255         // wenn Lines angegeben, erzeuge die Matrix aus Lines & Boxen
256         // ansonsten nur die Anzahl von Boxen.
257     /* #109161#
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      */
265     SwTableNode* InsertTable( const SwNodeIndex& rNdIdx,
266                         sal_uInt16 nBoxes, SwTxtFmtColl* pCntntTxtColl,
267                         sal_uInt16 nLines = 0, sal_uInt16 nRepeat = 0,
268                         SwTxtFmtColl* pHeadlineTxtColl = 0,
269                         const SwAttrSet * pAttrSet = 0);
270 
271         // erzeuge aus dem makierten Bereich eine ausgeglichene Tabelle
272     SwTableNode* TextToTable( const SwNodeRange& rRange, sal_Unicode cCh,
273                                 SwTableFmt* pTblFmt,
274                                 SwTableLineFmt* pLineFmt,
275                                 SwTableBoxFmt* pBoxFmt,
276                                 SwTxtFmtColl* pTxtColl,
277                                 SwUndoTxtToTbl* pUndo = 0 );
278 
279     SwNodeRange * ExpandRangeForTableBox(const SwNodeRange & rRange);
280 
281     //create a table from a vector of NodeRanges - API support
282     SwTableNode* TextToTable( const TableRanges_t& rTableNodes,
283                                 SwTableFmt* pTblFmt,
284                                 SwTableLineFmt* pLineFmt,
285                                 SwTableBoxFmt* pBoxFmt,
286                                 SwTxtFmtColl* pTxtColl
287                                 /*, SwUndo... pUndo*/ );
288 
289         // erzeuge aus der Tabelle wieder normalen Text
290     sal_Bool TableToText( const SwNodeRange& rRange, sal_Unicode cCh,
291                         SwUndoTblToTxt* = 0 );
292         // steht im untbl.cxx und darf nur vom Undoobject gerufen werden
293     SwTableNode* UndoTableToText( sal_uLong nStt, sal_uLong nEnd,
294                         const SwTblToTxtSaves& rSavedData );
295 
296         // fuege in der Line, vor der InsPos eine neue Box ein. Das Format
297         // wird von der nachfolgenden (vorhergenden;wenn an Ende) genommen
298         // in der Line muss schon eine Box vorhanden sein !
299     sal_Bool InsBoxen( SwTableNode*, SwTableLine*, SwTableBoxFmt*,
300                         // Formate fuer den TextNode der Box
301                         SwTxtFmtColl*, const SfxItemSet* pAutoAttr,
302                         sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
303         // Splittet eine Tabelle in der Grund-Zeile, in der der Index steht.
304         // Alle GrundZeilen dahinter wandern in eine neue Tabelle/-Node.
305         // Ist das Flag bCalcNewSize auf sal_True, wird fuer beide neuen Tabellen
306         // die neue SSize aus dem Max der Boxen errechnet; vorrausgesetzt,
307         // die SSize ist "absolut" gesetzt (LONG_MAX)
308         // (Wird zur Zeit nur fuer den RTF-Parser benoetigt)
309     SwTableNode* SplitTable( const SwNodeIndex& rPos, sal_Bool bAfter = sal_True,
310                                 sal_Bool bCalcNewSize = sal_False );
311         // fuegt 2 Tabellen, die hintereinander stehen, wieder zusammen
312     sal_Bool MergeTable( const SwNodeIndex& rPos, sal_Bool bWithPrev = sal_True,
313                     sal_uInt16 nMode = 0, SwHistory* pHistory = 0 );
314 
315         // fuege eine neue SwSection ein
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         // in welchem Doc steht das Nodes-Array ?
GetDoc()325             SwDoc* GetDoc()         { return pMyDoc; }
GetDoc() const326     const   SwDoc* GetDoc() const   { return pMyDoc; }
327 
328         // suche den vorhergehenden [/nachfolgenden ] ContentNode oder
329         // TabellenNode mit Frames. Wird kein Ende angeben, dann wird mit
330         // dem FrameIndex begonnen; ansonsten, wird mit dem vor rFrmIdx und
331         // dem hintern pEnd die Suche gestartet. Sollte kein gueltiger Node
332         // gefunden werden, wird 0 returnt. rFrmIdx zeigt auf dem Node mit
333         // Frames
334     SwNode* FindPrvNxtFrmNode( SwNodeIndex& rFrmIdx,
335                                 const SwNode* pEnd = 0 ) const;
336 
337     //-> #112139#
338     SwNode * DocumentSectionStartNode(SwNode * pNode) const;
339     SwNode * DocumentSectionEndNode(SwNode * pNode) const;
340     //<- #112139#
341 };
342 
343 #endif
344