489 int colMin = std::numeric_limits<int>::max();
491 int rowMin = std::numeric_limits<int>::max();
495 T_TABLE*
table =
static_cast<T_TABLE*
>( sel[0]->GetParent() );
499 if( T_TABLECELL* cell =
dynamic_cast<T_TABLECELL*
>( item ) )
501 colMin = std::min( colMin, cell->GetColumn() );
502 colMax = std::max( colMax, cell->GetColumn() + cell->GetColSpan() );
503 rowMin = std::min( rowMin, cell->GetRow() );
504 rowMax = std::max( rowMax, cell->GetRow() + cell->GetRowSpan() );
511 for(
int row = rowMin; row < rowMax; ++row )
513 extents.
y +=
table->GetRowHeight( row );
516 for(
int col = colMin; col < colMax; ++col )
518 extents.
x +=
table->GetColWidth( col );
520 T_TABLECELL* cell =
table->GetCell( row, col );
522 if( !cell->GetText().IsEmpty() )
524 if( !content.IsEmpty() )
527 content += cell->GetText();
531 cell->SetColSpan( 0 );
532 cell->SetRowSpan( 0 );
533 cell->SetText( wxEmptyString );
537 T_TABLECELL* topLeft =
table->GetCell( rowMin, colMin );
538 topLeft->SetColSpan( colMax - colMin );
539 topLeft->SetRowSpan( rowMax - rowMin );
540 topLeft->SetText( content );
541 topLeft->SetEnd( topLeft->GetStart() + extents );
544 commit.Push(
_(
"Merge Cells" ) );
699 if( !aSourceTable || aSel.
Empty() )
703 int targetColMin, targetColMax, targetRowMin, targetRowMax;
705 if( !
getCellBlockBounds( aSel, targetColMin, targetColMax, targetRowMin, targetRowMax ) )
708 T_TABLE* targetTable =
static_cast<T_TABLE*
>(
static_cast<T_TABLECELL*
>( aSel[0] )->GetParent() );
711 int sourceRows = aSourceTable->GetRowCount();
712 int sourceCols = aSourceTable->GetColCount();
714 int pasteEndRow = targetRowMin + sourceRows;
715 int pasteEndCol = targetColMin + sourceCols;
717 if( pasteEndRow > targetTable->GetRowCount() || pasteEndCol > targetTable->GetColCount() )
719 int rowsToAdd = std::max( 0, pasteEndRow - targetTable->GetRowCount() );
720 int colsToAdd = std::max( 0, pasteEndCol - targetTable->GetColCount() );
722 VECTOR2I pos = targetTable->GetPosition();
723 aCommit.Modify( targetTable,
getScreen() );
725 for(
int i = 0; i < rowsToAdd; ++i )
727 int insertRow = targetTable->GetRowCount();
728 int clipboardRow = insertRow - targetRowMin;
730 std::vector<T_TABLECELL*> sources;
731 sources.reserve( aSourceTable->GetColCount() );
733 for(
int col = 0; col < aSourceTable->GetColCount(); ++col )
734 sources.push_back( aSourceTable->GetCell( clipboardRow, col ) );
736 for(
int col = 0; col < targetTable->GetColCount(); ++col )
738 T_TABLECELL* sourceCell = ( col < aSourceTable->GetColCount() ) ? sources[col] : sources[0];
739 T_TABLECELL* cell =
copyCell( sourceCell );
740 targetTable->InsertCell( insertRow * targetTable->GetColCount(), cell );
743 for(
int afterRow = targetTable->GetRowCount() - 1; afterRow > insertRow; afterRow-- )
744 targetTable->SetRowHeight( afterRow, targetTable->GetRowHeight( afterRow - 1 ) );
746 targetTable->SetRowHeight( insertRow, aSourceTable->GetRowHeight( clipboardRow ) );
749 for(
int i = 0; i < colsToAdd; ++i )
751 int insertCol = targetTable->GetColCount();
752 int clipboardCol = insertCol - targetColMin;
753 int rowCount = targetTable->GetRowCount();
755 targetTable->SetColCount( targetTable->GetColCount() + 1 );
757 std::vector<T_TABLECELL*> sources;
758 sources.reserve( aSourceTable->GetRowCount() );
760 for(
int row = 0; row < aSourceTable->GetRowCount(); ++row )
761 sources.push_back( aSourceTable->GetCell( row, clipboardCol ) );
763 for(
int row = 0; row < rowCount; ++row )
765 T_TABLECELL* sourceCell = ( row < aSourceTable->GetRowCount() ) ? sources[row] : sources[0];
766 T_TABLECELL* cell =
copyCell( sourceCell );
767 targetTable->InsertCell( row * targetTable->GetColCount() + insertCol, cell );
770 for(
int afterCol = targetTable->GetColCount() - 1; afterCol > insertCol; afterCol-- )
771 targetTable->SetColWidth( afterCol, targetTable->GetColWidth( afterCol - 1 ) );
773 targetTable->SetColWidth( insertCol, aSourceTable->GetColWidth( clipboardCol ) );
776 targetTable->SetPosition( pos );
777 targetTable->Normalize();
780 for(
int srcRow = 0; srcRow < sourceRows; ++srcRow )
782 for(
int srcCol = 0; srcCol < sourceCols; ++srcCol )
784 int destRow = targetRowMin + srcRow;
785 int destCol = targetColMin + srcCol;
787 if( destRow >= targetTable->GetRowCount() || destCol >= targetTable->GetColCount() )
790 T_TABLECELL* sourceCell = aSourceTable->GetCell( srcRow, srcCol );
791 T_TABLECELL* targetCell = targetTable->GetCell( destRow, destCol );
793 aCommit.Modify( targetCell,
getScreen() );
795 targetCell->SetText( sourceCell->GetText() );
796 targetCell->SetAttributes( *sourceCell,
false );
797 targetCell->SetStroke( sourceCell->GetStroke() );
798 targetCell->SetFillMode( sourceCell->GetFillMode() );
799 targetCell->SetFillColor( sourceCell->GetFillColor() );
803 targetTable->Normalize();