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 24*f35c6d02SAndre 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 34*f35c6d02SAndre Fischer #include <com/sun/star/frame/XDispatchProvider.hpp> 3595a18594SAndre Fischer #include <com/sun/star/graphic/XGraphicProvider.hpp> 36*f35c6d02SAndre Fischer #include <com/sun/star/util/XURLTransformer.hpp> 3795a18594SAndre Fischer 3895a18594SAndre Fischer #include <cstring> 39b9e67834SAndre Fischer 40b9e67834SAndre Fischer using namespace css; 41b9e67834SAndre Fischer using namespace cssu; 42b9e67834SAndre Fischer 43b9e67834SAndre Fischer 44b9e67834SAndre Fischer namespace sfx2 { namespace sidebar { 45b9e67834SAndre Fischer 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 57b9e67834SAndre Fischer 58b9e67834SAndre Fischer 59b9e67834SAndre Fischer 60b9e67834SAndre Fischer Image Tools::GetImage ( 61b9e67834SAndre Fischer const ::rtl::OUString& rsURL, 62b9e67834SAndre Fischer const Reference<frame::XFrame>& rxFrame) 63b9e67834SAndre Fischer { 64b9e67834SAndre Fischer if (rsURL.getLength() > 0) 65b9e67834SAndre Fischer { 66b9e67834SAndre Fischer static const sal_Char* sUnoCommandPrefix = ".uno:"; 67b9e67834SAndre Fischer static const sal_Int32 nUnoCommandPrefixLength = strlen(sUnoCommandPrefix); 68b9e67834SAndre Fischer static const sal_Char* sCommandImagePrefix = "private:commandimage/"; 69b9e67834SAndre Fischer static const sal_Int32 nCommandImagePrefixLength = strlen(sCommandImagePrefix); 70b9e67834SAndre Fischer 71b9e67834SAndre Fischer if (rsURL.compareToAscii(sUnoCommandPrefix, nUnoCommandPrefixLength) == 0) 72b9e67834SAndre Fischer { 73b9e67834SAndre Fischer const Image aPanelImage (::GetImage(rxFrame, rsURL, sal_False, Theme::IsHighContrastMode())); 74b9e67834SAndre Fischer return aPanelImage; 75b9e67834SAndre Fischer } 76b9e67834SAndre Fischer else if (rsURL.compareToAscii(sCommandImagePrefix, nCommandImagePrefixLength) == 0) 77b9e67834SAndre Fischer { 78b9e67834SAndre Fischer ::rtl::OUStringBuffer aCommandName; 79b9e67834SAndre Fischer aCommandName.appendAscii(sUnoCommandPrefix); 80b9e67834SAndre Fischer aCommandName.append(rsURL.copy(nCommandImagePrefixLength)); 81b9e67834SAndre Fischer const ::rtl::OUString sCommandName (aCommandName.makeStringAndClear()); 82b9e67834SAndre Fischer 83b9e67834SAndre Fischer const Image aPanelImage (::GetImage(rxFrame, sCommandName, sal_False, Theme::IsHighContrastMode())); 84b9e67834SAndre Fischer return aPanelImage; 85b9e67834SAndre Fischer } 86b9e67834SAndre Fischer else 87b9e67834SAndre Fischer { 88b9e67834SAndre Fischer const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); 89b9e67834SAndre Fischer const Reference<graphic::XGraphicProvider> xGraphicProvider ( 90b9e67834SAndre Fischer aContext.createComponent("com.sun.star.graphic.GraphicProvider"), 91b9e67834SAndre Fischer UNO_QUERY); 92b9e67834SAndre Fischer if ( xGraphicProvider.is()) 93b9e67834SAndre Fischer { 94b9e67834SAndre Fischer ::comphelper::NamedValueCollection aMediaProperties; 95b9e67834SAndre Fischer aMediaProperties.put("URL", rsURL); 96b9e67834SAndre Fischer const Reference<graphic::XGraphic> xGraphic ( 97b9e67834SAndre Fischer xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()), 98b9e67834SAndre Fischer UNO_QUERY); 99b9e67834SAndre Fischer if (xGraphic.is()) 100b9e67834SAndre Fischer return Image(xGraphic); 101b9e67834SAndre Fischer } 102b9e67834SAndre Fischer } 103b9e67834SAndre Fischer } 104b9e67834SAndre Fischer return Image(); 105b9e67834SAndre Fischer } 106b9e67834SAndre Fischer 107b9e67834SAndre Fischer 10895a18594SAndre Fischer 10995a18594SAndre Fischer 11095a18594SAndre Fischer css::awt::Gradient Tools::VclToAwtGradient (const Gradient aVclGradient) 11195a18594SAndre Fischer { 11295a18594SAndre Fischer css::awt::Gradient aAwtGradient ( 11395a18594SAndre Fischer awt::GradientStyle(aVclGradient.GetStyle()), 11495a18594SAndre Fischer aVclGradient.GetStartColor().GetRGBColor(), 11595a18594SAndre Fischer aVclGradient.GetEndColor().GetRGBColor(), 11695a18594SAndre Fischer aVclGradient.GetAngle(), 11795a18594SAndre Fischer aVclGradient.GetBorder(), 11895a18594SAndre Fischer aVclGradient.GetOfsX(), 11995a18594SAndre Fischer aVclGradient.GetOfsY(), 12095a18594SAndre Fischer aVclGradient.GetStartIntensity(), 12195a18594SAndre Fischer aVclGradient.GetEndIntensity(), 12295a18594SAndre Fischer aVclGradient.GetSteps()); 12395a18594SAndre Fischer return aAwtGradient; 12495a18594SAndre Fischer } 12595a18594SAndre Fischer 12695a18594SAndre Fischer 12795a18594SAndre Fischer 12895a18594SAndre Fischer 12995a18594SAndre Fischer Gradient Tools::AwtToVclGradient (const css::awt::Gradient aAwtGradient) 13095a18594SAndre Fischer { 13195a18594SAndre Fischer Gradient aVclGradient ( 13295a18594SAndre Fischer GradientStyle(aAwtGradient.Style), 13395a18594SAndre Fischer aAwtGradient.StartColor, 13495a18594SAndre Fischer aAwtGradient.EndColor); 13595a18594SAndre Fischer aVclGradient.SetAngle(aAwtGradient.Angle); 13695a18594SAndre Fischer aVclGradient.SetBorder(aAwtGradient.Border); 13795a18594SAndre Fischer aVclGradient.SetOfsX(aAwtGradient.XOffset); 13895a18594SAndre Fischer aVclGradient.SetOfsY(aAwtGradient.YOffset); 13995a18594SAndre Fischer aVclGradient.SetStartIntensity(aAwtGradient.StartIntensity); 14095a18594SAndre Fischer aVclGradient.SetEndIntensity(aAwtGradient.EndIntensity); 14195a18594SAndre Fischer aVclGradient.SetSteps(aAwtGradient.StepCount); 14295a18594SAndre Fischer 14395a18594SAndre Fischer return aVclGradient; 14495a18594SAndre Fischer } 14595a18594SAndre Fischer 14695a18594SAndre Fischer 14795a18594SAndre Fischer 14895a18594SAndre Fischer 14995a18594SAndre Fischer SvBorder Tools::RectangleToSvBorder (const Rectangle aBox) 15095a18594SAndre Fischer { 15195a18594SAndre Fischer return SvBorder( 15295a18594SAndre Fischer aBox.Left(), 15395a18594SAndre Fischer aBox.Top(), 15495a18594SAndre Fischer aBox.Right(), 15595a18594SAndre Fischer aBox.Bottom()); 15695a18594SAndre Fischer } 15795a18594SAndre Fischer 158*f35c6d02SAndre Fischer 159*f35c6d02SAndre Fischer 160*f35c6d02SAndre Fischer 161*f35c6d02SAndre Fischer util::URL Tools::GetURL (const ::rtl::OUString& rsCommand) 162*f35c6d02SAndre Fischer { 163*f35c6d02SAndre Fischer util::URL aURL; 164*f35c6d02SAndre Fischer aURL.Complete = rsCommand; 165*f35c6d02SAndre Fischer 166*f35c6d02SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 167*f35c6d02SAndre Fischer const Reference<util::XURLTransformer> xParser ( 168*f35c6d02SAndre Fischer aComponentContext.createComponent("com.sun.star.util.URLTransformer"), 169*f35c6d02SAndre Fischer UNO_QUERY_THROW); 170*f35c6d02SAndre Fischer xParser->parseStrict(aURL); 171*f35c6d02SAndre Fischer 172*f35c6d02SAndre Fischer return aURL; 173*f35c6d02SAndre Fischer } 174*f35c6d02SAndre Fischer 175*f35c6d02SAndre Fischer 176*f35c6d02SAndre Fischer 177*f35c6d02SAndre Fischer 178*f35c6d02SAndre Fischer Reference<frame::XDispatch> Tools::GetDispatch ( 179*f35c6d02SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame, 180*f35c6d02SAndre Fischer const util::URL& rURL) 181*f35c6d02SAndre Fischer { 182*f35c6d02SAndre Fischer Reference<frame::XDispatchProvider> xProvider (rxFrame, UNO_QUERY_THROW); 183*f35c6d02SAndre Fischer Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(rURL, ::rtl::OUString(), 0)); 184*f35c6d02SAndre Fischer return xDispatch; 185*f35c6d02SAndre Fischer } 186*f35c6d02SAndre Fischer 187*f35c6d02SAndre Fischer 188b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar 189