diff options
author | Henry Castro <hcastro@collabora.com> | 2015-06-22 23:16:39 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2015-06-23 16:59:29 +0200 |
commit | 49002c028da9ca5d7e236ab166104630511b8426 (patch) | |
tree | ae1641652a451f115ce1dfa515046ce6bd134aec /sc | |
parent | 020aecf5d916b0c24941337f9c21834d88f4e5cd (diff) |
sc: add ScModelObj::getTextSelection().
Calc copy part of copy&paste
Change-Id: Id9d2d05b491849fa30b3c91c6b22abe60355e876
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/docuno.hxx | 3 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 82 |
2 files changed, 85 insertions, 0 deletions
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx index e11b9600470c..a7e9af5afb2c 100644 --- a/sc/inc/docuno.hxx +++ b/sc/inc/docuno.hxx @@ -403,6 +403,9 @@ public: /// @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, OString& rUsedMimeType) SAL_OVERRIDE; + /// @see vcl::ITiledRenderable::setGraphicSelection(). virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE; diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 6083452be826..27b72ee8a18d 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -37,6 +37,7 @@ #include <unotools/moduleoptions.hxx> #include <sfx2/printer.hxx> #include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> #include <vcl/pdfextoutdevdata.hxx> #include <vcl/waitobj.hxx> #include <unotools/charclass.hxx> @@ -107,6 +108,10 @@ #include "unonames.hxx" #include "ViewSettingsSequenceDefines.hxx" #include "viewuno.hxx" +#include "editsh.hxx" +#include "drawsh.hxx" +#include "drtxtob.hxx" +#include "transobj.hxx" #include "sc.hrc" @@ -679,6 +684,83 @@ void ScModelObj::setTextSelection(int nType, int nX, int nY) } } +OString ScModelObj::getTextSelection(const char* pMimeType, OString& rUsedMimeType) +{ + SolarMutexGuard aGuard; + + ScEditShell* pShell; + ScDrawShell* pDrawShell; + ScDrawTextObjectBar* pTextShell; + TransferableDataHelper aDataHelper; + ScViewData* pViewData = ScDocShell::GetViewData(); + uno::Reference<datatransfer::XTransferable> xTransferable; + + if (( pShell = PTR_CAST( ScEditShell, pViewData->GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) ))) + xTransferable = pShell->GetEditView()->GetTransferable(); + else if (( pTextShell = PTR_CAST( ScDrawTextObjectBar, pViewData->GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) ))) + { + ScDrawView* pView = pViewData->GetScDrawView(); + OutlinerView* pOutView = pView->GetTextEditOutlinerView(); + if (pOutView) + xTransferable = pOutView->GetEditView().GetTransferable(); + } + else if (( pDrawShell = PTR_CAST( ScDrawShell, pViewData->GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) ))) + xTransferable = pDrawShell->GetDrawView()->CopyToTransferable(); + else + { + ScTransferObj* pObj = pViewData->GetViewShell()->CopyToTransferable(); + xTransferable.set( pObj ); + } + + if (!xTransferable.is()) + xTransferable.set( aDataHelper.GetTransferable() ); + + // Take care of UTF-8 text here. + OString aMimeType(pMimeType); + 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(); + + if (!xTransferable->isDataFlavorSupported(aFlavor)) + return OString(); + + 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)); + } + else + { + uno::Sequence<sal_Int8> aSequence; + aAny >>= aSequence; + aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength()); + } + + rUsedMimeType = pMimeType; + return aRet; +} + void ScModelObj::setGraphicSelection(int nType, int nX, int nY) { SolarMutexGuard aGuard; |