summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2015-11-16 15:41:27 +0100
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2015-11-16 15:49:46 +0100
commitd8fc06d233f189341b3f9acc20253e371198e068 (patch)
tree763854ea14d181cd82244a7917849fee416e6ec8 /vcl
parent40fa83871e18bf7ff54f853e6b665f207ee8fb78 (diff)
Move functionality to retrieve command image to CommandInfoProvider
Change-Id: I79c22e0507c5eba8b5e28721de3279131aececc9
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/helper/commandinfoprovider.cxx79
-rw-r--r--vcl/source/window/builder.cxx74
-rw-r--r--vcl/source/window/toolbox2.cxx12
3 files changed, 72 insertions, 93 deletions
diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx
index 5d5ac771c08b..4eef99c1cb61 100644
--- a/vcl/source/helper/commandinfoprovider.cxx
+++ b/vcl/source/helper/commandinfoprovider.cxx
@@ -27,9 +27,10 @@
#include <com/sun/star/ui/GlobalAcceleratorConfiguration.hpp>
#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/ui/ImageType.hpp>
+#include <com/sun/star/ui/XImageManager.hpp>
#include <com/sun/star/awt/KeyModifier.hpp>
-
using namespace css;
using namespace css::uno;
@@ -61,7 +62,7 @@ namespace
mxFrame->removeEventListener(this);
}
virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
- throw (css::uno::RuntimeException, std::exception) override
+ throw (RuntimeException, std::exception) override
{
(void)rEvent;
mrInfoProvider.SetFrame(nullptr);
@@ -153,6 +154,66 @@ OUString CommandInfoProvider::GetCommandShortcut (const OUString& rsCommandName,
return OUString();
}
+Image CommandInfoProvider::GetImageForCommand(const OUString& rsCommandName, bool bLarge,
+ const Reference<frame::XFrame>& rxFrame)
+{
+ SetFrame(rxFrame);
+
+ if (rsCommandName.isEmpty())
+ return Image();
+
+ sal_Int16 nImageType(ui::ImageType::COLOR_NORMAL | ui::ImageType::SIZE_DEFAULT);
+ if (bLarge)
+ nImageType |= ui::ImageType::SIZE_LARGE;
+
+ 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];
+ Image aImage(xGraphic);
+
+ if (!!aImage)
+ return aImage;
+ }
+ }
+ 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]);
+
+ return Image(xGraphic);
+ }
+ catch (Exception&)
+ {
+ }
+
+ return Image();
+}
+
void CommandInfoProvider::SetFrame (const Reference<frame::XFrame>& rxFrame)
{
if (rxFrame != mxCachedDataFrame)
@@ -262,14 +323,14 @@ OUString CommandInfoProvider::RetrieveShortcutsFromConfiguration(
Sequence<Any> aKeyCodes (rxConfiguration->getPreferredKeyEventsForCommandList(aCommands));
if (aCommands.getLength() == 1)
{
- css::awt::KeyEvent aKeyEvent;
+ awt::KeyEvent aKeyEvent;
if (aKeyCodes[0] >>= aKeyEvent)
{
return AWTKey2VCLKey(aKeyEvent).GetName();
}
}
}
- catch (lang::IllegalArgumentException&)
+ catch (css::lang::IllegalArgumentException&)
{
}
}
@@ -313,12 +374,12 @@ OUString CommandInfoProvider::GetCommandProperty(const OUString& rsProperty, con
return OUString();
}
-vcl::KeyCode CommandInfoProvider::AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey)
+vcl::KeyCode CommandInfoProvider::AWTKey2VCLKey(const awt::KeyEvent& aAWTKey)
{
- bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT );
- bool bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 );
- bool bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 );
- bool bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 );
+ 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);
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 40036983126b..ad800893b75f 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -7,16 +7,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <com/sun/star/frame/ModuleManager.hpp>
-#include <com/sun/star/frame/XModuleManager2.hpp>
-#include <com/sun/star/frame/theUICommandDescription.hpp>
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
-#include <com/sun/star/ui/ImageType.hpp>
-#include <com/sun/star/ui/XImageManager.hpp>
-#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
-#include <com/sun/star/ui/XUIConfigurationManager.hpp>
-#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
-#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
#include <comphelper/processfactory.hxx>
#include <osl/module.hxx>
@@ -889,10 +880,6 @@ namespace
if (aCommand.isEmpty())
return;
- uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
- uno::Reference<frame::XModuleManager2> xModuleManager(frame::ModuleManager::create(xContext));
- OUString aModuleId(xModuleManager->identify(rFrame));
-
OUString aLabel(vcl::CommandInfoProvider::Instance().GetLabelForCommand(aCommand, rFrame));
if (!aLabel.isEmpty())
pButton->SetText(aLabel);
@@ -901,7 +888,7 @@ namespace
if (!aTooltip.isEmpty())
pButton->SetQuickHelpText(aTooltip);
- Image aImage(VclBuilder::getCommandImage(aCommand, /* bLarge = */ false, xContext, rFrame, aModuleId));
+ Image aImage(vcl::CommandInfoProvider::Instance().GetImageForCommand(aCommand, /*bLarge=*/ false, rFrame));
pButton->SetModeImage(aImage);
pButton->SetCommandHandler(aCommand);
@@ -2169,65 +2156,6 @@ void VclBuilder::reorderWithinParent(std::vector<vcl::Window*>& rChilds, bool bI
}
}
-Image VclBuilder::getCommandImage(const OUString& rCommand, bool bLarge,
- const uno::Reference<uno::XComponentContext>& rContext, const uno::Reference<frame::XFrame>& rFrame,
- const OUString& rModuleId)
-{
- if (rCommand.isEmpty())
- return Image();
-
- sal_Int16 nImageType(ui::ImageType::COLOR_NORMAL | ui::ImageType::SIZE_DEFAULT);
- if (bLarge)
- nImageType |= ui::ImageType::SIZE_LARGE;
-
- try
- {
- uno::Reference<frame::XController> xController(rFrame->getController());
- uno::Reference<frame::XModel> xModel(xController->getModel());
-
- uno::Reference<ui::XUIConfigurationManagerSupplier> xSupplier(xModel, uno::UNO_QUERY);
- if (xSupplier.is())
- {
- uno::Reference<ui::XUIConfigurationManager> xDocUICfgMgr(xSupplier->getUIConfigurationManager(), uno::UNO_QUERY);
- uno::Reference<ui::XImageManager> xDocImgMgr(xDocUICfgMgr->getImageManager(), uno::UNO_QUERY);
-
- uno::Sequence< uno::Reference<graphic::XGraphic> > aGraphicSeq;
- uno::Sequence<OUString> aImageCmdSeq { rCommand };
-
- aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq );
- uno::Reference<graphic::XGraphic> xGraphic = aGraphicSeq[0];
- Image aImage(xGraphic);
-
- if (!!aImage)
- return aImage;
- }
- }
- catch (uno::Exception&)
- {
- }
-
- try {
- uno::Reference<ui::XModuleUIConfigurationManagerSupplier> xModuleCfgMgrSupplier(ui::theModuleUIConfigurationManagerSupplier::get(rContext));
- uno::Reference<ui::XUIConfigurationManager> xUICfgMgr(xModuleCfgMgrSupplier->getUIConfigurationManager(rModuleId));
-
- uno::Sequence< uno::Reference<graphic::XGraphic> > aGraphicSeq;
- uno::Reference<ui::XImageManager> xModuleImageManager(xUICfgMgr->getImageManager(), uno::UNO_QUERY);
-
- uno::Sequence<OUString> aImageCmdSeq { rCommand };
-
- aGraphicSeq = xModuleImageManager->getImages(nImageType, aImageCmdSeq);
-
- uno::Reference<graphic::XGraphic> xGraphic(aGraphicSeq[0]);
-
- return Image(xGraphic);
- }
- catch (uno::Exception&)
- {
- }
-
- return Image();
-}
-
void VclBuilder::collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &rMap)
{
xmlreader::Span span;
diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx
index 5bb123aa4742..1de2f21de8d6 100644
--- a/vcl/source/window/toolbox2.cxx
+++ b/vcl/source/window/toolbox2.cxx
@@ -40,12 +40,6 @@
#include <unotools/confignode.hxx>
-#include <com/sun/star/frame/ModuleManager.hpp>
-#include <com/sun/star/frame/XController.hpp>
-#include <com/sun/star/frame/XModel.hpp>
-#include <com/sun/star/frame/XModuleManager2.hpp>
-#include <com/sun/star/lang/IllegalArgumentException.hpp>
-
using namespace vcl;
using namespace com::sun::star;
@@ -603,13 +597,9 @@ void ToolBox::InsertItem( sal_uInt16 nItemId, const OUString& rText,
void ToolBox::InsertItem(const OUString& rCommand, const uno::Reference<frame::XFrame>& rFrame, ToolBoxItemBits nBits, const Size& rRequestedSize, sal_uInt16 nPos)
{
- uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
- uno::Reference<frame::XModuleManager2> xModuleManager(frame::ModuleManager::create(xContext));
- OUString aModuleId(xModuleManager->identify(rFrame));
-
OUString aLabel(vcl::CommandInfoProvider::Instance().GetLabelForCommand(rCommand, rFrame));
OUString aTooltip(vcl::CommandInfoProvider::Instance().GetTooltipForCommand(rCommand, rFrame));
- Image aImage(VclBuilder::getCommandImage(rCommand, (GetToolboxButtonSize() == TOOLBOX_BUTTONSIZE_LARGE), xContext, rFrame, aModuleId));
+ Image aImage(vcl::CommandInfoProvider::Instance().GetImageForCommand(rCommand, (GetToolboxButtonSize() == TOOLBOX_BUTTONSIZE_LARGE), rFrame));
// let's invent an ItemId
const sal_uInt16 COMMAND_ITEMID_START = 30000;