summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-06-15 11:53:51 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-07-20 16:11:45 +0200
commit30cbe2e10e7208031662ffa02a7b4e61775219b7 (patch)
tree6e76d191acce65626728e43c3150cf42e969f183
parent32c231d90f3ba173dd60ceaf11e3cab6a5e6ef1a (diff)
sfx2: implement per-view LOK_CALLBACK_CONTEXT_MENU
Reviewed-on: https://gerrit.libreoffice.org/26293 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commits b8a1d072ff8e686fad4a507b85d163d699ed59e0 and 5b5706f41f97998785e1e7ad356580772da80c42) This fixes the failing CppunitTest_desktop_lib in this branch. Conflicts: sfx2/source/control/dispatch.cxx Change-Id: Ia321d2f03bf77eba87b1135799b3cb0409f23ebf
-rw-r--r--sfx2/source/control/dispatch.cxx122
-rw-r--r--sfx2/source/menu/mnumgr.cxx5
2 files changed, 6 insertions, 121 deletions
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index 94f025e2fee1..c0a35de70edc 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -26,14 +26,11 @@
#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>
@@ -148,103 +145,6 @@ 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);
- OUString aCommandURL = pMenu->GetItemCommand(nItemId);
-
- if (aCommandURL.isEmpty())
- {
- const SfxSlot *pSlot = SFX_SLOTPOOL().GetSlot(nItemId);
- if (pSlot)
- aCommandURL = pSlot->GetCommandString();
- }
-
- const OUString aItemText = pMenu->GetItemText(nItemId);
- Menu* pPopupSubmenu = pMenu->GetPopupMenu(nItemId);
-
- if (!aItemText.isEmpty())
- aItemTree.put("text", aItemText.toUtf8().getStr());
-
- if (pPopupSubmenu)
- {
- boost::property_tree::ptree aSubmenu = fillPopupMenu(pPopupSubmenu);
- if (aSubmenu.empty())
- continue;
-
- aItemTree.put("type", "menu");
- if (!aCommandURL.isEmpty())
- aItemTree.put("command", aCommandURL.toUtf8().getStr());
- aItemTree.push_back(std::make_pair("menu", aSubmenu));
- }
- else
- {
- // no point in exposing choices that don't have the .uno:
- // command
- if (aCommandURL.isEmpty())
- continue;
-
- aItemTree.put("type", "command");
- aItemTree.put("command", aCommandURL.toUtf8().getStr());
- }
-
- aItemTree.put("enabled", pMenu->IsItemEnabled(nItemId));
-
- MenuItemBits aItemBits = pMenu->GetItemBits(nItemId);
- bool bHasChecks = true;
- if (aItemBits & MenuItemBits::CHECKABLE)
- aItemTree.put("checktype", "checkmark");
- else if (aItemBits & MenuItemBits::RADIOCHECK)
- aItemTree.put("checktype", "radio");
- else if (aItemBits & MenuItemBits::AUTOCHECK)
- aItemTree.put("checktype", "auto");
- else
- bHasChecks = false;
-
- if (bHasChecks)
- aItemTree.put("checked", pMenu->IsItemChecked(nItemId));
- }
-
- 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.
*/
@@ -2034,25 +1934,9 @@ 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() );
- 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);
- if (SfxViewShell* pViewShell = xImp->pFrame->GetViewShell())
- pViewShell->libreOfficeKitViewCallback(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);
- }
- }
+ 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/sfx2/source/menu/mnumgr.cxx b/sfx2/source/menu/mnumgr.cxx
index 0741f4ec8b99..e940bb5897b0 100644
--- a/sfx2/source/menu/mnumgr.cxx
+++ b/sfx2/source/menu/mnumgr.cxx
@@ -474,8 +474,9 @@ void SfxPopupMenuManager::ExecutePopup( const ResId& rResId, SfxViewFrame* pFram
std::stringstream aStream;
boost::property_tree::write_json(aStream, aRoot, true);
- const SfxObjectShell* objSh = pFrame->GetObjectShell();
- objSh->libreOfficeKitCallback(LOK_CALLBACK_CONTEXT_MENU, aStream.str().c_str());
+ if (SfxViewShell* pViewShell = pFrame->GetViewShell())
+ pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_MENU, aStream.str().c_str());
+
}
else
aPop.Execute( rPoint, pWindow );