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

Miklos Vajna vmiklos at collabora.co.uk
Mon Nov 23 07:48:09 PST 2015


 sw/source/uibase/docvw/SidebarWin.cxx |   55 +++++++++++++++++++++++++++-------
 vcl/source/control/scrbar.cxx         |   14 ++++++++
 2 files changed, 58 insertions(+), 11 deletions(-)

New commits:
commit 527190f0c0284a9a4f5a021d0a9163ef9a63a67f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Nov 23 16:21:43 2015 +0100

    sw lok comments: handle mouse up/down events on the vertical scrollbar
    
    Change-Id: Ib1c334825a6629224fe0c8fba564656d53e67410

diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 0891a2a..8d4079d 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -92,9 +92,19 @@ void lcl_translateTwips(vcl::Window& rParent, vcl::Window& rChild, MouseEvent* p
 {
     // Set map mode, so that callback payloads will contain absolute coordinates instead of relative ones.
     Point aOffset(rChild.GetOutOffXPixel() - rParent.GetOutOffXPixel(), rChild.GetOutOffYPixel() - rParent.GetOutOffYPixel());
+    if (!rChild.IsMapModeEnabled())
+    {
+        MapMode aMapMode(rChild.GetMapMode());
+        aMapMode.SetMapUnit(MAP_TWIP);
+        aMapMode.SetScaleX(rParent.GetMapMode().GetScaleX());
+        aMapMode.SetScaleY(rParent.GetMapMode().GetScaleY());
+        rChild.SetMapMode(aMapMode);
+        rChild.EnableMapMode();
+    }
     aOffset = rChild.PixelToLogic(aOffset);
     MapMode aMapMode(rChild.GetMapMode());
     aMapMode.SetOrigin(aOffset);
+    aMapMode.SetMapUnit(rParent.GetMapMode().GetMapUnit());
     rChild.SetMapMode(aMapMode);
     rChild.EnableMapMode(false);
 
@@ -108,6 +118,31 @@ void lcl_translateTwips(vcl::Window& rParent, vcl::Window& rChild, MouseEvent* p
     }
 }
 
+/// Decide which one from the children of rParent should get rMouseEvent.
+vcl::Window* lcl_getHitWindow(sw::sidebarwindows::SwSidebarWin& rParent, const MouseEvent& rMouseEvent)
+{
+    vcl::Window* pRet = 0;
+
+    rParent.EditWin().Push(PushFlags::MAPMODE);
+    rParent.EditWin().EnableMapMode();
+    for (sal_Int16 i = rParent.GetChildCount() - 1; i >= 0; --i)
+    {
+        vcl::Window* pChild = rParent.GetChild(i);
+
+        Point aPosition(rParent.GetPosPixel());
+        aPosition.Move(pChild->GetPosPixel().getX(), pChild->GetPosPixel().getY());
+        Size aSize(rParent.GetSizePixel());
+        Rectangle aRectangleLogic(rParent.EditWin().PixelToLogic(aPosition), rParent.EditWin().PixelToLogic(aSize));
+        if (aRectangleLogic.IsInside(rMouseEvent.GetPosPixel()))
+        {
+            pRet = pChild;
+            break;
+        }
+    }
+    rParent.EditWin().Pop();
+    return pRet;
+}
+
 }
 
 namespace sw { namespace sidebarwindows {
@@ -441,29 +476,29 @@ void SwSidebarWin::MouseMove(const MouseEvent& rMouseEvent)
 
 void SwSidebarWin::MouseButtonDown(const MouseEvent& rMouseEvent)
 {
-    if (mpSidebarTextControl)
+    if (vcl::Window* pHit = lcl_getHitWindow(*this, rMouseEvent))
     {
-        mpSidebarTextControl->Push(PushFlags::MAPMODE);
+        pHit->Push(PushFlags::MAPMODE);
         MouseEvent aMouseEvent(rMouseEvent);
-        lcl_translateTwips(EditWin(), *mpSidebarTextControl, &aMouseEvent);
+        lcl_translateTwips(EditWin(), *pHit, &aMouseEvent);
 
-        mpSidebarTextControl->MouseButtonDown(aMouseEvent);
+        pHit->MouseButtonDown(aMouseEvent);
 
-        mpSidebarTextControl->Pop();
+        pHit->Pop();
     }
 }
 
 void SwSidebarWin::MouseButtonUp(const MouseEvent& rMouseEvent)
 {
-    if (mpSidebarTextControl)
+    if (vcl::Window* pHit = lcl_getHitWindow(*this, rMouseEvent))
     {
-        mpSidebarTextControl->Push(PushFlags::MAPMODE);
+        pHit->Push(PushFlags::MAPMODE);
         MouseEvent aMouseEvent(rMouseEvent);
-        lcl_translateTwips(EditWin(), *mpSidebarTextControl, &aMouseEvent);
+        lcl_translateTwips(EditWin(), *pHit, &aMouseEvent);
 
-        mpSidebarTextControl->MouseButtonUp(aMouseEvent);
+        pHit->MouseButtonUp(aMouseEvent);
 
-        mpSidebarTextControl->Pop();
+        pHit->Pop();
     }
 }
 
commit 439765480695975e10c92f39aa6a4cb6f2ee7646
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Nov 23 16:07:49 2015 +0100

    vcl lok: fix scrollbar to accept mouse events in twips
    
    Change-Id: Ieaedaa525d613f8ba55f336c613da163a09f7a33

diff --git a/vcl/source/control/scrbar.cxx b/vcl/source/control/scrbar.cxx
index 91c17b6..4ed1983 100644
--- a/vcl/source/control/scrbar.cxx
+++ b/vcl/source/control/scrbar.cxx
@@ -879,7 +879,19 @@ void ScrollBar::MouseButtonDown( const MouseEvent& rMEvt )
 
     if (rMEvt.IsLeft() || rMEvt.IsMiddle() || rMEvt.IsRight())
     {
-        const Point&        rMousePos = rMEvt.GetPosPixel();
+        Point aPosPixel;
+        if (!IsMapModeEnabled() && GetMapMode().GetMapUnit() == MAP_TWIP)
+        {
+            // rMEvt coordinates are in twips.
+            Push(PushFlags::MAPMODE);
+            EnableMapMode();
+            MapMode aMapMode = GetMapMode();
+            aMapMode.SetOrigin(Point(0, 0));
+            SetMapMode(aMapMode);
+            aPosPixel = LogicToPixel(rMEvt.GetPosPixel());
+            Pop();
+        }
+        const Point&        rMousePos = (GetMapMode().GetMapUnit() != MAP_TWIP ? rMEvt.GetPosPixel() : aPosPixel);
         StartTrackingFlags  nTrackFlags = StartTrackingFlags::NONE;
         bool                bHorizontal = ( GetStyle() & WB_HORZ ) != 0;
         bool                bIsInside = false;


More information about the Libreoffice-commits mailing list