[Libreoffice-commits] core.git: include/svx sd/qa sd/source svx/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Jan 25 14:39:22 UTC 2017


 include/svx/sdr/table/tablecontroller.hxx    |    3 +
 include/svx/selectioncontroller.hxx          |    4 ++
 sd/qa/unit/tiledrendering/data/tdf105502.odp |binary
 sd/qa/unit/tiledrendering/tiledrendering.cxx |   53 +++++++++++++++++++++++++++
 sd/source/ui/func/futext.cxx                 |   43 +++++++++++++++++++++
 svx/source/svdraw/selectioncontroller.cxx    |    4 ++
 6 files changed, 106 insertions(+), 1 deletion(-)

New commits:
commit cbc84a6599c08e5c79e544212c69c6946d0cdbf0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Jan 25 11:15:46 2017 +0100

    tdf#105502 sd increase font size: handle table selection
    
    In part of a table shape is selected, then only operate on the selected
    cells, not on all of them.
    
    Change-Id: I3a9ba2b99bcaa2e355b6fcdafdd142d4a809bce6
    Reviewed-on: https://gerrit.libreoffice.org/33524
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/include/svx/sdr/table/tablecontroller.hxx b/include/svx/sdr/table/tablecontroller.hxx
index ea511e7..1441c52 100644
--- a/include/svx/sdr/table/tablecontroller.hxx
+++ b/include/svx/sdr/table/tablecontroller.hxx
@@ -97,7 +97,8 @@ public:
     /// @see sdr::SelectionController::setCursorLogicPosition().
     SVX_DLLPRIVATE virtual bool setCursorLogicPosition(const Point& rPosition, bool bPoint) override;
 
-    void getSelectedCells( CellPos& rFirstPos, CellPos& rLastPos );
+    /// @see sdr::SelectionController::getSelectedCells().
+    void getSelectedCells( CellPos& rFirstPos, CellPos& rLastPos ) override;
     void setSelectedCells( const CellPos& rFirstPos, const CellPos& rLastPos );
     void clearSelection();
     void selectAll();
diff --git a/include/svx/selectioncontroller.hxx b/include/svx/selectioncontroller.hxx
index 4c4a8e5..d2fb9c4 100644
--- a/include/svx/selectioncontroller.hxx
+++ b/include/svx/selectioncontroller.hxx
@@ -37,6 +37,8 @@ class Point;
 namespace sdr
 {
 
+namespace table { struct CellPos; }
+
 class SVX_DLLPUBLIC SelectionController: public cppu::OWeakObject
 {
 public:
@@ -74,6 +76,8 @@ public:
     virtual bool hasSelectedCells() const;
     /// Allows adjusting the point or mark of the selection to a document coordinate.
     virtual bool setCursorLogicPosition(const Point& rPosition, bool bPoint);
+    /// Get the position of the first and the last selected cell.
+    virtual void getSelectedCells(table::CellPos& rFirstPos, table::CellPos& rLastPos);
 };
 
 }
diff --git a/sd/qa/unit/tiledrendering/data/tdf105502.odp b/sd/qa/unit/tiledrendering/data/tdf105502.odp
new file mode 100644
index 0000000..6fe8180
Binary files /dev/null and b/sd/qa/unit/tiledrendering/data/tdf105502.odp differ
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 65079fc..cbb8703 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -42,6 +42,8 @@
 #include <unomodel.hxx>
 #include <drawdoc.hxx>
 #include <undo/undomanager.hxx>
+#include <sfx2/request.hxx>
+#include <svx/svxids.hrc>
 
 using namespace css;
 
@@ -84,6 +86,7 @@ public:
     void testTdf103083();
     void testTdf104405();
     void testTdf81754();
+    void testTdf105502();
 
     CPPUNIT_TEST_SUITE(SdTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -116,6 +119,7 @@ public:
     CPPUNIT_TEST(testTdf103083);
     CPPUNIT_TEST(testTdf104405);
     CPPUNIT_TEST(testTdf81754);
+    CPPUNIT_TEST(testTdf105502);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -1505,6 +1509,55 @@ void SdTiledRenderingTest::testTdf81754()
     xDocShRef->DoClose();
 }
 
+void SdTiledRenderingTest::testTdf105502()
+{
+    // Load the document.
+    comphelper::LibreOfficeKit::setActive();
+    SdXImpressDocument* pXImpressDocument = createDoc("tdf105502.odp");
+    sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+    sd::Window* pWindow = pViewShell->GetActiveWindow();
+    CPPUNIT_ASSERT(pWindow);
+    SdPage* pActualPage = pViewShell->GetActualPage();
+    SdrObject* pObject = pActualPage->GetObj(0);
+    auto pTableObject = dynamic_cast<sdr::table::SdrTableObj*>(pObject);
+    CPPUNIT_ASSERT(pTableObject);
+
+    // Select the first row.
+    sd::View* pView = pViewShell->GetView();
+    pView->MarkObj(pObject, pView->GetSdrPageView());
+    pView->SdrBeginTextEdit(pObject);
+    rtl::Reference<sdr::SelectionController> xSelectionController(pView->getSelectionController());
+    CPPUNIT_ASSERT(xSelectionController.is());
+    SfxRequest aRequest(pViewShell->GetViewFrame(), SID_TABLE_SELECT_ROW);
+    xSelectionController->Execute(aRequest);
+
+    // Assert that the A1:B1 selection succeeded.
+    CPPUNIT_ASSERT(xSelectionController->hasSelectedCells());
+    sdr::table::CellPos aFirstCell;
+    sdr::table::CellPos aLastCell;
+    xSelectionController->getSelectedCells(aFirstCell, aLastCell);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aFirstCell.mnCol);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aFirstCell.mnRow);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aLastCell.mnCol);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aLastCell.mnRow);
+
+    // Grow font size for the selection.
+    comphelper::dispatchCommand(".uno:Grow", {});
+    Scheduler::ProcessEventsToIdle();
+
+    // Assert that the selected A1 has now a larger font than the unselected
+    // A2.
+    xmlDocPtr pXmlDoc = parseXmlDump();
+    sal_Int32 nA1Height = getXPath(pXmlDoc, "//Cell[1]/SdrText/OutlinerParaObject/EditTextObject/ContentInfo/attribs[1]/SvxFontHeightItem", "height").toInt32();
+    sal_Int32 nA2Height = getXPath(pXmlDoc, "//Cell[3]/SdrText/OutlinerParaObject/EditTextObject/ContentInfo/attribs[1]/SvxFontHeightItem", "height").toInt32();
+    // This failed when FuText::ChangeFontSize() never did "continue" in the
+    // text loop, instead of doing so depending on what IsInSelection() returns.
+    CPPUNIT_ASSERT(nA1Height > nA2Height);
+    xmlFreeDoc(pXmlDoc);
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sd/source/ui/func/futext.cxx b/sd/source/ui/func/futext.cxx
index 17aa214..ff426e2 100644
--- a/sd/source/ui/func/futext.cxx
+++ b/sd/source/ui/func/futext.cxx
@@ -40,6 +40,7 @@
 #include <sfx2/request.hxx>
 #include <editeng/editeng.hxx>
 #include <svx/svdoutl.hxx>
+#include <svx/svdotable.hxx>
 #include <svx/svxids.hrc>
 #include <sfx2/docfile.hxx>
 #include <comphelper/processfactory.hxx>
@@ -1358,6 +1359,24 @@ bool FuText::cancel()
     }
 }
 
+/// Is rCell covered by the rFirst - rLast selection?
+static bool IsInSelection(const sdr::table::CellPos& rFirst, const sdr::table::CellPos& rLast, sdr::table::CellPos& rCell)
+{
+    if (rCell.mnCol < rFirst.mnCol)
+        return false;
+
+    if (rCell.mnCol > rLast.mnCol)
+        return false;
+
+    if (rCell.mnRow < rFirst.mnRow)
+        return false;
+
+    if (rCell.mnRow > rLast.mnRow)
+        return false;
+
+    return true;
+}
+
 void FuText::ChangeFontSize( bool bGrow, OutlinerView* pOLV, const FontList* pFontList, ::sd::View* pView )
 {
     if( !pFontList || !pView )
@@ -1377,8 +1396,32 @@ void FuText::ChangeFontSize( bool bGrow, OutlinerView* pOLV, const FontList* pFo
             SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( rMarkList.GetMark(nMark)->GetMarkedSdrObj() );
             if( pTextObj )
             {
+                rtl::Reference<sdr::SelectionController> xSelectionController(pView->getSelectionController());
+                sdr::table::CellPos aFirstCell;
+                sdr::table::CellPos aLastCell;
+                sdr::table::SdrTableObj* pTableObject = nullptr;
+                if (xSelectionController.is() && xSelectionController->hasSelectedCells())
+                {
+                    // This is a table object, and one or more of its cells are
+                    // selected.
+                    xSelectionController->getSelectedCells(aFirstCell, aLastCell);
+                    pTableObject = dynamic_cast<sdr::table::SdrTableObj*>(pTextObj);
+                }
                 for( sal_Int32 nText = 0; nText < pTextObj->getTextCount(); nText++ )
                 {
+                    if (pTableObject)
+                    {
+                        sal_Int32 nColCount = pTableObject->getColumnCount();
+                        if (nColCount > 0)
+                        {
+                            sdr::table::CellPos aPos(nText % nColCount, nText / nColCount);
+                            if (!IsInSelection(aFirstCell, aLastCell, aPos))
+                                // There is a selection, but this cell is not
+                                // part of it: don't change font size.
+                                continue;
+                        }
+                    }
+
                     pTextObj->setActiveText( nText );
 
                     // Put text object into edit mode.
diff --git a/svx/source/svdraw/selectioncontroller.cxx b/svx/source/svdraw/selectioncontroller.cxx
index 3138f37..0fc2d52 100644
--- a/svx/source/svdraw/selectioncontroller.cxx
+++ b/svx/source/svdraw/selectioncontroller.cxx
@@ -110,6 +110,10 @@ bool SelectionController::hasSelectedCells() const
     return false;
 }
 
+void SelectionController::getSelectedCells(table::CellPos& /*rFirstPos*/, table::CellPos& /*rLastPos*/)
+{
+}
+
 bool SelectionController::setCursorLogicPosition(const Point& /*rPosition*/, bool /*bPoint*/)
 {
     return false;


More information about the Libreoffice-commits mailing list