xref: /AOO41X/main/sfx2/source/sidebar/Tools.cxx (revision 95a1859439d31511e7ca45b278e1eb5d6c4b3a93)
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 
24b9e67834SAndre Fischer #include "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>
32*95a18594SAndre Fischer #include <vcl/gradient.hxx>
33b9e67834SAndre Fischer 
34*95a18594SAndre Fischer #include <com/sun/star/graphic/XGraphicProvider.hpp>
35*95a18594SAndre Fischer 
36*95a18594SAndre Fischer #include <cstring>
37b9e67834SAndre Fischer 
38b9e67834SAndre Fischer using namespace css;
39b9e67834SAndre Fischer using namespace cssu;
40b9e67834SAndre Fischer 
41b9e67834SAndre Fischer 
42b9e67834SAndre Fischer namespace sfx2 { namespace sidebar {
43b9e67834SAndre Fischer 
44b9e67834SAndre Fischer Image Tools::GetImage (
45b9e67834SAndre Fischer     const ::rtl::OUString& rsImageURL,
46b9e67834SAndre Fischer     const ::rtl::OUString& rsHighContrastImageURL,
47b9e67834SAndre Fischer     const Reference<frame::XFrame>& rxFrame)
48b9e67834SAndre Fischer {
49b9e67834SAndre Fischer     if (Theme::IsHighContrastMode())
50b9e67834SAndre Fischer         return GetImage(rsHighContrastImageURL, rxFrame);
51b9e67834SAndre Fischer     else
52b9e67834SAndre Fischer         return GetImage(rsImageURL, rxFrame);
53b9e67834SAndre Fischer }
54b9e67834SAndre Fischer 
55b9e67834SAndre Fischer 
56b9e67834SAndre Fischer 
57b9e67834SAndre Fischer 
58b9e67834SAndre Fischer Image Tools::GetImage (
59b9e67834SAndre Fischer     const ::rtl::OUString& rsURL,
60b9e67834SAndre Fischer     const Reference<frame::XFrame>& rxFrame)
61b9e67834SAndre Fischer {
62b9e67834SAndre Fischer     if (rsURL.getLength() > 0)
63b9e67834SAndre Fischer     {
64b9e67834SAndre Fischer         static const sal_Char* sUnoCommandPrefix = ".uno:";
65b9e67834SAndre Fischer         static const sal_Int32 nUnoCommandPrefixLength = strlen(sUnoCommandPrefix);
66b9e67834SAndre Fischer         static const sal_Char* sCommandImagePrefix = "private:commandimage/";
67b9e67834SAndre Fischer         static const sal_Int32 nCommandImagePrefixLength = strlen(sCommandImagePrefix);
68b9e67834SAndre Fischer 
69b9e67834SAndre Fischer         if (rsURL.compareToAscii(sUnoCommandPrefix, nUnoCommandPrefixLength) == 0)
70b9e67834SAndre Fischer         {
71b9e67834SAndre Fischer             const Image aPanelImage (::GetImage(rxFrame, rsURL, sal_False, Theme::IsHighContrastMode()));
72b9e67834SAndre Fischer             return aPanelImage;
73b9e67834SAndre Fischer         }
74b9e67834SAndre Fischer         else if (rsURL.compareToAscii(sCommandImagePrefix, nCommandImagePrefixLength) == 0)
75b9e67834SAndre Fischer         {
76b9e67834SAndre Fischer             ::rtl::OUStringBuffer aCommandName;
77b9e67834SAndre Fischer             aCommandName.appendAscii(sUnoCommandPrefix);
78b9e67834SAndre Fischer             aCommandName.append(rsURL.copy(nCommandImagePrefixLength));
79b9e67834SAndre Fischer             const ::rtl::OUString sCommandName (aCommandName.makeStringAndClear());
80b9e67834SAndre Fischer 
81b9e67834SAndre Fischer             const Image aPanelImage (::GetImage(rxFrame, sCommandName, sal_False, Theme::IsHighContrastMode()));
82b9e67834SAndre Fischer             return aPanelImage;
83b9e67834SAndre Fischer         }
84b9e67834SAndre Fischer         else
85b9e67834SAndre Fischer         {
86b9e67834SAndre Fischer             const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory());
87b9e67834SAndre Fischer             const Reference<graphic::XGraphicProvider> xGraphicProvider (
88b9e67834SAndre Fischer                 aContext.createComponent("com.sun.star.graphic.GraphicProvider"),
89b9e67834SAndre Fischer                 UNO_QUERY);
90b9e67834SAndre Fischer             if ( xGraphicProvider.is())
91b9e67834SAndre Fischer             {
92b9e67834SAndre Fischer                 ::comphelper::NamedValueCollection aMediaProperties;
93b9e67834SAndre Fischer                 aMediaProperties.put("URL", rsURL);
94b9e67834SAndre Fischer                 const Reference<graphic::XGraphic> xGraphic (
95b9e67834SAndre Fischer                     xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()),
96b9e67834SAndre Fischer                     UNO_QUERY);
97b9e67834SAndre Fischer                 if (xGraphic.is())
98b9e67834SAndre Fischer                     return Image(xGraphic);
99b9e67834SAndre Fischer             }
100b9e67834SAndre Fischer         }
101b9e67834SAndre Fischer     }
102b9e67834SAndre Fischer     return Image();
103b9e67834SAndre Fischer }
104b9e67834SAndre Fischer 
105b9e67834SAndre Fischer 
106*95a18594SAndre Fischer 
107*95a18594SAndre Fischer 
108*95a18594SAndre Fischer css::awt::Gradient Tools::VclToAwtGradient (const Gradient aVclGradient)
109*95a18594SAndre Fischer {
110*95a18594SAndre Fischer     css::awt::Gradient aAwtGradient (
111*95a18594SAndre Fischer         awt::GradientStyle(aVclGradient.GetStyle()),
112*95a18594SAndre Fischer         aVclGradient.GetStartColor().GetRGBColor(),
113*95a18594SAndre Fischer         aVclGradient.GetEndColor().GetRGBColor(),
114*95a18594SAndre Fischer         aVclGradient.GetAngle(),
115*95a18594SAndre Fischer         aVclGradient.GetBorder(),
116*95a18594SAndre Fischer         aVclGradient.GetOfsX(),
117*95a18594SAndre Fischer         aVclGradient.GetOfsY(),
118*95a18594SAndre Fischer         aVclGradient.GetStartIntensity(),
119*95a18594SAndre Fischer         aVclGradient.GetEndIntensity(),
120*95a18594SAndre Fischer         aVclGradient.GetSteps());
121*95a18594SAndre Fischer     return aAwtGradient;
122*95a18594SAndre Fischer }
123*95a18594SAndre Fischer 
124*95a18594SAndre Fischer 
125*95a18594SAndre Fischer 
126*95a18594SAndre Fischer 
127*95a18594SAndre Fischer Gradient Tools::AwtToVclGradient (const css::awt::Gradient aAwtGradient)
128*95a18594SAndre Fischer {
129*95a18594SAndre Fischer     Gradient aVclGradient (
130*95a18594SAndre Fischer         GradientStyle(aAwtGradient.Style),
131*95a18594SAndre Fischer         aAwtGradient.StartColor,
132*95a18594SAndre Fischer         aAwtGradient.EndColor);
133*95a18594SAndre Fischer     aVclGradient.SetAngle(aAwtGradient.Angle);
134*95a18594SAndre Fischer     aVclGradient.SetBorder(aAwtGradient.Border);
135*95a18594SAndre Fischer     aVclGradient.SetOfsX(aAwtGradient.XOffset);
136*95a18594SAndre Fischer     aVclGradient.SetOfsY(aAwtGradient.YOffset);
137*95a18594SAndre Fischer     aVclGradient.SetStartIntensity(aAwtGradient.StartIntensity);
138*95a18594SAndre Fischer     aVclGradient.SetEndIntensity(aAwtGradient.EndIntensity);
139*95a18594SAndre Fischer     aVclGradient.SetSteps(aAwtGradient.StepCount);
140*95a18594SAndre Fischer 
141*95a18594SAndre Fischer     return aVclGradient;
142*95a18594SAndre Fischer }
143*95a18594SAndre Fischer 
144*95a18594SAndre Fischer 
145*95a18594SAndre Fischer 
146*95a18594SAndre Fischer 
147*95a18594SAndre Fischer SvBorder Tools::RectangleToSvBorder (const Rectangle aBox)
148*95a18594SAndre Fischer {
149*95a18594SAndre Fischer     return SvBorder(
150*95a18594SAndre Fischer         aBox.Left(),
151*95a18594SAndre Fischer         aBox.Top(),
152*95a18594SAndre Fischer         aBox.Right(),
153*95a18594SAndre Fischer         aBox.Bottom());
154*95a18594SAndre Fischer }
155*95a18594SAndre Fischer 
156b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar
157