LibreOffice Module sw (master) 1
ndtbl1.cxx
Go to the documentation of this file.
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#include <hintids.hxx>
21#include <editeng/boxitem.hxx>
22#include <editeng/brushitem.hxx>
24#include <fesh.hxx>
25#include <fmtornt.hxx>
26#include <fmtfsize.hxx>
27#include <fmtrowsplt.hxx>
28#include <tabcol.hxx>
29#include <frmatr.hxx>
30#include <cellfrm.hxx>
31#include <tabfrm.hxx>
32#include <cntfrm.hxx>
33#include <txtfrm.hxx>
34#include <svx/svxids.hrc>
35#include <doc.hxx>
36#include <IDocumentUndoRedo.hxx>
37#include <IDocumentState.hxx>
41#include <pam.hxx>
42#include <swcrsr.hxx>
43#include <viscrs.hxx>
44#include <swtable.hxx>
45#include <htmltbl.hxx>
46#include <tblsel.hxx>
47#include <swtblfmt.hxx>
48#include <ndindex.hxx>
49#include <undobj.hxx>
50#include <calbck.hxx>
51#include <UndoTable.hxx>
52#include <o3tl/enumrange.hxx>
53#include <o3tl/safeint.hxx>
54#include <osl/diagnose.h>
55#include <redline.hxx>
56
57using ::editeng::SvxBorderLine;
58using namespace ::com::sun::star;
59
60// See swtable.cxx too
61#define COLFUZZY 20L
62
63static bool IsSame( tools::Long nA, tools::Long nB ) { return std::abs(nA-nB) <= COLFUZZY; }
64
65namespace {
66
67// SwTableLine::ChgFrameFormat may delete old format which doesn't have writer listeners anymore.
68// This may invalidate my pointers, and lead to use-after-free. For this reason, I register myself
69// as a writer listener for the old format here, and take care to delete formats without listeners
70// in my own dtor.
71class SwTableFormatCmp : public SwClient
72{
73public:
74 SwTableFormatCmp( SwFrameFormat *pOld, SwFrameFormat *pNew, sal_Int16 nType );
75 ~SwTableFormatCmp() override;
76
77 static SwFrameFormat* FindNewFormat(std::vector<std::unique_ptr<SwTableFormatCmp>>& rArr,
78 SwFrameFormat const* pOld, sal_Int16 nType);
79
80private:
81 SwFrameFormat *m_pOld, *m_pNew;
82 sal_Int16 m_nType;
83};
84
85}
86
87SwTableFormatCmp::SwTableFormatCmp(SwFrameFormat* pO, SwFrameFormat* pN, sal_Int16 nT)
88 : m_pOld(pO)
89 , m_pNew(pN)
90 , m_nType(nT)
91{
92 if (m_pOld)
93 m_pOld->Add(this);
94}
95
96SwTableFormatCmp::~SwTableFormatCmp()
97{
98 if (m_pOld)
99 {
100 m_pOld->Remove(this);
101 if (!m_pOld->HasWriterListeners())
102 delete m_pOld;
103 }
104}
105
106// static
107SwFrameFormat* SwTableFormatCmp::FindNewFormat(std::vector<std::unique_ptr<SwTableFormatCmp>>& rArr,
108 SwFrameFormat const* pOld, sal_Int16 nType)
109{
110 for (const auto& pCmp : rArr)
111 {
112 if (pCmp->m_pOld == pOld && pCmp->m_nType == nType)
113 return pCmp->m_pNew;
114 }
115 return nullptr;
116}
117
118static void lcl_GetStartEndCell( const SwCursor& rCursor,
119 SwLayoutFrame *&prStart, SwLayoutFrame *&prEnd )
120{
121 OSL_ENSURE( rCursor.GetPointContentNode() && rCursor.GetMarkContentNode(),
122 "Tab selection not at ContentNode" );
123
124 Point aPtPos, aMkPos;
125 const SwShellCursor* pShCursor = dynamic_cast<const SwShellCursor*>(&rCursor);
126 if( pShCursor )
127 {
128 aPtPos = pShCursor->GetPtPos();
129 aMkPos = pShCursor->GetMkPos();
130 }
131
132 // Robust:
133 SwContentNode* pPointNd = rCursor.GetPointContentNode();
134 SwContentNode* pMarkNd = rCursor.GetMarkContentNode();
135
136 std::pair<Point, bool> tmp(aPtPos, true);
137 SwFrame *const pPointFrame = pPointNd ? pPointNd->getLayoutFrame(pPointNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, &tmp) : nullptr;
138 tmp.first = aMkPos;
139 SwFrame *const pMarkFrame = pMarkNd ? pMarkNd->getLayoutFrame(pMarkNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, &tmp) : nullptr;
140
141 prStart = pPointFrame ? pPointFrame->GetUpper() : nullptr;
142 prEnd = pMarkFrame ? pMarkFrame->GetUpper() : nullptr;
143}
144
145static bool lcl_GetBoxSel( const SwCursor& rCursor, SwSelBoxes& rBoxes,
146 bool bAllCursor = false )
147{
148 const SwTableCursor* pTableCursor =
149 dynamic_cast<const SwTableCursor*>(&rCursor);
150 if( pTableCursor )
151 ::GetTableSelCrs( *pTableCursor, rBoxes );
152 else
153 {
154 const SwPaM *pCurPam = &rCursor, *pSttPam = pCurPam;
155 do {
156 const SwNode* pNd = pCurPam->GetPointNode().FindTableBoxStartNode();
157 if( pNd )
158 {
159 SwTableBox* pBox = const_cast<SwTableBox*>(pNd->FindTableNode()->GetTable().
160 GetTableBox( pNd->GetIndex() ));
161 rBoxes.insert( pBox );
162 }
163 } while( bAllCursor &&
164 pSttPam != ( pCurPam = pCurPam->GetNext()) );
165 }
166 return !rBoxes.empty();
167}
168
169static void InsertLine( std::vector<SwTableLine*>& rLineArr, SwTableLine* pLine )
170{
171 if( rLineArr.end() == std::find( rLineArr.begin(), rLineArr.end(), pLine ) )
172 rLineArr.push_back( pLine );
173}
174
175static bool lcl_IsAnLower( const SwTableLine *pLine, const SwTableLine *pAssumed )
176{
177 const SwTableLine *pTmp = pAssumed->GetUpper() ?
178 pAssumed->GetUpper()->GetUpper() : nullptr;
179 while ( pTmp )
180 {
181 if ( pTmp == pLine )
182 return true;
183 pTmp = pTmp->GetUpper() ? pTmp->GetUpper()->GetUpper() : nullptr;
184 }
185 return false;
186}
187
188namespace {
189
190struct LinesAndTable
191{
192 std::vector<SwTableLine*> &m_rLines;
193 const SwTable &m_rTable;
194 bool m_bInsertLines;
195
196 LinesAndTable(std::vector<SwTableLine*> &rL, const SwTable &rTable) :
197 m_rLines(rL), m_rTable(rTable), m_bInsertLines(true) {}
198};
199
200}
201
202static bool FindLine_( FndLine_ & rLine, LinesAndTable* pPara );
203
204static bool FindBox_( FndBox_ & rBox, LinesAndTable* pPara )
205{
206 if (!rBox.GetLines().empty())
207 {
208 pPara->m_bInsertLines = true;
209 for (auto const& rpFndLine : rBox.GetLines())
210 {
211 FindLine_(*rpFndLine, pPara);
212 }
213
214 if (pPara->m_bInsertLines)
215 {
216 const SwTableLines &rLines = (rBox.GetBox())
217 ? rBox.GetBox()->GetTabLines()
218 : pPara->m_rTable.GetTabLines();
219 if (rBox.GetLines().size() == rLines.size())
220 {
221 for ( auto pLine : rLines )
222 ::InsertLine(pPara->m_rLines, pLine);
223 }
224 else
225 pPara->m_bInsertLines = false;
226 }
227 }
228 else if (rBox.GetBox())
229 {
230 ::InsertLine(pPara->m_rLines, rBox.GetBox()->GetUpper());
231 }
232 return true;
233}
234
235bool FindLine_( FndLine_& rLine, LinesAndTable* pPara )
236{
237 for (auto const& it : rLine.GetBoxes())
238 {
239 FindBox_(*it, pPara);
240 }
241 return true;
242}
243
244static void lcl_CollectLines( std::vector<SwTableLine*> &rArr, const SwCursor& rCursor, bool bRemoveLines )
245{
246 // Collect the selected Boxes first
247 SwSelBoxes aBoxes;
248 if( !::lcl_GetBoxSel( rCursor, aBoxes ))
249 return ;
250
251 // Copy the selected structure
252 const SwTable &rTable = aBoxes[0]->GetSttNd()->FindTableNode()->GetTable();
253 LinesAndTable aPara( rArr, rTable );
254 FndBox_ aFndBox( nullptr, nullptr );
255 {
256 FndPara aTmpPara( aBoxes, &aFndBox );
257 ForEach_FndLineCopyCol( const_cast<SwTableLines&>(rTable.GetTabLines()), &aTmpPara );
258 }
259
260 // Collect the Lines which only contain selected Boxes
261 ::FindBox_(aFndBox, &aPara);
262
263 // Remove lines, that have a common superordinate row.
264 // (Not for row split)
265 if ( !bRemoveLines )
266 return;
267
268 for ( std::vector<SwTableLine*>::size_type i = 0; i < rArr.size(); ++i )
269 {
270 SwTableLine *pUpLine = rArr[i];
271 for ( std::vector<SwTableLine*>::size_type k = 0; k < rArr.size(); ++k )
272 {
273 if ( k != i && ::lcl_IsAnLower( pUpLine, rArr[k] ) )
274 {
275 rArr.erase( rArr.begin() + k );
276 if ( k <= i )
277 --i;
278 --k;
279 }
280 }
281 }
282}
283
284static void lcl_ProcessRowAttr(std::vector<std::unique_ptr<SwTableFormatCmp>>& rFormatCmp,
285 SwTableLine* pLine, const SfxPoolItem& rNew)
286{
287 SwFrameFormat *pNewFormat = SwTableFormatCmp::FindNewFormat( rFormatCmp, pLine->GetFrameFormat(), 0 );
288 if ( nullptr != pNewFormat )
289 pLine->ChgFrameFormat( static_cast<SwTableLineFormat*>(pNewFormat) );
290 else
291 {
292 SwFrameFormat *pOld = pLine->GetFrameFormat();
293 SwFrameFormat *pNew = pLine->ClaimFrameFormat();
294 pNew->SetFormatAttr( rNew );
295 rFormatCmp.push_back(std::make_unique<SwTableFormatCmp>(pOld, pNew, 0));
296 }
297}
298
299static void lcl_ProcessBoxSize(std::vector<std::unique_ptr<SwTableFormatCmp>>& rFormatCmp,
300 SwTableBox* pBox, const SwFormatFrameSize& rNew);
301
302static void lcl_ProcessRowSize(std::vector<std::unique_ptr<SwTableFormatCmp>>& rFormatCmp,
303 SwTableLine* pLine, const SwFormatFrameSize& rNew)
304{
305 lcl_ProcessRowAttr( rFormatCmp, pLine, rNew );
306 SwTableBoxes &rBoxes = pLine->GetTabBoxes();
307 for ( auto pBox : rBoxes )
308 ::lcl_ProcessBoxSize( rFormatCmp, pBox, rNew );
309}
310
311static void lcl_ProcessBoxSize(std::vector<std::unique_ptr<SwTableFormatCmp>>& rFormatCmp,
312 SwTableBox* pBox, const SwFormatFrameSize& rNew)
313{
314 SwTableLines &rLines = pBox->GetTabLines();
315 if ( !rLines.empty() )
316 {
317 SwFormatFrameSize aSz( rNew );
318 aSz.SetHeight( rNew.GetHeight() ? rNew.GetHeight() / rLines.size() : 0 );
319 for ( auto pLine : rLines )
320 ::lcl_ProcessRowSize( rFormatCmp, pLine, aSz );
321 }
322}
323
324void SwDoc::SetRowSplit( const SwCursor& rCursor, const SwFormatRowSplit &rNew )
325{
326 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
327 if( !pTableNd )
328 return;
329
330 std::vector<SwTableLine*> aRowArr; // For Lines collecting
331 ::lcl_CollectLines( aRowArr, rCursor, false );
332
333 if( aRowArr.empty() )
334 return;
335
336 if (GetIDocumentUndoRedo().DoesUndo())
337 {
338 GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoAttrTable>(*pTableNd));
339 }
340
341 std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp;
342 aFormatCmp.reserve( std::max( 255, static_cast<int>(aRowArr.size()) ) );
343
344 for( auto pLn : aRowArr )
345 ::lcl_ProcessRowAttr( aFormatCmp, pLn, rNew );
346
348}
349
350std::unique_ptr<SwFormatRowSplit> SwDoc::GetRowSplit( const SwCursor& rCursor )
351{
352 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
353 if( !pTableNd )
354 return nullptr;
355
356 std::vector<SwTableLine*> aRowArr; // For Lines collecting
357 ::lcl_CollectLines( aRowArr, rCursor, false );
358
359 if( aRowArr.empty() )
360 return nullptr;
361
362 SwFormatRowSplit* pSz = &const_cast<SwFormatRowSplit&>(aRowArr[0]->GetFrameFormat()->GetRowSplit());
363
364 for ( auto pLn : aRowArr )
365 {
366 if ( pSz->GetValue() != pLn->GetFrameFormat()->GetRowSplit().GetValue() )
367 {
368 return nullptr;
369 }
370 }
371 return std::make_unique<SwFormatRowSplit>( *pSz );
372}
373
374/* Class: SwDoc
375 * Methods: SetRowHeight(), GetRowHeight()
376 *
377 * The line height is calculated from the Selection.
378 * Starting with every Cell within the Selection, all Cells are iterated
379 * through in an upwards fashion.
380 *
381 * The topmost Line gets the requested value, all Lines below it get
382 * a respective value that is calculated from the relation of the old and
383 * new size of the topmost Line in the lower line's own size.
384 *
385 * All changed Lines may get an own FrameFormat.
386 * Of course we can only touch every Line once.
387 */
388
389void SwDoc::SetRowHeight( const SwCursor& rCursor, const SwFormatFrameSize &rNew )
390{
391 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
392 if( !pTableNd )
393 return;
394
395 std::vector<SwTableLine*> aRowArr; // For Lines collecting
396 ::lcl_CollectLines( aRowArr, rCursor, true );
397
398 if( aRowArr.empty() )
399 return;
400
401 if (GetIDocumentUndoRedo().DoesUndo())
402 {
403 GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoAttrTable>(*pTableNd));
404 }
405
406 std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp;
407 aFormatCmp.reserve( std::max( 255, static_cast<int>(aRowArr.size()) ) );
408 for ( auto pLn : aRowArr )
409 ::lcl_ProcessRowSize( aFormatCmp, pLn, rNew );
410
412}
413
414std::unique_ptr<SwFormatFrameSize> SwDoc::GetRowHeight( const SwCursor& rCursor )
415{
416 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
417 if( !pTableNd )
418 return nullptr;
419
420 std::vector<SwTableLine*> aRowArr; // For Lines collecting
421 ::lcl_CollectLines( aRowArr, rCursor, true );
422
423 if( aRowArr.empty() )
424 return nullptr;
425
426 SwFormatFrameSize* pSz = &const_cast<SwFormatFrameSize&>(aRowArr[0]->GetFrameFormat()->GetFrameSize());
427
428 for ( auto pLn : aRowArr )
429 {
430 if ( *pSz != pLn->GetFrameFormat()->GetFrameSize() )
431 return nullptr;
432 }
433 return std::make_unique<SwFormatFrameSize>( *pSz );
434}
435
436bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly, const bool bOptimize )
437{
438 bool bRet = false;
439 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
440 if( pTableNd )
441 {
442 std::vector<SwTableLine*> aRowArr; // For Lines collecting
443 ::lcl_CollectLines( aRowArr, rCursor, true );
444
445 if( 1 < aRowArr.size() )
446 {
447 if( !bTstOnly )
448 {
449 tools::Long nHeight = 0;
450 sal_Int32 nTotalHeight = 0;
451 for ( auto pLn : aRowArr )
452 {
453 if (bOptimize)
454 nHeight = 0;
455 SwIterator<SwFrame,SwFormat> aIter( *pLn->GetFrameFormat() );
456 SwFrame* pFrame = aIter.First();
457 while ( pFrame )
458 {
459 nHeight = std::max( nHeight, pFrame->getFrameArea().Height() );
460 pFrame = aIter.Next();
461 }
462 nTotalHeight += nHeight;
463 }
464
465 if ( bOptimize )
466 nHeight = nTotalHeight / aRowArr.size();
467
468 SwFormatFrameSize aNew( SwFrameSize::Minimum, 0, nHeight );
469
470 if (GetIDocumentUndoRedo().DoesUndo())
471 {
472 GetIDocumentUndoRedo().AppendUndo(
473 std::make_unique<SwUndoAttrTable>(*pTableNd));
474 }
475
476 std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp;
477 aFormatCmp.reserve( std::max( 255, static_cast<int>(aRowArr.size()) ) );
478 for( auto pLn : aRowArr )
479 ::lcl_ProcessRowSize( aFormatCmp, pLn, aNew );
480
482 }
483 bRet = true;
484 }
485 }
486 return bRet;
487}
488
489void SwDoc::SetRowBackground( const SwCursor& rCursor, const SvxBrushItem &rNew )
490{
491 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
492 if( !pTableNd )
493 return;
494
495 std::vector<SwTableLine*> aRowArr; // For Lines collecting
496 ::lcl_CollectLines( aRowArr, rCursor, true );
497
498 if( aRowArr.empty() )
499 return;
500
501 if (GetIDocumentUndoRedo().DoesUndo())
502 {
503 GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoAttrTable>(*pTableNd));
504 }
505
506 std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp;
507 aFormatCmp.reserve( std::max( 255, static_cast<int>(aRowArr.size()) ) );
508
509 for( auto pLn : aRowArr )
510 ::lcl_ProcessRowAttr( aFormatCmp, pLn, rNew );
511
513}
514
515bool SwDoc::GetRowBackground( const SwCursor& rCursor, std::unique_ptr<SvxBrushItem>& rToFill )
516{
517 bool bRet = false;
518 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
519 if( pTableNd )
520 {
521 std::vector<SwTableLine*> aRowArr; // For Lines collecting
522 ::lcl_CollectLines( aRowArr, rCursor, true );
523
524 if( !aRowArr.empty() )
525 {
526 rToFill = aRowArr[0]->GetFrameFormat()->makeBackgroundBrushItem();
527
528 bRet = true;
529 for ( std::vector<SwTableLine*>::size_type i = 1; i < aRowArr.size(); ++i )
530 {
531 std::unique_ptr<SvxBrushItem> aAlternative(aRowArr[i]->GetFrameFormat()->makeBackgroundBrushItem());
532
533 if ( *rToFill != *aAlternative )
534 {
535 bRet = false;
536 break;
537 }
538 }
539 }
540 }
541 return bRet;
542}
543
544// has a table row, which is not a tracked deletion
545bool SwDoc::HasRowNotTracked( const SwCursor& rCursor )
546{
547 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
548 if( !pTableNd )
549 return false;
550
551 std::vector<SwTableLine*> aRowArr; // For Lines collecting
552 ::lcl_CollectLines( aRowArr, rCursor, true );
553
554 if( aRowArr.empty() )
555 return false;
556
557 SwRedlineTable::size_type nRedlinePos = 0;
558 SwDoc* pDoc = aRowArr[0]->GetFrameFormat()->GetDoc();
560
561 for( auto pLn : aRowArr )
562 {
563 auto pHasTextChangesOnlyProp = pLn->GetFrameFormat()->GetAttrSet().GetItem<SvxPrintItem>(RES_PRINT);
564 if ( !pHasTextChangesOnlyProp || pHasTextChangesOnlyProp->GetValue() )
565 // there is a not tracked row in the table selection
566 return true;
567
568 // tdf#150666 examine tracked row: it's possible to delete a tracked insertion
569 SwRedlineTable::size_type nPos = pLn->UpdateTextChangesOnly(nRedlinePos);
570 if ( nPos != SwRedlineTable::npos )
571 {
572 const SwRedlineTable& aRedlineTable = rIDRA.GetRedlineTable();
573 SwRangeRedline* pTmp = aRedlineTable[ nPos ];
574 if ( RedlineType::Insert == pTmp->GetType() )
575 return true;
576 }
577 }
578 return false;
579}
580
582 const SvxPrintItem &rNew, bool bAll, bool bIns )
583{
584 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
585 if( !pTableNd )
586 return;
587
588 std::vector<SwTableLine*> aRowArr; // For Lines collecting
589 if ( bAll )
590 {
591 const SwTableLines &rLines = pTableNd->GetTable().GetTabLines();
592 aRowArr.insert(aRowArr.end(), rLines.begin(), rLines.end());
593 }
594 else
595 ::lcl_CollectLines( aRowArr, rCursor, true );
596
597 if( aRowArr.empty() )
598 return;
599
600 if (GetIDocumentUndoRedo().DoesUndo())
601 {
602 GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoAttrTable>(*pTableNd));
603 }
604
605 bool bInsertDummy = !bAll && !bIns &&
606 // HasTextChangesOnly == false, i.e. a tracked row change (deletion, if bIns == false)
607 !rNew.GetValue();
608 std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp;
609 aFormatCmp.reserve( std::max( 255, static_cast<int>(aRowArr.size()) ) );
610
611 SwRedlineTable::size_type nRedlinePos = 0;
612 for( auto pLn : aRowArr )
613 {
614 // tdf#150666 deleting row insertion from the same author needs special handling,
615 // because removing redlines of the author can result an empty line,
616 // which doesn't contain any redline for the tracked row
617 bool bDeletionOfOwnRowInsertion = false;
618 if ( bInsertDummy )
619 {
620 SwRedlineTable::size_type nPos = pLn->UpdateTextChangesOnly(nRedlinePos);
621 if ( nPos != SwRedlineTable::npos )
622 {
623 SwDoc* pDoc = pLn->GetFrameFormat()->GetDoc();
625 const SwRedlineTable& aRedlineTable = rIDRA.GetRedlineTable();
626 SwRangeRedline* pTmp = aRedlineTable[ nPos ];
627 if ( RedlineType::Insert == pTmp->GetType() &&
628 rIDRA.GetRedlineAuthor() == pTmp->GetRedlineData().GetAuthor() &&
629 pTmp->GetText()[0] == CH_TXT_TRACKED_DUMMY_CHAR )
630 {
631 bDeletionOfOwnRowInsertion = true;
632 }
633 }
634 }
635
636 ::lcl_ProcessRowAttr( aFormatCmp, pLn, rNew );
637 // as a workaround for the rows without text content,
638 // add a redline with invisible text CH_TXT_TRACKED_DUMMY_CHAR
639 // (unless the table is part of a bigger deletion, where the
640 // new redline can cause a problem)
641 if ( bInsertDummy && (pLn->IsEmpty() || bDeletionOfOwnRowInsertion ) )
642 {
643 ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
644 SwNodeIndex aInsPos( *(pLn->GetTabBoxes()[0]->GetSttNd()), 1 );
647 SwPaM aPaM(aInsPos);
649 OUStringChar(CH_TXT_TRACKED_DUMMY_CHAR) );
650 aPaM.SetMark();
653 }
654 }
655
657}
658
659static void InsertCell( std::vector<SwCellFrame*>& rCellArr, SwCellFrame* pCellFrame )
660{
661 if( rCellArr.end() == std::find( rCellArr.begin(), rCellArr.end(), pCellFrame ) )
662 rCellArr.push_back( pCellFrame );
663}
664
665static void lcl_CollectCells( std::vector<SwCellFrame*> &rArr, const SwRect &rUnion,
666 SwTabFrame *pTab )
667{
668 SwLayoutFrame *pCell = pTab->FirstCell();
669 do
670 {
671 // If the Cell contains a CellFrame, we need to use it
672 // in order to get to the Cell
673 while ( !pCell->IsCellFrame() )
674 pCell = pCell->GetUpper();
675 OSL_ENSURE( pCell, "Frame is not a Cell" );
676 if ( rUnion.Overlaps( pCell->getFrameArea() ) )
677 ::InsertCell( rArr, static_cast<SwCellFrame*>(pCell) );
678
679 // Make sure the Cell is left (Areas)
680 SwLayoutFrame *pTmp = pCell;
681 do
682 { pTmp = pTmp->GetNextLayoutLeaf();
683 } while ( pCell->IsAnLower( pTmp ) );
684 pCell = pTmp;
685 } while( pCell && pTab->IsAnLower( pCell ) );
686}
687
688void SwDoc::SetTabBorders( const SwCursor& rCursor, const SfxItemSet& rSet )
689{
690 SwContentNode* pCntNd = rCursor.GetPoint()->GetNode().GetContentNode();
691 SwTableNode* pTableNd = pCntNd ? pCntNd->FindTableNode() : nullptr;
692 if( !pTableNd )
693 return ;
694
695 SwLayoutFrame *pStart, *pEnd;
696 ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
697
698 SwSelUnions aUnions;
699 ::MakeSelUnions( aUnions, pStart, pEnd );
700
701 if( aUnions.empty() )
702 return;
703
704 SwTable& rTable = pTableNd->GetTable();
705 if (GetIDocumentUndoRedo().DoesUndo())
706 {
707 GetIDocumentUndoRedo().AppendUndo( std::make_unique<SwUndoAttrTable>(*pTableNd) );
708 }
709
710 std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp;
711 aFormatCmp.reserve( 255 );
712 const SvxBoxItem* pSetBox;
713 const SvxBoxInfoItem *pSetBoxInfo;
714
715 const SvxBorderLine* pLeft = nullptr;
716 const SvxBorderLine* pRight = nullptr;
717 const SvxBorderLine* pTop = nullptr;
718 const SvxBorderLine* pBottom = nullptr;
719 const SvxBorderLine* pHori = nullptr;
720 const SvxBorderLine* pVert = nullptr;
721 bool bHoriValid = true, bVertValid = true,
722 bTopValid = true, bBottomValid = true,
723 bLeftValid = true, bRightValid = true;
724
725 // The Flags in the BoxInfo Item decide whether a BorderLine is valid!
726 pSetBoxInfo = rSet.GetItemIfSet( SID_ATTR_BORDER_INNER, false );
727 if( pSetBoxInfo )
728 {
729 pHori = pSetBoxInfo->GetHori();
730 pVert = pSetBoxInfo->GetVert();
731
732 bHoriValid = pSetBoxInfo->IsValid(SvxBoxInfoItemValidFlags::HORI);
733 bVertValid = pSetBoxInfo->IsValid(SvxBoxInfoItemValidFlags::VERT);
734
735 // Do we want to evaluate these?
736 bTopValid = pSetBoxInfo->IsValid(SvxBoxInfoItemValidFlags::TOP);
737 bBottomValid = pSetBoxInfo->IsValid(SvxBoxInfoItemValidFlags::BOTTOM);
738 bLeftValid = pSetBoxInfo->IsValid(SvxBoxInfoItemValidFlags::LEFT);
739 bRightValid = pSetBoxInfo->IsValid(SvxBoxInfoItemValidFlags::RIGHT);
740 }
741
742 pSetBox = rSet.GetItemIfSet( RES_BOX, false );
743 if( pSetBox )
744 {
745 pLeft = pSetBox->GetLeft();
746 pRight = pSetBox->GetRight();
747 pTop = pSetBox->GetTop();
748 pBottom = pSetBox->GetBottom();
749 }
750 else
751 {
752 // Not set, thus not valid values
753 bTopValid = bBottomValid = bLeftValid = bRightValid = false;
754 pSetBox = nullptr;
755 }
756
757 bool bFirst = true;
758 for ( SwSelUnions::size_type i = 0; i < aUnions.size(); ++i )
759 {
760 SwSelUnion *pUnion = &aUnions[i];
761 SwTabFrame *pTab = pUnion->GetTable();
762 const SwRect &rUnion = pUnion->GetUnion();
763 const bool bLast = (i == aUnions.size() - 1);
764
765 std::vector<SwCellFrame*> aCellArr;
766 aCellArr.reserve( 255 );
767 ::lcl_CollectCells( aCellArr, pUnion->GetUnion(), pTab );
768
769 // All Cell Borders that match the UnionRect or extend it are
770 // Outer Borders. All others are Inner Borders.
771
772 // New: The Outer Borders can, depending on whether it's a
773 // Start/Middle/Follow Table (for Selection via FollowTabs),
774 // also not be Outer Borders.
775 // Outer Borders are set on the left, right, at the top and at the bottom.
776 // Inner Borders are only set at the top and on the left.
777 for ( auto pCell : aCellArr )
778 {
779 const bool bVert = pTab->IsVertical();
780 const bool bRTL = pTab->IsRightToLeft();
781 bool bTopOver, bLeftOver, bRightOver, bBottomOver;
782 if ( bVert )
783 {
784 bTopOver = pCell->getFrameArea().Right() >= rUnion.Right();
785 bLeftOver = pCell->getFrameArea().Top() <= rUnion.Top();
786 bRightOver = pCell->getFrameArea().Bottom() >= rUnion.Bottom();
787 bBottomOver = pCell->getFrameArea().Left() <= rUnion.Left();
788 }
789 else
790 {
791 bTopOver = pCell->getFrameArea().Top() <= rUnion.Top();
792 bLeftOver = pCell->getFrameArea().Left() <= rUnion.Left();
793 bRightOver = pCell->getFrameArea().Right() >= rUnion.Right();
794 bBottomOver = pCell->getFrameArea().Bottom() >= rUnion.Bottom();
795 }
796
797 if ( bRTL )
798 std::swap( bLeftOver, bRightOver );
799
800 // Do not set anything by default in HeadlineRepeats
801 if ( pTab->IsFollow() &&
802 ( pTab->IsInHeadline( *pCell ) ||
803 // Same holds for follow flow rows
804 pCell->IsInFollowFlowRow() ) )
805 continue;
806
807 SvxBoxItem aBox( pCell->GetFormat()->GetBox() );
808
809 sal_Int16 nType = 0;
810
811 // Top Border
812 if( bTopValid )
813 {
814 if ( bFirst && bTopOver )
815 {
816 aBox.SetLine( pTop, SvxBoxItemLine::TOP );
817 nType |= 0x0001;
818 }
819 else if ( bHoriValid )
820 {
821 aBox.SetLine( nullptr, SvxBoxItemLine::TOP );
822 nType |= 0x0002;
823 }
824 }
825
826 // Fix fdo#62470 correct the input for RTL table
827 if (bRTL)
828 {
829 if( bLeftOver && bRightOver)
830 {
831 if ( bLeftValid )
832 {
833 aBox.SetLine( pLeft, SvxBoxItemLine::RIGHT );
834 nType |= 0x0010;
835 }
836 if ( bRightValid )
837 {
838 aBox.SetLine( pRight, SvxBoxItemLine::LEFT );
839 nType |= 0x0004;
840 }
841 }
842 else
843 {
844 if ( bLeftValid )
845 {
846 aBox.SetLine( bRightOver ? pLeft : nullptr, SvxBoxItemLine::RIGHT );
847 if (bVertValid)
848 nType |= 0x0020;
849 else
850 nType |= 0x0010;
851 }
852 if ( bLeftOver )
853 {
854 if ( bRightValid )
855 {
856 aBox.SetLine( pRight, SvxBoxItemLine::LEFT );
857 nType |= 0x0004;
858 }
859 }
860 else if ( bVertValid )
861 {
862 aBox.SetLine( pVert, SvxBoxItemLine::LEFT );
863 nType |= 0x0008;
864 }
865 }
866 }
867 else
868 {
869 // Left Border
870 if ( bLeftOver )
871 {
872 if( bLeftValid )
873 {
874 aBox.SetLine( pLeft, SvxBoxItemLine::LEFT );
875 nType |= 0x0004;
876 }
877 }
878 else if( bVertValid )
879 {
880 aBox.SetLine( pVert, SvxBoxItemLine::LEFT );
881 nType |= 0x0008;
882 }
883
884 // Right Border
885 if( bRightValid )
886 {
887 if ( bRightOver )
888 {
889 aBox.SetLine( pRight, SvxBoxItemLine::RIGHT );
890 nType |= 0x0010;
891 }
892 else if ( bVertValid )
893 {
894 aBox.SetLine( nullptr, SvxBoxItemLine::RIGHT );
895 nType |= 0x0020;
896 }
897 }
898 }
899
900 // Bottom Border
901 if ( bLast && bBottomOver )
902 {
903 if( bBottomValid )
904 {
905 aBox.SetLine( pBottom, SvxBoxItemLine::BOTTOM );
906 nType |= 0x0040;
907 }
908 }
909 else if( bHoriValid )
910 {
911 aBox.SetLine( pHori, SvxBoxItemLine::BOTTOM );
912 nType |= 0x0080;
913 }
914
915 if( pSetBox )
916 {
918 aBox.SetDistance( pSetBox->GetDistance( k ), k );
919 }
920
921 SwTableBox *pBox = const_cast<SwTableBox*>(pCell->GetTabBox());
922 SwFrameFormat *pNewFormat = SwTableFormatCmp::FindNewFormat( aFormatCmp, pBox->GetFrameFormat(), nType );
923 if ( nullptr != pNewFormat )
924 pBox->ChgFrameFormat( static_cast<SwTableBoxFormat*>(pNewFormat) );
925 else
926 {
927 SwFrameFormat *pOld = pBox->GetFrameFormat();
928 SwFrameFormat *pNew = pBox->ClaimFrameFormat();
929 pNew->SetFormatAttr( aBox );
930 aFormatCmp.push_back(std::make_unique<SwTableFormatCmp>(pOld, pNew, nType));
931 }
932 }
933
934 bFirst = false;
935 }
936
937 SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
938 if( pTableLayout )
939 {
941 SwTabFrame* pTabFrame = pFrame->ImplFindTabFrame();
942
943 pTableLayout->BordersChanged(
944 pTableLayout->GetBrowseWidthByTabFrame( *pTabFrame ) );
945 }
946 ::ClearFEShellTabCols(*this, nullptr);
948}
949
950static void lcl_SetLineStyle( SvxBorderLine *pToSet,
951 const Color *pColor, const SvxBorderLine *pBorderLine)
952{
953 if ( pBorderLine )
954 {
955 if ( !pColor )
956 {
957 Color aTmp( pToSet->GetColor() );
958 *pToSet = *pBorderLine;
959 pToSet->SetColor( aTmp );
960 }
961 else
962 *pToSet = *pBorderLine;
963 }
964 if ( pColor )
965 pToSet->SetColor( *pColor );
966}
967
968void SwDoc::SetTabLineStyle( const SwCursor& rCursor,
969 const Color* pColor, bool bSetLine,
970 const SvxBorderLine* pBorderLine )
971{
972 SwContentNode* pCntNd = rCursor.GetPoint()->GetNode().GetContentNode();
973 SwTableNode* pTableNd = pCntNd ? pCntNd->FindTableNode() : nullptr;
974 if( !pTableNd )
975 return ;
976
977 SwLayoutFrame *pStart, *pEnd;
978 ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
979
980 SwSelUnions aUnions;
981 ::MakeSelUnions( aUnions, pStart, pEnd );
982
983 if( aUnions.empty() )
984 return;
985
986 SwTable& rTable = pTableNd->GetTable();
987 if (GetIDocumentUndoRedo().DoesUndo())
988 {
989 GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoAttrTable>(*pTableNd));
990 }
991
992 SvxBorderLine aDefaultBorder(pBorderLine ? *pBorderLine
993 : SvxBorderLine(pColor, SvxBorderLineWidth::VeryThin));
994 if (pColor && pBorderLine)
995 aDefaultBorder.SetColor(*pColor);
996
997 for( auto &rU : aUnions )
998 {
999 SwSelUnion *pUnion = &rU;
1000 SwTabFrame *pTab = pUnion->GetTable();
1001 std::vector<SwCellFrame*> aCellArr;
1002 aCellArr.reserve( 255 );
1003 ::lcl_CollectCells( aCellArr, pUnion->GetUnion(), pTab );
1004
1005 for ( auto pCell : aCellArr )
1006 {
1007 // Do not set anything by default in HeadlineRepeats
1008 if ( pTab->IsFollow() && pTab->IsInHeadline( *pCell ) )
1009 continue;
1010
1011 const_cast<SwTableBox*>(pCell->GetTabBox())->ClaimFrameFormat();
1012 SwFrameFormat *pFormat = pCell->GetFormat();
1013 std::unique_ptr<SvxBoxItem> aBox(pFormat->GetBox().Clone());
1014
1015 SvxBorderLine* pTop = aBox->GetTop();
1016 SvxBorderLine* pBot = aBox->GetBottom();
1017 SvxBorderLine* pLeft = aBox->GetLeft();
1018 SvxBorderLine* pRight = aBox->GetRight();
1019
1020 if ( !pBorderLine && bSetLine )
1021 {
1022 aBox.reset(::GetDfltAttr(RES_BOX)->Clone());
1023 }
1024 else if ((pColor || pBorderLine) && !pTop && !pBot && !pLeft && !pRight)
1025 {
1026 aBox->SetLine(&aDefaultBorder, SvxBoxItemLine::TOP);
1027 aBox->SetLine(&aDefaultBorder, SvxBoxItemLine::BOTTOM);
1028 aBox->SetLine(&aDefaultBorder, SvxBoxItemLine::LEFT);
1029 aBox->SetLine(&aDefaultBorder, SvxBoxItemLine::RIGHT);
1030 }
1031 else
1032 {
1033 if (pTop)
1034 ::lcl_SetLineStyle(pTop, pColor, pBorderLine);
1035 if (pBot)
1036 ::lcl_SetLineStyle(pBot, pColor, pBorderLine);
1037 if (pLeft)
1038 ::lcl_SetLineStyle(pLeft, pColor, pBorderLine);
1039 if (pRight)
1040 ::lcl_SetLineStyle(pRight, pColor, pBorderLine);
1041 }
1042 pFormat->SetFormatAttr( *aBox );
1043 }
1044 }
1045
1046 SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
1047 if( pTableLayout )
1048 {
1050 SwTabFrame* pTabFrame = pFrame->ImplFindTabFrame();
1051
1052 pTableLayout->BordersChanged(
1053 pTableLayout->GetBrowseWidthByTabFrame( *pTabFrame ) );
1054 }
1055 ::ClearFEShellTabCols(*this, nullptr);
1057}
1058
1059void SwDoc::GetTabBorders( const SwCursor& rCursor, SfxItemSet& rSet )
1060{
1061 SwContentNode* pCntNd = rCursor.GetPoint()->GetNode().GetContentNode();
1062 SwTableNode* pTableNd = pCntNd ? pCntNd->FindTableNode() : nullptr;
1063 if( !pTableNd )
1064 return ;
1065
1066 SwLayoutFrame *pStart, *pEnd;
1067 ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
1068
1069 SwSelUnions aUnions;
1070 ::MakeSelUnions( aUnions, pStart, pEnd );
1071
1072 if( aUnions.empty() )
1073 return;
1074
1075 SvxBoxItem aSetBox ( rSet.Get(RES_BOX ) );
1076 SvxBoxInfoItem aSetBoxInfo( rSet.Get(SID_ATTR_BORDER_INNER) );
1077
1078 bool bTopSet = false,
1079 bBottomSet = false,
1080 bLeftSet = false,
1081 bRightSet = false,
1082 bHoriSet = false,
1083 bVertSet = false,
1084 bDistanceSet = false,
1085 bRTLTab = false;
1086
1087 aSetBoxInfo.ResetFlags();
1088
1089 for ( SwSelUnions::size_type i = 0; i < aUnions.size(); ++i )
1090 {
1091 SwSelUnion *pUnion = &aUnions[i];
1092 const SwTabFrame *pTab = pUnion->GetTable();
1093 const SwRect &rUnion = pUnion->GetUnion();
1094 const bool bFirst = i == 0;
1095 const bool bLast = (i == aUnions.size() - 1);
1096
1097 std::vector<SwCellFrame*> aCellArr;
1098 aCellArr.reserve(255);
1099 ::lcl_CollectCells( aCellArr, rUnion, const_cast<SwTabFrame*>(pTab) );
1100
1101 for ( auto pCell : aCellArr )
1102 {
1103 const bool bVert = pTab->IsVertical();
1104 const bool bRTL = bRTLTab = pTab->IsRightToLeft();
1105 bool bTopOver, bLeftOver, bRightOver, bBottomOver;
1106 if ( bVert )
1107 {
1108 bTopOver = pCell->getFrameArea().Right() >= rUnion.Right();
1109 bLeftOver = pCell->getFrameArea().Top() <= rUnion.Top();
1110 bRightOver = pCell->getFrameArea().Bottom() >= rUnion.Bottom();
1111 bBottomOver = pCell->getFrameArea().Left() <= rUnion.Left();
1112 }
1113 else
1114 {
1115 bTopOver = pCell->getFrameArea().Top() <= rUnion.Top();
1116 bLeftOver = pCell->getFrameArea().Left() <= rUnion.Left();
1117 bRightOver = pCell->getFrameArea().Right() >= rUnion.Right();
1118 bBottomOver = pCell->getFrameArea().Bottom() >= rUnion.Bottom();
1119 }
1120
1121 if ( bRTL )
1122 std::swap( bLeftOver, bRightOver );
1123
1124 const SwFrameFormat *pFormat = pCell->GetFormat();
1125 const SvxBoxItem &rBox = pFormat->GetBox();
1126
1127 // Top Border
1128 if ( bFirst && bTopOver )
1129 {
1130 if (aSetBoxInfo.IsValid(SvxBoxInfoItemValidFlags::TOP))
1131 {
1132 if ( !bTopSet )
1133 { bTopSet = true;
1134 aSetBox.SetLine( rBox.GetTop(), SvxBoxItemLine::TOP );
1135 }
1136 else if ((aSetBox.GetTop() && rBox.GetTop() &&
1137 (*aSetBox.GetTop() != *rBox.GetTop())) ||
1138 ((!aSetBox.GetTop()) != (!rBox.GetTop()))) // != expression is true, if one and only one of the two pointers is !0
1139 {
1140 aSetBoxInfo.SetValid(SvxBoxInfoItemValidFlags::TOP, false );
1141 aSetBox.SetLine( nullptr, SvxBoxItemLine::TOP );
1142 }
1143 }
1144 }
1145
1146 // Left Border
1147 if ( bLeftOver )
1148 {
1149 if (aSetBoxInfo.IsValid(SvxBoxInfoItemValidFlags::LEFT))
1150 {
1151 if ( !bLeftSet )
1152 { bLeftSet = true;
1153 aSetBox.SetLine( rBox.GetLeft(), SvxBoxItemLine::LEFT );
1154 }
1155 else if ((aSetBox.GetLeft() && rBox.GetLeft() &&
1156 (*aSetBox.GetLeft() != *rBox.GetLeft())) ||
1157 ((!aSetBox.GetLeft()) != (!rBox.GetLeft())))
1158 {
1159 aSetBoxInfo.SetValid(SvxBoxInfoItemValidFlags::LEFT, false );
1160 aSetBox.SetLine( nullptr, SvxBoxItemLine::LEFT );
1161 }
1162 }
1163 }
1164 else
1165 {
1166 if (aSetBoxInfo.IsValid(SvxBoxInfoItemValidFlags::VERT))
1167 {
1168 if ( !bVertSet )
1169 { bVertSet = true;
1170 aSetBoxInfo.SetLine( rBox.GetLeft(), SvxBoxInfoItemLine::VERT );
1171 }
1172 else if ((aSetBoxInfo.GetVert() && rBox.GetLeft() &&
1173 (*aSetBoxInfo.GetVert() != *rBox.GetLeft())) ||
1174 ((!aSetBoxInfo.GetVert()) != (!rBox.GetLeft())))
1175 { aSetBoxInfo.SetValid( SvxBoxInfoItemValidFlags::VERT, false );
1176 aSetBoxInfo.SetLine( nullptr, SvxBoxInfoItemLine::VERT );
1177 }
1178 }
1179 }
1180
1181 // Right Border
1182 if ( aSetBoxInfo.IsValid(SvxBoxInfoItemValidFlags::RIGHT) && bRightOver )
1183 {
1184 if ( !bRightSet )
1185 { bRightSet = true;
1186 aSetBox.SetLine( rBox.GetRight(), SvxBoxItemLine::RIGHT );
1187 }
1188 else if ((aSetBox.GetRight() && rBox.GetRight() &&
1189 (*aSetBox.GetRight() != *rBox.GetRight())) ||
1190 (!aSetBox.GetRight() != !rBox.GetRight()))
1191 { aSetBoxInfo.SetValid( SvxBoxInfoItemValidFlags::RIGHT, false );
1192 aSetBox.SetLine( nullptr, SvxBoxItemLine::RIGHT );
1193 }
1194 }
1195
1196 // Bottom Border
1197 if ( bLast && bBottomOver )
1198 {
1199 if ( aSetBoxInfo.IsValid(SvxBoxInfoItemValidFlags::BOTTOM) )
1200 {
1201 if ( !bBottomSet )
1202 { bBottomSet = true;
1203 aSetBox.SetLine( rBox.GetBottom(), SvxBoxItemLine::BOTTOM );
1204 }
1205 else if ((aSetBox.GetBottom() && rBox.GetBottom() &&
1206 (*aSetBox.GetBottom() != *rBox.GetBottom())) ||
1207 (!aSetBox.GetBottom() != !rBox.GetBottom()))
1208 { aSetBoxInfo.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, false );
1209 aSetBox.SetLine( nullptr, SvxBoxItemLine::BOTTOM );
1210 }
1211 }
1212 }
1213 // In all Lines, except for the last one, the horizontal Line
1214 // is taken from the Bottom Line.
1215 else
1216 {
1217 if (aSetBoxInfo.IsValid(SvxBoxInfoItemValidFlags::HORI))
1218 {
1219 if ( !bHoriSet )
1220 { bHoriSet = true;
1221 aSetBoxInfo.SetLine( rBox.GetBottom(), SvxBoxInfoItemLine::HORI );
1222 }
1223 else if ((aSetBoxInfo.GetHori() && rBox.GetBottom() &&
1224 (*aSetBoxInfo.GetHori() != *rBox.GetBottom())) ||
1225 ((!aSetBoxInfo.GetHori()) != (!rBox.GetBottom())))
1226 {
1227 aSetBoxInfo.SetValid( SvxBoxInfoItemValidFlags::HORI, false );
1228 aSetBoxInfo.SetLine( nullptr, SvxBoxInfoItemLine::HORI );
1229 }
1230 }
1231 }
1232
1233 // Distance to text
1234 if (aSetBoxInfo.IsValid(SvxBoxInfoItemValidFlags::DISTANCE))
1235 {
1236 if( !bDistanceSet ) // Set on first iteration
1237 {
1238 bDistanceSet = true;
1240 aSetBox.SetDistance( rBox.GetDistance( k ), k );
1241 }
1242 else
1243 {
1245 if( aSetBox.GetDistance( k ) !=
1246 rBox.GetDistance( k ) )
1247 {
1248 aSetBoxInfo.SetValid( SvxBoxInfoItemValidFlags::DISTANCE, false );
1249 aSetBox.SetAllDistances(0);
1250 break;
1251 }
1252 }
1253 }
1254 }
1255 }
1256
1257 // fdo#62470 fix the reading for table format.
1258 if ( bRTLTab )
1259 {
1260 SvxBoxItem aTempBox ( rSet.Get(RES_BOX ) );
1261 SvxBoxInfoItem aTempBoxInfo( rSet.Get(SID_ATTR_BORDER_INNER) );
1262
1263 aTempBox.SetLine( aSetBox.GetRight(), SvxBoxItemLine::RIGHT);
1264 aSetBox.SetLine( aSetBox.GetLeft(), SvxBoxItemLine::RIGHT);
1265 aSetBox.SetLine( aTempBox.GetRight(), SvxBoxItemLine::LEFT);
1266
1267 aTempBoxInfo.SetValid( SvxBoxInfoItemValidFlags::LEFT, aSetBoxInfo.IsValid(SvxBoxInfoItemValidFlags::LEFT) );
1268 aSetBoxInfo.SetValid( SvxBoxInfoItemValidFlags::LEFT, aSetBoxInfo.IsValid(SvxBoxInfoItemValidFlags::RIGHT) );
1269 aSetBoxInfo.SetValid( SvxBoxInfoItemValidFlags::RIGHT, aTempBoxInfo.IsValid(SvxBoxInfoItemValidFlags::LEFT) );
1270 }
1271
1272 rSet.Put( aSetBox );
1273 rSet.Put( aSetBoxInfo );
1274}
1275
1276void SwDoc::SetBoxAttr( const SwCursor& rCursor, const SfxPoolItem &rNew )
1277{
1278 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
1279 SwSelBoxes aBoxes;
1280 if( !(pTableNd && ::lcl_GetBoxSel( rCursor, aBoxes, true )) )
1281 return;
1282
1283 SwTable& rTable = pTableNd->GetTable();
1284 if (GetIDocumentUndoRedo().DoesUndo())
1285 {
1286 GetIDocumentUndoRedo().AppendUndo( std::make_unique<SwUndoAttrTable>(*pTableNd) );
1287 }
1288
1289 std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp;
1290 aFormatCmp.reserve(std::max<size_t>(255, aBoxes.size()));
1291 for (size_t i = 0; i < aBoxes.size(); ++i)
1292 {
1293 SwTableBox *pBox = aBoxes[i];
1294
1295 SwFrameFormat *pNewFormat = SwTableFormatCmp::FindNewFormat( aFormatCmp, pBox->GetFrameFormat(), 0 );
1296 if ( nullptr != pNewFormat )
1297 pBox->ChgFrameFormat( static_cast<SwTableBoxFormat*>(pNewFormat) );
1298 else
1299 {
1300 SwFrameFormat *pOld = pBox->GetFrameFormat();
1301 SwFrameFormat *pNew = pBox->ClaimFrameFormat();
1302 pNew->SetFormatAttr( rNew );
1303 aFormatCmp.push_back(std::make_unique<SwTableFormatCmp>(pOld, pNew, 0));
1304 }
1305
1306 pBox->SetDirectFormatting(true);
1307 }
1308
1309 SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
1310 if( pTableLayout )
1311 {
1313 SwTabFrame* pTabFrame = pFrame->ImplFindTabFrame();
1314
1315 pTableLayout->Resize(
1316 pTableLayout->GetBrowseWidthByTabFrame( *pTabFrame ), true );
1317 }
1319}
1320
1321bool SwDoc::GetBoxAttr( const SwCursor& rCursor, std::unique_ptr<SfxPoolItem>& rToFill )
1322{
1323 // tdf#144843 calling GetBoxAttr *requires* object
1324 assert(rToFill && "requires object here");
1325 bool bRet = false;
1326 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
1327 SwSelBoxes aBoxes;
1328 if( pTableNd && lcl_GetBoxSel( rCursor, aBoxes ))
1329 {
1330 bRet = true;
1331 bool bOneFound = false;
1332 const sal_uInt16 nWhich = rToFill->Which();
1333 for (size_t i = 0; i < aBoxes.size(); ++i)
1334 {
1335 switch ( nWhich )
1336 {
1337 case RES_BACKGROUND:
1338 {
1339 std::unique_ptr<SvxBrushItem> xBack =
1340 aBoxes[i]->GetFrameFormat()->makeBackgroundBrushItem();
1341 if( !bOneFound )
1342 {
1343 rToFill = std::move(xBack);
1344 bOneFound = true;
1345 }
1346 else if( *rToFill != *xBack )
1347 bRet = false;
1348 }
1349 break;
1350
1351 case RES_FRAMEDIR:
1352 {
1353 const SvxFrameDirectionItem& rDir =
1354 aBoxes[i]->GetFrameFormat()->GetFrameDir();
1355 if( !bOneFound )
1356 {
1357 rToFill.reset(rDir.Clone());
1358 bOneFound = true;
1359 }
1360 else if( rToFill && *rToFill != rDir )
1361 bRet = false;
1362 }
1363 break;
1364 case RES_VERT_ORIENT:
1365 {
1366 const SwFormatVertOrient& rOrient =
1367 aBoxes[i]->GetFrameFormat()->GetVertOrient();
1368 if( !bOneFound )
1369 {
1370 rToFill.reset(rOrient.Clone());
1371 bOneFound = true;
1372 }
1373 else if( rToFill && *rToFill != rOrient )
1374 bRet = false;
1375 }
1376 break;
1377 }
1378
1379 if ( !bRet )
1380 break;
1381 }
1382 }
1383 return bRet;
1384}
1385
1386void SwDoc::SetBoxAlign( const SwCursor& rCursor, sal_uInt16 nAlign )
1387{
1388 OSL_ENSURE( nAlign == text::VertOrientation::NONE ||
1389 nAlign == text::VertOrientation::CENTER ||
1390 nAlign == text::VertOrientation::BOTTOM, "Wrong alignment" );
1391 SwFormatVertOrient aVertOri( 0, nAlign );
1392 SetBoxAttr( rCursor, aVertOri );
1393}
1394
1395sal_uInt16 SwDoc::GetBoxAlign( const SwCursor& rCursor )
1396{
1397 sal_uInt16 nAlign = USHRT_MAX;
1398 SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode();
1399 SwSelBoxes aBoxes;
1400 if( pTableNd && ::lcl_GetBoxSel( rCursor, aBoxes ))
1401 {
1402 for (size_t i = 0; i < aBoxes.size(); ++i)
1403 {
1404 const SwFormatVertOrient &rOri =
1405 aBoxes[i]->GetFrameFormat()->GetVertOrient();
1406 if( USHRT_MAX == nAlign )
1407 nAlign = o3tl::narrowing<sal_uInt16>(rOri.GetVertOrient());
1408 else if( rOri.GetVertOrient() != nAlign )
1409 {
1410 nAlign = USHRT_MAX;
1411 break;
1412 }
1413 }
1414 }
1415 return nAlign;
1416}
1417
1418static sal_uInt16 lcl_CalcCellFit( const SwLayoutFrame *pCell )
1419{
1420 SwTwips nRet = 0;
1421 const SwFrame *pFrame = pCell->Lower(); // The whole Line
1422 SwRectFnSet aRectFnSet(pCell);
1423 while ( pFrame )
1424 {
1425 const SwTwips nAdd = aRectFnSet.GetWidth(pFrame->getFrameArea()) -
1426 aRectFnSet.GetWidth(pFrame->getFramePrintArea());
1427
1428 // pFrame does not necessarily have to be a SwTextFrame!
1429 const SwTwips nCalcFitToContent = pFrame->IsTextFrame() ?
1430 const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pFrame))->CalcFitToContent() :
1431 aRectFnSet.GetWidth(pFrame->getFramePrintArea());
1432
1433 nRet = std::max( nRet, nCalcFitToContent + nAdd );
1434 pFrame = pFrame->GetNext();
1435 }
1436 // Surrounding border as well as left and Right Border also need to be respected
1437 nRet += aRectFnSet.GetWidth(pCell->getFrameArea()) -
1438 aRectFnSet.GetWidth(pCell->getFramePrintArea());
1439
1440 // To compensate for the accuracy of calculation later on in SwTable::SetTabCols
1441 // we keep adding up a little.
1442 nRet += COLFUZZY;
1443 return o3tl::narrowing<sal_uInt16>(std::max( SwTwips(MINLAY), nRet ));
1444}
1445
1446/* The Line is within the Selection but not outlined by the TabCols.
1447 *
1448 * That means that the Line has been "split" by other Cells due to the
1449 * two-dimensional representation used. Thus, we have to distribute the cell's
1450 * default or minimum value amongst the Cell it has been split by.
1451 *
1452 * First, we collect the Columns (not the Column separators) which overlap
1453 * with the Cell. We then distribute the desired value according to the
1454 * amount of overlapping amongst the Cells.
1455 *
1456 * A Cell's default value stays the same if it already has a larger value than
1457 * the desired one. It's overwritten if it's smaller.
1458 */
1459static void lcl_CalcSubColValues( std::vector<sal_uInt16> &rToFill, const SwTabCols &rCols,
1460 const SwLayoutFrame *pCell, const SwLayoutFrame *pTab,
1461 bool bWishValues )
1462{
1463 const sal_uInt16 nWish = bWishValues ?
1464 ::lcl_CalcCellFit( pCell ) :
1465 MINLAY + sal_uInt16(pCell->getFrameArea().Width() - pCell->getFramePrintArea().Width());
1466
1467 SwRectFnSet aRectFnSet(pTab);
1468
1469 for ( size_t i = 0 ; i <= rCols.Count(); ++i )
1470 {
1471 tools::Long nColLeft = i == 0 ? rCols.GetLeft() : rCols[i-1];
1472 tools::Long nColRight = i == rCols.Count() ? rCols.GetRight() : rCols[i];
1473 nColLeft += rCols.GetLeftMin();
1474 nColRight += rCols.GetLeftMin();
1475
1476 // Adapt values to the proportions of the Table (Follows)
1477 if ( rCols.GetLeftMin() != aRectFnSet.GetLeft(pTab->getFrameArea()) )
1478 {
1479 const tools::Long nDiff = aRectFnSet.GetLeft(pTab->getFrameArea()) - rCols.GetLeftMin();
1480 nColLeft += nDiff;
1481 nColRight += nDiff;
1482 }
1483 const tools::Long nCellLeft = aRectFnSet.GetLeft(pCell->getFrameArea());
1484 const tools::Long nCellRight = aRectFnSet.GetRight(pCell->getFrameArea());
1485
1486 // Calculate overlapping value
1487 tools::Long nWidth = 0;
1488 if ( nColLeft <= nCellLeft && nColRight >= (nCellLeft+COLFUZZY) )
1489 nWidth = nColRight - nCellLeft;
1490 else if ( nColLeft <= (nCellRight-COLFUZZY) && nColRight >= nCellRight )
1491 nWidth = nCellRight - nColLeft;
1492 else if ( nColLeft >= nCellLeft && nColRight <= nCellRight )
1493 nWidth = nColRight - nColLeft;
1494 if ( nWidth && pCell->getFrameArea().Width() )
1495 {
1496 tools::Long nTmp = nWidth * nWish / pCell->getFrameArea().Width();
1497 if ( o3tl::make_unsigned(nTmp) > rToFill[i] )
1498 rToFill[i] = sal_uInt16(nTmp);
1499 }
1500 }
1501}
1502
1521static void lcl_CalcColValues( std::vector<sal_uInt16> &rToFill, const SwTabCols &rCols,
1522 const SwLayoutFrame *pStart, const SwLayoutFrame *pEnd,
1523 bool bWishValues )
1524{
1525 SwSelUnions aUnions;
1526 ::MakeSelUnions( aUnions, pStart, pEnd,
1528
1529 for ( auto &rU : aUnions )
1530 {
1531 SwSelUnion *pSelUnion = &rU;
1532 const SwTabFrame *pTab = pSelUnion->GetTable();
1533 const SwRect &rUnion = pSelUnion->GetUnion();
1534
1535 SwRectFnSet aRectFnSet(pTab);
1536 bool bRTL = pTab->IsRightToLeft();
1537
1538 const SwLayoutFrame *pCell = pTab->FirstCell();
1539 if (!pCell)
1540 continue;
1541 do
1542 {
1543 if ( pCell->IsCellFrame() && pCell->FindTabFrame() == pTab && ::IsFrameInTableSel( rUnion, pCell ) )
1544 {
1545 const tools::Long nCLeft = aRectFnSet.GetLeft(pCell->getFrameArea());
1546 const tools::Long nCRight = aRectFnSet.GetRight(pCell->getFrameArea());
1547
1548 bool bNotInCols = true;
1549
1550 for ( size_t i = 0; i <= rCols.Count(); ++i )
1551 {
1552 sal_uInt16 nFit = rToFill[i];
1553 tools::Long nColLeft = i == 0 ? rCols.GetLeft() : rCols[i-1];
1554 tools::Long nColRight = i == rCols.Count() ? rCols.GetRight() : rCols[i];
1555
1556 if ( bRTL )
1557 {
1558 tools::Long nTmpRight = nColRight;
1559 nColRight = rCols.GetRight() - nColLeft;
1560 nColLeft = rCols.GetRight() - nTmpRight;
1561 }
1562
1563 nColLeft += rCols.GetLeftMin();
1564 nColRight += rCols.GetLeftMin();
1565
1566 // Adapt values to the proportions of the Table (Follows)
1567 tools::Long nLeftA = nColLeft;
1568 tools::Long nRightA = nColRight;
1569 if ( rCols.GetLeftMin() != sal_uInt16(aRectFnSet.GetLeft(pTab->getFrameArea())) )
1570 {
1571 const tools::Long nDiff = aRectFnSet.GetLeft(pTab->getFrameArea()) - rCols.GetLeftMin();
1572 nLeftA += nDiff;
1573 nRightA += nDiff;
1574 }
1575
1576 // We don't want to take a too close look
1577 if ( ::IsSame(nCLeft, nLeftA) && ::IsSame(nCRight, nRightA))
1578 {
1579 bNotInCols = false;
1580 if ( bWishValues )
1581 {
1582 const sal_uInt16 nWish = ::lcl_CalcCellFit( pCell );
1583 if ( nWish > nFit )
1584 nFit = nWish;
1585 }
1586 else
1587 { const sal_uInt16 nMin = MINLAY + sal_uInt16(pCell->getFrameArea().Width() -
1588 pCell->getFramePrintArea().Width());
1589 if ( !nFit || nMin < nFit )
1590 nFit = nMin;
1591 }
1592 if ( rToFill[i] < nFit )
1593 rToFill[i] = nFit;
1594 }
1595 }
1596 if ( bNotInCols )
1597 ::lcl_CalcSubColValues( rToFill, rCols, pCell, pTab, bWishValues );
1598 }
1599 do {
1600 pCell = pCell->GetNextLayoutLeaf();
1601 } while( pCell && pCell->getFrameArea().Width() == 0 );
1602 } while ( pCell && pTab->IsAnLower( pCell ) );
1603 }
1604}
1605
1607 const bool bBalance,
1608 const bool bNoShrink )
1609{
1610 // Check whether the current Cursor has it's Point/Mark in a Table
1611 SwContentNode* pCntNd = rCursor.GetPoint()->GetNode().GetContentNode();
1612 SwTableNode* pTableNd = pCntNd ? pCntNd->FindTableNode() : nullptr;
1613 if( !pTableNd )
1614 return ;
1615
1616 SwLayoutFrame *pStart, *pEnd;
1617 ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
1618
1619 // Collect TabCols; we reset the Table with them
1620 SwFrame* pBoxFrame = pStart;
1621 while( pBoxFrame && !pBoxFrame->IsCellFrame() )
1622 pBoxFrame = pBoxFrame->GetUpper();
1623
1624 if ( !pBoxFrame )
1625 return; // Robust
1626
1627 SwTabCols aTabCols;
1628 GetTabCols( aTabCols, static_cast<SwCellFrame*>(pBoxFrame) );
1629
1630 if ( ! aTabCols.Count() )
1631 return;
1632
1633 std::vector<sal_uInt16> aWish(aTabCols.Count() + 1);
1634 std::vector<sal_uInt16> aMins(aTabCols.Count() + 1);
1635
1636 ::lcl_CalcColValues( aWish, aTabCols, pStart, pEnd, /*bWishValues=*/true );
1637
1638 // It's more robust if we calculate the minimum values for the whole Table
1639 const SwTabFrame *pTab = pStart->ImplFindTabFrame();
1640 pStart = const_cast<SwLayoutFrame*>(static_cast<SwLayoutFrame const *>(pTab->FirstCell()));
1641 pEnd = const_cast<SwLayoutFrame*>(pTab->FindLastContentOrTable()->GetUpper());
1642 while( !pEnd->IsCellFrame() )
1643 pEnd = pEnd->GetUpper();
1644 ::lcl_CalcColValues( aMins, aTabCols, pStart, pEnd, /*bWishValues=*/false );
1645
1646 sal_uInt16 nSelectedWidth = 0, nCols = 0;
1647 float fTotalWish = 0;
1648 if ( bBalance || bNoShrink )
1649 {
1650 // Find the combined size of the selected columns
1651 for ( size_t i = 0; i <= aTabCols.Count(); ++i )
1652 {
1653 if ( aWish[i] )
1654 {
1655 if ( i == 0 )
1656 nSelectedWidth += aTabCols[i] - aTabCols.GetLeft();
1657 else if ( i == aTabCols.Count() )
1658 nSelectedWidth += aTabCols.GetRight() - aTabCols[i-1];
1659 else
1660 nSelectedWidth += aTabCols[i] - aTabCols[i-1];
1661 ++nCols;
1662 }
1663 fTotalWish += aWish[i];
1664 }
1665 // bBalance: Distribute the width evenly
1666 if (bBalance)
1667 {
1668 assert(nCols);
1669 const sal_uInt16 nEqualWidth = nCols ? nSelectedWidth / nCols : 0;
1670 for (sal_uInt16 & rn : aWish)
1671 if (rn)
1672 rn = nEqualWidth;
1673 }
1674 }
1675
1676 const tools::Long nOldRight = aTabCols.GetRight();
1677
1678 // In order to make the implementation easier, but still use the available
1679 // space properly, we do this twice.
1680
1681 // The problem: The first column is getting wider, the others get slimmer
1682 // only afterwards.
1683 // The first column's desired width would be discarded as it would cause
1684 // the Table's width to exceed the maximum width.
1685 const tools::Long nMaxRight = std::max(aTabCols.GetRightMax(), nOldRight);
1686 const sal_uInt16 nEqualWidth = (nMaxRight - aTabCols.GetLeft()) / (aTabCols.Count() + 1);
1687 const sal_Int16 nTablePadding = nSelectedWidth - fTotalWish;
1688 for ( int k = 0; k < 2; ++k )
1689 {
1690 for ( size_t i = 0; i <= aTabCols.Count(); ++i )
1691 {
1692 // bNoShrink: distribute excess space proportionately on pass 2.
1693 if ( bNoShrink && k && nTablePadding > 0 && fTotalWish > 0 )
1694 aWish[i] += round( aWish[i] / fTotalWish * nTablePadding );
1695
1696 // First pass is primarily a shrink pass. Give all columns a chance
1697 // to grow by requesting the maximum width as "balanced".
1698 // Second pass is a first-come, first-served chance to max out.
1699 int nDiff = k ? aWish[i] : std::min(aWish[i], nEqualWidth);
1700 if ( nDiff )
1701 {
1702 int nMin = aMins[i];
1703 if ( nMin > nDiff )
1704 nDiff = nMin;
1705
1706 if ( i == 0 )
1707 {
1708 if( aTabCols.Count() )
1709 nDiff -= aTabCols[0] - aTabCols.GetLeft();
1710 else
1711 nDiff -= aTabCols.GetRight() - aTabCols.GetLeft();
1712 }
1713 else if ( i == aTabCols.Count() )
1714 nDiff -= aTabCols.GetRight() - aTabCols[i-1];
1715 else
1716 nDiff -= aTabCols[i] - aTabCols[i-1];
1717
1718 tools::Long nTabRight = aTabCols.GetRight() + nDiff;
1719
1720 // If the Table would become (or is already) too wide,
1721 // restrict the column growth to the allowed maximum.
1722 if (!bBalance && nTabRight > nMaxRight)
1723 {
1724 const tools::Long nTmpD = nTabRight - nMaxRight;
1725 nDiff -= nTmpD;
1726 nTabRight -= nTmpD;
1727 }
1728
1729 // all the remaining columns need to be shifted by the same amount
1730 for ( size_t i2 = i; i2 < aTabCols.Count(); ++i2 )
1731 aTabCols[i2] += nDiff;
1732 aTabCols.SetRight( nTabRight );
1733 }
1734 }
1735 }
1736
1737 const tools::Long nNewRight = aTabCols.GetRight();
1738
1739 SwFrameFormat *pFormat = pTableNd->GetTable().GetFrameFormat();
1740 const sal_Int16 nOriHori = pFormat->GetHoriOrient().GetHoriOrient();
1741
1742 // We can leave the "real" work to the SwTable now
1743 SetTabCols( aTabCols, false, static_cast<SwCellFrame*>(pBoxFrame) );
1744
1745 // Alignment might have been changed in SetTabCols; restore old value
1746 const SwFormatHoriOrient &rHori = pFormat->GetHoriOrient();
1747 SwFormatHoriOrient aHori( rHori );
1748 if ( aHori.GetHoriOrient() != nOriHori )
1749 {
1750 aHori.SetHoriOrient( nOriHori );
1751 pFormat->SetFormatAttr( aHori );
1752 }
1753
1754 // We switch to left-adjusted for automatic width
1755 // We adjust the right border for Border attributes
1756 if( !bBalance && nNewRight < nOldRight )
1757 {
1758 if( aHori.GetHoriOrient() == text::HoriOrientation::FULL )
1759 {
1760 aHori.SetHoriOrient( text::HoriOrientation::LEFT );
1761 pFormat->SetFormatAttr( aHori );
1762 }
1763 }
1764
1766}
1767
1768/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ NONE
no RedlineFlags
SvxBoxItemLine
const FndLines_t & GetLines() const
Definition: tblsel.hxx:172
const SwTableBox * GetBox() const
Definition: tblsel.hxx:174
const FndBoxes_t & GetBoxes() const
Definition: tblsel.hxx:202
virtual bool DeleteAndJoin(SwPaM &, SwDeleteFlags flags=SwDeleteFlags::Default)=0
complete delete of a given PaM
virtual bool InsertString(const SwPaM &rRg, const OUString &, const SwInsertFlags nInsertMode=SwInsertFlags::EMPTYEXPAND)=0
Insert string into existing text node at position rRg.Point().
virtual const SwRootFrame * GetCurrentLayout() const =0
virtual std::size_t GetRedlineAuthor()=0
virtual void SetRedlineFlags_intern(RedlineFlags eMode)=0
Set a new redline mode.
virtual const SwRedlineTable & GetRedlineTable() const =0
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
virtual void SetModified()=0
Must be called manually at changes of format.
bool GetValue() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
static const sal_Int16 VeryThin
bool IsValid(SvxBoxInfoItemValidFlags nValid) const
const editeng::SvxBorderLine * GetHori() const
const editeng::SvxBorderLine * GetVert() const
void SetValid(SvxBoxInfoItemValidFlags nValid, bool bValid=true)
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxInfoItemLine nLine)
const editeng::SvxBorderLine * GetTop() const
virtual SvxBoxItem * Clone(SfxItemPool *pPool=nullptr) const override
const editeng::SvxBorderLine * GetRight() const
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxItemLine nLine)
const editeng::SvxBorderLine * GetLeft() const
sal_Int16 GetDistance(SvxBoxItemLine nLine, bool bAllowNegative=false) const
void SetDistance(sal_Int16 nNew, SvxBoxItemLine nLine)
const editeng::SvxBorderLine * GetBottom() const
void SetAllDistances(sal_Int16 nNew)
virtual SvxFrameDirectionItem * Clone(SfxItemPool *pPool=nullptr) const override
tools::Long GetHeight() const
void SetHeight(tools::Long n)
SwCellFrame is one table cell in the document layout.
Definition: cellfrm.hxx:31
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1223
Definition: doc.hxx:197
void SetRowHeight(const SwCursor &rCursor, const SwFormatFrameSize &rNew)
Definition: ndtbl1.cxx:389
void SetTabLineStyle(const SwCursor &rCursor, const Color *pColor, bool bSetLine, const editeng::SvxBorderLine *pBorderLine)
Definition: ndtbl1.cxx:968
static sal_uInt16 GetBoxAlign(const SwCursor &rCursor)
Definition: ndtbl1.cxx:1395
void SetRowSplit(const SwCursor &rCursor, const SwFormatRowSplit &rNew)
Definition: ndtbl1.cxx:324
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:408
bool BalanceRowHeight(const SwCursor &rCursor, bool bTstOnly, const bool bOptimize)
Adjustment of Rowheights.
Definition: ndtbl1.cxx:436
static bool GetRowBackground(const SwCursor &rCursor, std::unique_ptr< SvxBrushItem > &rToFill)
Definition: ndtbl1.cxx:515
static bool GetBoxAttr(const SwCursor &rCursor, std::unique_ptr< SfxPoolItem > &rToFill)
Retrieves a box attribute from the given cursor.
Definition: ndtbl1.cxx:1321
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:329
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:158
static std::unique_ptr< SwFormatFrameSize > GetRowHeight(const SwCursor &rCursor)
Definition: ndtbl1.cxx:414
void SetRowNotTracked(const SwCursor &rCursor, const SvxPrintItem &rNotTracked, bool bAll=false, bool bIns=false)
rNotTracked = false means that the row was deleted or inserted with its tracked cell content bAll: de...
Definition: ndtbl1.cxx:581
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:349
static std::unique_ptr< SwFormatRowSplit > GetRowSplit(const SwCursor &rCursor)
Definition: ndtbl1.cxx:350
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
void SetTabCols(const SwTabCols &rNew, bool bCurRowOnly, const SwCellFrame *pBoxFrame)
Definition: ndtbl.cxx:2728
static void GetTabCols(SwTabCols &rFill, const SwCellFrame *pBoxFrame)
Definition: ndtbl.cxx:2539
void SetTabBorders(const SwCursor &rCursor, const SfxItemSet &rSet)
Definition: ndtbl1.cxx:688
void SetBoxAlign(const SwCursor &rCursor, sal_uInt16 nAlign)
Definition: ndtbl1.cxx:1386
void AdjustCellWidth(const SwCursor &rCursor, const bool bBalance, const bool bNoShrink)
Adjusts selected cell widths in such a way, that their content does not need to be wrapped (if possib...
Definition: ndtbl1.cxx:1606
static bool HasRowNotTracked(const SwCursor &rCursor)
don't call SetRowNotTracked() for rows with tracked row change
Definition: ndtbl1.cxx:545
void SetBoxAttr(const SwCursor &rCursor, const SfxPoolItem &rNew)
Definition: ndtbl1.cxx:1276
void SetRowBackground(const SwCursor &rCursor, const SvxBrushItem &rNew)
Definition: ndtbl1.cxx:489
static void GetTabBorders(const SwCursor &rCursor, SfxItemSet &rSet)
Definition: ndtbl1.cxx:1059
Defines the horizontal position of a fly frame.
Definition: fmtornt.hxx:73
void SetHoriOrient(sal_Int16 eNew)
Definition: fmtornt.hxx:96
sal_Int16 GetHoriOrient() const
Definition: fmtornt.hxx:94
Controls if a table row is allowed to split or not.
Definition: fmtrowsplt.hxx:32
Defines the vertical position of a fly frame.
Definition: fmtornt.hxx:37
virtual SwFormatVertOrient * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrfrm.cxx:1386
sal_Int16 GetVertOrient() const
Definition: fmtornt.hxx:57
const SvxBoxItem & GetBox(bool=true) const
Definition: frmatr.hxx:108
const SwFormatHoriOrient & GetHoriOrient(bool=true) const
Definition: fmtornt.hxx:115
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:447
const SwRect & getFrameArea() const
Definition: frame.hxx:179
const SwRect & getFramePrintArea() const
Definition: frame.hxx:180
Style of a layout element.
Definition: frmfmt.hxx:72
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool IsCellFrame() const
Definition: frame.hxx:1232
bool IsTextFrame() const
Definition: frame.hxx:1240
SwTabFrame * FindTabFrame()
Definition: frame.hxx:1105
SwFrame * GetNext()
Definition: frame.hxx:682
SwTabFrame * ImplFindTabFrame()
Definition: findfrm.cxx:554
bool IsRightToLeft() const
Definition: frame.hxx:993
SwLayoutFrame * GetUpper()
Definition: frame.hxx:684
const SwLayoutFrame * GetNextLayoutLeaf() const
Definition: frame.hxx:1026
bool IsVertical() const
Definition: frame.hxx:979
sal_uInt16 GetBrowseWidthByTabFrame(const SwTabFrame &rTabFrame) const
Calculates available width by table-frame.
Definition: htmltbl.cxx:343
bool Resize(sal_uInt16 nAbsAvail, bool bRecalc=false, bool bForce=false, sal_uLong nDelay=0)
Recalculation of table widths for available width that has been passed.
Definition: htmltbl.cxx:1697
void BordersChanged(sal_uInt16 nAbsAvail)
Definition: htmltbl.cxx:1767
TElementType * Next()
Definition: calbck.hxx:380
TElementType * First()
Definition: calbck.hxx:372
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame.
Definition: layfrm.hxx:36
const SwCellFrame * FirstCell() const
Calls ContainsAny first to reach the innermost cell.
Definition: findfrm.cxx:118
bool IsAnLower(const SwFrame *) const
Definition: findfrm.cxx:233
const SwFrame * Lower() const
Definition: layfrm.hxx:101
Marks a node in the document model.
Definition: ndindex.hxx:31
Base class of the Writer document model elements.
Definition: node.hxx:98
SwNodeOffset GetIndex() const
Definition: node.hxx:312
const SwStartNode * FindTableBoxStartNode() const
Definition: node.hxx:218
SwDoc & GetDoc()
Definition: node.hxx:233
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:380
SwContentNode * GetContentNode()
Definition: node.hxx:666
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
SwNode & GetPointNode() const
Definition: pam.hxx:275
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:643
SwContentNode * GetPointContentNode() const
Definition: pam.hxx:279
SwPaM * GetNext()
Definition: pam.hxx:314
SwContentNode * GetMarkContentNode() const
Definition: pam.hxx:280
OUString GetText() const
Definition: pam.cxx:1305
const SwPosition * GetPoint() const
Definition: pam.hxx:253
RedlineType GetType(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1975
const SwRedlineData & GetRedlineData(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1998
tools::Long GetWidth(const SwRect &rRect) const
Definition: frame.hxx:1386
tools::Long GetLeft(const SwRect &rRect) const
Definition: frame.hxx:1384
tools::Long GetRight(const SwRect &rRect) const
Definition: frame.hxx:1385
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Height(tools::Long nNew)
Definition: swrect.hxx:193
void Top(const tools::Long nTop)
Definition: swrect.hxx:206
void Right(const tools::Long nRight)
Definition: swrect.hxx:202
void Bottom(const tools::Long nBottom)
Definition: swrect.hxx:211
bool Overlaps(const SwRect &rRect) const
Definition: swrect.hxx:374
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
void Width(tools::Long nNew)
Definition: swrect.hxx:189
std::size_t GetAuthor() const
Definition: redline.hxx:128
static constexpr size_type npos
Definition: docary.hxx:224
vector_type::size_type size_type
Definition: docary.hxx:223
const SwRect & GetUnion() const
Definition: tblsel.hxx:130
const SwTabFrame * GetTable() const
Definition: tblsel.hxx:132
Represents the current text cursor of one opened edit window.
Definition: viscrs.hxx:140
const Point & GetPtPos() const
Definition: viscrs.hxx:165
const Point & GetMkPos() const
Definition: viscrs.hxx:167
size_t Count() const
Definition: tabcol.hxx:65
tools::Long GetLeft() const
Definition: tabcol.hxx:78
tools::Long GetLeftMin() const
Definition: tabcol.hxx:77
tools::Long GetRight() const
Definition: tabcol.hxx:79
tools::Long GetRightMax() const
Definition: tabcol.hxx:80
SwTabFrame is one table in the document layout, containing rows (which contain cells).
Definition: tabfrm.hxx:49
SwFrame * FindLastContentOrTable()
Definition: tabfrm.cxx:3652
bool IsInHeadline(const SwFrame &rFrame) const
Definition: tabfrm.cxx:5966
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
SwTableLine * GetUpper()
Definition: swtable.hxx:477
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:481
SwTableLines & GetTabLines()
Definition: swtable.hxx:474
void SetDirectFormatting(bool bDirect)
Set that this table box contains formatting that is not set by the table style.
Definition: swtable.hxx:485
void ChgFrameFormat(SwTableBoxFormat *pNewFormat, bool bNeedToReregister=true)
Definition: swtable.cxx:2130
SwFrameFormat * ClaimFrameFormat()
Definition: swtable.cxx:2094
SwTableLine is one table row in the document model.
Definition: swtable.hxx:376
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:398
void ChgFrameFormat(SwTableLineFormat *pNewFormat)
Definition: swtable.cxx:1515
SwFrameFormat * ClaimFrameFormat()
Definition: swtable.cxx:1482
SwTableBoxes & GetTabBoxes()
Definition: swtable.hxx:386
SwTableBox * GetUpper()
Definition: swtable.hxx:394
size_type size() const
Definition: swtable.hxx:76
iterator end()
Definition: swtable.hxx:79
iterator insert(iterator aIt, SwTableLine *pLine)
Definition: swtable.hxx:86
iterator begin()
Definition: swtable.hxx:77
bool empty() const
Definition: swtable.hxx:75
const SwTable & GetTable() const
Definition: node.hxx:542
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
SwTableLines & GetTabLines()
Definition: swtable.hxx:206
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:209
SwHTMLTableLayout * GetHTMLTableLayout()
Definition: swtable.hxx:182
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:168
SwTwips CalcFitToContent()
Simulates a formatting as if there were not right margin or Flys or other obstacles and returns the w...
Definition: txtfrm.cxx:3518
bool empty() const
size_type size() const
std::pair< const_iterator, bool > insert(Value &&x)
void ClearFEShellTabCols(SwDoc &rDoc, SwTabFrame const *const pFrame)
Definition: fetab.cxx:2266
@ Minimum
Value in Var-direction gives minimum (can be exceeded but not be less).
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(126)
constexpr TypedWhichId< SwFormatVertOrient > RES_VERT_ORIENT(108)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(111)
constexpr TypedWhichId< SvxBoxItem > RES_BOX(112)
#define CH_TXT_TRACKED_DUMMY_CHAR
Definition: hintids.hxx:191
constexpr TypedWhichId< SvxPrintItem > RES_PRINT(104)
const SfxPoolItem * GetDfltAttr(sal_uInt16 nWhich)
Get the default attribute from corresponding default attribute table.
Definition: hints.cxx:147
sal_uInt16 nPos
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
long Long
static void lcl_GetStartEndCell(const SwCursor &rCursor, SwLayoutFrame *&prStart, SwLayoutFrame *&prEnd)
Definition: ndtbl1.cxx:118
static bool lcl_GetBoxSel(const SwCursor &rCursor, SwSelBoxes &rBoxes, bool bAllCursor=false)
Definition: ndtbl1.cxx:145
static bool FindBox_(FndBox_ &rBox, LinesAndTable *pPara)
Definition: ndtbl1.cxx:204
static void InsertLine(std::vector< SwTableLine * > &rLineArr, SwTableLine *pLine)
Definition: ndtbl1.cxx:169
#define COLFUZZY
Definition: ndtbl1.cxx:61
static void lcl_CalcColValues(std::vector< sal_uInt16 > &rToFill, const SwTabCols &rCols, const SwLayoutFrame *pStart, const SwLayoutFrame *pEnd, bool bWishValues)
Retrieves new values to set the TabCols.
Definition: ndtbl1.cxx:1521
static bool IsSame(tools::Long nA, tools::Long nB)
Definition: ndtbl1.cxx:63
static void lcl_CollectCells(std::vector< SwCellFrame * > &rArr, const SwRect &rUnion, SwTabFrame *pTab)
Definition: ndtbl1.cxx:665
static sal_uInt16 lcl_CalcCellFit(const SwLayoutFrame *pCell)
Definition: ndtbl1.cxx:1418
static bool lcl_IsAnLower(const SwTableLine *pLine, const SwTableLine *pAssumed)
Definition: ndtbl1.cxx:175
static void lcl_SetLineStyle(SvxBorderLine *pToSet, const Color *pColor, const SvxBorderLine *pBorderLine)
Definition: ndtbl1.cxx:950
static bool FindLine_(FndLine_ &rLine, LinesAndTable *pPara)
Definition: ndtbl1.cxx:235
static void lcl_CollectLines(std::vector< SwTableLine * > &rArr, const SwCursor &rCursor, bool bRemoveLines)
Definition: ndtbl1.cxx:244
static void InsertCell(std::vector< SwCellFrame * > &rCellArr, SwCellFrame *pCellFrame)
Definition: ndtbl1.cxx:659
static void lcl_ProcessBoxSize(std::vector< std::unique_ptr< SwTableFormatCmp > > &rFormatCmp, SwTableBox *pBox, const SwFormatFrameSize &rNew)
Definition: ndtbl1.cxx:311
static void lcl_ProcessRowAttr(std::vector< std::unique_ptr< SwTableFormatCmp > > &rFormatCmp, SwTableLine *pLine, const SfxPoolItem &rNew)
Definition: ndtbl1.cxx:284
static void lcl_CalcSubColValues(std::vector< sal_uInt16 > &rToFill, const SwTabCols &rCols, const SwLayoutFrame *pCell, const SwLayoutFrame *pTab, bool bWishValues)
Definition: ndtbl1.cxx:1459
static void lcl_ProcessRowSize(std::vector< std::unique_ptr< SwTableFormatCmp > > &rFormatCmp, SwTableLine *pLine, const SwFormatFrameSize &rNew)
Definition: ndtbl1.cxx:302
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
SwNodeOffset abs(const SwNodeOffset &a)
Definition: nodeoffset.hxx:34
QPRO_FUNC_TYPE nType
static SfxItemSet & rSet
SwNode & GetNode() const
Definition: pam.hxx:81
std::vector< SwTableBox * > SwTableBoxes
Definition: swtable.hxx:105
#define MINLAY
Definition: swtypes.hxx:62
tools::Long SwTwips
Definition: swtypes.hxx:51
ITableControl & m_rTable
void ForEach_FndLineCopyCol(SwTableLines &rLines, FndPara *pFndPara)
This creates a structure mirroring the SwTable structure that contains all rows and non-leaf boxes (a...
Definition: tblsel.cxx:2090
void GetTableSelCrs(const SwCursorShell &rShell, SwSelBoxes &rBoxes)
Definition: tblsel.cxx:124
void MakeSelUnions(SwSelUnions &rUnions, const SwLayoutFrame *pStart, const SwLayoutFrame *pEnd, const SwTableSearchType eSearchType)
Definition: tblsel.cxx:1765
bool IsFrameInTableSel(const SwRect &rUnion, const SwFrame *pCell)
Definition: tblsel.cxx:668
std::vector< SwSelUnion > SwSelUnions
Definition: tblsel.hxx:138