[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - include/vcl vcl/source

Caolán McNamara caolanm at redhat.com
Fri Feb 19 20:17:31 UTC 2016


 include/vcl/spin.h             |    8 ++
 vcl/source/control/spinfld.cxx |  114 +++++++++++++++++++++--------------------
 vcl/source/window/toolbox.cxx  |    4 -
 3 files changed, 71 insertions(+), 55 deletions(-)

New commits:
commit 63212b4614c134233f520cee95611ec5e7b3d8a0
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Feb 18 14:16:23 2016 +0000

    Resolves: tdf#97953 spinbuttons are not suitable for reuse as up/down arrows
    
    (cherry picked from commit 4f034adcb79684bc4138e2f9708defd8a3532f74)
    
    Change-Id: Ibcd7bd4099210a26513caac6e3b16a88a4c8abad
    
    refactor ImplDrawSpinButton
    
    there is (supposed to be anyway) no logic change here,
    just unwind the overly complex flow
    
    Change-Id: I9c96f41b0480a60c486b476f383d856b464cd62d
    (cherry picked from commit 55b33456c14aa5311fb0e3d71f1cad4fbd73cbef)
    Reviewed-on: https://gerrit.libreoffice.org/22486
    Reviewed-by: David Ostrovsky <david at ostrovsky.org>
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/vcl/spin.h b/include/vcl/spin.h
index e4ce463..0f2f3eb 100644
--- a/include/vcl/spin.h
+++ b/include/vcl/spin.h
@@ -24,11 +24,19 @@
 
 class Rectangle;
 
+// Draw Spinners as found in a SpinButton. Some themes like gtk3 will draw +- elements here,
+// so these are only suitable in the context of SpinButtons
 void ImplDrawSpinButton(vcl::RenderContext& rRenderContext, vcl::Window* pWindow,
                         const Rectangle& rUpperRect, const Rectangle& rLowerRect,
                         bool bUpperIn, bool bLowerIn, bool bUpperEnabled = true, bool bLowerEnabled = true,
                         bool bHorz = false, bool bMirrorHorz = false);
 
+// Draw Up/Down buttons suitable for use in any context
+void ImplDrawUpDownButtons(vcl::RenderContext& rRenderContext,
+                           const Rectangle& rUpperRect, const Rectangle& rLowerRect,
+                           bool bUpperIn, bool bLowerIn, bool bUpperEnabled = true, bool bLowerEnabled = true,
+                           bool bHorz = false, bool bMirrorHorz = false);
+
 #endif // INCLUDED_VCL_SPIN_H
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/control/spinfld.cxx b/vcl/source/control/spinfld.cxx
index 750900f..d4bb3a6 100644
--- a/vcl/source/control/spinfld.cxx
+++ b/vcl/source/control/spinfld.cxx
@@ -158,49 +158,7 @@ void ImplDrawSpinButton(vcl::RenderContext& rRenderContext, vcl::Window* pWindow
                         bool bUpperIn, bool bLowerIn, bool bUpperEnabled, bool bLowerEnabled,
                         bool bHorz, bool bMirrorHorz)
 {
-    DecorationView aDecoView(&rRenderContext);
-
-    DrawButtonFlags nStyle = DrawButtonFlags::NoLeftLightBorder;
-    DrawSymbolFlags nSymStyle = DrawSymbolFlags::NONE;
-
-    SymbolType eType1, eType2;
-
-    const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
-    if ( rStyleSettings.GetOptions() & StyleSettingsOptions::SpinArrow )
-    {
-        // arrows are only use in OS/2 look
-        if ( bHorz )
-        {
-            eType1 = bMirrorHorz ? SymbolType::ARROW_RIGHT : SymbolType::ARROW_LEFT;
-            eType2 = bMirrorHorz ? SymbolType::ARROW_LEFT : SymbolType::ARROW_RIGHT;
-        }
-        else
-        {
-            eType1 = SymbolType::ARROW_UP;
-            eType2 = SymbolType::ARROW_DOWN;
-        }
-    }
-    else
-    {
-        if ( bHorz )
-        {
-            eType1 = bMirrorHorz ? SymbolType::SPIN_RIGHT : SymbolType::SPIN_LEFT;
-            eType2 = bMirrorHorz ? SymbolType::SPIN_LEFT : SymbolType::SPIN_RIGHT;
-        }
-        else
-        {
-            eType1 = SymbolType::SPIN_UP;
-            eType2 = SymbolType::SPIN_DOWN;
-        }
-    }
-
-    // draw upper/left Button
-    DrawButtonFlags nTempStyle = nStyle;
-    if (bUpperIn)
-        nTempStyle |= DrawButtonFlags::Pressed;
-
     bool bNativeOK = false;
-    Rectangle aUpRect;
 
     if (pWindow)
     {
@@ -236,15 +194,66 @@ void ImplDrawSpinButton(vcl::RenderContext& rRenderContext, vcl::Window* pWindow
             bNativeOK = ImplDrawNativeSpinbuttons(rRenderContext, aValue);
     }
 
-    if (!bNativeOK)
-        aUpRect = aDecoView.DrawButton(rUpperRect, nTempStyle);
+    if (bNativeOK)
+        return;
+
+    ImplDrawUpDownButtons(rRenderContext,
+                          rUpperRect, rLowerRect,
+                          bUpperIn, bLowerIn, bUpperEnabled, bLowerEnabled,
+                          bHorz, bMirrorHorz);
+}
+
+void ImplDrawUpDownButtons(vcl::RenderContext& rRenderContext,
+                           const Rectangle& rUpperRect, const Rectangle& rLowerRect,
+                           bool bUpperIn, bool bLowerIn, bool bUpperEnabled, bool bLowerEnabled,
+                           bool bHorz, bool bMirrorHorz)
+{
+    DecorationView aDecoView(&rRenderContext);
+
+    SymbolType eType1, eType2;
+
+    const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
+    if ( rStyleSettings.GetOptions() & StyleSettingsOptions::SpinArrow )
+    {
+        // arrows are only use in OS/2 look
+        if ( bHorz )
+        {
+            eType1 = bMirrorHorz ? SymbolType::ARROW_RIGHT : SymbolType::ARROW_LEFT;
+            eType2 = bMirrorHorz ? SymbolType::ARROW_LEFT : SymbolType::ARROW_RIGHT;
+        }
+        else
+        {
+            eType1 = SymbolType::ARROW_UP;
+            eType2 = SymbolType::ARROW_DOWN;
+        }
+    }
+    else
+    {
+        if ( bHorz )
+        {
+            eType1 = bMirrorHorz ? SymbolType::SPIN_RIGHT : SymbolType::SPIN_LEFT;
+            eType2 = bMirrorHorz ? SymbolType::SPIN_LEFT : SymbolType::SPIN_RIGHT;
+        }
+        else
+        {
+            eType1 = SymbolType::SPIN_UP;
+            eType2 = SymbolType::SPIN_DOWN;
+        }
+    }
+
+    DrawButtonFlags nStyle = DrawButtonFlags::NoLeftLightBorder;
+    // draw upper/left Button
+    if (bUpperIn)
+        nStyle |= DrawButtonFlags::Pressed;
+
+    Rectangle aUpRect = aDecoView.DrawButton(rUpperRect, nStyle);
 
+    nStyle = DrawButtonFlags::NoLeftLightBorder;
     // draw lower/right Button
     if (bLowerIn)
         nStyle |= DrawButtonFlags::Pressed;
-    Rectangle aLowRect;
-    if(!bNativeOK)
-        aLowRect = aDecoView.DrawButton(rLowerRect, nStyle);
+
+    Rectangle aLowRect = aDecoView.DrawButton(rLowerRect, nStyle);
 
      // make use of additional default edge
     aUpRect.Left()--;
@@ -285,16 +294,15 @@ void ImplDrawSpinButton(vcl::RenderContext& rRenderContext, vcl::Window* pWindow
             aLowRect.Top()++;
     }
 
-    DrawSymbolFlags nTempSymStyle = nSymStyle;
+    DrawSymbolFlags nSymStyle = DrawSymbolFlags::NONE;
     if (!bUpperEnabled)
-        nTempSymStyle |= DrawSymbolFlags::Disable;
-    if (!bNativeOK)
-        aDecoView.DrawSymbol(aUpRect, eType1, rStyleSettings.GetButtonTextColor(), nTempSymStyle);
+        nSymStyle |= DrawSymbolFlags::Disable;
+    aDecoView.DrawSymbol(aUpRect, eType1, rStyleSettings.GetButtonTextColor(), nSymStyle);
 
+    nSymStyle = DrawSymbolFlags::NONE;
     if (!bLowerEnabled)
         nSymStyle |= DrawSymbolFlags::Disable;
-    if (!bNativeOK)
-        aDecoView.DrawSymbol(aLowRect, eType2, rStyleSettings.GetButtonTextColor(), nSymStyle);
+    aDecoView.DrawSymbol(aLowRect, eType2, rStyleSettings.GetButtonTextColor(), nSymStyle);
 }
 
 void SpinField::ImplInitSpinFieldData()
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx
index 62140e4..140a473 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -2905,8 +2905,8 @@ void ToolBox::ImplDrawSpin(vcl::RenderContext& rRenderContext, bool bUpperIn, bo
         bTmpLower = false;
     }
 
-    ImplDrawSpinButton(rRenderContext, this, maUpperRect, maLowerRect,
-                       bUpperIn, bLowerIn, bTmpUpper, bTmpLower, !mbHorz);
+    ImplDrawUpDownButtons(rRenderContext, maUpperRect, maLowerRect,
+                          bUpperIn, bLowerIn, bTmpUpper, bTmpLower, !mbHorz);
 }
 
 void ToolBox::ImplDrawSeparator(vcl::RenderContext& rRenderContext, sal_uInt16 nPos, const Rectangle& rRect)


More information about the Libreoffice-commits mailing list