/src/libreoffice/sfx2/source/sidebar/Tools.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <sidebar/Tools.hxx> |
21 | | |
22 | | #include <sfx2/sidebar/Theme.hxx> |
23 | | |
24 | | #include <comphelper/namedvaluecollection.hxx> |
25 | | #include <comphelper/processfactory.hxx> |
26 | | #include <vcl/commandinfoprovider.hxx> |
27 | | |
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> |
33 | | |
34 | | using namespace css; |
35 | | using namespace css::uno; |
36 | | |
37 | | namespace sfx2::sidebar { |
38 | | |
39 | | css::uno::Reference<css::graphic::XGraphic> Tools::GetImage( |
40 | | const OUString& rsImageURL, |
41 | | const OUString& rsHighContrastImageURL, |
42 | | const Reference<frame::XFrame>& rxFrame) |
43 | 0 | { |
44 | 0 | if (Theme::IsHighContrastMode() && !rsHighContrastImageURL.isEmpty()) |
45 | 0 | return GetImage(rsHighContrastImageURL, rxFrame); |
46 | 0 | else |
47 | 0 | return GetImage(rsImageURL, rxFrame); |
48 | 0 | } |
49 | | |
50 | | css::uno::Reference<css::graphic::XGraphic> Tools::GetImage( |
51 | | const OUString& rsURL, |
52 | | const Reference<frame::XFrame>& rxFrame) |
53 | 0 | { |
54 | 0 | if (rsURL.getLength() > 0) |
55 | 0 | { |
56 | 0 | if (rsURL.startsWith(".uno:")) |
57 | 0 | return vcl::CommandInfoProvider::GetXGraphicForCommand(rsURL, rxFrame); |
58 | | |
59 | 0 | else |
60 | 0 | { |
61 | 0 | const Reference<uno::XComponentContext>& xContext(::comphelper::getProcessComponentContext()); |
62 | 0 | Reference<graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext)); |
63 | 0 | ::comphelper::NamedValueCollection aMediaProperties; |
64 | 0 | aMediaProperties.put(u"URL"_ustr, rsURL); |
65 | 0 | return xProvider->queryGraphic(aMediaProperties.getPropertyValues()); |
66 | 0 | } |
67 | 0 | } |
68 | 0 | return nullptr; |
69 | 0 | } |
70 | | |
71 | | util::URL Tools::GetURL (const OUString& rsCommand) |
72 | 0 | { |
73 | 0 | util::URL aURL; |
74 | 0 | aURL.Complete = rsCommand; |
75 | |
|
76 | 0 | const Reference<XComponentContext>& xComponentContext (::comphelper::getProcessComponentContext()); |
77 | 0 | const Reference<util::XURLTransformer> xParser = util::URLTransformer::create( xComponentContext ); |
78 | 0 | xParser->parseStrict(aURL); |
79 | |
|
80 | 0 | return aURL; |
81 | 0 | } |
82 | | |
83 | | Reference<frame::XDispatch> Tools::GetDispatch ( |
84 | | const css::uno::Reference<css::frame::XFrame>& rxFrame, |
85 | | const util::URL& rURL) |
86 | 0 | { |
87 | 0 | Reference<frame::XDispatchProvider> xProvider (rxFrame, UNO_QUERY_THROW); |
88 | 0 | Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(rURL, OUString(), 0)); |
89 | 0 | return xDispatch; |
90 | 0 | } |
91 | | |
92 | | OUString Tools::GetModuleName ( |
93 | | const css::uno::Reference<css::frame::XController>& rxController) |
94 | 0 | { |
95 | 0 | if (!rxController.is()) |
96 | 0 | return OUString(); |
97 | | |
98 | 0 | try |
99 | 0 | { |
100 | 0 | const Reference<XComponentContext>& xComponentContext (::comphelper::getProcessComponentContext()); |
101 | 0 | const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xComponentContext ); |
102 | 0 | return xModuleManager->identify(rxController); |
103 | 0 | } |
104 | 0 | catch (const Exception&) |
105 | 0 | { |
106 | | // Ignored. |
107 | 0 | } |
108 | 0 | return OUString(); |
109 | 0 | } |
110 | | |
111 | | } // end of namespace sfx2::sidebar |
112 | | |
113 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |