[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - sc/inc sc/source

Henry Castro hcastro at collabora.com
Tue Jun 23 08:02:33 PDT 2015


 sc/inc/docuno.hxx              |    3 +
 sc/source/ui/unoobj/docuno.cxx |   82 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)

New commits:
commit bad12423e6f64859eaf89d403a68d5b91ed23982
Author: Henry Castro <hcastro at collabora.com>
Date:   Mon Jun 22 23:16:39 2015 -0400

    sc: add ScModelObj::getTextSelection().
    
    Calc copy part of copy&paste
    
    Change-Id: Id9d2d05b491849fa30b3c91c6b22abe60355e876

diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index e11b960..a7e9af5 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 cfeaf2b..5375176 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;


More information about the Libreoffice-commits mailing list