From 03db067b74739dabe787dbce6af1f4b776ce888a Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 14 Nov 2015 10:37:45 +0100 Subject: [PATCH 328/398] sw lok comments: implement setTextSelection() API So that it's possible to drag the text selection start/end handles in comment text when there is an existing selection. (cherry picked from commit e320d070bb0d4dd0ceb696f2c7cc5afb7c4273c3) Change-Id: I3acc4770928d4f385f0ca09a2484a9e112409907 --- sw/inc/SidebarWin.hxx | 2 ++ sw/source/uibase/docvw/SidebarWin.cxx | 60 +++++++++++++++++++++++------------ sw/source/uibase/docvw/edtwin.cxx | 10 ++++++ 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx index e3899d5a1a8b..503f8f8a9771 100644 --- a/sw/inc/SidebarWin.hxx +++ b/sw/inc/SidebarWin.hxx @@ -183,6 +183,8 @@ class SwSidebarWin : public vcl::Window void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect); /// Is there a matching sub-widget inside this sidebar widget for rPointLogic? bool IsHitWindow(const Point& rPointLogic); + /// Allows adjusting the point or mark of the selection to a document coordinate. + void SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark); protected: virtual void DataChanged( const DataChangedEvent& aEvent) SAL_OVERRIDE; diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx index 71b763b84224..721ef95e4acf 100644 --- a/sw/source/uibase/docvw/SidebarWin.cxx +++ b/sw/source/uibase/docvw/SidebarWin.cxx @@ -83,6 +83,32 @@ #include #include +namespace +{ + +/// Translate absolute <-> relative twips: LOK wants absolute coordinates as output and gives absolute coordinates as input. +void lcl_translateTwips(vcl::Window& rParent, vcl::Window& rChild, MouseEvent* pMouseEvent) +{ + // 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()); + aOffset = rChild.PixelToLogic(aOffset); + MapMode aMapMode(rChild.GetMapMode()); + aMapMode.SetOrigin(aOffset); + rChild.SetMapMode(aMapMode); + rChild.EnableMapMode(false); + + if (pMouseEvent) + { + // Set event coordinates, so they contain relative coordinates instead of absolute ones. + Point aPos = pMouseEvent->GetPosPixel(); + aPos.Move(-aOffset.getX(), -aOffset.getY()); + MouseEvent aMouseEvent(aPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(), pMouseEvent->GetButtons(), pMouseEvent->GetModifier()); + *pMouseEvent = aMouseEvent; + } +} + +} + namespace sw { namespace sidebarwindows { #define METABUTTON_WIDTH 16 @@ -290,6 +316,19 @@ bool SwSidebarWin::IsHitWindow(const Point& rPointLogic) return aRectangleLogic.IsInside(rPointLogic); } +void SwSidebarWin::SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark) +{ + mpSidebarTextControl->Push(PushFlags::MAPMODE); + MouseEvent aMouseEvent(rPosition); + lcl_translateTwips(*EditWin(), *mpSidebarTextControl, &aMouseEvent); + Point aPosition(aMouseEvent.GetPosPixel()); + + EditView& rEditView = GetOutlinerView()->GetEditView(); + rEditView.SetCursorLogicPosition(aPosition, bPoint, bClearMark); + + mpSidebarTextControl->Pop(); +} + void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, sal_uLong nInFlags) { if (mpMetadataAuthor->IsVisible() ) @@ -358,27 +397,6 @@ void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, s } } -/// Translate absolute <-> relative twips: LOK wants absolute coordinates as output and gives absolute coordinates as input. -static void lcl_translateTwips(vcl::Window& rParent, vcl::Window& rChild, MouseEvent* pMouseEvent) -{ - // 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()); - aOffset = rChild.PixelToLogic(aOffset); - MapMode aMapMode(rChild.GetMapMode()); - aMapMode.SetOrigin(aOffset); - rChild.SetMapMode(aMapMode); - rChild.EnableMapMode(false); - - if (pMouseEvent) - { - // Set event coordinates, so they contain relative coordinates instead of absolute ones. - Point aPos = pMouseEvent->GetPosPixel(); - aPos.Move(-aOffset.getX(), -aOffset.getY()); - MouseEvent aMouseEvent(aPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(), pMouseEvent->GetButtons(), pMouseEvent->GetModifier()); - *pMouseEvent = aMouseEvent; - } -} - void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent) { if (mpSidebarTextControl) diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 53d0afd38f94..b9777914c5b4 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -6299,6 +6299,16 @@ void SwEditWin::SetCursorTwipPosition(const Point& rPosition, bool bPoint, bool } } + if (m_rView.GetPostItMgr()) + { + if (sw::sidebarwindows::SwSidebarWin* pWin = m_rView.GetPostItMgr()->GetActiveSidebarWin()) + { + // Editing postit text. + pWin->SetCursorLogicPosition(rPosition, bPoint, bClearMark); + return; + } + } + // Not an SwWrtShell, as that would make SwCrsrShell::GetCrsr() inaccessible. SwEditShell& rShell = m_rView.GetWrtShell(); -- 2.12.0