diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-19 09:53:56 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-19 09:22:54 +0000 |
commit | d299041e8cdd0318f79115061e0ab25359c2e396 (patch) | |
tree | bba5424f60a79972aeab4dc81faa4835f4a55a68 /sd/source | |
parent | c38e0f01ac23dc6b75c8bf23af277940310097d1 (diff) |
sd: implement getTextSelection() in SdXImpressDocument
Change-Id: I29df1873b3954aa64a613e06c53c8e9acfa6a79d
Reviewed-on: https://gerrit.libreoffice.org/16369
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sd/source')
-rw-r--r-- | sd/source/ui/inc/ViewShell.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/inc/unomodel.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 11 | ||||
-rw-r--r-- | sd/source/ui/view/viewshel.cxx | 48 |
4 files changed, 63 insertions, 0 deletions
diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx index 97ed710a68f7..d3dfadb891af 100644 --- a/sd/source/ui/inc/ViewShell.hxx +++ b/sd/source/ui/inc/ViewShell.hxx @@ -451,6 +451,8 @@ public: void LogicMouseMove(const MouseEvent& rMouseEvent); /// 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(OString aMimeType); /// 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 43444b83c1b9..2793ca09617b 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -251,6 +251,8 @@ public: 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; + /// @see vcl::ITiledRenderable::getTextSelection(). + virtual OString getTextSelection(const char* pMimeType) SAL_OVERRIDE; /// @see vcl::ITiledRenderable::setGraphicSelection(). virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE; /// @see lok::Document::resetSelection(). diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 1029f1908525..c74f3b1ffdbb 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2446,6 +2446,17 @@ void SdXImpressDocument::setTextSelection(int nType, int nX, int nY) } } +OString SdXImpressDocument::getTextSelection(const char* pMimeType) +{ + SolarMutexGuard aGuard; + + DrawViewShell* pViewShell = GetViewShell(); + if (!pViewShell) + return OString(); + + return pViewShell->GetTextSelection(pMimeType); +} + void SdXImpressDocument::setGraphicSelection(int nType, int nX, int nY) { SolarMutexGuard aGuard; diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx index d35cd0213478..c66405b47e2a 100644 --- a/sd/source/ui/view/viewshel.cxx +++ b/sd/source/ui/view/viewshel.cxx @@ -78,6 +78,7 @@ #include <editeng/numitem.hxx> #include <editeng/eeitem.hxx> #include <editeng/editview.hxx> +#include <editeng/editeng.hxx> #include <svl/poolitem.hxx> #include <glob.hrc> #include "AccessibleDocumentViewBase.hxx" @@ -552,6 +553,53 @@ void ViewShell::SetCursorMm100Position(const Point& rPosition, bool bPoint, bool } } +OString ViewShell::GetTextSelection(OString aMimeType) +{ + SdrView* pSdrView = GetView(); + if (!pSdrView) + return OString(); + + if (!pSdrView->GetTextEditObject()) + return OString(); + + EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView(); + uno::Reference<datatransfer::XTransferable> xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection()); + + // Take care of UTF-8 text here. + bool bConvert = false; + sal_Int32 nIndex = 0; + 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 (aMimeType == "text/plain;charset=utf-16") + aFlavor.DataType = cppu::UnoType<OUString>::get(); + else + aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get(); + + uno::Any aAny(xTransferable->getTransferData(aFlavor)); + + OString aRet; + if (aFlavor.DataType == cppu::UnoType<OUString>::get()) + { + OUString aString; + aAny >>= aString; + if (bConvert) + aRet = OUStringToOString(aString, RTL_TEXTENCODING_UTF8); + else + aRet = OString(reinterpret_cast<const sal_Char *>(aString.getStr()), aString.getLength() * sizeof(sal_Unicode)); + } + + return aRet; +} + void ViewShell::SetGraphicMm100Position(bool bStart, const Point& rPosition) { if (bStart) |