[Libreoffice-commits] core.git: sw/inc sw/qa sw/source
Philippe Jung
phil.jung at free.fr
Sun May 17 05:40:03 PDT 2015
sw/inc/swtable.hxx | 4 ++++
sw/qa/extras/uiwriter/data/tdf90883.odt |binary
sw/qa/extras/uiwriter/uiwriter.cxx | 18 ++++++++++++++++++
sw/source/core/table/swtable.cxx | 25 +++++++++++++++++++++++++
sw/source/uibase/shells/tabsh.cxx | 25 ++++++++++++++++++++++++-
5 files changed, 71 insertions(+), 1 deletion(-)
New commits:
commit d49242026ed9e342871b437998a40a253e4f26c8
Author: Philippe Jung <phil.jung at free.fr>
Date: Sat May 16 00:04:43 2015 +0200
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/15741
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>
diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx
index ac000d8..088c01b 100644
--- a/sw/inc/swtable.hxx
+++ b/sw/inc/swtable.hxx
@@ -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?
diff --git a/sw/qa/extras/uiwriter/data/tdf90883.odt b/sw/qa/extras/uiwriter/data/tdf90883.odt
new file mode 100644
index 0000000..ea9df27
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf90883.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 3a47b8d..e8ffdd7 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -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();
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index fa0ffd8..6fcab86 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -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?
diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx
index ead7b16..5862618 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -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 )
{
More information about the Libreoffice-commits
mailing list