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 | |
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
-rw-r--r-- | desktop/source/lib/init.cxx | 16 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 14 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 12 | ||||
-rw-r--r-- | include/vcl/ITiledRenderable.hxx | 7 | ||||
-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 |
8 files changed, 86 insertions, 0 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 5a5f609325e4..d7ca1438709b 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -207,6 +207,10 @@ static void doc_postMouseEvent (LibreOfficeKitDocument* pThis, int nX, int nY, int nCount); +static void doc_setTextSelection (LibreOfficeKitDocument* pThis, + int nType, + int nX, + int nY); struct LibLODocument_Impl : public _LibreOfficeKitDocument { @@ -235,6 +239,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument m_pDocumentClass->initializeForRendering = doc_initializeForRendering; m_pDocumentClass->registerCallback = doc_registerCallback; m_pDocumentClass->postMouseEvent = doc_postMouseEvent; + m_pDocumentClass->setTextSelection = doc_setTextSelection; gDocumentClass = m_pDocumentClass; } @@ -673,6 +678,17 @@ static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX, pDoc->postMouseEvent(nType, nX, nY, nCount); } +static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY) +{ + ITiledRenderable* pDoc = getTiledRenderable(pThis); + if (!pDoc) + { + gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering"; + return; + } + + pDoc->setTextSelection(nType, nX, nY); +} static char* lo_getError (LibreOfficeKit *pThis) { diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 204479502eb7..eccf19bd82ce 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -117,6 +117,15 @@ typedef enum } LibreOfficeKitMouseEventType; +typedef enum +{ + /// The start of selection is to be adjusted. + LOK_SETTEXTSELECTION_START, + /// The end of selection is to be adjusted. + LOK_SETTEXTSELECTION_END +} +LibreOfficeKitSetTextSelectionType; + typedef void (*LibreOfficeKitCallback)(int nType, const char* pPayload, void* pData); #endif // LOK_USE_UNSTABLE_API @@ -204,6 +213,11 @@ struct _LibreOfficeKitDocumentClass int nX, int nY, int nCount); + /// @see lok::Document::setTextSelection + void (*setTextSelection)(LibreOfficeKitDocument* pThis, + int nType, + int nX, + int nY); #endif // LOK_USE_UNSTABLE_API }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 8448fcd75204..ef365ce04f4e 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -117,6 +117,18 @@ public: { mpDoc->pClass->postMouseEvent(mpDoc, nType, nX, nY, nCount); } + + /** + * Sets the start or end of a text selection. + * + * @param nType @see LibreOfficeKitSetTextSelectionType + * @param nX horizontal position in document coordinates + * @param nY vertical position in document coordinates + */ + inline void setTextSelection(int nType, int nX, int nY) + { + mpDoc->pClass->setTextSelection(mpDoc, nType, nX, nY); + } #endif // LOK_USE_UNSTABLE_API }; diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx index 9edd7a11aa9e..d5b3e8077923 100644 --- a/include/vcl/ITiledRenderable.hxx +++ b/include/vcl/ITiledRenderable.hxx @@ -107,6 +107,13 @@ public: * @see lok::Document::postMouseEvent(). */ virtual void postMouseEvent(int /*nType*/, int /*nX*/, int /*nY*/, int /*nCount*/) { } + + /** + * Sets the start or end of a text selection. + * + * @see lok::Document::setTextSelection(). + */ + virtual void setTextSelection(int /*nType*/, int /*nX*/, int /*nY*/) { } }; } // namespace vcl 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); |