tdf#150622 sidebar icons empty in High Contrast mode
[LibreOffice.git] / sfx2 / source / sidebar / Tools.cxx
blob727e85a4fac03a209e0cac7d5381df66b5cf5576
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sidebar/Tools.hxx>
22 #include <sfx2/sidebar/Theme.hxx>
24 #include <comphelper/namedvaluecollection.hxx>
25 #include <comphelper/processfactory.hxx>
26 #include <vcl/commandinfoprovider.hxx>
28 #include <com/sun/star/frame/XDispatchProvider.hpp>
29 #include <com/sun/star/frame/XFrame.hpp>
30 #include <com/sun/star/util/URLTransformer.hpp>
31 #include <com/sun/star/frame/ModuleManager.hpp>
32 #include <com/sun/star/graphic/GraphicProvider.hpp>
34 using namespace css;
35 using namespace css::uno;
37 namespace sfx2::sidebar {
39 css::uno::Reference<css::graphic::XGraphic> Tools::GetImage(
40 const OUString& rsImageURL,
41 const OUString& rsHighContrastImageURL,
42 const Reference<frame::XFrame>& rxFrame)
44 if (Theme::IsHighContrastMode() && !rsHighContrastImageURL.isEmpty())
45 return GetImage(rsHighContrastImageURL, rxFrame);
46 else
47 return GetImage(rsImageURL, rxFrame);
50 css::uno::Reference<css::graphic::XGraphic> Tools::GetImage(
51 const OUString& rsURL,
52 const Reference<frame::XFrame>& rxFrame)
54 if (rsURL.getLength() > 0)
56 if (rsURL.startsWith(".uno:"))
57 return vcl::CommandInfoProvider::GetXGraphicForCommand(rsURL, rxFrame);
59 else
61 Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext());
62 Reference<graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext));
63 ::comphelper::NamedValueCollection aMediaProperties;
64 aMediaProperties.put("URL", rsURL);
65 return xProvider->queryGraphic(aMediaProperties.getPropertyValues());
68 return nullptr;
71 util::URL Tools::GetURL (const OUString& rsCommand)
73 util::URL aURL;
74 aURL.Complete = rsCommand;
76 const Reference<XComponentContext> xComponentContext (::comphelper::getProcessComponentContext());
77 const Reference<util::XURLTransformer> xParser = util::URLTransformer::create( xComponentContext );
78 xParser->parseStrict(aURL);
80 return aURL;
83 Reference<frame::XDispatch> Tools::GetDispatch (
84 const css::uno::Reference<css::frame::XFrame>& rxFrame,
85 const util::URL& rURL)
87 Reference<frame::XDispatchProvider> xProvider (rxFrame, UNO_QUERY_THROW);
88 Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(rURL, OUString(), 0));
89 return xDispatch;
92 OUString Tools::GetModuleName (
93 const css::uno::Reference<css::frame::XController>& rxController)
95 if (!rxController.is())
96 return OUString();
98 try
100 const Reference<XComponentContext> xComponentContext (::comphelper::getProcessComponentContext());
101 const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xComponentContext );
102 return xModuleManager->identify(rxController);
104 catch (const Exception&)
106 // Ignored.
108 return OUString();
111 } // end of namespace sfx2::sidebar
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */