From 096637c9570654437e9f5e12a614fdcefc23ae3a Mon Sep 17 00:00:00 2001 From: Maxim Monastirsky Date: Fri, 17 Feb 2017 11:11:44 +0200 Subject: CommandInfoProvider can be a namespace Change-Id: I8b56423724360f49e1f361cb95056b391a9a3a42 --- vcl/source/helper/commandinfoprovider.cxx | 337 +++++++++++++++--------------- 1 file changed, 163 insertions(+), 174 deletions(-) (limited to 'vcl/source/helper') diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx index 7ba86900caf4..4b5b2b424b6c 100644 --- a/vcl/source/helper/commandinfoprovider.cxx +++ b/vcl/source/helper/commandinfoprovider.cxx @@ -18,11 +18,10 @@ */ #include +#include #include #include #include -#include -#include #include #include @@ -33,21 +32,163 @@ #include #include -#include "svdata.hxx" - using namespace css; using namespace css::uno; +namespace vcl { namespace CommandInfoProvider { + +Reference const GetDocumentAcceleratorConfiguration(const Reference& rxFrame) +{ + Reference xController = rxFrame->getController(); + if (xController.is()) + { + Reference xModel (xController->getModel()); + if (xModel.is()) + { + Reference xSupplier (xModel, UNO_QUERY); + if (xSupplier.is()) + { + Reference xConfigurationManager( + xSupplier->getUIConfigurationManager(), + UNO_QUERY); + if (xConfigurationManager.is()) + { + return xConfigurationManager->getShortCutManager(); + } + } + } + } + return nullptr; +} + +Reference const GetModuleAcceleratorConfiguration(const Reference& rxFrame) +{ + css::uno::Reference curModuleAcceleratorConfiguration; + try + { + Reference xSupplier = ui::theModuleUIConfigurationManagerSupplier::get(comphelper::getProcessComponentContext()); + Reference xManager ( + xSupplier->getUIConfigurationManager(GetModuleIdentifier(rxFrame))); + if (xManager.is()) + { + curModuleAcceleratorConfiguration = xManager->getShortCutManager(); + } + } + catch (Exception&) + { + } + return curModuleAcceleratorConfiguration; +} + +Reference const GetGlobalAcceleratorConfiguration() +{ + // Get the global accelerator configuration. + return ui::GlobalAcceleratorConfiguration::create(comphelper::getProcessComponentContext()); + +} + +vcl::KeyCode AWTKey2VCLKey(const awt::KeyEvent& aAWTKey) +{ + 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 ); + sal_uInt16 nKey = (sal_uInt16)aAWTKey.KeyCode; + + return vcl::KeyCode(nKey, bShift, bMod1, bMod2, bMod3); +} + +OUString RetrieveShortcutsFromConfiguration( + const Reference& rxConfiguration, + const OUString& rsCommandName) +{ + if (rxConfiguration.is()) + { + try + { + Sequence aCommands { rsCommandName }; + + Sequence aKeyCodes (rxConfiguration->getPreferredKeyEventsForCommandList(aCommands)); + if (aCommands.getLength() == 1) + { + awt::KeyEvent aKeyEvent; + if (aKeyCodes[0] >>= aKeyEvent) + { + return AWTKey2VCLKey(aKeyEvent).GetName(); + } + } + } + catch (css::lang::IllegalArgumentException&) + { + } + } + return OUString(); +} + +bool ResourceHasKey(const OUString& rsResourceName, const OUString& rsCommandName, const Reference& rxFrame) +{ + Sequence< OUString > aSequence; + try + { + const OUString sModuleIdentifier (GetModuleIdentifier(rxFrame)); + if (!sModuleIdentifier.isEmpty()) + { + Reference xNameAccess = frame::theUICommandDescription::get(comphelper::getProcessComponentContext()); + Reference 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; +} -namespace vcl { +Sequence GetCommandProperties(const OUString& rsCommandName, const Reference& rxFrame) +{ + Sequence aProperties; -CommandInfoProvider::CommandInfoProvider() { } + try + { + const OUString sModuleIdentifier (GetModuleIdentifier(rxFrame)); + if (sModuleIdentifier.getLength() > 0) + { + Reference xNameAccess = frame::theUICommandDescription::get(comphelper::getProcessComponentContext()); + Reference xUICommandLabels; + if (xNameAccess->getByName(sModuleIdentifier) >>= xUICommandLabels) + xUICommandLabels->getByName(rsCommandName) >>= aProperties; + } + } + catch (Exception&) + { + } -CommandInfoProvider::~CommandInfoProvider() + return aProperties; +} + +OUString GetCommandProperty(const OUString& rsProperty, const OUString& rsCommandName, const Reference& rxFrame) { + const Sequence aProperties (GetCommandProperties(rsCommandName, rxFrame)); + for (sal_Int32 nIndex=0; nIndex>= sLabel; + return sLabel; + } + } + return OUString(); } -OUString CommandInfoProvider::GetLabelForCommand ( +OUString GetLabelForCommand ( const OUString& rsCommandName, const Reference& rxFrame) { @@ -55,7 +196,7 @@ OUString CommandInfoProvider::GetLabelForCommand ( return GetCommandProperty("Name", rsCommandName, rxFrame); } -OUString CommandInfoProvider::GetMenuLabelForCommand ( +OUString GetMenuLabelForCommand ( const OUString& rsCommandName, const Reference& rxFrame) { @@ -65,7 +206,7 @@ OUString CommandInfoProvider::GetMenuLabelForCommand ( return GetCommandProperty("Label", rsCommandName, rxFrame); } -OUString CommandInfoProvider::GetPopupLabelForCommand ( +OUString GetPopupLabelForCommand ( const OUString& rsCommandName, const css::uno::Reference& rxFrame) { @@ -76,7 +217,7 @@ OUString CommandInfoProvider::GetPopupLabelForCommand ( return GetCommandProperty("Label", rsCommandName, rxFrame); } -OUString CommandInfoProvider::GetTooltipForCommand ( +OUString GetTooltipForCommand ( const OUString& rsCommandName, const Reference& rxFrame) { @@ -98,7 +239,7 @@ OUString CommandInfoProvider::GetTooltipForCommand ( return sLabel; } -OUString CommandInfoProvider::GetCommandShortcut (const OUString& rsCommandName, +OUString GetCommandShortcut (const OUString& rsCommandName, const Reference& rxFrame) { @@ -119,14 +260,14 @@ OUString CommandInfoProvider::GetCommandShortcut (const OUString& rsCommandName, return OUString(); } -OUString CommandInfoProvider::GetRealCommandForCommand(const OUString& rCommandName, +OUString GetRealCommandForCommand(const OUString& rCommandName, const css::uno::Reference& rxFrame) { return GetCommandProperty("TargetURL", rCommandName, rxFrame); } -BitmapEx CommandInfoProvider::GetBitmapForCommand(const OUString& rsCommandName, +BitmapEx GetBitmapForCommand(const OUString& rsCommandName, const Reference& rxFrame, vcl::ImageType eImageType) { @@ -192,14 +333,14 @@ BitmapEx CommandInfoProvider::GetBitmapForCommand(const OUString& rsCommandName, return BitmapEx(); } -Image CommandInfoProvider::GetImageForCommand(const OUString& rsCommandName, +Image GetImageForCommand(const OUString& rsCommandName, const Reference& rxFrame, vcl::ImageType eImageType) { return Image(GetBitmapForCommand(rsCommandName, rxFrame, eImageType)); } -sal_Int32 CommandInfoProvider::GetPropertiesForCommand ( +sal_Int32 GetPropertiesForCommand ( const OUString& rsCommandName, const Reference& rxFrame) { @@ -217,17 +358,17 @@ sal_Int32 CommandInfoProvider::GetPropertiesForCommand ( return nValue; } -bool CommandInfoProvider::IsRotated(const OUString& rsCommandName, const Reference& rxFrame) +bool IsRotated(const OUString& rsCommandName, const Reference& rxFrame) { return ResourceHasKey("private:resource/image/commandrotateimagelist", rsCommandName, rxFrame); } -bool CommandInfoProvider::IsMirrored(const OUString& rsCommandName, const Reference& rxFrame) +bool IsMirrored(const OUString& rsCommandName, const Reference& rxFrame) { return ResourceHasKey("private:resource/image/commandmirrorimagelist", rsCommandName, rxFrame); } -bool CommandInfoProvider::IsExperimental(const OUString& rsCommandName, +bool IsExperimental(const OUString& rsCommandName, const OUString& rModuleName) { Sequence aProperties; @@ -256,153 +397,13 @@ bool CommandInfoProvider::IsExperimental(const OUString& rsCommandName, return false; } -Reference const CommandInfoProvider::GetDocumentAcceleratorConfiguration(const Reference& rxFrame) -{ - Reference xController = rxFrame->getController(); - if (xController.is()) - { - Reference xModel (xController->getModel()); - if (xModel.is()) - { - Reference xSupplier (xModel, UNO_QUERY); - if (xSupplier.is()) - { - Reference xConfigurationManager( - xSupplier->getUIConfigurationManager(), - UNO_QUERY); - if (xConfigurationManager.is()) - { - return xConfigurationManager->getShortCutManager(); - } - } - } - } - return nullptr; -} - -Reference const CommandInfoProvider::GetModuleAcceleratorConfiguration(const Reference& rxFrame) -{ - css::uno::Reference curModuleAcceleratorConfiguration; - try - { - Reference xSupplier = ui::theModuleUIConfigurationManagerSupplier::get(comphelper::getProcessComponentContext()); - Reference xManager ( - xSupplier->getUIConfigurationManager(GetModuleIdentifier(rxFrame))); - if (xManager.is()) - { - curModuleAcceleratorConfiguration = xManager->getShortCutManager(); - } - } - catch (Exception&) - { - } - return curModuleAcceleratorConfiguration; -} - -Reference const CommandInfoProvider::GetGlobalAcceleratorConfiguration() -{ - // Get the global accelerator configuration. - return ui::GlobalAcceleratorConfiguration::create(comphelper::getProcessComponentContext()); - -} - -OUString const CommandInfoProvider::GetModuleIdentifier(const Reference& rxFrame) +OUString const GetModuleIdentifier(const Reference& rxFrame) { Reference xModuleManager = frame::ModuleManager::create(comphelper::getProcessComponentContext()); return xModuleManager->identify(rxFrame); } -OUString CommandInfoProvider::RetrieveShortcutsFromConfiguration( - const Reference& rxConfiguration, - const OUString& rsCommandName) -{ - if (rxConfiguration.is()) - { - try - { - Sequence aCommands { rsCommandName }; - - Sequence aKeyCodes (rxConfiguration->getPreferredKeyEventsForCommandList(aCommands)); - if (aCommands.getLength() == 1) - { - awt::KeyEvent aKeyEvent; - if (aKeyCodes[0] >>= aKeyEvent) - { - return AWTKey2VCLKey(aKeyEvent).GetName(); - } - } - } - catch (css::lang::IllegalArgumentException&) - { - } - } - return OUString(); -} - -bool CommandInfoProvider::ResourceHasKey(const OUString& rsResourceName, const OUString& rsCommandName, const Reference& rxFrame) -{ - Sequence< OUString > aSequence; - try - { - const OUString sModuleIdentifier (GetModuleIdentifier(rxFrame)); - if (!sModuleIdentifier.isEmpty()) - { - Reference xNameAccess = frame::theUICommandDescription::get(comphelper::getProcessComponentContext()); - Reference 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; -} - -Sequence CommandInfoProvider::GetCommandProperties(const OUString& rsCommandName, const Reference& rxFrame) -{ - Sequence aProperties; - - try - { - const OUString sModuleIdentifier (GetModuleIdentifier(rxFrame)); - if (sModuleIdentifier.getLength() > 0) - { - Reference xNameAccess = frame::theUICommandDescription::get(comphelper::getProcessComponentContext()); - Reference xUICommandLabels; - if (xNameAccess->getByName(sModuleIdentifier) >>= xUICommandLabels) - xUICommandLabels->getByName(rsCommandName) >>= aProperties; - } - } - catch (Exception&) - { - } - - return aProperties; -} - -OUString CommandInfoProvider::GetCommandProperty(const OUString& rsProperty, const OUString& rsCommandName, const Reference& rxFrame) -{ - const Sequence aProperties (GetCommandProperties(rsCommandName, rxFrame)); - for (sal_Int32 nIndex=0; nIndex>= sLabel; - return sLabel; - } - } - return OUString(); -} - -OUString CommandInfoProvider::GetCommandPropertyFromModule( const OUString& rCommandName, const OUString& rModuleName ) +OUString GetCommandPropertyFromModule( const OUString& rCommandName, const OUString& rModuleName ) { OUString sLabel; if ( rCommandName.isEmpty() ) @@ -434,18 +435,6 @@ OUString CommandInfoProvider::GetCommandPropertyFromModule( const OUString& rCom return OUString(); } -vcl::KeyCode CommandInfoProvider::AWTKey2VCLKey(const awt::KeyEvent& aAWTKey) -{ - 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 ); - sal_uInt16 nKey = (sal_uInt16)aAWTKey.KeyCode; - - return vcl::KeyCode(nKey, bShift, bMod1, bMod2, bMod3); -} - - -} // end of namespace vcl +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit