Kaydet (Commit) d4924202 authored tarafından Philippe Jung's avatar Philippe Jung Kaydeden (comit) Miklos Vajna

tdf#90883 WRITER: Insert button with multiple rows/columns selected

Compute the number of rows/columns to insert based on selected cells.

Change-Id: I489bca715dcf31d191f9a875ac5d59a6140a14d7
Reviewed-on: https://gerrit.libreoffice.org/15741Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst dc65b024
......@@ -433,6 +433,10 @@ public:
// Return "value" of box (for calculating in table).
double GetValue( SwTblCalcPara& rPara ) const;
// Computes "coordinates" of a box, used to computed selection
// width or height when inserting cols or rows
Point GetCoordinates() const;
bool IsInHeadline( const SwTable* pTbl = 0 ) const;
// Contains box contents, that can be formatted as a number?
......
......@@ -92,6 +92,7 @@ public:
void testTdf90362();
void testUndoCharAttribute();
void testTdf86639();
void testTdf90883TableBoxGetCoordinates();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
......@@ -128,6 +129,7 @@ public:
CPPUNIT_TEST(testTdf90362);
CPPUNIT_TEST(testUndoCharAttribute);
CPPUNIT_TEST(testTdf86639);
CPPUNIT_TEST(testTdf90883TableBoxGetCoordinates);
CPPUNIT_TEST_SUITE_END();
......@@ -962,6 +964,22 @@ void SwUiWriterTest::testTdf86639()
CPPUNIT_ASSERT_EQUAL(aExpected, getProperty<OUString>(getRun(getParagraph(1), 1), "CharFontName"));
}
void SwUiWriterTest::testTdf90883TableBoxGetCoordinates()
{
SwDoc* pDoc = createDoc("tdf90883.odt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(true);
SwSelBoxes aBoxes;
::GetTblSel( *pWrtShell, aBoxes );
CPPUNIT_ASSERT_EQUAL( 2, (int)aBoxes.size() );
Point pos ( aBoxes[0]->GetCoordinates() );
CPPUNIT_ASSERT_EQUAL( 1, (int)pos.X() );
CPPUNIT_ASSERT_EQUAL( 1, (int)pos.Y() );
pos = aBoxes[1]->GetCoordinates();
CPPUNIT_ASSERT_EQUAL( 1, (int)pos.X() );
CPPUNIT_ASSERT_EQUAL( 2, (int)pos.Y() );
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
......
......@@ -1841,6 +1841,31 @@ void sw_GetTblBoxColStr( sal_uInt16 nCol, OUString& rNm )
} while( true );
}
Point SwTableBox::GetCoordinates() const
{
if( !pSttNd ) // box without content?
{
// search for the next first box?
return Point( 0, 0 );
}
const SwTable& rTbl = pSttNd->FindTableNode()->GetTable();
sal_uInt16 nX, nY;
const SwTableBox* pBox = this;
do {
const SwTableBoxes* pBoxes = &pBox->GetUpper()->GetTabBoxes();
const SwTableLine* pLine = pBox->GetUpper();
// at the first level?
const SwTableLines* pLines = pLine->GetUpper()
? &pLine->GetUpper()->GetTabLines() : &rTbl.GetTabLines();
nY = pLines->GetPos( pLine ) + 1 ;
nX = pBoxes->GetPos( pBox ) + 1 ;
pBox = pLine->GetUpper();
} while( pBox );
return Point( nX, nY );
}
OUString SwTableBox::GetName() const
{
if( !pSttNd ) // box without content?
......
......@@ -833,7 +833,30 @@ void SwTableShell::Execute(SfxRequest &rReq)
bAfter = static_cast<const SfxBoolItem* >(pItem)->GetValue();
}
else if( !rReq.IsAPI() )
++nCount;
{
SwSelBoxes aBoxes;
::GetTblSel( rSh, aBoxes );
if ( !aBoxes.empty() )
{
long maxX = 0;
long maxY = 0;
long minX = std::numeric_limits<long>::max();
long minY = std::numeric_limits<long>::max();
long nbBoxes = aBoxes.size();
for ( int i = 0; i < nbBoxes; i++ )
{
Point aCoord ( aBoxes[i]->GetCoordinates() );
if ( aCoord.X() < minX ) minX = aCoord.X();
if ( aCoord.X() > maxX ) maxX = aCoord.X();
if ( aCoord.Y() < minY ) minY = aCoord.Y();
if ( aCoord.Y() > maxY ) maxY = aCoord.Y();
}
if (bColumn)
nCount = maxX - minX + 1;
else
nCount = maxY - minY + 1;
}
}
if( nCount )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment