lok context menu: Expose context menu
Change-Id: I0968689630e10f838c075e86357eb36a9a220d0d
This commit is contained in:
committed by
Jan Holesovsky
parent
396ed6ff96
commit
610db8d5d0
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() )
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user