summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranav Kant <pranavk@collabora.com>2016-03-31 14:47:27 +0530
committerJan Holesovsky <kendy@collabora.com>2016-04-08 12:49:45 +0200
commit6be044e919d28b93332f04bdc18f6def2925b098 (patch)
treee996b7cfa31c655b7998761394dd9b4d35be4f8d
parent9820da23375d89c26d6feb9d8ee3969916dc0d76 (diff)
lok context menu: Expose context menu
Change-Id: I0968689630e10f838c075e86357eb36a9a220d0d
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitEnums.h16
-rw-r--r--sc/source/ui/inc/gridwin.hxx2
-rw-r--r--sc/source/ui/unoobj/docuno.cxx10
-rw-r--r--sd/source/ui/unoidl/unomodel.cxx10
-rw-r--r--sfx2/source/menu/mnumgr.cxx124
-rw-r--r--sw/source/uibase/inc/edtwin.hxx4
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx9
7 files changed, 166 insertions, 9 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 343d169b7b07..88098b1d6700 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -280,6 +280,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/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index dc1cec7fd8c7..a39320c99d16 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -301,7 +301,6 @@ protected:
virtual void LoseFocus() SAL_OVERRIDE;
virtual void RequestHelp( const HelpEvent& rEvt ) SAL_OVERRIDE;
- virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) SAL_OVERRIDE;
virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) SAL_OVERRIDE;
@@ -319,6 +318,7 @@ public:
rtl::Reference<sdr::overlay::OverlayManager> getOverlayManager();
void flushOverlayManager();
+ virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index d21a7a24ede1..cba78bd63e70 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(nTilePixelHeight * TWIPS_PER_PIXEL, nTileTwipHeight), 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 61e2bbc5bb02..57fca72a89bc 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2454,16 +2454,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/menu/mnumgr.cxx b/sfx2/source/menu/mnumgr.cxx
index 782d041b7081..b3a896170e84 100644
--- a/sfx2/source/menu/mnumgr.cxx
+++ b/sfx2/source/menu/mnumgr.cxx
@@ -17,6 +17,8 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <boost/property_tree/json_parser.hpp>
+
#include <com/sun/star/embed/VerbDescriptor.hpp>
#include <com/sun/star/embed/VerbAttributes.hpp>
#include <com/sun/star/container/XNamed.hpp>
@@ -64,6 +66,9 @@
#include <sfx2/objface.hxx>
#include "thessubmenu.hxx"
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/lok.hxx>
+
// static member initialization
PopupMenu * SfxPopupMenuManager::pStaticThesSubMenu = NULL;
@@ -330,6 +335,105 @@ SfxPopupMenuManager* SfxPopupMenuManager::Popup( const ResId& rResId, SfxViewFra
return 0;
}
+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
void SfxPopupMenuManager::ExecutePopup( const ResId& rResId, SfxViewFrame* pFrame, const Point& rPoint, vcl::Window* pWindow )
{
@@ -372,9 +476,23 @@ void SfxPopupMenuManager::ExecutePopup( const ResId& rResId, SfxViewFrame* pFram
pSVMenu = static_cast<PopupMenu*>( pMenu );
}
- SfxPopupMenuManager aPop( pSVMenu, pFrame->GetBindings() );
- aPop.RemoveDisabledEntries();
- aPop.Execute( rPoint, pWindow );
+ if (comphelper::LibreOfficeKit::isActive())
+ {
+ boost::property_tree::ptree aMenu = fillPopupMenu(pSVMenu);
+ boost::property_tree::ptree aRoot;
+ aRoot.add_child("menu", aMenu);
+
+ 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());
+ }
+ else
+ {
+ SfxPopupMenuManager aPop( pSVMenu, pFrame->GetBindings() );
+ aPop.RemoveDisabledEntries();
+ aPop.Execute( rPoint, pWindow );
+ }
// #i112646 avoid crash when context menu is closed.
// the (manually inserted) sub-menu needs to be destroyed before
diff --git a/sw/source/uibase/inc/edtwin.hxx b/sw/source/uibase/inc/edtwin.hxx
index ed65f1e9d1d6..52ad95bbc510 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) SAL_OVERRIDE;
virtual void RequestHelp(const HelpEvent& rEvt) SAL_OVERRIDE;
- virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
-
// Drag & Drop Interface
virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) SAL_OVERRIDE;
virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) SAL_OVERRIDE;
@@ -297,6 +295,8 @@ public:
virtual ~SwEditWin();
virtual void dispose() SAL_OVERRIDE;
+ virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
+
/// @see OutputDevice::LogicInvalidate().
void LogicInvalidate(const Rectangle* pRectangle) SAL_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 1f7fbf9de8f6..9a78c37b6ca2 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3344,12 +3344,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);