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 <sfx2/sidebar/Tools.hxx>
22 #include <sfx2/sidebar/Theme.hxx>
24 #include <comphelper/processfactory.hxx>
25 #include <vcl/commandinfoprovider.hxx>
26 #include <vcl/gradient.hxx>
28 #include <com/sun/star/frame/XDispatchProvider.hpp>
29 #include <com/sun/star/util/URLTransformer.hpp>
30 #include <com/sun/star/frame/ModuleManager.hpp>
35 using namespace css::uno
;
37 namespace sfx2
{ namespace sidebar
{
39 Image
Tools::GetImage (
40 const ::rtl::OUString
& rsImageURL
,
41 const ::rtl::OUString
& rsHighContrastImageURL
,
42 const Reference
<frame::XFrame
>& rxFrame
)
44 if (Theme::IsHighContrastMode())
45 return GetImage(rsHighContrastImageURL
, rxFrame
);
47 return GetImage(rsImageURL
, rxFrame
);
50 Image
Tools::GetImage (
51 const ::rtl::OUString
& rsURL
,
52 const Reference
<frame::XFrame
>& rxFrame
)
54 if (rsURL
.getLength() > 0)
56 if (rsURL
.startsWith(".uno:"))
58 return vcl::CommandInfoProvider::GetImageForCommand(rsURL
, rxFrame
);
68 css::awt::Gradient
Tools::VclToAwtGradient (const Gradient
& rVclGradient
)
70 css::awt::Gradient
aAwtGradient (
71 awt::GradientStyle(rVclGradient
.GetStyle()),
72 sal_Int32(rVclGradient
.GetStartColor().GetRGBColor()),
73 sal_Int32(rVclGradient
.GetEndColor().GetRGBColor()),
74 rVclGradient
.GetAngle(),
75 rVclGradient
.GetBorder(),
76 rVclGradient
.GetOfsX(),
77 rVclGradient
.GetOfsY(),
78 rVclGradient
.GetStartIntensity(),
79 rVclGradient
.GetEndIntensity(),
80 rVclGradient
.GetSteps());
84 Gradient
Tools::AwtToVclGradient (const css::awt::Gradient
& rAwtGradient
)
86 Gradient
aVclGradient (
87 GradientStyle(rAwtGradient
.Style
),
88 Color(rAwtGradient
.StartColor
),
89 Color(rAwtGradient
.EndColor
));
90 aVclGradient
.SetAngle(rAwtGradient
.Angle
);
91 aVclGradient
.SetBorder(rAwtGradient
.Border
);
92 aVclGradient
.SetOfsX(rAwtGradient
.XOffset
);
93 aVclGradient
.SetOfsY(rAwtGradient
.YOffset
);
94 aVclGradient
.SetStartIntensity(rAwtGradient
.StartIntensity
);
95 aVclGradient
.SetEndIntensity(rAwtGradient
.EndIntensity
);
96 aVclGradient
.SetSteps(rAwtGradient
.StepCount
);
101 util::URL
Tools::GetURL (const ::rtl::OUString
& rsCommand
)
104 aURL
.Complete
= rsCommand
;
106 const Reference
<XComponentContext
> xComponentContext (::comphelper::getProcessComponentContext());
107 const Reference
<util::XURLTransformer
> xParser
= util::URLTransformer::create( xComponentContext
);
108 xParser
->parseStrict(aURL
);
113 Reference
<frame::XDispatch
> Tools::GetDispatch (
114 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
115 const util::URL
& rURL
)
117 Reference
<frame::XDispatchProvider
> xProvider (rxFrame
, UNO_QUERY_THROW
);
118 Reference
<frame::XDispatch
> xDispatch (xProvider
->queryDispatch(rURL
, ::rtl::OUString(), 0));
122 ::rtl::OUString
Tools::GetModuleName (
123 const css::uno::Reference
<css::frame::XController
>& rxController
)
125 if (!rxController
.is())
126 return ::rtl::OUString();
130 const Reference
<XComponentContext
> xComponentContext (::comphelper::getProcessComponentContext());
131 const Reference
<frame::XModuleManager
> xModuleManager
= frame::ModuleManager::create( xComponentContext
);
132 return xModuleManager
->identify(rxController
);
134 catch (const Exception
&)
138 return ::rtl::OUString();
141 } } // end of namespace sfx2::sidebar
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */