diff options
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitEnums.h | 16 | ||||
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 7 | ||||
-rw-r--r-- | sc/source/ui/inc/gridwin.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 10 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 10 | ||||
-rw-r--r-- | sfx2/source/control/dispatch.cxx | 126 | ||||
-rw-r--r-- | sw/source/uibase/inc/edtwin.hxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 9 |
8 files changed, 175 insertions, 9 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 80ed9def0fd8..fb713cdde185 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -289,6 +289,22 @@ typedef enum * } */ LOK_CALLBACK_ERROR, + + /** + * Context menu structure + * + * Returns the structure of context menu + * + * { + * "menu": [ + * {"text": "label text", "type": "command | separator | menu", + * "command | menu": "..." }, + * ... + * ] + * } + */ + LOK_CALLBACK_CONTEXT_MENU, + } LibreOfficeKitCallbackType; diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 155174f2a289..81ccb378cb4a 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -336,6 +336,8 @@ callbackTypeToString (int nType) return "LOK_CALLBACK_DOCUMENT_PASSWORD"; case LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY: return "LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY"; + case LOK_CALLBACK_CONTEXT_MENU: + return "LOK_CALLBACK_CONTEXT_MENU"; } return nullptr; } @@ -1141,6 +1143,11 @@ callback (gpointer pData) reportError(pDocView, pCallback->m_aPayload); } break; + case LOK_CALLBACK_CONTEXT_MENU: + { + // TODO: Implement me + break; + } default: g_assert(false); break; diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx index a8862538e5d2..d4baed73d77f 100644 --- a/sc/source/ui/inc/gridwin.hxx +++ b/sc/source/ui/inc/gridwin.hxx @@ -295,7 +295,6 @@ protected: virtual void LoseFocus() override; virtual void RequestHelp( const HelpEvent& rEvt ) override; - virtual void Command( const CommandEvent& rCEvt ) override; virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; @@ -313,6 +312,7 @@ public: rtl::Reference<sdr::overlay::OverlayManager> getOverlayManager(); void flushOverlayManager(); + virtual void Command( const CommandEvent& rCEvt ) override; virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index ead7061e9108..81af766093c6 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -597,13 +597,21 @@ void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount, int nButt Fraction(mnTilePixelHeight * TWIPS_PER_PIXEL, mnTileTwipHeight), true); // Calc operates in pixels... - MouseEvent aEvent(Point(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY()), nCount, + Point aPos(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY()); + MouseEvent aEvent(aPos, nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier); switch (nType) { case LOK_MOUSEEVENT_MOUSEBUTTONDOWN: pGridWindow->MouseButtonDown(aEvent); + + // Invoke the context menu + if (nButtons & MOUSE_RIGHT) + { + const CommandEvent aCEvt(aPos, CommandEventId::ContextMenu, true, nullptr); + pGridWindow->Command(aCEvt); + } break; case LOK_MOUSEEVENT_MOUSEBUTTONUP: pGridWindow->MouseButtonUp(aEvent); diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 546f360bba12..a44f12ed6f73 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2438,16 +2438,24 @@ void SdXImpressDocument::postMouseEvent(int nType, int nX, int nY, int nCount, i SolarMutexGuard aGuard; DrawViewShell* pViewShell = GetViewShell(); + Window* pWindow = pViewShell->GetActiveWindow(); if (!pViewShell) return; - MouseEvent aEvent(Point(convertTwipToMm100(nX), convertTwipToMm100(nY)), nCount, + Point aPos(Point(convertTwipToMm100(nX), convertTwipToMm100(nY))); + MouseEvent aEvent(aPos, nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier); switch (nType) { case LOK_MOUSEEVENT_MOUSEBUTTONDOWN: pViewShell->LogicMouseButtonDown(aEvent); + + if (nButtons & MOUSE_RIGHT) + { + const CommandEvent aCEvt(aPos, CommandEventId::ContextMenu, true, nullptr); + pViewShell->Command(aCEvt, pWindow); + } break; case LOK_MOUSEEVENT_MOUSEBUTTONUP: pViewShell->LogicMouseButtonUp(aEvent); diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx index b6e3600d56d6..7782459d5186 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -26,11 +26,14 @@ #include <stdarg.h> #include <stdlib.h> +#include <boost/property_tree/json_parser.hpp> + #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp> #include <com/sun/star/frame/XLayoutManager.hpp> #include <com/sun/star/frame/XPopupMenuController.hpp> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <comphelper/lok.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> @@ -144,6 +147,107 @@ struct SfxDispatcher_Impl std::deque< std::deque<SfxToDo_Impl> > aToDoCopyStack; }; +namespace { + + boost::property_tree::ptree fillPopupMenu(Menu* pMenu) + { + // Activate this menu first + pMenu->HandleMenuActivateEvent(pMenu); + pMenu->HandleMenuDeActivateEvent(pMenu); + + boost::property_tree::ptree aTree; + // If last item inserted is some valid text + bool bIsLastItemText = false; + sal_uInt16 nCount = pMenu->GetItemCount(); + for (sal_uInt16 nPos = 0; nPos < nCount; nPos++) + { + boost::property_tree::ptree aItemTree; + const MenuItemType aItemType = pMenu->GetItemType(nPos); + + if (aItemType == MenuItemType::DONTKNOW) + continue; + + if (aItemType == MenuItemType::SEPARATOR) + { + if (bIsLastItemText) + aItemTree.put("type", "separator"); + bIsLastItemText = false; + } + else + { + const sal_uInt16 nItemId = pMenu->GetItemId(nPos); + const OUString aCommandURL = pMenu->GetItemCommand(nItemId); + + const OUString aItemText = pMenu->GetItemText(nItemId); + Menu* pPopupSubmenu = pMenu->GetPopupMenu(nItemId); + + if (!pMenu->IsItemEnabled(nItemId)) + continue; + + if (!aItemText.isEmpty()) + aItemTree.put("text", std::string(aItemText.toUtf8().getStr())); + + if (pPopupSubmenu) + { + boost::property_tree::ptree aSubmenu = fillPopupMenu(pPopupSubmenu); + if (!aSubmenu.empty()) + { + aItemTree.put("type", "menu"); + aItemTree.push_back(std::make_pair("menu", aSubmenu)); + } + else + aItemTree.clear(); + } + else + { + if (!aCommandURL.isEmpty()) + { + aItemTree.put("type", "command"); + aItemTree.put("command", std::string(aCommandURL.toUtf8().getStr())); + } + } + + MenuItemBits aItemBits = pMenu->GetItemBits(nItemId); + bool bHasChecks = false; + if (aItemBits & MenuItemBits::CHECKABLE) + { + aItemTree.put("checktype", "checkmark"); + bHasChecks = true; + } + else if (aItemBits & MenuItemBits::RADIOCHECK) + { + aItemTree.put("checktype", "radio"); + bHasChecks = true; + } + else if (aItemBits & MenuItemBits::AUTOCHECK) + { + aItemTree.put("checktype", "auto"); + bHasChecks = true; + } + + if (bHasChecks) + { + if (pMenu->IsItemChecked(nItemId)) + aItemTree.put("checked", "true"); + else + aItemTree.put("checked", "false"); + } + } + + if (!aItemTree.empty()) + { + aTree.push_back(std::make_pair("", aItemTree)); + if (aItemType != MenuItemType::SEPARATOR) + bIsLastItemText = true; + } + } + + return aTree; + } + +} // end anonymous namespace + + /** This method checks if the stack of the SfxDispatchers is flushed, or if push- or pop- commands are pending. */ @@ -1884,9 +1988,25 @@ void SfxDispatcher::ExecutePopup( const OUString& rResName, vcl::Window *pWin, c xPopupController->setPopupMenu( xPopupMenu ); VCLXMenu* pAwtMenu = VCLXMenu::GetImplementation( xPopupMenu ); PopupMenu* pVCLMenu = static_cast< PopupMenu* >( pAwtMenu->GetMenu() ); - OUString aMenuURL = "private:resource/popupmenu/" + rResName; - if ( pVCLMenu && GetFrame()->GetViewShell()->TryContextMenuInterception( *pVCLMenu, aMenuURL, aEvent ) ) - pVCLMenu->Execute( pWindow, aPos ); + if (comphelper::LibreOfficeKit::isActive()) + { + boost::property_tree::ptree aMenu = fillPopupMenu(pVCLMenu); + boost::property_tree::ptree aRoot; + aRoot.add_child("menu", aMenu); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aRoot, true); + const SfxObjectShell* objSh = xImp->pFrame->GetObjectShell(); + objSh->libreOfficeKitCallback(LOK_CALLBACK_CONTEXT_MENU, aStream.str().c_str()); + } + else + { + OUString aMenuURL = "private:resource/popupmenu/" + rResName; + if (pVCLMenu && GetFrame()->GetViewShell()->TryContextMenuInterception(*pVCLMenu, aMenuURL, aEvent)) + { + pVCLMenu->Execute(pWindow, aPos); + } + } css::uno::Reference< css::lang::XComponent > xComponent( xPopupController, css::uno::UNO_QUERY ); if ( xComponent.is() ) diff --git a/sw/source/uibase/inc/edtwin.hxx b/sw/source/uibase/inc/edtwin.hxx index 58f2a489a7e4..96c1d5a7898c 100644 --- a/sw/source/uibase/inc/edtwin.hxx +++ b/sw/source/uibase/inc/edtwin.hxx @@ -197,8 +197,6 @@ protected: virtual void MouseButtonUp(const MouseEvent& rMEvt) override; virtual void RequestHelp(const HelpEvent& rEvt) override; - virtual void Command( const CommandEvent& rCEvt ) override; - // Drag & Drop Interface virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; @@ -295,6 +293,8 @@ public: virtual ~SwEditWin(); virtual void dispose() override; + virtual void Command( const CommandEvent& rCEvt ) override; + /// @see OutputDevice::LogicInvalidate(). void LogicInvalidate(const Rectangle* pRectangle) override; /// Same as MouseButtonDown(), but coordinates are in logic unit. diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 2087912ee710..5a7d25211b92 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3305,12 +3305,19 @@ void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int SolarMutexGuard aGuard; SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin(); - MouseEvent aEvent(Point(nX, nY), nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier); + Point aPos(nX , nY); + MouseEvent aEvent(aPos, nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier); switch (nType) { case LOK_MOUSEEVENT_MOUSEBUTTONDOWN: rEditWin.LogicMouseButtonDown(aEvent); + + if (nButtons & MOUSE_RIGHT) + { + const CommandEvent aCEvt(aPos, CommandEventId::ContextMenu, true, nullptr); + rEditWin.Command(aCEvt); + } break; case LOK_MOUSEEVENT_MOUSEBUTTONUP: rEditWin.LogicMouseButtonUp(aEvent); |