summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Jung <phil.jung@free.fr>2015-05-16 00:04:43 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-05-17 12:39:39 +0000
commitd49242026ed9e342871b437998a40a253e4f26c8 (patch)
tree45746ab04b2b220a2fafc0cc8bcc14429af92e99
parentdc65b0242544a7d4c22c6fcf473dafb3e2d41121 (diff)
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@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--sw/inc/swtable.hxx4
-rw-r--r--sw/qa/extras/uiwriter/data/tdf90883.odtbin0 -> 8759 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx18
-rw-r--r--sw/source/core/table/swtable.cxx25
-rw-r--r--sw/source/uibase/shells/tabsh.cxx25
5 files changed, 71 insertions, 1 deletions
diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx
index ac000d87757b..088c01b82703 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 000000000000..ea9df27444cf
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf90883.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 3a47b8d8fbf1..e8ffdd78b976 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 fa0ffd8594f7..6fcab86bdd65 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 ead7b165eb21..586261803f11 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 )
{