Kaydet (Commit) d8ac2024 authored tarafından Henry Castro's avatar Henry Castro Kaydeden (comit) Jan Holesovsky

lok: allow paste content to popup dialog

Change-Id: I1893d52df505bc43428c37a624ca05c569ba1bc0
Reviewed-on: https://gerrit.libreoffice.org/70958
Tested-by: Jenkins
Reviewed-by: 's avatarHenry Castro <hcastro@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/71369Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
Tested-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst 4fa1bdfa
...@@ -21,7 +21,11 @@ ...@@ -21,7 +21,11 @@
#include <com/sun/star/frame/XStorable.hpp> #include <com/sun/star/frame/XStorable.hpp>
#include <vcl/combobox.hxx>
#include <vcl/scheduler.hxx> #include <vcl/scheduler.hxx>
#include <vcl/svapp.hxx>
#include <vcl/syswin.hxx>
#include <vcl/window.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <rtl/uri.hxx> #include <rtl/uri.hxx>
#include <sfx2/objsh.hxx> #include <sfx2/objsh.hxx>
...@@ -128,6 +132,7 @@ public: ...@@ -128,6 +132,7 @@ public:
void testInsertCertificate_PEM_DOCX(); void testInsertCertificate_PEM_DOCX();
void testSignDocument_PEM_PDF(); void testSignDocument_PEM_PDF();
void testTextSelectionHandles(); void testTextSelectionHandles();
void testDialogPaste();
void testABI(); void testABI();
CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST_SUITE(DesktopLOKTest);
...@@ -180,6 +185,7 @@ public: ...@@ -180,6 +185,7 @@ public:
CPPUNIT_TEST(testSignDocument_PEM_PDF); CPPUNIT_TEST(testSignDocument_PEM_PDF);
#endif #endif
CPPUNIT_TEST(testTextSelectionHandles); CPPUNIT_TEST(testTextSelectionHandles);
CPPUNIT_TEST(testDialogPaste);
CPPUNIT_TEST(testABI); CPPUNIT_TEST(testABI);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
...@@ -207,6 +213,23 @@ public: ...@@ -207,6 +213,23 @@ public:
}; };
static Control* GetFocusControl(vcl::Window const * pParent)
{
sal_uInt16 nChildren = pParent->GetChildCount();
for (sal_uInt16 nChild = 0; nChild < nChildren; ++nChild)
{
vcl::Window* pChild = pParent->GetChild( nChild );
Control* pCtrl = dynamic_cast<Control*>(pChild);
if (pCtrl && pCtrl->HasControlFocus())
return pCtrl;
Control* pSubCtrl = GetFocusControl( pChild );
if (pSubCtrl)
return pSubCtrl;
}
return nullptr;
}
LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType) LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType)
{ {
OUString aFileURL; OUString aFileURL;
...@@ -2602,6 +2625,34 @@ void DesktopLOKTest::testTextSelectionHandles() ...@@ -2602,6 +2625,34 @@ void DesktopLOKTest::testTextSelectionHandles()
comphelper::LibreOfficeKit::setActive(false); comphelper::LibreOfficeKit::setActive(false);
} }
void DesktopLOKTest::testDialogPaste()
{
comphelper::LibreOfficeKit::setActive();
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
pDocument->pClass->postUnoCommand(pDocument, ".uno:HyperlinkDialog", nullptr, false);
Scheduler::ProcessEventsToIdle();
SfxViewShell* pViewShell = SfxViewShell::Current();
pViewShell->GetViewFrame()->GetBindings().Update();
VclPtr<vcl::Window> pWindow(Application::GetActiveTopWindow());
CPPUNIT_ASSERT(pWindow);
pDocument->pClass->postWindow(pDocument, pWindow->GetLOKWindowId(), LOK_WINDOW_PASTE,
"{ \"MimeType\" : { \"type\" : \"string\", \"value\" : \"text/plain;charset=utf-8\" }, \"Data\" : { \"type\" : \"[]byte\", \"value\" : \"www.softwarelibre.org.bo\" } }");
Scheduler::ProcessEventsToIdle();
Control* pCtrlFocused = GetFocusControl(pWindow.get());
CPPUNIT_ASSERT(pCtrlFocused);
ComboBox* pCtrlURL = dynamic_cast<ComboBox*>(pCtrlFocused);
CPPUNIT_ASSERT(pCtrlURL);
CPPUNIT_ASSERT_EQUAL(OUString("www.softwarelibre.org.bo"), pCtrlURL->GetText());
static_cast<SystemWindow*>(pWindow.get())->Close();
Scheduler::ProcessEventsToIdle();
comphelper::LibreOfficeKit::setActive(false);
}
namespace { namespace {
size_t documentClassOffset(int i) size_t documentClassOffset(int i)
......
...@@ -353,6 +353,15 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char ...@@ -353,6 +353,15 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char
aValue.Value <<= static_cast<sal_Int16>(OString(rValue.c_str()).toInt32()); aValue.Value <<= static_cast<sal_Int16>(OString(rValue.c_str()).toInt32());
else if (rType == "unsigned short") else if (rType == "unsigned short")
aValue.Value <<= static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32()); aValue.Value <<= static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32());
else if (rType == "[]byte")
{
aNodeValue = rPair.second.get_child("value", aNodeNull);
if (aNodeValue != aNodeNull && aNodeValue.size() == 0)
{
uno::Sequence< sal_Int8 > aSeqByte(reinterpret_cast<const sal_Int8*>(rValue.c_str()), rValue.size());
aValue.Value <<= aSeqByte;
}
}
else if (rType == "[]any") else if (rType == "[]any")
{ {
aNodeValue = rPair.second.get_child("value", aNodeNull); aNodeValue = rPair.second.get_child("value", aNodeNull);
...@@ -803,7 +812,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* pThis, unsigned nLOKWindo ...@@ -803,7 +812,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* pThis, unsigned nLOKWindo
const int nWidth, const int nHeight, const int nWidth, const int nHeight,
const double fDPIScale); const double fDPIScale);
static void doc_postWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, int nAction); static void doc_postWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, int nAction, const char* pData);
static char* doc_getPartInfo(LibreOfficeKitDocument* pThis, int nPart); static char* doc_getPartInfo(LibreOfficeKitDocument* pThis, int nPart);
...@@ -4243,7 +4252,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW ...@@ -4243,7 +4252,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW
#endif #endif
} }
static void doc_postWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId, int nAction) static void doc_postWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId, int nAction, const char* pData)
{ {
comphelper::ProfileZone aZone("doc_postWindow"); comphelper::ProfileZone aZone("doc_postWindow");
...@@ -4265,6 +4274,30 @@ static void doc_postWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindo ...@@ -4265,6 +4274,30 @@ static void doc_postWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindo
else if (FloatingWindow* pFloatWin = dynamic_cast<FloatingWindow*>(pWindow.get())) else if (FloatingWindow* pFloatWin = dynamic_cast<FloatingWindow*>(pWindow.get()))
pFloatWin->EndPopupMode(FloatWinPopupEndFlags::Cancel | FloatWinPopupEndFlags::CloseAll); pFloatWin->EndPopupMode(FloatWinPopupEndFlags::Cancel | FloatWinPopupEndFlags::CloseAll);
} }
else if (nAction == LOK_WINDOW_PASTE)
{
OUString aMimeType;
css::uno::Sequence<sal_Int8> aData;
std::vector<beans::PropertyValue> aArgs(jsonToPropertyValuesVector(pData));
{
aArgs.size() == 2 &&
aArgs[0].Name == "MimeType" && (aArgs[0].Value >>= aMimeType) &&
aArgs[1].Name == "Data" && (aArgs[1].Value >>= aData);
}
if (!aMimeType.isEmpty() && aData.getLength() > 0)
{
uno::Reference<datatransfer::XTransferable> xTransferable(new LOKTransferable(aMimeType, aData));
uno::Reference<datatransfer::clipboard::XClipboard> xClipboard(new LOKClipboard);
xClipboard->setContents(xTransferable, uno::Reference<datatransfer::clipboard::XClipboardOwner>());
pWindow->SetClipboard(xClipboard);
KeyEvent aEvent(0, KEY_PASTE, 0);
Application::PostKeyEvent(VclEventId::WindowKeyInput, pWindow, &aEvent);
}
else
gImpl->maLastExceptionMsg = "Window command 'paste': wrong parameters.";
}
} }
// CERTIFICATE AND DOCUMENT SIGNING // CERTIFICATE AND DOCUMENT SIGNING
......
...@@ -29,11 +29,17 @@ OUString SAL_CALL LOKClipboard::getName() ...@@ -29,11 +29,17 @@ OUString SAL_CALL LOKClipboard::getName()
} }
LOKTransferable::LOKTransferable(const char* pMimeType, const char* pData, std::size_t nSize) LOKTransferable::LOKTransferable(const char* pMimeType, const char* pData, std::size_t nSize)
: m_aMimeType(pMimeType), : m_aMimeType(OUString::fromUtf8(pMimeType)),
m_aSequence(reinterpret_cast<const sal_Int8*>(pData), nSize) m_aSequence(reinterpret_cast<const sal_Int8*>(pData), nSize)
{ {
} }
LOKTransferable::LOKTransferable(const OUString& sMimeType, const css::uno::Sequence<sal_Int8>& aSequence)
: m_aMimeType(sMimeType),
m_aSequence(aSequence)
{
}
uno::Any SAL_CALL LOKTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor) uno::Any SAL_CALL LOKTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor)
{ {
uno::Any aRet; uno::Any aRet;
...@@ -51,7 +57,7 @@ std::vector<datatransfer::DataFlavor> LOKTransferable::getTransferDataFlavorsAsV ...@@ -51,7 +57,7 @@ std::vector<datatransfer::DataFlavor> LOKTransferable::getTransferDataFlavorsAsV
{ {
std::vector<datatransfer::DataFlavor> aRet; std::vector<datatransfer::DataFlavor> aRet;
datatransfer::DataFlavor aFlavor; datatransfer::DataFlavor aFlavor;
aFlavor.MimeType = OUString::fromUtf8(m_aMimeType.getStr()); aFlavor.MimeType = m_aMimeType;
aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get(); aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get();
sal_Int32 nIndex(0); sal_Int32 nIndex(0);
......
...@@ -32,7 +32,7 @@ public: ...@@ -32,7 +32,7 @@ public:
/// Represents the contents of LOKClipboard. /// Represents the contents of LOKClipboard.
class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable> class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
{ {
OString m_aMimeType; OUString m_aMimeType;
css::uno::Sequence<sal_Int8> m_aSequence; css::uno::Sequence<sal_Int8> m_aSequence;
/// Provides a list of flavors, used by getTransferDataFlavors() and isDataFlavorSupported(). /// Provides a list of flavors, used by getTransferDataFlavors() and isDataFlavorSupported().
...@@ -40,6 +40,7 @@ class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransfer ...@@ -40,6 +40,7 @@ class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransfer
public: public:
LOKTransferable(const char* pMimeType, const char* pData, std::size_t nSize); LOKTransferable(const char* pMimeType, const char* pData, std::size_t nSize);
LOKTransferable(const OUString& sMimeType, const css::uno::Sequence<sal_Int8>& aSequence);
css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override; css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override;
......
...@@ -294,7 +294,7 @@ struct _LibreOfficeKitDocumentClass ...@@ -294,7 +294,7 @@ struct _LibreOfficeKitDocumentClass
const int width, const int height); const int width, const int height);
/// @see lok::Document::postWindow(). /// @see lok::Document::postWindow().
void (*postWindow) (LibreOfficeKitDocument* pThis, unsigned nWindowId, int nAction); void (*postWindow) (LibreOfficeKitDocument* pThis, unsigned nWindowId, int nAction, const char* pData);
/// @see lok::Document::postWindowKeyEvent(). /// @see lok::Document::postWindowKeyEvent().
void (*postWindowKeyEvent) (LibreOfficeKitDocument* pThis, void (*postWindowKeyEvent) (LibreOfficeKitDocument* pThis,
......
...@@ -188,9 +188,9 @@ public: ...@@ -188,9 +188,9 @@ public:
* *
* @param nWindowid * @param nWindowid
*/ */
void postWindow(unsigned nWindowId, int nAction) void postWindow(unsigned nWindowId, int nAction, const char* pData)
{ {
return mpDoc->pClass->postWindow(mpDoc, nWindowId, nAction); return mpDoc->pClass->postWindow(mpDoc, nWindowId, nAction, pData);
} }
/** /**
......
...@@ -42,7 +42,8 @@ LibreOfficeKitTileMode; ...@@ -42,7 +42,8 @@ LibreOfficeKitTileMode;
typedef enum typedef enum
{ {
LOK_WINDOW_CLOSE LOK_WINDOW_CLOSE,
LOK_WINDOW_PASTE
} }
LibreOfficeKitWindowAction; LibreOfficeKitWindowAction;
......
...@@ -423,7 +423,7 @@ gtv_application_window_unregister_child_window(GtvApplicationWindow* window, Gtk ...@@ -423,7 +423,7 @@ gtv_application_window_unregister_child_window(GtvApplicationWindow* window, Gtk
LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview)); LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview));
guint dialogId = 0; guint dialogId = 0;
g_object_get(G_OBJECT(pChildWin), "dialogid", &dialogId, nullptr); g_object_get(G_OBJECT(pChildWin), "dialogid", &dialogId, nullptr);
pDocument->pClass->postWindow(pDocument, dialogId, LOK_WINDOW_CLOSE); pDocument->pClass->postWindow(pDocument, dialogId, LOK_WINDOW_CLOSE, nullptr);
} }
} }
......
...@@ -278,7 +278,7 @@ void testDialog( Document *pDocument, const char *uno_cmd ) ...@@ -278,7 +278,7 @@ void testDialog( Document *pDocument, const char *uno_cmd )
} }
aTimes.emplace_back("post close dialog"); aTimes.emplace_back("post close dialog");
pDocument->postWindow(nDialogId, LOK_WINDOW_CLOSE); pDocument->postWindow(nDialogId, LOK_WINDOW_CLOSE, nullptr);
aTimes.emplace_back(); aTimes.emplace_back();
pDocument->destroyView(view); pDocument->destroyView(view);
......
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