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

lok::Document::paste: check if the given mime type is supported

Change-Id: Ib59ea43700815c53cdd4be819e2e9cf35c6f89e9
üst 2e61410d
......@@ -331,12 +331,15 @@ void DesktopLOKTest::testPasteWriter()
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
OString aText("hello");
pDocument->pClass->paste(pDocument, "text/plain;charset=utf-8", aText.getStr(), aText.getLength());
CPPUNIT_ASSERT(pDocument->pClass->paste(pDocument, "text/plain;charset=utf-8", aText.getStr(), aText.getLength()));
pDocument->pClass->postUnoCommand(pDocument, ".uno:SelectAll", 0);
char* pText = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", 0);
CPPUNIT_ASSERT_EQUAL(OString("hello"), OString(pText));
free(pText);
CPPUNIT_ASSERT(!pDocument->pClass->paste(pDocument, "textt/plain;charset=utf-8", aText.getStr(), aText.getLength()));
comphelper::LibreOfficeKit::setActive(false);
}
......
......@@ -1017,6 +1017,13 @@ static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, cons
}
pWindow->SetClipboard(xClipboard);
if (!pDoc->isMimeTypeSupported())
{
if (gImpl)
gImpl->maLastExceptionMsg = "Document doesn't support this mime type";
return false;
}
OUString aCommand(".uno:Paste");
uno::Sequence<beans::PropertyValue> aPropertyValues;
if (!comphelper::dispatchCommand(aCommand, aPropertyValues))
......
......@@ -150,6 +150,11 @@ public:
/// Returns the current vcl::Window of the component.
virtual vcl::Window* getWindow() = 0;
virtual bool isMimeTypeSupported()
{
return false;
}
};
} // namespace vcl
......
......@@ -433,6 +433,8 @@ public:
virtual OUString getPartPageRectangles() override;
/// @see vcl::ITiledRenderable::getWindow().
virtual vcl::Window* getWindow() override;
/// @see vcl::ITiledRenderable::isMimeTypeSupported().
virtual bool isMimeTypeSupported() override;
// ::com::sun::star::tiledrendering::XTiledRenderable
virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) throw (::css::uno::RuntimeException, ::std::exception) override;
......
......@@ -3189,6 +3189,16 @@ vcl::Window* SwXTextDocument::getWindow()
return &pDocShell->GetView()->GetEditWin();
}
bool SwXTextDocument::isMimeTypeSupported()
{
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
if (!pWrtShell)
return false;
TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromSystemClipboard(&pWrtShell->GetView().GetEditWin()));
return aDataHelper.GetXTransferable().is() && SwTransferable::IsPaste(*pWrtShell, aDataHelper);
}
int SwXTextDocument::getPart()
{
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