46 auto cellBlockSelection = [](
const SELECTION& sel )
51 int colMin = std::numeric_limits<int>::max();
53 int rowMin = std::numeric_limits<int>::max();
59 if( T_TABLECELL* cell =
dynamic_cast<T_TABLECELL*
>( item ) )
61 colMin = std::min( colMin, cell->GetColumn() );
62 colMax = std::max( colMax, cell->GetColumn() + cell->GetColSpan() );
63 rowMin = std::min( rowMin, cell->GetRow() );
64 rowMax = std::max( rowMax, cell->GetRow() + cell->GetRowSpan() );
66 selectedArea += cell->GetColSpan() * cell->GetRowSpan();
70 return selectedArea == ( colMax - colMin ) * ( rowMax - rowMin );
73 auto structureEditable = [
this](
const SELECTION& sel )
78 auto mergedCellsSelection = [](
const SELECTION& sel )
82 if( T_TABLECELL* cell =
dynamic_cast<T_TABLECELL*
>( item ) )
84 if( cell->GetColSpan() > 1 || cell->GetRowSpan() > 1 )
96 auto structureSelection = cellSelection && structureEditable;
513 int colMin = std::numeric_limits<int>::max();
515 int rowMin = std::numeric_limits<int>::max();
519 T_TABLE*
table =
static_cast<T_TABLE*
>( sel[0]->GetParent() );
523 if( T_TABLECELL* cell =
dynamic_cast<T_TABLECELL*
>( item ) )
525 colMin = std::min( colMin, cell->GetColumn() );
526 colMax = std::max( colMax, cell->GetColumn() + cell->GetColSpan() );
527 rowMin = std::min( rowMin, cell->GetRow() );
528 rowMax = std::max( rowMax, cell->GetRow() + cell->GetRowSpan() );
535 for(
int row = rowMin; row < rowMax; ++row )
537 extents.
y +=
table->GetRowHeight( row );
540 for(
int col = colMin; col < colMax; ++col )
542 extents.
x +=
table->GetColWidth( col );
544 T_TABLECELL* cell =
table->GetCell( row, col );
546 if( !cell->GetText().IsEmpty() )
548 if( !content.IsEmpty() )
551 content += cell->GetText();
555 cell->SetColSpan( 0 );
556 cell->SetRowSpan( 0 );
557 cell->SetText( wxEmptyString );
561 T_TABLECELL* topLeft =
table->GetCell( rowMin, colMin );
562 topLeft->SetColSpan( colMax - colMin );
563 topLeft->SetRowSpan( rowMax - rowMin );
564 topLeft->SetText( content );
565 topLeft->SetEnd( topLeft->GetStart() + extents );
568 commit.Push(
_(
"Merge Cells" ) );
736 int targetColMin, targetColMax, targetRowMin, targetRowMax;
738 if( !
getCellBlockBounds( aSel, targetColMin, targetColMax, targetRowMin, targetRowMax ) )
741 T_TABLE* targetTable =
static_cast<T_TABLE*
>(
static_cast<T_TABLECELL*
>( aSel[0] )->GetParent() );
744 int sourceRows = aSourceTable->GetRowCount();
745 int sourceCols = aSourceTable->GetColCount();
747 int pasteEndRow = targetRowMin + sourceRows;
748 int pasteEndCol = targetColMin + sourceCols;
750 if( pasteEndRow > targetTable->GetRowCount() || pasteEndCol > targetTable->GetColCount() )
752 int rowsToAdd = std::max( 0, pasteEndRow - targetTable->GetRowCount() );
753 int colsToAdd = std::max( 0, pasteEndCol - targetTable->GetColCount() );
755 VECTOR2I pos = targetTable->GetPosition();
756 aCommit.Modify( targetTable,
getScreen() );
758 for(
int i = 0; i < rowsToAdd; ++i )
760 int insertRow = targetTable->GetRowCount();
761 int clipboardRow = insertRow - targetRowMin;
763 std::vector<T_TABLECELL*> sources;
764 sources.reserve( aSourceTable->GetColCount() );
766 for(
int col = 0; col < aSourceTable->GetColCount(); ++col )
767 sources.push_back( aSourceTable->GetCell( clipboardRow, col ) );
769 for(
int col = 0; col < targetTable->GetColCount(); ++col )
771 T_TABLECELL* sourceCell = ( col < aSourceTable->GetColCount() ) ? sources[col] : sources[0];
772 T_TABLECELL* cell =
copyCell( sourceCell );
773 targetTable->InsertCell( insertRow * targetTable->GetColCount(), cell );
776 for(
int afterRow = targetTable->GetRowCount() - 1; afterRow > insertRow; afterRow-- )
777 targetTable->SetRowHeight( afterRow, targetTable->GetRowHeight( afterRow - 1 ) );
779 targetTable->SetRowHeight( insertRow, aSourceTable->GetRowHeight( clipboardRow ) );
782 for(
int i = 0; i < colsToAdd; ++i )
784 int insertCol = targetTable->GetColCount();
785 int clipboardCol = insertCol - targetColMin;
786 int rowCount = targetTable->GetRowCount();
788 targetTable->SetColCount( targetTable->GetColCount() + 1 );
790 std::vector<T_TABLECELL*> sources;
791 sources.reserve( aSourceTable->GetRowCount() );
793 for(
int row = 0; row < aSourceTable->GetRowCount(); ++row )
794 sources.push_back( aSourceTable->GetCell( row, clipboardCol ) );
796 for(
int row = 0; row < rowCount; ++row )
798 T_TABLECELL* sourceCell = ( row < aSourceTable->GetRowCount() ) ? sources[row] : sources[0];
799 T_TABLECELL* cell =
copyCell( sourceCell );
800 targetTable->InsertCell( row * targetTable->GetColCount() + insertCol, cell );
803 for(
int afterCol = targetTable->GetColCount() - 1; afterCol > insertCol; afterCol-- )
804 targetTable->SetColWidth( afterCol, targetTable->GetColWidth( afterCol - 1 ) );
806 targetTable->SetColWidth( insertCol, aSourceTable->GetColWidth( clipboardCol ) );
809 targetTable->SetPosition( pos );
810 targetTable->Normalize();
813 for(
int srcRow = 0; srcRow < sourceRows; ++srcRow )
815 for(
int srcCol = 0; srcCol < sourceCols; ++srcCol )
817 int destRow = targetRowMin + srcRow;
818 int destCol = targetColMin + srcCol;
820 if( destRow >= targetTable->GetRowCount() || destCol >= targetTable->GetColCount() )
823 T_TABLECELL* sourceCell = aSourceTable->GetCell( srcRow, srcCol );
824 T_TABLECELL* targetCell = targetTable->GetCell( destRow, destCol );
826 aCommit.Modify( targetCell,
getScreen() );
828 targetCell->SetText( sourceCell->GetText() );
829 targetCell->SetAttributes( *sourceCell,
false );
830 targetCell->SetStroke( sourceCell->GetStroke() );
831 targetCell->SetFillMode( sourceCell->GetFillMode() );
832 targetCell->SetFillColor( sourceCell->GetFillColor() );
836 targetTable->Normalize();