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