From 03d33ba9410433d2072364b3afb9dbd6b19c4d0d Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Thu, 6 Jun 2019 17:45:24 +0100 Subject: lok: re-factor getTextSelection. Change-Id: I2c27c213ee980e19d6020e9599b2b72115e7f28e Reviewed-on: https://gerrit.libreoffice.org/73626 Tested-by: Jenkins Reviewed-by: Michael Meeks --- sd/source/ui/inc/ViewShell.hxx | 4 +-- sd/source/ui/inc/unomodel.hxx | 4 +-- sd/source/ui/unoidl/unomodel.cxx | 6 ++--- sd/source/ui/view/viewshel.cxx | 53 +++------------------------------------- 4 files changed, 11 insertions(+), 56 deletions(-) (limited to 'sd/source/ui') diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx index dea7dfbfea4c..c8fce2036aeb 100644 --- a/sd/source/ui/inc/ViewShell.hxx +++ b/sd/source/ui/inc/ViewShell.hxx @@ -412,8 +412,8 @@ public: /// Allows adjusting the point or mark of the selection to a document coordinate. void SetCursorMm100Position(const Point& rPosition, bool bPoint, bool bClearMark); - /// Gets the currently selected text. - OString GetTextSelection(const OString& aMimeType, OString& rUsedMimeType); + /// Gets the current selectiion + css::uno::Reference GetSelectionTransferrable(); /// Allows starting or ending a graphic move or resize action. void SetGraphicMm100Position(bool bStart, const Point& rPosition); diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx index d13109d0667e..2be081b447f1 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -249,8 +249,8 @@ public: virtual void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier) override; /// @see vcl::ITiledRenderable::setTextSelection(). virtual void setTextSelection(int nType, int nX, int nY) override; - /// @see vcl::ITiledRenderable::getTextSelection(). - virtual OString getTextSelection(const char* pMimeType, OString& rUsedMimeType) override; + /// @see vcl::ITiledRenderable::getSelection(). + virtual css::uno::Reference getSelection() override; /// @see vcl::ITiledRenderable::setGraphicSelection(). virtual void setGraphicSelection(int nType, int nX, int nY) override; /// @see lok::Document::resetSelection(). diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 237dab1bace1..e6c15f7f1cd0 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2538,15 +2538,15 @@ void SdXImpressDocument::setTextSelection(int nType, int nX, int nY) } } -OString SdXImpressDocument::getTextSelection(const char* pMimeType, OString& rUsedMimeType) +uno::Reference SdXImpressDocument::getSelection() { SolarMutexGuard aGuard; DrawViewShell* pViewShell = GetViewShell(); if (!pViewShell) - return OString(); + return uno::Reference(); - return pViewShell->GetTextSelection(pMimeType, rUsedMimeType); + return pViewShell->GetSelectionTransferrable(); } void SdXImpressDocument::setGraphicSelection(int nType, int nX, int nY) diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx index 8679f069b734..f2c1a5603041 100644 --- a/sd/source/ui/view/viewshel.cxx +++ b/sd/source/ui/view/viewshel.cxx @@ -524,62 +524,17 @@ void ViewShell::SetCursorMm100Position(const Point& rPosition, bool bPoint, bool } } -OString ViewShell::GetTextSelection(const OString& _aMimeType, OString& rUsedMimeType) +uno::Reference ViewShell::GetSelectionTransferrable() { SdrView* pSdrView = GetView(); if (!pSdrView) - return OString(); + return uno::Reference(); if (!pSdrView->GetTextEditObject()) - return OString(); + return uno::Reference(); EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView(); - uno::Reference xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection()); - - // Take care of UTF-8 text here. - bool bConvert = false; - sal_Int32 nIndex = 0; - OString aMimeType = _aMimeType; - if (aMimeType.getToken(0, ';', nIndex) == "text/plain") - { - if (aMimeType.getToken(0, ';', nIndex) == "charset=utf-8") - { - aMimeType = "text/plain;charset=utf-16"; - bConvert = true; - } - } - - datatransfer::DataFlavor aFlavor; - aFlavor.MimeType = OUString::fromUtf8(aMimeType.getStr()); - if (bConvert || aMimeType == "text/plain;charset=utf-16") - aFlavor.DataType = cppu::UnoType::get(); - else - aFlavor.DataType = cppu::UnoType< uno::Sequence >::get(); - - if (!xTransferable->isDataFlavorSupported(aFlavor)) - return OString(); - - uno::Any aAny(xTransferable->getTransferData(aFlavor)); - - OString aRet; - if (aFlavor.DataType == cppu::UnoType::get()) - { - OUString aString; - aAny >>= aString; - if (bConvert) - aRet = OUStringToOString(aString, RTL_TEXTENCODING_UTF8); - else - aRet = OString(reinterpret_cast(aString.getStr()), aString.getLength() * sizeof(sal_Unicode)); - } - else - { - uno::Sequence aSequence; - aAny >>= aSequence; - aRet = OString(reinterpret_cast(aSequence.getArray()), aSequence.getLength()); - } - - rUsedMimeType = _aMimeType; - return aRet; + return rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection()); } void ViewShell::SetGraphicMm100Position(bool bStart, const Point& rPosition) -- cgit