1b9e67834SAndre Fischer /**************************************************************
2b9e67834SAndre Fischer *
3b9e67834SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
4b9e67834SAndre Fischer * or more contributor license agreements. See the NOTICE file
5b9e67834SAndre Fischer * distributed with this work for additional information
6b9e67834SAndre Fischer * regarding copyright ownership. The ASF licenses this file
7b9e67834SAndre Fischer * to you under the Apache License, Version 2.0 (the
8b9e67834SAndre Fischer * "License"); you may not use this file except in compliance
9b9e67834SAndre Fischer * with the License. You may obtain a copy of the License at
10b9e67834SAndre Fischer *
11b9e67834SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
12b9e67834SAndre Fischer *
13b9e67834SAndre Fischer * Unless required by applicable law or agreed to in writing,
14b9e67834SAndre Fischer * software distributed under the License is distributed on an
15b9e67834SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b9e67834SAndre Fischer * KIND, either express or implied. See the License for the
17b9e67834SAndre Fischer * specific language governing permissions and limitations
18b9e67834SAndre Fischer * under the License.
19b9e67834SAndre Fischer *
20b9e67834SAndre Fischer *************************************************************/
21b9e67834SAndre Fischer
22b9e67834SAndre Fischer #include "precompiled_sfx2.hxx"
23b9e67834SAndre Fischer
24f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx"
25b9e67834SAndre Fischer
26b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
27b9e67834SAndre Fischer
28b9e67834SAndre Fischer #include "sfx2/imagemgr.hxx"
29b9e67834SAndre Fischer #include <comphelper/processfactory.hxx>
30b9e67834SAndre Fischer #include <comphelper/componentcontext.hxx>
31b9e67834SAndre Fischer #include <comphelper/namedvaluecollection.hxx>
3295a18594SAndre Fischer #include <vcl/gradient.hxx>
33b9e67834SAndre Fischer
34f35c6d02SAndre Fischer #include <com/sun/star/frame/XDispatchProvider.hpp>
3595a18594SAndre Fischer #include <com/sun/star/graphic/XGraphicProvider.hpp>
36f35c6d02SAndre Fischer #include <com/sun/star/util/XURLTransformer.hpp>
37d46a1e42SAndre Fischer #include <com/sun/star/frame/XModuleManager.hpp>
3895a18594SAndre Fischer
3995a18594SAndre Fischer #include <cstring>
40b9e67834SAndre Fischer
41b9e67834SAndre Fischer using namespace css;
42b9e67834SAndre Fischer using namespace cssu;
43b9e67834SAndre Fischer
44b9e67834SAndre Fischer namespace sfx2 { namespace sidebar {
45b9e67834SAndre Fischer
GetImage(const::rtl::OUString & rsImageURL,const::rtl::OUString & rsHighContrastImageURL,const Reference<frame::XFrame> & rxFrame)46b9e67834SAndre Fischer Image Tools::GetImage (
47b9e67834SAndre Fischer const ::rtl::OUString& rsImageURL,
48b9e67834SAndre Fischer const ::rtl::OUString& rsHighContrastImageURL,
49b9e67834SAndre Fischer const Reference<frame::XFrame>& rxFrame)
50b9e67834SAndre Fischer {
51b9e67834SAndre Fischer if (Theme::IsHighContrastMode())
52b9e67834SAndre Fischer return GetImage(rsHighContrastImageURL, rxFrame);
53b9e67834SAndre Fischer else
54b9e67834SAndre Fischer return GetImage(rsImageURL, rxFrame);
55b9e67834SAndre Fischer }
56b9e67834SAndre Fischer
GetImage(const::rtl::OUString & rsURL,const Reference<frame::XFrame> & rxFrame)57b9e67834SAndre Fischer Image Tools::GetImage (
58b9e67834SAndre Fischer const ::rtl::OUString& rsURL,
59b9e67834SAndre Fischer const Reference<frame::XFrame>& rxFrame)
60b9e67834SAndre Fischer {
61b9e67834SAndre Fischer if (rsURL.getLength() > 0)
62b9e67834SAndre Fischer {
63b9e67834SAndre Fischer static const sal_Char* sUnoCommandPrefix = ".uno:";
64b9e67834SAndre Fischer static const sal_Int32 nUnoCommandPrefixLength = strlen(sUnoCommandPrefix);
65b9e67834SAndre Fischer static const sal_Char* sCommandImagePrefix = "private:commandimage/";
66b9e67834SAndre Fischer static const sal_Int32 nCommandImagePrefixLength = strlen(sCommandImagePrefix);
67b9e67834SAndre Fischer
68b9e67834SAndre Fischer if (rsURL.compareToAscii(sUnoCommandPrefix, nUnoCommandPrefixLength) == 0)
69b9e67834SAndre Fischer {
70b9e67834SAndre Fischer const Image aPanelImage (::GetImage(rxFrame, rsURL, sal_False, Theme::IsHighContrastMode()));
71b9e67834SAndre Fischer return aPanelImage;
72b9e67834SAndre Fischer }
73b9e67834SAndre Fischer else if (rsURL.compareToAscii(sCommandImagePrefix, nCommandImagePrefixLength) == 0)
74b9e67834SAndre Fischer {
75b9e67834SAndre Fischer ::rtl::OUStringBuffer aCommandName;
76b9e67834SAndre Fischer aCommandName.appendAscii(sUnoCommandPrefix);
77b9e67834SAndre Fischer aCommandName.append(rsURL.copy(nCommandImagePrefixLength));
78b9e67834SAndre Fischer const ::rtl::OUString sCommandName (aCommandName.makeStringAndClear());
79b9e67834SAndre Fischer
80b9e67834SAndre Fischer const Image aPanelImage (::GetImage(rxFrame, sCommandName, sal_False, Theme::IsHighContrastMode()));
81b9e67834SAndre Fischer return aPanelImage;
82b9e67834SAndre Fischer }
83b9e67834SAndre Fischer else
84b9e67834SAndre Fischer {
85b9e67834SAndre Fischer const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory());
86b9e67834SAndre Fischer const Reference<graphic::XGraphicProvider> xGraphicProvider (
87b9e67834SAndre Fischer aContext.createComponent("com.sun.star.graphic.GraphicProvider"),
88b9e67834SAndre Fischer UNO_QUERY);
89b9e67834SAndre Fischer if ( xGraphicProvider.is())
90b9e67834SAndre Fischer {
91b9e67834SAndre Fischer ::comphelper::NamedValueCollection aMediaProperties;
92b9e67834SAndre Fischer aMediaProperties.put("URL", rsURL);
93b9e67834SAndre Fischer const Reference<graphic::XGraphic> xGraphic (
94b9e67834SAndre Fischer xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()),
95b9e67834SAndre Fischer UNO_QUERY);
96b9e67834SAndre Fischer if (xGraphic.is())
97b9e67834SAndre Fischer return Image(xGraphic);
98b9e67834SAndre Fischer }
99b9e67834SAndre Fischer }
100b9e67834SAndre Fischer }
101b9e67834SAndre Fischer return Image();
102b9e67834SAndre Fischer }
103b9e67834SAndre Fischer
VclToAwtGradient(const Gradient aVclGradient)10495a18594SAndre Fischer css::awt::Gradient Tools::VclToAwtGradient (const Gradient aVclGradient)
10595a18594SAndre Fischer {
10695a18594SAndre Fischer css::awt::Gradient aAwtGradient (
10795a18594SAndre Fischer awt::GradientStyle(aVclGradient.GetStyle()),
10895a18594SAndre Fischer aVclGradient.GetStartColor().GetRGBColor(),
10995a18594SAndre Fischer aVclGradient.GetEndColor().GetRGBColor(),
11095a18594SAndre Fischer aVclGradient.GetAngle(),
11195a18594SAndre Fischer aVclGradient.GetBorder(),
11295a18594SAndre Fischer aVclGradient.GetOfsX(),
11395a18594SAndre Fischer aVclGradient.GetOfsY(),
11495a18594SAndre Fischer aVclGradient.GetStartIntensity(),
11595a18594SAndre Fischer aVclGradient.GetEndIntensity(),
11695a18594SAndre Fischer aVclGradient.GetSteps());
11795a18594SAndre Fischer return aAwtGradient;
11895a18594SAndre Fischer }
11995a18594SAndre Fischer
AwtToVclGradient(const css::awt::Gradient aAwtGradient)12095a18594SAndre Fischer Gradient Tools::AwtToVclGradient (const css::awt::Gradient aAwtGradient)
12195a18594SAndre Fischer {
12295a18594SAndre Fischer Gradient aVclGradient (
12395a18594SAndre Fischer GradientStyle(aAwtGradient.Style),
12495a18594SAndre Fischer aAwtGradient.StartColor,
12595a18594SAndre Fischer aAwtGradient.EndColor);
12695a18594SAndre Fischer aVclGradient.SetAngle(aAwtGradient.Angle);
12795a18594SAndre Fischer aVclGradient.SetBorder(aAwtGradient.Border);
12895a18594SAndre Fischer aVclGradient.SetOfsX(aAwtGradient.XOffset);
12995a18594SAndre Fischer aVclGradient.SetOfsY(aAwtGradient.YOffset);
13095a18594SAndre Fischer aVclGradient.SetStartIntensity(aAwtGradient.StartIntensity);
13195a18594SAndre Fischer aVclGradient.SetEndIntensity(aAwtGradient.EndIntensity);
13295a18594SAndre Fischer aVclGradient.SetSteps(aAwtGradient.StepCount);
13395a18594SAndre Fischer
13495a18594SAndre Fischer return aVclGradient;
13595a18594SAndre Fischer }
13695a18594SAndre Fischer
RectangleToSvBorder(const Rectangle aBox)13795a18594SAndre Fischer SvBorder Tools::RectangleToSvBorder (const Rectangle aBox)
13895a18594SAndre Fischer {
13995a18594SAndre Fischer return SvBorder(
14095a18594SAndre Fischer aBox.Left(),
14195a18594SAndre Fischer aBox.Top(),
14295a18594SAndre Fischer aBox.Right(),
14395a18594SAndre Fischer aBox.Bottom());
14495a18594SAndre Fischer }
14595a18594SAndre Fischer
GetURL(const::rtl::OUString & rsCommand)146f35c6d02SAndre Fischer util::URL Tools::GetURL (const ::rtl::OUString& rsCommand)
147f35c6d02SAndre Fischer {
148f35c6d02SAndre Fischer util::URL aURL;
149f35c6d02SAndre Fischer aURL.Complete = rsCommand;
150f35c6d02SAndre Fischer
151f35c6d02SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory());
152f35c6d02SAndre Fischer const Reference<util::XURLTransformer> xParser (
153f35c6d02SAndre Fischer aComponentContext.createComponent("com.sun.star.util.URLTransformer"),
154f35c6d02SAndre Fischer UNO_QUERY_THROW);
155f35c6d02SAndre Fischer xParser->parseStrict(aURL);
156f35c6d02SAndre Fischer
157f35c6d02SAndre Fischer return aURL;
158f35c6d02SAndre Fischer }
159f35c6d02SAndre Fischer
GetDispatch(const cssu::Reference<css::frame::XFrame> & rxFrame,const util::URL & rURL)160f35c6d02SAndre Fischer Reference<frame::XDispatch> Tools::GetDispatch (
161f35c6d02SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame,
162f35c6d02SAndre Fischer const util::URL& rURL)
163f35c6d02SAndre Fischer {
164f35c6d02SAndre Fischer Reference<frame::XDispatchProvider> xProvider (rxFrame, UNO_QUERY_THROW);
165f35c6d02SAndre Fischer Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(rURL, ::rtl::OUString(), 0));
166f35c6d02SAndre Fischer return xDispatch;
167f35c6d02SAndre Fischer }
168f35c6d02SAndre Fischer
GetModuleName(const cssu::Reference<css::frame::XFrame> & rxFrame)169d46a1e42SAndre Fischer ::rtl::OUString Tools::GetModuleName (
170d46a1e42SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame)
171d46a1e42SAndre Fischer {
172d46a1e42SAndre Fischer if ( ! rxFrame.is() || ! rxFrame->getController().is())
173d46a1e42SAndre Fischer return ::rtl::OUString();
174d46a1e42SAndre Fischer
175d46a1e42SAndre Fischer try
176d46a1e42SAndre Fischer {
177d46a1e42SAndre Fischer const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory());
178d46a1e42SAndre Fischer const Reference<frame::XModuleManager> xModuleManager (
179d46a1e42SAndre Fischer aContext.createComponent("com.sun.star.frame.ModuleManager"),
180d46a1e42SAndre Fischer UNO_QUERY_THROW);
181d46a1e42SAndre Fischer return xModuleManager->identify(rxFrame);
182d46a1e42SAndre Fischer }
183d46a1e42SAndre Fischer catch (const Exception&)
184d46a1e42SAndre Fischer {
185d46a1e42SAndre Fischer // Ignored.
186d46a1e42SAndre Fischer }
187d46a1e42SAndre Fischer return ::rtl::OUString();
188d46a1e42SAndre Fischer }
189d46a1e42SAndre Fischer
190b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar
191*549760eaSmseidel
192*549760eaSmseidel /* vim: set noet sw=4 ts=4: */
193