diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-02-10 17:43:18 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-02-16 09:20:48 +0100 |
commit | 565a9f3fd8333e14497f058f9e4387e511aa36c9 (patch) | |
tree | fa1ecc90c51e5cfc7f479692c5b120bc0fe120bb /sw | |
parent | 0135d5d5c2a41bc306062334db731b98438a6caf (diff) |
LOK: add lok::Document::setTextSelection()
What's interesting about this is that it allows adjusting the position
of both the point and mark of the selection, while the normal UI only
allows adjusting the point.
Change-Id: If61f57c68c28c67fec252f2b666a706f52dd8d26
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/unotxdoc.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/docvw/edtwin.cxx | 14 | ||||
-rw-r--r-- | sw/source/uibase/inc/edtwin.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 19 |
4 files changed, 37 insertions, 0 deletions
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 894a12714946..6ffa02fff8ca 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -415,6 +415,8 @@ public: virtual void registerCallback(LibreOfficeKitCallback pCallback, void* pData) SAL_OVERRIDE; /// @see vcl::ITiledRenderable::postMouseEvent(). virtual void postMouseEvent(int nType, int nX, int nY, int nCount) SAL_OVERRIDE; + /// @see vcl::ITiledRenderable::setTextSelection(). + virtual void setTextSelection(int nType, int nX, int nY) SAL_OVERRIDE; void Invalidate(); void Reactivate(SwDocShell* pNewDocShell); diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 6666249466da..bb592175fde4 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -6256,4 +6256,18 @@ void SwEditWin::LogicMouseButtonUp(const MouseEvent& rMouseEvent) MouseButtonUp(rMouseEvent); } +void SwEditWin::SetCursorLogicPosition(bool bPoint, const Point& rPosition) +{ + // Not an SwWrtShell, as that would make SwCrsrShell::GetCrsr() inaccessible. + SwEditShell& rShell = m_rView.GetWrtShell(); + SwMvContext aMvContext(&rShell); + // If the mark is to be updated, then exchange the point and mark before + // and after, as we can't easily set the mark. + if (!bPoint) + rShell.GetCrsr()->Exchange(); + rShell.SetCrsr(rPosition); + if (!bPoint) + rShell.GetCrsr()->Exchange(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/inc/edtwin.hxx b/sw/source/uibase/inc/edtwin.hxx index 5557321a5a1a..9af94460629c 100644 --- a/sw/source/uibase/inc/edtwin.hxx +++ b/sw/source/uibase/inc/edtwin.hxx @@ -305,6 +305,8 @@ public: void LogicMouseButtonDown(const MouseEvent& rMouseEvent); /// Same as MouseButtonUp(), but coordinates are in logic unit. void LogicMouseButtonUp(const MouseEvent& rMouseEvent); + /// Allows adjusting the point or mark of the selection to a document coordinate. + void SetCursorLogicPosition(bool bPoint, const Point& rPosition); }; #endif diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 70abbac57cbf..3a98cd955384 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3194,6 +3194,25 @@ void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount) } } +void SwXTextDocument::setTextSelection(int nType, int nX, int nY) +{ + SolarMutexGuard aGuard; + + SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin(); + switch (nType) + { + case LOK_SETTEXTSELECTION_START: + rEditWin.SetCursorLogicPosition(/*bPoint=*/false, Point(nX, nY)); + break; + case LOK_SETTEXTSELECTION_END: + rEditWin.SetCursorLogicPosition(/*bPoint=*/true, Point(nX, nY)); + break; + default: + assert(false); + break; + } +} + void * SAL_CALL SwXTextDocument::operator new( size_t t) throw() { return SwXTextDocumentBaseClass::operator new(t); |