Kaydet (Commit) cfc43751 authored tarafından Miklos Vajna's avatar Miklos Vajna

LOK: add lok::Document::getTextSelection()

I.e. the copy part of copy&paste. Only the Writer bits for now.

Change-Id: Ia003e76e3b234735f472cdef125514f9771d8640
üst 158dca0e
...@@ -215,6 +215,8 @@ static void doc_setTextSelection (LibreOfficeKitDocument* pThis, ...@@ -215,6 +215,8 @@ static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
int nType, int nType,
int nX, int nX,
int nY); int nY);
static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
const char* pMimeType);
static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis, static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
int nType, int nType,
int nX, int nX,
...@@ -251,6 +253,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument ...@@ -251,6 +253,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
m_pDocumentClass->postMouseEvent = doc_postMouseEvent; m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
m_pDocumentClass->postUnoCommand = doc_postUnoCommand; m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
m_pDocumentClass->setTextSelection = doc_setTextSelection; m_pDocumentClass->setTextSelection = doc_setTextSelection;
m_pDocumentClass->getTextSelection = doc_getTextSelection;
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection; m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
m_pDocumentClass->resetSelection = doc_resetSelection; m_pDocumentClass->resetSelection = doc_resetSelection;
...@@ -788,6 +791,22 @@ static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int n ...@@ -788,6 +791,22 @@ static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int n
pDoc->setTextSelection(nType, nX, nY); pDoc->setTextSelection(nType, nX, nY);
} }
static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMimeType)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
return 0;
}
OString aRet = pDoc->getTextSelection(pMimeType);
char* pMemory = static_cast<char*>(malloc(aRet.getLength() + 1));
strcpy(pMemory, aRet.getStr());
return pMemory;
}
static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY) static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
{ {
ITiledRenderable* pDoc = getTiledRenderable(pThis); ITiledRenderable* pDoc = getTiledRenderable(pThis);
......
...@@ -146,6 +146,10 @@ struct _LibreOfficeKitDocumentClass ...@@ -146,6 +146,10 @@ struct _LibreOfficeKitDocumentClass
int nX, int nX,
int nY); int nY);
/// @see lok::Document::getTextSelection
char* (*getTextSelection) (LibreOfficeKitDocument* pThis,
const char* pMimeType);
/// @see lok::Document::setGraphicSelection /// @see lok::Document::setGraphicSelection
void (*setGraphicSelection) (LibreOfficeKitDocument* pThis, void (*setGraphicSelection) (LibreOfficeKitDocument* pThis,
int nType, int nType,
......
...@@ -216,6 +216,16 @@ public: ...@@ -216,6 +216,16 @@ public:
mpDoc->pClass->setTextSelection(mpDoc, nType, nX, nY); mpDoc->pClass->setTextSelection(mpDoc, nType, nX, nY);
} }
/**
* Gets the currently selected text.
*
* @param pMimeType determines the return format, for example text/plain;charset=utf-8.
*/
inline char* getTextSelection(const char* pMimeType)
{
return mpDoc->pClass->getTextSelection(mpDoc, pMimeType);
}
/** /**
* Adjusts the graphic selection. * Adjusts the graphic selection.
* *
......
...@@ -121,6 +121,13 @@ public: ...@@ -121,6 +121,13 @@ public:
*/ */
virtual void setTextSelection(int nType, int nX, int nY) = 0; virtual void setTextSelection(int nType, int nX, int nY) = 0;
/**
* Gets the text selection.
*
* @see lok::Document::getTextSelection().
*/
virtual OString getTextSelection(const char* /*pMimeType*/) { return OString(); }
/** /**
* Adjusts the graphic selection. * Adjusts the graphic selection.
* *
......
...@@ -417,6 +417,8 @@ public: ...@@ -417,6 +417,8 @@ public:
virtual void postMouseEvent(int nType, int nX, int nY, int nCount) SAL_OVERRIDE; virtual void postMouseEvent(int nType, int nX, int nY, int nCount) SAL_OVERRIDE;
/// @see vcl::ITiledRenderable::setTextSelection(). /// @see vcl::ITiledRenderable::setTextSelection().
virtual void setTextSelection(int nType, int nX, int nY) SAL_OVERRIDE; 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(). /// @see vcl::ITiledRenderable::setGraphicSelection().
virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE; virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE;
/// @see vcl::ITiledRenderable::resetSelection(). /// @see vcl::ITiledRenderable::resetSelection().
......
...@@ -133,6 +133,7 @@ ...@@ -133,6 +133,7 @@
#include <view.hxx> #include <view.hxx>
#include <srcview.hxx> #include <srcview.hxx>
#include <edtwin.hxx> #include <edtwin.hxx>
#include <swdtflvr.hxx>
#include <svtools/langtab.hxx> #include <svtools/langtab.hxx>
#include <map> #include <map>
...@@ -3253,6 +3254,47 @@ void SwXTextDocument::setTextSelection(int nType, int nX, int nY) ...@@ -3253,6 +3254,47 @@ void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
} }
} }
OString SwXTextDocument::getTextSelection(const char* pMimeType)
{
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
uno::Reference<datatransfer::XTransferable> xTransferable(new SwTransferable(*pWrtShell));
// 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();
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 SwXTextDocument::setGraphicSelection(int nType, int nX, int nY) void SwXTextDocument::setGraphicSelection(int nType, int nX, int nY)
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment