22#include <com/sun/star/lang/NoSupportException.hpp>
28#include <svx/strings.hrc>
97 if(
mnRight >= mxTable->getColumnCount() )
101 if(
mnTop >= mxTable->getRowCount() )
131 mnLeft = mxTable->getColumnCount() - 1;
144 const sal_Int32 nLeft =
mnLeft + nColumnOffset;
145 if( (nLeft >= 0) && (nLeft < mxTable->getColumnCount() ) )
148 const sal_Int32 nTop =
mnTop + nRowOffset;
149 if( (nTop >= 0) && (nTop < mxTable->getRowCount()) )
171 if( xCell.is() && xCell->isMerged() )
175 xCell.set(
dynamic_cast< Cell*
>( mxTable->getCellByPosition(
mnRight,
mnBottom ).get() ) );
178 if( xCell->isMerged() )
184 xCell.set(
dynamic_cast< Cell*
>( mxTable->getCellByPosition( rEnd.
mnCol, rEnd.
mnRow ).get() ) );
189 rEnd.
mnCol += xCell->getColumnSpan()-1;
190 rEnd.
mnRow += xCell->getRowSpan()-1;
194 sal_Int32 nRow, nCol;
195 for( nRow = rStart.
mnRow; nRow <= rEnd.
mnRow; nRow++ )
197 for( nCol = rStart.
mnCol; nCol <= rEnd.
mnCol; nCol++ )
199 xCell.set(
dynamic_cast< Cell*
>( mxTable->getCellByPosition( nCol, nRow ).get() ) );
203 if( xCell->isMerged() )
205 sal_Int32 nOriginCol, nOriginRow;
208 if( (nOriginCol < rStart.
mnCol) || (nOriginRow < rStart.
mnRow) )
211 xCell.set(
dynamic_cast< Cell*
>( mxTable->getCellByPosition( nOriginCol, nOriginRow ).get() ) );
214 nOriginCol += xCell->getColumnSpan()-1;
215 nOriginRow += xCell->getRowSpan()-1;
217 if( (nOriginCol > rEnd.
mnCol) || (nOriginRow > rEnd.
mnRow) )
222 else if( ((nCol + xCell->getColumnSpan() - 1) > rEnd.
mnCol) || ((nRow + xCell->getRowSpan() - 1 ) > rEnd.
mnRow) )
242 throw NoSupportException();
244 if( !mxTable.is() || (mxTable->getSdrTableObj() ==
nullptr) )
245 throw DisposedException();
247 SdrModel& rModel(mxTable->getSdrTableObj()->getSdrModelFromSdrObject());
248 const bool bUndo(mxTable->getSdrTableObj()->IsInserted() && rModel.
IsUndoEnabled());
257 mxTable->setModified(
true);
273 const sal_Int32 nRowCount = mxTable->getRowCount();
275 sal_Int32 nNewCols = 0, nRow;
280 CellRef xCell(
dynamic_cast< Cell*
>( mxTable->getCellByPosition( nCol, nRow ).get() ) );
281 if( xCell.is() && !xCell->isMerged() )
282 nNewCols = std::max( nNewCols, nColumns - xCell->getColumnSpan() + 1 - rLeftOvers[nRow] );
287 static constexpr OUStringLiteral sWidth(
u"Width");
288 Reference< XTableColumns > xCols( mxTable->getColumns(), UNO_SET_THROW );
289 Reference< XPropertySet > xRefColumn( xCols->getByIndex( nCol ), UNO_QUERY_THROW );
290 sal_Int32 nWidth = 0;
291 xRefColumn->getPropertyValue( sWidth ) >>= nWidth;
292 const sal_Int32 nNewWidth = nWidth / (nNewCols + 1);
295 xRefColumn->setPropertyValue( sWidth,
Any( nWidth - (nNewWidth * nNewCols) ) );
297 xCols->insertByIndex( nCol + 1, nNewCols );
301 for( sal_Int32 nNewCol = nCol + nNewCols; nNewCol > nCol; --nNewCol )
303 Reference< XPropertySet > xNewCol( xCols->getByIndex( nNewCol ), UNO_QUERY_THROW );
304 xNewCol->setPropertyValue( sWidth,
Any( nNewWidth ) );
308 for( nRow = 0; nRow < nRowCount; ++nRow )
310 CellRef xCell(
dynamic_cast< Cell*
>( mxTable->getCellByPosition( nCol, nRow ).get() ) );
311 if( !xCell.is() || xCell->isMerged() )
316 xCell.set(
dynamic_cast< Cell*
>(mxTable->getCellByPosition( nCol+1, nRow ).get() ) );
317 if( !xCell.is() || !xCell->isMerged() )
318 rLeftOvers[nRow] += nNewCols;
323 sal_Int32 nRowSpan = xCell->getRowSpan() - 1;
324 sal_Int32 nColSpan = xCell->getColumnSpan() - 1;
328 sal_Int32 nCellsAvailable = 1 + nColSpan + rLeftOvers[nRow];
330 nCellsAvailable += nNewCols;
332 DBG_ASSERT( nCellsAvailable > nColumns,
"sdr::table::CellCursor::split_column(), somethings wrong" );
334 sal_Int32 nSplitSpan = (nCellsAvailable / (nColumns + 1)) - 1;
336 sal_Int32 nSplitCol = nCol;
337 sal_Int32 nSplits = nColumns + 1;
342 nSplitSpan = nCellsAvailable - ((nSplitSpan+1) * nColumns) - 1;
344 mxTable->merge( nSplitCol, nRow, nSplitSpan + 1, nRowSpan + 1);
346 nSplitCol += nSplitSpan + 1;
351 rLeftOvers[nRow++] = 0;
359 if( nColSpan < (rLeftOvers[nRow] + nNewCols) )
360 mxTable->merge( nCol, nRow, (rLeftOvers[nRow] + nNewCols) + 1, nRowSpan + 1 );
364 rLeftOvers[nRow++] = 0;
376 const sal_Int32 nRowCount = mxTable->getRowCount();
378 std::vector< sal_Int32 > aLeftOvers( nRowCount );
387 const sal_Int32 nColCount = mxTable->getColumnCount();
389 sal_Int32 nNewRows = 0, nCol;
394 CellRef xCell(
dynamic_cast< Cell*
>( mxTable->getCellByPosition( nCol, nRow ).get() ) );
395 if( xCell.is() && !xCell->isMerged() )
396 nNewRows = std::max( nNewRows, nRows - xCell->getRowSpan() + 1 - rLeftOvers[nCol] );
401 static constexpr OUStringLiteral sHeight(
u"Height");
402 Reference< XTableRows > xRows( mxTable->getRows(), UNO_SET_THROW );
403 Reference< XPropertySet > xRefRow( xRows->getByIndex( nRow ), UNO_QUERY_THROW );
404 sal_Int32 nHeight = 0;
405 xRefRow->getPropertyValue( sHeight ) >>= nHeight;
406 const sal_Int32 nNewHeight = nHeight / (nNewRows + 1);
409 xRefRow->setPropertyValue( sHeight,
Any( nHeight - (nNewHeight * nNewRows) ) );
411 xRows->insertByIndex( nRow + 1, nNewRows );
415 for( sal_Int32 nNewRow = nRow + nNewRows; nNewRow > nRow; --nNewRow )
417 Reference< XPropertySet > xNewRow( xRows->getByIndex( nNewRow ), UNO_QUERY_THROW );
418 xNewRow->setPropertyValue( sHeight,
Any( nNewHeight ) );
422 for( nCol = 0; nCol < nColCount; ++nCol )
424 CellRef xCell(
dynamic_cast< Cell*
>( mxTable->getCellByPosition( nCol, nRow ).get() ) );
425 if( !xCell.is() || xCell->isMerged() )
430 xCell.set(
dynamic_cast< Cell*
>(mxTable->getCellByPosition( nCol, nRow+1 ).get() ) );
431 if( !xCell.is() || !xCell->isMerged() )
432 rLeftOvers[nCol] += nNewRows;
437 sal_Int32 nRowSpan = xCell->getRowSpan() - 1;
438 sal_Int32 nColSpan = xCell->getColumnSpan() - 1;
442 sal_Int32 nCellsAvailable = 1 + nRowSpan + rLeftOvers[nCol];
444 nCellsAvailable += nNewRows;
446 DBG_ASSERT( nCellsAvailable > nRows,
"sdr::table::CellCursor::split_row(), somethings wrong" );
448 sal_Int32 nSplitSpan = (nCellsAvailable / (nRows + 1)) - 1;
450 sal_Int32 nSplitRow = nRow;
451 sal_Int32 nSplits = nRows + 1;
456 nSplitSpan = nCellsAvailable - ((nSplitSpan+1) * nRows) - 1;
458 mxTable->merge( nCol, nSplitRow, nColSpan + 1, nSplitSpan + 1 );
460 nSplitRow += nSplitSpan + 1;
465 rLeftOvers[nCol++] = 0;
473 if( nRowSpan < (rLeftOvers[nCol] + nNewRows) )
474 mxTable->merge( nCol, nRow, nColSpan + 1, (rLeftOvers[nCol] + nNewRows) + 1 );
478 rLeftOvers[nCol++] = 0;
490 const sal_Int32 nColCount = mxTable->getColumnCount();
492 std::vector< sal_Int32 > aLeftOvers( nColCount );
501 if( (nColumns < 0) || (nRows < 0) )
502 throw IllegalArgumentException();
504 if( !mxTable.is() || (mxTable->getSdrTableObj() ==
nullptr) )
505 throw DisposedException();
507 SdrModel& rModel(mxTable->getSdrTableObj()->getSdrModelFromSdrObject());
508 const bool bUndo(mxTable->getSdrTableObj()->IsInserted() && rModel.
IsUndoEnabled());
521 if( nColumns > 0 ||nRows > 0 )
522 mxTable->setModified(
true);
527 throw NoSupportException();
virtual void SetChanged(bool bFlg=true)
bool IsUndoEnabled() const
returns true if undo is currently enabled This returns false if undo was disabled using EnableUndo( f...
virtual void SAL_CALL gotoStart() override
virtual void SAL_CALL gotoOffset(::sal_Int32 nColumnOffset, ::sal_Int32 nRowOffset) override
virtual void SAL_CALL split(::sal_Int32 Columns, ::sal_Int32 Rows) override
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName(const OUString &aRange) override
virtual ~CellCursor() override
virtual void SAL_CALL merge() override
virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow) override
virtual void SAL_CALL gotoEnd() override
void split_horizontal(sal_Int32 nColumns)
virtual void SAL_CALL gotoPrevious() override
CellCursor(const TableModelRef &xTableModel, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom)
virtual sal_Bool SAL_CALL isMergeable() override
bool GetMergedSelection(CellPos &rStart, CellPos &rEnd)
returns true and the merged cell positions if a merge is valid or false if a merge is not valid for t...
void split_row(sal_Int32 nRow, sal_Int32 nRows, std::vector< sal_Int32 > &rLeftOvers)
void split_column(sal_Int32 nCol, sal_Int32 nColumns, std::vector< sal_Int32 > &rLeftOvers)
virtual void SAL_CALL gotoNext() override
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition(sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom) override
void split_vertical(sal_Int32 nRows)
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName(const OUString &aRange) override
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition(sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom) override
virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow) override
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
OUString SvxResId(TranslateId aId)
bool findMergeOrigin(const TableModelRef &xTable, sal_Int32 nMergedX, sal_Int32 nMergedY, sal_Int32 &rOriginX, sal_Int32 &rOriginY)
returns true if the cell(nMergedX,nMergedY) is merged with other cells.
::cppu::ImplInheritanceHelper< CellRange, css::table::XCellCursor, css::table::XMergeableCellRange > CellCursorBase