vcl/source/control/spinfld.cxx |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

New commits:
commit 869b88488ac443cc64943254064da20b0f361c56
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon May 13 16:37:45 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Tue May 14 07:25:44 2024 +0200

    tdf#160824 vcl: Require mouse over spinfield to mouse-wheel through values
    
    In the same way that
    
        commit 22250df05830700b2555348b8ac46ee1007d0e5d
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Fri Dec 8 11:50:40 2023 +0100
    
            tdf#158548 vcl: Require mouse over listbox to mouse-wheel through 
entries
    
    restricted changing listbox values for the focused
    listbox on mouse-wheel to the case when the listbox
    is also hovered over by the mouse, do the same for
    `SpinField` as well, to avoid accidently changing
    the value as described e.g. for the tdf#160824
    scenario.
    
    This is also in line with Qt spin boxes that
    only change their values on mouse-wheel when
    the mouse pointer is above them.
    
    For the gtk3 VCL plugin that uses native spin boxes,
    this commit has no effect, and the value doesn't
    change on mouse-wheel at all.
    
    Change-Id: I22277294f76655cd13b1dc57416c82afe44460d1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167604
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/source/control/spinfld.cxx b/vcl/source/control/spinfld.cxx
index 973825a3a977..1eb8357a2940 100644
--- a/vcl/source/control/spinfld.cxx
+++ b/vcl/source/control/spinfld.cxx
@@ -543,9 +543,18 @@ bool SpinField::EventNotify(NotifyEvent& rNEvt)
     {
         if ((rNEvt.GetCommandEvent()->GetCommand() == CommandEventId::Wheel) 
&& !IsReadOnly())
         {
+            const Point& rMousePos = 
rNEvt.GetCommandEvent()->GetMousePosPixel();
+            bool bMouseHovered = maUpperRect.Contains(rMousePos) || 
maLowerRect.Contains(rMousePos);
+            if (!bMouseHovered && mpEdit)
+            {
+                const tools::Rectangle aEditRect(mpEdit->GetPosPixel(), 
mpEdit->GetSizePixel());
+                bMouseHovered = aEditRect.Contains(rMousePos);
+            }
+
             MouseWheelBehaviour 
nWheelBehavior(GetSettings().GetMouseSettings().GetWheelBehavior());
-            if (nWheelBehavior == MouseWheelBehaviour::ALWAYS
-               || (nWheelBehavior == MouseWheelBehaviour::FocusOnly && 
HasChildPathFocus()))
+            if (bMouseHovered
+                && (nWheelBehavior == MouseWheelBehaviour::ALWAYS
+                    || (nWheelBehavior == MouseWheelBehaviour::FocusOnly && 
HasChildPathFocus())))
             {
                 const CommandWheelData* pData = 
rNEvt.GetCommandEvent()->GetWheelData();
                 if (pData->GetMode() == CommandWheelMode::SCROLL)

Reply via email to