485 int colMin = std::numeric_limits<int>::max();
487 int rowMin = std::numeric_limits<int>::max();
491 T_TABLE*
table =
static_cast<T_TABLE*
>( sel[0]->GetParent() );
495 if( T_TABLECELL* cell =
dynamic_cast<T_TABLECELL*
>( item ) )
497 colMin = std::min( colMin, cell->GetColumn() );
498 colMax = std::max( colMax, cell->GetColumn() + cell->GetColSpan() );
499 rowMin = std::min( rowMin, cell->GetRow() );
500 rowMax = std::max( rowMax, cell->GetRow() + cell->GetRowSpan() );
507 for(
int row = rowMin; row < rowMax; ++row )
509 extents.
y +=
table->GetRowHeight( row );
512 for(
int col = colMin; col < colMax; ++col )
514 extents.
x +=
table->GetColWidth( col );
516 T_TABLECELL* cell =
table->GetCell( row, col );
518 if( !cell->GetText().IsEmpty() )
520 if( !content.IsEmpty() )
523 content += cell->GetText();
527 cell->SetColSpan( 0 );
528 cell->SetRowSpan( 0 );
529 cell->SetText( wxEmptyString );
533 T_TABLECELL* topLeft =
table->GetCell( rowMin, colMin );
534 topLeft->SetColSpan( colMax - colMin );
535 topLeft->SetRowSpan( rowMax - rowMin );
536 topLeft->SetText( content );
537 topLeft->SetEnd( topLeft->GetStart() + extents );
540 commit.Push(
_(
"Merge Cells" ) );
695 if( !aSourceTable || aSel.
Empty() )
699 int targetColMin, targetColMax, targetRowMin, targetRowMax;
701 if( !
getCellBlockBounds( aSel, targetColMin, targetColMax, targetRowMin, targetRowMax ) )
704 T_TABLE* targetTable =
static_cast<T_TABLE*
>(
static_cast<T_TABLECELL*
>( aSel[0] )->GetParent() );
707 int sourceRows = aSourceTable->GetRowCount();
708 int sourceCols = aSourceTable->GetColCount();
710 int pasteEndRow = targetRowMin + sourceRows;
711 int pasteEndCol = targetColMin + sourceCols;
713 if( pasteEndRow > targetTable->GetRowCount() || pasteEndCol > targetTable->GetColCount() )
715 int rowsToAdd = std::max( 0, pasteEndRow - targetTable->GetRowCount() );
716 int colsToAdd = std::max( 0, pasteEndCol - targetTable->GetColCount() );
718 VECTOR2I pos = targetTable->GetPosition();
719 aCommit.Modify( targetTable,
getScreen() );
721 for(
int i = 0; i < rowsToAdd; ++i )
723 int insertRow = targetTable->GetRowCount();
724 int clipboardRow = insertRow - targetRowMin;
726 std::vector<T_TABLECELL*> sources;
727 sources.reserve( aSourceTable->GetColCount() );
729 for(
int col = 0; col < aSourceTable->GetColCount(); ++col )
730 sources.push_back( aSourceTable->GetCell( clipboardRow, col ) );
732 for(
int col = 0; col < targetTable->GetColCount(); ++col )
734 T_TABLECELL* sourceCell = ( col < aSourceTable->GetColCount() ) ? sources[col] : sources[0];
735 T_TABLECELL* cell =
copyCell( sourceCell );
736 targetTable->InsertCell( insertRow * targetTable->GetColCount(), cell );
739 for(
int afterRow = targetTable->GetRowCount() - 1; afterRow > insertRow; afterRow-- )
740 targetTable->SetRowHeight( afterRow, targetTable->GetRowHeight( afterRow - 1 ) );
742 targetTable->SetRowHeight( insertRow, aSourceTable->GetRowHeight( clipboardRow ) );
745 for(
int i = 0; i < colsToAdd; ++i )
747 int insertCol = targetTable->GetColCount();
748 int clipboardCol = insertCol - targetColMin;
749 int rowCount = targetTable->GetRowCount();
751 targetTable->SetColCount( targetTable->GetColCount() + 1 );
753 std::vector<T_TABLECELL*> sources;
754 sources.reserve( aSourceTable->GetRowCount() );
756 for(
int row = 0; row < aSourceTable->GetRowCount(); ++row )
757 sources.push_back( aSourceTable->GetCell( row, clipboardCol ) );
759 for(
int row = 0; row < rowCount; ++row )
761 T_TABLECELL* sourceCell = ( row < aSourceTable->GetRowCount() ) ? sources[row] : sources[0];
762 T_TABLECELL* cell =
copyCell( sourceCell );
763 targetTable->InsertCell( row * targetTable->GetColCount() + insertCol, cell );
766 for(
int afterCol = targetTable->GetColCount() - 1; afterCol > insertCol; afterCol-- )
767 targetTable->SetColWidth( afterCol, targetTable->GetColWidth( afterCol - 1 ) );
769 targetTable->SetColWidth( insertCol, aSourceTable->GetColWidth( clipboardCol ) );
772 targetTable->SetPosition( pos );
773 targetTable->Normalize();
776 for(
int srcRow = 0; srcRow < sourceRows; ++srcRow )
778 for(
int srcCol = 0; srcCol < sourceCols; ++srcCol )
780 int destRow = targetRowMin + srcRow;
781 int destCol = targetColMin + srcCol;
783 if( destRow >= targetTable->GetRowCount() || destCol >= targetTable->GetColCount() )
786 T_TABLECELL* sourceCell = aSourceTable->GetCell( srcRow, srcCol );
787 T_TABLECELL* targetCell = targetTable->GetCell( destRow, destCol );
789 aCommit.Modify( targetCell,
getScreen() );
791 targetCell->SetText( sourceCell->GetText() );
792 targetCell->SetAttributes( *sourceCell,
false );
793 targetCell->SetStroke( sourceCell->GetStroke() );
794 targetCell->SetFillMode( sourceCell->GetFillMode() );
795 targetCell->SetFillColor( sourceCell->GetFillColor() );
799 targetTable->Normalize();