xref: /aoo41x/main/sw/source/core/table/swtable.cxx (revision dec99bbd)
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
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
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.
19efeef26fSAndrew Rist  *
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 #include <ctype.h>
28cdf0e10cSrcweir #include <float.h>
29cdf0e10cSrcweir #include <hintids.hxx>
30cdf0e10cSrcweir #include <hints.hxx>  	// fuer SwAttrSetChg
31cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
32cdf0e10cSrcweir #include <editeng/shaditem.hxx>
33cdf0e10cSrcweir #include <editeng/adjitem.hxx>
34cdf0e10cSrcweir #include <editeng/colritem.hxx>
35cdf0e10cSrcweir #include <sfx2/linkmgr.hxx>
36cdf0e10cSrcweir #include <editeng/boxitem.hxx>
37cdf0e10cSrcweir #include <fmtfsize.hxx>
38cdf0e10cSrcweir #include <fmtornt.hxx>
39cdf0e10cSrcweir #include <fmtpdsc.hxx>
40cdf0e10cSrcweir #include <fldbas.hxx>
41cdf0e10cSrcweir #include <fmtfld.hxx>
42cdf0e10cSrcweir #include <frmatr.hxx>
43cdf0e10cSrcweir #include <doc.hxx>
44cdf0e10cSrcweir #include <docary.hxx> 	// fuer RedlineTbl()
45cdf0e10cSrcweir #include <frame.hxx>
46cdf0e10cSrcweir #include <swtable.hxx>
47cdf0e10cSrcweir #include <ndtxt.hxx>
48cdf0e10cSrcweir #include <tabcol.hxx>
49cdf0e10cSrcweir #include <tabfrm.hxx>
50cdf0e10cSrcweir #include <cellfrm.hxx>
51cdf0e10cSrcweir #include <rowfrm.hxx>
52cdf0e10cSrcweir #include <swserv.hxx>
53cdf0e10cSrcweir #include <expfld.hxx>
54cdf0e10cSrcweir #include <mdiexp.hxx>
55cdf0e10cSrcweir #include <cellatr.hxx>
56cdf0e10cSrcweir #include <txatbase.hxx>
57cdf0e10cSrcweir #include <htmltbl.hxx>
58cdf0e10cSrcweir #include <swtblfmt.hxx>
59cdf0e10cSrcweir #include <ndindex.hxx>
60cdf0e10cSrcweir #include <tblrwcl.hxx>
61cdf0e10cSrcweir #include <shellres.hxx>
62cdf0e10cSrcweir #include <viewsh.hxx>
63cdf0e10cSrcweir #include <redline.hxx>
64cdf0e10cSrcweir #include <list>
65cdf0e10cSrcweir #include <switerator.hxx>
66cdf0e10cSrcweir 
67cdf0e10cSrcweir #ifndef DBG_UTIL
68cdf0e10cSrcweir #define CHECK_TABLE(t)
69cdf0e10cSrcweir #else
70cdf0e10cSrcweir #ifdef DEBUG
71cdf0e10cSrcweir #define CHECK_TABLE(t) (t).CheckConsistency();
72cdf0e10cSrcweir #else
73cdf0e10cSrcweir #define CHECK_TABLE(t)
74cdf0e10cSrcweir #endif
75cdf0e10cSrcweir #endif
76cdf0e10cSrcweir 
77cdf0e10cSrcweir using namespace com::sun::star;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir TYPEINIT1( SwTable, SwClient );
80cdf0e10cSrcweir TYPEINIT1( SwTableBox, SwClient );
81cdf0e10cSrcweir TYPEINIT1( SwTableLine, SwClient );
82cdf0e10cSrcweir TYPEINIT1( SwTableFmt, SwFrmFmt );
83cdf0e10cSrcweir TYPEINIT1( SwTableBoxFmt, SwFrmFmt );
84cdf0e10cSrcweir TYPEINIT1( SwTableLineFmt, SwFrmFmt );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir SV_IMPL_PTRARR(SwTableLines,SwTableLine*);
87cdf0e10cSrcweir SV_IMPL_PTRARR(SwTableBoxes,SwTableBox*);
88cdf0e10cSrcweir SV_IMPL_PTRARR_SORT(SwTableSortBoxes,SwTableBoxPtr);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir SV_IMPL_REF( SwServerObject )
91cdf0e10cSrcweir 
92cdf0e10cSrcweir #define COLFUZZY 20
93cdf0e10cSrcweir 
94cdf0e10cSrcweir void ChgTextToNum( SwTableBox& rBox, const String& rTxt, const Color* pCol,
95cdf0e10cSrcweir 					sal_Bool bChgAlign,sal_uLong nNdPos );
96cdf0e10cSrcweir //----------------------------------
97cdf0e10cSrcweir 
98cdf0e10cSrcweir class SwTableBox_Impl
99cdf0e10cSrcweir {
100cdf0e10cSrcweir 	Color *mpUserColor, *mpNumFmtColor;
101cdf0e10cSrcweir     long mnRowSpan;
102cdf0e10cSrcweir     bool mbDummyFlag;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	void SetNewCol( Color** ppCol, const Color* pNewCol );
105cdf0e10cSrcweir public:
SwTableBox_Impl()106cdf0e10cSrcweir 	SwTableBox_Impl() : mpUserColor(0), mpNumFmtColor(0), mnRowSpan(1),
107cdf0e10cSrcweir         mbDummyFlag( false ) {}
~SwTableBox_Impl()108cdf0e10cSrcweir 	~SwTableBox_Impl() { delete mpUserColor; delete mpNumFmtColor; }
109cdf0e10cSrcweir 
GetSaveUserColor() const110cdf0e10cSrcweir 	const Color* GetSaveUserColor()	const		{ return mpUserColor; }
GetSaveNumFmtColor() const111cdf0e10cSrcweir 	const Color* GetSaveNumFmtColor() const 	{ return mpNumFmtColor; }
SetSaveUserColor(const Color * p)112cdf0e10cSrcweir 	void SetSaveUserColor(const Color* p )		{ SetNewCol( &mpUserColor, p ); }
SetSaveNumFmtColor(const Color * p)113cdf0e10cSrcweir 	void SetSaveNumFmtColor( const Color* p )	{ SetNewCol( &mpNumFmtColor, p ); }
getRowSpan() const114cdf0e10cSrcweir     long getRowSpan() const { return mnRowSpan; }
setRowSpan(long nNewRowSpan)115cdf0e10cSrcweir     void setRowSpan( long nNewRowSpan ) { mnRowSpan = nNewRowSpan; }
getDummyFlag() const116cdf0e10cSrcweir     bool getDummyFlag() const { return mbDummyFlag; }
setDummyFlag(bool bDummy)117cdf0e10cSrcweir     void setDummyFlag( bool bDummy ) { mbDummyFlag = bDummy; }
118cdf0e10cSrcweir };
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // ----------- Inlines -----------------------------
121cdf0e10cSrcweir 
GetSaveUserColor() const122cdf0e10cSrcweir inline const Color* SwTableBox::GetSaveUserColor() const
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	return pImpl ? pImpl->GetSaveUserColor() : 0;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
GetSaveNumFmtColor() const127cdf0e10cSrcweir inline const Color* SwTableBox::GetSaveNumFmtColor() const
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	return pImpl ? pImpl->GetSaveNumFmtColor() : 0;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
SetSaveUserColor(const Color * p)132cdf0e10cSrcweir inline void SwTableBox::SetSaveUserColor(const Color* p )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	if( pImpl )
135cdf0e10cSrcweir 		pImpl->SetSaveUserColor( p );
136cdf0e10cSrcweir 	else if( p )
137cdf0e10cSrcweir 		( pImpl = new SwTableBox_Impl ) ->SetSaveUserColor( p );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
SetSaveNumFmtColor(const Color * p)140cdf0e10cSrcweir inline void SwTableBox::SetSaveNumFmtColor( const Color* p )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	if( pImpl )
143cdf0e10cSrcweir 		pImpl->SetSaveNumFmtColor( p );
144cdf0e10cSrcweir 	else if( p )
145cdf0e10cSrcweir 		( pImpl = new SwTableBox_Impl )->SetSaveNumFmtColor( p );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
getRowSpan() const148cdf0e10cSrcweir long SwTableBox::getRowSpan() const
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     return pImpl ? pImpl->getRowSpan() : 1;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
setRowSpan(long nNewRowSpan)153cdf0e10cSrcweir void SwTableBox::setRowSpan( long nNewRowSpan )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     if( !pImpl )
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         if( nNewRowSpan == 1 )
158cdf0e10cSrcweir             return;
159cdf0e10cSrcweir         pImpl = new SwTableBox_Impl();
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir     pImpl->setRowSpan( nNewRowSpan );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
getDummyFlag() const164cdf0e10cSrcweir bool SwTableBox::getDummyFlag() const
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     return pImpl ? pImpl->getDummyFlag() : false;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
setDummyFlag(bool bDummy)169cdf0e10cSrcweir void SwTableBox::setDummyFlag( bool bDummy )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     if( !pImpl )
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         if( !bDummy )
174cdf0e10cSrcweir             return;
175cdf0e10cSrcweir         pImpl = new SwTableBox_Impl();
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir     pImpl->setDummyFlag( bDummy );
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir //JP 15.09.98: Bug 55741 - Tabs beibehalten (vorne und hinten)
lcl_TabToBlankAtSttEnd(String & rTxt)181cdf0e10cSrcweir String& lcl_TabToBlankAtSttEnd( String& rTxt )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir 	sal_Unicode c;
184cdf0e10cSrcweir 	xub_StrLen n;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	for( n = 0; n < rTxt.Len() && ' ' >= ( c = rTxt.GetChar( n )); ++n )
187cdf0e10cSrcweir 		if( '\x9' == c )
188cdf0e10cSrcweir 			rTxt.SetChar( n, ' ' );
189cdf0e10cSrcweir 	for( n = rTxt.Len(); n && ' ' >= ( c = rTxt.GetChar( --n )); )
190cdf0e10cSrcweir 		if( '\x9' == c )
191cdf0e10cSrcweir 			rTxt.SetChar( n, ' ' );
192cdf0e10cSrcweir 	return rTxt;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
lcl_DelTabsAtSttEnd(String & rTxt)195cdf0e10cSrcweir String& lcl_DelTabsAtSttEnd( String& rTxt )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	sal_Unicode c;
198cdf0e10cSrcweir 	xub_StrLen n;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 	for( n = 0; n < rTxt.Len() && ' ' >= ( c = rTxt.GetChar( n )); ++n )
201cdf0e10cSrcweir 		if( '\x9' == c )
202cdf0e10cSrcweir 			rTxt.Erase( n--, 1 );
203cdf0e10cSrcweir 	for( n = rTxt.Len(); n && ' ' >= ( c = rTxt.GetChar( --n )); )
204cdf0e10cSrcweir 		if( '\x9' == c )
205cdf0e10cSrcweir 			rTxt.Erase( n, 1 );
206cdf0e10cSrcweir 	return rTxt;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
_InsTblBox(SwDoc * pDoc,SwTableNode * pTblNd,SwTableLine * pLine,SwTableBoxFmt * pBoxFrmFmt,SwTableBox * pBox,sal_uInt16 nInsPos,sal_uInt16 nCnt)209cdf0e10cSrcweir void _InsTblBox( SwDoc* pDoc, SwTableNode* pTblNd,
210cdf0e10cSrcweir 						SwTableLine* pLine, SwTableBoxFmt* pBoxFrmFmt,
211cdf0e10cSrcweir 						SwTableBox* pBox,
212cdf0e10cSrcweir 						sal_uInt16 nInsPos, sal_uInt16 nCnt )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	ASSERT( pBox->GetSttNd(), "Box ohne Start-Node" );
215cdf0e10cSrcweir 	SwNodeIndex aIdx( *pBox->GetSttNd(), +1 );
216cdf0e10cSrcweir 	SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
217cdf0e10cSrcweir 	if( !pCNd )
218cdf0e10cSrcweir 		pCNd = pDoc->GetNodes().GoNext( &aIdx );
219cdf0e10cSrcweir 	ASSERT( pCNd, "Box ohne ContentNode" );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	if( pCNd->IsTxtNode() )
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		if( pBox->GetSaveNumFmtColor() && pCNd->GetpSwAttrSet() )
224cdf0e10cSrcweir 		{
225cdf0e10cSrcweir 			SwAttrSet aAttrSet( *pCNd->GetpSwAttrSet() );
226cdf0e10cSrcweir 			if( pBox->GetSaveUserColor() )
227cdf0e10cSrcweir 				aAttrSet.Put( SvxColorItem( *pBox->GetSaveUserColor(), RES_CHRATR_COLOR ));
228cdf0e10cSrcweir 			else
229cdf0e10cSrcweir 				aAttrSet.ClearItem( RES_CHRATR_COLOR );
230cdf0e10cSrcweir 			pDoc->GetNodes().InsBoxen( pTblNd, pLine, pBoxFrmFmt,
231cdf0e10cSrcweir 									((SwTxtNode*)pCNd)->GetTxtColl(),
232cdf0e10cSrcweir 									&aAttrSet, nInsPos, nCnt );
233cdf0e10cSrcweir 		}
234cdf0e10cSrcweir 		else
235cdf0e10cSrcweir 			pDoc->GetNodes().InsBoxen( pTblNd, pLine, pBoxFrmFmt,
236cdf0e10cSrcweir 									((SwTxtNode*)pCNd)->GetTxtColl(),
237cdf0e10cSrcweir 									pCNd->GetpSwAttrSet(),
238cdf0e10cSrcweir 									nInsPos, nCnt );
239cdf0e10cSrcweir 	}
240cdf0e10cSrcweir 	else
241cdf0e10cSrcweir 		pDoc->GetNodes().InsBoxen( pTblNd, pLine, pBoxFrmFmt,
242cdf0e10cSrcweir 				(SwTxtFmtColl*)pDoc->GetDfltTxtFmtColl(), 0,
243cdf0e10cSrcweir 				nInsPos, nCnt );
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     long nRowSpan = pBox->getRowSpan();
246cdf0e10cSrcweir     if( nRowSpan != 1 )
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir 		SwTableBoxes& rTblBoxes = pLine->GetTabBoxes();
249cdf0e10cSrcweir         for( sal_uInt16 i = 0; i < nCnt; ++i )
250cdf0e10cSrcweir         {
251cdf0e10cSrcweir             pBox = rTblBoxes[ i + nInsPos ];
252cdf0e10cSrcweir             pBox->setRowSpan( nRowSpan );
253cdf0e10cSrcweir         }
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir /*************************************************************************
258cdf0e10cSrcweir |*
259cdf0e10cSrcweir |*	SwTable::SwTable()
260cdf0e10cSrcweir |*
261cdf0e10cSrcweir |*************************************************************************/
SwTable(SwTableFmt * pFmt)262cdf0e10cSrcweir SwTable::SwTable( SwTableFmt* pFmt )
263cdf0e10cSrcweir 	: SwClient( pFmt ),
264cdf0e10cSrcweir 	pHTMLLayout( 0 ),
265cdf0e10cSrcweir     pTableNode( 0 ),
266cdf0e10cSrcweir 	nGrfsThatResize( 0 ),
267cdf0e10cSrcweir     nRowsToRepeat( 1 ),
268cdf0e10cSrcweir     bModifyLocked( sal_False ),
269cdf0e10cSrcweir     bNewModel( sal_True )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	// default Wert aus den Optionen setzen
272cdf0e10cSrcweir 	eTblChgMode = (TblChgMode)GetTblChgDefaultMode();
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
SwTable(const SwTable & rTable)275cdf0e10cSrcweir SwTable::SwTable( const SwTable& rTable )
276cdf0e10cSrcweir 	: SwClient( rTable.GetFrmFmt() ),
277cdf0e10cSrcweir 	pHTMLLayout( 0 ),
278cdf0e10cSrcweir     pTableNode( 0 ),
279cdf0e10cSrcweir 	eTblChgMode( rTable.eTblChgMode ),
280cdf0e10cSrcweir 	nGrfsThatResize( 0 ),
281cdf0e10cSrcweir     nRowsToRepeat( rTable.GetRowsToRepeat() ),
282cdf0e10cSrcweir     bModifyLocked( sal_False ),
283cdf0e10cSrcweir     bNewModel( rTable.bNewModel )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
DelBoxNode(SwTableSortBoxes & rSortCntBoxes)287cdf0e10cSrcweir void DelBoxNode( SwTableSortBoxes& rSortCntBoxes )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir 	for( sal_uInt16 n = 0; n < rSortCntBoxes.Count(); ++n )
290cdf0e10cSrcweir 		rSortCntBoxes[ n ]->pSttNd = 0;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
~SwTable()293cdf0e10cSrcweir SwTable::~SwTable()
294cdf0e10cSrcweir {
295cdf0e10cSrcweir 	if( refObj.Is() )
296cdf0e10cSrcweir 	{
297cdf0e10cSrcweir 		SwDoc* pDoc = GetFrmFmt()->GetDoc();
298cdf0e10cSrcweir 		if( !pDoc->IsInDtor() )			// dann aus der Liste entfernen
299cdf0e10cSrcweir 			pDoc->GetLinkManager().RemoveServer( &refObj );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 		refObj->Closed();
302cdf0e10cSrcweir 	}
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 	// ist die Tabelle der letzte Client im FrameFormat, kann dieses
305cdf0e10cSrcweir 	// geloescht werden
306cdf0e10cSrcweir 	SwTableFmt* pFmt = (SwTableFmt*)GetFrmFmt();
307cdf0e10cSrcweir 	pFmt->Remove( this );				// austragen,
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 	if( !pFmt->GetDepends() )
310cdf0e10cSrcweir 		pFmt->GetDoc()->DelTblFrmFmt( pFmt );	// und loeschen
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 	// Loesche die Pointer aus dem SortArray der Boxen, die
313cdf0e10cSrcweir 	// Objecte bleiben erhalten und werden vom DTOR der Lines/Boxes
314cdf0e10cSrcweir 	// Arrays geloescht.
315cdf0e10cSrcweir 	//JP: reicht leider nicht, es muessen die Pointer auf den StartNode
316cdf0e10cSrcweir 	//	der Section geloescht werden
317cdf0e10cSrcweir 	DelBoxNode( aSortCntBoxes );
318cdf0e10cSrcweir 	aSortCntBoxes.Remove( (sal_uInt16)0, aSortCntBoxes.Count() );
319cdf0e10cSrcweir 	delete pHTMLLayout;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir /*************************************************************************
323cdf0e10cSrcweir |*
324cdf0e10cSrcweir |*	SwTable::Modify()
325cdf0e10cSrcweir |*
326cdf0e10cSrcweir |*************************************************************************/
FmtInArr(SvPtrarr & rFmtArr,SwFmt * pBoxFmt)327cdf0e10cSrcweir inline void FmtInArr( SvPtrarr& rFmtArr, SwFmt* pBoxFmt )
328cdf0e10cSrcweir {
329cdf0e10cSrcweir 	sal_Bool bRet = USHRT_MAX != rFmtArr.GetPos( (VoidPtr)pBoxFmt );
330cdf0e10cSrcweir 	if( !bRet )
331cdf0e10cSrcweir 		rFmtArr.Insert( (VoidPtr)pBoxFmt, rFmtArr.Count() );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir void lcl_ModifyBoxes( SwTableBoxes &rBoxes, const long nOld,
335cdf0e10cSrcweir 						 const long nNew, SvPtrarr& rFmtArr );
336cdf0e10cSrcweir 
lcl_ModifyLines(SwTableLines & rLines,const long nOld,const long nNew,SvPtrarr & rFmtArr,const bool bCheckSum)337cdf0e10cSrcweir void lcl_ModifyLines( SwTableLines &rLines, const long nOld,
338cdf0e10cSrcweir 						 const long nNew, SvPtrarr& rFmtArr, const bool bCheckSum )
339cdf0e10cSrcweir {
340cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < rLines.Count(); ++i )
341cdf0e10cSrcweir 		::lcl_ModifyBoxes( rLines[i]->GetTabBoxes(), nOld, nNew, rFmtArr );
342cdf0e10cSrcweir     if( bCheckSum )
343cdf0e10cSrcweir     {
344cdf0e10cSrcweir         for( sal_uInt16 i = 0; i < rFmtArr.Count(); ++i )
345cdf0e10cSrcweir         {
346cdf0e10cSrcweir             SwFmt* pFmt = (SwFmt*)rFmtArr[i];
347cdf0e10cSrcweir             sal_uInt64 nBox = pFmt->GetFrmSize().GetWidth();
348cdf0e10cSrcweir             nBox *= nNew;
349cdf0e10cSrcweir             nBox /= nOld;
350cdf0e10cSrcweir 			SwFmtFrmSize aNewBox( ATT_VAR_SIZE, SwTwips(nBox), 0 );
351cdf0e10cSrcweir 			pFmt->LockModify();
352cdf0e10cSrcweir             pFmt->SetFmtAttr( aNewBox );
353cdf0e10cSrcweir 			pFmt->UnlockModify();
354cdf0e10cSrcweir         }
355cdf0e10cSrcweir     }
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
lcl_ModifyBoxes(SwTableBoxes & rBoxes,const long nOld,const long nNew,SvPtrarr & rFmtArr)358cdf0e10cSrcweir void lcl_ModifyBoxes( SwTableBoxes &rBoxes, const long nOld,
359cdf0e10cSrcweir 						 const long nNew, SvPtrarr& rFmtArr )
360cdf0e10cSrcweir {
361cdf0e10cSrcweir     sal_uInt64 nSum = 0; // To avoid rounding errors we summarize all box widths
362cdf0e10cSrcweir     sal_uInt64 nOriginalSum = 0; // Sum of original widths
363cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < rBoxes.Count(); ++i )
364cdf0e10cSrcweir 	{
365cdf0e10cSrcweir 		SwTableBox &rBox = *rBoxes[i];
366cdf0e10cSrcweir 		if ( rBox.GetTabLines().Count() )
367cdf0e10cSrcweir         {
368cdf0e10cSrcweir             // For SubTables the rounding problem will not be solved :-(
369cdf0e10cSrcweir 			::lcl_ModifyLines( rBox.GetTabLines(), nOld, nNew, rFmtArr, false );
370cdf0e10cSrcweir         }
371cdf0e10cSrcweir 		//Die Box anpassen
372cdf0e10cSrcweir 		SwFrmFmt *pFmt = rBox.GetFrmFmt();
373cdf0e10cSrcweir         sal_uInt64 nBox = pFmt->GetFrmSize().GetWidth();
374cdf0e10cSrcweir         nOriginalSum += nBox;
375cdf0e10cSrcweir         nBox *= nNew;
376cdf0e10cSrcweir         nBox /= nOld;
377cdf0e10cSrcweir         sal_uInt64 nWishedSum = nOriginalSum;
378cdf0e10cSrcweir         nWishedSum *= nNew;
379cdf0e10cSrcweir         nWishedSum /= nOld;
380cdf0e10cSrcweir         nWishedSum -= nSum;
381cdf0e10cSrcweir         if( nWishedSum > 0 )
382cdf0e10cSrcweir         {
383cdf0e10cSrcweir             if( nBox == nWishedSum )
384cdf0e10cSrcweir                 FmtInArr( rFmtArr, pFmt );
385cdf0e10cSrcweir             else
386cdf0e10cSrcweir             {
387cdf0e10cSrcweir                 nBox = nWishedSum;
388cdf0e10cSrcweir                 pFmt = rBox.ClaimFrmFmt();
389cdf0e10cSrcweir                 SwFmtFrmSize aNewBox( ATT_VAR_SIZE, static_cast< SwTwips >(nBox), 0 );
390cdf0e10cSrcweir                 pFmt->LockModify();
391cdf0e10cSrcweir                 pFmt->SetFmtAttr( aNewBox );
392cdf0e10cSrcweir                 pFmt->UnlockModify();
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir         }
395cdf0e10cSrcweir         else {
396cdf0e10cSrcweir             ASSERT( false, "Rounding error" );
397cdf0e10cSrcweir         }
398cdf0e10cSrcweir         nSum += nBox;
399cdf0e10cSrcweir 	}
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)402cdf0e10cSrcweir void SwTable::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir 	// fange SSize Aenderungen ab, um die Lines/Boxen anzupassen
405cdf0e10cSrcweir 	sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
406cdf0e10cSrcweir 	const SwFmtFrmSize* pNewSize = 0, *pOldSize = 0;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 	if( RES_ATTRSET_CHG == nWhich )
409cdf0e10cSrcweir 	{
410cdf0e10cSrcweir 		if( SFX_ITEM_SET == ((SwAttrSetChg*)pNew)->GetChgSet()->GetItemState(
411cdf0e10cSrcweir 			RES_FRM_SIZE, sal_False, (const SfxPoolItem**)&pNewSize ))
412cdf0e10cSrcweir 			pOldSize = &((SwAttrSetChg*)pOld)->GetChgSet()->GetFrmSize();
413cdf0e10cSrcweir 	}
414cdf0e10cSrcweir 	else if( RES_FRM_SIZE == nWhich )
415cdf0e10cSrcweir 	{
416cdf0e10cSrcweir 		pOldSize = (const SwFmtFrmSize*)pOld;
417cdf0e10cSrcweir 		pNewSize = (const SwFmtFrmSize*)pNew;
418cdf0e10cSrcweir 	}
419cdf0e10cSrcweir     else
420cdf0e10cSrcweir         CheckRegistration( pOld, pNew );
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 	if( pOldSize || pNewSize )
423cdf0e10cSrcweir 	{
424cdf0e10cSrcweir 		if ( !IsModifyLocked() )
425cdf0e10cSrcweir 		{
426cdf0e10cSrcweir 			ASSERT( pOldSize && pOldSize->Which() == RES_FRM_SIZE &&
427cdf0e10cSrcweir 					pNewSize && pNewSize->Which() == RES_FRM_SIZE,
428cdf0e10cSrcweir 					"Kein Old oder New fuer FmtFrmSize-Modify der SwTable." );
429cdf0e10cSrcweir             AdjustWidths( pOldSize->GetWidth(), pNewSize->GetWidth() );
430cdf0e10cSrcweir 		}
431cdf0e10cSrcweir 	}
432cdf0e10cSrcweir }
433cdf0e10cSrcweir 
AdjustWidths(const long nOld,const long nNew)434cdf0e10cSrcweir void SwTable::AdjustWidths( const long nOld, const long nNew )
435cdf0e10cSrcweir {
436cdf0e10cSrcweir     SvPtrarr aFmtArr( (sal_uInt8)aLines[0]->GetTabBoxes().Count(), 1 );
437cdf0e10cSrcweir     ::lcl_ModifyLines( aLines, nOld, nNew, aFmtArr, true );
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir /*************************************************************************
441cdf0e10cSrcweir |*
442cdf0e10cSrcweir |*	SwTable::GetTabCols()
443cdf0e10cSrcweir |*
444cdf0e10cSrcweir |*************************************************************************/
lcl_RefreshHidden(SwTabCols & rToFill,sal_uInt16 nPos)445cdf0e10cSrcweir void lcl_RefreshHidden( SwTabCols &rToFill, sal_uInt16 nPos )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < rToFill.Count(); ++i )
448cdf0e10cSrcweir 	{
449cdf0e10cSrcweir 		if ( Abs((long)(nPos - rToFill[i])) <= COLFUZZY )
450cdf0e10cSrcweir 		{
451cdf0e10cSrcweir             rToFill.SetHidden( i, sal_False );
452cdf0e10cSrcweir 			break;
453cdf0e10cSrcweir 		}
454cdf0e10cSrcweir 	}
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
lcl_SortedTabColInsert(SwTabCols & rToFill,const SwTableBox * pBox,const SwFrmFmt * pTabFmt,const sal_Bool bHidden,const FASTBOOL bRefreshHidden)457cdf0e10cSrcweir void lcl_SortedTabColInsert( SwTabCols &rToFill, const SwTableBox *pBox,
458cdf0e10cSrcweir                    const SwFrmFmt *pTabFmt, const sal_Bool bHidden,
459cdf0e10cSrcweir 				   const FASTBOOL bRefreshHidden )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir 	const long nWish = pTabFmt->GetFrmSize().GetWidth();
462cdf0e10cSrcweir 	const long nAct  = rToFill.GetRight() - rToFill.GetLeft();  // +1 why?
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 	//Der Wert fuer die linke Kante der Box errechnet sich aus den
465cdf0e10cSrcweir 	//Breiten der vorhergehenden Boxen.
466cdf0e10cSrcweir 	sal_uInt16 nPos = 0;
467cdf0e10cSrcweir     sal_uInt16 nSum = 0;
468cdf0e10cSrcweir     sal_uInt16 nLeftMin = 0;
469cdf0e10cSrcweir     sal_uInt16 nRightMax = 0;
470cdf0e10cSrcweir 	const SwTableBox  *pCur  = pBox;
471cdf0e10cSrcweir 	const SwTableLine *pLine = pBox->GetUpper();
472cdf0e10cSrcweir 	while ( pLine )
473cdf0e10cSrcweir 	{	const SwTableBoxes &rBoxes = pLine->GetTabBoxes();
474cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < rBoxes.Count(); ++i )
475cdf0e10cSrcweir 		{
476cdf0e10cSrcweir             SwTwips nWidth = rBoxes[i]->GetFrmFmt()->GetFrmSize().GetWidth();
477cdf0e10cSrcweir             nSum = (sal_uInt16)(nSum + nWidth);
478cdf0e10cSrcweir 			sal_uInt64 nTmp = nSum;
479cdf0e10cSrcweir             nTmp *= nAct;
480cdf0e10cSrcweir 			nTmp /= nWish;
481cdf0e10cSrcweir             if (rBoxes[i] != pCur)
482cdf0e10cSrcweir             {
483cdf0e10cSrcweir                 if ( pLine == pBox->GetUpper() || 0 == nLeftMin )
484cdf0e10cSrcweir                     nLeftMin = (sal_uInt16)(nTmp - nPos);
485cdf0e10cSrcweir 			    nPos = (sal_uInt16)nTmp;
486cdf0e10cSrcweir             }
487cdf0e10cSrcweir             else
488cdf0e10cSrcweir             {
489cdf0e10cSrcweir                 nSum = (sal_uInt16)(nSum - nWidth);
490cdf0e10cSrcweir                 if ( 0 == nRightMax )
491cdf0e10cSrcweir                     nRightMax = (sal_uInt16)(nTmp - nPos);
492cdf0e10cSrcweir                 break;
493cdf0e10cSrcweir             }
494cdf0e10cSrcweir 		}
495cdf0e10cSrcweir 		pCur  = pLine->GetUpper();
496cdf0e10cSrcweir 		pLine = pCur ? pCur->GetUpper() : 0;
497cdf0e10cSrcweir 	}
498cdf0e10cSrcweir 
499cdf0e10cSrcweir     sal_Bool bInsert = !bRefreshHidden;
500cdf0e10cSrcweir 	for ( sal_uInt16 j = 0; bInsert && (j < rToFill.Count()); ++j )
501cdf0e10cSrcweir 	{
502cdf0e10cSrcweir         long nCmp = rToFill[j];
503cdf0e10cSrcweir 		if ( (nPos >= ((nCmp >= COLFUZZY) ? nCmp - COLFUZZY : nCmp)) &&
504cdf0e10cSrcweir 			 (nPos <= (nCmp + COLFUZZY)) )
505cdf0e10cSrcweir 		{
506cdf0e10cSrcweir 			bInsert = sal_False;		//Hat ihn schon.
507cdf0e10cSrcweir 		}
508cdf0e10cSrcweir 		else if ( nPos < nCmp )
509cdf0e10cSrcweir 		{
510cdf0e10cSrcweir     		bInsert = sal_False;
511cdf0e10cSrcweir             rToFill.Insert( nPos, bHidden, j );
512cdf0e10cSrcweir 		}
513cdf0e10cSrcweir 	}
514cdf0e10cSrcweir 	if ( bInsert )
515cdf0e10cSrcweir         rToFill.Insert( nPos, bHidden, rToFill.Count() );
516cdf0e10cSrcweir 	else if ( bRefreshHidden )
517cdf0e10cSrcweir 		::lcl_RefreshHidden( rToFill, nPos );
518cdf0e10cSrcweir 
519cdf0e10cSrcweir     if ( bHidden && !bRefreshHidden )
520cdf0e10cSrcweir     {
521cdf0e10cSrcweir         // calculate minimum/maximum values for the existing entries:
522cdf0e10cSrcweir         nLeftMin = nPos - nLeftMin;
523cdf0e10cSrcweir         nRightMax = nPos + nRightMax;
524cdf0e10cSrcweir 
525cdf0e10cSrcweir         // check if nPos is entry:
526cdf0e10cSrcweir         bool bFoundPos = false;
527cdf0e10cSrcweir         bool bFoundMax = false;
528cdf0e10cSrcweir     	for ( sal_uInt16 j = 0; !(bFoundPos && bFoundMax ) && j < rToFill.Count(); ++j )
529cdf0e10cSrcweir         {
530cdf0e10cSrcweir             SwTabColsEntry& rEntry = rToFill.GetEntry( j );
531cdf0e10cSrcweir             long nCmp = rToFill[j];
532cdf0e10cSrcweir 
533cdf0e10cSrcweir             if ( (nPos >= ((nCmp >= COLFUZZY) ? nCmp - COLFUZZY : nCmp)) &&
534cdf0e10cSrcweir 			     (nPos <= (nCmp + COLFUZZY)) )
535cdf0e10cSrcweir             {
536cdf0e10cSrcweir                 // check if nLeftMin is > old minimum for entry nPos:
537cdf0e10cSrcweir                 const long nOldMin = rEntry.nMin;
538cdf0e10cSrcweir                 if ( nLeftMin > nOldMin )
539cdf0e10cSrcweir                     rEntry.nMin = nLeftMin;
540cdf0e10cSrcweir                 // check if nRightMin is < old maximum for entry nPos:
541cdf0e10cSrcweir                 const long nOldMax = rEntry.nMax;
542cdf0e10cSrcweir                 if ( nRightMax < nOldMax )
543cdf0e10cSrcweir                     rEntry.nMax = nRightMax;
544cdf0e10cSrcweir 
545cdf0e10cSrcweir                 bFoundPos = true;
546cdf0e10cSrcweir             }
547cdf0e10cSrcweir 	    	else if ( (nRightMax >= ((nCmp >= COLFUZZY) ? nCmp - COLFUZZY : nCmp)) &&
548cdf0e10cSrcweir 			          (nRightMax <= (nCmp + COLFUZZY)) )
549cdf0e10cSrcweir             {
550cdf0e10cSrcweir                 // check if nPos is > old minimum for entry nRightMax:
551cdf0e10cSrcweir                 const long nOldMin = rEntry.nMin;
552cdf0e10cSrcweir                 if ( nPos > nOldMin )
553cdf0e10cSrcweir                     rEntry.nMin = nPos;
554cdf0e10cSrcweir 
555cdf0e10cSrcweir                 bFoundMax = true;
556cdf0e10cSrcweir             }
557cdf0e10cSrcweir         }
558cdf0e10cSrcweir     }
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
lcl_ProcessBoxGet(const SwTableBox * pBox,SwTabCols & rToFill,const SwFrmFmt * pTabFmt,FASTBOOL bRefreshHidden)561cdf0e10cSrcweir void lcl_ProcessBoxGet( const SwTableBox *pBox, SwTabCols &rToFill,
562cdf0e10cSrcweir 						const SwFrmFmt *pTabFmt, FASTBOOL bRefreshHidden )
563cdf0e10cSrcweir {
564cdf0e10cSrcweir 	if ( pBox->GetTabLines().Count() )
565cdf0e10cSrcweir 	{
566cdf0e10cSrcweir 		const SwTableLines &rLines = pBox->GetTabLines();
567cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < rLines.Count(); ++i )
568cdf0e10cSrcweir 		{	const SwTableBoxes &rBoxes = rLines[i]->GetTabBoxes();
569cdf0e10cSrcweir 			for ( sal_uInt16 j = 0; j < rBoxes.Count(); ++j )
570cdf0e10cSrcweir 				::lcl_ProcessBoxGet( rBoxes[j], rToFill, pTabFmt, bRefreshHidden);
571cdf0e10cSrcweir 		}
572cdf0e10cSrcweir 	}
573cdf0e10cSrcweir 	else
574cdf0e10cSrcweir 		::lcl_SortedTabColInsert( rToFill, pBox, pTabFmt, sal_False, bRefreshHidden );
575cdf0e10cSrcweir }
576cdf0e10cSrcweir 
lcl_ProcessLineGet(const SwTableLine * pLine,SwTabCols & rToFill,const SwFrmFmt * pTabFmt)577cdf0e10cSrcweir void lcl_ProcessLineGet( const SwTableLine *pLine, SwTabCols &rToFill,
578cdf0e10cSrcweir 						 const SwFrmFmt *pTabFmt )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < pLine->GetTabBoxes().Count(); ++i )
581cdf0e10cSrcweir 	{
582cdf0e10cSrcweir 		const SwTableBox *pBox = pLine->GetTabBoxes()[i];
583cdf0e10cSrcweir 		if ( pBox->GetSttNd() )
584cdf0e10cSrcweir 			::lcl_SortedTabColInsert( rToFill, pBox, pTabFmt, sal_True, sal_False );
585cdf0e10cSrcweir 		else
586cdf0e10cSrcweir 			for ( sal_uInt16 j = 0; j < pBox->GetTabLines().Count(); ++j )
587cdf0e10cSrcweir 				::lcl_ProcessLineGet( pBox->GetTabLines()[j], rToFill, pTabFmt );
588cdf0e10cSrcweir 	}
589cdf0e10cSrcweir }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir // MS: Sonst Absturz auf der DEC-Kiste
592cdf0e10cSrcweir //
593cdf0e10cSrcweir #if defined(ALPHA) && defined(WNT)
594cdf0e10cSrcweir #pragma optimize("", off)
595cdf0e10cSrcweir #endif
596cdf0e10cSrcweir 
GetTabCols(SwTabCols & rToFill,const SwTableBox * pStart,sal_Bool bRefreshHidden,sal_Bool bCurRowOnly) const597cdf0e10cSrcweir void SwTable::GetTabCols( SwTabCols &rToFill, const SwTableBox *pStart,
598cdf0e10cSrcweir 			  sal_Bool bRefreshHidden, sal_Bool bCurRowOnly ) const
599cdf0e10cSrcweir {
600cdf0e10cSrcweir 	//MA 30. Nov. 95: Opt: wenn bHidden gesetzt ist, wird nur das Hidden
601cdf0e10cSrcweir 	//Array aktualisiert.
602cdf0e10cSrcweir 	if ( bRefreshHidden )
603cdf0e10cSrcweir 	{
604cdf0e10cSrcweir 		//Korrekturen entfernen
605cdf0e10cSrcweir 		sal_uInt16 i;
606cdf0e10cSrcweir 		for ( i = 0; i < rToFill.Count(); ++i )
607cdf0e10cSrcweir         {
608cdf0e10cSrcweir             SwTabColsEntry& rEntry = rToFill.GetEntry( i );
609cdf0e10cSrcweir             rEntry.nPos -= rToFill.GetLeft();
610cdf0e10cSrcweir             rEntry.nMin -= rToFill.GetLeft();
611cdf0e10cSrcweir             rEntry.nMax -= rToFill.GetLeft();
612cdf0e10cSrcweir         }
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 		//Alle sind hidden, dann die sichtbaren eintragen.
615cdf0e10cSrcweir         for ( i = 0; i < rToFill.Count(); ++i )
616cdf0e10cSrcweir             rToFill.SetHidden( i, sal_True );
617cdf0e10cSrcweir 	}
618cdf0e10cSrcweir 	else
619cdf0e10cSrcweir 	{
620cdf0e10cSrcweir 		rToFill.Remove( 0, rToFill.Count() );
621cdf0e10cSrcweir     }
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 	//Eingetragen werden:
624cdf0e10cSrcweir 	//1. Alle Boxen unterhalb der dem Start uebergeordneten Line sowie
625cdf0e10cSrcweir 	//	 deren untergeordnete Boxen falls vorhanden.
626cdf0e10cSrcweir 	//2. Ausgehend von der Line die uebergeordnete Box sowie deren Nachbarn;
627cdf0e10cSrcweir 	//	 nicht aber deren untergeordnete.
628cdf0e10cSrcweir 	//3. Mit der der Boxenkette uebergeordneten Line wieder wie 2. bis einer
629cdf0e10cSrcweir 	//	 Line keine Box (sondern die Table) uebergeordnet ist.
630cdf0e10cSrcweir 	//Es werden nur diejenigen Boxen eingetragen, die keine weiteren Zeilen
631cdf0e10cSrcweir 	//enhalten. Die eintragende Funktion sorgt dafuer, dass keine doppelten
632cdf0e10cSrcweir 	//eingetragen werden. Um dies zu gewaehrleisten wird mit einer gewissen
633cdf0e10cSrcweir 	//Unschaerfe gearbeitet (um Rundungsfehler auszuschalten).
634cdf0e10cSrcweir 	//Es werden nur die linken Kanten der Boxen eingetragen.
635cdf0e10cSrcweir 	//Am Schluss wird der Erste wieder ausgetragen denn er ist bereits vom
636cdf0e10cSrcweir 	//Rand abgedeckt.
637cdf0e10cSrcweir 
638cdf0e10cSrcweir 	//4. Nochmalige abscannen der Tabelle und eintragen _aller_ Boxen,
639cdf0e10cSrcweir 	//	 jetzt aber als Hidden.
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 	const SwFrmFmt *pTabFmt = GetFrmFmt();
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 	//1.
644cdf0e10cSrcweir 	const SwTableBoxes &rBoxes = pStart->GetUpper()->GetTabBoxes();
645cdf0e10cSrcweir 
646cdf0e10cSrcweir     sal_uInt16 i;
647cdf0e10cSrcweir 	for ( i = 0; i < rBoxes.Count(); ++i )
648cdf0e10cSrcweir 		::lcl_ProcessBoxGet( rBoxes[i], rToFill, pTabFmt, bRefreshHidden );
649cdf0e10cSrcweir 
650cdf0e10cSrcweir 	//2. und 3.
651cdf0e10cSrcweir 	const SwTableLine *pLine = pStart->GetUpper()->GetUpper() ?
652cdf0e10cSrcweir 								pStart->GetUpper()->GetUpper()->GetUpper() : 0;
653cdf0e10cSrcweir 	while ( pLine )
654cdf0e10cSrcweir 	{
655cdf0e10cSrcweir         const SwTableBoxes &rBoxes2 = pLine->GetTabBoxes();
656cdf0e10cSrcweir         for ( sal_uInt16 k = 0; k < rBoxes2.Count(); ++k )
657cdf0e10cSrcweir             ::lcl_SortedTabColInsert( rToFill, rBoxes2[k],
658cdf0e10cSrcweir 									  pTabFmt, sal_False, bRefreshHidden );
659cdf0e10cSrcweir 		pLine = pLine->GetUpper() ? pLine->GetUpper()->GetUpper() : 0;
660cdf0e10cSrcweir 	}
661cdf0e10cSrcweir 
662cdf0e10cSrcweir 	if ( !bRefreshHidden )
663cdf0e10cSrcweir 	{
664cdf0e10cSrcweir 		//4.
665cdf0e10cSrcweir 		if ( !bCurRowOnly )
666cdf0e10cSrcweir 		{
667cdf0e10cSrcweir 			for ( i = 0; i < aLines.Count(); ++i )
668cdf0e10cSrcweir 				::lcl_ProcessLineGet( aLines[i], rToFill, pTabFmt );
669cdf0e10cSrcweir 		}
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 		rToFill.Remove( 0, 1 );
672cdf0e10cSrcweir     }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir 	//Die Koordinaten sind jetzt relativ zum linken Rand der Tabelle - also
675cdf0e10cSrcweir 	//relativ zum nLeft vom SwTabCols. Die Werte werden aber relativ zum
676cdf0e10cSrcweir 	//linken Rand - also nLeftMin vom SwTabCols - erwartet.
677cdf0e10cSrcweir 	//Alle Werte muessen also um nLeft erweitert werden.
678cdf0e10cSrcweir 	for ( i = 0; i < rToFill.Count(); ++i )
679cdf0e10cSrcweir     {
680cdf0e10cSrcweir         SwTabColsEntry& rEntry = rToFill.GetEntry( i );
681cdf0e10cSrcweir         rEntry.nPos += rToFill.GetLeft();
682cdf0e10cSrcweir         rEntry.nMin += rToFill.GetLeft();
683cdf0e10cSrcweir         rEntry.nMax += rToFill.GetLeft();
684cdf0e10cSrcweir     }
685cdf0e10cSrcweir }
686cdf0e10cSrcweir 
687cdf0e10cSrcweir #if defined(ALPHA) && defined(WNT)
688cdf0e10cSrcweir #pragma optimize("", on)
689cdf0e10cSrcweir #endif
690cdf0e10cSrcweir 
691cdf0e10cSrcweir /*************************************************************************
692cdf0e10cSrcweir |*
693cdf0e10cSrcweir |*	SwTable::SetTabCols()
694cdf0e10cSrcweir |*
695cdf0e10cSrcweir |*************************************************************************/
696cdf0e10cSrcweir //Struktur zur Parameteruebergabe
697cdf0e10cSrcweir struct Parm
698cdf0e10cSrcweir {
699cdf0e10cSrcweir 	const SwTabCols &rNew;
700cdf0e10cSrcweir 	const SwTabCols &rOld;
701cdf0e10cSrcweir 	long nNewWish,
702cdf0e10cSrcweir 		 nOldWish;
703cdf0e10cSrcweir 	SvPtrarr aBoxArr;
704cdf0e10cSrcweir 	SwShareBoxFmts aShareFmts;
705cdf0e10cSrcweir 
ParmParm706cdf0e10cSrcweir 	Parm( const SwTabCols &rN, const SwTabCols &rO ) :
707cdf0e10cSrcweir 		rNew( rN ), rOld( rO ), aBoxArr( 10, 1 ) {}
708cdf0e10cSrcweir };
BoxInArr(SvPtrarr & rArr,SwTableBox * pBox)709cdf0e10cSrcweir inline sal_Bool BoxInArr( SvPtrarr& rArr, SwTableBox* pBox )
710cdf0e10cSrcweir {
711cdf0e10cSrcweir 	sal_Bool bRet = USHRT_MAX != rArr.GetPos( (VoidPtr)pBox );
712cdf0e10cSrcweir 	if( !bRet )
713cdf0e10cSrcweir 		rArr.Insert( (VoidPtr)pBox, rArr.Count() );
714cdf0e10cSrcweir 	return bRet;
715cdf0e10cSrcweir }
716cdf0e10cSrcweir 
717cdf0e10cSrcweir void lcl_ProcessBoxSet( SwTableBox *pBox, Parm &rParm );
718cdf0e10cSrcweir 
lcl_ProcessLine(SwTableLine * pLine,Parm & rParm)719cdf0e10cSrcweir void lcl_ProcessLine( SwTableLine *pLine, Parm &rParm )
720cdf0e10cSrcweir {
721cdf0e10cSrcweir 	SwTableBoxes &rBoxes = pLine->GetTabBoxes();
722cdf0e10cSrcweir 	for ( int i = rBoxes.Count()-1; i >= 0; --i )
723cdf0e10cSrcweir         ::lcl_ProcessBoxSet( rBoxes[ static_cast< sal_uInt16 >(i) ], rParm );
724cdf0e10cSrcweir }
725cdf0e10cSrcweir 
lcl_ProcessBoxSet(SwTableBox * pBox,Parm & rParm)726cdf0e10cSrcweir void lcl_ProcessBoxSet( SwTableBox *pBox, Parm &rParm )
727cdf0e10cSrcweir {
728cdf0e10cSrcweir 	if ( pBox->GetTabLines().Count() )
729cdf0e10cSrcweir 	{	SwTableLines &rLines = pBox->GetTabLines();
730cdf0e10cSrcweir 		for ( int i = rLines.Count()-1; i >= 0; --i )
731cdf0e10cSrcweir             lcl_ProcessLine( rLines[ static_cast< sal_uInt16 >(i) ], rParm );
732cdf0e10cSrcweir 	}
733cdf0e10cSrcweir 	else
734cdf0e10cSrcweir 	{
735cdf0e10cSrcweir 		//Aktuelle Position (linke und rechte Kante berechnen) und im
736cdf0e10cSrcweir 		//alten TabCols suchen. Im neuen TabCols die Werte vergleichen und
737cdf0e10cSrcweir 		//wenn es Unterschiede gibt die Box entsprechend anpassen.
738cdf0e10cSrcweir 		//Wenn an der veraenderten Kante kein Nachbar existiert werden auch
739cdf0e10cSrcweir 		//alle uebergeordneten Boxen angepasst.
740cdf0e10cSrcweir 
741cdf0e10cSrcweir 		const long nOldAct = rParm.rOld.GetRight() -
742cdf0e10cSrcweir 							 rParm.rOld.GetLeft(); // +1 why?
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 		//Der Wert fuer die linke Kante der Box errechnet sich aus den
745cdf0e10cSrcweir 		//Breiten der vorhergehenden Boxen plus dem linken Rand
746cdf0e10cSrcweir 		long nLeft = rParm.rOld.GetLeft();
747cdf0e10cSrcweir 		const  SwTableBox  *pCur  = pBox;
748cdf0e10cSrcweir 		const  SwTableLine *pLine = pBox->GetUpper();
749cdf0e10cSrcweir 
750cdf0e10cSrcweir 		while ( pLine )
751cdf0e10cSrcweir 		{	const SwTableBoxes &rBoxes = pLine->GetTabBoxes();
752cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; (i < rBoxes.Count()) && (rBoxes[i] != pCur); ++i)
753cdf0e10cSrcweir 			{
754cdf0e10cSrcweir 				sal_uInt64 nWidth = rBoxes[i]->GetFrmFmt()->
755cdf0e10cSrcweir 										GetFrmSize().GetWidth();
756cdf0e10cSrcweir 				nWidth *= nOldAct;
757cdf0e10cSrcweir 				nWidth /= rParm.nOldWish;
758cdf0e10cSrcweir 				nLeft += (sal_uInt16)nWidth;
759cdf0e10cSrcweir 			}
760cdf0e10cSrcweir 			pCur  = pLine->GetUpper();
761cdf0e10cSrcweir 			pLine = pCur ? pCur->GetUpper() : 0;
762cdf0e10cSrcweir 		}
763cdf0e10cSrcweir 		long nLeftDiff;
764cdf0e10cSrcweir 		long nRightDiff = 0;
765cdf0e10cSrcweir 		if ( nLeft != rParm.rOld.GetLeft() ) //Es gibt noch Boxen davor.
766cdf0e10cSrcweir 		{
767cdf0e10cSrcweir 			//Rechte Kante ist linke Kante plus Breite.
768cdf0e10cSrcweir 			sal_uInt64 nWidth = pBox->GetFrmFmt()->GetFrmSize().GetWidth();
769cdf0e10cSrcweir 			nWidth *= nOldAct;
770cdf0e10cSrcweir 			nWidth /= rParm.nOldWish;
771cdf0e10cSrcweir 			long nRight = nLeft + (long)nWidth;
772cdf0e10cSrcweir 			sal_uInt16 nLeftPos  = USHRT_MAX,
773cdf0e10cSrcweir 				   nRightPos = USHRT_MAX;
774cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; i < rParm.rOld.Count(); ++i )
775cdf0e10cSrcweir 			{
776cdf0e10cSrcweir 				if ( nLeft >= (rParm.rOld[i] - COLFUZZY) &&
777cdf0e10cSrcweir 					 nLeft <= (rParm.rOld[i] + COLFUZZY) )
778cdf0e10cSrcweir 					nLeftPos = i;
779cdf0e10cSrcweir 				else if ( nRight >= (rParm.rOld[i] - COLFUZZY) &&
780cdf0e10cSrcweir 						  nRight <= (rParm.rOld[i] + COLFUZZY) )
781cdf0e10cSrcweir 					nRightPos = i;
782cdf0e10cSrcweir 			}
783cdf0e10cSrcweir 			nLeftDiff = nLeftPos != USHRT_MAX ?
784cdf0e10cSrcweir 					(int)rParm.rOld[nLeftPos] - (int)rParm.rNew[nLeftPos] : 0;
785cdf0e10cSrcweir 			nRightDiff= nRightPos!= USHRT_MAX ?
786cdf0e10cSrcweir 					(int)rParm.rNew[nRightPos] - (int)rParm.rOld[nRightPos] : 0;
787cdf0e10cSrcweir 		}
788cdf0e10cSrcweir 		else	//Die erste Box.
789cdf0e10cSrcweir 		{
790cdf0e10cSrcweir 			nLeftDiff = (long)rParm.rOld.GetLeft() - (long)rParm.rNew.GetLeft();
791cdf0e10cSrcweir 			if ( rParm.rOld.Count() )
792cdf0e10cSrcweir 			{
793cdf0e10cSrcweir 				//Differnz zu der Kante berechnen, von der die erste Box
794cdf0e10cSrcweir 				//beruehrt wird.
795cdf0e10cSrcweir 				sal_uInt64 nWidth = pBox->GetFrmFmt()->GetFrmSize().GetWidth();
796cdf0e10cSrcweir 				nWidth *= nOldAct;
797cdf0e10cSrcweir 				nWidth /= rParm.nOldWish;
798cdf0e10cSrcweir 				long nTmp = (long)nWidth;
799cdf0e10cSrcweir 				nTmp += rParm.rOld.GetLeft();
800cdf0e10cSrcweir 				sal_uInt16 nLeftPos = USHRT_MAX;
801cdf0e10cSrcweir 				for ( sal_uInt16 i = 0; i < rParm.rOld.Count() &&
802cdf0e10cSrcweir 									nLeftPos == USHRT_MAX; ++i )
803cdf0e10cSrcweir 				{
804cdf0e10cSrcweir 					if ( nTmp >= (rParm.rOld[i] - COLFUZZY) &&
805cdf0e10cSrcweir 						 nTmp <= (rParm.rOld[i] + COLFUZZY) )
806cdf0e10cSrcweir 						nLeftPos = i;
807cdf0e10cSrcweir 				}
808cdf0e10cSrcweir 				if ( nLeftPos != USHRT_MAX )
809cdf0e10cSrcweir 					nRightDiff = (long)rParm.rNew[nLeftPos] -
810cdf0e10cSrcweir 								 (long)rParm.rOld[nLeftPos];
811cdf0e10cSrcweir 			}
812cdf0e10cSrcweir //MA 11. Feb. 99: #61577# 0 sollte doch gerade richtig sein, weil die
813cdf0e10cSrcweir //Kante doch schon in SetTabCols() korrigiert wurde.
814cdf0e10cSrcweir //			else
815cdf0e10cSrcweir //				nRightDiff = (long)rParm.rNew.GetRight() -
816cdf0e10cSrcweir //							 (long)rParm.rOld.GetRight();
817cdf0e10cSrcweir 		}
818cdf0e10cSrcweir 
819cdf0e10cSrcweir         if( pBox->getRowSpan() == 1 )
820cdf0e10cSrcweir         {
821cdf0e10cSrcweir             SwTableBoxes& rTblBoxes = pBox->GetUpper()->GetTabBoxes();
822cdf0e10cSrcweir             sal_uInt16 nPos = rTblBoxes.C40_GETPOS( SwTableBox, pBox );
823cdf0e10cSrcweir             if( nPos && rTblBoxes[ nPos - 1 ]->getRowSpan() != 1 )
824cdf0e10cSrcweir                 nLeftDiff = 0;
825cdf0e10cSrcweir             if( nPos + 1 < rTblBoxes.Count() &&
826cdf0e10cSrcweir                 rTblBoxes[ nPos + 1 ]->getRowSpan() != 1 )
827cdf0e10cSrcweir                 nRightDiff = 0;
828cdf0e10cSrcweir         }
829cdf0e10cSrcweir         else
830cdf0e10cSrcweir             nLeftDiff = nRightDiff = 0;
831cdf0e10cSrcweir 
832cdf0e10cSrcweir 		if ( nLeftDiff || nRightDiff )
833cdf0e10cSrcweir 		{
834cdf0e10cSrcweir 			//Die Differenz ist der tatsaechliche Differenzbetrag; die
835cdf0e10cSrcweir 			//Attribute der Boxen um diesen Betrag anzupassen macht keinen
836cdf0e10cSrcweir 			//Sinn wenn die Tabelle gestrecht ist. Der Differenzbetrag muss
837cdf0e10cSrcweir 			//entsprechend umgerechnet werden.
838cdf0e10cSrcweir 			long nTmp = rParm.rNew.GetRight() - rParm.rNew.GetLeft(); // +1 why?
839cdf0e10cSrcweir 			nLeftDiff *= rParm.nNewWish;
840cdf0e10cSrcweir 			nLeftDiff /= nTmp;
841cdf0e10cSrcweir 			nRightDiff *= rParm.nNewWish;
842cdf0e10cSrcweir 			nRightDiff /= nTmp;
843cdf0e10cSrcweir 			long nDiff = nLeftDiff + nRightDiff;
844cdf0e10cSrcweir 
845cdf0e10cSrcweir 			//Box und alle uebergeordneten um den Differenzbetrag anpassen.
846cdf0e10cSrcweir             while ( pBox )
847cdf0e10cSrcweir 			{
848cdf0e10cSrcweir                 SwFmtFrmSize aFmtFrmSize( pBox->GetFrmFmt()->GetFrmSize() );
849cdf0e10cSrcweir                 aFmtFrmSize.SetWidth( aFmtFrmSize.GetWidth() + nDiff );
850cdf0e10cSrcweir                 if ( aFmtFrmSize.GetWidth() < 0 )
851cdf0e10cSrcweir                     aFmtFrmSize.SetWidth( -aFmtFrmSize.GetWidth() );
852cdf0e10cSrcweir                 rParm.aShareFmts.SetSize( *pBox, aFmtFrmSize );
853cdf0e10cSrcweir 
854cdf0e10cSrcweir                 // The outer cells of the last row are responsible to adjust a surrounding cell.
855cdf0e10cSrcweir                 // Last line check:
856cdf0e10cSrcweir                 if ( pBox->GetUpper()->GetUpper() &&
857cdf0e10cSrcweir                      pBox->GetUpper() != pBox->GetUpper()->GetUpper()->GetTabLines()
858cdf0e10cSrcweir                         [pBox->GetUpper()->GetUpper()->GetTabLines().Count()-1])
859cdf0e10cSrcweir                 {
860cdf0e10cSrcweir                    pBox = 0;
861cdf0e10cSrcweir                 }
862cdf0e10cSrcweir                 else
863cdf0e10cSrcweir                 {
864cdf0e10cSrcweir                     // Middle cell check:
865cdf0e10cSrcweir                     if ( pBox != pBox->GetUpper()->GetTabBoxes()[0] )
866cdf0e10cSrcweir                         nDiff = nRightDiff;
867cdf0e10cSrcweir 
868cdf0e10cSrcweir                     if ( pBox != pBox->GetUpper()->GetTabBoxes()
869cdf0e10cSrcweir                                 [pBox->GetUpper()->GetTabBoxes().Count()-1] )
870cdf0e10cSrcweir                         nDiff -= nRightDiff;
871cdf0e10cSrcweir 
872cdf0e10cSrcweir                     pBox = nDiff ? pBox->GetUpper()->GetUpper() : 0;
873cdf0e10cSrcweir                 }
874cdf0e10cSrcweir             }
875cdf0e10cSrcweir 		}
876cdf0e10cSrcweir 	}
877cdf0e10cSrcweir }
878cdf0e10cSrcweir 
lcl_ProcessBoxPtr(SwTableBox * pBox,SvPtrarr & rBoxArr,sal_Bool bBefore)879cdf0e10cSrcweir void lcl_ProcessBoxPtr( SwTableBox *pBox, SvPtrarr &rBoxArr,
880cdf0e10cSrcweir 						   sal_Bool bBefore )
881cdf0e10cSrcweir {
882cdf0e10cSrcweir 	if ( pBox->GetTabLines().Count() )
883cdf0e10cSrcweir 	{
884cdf0e10cSrcweir 		const SwTableLines &rLines = pBox->GetTabLines();
885cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < rLines.Count(); ++i )
886cdf0e10cSrcweir 		{
887cdf0e10cSrcweir 			const SwTableBoxes &rBoxes = rLines[i]->GetTabBoxes();
888cdf0e10cSrcweir 			for ( sal_uInt16 j = 0; j < rBoxes.Count(); ++j )
889cdf0e10cSrcweir 				::lcl_ProcessBoxPtr( rBoxes[j], rBoxArr, bBefore );
890cdf0e10cSrcweir 		}
891cdf0e10cSrcweir 	}
892cdf0e10cSrcweir 	else if ( bBefore )
893cdf0e10cSrcweir 		rBoxArr.Insert( (VoidPtr)pBox, 0 );
894cdf0e10cSrcweir 	else
895cdf0e10cSrcweir 		rBoxArr.Insert( (VoidPtr)pBox, rBoxArr.Count() );
896cdf0e10cSrcweir }
897cdf0e10cSrcweir 
898cdf0e10cSrcweir void lcl_AdjustBox( SwTableBox *pBox, const long nDiff, Parm &rParm );
899cdf0e10cSrcweir 
lcl_AdjustLines(SwTableLines & rLines,const long nDiff,Parm & rParm)900cdf0e10cSrcweir void lcl_AdjustLines( SwTableLines &rLines, const long nDiff, Parm &rParm )
901cdf0e10cSrcweir {
902cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < rLines.Count(); ++i )
903cdf0e10cSrcweir 	{
904cdf0e10cSrcweir 		SwTableBox *pBox = rLines[i]->GetTabBoxes()
905cdf0e10cSrcweir 								[rLines[i]->GetTabBoxes().Count()-1];
906cdf0e10cSrcweir 		lcl_AdjustBox( pBox, nDiff, rParm );
907cdf0e10cSrcweir 	}
908cdf0e10cSrcweir }
909cdf0e10cSrcweir 
lcl_AdjustBox(SwTableBox * pBox,const long nDiff,Parm & rParm)910cdf0e10cSrcweir void lcl_AdjustBox( SwTableBox *pBox, const long nDiff, Parm &rParm )
911cdf0e10cSrcweir {
912cdf0e10cSrcweir 	if ( pBox->GetTabLines().Count() )
913cdf0e10cSrcweir 		::lcl_AdjustLines( pBox->GetTabLines(), nDiff, rParm );
914cdf0e10cSrcweir 
915cdf0e10cSrcweir 	//Groesse der Box anpassen.
916cdf0e10cSrcweir 	SwFmtFrmSize aFmtFrmSize( pBox->GetFrmFmt()->GetFrmSize() );
917cdf0e10cSrcweir 	aFmtFrmSize.SetWidth( aFmtFrmSize.GetWidth() + nDiff );
918cdf0e10cSrcweir //#30009#		if ( aFmtFrmSize.GetWidth() < 0 )
919cdf0e10cSrcweir //			aFmtFrmSize.SetWidth( -aFmtFrmSize.GetWidth() );
920cdf0e10cSrcweir 
921cdf0e10cSrcweir 	rParm.aShareFmts.SetSize( *pBox, aFmtFrmSize );
922cdf0e10cSrcweir }
923cdf0e10cSrcweir 
SetTabCols(const SwTabCols & rNew,const SwTabCols & rOld,const SwTableBox * pStart,sal_Bool bCurRowOnly)924cdf0e10cSrcweir void SwTable::SetTabCols( const SwTabCols &rNew, const SwTabCols &rOld,
925cdf0e10cSrcweir 						  const SwTableBox *pStart, sal_Bool bCurRowOnly )
926cdf0e10cSrcweir {
927cdf0e10cSrcweir     CHECK_TABLE( *this )
928cdf0e10cSrcweir 
929cdf0e10cSrcweir 	SetHTMLTableLayout( 0 ); 	// MIB 9.7.97: HTML-Layout loeschen
930cdf0e10cSrcweir 
931cdf0e10cSrcweir     // FME: Made rOld const. The caller is responsible for passing correct
932cdf0e10cSrcweir     // values of rOld. Therefore we do not have to call GetTabCols anymore:
933cdf0e10cSrcweir     //GetTabCols( rOld, pStart );
934cdf0e10cSrcweir 
935cdf0e10cSrcweir 	Parm aParm( rNew, rOld );
936cdf0e10cSrcweir 
937cdf0e10cSrcweir 	ASSERT( rOld.Count() == rNew.Count(), "Columnanzahl veraendert.");
938cdf0e10cSrcweir 
939cdf0e10cSrcweir 	//Raender verarbeiten. Groesse der Tabelle und ein paar Boxen mussen
940cdf0e10cSrcweir 	//angepasst werden. Bei der Groesseneinstellung darf allerdings das
941cdf0e10cSrcweir 	//Modify nicht verarbeitet werden - dieses wuerde alle Boxen anpassen
942cdf0e10cSrcweir 	//und das koennen wir ueberhaupt nicht gebrauchen.
943cdf0e10cSrcweir 	SwFrmFmt *pFmt = GetFrmFmt();
944cdf0e10cSrcweir 	aParm.nOldWish = aParm.nNewWish = pFmt->GetFrmSize().GetWidth();
945cdf0e10cSrcweir 	if ( (rOld.GetLeft() != rNew.GetLeft()) ||
946cdf0e10cSrcweir 		 (rOld.GetRight()!= rNew.GetRight()) )
947cdf0e10cSrcweir 	{
948cdf0e10cSrcweir 		LockModify();
949cdf0e10cSrcweir 		{
950cdf0e10cSrcweir 			SvxLRSpaceItem aLR( pFmt->GetLRSpace() );
951cdf0e10cSrcweir             SvxShadowItem aSh( pFmt->GetShadow() );
952cdf0e10cSrcweir 
953cdf0e10cSrcweir             SwTwips nShRight = aSh.CalcShadowSpace( SHADOW_RIGHT );
954cdf0e10cSrcweir             SwTwips nShLeft = aSh.CalcShadowSpace( SHADOW_LEFT );
955cdf0e10cSrcweir 
956cdf0e10cSrcweir 			aLR.SetLeft ( rNew.GetLeft() - nShLeft );
957cdf0e10cSrcweir             aLR.SetRight( rNew.GetRightMax() - rNew.GetRight() - nShRight );
958cdf0e10cSrcweir             pFmt->SetFmtAttr( aLR );
959cdf0e10cSrcweir 
960cdf0e10cSrcweir 			//Die Ausrichtung der Tabelle muss entsprechend angepasst werden,
961cdf0e10cSrcweir 			//das geschieht so, dass die Tabelle genauso stehenbleibt wie der
962cdf0e10cSrcweir 			//Anwender sie gerade hingezuppelt hat.
963cdf0e10cSrcweir 			SwFmtHoriOrient aOri( pFmt->GetHoriOrient() );
964cdf0e10cSrcweir 			if(text::HoriOrientation::NONE != aOri.GetHoriOrient())
965cdf0e10cSrcweir 			{
966cdf0e10cSrcweir 				const sal_Bool bLeftDist = rNew.GetLeft() != nShLeft;
967cdf0e10cSrcweir 				const sal_Bool bRightDist = rNew.GetRight() + nShRight != rNew.GetRightMax();
968cdf0e10cSrcweir 				if(!bLeftDist && !bRightDist)
969cdf0e10cSrcweir 					aOri.SetHoriOrient( text::HoriOrientation::FULL );
970cdf0e10cSrcweir 				else if(!bRightDist && rNew.GetLeft() > nShLeft )
971cdf0e10cSrcweir 					aOri.SetHoriOrient( text::HoriOrientation::RIGHT );
972cdf0e10cSrcweir 				else if(!bLeftDist && rNew.GetRight() + nShRight < rNew.GetRightMax())
973cdf0e10cSrcweir 					aOri.SetHoriOrient( text::HoriOrientation::LEFT );
974cdf0e10cSrcweir 				else
975cdf0e10cSrcweir 					aOri.SetHoriOrient( text::HoriOrientation::NONE );
976cdf0e10cSrcweir 			}
977cdf0e10cSrcweir             pFmt->SetFmtAttr( aOri );
978cdf0e10cSrcweir 		}
979cdf0e10cSrcweir 		const long nAct = rOld.GetRight() - rOld.GetLeft(); // +1 why?
980cdf0e10cSrcweir 		long nTabDiff = 0;
981cdf0e10cSrcweir 
982cdf0e10cSrcweir 		if ( rOld.GetLeft() != rNew.GetLeft() )
983cdf0e10cSrcweir 		{
984cdf0e10cSrcweir 			nTabDiff = rOld.GetLeft() - rNew.GetLeft();
985cdf0e10cSrcweir 			nTabDiff *= aParm.nOldWish;
986cdf0e10cSrcweir 			nTabDiff /= nAct;
987cdf0e10cSrcweir 		}
988cdf0e10cSrcweir 		if ( rOld.GetRight() != rNew.GetRight() )
989cdf0e10cSrcweir 		{
990cdf0e10cSrcweir 			long nDiff = rNew.GetRight() - rOld.GetRight();
991cdf0e10cSrcweir 			nDiff *= aParm.nOldWish;
992cdf0e10cSrcweir 			nDiff /= nAct;
993cdf0e10cSrcweir 			nTabDiff += nDiff;
994cdf0e10cSrcweir             if( !IsNewModel() )
995cdf0e10cSrcweir                 ::lcl_AdjustLines( GetTabLines(), nDiff, aParm );
996cdf0e10cSrcweir 		}
997cdf0e10cSrcweir 
998cdf0e10cSrcweir 		//Groesse der Tabelle anpassen. Es muss beachtet werden, das die
999cdf0e10cSrcweir 		//Tabelle gestrecht sein kann.
1000cdf0e10cSrcweir 		if ( nTabDiff )
1001cdf0e10cSrcweir 		{
1002cdf0e10cSrcweir 			aParm.nNewWish += nTabDiff;
1003cdf0e10cSrcweir 			if ( aParm.nNewWish < 0 )
1004cdf0e10cSrcweir 				aParm.nNewWish = USHRT_MAX;	//Uuups! Eine Rolle rueckwaerts.
1005cdf0e10cSrcweir 			SwFmtFrmSize aSz( pFmt->GetFrmSize() );
1006cdf0e10cSrcweir 			if ( aSz.GetWidth() != aParm.nNewWish )
1007cdf0e10cSrcweir 			{
1008cdf0e10cSrcweir 				aSz.SetWidth( aParm.nNewWish );
1009cdf0e10cSrcweir 				aSz.SetWidthPercent( 0 );
1010cdf0e10cSrcweir                 pFmt->SetFmtAttr( aSz );
1011cdf0e10cSrcweir 			}
1012cdf0e10cSrcweir 		}
1013cdf0e10cSrcweir 		UnlockModify();
1014cdf0e10cSrcweir 	}
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir     if( IsNewModel() )
1017cdf0e10cSrcweir         NewSetTabCols( aParm, rNew, rOld, pStart, bCurRowOnly );
1018cdf0e10cSrcweir     else
1019cdf0e10cSrcweir 	{
1020cdf0e10cSrcweir 		if ( bCurRowOnly )
1021cdf0e10cSrcweir 		{
1022cdf0e10cSrcweir 			//Um die aktuelle Zeile anzupassen muessen wir analog zu dem
1023cdf0e10cSrcweir 			//Verfahren zum fuellen der TabCols (siehe GetTabCols()) die
1024cdf0e10cSrcweir 			//Boxen der aktuellen Zeile abklappern.
1025cdf0e10cSrcweir 			//Leider muessen wir auch hier dafuer sorgen, dass die Boxen von
1026cdf0e10cSrcweir 			//hinten nach vorne bzw. von innen nach aussen veraendert werden.
1027cdf0e10cSrcweir 			//Der beste Weg hierzu scheint mir darin zu liegen die
1028cdf0e10cSrcweir 			//entsprechenden Boxen in einem PtrArray vorzumerken.
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir 			const SwTableBoxes &rBoxes = pStart->GetUpper()->GetTabBoxes();
1031cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; i < rBoxes.Count(); ++i )
1032cdf0e10cSrcweir 				::lcl_ProcessBoxPtr( rBoxes[i], aParm.aBoxArr, sal_False );
1033cdf0e10cSrcweir 
1034cdf0e10cSrcweir 			const SwTableLine *pLine = pStart->GetUpper()->GetUpper() ?
1035cdf0e10cSrcweir 									pStart->GetUpper()->GetUpper()->GetUpper() : 0;
1036cdf0e10cSrcweir 			const SwTableBox  *pExcl = pStart->GetUpper()->GetUpper();
1037cdf0e10cSrcweir 			while ( pLine )
1038cdf0e10cSrcweir 			{
1039cdf0e10cSrcweir                 const SwTableBoxes &rBoxes2 = pLine->GetTabBoxes();
1040cdf0e10cSrcweir 				sal_Bool bBefore = sal_True;
1041cdf0e10cSrcweir                 for ( sal_uInt16 i = 0; i < rBoxes2.Count(); ++i )
1042cdf0e10cSrcweir 				{
1043cdf0e10cSrcweir                     if ( rBoxes2[i] != pExcl )
1044cdf0e10cSrcweir                         ::lcl_ProcessBoxPtr( rBoxes2[i], aParm.aBoxArr, bBefore );
1045cdf0e10cSrcweir 					else
1046cdf0e10cSrcweir 						bBefore = sal_False;
1047cdf0e10cSrcweir 				}
1048cdf0e10cSrcweir 				pExcl = pLine->GetUpper();
1049cdf0e10cSrcweir 				pLine = pLine->GetUpper() ? pLine->GetUpper()->GetUpper() : 0;
1050cdf0e10cSrcweir 			}
1051cdf0e10cSrcweir 			//Nachdem wir haufenweise Boxen (hoffentlich alle und in der richtigen
1052cdf0e10cSrcweir 			//Reihenfolge) eingetragen haben, brauchen diese nur noch rueckwaerts
1053cdf0e10cSrcweir 			//verarbeitet zu werden.
1054cdf0e10cSrcweir             for ( int j = aParm.aBoxArr.Count()-1; j >= 0; --j )
1055cdf0e10cSrcweir 			{
1056cdf0e10cSrcweir                 SwTableBox *pBox = (SwTableBox*)aParm.aBoxArr[ static_cast< sal_uInt16 >(j)];
1057cdf0e10cSrcweir 				::lcl_ProcessBoxSet( pBox, aParm );
1058cdf0e10cSrcweir 			}
1059cdf0e10cSrcweir 		}
1060cdf0e10cSrcweir 		else
1061cdf0e10cSrcweir 		{	//Die gesamte Tabelle anzupassen ist 'einfach'.
1062cdf0e10cSrcweir 			//Es werden alle Boxen, die keine Lines mehr enthalten angepasst.
1063cdf0e10cSrcweir 			//Diese Boxen passen alle uebergeordneten Boxen entsprechend mit an.
1064cdf0e10cSrcweir 			//Um uns nicht selbst hereinzulegen muss natuerlich rueckwaerst
1065cdf0e10cSrcweir 			//gearbeitet werden!
1066cdf0e10cSrcweir 			SwTableLines &rLines = GetTabLines();
1067cdf0e10cSrcweir 			for ( int i = rLines.Count()-1; i >= 0; --i )
1068cdf0e10cSrcweir                 ::lcl_ProcessLine( rLines[ static_cast< sal_uInt16 >(i) ], aParm );
1069cdf0e10cSrcweir 		}
1070cdf0e10cSrcweir 	}
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir #ifdef DBG_UTIL
1073cdf0e10cSrcweir 	{
1074cdf0e10cSrcweir // steht im tblrwcl.cxx
1075cdf0e10cSrcweir extern void _CheckBoxWidth( const SwTableLine&, SwTwips );
1076cdf0e10cSrcweir 		// checke doch mal ob die Tabellen korrekte Breiten haben
1077cdf0e10cSrcweir 		SwTwips nSize = GetFrmFmt()->GetFrmSize().GetWidth();
1078cdf0e10cSrcweir 		for( sal_uInt16 n = 0; n < aLines.Count(); ++n  )
1079cdf0e10cSrcweir 			_CheckBoxWidth( *aLines[ n ], nSize );
1080cdf0e10cSrcweir 	}
1081cdf0e10cSrcweir #endif
1082cdf0e10cSrcweir }
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir typedef std::pair<sal_uInt16, sal_uInt16> ColChange;
1085cdf0e10cSrcweir typedef std::list< ColChange > ChangeList;
1086cdf0e10cSrcweir 
lcl_AdjustWidthsInLine(SwTableLine * pLine,ChangeList & rOldNew,Parm & rParm,sal_uInt16 nColFuzzy)1087cdf0e10cSrcweir static void lcl_AdjustWidthsInLine( SwTableLine* pLine, ChangeList& rOldNew,
1088cdf0e10cSrcweir     Parm& rParm, sal_uInt16 nColFuzzy )
1089cdf0e10cSrcweir {
1090cdf0e10cSrcweir     ChangeList::iterator pCurr = rOldNew.begin();
1091cdf0e10cSrcweir     if( pCurr == rOldNew.end() )
1092cdf0e10cSrcweir         return;
1093cdf0e10cSrcweir     sal_uInt16 nCount = pLine->GetTabBoxes().Count();
1094cdf0e10cSrcweir     sal_uInt16 i = 0;
1095cdf0e10cSrcweir     SwTwips nBorder = 0;
1096cdf0e10cSrcweir     SwTwips nRest = 0;
1097cdf0e10cSrcweir     while( i < nCount )
1098cdf0e10cSrcweir     {
1099cdf0e10cSrcweir         SwTableBox* pBox = pLine->GetTabBoxes()[i++];
1100cdf0e10cSrcweir         SwTwips nWidth = pBox->GetFrmFmt()->GetFrmSize().GetWidth();
1101cdf0e10cSrcweir         SwTwips nNewWidth = nWidth - nRest;
1102cdf0e10cSrcweir         nRest = 0;
1103cdf0e10cSrcweir         nBorder += nWidth;
1104cdf0e10cSrcweir         if( pCurr != rOldNew.end() && nBorder + nColFuzzy >= pCurr->first )
1105cdf0e10cSrcweir         {
1106cdf0e10cSrcweir             nBorder -= nColFuzzy;
1107cdf0e10cSrcweir             while( pCurr != rOldNew.end() && nBorder > pCurr->first )
1108cdf0e10cSrcweir                 ++pCurr;
1109cdf0e10cSrcweir             if( pCurr != rOldNew.end() )
1110cdf0e10cSrcweir             {
1111cdf0e10cSrcweir                 nBorder += nColFuzzy;
1112cdf0e10cSrcweir                 if( nBorder + nColFuzzy >= pCurr->first )
1113cdf0e10cSrcweir                 {
1114cdf0e10cSrcweir                     if( pCurr->second == pCurr->first )
1115cdf0e10cSrcweir                         nRest = 0;
1116cdf0e10cSrcweir                     else
1117cdf0e10cSrcweir                         nRest = pCurr->second - nBorder;
1118cdf0e10cSrcweir                     nNewWidth += nRest;
1119cdf0e10cSrcweir                     ++pCurr;
1120cdf0e10cSrcweir                 }
1121cdf0e10cSrcweir             }
1122cdf0e10cSrcweir         }
1123cdf0e10cSrcweir         if( nNewWidth != nWidth )
1124cdf0e10cSrcweir         {
1125cdf0e10cSrcweir             if( nNewWidth < 0 )
1126cdf0e10cSrcweir             {
1127cdf0e10cSrcweir                 nRest += 1 - nNewWidth;
1128cdf0e10cSrcweir                 nNewWidth = 1;
1129cdf0e10cSrcweir             }
1130cdf0e10cSrcweir             SwFmtFrmSize aFmtFrmSize( pBox->GetFrmFmt()->GetFrmSize() );
1131cdf0e10cSrcweir             aFmtFrmSize.SetWidth( nNewWidth );
1132cdf0e10cSrcweir             rParm.aShareFmts.SetSize( *pBox, aFmtFrmSize );
1133cdf0e10cSrcweir         }
1134cdf0e10cSrcweir     }
1135cdf0e10cSrcweir }
1136cdf0e10cSrcweir 
lcl_CalcNewWidths(std::list<sal_uInt16> & rSpanPos,ChangeList & rChanges,SwTableLine * pLine,long nWish,long nWidth,bool bTop)1137cdf0e10cSrcweir static void lcl_CalcNewWidths( std::list<sal_uInt16> &rSpanPos, ChangeList& rChanges,
1138cdf0e10cSrcweir     SwTableLine* pLine, long nWish, long nWidth, bool bTop )
1139cdf0e10cSrcweir {
1140cdf0e10cSrcweir     if( !rChanges.size() )
1141cdf0e10cSrcweir     {
1142cdf0e10cSrcweir         rSpanPos.clear();
1143cdf0e10cSrcweir         return;
1144cdf0e10cSrcweir     }
1145cdf0e10cSrcweir     if( !rSpanPos.size() )
1146cdf0e10cSrcweir     {
1147cdf0e10cSrcweir         rChanges.clear();
1148cdf0e10cSrcweir         return;
1149cdf0e10cSrcweir     }
1150cdf0e10cSrcweir     std::list<sal_uInt16> aNewSpanPos;
1151cdf0e10cSrcweir     ChangeList aNewChanges;
1152cdf0e10cSrcweir     ChangeList::iterator pCurr = rChanges.begin();
1153cdf0e10cSrcweir     aNewChanges.push_back( *pCurr ); // Nullposition
1154cdf0e10cSrcweir     std::list<sal_uInt16>::iterator pSpan = rSpanPos.begin();
1155cdf0e10cSrcweir     sal_uInt16 nCurr = 0;
1156cdf0e10cSrcweir     sal_uInt16 nOrgSum = 0;
1157cdf0e10cSrcweir     bool bRowSpan = false;
1158cdf0e10cSrcweir     sal_uInt16 nRowSpanCount = 0;
1159cdf0e10cSrcweir     sal_uInt16 nCount = pLine->GetTabBoxes().Count();
1160cdf0e10cSrcweir     for( sal_uInt16 nCurrBox = 0; nCurrBox < nCount; ++nCurrBox )
1161cdf0e10cSrcweir     {
1162cdf0e10cSrcweir         SwTableBox* pBox = pLine->GetTabBoxes()[nCurrBox];
1163cdf0e10cSrcweir         SwTwips nCurrWidth = pBox->GetFrmFmt()->GetFrmSize().GetWidth();
1164cdf0e10cSrcweir         const long nRowSpan = pBox->getRowSpan();
1165cdf0e10cSrcweir         const bool bCurrRowSpan = bTop ? nRowSpan < 0 :
1166cdf0e10cSrcweir             ( nRowSpan > 1 || nRowSpan < -1 );
1167cdf0e10cSrcweir         if( bRowSpan || bCurrRowSpan )
1168cdf0e10cSrcweir             aNewSpanPos.push_back( nRowSpanCount );
1169cdf0e10cSrcweir         bRowSpan = bCurrRowSpan;
1170cdf0e10cSrcweir         nOrgSum = (sal_uInt16)(nOrgSum + nCurrWidth);
1171cdf0e10cSrcweir         sal_uInt64 nSum = nOrgSum;
1172cdf0e10cSrcweir         nSum *= nWidth;
1173cdf0e10cSrcweir         nSum /= nWish;
1174cdf0e10cSrcweir         nSum *= nWish;
1175cdf0e10cSrcweir         nSum /= nWidth;
1176cdf0e10cSrcweir         sal_uInt16 nPos = (sal_uInt16)nSum;
1177cdf0e10cSrcweir         while( pCurr != rChanges.end() && pCurr->first < nPos )
1178cdf0e10cSrcweir         {
1179cdf0e10cSrcweir #ifdef DBG_UTIL
1180cdf0e10cSrcweir             sal_uInt16 nTemp = pCurr->first;
1181cdf0e10cSrcweir             nTemp = pCurr->second;
1182cdf0e10cSrcweir #endif
1183cdf0e10cSrcweir             ++nCurr;
1184cdf0e10cSrcweir             ++pCurr;
1185cdf0e10cSrcweir         }
1186cdf0e10cSrcweir         bool bNew = true;
1187cdf0e10cSrcweir         if( pCurr != rChanges.end() && pCurr->first <= nPos &&
1188cdf0e10cSrcweir             pCurr->first != pCurr->second )
1189cdf0e10cSrcweir         {
1190cdf0e10cSrcweir             while( pSpan != rSpanPos.end() && *pSpan < nCurr )
1191cdf0e10cSrcweir                 ++pSpan;
1192cdf0e10cSrcweir             if( pSpan != rSpanPos.end() && *pSpan == nCurr )
1193cdf0e10cSrcweir             {
1194cdf0e10cSrcweir                 aNewChanges.push_back( *pCurr );
1195cdf0e10cSrcweir                 ++nRowSpanCount;
1196cdf0e10cSrcweir                 bNew = false;
1197cdf0e10cSrcweir             }
1198cdf0e10cSrcweir         }
1199cdf0e10cSrcweir         if( bNew )
1200cdf0e10cSrcweir         {
1201cdf0e10cSrcweir             ColChange aTmp( nPos, nPos );
1202cdf0e10cSrcweir             aNewChanges.push_back( aTmp );
1203cdf0e10cSrcweir             ++nRowSpanCount;
1204cdf0e10cSrcweir         }
1205cdf0e10cSrcweir     }
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir     pCurr = aNewChanges.begin();
1208cdf0e10cSrcweir     ChangeList::iterator pLast = pCurr;
1209cdf0e10cSrcweir     ChangeList::iterator pLeftMove = pCurr;
1210cdf0e10cSrcweir     while( pCurr != aNewChanges.end() )
1211cdf0e10cSrcweir     {
1212cdf0e10cSrcweir         if( pLeftMove == pCurr )
1213cdf0e10cSrcweir         {
1214cdf0e10cSrcweir             while( ++pLeftMove != aNewChanges.end() && pLeftMove->first <= pLeftMove->second )
1215cdf0e10cSrcweir                 ;
1216cdf0e10cSrcweir         }
1217cdf0e10cSrcweir         if( pCurr->second == pCurr->first )
1218cdf0e10cSrcweir         {
1219cdf0e10cSrcweir             if( pLeftMove != aNewChanges.end() && pCurr->second > pLeftMove->second )
1220cdf0e10cSrcweir             {
1221cdf0e10cSrcweir                 if( pLeftMove->first == pLast->first )
1222cdf0e10cSrcweir                     pCurr->second = pLeftMove->second;
1223cdf0e10cSrcweir                 else
1224cdf0e10cSrcweir                 {
1225cdf0e10cSrcweir                     sal_uInt64 nTmp = pCurr->first - pLast->first;
1226cdf0e10cSrcweir                     nTmp *= pLeftMove->second - pLast->second;
1227cdf0e10cSrcweir                     nTmp /= pLeftMove->first - pLast->first;
1228cdf0e10cSrcweir                     nTmp += pLast->second;
1229cdf0e10cSrcweir                     pCurr->second = (sal_uInt16)nTmp;
1230cdf0e10cSrcweir                 }
1231cdf0e10cSrcweir             }
1232cdf0e10cSrcweir             pLast = pCurr;
1233cdf0e10cSrcweir             ++pCurr;
1234cdf0e10cSrcweir         }
1235cdf0e10cSrcweir         else if( pCurr->second > pCurr->first )
1236cdf0e10cSrcweir         {
1237cdf0e10cSrcweir             pLast = pCurr;
1238cdf0e10cSrcweir             ++pCurr;
1239cdf0e10cSrcweir             ChangeList::iterator pNext = pCurr;
1240cdf0e10cSrcweir             while( pNext != pLeftMove && pNext->second == pNext->first &&
1241cdf0e10cSrcweir                 pNext->second < pLast->second )
1242cdf0e10cSrcweir                 ++pNext;
1243cdf0e10cSrcweir             while( pCurr != pNext )
1244cdf0e10cSrcweir             {
1245cdf0e10cSrcweir                 if( pNext == aNewChanges.end() || pNext->first == pLast->first )
1246cdf0e10cSrcweir                     pCurr->second = pLast->second;
1247cdf0e10cSrcweir                 else
1248cdf0e10cSrcweir                 {
1249cdf0e10cSrcweir                     sal_uInt64 nTmp = pCurr->first - pLast->first;
1250cdf0e10cSrcweir                     nTmp *= pNext->second - pLast->second;
1251cdf0e10cSrcweir                     nTmp /= pNext->first - pLast->first;
1252cdf0e10cSrcweir                     nTmp += pLast->second;
1253cdf0e10cSrcweir                     pCurr->second = (sal_uInt16)nTmp;
1254cdf0e10cSrcweir                 }
1255cdf0e10cSrcweir                 ++pCurr;
1256cdf0e10cSrcweir             }
1257cdf0e10cSrcweir             pLast = pCurr;
1258cdf0e10cSrcweir         }
1259cdf0e10cSrcweir         else
1260cdf0e10cSrcweir         {
1261cdf0e10cSrcweir             pLast = pCurr;
1262cdf0e10cSrcweir             ++pCurr;
1263cdf0e10cSrcweir         }
1264cdf0e10cSrcweir     }
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir     rChanges.clear();
1267cdf0e10cSrcweir     ChangeList::iterator pCopy = aNewChanges.begin();
1268cdf0e10cSrcweir     while( pCopy != aNewChanges.end() )
1269cdf0e10cSrcweir         rChanges.push_back( *pCopy++ );
1270cdf0e10cSrcweir     rSpanPos.clear();
1271cdf0e10cSrcweir     std::list<sal_uInt16>::iterator pSpCopy = aNewSpanPos.begin();
1272cdf0e10cSrcweir     while( pSpCopy != aNewSpanPos.end() )
1273cdf0e10cSrcweir         rSpanPos.push_back( *pSpCopy++ );
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir 
NewSetTabCols(Parm & rParm,const SwTabCols & rNew,const SwTabCols & rOld,const SwTableBox * pStart,sal_Bool bCurRowOnly)1276cdf0e10cSrcweir void SwTable::NewSetTabCols( Parm &rParm, const SwTabCols &rNew,
1277cdf0e10cSrcweir     const SwTabCols &rOld, const SwTableBox *pStart, sal_Bool bCurRowOnly )
1278cdf0e10cSrcweir {
1279cdf0e10cSrcweir #ifdef DBG_UTIL
1280cdf0e10cSrcweir     static int nCallCount = 0;
1281cdf0e10cSrcweir     ++nCallCount;
1282cdf0e10cSrcweir #endif
1283cdf0e10cSrcweir     // First step: evaluate which lines have been moved/which widths changed
1284cdf0e10cSrcweir     ChangeList aOldNew;
1285cdf0e10cSrcweir     const long nNewWidth = rParm.rNew.GetRight() - rParm.rNew.GetLeft();
1286cdf0e10cSrcweir     const long nOldWidth = rParm.rOld.GetRight() - rParm.rOld.GetLeft();
1287cdf0e10cSrcweir     if( nNewWidth < 1 || nOldWidth < 1 )
1288cdf0e10cSrcweir         return;
1289cdf0e10cSrcweir     for( sal_uInt16 i = 0; i <= rOld.Count(); ++i )
1290cdf0e10cSrcweir     {
1291cdf0e10cSrcweir         sal_uInt64 nNewPos;
1292cdf0e10cSrcweir         sal_uInt64 nOldPos;
1293cdf0e10cSrcweir         if( i == rOld.Count() )
1294cdf0e10cSrcweir         {
1295cdf0e10cSrcweir             nOldPos = rParm.rOld.GetRight() - rParm.rOld.GetLeft();
1296cdf0e10cSrcweir             nNewPos = rParm.rNew.GetRight() - rParm.rNew.GetLeft();
1297cdf0e10cSrcweir         }
1298cdf0e10cSrcweir         else
1299cdf0e10cSrcweir         {
1300cdf0e10cSrcweir             nOldPos = rOld[i] - rParm.rOld.GetLeft();
1301cdf0e10cSrcweir             nNewPos = rNew[i] - rParm.rNew.GetLeft();
1302cdf0e10cSrcweir         }
1303cdf0e10cSrcweir         nNewPos *= rParm.nNewWish;
1304cdf0e10cSrcweir         nNewPos /= nNewWidth;
1305cdf0e10cSrcweir         nOldPos *= rParm.nOldWish;
1306cdf0e10cSrcweir         nOldPos /= nOldWidth;
1307cdf0e10cSrcweir         if( nOldPos != nNewPos && nNewPos > 0 && nOldPos > 0 )
1308cdf0e10cSrcweir         {
1309cdf0e10cSrcweir             ColChange aChg( (sal_uInt16)nOldPos, (sal_uInt16)nNewPos );
1310cdf0e10cSrcweir             aOldNew.push_back( aChg );
1311cdf0e10cSrcweir         }
1312cdf0e10cSrcweir     }
1313cdf0e10cSrcweir     // Finished first step
1314cdf0e10cSrcweir     int nCount = aOldNew.size();
1315cdf0e10cSrcweir     if( !nCount )
1316cdf0e10cSrcweir         return; // no change, nothing to do
1317cdf0e10cSrcweir     SwTableLines &rLines = GetTabLines();
1318cdf0e10cSrcweir     if( bCurRowOnly )
1319cdf0e10cSrcweir     {
1320cdf0e10cSrcweir         const SwTableLine* pCurrLine = pStart->GetUpper();
1321cdf0e10cSrcweir         sal_uInt16 nCurr = rLines.C40_GETPOS( SwTableLine, pCurrLine );
1322cdf0e10cSrcweir         if( nCurr >= USHRT_MAX )
1323cdf0e10cSrcweir             return;
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir         ColChange aChg( 0, 0 );
1326cdf0e10cSrcweir         aOldNew.push_front( aChg );
1327cdf0e10cSrcweir         std::list<sal_uInt16> aRowSpanPos;
1328cdf0e10cSrcweir         if( nCurr )
1329cdf0e10cSrcweir         {
1330cdf0e10cSrcweir             ChangeList aCopy;
1331cdf0e10cSrcweir             ChangeList::iterator pCop = aOldNew.begin();
1332cdf0e10cSrcweir             sal_uInt16 nPos = 0;
1333cdf0e10cSrcweir             while( pCop != aOldNew.end() )
1334cdf0e10cSrcweir             {
1335cdf0e10cSrcweir                 aCopy.push_back( *pCop );
1336cdf0e10cSrcweir                 ++pCop;
1337cdf0e10cSrcweir                 aRowSpanPos.push_back( nPos++ );
1338cdf0e10cSrcweir             }
1339cdf0e10cSrcweir             lcl_CalcNewWidths( aRowSpanPos, aCopy, rLines[nCurr],
1340cdf0e10cSrcweir                 rParm.nOldWish, nOldWidth, true );
1341cdf0e10cSrcweir             bool bGoOn = aRowSpanPos.size() > 0;
1342cdf0e10cSrcweir             sal_uInt16 j = nCurr;
1343cdf0e10cSrcweir             while( bGoOn )
1344cdf0e10cSrcweir             {
1345cdf0e10cSrcweir                 lcl_CalcNewWidths( aRowSpanPos, aCopy, rLines[--j],
1346cdf0e10cSrcweir                     rParm.nOldWish, nOldWidth, true );
1347cdf0e10cSrcweir                 lcl_AdjustWidthsInLine( rLines[j], aCopy, rParm, 0 );
1348cdf0e10cSrcweir                 bGoOn = aRowSpanPos.size() > 0 && j > 0;
1349cdf0e10cSrcweir             };
1350cdf0e10cSrcweir             aRowSpanPos.clear();
1351cdf0e10cSrcweir         }
1352cdf0e10cSrcweir         if( nCurr+1 < rLines.Count() )
1353cdf0e10cSrcweir         {
1354cdf0e10cSrcweir             ChangeList aCopy;
1355cdf0e10cSrcweir             ChangeList::iterator pCop = aOldNew.begin();
1356cdf0e10cSrcweir             sal_uInt16 nPos = 0;
1357cdf0e10cSrcweir             while( pCop != aOldNew.end() )
1358cdf0e10cSrcweir             {
1359cdf0e10cSrcweir                 aCopy.push_back( *pCop );
1360cdf0e10cSrcweir                 ++pCop;
1361cdf0e10cSrcweir                 aRowSpanPos.push_back( nPos++ );
1362cdf0e10cSrcweir             }
1363cdf0e10cSrcweir             lcl_CalcNewWidths( aRowSpanPos, aCopy, rLines[nCurr],
1364cdf0e10cSrcweir                 rParm.nOldWish, nOldWidth, false );
1365cdf0e10cSrcweir             bool bGoOn = aRowSpanPos.size() > 0;
1366cdf0e10cSrcweir             sal_uInt16 j = nCurr;
1367cdf0e10cSrcweir             while( bGoOn )
1368cdf0e10cSrcweir             {
1369cdf0e10cSrcweir                 lcl_CalcNewWidths( aRowSpanPos, aCopy, rLines[++j],
1370cdf0e10cSrcweir                     rParm.nOldWish, nOldWidth, false );
1371cdf0e10cSrcweir                 lcl_AdjustWidthsInLine( rLines[j], aCopy, rParm, 0 );
1372cdf0e10cSrcweir                 bGoOn = aRowSpanPos.size() > 0 && j+1 < rLines.Count();
1373cdf0e10cSrcweir             };
1374cdf0e10cSrcweir         }
1375cdf0e10cSrcweir         ::lcl_AdjustWidthsInLine( rLines[nCurr], aOldNew, rParm, 1 );
1376cdf0e10cSrcweir     }
1377cdf0e10cSrcweir     else for( sal_uInt16 i = 0; i < rLines.Count(); ++i )
1378cdf0e10cSrcweir         ::lcl_AdjustWidthsInLine( rLines[i], aOldNew, rParm, COLFUZZY );
1379cdf0e10cSrcweir     CHECK_TABLE( *this )
1380cdf0e10cSrcweir }
1381cdf0e10cSrcweir 
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir /*************************************************************************
1384cdf0e10cSrcweir |*
1385cdf0e10cSrcweir |*	const SwTableBox* SwTable::GetTblBox( const Strn?ng& rName ) const
1386cdf0e10cSrcweir |*		gebe den Pointer auf die benannte Box zurueck.
1387cdf0e10cSrcweir |*
1388cdf0e10cSrcweir |*************************************************************************/
1389cdf0e10cSrcweir 
IsValidRowName(const String & rStr)1390cdf0e10cSrcweir sal_Bool IsValidRowName( const String& rStr )
1391cdf0e10cSrcweir {
1392cdf0e10cSrcweir 	sal_Bool bIsValid = sal_True;
1393cdf0e10cSrcweir 	xub_StrLen nLen = rStr.Len();
1394cdf0e10cSrcweir 	for (xub_StrLen i = 0;  i < nLen && bIsValid;  ++i)
1395cdf0e10cSrcweir 	{
1396cdf0e10cSrcweir 		const sal_Unicode cChar = rStr.GetChar(i);
1397cdf0e10cSrcweir 		if (cChar < '0' || cChar > '9')
1398cdf0e10cSrcweir 			bIsValid = sal_False;
1399cdf0e10cSrcweir 	}
1400cdf0e10cSrcweir 	return bIsValid;
1401cdf0e10cSrcweir }
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir // --> OD 2007-08-03 #i80314#
1404cdf0e10cSrcweir // add 3rd parameter and its handling
_GetBoxNum(String & rStr,sal_Bool bFirstPart,const bool bPerformValidCheck)1405cdf0e10cSrcweir sal_uInt16 SwTable::_GetBoxNum( String& rStr, sal_Bool bFirstPart,
1406cdf0e10cSrcweir                             const bool bPerformValidCheck )
1407cdf0e10cSrcweir {
1408cdf0e10cSrcweir 	sal_uInt16 nRet = 0;
1409cdf0e10cSrcweir 	xub_StrLen nPos = 0;
1410cdf0e10cSrcweir     if( bFirstPart )   // sal_True == column; sal_False == row
1411cdf0e10cSrcweir 	{
1412cdf0e10cSrcweir 		// die 1. ist mit Buchstaben addressiert!
1413cdf0e10cSrcweir 		sal_Unicode cChar;
1414cdf0e10cSrcweir 		sal_Bool bFirst = sal_True;
1415cdf0e10cSrcweir 		while( 0 != ( cChar = rStr.GetChar( nPos )) &&
1416cdf0e10cSrcweir 			   ( (cChar >= 'A' && cChar <= 'Z') ||
1417cdf0e10cSrcweir 			     (cChar >= 'a' && cChar <= 'z') ) )
1418cdf0e10cSrcweir 		{
1419cdf0e10cSrcweir 			if( (cChar -= 'A') >= 26 )
1420cdf0e10cSrcweir 				cChar -= 'a' - '[';
1421cdf0e10cSrcweir 			if( bFirst )
1422cdf0e10cSrcweir 				bFirst = sal_False;
1423cdf0e10cSrcweir 			else
1424cdf0e10cSrcweir 				++nRet;
1425cdf0e10cSrcweir 			nRet = nRet * 52 + cChar;
1426cdf0e10cSrcweir 			++nPos;
1427cdf0e10cSrcweir 		}
1428cdf0e10cSrcweir 		rStr.Erase( 0, nPos );		// Zeichen aus dem String loeschen
1429cdf0e10cSrcweir 	}
1430cdf0e10cSrcweir 	else if( STRING_NOTFOUND == ( nPos = rStr.Search( aDotStr ) ))
1431cdf0e10cSrcweir 	{
1432cdf0e10cSrcweir         nRet = 0;
1433cdf0e10cSrcweir         if ( !bPerformValidCheck || IsValidRowName( rStr ) )
1434cdf0e10cSrcweir         {
1435cdf0e10cSrcweir 			nRet = static_cast<sal_uInt16>(rStr.ToInt32());
1436cdf0e10cSrcweir         }
1437cdf0e10cSrcweir 		rStr.Erase();
1438cdf0e10cSrcweir 	}
1439cdf0e10cSrcweir 	else
1440cdf0e10cSrcweir 	{
1441cdf0e10cSrcweir         nRet = 0;
1442cdf0e10cSrcweir 		String aTxt( rStr.Copy( 0, nPos ) );
1443cdf0e10cSrcweir         if ( !bPerformValidCheck || IsValidRowName( aTxt ) )
1444cdf0e10cSrcweir         {
1445cdf0e10cSrcweir 			nRet = static_cast<sal_uInt16>(aTxt.ToInt32());
1446cdf0e10cSrcweir         }
1447cdf0e10cSrcweir 		rStr.Erase( 0, nPos+1 );
1448cdf0e10cSrcweir 	}
1449cdf0e10cSrcweir 	return nRet;
1450cdf0e10cSrcweir }
1451cdf0e10cSrcweir // <--
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir // --> OD 2007-08-03 #i80314#
1454cdf0e10cSrcweir // add 2nd parameter and its handling
GetTblBox(const String & rName,const bool bPerformValidCheck) const1455cdf0e10cSrcweir const SwTableBox* SwTable::GetTblBox( const String& rName,
1456cdf0e10cSrcweir                                       const bool bPerformValidCheck ) const
1457cdf0e10cSrcweir {
1458cdf0e10cSrcweir 	const SwTableBox* pBox = 0;
1459cdf0e10cSrcweir 	const SwTableLine* pLine;
1460cdf0e10cSrcweir 	const SwTableLines* pLines;
1461cdf0e10cSrcweir 	const SwTableBoxes* pBoxes;
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir 	sal_uInt16 nLine, nBox;
1464cdf0e10cSrcweir 	String aNm( rName );
1465cdf0e10cSrcweir 	while( aNm.Len() )
1466cdf0e10cSrcweir 	{
1467cdf0e10cSrcweir         nBox = SwTable::_GetBoxNum( aNm, 0 == pBox, bPerformValidCheck );
1468cdf0e10cSrcweir 		// erste Box ?
1469cdf0e10cSrcweir 		if( !pBox )
1470cdf0e10cSrcweir 			pLines = &GetTabLines();
1471cdf0e10cSrcweir 		else
1472cdf0e10cSrcweir 		{
1473cdf0e10cSrcweir 			pLines = &pBox->GetTabLines();
1474cdf0e10cSrcweir 			if( nBox )
1475cdf0e10cSrcweir 				--nBox;
1476cdf0e10cSrcweir 		}
1477cdf0e10cSrcweir 
1478cdf0e10cSrcweir         nLine = SwTable::_GetBoxNum( aNm, sal_False, bPerformValidCheck );
1479cdf0e10cSrcweir 
1480cdf0e10cSrcweir 		// bestimme die Line
1481cdf0e10cSrcweir 		if( !nLine || nLine > pLines->Count() )
1482cdf0e10cSrcweir 			return 0;
1483cdf0e10cSrcweir 		pLine = (*pLines)[ nLine-1 ];
1484cdf0e10cSrcweir 
1485cdf0e10cSrcweir 		// bestimme die Box
1486cdf0e10cSrcweir 		pBoxes = &pLine->GetTabBoxes();
1487cdf0e10cSrcweir 		if( nBox >= pBoxes->Count() )
1488cdf0e10cSrcweir 			return 0;
1489cdf0e10cSrcweir 		pBox = (*pBoxes)[ nBox ];
1490cdf0e10cSrcweir 	}
1491cdf0e10cSrcweir 
1492cdf0e10cSrcweir 	// abpruefen, ob die gefundene Box auch wirklich eine Inhaltstragende
1493cdf0e10cSrcweir 	// Box ist ??
1494cdf0e10cSrcweir 	if( pBox && !pBox->GetSttNd() )
1495cdf0e10cSrcweir 	{
1496cdf0e10cSrcweir 		ASSERT( sal_False, "Box ohne Inhalt, suche die naechste !!" );
1497cdf0e10cSrcweir 		// "herunterfallen lassen" bis zur ersten Box
1498cdf0e10cSrcweir 		while( pBox->GetTabLines().Count() )
1499cdf0e10cSrcweir 			pBox = pBox->GetTabLines()[0]->GetTabBoxes()[0];
1500cdf0e10cSrcweir 	}
1501cdf0e10cSrcweir 	return pBox;
1502cdf0e10cSrcweir }
1503cdf0e10cSrcweir 
GetTblBox(sal_uLong nSttIdx)1504cdf0e10cSrcweir SwTableBox* SwTable::GetTblBox( sal_uLong nSttIdx )
1505cdf0e10cSrcweir {
1506cdf0e10cSrcweir 	//MA: Zur Optimierung nicht immer umstaendlich das ganze SortArray abhuenern.
1507cdf0e10cSrcweir     //OS: #102675# converting text to table tries und certain conditions
1508cdf0e10cSrcweir     // to ask for a table box of a table that is not yet having a format
1509cdf0e10cSrcweir     if(!GetFrmFmt())
1510cdf0e10cSrcweir         return 0;
1511cdf0e10cSrcweir     SwTableBox* pRet = 0;
1512cdf0e10cSrcweir     SwNodes& rNds = GetFrmFmt()->GetDoc()->GetNodes();
1513cdf0e10cSrcweir 	sal_uLong nIndex = nSttIdx + 1;
1514cdf0e10cSrcweir 	SwCntntNode* pCNd = 0;
1515cdf0e10cSrcweir     SwTableNode* pTblNd = 0;
1516cdf0e10cSrcweir 
1517cdf0e10cSrcweir     while ( nIndex < rNds.Count() )
1518cdf0e10cSrcweir     {
1519cdf0e10cSrcweir         pTblNd = rNds[ nIndex ]->GetTableNode();
1520cdf0e10cSrcweir         if ( pTblNd )
1521cdf0e10cSrcweir             break;
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir         pCNd = rNds[ nIndex ]->GetCntntNode();
1524cdf0e10cSrcweir         if ( pCNd )
1525cdf0e10cSrcweir             break;
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir         ++nIndex;
1528cdf0e10cSrcweir     }
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir 	if ( pCNd || pTblNd )
1531cdf0e10cSrcweir 	{
1532cdf0e10cSrcweir         SwModify* pModify = pCNd;
1533cdf0e10cSrcweir         // --> FME 2007-3-26 #144862# Better handling of table in table:
1534cdf0e10cSrcweir         if ( pTblNd && pTblNd->GetTable().GetFrmFmt() )
1535cdf0e10cSrcweir             pModify = pTblNd->GetTable().GetFrmFmt();
1536cdf0e10cSrcweir         // <--
1537cdf0e10cSrcweir 
1538cdf0e10cSrcweir         SwFrm* pFrm = SwIterator<SwFrm,SwModify>::FirstElement( *pModify );
1539cdf0e10cSrcweir 		while ( pFrm && !pFrm->IsCellFrm() )
1540cdf0e10cSrcweir 			pFrm = pFrm->GetUpper();
1541cdf0e10cSrcweir 		if ( pFrm )
1542cdf0e10cSrcweir 			pRet = (SwTableBox*)((SwCellFrm*)pFrm)->GetTabBox();
1543cdf0e10cSrcweir 	}
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 	//Falls es das Layout noch nicht gibt oder sonstwie etwas schieft geht.
1546cdf0e10cSrcweir 	if ( !pRet )
1547cdf0e10cSrcweir 	{
1548cdf0e10cSrcweir 		for( sal_uInt16 n = aSortCntBoxes.Count(); n; )
1549cdf0e10cSrcweir 			if( aSortCntBoxes[ --n ]->GetSttIdx() == nSttIdx )
1550cdf0e10cSrcweir 				return aSortCntBoxes[ n ];
1551cdf0e10cSrcweir 	}
1552cdf0e10cSrcweir 	return pRet;
1553cdf0e10cSrcweir }
1554cdf0e10cSrcweir 
IsTblComplex() const1555cdf0e10cSrcweir sal_Bool SwTable::IsTblComplex() const
1556cdf0e10cSrcweir {
1557cdf0e10cSrcweir 	// returnt sal_True wenn sich in der Tabelle Verschachtelungen befinden
1558cdf0e10cSrcweir 	// steht eine Box nicht in der obersten Line, da wurde gesplittet/
1559cdf0e10cSrcweir 	// gemergt und die Struktur ist komplexer.
1560cdf0e10cSrcweir 	for( sal_uInt16 n = 0; n < aSortCntBoxes.Count(); ++n )
1561cdf0e10cSrcweir 		if( aSortCntBoxes[ n ]->GetUpper()->GetUpper() )
1562cdf0e10cSrcweir 			return sal_True;
1563cdf0e10cSrcweir 	return sal_False;
1564cdf0e10cSrcweir }
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir 
1568cdf0e10cSrcweir /*************************************************************************
1569cdf0e10cSrcweir |*
1570cdf0e10cSrcweir |*	SwTableLine::SwTableLine()
1571cdf0e10cSrcweir |*
1572cdf0e10cSrcweir |*************************************************************************/
SwTableLine(SwTableLineFmt * pFmt,sal_uInt16 nBoxes,SwTableBox * pUp)1573cdf0e10cSrcweir SwTableLine::SwTableLine( SwTableLineFmt *pFmt, sal_uInt16 nBoxes,
1574cdf0e10cSrcweir 							SwTableBox *pUp )
1575cdf0e10cSrcweir 	: SwClient( pFmt ),
1576cdf0e10cSrcweir 	aBoxes( (sal_uInt8)nBoxes, 1 ),
1577cdf0e10cSrcweir 	pUpper( pUp )
1578cdf0e10cSrcweir {
1579cdf0e10cSrcweir }
1580cdf0e10cSrcweir 
~SwTableLine()1581cdf0e10cSrcweir SwTableLine::~SwTableLine()
1582cdf0e10cSrcweir {
1583cdf0e10cSrcweir 	// ist die TabelleLine der letzte Client im FrameFormat, kann dieses
1584cdf0e10cSrcweir 	// geloescht werden
1585cdf0e10cSrcweir 	SwModify* pMod = GetFrmFmt();
1586cdf0e10cSrcweir 	pMod->Remove( this );				// austragen,
1587cdf0e10cSrcweir 	if( !pMod->GetDepends() )
1588cdf0e10cSrcweir 		delete pMod;	// und loeschen
1589cdf0e10cSrcweir }
1590cdf0e10cSrcweir 
1591cdf0e10cSrcweir /*************************************************************************
1592cdf0e10cSrcweir |*
1593cdf0e10cSrcweir |*	SwTableLine::ClaimFrmFmt(), ChgFrmFmt()
1594cdf0e10cSrcweir |*
1595cdf0e10cSrcweir |*************************************************************************/
ClaimFrmFmt()1596cdf0e10cSrcweir SwFrmFmt* SwTableLine::ClaimFrmFmt()
1597cdf0e10cSrcweir {
1598cdf0e10cSrcweir     // This method makes sure that this object is an exclusive SwTableLine client
1599cdf0e10cSrcweir     // of an SwTableLineFmt object
1600cdf0e10cSrcweir     // If other SwTableLine objects currently listen to the same SwTableLineFmt as
1601cdf0e10cSrcweir     // this one, something needs to be done
1602cdf0e10cSrcweir 	SwTableLineFmt *pRet = (SwTableLineFmt*)GetFrmFmt();
1603cdf0e10cSrcweir 	SwIterator<SwTableLine,SwFmt> aIter( *pRet );
1604cdf0e10cSrcweir 	for( SwTableLine* pLast = aIter.First(); pLast; pLast = aIter.Next() )
1605cdf0e10cSrcweir     {
1606cdf0e10cSrcweir 	    if ( pLast != this )
1607cdf0e10cSrcweir 	    {
1608cdf0e10cSrcweir             // found another SwTableLine that is a client of the current Fmt
1609cdf0e10cSrcweir             // create a new Fmt as a copy and use it for this object
1610cdf0e10cSrcweir 		    SwTableLineFmt *pNewFmt = pRet->GetDoc()->MakeTableLineFmt();
1611cdf0e10cSrcweir 		    *pNewFmt = *pRet;
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir 		    // register SwRowFrms that know me as clients at the new Fmt
1614cdf0e10cSrcweir             SwIterator<SwRowFrm,SwFmt> aFrmIter( *pRet );
1615cdf0e10cSrcweir 	        for( SwRowFrm* pFrm = aFrmIter.First(); pFrm; pFrm = aFrmIter.Next() )
1616cdf0e10cSrcweir 		        if( pFrm->GetTabLine() == this )
1617cdf0e10cSrcweir                     pFrm->RegisterToFormat( *pNewFmt );
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir 		    // register myself
1620cdf0e10cSrcweir 		    pNewFmt->Add( this );
1621cdf0e10cSrcweir 		    pRet = pNewFmt;
1622cdf0e10cSrcweir             break;
1623cdf0e10cSrcweir         }
1624cdf0e10cSrcweir 	}
1625cdf0e10cSrcweir 
1626cdf0e10cSrcweir 	return pRet;
1627cdf0e10cSrcweir }
1628cdf0e10cSrcweir 
ChgFrmFmt(SwTableLineFmt * pNewFmt)1629cdf0e10cSrcweir void SwTableLine::ChgFrmFmt( SwTableLineFmt *pNewFmt )
1630cdf0e10cSrcweir {
1631cdf0e10cSrcweir 	SwFrmFmt *pOld = GetFrmFmt();
1632cdf0e10cSrcweir 	SwIterator<SwRowFrm,SwFmt> aIter( *pOld );
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir 	//Erstmal die Frms ummelden.
1635cdf0e10cSrcweir 	for( SwRowFrm* pRow = aIter.First(); pRow; pRow = aIter.Next() )
1636cdf0e10cSrcweir 	{
1637cdf0e10cSrcweir 		if( pRow->GetTabLine() == this )
1638cdf0e10cSrcweir 		{
1639cdf0e10cSrcweir             pRow->RegisterToFormat( *pNewFmt );
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir             pRow->InvalidateSize();
1642cdf0e10cSrcweir 			pRow->_InvalidatePrt();
1643cdf0e10cSrcweir 			pRow->SetCompletePaint();
1644cdf0e10cSrcweir 			pRow->ReinitializeFrmSizeAttrFlags();
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir             // --> FME 2004-10-27 #i35063#
1647cdf0e10cSrcweir             // consider 'split row allowed' attribute
1648cdf0e10cSrcweir             SwTabFrm* pTab = pRow->FindTabFrm();
1649cdf0e10cSrcweir             bool bInFollowFlowRow = false;
1650cdf0e10cSrcweir             const bool bInFirstNonHeadlineRow = pTab->IsFollow() &&
1651cdf0e10cSrcweir                                                 pRow == pTab->GetFirstNonHeadlineRow();
1652cdf0e10cSrcweir             if ( bInFirstNonHeadlineRow ||
1653cdf0e10cSrcweir                  !pRow->GetNext() ||
1654cdf0e10cSrcweir                  0 != ( bInFollowFlowRow = pRow->IsInFollowFlowRow() ) ||
1655cdf0e10cSrcweir                  0 != pRow->IsInSplitTableRow() )
1656cdf0e10cSrcweir             {
1657cdf0e10cSrcweir                 if ( bInFirstNonHeadlineRow || bInFollowFlowRow )
1658cdf0e10cSrcweir                     pTab = pTab->FindMaster();
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir                 pTab->SetRemoveFollowFlowLinePending( sal_True );
1661cdf0e10cSrcweir                 pTab->InvalidatePos();
1662cdf0e10cSrcweir             }
1663cdf0e10cSrcweir             // <--
1664cdf0e10cSrcweir         }
1665cdf0e10cSrcweir 	}
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir 	//Jetzt noch mich selbst ummelden.
1668cdf0e10cSrcweir 	pNewFmt->Add( this );
1669cdf0e10cSrcweir 
1670cdf0e10cSrcweir 	if ( !pOld->GetDepends() )
1671cdf0e10cSrcweir 		delete pOld;
1672cdf0e10cSrcweir }
1673cdf0e10cSrcweir 
GetTableLineHeight(bool & bLayoutAvailable) const1674cdf0e10cSrcweir SwTwips SwTableLine::GetTableLineHeight( bool& bLayoutAvailable ) const
1675cdf0e10cSrcweir {
1676cdf0e10cSrcweir     SwTwips nRet = 0;
1677cdf0e10cSrcweir     bLayoutAvailable = false;
1678cdf0e10cSrcweir 	SwIterator<SwRowFrm,SwFmt> aIter( *GetFrmFmt() );
1679cdf0e10cSrcweir     // A row could appear several times in headers/footers so only one chain of master/follow tables
1680cdf0e10cSrcweir     // will be accepted...
1681cdf0e10cSrcweir     const SwTabFrm* pChain = NULL; // My chain
1682cdf0e10cSrcweir 	for( SwRowFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
1683cdf0e10cSrcweir     {
1684cdf0e10cSrcweir 		if( pLast->GetTabLine() == this )
1685cdf0e10cSrcweir 		{
1686cdf0e10cSrcweir             const SwTabFrm* pTab = pLast->FindTabFrm();
1687cdf0e10cSrcweir             bLayoutAvailable = ( pTab && pTab->IsVertical() ) ?
1688cdf0e10cSrcweir                                ( 0 < pTab->Frm().Height() ) :
1689cdf0e10cSrcweir                                ( 0 < pTab->Frm().Width() );
1690cdf0e10cSrcweir 
1691cdf0e10cSrcweir             // The first one defines the chain, if a chain is defined, only members of the chain
1692cdf0e10cSrcweir             // will be added.
1693cdf0e10cSrcweir             if( !pChain || pChain->IsAnFollow( pTab ) || pTab->IsAnFollow( pChain ) )
1694cdf0e10cSrcweir             {
1695cdf0e10cSrcweir                 pChain = pTab; // defines my chain (even it is already)
1696cdf0e10cSrcweir                 if( pTab->IsVertical() )
1697cdf0e10cSrcweir                     nRet += pLast->Frm().Width();
1698cdf0e10cSrcweir                 else
1699cdf0e10cSrcweir                     nRet += pLast->Frm().Height();
1700cdf0e10cSrcweir                 // Optimization, if there are no master/follows in my chain, nothing more to add
1701cdf0e10cSrcweir                 if( !pTab->HasFollow() && !pTab->IsFollow() )
1702cdf0e10cSrcweir                     break;
1703cdf0e10cSrcweir                 // This is not an optimization, this is necessary to avoid double additions of
1704cdf0e10cSrcweir                 // repeating rows
1705cdf0e10cSrcweir                 if( pTab->IsInHeadline(*pLast) )
1706cdf0e10cSrcweir                     break;
1707cdf0e10cSrcweir             }
1708cdf0e10cSrcweir         }
1709cdf0e10cSrcweir     }
1710cdf0e10cSrcweir     return nRet;
1711cdf0e10cSrcweir }
1712cdf0e10cSrcweir 
1713cdf0e10cSrcweir /*************************************************************************
1714cdf0e10cSrcweir |*
1715cdf0e10cSrcweir |*	SwTableBox::SwTableBox()
1716cdf0e10cSrcweir |*
1717cdf0e10cSrcweir |*************************************************************************/
SwTableBox(SwTableBoxFmt * pFmt,sal_uInt16 nLines,SwTableLine * pUp)1718cdf0e10cSrcweir SwTableBox::SwTableBox( SwTableBoxFmt* pFmt, sal_uInt16 nLines, SwTableLine *pUp )
1719cdf0e10cSrcweir 	: SwClient( 0 ),
1720cdf0e10cSrcweir 	aLines( (sal_uInt8)nLines, 1 ),
1721cdf0e10cSrcweir 	pSttNd( 0 ),
1722cdf0e10cSrcweir 	pUpper( pUp ),
1723cdf0e10cSrcweir 	pImpl( 0 )
1724cdf0e10cSrcweir {
1725cdf0e10cSrcweir 	CheckBoxFmt( pFmt )->Add( this );
1726cdf0e10cSrcweir }
1727cdf0e10cSrcweir 
SwTableBox(SwTableBoxFmt * pFmt,const SwNodeIndex & rIdx,SwTableLine * pUp)1728cdf0e10cSrcweir SwTableBox::SwTableBox( SwTableBoxFmt* pFmt, const SwNodeIndex &rIdx,
1729cdf0e10cSrcweir 						SwTableLine *pUp )
1730cdf0e10cSrcweir 	: SwClient( 0 ),
1731cdf0e10cSrcweir 	aLines( 0, 0 ),
1732cdf0e10cSrcweir 	pUpper( pUp ),
1733cdf0e10cSrcweir 	pImpl( 0 )
1734cdf0e10cSrcweir {
1735cdf0e10cSrcweir 	CheckBoxFmt( pFmt )->Add( this );
1736cdf0e10cSrcweir 
1737cdf0e10cSrcweir     pSttNd = rIdx.GetNode().GetStartNode();
1738cdf0e10cSrcweir 
1739cdf0e10cSrcweir 	// an der Table eintragen
1740cdf0e10cSrcweir 	const SwTableNode* pTblNd = pSttNd->FindTableNode();
1741cdf0e10cSrcweir 	ASSERT( pTblNd, "in welcher Tabelle steht denn die Box?" );
1742cdf0e10cSrcweir 	SwTableSortBoxes& rSrtArr = (SwTableSortBoxes&)pTblNd->GetTable().
1743cdf0e10cSrcweir 								GetTabSortBoxes();
1744cdf0e10cSrcweir 	SwTableBox* p = this;	// error: &this
1745cdf0e10cSrcweir 	rSrtArr.Insert( p );		// eintragen
1746cdf0e10cSrcweir }
1747cdf0e10cSrcweir 
SwTableBox(SwTableBoxFmt * pFmt,const SwStartNode & rSttNd,SwTableLine * pUp)1748cdf0e10cSrcweir SwTableBox::SwTableBox( SwTableBoxFmt* pFmt, const SwStartNode& rSttNd, SwTableLine *pUp ) :
1749cdf0e10cSrcweir 	SwClient( 0 ),
1750cdf0e10cSrcweir 	aLines( 0, 0 ),
1751cdf0e10cSrcweir     pSttNd( &rSttNd ),
1752cdf0e10cSrcweir 	pUpper( pUp ),
1753cdf0e10cSrcweir     pImpl( 0 )
1754cdf0e10cSrcweir {
1755cdf0e10cSrcweir     CheckBoxFmt( pFmt )->Add( this );
1756cdf0e10cSrcweir 
1757cdf0e10cSrcweir 	// an der Table eintragen
1758cdf0e10cSrcweir 	const SwTableNode* pTblNd = pSttNd->FindTableNode();
1759cdf0e10cSrcweir 	ASSERT( pTblNd, "in welcher Tabelle steht denn die Box?" );
1760cdf0e10cSrcweir 	SwTableSortBoxes& rSrtArr = (SwTableSortBoxes&)pTblNd->GetTable().
1761cdf0e10cSrcweir 								GetTabSortBoxes();
1762cdf0e10cSrcweir 	SwTableBox* p = this;	// error: &this
1763cdf0e10cSrcweir 	rSrtArr.Insert( p );		// eintragen
1764cdf0e10cSrcweir }
1765cdf0e10cSrcweir 
~SwTableBox()1766cdf0e10cSrcweir SwTableBox::~SwTableBox()
1767cdf0e10cSrcweir {
1768cdf0e10cSrcweir 	// Inhaltstragende Box ?
1769cdf0e10cSrcweir 	if( !GetFrmFmt()->GetDoc()->IsInDtor() && pSttNd )
1770cdf0e10cSrcweir 	{
1771cdf0e10cSrcweir 		// an der Table austragen
1772cdf0e10cSrcweir 		const SwTableNode* pTblNd = pSttNd->FindTableNode();
1773cdf0e10cSrcweir 		ASSERT( pTblNd, "in welcher Tabelle steht denn die Box?" );
1774cdf0e10cSrcweir 		SwTableSortBoxes& rSrtArr = (SwTableSortBoxes&)pTblNd->GetTable().
1775cdf0e10cSrcweir 									GetTabSortBoxes();
1776cdf0e10cSrcweir 		SwTableBox *p = this;	// error: &this
1777cdf0e10cSrcweir 		rSrtArr.Remove( p );		// austragen
1778cdf0e10cSrcweir 	}
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir 	// ist die TabelleBox der letzte Client im FrameFormat, kann dieses
1781cdf0e10cSrcweir 	// geloescht werden
1782cdf0e10cSrcweir 	SwModify* pMod = GetFrmFmt();
1783cdf0e10cSrcweir 	pMod->Remove( this );				// austragen,
1784cdf0e10cSrcweir 	if( !pMod->GetDepends() )
1785cdf0e10cSrcweir 		delete pMod;	// und loeschen
1786cdf0e10cSrcweir 
1787cdf0e10cSrcweir 	delete pImpl;
1788cdf0e10cSrcweir }
1789cdf0e10cSrcweir 
CheckBoxFmt(SwTableBoxFmt * pFmt)1790cdf0e10cSrcweir SwTableBoxFmt* SwTableBox::CheckBoxFmt( SwTableBoxFmt* pFmt )
1791cdf0e10cSrcweir {
1792cdf0e10cSrcweir 	// sollte das Format eine Formel oder einen Value tragen, dann muss die
1793cdf0e10cSrcweir 	// Box alleine am Format haengen. Ggfs. muss ein neues angelegt werden.
1794cdf0e10cSrcweir 	if( SFX_ITEM_SET == pFmt->GetItemState( RES_BOXATR_VALUE, sal_False ) ||
1795cdf0e10cSrcweir 		SFX_ITEM_SET == pFmt->GetItemState( RES_BOXATR_FORMULA, sal_False ) )
1796cdf0e10cSrcweir 	{
1797cdf0e10cSrcweir 		SwTableBox* pOther = SwIterator<SwTableBox,SwFmt>::FirstElement( *pFmt );
1798cdf0e10cSrcweir 		if( pOther )
1799cdf0e10cSrcweir 		{
1800cdf0e10cSrcweir 			SwTableBoxFmt* pNewFmt = pFmt->GetDoc()->MakeTableBoxFmt();
1801cdf0e10cSrcweir 			pNewFmt->LockModify();
1802cdf0e10cSrcweir 			*pNewFmt = *pFmt;
1803cdf0e10cSrcweir 
1804cdf0e10cSrcweir 			// Values und Formeln entfernen
1805cdf0e10cSrcweir             pNewFmt->ResetFmtAttr( RES_BOXATR_FORMULA, RES_BOXATR_VALUE );
1806cdf0e10cSrcweir 			pNewFmt->UnlockModify();
1807cdf0e10cSrcweir 
1808cdf0e10cSrcweir 			pFmt = pNewFmt;
1809cdf0e10cSrcweir 		}
1810cdf0e10cSrcweir 	}
1811cdf0e10cSrcweir 	return pFmt;
1812cdf0e10cSrcweir }
1813cdf0e10cSrcweir 
1814cdf0e10cSrcweir /*************************************************************************
1815cdf0e10cSrcweir |*
1816cdf0e10cSrcweir |*	SwTableBox::ClaimFrmFmt(), ChgFrmFmt()
1817cdf0e10cSrcweir |*
1818cdf0e10cSrcweir |*************************************************************************/
ClaimFrmFmt()1819cdf0e10cSrcweir SwFrmFmt* SwTableBox::ClaimFrmFmt()
1820cdf0e10cSrcweir {
1821cdf0e10cSrcweir     // This method makes sure that this object is an exclusive SwTableBox client
1822cdf0e10cSrcweir     // of an SwTableBoxFmt object
1823cdf0e10cSrcweir     // If other SwTableBox objects currently listen to the same SwTableBoxFmt as
1824cdf0e10cSrcweir     // this one, something needs to be done
1825cdf0e10cSrcweir 	SwTableBoxFmt *pRet = (SwTableBoxFmt*)GetFrmFmt();
1826cdf0e10cSrcweir 	SwIterator<SwTableBox,SwFmt> aIter( *pRet );
1827cdf0e10cSrcweir 	for( SwTableBox* pLast = aIter.First(); pLast; pLast = aIter.Next() )
1828cdf0e10cSrcweir     {
1829cdf0e10cSrcweir 	    if ( pLast != this )
1830cdf0e10cSrcweir         {
1831cdf0e10cSrcweir             // Found another SwTableBox object
1832cdf0e10cSrcweir             // create a new Fmt as a copy and assign me to it
1833cdf0e10cSrcweir 		    // don't copy values and formulas
1834cdf0e10cSrcweir 		    SwTableBoxFmt* pNewFmt = pRet->GetDoc()->MakeTableBoxFmt();
1835cdf0e10cSrcweir 		    pNewFmt->LockModify();
1836cdf0e10cSrcweir 		    *pNewFmt = *pRet;
1837cdf0e10cSrcweir             pNewFmt->ResetFmtAttr( RES_BOXATR_FORMULA, RES_BOXATR_VALUE );
1838cdf0e10cSrcweir 		    pNewFmt->UnlockModify();
1839cdf0e10cSrcweir 
1840cdf0e10cSrcweir 		    // re-register SwCellFrm objects that know me
1841cdf0e10cSrcweir             SwIterator<SwCellFrm,SwFmt> aFrmIter( *pRet );
1842cdf0e10cSrcweir 	        for( SwCellFrm* pCell = aFrmIter.First(); pCell; pCell = aFrmIter.Next() )
1843cdf0e10cSrcweir 		        if( pCell->GetTabBox() == this )
1844cdf0e10cSrcweir                     pCell->RegisterToFormat( *pNewFmt );
1845cdf0e10cSrcweir 
1846cdf0e10cSrcweir 		    // re-register myself
1847cdf0e10cSrcweir 		    pNewFmt->Add( this );
1848cdf0e10cSrcweir 		    pRet = pNewFmt;
1849cdf0e10cSrcweir             break;
1850cdf0e10cSrcweir         }
1851cdf0e10cSrcweir     }
1852cdf0e10cSrcweir 	return pRet;
1853cdf0e10cSrcweir }
1854cdf0e10cSrcweir 
ChgFrmFmt(SwTableBoxFmt * pNewFmt)1855cdf0e10cSrcweir void SwTableBox::ChgFrmFmt( SwTableBoxFmt* pNewFmt )
1856cdf0e10cSrcweir {
1857cdf0e10cSrcweir 	SwFrmFmt *pOld = GetFrmFmt();
1858cdf0e10cSrcweir 	SwIterator<SwCellFrm,SwFmt> aIter( *pOld );
1859cdf0e10cSrcweir 
1860cdf0e10cSrcweir 	//Erstmal die Frms ummelden.
1861cdf0e10cSrcweir 	for( SwCellFrm* pCell = aIter.First(); pCell; pCell = aIter.Next() )
1862cdf0e10cSrcweir 	{
1863cdf0e10cSrcweir 		if( pCell->GetTabBox() == this )
1864cdf0e10cSrcweir 		{
1865cdf0e10cSrcweir             pCell->RegisterToFormat( *pNewFmt );
1866cdf0e10cSrcweir 			pCell->InvalidateSize();
1867cdf0e10cSrcweir 			pCell->_InvalidatePrt();
1868cdf0e10cSrcweir 			pCell->SetCompletePaint();
1869cdf0e10cSrcweir             pCell->SetDerivedVert( sal_False );
1870cdf0e10cSrcweir             pCell->CheckDirChange();
1871cdf0e10cSrcweir 
1872cdf0e10cSrcweir             // --> FME 2005-04-15 #i47489#
1873cdf0e10cSrcweir             // make sure that the row will be formatted, in order
1874cdf0e10cSrcweir             // to have the correct Get(Top|Bottom)MarginForLowers values
1875cdf0e10cSrcweir             // set at the row.
1876cdf0e10cSrcweir             const SwTabFrm* pTab = pCell->FindTabFrm();
1877cdf0e10cSrcweir             if ( pTab && pTab->IsCollapsingBorders() )
1878cdf0e10cSrcweir             {
1879cdf0e10cSrcweir                 SwFrm* pRow = pCell->GetUpper();
1880cdf0e10cSrcweir                 pRow->_InvalidateSize();
1881cdf0e10cSrcweir                 pRow->_InvalidatePrt();
1882cdf0e10cSrcweir             }
1883cdf0e10cSrcweir             // <--
1884cdf0e10cSrcweir         }
1885cdf0e10cSrcweir 	}
1886cdf0e10cSrcweir 
1887cdf0e10cSrcweir 	//Jetzt noch mich selbst ummelden.
1888cdf0e10cSrcweir 	pNewFmt->Add( this );
1889cdf0e10cSrcweir 
1890cdf0e10cSrcweir 	if( !pOld->GetDepends() )
1891cdf0e10cSrcweir 		delete pOld;
1892cdf0e10cSrcweir }
1893cdf0e10cSrcweir 
1894cdf0e10cSrcweir /*************************************************************************
1895cdf0e10cSrcweir |*
1896cdf0e10cSrcweir |*	String SwTableBox::GetName() const
1897cdf0e10cSrcweir |*		gebe den Namen dieser Box zurueck. Dieser wird dynamisch bestimmt
1898cdf0e10cSrcweir |*		und ergibt sich aus der Position in den Lines/Boxen/Tabelle
1899cdf0e10cSrcweir |*
1900cdf0e10cSrcweir |*************************************************************************/
lcl_GetTblBoxColStr(sal_uInt16 nCol,String & rNm)1901cdf0e10cSrcweir void lcl_GetTblBoxColStr( sal_uInt16 nCol, String& rNm )
1902cdf0e10cSrcweir {
1903cdf0e10cSrcweir 	const sal_uInt16 coDiff = 52; 	// 'A'-'Z' 'a' - 'z'
1904cdf0e10cSrcweir     sal_uInt16 nCalc;
1905cdf0e10cSrcweir 
1906cdf0e10cSrcweir 	do {
1907cdf0e10cSrcweir 		nCalc = nCol % coDiff;
1908cdf0e10cSrcweir 		if( nCalc >= 26 )
1909cdf0e10cSrcweir 			rNm.Insert( sal_Unicode('a' - 26 + nCalc ), 0 );
1910cdf0e10cSrcweir 		else
1911cdf0e10cSrcweir 			rNm.Insert( sal_Unicode('A' + nCalc ), 0 );
1912cdf0e10cSrcweir 
1913cdf0e10cSrcweir         if( 0 == (nCol = nCol - nCalc) )
1914cdf0e10cSrcweir 			break;
1915cdf0e10cSrcweir 		nCol /= coDiff;
1916cdf0e10cSrcweir 		--nCol;
1917cdf0e10cSrcweir 	} while( 1 );
1918cdf0e10cSrcweir }
1919cdf0e10cSrcweir 
GetName() const1920cdf0e10cSrcweir String SwTableBox::GetName() const
1921cdf0e10cSrcweir {
1922cdf0e10cSrcweir 	if( !pSttNd )		// keine Content Box ??
1923cdf0e10cSrcweir 	{
1924cdf0e10cSrcweir 		// die naechste erste Box suchen ??
1925cdf0e10cSrcweir 		return aEmptyStr;
1926cdf0e10cSrcweir 	}
1927cdf0e10cSrcweir 
1928cdf0e10cSrcweir 	const SwTable& rTbl = pSttNd->FindTableNode()->GetTable();
1929cdf0e10cSrcweir     sal_uInt16 nPos;
1930cdf0e10cSrcweir 	String sNm, sTmp;
1931cdf0e10cSrcweir 	const SwTableBox* pBox = this;
1932cdf0e10cSrcweir 	do {
1933cdf0e10cSrcweir 		const SwTableBoxes* pBoxes = &pBox->GetUpper()->GetTabBoxes();
1934cdf0e10cSrcweir 		const SwTableLine* pLine = pBox->GetUpper();
1935cdf0e10cSrcweir 		// auf oberstere Ebene ?
1936cdf0e10cSrcweir 		const SwTableLines* pLines = pLine->GetUpper()
1937cdf0e10cSrcweir 				? &pLine->GetUpper()->GetTabLines() : &rTbl.GetTabLines();
1938cdf0e10cSrcweir 
1939cdf0e10cSrcweir 		sTmp = String::CreateFromInt32( nPos = pLines->GetPos( pLine ) + 1 );
1940cdf0e10cSrcweir 		if( sNm.Len() )
1941cdf0e10cSrcweir 			sNm.Insert( aDotStr, 0 ).Insert( sTmp, 0 );
1942cdf0e10cSrcweir 		else
1943cdf0e10cSrcweir 			sNm = sTmp;
1944cdf0e10cSrcweir 
1945cdf0e10cSrcweir 		sTmp = String::CreateFromInt32(( nPos = pBoxes->GetPos( pBox )) + 1 );
1946cdf0e10cSrcweir 		if( 0 != ( pBox = pLine->GetUpper()) )
1947cdf0e10cSrcweir 			sNm.Insert( aDotStr, 0 ).Insert( sTmp, 0 );
1948cdf0e10cSrcweir 		else
1949cdf0e10cSrcweir 			::lcl_GetTblBoxColStr( nPos, sNm );
1950cdf0e10cSrcweir 
1951cdf0e10cSrcweir 	} while( pBox );
1952cdf0e10cSrcweir 	return sNm;
1953cdf0e10cSrcweir }
1954cdf0e10cSrcweir 
IsInHeadline(const SwTable * pTbl) const1955cdf0e10cSrcweir sal_Bool SwTableBox::IsInHeadline( const SwTable* pTbl ) const
1956cdf0e10cSrcweir {
1957cdf0e10cSrcweir 	if( !GetUpper() )			// sollte nur beim Merge vorkommen.
1958cdf0e10cSrcweir 		return sal_False;
1959cdf0e10cSrcweir 
1960cdf0e10cSrcweir 	if( !pTbl )
1961cdf0e10cSrcweir 		pTbl = &pSttNd->FindTableNode()->GetTable();
1962cdf0e10cSrcweir 
1963cdf0e10cSrcweir 	const SwTableLine* pLine = GetUpper();
1964cdf0e10cSrcweir 	while( pLine->GetUpper() )
1965cdf0e10cSrcweir 		pLine = pLine->GetUpper()->GetUpper();
1966cdf0e10cSrcweir 
1967cdf0e10cSrcweir 	// Headerline?
1968cdf0e10cSrcweir 	return pTbl->GetTabLines()[ 0 ] == pLine;
1969cdf0e10cSrcweir }
1970cdf0e10cSrcweir 
1971cdf0e10cSrcweir #ifdef DBG_UTIL
1972cdf0e10cSrcweir 
GetSttIdx() const1973cdf0e10cSrcweir sal_uLong SwTableBox::GetSttIdx() const
1974cdf0e10cSrcweir {
1975cdf0e10cSrcweir 	return pSttNd ? pSttNd->GetIndex() : 0;
1976cdf0e10cSrcweir }
1977cdf0e10cSrcweir #endif
1978cdf0e10cSrcweir 
1979cdf0e10cSrcweir 	// erfrage vom Client Informationen
GetInfo(SfxPoolItem & rInfo) const1980cdf0e10cSrcweir sal_Bool SwTable::GetInfo( SfxPoolItem& rInfo ) const
1981cdf0e10cSrcweir {
1982cdf0e10cSrcweir 	switch( rInfo.Which() )
1983cdf0e10cSrcweir 	{
1984cdf0e10cSrcweir 	case RES_AUTOFMT_DOCNODE:
1985cdf0e10cSrcweir     {
1986cdf0e10cSrcweir         const SwTableNode* pTblNode = GetTableNode();
1987cdf0e10cSrcweir         if( pTblNode && &pTblNode->GetNodes() == ((SwAutoFmtGetDocNode&)rInfo).pNodes )
1988cdf0e10cSrcweir         {
1989cdf0e10cSrcweir             if ( aSortCntBoxes.Count() )
1990cdf0e10cSrcweir             {
1991cdf0e10cSrcweir   			    SwNodeIndex aIdx( *aSortCntBoxes[ 0 ]->GetSttNd() );
1992cdf0e10cSrcweir     		    ((SwAutoFmtGetDocNode&)rInfo).pCntntNode =
1993cdf0e10cSrcweir 	    		    			GetFrmFmt()->GetDoc()->GetNodes().GoNext( &aIdx );
1994cdf0e10cSrcweir             }
1995cdf0e10cSrcweir 			return sal_False;
1996cdf0e10cSrcweir 		}
1997cdf0e10cSrcweir 		break;
1998cdf0e10cSrcweir     }
1999cdf0e10cSrcweir 	case RES_FINDNEARESTNODE:
2000cdf0e10cSrcweir         if( GetFrmFmt() && ((SwFmtPageDesc&)GetFrmFmt()->GetFmtAttr(
2001cdf0e10cSrcweir 			RES_PAGEDESC )).GetPageDesc() &&
2002cdf0e10cSrcweir 			aSortCntBoxes.Count() &&
2003cdf0e10cSrcweir 			aSortCntBoxes[ 0 ]->GetSttNd()->GetNodes().IsDocNodes() )
2004cdf0e10cSrcweir 			((SwFindNearestNode&)rInfo).CheckNode( *
2005cdf0e10cSrcweir 				aSortCntBoxes[ 0 ]->GetSttNd()->FindTableNode() );
2006cdf0e10cSrcweir 		break;
2007cdf0e10cSrcweir 
2008cdf0e10cSrcweir 	case RES_CONTENT_VISIBLE:
2009cdf0e10cSrcweir 		{
2010cdf0e10cSrcweir 			((SwPtrMsgPoolItem&)rInfo).pObject = SwIterator<SwFrm,SwFmt>::FirstElement( *GetFrmFmt() );
2011cdf0e10cSrcweir 		}
2012cdf0e10cSrcweir 		return sal_False;
2013cdf0e10cSrcweir 	}
2014cdf0e10cSrcweir 	return sal_True;
2015cdf0e10cSrcweir }
2016cdf0e10cSrcweir 
FindTable(SwFrmFmt const * const pFmt)2017cdf0e10cSrcweir SwTable * SwTable::FindTable( SwFrmFmt const*const pFmt )
2018cdf0e10cSrcweir {
2019cdf0e10cSrcweir     return (pFmt)
2020cdf0e10cSrcweir         ? SwIterator<SwTable,SwFmt>::FirstElement(*pFmt)
2021cdf0e10cSrcweir         : 0;
2022cdf0e10cSrcweir }
2023cdf0e10cSrcweir 
GetTableNode() const2024cdf0e10cSrcweir SwTableNode* SwTable::GetTableNode() const
2025cdf0e10cSrcweir {
2026cdf0e10cSrcweir     return GetTabSortBoxes().Count() ?
2027cdf0e10cSrcweir            (SwTableNode*)GetTabSortBoxes()[ 0 ]->GetSttNd()->FindTableNode() :
2028cdf0e10cSrcweir            pTableNode;
2029cdf0e10cSrcweir }
2030cdf0e10cSrcweir 
SetRefObject(SwServerObject * pObj)2031cdf0e10cSrcweir void SwTable::SetRefObject( SwServerObject* pObj )
2032cdf0e10cSrcweir {
2033cdf0e10cSrcweir 	if( refObj.Is() )
2034cdf0e10cSrcweir 		refObj->Closed();
2035cdf0e10cSrcweir 
2036cdf0e10cSrcweir 	refObj = pObj;
2037cdf0e10cSrcweir }
2038cdf0e10cSrcweir 
2039cdf0e10cSrcweir 
SetHTMLTableLayout(SwHTMLTableLayout * p)2040cdf0e10cSrcweir void SwTable::SetHTMLTableLayout( SwHTMLTableLayout *p )
2041cdf0e10cSrcweir {
2042cdf0e10cSrcweir 	delete pHTMLLayout;
2043cdf0e10cSrcweir 	pHTMLLayout = p;
2044cdf0e10cSrcweir }
2045cdf0e10cSrcweir 
ChgTextToNum(SwTableBox & rBox,const String & rTxt,const Color * pCol,sal_Bool bChgAlign)2046cdf0e10cSrcweir void ChgTextToNum( SwTableBox& rBox, const String& rTxt, const Color* pCol,
2047cdf0e10cSrcweir 					sal_Bool bChgAlign )
2048cdf0e10cSrcweir {
2049cdf0e10cSrcweir     sal_uLong nNdPos = rBox.IsValidNumTxtNd( sal_True );
2050cdf0e10cSrcweir     ChgTextToNum( rBox,rTxt,pCol,bChgAlign,nNdPos);
2051cdf0e10cSrcweir }
ChgTextToNum(SwTableBox & rBox,const String & rTxt,const Color * pCol,sal_Bool bChgAlign,sal_uLong nNdPos)2052cdf0e10cSrcweir void ChgTextToNum( SwTableBox& rBox, const String& rTxt, const Color* pCol,
2053cdf0e10cSrcweir 					sal_Bool bChgAlign,sal_uLong nNdPos )
2054cdf0e10cSrcweir {
2055cdf0e10cSrcweir 
2056cdf0e10cSrcweir 	if( ULONG_MAX != nNdPos )
2057cdf0e10cSrcweir 	{
2058cdf0e10cSrcweir 		SwDoc* pDoc = rBox.GetFrmFmt()->GetDoc();
2059cdf0e10cSrcweir 		SwTxtNode* pTNd = pDoc->GetNodes()[ nNdPos ]->GetTxtNode();
2060cdf0e10cSrcweir 		const SfxPoolItem* pItem;
2061cdf0e10cSrcweir 
2062cdf0e10cSrcweir 		// Ausrichtung umsetzen
2063cdf0e10cSrcweir 		if( bChgAlign )
2064cdf0e10cSrcweir 		{
2065cdf0e10cSrcweir 			pItem = &pTNd->SwCntntNode::GetAttr( RES_PARATR_ADJUST );
2066cdf0e10cSrcweir 			SvxAdjust eAdjust = ((SvxAdjustItem*)pItem)->GetAdjust();
2067cdf0e10cSrcweir 			if( SVX_ADJUST_LEFT == eAdjust || SVX_ADJUST_BLOCK == eAdjust )
2068cdf0e10cSrcweir 			{
2069cdf0e10cSrcweir 				SvxAdjustItem aAdjust( *(SvxAdjustItem*)pItem );
2070cdf0e10cSrcweir 				aAdjust.SetAdjust( SVX_ADJUST_RIGHT );
2071cdf0e10cSrcweir                 pTNd->SetAttr( aAdjust );
2072cdf0e10cSrcweir 			}
2073cdf0e10cSrcweir 		}
2074cdf0e10cSrcweir 
2075cdf0e10cSrcweir 		// Farbe umsetzen oder "Benutzer Farbe" sichern
2076cdf0e10cSrcweir 		if( !pTNd->GetpSwAttrSet() || SFX_ITEM_SET != pTNd->GetpSwAttrSet()->
2077cdf0e10cSrcweir 			GetItemState( RES_CHRATR_COLOR, sal_False, &pItem ))
2078cdf0e10cSrcweir 			pItem = 0;
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir 		const Color* pOldNumFmtColor = rBox.GetSaveNumFmtColor();
2081cdf0e10cSrcweir 		const Color* pNewUserColor = pItem ? &((SvxColorItem*)pItem)->GetValue() : 0;
2082cdf0e10cSrcweir 
2083cdf0e10cSrcweir 		if( ( pNewUserColor && pOldNumFmtColor &&
2084cdf0e10cSrcweir 				*pNewUserColor == *pOldNumFmtColor ) ||
2085cdf0e10cSrcweir 			( !pNewUserColor && !pOldNumFmtColor ))
2086cdf0e10cSrcweir 		{
2087cdf0e10cSrcweir 			// User Color nicht veraendern aktuellen Werte setzen
2088cdf0e10cSrcweir 			// ggfs. die alte NumFmtColor loeschen
2089cdf0e10cSrcweir 			if( pCol )
2090cdf0e10cSrcweir 				// ggfs. die Farbe setzen
2091cdf0e10cSrcweir                 pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
2092cdf0e10cSrcweir 			else if( pItem )
2093cdf0e10cSrcweir 			{
2094cdf0e10cSrcweir 				pNewUserColor = rBox.GetSaveUserColor();
2095cdf0e10cSrcweir 				if( pNewUserColor )
2096cdf0e10cSrcweir                     pTNd->SetAttr( SvxColorItem( *pNewUserColor, RES_CHRATR_COLOR ));
2097cdf0e10cSrcweir 				else
2098cdf0e10cSrcweir                     pTNd->ResetAttr( RES_CHRATR_COLOR );
2099cdf0e10cSrcweir 			}
2100cdf0e10cSrcweir 		}
2101cdf0e10cSrcweir 		else
2102cdf0e10cSrcweir 		{
2103cdf0e10cSrcweir 			// User Color merken, ggfs. die NumFormat Color setzen, aber
2104cdf0e10cSrcweir 			// nie die Farbe zurueck setzen
2105cdf0e10cSrcweir 			rBox.SetSaveUserColor( pNewUserColor );
2106cdf0e10cSrcweir 
2107cdf0e10cSrcweir 			if( pCol )
2108cdf0e10cSrcweir 				// ggfs. die Farbe setzen
2109cdf0e10cSrcweir                 pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
2110cdf0e10cSrcweir 
2111cdf0e10cSrcweir 		}
2112cdf0e10cSrcweir 		rBox.SetSaveNumFmtColor( pCol );
2113cdf0e10cSrcweir 
2114cdf0e10cSrcweir 		if( pTNd->GetTxt() != rTxt )
2115cdf0e10cSrcweir 		{
2116cdf0e10cSrcweir 			// Text austauschen
2117cdf0e10cSrcweir 			//JP 15.09.98: Bug 55741 - Tabs beibehalten (vorne und hinten!)
2118cdf0e10cSrcweir 			const String& rOrig = pTNd->GetTxt();
2119cdf0e10cSrcweir 			xub_StrLen n;
2120cdf0e10cSrcweir 
2121cdf0e10cSrcweir 			for( n = 0; n < rOrig.Len() && '\x9' == rOrig.GetChar( n ); ++n )
2122cdf0e10cSrcweir 				;
2123cdf0e10cSrcweir             for( ; n < rOrig.Len() && '\x01' == rOrig.GetChar( n ); ++n )
2124cdf0e10cSrcweir 				;
2125cdf0e10cSrcweir 			SwIndex aIdx( pTNd, n );
2126cdf0e10cSrcweir 			for( n = rOrig.Len(); n && '\x9' == rOrig.GetChar( --n ); )
2127cdf0e10cSrcweir 				;
2128cdf0e10cSrcweir 			n -= aIdx.GetIndex() - 1;
2129cdf0e10cSrcweir 
2130cdf0e10cSrcweir 			//JP 06.04.99: Bug 64321 - DontExpand-Flags vorm Austauschen
2131cdf0e10cSrcweir 			//             zuruecksetzen, damit sie wieder aufgespannt werden
2132cdf0e10cSrcweir 			{
2133cdf0e10cSrcweir 				SwIndex aResetIdx( aIdx, n );
2134cdf0e10cSrcweir 				pTNd->DontExpandFmt( aResetIdx, sal_False, sal_False );
2135cdf0e10cSrcweir 			}
2136cdf0e10cSrcweir 
2137cdf0e10cSrcweir             if( !pDoc->IsIgnoreRedline() && pDoc->GetRedlineTbl().Count() )
2138cdf0e10cSrcweir             {
2139cdf0e10cSrcweir                 SwPaM aTemp(*pTNd, 0, *pTNd, rOrig.Len());
2140cdf0e10cSrcweir                 pDoc->DeleteRedline(aTemp, true, USHRT_MAX);
2141cdf0e10cSrcweir             }
2142cdf0e10cSrcweir 
2143cdf0e10cSrcweir             pTNd->EraseText( aIdx, n,
2144cdf0e10cSrcweir                     IDocumentContentOperations::INS_EMPTYEXPAND );
2145cdf0e10cSrcweir             pTNd->InsertText( rTxt, aIdx,
2146cdf0e10cSrcweir                     IDocumentContentOperations::INS_EMPTYEXPAND );
2147cdf0e10cSrcweir 
2148cdf0e10cSrcweir             if( pDoc->IsRedlineOn() )
2149cdf0e10cSrcweir             {
2150cdf0e10cSrcweir                 SwPaM aTemp(*pTNd, 0, *pTNd, rTxt.Len());
2151cdf0e10cSrcweir                 pDoc->AppendRedline(new SwRedline(nsRedlineType_t::REDLINE_INSERT, aTemp), true);
2152cdf0e10cSrcweir             }
2153cdf0e10cSrcweir 		}
2154cdf0e10cSrcweir 
2155cdf0e10cSrcweir 		// vertikale Ausrichtung umsetzen
2156cdf0e10cSrcweir 		if( bChgAlign &&
2157cdf0e10cSrcweir 			( SFX_ITEM_SET != rBox.GetFrmFmt()->GetItemState(
2158cdf0e10cSrcweir 				RES_VERT_ORIENT, sal_True, &pItem ) ||
2159cdf0e10cSrcweir 				text::VertOrientation::TOP == ((SwFmtVertOrient*)pItem)->GetVertOrient() ))
2160cdf0e10cSrcweir 		{
2161cdf0e10cSrcweir             rBox.GetFrmFmt()->SetFmtAttr( SwFmtVertOrient( 0, text::VertOrientation::BOTTOM ));
2162cdf0e10cSrcweir 		}
2163cdf0e10cSrcweir 	}
2164cdf0e10cSrcweir }
2165cdf0e10cSrcweir 
ChgNumToText(SwTableBox & rBox,sal_uLong nFmt)2166cdf0e10cSrcweir void ChgNumToText( SwTableBox& rBox, sal_uLong nFmt )
2167cdf0e10cSrcweir {
2168cdf0e10cSrcweir 	sal_uLong nNdPos = rBox.IsValidNumTxtNd( sal_False );
2169cdf0e10cSrcweir 	if( ULONG_MAX != nNdPos )
2170cdf0e10cSrcweir 	{
2171cdf0e10cSrcweir 		SwDoc* pDoc = rBox.GetFrmFmt()->GetDoc();
2172cdf0e10cSrcweir 		SwTxtNode* pTNd = pDoc->GetNodes()[ nNdPos ]->GetTxtNode();
2173cdf0e10cSrcweir 		sal_Bool bChgAlign = pDoc->IsInsTblAlignNum();
2174cdf0e10cSrcweir 		const SfxPoolItem* pItem;
2175cdf0e10cSrcweir 
2176cdf0e10cSrcweir 		Color* pCol = 0;
2177cdf0e10cSrcweir 		if( NUMBERFORMAT_TEXT != nFmt )
2178cdf0e10cSrcweir 		{
2179cdf0e10cSrcweir 			// speziellen Textformat:
2180cdf0e10cSrcweir 			String sTmp, sTxt( pTNd->GetTxt() );
2181cdf0e10cSrcweir 			pDoc->GetNumberFormatter()->GetOutputString( sTxt, nFmt, sTmp, &pCol );
2182cdf0e10cSrcweir 			if( sTxt != sTmp )
2183cdf0e10cSrcweir 			{
2184cdf0e10cSrcweir 				// Text austauschen
2185cdf0e10cSrcweir 				SwIndex aIdx( pTNd, sTxt.Len() );
2186cdf0e10cSrcweir 				//JP 06.04.99: Bug 64321 - DontExpand-Flags vorm Austauschen
2187cdf0e10cSrcweir 				//             zuruecksetzen, damit sie wieder aufgespannt werden
2188cdf0e10cSrcweir 				pTNd->DontExpandFmt( aIdx, sal_False, sal_False );
2189cdf0e10cSrcweir 				aIdx = 0;
2190cdf0e10cSrcweir                 pTNd->EraseText( aIdx, STRING_LEN,
2191cdf0e10cSrcweir                         IDocumentContentOperations::INS_EMPTYEXPAND );
2192cdf0e10cSrcweir                 pTNd->InsertText( sTmp, aIdx,
2193cdf0e10cSrcweir                         IDocumentContentOperations::INS_EMPTYEXPAND );
2194cdf0e10cSrcweir             }
2195cdf0e10cSrcweir         }
2196cdf0e10cSrcweir 
2197cdf0e10cSrcweir         const SfxItemSet* pAttrSet = pTNd->GetpSwAttrSet();
2198cdf0e10cSrcweir 
2199cdf0e10cSrcweir 		// Ausrichtung umsetzen
2200cdf0e10cSrcweir 		if( bChgAlign && pAttrSet && SFX_ITEM_SET == pAttrSet->GetItemState(
2201cdf0e10cSrcweir 			RES_PARATR_ADJUST, sal_False, &pItem ) &&
2202cdf0e10cSrcweir 				SVX_ADJUST_RIGHT == ((SvxAdjustItem*)pItem)->GetAdjust() )
2203cdf0e10cSrcweir 		{
2204cdf0e10cSrcweir             pTNd->SetAttr( SvxAdjustItem( SVX_ADJUST_LEFT, RES_PARATR_ADJUST ) );
2205cdf0e10cSrcweir 		}
2206cdf0e10cSrcweir 
2207cdf0e10cSrcweir 		// Farbe umsetzen oder "Benutzer Farbe" sichern
2208cdf0e10cSrcweir 		if( !pAttrSet || SFX_ITEM_SET != pAttrSet->
2209cdf0e10cSrcweir 			GetItemState( RES_CHRATR_COLOR, sal_False, &pItem ))
2210cdf0e10cSrcweir 			pItem = 0;
2211cdf0e10cSrcweir 
2212cdf0e10cSrcweir 		const Color* pOldNumFmtColor = rBox.GetSaveNumFmtColor();
2213cdf0e10cSrcweir 		const Color* pNewUserColor = pItem ? &((SvxColorItem*)pItem)->GetValue() : 0;
2214cdf0e10cSrcweir 
2215cdf0e10cSrcweir 		if( ( pNewUserColor && pOldNumFmtColor &&
2216cdf0e10cSrcweir 				*pNewUserColor == *pOldNumFmtColor ) ||
2217cdf0e10cSrcweir 			( !pNewUserColor && !pOldNumFmtColor ))
2218cdf0e10cSrcweir 		{
2219cdf0e10cSrcweir 			// User Color nicht veraendern aktuellen Werte setzen
2220cdf0e10cSrcweir 			// ggfs. die alte NumFmtColor loeschen
2221cdf0e10cSrcweir 			if( pCol )
2222cdf0e10cSrcweir 				// ggfs. die Farbe setzen
2223cdf0e10cSrcweir                 pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
2224cdf0e10cSrcweir 			else if( pItem )
2225cdf0e10cSrcweir 			{
2226cdf0e10cSrcweir 				pNewUserColor = rBox.GetSaveUserColor();
2227cdf0e10cSrcweir 				if( pNewUserColor )
2228cdf0e10cSrcweir                     pTNd->SetAttr( SvxColorItem( *pNewUserColor, RES_CHRATR_COLOR ));
2229cdf0e10cSrcweir 				else
2230cdf0e10cSrcweir                     pTNd->ResetAttr( RES_CHRATR_COLOR );
2231cdf0e10cSrcweir 			}
2232cdf0e10cSrcweir 		}
2233cdf0e10cSrcweir 		else
2234cdf0e10cSrcweir 		{
2235cdf0e10cSrcweir 			// User Color merken, ggfs. die NumFormat Color setzen, aber
2236cdf0e10cSrcweir 			// nie die Farbe zurueck setzen
2237cdf0e10cSrcweir 			rBox.SetSaveUserColor( pNewUserColor );
2238cdf0e10cSrcweir 
2239cdf0e10cSrcweir 			if( pCol )
2240cdf0e10cSrcweir 				// ggfs. die Farbe setzen
2241cdf0e10cSrcweir                 pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
2242cdf0e10cSrcweir 
2243cdf0e10cSrcweir 		}
2244cdf0e10cSrcweir 		rBox.SetSaveNumFmtColor( pCol );
2245cdf0e10cSrcweir 
2246cdf0e10cSrcweir 
2247cdf0e10cSrcweir 		// vertikale Ausrichtung umsetzen
2248cdf0e10cSrcweir 		if( bChgAlign &&
2249cdf0e10cSrcweir 			SFX_ITEM_SET == rBox.GetFrmFmt()->GetItemState(
2250cdf0e10cSrcweir 			RES_VERT_ORIENT, sal_False, &pItem ) &&
2251cdf0e10cSrcweir 			text::VertOrientation::BOTTOM == ((SwFmtVertOrient*)pItem)->GetVertOrient() )
2252cdf0e10cSrcweir 		{
2253cdf0e10cSrcweir             rBox.GetFrmFmt()->SetFmtAttr( SwFmtVertOrient( 0, text::VertOrientation::TOP ));
2254cdf0e10cSrcweir 		}
2255cdf0e10cSrcweir 	}
2256cdf0e10cSrcweir }
2257cdf0e10cSrcweir 
2258cdf0e10cSrcweir // zum Erkennen von Veraenderungen (haupts. TableBoxAttribute)
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)2259cdf0e10cSrcweir void SwTableBoxFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
2260cdf0e10cSrcweir {
2261cdf0e10cSrcweir 	if( !IsModifyLocked() && !IsInDocDTOR() )
2262cdf0e10cSrcweir 	{
2263cdf0e10cSrcweir         const SwTblBoxNumFormat *pNewFmt = 0;
2264cdf0e10cSrcweir         const SwTblBoxFormula *pNewFml = 0;
2265cdf0e10cSrcweir         const SwTblBoxValue *pNewVal = 0;
2266cdf0e10cSrcweir 		double aOldValue = 0;
2267cdf0e10cSrcweir 		sal_uLong nOldFmt = NUMBERFORMAT_TEXT;
2268cdf0e10cSrcweir 
2269cdf0e10cSrcweir         switch( pNew ? pNew->Which() : 0 )
2270cdf0e10cSrcweir 		{
2271cdf0e10cSrcweir 		case RES_ATTRSET_CHG:
2272cdf0e10cSrcweir 			{
2273cdf0e10cSrcweir 				const SfxItemSet& rSet = *((SwAttrSetChg*)pNew)->GetChgSet();
2274cdf0e10cSrcweir 				if( SFX_ITEM_SET == rSet.GetItemState( RES_BOXATR_FORMAT,
2275cdf0e10cSrcweir 									sal_False, (const SfxPoolItem**)&pNewFmt ) )
2276cdf0e10cSrcweir 					nOldFmt = ((SwTblBoxNumFormat&)((SwAttrSetChg*)pOld)->
2277cdf0e10cSrcweir 							GetChgSet()->Get( RES_BOXATR_FORMAT )).GetValue();
2278cdf0e10cSrcweir 				rSet.GetItemState( RES_BOXATR_FORMULA, sal_False,
2279cdf0e10cSrcweir 									(const SfxPoolItem**)&pNewFml );
2280cdf0e10cSrcweir 				if( SFX_ITEM_SET == rSet.GetItemState( RES_BOXATR_VALUE,
2281cdf0e10cSrcweir 									sal_False, (const SfxPoolItem**)&pNewVal ) )
2282cdf0e10cSrcweir 					aOldValue = ((SwTblBoxValue&)((SwAttrSetChg*)pOld)->
2283cdf0e10cSrcweir 							GetChgSet()->Get( RES_BOXATR_VALUE )).GetValue();
2284cdf0e10cSrcweir 			}
2285cdf0e10cSrcweir 			break;
2286cdf0e10cSrcweir 
2287cdf0e10cSrcweir 		case RES_BOXATR_FORMAT:
2288cdf0e10cSrcweir 			pNewFmt = (SwTblBoxNumFormat*)pNew;
2289cdf0e10cSrcweir 			nOldFmt = ((SwTblBoxNumFormat*)pOld)->GetValue();
2290cdf0e10cSrcweir 			break;
2291cdf0e10cSrcweir 		case RES_BOXATR_FORMULA:
2292cdf0e10cSrcweir 			pNewFml = (SwTblBoxFormula*)pNew;
2293cdf0e10cSrcweir 			break;
2294cdf0e10cSrcweir 		case RES_BOXATR_VALUE:
2295cdf0e10cSrcweir 			pNewVal = (SwTblBoxValue*)pNew;
2296cdf0e10cSrcweir 			aOldValue = ((SwTblBoxValue*)pOld)->GetValue();
2297cdf0e10cSrcweir 			break;
2298cdf0e10cSrcweir 		}
2299cdf0e10cSrcweir 
2300cdf0e10cSrcweir 		// es hat sich etwas getan und im Set ist noch irgendein BoxAttribut
2301cdf0e10cSrcweir 		// vorhanden!
2302cdf0e10cSrcweir 		if( pNewFmt || pNewFml || pNewVal )
2303cdf0e10cSrcweir 		{
2304cdf0e10cSrcweir 			GetDoc()->SetFieldsDirty(true, NULL, 0);
2305cdf0e10cSrcweir 
2306cdf0e10cSrcweir 			if( SFX_ITEM_SET == GetItemState( RES_BOXATR_FORMAT, sal_False ) ||
2307cdf0e10cSrcweir 				SFX_ITEM_SET == GetItemState( RES_BOXATR_VALUE, sal_False ) ||
2308cdf0e10cSrcweir 				SFX_ITEM_SET == GetItemState( RES_BOXATR_FORMULA, sal_False ) )
2309cdf0e10cSrcweir 			{
2310cdf0e10cSrcweir 				// die Box holen
2311cdf0e10cSrcweir 				SwIterator<SwTableBox,SwFmt> aIter( *this );
2312cdf0e10cSrcweir 				SwTableBox* pBox = aIter.First();
2313cdf0e10cSrcweir 				if( pBox )
2314cdf0e10cSrcweir 				{
2315cdf0e10cSrcweir 					ASSERT( !aIter.Next(), "keine Box oder mehrere am Format" );
2316cdf0e10cSrcweir 
2317cdf0e10cSrcweir 					sal_uLong nNewFmt;
2318cdf0e10cSrcweir 					if( pNewFmt )
2319cdf0e10cSrcweir 					{
2320cdf0e10cSrcweir 						nNewFmt = pNewFmt->GetValue();
2321cdf0e10cSrcweir 						// neu Formatieren
2322cdf0e10cSrcweir 						// ist es neuer oder wurde der akt. entfernt?
2323cdf0e10cSrcweir 						if( SFX_ITEM_SET != GetItemState( RES_BOXATR_VALUE, sal_False ))
2324cdf0e10cSrcweir 							pNewFmt = 0;
2325cdf0e10cSrcweir 					}
2326cdf0e10cSrcweir 					else
2327cdf0e10cSrcweir 					{
2328cdf0e10cSrcweir 						// das akt. Item besorgen
2329cdf0e10cSrcweir 						GetItemState( RES_BOXATR_FORMAT, sal_False,
2330cdf0e10cSrcweir 											(const SfxPoolItem**)&pNewFmt );
2331cdf0e10cSrcweir 						nOldFmt = GetTblBoxNumFmt().GetValue();
2332cdf0e10cSrcweir 						nNewFmt = pNewFmt ? pNewFmt->GetValue() : nOldFmt;
2333cdf0e10cSrcweir 					}
2334cdf0e10cSrcweir 
2335cdf0e10cSrcweir 					// ist es neuer oder wurde der akt. entfernt?
2336cdf0e10cSrcweir 					if( pNewVal )
2337cdf0e10cSrcweir 					{
2338cdf0e10cSrcweir 						if( NUMBERFORMAT_TEXT != nNewFmt )
2339cdf0e10cSrcweir 						{
2340cdf0e10cSrcweir 							if( SFX_ITEM_SET == GetItemState(
2341cdf0e10cSrcweir 												RES_BOXATR_VALUE, sal_False ))
2342cdf0e10cSrcweir 								nOldFmt = NUMBERFORMAT_TEXT;
2343cdf0e10cSrcweir 							else
2344cdf0e10cSrcweir 								nNewFmt = NUMBERFORMAT_TEXT;
2345cdf0e10cSrcweir 						}
2346cdf0e10cSrcweir 						else if( NUMBERFORMAT_TEXT == nNewFmt )
2347cdf0e10cSrcweir 							nOldFmt = 0;
2348cdf0e10cSrcweir 					}
2349cdf0e10cSrcweir 
2350cdf0e10cSrcweir 					// Logik:
2351cdf0e10cSrcweir 					// ValueAenderung:	-> "simuliere" eine FormatAenderung!
2352cdf0e10cSrcweir 					// FormatAenderung:
2353cdf0e10cSrcweir 					// Text -> !Text oder FormatAenderung:
2354cdf0e10cSrcweir 					//			- Ausrichtung auf RECHTS, wenn LINKS oder Blocksatz
2355cdf0e10cSrcweir 					//			- vertikale Ausrichtung auf UNTEN wenn OBEN oder nicht
2356cdf0e10cSrcweir 					//				gesetzt ist.
2357cdf0e10cSrcweir 					//			- Text ersetzen (Farbe?? neg. Zahlen ROT??)
2358cdf0e10cSrcweir 					// !Text -> Text:
2359cdf0e10cSrcweir 					//			- Ausrichtung auf LINKS, wenn RECHTS
2360cdf0e10cSrcweir 					//			- vertikale Ausrichtung auf OEBN, wenn UNTEN gesetzt ist
2361cdf0e10cSrcweir 
2362cdf0e10cSrcweir 					SvNumberFormatter* pNumFmtr = GetDoc()->GetNumberFormatter();
2363cdf0e10cSrcweir 					sal_Bool bNewIsTxtFmt = pNumFmtr->IsTextFormat( nNewFmt ) ||
2364cdf0e10cSrcweir 										NUMBERFORMAT_TEXT == nNewFmt;
2365cdf0e10cSrcweir 
2366cdf0e10cSrcweir 					if( (!bNewIsTxtFmt && nOldFmt != nNewFmt) || pNewFml )
2367cdf0e10cSrcweir 					{
2368cdf0e10cSrcweir 						sal_Bool bChgTxt = sal_True;
2369cdf0e10cSrcweir 						double fVal = 0;
2370cdf0e10cSrcweir 						if( !pNewVal && SFX_ITEM_SET != GetItemState(
2371cdf0e10cSrcweir 							RES_BOXATR_VALUE, sal_False, (const SfxPoolItem**)&pNewVal ))
2372cdf0e10cSrcweir 						{
2373cdf0e10cSrcweir 							// es wurde noch nie ein Wert gesetzt, dann versuche
2374cdf0e10cSrcweir 							// doch mal den Inhalt auszuwerten
2375cdf0e10cSrcweir 							sal_uLong nNdPos = pBox->IsValidNumTxtNd( sal_True );
2376cdf0e10cSrcweir 							if( ULONG_MAX != nNdPos )
2377cdf0e10cSrcweir 							{
2378cdf0e10cSrcweir 								sal_uInt32 nTmpFmtIdx = nNewFmt;
2379cdf0e10cSrcweir 								String aTxt( GetDoc()->GetNodes()[ nNdPos ]
2380cdf0e10cSrcweir 												->GetTxtNode()->GetRedlineTxt());
2381cdf0e10cSrcweir 								if( !aTxt.Len() )
2382cdf0e10cSrcweir 									bChgTxt = sal_False;
2383cdf0e10cSrcweir 								else
2384cdf0e10cSrcweir 								{
2385cdf0e10cSrcweir 									//JP 15.09.98: Bug 55741 - Tabs beibehalten
2386cdf0e10cSrcweir 									lcl_TabToBlankAtSttEnd( aTxt );
2387cdf0e10cSrcweir 
2388cdf0e10cSrcweir 									// JP 22.04.98: Bug 49659 -
2389cdf0e10cSrcweir 									//			Sonderbehandlung fuer Prozent
2390cdf0e10cSrcweir 									sal_Bool bIsNumFmt = sal_False;
2391cdf0e10cSrcweir 									if( NUMBERFORMAT_PERCENT ==
2392cdf0e10cSrcweir 										pNumFmtr->GetType( nNewFmt ))
2393cdf0e10cSrcweir 									{
2394cdf0e10cSrcweir 										sal_uInt32 nTmpFmt = 0;
2395cdf0e10cSrcweir 										if( pNumFmtr->IsNumberFormat(
2396cdf0e10cSrcweir 													aTxt, nTmpFmt, fVal ))
2397cdf0e10cSrcweir 										{
2398cdf0e10cSrcweir 											if( NUMBERFORMAT_NUMBER ==
2399cdf0e10cSrcweir 												pNumFmtr->GetType( nTmpFmt ))
2400cdf0e10cSrcweir 												aTxt += '%';
2401cdf0e10cSrcweir 
2402cdf0e10cSrcweir 											bIsNumFmt = pNumFmtr->IsNumberFormat(
2403cdf0e10cSrcweir 														aTxt, nTmpFmtIdx, fVal );
2404cdf0e10cSrcweir 										}
2405cdf0e10cSrcweir 									}
2406cdf0e10cSrcweir 									else
2407cdf0e10cSrcweir 										bIsNumFmt = pNumFmtr->IsNumberFormat(
2408cdf0e10cSrcweir 														aTxt, nTmpFmtIdx, fVal );
2409cdf0e10cSrcweir 
2410cdf0e10cSrcweir 									if( bIsNumFmt )
2411cdf0e10cSrcweir 									{
2412cdf0e10cSrcweir 										// dann setze den Value direkt in den Set -
2413cdf0e10cSrcweir 										// ohne Modify
2414cdf0e10cSrcweir 										int bIsLockMod = IsModifyLocked();
2415cdf0e10cSrcweir 										LockModify();
2416cdf0e10cSrcweir                                         SetFmtAttr( SwTblBoxValue( fVal ));
2417cdf0e10cSrcweir 										if( !bIsLockMod )
2418cdf0e10cSrcweir 											UnlockModify();
2419cdf0e10cSrcweir 									}
2420cdf0e10cSrcweir 								}
2421cdf0e10cSrcweir 							}
2422cdf0e10cSrcweir 						}
2423cdf0e10cSrcweir 						else
2424cdf0e10cSrcweir 							fVal = pNewVal->GetValue();
2425cdf0e10cSrcweir 
2426cdf0e10cSrcweir 						// den Inhalt mit dem neuen Wert Formtieren und in den Absatz
2427cdf0e10cSrcweir 						// schbreiben
2428cdf0e10cSrcweir 						Color* pCol = 0;
2429cdf0e10cSrcweir 						String sNewTxt;
2430cdf0e10cSrcweir 						if( DBL_MAX == fVal )
2431cdf0e10cSrcweir 							sNewTxt = ViewShell::GetShellRes()->aCalc_Error;
2432cdf0e10cSrcweir 						else
2433cdf0e10cSrcweir 						{
2434cdf0e10cSrcweir 							pNumFmtr->GetOutputString( fVal, nNewFmt, sNewTxt, &pCol );
2435cdf0e10cSrcweir 
2436cdf0e10cSrcweir 							if( !bChgTxt )
2437cdf0e10cSrcweir 								sNewTxt.Erase();
2438cdf0e10cSrcweir 						}
2439cdf0e10cSrcweir 
2440cdf0e10cSrcweir 						// ueber alle Boxen
2441cdf0e10cSrcweir 						ChgTextToNum( *pBox, sNewTxt, pCol,
2442cdf0e10cSrcweir 										GetDoc()->IsInsTblAlignNum() );
2443cdf0e10cSrcweir 
2444cdf0e10cSrcweir 					}
2445cdf0e10cSrcweir 					else if( bNewIsTxtFmt && nOldFmt != nNewFmt )
2446cdf0e10cSrcweir 					{
2447cdf0e10cSrcweir 						// auf jedenfall muessen jetzt die Formeln/Values
2448cdf0e10cSrcweir 						// geloescht werden!
2449cdf0e10cSrcweir 	//					LockModify();
2450cdf0e10cSrcweir 	//					ResetAttr( RES_BOXATR_FORMULA, RES_BOXATR_VALUE );
2451cdf0e10cSrcweir 	//					UnlockModify();
2452cdf0e10cSrcweir 
2453cdf0e10cSrcweir 
2454cdf0e10cSrcweir 						ChgNumToText( *pBox, nNewFmt );
2455cdf0e10cSrcweir 					}
2456cdf0e10cSrcweir 				}
2457cdf0e10cSrcweir 			}
2458cdf0e10cSrcweir 		}
2459cdf0e10cSrcweir 	}
2460cdf0e10cSrcweir 	// Und die Basis-Klasse rufen
2461cdf0e10cSrcweir 	SwFrmFmt::Modify( pOld, pNew );
2462cdf0e10cSrcweir }
2463cdf0e10cSrcweir 
HasNumCntnt(double & rNum,sal_uInt32 & rFmtIndex,sal_Bool & rIsEmptyTxtNd) const2464cdf0e10cSrcweir sal_Bool SwTableBox::HasNumCntnt( double& rNum, sal_uInt32& rFmtIndex,
2465cdf0e10cSrcweir 							sal_Bool& rIsEmptyTxtNd ) const
2466cdf0e10cSrcweir {
2467cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2468cdf0e10cSrcweir 	sal_uLong nNdPos = IsValidNumTxtNd( sal_True );
2469cdf0e10cSrcweir 	if( ULONG_MAX != nNdPos )
2470cdf0e10cSrcweir 	{
2471cdf0e10cSrcweir 		String aTxt( pSttNd->GetNodes()[ nNdPos ]->GetTxtNode()->
2472cdf0e10cSrcweir 							GetRedlineTxt() );
2473cdf0e10cSrcweir 		//JP 15.09.98: Bug 55741 - Tabs beibehalten
2474cdf0e10cSrcweir 		lcl_TabToBlankAtSttEnd( aTxt );
2475cdf0e10cSrcweir 		rIsEmptyTxtNd = 0 == aTxt.Len();
2476cdf0e10cSrcweir 		SvNumberFormatter* pNumFmtr = GetFrmFmt()->GetDoc()->GetNumberFormatter();
2477cdf0e10cSrcweir 
2478cdf0e10cSrcweir 		const SfxPoolItem* pItem;
2479cdf0e10cSrcweir 		if( SFX_ITEM_SET == GetFrmFmt()->GetItemState( RES_BOXATR_FORMAT,
2480cdf0e10cSrcweir 				sal_False, &pItem ))
2481cdf0e10cSrcweir 		{
2482cdf0e10cSrcweir 			rFmtIndex = ((SwTblBoxNumFormat*)pItem)->GetValue();
2483cdf0e10cSrcweir 			// JP 22.04.98: Bug 49659 - Sonderbehandlung fuer Prozent
2484cdf0e10cSrcweir 			if( !rIsEmptyTxtNd &&
2485cdf0e10cSrcweir 				NUMBERFORMAT_PERCENT == pNumFmtr->GetType( rFmtIndex ))
2486cdf0e10cSrcweir 			{
2487cdf0e10cSrcweir 				sal_uInt32 nTmpFmt = 0;
2488cdf0e10cSrcweir 				if( pNumFmtr->IsNumberFormat( aTxt, nTmpFmt, rNum ) &&
2489cdf0e10cSrcweir 					NUMBERFORMAT_NUMBER == pNumFmtr->GetType( nTmpFmt ))
2490cdf0e10cSrcweir 					aTxt += '%';
2491cdf0e10cSrcweir 			}
2492cdf0e10cSrcweir 		}
2493cdf0e10cSrcweir 		else
2494cdf0e10cSrcweir 			rFmtIndex = 0;
2495cdf0e10cSrcweir 
2496cdf0e10cSrcweir 		bRet = pNumFmtr->IsNumberFormat( aTxt, rFmtIndex, rNum );
2497cdf0e10cSrcweir 	}
2498cdf0e10cSrcweir 	else
2499cdf0e10cSrcweir 		rIsEmptyTxtNd = sal_False;
2500cdf0e10cSrcweir 	return bRet;
2501cdf0e10cSrcweir }
2502cdf0e10cSrcweir 
IsNumberChanged() const2503cdf0e10cSrcweir sal_Bool SwTableBox::IsNumberChanged() const
2504cdf0e10cSrcweir {
2505cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
2506cdf0e10cSrcweir 
2507cdf0e10cSrcweir 	if( SFX_ITEM_SET == GetFrmFmt()->GetItemState( RES_BOXATR_FORMULA, sal_False ))
2508cdf0e10cSrcweir 	{
2509cdf0e10cSrcweir 		const SwTblBoxNumFormat *pNumFmt;
2510cdf0e10cSrcweir 		const SwTblBoxValue *pValue;
2511cdf0e10cSrcweir 
2512cdf0e10cSrcweir 		if( SFX_ITEM_SET != GetFrmFmt()->GetItemState( RES_BOXATR_VALUE, sal_False,
2513cdf0e10cSrcweir 			(const SfxPoolItem**)&pValue ))
2514cdf0e10cSrcweir 			pValue = 0;
2515cdf0e10cSrcweir 		if( SFX_ITEM_SET != GetFrmFmt()->GetItemState( RES_BOXATR_FORMAT, sal_False,
2516cdf0e10cSrcweir 			(const SfxPoolItem**)&pNumFmt ))
2517cdf0e10cSrcweir 			pNumFmt = 0;
2518cdf0e10cSrcweir 
2519cdf0e10cSrcweir 		sal_uLong nNdPos;
2520cdf0e10cSrcweir 		if( pNumFmt && pValue &&
2521cdf0e10cSrcweir 			ULONG_MAX != ( nNdPos = IsValidNumTxtNd( sal_True ) ) )
2522cdf0e10cSrcweir 		{
2523cdf0e10cSrcweir 			String sNewTxt, sOldTxt( pSttNd->GetNodes()[ nNdPos ]->
2524cdf0e10cSrcweir 									GetTxtNode()->GetRedlineTxt() );
2525cdf0e10cSrcweir 			lcl_DelTabsAtSttEnd( sOldTxt );
2526cdf0e10cSrcweir 
2527cdf0e10cSrcweir 			Color* pCol = 0;
2528cdf0e10cSrcweir 			GetFrmFmt()->GetDoc()->GetNumberFormatter()->GetOutputString(
2529cdf0e10cSrcweir 				pValue->GetValue(), pNumFmt->GetValue(), sNewTxt, &pCol );
2530cdf0e10cSrcweir 
2531cdf0e10cSrcweir 			bRet = sNewTxt != sOldTxt ||
2532cdf0e10cSrcweir 					!( ( !pCol && !GetSaveNumFmtColor() ) ||
2533cdf0e10cSrcweir 					   ( pCol && GetSaveNumFmtColor() &&
2534cdf0e10cSrcweir 						*pCol == *GetSaveNumFmtColor() ));
2535cdf0e10cSrcweir 		}
2536cdf0e10cSrcweir 	}
2537cdf0e10cSrcweir 	return bRet;
2538cdf0e10cSrcweir }
2539cdf0e10cSrcweir 
IsValidNumTxtNd(sal_Bool bCheckAttr) const2540cdf0e10cSrcweir sal_uLong SwTableBox::IsValidNumTxtNd( sal_Bool bCheckAttr ) const
2541cdf0e10cSrcweir {
2542cdf0e10cSrcweir 	sal_uLong nPos = ULONG_MAX;
2543cdf0e10cSrcweir 	if( pSttNd )
2544cdf0e10cSrcweir 	{
2545cdf0e10cSrcweir 		SwNodeIndex aIdx( *pSttNd );
2546cdf0e10cSrcweir 		sal_uLong nIndex = aIdx.GetIndex();
2547cdf0e10cSrcweir 		const sal_uLong nIndexEnd = pSttNd->GetNodes()[ nIndex ]->EndOfSectionIndex();
2548cdf0e10cSrcweir 		const SwTxtNode *pTextNode = 0;
2549cdf0e10cSrcweir 		while( ++nIndex < nIndexEnd )
2550cdf0e10cSrcweir 		{
2551cdf0e10cSrcweir             const SwNode* pNode = pSttNd->GetNodes()[nIndex];
2552cdf0e10cSrcweir 			if( pNode->IsTableNode() )
2553cdf0e10cSrcweir 			{    /*return ULONG_MAX if the cell contains a table(in table)*/
2554cdf0e10cSrcweir 				pTextNode = 0;
2555cdf0e10cSrcweir 				break;
2556cdf0e10cSrcweir 			}
2557cdf0e10cSrcweir 			if( pNode->IsTxtNode() )
2558cdf0e10cSrcweir 			{
2559cdf0e10cSrcweir 				if( pTextNode )
2560cdf0e10cSrcweir 				{    /*return ULONG_MAX if the cell contains complex paragraphs*/
2561cdf0e10cSrcweir 					pTextNode = 0;
2562cdf0e10cSrcweir 					break;
2563cdf0e10cSrcweir 				}
2564cdf0e10cSrcweir                 else
2565cdf0e10cSrcweir                 {
2566cdf0e10cSrcweir                     pTextNode = pNode->GetTxtNode();
2567cdf0e10cSrcweir                     nPos = nIndex;
2568cdf0e10cSrcweir                 }
2569cdf0e10cSrcweir 			}
2570cdf0e10cSrcweir 		}
2571cdf0e10cSrcweir 		if( pTextNode )
2572cdf0e10cSrcweir 		{
2573cdf0e10cSrcweir 			if( bCheckAttr )
2574cdf0e10cSrcweir 			{
2575cdf0e10cSrcweir 				const SwpHints* pHts = pTextNode->GetpSwpHints();
2576cdf0e10cSrcweir 				const String& rTxt = pTextNode->GetTxt();
2577cdf0e10cSrcweir                 // dann teste doch mal, ob das wirklich nur Text im Node steht!
2578cdf0e10cSrcweir                 // Flys/Felder/..
2579cdf0e10cSrcweir                 if( pHts )
2580cdf0e10cSrcweir                 {
2581b1f53925SMichael Stahl                     xub_StrLen nNextSetField = 0;
2582cdf0e10cSrcweir                     for( sal_uInt16 n = 0; n < pHts->Count(); ++n )
2583cdf0e10cSrcweir                     {
2584cdf0e10cSrcweir                         const SwTxtAttr* pAttr = (*pHts)[ n ];
2585cdf0e10cSrcweir                         if( RES_TXTATR_NOEND_BEGIN <= pAttr->Which() ||
2586cdf0e10cSrcweir                             *pAttr->GetStart() ||
2587cdf0e10cSrcweir                             *pAttr->GetAnyEnd() < rTxt.Len() )
2588cdf0e10cSrcweir                         {
2589*dec99bbdSOliver-Rainer Wittmann                             if ( (*pAttr->GetStart() == nNextSetField)
2590*dec99bbdSOliver-Rainer Wittmann                                  && (pAttr->Which() == RES_TXTATR_FIELD))
2591cdf0e10cSrcweir                             {
2592b1f53925SMichael Stahl                                 // #i104949# hideous hack for report builder:
2593b1f53925SMichael Stahl                                 // it inserts hidden variable-set fields at
2594b1f53925SMichael Stahl                                 // the beginning of para in cell, but they
2595b1f53925SMichael Stahl                                 // should not turn cell into text cell
2596c0286415SOliver-Rainer Wittmann                                 const SwField* pField = pAttr->GetFmtFld().GetField();
2597b1f53925SMichael Stahl                                 if (pField &&
2598b1f53925SMichael Stahl                                     (pField->GetTypeId() == TYP_SETFLD) &&
2599b1f53925SMichael Stahl                                     (0 != (static_cast<SwSetExpField const*>
2600b1f53925SMichael Stahl                                            (pField)->GetSubType() &
2601b1f53925SMichael Stahl                                         nsSwExtendedSubType::SUB_INVISIBLE)))
2602cdf0e10cSrcweir                                 {
2603b1f53925SMichael Stahl                                     nNextSetField = *pAttr->GetStart() + 1;
2604cdf0e10cSrcweir                                     continue;
2605cdf0e10cSrcweir                                 }
2606cdf0e10cSrcweir                             }
2607cdf0e10cSrcweir                             nPos = ULONG_MAX;
2608cdf0e10cSrcweir                             break;
2609cdf0e10cSrcweir                         }
2610cdf0e10cSrcweir                     }
2611cdf0e10cSrcweir                 }
2612cdf0e10cSrcweir 			}
2613cdf0e10cSrcweir 		}
2614cdf0e10cSrcweir         else
2615cdf0e10cSrcweir             nPos = ULONG_MAX;
2616cdf0e10cSrcweir 	}
2617cdf0e10cSrcweir 	return nPos;
2618cdf0e10cSrcweir }
2619cdf0e10cSrcweir 
2620cdf0e10cSrcweir // ist das eine FormelBox oder eine Box mit numerischen Inhalt (AutoSum)
IsFormulaOrValueBox() const2621cdf0e10cSrcweir sal_uInt16 SwTableBox::IsFormulaOrValueBox() const
2622cdf0e10cSrcweir {
2623cdf0e10cSrcweir 	sal_uInt16 nWhich = 0;
2624cdf0e10cSrcweir 	const SwTxtNode* pTNd;
2625cdf0e10cSrcweir 	SwFrmFmt* pFmt = GetFrmFmt();
2626cdf0e10cSrcweir 	if( SFX_ITEM_SET == pFmt->GetItemState( RES_BOXATR_FORMULA, sal_False ))
2627cdf0e10cSrcweir 		nWhich = RES_BOXATR_FORMULA;
2628cdf0e10cSrcweir 	else if( SFX_ITEM_SET == pFmt->GetItemState( RES_BOXATR_VALUE, sal_False ) &&
2629cdf0e10cSrcweir 			!pFmt->GetDoc()->GetNumberFormatter()->IsTextFormat(
2630cdf0e10cSrcweir 				pFmt->GetTblBoxNumFmt().GetValue() ))
2631cdf0e10cSrcweir 		nWhich = RES_BOXATR_VALUE;
2632cdf0e10cSrcweir 	else if( pSttNd && pSttNd->GetIndex() + 2 == pSttNd->EndOfSectionIndex()
2633cdf0e10cSrcweir 			&& 0 != ( pTNd = pSttNd->GetNodes()[ pSttNd->GetIndex() + 1 ]
2634cdf0e10cSrcweir 			->GetTxtNode() ) && !pTNd->GetTxt().Len() )
2635cdf0e10cSrcweir 		nWhich = USHRT_MAX;
2636cdf0e10cSrcweir 
2637cdf0e10cSrcweir 	return nWhich;
2638cdf0e10cSrcweir }
2639cdf0e10cSrcweir 
ActualiseValueBox()2640cdf0e10cSrcweir void SwTableBox::ActualiseValueBox()
2641cdf0e10cSrcweir {
2642cdf0e10cSrcweir 	const SfxPoolItem *pFmtItem, *pValItem;
2643cdf0e10cSrcweir 	SwFrmFmt* pFmt = GetFrmFmt();
2644cdf0e10cSrcweir 	if( SFX_ITEM_SET == pFmt->GetItemState( RES_BOXATR_FORMAT, sal_True, &pFmtItem )
2645cdf0e10cSrcweir 		&& SFX_ITEM_SET == pFmt->GetItemState( RES_BOXATR_VALUE, sal_True, &pValItem ))
2646cdf0e10cSrcweir 	{
2647cdf0e10cSrcweir         const sal_uLong nFmtId = ((SwTblBoxNumFormat*)pFmtItem)->GetValue();
2648cdf0e10cSrcweir 		sal_uLong nNdPos = ULONG_MAX;
2649cdf0e10cSrcweir 		SvNumberFormatter* pNumFmtr = pFmt->GetDoc()->GetNumberFormatter();
2650cdf0e10cSrcweir 
2651cdf0e10cSrcweir 		if( !pNumFmtr->IsTextFormat( nFmtId ) &&
2652cdf0e10cSrcweir 			ULONG_MAX != (nNdPos = IsValidNumTxtNd( sal_True )) )
2653cdf0e10cSrcweir 		{
2654cdf0e10cSrcweir 			double fVal = ((SwTblBoxValue*)pValItem)->GetValue();
2655cdf0e10cSrcweir 			Color* pCol = 0;
2656cdf0e10cSrcweir 			String sNewTxt;
2657cdf0e10cSrcweir 			pNumFmtr->GetOutputString( fVal, nFmtId, sNewTxt, &pCol );
2658cdf0e10cSrcweir 
2659cdf0e10cSrcweir 			const String& rTxt = pSttNd->GetNodes()[ nNdPos ]->GetTxtNode()->GetTxt();
2660cdf0e10cSrcweir 			if( rTxt != sNewTxt )
2661cdf0e10cSrcweir 				ChgTextToNum( *this, sNewTxt, pCol, sal_False ,nNdPos);
2662cdf0e10cSrcweir 		}
2663cdf0e10cSrcweir 	}
2664cdf0e10cSrcweir }
2665cdf0e10cSrcweir 
SetNewCol(Color ** ppCol,const Color * pNewCol)2666cdf0e10cSrcweir void SwTableBox_Impl::SetNewCol( Color** ppCol, const Color* pNewCol )
2667cdf0e10cSrcweir {
2668cdf0e10cSrcweir 	if( *ppCol != pNewCol )
2669cdf0e10cSrcweir 	{
2670cdf0e10cSrcweir 		delete *ppCol;
2671cdf0e10cSrcweir 		if( pNewCol )
2672cdf0e10cSrcweir 			*ppCol = new Color( *pNewCol );
2673cdf0e10cSrcweir 		else
2674cdf0e10cSrcweir 			*ppCol = 0;
2675cdf0e10cSrcweir 	}
2676cdf0e10cSrcweir }
2677cdf0e10cSrcweir 
2678cdf0e10cSrcweir struct SwTableCellInfo::Impl
2679cdf0e10cSrcweir {
2680cdf0e10cSrcweir     const SwTable * m_pTable;
2681cdf0e10cSrcweir     const SwCellFrm * m_pCellFrm;
2682cdf0e10cSrcweir     const SwTabFrm * m_pTabFrm;
2683cdf0e10cSrcweir     typedef ::std::set<const SwTableBox *> TableBoxes_t;
2684cdf0e10cSrcweir     TableBoxes_t m_HandledTableBoxes;
2685cdf0e10cSrcweir 
2686cdf0e10cSrcweir public:
ImplSwTableCellInfo::Impl2687cdf0e10cSrcweir     Impl()
2688cdf0e10cSrcweir         : m_pTable(NULL), m_pCellFrm(NULL), m_pTabFrm(NULL)
2689cdf0e10cSrcweir     {
2690cdf0e10cSrcweir     }
2691cdf0e10cSrcweir 
~ImplSwTableCellInfo::Impl2692cdf0e10cSrcweir     ~Impl() {}
2693cdf0e10cSrcweir 
setTableSwTableCellInfo::Impl2694cdf0e10cSrcweir     void setTable(const SwTable * pTable) {
2695cdf0e10cSrcweir         m_pTable = pTable;
2696cdf0e10cSrcweir         SwFrmFmt * pFrmFmt = m_pTable->GetFrmFmt();
2697cdf0e10cSrcweir         m_pTabFrm = SwIterator<SwTabFrm,SwFmt>::FirstElement(*pFrmFmt);
2698cdf0e10cSrcweir         if (m_pTabFrm->IsFollow())
2699cdf0e10cSrcweir             m_pTabFrm = m_pTabFrm->FindMaster(true);
2700cdf0e10cSrcweir     }
getTableSwTableCellInfo::Impl2701cdf0e10cSrcweir     const SwTable * getTable() const { return m_pTable; }
2702cdf0e10cSrcweir 
getCellFrmSwTableCellInfo::Impl2703cdf0e10cSrcweir     const SwCellFrm * getCellFrm() const { return m_pCellFrm; }
2704cdf0e10cSrcweir 
2705cdf0e10cSrcweir     const SwFrm * getNextFrmInTable(const SwFrm * pFrm);
2706cdf0e10cSrcweir     const SwCellFrm * getNextCellFrm(const SwFrm * pFrm);
2707cdf0e10cSrcweir     const SwCellFrm * getNextTableBoxsCellFrm(const SwFrm * pFrm);
2708cdf0e10cSrcweir     bool getNext();
2709cdf0e10cSrcweir };
2710cdf0e10cSrcweir 
getNextFrmInTable(const SwFrm * pFrm)2711cdf0e10cSrcweir const SwFrm * SwTableCellInfo::Impl::getNextFrmInTable(const SwFrm * pFrm)
2712cdf0e10cSrcweir {
2713cdf0e10cSrcweir     const SwFrm * pResult = NULL;
2714cdf0e10cSrcweir 
2715cdf0e10cSrcweir     if (((! pFrm->IsTabFrm()) || pFrm == m_pTabFrm) && pFrm->GetLower())
2716cdf0e10cSrcweir         pResult = pFrm->GetLower();
2717cdf0e10cSrcweir     else if (pFrm->GetNext())
2718cdf0e10cSrcweir         pResult = pFrm->GetNext();
2719cdf0e10cSrcweir     else
2720cdf0e10cSrcweir     {
2721cdf0e10cSrcweir         while (pFrm->GetUpper() != NULL)
2722cdf0e10cSrcweir         {
2723cdf0e10cSrcweir             pFrm = pFrm->GetUpper();
2724cdf0e10cSrcweir 
2725cdf0e10cSrcweir             if (pFrm->IsTabFrm())
2726cdf0e10cSrcweir             {
2727cdf0e10cSrcweir                 m_pTabFrm = static_cast<const SwTabFrm *>(pFrm)->GetFollow();
2728cdf0e10cSrcweir                 pResult = m_pTabFrm;
2729cdf0e10cSrcweir                 break;
2730cdf0e10cSrcweir             }
2731cdf0e10cSrcweir             else if (pFrm->GetNext())
2732cdf0e10cSrcweir             {
2733cdf0e10cSrcweir                 pResult = pFrm->GetNext();
2734cdf0e10cSrcweir                 break;
2735cdf0e10cSrcweir             }
2736cdf0e10cSrcweir         }
2737cdf0e10cSrcweir     }
2738cdf0e10cSrcweir 
2739cdf0e10cSrcweir     return pResult;
2740cdf0e10cSrcweir }
2741cdf0e10cSrcweir 
getNextCellFrm(const SwFrm * pFrm)2742cdf0e10cSrcweir const SwCellFrm * SwTableCellInfo::Impl::getNextCellFrm(const SwFrm * pFrm)
2743cdf0e10cSrcweir {
2744cdf0e10cSrcweir     const SwCellFrm * pResult = NULL;
2745cdf0e10cSrcweir 
2746cdf0e10cSrcweir     while ((pFrm = getNextFrmInTable(pFrm)) != NULL)
2747cdf0e10cSrcweir     {
2748cdf0e10cSrcweir         if (pFrm->IsCellFrm())
2749cdf0e10cSrcweir         {
2750cdf0e10cSrcweir             pResult = static_cast<const SwCellFrm *>(pFrm);
2751cdf0e10cSrcweir             break;
2752cdf0e10cSrcweir         }
2753cdf0e10cSrcweir     }
2754cdf0e10cSrcweir 
2755cdf0e10cSrcweir     return pResult;
2756cdf0e10cSrcweir }
2757cdf0e10cSrcweir 
getNextTableBoxsCellFrm(const SwFrm * pFrm)2758cdf0e10cSrcweir const SwCellFrm * SwTableCellInfo::Impl::getNextTableBoxsCellFrm(const SwFrm * pFrm)
2759cdf0e10cSrcweir {
2760cdf0e10cSrcweir     const SwCellFrm * pResult = NULL;
2761cdf0e10cSrcweir 
2762cdf0e10cSrcweir     while ((pFrm = getNextCellFrm(pFrm)) != NULL)
2763cdf0e10cSrcweir     {
2764cdf0e10cSrcweir         const SwCellFrm * pCellFrm = static_cast<const SwCellFrm *>(pFrm);
2765cdf0e10cSrcweir         const SwTableBox * pTabBox = pCellFrm->GetTabBox();
2766cdf0e10cSrcweir         TableBoxes_t::const_iterator aIt = m_HandledTableBoxes.find(pTabBox);
2767cdf0e10cSrcweir 
2768cdf0e10cSrcweir         if (aIt == m_HandledTableBoxes.end())
2769cdf0e10cSrcweir         {
2770cdf0e10cSrcweir             pResult = pCellFrm;
2771cdf0e10cSrcweir             m_HandledTableBoxes.insert(pTabBox);
2772cdf0e10cSrcweir             break;
2773cdf0e10cSrcweir         }
2774cdf0e10cSrcweir     }
2775cdf0e10cSrcweir 
2776cdf0e10cSrcweir     return pResult;
2777cdf0e10cSrcweir }
2778cdf0e10cSrcweir 
getCellFrm() const2779cdf0e10cSrcweir const SwCellFrm * SwTableCellInfo::getCellFrm() const
2780cdf0e10cSrcweir {
2781cdf0e10cSrcweir     return m_pImpl->getCellFrm();
2782cdf0e10cSrcweir }
2783cdf0e10cSrcweir 
getNext()2784cdf0e10cSrcweir bool SwTableCellInfo::Impl::getNext()
2785cdf0e10cSrcweir {
2786cdf0e10cSrcweir     if (m_pCellFrm == NULL)
2787cdf0e10cSrcweir     {
2788cdf0e10cSrcweir         if (m_pTabFrm != NULL)
2789cdf0e10cSrcweir             m_pCellFrm = Impl::getNextTableBoxsCellFrm(m_pTabFrm);
2790cdf0e10cSrcweir     }
2791cdf0e10cSrcweir     else
2792cdf0e10cSrcweir         m_pCellFrm = Impl::getNextTableBoxsCellFrm(m_pCellFrm);
2793cdf0e10cSrcweir 
2794cdf0e10cSrcweir     return m_pCellFrm != NULL;
2795cdf0e10cSrcweir }
2796cdf0e10cSrcweir 
SwTableCellInfo(const SwTable * pTable)2797cdf0e10cSrcweir SwTableCellInfo::SwTableCellInfo(const SwTable * pTable)
2798cdf0e10cSrcweir {
2799cdf0e10cSrcweir     m_pImpl.reset(new Impl());
2800cdf0e10cSrcweir     m_pImpl->setTable(pTable);
2801cdf0e10cSrcweir }
2802cdf0e10cSrcweir 
~SwTableCellInfo()2803cdf0e10cSrcweir SwTableCellInfo::~SwTableCellInfo()
2804cdf0e10cSrcweir {
2805cdf0e10cSrcweir }
2806cdf0e10cSrcweir 
getNext()2807cdf0e10cSrcweir bool SwTableCellInfo::getNext()
2808cdf0e10cSrcweir {
2809cdf0e10cSrcweir     return m_pImpl->getNext();
2810cdf0e10cSrcweir }
2811cdf0e10cSrcweir 
getRect() const2812cdf0e10cSrcweir SwRect SwTableCellInfo::getRect() const
2813cdf0e10cSrcweir {
2814cdf0e10cSrcweir     SwRect aRet;
2815cdf0e10cSrcweir 
2816cdf0e10cSrcweir     if (getCellFrm() != NULL)
2817cdf0e10cSrcweir         aRet = getCellFrm()->Frm();
2818cdf0e10cSrcweir 
2819cdf0e10cSrcweir     return aRet;
2820cdf0e10cSrcweir }
2821cdf0e10cSrcweir 
getTableBox() const2822cdf0e10cSrcweir const SwTableBox * SwTableCellInfo::getTableBox() const
2823cdf0e10cSrcweir {
2824cdf0e10cSrcweir     const SwTableBox * pRet = NULL;
2825cdf0e10cSrcweir 
2826cdf0e10cSrcweir     if (getCellFrm() != NULL)
2827cdf0e10cSrcweir         pRet = getCellFrm()->GetTabBox();
2828cdf0e10cSrcweir 
2829cdf0e10cSrcweir     return pRet;
2830cdf0e10cSrcweir }
2831cdf0e10cSrcweir 
RegisterToFormat(SwFmt & rFmt)2832cdf0e10cSrcweir void SwTable::RegisterToFormat( SwFmt& rFmt )
2833cdf0e10cSrcweir {
2834cdf0e10cSrcweir     rFmt.Add( this );
2835cdf0e10cSrcweir }
2836cdf0e10cSrcweir 
RegisterToFormat(SwFmt & rFmt)2837cdf0e10cSrcweir void SwTableLine::RegisterToFormat( SwFmt& rFmt )
2838cdf0e10cSrcweir {
2839cdf0e10cSrcweir     rFmt.Add( this );
2840cdf0e10cSrcweir }
2841cdf0e10cSrcweir 
RegisterToFormat(SwFmt & rFmt)2842cdf0e10cSrcweir void SwTableBox::RegisterToFormat( SwFmt& rFmt )
2843cdf0e10cSrcweir {
2844cdf0e10cSrcweir     rFmt.Add( this );
2845cdf0e10cSrcweir }
2846cdf0e10cSrcweir 
ForgetFrmFmt()2847cdf0e10cSrcweir void SwTableBox::ForgetFrmFmt()
2848cdf0e10cSrcweir {
2849cdf0e10cSrcweir     if ( GetRegisteredIn() )
2850cdf0e10cSrcweir         GetRegisteredInNonConst()->Remove(this);
2851cdf0e10cSrcweir }
2852cdf0e10cSrcweir 
2853cdf0e10cSrcweir 
2854