1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #include "precompiled_sfx2.hxx" 23 24 #include "sfx2/sidebar/Tools.hxx" 25 26 #include "sfx2/sidebar/Theme.hxx" 27 28 #include "sfx2/imagemgr.hxx" 29 #include <comphelper/processfactory.hxx> 30 #include <comphelper/componentcontext.hxx> 31 #include <comphelper/namedvaluecollection.hxx> 32 #include <vcl/gradient.hxx> 33 34 #include <com/sun/star/frame/XDispatchProvider.hpp> 35 #include <com/sun/star/graphic/XGraphicProvider.hpp> 36 #include <com/sun/star/util/XURLTransformer.hpp> 37 38 #include <cstring> 39 40 using namespace css; 41 using namespace cssu; 42 43 44 namespace sfx2 { namespace sidebar { 45 46 Image Tools::GetImage ( 47 const ::rtl::OUString& rsImageURL, 48 const ::rtl::OUString& rsHighContrastImageURL, 49 const Reference<frame::XFrame>& rxFrame) 50 { 51 if (Theme::IsHighContrastMode()) 52 return GetImage(rsHighContrastImageURL, rxFrame); 53 else 54 return GetImage(rsImageURL, rxFrame); 55 } 56 57 58 59 60 Image Tools::GetImage ( 61 const ::rtl::OUString& rsURL, 62 const Reference<frame::XFrame>& rxFrame) 63 { 64 if (rsURL.getLength() > 0) 65 { 66 static const sal_Char* sUnoCommandPrefix = ".uno:"; 67 static const sal_Int32 nUnoCommandPrefixLength = strlen(sUnoCommandPrefix); 68 static const sal_Char* sCommandImagePrefix = "private:commandimage/"; 69 static const sal_Int32 nCommandImagePrefixLength = strlen(sCommandImagePrefix); 70 71 if (rsURL.compareToAscii(sUnoCommandPrefix, nUnoCommandPrefixLength) == 0) 72 { 73 const Image aPanelImage (::GetImage(rxFrame, rsURL, sal_False, Theme::IsHighContrastMode())); 74 return aPanelImage; 75 } 76 else if (rsURL.compareToAscii(sCommandImagePrefix, nCommandImagePrefixLength) == 0) 77 { 78 ::rtl::OUStringBuffer aCommandName; 79 aCommandName.appendAscii(sUnoCommandPrefix); 80 aCommandName.append(rsURL.copy(nCommandImagePrefixLength)); 81 const ::rtl::OUString sCommandName (aCommandName.makeStringAndClear()); 82 83 const Image aPanelImage (::GetImage(rxFrame, sCommandName, sal_False, Theme::IsHighContrastMode())); 84 return aPanelImage; 85 } 86 else 87 { 88 const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); 89 const Reference<graphic::XGraphicProvider> xGraphicProvider ( 90 aContext.createComponent("com.sun.star.graphic.GraphicProvider"), 91 UNO_QUERY); 92 if ( xGraphicProvider.is()) 93 { 94 ::comphelper::NamedValueCollection aMediaProperties; 95 aMediaProperties.put("URL", rsURL); 96 const Reference<graphic::XGraphic> xGraphic ( 97 xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()), 98 UNO_QUERY); 99 if (xGraphic.is()) 100 return Image(xGraphic); 101 } 102 } 103 } 104 return Image(); 105 } 106 107 108 109 110 css::awt::Gradient Tools::VclToAwtGradient (const Gradient aVclGradient) 111 { 112 css::awt::Gradient aAwtGradient ( 113 awt::GradientStyle(aVclGradient.GetStyle()), 114 aVclGradient.GetStartColor().GetRGBColor(), 115 aVclGradient.GetEndColor().GetRGBColor(), 116 aVclGradient.GetAngle(), 117 aVclGradient.GetBorder(), 118 aVclGradient.GetOfsX(), 119 aVclGradient.GetOfsY(), 120 aVclGradient.GetStartIntensity(), 121 aVclGradient.GetEndIntensity(), 122 aVclGradient.GetSteps()); 123 return aAwtGradient; 124 } 125 126 127 128 129 Gradient Tools::AwtToVclGradient (const css::awt::Gradient aAwtGradient) 130 { 131 Gradient aVclGradient ( 132 GradientStyle(aAwtGradient.Style), 133 aAwtGradient.StartColor, 134 aAwtGradient.EndColor); 135 aVclGradient.SetAngle(aAwtGradient.Angle); 136 aVclGradient.SetBorder(aAwtGradient.Border); 137 aVclGradient.SetOfsX(aAwtGradient.XOffset); 138 aVclGradient.SetOfsY(aAwtGradient.YOffset); 139 aVclGradient.SetStartIntensity(aAwtGradient.StartIntensity); 140 aVclGradient.SetEndIntensity(aAwtGradient.EndIntensity); 141 aVclGradient.SetSteps(aAwtGradient.StepCount); 142 143 return aVclGradient; 144 } 145 146 147 148 149 SvBorder Tools::RectangleToSvBorder (const Rectangle aBox) 150 { 151 return SvBorder( 152 aBox.Left(), 153 aBox.Top(), 154 aBox.Right(), 155 aBox.Bottom()); 156 } 157 158 159 160 161 util::URL Tools::GetURL (const ::rtl::OUString& rsCommand) 162 { 163 util::URL aURL; 164 aURL.Complete = rsCommand; 165 166 const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 167 const Reference<util::XURLTransformer> xParser ( 168 aComponentContext.createComponent("com.sun.star.util.URLTransformer"), 169 UNO_QUERY_THROW); 170 xParser->parseStrict(aURL); 171 172 return aURL; 173 } 174 175 176 177 178 Reference<frame::XDispatch> Tools::GetDispatch ( 179 const cssu::Reference<css::frame::XFrame>& rxFrame, 180 const util::URL& rURL) 181 { 182 Reference<frame::XDispatchProvider> xProvider (rxFrame, UNO_QUERY_THROW); 183 Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(rURL, ::rtl::OUString(), 0)); 184 return xDispatch; 185 } 186 187 188 } } // end of namespace sfx2::sidebar 189