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

Noel Grandin noel at peralex.com
Wed May 11 06:56:05 UTC 2016


 include/svtools/ruler.hxx        |   22 +++++++++++-----------
 svtools/source/control/ruler.cxx |   33 ++++++++++++++-------------------
 svx/source/dialog/svxruler.cxx   |   19 +++++++------------
 3 files changed, 32 insertions(+), 42 deletions(-)

New commits:
commit f09ab2ccb8bbbcf9b9db3cec94ce9b59f901a1c6
Author: Noel Grandin <noel at peralex.com>
Date:   Tue May 10 15:32:29 2016 +0200

    convert RULER_INDENT to scoped enum
    
    Also separate out the INVISIBLE flag into it's own bit, because the
    constant is shared with other fields.
    Also fix some dubious code in SVX that was setting stuff on the field
    that meant nothing.
    
    Change-Id: If460be575eee38b8e9f01af4d73f93f6426c604f
    Reviewed-on: https://gerrit.libreoffice.org/24853
    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 620f3f3..42869f85 100644
--- a/include/svtools/ruler.hxx
+++ b/include/svtools/ruler.hxx
@@ -171,9 +171,9 @@ initialized:
 
     long    nPos            - offset relative to the origin in pixels
     sal_uInt16 nStyle       - bit style:
-                                RULER_INDENT_TOP    (indent of the first line)
-                                RULER_INDENT_BOTTOM (left/right indent)
-                                RULER_INDENT_BORDER (Vertical line that shows the border distance)
+                                RulerIndentStyle::Top    (indent of the first line)
+                                RulerIndentStyle::Bottom (left/right indent)
+                                RulerIndentStyle::Border (Vertical line that shows the border distance)
                                 The following bits can be set in addition
                                 to these styles:
                                 RULER_STYLE_DONTKNOW (for old position or for
@@ -502,15 +502,15 @@ struct RulerBorder
 };
 
 
-#define RULER_INDENT_TOP        ((sal_uInt16)0x0000)
-#define RULER_INDENT_BOTTOM     ((sal_uInt16)0x0001)
-#define RULER_INDENT_BORDER     ((sal_uInt16)0x0002)
-#define RULER_INDENT_STYLE      ((sal_uInt16)0x000F)
+enum class RulerIndentStyle {
+    Top, Bottom, Border
+};
 
 struct RulerIndent
 {
-    long        nPos;
-    sal_uInt16  nStyle;
+    long              nPos;
+    RulerIndentStyle  nStyle;
+    bool              bInvisible;
 };
 
 
@@ -659,7 +659,7 @@ private:
     SVT_DLLPRIVATE void ImplDrawBorders(vcl::RenderContext& rRenderContext,
                                         long nMin, long nMax, long nVirTop, long nVirBottom);
     SVT_DLLPRIVATE void ImplDrawIndent(vcl::RenderContext& rRenderContext,
-                                       const tools::Polygon& rPoly, sal_uInt16 nStyle, bool bIsHit = false);
+                                       const tools::Polygon& rPoly, bool bIsHit = false);
     SVT_DLLPRIVATE void ImplDrawIndents(vcl::RenderContext& rRenderContext,
                                         long nMin, long nMax, long nVirTop, long nVirBottom);
     SVT_DLLPRIVATE void ImplDrawTab(vcl::RenderContext& rRenderContext, const Point& rPos, sal_uInt16 nStyle);
@@ -683,7 +683,7 @@ private:
     SVT_DLLPRIVATE bool ImplHitTest( const Point& rPosition,
                                          RulerSelection* pHitTest,
                                          bool bRequiredStyle = false,
-                                         sal_uInt16 nRequiredStyle = 0 ) const;
+                                         RulerIndentStyle nRequiredStyle = RulerIndentStyle::Top ) const;
     SVT_DLLPRIVATE bool     ImplDocHitTest( const Point& rPos, RulerType eDragType, RulerSelection* pHitTest ) const;
     SVT_DLLPRIVATE bool     ImplStartDrag( RulerSelection* pHitTest, sal_uInt16 nModifier );
     SVT_DLLPRIVATE void     ImplDrag( const Point& rPos );
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx
index 81c551d..050cce7 100644
--- a/svtools/source/control/ruler.cxx
+++ b/svtools/source/control/ruler.cxx
@@ -789,13 +789,10 @@ void Ruler::ImplDrawBorders(vcl::RenderContext& rRenderContext, long nMin, long
     }
 }
 
-void Ruler::ImplDrawIndent(vcl::RenderContext& rRenderContext, const tools::Polygon& rPoly, sal_uInt16 nStyle, bool bIsHit)
+void Ruler::ImplDrawIndent(vcl::RenderContext& rRenderContext, const tools::Polygon& rPoly, bool bIsHit)
 {
     const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
 
-    if (nStyle & RULER_STYLE_INVISIBLE)
-        return;
-
     rRenderContext.SetLineColor(rStyleSettings.GetDarkShadowColor());
     rRenderContext.SetFillColor(bIsHit ? rStyleSettings.GetDarkShadowColor() : rStyleSettings.GetWorkspaceColor());
     rRenderContext.DrawPolygon(rPoly);
@@ -812,23 +809,22 @@ void Ruler::ImplDrawIndents(vcl::RenderContext& rRenderContext, long nMin, long
 
     for (j = 0; j < mpData->pIndents.size(); j++)
     {
-        if (mpData->pIndents[j].nStyle & RULER_STYLE_INVISIBLE)
+        if (mpData->pIndents[j].bInvisible)
             continue;
 
-        sal_uInt16  nStyle = mpData->pIndents[j].nStyle;
-        sal_uInt16  nIndentStyle = nStyle & RULER_INDENT_STYLE;
+        RulerIndentStyle nIndentStyle = mpData->pIndents[j].nStyle;
 
         n = mpData->pIndents[j].nPos+mpData->nNullVirOff;
 
         if ((n >= nMin) && (n <= nMax))
         {
-            if (nIndentStyle == RULER_INDENT_BORDER)
+            if (nIndentStyle == RulerIndentStyle::Border)
             {
                 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
                 rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
                 ImplVDrawLine(rRenderContext, n, nVirTop + 1, n, nVirBottom - 1);
             }
-            else if (nIndentStyle == RULER_INDENT_BOTTOM)
+            else if (nIndentStyle == RulerIndentStyle::Bottom)
             {
                 aPoly.SetPoint(Point(n + 0, nVirBottom - nIndentHeight), 0);
                 aPoly.SetPoint(Point(n - nIndentWidth2, nVirBottom - 3), 1);
@@ -855,7 +851,7 @@ void Ruler::ImplDrawIndents(vcl::RenderContext& rRenderContext, long nMin, long
                     aPoly[i] = aSet;
                 }
             }
-            if (RULER_INDENT_BORDER != nIndentStyle)
+            if (RulerIndentStyle::Border != nIndentStyle)
             {
                 bool bIsHit = false;
                 if(mxCurrentHitTest.get() != nullptr && mxCurrentHitTest->eType == RULER_TYPE_INDENT)
@@ -866,7 +862,7 @@ void Ruler::ImplDrawIndents(vcl::RenderContext& rRenderContext, long nMin, long
                 {
                     bIsHit = mnDragAryPos == j;
                 }
-                ImplDrawIndent(rRenderContext, aPoly, nStyle, bIsHit);
+                ImplDrawIndent(rRenderContext, aPoly, bIsHit);
             }
         }
     }
@@ -1476,7 +1472,7 @@ void Ruler::ImplUpdate( bool bMustCalc )
 }
 
 bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest,
-                         bool bRequireStyle, sal_uInt16 nRequiredStyle ) const
+                         bool bRequireStyle, RulerIndentStyle nRequiredStyle ) const
 {
     sal_Int32   i;
     sal_uInt16  nStyle;
@@ -1586,14 +1582,13 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest,
 
         for ( i = mpData->pIndents.size(); i; i-- )
         {
-            nStyle = mpData->pIndents[i-1].nStyle;
-            if ( (! bRequireStyle || nStyle == nRequiredStyle) &&
-                 !(nStyle & RULER_STYLE_INVISIBLE) )
+            RulerIndentStyle nIndentStyle = mpData->pIndents[i-1].nStyle;
+            if ( (! bRequireStyle || nIndentStyle == nRequiredStyle) &&
+                 !mpData->pIndents[i-1].bInvisible )
             {
-                nStyle &= RULER_INDENT_STYLE;
                 n1 = mpData->pIndents[i-1].nPos;
 
-                if ( (nStyle == RULER_INDENT_BOTTOM) != !bIsHori )
+                if ( (nIndentStyle == RulerIndentStyle::Bottom) != !bIsHori )
                 {
                     aRect.Left()    = n1-nIndentWidth2;
                     aRect.Right()   = n1+nIndentWidth2;
@@ -1781,12 +1776,12 @@ bool Ruler::ImplDocHitTest( const Point& rPos, RulerType eDragType,
 {
     Point aPos = rPos;
     bool bRequiredStyle = false;
-    sal_uInt16 nRequiredStyle = 0;
+    RulerIndentStyle nRequiredStyle = RulerIndentStyle::Top;
 
     if (eDragType == RULER_TYPE_INDENT)
     {
         bRequiredStyle = true;
-        nRequiredStyle = RULER_INDENT_BOTTOM;
+        nRequiredStyle = RulerIndentStyle::Bottom;
     }
 
     if ( mnWinStyle & WB_HORZ )
diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx
index 526924a..1dc71e8 100644
--- a/svx/source/dialog/svxruler.cxx
+++ b/svx/source/dialog/svxruler.cxx
@@ -293,14 +293,14 @@ SvxRuler::SvxRuler(
         for(size_t nIn = 0; nIn < mpIndents.size(); nIn++)
         {
             mpIndents[nIn].nPos = 0;
-            mpIndents[nIn].nStyle = RULER_STYLE_DONTKNOW;
+            mpIndents[nIn].nStyle = RulerIndentStyle::Top;
         }
 
-        mpIndents[0].nStyle = RULER_STYLE_DONTKNOW;
-        mpIndents[1].nStyle = RULER_STYLE_DONTKNOW;
-        mpIndents[INDENT_FIRST_LINE].nStyle = RULER_INDENT_TOP;
-        mpIndents[INDENT_LEFT_MARGIN].nStyle = RULER_INDENT_BOTTOM;
-        mpIndents[INDENT_RIGHT_MARGIN].nStyle = RULER_INDENT_BOTTOM;
+        mpIndents[0].nStyle = RulerIndentStyle::Top;
+        mpIndents[1].nStyle = RulerIndentStyle::Top;
+        mpIndents[INDENT_FIRST_LINE].nStyle = RulerIndentStyle::Top;
+        mpIndents[INDENT_LEFT_MARGIN].nStyle = RulerIndentStyle::Bottom;
+        mpIndents[INDENT_RIGHT_MARGIN].nStyle = RulerIndentStyle::Bottom;
     }
 
     if( (nFlags & SvxRulerSupportFlags::BORDERS) ==  SvxRulerSupportFlags::BORDERS )
@@ -916,10 +916,7 @@ void SvxRuler::UpdatePara()
         mpIndents[INDENT_FIRST_LINE].nPos   = ConvertHPosPixel(leftFirstLine);
         mpIndents[INDENT_RIGHT_MARGIN].nPos = ConvertHPosPixel(rightMargin);
 
-        if( mxParaItem->IsAutoFirst() )
-            mpIndents[INDENT_FIRST_LINE].nStyle |= RULER_STYLE_INVISIBLE;
-        else
-            mpIndents[INDENT_FIRST_LINE].nStyle &= ~RULER_STYLE_INVISIBLE;
+        mpIndents[INDENT_FIRST_LINE].bInvisible = mxParaItem->IsAutoFirst();
 
         SetIndents(INDENT_COUNT, &mpIndents[0] + INDENT_GAP);
     }
@@ -3179,7 +3176,6 @@ bool SvxRuler::StartDrag()
             sal_uInt16 nIndent = INDENT_LEFT_MARGIN;
             if((nIndent) == GetDragAryPos() + INDENT_GAP) {  // Left paragraph indent
                 mpIndents[0] = mpIndents[INDENT_FIRST_LINE];
-                mpIndents[0].nStyle |= RULER_STYLE_DONTKNOW;
                 EvalModifier();
             }
             else
@@ -3187,7 +3183,6 @@ bool SvxRuler::StartDrag()
                 nDragType = SvxRulerDragFlags::OBJECT;
             }
             mpIndents[1] = mpIndents[GetDragAryPos() + INDENT_GAP];
-            mpIndents[1].nStyle |= RULER_STYLE_DONTKNOW;
             break;
         }
         case RULER_TYPE_TAB: // Tabs (Modifier)


More information about the Libreoffice-commits mailing list