[Libreoffice-commits] core.git: 2 commits - include/svtools svtools/source svx/source

Noel Grandin noel at peralex.com
Wed May 11 06:59:09 UTC 2016


 include/svtools/ruler.hxx        |   75 +++++++++++++++++++++------------------
 svtools/source/control/ruler.cxx |   44 +++++++++++-----------
 svx/source/dialog/svxruler.cxx   |   32 ++++++++--------
 3 files changed, 79 insertions(+), 72 deletions(-)

New commits:
commit 2d21ec205d1eca652fd501790d9d86a3336d6074
Author: Noel Grandin <noel at peralex.com>
Date:   Tue May 10 15:38:49 2016 +0200

    Convert RULER_BORDER to scoped enum
    
    Change-Id: Ia8dcffe817e6f7a5f8470ce08c25103c527d221d
    Reviewed-on: https://gerrit.libreoffice.org/24854
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/include/svtools/ruler.hxx b/include/svtools/ruler.hxx
index ee6340c..0db49dc 100644
--- a/include/svtools/ruler.hxx
+++ b/include/svtools/ruler.hxx
@@ -139,25 +139,25 @@ has to be passed. In the array, the following values have to be initialized:
     long    nWidth          - column spacing in pixels (can also be 0, for example,
                               for table columns)
     sal_uInt16 nStyle       - bit style:
-                                RULER_BORDER_SIZEABLE
+                                RulerBorderStyle::Sizeable
                                 Column spacing can be changed. This flag should
                                 only be set if the size of the spacing is changed,
                                 not that of a cell.
-                                RULER_BORDER_MOVEABLE
+                                RulerBorderStyle::Moveable
                                 Column spacing/border can be moved. Whenever
                                 table borders are to be moved, this flag should
                                 be set instead of SIZEABLE (SIZEABLE indicates
                                 that the size of a spacing, not that of a single
                                 cell can be changed).
-                                RULER_BORDER_VARIABLE
+                                RulerBorderStyle::Variable
                                 Not all of the column spacings are equal
-                                RULER_BORDER_TABLE
+                                RulerBorderStyle::Table
                                 Table border. Whenever this style is set, the column
                                 width must be 0.
-                                RULER_BORDER_SNAP
+                                RulerBorderStyle::Snap
                                 Auxiliary line. Whenever this style is set, the
                                 column width must be 0.
-                                RULER_BORDER_MARGIN
+                                RulerBorderStyle::Margin
                                 Margin. Whenever this style is set, the column
                                 width must be 0.
 
@@ -487,23 +487,28 @@ enum class RulerDragSize {
 #define RULER_MARGIN_SIZEABLE   ((sal_uInt16)0x0001)
 
 
-#define RULER_BORDER_SIZEABLE   ((sal_uInt16)0x0001)
-#define RULER_BORDER_MOVEABLE   ((sal_uInt16)0x0002)
-#define RULER_BORDER_VARIABLE   ((sal_uInt16)0x0004)
-#define RULER_BORDER_TABLE      ((sal_uInt16)0x0008)
-#define RULER_BORDER_SNAP       ((sal_uInt16)0x0010)
-#define RULER_BORDER_MARGIN     ((sal_uInt16)0x0020)
+enum class RulerBorderStyle {
+    Sizeable   = 0x0001,
+    Moveable   = 0x0002,
+    Variable   = 0x0004,
+    Table      = 0x0008,
+    Snap       = 0x0010,
+    Margin     = 0x0020,
+    Invisible  = 0x0040
+};
+namespace o3tl {
+    template<> struct typed_flags<RulerBorderStyle> : is_typed_flags<RulerBorderStyle, 0x007f> {};
+}
 
 struct RulerBorder
 {
-    long        nPos;
-    long        nWidth;
-    sal_uInt16  nStyle;
-    long        nMinPos; //minimum/maximum position, supported for table borders/rows
-    long        nMaxPos;
+    long             nPos;
+    long             nWidth;
+    RulerBorderStyle nStyle;
+    long             nMinPos; //minimum/maximum position, supported for table borders/rows
+    long             nMaxPos;
 };
 
-
 enum class RulerIndentStyle {
     Top, Bottom, Border
 };
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx
index 243e93c..e97a098 100644
--- a/svtools/source/control/ruler.cxx
+++ b/svtools/source/control/ruler.cxx
@@ -701,7 +701,7 @@ void Ruler::ImplDrawBorders(vcl::RenderContext& rRenderContext, long nMin, long
 
     for (i = 0; i < mpData->pBorders.size(); i++)
     {
-        if (mpData->pBorders[i].nStyle & RULER_STYLE_INVISIBLE)
+        if (mpData->pBorders[i].nStyle & RulerBorderStyle::Invisible)
             continue;
 
         n1 = mpData->pBorders[i].nPos + mpData->nNullVirOff;
@@ -727,7 +727,7 @@ void Ruler::ImplDrawBorders(vcl::RenderContext& rRenderContext, long nMin, long
                 rRenderContext.SetLineColor(rStyleSettings.GetDarkShadowColor());
                 ImplVDrawLine(rRenderContext, n2, nVirTop, n2, nVirBottom);
 
-                if (mpData->pBorders[i].nStyle & RULER_BORDER_VARIABLE)
+                if (mpData->pBorders[i].nStyle & RulerBorderStyle::Variable)
                 {
                     if (n2 - n1 > RULER_VAR_SIZE + 4)
                     {
@@ -754,7 +754,7 @@ void Ruler::ImplDrawBorders(vcl::RenderContext& rRenderContext, long nMin, long
                     }
                 }
 
-                if (mpData->pBorders[i].nStyle & RULER_BORDER_SIZEABLE)
+                if (mpData->pBorders[i].nStyle & RulerBorderStyle::Sizeable)
                 {
                     if (n2 - n1 > RULER_VAR_SIZE + 10)
                     {
@@ -772,9 +772,9 @@ void Ruler::ImplDrawBorders(vcl::RenderContext& rRenderContext, long nMin, long
                 n = n1 + ((n2 - n1) / 2);
                 rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
 
-                if (mpData->pBorders[i].nStyle & RULER_BORDER_SNAP)
+                if (mpData->pBorders[i].nStyle & RulerBorderStyle::Snap)
                     ImplVDrawLine(rRenderContext, n, nVirTop, n, nVirBottom);
-                else if (mpData->pBorders[i].nStyle & RULER_BORDER_MARGIN)
+                else if (mpData->pBorders[i].nStyle & RulerBorderStyle::Margin)
                     ImplVDrawLine(rRenderContext, n, nVirTop, n, nVirBottom);
                 else
                 {
@@ -1643,15 +1643,15 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest,
 
         if ( (nX >= n1) && (nX <= n2) )
         {
-            nStyle = mpData->pBorders[i-1].nStyle;
-            if ( !(nStyle & RULER_STYLE_INVISIBLE) )
+            RulerBorderStyle nBorderStyle = mpData->pBorders[i-1].nStyle;
+            if ( !(nBorderStyle & RulerBorderStyle::Invisible) )
             {
                 pHitTest->eType     = RULER_TYPE_BORDER;
                 pHitTest->nAryPos   = i-1;
 
-                if ( !(nStyle & RULER_BORDER_SIZEABLE) )
+                if ( !(nBorderStyle & RulerBorderStyle::Sizeable) )
                 {
-                    if ( nStyle & RULER_BORDER_MOVEABLE )
+                    if ( nBorderStyle & RulerBorderStyle::Moveable )
                     {
                         pHitTest->bSizeBar = true;
                         pHitTest->mnDragSize = RulerDragSize::Move;
@@ -1683,7 +1683,7 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest,
                     }
                     else
                     {
-                        if ( nStyle & RULER_BORDER_MOVEABLE )
+                        if ( nBorderStyle & RulerBorderStyle::Moveable )
                         {
                             pHitTest->bSizeBar = true;
                             pHitTest->mnDragSize = RulerDragSize::Move;
diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx
index 5695a3c..5994360 100644
--- a/svx/source/dialog/svxruler.cxx
+++ b/svx/source/dialog/svxruler.cxx
@@ -319,7 +319,7 @@ SvxRuler::SvxRuler(
         {
             mpObjectBorders[nBorder].nPos   = 0;
             mpObjectBorders[nBorder].nWidth = 0;
-            mpObjectBorders[nBorder].nStyle = RULER_BORDER_MOVEABLE;
+            mpObjectBorders[nBorder].nStyle = RulerBorderStyle::Moveable;
         }
     }
 
@@ -796,19 +796,19 @@ void SvxRuler::UpdateColumns()
     {
         mpBorders.resize(mxColumnItem->Count());
 
-        sal_uInt16 nStyleFlags = RULER_BORDER_VARIABLE;
+        RulerBorderStyle nStyleFlags = RulerBorderStyle::Variable;
 
         bool bProtectColumns =
                     mxRulerImpl->aProtectItem.IsSizeProtected() ||
                     mxRulerImpl->aProtectItem.IsPosProtected();
 
         if( !bProtectColumns )
-            nStyleFlags |= RULER_BORDER_MOVEABLE;
+            nStyleFlags |= RulerBorderStyle::Moveable;
 
         if( mxColumnItem->IsTable() )
-            nStyleFlags |= RULER_BORDER_TABLE;
+            nStyleFlags |= RulerBorderStyle::Table;
         else if ( !bProtectColumns )
-            nStyleFlags |= RULER_BORDER_SIZEABLE;
+            nStyleFlags |= RulerBorderStyle::Sizeable;
 
         sal_uInt16 nBorders = mxColumnItem->Count();
 
@@ -819,7 +819,7 @@ void SvxRuler::UpdateColumns()
         {
             mpBorders[i].nStyle = nStyleFlags;
             if(!mxColumnItem->At(i).bVisible)
-                mpBorders[i].nStyle |= RULER_STYLE_INVISIBLE;
+                mpBorders[i].nStyle |= RulerBorderStyle::Invisible;
 
             mpBorders[i].nPos = ConvertPosPixel(mxColumnItem->At(i).nEnd + lAppNullOffset);
 
commit dc29492cd77a10163f004836afffdf8bd3c381d1
Author: Noel Grandin <noel at peralex.com>
Date:   Tue May 10 15:21:17 2016 +0200

    Convert RULER_DRAGSIZE to scoped enum
    
    Change-Id: Iddf7562273072eb4d5d60efc730d5c40bfc79f46
    Reviewed-on: https://gerrit.libreoffice.org/24852
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/include/svtools/ruler.hxx b/include/svtools/ruler.hxx
index 42869f85..ee6340c 100644
--- a/include/svtools/ruler.hxx
+++ b/include/svtools/ruler.hxx
@@ -264,9 +264,9 @@ it has been dragged. There are the following query methods:
     - GetDragSize()
         If Borders are dragged, this can be used to query whether the size
         resp. which side or the position should be changed.
-            RULER_DRAGSIZE_MOVE oder 0      - Move
-            RULER_DRAGSIZE_1                - left/upper border
-            RULER_DRAGSIZE_2                - right/bottom border
+            RulerDragSize::Move oder 0      - Move
+            RulerDragSize::N1                - left/upper border
+            RulerDragSize::N2                - right/bottom border
 
     - IsDragDelete()
         This method can be used to query whether the mouse has been
@@ -473,9 +473,11 @@ enum RulerExtra { RULER_EXTRA_DONTKNOW,
 #define RULER_STYLE_DONTKNOW    ((sal_uInt16)0x4000)
 #define RULER_STYLE_INVISIBLE   ((sal_uInt16)0x2000)
 
-#define RULER_DRAGSIZE_MOVE     0
-#define RULER_DRAGSIZE_1        1
-#define RULER_DRAGSIZE_2        2
+enum class RulerDragSize {
+    Move,
+    N1,
+    N2
+};
 
 #define RULER_MOUSE_BORDERMOVE  5
 #define RULER_MOUSE_BORDERWIDTH 5
@@ -538,19 +540,19 @@ struct RulerLine
 
 struct RulerSelection
 {
-    long        nPos;
-    RulerType   eType;
-    sal_uInt16  nAryPos;
-    sal_uInt16  mnDragSize;
-    bool        bSize;
-    bool        bSizeBar;
-    bool        bExpandTest;
+    long          nPos;
+    RulerType     eType;
+    sal_uInt16    nAryPos;
+    RulerDragSize mnDragSize;
+    bool          bSize;
+    bool          bSizeBar;
+    bool          bExpandTest;
 
     RulerSelection()
         : nPos(0)
         , eType(RULER_TYPE_DONTKNOW)
         , nAryPos(0)
-        , mnDragSize(0)
+        , mnDragSize(RulerDragSize::Move)
         , bSize(false)
         , bSizeBar(false)
         , bExpandTest( false )
@@ -618,7 +620,7 @@ private:
     WinBits         mnWinStyle;
     sal_uInt16      mnUnitIndex;
     sal_uInt16      mnDragAryPos;
-    sal_uInt16      mnDragSize;
+    RulerDragSize   mnDragSize;
     sal_uInt16      mnDragModifier;
     sal_uInt16      mnExtraStyle;
     sal_uInt16      mnExtraClicks;
@@ -741,7 +743,7 @@ public:
     RulerType       GetDragType() const { return meDragType; }
     long            GetDragPos() const { return mnDragPos; }
     sal_uInt16      GetDragAryPos() const { return mnDragAryPos; }
-    sal_uInt16      GetDragSize() const { return mnDragSize; }
+    RulerDragSize   GetDragSize() const { return mnDragSize; }
     bool            IsDragDelete() const { return mbDragDelete; }
     bool            IsDragCanceled() const { return mbDragCanceled; }
     sal_uInt16      GetDragModifier() const { return mnDragModifier; }
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx
index 050cce7..243e93c 100644
--- a/svtools/source/control/ruler.cxx
+++ b/svtools/source/control/ruler.cxx
@@ -237,7 +237,7 @@ void Ruler::ImplInit( WinBits nWinBits )
     mnDragPos       = 0;                    // Drag-Position (Null point)
     mnUpdateEvtId   = nullptr;                    // Update event was not sent yet
     mnDragAryPos    = 0;                    // Drag-Array-Index
-    mnDragSize      = 0;                    // Did size change at dragging
+    mnDragSize      = RulerDragSize::Move;  // Did size change at dragging
     mnDragModifier  = 0;                    // Modifier key at dragging
     mnExtraStyle    = 0;                    // Style of Extra field
     mnExtraClicks   = 0;                    // No. of clicks for Extra field
@@ -1500,7 +1500,7 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest,
 
     // #i32608#
     pHitTest->nAryPos = 0;
-    pHitTest->mnDragSize = 0;
+    pHitTest->mnDragSize = RulerDragSize::Move;
     pHitTest->bSize = false;
     pHitTest->bSizeBar = false;
 
@@ -1654,7 +1654,7 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest,
                     if ( nStyle & RULER_BORDER_MOVEABLE )
                     {
                         pHitTest->bSizeBar = true;
-                        pHitTest->mnDragSize = RULER_DRAGSIZE_MOVE;
+                        pHitTest->mnDragSize = RulerDragSize::Move;
                     }
                 }
                 else
@@ -1674,19 +1674,19 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest,
                     if ( nX <= n1+nMOff )
                     {
                         pHitTest->bSize = true;
-                        pHitTest->mnDragSize = RULER_DRAGSIZE_1;
+                        pHitTest->mnDragSize = RulerDragSize::N1;
                     }
                     else if ( nX >= n2-nMOff )
                     {
                         pHitTest->bSize = true;
-                        pHitTest->mnDragSize = RULER_DRAGSIZE_2;
+                        pHitTest->mnDragSize = RulerDragSize::N2;
                     }
                     else
                     {
                         if ( nStyle & RULER_BORDER_MOVEABLE )
                         {
                             pHitTest->bSizeBar = true;
-                            pHitTest->mnDragSize = RULER_DRAGSIZE_MOVE;
+                            pHitTest->mnDragSize = RulerDragSize::Move;
                         }
                     }
                 }
@@ -1871,7 +1871,7 @@ bool Ruler::ImplStartDrag( RulerSelection* pHitTest, sal_uInt16 nModifier )
         meDragType      = RULER_TYPE_DONTKNOW;
         mnDragPos       = 0;
         mnDragAryPos    = 0;
-        mnDragSize      = 0;
+        mnDragSize      = RulerDragSize::Move;
         mnDragModifier  = 0;
         mpData          = mpSaveData;
     }
@@ -1972,7 +1972,7 @@ void Ruler::ImplEndDrag()
     meDragType      = RULER_TYPE_DONTKNOW;
     mnDragPos       = 0;
     mnDragAryPos    = 0;
-    mnDragSize      = 0;
+    mnDragSize      = RulerDragSize::Move;
     mbDragCanceled  = false;
     mbDragDelete    = false;
     mnDragModifier  = 0;
@@ -2067,18 +2067,18 @@ void Ruler::MouseMove( const MouseEvent& rMEvt )
         {
             if (mnWinStyle & WB_HORZ)
             {
-                if (mxCurrentHitTest->mnDragSize == RULER_DRAGSIZE_1)
+                if (mxCurrentHitTest->mnDragSize == RulerDragSize::N1)
                     ePtrStyle = PointerStyle::TabSelectW;
-                else if (mxCurrentHitTest->mnDragSize == RULER_DRAGSIZE_2)
+                else if (mxCurrentHitTest->mnDragSize == RulerDragSize::N2)
                     ePtrStyle = PointerStyle::TabSelectE;
                 else
                     ePtrStyle = PointerStyle::ESize;
             }
             else
             {
-                if (mxCurrentHitTest->mnDragSize == RULER_DRAGSIZE_1)
+                if (mxCurrentHitTest->mnDragSize == RulerDragSize::N1)
                     ePtrStyle = PointerStyle::WindowNSize;
-                else if (mxCurrentHitTest->mnDragSize == RULER_DRAGSIZE_2)
+                else if (mxCurrentHitTest->mnDragSize == RulerDragSize::N2)
                     ePtrStyle = PointerStyle::WindowSSize;
                 else
                     ePtrStyle = PointerStyle::SSize;
diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx
index 1dc71e8..5695a3c 100644
--- a/svx/source/dialog/svxruler.cxx
+++ b/svx/source/dialog/svxruler.cxx
@@ -1755,7 +1755,7 @@ void SvxRuler::DragBorders()
         nIndex = 0;
     }
 
-    sal_uInt16 nDragSize = GetDragSize();
+    RulerDragSize nDragSize = GetDragSize();
     long lDiff = 0;
 
     // the drag position has to be corrected to be able to prevent borders from passing each other
@@ -1763,7 +1763,7 @@ void SvxRuler::DragBorders()
 
     switch(nDragSize)
     {
-        case RULER_DRAGSIZE_MOVE:
+        case RulerDragSize::Move:
         {
 ADD_DEBUG_TEXT("lLastLMargin: ", OUString::number(mxRulerImpl->lLastLMargin))
             if(GetDragType() == RULER_TYPE_BORDER)
@@ -1925,14 +1925,14 @@ ADD_DEBUG_TEXT("lLastLMargin: ", OUString::number(mxRulerImpl->lLastLMargin))
                 mpBorders[nIndex].nPos += lDiff;
             break;
         }
-      case RULER_DRAGSIZE_1:
+      case RulerDragSize::N1:
         {
             lDiff = lPos - mpBorders[nIndex].nPos;
             mpBorders[nIndex].nWidth += mpBorders[nIndex].nPos - lPos;
             mpBorders[nIndex].nPos = lPos;
             break;
         }
-      case RULER_DRAGSIZE_2:
+      case RulerDragSize::N2:
         {
             const long nOld = mpBorders[nIndex].nWidth;
             mpBorders[nIndex].nWidth = lPos - mpBorders[nIndex].nPos;
@@ -1942,7 +1942,7 @@ ADD_DEBUG_TEXT("lLastLMargin: ", OUString::number(mxRulerImpl->lLastLMargin))
     }
     if(!bRightIndentsCorrected &&
        GetActRightColumn() == nIndex &&
-       nDragSize != RULER_DRAGSIZE_2 &&
+       nDragSize != RulerDragSize::N2 &&
        !mpIndents.empty() &&
        !mxRulerImpl->bIsTableRows)
     {
@@ -1950,7 +1950,7 @@ ADD_DEBUG_TEXT("lLastLMargin: ", OUString::number(mxRulerImpl->lLastLMargin))
     }
     else if(!bLeftIndentsCorrected &&
             GetActLeftColumn() == nIndex &&
-            nDragSize != RULER_DRAGSIZE_1 &&
+            nDragSize != RulerDragSize::N1 &&
             !mpIndents.empty())
     {
         UpdateParaContents_Impl(lDiff, MOVE_LEFT);
@@ -1961,7 +1961,7 @@ ADD_DEBUG_TEXT("lLastLMargin: ", OUString::number(mxRulerImpl->lLastLMargin))
 void SvxRuler::DragObjectBorder()
 {
     /* Dragging of object edges */
-    if(RULER_DRAGSIZE_MOVE == GetDragSize())
+    if(RulerDragSize::Move == GetDragSize())
     {
         const long lPosition = MakePositionSticky(GetCorrectedDragPos(), GetLeftFrameMargin());
 
@@ -2770,7 +2770,7 @@ void SvxRuler::CalcMinMax()
         const sal_uInt16 nIdx = GetDragAryPos();
         switch(GetDragSize())
         {
-          case RULER_DRAGSIZE_1 :
+          case RulerDragSize::N1 :
             {
                 nMaxRight = mpBorders[nIdx].nPos +
                     mpBorders[nIdx].nWidth + lNullPix;
@@ -2801,7 +2801,7 @@ void SvxRuler::CalcMinMax()
                 nMaxLeft += nDragOffset;
                 break;
             }
-          case RULER_DRAGSIZE_MOVE:
+          case RulerDragSize::Move:
             {
                 if(mxColumnItem.get())
                 {
@@ -2982,7 +2982,7 @@ void SvxRuler::CalcMinMax()
                 }
                 break;
             }
-          case RULER_DRAGSIZE_2:
+          case RulerDragSize::N2:
             {
                 nMaxLeft = lNullPix + mpBorders[nIdx].nPos;
                 if(nIdx == mxColumnItem->Count()-2) { // last column


More information about the Libreoffice-commits mailing list