2013-06-16 02:48:58 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2013-04-19 08:51:45 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
2015-11-16 12:23:25 +01:00
|
|
|
#include <vcl/commandinfoprovider.hxx>
|
2016-07-13 15:52:26 +02:00
|
|
|
#include <vcl/mnemonic.hxx>
|
|
|
|
#include <comphelper/string.hxx>
|
2015-11-13 17:00:03 +01:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2015-09-01 18:13:22 +09:00
|
|
|
#include <cppuhelper/compbase.hxx>
|
2013-04-19 08:51:45 +00:00
|
|
|
#include <cppuhelper/basemutex.hxx>
|
|
|
|
|
2013-05-27 14:52:39 +02:00
|
|
|
#include <com/sun/star/frame/ModuleManager.hpp>
|
2014-01-28 15:27:32 +01:00
|
|
|
#include <com/sun/star/frame/theUICommandDescription.hpp>
|
2013-05-27 14:52:39 +02:00
|
|
|
#include <com/sun/star/ui/GlobalAcceleratorConfiguration.hpp>
|
2013-04-19 08:51:45 +00:00
|
|
|
#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
|
2014-01-29 18:58:18 +01:00
|
|
|
#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
|
2015-11-16 15:41:27 +01:00
|
|
|
#include <com/sun/star/ui/ImageType.hpp>
|
|
|
|
#include <com/sun/star/ui/XImageManager.hpp>
|
2015-11-16 12:23:25 +01:00
|
|
|
#include <com/sun/star/awt/KeyModifier.hpp>
|
|
|
|
|
2015-11-26 11:32:40 +00:00
|
|
|
#include "svdata.hxx"
|
|
|
|
|
2013-04-19 08:51:45 +00:00
|
|
|
using namespace css;
|
2014-09-02 17:38:00 +00:00
|
|
|
using namespace css::uno;
|
2013-04-19 08:51:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2015-09-01 18:13:22 +09:00
|
|
|
typedef ::cppu::WeakComponentImplHelper <
|
2015-11-17 18:01:13 +02:00
|
|
|
css::frame::XFrameActionListener
|
2013-04-19 08:51:45 +00:00
|
|
|
> FrameListenerInterfaceBase;
|
|
|
|
class FrameListener
|
|
|
|
: public ::cppu::BaseMutex,
|
|
|
|
public FrameListenerInterfaceBase
|
|
|
|
{
|
|
|
|
public:
|
2015-11-16 12:23:25 +01:00
|
|
|
FrameListener (vcl::CommandInfoProvider& rInfoProvider, const Reference<frame::XFrame>& rxFrame)
|
2013-04-19 08:51:45 +00:00
|
|
|
: FrameListenerInterfaceBase(m_aMutex),
|
|
|
|
mrInfoProvider(rInfoProvider),
|
|
|
|
mxFrame(rxFrame)
|
|
|
|
{
|
|
|
|
if (mxFrame.is())
|
2015-11-17 18:01:13 +02:00
|
|
|
mxFrame->addFrameActionListener(this);
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
2016-11-23 21:48:33 +01:00
|
|
|
|
2015-11-17 18:01:13 +02:00
|
|
|
virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent)
|
|
|
|
throw (css::uno::RuntimeException, std::exception) override
|
|
|
|
{
|
|
|
|
// The same frame can be reused for a different component, e.g.
|
|
|
|
// starting component from the start center, so need to re-init the cached data.
|
|
|
|
if (aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING)
|
|
|
|
mrInfoProvider.SetFrame(nullptr);
|
|
|
|
}
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void SAL_CALL disposing() override
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
if (mxFrame.is())
|
2015-11-17 18:01:13 +02:00
|
|
|
mxFrame->removeFrameActionListener(this);
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
|
2015-11-16 15:41:27 +01:00
|
|
|
throw (RuntimeException, std::exception) override
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
(void)rEvent;
|
2015-11-10 10:23:17 +01:00
|
|
|
mrInfoProvider.SetFrame(nullptr);
|
|
|
|
mxFrame = nullptr;
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-11-16 12:23:25 +01:00
|
|
|
vcl::CommandInfoProvider& mrInfoProvider;
|
2013-04-19 08:51:45 +00:00
|
|
|
Reference<frame::XFrame> mxFrame;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-11-16 12:23:25 +01:00
|
|
|
namespace vcl {
|
2013-04-19 08:51:45 +00:00
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
CommandInfoProvider& CommandInfoProvider::Instance()
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
static CommandInfoProvider aProvider;
|
|
|
|
return aProvider;
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
CommandInfoProvider::CommandInfoProvider()
|
2013-05-27 14:52:39 +02:00
|
|
|
: mxContext(comphelper::getProcessComponentContext()),
|
2013-04-19 08:51:45 +00:00
|
|
|
mxCachedDataFrame(),
|
|
|
|
mxCachedDocumentAcceleratorConfiguration(),
|
|
|
|
mxCachedModuleAcceleratorConfiguration(),
|
|
|
|
mxCachedGlobalAcceleratorConfiguration(),
|
|
|
|
msCachedModuleIdentifier(),
|
|
|
|
mxFrameListener()
|
|
|
|
{
|
2015-11-26 11:32:40 +00:00
|
|
|
ImplGetSVData()->mpCommandInfoProvider = this;
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 11:32:40 +00:00
|
|
|
void CommandInfoProvider::dispose()
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
if (mxFrameListener.is())
|
|
|
|
{
|
|
|
|
mxFrameListener->dispose();
|
2015-11-26 11:32:40 +00:00
|
|
|
mxFrameListener.clear();
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
2015-11-26 11:32:40 +00:00
|
|
|
mxCachedGlobalAcceleratorConfiguration.clear();
|
|
|
|
mxCachedModuleAcceleratorConfiguration.clear();
|
|
|
|
mxCachedDocumentAcceleratorConfiguration.clear();
|
|
|
|
mxCachedDataFrame.clear();
|
|
|
|
mxContext.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandInfoProvider::~CommandInfoProvider()
|
|
|
|
{
|
|
|
|
dispose();
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OUString CommandInfoProvider::GetLabelForCommand (
|
|
|
|
const OUString& rsCommandName,
|
|
|
|
const Reference<frame::XFrame>& rxFrame)
|
|
|
|
{
|
|
|
|
SetFrame(rxFrame);
|
|
|
|
|
2015-11-13 17:00:03 +01:00
|
|
|
return GetCommandProperty("Name", rsCommandName);
|
|
|
|
}
|
|
|
|
|
2015-11-17 12:08:30 +01:00
|
|
|
OUString CommandInfoProvider::GetMenuLabelForCommand (
|
|
|
|
const OUString& rsCommandName,
|
|
|
|
const Reference<frame::XFrame>& rxFrame)
|
|
|
|
{
|
|
|
|
SetFrame(rxFrame);
|
|
|
|
|
|
|
|
// Here we want to use "Label", not "Name". "Name" is a stripped-down version of "Label" without accelerators
|
|
|
|
// and ellipsis. In the menu, we want to have those accelerators and ellipsis.
|
|
|
|
return GetCommandProperty("Label", rsCommandName);
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString CommandInfoProvider::GetPopupLabelForCommand (
|
|
|
|
const OUString& rsCommandName,
|
|
|
|
const css::uno::Reference<css::frame::XFrame>& rxFrame)
|
|
|
|
{
|
|
|
|
SetFrame(rxFrame);
|
|
|
|
|
|
|
|
OUString sPopupLabel(GetCommandProperty("PopupLabel", rsCommandName));
|
|
|
|
if (!sPopupLabel.isEmpty())
|
|
|
|
return sPopupLabel;
|
|
|
|
return GetCommandProperty("Label", rsCommandName);
|
|
|
|
}
|
|
|
|
|
2015-11-13 17:00:03 +01:00
|
|
|
OUString CommandInfoProvider::GetTooltipForCommand (
|
|
|
|
const OUString& rsCommandName,
|
2016-02-26 10:36:34 +02:00
|
|
|
const Reference<frame::XFrame>& rxFrame)
|
2015-11-13 17:00:03 +01:00
|
|
|
{
|
|
|
|
SetFrame(rxFrame);
|
|
|
|
|
|
|
|
OUString sLabel (GetCommandProperty("TooltipLabel", rsCommandName));
|
2016-07-13 15:52:26 +02:00
|
|
|
if (sLabel.isEmpty()) {
|
|
|
|
sLabel = GetPopupLabelForCommand(rsCommandName, rxFrame);
|
|
|
|
// Remove '...' at the end and mnemonics (we don't want those in tooltips)
|
|
|
|
sLabel = comphelper::string::stripEnd(sLabel, '.');
|
|
|
|
sLabel = MnemonicGenerator::EraseAllMnemonicChars(sLabel);
|
|
|
|
}
|
2015-11-13 17:00:03 +01:00
|
|
|
|
2016-03-21 12:05:30 +02:00
|
|
|
// Command can be just an alias to another command,
|
|
|
|
// so need to get the shortcut of the "real" command.
|
|
|
|
const OUString sRealCommand(GetRealCommandForCommand(rsCommandName, rxFrame));
|
|
|
|
const OUString sShortCut(GetCommandShortcut(!sRealCommand.isEmpty() ? sRealCommand : rsCommandName, rxFrame));
|
2016-02-26 10:36:34 +02:00
|
|
|
if (!sShortCut.isEmpty())
|
|
|
|
return sLabel + " (" + sShortCut + ")";
|
2015-11-13 17:00:03 +01:00
|
|
|
return sLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString CommandInfoProvider::GetCommandShortcut (const OUString& rsCommandName,
|
|
|
|
const Reference<frame::XFrame>& rxFrame)
|
|
|
|
{
|
|
|
|
SetFrame(rxFrame);
|
|
|
|
|
|
|
|
OUString sShortcut;
|
|
|
|
|
|
|
|
sShortcut = RetrieveShortcutsFromConfiguration(GetDocumentAcceleratorConfiguration(), rsCommandName);
|
|
|
|
if (sShortcut.getLength() > 0)
|
|
|
|
return sShortcut;
|
|
|
|
|
|
|
|
sShortcut = RetrieveShortcutsFromConfiguration(GetModuleAcceleratorConfiguration(), rsCommandName);
|
|
|
|
if (sShortcut.getLength() > 0)
|
|
|
|
return sShortcut;
|
|
|
|
|
|
|
|
sShortcut = RetrieveShortcutsFromConfiguration(GetGlobalAcceleratorConfiguration(), rsCommandName);
|
|
|
|
if (sShortcut.getLength() > 0)
|
|
|
|
return sShortcut;
|
|
|
|
|
|
|
|
return OUString();
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 12:47:43 +02:00
|
|
|
OUString CommandInfoProvider::GetRealCommandForCommand(const OUString& rCommandName,
|
|
|
|
const css::uno::Reference<frame::XFrame>& rxFrame)
|
|
|
|
{
|
|
|
|
SetFrame(rxFrame);
|
|
|
|
|
|
|
|
return GetCommandProperty("TargetURL", rCommandName);
|
|
|
|
}
|
|
|
|
|
2017-01-20 16:46:14 +00:00
|
|
|
BitmapEx CommandInfoProvider::GetBitmapForCommand(const OUString& rsCommandName,
|
|
|
|
const Reference<frame::XFrame>& rxFrame,
|
|
|
|
vcl::ImageType eImageType)
|
2015-11-16 15:41:27 +01:00
|
|
|
{
|
|
|
|
SetFrame(rxFrame);
|
|
|
|
|
|
|
|
if (rsCommandName.isEmpty())
|
2017-01-20 16:46:14 +00:00
|
|
|
return BitmapEx();
|
2015-11-16 15:41:27 +01:00
|
|
|
|
|
|
|
sal_Int16 nImageType(ui::ImageType::COLOR_NORMAL | ui::ImageType::SIZE_DEFAULT);
|
2016-10-30 16:24:37 +01:00
|
|
|
|
|
|
|
if (eImageType == vcl::ImageType::Size26)
|
2015-11-16 15:41:27 +01:00
|
|
|
nImageType |= ui::ImageType::SIZE_LARGE;
|
2016-10-30 16:24:37 +01:00
|
|
|
else if (eImageType == vcl::ImageType::Size32)
|
|
|
|
nImageType |= ui::ImageType::SIZE_32;
|
2015-11-16 15:41:27 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference<frame::XController> xController(rxFrame->getController());
|
|
|
|
Reference<frame::XModel> xModel(xController->getModel());
|
|
|
|
|
|
|
|
Reference<ui::XUIConfigurationManagerSupplier> xSupplier(xModel, UNO_QUERY);
|
|
|
|
if (xSupplier.is())
|
|
|
|
{
|
|
|
|
Reference<ui::XUIConfigurationManager> xDocUICfgMgr(xSupplier->getUIConfigurationManager(), UNO_QUERY);
|
|
|
|
Reference<ui::XImageManager> xDocImgMgr(xDocUICfgMgr->getImageManager(), UNO_QUERY);
|
|
|
|
|
|
|
|
Sequence< Reference<graphic::XGraphic> > aGraphicSeq;
|
|
|
|
Sequence<OUString> aImageCmdSeq { rsCommandName };
|
|
|
|
|
|
|
|
aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq );
|
|
|
|
Reference<graphic::XGraphic> xGraphic = aGraphicSeq[0];
|
2017-01-20 16:46:14 +00:00
|
|
|
const Graphic aGraphic(xGraphic);
|
|
|
|
BitmapEx aBitmap(aGraphic.GetBitmapEx());
|
2015-11-16 15:41:27 +01:00
|
|
|
|
2017-01-20 16:46:14 +00:00
|
|
|
if (!!aBitmap)
|
|
|
|
return aBitmap;
|
2015-11-16 15:41:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Reference<ui::XModuleUIConfigurationManagerSupplier> xModuleCfgMgrSupplier(ui::theModuleUIConfigurationManagerSupplier::get(mxContext));
|
|
|
|
Reference<ui::XUIConfigurationManager> xUICfgMgr(xModuleCfgMgrSupplier->getUIConfigurationManager(GetModuleIdentifier()));
|
|
|
|
|
|
|
|
Sequence< Reference<graphic::XGraphic> > aGraphicSeq;
|
|
|
|
Reference<ui::XImageManager> xModuleImageManager(xUICfgMgr->getImageManager(), UNO_QUERY);
|
|
|
|
|
|
|
|
Sequence<OUString> aImageCmdSeq { rsCommandName };
|
|
|
|
|
|
|
|
aGraphicSeq = xModuleImageManager->getImages(nImageType, aImageCmdSeq);
|
|
|
|
|
|
|
|
Reference<graphic::XGraphic> xGraphic(aGraphicSeq[0]);
|
|
|
|
|
2017-01-20 16:46:14 +00:00
|
|
|
const Graphic aGraphic(xGraphic);
|
|
|
|
|
|
|
|
return aGraphic.GetBitmapEx();
|
2015-11-16 15:41:27 +01:00
|
|
|
}
|
|
|
|
catch (Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-20 16:46:14 +00:00
|
|
|
return BitmapEx();
|
|
|
|
}
|
|
|
|
|
|
|
|
Image CommandInfoProvider::GetImageForCommand(const OUString& rsCommandName,
|
|
|
|
const Reference<frame::XFrame>& rxFrame,
|
|
|
|
vcl::ImageType eImageType)
|
|
|
|
{
|
|
|
|
return Image(GetBitmapForCommand(rsCommandName, rxFrame, eImageType));
|
2015-11-16 15:41:27 +01:00
|
|
|
}
|
|
|
|
|
2015-11-17 11:08:46 +01:00
|
|
|
sal_Int32 CommandInfoProvider::GetPropertiesForCommand (
|
|
|
|
const OUString& rsCommandName,
|
|
|
|
const Reference<frame::XFrame>& rxFrame)
|
|
|
|
{
|
|
|
|
SetFrame(rxFrame);
|
|
|
|
|
2015-11-17 15:47:25 +01:00
|
|
|
sal_Int32 nValue = 0;
|
2015-11-17 11:08:46 +01:00
|
|
|
const Sequence<beans::PropertyValue> aProperties (GetCommandProperties(rsCommandName));
|
|
|
|
for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex)
|
|
|
|
{
|
|
|
|
if (aProperties[nIndex].Name == "Properties")
|
|
|
|
{
|
|
|
|
aProperties[nIndex].Value >>= nValue;
|
2015-11-17 15:47:25 +01:00
|
|
|
break;
|
2015-11-17 11:08:46 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-17 15:47:25 +01:00
|
|
|
return nValue;
|
2015-11-17 11:08:46 +01:00
|
|
|
}
|
|
|
|
|
2015-12-04 17:05:11 +01:00
|
|
|
bool CommandInfoProvider::IsRotated(const OUString& rsCommandName)
|
|
|
|
{
|
|
|
|
return ResourceHasKey("private:resource/image/commandrotateimagelist", rsCommandName);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommandInfoProvider::IsMirrored(const OUString& rsCommandName)
|
|
|
|
{
|
|
|
|
return ResourceHasKey("private:resource/image/commandmirrorimagelist", rsCommandName);
|
|
|
|
}
|
|
|
|
|
2016-10-13 21:20:36 +02:00
|
|
|
bool CommandInfoProvider::IsExperimental(const OUString& rsCommandName,
|
|
|
|
const OUString& rModuleName)
|
|
|
|
{
|
|
|
|
Sequence<beans::PropertyValue> aProperties;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( rModuleName.getLength() > 0)
|
|
|
|
{
|
|
|
|
Reference<container::XNameAccess> xNameAccess = frame::theUICommandDescription::get(mxContext);
|
|
|
|
Reference<container::XNameAccess> xUICommandLabels;
|
|
|
|
if (xNameAccess->getByName( rModuleName ) >>= xUICommandLabels )
|
|
|
|
xUICommandLabels->getByName(rsCommandName) >>= aProperties;
|
|
|
|
|
|
|
|
for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex)
|
|
|
|
{
|
|
|
|
if (aProperties[nIndex].Name == "IsExperimental")
|
|
|
|
{
|
2016-10-17 15:12:03 +02:00
|
|
|
bool bValue;
|
|
|
|
return (aProperties[nIndex].Value >>= bValue) && bValue;
|
2016-10-13 21:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-19 08:51:45 +00:00
|
|
|
void CommandInfoProvider::SetFrame (const Reference<frame::XFrame>& rxFrame)
|
|
|
|
{
|
|
|
|
if (rxFrame != mxCachedDataFrame)
|
|
|
|
{
|
|
|
|
// Detach from the old frame.
|
|
|
|
if (mxFrameListener.is())
|
|
|
|
{
|
|
|
|
mxFrameListener->dispose();
|
2015-11-10 10:23:17 +01:00
|
|
|
mxFrameListener = nullptr;
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Release objects that are tied to the old frame.
|
2015-11-10 10:23:17 +01:00
|
|
|
mxCachedDocumentAcceleratorConfiguration = nullptr;
|
|
|
|
mxCachedModuleAcceleratorConfiguration = nullptr;
|
2014-11-12 14:24:10 +05:30
|
|
|
msCachedModuleIdentifier.clear();
|
2013-04-19 08:51:45 +00:00
|
|
|
mxCachedDataFrame = rxFrame;
|
|
|
|
|
|
|
|
// Connect to the new frame.
|
|
|
|
if (rxFrame.is())
|
|
|
|
mxFrameListener = new FrameListener(*this, rxFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-18 09:22:27 +02:00
|
|
|
Reference<ui::XAcceleratorConfiguration> const & CommandInfoProvider::GetDocumentAcceleratorConfiguration()
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
if ( ! mxCachedDocumentAcceleratorConfiguration.is())
|
|
|
|
{
|
|
|
|
// Get the accelerator configuration for the document.
|
|
|
|
if (mxCachedDataFrame.is())
|
|
|
|
{
|
|
|
|
Reference<frame::XController> xController = mxCachedDataFrame->getController();
|
|
|
|
if (xController.is())
|
|
|
|
{
|
|
|
|
Reference<frame::XModel> xModel (xController->getModel());
|
|
|
|
if (xModel.is())
|
|
|
|
{
|
|
|
|
Reference<ui::XUIConfigurationManagerSupplier> xSupplier (xModel, UNO_QUERY);
|
|
|
|
if (xSupplier.is())
|
|
|
|
{
|
|
|
|
Reference<ui::XUIConfigurationManager> xConfigurationManager(
|
|
|
|
xSupplier->getUIConfigurationManager(),
|
|
|
|
UNO_QUERY);
|
|
|
|
if (xConfigurationManager.is())
|
|
|
|
{
|
2013-05-27 14:52:39 +02:00
|
|
|
mxCachedDocumentAcceleratorConfiguration = xConfigurationManager->getShortCutManager();
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mxCachedDocumentAcceleratorConfiguration;
|
|
|
|
}
|
|
|
|
|
2016-07-18 09:22:27 +02:00
|
|
|
Reference<ui::XAcceleratorConfiguration> const & CommandInfoProvider::GetModuleAcceleratorConfiguration()
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
if ( ! mxCachedModuleAcceleratorConfiguration.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-01-29 18:58:18 +01:00
|
|
|
Reference<ui::XModuleUIConfigurationManagerSupplier> xSupplier = ui::theModuleUIConfigurationManagerSupplier::get(mxContext);
|
2013-04-19 08:51:45 +00:00
|
|
|
Reference<ui::XUIConfigurationManager> xManager (
|
|
|
|
xSupplier->getUIConfigurationManager(GetModuleIdentifier()));
|
|
|
|
if (xManager.is())
|
|
|
|
{
|
2013-05-27 14:52:39 +02:00
|
|
|
mxCachedModuleAcceleratorConfiguration = xManager->getShortCutManager();
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mxCachedModuleAcceleratorConfiguration;
|
|
|
|
}
|
|
|
|
|
2016-07-18 09:22:27 +02:00
|
|
|
Reference<ui::XAcceleratorConfiguration> const & CommandInfoProvider::GetGlobalAcceleratorConfiguration()
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
// Get the global accelerator configuration.
|
|
|
|
if ( ! mxCachedGlobalAcceleratorConfiguration.is())
|
|
|
|
{
|
2013-05-27 14:52:39 +02:00
|
|
|
mxCachedGlobalAcceleratorConfiguration = ui::GlobalAcceleratorConfiguration::create(mxContext);
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mxCachedGlobalAcceleratorConfiguration;
|
|
|
|
}
|
|
|
|
|
2016-07-18 09:22:27 +02:00
|
|
|
OUString const & CommandInfoProvider::GetModuleIdentifier()
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
if (msCachedModuleIdentifier.getLength() == 0)
|
|
|
|
{
|
2013-05-27 14:52:39 +02:00
|
|
|
Reference<frame::XModuleManager2> xModuleManager = frame::ModuleManager::create(mxContext);
|
|
|
|
msCachedModuleIdentifier = xModuleManager->identify(mxCachedDataFrame);
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
return msCachedModuleIdentifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString CommandInfoProvider::RetrieveShortcutsFromConfiguration(
|
|
|
|
const Reference<ui::XAcceleratorConfiguration>& rxConfiguration,
|
|
|
|
const OUString& rsCommandName)
|
|
|
|
{
|
|
|
|
if (rxConfiguration.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-11-15 12:17:19 +02:00
|
|
|
Sequence<OUString> aCommands { rsCommandName };
|
2013-04-19 08:51:45 +00:00
|
|
|
|
|
|
|
Sequence<Any> aKeyCodes (rxConfiguration->getPreferredKeyEventsForCommandList(aCommands));
|
|
|
|
if (aCommands.getLength() == 1)
|
|
|
|
{
|
2015-11-16 15:41:27 +01:00
|
|
|
awt::KeyEvent aKeyEvent;
|
2013-04-19 08:51:45 +00:00
|
|
|
if (aKeyCodes[0] >>= aKeyEvent)
|
|
|
|
{
|
2015-11-16 12:23:25 +01:00
|
|
|
return AWTKey2VCLKey(aKeyEvent).GetName();
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 15:41:27 +01:00
|
|
|
catch (css::lang::IllegalArgumentException&)
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OUString();
|
|
|
|
}
|
|
|
|
|
2015-12-04 17:05:11 +01:00
|
|
|
bool CommandInfoProvider::ResourceHasKey(const OUString& rsResourceName, const OUString& rsCommandName)
|
|
|
|
{
|
|
|
|
Sequence< OUString > aSequence;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const OUString sModuleIdentifier (GetModuleIdentifier());
|
|
|
|
if (!sModuleIdentifier.isEmpty())
|
|
|
|
{
|
|
|
|
Reference<container::XNameAccess> xNameAccess = frame::theUICommandDescription::get(mxContext);
|
|
|
|
Reference<container::XNameAccess> xUICommandLabels;
|
|
|
|
if (xNameAccess->getByName(sModuleIdentifier) >>= xUICommandLabels) {
|
|
|
|
xUICommandLabels->getByName(rsResourceName) >>= aSequence;
|
|
|
|
for ( sal_Int32 i = 0; i < aSequence.getLength(); i++ )
|
|
|
|
{
|
|
|
|
if (aSequence[i] == rsCommandName)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-13 17:00:03 +01:00
|
|
|
Sequence<beans::PropertyValue> CommandInfoProvider::GetCommandProperties(const OUString& rsCommandName)
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
Sequence<beans::PropertyValue> aProperties;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const OUString sModuleIdentifier (GetModuleIdentifier());
|
|
|
|
if (sModuleIdentifier.getLength() > 0)
|
|
|
|
{
|
2014-01-28 15:27:32 +01:00
|
|
|
Reference<container::XNameAccess> xNameAccess = frame::theUICommandDescription::get(mxContext);
|
2013-04-19 08:51:45 +00:00
|
|
|
Reference<container::XNameAccess> xUICommandLabels;
|
2013-05-27 14:52:39 +02:00
|
|
|
if (xNameAccess->getByName(sModuleIdentifier) >>= xUICommandLabels)
|
|
|
|
xUICommandLabels->getByName(rsCommandName) >>= aProperties;
|
2013-04-19 08:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return aProperties;
|
|
|
|
}
|
|
|
|
|
2015-11-13 17:00:03 +01:00
|
|
|
OUString CommandInfoProvider::GetCommandProperty(const OUString& rsProperty, const OUString& rsCommandName)
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
const Sequence<beans::PropertyValue> aProperties (GetCommandProperties(rsCommandName));
|
|
|
|
for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex)
|
|
|
|
{
|
2015-11-13 17:00:03 +01:00
|
|
|
if (aProperties[nIndex].Name == rsProperty)
|
2013-04-19 08:51:45 +00:00
|
|
|
{
|
|
|
|
OUString sLabel;
|
|
|
|
aProperties[nIndex].Value >>= sLabel;
|
|
|
|
return sLabel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OUString();
|
|
|
|
}
|
|
|
|
|
2016-04-15 13:38:17 +02:00
|
|
|
OUString CommandInfoProvider::GetCommandPropertyFromModule( const OUString& rCommandName, const OUString& rModuleName )
|
2016-03-05 01:48:55 +05:30
|
|
|
{
|
|
|
|
OUString sLabel;
|
2016-04-15 13:38:17 +02:00
|
|
|
if ( rCommandName.isEmpty() )
|
2016-03-05 01:48:55 +05:30
|
|
|
return sLabel;
|
|
|
|
|
|
|
|
Sequence<beans::PropertyValue> aProperties;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( rModuleName.getLength() > 0)
|
|
|
|
{
|
|
|
|
Reference<container::XNameAccess> xNameAccess = frame::theUICommandDescription::get(mxContext);
|
|
|
|
Reference<container::XNameAccess> xUICommandLabels;
|
|
|
|
if (xNameAccess->getByName( rModuleName ) >>= xUICommandLabels )
|
2016-04-15 13:38:17 +02:00
|
|
|
xUICommandLabels->getByName(rCommandName) >>= aProperties;
|
2016-03-05 01:48:55 +05:30
|
|
|
|
|
|
|
for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex)
|
|
|
|
{
|
|
|
|
if(aProperties[nIndex].Name == "Label")
|
|
|
|
{
|
|
|
|
aProperties[nIndex].Value >>= sLabel;
|
|
|
|
return sLabel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return OUString();
|
|
|
|
}
|
|
|
|
|
2015-11-16 15:41:27 +01:00
|
|
|
vcl::KeyCode CommandInfoProvider::AWTKey2VCLKey(const awt::KeyEvent& aAWTKey)
|
2015-11-16 12:23:25 +01:00
|
|
|
{
|
2015-11-16 15:41:27 +01:00
|
|
|
bool bShift = ((aAWTKey.Modifiers & awt::KeyModifier::SHIFT) == awt::KeyModifier::SHIFT );
|
|
|
|
bool bMod1 = ((aAWTKey.Modifiers & awt::KeyModifier::MOD1 ) == awt::KeyModifier::MOD1 );
|
|
|
|
bool bMod2 = ((aAWTKey.Modifiers & awt::KeyModifier::MOD2 ) == awt::KeyModifier::MOD2 );
|
|
|
|
bool bMod3 = ((aAWTKey.Modifiers & awt::KeyModifier::MOD3 ) == awt::KeyModifier::MOD3 );
|
2015-11-16 12:23:25 +01:00
|
|
|
sal_uInt16 nKey = (sal_uInt16)aAWTKey.KeyCode;
|
|
|
|
|
|
|
|
return vcl::KeyCode(nKey, bShift, bMod1, bMod2, bMod3);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // end of namespace vcl
|
2013-06-16 02:48:58 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|