diff options
author | Jan Holesovsky <kendy@collabora.com> | 2017-11-24 18:50:05 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2017-11-28 19:49:18 +0100 |
commit | 80d9696eb76e69101996c7a35ffec4c247e079d8 (patch) | |
tree | 2594fea36623214f7be95ada417e2813bbc9a8ed /desktop | |
parent | 42777e61a4060b7b78795a5bb89e3155327a2555 (diff) |
lokdialog: Move the painting down to Window, and enable Calc and Impress.
Tested with .uno:FormatCellDialog in Calc, Impress not tested.
Change-Id: I6d911c29616988db0625be9e2a63cf2172c69ee8
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/lib/init.cxx | 156 |
1 files changed, 115 insertions, 41 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 1596c7788ec8..2770575a9e0d 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -564,7 +564,7 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nCharCode, int nKeyCode); static void doc_postDialogKeyEvent(LibreOfficeKitDocument* pThis, - unsigned nDialogId, + unsigned nLOKWindowId, int nType, int nCharCode, int nKeyCode); @@ -576,7 +576,7 @@ static void doc_postMouseEvent (LibreOfficeKitDocument* pThis, int nButtons, int nModifier); static void doc_postDialogMouseEvent (LibreOfficeKitDocument* pThis, - unsigned nDialogId, + unsigned nLOKWindowId, int nType, int nX, int nY, @@ -584,7 +584,7 @@ static void doc_postDialogMouseEvent (LibreOfficeKitDocument* pThis, int nButtons, int nModifier); static void doc_postDialogChildMouseEvent (LibreOfficeKitDocument* pThis, - unsigned nDialogId, + unsigned nLOKWindowId, int nType, int nX, int nY, @@ -631,14 +631,14 @@ static unsigned char* doc_renderFont(LibreOfficeKitDocument* pThis, int* pFontHeight); static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart); -static void doc_paintDialog(LibreOfficeKitDocument* pThis, unsigned nDialogId, unsigned char* pBuffer, +static void doc_paintDialog(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, unsigned char* pBuffer, const int nX, const int nY, const int nWidth, const int nHeight); -static void doc_getDialogInfo(LibreOfficeKitDocument* pThis, unsigned nDialogId, +static void doc_getDialogInfo(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, char** pDialogTitle, int* nWidth, int* nHeight); -static void doc_paintActiveFloatingWindow(LibreOfficeKitDocument* pThis, unsigned nDialogId, unsigned char* pBuffer, int* nWidth, int* nHeight); +static void doc_paintActiveFloatingWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, unsigned char* pBuffer, int* nWidth, int* nHeight); LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) : mxComponent(xComponent) @@ -1049,7 +1049,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) boost::property_tree::ptree aTree; std::stringstream aStream(payload); boost::property_tree::read_json(aStream, aTree); - const unsigned nDialogId = aTree.get<unsigned>("dialogId", 0); + const unsigned nLOKWindowId = aTree.get<unsigned>("dialogId", 0); if (aTree.get<std::string>("action", "") == "invalidate") { std::string aRectStr = aTree.get<std::string>("rectangle", ""); @@ -1057,7 +1057,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) // remove all previous dialog part invalidations if (aRectStr.empty()) { - removeAll([&nDialogId] (const queue_type::value_type& elem) { + removeAll([&nLOKWindowId] (const queue_type::value_type& elem) { if (elem.first == LOK_CALLBACK_DIALOG) { boost::property_tree::ptree aOldTree; @@ -1065,7 +1065,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) boost::property_tree::read_json(aOldStream, aOldTree); const unsigned nOldDialogId = aOldTree.get<unsigned>("dialogId", 0); if (aOldTree.get<std::string>("action", "") == "invalidate" && - nDialogId == nOldDialogId) + nLOKWindowId == nOldDialogId) { return true; } @@ -1078,7 +1078,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) // if we have to invalidate all of the dialog, ignore // any part invalidation message const auto& pos = std::find_if(m_queue.rbegin(), m_queue.rend(), - [&nDialogId] (const queue_type::value_type& elem) + [&nLOKWindowId] (const queue_type::value_type& elem) { if (elem.first != LOK_CALLBACK_DIALOG) return false; @@ -1088,7 +1088,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) boost::property_tree::read_json(aOldStream, aOldTree); const unsigned nOldDialogId = aOldTree.get<unsigned>("dialogId", 0); if (aOldTree.get<std::string>("action", "") == "invalidate" && - nDialogId == nOldDialogId && + nLOKWindowId == nOldDialogId && aOldTree.get<std::string>("rectangle", "").empty()) { return true; @@ -1109,7 +1109,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) aRectStream >> nLeft >> nComma >> nTop >> nComma >> nWidth >> nComma >> nHeight; Rectangle aNewRect = Rectangle(nLeft, nTop, nLeft + nWidth, nTop + nHeight); bool currentIsRedundant = false; - removeAll([&aNewRect, &nDialogId, ¤tIsRedundant] (const queue_type::value_type& elem) { + removeAll([&aNewRect, &nLOKWindowId, ¤tIsRedundant] (const queue_type::value_type& elem) { if (elem.first != LOK_CALLBACK_DIALOG) return false; @@ -1129,7 +1129,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) aOldRectStream >> nOldLeft >> nOldComma >> nOldTop >> nOldComma >> nOldWidth >> nOldComma >> nOldHeight; Rectangle aOldRect = Rectangle(nOldLeft, nOldTop, nOldLeft + nOldWidth, nOldTop + nOldHeight); - if (nDialogId == nOldDialogId) + if (nLOKWindowId == nOldDialogId) { // new one engulfs the old one? if (aNewRect.IsInside(aOldRect)) @@ -1342,10 +1342,14 @@ ITiledRenderable* getTiledRenderable(LibreOfficeKitDocument* pThis) return dynamic_cast<ITiledRenderable*>(pDocument->mxComponent.get()); } -IDialogRenderable* getDialogRenderable(LibreOfficeKitDocument* pThis) +VclPtr<Window> findWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId) { - LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); - return dynamic_cast<IDialogRenderable*>(pDocument->mxComponent.get()); + ITiledRenderable* pRenderable = getTiledRenderable(pThis); + + if (!pRenderable) + return VclPtr<Window>(); + + return pRenderable->findWindow(nLOKWindowId); } } // anonymous namespace @@ -2277,18 +2281,31 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar pDoc->postKeyEvent(nType, nCharCode, nKeyCode); } -static void doc_postDialogKeyEvent(LibreOfficeKitDocument* pThis, unsigned nDialogId, int nType, int nCharCode, int nKeyCode) +static void doc_postDialogKeyEvent(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, int nType, int nCharCode, int nKeyCode) { SolarMutexGuard aGuard; - IDialogRenderable* pDoc = getDialogRenderable(pThis); - if (!pDoc) + VclPtr<Window> pWindow = findWindow(pThis, nLOKWindowId); + if (!pWindow) { - gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering"; + gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found."; return; } - pDoc->postDialogKeyEvent(nDialogId, nType, nCharCode, nKeyCode); + KeyEvent aEvent(nCharCode, nKeyCode, 0); + + switch (nType) + { + case LOK_KEYEVENT_KEYINPUT: + pWindow->LOKKeyInput(aEvent); + break; + case LOK_KEYEVENT_KEYUP: + pWindow->LOKKeyUp(aEvent); + break; + default: + assert(false); + break; + } } /** Class to react on finishing of a dispatched command. @@ -2442,32 +2459,66 @@ static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX, } } -static void doc_postDialogMouseEvent(LibreOfficeKitDocument* pThis, unsigned nDialogId, int nType, int nX, int nY, int nCount, int nButtons, int nModifier) +static void doc_postDialogMouseEvent(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, int nType, int nX, int nY, int nCount, int nButtons, int nModifier) { SolarMutexGuard aGuard; - IDialogRenderable* pDoc = getDialogRenderable(pThis); - if (!pDoc) + VclPtr<Window> pWindow = findWindow(pThis, nLOKWindowId); + if (!pWindow) { - gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering"; + gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found."; return; } - pDoc->postDialogMouseEvent(nDialogId, nType, nX, nY, nCount, nButtons, nModifier); + Point aPos(nX, nY); + MouseEvent aEvent(aPos, nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier); + + switch (nType) + { + case LOK_MOUSEEVENT_MOUSEBUTTONDOWN: + pWindow->LogicMouseButtonDown(aEvent); + break; + case LOK_MOUSEEVENT_MOUSEBUTTONUP: + pWindow->LogicMouseButtonUp(aEvent); + break; + case LOK_MOUSEEVENT_MOUSEMOVE: + pWindow->LogicMouseMove(aEvent); + break; + default: + assert(false); + break; + } } -static void doc_postDialogChildMouseEvent(LibreOfficeKitDocument* pThis, unsigned nDialogId, int nType, int nX, int nY, int nCount, int nButtons, int nModifier) +static void doc_postDialogChildMouseEvent(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, int nType, int nX, int nY, int nCount, int nButtons, int nModifier) { SolarMutexGuard aGuard; - IDialogRenderable* pDoc = getDialogRenderable(pThis); - if (!pDoc) + VclPtr<Window> pWindow = findWindow(pThis, nLOKWindowId); + if (!pWindow) { - gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering"; + gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found."; return; } - pDoc->postDialogChildMouseEvent(nDialogId, nType, nX, nY, nCount, nButtons, nModifier); + Point aPos(nX, nY); + MouseEvent aEvent(aPos, nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier); + + switch (nType) + { + case LOK_MOUSEEVENT_MOUSEBUTTONDOWN: + pWindow->LogicMouseButtonDownChild(aEvent); + break; + case LOK_MOUSEEVENT_MOUSEBUTTONUP: + pWindow->LogicMouseButtonUpChild(aEvent); + break; + case LOK_MOUSEEVENT_MOUSEMOVE: + pWindow->LogicMouseMoveChild(aEvent); + break; + default: + assert(false); + break; + } } static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY) @@ -3246,14 +3297,25 @@ unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/, return nullptr; } -static void doc_getDialogInfo(LibreOfficeKitDocument* pThis, unsigned nDialogId, +static void doc_getDialogInfo(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, char** pDialogTitle, int* nWidth, int* nHeight) { + // FIXME - I guess we should kill this one, and use only the callback + // "created"? + SolarMutexGuard aGuard; - IDialogRenderable* pDialogRenderable = getDialogRenderable(pThis); - OUString aDialogTitle; - pDialogRenderable->getDialogInfo(nDialogId, aDialogTitle, *nWidth, *nHeight); + VclPtr<Window> pWindow = findWindow(pThis, nLOKWindowId); + if (!pWindow) + { + gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found."; + return; + } + + OUString aDialogTitle(pWindow->GetText()); + const Size aSize = pWindow->GetSizePixel(); + *nWidth = aSize.getWidth(); + *nHeight = aSize.getHeight(); // copy dialog title if (!aDialogTitle.isEmpty()) @@ -3264,14 +3326,19 @@ static void doc_getDialogInfo(LibreOfficeKitDocument* pThis, unsigned nDialogId, } } -static void doc_paintDialog(LibreOfficeKitDocument* pThis, unsigned nDialogId, +static void doc_paintDialog(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, unsigned char* pBuffer, const int nX, const int nY, const int nWidth, const int nHeight) { SolarMutexGuard aGuard; - IDialogRenderable* pDialogRenderable = getDialogRenderable(pThis); + VclPtr<Window> pWindow = findWindow(pThis, nLOKWindowId); + if (!pWindow) + { + gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found."; + return; + } ScopedVclPtrInstance<VirtualDevice> pDevice(nullptr, Size(1, 1), DeviceFormat::DEFAULT); pDevice->SetBackground(Wallpaper(Color(COL_TRANSPARENT))); @@ -3283,15 +3350,20 @@ static void doc_paintDialog(LibreOfficeKitDocument* pThis, unsigned nDialogId, pDevice->SetMapMode(aMapMode); comphelper::LibreOfficeKit::setDialogPainting(true); - pDialogRenderable->paintDialog(nDialogId, *pDevice.get()); + pWindow->paintDialog(*pDevice.get()); comphelper::LibreOfficeKit::setDialogPainting(false); } -static void doc_paintActiveFloatingWindow(LibreOfficeKitDocument* pThis, unsigned nDialogId, unsigned char* pBuffer, int* nWidth, int* nHeight) +static void doc_paintActiveFloatingWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, unsigned char* pBuffer, int* nWidth, int* nHeight) { SolarMutexGuard aGuard; - IDialogRenderable* pDialogRenderable = getDialogRenderable(pThis); + VclPtr<Window> pWindow = findWindow(pThis, nLOKWindowId); + if (!pWindow) + { + gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found."; + return; + } ScopedVclPtrInstance<VirtualDevice> pDevice(nullptr, Size(1, 1), DeviceFormat::DEFAULT); pDevice->SetBackground(Wallpaper(Color(COL_TRANSPARENT))); @@ -3299,7 +3371,9 @@ static void doc_paintActiveFloatingWindow(LibreOfficeKitDocument* pThis, unsigne pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(*nWidth, *nHeight), Fraction(1.0), Point(), pBuffer); comphelper::LibreOfficeKit::setDialogPainting(true); - pDialogRenderable->paintActiveFloatingWindow(nDialogId, *pDevice.get(), *nWidth, *nHeight); + const Size aSize = pWindow->PaintActiveFloatingWindow(*pDevice.get()); + *nWidth = aSize.getWidth(); + *nHeight = aSize.getHeight(); comphelper::LibreOfficeKit::setDialogPainting(false); } |