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() ...@@ -331,12 +331,15 @@ void DesktopLOKTest::testPasteWriter()
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
OString aText("hello"); 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); pDocument->pClass->postUnoCommand(pDocument, ".uno:SelectAll", 0);
char* pText = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", 0); char* pText = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", 0);
CPPUNIT_ASSERT_EQUAL(OString("hello"), OString(pText)); CPPUNIT_ASSERT_EQUAL(OString("hello"), OString(pText));
free(pText); free(pText);
CPPUNIT_ASSERT(!pDocument->pClass->paste(pDocument, "textt/plain;charset=utf-8", aText.getStr(), aText.getLength()));
comphelper::LibreOfficeKit::setActive(false); comphelper::LibreOfficeKit::setActive(false);
} }
......
...@@ -1017,6 +1017,13 @@ static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, cons ...@@ -1017,6 +1017,13 @@ static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, cons
} }
pWindow->SetClipboard(xClipboard); pWindow->SetClipboard(xClipboard);
if (!pDoc->isMimeTypeSupported())
{
if (gImpl)
gImpl->maLastExceptionMsg = "Document doesn't support this mime type";
return false;
}
OUString aCommand(".uno:Paste"); OUString aCommand(".uno:Paste");
uno::Sequence<beans::PropertyValue> aPropertyValues; uno::Sequence<beans::PropertyValue> aPropertyValues;
if (!comphelper::dispatchCommand(aCommand, aPropertyValues)) if (!comphelper::dispatchCommand(aCommand, aPropertyValues))
......
...@@ -150,6 +150,11 @@ public: ...@@ -150,6 +150,11 @@ public:
/// Returns the current vcl::Window of the component. /// Returns the current vcl::Window of the component.
virtual vcl::Window* getWindow() = 0; virtual vcl::Window* getWindow() = 0;
virtual bool isMimeTypeSupported()
{
return false;
}
}; };
} // namespace vcl } // namespace vcl
......
...@@ -433,6 +433,8 @@ public: ...@@ -433,6 +433,8 @@ public:
virtual OUString getPartPageRectangles() override; virtual OUString getPartPageRectangles() override;
/// @see vcl::ITiledRenderable::getWindow(). /// @see vcl::ITiledRenderable::getWindow().
virtual vcl::Window* getWindow() override; virtual vcl::Window* getWindow() override;
/// @see vcl::ITiledRenderable::isMimeTypeSupported().
virtual bool isMimeTypeSupported() override;
// ::com::sun::star::tiledrendering::XTiledRenderable // ::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; 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() ...@@ -3189,6 +3189,16 @@ vcl::Window* SwXTextDocument::getWindow()
return &pDocShell->GetView()->GetEditWin(); 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() int SwXTextDocument::getPart()
{ {
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