LibreOffice Module sfx2 (master) 1
Tools.cxx
Go to the documentation of this file.
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
23
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
34using namespace css;
35using namespace css::uno;
36
37namespace sfx2::sidebar {
38
39css::uno::Reference<css::graphic::XGraphic> Tools::GetImage(
40 const OUString& rsImageURL,
41 const OUString& rsHighContrastImageURL,
42 const Reference<frame::XFrame>& rxFrame)
43{
44 if (Theme::IsHighContrastMode() && !rsHighContrastImageURL.isEmpty())
45 return GetImage(rsHighContrastImageURL, rxFrame);
46 else
47 return GetImage(rsImageURL, rxFrame);
48}
49
50css::uno::Reference<css::graphic::XGraphic> Tools::GetImage(
51 const OUString& rsURL,
52 const Reference<frame::XFrame>& rxFrame)
53{
54 if (rsURL.getLength() > 0)
55 {
56 if (rsURL.startsWith(".uno:"))
58
59 else
60 {
61 Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext());
62 Reference<graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext));
64 aMediaProperties.put("URL", rsURL);
65 return xProvider->queryGraphic(aMediaProperties.getPropertyValues());
66 }
67 }
68 return nullptr;
69}
70
71util::URL Tools::GetURL (const OUString& rsCommand)
72{
73 util::URL aURL;
74 aURL.Complete = rsCommand;
75
76 const Reference<XComponentContext> xComponentContext (::comphelper::getProcessComponentContext());
77 const Reference<util::XURLTransformer> xParser = util::URLTransformer::create( xComponentContext );
78 xParser->parseStrict(aURL);
79
80 return aURL;
81}
82
83Reference<frame::XDispatch> Tools::GetDispatch (
84 const css::uno::Reference<css::frame::XFrame>& rxFrame,
85 const util::URL& rURL)
86{
87 Reference<frame::XDispatchProvider> xProvider (rxFrame, UNO_QUERY_THROW);
88 Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(rURL, OUString(), 0));
89 return xDispatch;
90}
91
93 const css::uno::Reference<css::frame::XController>& rxController)
94{
95 if (!rxController.is())
96 return OUString();
97
98 try
99 {
100 const Reference<XComponentContext> xComponentContext (::comphelper::getProcessComponentContext());
101 const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xComponentContext );
102 return xModuleManager->identify(rxController);
103 }
104 catch (const Exception&)
105 {
106 // Ignored.
107 }
108 return OUString();
109}
110
111} // end of namespace sfx2::sidebar
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
static bool IsHighContrastMode()
Definition: Theme.cxx:70
static css::uno::Reference< css::graphic::XGraphic > GetImage(const OUString &rsImageURL, const OUString &rsHighContrastImageURL, const css::uno::Reference< css::frame::XFrame > &rxFrame)
static OUString GetModuleName(const css::uno::Reference< css::frame::XController > &rxFrame)
Definition: Tools.cxx:92
static css::uno::Reference< css::frame::XDispatch > GetDispatch(const css::uno::Reference< css::frame::XFrame > &rxFrame, const css::util::URL &rURL)
Definition: Tools.cxx:83
static css::util::URL GetURL(const OUString &rsCommand)
Definition: Tools.cxx:71
Reference< XDispatch > xDispatch
URL aURL
@ Exception
Reference< graphic::XGraphic > GetXGraphicForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)