1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
27 #include <vcl/gradient.hxx>
29 #include <com/sun/star/frame/XDispatchProvider.hpp>
30 #include <com/sun/star/frame/XFrame.hpp>
31 #include <com/sun/star/util/URLTransformer.hpp>
32 #include <com/sun/star/frame/ModuleManager.hpp>
33 #include <com/sun/star/graphic/GraphicProvider.hpp>
36 using namespace css::uno
;
38 namespace sfx2::sidebar
{
40 css::uno::Reference
<css::graphic::XGraphic
> Tools::GetImage(
41 const OUString
& rsImageURL
,
42 const OUString
& rsHighContrastImageURL
,
43 const Reference
<frame::XFrame
>& rxFrame
)
45 if (Theme::IsHighContrastMode())
46 return GetImage(rsHighContrastImageURL
, rxFrame
);
48 return GetImage(rsImageURL
, rxFrame
);
51 css::uno::Reference
<css::graphic::XGraphic
> Tools::GetImage(
52 const OUString
& rsURL
,
53 const Reference
<frame::XFrame
>& rxFrame
)
55 if (rsURL
.getLength() > 0)
57 if (rsURL
.startsWith(".uno:"))
58 return vcl::CommandInfoProvider::GetXGraphicForCommand(rsURL
, rxFrame
);
62 Reference
<uno::XComponentContext
> xContext(::comphelper::getProcessComponentContext());
63 Reference
<graphic::XGraphicProvider
> xProvider(graphic::GraphicProvider::create(xContext
));
64 ::comphelper::NamedValueCollection aMediaProperties
;
65 aMediaProperties
.put("URL", rsURL
);
66 return xProvider
->queryGraphic(aMediaProperties
.getPropertyValues());
72 util::URL
Tools::GetURL (const OUString
& rsCommand
)
75 aURL
.Complete
= rsCommand
;
77 const Reference
<XComponentContext
> xComponentContext (::comphelper::getProcessComponentContext());
78 const Reference
<util::XURLTransformer
> xParser
= util::URLTransformer::create( xComponentContext
);
79 xParser
->parseStrict(aURL
);
84 Reference
<frame::XDispatch
> Tools::GetDispatch (
85 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
86 const util::URL
& rURL
)
88 Reference
<frame::XDispatchProvider
> xProvider (rxFrame
, UNO_QUERY_THROW
);
89 Reference
<frame::XDispatch
> xDispatch (xProvider
->queryDispatch(rURL
, OUString(), 0));
93 OUString
Tools::GetModuleName (
94 const css::uno::Reference
<css::frame::XController
>& rxController
)
96 if (!rxController
.is())
101 const Reference
<XComponentContext
> xComponentContext (::comphelper::getProcessComponentContext());
102 const Reference
<frame::XModuleManager
> xModuleManager
= frame::ModuleManager::create( xComponentContext
);
103 return xModuleManager
->identify(rxController
);
105 catch (const Exception
&)
112 } // end of namespace sfx2::sidebar
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */