Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "hintids.hxx"
22 : #include <editeng/lrspitem.hxx>
23 : #include <editeng/boxitem.hxx>
24 : #include <editeng/brshitem.hxx>
25 : #include <editeng/frmdiritem.hxx>
26 : #include <fmtornt.hxx>
27 : #include <fmtfsize.hxx>
28 : #include <fmtlsplt.hxx>
29 : #include <fmtrowsplt.hxx>
30 : #include <tabcol.hxx>
31 : #include <frmatr.hxx>
32 : #include <cellfrm.hxx>
33 : #include <tabfrm.hxx>
34 : #include <cntfrm.hxx>
35 : #include <txtfrm.hxx>
36 : #include <svx/svxids.hrc>
37 : #include <doc.hxx>
38 : #include <IDocumentUndoRedo.hxx>
39 : #include "pam.hxx"
40 : #include "swcrsr.hxx"
41 : #include "viscrs.hxx"
42 : #include "swtable.hxx"
43 : #include "htmltbl.hxx"
44 : #include "tblsel.hxx"
45 : #include "swtblfmt.hxx"
46 : #include "docary.hxx"
47 : #include "ndindex.hxx"
48 : #include "undobj.hxx"
49 : #include "switerator.hxx"
50 : #include <UndoTable.hxx>
51 : #include <boost/foreach.hpp>
52 :
53 : using ::editeng::SvxBorderLine;
54 : using namespace ::com::sun::star;
55 :
56 :
57 : extern void ClearFEShellTabCols();
58 :
59 : //siehe auch swtable.cxx
60 : #define COLFUZZY 20L
61 :
62 9 : inline bool IsSame( long nA, long nB ) { return Abs(nA-nB) <= COLFUZZY; }
63 :
64 : class SwTblFmtCmp
65 : {
66 : public:
67 : SwFrmFmt *pOld,
68 : *pNew;
69 : sal_Int16 nType;
70 :
71 : SwTblFmtCmp( SwFrmFmt *pOld, SwFrmFmt *pNew, sal_Int16 nType );
72 :
73 : static SwFrmFmt *FindNewFmt( std::vector<SwTblFmtCmp*> &rArr, SwFrmFmt*pOld, sal_Int16 nType );
74 : static void Delete( std::vector<SwTblFmtCmp*> &rArr );
75 : };
76 :
77 :
78 0 : SwTblFmtCmp::SwTblFmtCmp( SwFrmFmt *pO, SwFrmFmt *pN, sal_Int16 nT )
79 0 : : pOld ( pO ), pNew ( pN ), nType( nT )
80 : {
81 0 : }
82 :
83 0 : SwFrmFmt *SwTblFmtCmp::FindNewFmt( std::vector<SwTblFmtCmp*> &rArr, SwFrmFmt *pOld, sal_Int16 nType )
84 : {
85 0 : for ( sal_uInt16 i = 0; i < rArr.size(); ++i )
86 : {
87 0 : SwTblFmtCmp *pCmp = rArr[i];
88 0 : if ( pCmp->pOld == pOld && pCmp->nType == nType )
89 0 : return pCmp->pNew;
90 : }
91 0 : return 0;
92 : }
93 :
94 0 : void SwTblFmtCmp::Delete( std::vector<SwTblFmtCmp*> &rArr )
95 : {
96 0 : for ( sal_uInt16 i = 0; i < rArr.size(); ++i )
97 0 : delete rArr[i];
98 0 : }
99 :
100 11 : static void lcl_GetStartEndCell( const SwCursor& rCrsr,
101 : SwLayoutFrm *&prStart, SwLayoutFrm *&prEnd )
102 : {
103 : OSL_ENSURE( rCrsr.GetCntntNode() && rCrsr.GetCntntNode( sal_False ),
104 : "Tabselection nicht auf Cnt." );
105 :
106 11 : Point aPtPos, aMkPos;
107 11 : const SwShellCrsr* pShCrsr = dynamic_cast<const SwShellCrsr*>(&rCrsr);
108 11 : if( pShCrsr )
109 : {
110 9 : aPtPos = pShCrsr->GetPtPos();
111 9 : aMkPos = pShCrsr->GetMkPos();
112 : }
113 :
114 : // robust:
115 11 : SwCntntNode* pPointNd = rCrsr.GetCntntNode();
116 11 : SwCntntNode* pMarkNd = rCrsr.GetCntntNode(sal_False);
117 :
118 11 : SwFrm* pPointFrm = pPointNd ? pPointNd->getLayoutFrm( pPointNd->GetDoc()->GetCurrentLayout(), &aPtPos ) : 0;
119 11 : SwFrm* pMarkFrm = pMarkNd ? pMarkNd->getLayoutFrm( pMarkNd->GetDoc()->GetCurrentLayout(), &aMkPos ) : 0;
120 :
121 11 : prStart = pPointFrm ? pPointFrm->GetUpper() : 0;
122 11 : prEnd = pMarkFrm ? pMarkFrm->GetUpper() : 0;
123 11 : }
124 :
125 0 : static bool lcl_GetBoxSel( const SwCursor& rCursor, SwSelBoxes& rBoxes,
126 : bool bAllCrsr = false )
127 : {
128 : const SwTableCursor* pTblCrsr =
129 0 : dynamic_cast<const SwTableCursor*>(&rCursor);
130 0 : if( pTblCrsr )
131 0 : ::GetTblSelCrs( *pTblCrsr, rBoxes );
132 : else
133 : {
134 0 : const SwPaM *pCurPam = &rCursor, *pSttPam = pCurPam;
135 0 : do {
136 0 : const SwNode* pNd = pCurPam->GetNode()->FindTableBoxStartNode();
137 0 : if( pNd )
138 : {
139 0 : SwTableBox* pBox = (SwTableBox*)pNd->FindTableNode()->GetTable().
140 0 : GetTblBox( pNd->GetIndex() );
141 0 : rBoxes.insert( pBox );
142 : }
143 : } while( bAllCrsr &&
144 0 : pSttPam != ( pCurPam = (SwPaM*)pCurPam->GetNext()) );
145 : }
146 0 : return !rBoxes.empty();
147 : }
148 :
149 : /***********************************************************************
150 : #* Class : SwDoc
151 : #* Methoden : SetRowHeight(), GetRowHeight()
152 : #***********************************************************************/
153 : //Die Zeilenhoehe wird ausgehend von der Selektion ermittelt/gesetzt.
154 : //Ausgehend von jeder Zelle innerhalb der Selektion werden nach oben alle
155 : //Zeilen abgeklappert, die oberste Zeile erhaelt den gewuenschten Wert alle
156 : //tieferliegenden Zeilen einen entsprechenden Wert der sich aus der
157 : //Relation der alten und neuen Groesse der obersten Zeile und ihrer
158 : //eigenen Groesse ergiebt.
159 : //Alle veraenderten Zeilen erhalten ggf. ein eigenes FrmFmt.
160 : //Natuerlich darf jede Zeile nur einmal angefasst werden.
161 :
162 0 : inline void InsertLine( std::vector<SwTableLine*>& rLineArr, SwTableLine* pLine )
163 : {
164 0 : if( rLineArr.end() == std::find( rLineArr.begin(), rLineArr.end(), pLine ) )
165 0 : rLineArr.push_back( pLine );
166 0 : }
167 :
168 : //-----------------------------------------------------------------------------
169 :
170 0 : static bool lcl_IsAnLower( const SwTableLine *pLine, const SwTableLine *pAssumed )
171 : {
172 0 : const SwTableLine *pTmp = pAssumed->GetUpper() ?
173 0 : pAssumed->GetUpper()->GetUpper() : 0;
174 0 : while ( pTmp )
175 : {
176 0 : if ( pTmp == pLine )
177 0 : return true;
178 0 : pTmp = pTmp->GetUpper() ? pTmp->GetUpper()->GetUpper() : 0;
179 : }
180 0 : return false;
181 : }
182 : //-----------------------------------------------------------------------------
183 :
184 : struct LinesAndTable
185 : {
186 : std::vector<SwTableLine*> &rLines;
187 : const SwTable &rTable;
188 : bool bInsertLines;
189 :
190 0 : LinesAndTable( std::vector<SwTableLine*> &rL, const SwTable &rTbl ) :
191 0 : rLines( rL ), rTable( rTbl ), bInsertLines( true ) {}
192 : };
193 :
194 :
195 : bool _FindLine( _FndLine & rLine, LinesAndTable* pPara );
196 :
197 0 : bool _FindBox( _FndBox & rBox, LinesAndTable* pPara )
198 : {
199 0 : if (!rBox.GetLines().empty())
200 : {
201 0 : pPara->bInsertLines = sal_True;
202 0 : BOOST_FOREACH( _FndLine & rFndLine, rBox.GetLines() )
203 0 : _FindLine( rFndLine, pPara );
204 0 : if ( pPara->bInsertLines )
205 : {
206 0 : const SwTableLines &rLines = (rBox.GetBox())
207 0 : ? rBox.GetBox()->GetTabLines()
208 0 : : pPara->rTable.GetTabLines();
209 0 : if (rBox.GetLines().size() == rLines.size())
210 : {
211 0 : for ( sal_uInt16 i = 0; i < rLines.size(); ++i )
212 : ::InsertLine( pPara->rLines,
213 0 : (SwTableLine*)rLines[i] );
214 : }
215 : else
216 0 : pPara->bInsertLines = sal_False;
217 : }
218 : }
219 0 : else if (rBox.GetBox())
220 : {
221 : ::InsertLine( pPara->rLines,
222 0 : static_cast<SwTableLine*>(rBox.GetBox()->GetUpper()));
223 : }
224 0 : return true;
225 : }
226 :
227 0 : bool _FindLine( _FndLine& rLine, LinesAndTable* pPara )
228 : {
229 0 : for (_FndBoxes::iterator it = rLine.GetBoxes().begin();
230 0 : it != rLine.GetBoxes().end(); ++it)
231 : {
232 0 : _FindBox(*it, pPara);
233 : }
234 0 : return true;
235 : }
236 :
237 0 : static void lcl_CollectLines( std::vector<SwTableLine*> &rArr, const SwCursor& rCursor, bool bRemoveLines )
238 : {
239 : //Zuerst die selektierten Boxen einsammeln.
240 0 : SwSelBoxes aBoxes;
241 0 : if( !::lcl_GetBoxSel( rCursor, aBoxes ))
242 0 : return ;
243 :
244 : //Die selektierte Struktur kopieren.
245 0 : const SwTable &rTable = aBoxes[0]->GetSttNd()->FindTableNode()->GetTable();
246 0 : LinesAndTable aPara( rArr, rTable );
247 0 : _FndBox aFndBox( 0, 0 );
248 : {
249 0 : _FndPara aTmpPara( aBoxes, &aFndBox );
250 0 : ForEach_FndLineCopyCol( (SwTableLines&)rTable.GetTabLines(), &aTmpPara );
251 : }
252 :
253 : //Diejenigen Lines einsammeln, die nur selektierte Boxen enthalten.
254 0 : ::_FindBox(aFndBox, &aPara);
255 :
256 : // Remove lines, that have a common superordinate row.
257 : // (Not for row split)
258 0 : if ( bRemoveLines )
259 : {
260 0 : for ( sal_uInt16 i = 0; i < rArr.size(); ++i )
261 : {
262 0 : SwTableLine *pUpLine = rArr[i];
263 0 : for ( sal_uInt16 k = 0; k < rArr.size(); ++k )
264 : {
265 0 : if ( k != i && ::lcl_IsAnLower( pUpLine, rArr[k] ) )
266 : {
267 0 : rArr.erase( rArr.begin() + k );
268 0 : if ( k <= i )
269 0 : --i;
270 0 : --k;
271 : }
272 : }
273 : }
274 0 : }
275 : }
276 :
277 : //-----------------------------------------------------------------------------
278 :
279 0 : static void lcl_ProcessRowAttr( std::vector<SwTblFmtCmp*>& rFmtCmp, SwTableLine* pLine, const SfxPoolItem& rNew )
280 : {
281 : SwFrmFmt *pNewFmt;
282 0 : if ( 0 != (pNewFmt = SwTblFmtCmp::FindNewFmt( rFmtCmp, pLine->GetFrmFmt(), 0 )))
283 0 : pLine->ChgFrmFmt( (SwTableLineFmt*)pNewFmt );
284 : else
285 : {
286 0 : SwFrmFmt *pOld = pLine->GetFrmFmt();
287 0 : SwFrmFmt *pNew = pLine->ClaimFrmFmt();
288 0 : pNew->SetFmtAttr( rNew );
289 0 : rFmtCmp.push_back( new SwTblFmtCmp( pOld, pNew, 0 ) );
290 : }
291 0 : }
292 :
293 : //-----------------------------------------------------------------------------
294 :
295 : static void lcl_ProcessBoxSize( std::vector<SwTblFmtCmp*> &rFmtCmp, SwTableBox *pBox, const SwFmtFrmSize &rNew );
296 :
297 0 : static void lcl_ProcessRowSize( std::vector<SwTblFmtCmp*> &rFmtCmp, SwTableLine *pLine, const SwFmtFrmSize &rNew )
298 : {
299 0 : lcl_ProcessRowAttr( rFmtCmp, pLine, rNew );
300 0 : SwTableBoxes &rBoxes = pLine->GetTabBoxes();
301 0 : for ( sal_uInt16 i = 0; i < rBoxes.size(); ++i )
302 0 : ::lcl_ProcessBoxSize( rFmtCmp, rBoxes[i], rNew );
303 0 : }
304 :
305 : //-----------------------------------------------------------------------------
306 :
307 0 : static void lcl_ProcessBoxSize( std::vector<SwTblFmtCmp*> &rFmtCmp, SwTableBox *pBox, const SwFmtFrmSize &rNew )
308 : {
309 0 : SwTableLines &rLines = pBox->GetTabLines();
310 0 : if ( !rLines.empty() )
311 : {
312 0 : SwFmtFrmSize aSz( rNew );
313 0 : aSz.SetHeight( rNew.GetHeight() ? rNew.GetHeight() / rLines.size() : 0 );
314 0 : for ( sal_uInt16 i = 0; i < rLines.size(); ++i )
315 0 : ::lcl_ProcessRowSize( rFmtCmp, rLines[i], aSz );
316 : }
317 0 : }
318 :
319 : //-----------------------------------------------------------------------------
320 :
321 : /******************************************************************************
322 : * void SwDoc::SetRowSplit()
323 : ******************************************************************************/
324 0 : void SwDoc::SetRowSplit( const SwCursor& rCursor, const SwFmtRowSplit &rNew )
325 : {
326 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
327 0 : if( pTblNd )
328 : {
329 0 : std::vector<SwTableLine*> aRowArr; //Zum sammeln Lines.
330 0 : ::lcl_CollectLines( aRowArr, rCursor, false );
331 :
332 0 : if( !aRowArr.empty() )
333 : {
334 0 : if (GetIDocumentUndoRedo().DoesUndo())
335 : {
336 0 : GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTbl(*pTblNd));
337 : }
338 :
339 0 : std::vector<SwTblFmtCmp*> aFmtCmp;
340 0 : aFmtCmp.reserve( Max( 255, (int)aRowArr.size() ) );
341 :
342 0 : for( sal_uInt16 i = 0; i < aRowArr.size(); ++i )
343 0 : ::lcl_ProcessRowAttr( aFmtCmp, aRowArr[i], rNew );
344 :
345 0 : SwTblFmtCmp::Delete( aFmtCmp );
346 0 : SetModified();
347 0 : }
348 : }
349 0 : }
350 :
351 :
352 : /******************************************************************************
353 : * SwTwips SwDoc::GetRowSplit() const
354 : ******************************************************************************/
355 0 : void SwDoc::GetRowSplit( const SwCursor& rCursor, SwFmtRowSplit *& rpSz ) const
356 : {
357 0 : rpSz = 0;
358 :
359 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
360 0 : if( pTblNd )
361 : {
362 0 : std::vector<SwTableLine*> aRowArr; //Zum sammeln der Lines.
363 0 : ::lcl_CollectLines( aRowArr, rCursor, false );
364 :
365 0 : if( !aRowArr.empty() )
366 : {
367 0 : rpSz = &(SwFmtRowSplit&)aRowArr[0]->GetFrmFmt()->GetRowSplit();
368 :
369 0 : for ( sal_uInt16 i = 1; i < aRowArr.size() && rpSz; ++i )
370 : {
371 0 : if ( (*rpSz).GetValue() != aRowArr[i]->GetFrmFmt()->GetRowSplit().GetValue() )
372 0 : rpSz = 0;
373 : }
374 0 : if ( rpSz )
375 0 : rpSz = new SwFmtRowSplit( *rpSz );
376 0 : }
377 : }
378 0 : }
379 :
380 :
381 : /******************************************************************************
382 : * void SwDoc::SetRowHeight( SwTwips nNew )
383 : ******************************************************************************/
384 0 : void SwDoc::SetRowHeight( const SwCursor& rCursor, const SwFmtFrmSize &rNew )
385 : {
386 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
387 0 : if( pTblNd )
388 : {
389 0 : std::vector<SwTableLine*> aRowArr; //Zum sammeln Lines.
390 0 : ::lcl_CollectLines( aRowArr, rCursor, true );
391 :
392 0 : if( !aRowArr.empty() )
393 : {
394 0 : if (GetIDocumentUndoRedo().DoesUndo())
395 : {
396 0 : GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTbl(*pTblNd));
397 : }
398 :
399 0 : std::vector<SwTblFmtCmp*> aFmtCmp;
400 0 : aFmtCmp.reserve( Max( 255, (int)aRowArr.size() ) );
401 0 : for ( sal_uInt16 i = 0; i < aRowArr.size(); ++i )
402 0 : ::lcl_ProcessRowSize( aFmtCmp, aRowArr[i], rNew );
403 0 : SwTblFmtCmp::Delete( aFmtCmp );
404 :
405 0 : SetModified();
406 0 : }
407 : }
408 0 : }
409 :
410 :
411 : /******************************************************************************
412 : * SwTwips SwDoc::GetRowHeight() const
413 : ******************************************************************************/
414 0 : void SwDoc::GetRowHeight( const SwCursor& rCursor, SwFmtFrmSize *& rpSz ) const
415 : {
416 0 : rpSz = 0;
417 :
418 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
419 0 : if( pTblNd )
420 : {
421 0 : std::vector<SwTableLine*> aRowArr; //Zum sammeln der Lines.
422 0 : ::lcl_CollectLines( aRowArr, rCursor, true );
423 :
424 0 : if( !aRowArr.empty() )
425 : {
426 0 : rpSz = &(SwFmtFrmSize&)aRowArr[0]->GetFrmFmt()->GetFrmSize();
427 :
428 0 : for ( sal_uInt16 i = 1; i < aRowArr.size() && rpSz; ++i )
429 : {
430 0 : if ( *rpSz != aRowArr[i]->GetFrmFmt()->GetFrmSize() )
431 0 : rpSz = 0;
432 : }
433 0 : if ( rpSz )
434 0 : rpSz = new SwFmtFrmSize( *rpSz );
435 0 : }
436 : }
437 0 : }
438 :
439 0 : sal_Bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, sal_Bool bTstOnly )
440 : {
441 0 : sal_Bool bRet = sal_False;
442 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
443 0 : if( pTblNd )
444 : {
445 0 : std::vector<SwTableLine*> aRowArr; //Zum sammeln der Lines.
446 0 : ::lcl_CollectLines( aRowArr, rCursor, true );
447 :
448 0 : if( 1 < aRowArr.size() )
449 : {
450 0 : if( !bTstOnly )
451 : {
452 0 : long nHeight = 0;
453 : sal_uInt16 i;
454 :
455 0 : for ( i = 0; i < aRowArr.size(); ++i )
456 : {
457 0 : SwIterator<SwFrm,SwFmt> aIter( *aRowArr[i]->GetFrmFmt() );
458 0 : SwFrm* pFrm = aIter.First();
459 0 : while ( pFrm )
460 : {
461 0 : nHeight = Max( nHeight, pFrm->Frm().Height() );
462 0 : pFrm = aIter.Next();
463 : }
464 0 : }
465 0 : SwFmtFrmSize aNew( ATT_MIN_SIZE, 0, nHeight );
466 :
467 0 : if (GetIDocumentUndoRedo().DoesUndo())
468 : {
469 0 : GetIDocumentUndoRedo().AppendUndo(
470 0 : new SwUndoAttrTbl(*pTblNd));
471 : }
472 :
473 0 : std::vector<SwTblFmtCmp*> aFmtCmp;
474 0 : aFmtCmp.reserve( Max( 255, (int)aRowArr.size() ) );
475 0 : for( i = 0; i < aRowArr.size(); ++i )
476 0 : ::lcl_ProcessRowSize( aFmtCmp, (SwTableLine*)aRowArr[i], aNew );
477 0 : SwTblFmtCmp::Delete( aFmtCmp );
478 :
479 0 : SetModified();
480 : }
481 0 : bRet = sal_True;
482 0 : }
483 : }
484 0 : return bRet;
485 : }
486 :
487 : /******************************************************************************
488 : * void SwDoc::SetRowBackground()
489 : ******************************************************************************/
490 0 : void SwDoc::SetRowBackground( const SwCursor& rCursor, const SvxBrushItem &rNew )
491 : {
492 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
493 0 : if( pTblNd )
494 : {
495 0 : std::vector<SwTableLine*> aRowArr; //Zum sammeln Lines.
496 0 : ::lcl_CollectLines( aRowArr, rCursor, true );
497 :
498 0 : if( !aRowArr.empty() )
499 : {
500 0 : if (GetIDocumentUndoRedo().DoesUndo())
501 : {
502 0 : GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTbl(*pTblNd));
503 : }
504 :
505 0 : std::vector<SwTblFmtCmp*> aFmtCmp;
506 0 : aFmtCmp.reserve( Max( 255, (int)aRowArr.size() ) );
507 :
508 0 : for( sal_uInt16 i = 0; i < aRowArr.size(); ++i )
509 0 : ::lcl_ProcessRowAttr( aFmtCmp, aRowArr[i], rNew );
510 :
511 0 : SwTblFmtCmp::Delete( aFmtCmp );
512 0 : SetModified();
513 0 : }
514 : }
515 0 : }
516 :
517 : /******************************************************************************
518 : * SwTwips SwDoc::GetRowBackground() const
519 : ******************************************************************************/
520 0 : sal_Bool SwDoc::GetRowBackground( const SwCursor& rCursor, SvxBrushItem &rToFill ) const
521 : {
522 0 : sal_Bool bRet = sal_False;
523 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
524 0 : if( pTblNd )
525 : {
526 0 : std::vector<SwTableLine*> aRowArr; //Zum sammeln Lines.
527 0 : ::lcl_CollectLines( aRowArr, rCursor, true );
528 :
529 0 : if( !aRowArr.empty() )
530 : {
531 0 : rToFill = aRowArr[0]->GetFrmFmt()->GetBackground();
532 :
533 0 : bRet = sal_True;
534 0 : for ( sal_uInt16 i = 1; i < aRowArr.size(); ++i )
535 0 : if ( rToFill != aRowArr[i]->GetFrmFmt()->GetBackground() )
536 : {
537 0 : bRet = sal_False;
538 0 : break;
539 : }
540 0 : }
541 : }
542 0 : return bRet;
543 : }
544 :
545 : /***********************************************************************
546 : #* Class : SwDoc
547 : #* Methoden : SetTabBorders(), GetTabBorders()
548 : #***********************************************************************/
549 14 : inline void InsertCell( std::vector<SwCellFrm*>& rCellArr, SwCellFrm* pCellFrm )
550 : {
551 14 : if( rCellArr.end() == std::find( rCellArr.begin(), rCellArr.end(), pCellFrm ) )
552 14 : rCellArr.push_back( pCellFrm );
553 14 : }
554 :
555 : //-----------------------------------------------------------------------------
556 11 : static void lcl_CollectCells( std::vector<SwCellFrm*> &rArr, const SwRect &rUnion,
557 : SwTabFrm *pTab )
558 : {
559 11 : SwLayoutFrm *pCell = pTab->FirstCell();
560 41 : do
561 : {
562 : // Wenn in der Zelle ein spaltiger Bereich sitzt, muessen wir
563 : // uns erst wieder zur Zelle hochhangeln
564 52 : while ( !pCell->IsCellFrm() )
565 0 : pCell = pCell->GetUpper();
566 : OSL_ENSURE( pCell, "Frame ist keine Zelle." );
567 26 : if ( rUnion.IsOver( pCell->Frm() ) )
568 14 : ::InsertCell( rArr, (SwCellFrm*)pCell );
569 : //Dafuer sorgen, dass die Zelle auch verlassen wird (Bereiche)
570 26 : SwLayoutFrm *pTmp = pCell;
571 26 : do
572 26 : { pTmp = pTmp->GetNextLayoutLeaf();
573 26 : } while ( pCell->IsAnLower( pTmp ) );
574 26 : pCell = pTmp;
575 15 : } while( pCell && pTab->IsAnLower( pCell ) );
576 11 : }
577 :
578 0 : void SwDoc::SetTabBorders( const SwCursor& rCursor, const SfxItemSet& rSet )
579 : {
580 0 : SwCntntNode* pCntNd = rCursor.GetPoint()->nNode.GetNode().GetCntntNode();
581 0 : SwTableNode* pTblNd = pCntNd ? pCntNd->FindTableNode() : 0;
582 0 : if( !pTblNd )
583 0 : return ;
584 :
585 : SwLayoutFrm *pStart, *pEnd;
586 0 : ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
587 :
588 0 : SwSelUnions aUnions;
589 0 : ::MakeSelUnions( aUnions, pStart, pEnd );
590 :
591 0 : if( !aUnions.empty() )
592 : {
593 0 : SwTable& rTable = pTblNd->GetTable();
594 0 : if (GetIDocumentUndoRedo().DoesUndo())
595 : {
596 0 : GetIDocumentUndoRedo().AppendUndo( new SwUndoAttrTbl(*pTblNd) );
597 : }
598 :
599 0 : std::vector<SwTblFmtCmp*> aFmtCmp;
600 0 : aFmtCmp.reserve( 255 );
601 : const SvxBoxItem* pSetBox;
602 : const SvxBoxInfoItem *pSetBoxInfo;
603 :
604 0 : const SvxBorderLine* pLeft = 0;
605 0 : const SvxBorderLine* pRight = 0;
606 0 : const SvxBorderLine* pTop = 0;
607 0 : const SvxBorderLine* pBottom = 0;
608 0 : const SvxBorderLine* pHori = 0;
609 0 : const SvxBorderLine* pVert = 0;
610 0 : sal_Bool bHoriValid = sal_True, bVertValid = sal_True,
611 0 : bTopValid = sal_True, bBottomValid = sal_True,
612 0 : bLeftValid = sal_True, bRightValid = sal_True;
613 :
614 : // JP 21.07.95: die Flags im BoxInfo-Item entscheiden, wann eine
615 : // BorderLine gueltig ist!!
616 0 : if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER, sal_False,
617 0 : (const SfxPoolItem**)&pSetBoxInfo) )
618 : {
619 0 : pHori = pSetBoxInfo->GetHori();
620 0 : pVert = pSetBoxInfo->GetVert();
621 :
622 0 : bHoriValid = pSetBoxInfo->IsValid(VALID_HORI);
623 0 : bVertValid = pSetBoxInfo->IsValid(VALID_VERT);
624 :
625 : // wollen wir die auswerten ??
626 0 : bTopValid = pSetBoxInfo->IsValid(VALID_TOP);
627 0 : bBottomValid = pSetBoxInfo->IsValid(VALID_BOTTOM);
628 0 : bLeftValid = pSetBoxInfo->IsValid(VALID_LEFT);
629 0 : bRightValid = pSetBoxInfo->IsValid(VALID_RIGHT);
630 : }
631 :
632 0 : if( SFX_ITEM_SET == rSet.GetItemState( RES_BOX, sal_False,
633 0 : (const SfxPoolItem**)&pSetBox) )
634 : {
635 0 : pLeft = pSetBox->GetLeft();
636 0 : pRight = pSetBox->GetRight();
637 0 : pTop = pSetBox->GetTop();
638 0 : pBottom = pSetBox->GetBottom();
639 : }
640 : else
641 : {
642 : // nicht gesetzt, also keine gueltigen Werte
643 0 : bTopValid = bBottomValid = bLeftValid = bRightValid = sal_False;
644 0 : pSetBox = 0;
645 : }
646 :
647 0 : bool bFirst = true;
648 0 : for ( sal_uInt16 i = 0; i < aUnions.size(); ++i )
649 : {
650 0 : SwSelUnion *pUnion = &aUnions[i];
651 0 : SwTabFrm *pTab = pUnion->GetTable();
652 0 : const SwRect &rUnion = pUnion->GetUnion();
653 0 : const bool bLast = (i == aUnions.size() - 1);
654 :
655 0 : std::vector<SwCellFrm*> aCellArr;
656 0 : aCellArr.reserve( 255 );
657 0 : ::lcl_CollectCells( aCellArr, pUnion->GetUnion(), pTab );
658 :
659 : //Alle Zellenkanten, die mit dem UnionRect uebereinstimmen oder
660 : //darueber hinausragen sind Aussenkanten. Alle anderen sind
661 : //Innenkanten.
662 : //neu: Die Aussenkanten koennen abhaengig davon, ob es sich um eine
663 : //Start/Mittlere/Folge -Tabelle (bei Selektionen ueber FollowTabs)
664 : //handelt doch keine Aussenkanten sein.
665 : //Aussenkanten werden links, rechts, oben und unten gesetzt.
666 : //Innenkanten werden nur oben und links gesetzt.
667 0 : for ( sal_uInt16 j = 0; j < aCellArr.size(); ++j )
668 : {
669 0 : SwCellFrm *pCell = aCellArr[j];
670 0 : const sal_Bool bVert = pTab->IsVertical();
671 0 : const sal_Bool bRTL = pTab->IsRightToLeft();
672 : sal_Bool bTopOver, bLeftOver, bRightOver, bBottomOver;
673 0 : if ( bVert )
674 : {
675 0 : bTopOver = pCell->Frm().Right() >= rUnion.Right();
676 0 : bLeftOver = pCell->Frm().Top() <= rUnion.Top();
677 0 : bRightOver = pCell->Frm().Bottom() >= rUnion.Bottom();
678 0 : bBottomOver = pCell->Frm().Left() <= rUnion.Left();
679 : }
680 : else
681 : {
682 0 : bTopOver = pCell->Frm().Top() <= rUnion.Top();
683 0 : bLeftOver = pCell->Frm().Left() <= rUnion.Left();
684 0 : bRightOver = pCell->Frm().Right() >= rUnion.Right();
685 0 : bBottomOver = pCell->Frm().Bottom() >= rUnion.Bottom();
686 : }
687 :
688 0 : if ( bRTL )
689 : {
690 0 : sal_Bool bTmp = bRightOver;
691 0 : bRightOver = bLeftOver;
692 0 : bLeftOver = bTmp;
693 : }
694 :
695 : //Grundsaetzlich nichts setzen in HeadlineRepeats.
696 0 : if ( pTab->IsFollow() &&
697 0 : ( pTab->IsInHeadline( *pCell ) ||
698 : // Same holds for follow flow rows.
699 0 : pCell->IsInFollowFlowRow() ) )
700 0 : continue;
701 :
702 0 : SvxBoxItem aBox( pCell->GetFmt()->GetBox() );
703 :
704 0 : sal_Int16 nType = 0;
705 :
706 : //Obere Kante
707 0 : if( bTopValid )
708 : {
709 0 : if ( bFirst && bTopOver )
710 : {
711 0 : aBox.SetLine( pTop, BOX_LINE_TOP );
712 0 : nType |= 0x0001;
713 : }
714 0 : else if ( bHoriValid )
715 : {
716 0 : aBox.SetLine( 0, BOX_LINE_TOP );
717 0 : nType |= 0x0002;
718 : }
719 : }
720 :
721 : //Linke Kante
722 0 : if ( bLeftOver )
723 : {
724 0 : if( bLeftValid )
725 : {
726 0 : aBox.SetLine( pLeft, BOX_LINE_LEFT );
727 0 : nType |= 0x0004;
728 : }
729 : }
730 0 : else if( bVertValid )
731 : {
732 0 : aBox.SetLine( pVert, BOX_LINE_LEFT );
733 0 : nType |= 0x0008;
734 : }
735 :
736 : //Rechte Kante
737 0 : if( bRightValid )
738 : {
739 0 : if ( bRightOver )
740 : {
741 0 : aBox.SetLine( pRight, BOX_LINE_RIGHT );
742 0 : nType |= 0x0010;
743 : }
744 0 : else if ( bVertValid )
745 : {
746 0 : aBox.SetLine( 0, BOX_LINE_RIGHT );
747 0 : nType |= 0x0020;
748 : }
749 : }
750 :
751 : //Untere Kante
752 0 : if ( bLast && bBottomOver )
753 : {
754 0 : if( bBottomValid )
755 : {
756 0 : aBox.SetLine( pBottom, BOX_LINE_BOTTOM );
757 0 : nType |= 0x0040;
758 : }
759 : }
760 0 : else if( bHoriValid )
761 : {
762 0 : aBox.SetLine( pHori, BOX_LINE_BOTTOM );
763 0 : nType |= 0x0080;
764 : }
765 :
766 0 : if( pSetBox )
767 : {
768 : static sal_uInt16 const aBorders[] = {
769 : BOX_LINE_BOTTOM, BOX_LINE_TOP,
770 : BOX_LINE_RIGHT, BOX_LINE_LEFT };
771 0 : const sal_uInt16* pBrd = aBorders;
772 0 : for( int k = 0; k < 4; ++k, ++pBrd )
773 0 : aBox.SetDistance( pSetBox->GetDistance( *pBrd ), *pBrd );
774 : }
775 :
776 0 : SwTableBox *pBox = (SwTableBox*)pCell->GetTabBox();
777 : SwFrmFmt *pNewFmt;
778 0 : if ( 0 != (pNewFmt = SwTblFmtCmp::FindNewFmt( aFmtCmp, pBox->GetFrmFmt(), nType )))
779 0 : pBox->ChgFrmFmt( (SwTableBoxFmt*)pNewFmt );
780 : else
781 : {
782 0 : SwFrmFmt *pOld = pBox->GetFrmFmt();
783 0 : SwFrmFmt *pNew = pBox->ClaimFrmFmt();
784 0 : pNew->SetFmtAttr( aBox );
785 0 : aFmtCmp.push_back( new SwTblFmtCmp( pOld, pNew, nType ) );
786 : }
787 0 : }
788 :
789 0 : bFirst = false;
790 0 : }
791 :
792 0 : SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
793 0 : if( pTableLayout )
794 : {
795 0 : SwCntntFrm* pFrm = rCursor.GetCntntNode()->getLayoutFrm( rCursor.GetCntntNode()->GetDoc()->GetCurrentLayout() );
796 0 : SwTabFrm* pTabFrm = pFrm->ImplFindTabFrm();
797 :
798 : pTableLayout->BordersChanged(
799 0 : pTableLayout->GetBrowseWidthByTabFrm( *pTabFrm ), sal_True );
800 : }
801 0 : SwTblFmtCmp::Delete( aFmtCmp );
802 0 : ::ClearFEShellTabCols();
803 0 : SetModified();
804 0 : }
805 : }
806 :
807 0 : static void lcl_SetLineStyle( SvxBorderLine *pToSet,
808 : const Color *pColor, const SvxBorderLine *pBorderLine)
809 : {
810 0 : if ( pBorderLine )
811 : {
812 0 : if ( !pColor )
813 : {
814 0 : Color aTmp( pToSet->GetColor() );
815 0 : *pToSet = *pBorderLine;
816 0 : pToSet->SetColor( aTmp );
817 : }
818 : else
819 0 : *pToSet = *pBorderLine;
820 : }
821 0 : if ( pColor )
822 0 : pToSet->SetColor( *pColor );
823 0 : }
824 :
825 0 : void SwDoc::SetTabLineStyle( const SwCursor& rCursor,
826 : const Color* pColor, sal_Bool bSetLine,
827 : const SvxBorderLine* pBorderLine )
828 : {
829 0 : SwCntntNode* pCntNd = rCursor.GetPoint()->nNode.GetNode().GetCntntNode();
830 0 : SwTableNode* pTblNd = pCntNd ? pCntNd->FindTableNode() : 0;
831 0 : if( !pTblNd )
832 0 : return ;
833 :
834 : SwLayoutFrm *pStart, *pEnd;
835 0 : ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
836 :
837 0 : SwSelUnions aUnions;
838 0 : ::MakeSelUnions( aUnions, pStart, pEnd );
839 :
840 0 : if( !aUnions.empty() )
841 : {
842 0 : SwTable& rTable = pTblNd->GetTable();
843 0 : if (GetIDocumentUndoRedo().DoesUndo())
844 : {
845 0 : GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTbl(*pTblNd));
846 : }
847 :
848 0 : for( sal_uInt16 i = 0; i < aUnions.size(); ++i )
849 : {
850 0 : SwSelUnion *pUnion = &aUnions[i];
851 0 : SwTabFrm *pTab = pUnion->GetTable();
852 0 : std::vector<SwCellFrm*> aCellArr;
853 0 : aCellArr.reserve( 255 );
854 0 : ::lcl_CollectCells( aCellArr, pUnion->GetUnion(), pTab );
855 :
856 0 : for ( sal_uInt16 j = 0; j < aCellArr.size(); ++j )
857 : {
858 0 : SwCellFrm *pCell = aCellArr[j];
859 :
860 : //Grundsaetzlich nichts setzen in HeadlineRepeats.
861 0 : if ( pTab->IsFollow() && pTab->IsInHeadline( *pCell ) )
862 0 : continue;
863 :
864 0 : ((SwTableBox*)pCell->GetTabBox())->ClaimFrmFmt();
865 0 : SwFrmFmt *pFmt = pCell->GetFmt();
866 0 : SvxBoxItem aBox( pFmt->GetBox() );
867 :
868 0 : if ( !pBorderLine && bSetLine )
869 0 : aBox = *(SvxBoxItem*)::GetDfltAttr( RES_BOX );
870 : else
871 : {
872 0 : if ( aBox.GetTop() )
873 0 : ::lcl_SetLineStyle( (SvxBorderLine*)aBox.GetTop(),
874 0 : pColor, pBorderLine );
875 0 : if ( aBox.GetBottom() )
876 0 : ::lcl_SetLineStyle( (SvxBorderLine*)aBox.GetBottom(),
877 0 : pColor, pBorderLine );
878 0 : if ( aBox.GetLeft() )
879 0 : ::lcl_SetLineStyle( (SvxBorderLine*)aBox.GetLeft(),
880 0 : pColor, pBorderLine );
881 0 : if ( aBox.GetRight() )
882 0 : ::lcl_SetLineStyle( (SvxBorderLine*)aBox.GetRight(),
883 0 : pColor, pBorderLine );
884 : }
885 0 : pFmt->SetFmtAttr( aBox );
886 0 : }
887 0 : }
888 :
889 0 : SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
890 0 : if( pTableLayout )
891 : {
892 0 : SwCntntFrm* pFrm = rCursor.GetCntntNode()->getLayoutFrm( rCursor.GetCntntNode()->GetDoc()->GetCurrentLayout() );
893 0 : SwTabFrm* pTabFrm = pFrm->ImplFindTabFrm();
894 :
895 : pTableLayout->BordersChanged(
896 0 : pTableLayout->GetBrowseWidthByTabFrm( *pTabFrm ), sal_True );
897 : }
898 0 : ::ClearFEShellTabCols();
899 0 : SetModified();
900 0 : }
901 : }
902 :
903 11 : void SwDoc::GetTabBorders( const SwCursor& rCursor, SfxItemSet& rSet ) const
904 : {
905 11 : SwCntntNode* pCntNd = rCursor.GetPoint()->nNode.GetNode().GetCntntNode();
906 11 : SwTableNode* pTblNd = pCntNd ? pCntNd->FindTableNode() : 0;
907 11 : if( !pTblNd )
908 11 : return ;
909 :
910 : SwLayoutFrm *pStart, *pEnd;
911 11 : ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
912 :
913 11 : SwSelUnions aUnions;
914 11 : ::MakeSelUnions( aUnions, pStart, pEnd );
915 :
916 11 : if( !aUnions.empty() )
917 : {
918 11 : SvxBoxItem aSetBox ((const SvxBoxItem &) rSet.Get(RES_BOX ));
919 11 : SvxBoxInfoItem aSetBoxInfo((const SvxBoxInfoItem&) rSet.Get(SID_ATTR_BORDER_INNER));
920 :
921 11 : sal_Bool bTopSet = sal_False,
922 11 : bBottomSet = sal_False,
923 11 : bLeftSet = sal_False,
924 11 : bRightSet = sal_False,
925 11 : bHoriSet = sal_False,
926 11 : bVertSet = sal_False,
927 11 : bDistanceSet = sal_False;
928 :
929 11 : aSetBoxInfo.ResetFlags();
930 :
931 22 : for ( sal_uInt16 i = 0; i < aUnions.size(); ++i )
932 : {
933 11 : SwSelUnion *pUnion = &aUnions[i];
934 11 : const SwTabFrm *pTab = pUnion->GetTable();
935 11 : const SwRect &rUnion = pUnion->GetUnion();
936 11 : const bool bFirst = i == 0;
937 11 : const bool bLast = (i == aUnions.size() - 1);
938 :
939 11 : std::vector<SwCellFrm*> aCellArr;
940 11 : aCellArr.reserve(255);
941 11 : ::lcl_CollectCells( aCellArr, rUnion, (SwTabFrm*)pTab );
942 :
943 25 : for ( sal_uInt16 j = 0; j < aCellArr.size(); ++j )
944 : {
945 14 : SwCellFrm *pCell = aCellArr[j];
946 14 : const sal_Bool bVert = pTab->IsVertical();
947 14 : const sal_Bool bRTL = pTab->IsRightToLeft();
948 : sal_Bool bTopOver, bLeftOver, bRightOver, bBottomOver;
949 14 : if ( bVert )
950 : {
951 0 : bTopOver = pCell->Frm().Right() >= rUnion.Right();
952 0 : bLeftOver = pCell->Frm().Top() <= rUnion.Top();
953 0 : bRightOver = pCell->Frm().Bottom() >= rUnion.Bottom();
954 0 : bBottomOver = pCell->Frm().Left() <= rUnion.Left();
955 : }
956 : else
957 : {
958 14 : bTopOver = pCell->Frm().Top() <= rUnion.Top();
959 14 : bLeftOver = pCell->Frm().Left() <= rUnion.Left();
960 14 : bRightOver = pCell->Frm().Right() >= rUnion.Right();
961 14 : bBottomOver = pCell->Frm().Bottom() >= rUnion.Bottom();
962 : }
963 :
964 14 : if ( bRTL )
965 : {
966 0 : sal_Bool bTmp = bRightOver;
967 0 : bRightOver = bLeftOver;
968 0 : bLeftOver = bTmp;
969 : }
970 :
971 14 : const SwFrmFmt *pFmt = pCell->GetFmt();
972 14 : const SvxBoxItem &rBox = pFmt->GetBox();
973 :
974 : //Obere Kante
975 14 : if ( bFirst && bTopOver )
976 : {
977 12 : if (aSetBoxInfo.IsValid(VALID_TOP))
978 : {
979 12 : if ( !bTopSet )
980 11 : { bTopSet = sal_True;
981 11 : aSetBox.SetLine( rBox.GetTop(), BOX_LINE_TOP );
982 : }
983 4 : else if ((aSetBox.GetTop() && rBox.GetTop() &&
984 1 : !(*aSetBox.GetTop() == *rBox.GetTop())) ||
985 2 : ((!aSetBox.GetTop()) ^ (!rBox.GetTop()))) // XOR-Ausdruck ist sal_True, wenn genau einer der beiden Pointer 0 ist
986 : {
987 0 : aSetBoxInfo.SetValid(VALID_TOP, sal_False );
988 0 : aSetBox.SetLine( 0, BOX_LINE_TOP );
989 : }
990 : }
991 : }
992 :
993 : //Linke Kante
994 14 : if ( bLeftOver )
995 : {
996 12 : if (aSetBoxInfo.IsValid(VALID_LEFT))
997 : {
998 12 : if ( !bLeftSet )
999 11 : { bLeftSet = sal_True;
1000 11 : aSetBox.SetLine( rBox.GetLeft(), BOX_LINE_LEFT );
1001 : }
1002 4 : else if ((aSetBox.GetLeft() && rBox.GetLeft() &&
1003 1 : !(*aSetBox.GetLeft() == *rBox.GetLeft())) ||
1004 2 : ((!aSetBox.GetLeft()) ^ (!rBox.GetLeft())))
1005 : {
1006 0 : aSetBoxInfo.SetValid(VALID_LEFT, sal_False );
1007 0 : aSetBox.SetLine( 0, BOX_LINE_LEFT );
1008 : }
1009 : }
1010 : }
1011 : else
1012 : {
1013 2 : if (aSetBoxInfo.IsValid(VALID_VERT))
1014 : {
1015 2 : if ( !bVertSet )
1016 1 : { bVertSet = sal_True;
1017 1 : aSetBoxInfo.SetLine( rBox.GetLeft(), BOXINFO_LINE_VERT );
1018 : }
1019 4 : else if ((aSetBoxInfo.GetVert() && rBox.GetLeft() &&
1020 1 : !(*aSetBoxInfo.GetVert() == *rBox.GetLeft())) ||
1021 2 : ((!aSetBoxInfo.GetVert()) ^ (!rBox.GetLeft())))
1022 0 : { aSetBoxInfo.SetValid( VALID_VERT, sal_False );
1023 0 : aSetBoxInfo.SetLine( 0, BOXINFO_LINE_VERT );
1024 : }
1025 : }
1026 : }
1027 :
1028 : //Rechte Kante
1029 14 : if ( aSetBoxInfo.IsValid(VALID_RIGHT) && bRightOver )
1030 : {
1031 12 : if ( !bRightSet )
1032 11 : { bRightSet = sal_True;
1033 11 : aSetBox.SetLine( rBox.GetRight(), BOX_LINE_RIGHT );
1034 : }
1035 4 : else if ((aSetBox.GetRight() && rBox.GetRight() &&
1036 1 : !(*aSetBox.GetRight() == *rBox.GetRight())) ||
1037 2 : (!aSetBox.GetRight() ^ !rBox.GetRight()))
1038 0 : { aSetBoxInfo.SetValid( VALID_RIGHT, sal_False );
1039 0 : aSetBox.SetLine( 0, BOX_LINE_RIGHT );
1040 : }
1041 : }
1042 :
1043 : //Untere Kante
1044 14 : if ( bLast && bBottomOver )
1045 : {
1046 24 : if ( aSetBoxInfo.IsValid(VALID_BOTTOM) )
1047 : {
1048 12 : if ( !bBottomSet )
1049 11 : { bBottomSet = sal_True;
1050 11 : aSetBox.SetLine( rBox.GetBottom(), BOX_LINE_BOTTOM );
1051 : }
1052 4 : else if ((aSetBox.GetBottom() && rBox.GetBottom() &&
1053 1 : !(*aSetBox.GetBottom() == *rBox.GetBottom())) ||
1054 2 : (!aSetBox.GetBottom() ^ !rBox.GetBottom()))
1055 0 : { aSetBoxInfo.SetValid( VALID_BOTTOM, sal_False );
1056 0 : aSetBox.SetLine( 0, BOX_LINE_BOTTOM );
1057 : }
1058 : }
1059 : }
1060 : //in allen Zeilen ausser der letzten werden die
1061 : // horiz. Linien aus der Bottom-Linie entnommen
1062 : else
1063 : {
1064 2 : if (aSetBoxInfo.IsValid(VALID_HORI))
1065 : {
1066 2 : if ( !bHoriSet )
1067 1 : { bHoriSet = sal_True;
1068 1 : aSetBoxInfo.SetLine( rBox.GetBottom(), BOXINFO_LINE_HORI );
1069 : }
1070 4 : else if ((aSetBoxInfo.GetHori() && rBox.GetBottom() &&
1071 1 : !(*aSetBoxInfo.GetHori() == *rBox.GetBottom())) ||
1072 2 : ((!aSetBoxInfo.GetHori()) ^ (!rBox.GetBottom())))
1073 : {
1074 0 : aSetBoxInfo.SetValid( VALID_HORI, sal_False );
1075 0 : aSetBoxInfo.SetLine( 0, BOXINFO_LINE_HORI );
1076 : }
1077 : }
1078 : }
1079 :
1080 : // Abstand zum Text
1081 14 : if (aSetBoxInfo.IsValid(VALID_DISTANCE))
1082 : {
1083 : static sal_uInt16 const aBorders[] = {
1084 : BOX_LINE_BOTTOM, BOX_LINE_TOP,
1085 : BOX_LINE_RIGHT, BOX_LINE_LEFT };
1086 14 : const sal_uInt16* pBrd = aBorders;
1087 :
1088 14 : if( !bDistanceSet ) // bei 1. Durchlauf erstmal setzen
1089 : {
1090 11 : bDistanceSet = sal_True;
1091 55 : for( int k = 0; k < 4; ++k, ++pBrd )
1092 44 : aSetBox.SetDistance( rBox.GetDistance( *pBrd ),
1093 88 : *pBrd );
1094 : }
1095 : else
1096 : {
1097 15 : for( int k = 0; k < 4; ++k, ++pBrd )
1098 24 : if( aSetBox.GetDistance( *pBrd ) !=
1099 12 : rBox.GetDistance( *pBrd ) )
1100 : {
1101 0 : aSetBoxInfo.SetValid( VALID_DISTANCE, sal_False );
1102 0 : aSetBox.SetDistance( (sal_uInt16) 0 );
1103 0 : break;
1104 : }
1105 : }
1106 : }
1107 : }
1108 11 : }
1109 11 : rSet.Put( aSetBox );
1110 11 : rSet.Put( aSetBoxInfo );
1111 11 : }
1112 : }
1113 :
1114 : /***********************************************************************
1115 : #* Class : SwDoc
1116 : #* Methoden : SetBoxAttr
1117 : #***********************************************************************/
1118 0 : void SwDoc::SetBoxAttr( const SwCursor& rCursor, const SfxPoolItem &rNew )
1119 : {
1120 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
1121 0 : SwSelBoxes aBoxes;
1122 0 : if( pTblNd && ::lcl_GetBoxSel( rCursor, aBoxes, true ) )
1123 : {
1124 0 : SwTable& rTable = pTblNd->GetTable();
1125 0 : if (GetIDocumentUndoRedo().DoesUndo())
1126 : {
1127 0 : GetIDocumentUndoRedo().AppendUndo( new SwUndoAttrTbl(*pTblNd) );
1128 : }
1129 :
1130 0 : std::vector<SwTblFmtCmp*> aFmtCmp;
1131 0 : aFmtCmp.reserve(std::max<size_t>(255, aBoxes.size()));
1132 0 : for (size_t i = 0; i < aBoxes.size(); ++i)
1133 : {
1134 0 : SwTableBox *pBox = aBoxes[i];
1135 :
1136 : SwFrmFmt *pNewFmt;
1137 0 : if ( 0 != (pNewFmt = SwTblFmtCmp::FindNewFmt( aFmtCmp, pBox->GetFrmFmt(), 0 )))
1138 0 : pBox->ChgFrmFmt( (SwTableBoxFmt*)pNewFmt );
1139 : else
1140 : {
1141 0 : SwFrmFmt *pOld = pBox->GetFrmFmt();
1142 0 : SwFrmFmt *pNew = pBox->ClaimFrmFmt();
1143 0 : pNew->SetFmtAttr( rNew );
1144 0 : aFmtCmp.push_back( new SwTblFmtCmp( pOld, pNew, 0 ) );
1145 : }
1146 : }
1147 :
1148 0 : SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
1149 0 : if( pTableLayout )
1150 : {
1151 0 : SwCntntFrm* pFrm = rCursor.GetCntntNode()->getLayoutFrm( rCursor.GetCntntNode()->GetDoc()->GetCurrentLayout() );
1152 0 : SwTabFrm* pTabFrm = pFrm->ImplFindTabFrm();
1153 :
1154 : pTableLayout->Resize(
1155 0 : pTableLayout->GetBrowseWidthByTabFrm( *pTabFrm ), sal_True );
1156 : }
1157 0 : SwTblFmtCmp::Delete( aFmtCmp );
1158 0 : SetModified();
1159 0 : }
1160 0 : }
1161 :
1162 : /***********************************************************************
1163 : #* Class : SwDoc
1164 : #* Methoden : GetBoxAttr()
1165 : #***********************************************************************/
1166 :
1167 0 : sal_Bool SwDoc::GetBoxAttr( const SwCursor& rCursor, SfxPoolItem& rToFill ) const
1168 : {
1169 0 : sal_Bool bRet = sal_False;
1170 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
1171 0 : SwSelBoxes aBoxes;
1172 0 : if( pTblNd && lcl_GetBoxSel( rCursor, aBoxes ))
1173 : {
1174 0 : bRet = sal_True;
1175 0 : bool bOneFound = false;
1176 0 : const sal_uInt16 nWhich = rToFill.Which();
1177 0 : for (size_t i = 0; i < aBoxes.size(); ++i)
1178 : {
1179 0 : switch ( nWhich )
1180 : {
1181 : case RES_BACKGROUND:
1182 : {
1183 : const SvxBrushItem &rBack =
1184 0 : aBoxes[i]->GetFrmFmt()->GetBackground();
1185 0 : if( !bOneFound )
1186 : {
1187 0 : (SvxBrushItem&)rToFill = rBack;
1188 0 : bOneFound = true;
1189 : }
1190 0 : else if( rToFill != rBack )
1191 0 : bRet = sal_False;
1192 : }
1193 0 : break;
1194 :
1195 : case RES_FRAMEDIR:
1196 : {
1197 : const SvxFrameDirectionItem& rDir =
1198 0 : aBoxes[i]->GetFrmFmt()->GetFrmDir();
1199 0 : if( !bOneFound )
1200 : {
1201 0 : (SvxFrameDirectionItem&)rToFill = rDir;
1202 0 : bOneFound = true;
1203 : }
1204 0 : else if( rToFill != rDir )
1205 0 : bRet = sal_False;
1206 : }
1207 : }
1208 :
1209 0 : if ( sal_False == bRet )
1210 0 : break;
1211 : }
1212 : }
1213 0 : return bRet;
1214 : }
1215 :
1216 : /***********************************************************************
1217 : #* Class : SwDoc
1218 : #* Methoden : SetBoxAlign, SetBoxAlign
1219 : #***********************************************************************/
1220 0 : void SwDoc::SetBoxAlign( const SwCursor& rCursor, sal_uInt16 nAlign )
1221 : {
1222 : OSL_ENSURE( nAlign == text::VertOrientation::NONE ||
1223 : nAlign == text::VertOrientation::CENTER ||
1224 : nAlign == text::VertOrientation::BOTTOM, "wrong alignment" );
1225 0 : SwFmtVertOrient aVertOri( 0, nAlign );
1226 0 : SetBoxAttr( rCursor, aVertOri );
1227 0 : }
1228 :
1229 0 : sal_uInt16 SwDoc::GetBoxAlign( const SwCursor& rCursor ) const
1230 : {
1231 0 : sal_uInt16 nAlign = USHRT_MAX;
1232 0 : SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
1233 0 : SwSelBoxes aBoxes;
1234 0 : if( pTblNd && ::lcl_GetBoxSel( rCursor, aBoxes ))
1235 : {
1236 0 : for (size_t i = 0; i < aBoxes.size(); ++i)
1237 : {
1238 : const SwFmtVertOrient &rOri =
1239 0 : aBoxes[i]->GetFrmFmt()->GetVertOrient();
1240 0 : if( USHRT_MAX == nAlign )
1241 0 : nAlign = static_cast<sal_uInt16>(rOri.GetVertOrient());
1242 0 : else if( rOri.GetVertOrient() != nAlign )
1243 : {
1244 0 : nAlign = USHRT_MAX;
1245 0 : break;
1246 : }
1247 : }
1248 : }
1249 0 : return nAlign;
1250 : }
1251 :
1252 :
1253 : /***********************************************************************
1254 : #* Class : SwDoc
1255 : #* Methoden : AdjustCellWidth()
1256 : #***********************************************************************/
1257 0 : static sal_uInt16 lcl_CalcCellFit( const SwLayoutFrm *pCell )
1258 : {
1259 0 : SwTwips nRet = 0;
1260 0 : const SwFrm *pFrm = pCell->Lower(); //Die ganze Zelle.
1261 0 : SWRECTFN( pCell )
1262 0 : while ( pFrm )
1263 : {
1264 0 : const SwTwips nAdd = (pFrm->Frm().*fnRect->fnGetWidth)() -
1265 0 : (pFrm->Prt().*fnRect->fnGetWidth)();
1266 :
1267 : // pFrm does not necessarily have to be a SwTxtFrm!
1268 0 : const SwTwips nCalcFitToContent = pFrm->IsTxtFrm() ?
1269 : ((SwTxtFrm*)pFrm)->CalcFitToContent() :
1270 0 : (pFrm->Prt().*fnRect->fnGetWidth)();
1271 :
1272 0 : nRet = Max( nRet, nCalcFitToContent + nAdd );
1273 0 : pFrm = pFrm->GetNext();
1274 : }
1275 : //Umrandung und linker/rechter Rand wollen mit kalkuliert werden.
1276 0 : nRet += (pCell->Frm().*fnRect->fnGetWidth)() -
1277 0 : (pCell->Prt().*fnRect->fnGetWidth)();
1278 :
1279 : //Um Rechenungenauikeiten, die spaeter bei SwTable::SetTabCols enstehen,
1280 : //auszugleichen, addieren wir noch ein bischen.
1281 0 : nRet += COLFUZZY;
1282 0 : return (sal_uInt16)Max( long(MINLAY), nRet );
1283 : }
1284 :
1285 : /*Die Zelle ist in der Selektion, wird aber nicht von den TabCols beschrieben.
1286 : *Das bedeutet, dass die Zelle aufgrund der zweidimensionalen Darstellung von
1287 : *anderen Zellen "geteilt" wurde. Wir muessen also den Wunsch- bzw. Minimalwert
1288 : *der Zelle auf die Spalten, durch die sie geteilt wurde verteilen.
1289 : *
1290 : *Dazu sammeln wir zuerst die Spalten - nicht die Spaltentrenner! - ein, die
1291 : *sich mit der Zelle ueberschneiden. Den Wunschwert der Zelle verteilen wir
1292 : *dann anhand des Betrages der Ueberschneidung auf die Zellen.
1293 : *Wenn eine Zelle bereits einen groesseren Wunschwert angemeldet hat, so bleibt
1294 : *dieser erhalten, kleinere Wuensche werden ueberschrieben.
1295 : */
1296 :
1297 0 : static void lcl_CalcSubColValues( std::vector<sal_uInt16> &rToFill, const SwTabCols &rCols,
1298 : const SwLayoutFrm *pCell, const SwLayoutFrm *pTab,
1299 : sal_Bool bWishValues )
1300 : {
1301 : const sal_uInt16 nWish = bWishValues ?
1302 : ::lcl_CalcCellFit( pCell ) :
1303 0 : MINLAY + sal_uInt16(pCell->Frm().Width() - pCell->Prt().Width());
1304 :
1305 0 : SWRECTFN( pTab )
1306 :
1307 0 : for ( sal_uInt16 i = 0 ; i <= rCols.Count(); ++i )
1308 : {
1309 0 : long nColLeft = i == 0 ? rCols.GetLeft() : rCols[i-1];
1310 0 : long nColRight = i == rCols.Count() ? rCols.GetRight() : rCols[i];
1311 0 : nColLeft += rCols.GetLeftMin();
1312 0 : nColRight += rCols.GetLeftMin();
1313 :
1314 : //Werte auf die Verhaeltnisse der Tabelle (Follows) anpassen.
1315 0 : if ( rCols.GetLeftMin() != sal_uInt16((pTab->Frm().*fnRect->fnGetLeft)()) )
1316 : {
1317 0 : const long nDiff = (pTab->Frm().*fnRect->fnGetLeft)() - rCols.GetLeftMin();
1318 0 : nColLeft += nDiff;
1319 0 : nColRight += nDiff;
1320 : }
1321 0 : const long nCellLeft = (pCell->Frm().*fnRect->fnGetLeft)();
1322 0 : const long nCellRight = (pCell->Frm().*fnRect->fnGetRight)();
1323 :
1324 : //Ueberschneidungsbetrag ermitteln.
1325 0 : long nWidth = 0;
1326 0 : if ( nColLeft <= nCellLeft && nColRight >= (nCellLeft+COLFUZZY) )
1327 0 : nWidth = nColRight - nCellLeft;
1328 0 : else if ( nColLeft <= (nCellRight-COLFUZZY) && nColRight >= nCellRight )
1329 0 : nWidth = nCellRight - nColLeft;
1330 0 : else if ( nColLeft >= nCellLeft && nColRight <= nCellRight )
1331 0 : nWidth = nColRight - nColLeft;
1332 0 : if ( nWidth && pCell->Frm().Width() )
1333 : {
1334 0 : long nTmp = nWidth * nWish / pCell->Frm().Width();
1335 0 : if ( sal_uInt16(nTmp) > rToFill[i] )
1336 0 : rToFill[i] = sal_uInt16(nTmp);
1337 : }
1338 : }
1339 0 : }
1340 :
1341 : /*Besorgt neue Werte zu Einstellung der TabCols.
1342 : *Es wird nicht ueber die Eintrage in den TabCols itereriert, sondern
1343 : *quasi ueber die Zwischenraeume, die ja die Zellen beschreiben.
1344 : *
1345 : *bWishValues == sal_True: Es werden zur aktuellen Selektion bzw. zur aktuellen
1346 : * Zelle die Wunschwerte aller betroffen Zellen ermittelt.
1347 : * Sind mehrere Zellen in einer Spalte, so wird der
1348 : * groesste Wunschwert als Ergebnis geliefert.
1349 : * Fuer die TabCol-Eintraege, zu denen keine Zellen
1350 : * ermittelt wurden, werden 0-en eingetragen.
1351 : *
1352 : *bWishValues == sal_False: Die Selektion wird senkrecht ausgedehnt. Zu jeder
1353 : * Spalte in den TabCols, die sich mit der Selektion
1354 : * schneidet wird der Minimalwert ermittelt.
1355 : */
1356 :
1357 0 : static void lcl_CalcColValues( std::vector<sal_uInt16> &rToFill, const SwTabCols &rCols,
1358 : const SwLayoutFrm *pStart, const SwLayoutFrm *pEnd,
1359 : sal_Bool bWishValues )
1360 : {
1361 0 : SwSelUnions aUnions;
1362 : ::MakeSelUnions( aUnions, pStart, pEnd,
1363 0 : bWishValues ? nsSwTblSearchType::TBLSEARCH_NONE : nsSwTblSearchType::TBLSEARCH_COL );
1364 :
1365 0 : for ( sal_uInt16 i2 = 0; i2 < aUnions.size(); ++i2 )
1366 : {
1367 0 : SwSelUnion *pSelUnion = &aUnions[i2];
1368 0 : const SwTabFrm *pTab = pSelUnion->GetTable();
1369 0 : const SwRect &rUnion = pSelUnion->GetUnion();
1370 :
1371 0 : SWRECTFN( pTab )
1372 0 : sal_Bool bRTL = pTab->IsRightToLeft();
1373 :
1374 0 : const SwLayoutFrm *pCell = pTab->FirstCell();
1375 0 : do
1376 : {
1377 0 : if ( pCell->IsCellFrm() && pCell->FindTabFrm() == pTab && ::IsFrmInTblSel( rUnion, pCell ) )
1378 : {
1379 0 : const long nCLeft = (pCell->Frm().*fnRect->fnGetLeft)();
1380 0 : const long nCRight = (pCell->Frm().*fnRect->fnGetRight)();
1381 :
1382 0 : bool bNotInCols = true;
1383 :
1384 0 : for ( sal_uInt16 i = 0; i <= rCols.Count(); ++i )
1385 : {
1386 0 : sal_uInt16 nFit = rToFill[i];
1387 0 : long nColLeft = i == 0 ? rCols.GetLeft() : rCols[i-1];
1388 0 : long nColRight = i == rCols.Count() ? rCols.GetRight() : rCols[i];
1389 :
1390 0 : if ( bRTL )
1391 : {
1392 0 : long nTmpRight = nColRight;
1393 0 : nColRight = rCols.GetRight() - nColLeft;
1394 0 : nColLeft = rCols.GetRight() - nTmpRight;
1395 : }
1396 :
1397 0 : nColLeft += rCols.GetLeftMin();
1398 0 : nColRight += rCols.GetLeftMin();
1399 :
1400 : //Werte auf die Verhaeltnisse der Tabelle (Follows) anpassen.
1401 0 : long nLeftA = nColLeft;
1402 0 : long nRightA = nColRight;
1403 0 : if ( rCols.GetLeftMin() != sal_uInt16((pTab->Frm().*fnRect->fnGetLeft)()) )
1404 : {
1405 0 : const long nDiff = (pTab->Frm().*fnRect->fnGetLeft)() - rCols.GetLeftMin();
1406 0 : nLeftA += nDiff;
1407 0 : nRightA += nDiff;
1408 : }
1409 :
1410 : //Wir wollen nicht allzu genau hinsehen.
1411 0 : if ( ::IsSame(nCLeft, nLeftA) && ::IsSame(nCRight, nRightA))
1412 : {
1413 0 : bNotInCols = false;
1414 0 : if ( bWishValues )
1415 : {
1416 0 : const sal_uInt16 nWish = ::lcl_CalcCellFit( pCell );
1417 0 : if ( nWish > nFit )
1418 0 : nFit = nWish;
1419 : }
1420 : else
1421 0 : { const sal_uInt16 nMin = MINLAY + sal_uInt16(pCell->Frm().Width() -
1422 0 : pCell->Prt().Width());
1423 0 : if ( !nFit || nMin < nFit )
1424 0 : nFit = nMin;
1425 : }
1426 0 : if ( rToFill[i] < nFit )
1427 0 : rToFill[i] = nFit;
1428 : }
1429 : }
1430 0 : if ( bNotInCols )
1431 0 : ::lcl_CalcSubColValues( rToFill, rCols, pCell, pTab, bWishValues );
1432 : }
1433 0 : do {
1434 0 : pCell = pCell->GetNextLayoutLeaf();
1435 0 : }while( pCell && pCell->Frm().Width() == 0 );
1436 0 : } while ( pCell && pTab->IsAnLower( pCell ) );
1437 0 : }
1438 0 : }
1439 :
1440 :
1441 0 : void SwDoc::AdjustCellWidth( const SwCursor& rCursor, sal_Bool bBalance )
1442 : {
1443 : // pruefe ob vom aktuellen Crsr der Point/Mark in einer Tabelle stehen
1444 0 : SwCntntNode* pCntNd = rCursor.GetPoint()->nNode.GetNode().GetCntntNode();
1445 0 : SwTableNode* pTblNd = pCntNd ? pCntNd->FindTableNode() : 0;
1446 0 : if( !pTblNd )
1447 : return ;
1448 :
1449 : SwLayoutFrm *pStart, *pEnd;
1450 0 : ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
1451 :
1452 : //TabCols besorgen, den ueber diese stellen wir die Tabelle neu ein.
1453 0 : SwFrm* pBoxFrm = pStart;
1454 0 : while( pBoxFrm && !pBoxFrm->IsCellFrm() )
1455 0 : pBoxFrm = pBoxFrm->GetUpper();
1456 :
1457 0 : if ( !pBoxFrm )
1458 : return; // robust
1459 :
1460 0 : SwTabCols aTabCols;
1461 0 : GetTabCols( aTabCols, 0, (SwCellFrm*)pBoxFrm );
1462 :
1463 0 : if ( ! aTabCols.Count() )
1464 : return;
1465 :
1466 0 : std::vector<sal_uInt16> aWish(aTabCols.Count() + 1);
1467 0 : std::vector<sal_uInt16> aMins(aTabCols.Count() + 1);
1468 :
1469 : sal_uInt16 i;
1470 :
1471 0 : ::lcl_CalcColValues( aWish, aTabCols, pStart, pEnd, sal_True );
1472 :
1473 : //Es ist Robuster wenn wir die Min-Werte fuer die ganze Tabelle berechnen.
1474 0 : const SwTabFrm *pTab = pStart->ImplFindTabFrm();
1475 0 : pStart = (SwLayoutFrm*)pTab->FirstCell();
1476 0 : pEnd = (SwLayoutFrm*)pTab->FindLastCntnt()->GetUpper();
1477 0 : while( !pEnd->IsCellFrm() )
1478 0 : pEnd = pEnd->GetUpper();
1479 0 : ::lcl_CalcColValues( aMins, aTabCols, pStart, pEnd, sal_False );
1480 :
1481 0 : if( bBalance )
1482 : {
1483 : //Alle Spalten, die makiert sind haben jetzt einen Wunschwert
1484 : //eingtragen. Wir addieren die aktuellen Werte, teilen das Ergebnis
1485 : //durch die Anzahl und haben eine Wunschwert fuer den ausgleich.
1486 0 : sal_uInt16 nWish = 0, nCnt = 0;
1487 0 : for ( i = 0; i <= aTabCols.Count(); ++i )
1488 : {
1489 0 : int nDiff = aWish[i];
1490 0 : if ( nDiff )
1491 : {
1492 0 : if ( i == 0 )
1493 0 : nWish = static_cast<sal_uInt16>( nWish + aTabCols[i] - aTabCols.GetLeft() );
1494 0 : else if ( i == aTabCols.Count() )
1495 0 : nWish = static_cast<sal_uInt16>(nWish + aTabCols.GetRight() - aTabCols[i-1] );
1496 : else
1497 0 : nWish = static_cast<sal_uInt16>(nWish + aTabCols[i] - aTabCols[i-1] );
1498 0 : ++nCnt;
1499 : }
1500 : }
1501 0 : nWish = nWish / nCnt;
1502 0 : for ( i = 0; i < aWish.size(); ++i )
1503 0 : if ( aWish[i] )
1504 0 : aWish[i] = nWish;
1505 : }
1506 :
1507 0 : const sal_uInt16 nOldRight = static_cast<sal_uInt16>(aTabCols.GetRight());
1508 :
1509 : //Um die Impl. einfach zu gestalten, aber trotzdem in den meissten Faellen
1510 : //den Platz richtig auszunutzen laufen wir zweimal.
1511 : //Problem: Erste Spalte wird breiter, die anderen aber erst danach
1512 : //schmaler. Die Wunschbreite der ersten Spalte wuerde abgelehnt, weil
1513 : //mit ihr die max. Breite der Tabelle ueberschritten wuerde.
1514 0 : for ( sal_uInt16 k= 0; k < 2; ++k )
1515 : {
1516 0 : for ( i = 0; i <= aTabCols.Count(); ++i )
1517 : {
1518 0 : int nDiff = aWish[i];
1519 0 : if ( nDiff )
1520 : {
1521 0 : int nMin = aMins[i];
1522 0 : if ( nMin > nDiff )
1523 0 : nDiff = nMin;
1524 :
1525 0 : if ( i == 0 )
1526 : {
1527 0 : if( aTabCols.Count() )
1528 0 : nDiff -= aTabCols[0] - aTabCols.GetLeft();
1529 : else
1530 0 : nDiff -= aTabCols.GetRight() - aTabCols.GetLeft();
1531 : }
1532 0 : else if ( i == aTabCols.Count() )
1533 0 : nDiff -= aTabCols.GetRight() - aTabCols[i-1];
1534 : else
1535 0 : nDiff -= aTabCols[i] - aTabCols[i-1];
1536 :
1537 0 : long nTabRight = aTabCols.GetRight() + nDiff;
1538 :
1539 : //Wenn die Tabelle zu breit wuerde begrenzen wir die Anpassung
1540 : //auf das erlaubte Maximum.
1541 0 : if ( !bBalance && nTabRight > aTabCols.GetRightMax() )
1542 : {
1543 0 : const long nTmpD = nTabRight - aTabCols.GetRightMax();
1544 0 : nDiff -= nTmpD;
1545 0 : nTabRight -= nTmpD;
1546 : }
1547 0 : for ( sal_uInt16 i2 = i; i2 < aTabCols.Count(); ++i2 )
1548 0 : aTabCols[i2] += nDiff;
1549 0 : aTabCols.SetRight( nTabRight );
1550 : }
1551 : }
1552 : }
1553 :
1554 0 : const sal_uInt16 nNewRight = static_cast<sal_uInt16>(aTabCols.GetRight());
1555 :
1556 0 : SwFrmFmt *pFmt = pTblNd->GetTable().GetFrmFmt();
1557 0 : const sal_Int16 nOriHori = pFmt->GetHoriOrient().GetHoriOrient();
1558 :
1559 : //So, die richtige Arbeit koennen wir jetzt der SwTable ueberlassen.
1560 0 : SetTabCols( aTabCols, sal_False, 0, (SwCellFrm*)pBoxFrm );
1561 :
1562 : // i54248: lijian/fme
1563 : // alignment might have been changed in SetTabCols, restore old value:
1564 0 : const SwFmtHoriOrient &rHori = pFmt->GetHoriOrient();
1565 0 : SwFmtHoriOrient aHori( rHori );
1566 0 : if ( aHori.GetHoriOrient() != nOriHori )
1567 : {
1568 0 : aHori.SetHoriOrient( nOriHori );
1569 0 : pFmt->SetFmtAttr( aHori );
1570 : }
1571 :
1572 : //Bei Automatischer Breite wird auf Linksbuendig umgeschaltet.
1573 : //Bei Randattributen wird der Rechte Rand angepasst.
1574 0 : if( !bBalance && nNewRight < nOldRight )
1575 : {
1576 0 : if( aHori.GetHoriOrient() == text::HoriOrientation::FULL )
1577 : {
1578 0 : aHori.SetHoriOrient( text::HoriOrientation::LEFT );
1579 0 : pFmt->SetFmtAttr( aHori );
1580 : }
1581 : }
1582 :
1583 0 : SetModified();
1584 : }
1585 :
1586 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|