28#include <com/sun/star/frame/XFrame.hpp>
29#include <com/sun/star/frame/ModuleManager.hpp>
30#include <com/sun/star/frame/theUICommandDescription.hpp>
31#include <com/sun/star/ui/GlobalAcceleratorConfiguration.hpp>
32#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
33#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
34#include <com/sun/star/ui/ImageType.hpp>
35#include <com/sun/star/ui/XImageManager.hpp>
36#include <com/sun/star/awt/KeyModifier.hpp>
39using namespace css::uno;
45 static WeakReference<container::XNameAccess> xWeakRef;
46 css::uno::Reference<container::XNameAccess> xRef(xWeakRef);
59 static WeakReference<ui::XModuleUIConfigurationManagerSupplier> xWeakRef;
60 css::uno::Reference<ui::XModuleUIConfigurationManagerSupplier> xRef(xWeakRef);
73 static WeakReference<ui::XAcceleratorConfiguration> xWeakRef;
74 css::uno::Reference<ui::XAcceleratorConfiguration> xRef(xWeakRef);
87 Reference<frame::XController>
xController = rxFrame->getController();
90 Reference<ui::XUIConfigurationManagerSupplier> xSupplier(
xController->getModel(), UNO_QUERY);
93 Reference<ui::XUIConfigurationManager> xConfigurationManager(
94 xSupplier->getUIConfigurationManager());
95 if (xConfigurationManager.is())
97 return xConfigurationManager->getShortCutManager();
106 css::uno::Reference<css::ui::XAcceleratorConfiguration> curModuleAcceleratorConfiguration;
110 Reference<ui::XUIConfigurationManager> xManager (
114 curModuleAcceleratorConfiguration = xManager->getShortCutManager();
120 return curModuleAcceleratorConfiguration;
125 bool bShift = ((aAWTKey.Modifiers & awt::KeyModifier::SHIFT) == awt::KeyModifier::SHIFT );
126 bool bMod1 = ((aAWTKey.Modifiers & awt::KeyModifier::MOD1 ) == awt::KeyModifier::MOD1 );
127 bool bMod2 = ((aAWTKey.Modifiers & awt::KeyModifier::MOD2 ) == awt::KeyModifier::MOD2 );
128 bool bMod3 = ((aAWTKey.Modifiers & awt::KeyModifier::MOD3 ) == awt::KeyModifier::MOD3 );
129 sal_uInt16 nKey =
static_cast<sal_uInt16
>(aAWTKey.KeyCode);
135 const Reference<ui::XAcceleratorConfiguration>& rxConfiguration,
136 const OUString& rsCommandName)
138 if (rxConfiguration.is())
142 Sequence<OUString> aCommands { rsCommandName };
144 Sequence<Any> aKeyCodes (rxConfiguration->getPreferredKeyEventsForCommandList(aCommands));
145 if (aCommands.getLength() == 1)
147 awt::KeyEvent aKeyEvent;
148 if (aKeyCodes[0] >>= aKeyEvent)
154 catch (css::lang::IllegalArgumentException&)
162 const Reference<ui::XAcceleratorConfiguration>& rxConfiguration,
163 const OUString& rsCommandName)
165 if (rxConfiguration.is())
169 Sequence<OUString> aCommands { rsCommandName };
171 Sequence<Any> aKeyCodes (rxConfiguration->getPreferredKeyEventsForCommandList(aCommands));
172 if (aCommands.getLength() == 1)
174 awt::KeyEvent aKeyEvent;
175 if (aKeyCodes[0] >>= aKeyEvent)
181 catch (css::lang::IllegalArgumentException&)
188static bool ResourceHasKey(
const OUString& rsResourceName,
const OUString& rsCommandName,
const OUString& rsModuleName)
190 Sequence< OUString > aSequence;
193 if (!rsModuleName.isEmpty())
196 Reference<container::XNameAccess> xUICommandLabels;
197 if (xNameAccess->getByName(rsModuleName) >>= xUICommandLabels)
199 xUICommandLabels->getByName(rsResourceName) >>= aSequence;
211Sequence<beans::PropertyValue>
GetCommandProperties(
const OUString& rsCommandName,
const OUString& rsModuleName)
217 if (!rsModuleName.isEmpty())
220 Reference<container::XNameAccess> xUICommandLabels;
221 if ((xNameAccess->getByName(rsModuleName) >>= xUICommandLabels) && xUICommandLabels->hasByName(rsCommandName))
222 xUICommandLabels->getByName(rsCommandName) >>=
aProperties;
232static OUString
GetCommandProperty(
const OUString& rsProperty,
const Sequence<beans::PropertyValue> &rProperties)
234 auto pProp = std::find_if(rProperties.begin(), rProperties.end(),
235 [&rsProperty](
const beans::PropertyValue& rProp) { return rProp.Name == rsProperty; });
236 if (pProp != rProperties.end())
239 pProp->Value >>= sLabel;
260 if (!sPopupLabel.isEmpty())
268 if (!sLabel.isEmpty())
274 const OUString& rsCommandName,
275 const css::uno::Sequence<css::beans::PropertyValue>& rProperties,
276 const Reference<frame::XFrame>& rxFrame)
279 if (sLabel.isEmpty()) {
289 const OUString sShortCut(
GetCommandShortcut(!sRealCommand.isEmpty() ? sRealCommand : rsCommandName, rxFrame));
290 if (!sShortCut.isEmpty())
291 return sLabel +
" (" + sShortCut +
")";
296 const Reference<frame::XFrame>& rxFrame)
302 if (sShortcut.getLength() > 0)
306 if (sShortcut.getLength() > 0)
310 if (sShortcut.getLength() > 0)
321 if (aKeyCodeShortcut.
GetCode())
322 return aKeyCodeShortcut;
325 if (aKeyCodeShortcut.
GetCode())
326 return aKeyCodeShortcut;
329 if (aKeyCodeShortcut.
GetCode())
330 return aKeyCodeShortcut;
341 const Reference<frame::XFrame>& rxFrame,
344 if (rsCommandName.isEmpty())
347 sal_Int16 nImageType(ui::ImageType::COLOR_NORMAL | ui::ImageType::SIZE_DEFAULT);
350 nImageType |= ui::ImageType::SIZE_LARGE;
352 nImageType |= ui::ImageType::SIZE_32;
356 Reference<frame::XController>
xController(rxFrame->getController(), UNO_SET_THROW);
357 Reference<ui::XUIConfigurationManagerSupplier> xSupplier(
xController->getModel(), UNO_QUERY);
360 Reference<ui::XUIConfigurationManager> xDocUICfgMgr(xSupplier->getUIConfigurationManager());
361 Reference<ui::XImageManager> xDocImgMgr(xDocUICfgMgr->getImageManager(), UNO_QUERY);
363 Sequence<OUString> aImageCmdSeq { rsCommandName };
365 Sequence<Reference<graphic::XGraphic>> aGraphicSeq = xDocImgMgr->getImages(nImageType, aImageCmdSeq);
366 Reference<graphic::XGraphic> xGraphic = aGraphicSeq[0];
378 Reference<ui::XUIConfigurationManager> xUICfgMgr(xModuleCfgMgrSupplier->getUIConfigurationManager(
GetModuleIdentifier(rxFrame)));
379 Reference<ui::XImageManager> xModuleImageManager(xUICfgMgr->getImageManager(), UNO_QUERY);
381 Sequence<OUString> aImageCmdSeq { rsCommandName };
383 Sequence<Reference<graphic::XGraphic>> aGraphicSeq = xModuleImageManager->getImages(nImageType, aImageCmdSeq);
384 Reference<graphic::XGraphic> xGraphic(aGraphicSeq[0]);
396 const Reference<frame::XFrame>& rxFrame,
403 const OUString& rsCommandName,
404 const OUString& rsModuleName)
410 [](
const beans::PropertyValue& rProp) { return rProp.Name ==
"Properties"; });
417bool IsRotated(
const OUString& rsCommandName,
const OUString& rsModuleName)
419 return ResourceHasKey(
"private:resource/image/commandrotateimagelist", rsCommandName, rsModuleName);
422bool IsMirrored(
const OUString& rsCommandName,
const OUString& rsModuleName)
424 return ResourceHasKey(
"private:resource/image/commandmirrorimagelist", rsCommandName, rsModuleName);
432 if( rModuleName.getLength() > 0)
435 Reference<container::XNameAccess> xUICommandLabels;
436 if (xNameAccess->getByName( rModuleName ) >>= xUICommandLabels )
437 xUICommandLabels->getByName(rsCommandName) >>=
aProperties;
440 [](
const beans::PropertyValue& rProp) {
return rProp.Name ==
"IsExperimental"; });
444 return (pProp->Value >>= bValue) && bValue;
456 static WeakReference<frame::XModuleManager2> xWeakRef;
457 css::uno::Reference<frame::XModuleManager2> xRef(xWeakRef);
467 return xRef->identify(rxFrame);
PropertiesInfo aProperties
static OUString EraseAllMnemonicChars(const OUString &rStr)
sal_uInt16 GetCode() const
OString stripEnd(const OString &rIn, char c)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
Reference< XComponentContext > getProcessComponentContext()
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
Return a label for the given command.
static bool ResourceHasKey(const OUString &rsResourceName, const OUString &rsCommandName, const OUString &rsModuleName)
bool IsRotated(const OUString &rsCommandName, const OUString &rsModuleName)
OUString GetTooltipForCommand(const OUString &rsCommandName, const css::uno::Sequence< css::beans::PropertyValue > &rProperties, const Reference< frame::XFrame > &rxFrame)
OUString GetRealCommandForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Reference< graphic::XGraphic > GetXGraphicForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
OUString GetCommandShortcut(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame)
static Reference< ui::XAcceleratorConfiguration > GetGlobalAcceleratorConfiguration()
static vcl::KeyCode AWTKey2VCLKey(const awt::KeyEvent &aAWTKey)
static OUString RetrieveShortcutsFromConfiguration(const Reference< ui::XAcceleratorConfiguration > &rxConfiguration, const OUString &rsCommandName)
sal_Int32 GetPropertiesForCommand(const OUString &rsCommandName, const OUString &rsModuleName)
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
OUString GetPopupLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
static OUString GetCommandProperty(const OUString &rsProperty, const Sequence< beans::PropertyValue > &rProperties)
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
OUString GetLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Return a label for the given command.
static Reference< container::XNameAccess > GetCommandDescription()
bool IsMirrored(const OUString &rsCommandName, const OUString &rsModuleName)
bool IsExperimental(const OUString &rsCommandName, const OUString &rModuleName)
Returns whether the command is experimental.
static Reference< ui::XAcceleratorConfiguration > GetModuleAcceleratorConfiguration(const Reference< frame::XFrame > &rxFrame)
vcl::KeyCode GetCommandKeyCodeShortcut(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame)
static vcl::KeyCode RetrieveKeyCodeShortcutsFromConfiguration(const Reference< ui::XAcceleratorConfiguration > &rxConfiguration, const OUString &rsCommandName)
OUString GetTooltipLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
static Reference< ui::XAcceleratorConfiguration > GetDocumentAcceleratorConfiguration(const Reference< frame::XFrame > &rxFrame)
static Reference< ui::XModuleUIConfigurationManagerSupplier > GetModuleConfigurationSupplier()
OUString GetMenuLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Reference< XController > xController