[Libreoffice-commits] core.git: 2 commits - include/svx include/tools svx/source sw/source vcl/source

Noel Grandin noel.grandin at collabora.co.uk
Sun Jan 28 06:32:11 UTC 2018


 include/svx/sdr/table/tablecontroller.hxx |    6 ++---
 include/tools/gen.hxx                     |   32 ++++++++++++++++++++----------
 svx/source/svdraw/svdedxv.cxx             |    2 -
 svx/source/svdraw/svdopath.cxx            |    8 +++----
 svx/source/table/tablecontroller.cxx      |   32 ++++++++++++------------------
 svx/source/unodraw/unoshape.cxx           |    4 +--
 sw/source/core/bastyp/swrect.cxx          |    6 +----
 vcl/source/control/scrbar.cxx             |    8 +++----
 8 files changed, 51 insertions(+), 47 deletions(-)

New commits:
commit b2897ae7e15d69e25bc608f073e77a5a7aabd9b3
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Jan 26 09:16:07 2018 +0200

    make SvxTableController constructor take SdrTableObj
    
    since the only call site already effectively checks that, simplify the
    constructor code accordingly
    
    Change-Id: I29e5283d529a988693972d85cfa8196ba2906220
    Reviewed-on: https://gerrit.libreoffice.org/48651
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/sdr/table/tablecontroller.hxx b/include/svx/sdr/table/tablecontroller.hxx
index b2eeadc48007..9ad6658a299c 100644
--- a/include/svx/sdr/table/tablecontroller.hxx
+++ b/include/svx/sdr/table/tablecontroller.hxx
@@ -42,7 +42,7 @@ class TableModel;
 class SVX_DLLPUBLIC SvxTableController: public sdr::SelectionController
 {
 public:
-    SVX_DLLPRIVATE SvxTableController( SdrObjEditView* pView, const SdrObject* pObj );
+    SVX_DLLPRIVATE SvxTableController( SdrObjEditView* pView, const SdrTableObj* pObj );
     SVX_DLLPRIVATE virtual ~SvxTableController() override;
 
     // from sdr::SelectionController
@@ -76,7 +76,7 @@ public:
     SVX_DLLPRIVATE void DistributeRows();
     SVX_DLLPRIVATE void SetVertical( sal_uInt16 nSId );
 
-    SVX_DLLPRIVATE static rtl::Reference< sdr::SelectionController > create( SdrObjEditView* pView, const SdrObject* pObj, const rtl::Reference< sdr::SelectionController >& xRefController );
+    SVX_DLLPRIVATE static rtl::Reference< sdr::SelectionController > create( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController );
 
     SVX_DLLPRIVATE void MergeAttrFromSelectedCells(SfxItemSet& rAttr, bool bOnlyHardAttr) const;
     SVX_DLLPRIVATE void SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bReplaceAll);
@@ -184,7 +184,7 @@ private:
     ImplSVEvent * mnUpdateEvent;
 };
 
-rtl::Reference< sdr::SelectionController > CreateTableController( SdrObjEditView* pView, const SdrObject* pObj, const rtl::Reference< sdr::SelectionController >& xRefController );
+rtl::Reference< sdr::SelectionController > CreateTableController( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController );
 
 } }
 
diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx
index 734008157212..29d54d576e4f 100644
--- a/svx/source/svdraw/svdedxv.cxx
+++ b/svx/source/svdraw/svdedxv.cxx
@@ -2413,7 +2413,7 @@ void SdrObjEditView::MarkListHasChanged()
         // check for table
         if( pObj && (pObj->GetObjInventor() == SdrInventor::Default ) && (pObj->GetObjIdentifier() == OBJ_TABLE) )
         {
-            mxSelectionController = sdr::table::CreateTableController( this, pObj, mxLastSelectionController );
+            mxSelectionController = sdr::table::CreateTableController( this, static_cast<sdr::table::SdrTableObj const *>(pObj), mxLastSelectionController );
             if( mxSelectionController.is() )
             {
                 mxLastSelectionController.clear();
diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx
index f683569df3df..804ebcb655a2 100644
--- a/svx/source/table/tablecontroller.cxx
+++ b/svx/source/table/tablecontroller.cxx
@@ -141,13 +141,13 @@ void SAL_CALL SvxTableControllerModifyListener::disposing( const css::lang::Even
 // class SvxTableController
 
 
-rtl::Reference< sdr::SelectionController > CreateTableController( SdrObjEditView* pView, const SdrObject* pObj, const rtl::Reference< sdr::SelectionController >& xRefController )
+rtl::Reference< sdr::SelectionController > CreateTableController( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController )
 {
     return SvxTableController::create( pView, pObj, xRefController );
 }
 
 
-rtl::Reference< sdr::SelectionController > SvxTableController::create( SdrObjEditView* pView, const SdrObject* pObj, const rtl::Reference< sdr::SelectionController >& xRefController )
+rtl::Reference< sdr::SelectionController > SvxTableController::create( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController )
 {
     if( xRefController.is() )
     {
@@ -159,33 +159,27 @@ rtl::Reference< sdr::SelectionController > SvxTableController::create( SdrObjEdi
 }
 
 
-SvxTableController::SvxTableController( SdrObjEditView* pView, const SdrObject* pObj )
+SvxTableController::SvxTableController( SdrObjEditView* pView, const SdrTableObj* pObj )
 : mbCellSelectionMode(false)
 , mbLeftButtonDown(false)
 , mpSelectionOverlay(nullptr)
 , mpView( dynamic_cast< SdrView* >( pView ) )
-, mxTableObj( dynamic_cast< SdrTableObj* >( const_cast< SdrObject* >( pObj ) ) )
+, mxTableObj( const_cast< SdrTableObj* >( pObj ) )
 , mpModel( nullptr )
 , mnUpdateEvent( nullptr )
 {
-    if( pObj )
-    {
-        mpModel = pObj->GetModel();
+    mpModel = mxTableObj->GetModel();
 
-        if( mxTableObj.is() )
-        {
-            mxTableObj->getActiveCellPos( maCursorFirstPos );
-            maCursorLastPos = maCursorFirstPos;
+    mxTableObj->getActiveCellPos( maCursorFirstPos );
+    maCursorLastPos = maCursorFirstPos;
 
-            Reference< XTable > xTable( mxTableObj->getTable() );
-            if( xTable.is() )
-            {
-                mxModifyListener = new SvxTableControllerModifyListener( this );
-                xTable->addModifyListener( mxModifyListener );
+    Reference< XTable > xTable( mxTableObj->getTable() );
+    if( xTable.is() )
+    {
+        mxModifyListener = new SvxTableControllerModifyListener( this );
+        xTable->addModifyListener( mxModifyListener );
 
-                mxTable.set( dynamic_cast< TableModel* >( xTable.get() ) );
-            }
-        }
+        mxTable.set( dynamic_cast< TableModel* >( xTable.get() ) );
     }
 }
 
commit 5ab1b4f97032e4b1f1f0c080311f3a393ce89585
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jan 25 14:56:44 2018 +0200

    make RECT_EMPTY purely an implementation detail
    
    and make outside code use the IsEmpty/SetEmpty methods
    
    Change-Id: I4821d1bdceb99bb6a837a85ff2131003f9a160a5
    Reviewed-on: https://gerrit.libreoffice.org/48584
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/tools/gen.hxx b/include/tools/gen.hxx
index a10b74e03b0b..ca0c43d272a5 100644
--- a/include/tools/gen.hxx
+++ b/include/tools/gen.hxx
@@ -327,7 +327,6 @@ inline std::basic_ostream<charT, traits> & operator <<(
 }
 // Rectangle
 
-#define RECT_EMPTY  (short(-32767))
 #define RECT_MAX    LONG_MAX
 #define RECT_MIN    LONG_MIN
 
@@ -344,11 +343,14 @@ namespace tools
 {
 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC Rectangle
 {
+    static constexpr short RECT_EMPTY = -32767;
 public:
                         Rectangle();
                         Rectangle( const Point& rLT, const Point& rRB );
                         Rectangle( long nLeft, long nTop,
                                    long nRight, long nBottom );
+    /// Constructs an empty Rectangle, with top/left at the specified params
+                        Rectangle( long nLeft, long nTop );
                         Rectangle( const Point& rLT, const Size& rSize );
 
     long                Left() const    { return nLeft;   }
@@ -394,7 +396,11 @@ public:
     bool                IsOver( const tools::Rectangle& rRect ) const;
 
     void                SetEmpty() { nRight = nBottom = RECT_EMPTY; }
+    void                SetWidthEmpty() { nRight = RECT_EMPTY; }
+    void                SetHeightEmpty() { nBottom = RECT_EMPTY; }
     inline bool         IsEmpty() const;
+    bool                IsWidthEmpty() const { return nRight == RECT_EMPTY; }
+    bool                IsHeightEmpty() const { return nBottom == RECT_EMPTY; }
 
     inline bool         operator == ( const tools::Rectangle& rRect ) const;
     inline bool         operator != ( const tools::Rectangle& rRect ) const;
@@ -465,6 +471,13 @@ inline tools::Rectangle::Rectangle( long _nLeft,  long _nTop,
     nBottom = _nBottom;
 }
 
+inline tools::Rectangle::Rectangle( long _nLeft,  long _nTop )
+{
+    nLeft   = _nLeft;
+    nTop    = _nTop;
+    nRight = nBottom = RECT_EMPTY;
+}
+
 inline tools::Rectangle::Rectangle( const Point& rLT, const Size& rSize )
 {
     nLeft   = rLT.X();
@@ -654,19 +667,18 @@ namespace tools
 {
 inline Rectangle operator + ( const Rectangle& rRect, const Point& rPt )
 {
-    Rectangle aRect( rRect.nLeft  + rPt.X(), rRect.nTop    + rPt.Y(),
-                     (rRect.nRight  == RECT_EMPTY) ? RECT_EMPTY : rRect.nRight + rPt.X(),
-                     (rRect.nBottom == RECT_EMPTY) ? RECT_EMPTY : rRect.nBottom + rPt.Y() );
-    return aRect;
+    return rRect.IsEmpty()
+        ?  Rectangle( rRect.nLeft  + rPt.X(), rRect.nTop    + rPt.Y() )
+        :  Rectangle( rRect.nLeft  + rPt.X(), rRect.nTop    + rPt.Y(),
+                      rRect.nRight + rPt.X(), rRect.nBottom + rPt.Y() );
 }
 
 inline Rectangle operator - ( const Rectangle& rRect, const Point& rPt )
 {
-    Rectangle aRect( rRect.nLeft - rPt.X(),
-                     rRect.nTop - rPt.Y(),
-                     (rRect.nRight  == RECT_EMPTY) ? RECT_EMPTY : rRect.nRight - rPt.X(),
-                     (rRect.nBottom == RECT_EMPTY) ? RECT_EMPTY : rRect.nBottom - rPt.Y() );
-    return aRect;
+    return rRect.IsEmpty()
+        ? Rectangle( rRect.nLeft - rPt.X(),  rRect.nTop - rPt.Y() )
+        : Rectangle( rRect.nLeft - rPt.X(),  rRect.nTop - rPt.Y(),
+                     rRect.nRight - rPt.X(), rRect.nBottom - rPt.Y() );
 }
 }
 
diff --git a/svx/source/svdraw/svdopath.cxx b/svx/source/svdraw/svdopath.cxx
index 8a14da00bfdd..b71e20f92a94 100644
--- a/svx/source/svdraw/svdopath.cxx
+++ b/svx/source/svdraw/svdopath.cxx
@@ -2425,13 +2425,13 @@ void SdrPathObj::NbcSetSnapRect(const tools::Rectangle& rRect)
 {
     tools::Rectangle aOld(GetSnapRect());
 
-    // Take RECT_EMPTY into account when calculating scale factors
-    long nMulX = (RECT_EMPTY == rRect.Right()) ? 0 : rRect.Right()  - rRect.Left();
+    // Take empty into account when calculating scale factors
+    long nMulX = rRect.IsWidthEmpty() ? 0 : rRect.Right()  - rRect.Left();
 
     long nDivX = aOld.Right()   - aOld.Left();
 
-    // Take RECT_EMPTY into account when calculating scale factors
-    long nMulY = (RECT_EMPTY == rRect.Bottom()) ? 0 : rRect.Bottom() - rRect.Top();
+    // Take empty into account when calculating scale factors
+    long nMulY = rRect.IsHeightEmpty() ? 0 : rRect.Bottom() - rRect.Top();
 
     long nDivY = aOld.Bottom()  - aOld.Top();
     if ( nDivX == 0 ) { nMulX = 1; nDivX = 1; }
diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx
index 14cc1a0f108f..0f33c8287e87 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -1220,13 +1220,13 @@ void SAL_CALL SvxShape::setSize( const awt::Size& rSize )
             //aRect.SetSize(aLocalSize); // this call subtract 1 // http://www.openoffice.org/issues/show_bug.cgi?id=83193
             if ( !aLocalSize.Width() )
             {
-                aRect.Right() = RECT_EMPTY;
+                aRect.SetWidthEmpty();
             }
             else
                 aRect.setWidth(aLocalSize.Width());
             if ( !aLocalSize.Height() )
             {
-                aRect.Bottom() = RECT_EMPTY;
+                aRect.SetHeightEmpty();
             }
             else
                 aRect.setHeight(aLocalSize.Height());
diff --git a/sw/source/core/bastyp/swrect.cxx b/sw/source/core/bastyp/swrect.cxx
index dab5547f6c3f..ac71a2023de3 100644
--- a/sw/source/core/bastyp/swrect.cxx
+++ b/sw/source/core/bastyp/swrect.cxx
@@ -29,10 +29,8 @@
 SwRect::SwRect( const tools::Rectangle &rRect ) :
     m_Point( rRect.Left(), rRect.Top() )
 {
-    m_Size.setWidth(rRect.Right() == RECT_EMPTY ? 0 :
-                            rRect.Right()  - rRect.Left() +1);
-    m_Size.setHeight(rRect.Bottom() == RECT_EMPTY ? 0 :
-                            rRect.Bottom() - rRect.Top() + 1);
+    m_Size.setWidth( rRect.IsWidthEmpty() ? 0 : rRect.Right()  - rRect.Left() + 1);
+    m_Size.setHeight(rRect.IsHeightEmpty() ? 0 : rRect.Bottom() - rRect.Top()  + 1);
 }
 
 Point SwRect::Center() const
diff --git a/vcl/source/control/scrbar.cxx b/vcl/source/control/scrbar.cxx
index 2695f6da714b..56a23f2c9cc2 100644
--- a/vcl/source/control/scrbar.cxx
+++ b/vcl/source/control/scrbar.cxx
@@ -131,11 +131,11 @@ void ScrollBar::ImplUpdateRects( bool bUpdate )
             maThumbRect.Left()      = maTrackRect.Left()+mnThumbPixPos;
             maThumbRect.Right()     = maThumbRect.Left()+mnThumbPixSize-1;
             if ( !mnThumbPixPos )
-                maPage1Rect.Right()     = RECT_EMPTY;
+                maPage1Rect.SetWidthEmpty();
             else
                 maPage1Rect.Right()     = maThumbRect.Left()-1;
             if ( mnThumbPixPos >= (mnThumbPixRange-mnThumbPixSize) )
-                maPage2Rect.Right()     = RECT_EMPTY;
+                maPage2Rect.SetWidthEmpty();
             else
             {
                 maPage2Rect.Left()      = maThumbRect.Right()+1;
@@ -147,11 +147,11 @@ void ScrollBar::ImplUpdateRects( bool bUpdate )
             maThumbRect.Top()       = maTrackRect.Top()+mnThumbPixPos;
             maThumbRect.Bottom()    = maThumbRect.Top()+mnThumbPixSize-1;
             if ( !mnThumbPixPos )
-                maPage1Rect.Bottom()    = RECT_EMPTY;
+                maPage1Rect.SetHeightEmpty();
             else
                 maPage1Rect.Bottom()    = maThumbRect.Top()-1;
             if ( mnThumbPixPos >= (mnThumbPixRange-mnThumbPixSize) )
-                maPage2Rect.Bottom()    = RECT_EMPTY;
+                maPage2Rect.SetHeightEmpty();
             else
             {
                 maPage2Rect.Top()       = maThumbRect.Bottom()+1;


More information about the Libreoffice-commits mailing list