1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #define _ZFORLIST_DECLARE_TABLE
31cdf0e10cSrcweir #include <svl/zforlist.hxx>
32cdf0e10cSrcweir #include <frmfmt.hxx>
33cdf0e10cSrcweir #include <doc.hxx>
34cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
35cdf0e10cSrcweir #include <cntfrm.hxx>
36cdf0e10cSrcweir #include <pam.hxx>
37cdf0e10cSrcweir #include <swtable.hxx>
38cdf0e10cSrcweir #include <ndtxt.hxx>
39cdf0e10cSrcweir #include <fldbas.hxx>
40cdf0e10cSrcweir #include <tblsel.hxx>
41cdf0e10cSrcweir #include <tabfrm.hxx>
42cdf0e10cSrcweir #include <poolfmt.hxx>
43cdf0e10cSrcweir #include <cellatr.hxx>
44cdf0e10cSrcweir #include <mvsave.hxx>
45cdf0e10cSrcweir #include <docary.hxx>
46cdf0e10cSrcweir #include <fmtanchr.hxx>
47cdf0e10cSrcweir #include <hints.hxx>
48cdf0e10cSrcweir #include <UndoTable.hxx>
49cdf0e10cSrcweir #include <redline.hxx>
50cdf0e10cSrcweir #include <fmtfsize.hxx>
51cdf0e10cSrcweir #include <list>
52cdf0e10cSrcweir
53cdf0e10cSrcweir sal_Bool _FndCntntLine( const SwTableLine*& rpLine, void* pPara );
54cdf0e10cSrcweir sal_Bool _FndCntntBox( const SwTableBox*& rpBox, void* pPara );
55cdf0e10cSrcweir void lcl_CpyBox( const SwTable& rCpyTbl, const SwTableBox* pCpyBox,
56cdf0e10cSrcweir SwTable& rDstTbl, SwTableBox* pDstBox,
57cdf0e10cSrcweir sal_Bool bDelCntnt, SwUndoTblCpyTbl* pUndo );
58cdf0e10cSrcweir
59cdf0e10cSrcweir // The following type will be used by table copy functions to describe
60cdf0e10cSrcweir // the structure of tables (or parts of tables).
61cdf0e10cSrcweir // It's for new table model only.
62cdf0e10cSrcweir
63cdf0e10cSrcweir namespace
64cdf0e10cSrcweir {
65cdf0e10cSrcweir struct BoxSpanInfo
66cdf0e10cSrcweir {
67cdf0e10cSrcweir SwTableBox* mpBox;
68cdf0e10cSrcweir SwTableBox* mpCopy;
69cdf0e10cSrcweir sal_uInt16 mnColSpan;
70cdf0e10cSrcweir bool mbSelected;
71cdf0e10cSrcweir };
72cdf0e10cSrcweir
73cdf0e10cSrcweir typedef std::vector< BoxSpanInfo > BoxStructure;
74cdf0e10cSrcweir typedef std::vector< BoxStructure > LineStructure;
75cdf0e10cSrcweir typedef std::list< sal_uLong > ColumnStructure;
76cdf0e10cSrcweir
77cdf0e10cSrcweir struct SubBox
78cdf0e10cSrcweir {
79cdf0e10cSrcweir SwTableBox *mpBox;
80cdf0e10cSrcweir bool mbCovered;
81cdf0e10cSrcweir };
82cdf0e10cSrcweir
83cdf0e10cSrcweir typedef std::list< SubBox > SubLine;
84cdf0e10cSrcweir typedef std::list< SubLine > SubTable;
85cdf0e10cSrcweir
86cdf0e10cSrcweir class TableStructure
87cdf0e10cSrcweir {
88cdf0e10cSrcweir public:
89cdf0e10cSrcweir LineStructure maLines;
90cdf0e10cSrcweir ColumnStructure maCols;
91cdf0e10cSrcweir sal_uInt16 mnStartCol;
92cdf0e10cSrcweir sal_uInt16 mnAddLine;
93cdf0e10cSrcweir void addLine( sal_uInt16 &rLine, const SwTableBoxes&, const SwSelBoxes*,
94cdf0e10cSrcweir bool bNewModel );
95cdf0e10cSrcweir void addBox( sal_uInt16 nLine, const SwSelBoxes*, SwTableBox *pBox,
96cdf0e10cSrcweir sal_uLong &rnB, sal_uInt16 &rnC, ColumnStructure::iterator& rpCl,
97cdf0e10cSrcweir BoxStructure::iterator& rpSel, bool &rbSel, bool bCover );
98cdf0e10cSrcweir void incColSpan( sal_uInt16 nLine, sal_uInt16 nCol );
99cdf0e10cSrcweir TableStructure( const SwTable& rTable );
100cdf0e10cSrcweir TableStructure( const SwTable& rTable, _FndBox &rFndBox,
101cdf0e10cSrcweir const SwSelBoxes& rSelBoxes,
102cdf0e10cSrcweir LineStructure::size_type nMinSize );
getLineCount() const103cdf0e10cSrcweir LineStructure::size_type getLineCount() const
104cdf0e10cSrcweir { return maLines.size(); }
105cdf0e10cSrcweir void moreLines( const SwTable& rTable );
106cdf0e10cSrcweir void assignBoxes( const TableStructure &rSource );
107cdf0e10cSrcweir void copyBoxes( const SwTable& rSource, SwTable& rDstTbl,
108cdf0e10cSrcweir SwUndoTblCpyTbl* pUndo ) const;
109cdf0e10cSrcweir };
110cdf0e10cSrcweir
111cdf0e10cSrcweir SubTable::iterator insertSubLine( SubTable& rSubTable, SwTableLine& rLine,
112cdf0e10cSrcweir SubTable::iterator pStartLn );
113cdf0e10cSrcweir
insertSubBox(SubTable & rSubTable,SwTableBox & rBox,SubTable::iterator pStartLn,SubTable::iterator pEndLn)114cdf0e10cSrcweir SubTable::iterator insertSubBox( SubTable& rSubTable, SwTableBox& rBox,
115cdf0e10cSrcweir SubTable::iterator pStartLn, SubTable::iterator pEndLn )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir if( rBox.GetTabLines().Count() )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir SubTable::difference_type nSize = std::distance( pStartLn, pEndLn );
120cdf0e10cSrcweir if( nSize < rBox.GetTabLines().Count() )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir SubLine aSubLine;
123cdf0e10cSrcweir SubLine::iterator pBox = pStartLn->begin();
124cdf0e10cSrcweir SubLine::iterator pEnd = pStartLn->end();
125cdf0e10cSrcweir while( pBox != pEnd )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir SubBox aSub;
128cdf0e10cSrcweir aSub.mpBox = pBox->mpBox;
129cdf0e10cSrcweir aSub.mbCovered = true;
130cdf0e10cSrcweir aSubLine.push_back( aSub );
131cdf0e10cSrcweir ++pBox;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir do
134cdf0e10cSrcweir {
135cdf0e10cSrcweir rSubTable.insert( pEndLn, aSubLine );
136cdf0e10cSrcweir } while( ++nSize < rBox.GetTabLines().Count() );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir for( sal_uInt16 nLine = 0; nLine < rBox.GetTabLines().Count(); ++nLine )
139cdf0e10cSrcweir pStartLn = insertSubLine( rSubTable, *rBox.GetTabLines()[nLine],
140cdf0e10cSrcweir pStartLn );
141cdf0e10cSrcweir ASSERT( pStartLn == pEndLn, "Sub line confusion" );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir else
144cdf0e10cSrcweir {
145cdf0e10cSrcweir SubBox aSub;
146cdf0e10cSrcweir aSub.mpBox = &rBox;
147cdf0e10cSrcweir aSub.mbCovered = false;
148cdf0e10cSrcweir while( pStartLn != pEndLn )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir pStartLn->push_back( aSub );
151cdf0e10cSrcweir aSub.mbCovered = true;
152cdf0e10cSrcweir ++pStartLn;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir return pStartLn;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
insertSubLine(SubTable & rSubTable,SwTableLine & rLine,SubTable::iterator pStartLn)158cdf0e10cSrcweir SubTable::iterator insertSubLine( SubTable& rSubTable, SwTableLine& rLine,
159cdf0e10cSrcweir SubTable::iterator pStartLn )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir SubTable::iterator pMax = pStartLn;
162cdf0e10cSrcweir ++pMax;
163cdf0e10cSrcweir SubTable::difference_type nMax = 1;
164cdf0e10cSrcweir for( sal_uInt16 nBox = 0; nBox < rLine.GetTabBoxes().Count(); ++nBox )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir SubTable::iterator pTmp = insertSubBox( rSubTable,
167cdf0e10cSrcweir *rLine.GetTabBoxes()[nBox], pStartLn, pMax );
168cdf0e10cSrcweir SubTable::difference_type nTmp = std::distance( pStartLn, pTmp );
169cdf0e10cSrcweir if( nTmp > nMax )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir pMax = pTmp;
172cdf0e10cSrcweir nMax = nTmp;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir }
175cdf0e10cSrcweir return pMax;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
TableStructure(const SwTable & rTable)178cdf0e10cSrcweir TableStructure::TableStructure( const SwTable& rTable ) :
179cdf0e10cSrcweir maLines( rTable.GetTabLines().Count() ), mnStartCol(USHRT_MAX),
180cdf0e10cSrcweir mnAddLine(0)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir maCols.push_front(0);
183cdf0e10cSrcweir const SwTableLines &rLines = rTable.GetTabLines();
184cdf0e10cSrcweir sal_uInt16 nCnt = 0;
185cdf0e10cSrcweir for( sal_uInt16 nLine = 0; nLine < rLines.Count(); ++nLine )
186cdf0e10cSrcweir addLine( nCnt, rLines[nLine]->GetTabBoxes(), 0, rTable.IsNewModel() );
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
TableStructure(const SwTable & rTable,_FndBox & rFndBox,const SwSelBoxes & rSelBoxes,LineStructure::size_type nMinSize)189cdf0e10cSrcweir TableStructure::TableStructure( const SwTable& rTable,
190cdf0e10cSrcweir _FndBox &rFndBox, const SwSelBoxes& rSelBoxes,
191cdf0e10cSrcweir LineStructure::size_type nMinSize )
192cdf0e10cSrcweir : mnStartCol(USHRT_MAX), mnAddLine(0)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir if( rFndBox.GetLines().Count() )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir bool bNoSelection = rSelBoxes.Count() < 2;
197cdf0e10cSrcweir _FndLines &rFndLines = rFndBox.GetLines();
198cdf0e10cSrcweir maCols.push_front(0);
199cdf0e10cSrcweir const SwTableLine* pLine = rFndLines[0]->GetLine();
200cdf0e10cSrcweir sal_uInt16 nStartLn = rTable.GetTabLines().C40_GETPOS( SwTableLine, pLine );
201cdf0e10cSrcweir sal_uInt16 nEndLn = nStartLn;
202cdf0e10cSrcweir if( rFndLines.Count() > 1 )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir pLine = rFndLines[ rFndLines.Count()-1 ]->GetLine();
205cdf0e10cSrcweir nEndLn = rTable.GetTabLines().C40_GETPOS( SwTableLine, pLine );
206cdf0e10cSrcweir }
207cdf0e10cSrcweir if( nStartLn < USHRT_MAX && nEndLn < USHRT_MAX )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir const SwTableLines &rLines = rTable.GetTabLines();
210cdf0e10cSrcweir if( bNoSelection &&
211cdf0e10cSrcweir (sal_uInt16)nMinSize > nEndLn - nStartLn + 1 )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir sal_uInt16 nNewEndLn = nStartLn + (sal_uInt16)nMinSize - 1;
214cdf0e10cSrcweir if( nNewEndLn >= rLines.Count() )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir mnAddLine = nNewEndLn - rLines.Count() + 1;
217cdf0e10cSrcweir nNewEndLn = rLines.Count() - 1;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir while( nEndLn < nNewEndLn )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir SwTableLine *pLine2 = rLines[ ++nEndLn ];
222cdf0e10cSrcweir SwTableBox *pTmpBox = pLine2->GetTabBoxes()[0];
223cdf0e10cSrcweir _FndLine *pInsLine = new _FndLine( pLine2, &rFndBox );
224cdf0e10cSrcweir _FndBox *pFndBox = new _FndBox( pTmpBox, pInsLine );
225cdf0e10cSrcweir pInsLine->GetBoxes().C40_INSERT( _FndBox, pFndBox, 0 );
226cdf0e10cSrcweir rFndLines.C40_INSERT( _FndLine, pInsLine, rFndLines.Count() );
227cdf0e10cSrcweir }
228cdf0e10cSrcweir }
229cdf0e10cSrcweir maLines.resize( nEndLn - nStartLn + 1 );
230cdf0e10cSrcweir const SwSelBoxes* pSelBoxes = &rSelBoxes;
231cdf0e10cSrcweir sal_uInt16 nCnt = 0;
232cdf0e10cSrcweir for( sal_uInt16 nLine = nStartLn; nLine <= nEndLn; ++nLine )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir addLine( nCnt, rLines[nLine]->GetTabBoxes(),
235cdf0e10cSrcweir pSelBoxes, rTable.IsNewModel() );
236cdf0e10cSrcweir if( bNoSelection )
237cdf0e10cSrcweir pSelBoxes = 0;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir if( bNoSelection && mnStartCol < USHRT_MAX )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir BoxStructure::iterator pC = maLines[0].begin();
243cdf0e10cSrcweir BoxStructure::iterator pEnd = maLines[0].end();
244cdf0e10cSrcweir sal_uInt16 nIdx = mnStartCol;
245cdf0e10cSrcweir mnStartCol = 0;
246cdf0e10cSrcweir while( nIdx && pC != pEnd )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir mnStartCol = mnStartCol + pC->mnColSpan;
249cdf0e10cSrcweir --nIdx;
250cdf0e10cSrcweir ++pC;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir }
253cdf0e10cSrcweir else
254cdf0e10cSrcweir mnStartCol = USHRT_MAX;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir }
257cdf0e10cSrcweir
addLine(sal_uInt16 & rLine,const SwTableBoxes & rBoxes,const SwSelBoxes * pSelBoxes,bool bNewModel)258cdf0e10cSrcweir void TableStructure::addLine( sal_uInt16 &rLine, const SwTableBoxes& rBoxes,
259cdf0e10cSrcweir const SwSelBoxes* pSelBoxes, bool bNewModel )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir bool bComplex = false;
262cdf0e10cSrcweir if( !bNewModel )
263cdf0e10cSrcweir for( sal_uInt16 nBox = 0; !bComplex && nBox < rBoxes.Count(); ++nBox )
264cdf0e10cSrcweir bComplex = rBoxes[nBox]->GetTabLines().Count() > 0;
265cdf0e10cSrcweir if( bComplex )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir SubTable aSubTable;
268cdf0e10cSrcweir SubLine aSubLine;
269cdf0e10cSrcweir aSubTable.push_back( aSubLine );
270cdf0e10cSrcweir SubTable::iterator pStartLn = aSubTable.begin();
271cdf0e10cSrcweir SubTable::iterator pEndLn = aSubTable.end();
272cdf0e10cSrcweir for( sal_uInt16 nBox = 0; nBox < rBoxes.Count(); ++nBox )
273cdf0e10cSrcweir insertSubBox( aSubTable, *rBoxes[nBox], pStartLn, pEndLn );
274cdf0e10cSrcweir SubTable::size_type nSize = aSubTable.size();
275cdf0e10cSrcweir if( nSize )
276cdf0e10cSrcweir {
277cdf0e10cSrcweir maLines.resize( maLines.size() + nSize - 1 );
278cdf0e10cSrcweir while( pStartLn != pEndLn )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir bool bSelected = false;
281cdf0e10cSrcweir sal_uLong nBorder = 0;
282cdf0e10cSrcweir sal_uInt16 nCol = 0;
283cdf0e10cSrcweir maLines[rLine].reserve( pStartLn->size() );
284cdf0e10cSrcweir BoxStructure::iterator pSel = maLines[rLine].end();
285cdf0e10cSrcweir ColumnStructure::iterator pCol = maCols.begin();
286cdf0e10cSrcweir SubLine::iterator pBox = pStartLn->begin();
287cdf0e10cSrcweir SubLine::iterator pEnd = pStartLn->end();
288cdf0e10cSrcweir while( pBox != pEnd )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir addBox( rLine, pSelBoxes, pBox->mpBox, nBorder, nCol,
291cdf0e10cSrcweir pCol, pSel, bSelected, pBox->mbCovered );
292cdf0e10cSrcweir ++pBox;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir ++rLine;
295cdf0e10cSrcweir ++pStartLn;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir }
298cdf0e10cSrcweir }
299cdf0e10cSrcweir else
300cdf0e10cSrcweir {
301cdf0e10cSrcweir bool bSelected = false;
302cdf0e10cSrcweir sal_uLong nBorder = 0;
303cdf0e10cSrcweir sal_uInt16 nCol = 0;
304cdf0e10cSrcweir maLines[rLine].reserve( rBoxes.Count() );
305cdf0e10cSrcweir ColumnStructure::iterator pCol = maCols.begin();
306cdf0e10cSrcweir BoxStructure::iterator pSel = maLines[rLine].end();
307cdf0e10cSrcweir for( sal_uInt16 nBox = 0; nBox < rBoxes.Count(); ++nBox )
308cdf0e10cSrcweir addBox( rLine, pSelBoxes, rBoxes[nBox], nBorder, nCol,
309cdf0e10cSrcweir pCol, pSel, bSelected, false );
310cdf0e10cSrcweir ++rLine;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
addBox(sal_uInt16 nLine,const SwSelBoxes * pSelBoxes,SwTableBox * pBox,sal_uLong & rnBorder,sal_uInt16 & rnCol,ColumnStructure::iterator & rpCol,BoxStructure::iterator & rpSel,bool & rbSelected,bool bCovered)314cdf0e10cSrcweir void TableStructure::addBox( sal_uInt16 nLine, const SwSelBoxes* pSelBoxes,
315cdf0e10cSrcweir SwTableBox *pBox, sal_uLong &rnBorder, sal_uInt16 &rnCol,
316cdf0e10cSrcweir ColumnStructure::iterator& rpCol, BoxStructure::iterator& rpSel,
317cdf0e10cSrcweir bool &rbSelected, bool bCovered )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir BoxSpanInfo aInfo;
320cdf0e10cSrcweir if( pSelBoxes &&
321cdf0e10cSrcweir USHRT_MAX != pSelBoxes->GetPos( pBox ) )
322cdf0e10cSrcweir {
323cdf0e10cSrcweir aInfo.mbSelected = true;
324cdf0e10cSrcweir if( mnStartCol == USHRT_MAX )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir mnStartCol = (sal_uInt16)maLines[nLine].size();
327cdf0e10cSrcweir if( pSelBoxes->Count() < 2 )
328cdf0e10cSrcweir {
329cdf0e10cSrcweir pSelBoxes = 0;
330cdf0e10cSrcweir aInfo.mbSelected = false;
331cdf0e10cSrcweir }
332cdf0e10cSrcweir }
333cdf0e10cSrcweir }
334cdf0e10cSrcweir else
335cdf0e10cSrcweir aInfo.mbSelected = false;
336cdf0e10cSrcweir rnBorder += pBox->GetFrmFmt()->GetFrmSize().GetWidth();
337cdf0e10cSrcweir sal_uInt16 nLeftCol = rnCol;
338cdf0e10cSrcweir while( rpCol != maCols.end() && *rpCol < rnBorder )
339cdf0e10cSrcweir {
340cdf0e10cSrcweir ++rnCol;
341cdf0e10cSrcweir ++rpCol;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir if( rpCol == maCols.end() || *rpCol > rnBorder )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir maCols.insert( rpCol, rnBorder );
346cdf0e10cSrcweir --rpCol;
347cdf0e10cSrcweir incColSpan( nLine, rnCol );
348cdf0e10cSrcweir }
349cdf0e10cSrcweir aInfo.mnColSpan = rnCol - nLeftCol;
350cdf0e10cSrcweir aInfo.mpCopy = 0;
351cdf0e10cSrcweir aInfo.mpBox = bCovered ? 0 : pBox;
352cdf0e10cSrcweir maLines[nLine].push_back( aInfo );
353cdf0e10cSrcweir if( aInfo.mbSelected )
354cdf0e10cSrcweir {
355cdf0e10cSrcweir if( rbSelected )
356cdf0e10cSrcweir {
357cdf0e10cSrcweir while( rpSel != maLines[nLine].end() )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir rpSel->mbSelected = true;
360cdf0e10cSrcweir ++rpSel;
361cdf0e10cSrcweir }
362cdf0e10cSrcweir }
363cdf0e10cSrcweir else
364cdf0e10cSrcweir {
365cdf0e10cSrcweir rpSel = maLines[nLine].end();
366cdf0e10cSrcweir rbSelected = true;
367cdf0e10cSrcweir }
368cdf0e10cSrcweir --rpSel;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir }
371cdf0e10cSrcweir
moreLines(const SwTable & rTable)372cdf0e10cSrcweir void TableStructure::moreLines( const SwTable& rTable )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir if( mnAddLine )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir const SwTableLines &rLines = rTable.GetTabLines();
377cdf0e10cSrcweir sal_uInt16 nLineCount = rLines.Count();
378cdf0e10cSrcweir if( nLineCount < mnAddLine )
379cdf0e10cSrcweir mnAddLine = nLineCount;
380cdf0e10cSrcweir sal_uInt16 nLine = (sal_uInt16)maLines.size();
381cdf0e10cSrcweir maLines.resize( nLine + mnAddLine );
382cdf0e10cSrcweir while( mnAddLine )
383cdf0e10cSrcweir {
384cdf0e10cSrcweir SwTableLine *pLine = rLines[ nLineCount - mnAddLine ];
385cdf0e10cSrcweir addLine( nLine, pLine->GetTabBoxes(), 0, rTable.IsNewModel() );
386cdf0e10cSrcweir --mnAddLine;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir }
389cdf0e10cSrcweir }
390cdf0e10cSrcweir
incColSpan(sal_uInt16 nLineMax,sal_uInt16 nNewCol)391cdf0e10cSrcweir void TableStructure::incColSpan( sal_uInt16 nLineMax, sal_uInt16 nNewCol )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir for( sal_uInt16 nLine = 0; nLine < nLineMax; ++nLine )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir BoxStructure::iterator pInfo = maLines[nLine].begin();
396cdf0e10cSrcweir BoxStructure::iterator pEnd = maLines[nLine].end();
397cdf0e10cSrcweir long nCol = pInfo->mnColSpan;
398cdf0e10cSrcweir while( nNewCol > nCol && ++pInfo != pEnd )
399cdf0e10cSrcweir nCol += pInfo->mnColSpan;
400cdf0e10cSrcweir if( pInfo != pEnd )
401cdf0e10cSrcweir ++(pInfo->mnColSpan);
402cdf0e10cSrcweir }
403cdf0e10cSrcweir }
404cdf0e10cSrcweir
assignBoxes(const TableStructure & rSource)405cdf0e10cSrcweir void TableStructure::assignBoxes( const TableStructure &rSource )
406cdf0e10cSrcweir {
407cdf0e10cSrcweir LineStructure::const_iterator pFirstLine = rSource.maLines.begin();
408cdf0e10cSrcweir LineStructure::const_iterator pLastLine = rSource.maLines.end();
409cdf0e10cSrcweir if( pFirstLine == pLastLine )
410cdf0e10cSrcweir return;
411cdf0e10cSrcweir LineStructure::const_iterator pCurrLine = pFirstLine;
412cdf0e10cSrcweir LineStructure::size_type nLineCount = maLines.size();
413cdf0e10cSrcweir sal_uInt16 nFirstStartCol = 0;
414cdf0e10cSrcweir {
415cdf0e10cSrcweir BoxStructure::const_iterator pFirstBox = pFirstLine->begin();
416cdf0e10cSrcweir if( pFirstBox != pFirstLine->end() && pFirstBox->mpBox &&
417cdf0e10cSrcweir pFirstBox->mpBox->getDummyFlag() )
418cdf0e10cSrcweir nFirstStartCol = pFirstBox->mnColSpan;
419cdf0e10cSrcweir }
420cdf0e10cSrcweir for( LineStructure::size_type nLine = 0; nLine < nLineCount; ++nLine )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir BoxStructure::const_iterator pFirstBox = pCurrLine->begin();
423cdf0e10cSrcweir BoxStructure::const_iterator pLastBox = pCurrLine->end();
424cdf0e10cSrcweir sal_uInt16 nCurrStartCol = mnStartCol;
425cdf0e10cSrcweir if( pFirstBox != pLastBox )
426cdf0e10cSrcweir {
427cdf0e10cSrcweir BoxStructure::const_iterator pTmpBox = pLastBox;
428cdf0e10cSrcweir --pTmpBox;
429cdf0e10cSrcweir if( pTmpBox->mpBox && pTmpBox->mpBox->getDummyFlag() )
430cdf0e10cSrcweir --pLastBox;
431cdf0e10cSrcweir if( pFirstBox != pLastBox && pFirstBox->mpBox &&
432cdf0e10cSrcweir pFirstBox->mpBox->getDummyFlag() )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir if( nCurrStartCol < USHRT_MAX )
435cdf0e10cSrcweir {
436cdf0e10cSrcweir if( pFirstBox->mnColSpan > nFirstStartCol )
437cdf0e10cSrcweir nCurrStartCol = pFirstBox->mnColSpan - nFirstStartCol
438cdf0e10cSrcweir + nCurrStartCol;
439cdf0e10cSrcweir }
440cdf0e10cSrcweir ++pFirstBox;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir }
443cdf0e10cSrcweir if( pFirstBox != pLastBox )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir BoxStructure::const_iterator pCurrBox = pFirstBox;
446cdf0e10cSrcweir BoxStructure &rBox = maLines[nLine];
447cdf0e10cSrcweir BoxStructure::size_type nBoxCount = rBox.size();
448cdf0e10cSrcweir sal_uInt16 nCol = 0;
449cdf0e10cSrcweir for( BoxStructure::size_type nBox = 0; nBox < nBoxCount; ++nBox )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir BoxSpanInfo& rInfo = rBox[nBox];
452cdf0e10cSrcweir nCol = nCol + rInfo.mnColSpan;
453cdf0e10cSrcweir if( rInfo.mbSelected || nCol > nCurrStartCol )
454cdf0e10cSrcweir {
455cdf0e10cSrcweir rInfo.mpCopy = pCurrBox->mpBox;
456cdf0e10cSrcweir if( rInfo.mbSelected && rInfo.mpCopy->getDummyFlag() )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir ++pCurrBox;
459cdf0e10cSrcweir if( pCurrBox == pLastBox )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir pCurrBox = pFirstBox;
462cdf0e10cSrcweir if( pCurrBox->mpBox->getDummyFlag() )
463cdf0e10cSrcweir ++pCurrBox;
464cdf0e10cSrcweir }
465cdf0e10cSrcweir rInfo.mpCopy = pCurrBox->mpBox;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir ++pCurrBox;
468cdf0e10cSrcweir if( pCurrBox == pLastBox )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir if( rInfo.mbSelected )
471cdf0e10cSrcweir pCurrBox = pFirstBox;
472cdf0e10cSrcweir else
473cdf0e10cSrcweir {
474cdf0e10cSrcweir rInfo.mbSelected = rInfo.mpCopy == 0;
475cdf0e10cSrcweir break;
476cdf0e10cSrcweir }
477cdf0e10cSrcweir }
478cdf0e10cSrcweir rInfo.mbSelected = rInfo.mpCopy == 0;
479cdf0e10cSrcweir }
480cdf0e10cSrcweir }
481cdf0e10cSrcweir }
482cdf0e10cSrcweir ++pCurrLine;
483cdf0e10cSrcweir if( pCurrLine == pLastLine )
484cdf0e10cSrcweir pCurrLine = pFirstLine;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir }
487cdf0e10cSrcweir
copyBoxes(const SwTable & rSource,SwTable & rDstTbl,SwUndoTblCpyTbl * pUndo) const488cdf0e10cSrcweir void TableStructure::copyBoxes( const SwTable& rSource, SwTable& rDstTbl,
489cdf0e10cSrcweir SwUndoTblCpyTbl* pUndo ) const
490cdf0e10cSrcweir {
491cdf0e10cSrcweir LineStructure::size_type nLineCount = maLines.size();
492cdf0e10cSrcweir for( LineStructure::size_type nLine = 0; nLine < nLineCount; ++nLine )
493cdf0e10cSrcweir {
494cdf0e10cSrcweir const BoxStructure &rBox = maLines[nLine];
495cdf0e10cSrcweir BoxStructure::size_type nBoxCount = rBox.size();
496cdf0e10cSrcweir for( BoxStructure::size_type nBox = 0; nBox < nBoxCount; ++nBox )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir const BoxSpanInfo& rInfo = rBox[nBox];
499cdf0e10cSrcweir if( ( rInfo.mpCopy && !rInfo.mpCopy->getDummyFlag() )
500cdf0e10cSrcweir || rInfo.mbSelected )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir SwTableBox *pBox = rInfo.mpBox;
503cdf0e10cSrcweir if( pBox && pBox->getRowSpan() > 0 )
504cdf0e10cSrcweir lcl_CpyBox( rSource, rInfo.mpCopy, rDstTbl, pBox,
505cdf0e10cSrcweir sal_True, pUndo );
506cdf0e10cSrcweir /* Idea: If target cell is a covered cell, append content
507cdf0e10cSrcweir to master cell.
508cdf0e10cSrcweir sal_Bool bReplace = sal_True;
509cdf0e10cSrcweir if( pBox->getRowSpan() < 0 )
510cdf0e10cSrcweir {
511cdf0e10cSrcweir if( rInfo.mpCopy->getRowSpan() < 0 )
512cdf0e10cSrcweir continue;
513cdf0e10cSrcweir pBox = &pBox->FindStartOfRowSpan( rDstTbl );
514cdf0e10cSrcweir bReplace = sal_False;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir lcl_CpyBox( rSource, rInfo.mpCopy, rDstTbl, pBox,
517cdf0e10cSrcweir bReplace, pUndo );
518cdf0e10cSrcweir */
519cdf0e10cSrcweir }
520cdf0e10cSrcweir }
521cdf0e10cSrcweir }
522cdf0e10cSrcweir }
523cdf0e10cSrcweir }
524cdf0e10cSrcweir
525cdf0e10cSrcweir // ---------------------------------------------------------------
526cdf0e10cSrcweir
527cdf0e10cSrcweir // kopiere die Tabelle in diese.
528cdf0e10cSrcweir // Kopiere alle Boxen einer Line in entsprechenden Boxen. Der alte Inhalt
529cdf0e10cSrcweir // wird dabei geloescht.
530cdf0e10cSrcweir // Ist keine mehr vorhanden, kommt der restliche Inhalt in die letzte
531cdf0e10cSrcweir // Box einer "GrundLine".
532cdf0e10cSrcweir // Ist auch keine Line mehr vorhanden, -> auch in die letzte Box
533cdf0e10cSrcweir // einer "GrundLine"
534cdf0e10cSrcweir
535cdf0e10cSrcweir
lcl_CpyBox(const SwTable & rCpyTbl,const SwTableBox * pCpyBox,SwTable & rDstTbl,SwTableBox * pDstBox,sal_Bool bDelCntnt,SwUndoTblCpyTbl * pUndo)536cdf0e10cSrcweir void lcl_CpyBox( const SwTable& rCpyTbl, const SwTableBox* pCpyBox,
537cdf0e10cSrcweir SwTable& rDstTbl, SwTableBox* pDstBox,
538cdf0e10cSrcweir sal_Bool bDelCntnt, SwUndoTblCpyTbl* pUndo )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir ASSERT( ( !pCpyBox || pCpyBox->GetSttNd() ) && pDstBox->GetSttNd(),
541cdf0e10cSrcweir "Keine inhaltstragende Box" );
542cdf0e10cSrcweir
543cdf0e10cSrcweir SwDoc* pCpyDoc = rCpyTbl.GetFrmFmt()->GetDoc();
544cdf0e10cSrcweir SwDoc* pDoc = rDstTbl.GetFrmFmt()->GetDoc();
545cdf0e10cSrcweir
546cdf0e10cSrcweir // kopiere erst den neuen und loeschen dann den alten Inhalt
547cdf0e10cSrcweir // (keine leeren Section erzeugen; werden sonst geloescht!)
548cdf0e10cSrcweir std::auto_ptr< SwNodeRange > pRg( pCpyBox ?
549cdf0e10cSrcweir new SwNodeRange ( *pCpyBox->GetSttNd(), 1,
550cdf0e10cSrcweir *pCpyBox->GetSttNd()->EndOfSectionNode() ) : 0 );
551cdf0e10cSrcweir
552cdf0e10cSrcweir SwNodeIndex aInsIdx( *pDstBox->GetSttNd(), bDelCntnt ? 1 :
553cdf0e10cSrcweir pDstBox->GetSttNd()->EndOfSectionIndex() -
554cdf0e10cSrcweir pDstBox->GetSttIdx() );
555cdf0e10cSrcweir
556cdf0e10cSrcweir if( pUndo )
557cdf0e10cSrcweir pUndo->AddBoxBefore( *pDstBox, bDelCntnt );
558cdf0e10cSrcweir
559cdf0e10cSrcweir bool bUndoRedline = pUndo && pDoc->IsRedlineOn();
560cdf0e10cSrcweir ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
561cdf0e10cSrcweir
562cdf0e10cSrcweir SwNodeIndex aSavePos( aInsIdx, -1 );
563cdf0e10cSrcweir if( pRg.get() )
564*dec99bbdSOliver-Rainer Wittmann pCpyDoc->CopyWithFlyInFly( *pRg, 0, aInsIdx, NULL, sal_False );
565cdf0e10cSrcweir else
566cdf0e10cSrcweir pDoc->GetNodes().MakeTxtNode( aInsIdx, (SwTxtFmtColl*)pDoc->GetDfltTxtFmtColl() );
567cdf0e10cSrcweir aSavePos++;
568cdf0e10cSrcweir
569cdf0e10cSrcweir SwTableLine* pLine = pDstBox->GetUpper();
570cdf0e10cSrcweir while( pLine->GetUpper() )
571cdf0e10cSrcweir pLine = pLine->GetUpper()->GetUpper();
572cdf0e10cSrcweir
573cdf0e10cSrcweir sal_Bool bReplaceColl = sal_True;
574cdf0e10cSrcweir if( bDelCntnt && !bUndoRedline )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir // zuerst die Fly loeschen, dann die entsprechenden Nodes
577cdf0e10cSrcweir SwNodeIndex aEndNdIdx( *aInsIdx.GetNode().EndOfSectionNode() );
578cdf0e10cSrcweir
579cdf0e10cSrcweir // Bookmarks usw. verschieben
580cdf0e10cSrcweir {
581cdf0e10cSrcweir SwPosition aMvPos( aInsIdx );
582cdf0e10cSrcweir SwCntntNode* pCNd = pDoc->GetNodes().GoPrevious( &aMvPos.nNode );
583cdf0e10cSrcweir aMvPos.nContent.Assign( pCNd, pCNd->Len() );
584cdf0e10cSrcweir pDoc->CorrAbs( aInsIdx, aEndNdIdx, aMvPos, /*sal_True*/sal_False );
585cdf0e10cSrcweir }
586cdf0e10cSrcweir
587cdf0e10cSrcweir // stehen noch FlyFrames rum, loesche auch diese
588cdf0e10cSrcweir for( sal_uInt16 n = 0; n < pDoc->GetSpzFrmFmts()->Count(); ++n )
589cdf0e10cSrcweir {
590cdf0e10cSrcweir SwFrmFmt *const pFly = (*pDoc->GetSpzFrmFmts())[n];
591cdf0e10cSrcweir SwFmtAnchor const*const pAnchor = &pFly->GetAnchor();
592cdf0e10cSrcweir SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
593cdf0e10cSrcweir if (pAPos &&
594cdf0e10cSrcweir ((FLY_AT_PARA == pAnchor->GetAnchorId()) ||
595cdf0e10cSrcweir (FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
596cdf0e10cSrcweir aInsIdx <= pAPos->nNode && pAPos->nNode <= aEndNdIdx )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir pDoc->DelLayoutFmt( pFly );
599cdf0e10cSrcweir }
600cdf0e10cSrcweir }
601cdf0e10cSrcweir
602cdf0e10cSrcweir // ist DestBox eine Headline-Box und hat Tabellen-Vorlage gesetzt,
603cdf0e10cSrcweir // dann NICHT die TabellenHeadline-Vorlage automatisch setzen
604cdf0e10cSrcweir if( 1 < rDstTbl.GetTabLines().Count() &&
605cdf0e10cSrcweir pLine == rDstTbl.GetTabLines()[0] )
606cdf0e10cSrcweir {
607cdf0e10cSrcweir SwCntntNode* pCNd = aInsIdx.GetNode().GetCntntNode();
608cdf0e10cSrcweir if( !pCNd )
609cdf0e10cSrcweir {
610cdf0e10cSrcweir SwNodeIndex aTmp( aInsIdx );
611cdf0e10cSrcweir pCNd = pDoc->GetNodes().GoNext( &aTmp );
612cdf0e10cSrcweir }
613cdf0e10cSrcweir
614cdf0e10cSrcweir if( pCNd &&
615cdf0e10cSrcweir /*RES_POOLCOLL_TABLE == */
616cdf0e10cSrcweir RES_POOLCOLL_TABLE_HDLN !=
617cdf0e10cSrcweir pCNd->GetFmtColl()->GetPoolFmtId() )
618cdf0e10cSrcweir bReplaceColl = sal_False;
619cdf0e10cSrcweir }
620cdf0e10cSrcweir
621cdf0e10cSrcweir pDoc->GetNodes().Delete( aInsIdx, aEndNdIdx.GetIndex() - aInsIdx.GetIndex() );
622cdf0e10cSrcweir }
623cdf0e10cSrcweir
624cdf0e10cSrcweir //b6341295: Table copy redlining will be managed by AddBoxAfter()
625cdf0e10cSrcweir if( pUndo )
626cdf0e10cSrcweir pUndo->AddBoxAfter( *pDstBox, aInsIdx, bDelCntnt );
627cdf0e10cSrcweir
628cdf0e10cSrcweir // heading
629cdf0e10cSrcweir SwTxtNode *const pTxtNd = aSavePos.GetNode().GetTxtNode();
630cdf0e10cSrcweir if( pTxtNd )
631cdf0e10cSrcweir {
632cdf0e10cSrcweir sal_uInt16 nPoolId = pTxtNd->GetTxtColl()->GetPoolFmtId();
633cdf0e10cSrcweir if( bReplaceColl &&
634cdf0e10cSrcweir (( 1 < rDstTbl.GetTabLines().Count() &&
635cdf0e10cSrcweir pLine == rDstTbl.GetTabLines()[0] )
636cdf0e10cSrcweir // gilt noch die Tabellen-Inhalt ??
637cdf0e10cSrcweir ? RES_POOLCOLL_TABLE == nPoolId
638cdf0e10cSrcweir : RES_POOLCOLL_TABLE_HDLN == nPoolId ) )
639cdf0e10cSrcweir {
640cdf0e10cSrcweir SwTxtFmtColl* pColl = pDoc->GetTxtCollFromPool(
641cdf0e10cSrcweir static_cast<sal_uInt16>(
642cdf0e10cSrcweir RES_POOLCOLL_TABLE == nPoolId
643cdf0e10cSrcweir ? RES_POOLCOLL_TABLE_HDLN
644cdf0e10cSrcweir : RES_POOLCOLL_TABLE ) );
645cdf0e10cSrcweir if( pColl ) // Vorlage umsetzen
646cdf0e10cSrcweir {
647cdf0e10cSrcweir SwPaM aPam( aSavePos );
648cdf0e10cSrcweir aPam.SetMark();
649cdf0e10cSrcweir aPam.Move( fnMoveForward, fnGoSection );
650cdf0e10cSrcweir pDoc->SetTxtFmtColl( aPam, pColl );
651cdf0e10cSrcweir }
652cdf0e10cSrcweir }
653cdf0e10cSrcweir
654cdf0e10cSrcweir // loesche die akt. Formel/Format/Value Werte
655cdf0e10cSrcweir if( SFX_ITEM_SET == pDstBox->GetFrmFmt()->GetItemState( RES_BOXATR_FORMAT ) ||
656cdf0e10cSrcweir SFX_ITEM_SET == pDstBox->GetFrmFmt()->GetItemState( RES_BOXATR_FORMULA ) ||
657cdf0e10cSrcweir SFX_ITEM_SET == pDstBox->GetFrmFmt()->GetItemState( RES_BOXATR_VALUE ) )
658cdf0e10cSrcweir {
659cdf0e10cSrcweir pDstBox->ClaimFrmFmt()->ResetFmtAttr( RES_BOXATR_FORMAT,
660cdf0e10cSrcweir RES_BOXATR_VALUE );
661cdf0e10cSrcweir }
662cdf0e10cSrcweir
663cdf0e10cSrcweir // kopiere die TabellenBoxAttribute - Formel/Format/Value
664cdf0e10cSrcweir if( pCpyBox )
665cdf0e10cSrcweir {
666cdf0e10cSrcweir SfxItemSet aBoxAttrSet( pCpyDoc->GetAttrPool(), RES_BOXATR_FORMAT,
667cdf0e10cSrcweir RES_BOXATR_VALUE );
668cdf0e10cSrcweir aBoxAttrSet.Put( pCpyBox->GetFrmFmt()->GetAttrSet() );
669cdf0e10cSrcweir if( aBoxAttrSet.Count() )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir const SfxPoolItem* pItem;
672cdf0e10cSrcweir SvNumberFormatter* pN = pDoc->GetNumberFormatter( sal_False );
673cdf0e10cSrcweir if( pN && pN->HasMergeFmtTbl() && SFX_ITEM_SET == aBoxAttrSet.
674cdf0e10cSrcweir GetItemState( RES_BOXATR_FORMAT, sal_False, &pItem ) )
675cdf0e10cSrcweir {
676cdf0e10cSrcweir sal_uLong nOldIdx = ((SwTblBoxNumFormat*)pItem)->GetValue();
677cdf0e10cSrcweir sal_uLong nNewIdx = pN->GetMergeFmtIndex( nOldIdx );
678cdf0e10cSrcweir if( nNewIdx != nOldIdx )
679cdf0e10cSrcweir aBoxAttrSet.Put( SwTblBoxNumFormat( nNewIdx ));
680cdf0e10cSrcweir }
681cdf0e10cSrcweir pDstBox->ClaimFrmFmt()->SetFmtAttr( aBoxAttrSet );
682cdf0e10cSrcweir }
683cdf0e10cSrcweir }
684cdf0e10cSrcweir }
685cdf0e10cSrcweir }
686cdf0e10cSrcweir
InsNewTable(const SwTable & rCpyTbl,const SwSelBoxes & rSelBoxes,SwUndoTblCpyTbl * pUndo)687cdf0e10cSrcweir sal_Bool SwTable::InsNewTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
688cdf0e10cSrcweir SwUndoTblCpyTbl* pUndo )
689cdf0e10cSrcweir {
690cdf0e10cSrcweir SwDoc* pDoc = GetFrmFmt()->GetDoc();
691cdf0e10cSrcweir SwDoc* pCpyDoc = rCpyTbl.GetFrmFmt()->GetDoc();
692cdf0e10cSrcweir
693cdf0e10cSrcweir SwTblNumFmtMerge aTNFM( *pCpyDoc, *pDoc );
694cdf0e10cSrcweir
695cdf0e10cSrcweir // analyse source structure
696cdf0e10cSrcweir TableStructure aCopyStruct( rCpyTbl );
697cdf0e10cSrcweir
698cdf0e10cSrcweir // analyse target structure (from start box) and selected substructure
699cdf0e10cSrcweir _FndBox aFndBox( 0, 0 );
700cdf0e10cSrcweir { // get all boxes/lines
701cdf0e10cSrcweir _FndPara aPara( rSelBoxes, &aFndBox );
702cdf0e10cSrcweir GetTabLines().ForEach( &_FndLineCopyCol, &aPara );
703cdf0e10cSrcweir }
704cdf0e10cSrcweir TableStructure aTarget( *this, aFndBox, rSelBoxes, aCopyStruct.getLineCount() );
705cdf0e10cSrcweir
706cdf0e10cSrcweir bool bClear = false;
707cdf0e10cSrcweir if( aTarget.mnAddLine && IsNewModel() )
708cdf0e10cSrcweir {
709cdf0e10cSrcweir SwSelBoxes aBoxes;
710cdf0e10cSrcweir aBoxes.Insert( GetTabLines()[ GetTabLines().Count()-1 ]->GetTabBoxes()[0] );
711cdf0e10cSrcweir if( pUndo )
712cdf0e10cSrcweir pUndo->InsertRow( *this, aBoxes, aTarget.mnAddLine );
713cdf0e10cSrcweir else
714cdf0e10cSrcweir InsertRow( pDoc, aBoxes, aTarget.mnAddLine, sal_True );
715cdf0e10cSrcweir
716cdf0e10cSrcweir aTarget.moreLines( *this );
717cdf0e10cSrcweir bClear = true;
718cdf0e10cSrcweir }
719cdf0e10cSrcweir
720cdf0e10cSrcweir // find mapping, if needed extend target table and/or selection
721cdf0e10cSrcweir aTarget.assignBoxes( aCopyStruct );
722cdf0e10cSrcweir
723cdf0e10cSrcweir {
724cdf0e10cSrcweir // Change table formulas into relative representation
725cdf0e10cSrcweir SwTableFmlUpdate aMsgHnt( &rCpyTbl );
726cdf0e10cSrcweir aMsgHnt.eFlags = TBL_RELBOXNAME;
727cdf0e10cSrcweir pCpyDoc->UpdateTblFlds( &aMsgHnt );
728cdf0e10cSrcweir }
729cdf0e10cSrcweir
730cdf0e10cSrcweir // delete frames
731cdf0e10cSrcweir aFndBox.SetTableLines( *this );
732cdf0e10cSrcweir if( bClear )
733cdf0e10cSrcweir aFndBox.ClearLineBehind();
734cdf0e10cSrcweir aFndBox.DelFrms( *this );
735cdf0e10cSrcweir
736cdf0e10cSrcweir // copy boxes
737cdf0e10cSrcweir aTarget.copyBoxes( rCpyTbl, *this, pUndo );
738cdf0e10cSrcweir
739cdf0e10cSrcweir // adjust row span attributes accordingly
740cdf0e10cSrcweir
741cdf0e10cSrcweir // make frames
742cdf0e10cSrcweir aFndBox.MakeFrms( *this );
743cdf0e10cSrcweir
744cdf0e10cSrcweir return sal_True;
745cdf0e10cSrcweir }
746cdf0e10cSrcweir
747cdf0e10cSrcweir // ---------------------------------------------------------------
748cdf0e10cSrcweir
749cdf0e10cSrcweir // kopiere die Tabelle in diese.
750cdf0e10cSrcweir // Kopiere alle Boxen einer Line in entsprechenden Boxen. Der alte Inhalt
751cdf0e10cSrcweir // wird dabei geloescht.
752cdf0e10cSrcweir // Ist keine mehr vorhanden, kommt der restliche Inhalt in die letzte
753cdf0e10cSrcweir // Box einer "GrundLine".
754cdf0e10cSrcweir // Ist auch keine Line mehr vorhanden, -> auch in die letzte Box
755cdf0e10cSrcweir // einer "GrundLine"
756cdf0e10cSrcweir
757cdf0e10cSrcweir
InsTable(const SwTable & rCpyTbl,const SwNodeIndex & rSttBox,SwUndoTblCpyTbl * pUndo)758cdf0e10cSrcweir sal_Bool SwTable::InsTable( const SwTable& rCpyTbl, const SwNodeIndex& rSttBox,
759cdf0e10cSrcweir SwUndoTblCpyTbl* pUndo )
760cdf0e10cSrcweir {
761cdf0e10cSrcweir SetHTMLTableLayout( 0 ); // MIB 9.7.97: HTML-Layout loeschen
762cdf0e10cSrcweir
763cdf0e10cSrcweir SwDoc* pDoc = GetFrmFmt()->GetDoc();
764cdf0e10cSrcweir
765cdf0e10cSrcweir SwTableNode* pTblNd = pDoc->IsIdxInTbl( rSttBox );
766cdf0e10cSrcweir
767cdf0e10cSrcweir // suche erstmal die Box, in die kopiert werden soll:
768cdf0e10cSrcweir SwTableBox* pMyBox = (SwTableBox*)GetTblBox(
769cdf0e10cSrcweir rSttBox.GetNode().FindTableBoxStartNode()->GetIndex() );
770cdf0e10cSrcweir
771cdf0e10cSrcweir ASSERT( pMyBox, "Index steht nicht in dieser Tabelle in einer Box" );
772cdf0e10cSrcweir
773cdf0e10cSrcweir // loesche erstmal die Frames der Tabelle
774cdf0e10cSrcweir _FndBox aFndBox( 0, 0 );
775cdf0e10cSrcweir aFndBox.DelFrms( pTblNd->GetTable() );
776cdf0e10cSrcweir
777cdf0e10cSrcweir SwDoc* pCpyDoc = rCpyTbl.GetFrmFmt()->GetDoc();
778cdf0e10cSrcweir
779cdf0e10cSrcweir {
780cdf0e10cSrcweir // Tabellen-Formeln in die relative Darstellung umwandeln
781cdf0e10cSrcweir SwTableFmlUpdate aMsgHnt( &rCpyTbl );
782cdf0e10cSrcweir aMsgHnt.eFlags = TBL_RELBOXNAME;
783cdf0e10cSrcweir pCpyDoc->UpdateTblFlds( &aMsgHnt );
784cdf0e10cSrcweir }
785cdf0e10cSrcweir
786cdf0e10cSrcweir SwTblNumFmtMerge aTNFM( *pCpyDoc, *pDoc );
787cdf0e10cSrcweir
788cdf0e10cSrcweir sal_Bool bDelCntnt = sal_True;
789cdf0e10cSrcweir const SwTableBox* pTmp;
790cdf0e10cSrcweir
791cdf0e10cSrcweir for( sal_uInt16 nLines = 0; nLines < rCpyTbl.GetTabLines().Count(); ++nLines )
792cdf0e10cSrcweir {
793cdf0e10cSrcweir // hole die erste Box von der Copy-Line
794cdf0e10cSrcweir const SwTableBox* pCpyBox = rCpyTbl.GetTabLines()[nLines]
795cdf0e10cSrcweir ->GetTabBoxes()[0];
796cdf0e10cSrcweir while( pCpyBox->GetTabLines().Count() )
797cdf0e10cSrcweir pCpyBox = pCpyBox->GetTabLines()[0]->GetTabBoxes()[0];
798cdf0e10cSrcweir
799cdf0e10cSrcweir do {
800cdf0e10cSrcweir // kopiere erst den neuen und loeschen dann den alten Inhalt
801cdf0e10cSrcweir // (keine leeren Section erzeugen, werden sonst geloescht!)
802cdf0e10cSrcweir lcl_CpyBox( rCpyTbl, pCpyBox, *this, pMyBox, bDelCntnt, pUndo );
803cdf0e10cSrcweir
804cdf0e10cSrcweir if( 0 == (pTmp = pCpyBox->FindNextBox( rCpyTbl, pCpyBox, sal_False )))
805cdf0e10cSrcweir break; // es folgt keine weitere Box mehr
806cdf0e10cSrcweir pCpyBox = pTmp;
807cdf0e10cSrcweir
808cdf0e10cSrcweir if( 0 == ( pTmp = pMyBox->FindNextBox( *this, pMyBox, sal_False )))
809cdf0e10cSrcweir bDelCntnt = sal_False; // kein Platz mehr ??
810cdf0e10cSrcweir else
811cdf0e10cSrcweir pMyBox = (SwTableBox*)pTmp;
812cdf0e10cSrcweir
813cdf0e10cSrcweir } while( sal_True );
814cdf0e10cSrcweir
815cdf0e10cSrcweir // suche die oberste Line
816cdf0e10cSrcweir SwTableLine* pNxtLine = pMyBox->GetUpper();
817cdf0e10cSrcweir while( pNxtLine->GetUpper() )
818cdf0e10cSrcweir pNxtLine = pNxtLine->GetUpper()->GetUpper();
819cdf0e10cSrcweir sal_uInt16 nPos = GetTabLines().C40_GETPOS( SwTableLine, pNxtLine );
820cdf0e10cSrcweir // gibt es eine naechste ??
821cdf0e10cSrcweir if( nPos + 1 >= GetTabLines().Count() )
822cdf0e10cSrcweir bDelCntnt = sal_False; // es gibt keine, alles in die letzte Box
823cdf0e10cSrcweir else
824cdf0e10cSrcweir {
825cdf0e10cSrcweir // suche die naechste "Inhaltstragende Box"
826cdf0e10cSrcweir pNxtLine = GetTabLines()[ nPos+1 ];
827cdf0e10cSrcweir pMyBox = pNxtLine->GetTabBoxes()[0];
828cdf0e10cSrcweir while( pMyBox->GetTabLines().Count() )
829cdf0e10cSrcweir pMyBox = pMyBox->GetTabLines()[0]->GetTabBoxes()[0];
830cdf0e10cSrcweir bDelCntnt = sal_True;
831cdf0e10cSrcweir }
832cdf0e10cSrcweir }
833cdf0e10cSrcweir
834cdf0e10cSrcweir aFndBox.MakeFrms( pTblNd->GetTable() ); // erzeuge die Frames neu
835cdf0e10cSrcweir return sal_True;
836cdf0e10cSrcweir }
837cdf0e10cSrcweir
838cdf0e10cSrcweir
InsTable(const SwTable & rCpyTbl,const SwSelBoxes & rSelBoxes,SwUndoTblCpyTbl * pUndo)839cdf0e10cSrcweir sal_Bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
840cdf0e10cSrcweir SwUndoTblCpyTbl* pUndo )
841cdf0e10cSrcweir {
842cdf0e10cSrcweir ASSERT( rSelBoxes.Count(), "Missing selection" )
843cdf0e10cSrcweir
844cdf0e10cSrcweir SetHTMLTableLayout( 0 ); // MIB 9.7.97: HTML-Layout loeschen
845cdf0e10cSrcweir
846cdf0e10cSrcweir if( IsNewModel() || rCpyTbl.IsNewModel() )
847cdf0e10cSrcweir return InsNewTable( rCpyTbl, rSelBoxes, pUndo );
848cdf0e10cSrcweir
849cdf0e10cSrcweir ASSERT( !rCpyTbl.IsTblComplex(), "Table too complex" )
850cdf0e10cSrcweir
851cdf0e10cSrcweir SwDoc* pDoc = GetFrmFmt()->GetDoc();
852cdf0e10cSrcweir SwDoc* pCpyDoc = rCpyTbl.GetFrmFmt()->GetDoc();
853cdf0e10cSrcweir
854cdf0e10cSrcweir SwTblNumFmtMerge aTNFM( *pCpyDoc, *pDoc );
855cdf0e10cSrcweir
856cdf0e10cSrcweir SwTableBox *pTmpBox, *pSttBox = (SwTableBox*)rSelBoxes[0];
857cdf0e10cSrcweir
858cdf0e10cSrcweir sal_uInt16 nLn, nBx;
859cdf0e10cSrcweir _FndLine *pFLine, *pInsFLine = 0;
860cdf0e10cSrcweir _FndBox aFndBox( 0, 0 );
861cdf0e10cSrcweir // suche alle Boxen / Lines
862cdf0e10cSrcweir {
863cdf0e10cSrcweir _FndPara aPara( rSelBoxes, &aFndBox );
864cdf0e10cSrcweir ((SwTableLines&)GetTabLines()).ForEach( &_FndLineCopyCol, &aPara );
865cdf0e10cSrcweir }
866cdf0e10cSrcweir
867cdf0e10cSrcweir // JP 06.09.96: Sonderfall - eine Box in der Tabelle -> in alle
868cdf0e10cSrcweir // selektierten Boxen kopieren!
869cdf0e10cSrcweir if( 1 != rCpyTbl.GetTabSortBoxes().Count() )
870cdf0e10cSrcweir {
871cdf0e10cSrcweir SwTableLine* pSttLine = pSttBox->GetUpper();
872cdf0e10cSrcweir sal_uInt16 nSttBox = pSttLine->GetTabBoxes().C40_GETPOS( SwTableBox, pSttBox );
873cdf0e10cSrcweir sal_uInt16 nSttLine = GetTabLines().C40_GETPOS( SwTableLine, pSttLine );
874cdf0e10cSrcweir _FndBox* pFndBox;
875cdf0e10cSrcweir
876cdf0e10cSrcweir sal_uInt16 nFndCnt = aFndBox.GetLines().Count();
877cdf0e10cSrcweir if( !nFndCnt )
878cdf0e10cSrcweir return sal_False;
879cdf0e10cSrcweir
880cdf0e10cSrcweir // teste ob genug Platz fuer die einzelnen Lines und Boxen ist:
881cdf0e10cSrcweir sal_uInt16 nTstLns = 0;
882cdf0e10cSrcweir pFLine = aFndBox.GetLines()[ 0 ];
883cdf0e10cSrcweir pSttLine = pFLine->GetLine();
884cdf0e10cSrcweir nSttLine = GetTabLines().C40_GETPOS( SwTableLine, pSttLine );
885cdf0e10cSrcweir // sind ueberhaupt soviele Zeilen vorhanden
886cdf0e10cSrcweir if( 1 == nFndCnt )
887cdf0e10cSrcweir {
888cdf0e10cSrcweir // in der Tabelle noch genug Platz ??
889cdf0e10cSrcweir if( (GetTabLines().Count() - nSttLine ) <
890cdf0e10cSrcweir rCpyTbl.GetTabLines().Count() )
891cdf0e10cSrcweir {
892cdf0e10cSrcweir // sollte nicht mehr soviele Lines vorhanden sein, dann
893cdf0e10cSrcweir // teste, ob man durch einfuegen neuer zum Ziel kommt. Aber
894cdf0e10cSrcweir // nur wenn die SSelection eine Box umfasst !!
895cdf0e10cSrcweir if( 1 < rSelBoxes.Count() )
896cdf0e10cSrcweir return sal_False;
897cdf0e10cSrcweir
898cdf0e10cSrcweir sal_uInt16 nNewLns = rCpyTbl.GetTabLines().Count() -
899cdf0e10cSrcweir (GetTabLines().Count() - nSttLine );
900cdf0e10cSrcweir
901cdf0e10cSrcweir // Dann teste mal ob die Anzahl der Boxen fuer die Lines reicht
902cdf0e10cSrcweir SwTableLine* pLastLn = GetTabLines()[ GetTabLines().Count()-1 ];
903cdf0e10cSrcweir
904cdf0e10cSrcweir pSttBox = pFLine->GetBoxes()[0]->GetBox();
905cdf0e10cSrcweir nSttBox = pFLine->GetLine()->GetTabBoxes().C40_GETPOS( SwTableBox, pSttBox );
906cdf0e10cSrcweir for( sal_uInt16 n = rCpyTbl.GetTabLines().Count() - nNewLns;
907cdf0e10cSrcweir n < rCpyTbl.GetTabLines().Count(); ++n )
908cdf0e10cSrcweir {
909cdf0e10cSrcweir SwTableLine* pCpyLn = rCpyTbl.GetTabLines()[ n ];
910cdf0e10cSrcweir
911cdf0e10cSrcweir if( pLastLn->GetTabBoxes().Count() < nSttBox ||
912cdf0e10cSrcweir ( pLastLn->GetTabBoxes().Count() - nSttBox ) <
913cdf0e10cSrcweir pCpyLn->GetTabBoxes().Count() )
914cdf0e10cSrcweir return sal_False;
915cdf0e10cSrcweir
916cdf0e10cSrcweir // Test auf Verschachtelungen
917cdf0e10cSrcweir for( nBx = 0; nBx < pCpyLn->GetTabBoxes().Count(); ++nBx )
918cdf0e10cSrcweir if( !( pTmpBox = pLastLn->GetTabBoxes()[ nSttBox + nBx ])
919cdf0e10cSrcweir ->GetSttNd() )
920cdf0e10cSrcweir return sal_False;
921cdf0e10cSrcweir }
922cdf0e10cSrcweir // es ist also Platz fuer das zu kopierende vorhanden, also
923cdf0e10cSrcweir // fuege entsprechend neue Zeilen ein.
924cdf0e10cSrcweir SwTableBox* pInsBox = pLastLn->GetTabBoxes()[ nSttBox ];
925cdf0e10cSrcweir ASSERT( pInsBox && pInsBox->GetSttNd(),
926cdf0e10cSrcweir "kein CntntBox oder steht nicht in dieser Tabelle" );
927cdf0e10cSrcweir SwSelBoxes aBoxes;
928cdf0e10cSrcweir
929cdf0e10cSrcweir if( pUndo
930cdf0e10cSrcweir ? !pUndo->InsertRow( *this, SelLineFromBox( pInsBox,
931cdf0e10cSrcweir aBoxes, sal_True ), nNewLns )
932cdf0e10cSrcweir : !InsertRow( pDoc, SelLineFromBox( pInsBox,
933cdf0e10cSrcweir aBoxes, sal_True ), nNewLns, sal_True ) )
934cdf0e10cSrcweir return sal_False;
935cdf0e10cSrcweir }
936cdf0e10cSrcweir
937cdf0e10cSrcweir nTstLns = rCpyTbl.GetTabLines().Count(); // soviele Kopieren
938cdf0e10cSrcweir }
939cdf0e10cSrcweir else if( 0 == (nFndCnt % rCpyTbl.GetTabLines().Count()) )
940cdf0e10cSrcweir nTstLns = nFndCnt;
941cdf0e10cSrcweir else
942cdf0e10cSrcweir return sal_False; // kein Platz fuer die Zeilen
943cdf0e10cSrcweir
944cdf0e10cSrcweir for( nLn = 0; nLn < nTstLns; ++nLn )
945cdf0e10cSrcweir {
946cdf0e10cSrcweir // Zeilen sind genug vorhanden, dann ueberpruefe die Boxen
947cdf0e10cSrcweir // je Zeile
948cdf0e10cSrcweir pFLine = aFndBox.GetLines()[ nLn % nFndCnt ];
949cdf0e10cSrcweir SwTableLine* pLine = pFLine->GetLine();
950cdf0e10cSrcweir pSttBox = pFLine->GetBoxes()[0]->GetBox();
951cdf0e10cSrcweir nSttBox = pLine->GetTabBoxes().C40_GETPOS( SwTableBox, pSttBox );
952cdf0e10cSrcweir if( nLn >= nFndCnt )
953cdf0e10cSrcweir {
954cdf0e10cSrcweir // es sind im ClipBoard mehr Zeilen als selectiert wurden
955cdf0e10cSrcweir pInsFLine = new _FndLine( GetTabLines()[ nSttLine + nLn ],
956cdf0e10cSrcweir &aFndBox );
957cdf0e10cSrcweir pLine = pInsFLine->GetLine();
958cdf0e10cSrcweir }
959cdf0e10cSrcweir SwTableLine* pCpyLn = rCpyTbl.GetTabLines()[ nLn %
960cdf0e10cSrcweir rCpyTbl.GetTabLines().Count() ];
961cdf0e10cSrcweir
962cdf0e10cSrcweir // zu wenig Zeilen selektiert ?
963cdf0e10cSrcweir if( pInsFLine )
964cdf0e10cSrcweir {
965cdf0e10cSrcweir // eine neue Zeile wird in die FndBox eingefuegt,
966cdf0e10cSrcweir if( pLine->GetTabBoxes().Count() < nSttBox ||
967cdf0e10cSrcweir ( pLine->GetTabBoxes().Count() - nSttBox ) <
968cdf0e10cSrcweir pFLine->GetBoxes().Count() )
969cdf0e10cSrcweir return sal_False;
970cdf0e10cSrcweir
971cdf0e10cSrcweir // Test auf Verschachtelungen
972cdf0e10cSrcweir for( nBx = 0; nBx < pFLine->GetBoxes().Count(); ++nBx )
973cdf0e10cSrcweir {
974cdf0e10cSrcweir if( !( pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ])
975cdf0e10cSrcweir ->GetSttNd() )
976cdf0e10cSrcweir return sal_False;
977cdf0e10cSrcweir // wenn Ok, fuege die Box in die FndLine zu
978cdf0e10cSrcweir pFndBox = new _FndBox( pTmpBox, pInsFLine );
979cdf0e10cSrcweir pInsFLine->GetBoxes().C40_INSERT( _FndBox, pFndBox, nBx );
980cdf0e10cSrcweir }
981cdf0e10cSrcweir aFndBox.GetLines().C40_INSERT( _FndLine, pInsFLine, nLn );
982cdf0e10cSrcweir }
983cdf0e10cSrcweir else if( pFLine->GetBoxes().Count() == 1 )
984cdf0e10cSrcweir {
985cdf0e10cSrcweir if( pLine->GetTabBoxes().Count() < nSttBox ||
986cdf0e10cSrcweir ( pLine->GetTabBoxes().Count() - nSttBox ) <
987cdf0e10cSrcweir pCpyLn->GetTabBoxes().Count() )
988cdf0e10cSrcweir return sal_False;
989cdf0e10cSrcweir
990cdf0e10cSrcweir // Test auf Verschachtelungen
991cdf0e10cSrcweir for( nBx = 0; nBx < pCpyLn->GetTabBoxes().Count(); ++nBx )
992cdf0e10cSrcweir {
993cdf0e10cSrcweir if( !( pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ])
994cdf0e10cSrcweir ->GetSttNd() )
995cdf0e10cSrcweir return sal_False;
996cdf0e10cSrcweir // wenn Ok, fuege die Box in die FndLine zu
997cdf0e10cSrcweir if( nBx == pFLine->GetBoxes().Count() )
998cdf0e10cSrcweir {
999cdf0e10cSrcweir pFndBox = new _FndBox( pTmpBox, pFLine );
1000cdf0e10cSrcweir pFLine->GetBoxes().C40_INSERT( _FndBox, pFndBox, nBx );
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir }
1003cdf0e10cSrcweir }
1004cdf0e10cSrcweir else
1005cdf0e10cSrcweir {
1006cdf0e10cSrcweir // ueberpruefe die selektierten Boxen mit denen im Clipboard
1007cdf0e10cSrcweir // (n-Fach)
1008cdf0e10cSrcweir if( 0 != ( pFLine->GetBoxes().Count() %
1009cdf0e10cSrcweir pCpyLn->GetTabBoxes().Count() ))
1010cdf0e10cSrcweir return sal_False;
1011cdf0e10cSrcweir
1012cdf0e10cSrcweir // Test auf Verschachtelungen
1013cdf0e10cSrcweir for( nBx = 0; nBx < pFLine->GetBoxes().Count(); ++nBx )
1014cdf0e10cSrcweir if( !pFLine->GetBoxes()[ nBx ]->GetBox()->GetSttNd() )
1015cdf0e10cSrcweir return sal_False;
1016cdf0e10cSrcweir }
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir
1019cdf0e10cSrcweir if( !aFndBox.GetLines().Count() )
1020cdf0e10cSrcweir return sal_False;
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir
1023cdf0e10cSrcweir {
1024cdf0e10cSrcweir // Tabellen-Formeln in die relative Darstellung umwandeln
1025cdf0e10cSrcweir SwTableFmlUpdate aMsgHnt( &rCpyTbl );
1026cdf0e10cSrcweir aMsgHnt.eFlags = TBL_RELBOXNAME;
1027cdf0e10cSrcweir pCpyDoc->UpdateTblFlds( &aMsgHnt );
1028cdf0e10cSrcweir }
1029cdf0e10cSrcweir
1030cdf0e10cSrcweir // loesche die Frames
1031cdf0e10cSrcweir aFndBox.SetTableLines( *this );
1032ca62e2c2SSteve Yin //Solution:Not dispose accessible table
1033ca62e2c2SSteve Yin //aFndBox.DelFrms( *this );
1034ca62e2c2SSteve Yin aFndBox.DelFrms( *this,sal_False );
1035cdf0e10cSrcweir
1036cdf0e10cSrcweir if( 1 == rCpyTbl.GetTabSortBoxes().Count() )
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir SwTableBox *pTmpBx = rCpyTbl.GetTabSortBoxes()[0];
1039cdf0e10cSrcweir for( sal_uInt16 n = 0; n < rSelBoxes.Count(); ++n )
1040cdf0e10cSrcweir lcl_CpyBox( rCpyTbl, pTmpBx, *this,
1041cdf0e10cSrcweir (SwTableBox*)rSelBoxes[n], sal_True, pUndo );
1042cdf0e10cSrcweir }
1043cdf0e10cSrcweir else
1044cdf0e10cSrcweir for( nLn = 0; nLn < aFndBox.GetLines().Count(); ++nLn )
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir pFLine = aFndBox.GetLines()[ nLn ];
1047cdf0e10cSrcweir SwTableLine* pCpyLn = rCpyTbl.GetTabLines()[
1048cdf0e10cSrcweir nLn % rCpyTbl.GetTabLines().Count() ];
1049cdf0e10cSrcweir for( nBx = 0; nBx < pFLine->GetBoxes().Count(); ++nBx )
1050cdf0e10cSrcweir {
1051cdf0e10cSrcweir // Kopiere in pMyBox die pCpyBox
1052cdf0e10cSrcweir lcl_CpyBox( rCpyTbl, pCpyLn->GetTabBoxes()[
1053cdf0e10cSrcweir nBx % pCpyLn->GetTabBoxes().Count() ],
1054cdf0e10cSrcweir *this, pFLine->GetBoxes()[ nBx ]->GetBox(), sal_True, pUndo );
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir }
1057cdf0e10cSrcweir
1058cdf0e10cSrcweir aFndBox.MakeFrms( *this );
1059cdf0e10cSrcweir return sal_True;
1060cdf0e10cSrcweir }
1061cdf0e10cSrcweir
1062cdf0e10cSrcweir
1063cdf0e10cSrcweir
_FndCntntBox(const SwTableBox * & rpBox,void * pPara)1064cdf0e10cSrcweir sal_Bool _FndCntntBox( const SwTableBox*& rpBox, void* pPara )
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir SwTableBox* pBox = (SwTableBox*)rpBox;
1067cdf0e10cSrcweir if( rpBox->GetTabLines().Count() )
1068cdf0e10cSrcweir pBox->GetTabLines().ForEach( &_FndCntntLine, pPara );
1069cdf0e10cSrcweir else
1070cdf0e10cSrcweir ((SwSelBoxes*)pPara)->Insert( pBox );
1071cdf0e10cSrcweir return sal_True;
1072cdf0e10cSrcweir }
1073cdf0e10cSrcweir
1074cdf0e10cSrcweir
_FndCntntLine(const SwTableLine * & rpLine,void * pPara)1075cdf0e10cSrcweir sal_Bool _FndCntntLine( const SwTableLine*& rpLine, void* pPara )
1076cdf0e10cSrcweir {
1077cdf0e10cSrcweir ((SwTableLine*)rpLine)->GetTabBoxes().ForEach( &_FndCntntBox, pPara );
1078cdf0e10cSrcweir return sal_True;
1079cdf0e10cSrcweir }
1080cdf0e10cSrcweir
1081cdf0e10cSrcweir
1082cdf0e10cSrcweir // suche alle Inhaltstragenden-Boxen dieser Box
SelLineFromBox(const SwTableBox * pBox,SwSelBoxes & rBoxes,sal_Bool bToTop) const1083cdf0e10cSrcweir SwSelBoxes& SwTable::SelLineFromBox( const SwTableBox* pBox,
1084cdf0e10cSrcweir SwSelBoxes& rBoxes, sal_Bool bToTop ) const
1085cdf0e10cSrcweir {
1086cdf0e10cSrcweir SwTableLine* pLine = (SwTableLine*)pBox->GetUpper();
1087cdf0e10cSrcweir if( bToTop )
1088cdf0e10cSrcweir while( pLine->GetUpper() )
1089cdf0e10cSrcweir pLine = pLine->GetUpper()->GetUpper();
1090cdf0e10cSrcweir
1091cdf0e10cSrcweir // alle alten loeschen
1092cdf0e10cSrcweir rBoxes.Remove( sal_uInt16(0), rBoxes.Count() );
1093cdf0e10cSrcweir pLine->GetTabBoxes().ForEach( &_FndCntntBox, &rBoxes );
1094cdf0e10cSrcweir return rBoxes;
1095cdf0e10cSrcweir }
1096cdf0e10cSrcweir
1097cdf0e10cSrcweir
1098