[Libreoffice-commits] core.git: include/vcl vcl/source

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Mon Nov 16 06:50:22 PST 2015


 include/vcl/commandinfoprovider.hxx       |    8 ++-
 vcl/source/helper/commandinfoprovider.cxx |   79 ++++++++++++++++++++++++++----
 vcl/source/window/builder.cxx             |   74 ----------------------------
 vcl/source/window/toolbox2.cxx            |   12 ----
 4 files changed, 79 insertions(+), 94 deletions(-)

New commits:
commit d8fc06d233f189341b3f9acc20253e371198e068
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Mon Nov 16 15:41:27 2015 +0100

    Move functionality to retrieve command image to CommandInfoProvider
    
    Change-Id: I79c22e0507c5eba8b5e28721de3279131aececc9

diff --git a/include/vcl/commandinfoprovider.hxx b/include/vcl/commandinfoprovider.hxx
index 91d98b7..0dc69f8 100644
--- a/include/vcl/commandinfoprovider.hxx
+++ b/include/vcl/commandinfoprovider.hxx
@@ -21,6 +21,7 @@
 
 #include <vcl/dllapi.h>
 #include <vcl/keycod.hxx>
+#include <vcl/image.hxx>
 
 #include <com/sun/star/frame/XFrame.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
@@ -76,7 +77,12 @@ public:
 
     /** Returns the shortcut for a command in human-readable form */
     OUString GetCommandShortcut (const OUString& rCommandName,
-                                        const css::uno::Reference<css::frame::XFrame>& rxFrame);
+                                 const css::uno::Reference<css::frame::XFrame>& rxFrame);
+
+    Image GetImageForCommand(
+        const OUString& rsCommandName,
+        bool bLarge,
+        const css::uno::Reference<css::frame::XFrame>& rxFrame);
 
     /** Do not call.  Should be part of a local and hidden interface.
     */
diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx
index 5d5ac77..4eef99c 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 4003698..ad80089 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 5bb123a..1de2f21 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;


More information about the Libreoffice-commits mailing list