1*b9e67834SAndre Fischer /************************************************************** 2*b9e67834SAndre Fischer * 3*b9e67834SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4*b9e67834SAndre Fischer * or more contributor license agreements. See the NOTICE file 5*b9e67834SAndre Fischer * distributed with this work for additional information 6*b9e67834SAndre Fischer * regarding copyright ownership. The ASF licenses this file 7*b9e67834SAndre Fischer * to you under the Apache License, Version 2.0 (the 8*b9e67834SAndre Fischer * "License"); you may not use this file except in compliance 9*b9e67834SAndre Fischer * with the License. You may obtain a copy of the License at 10*b9e67834SAndre Fischer * 11*b9e67834SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12*b9e67834SAndre Fischer * 13*b9e67834SAndre Fischer * Unless required by applicable law or agreed to in writing, 14*b9e67834SAndre Fischer * software distributed under the License is distributed on an 15*b9e67834SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b9e67834SAndre Fischer * KIND, either express or implied. See the License for the 17*b9e67834SAndre Fischer * specific language governing permissions and limitations 18*b9e67834SAndre Fischer * under the License. 19*b9e67834SAndre Fischer * 20*b9e67834SAndre Fischer *************************************************************/ 21*b9e67834SAndre Fischer 22*b9e67834SAndre Fischer #include "precompiled_sfx2.hxx" 23*b9e67834SAndre Fischer 24*b9e67834SAndre Fischer #include "Tools.hxx" 25*b9e67834SAndre Fischer 26*b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx" 27*b9e67834SAndre Fischer 28*b9e67834SAndre Fischer #include "sfx2/imagemgr.hxx" 29*b9e67834SAndre Fischer #include <comphelper/processfactory.hxx> 30*b9e67834SAndre Fischer #include <comphelper/componentcontext.hxx> 31*b9e67834SAndre Fischer #include <comphelper/namedvaluecollection.hxx> 32*b9e67834SAndre Fischer 33*b9e67834SAndre Fischer 34*b9e67834SAndre Fischer using namespace css; 35*b9e67834SAndre Fischer using namespace cssu; 36*b9e67834SAndre Fischer 37*b9e67834SAndre Fischer 38*b9e67834SAndre Fischer namespace sfx2 { namespace sidebar { 39*b9e67834SAndre Fischer 40*b9e67834SAndre Fischer Image Tools::GetImage ( 41*b9e67834SAndre Fischer const ::rtl::OUString& rsImageURL, 42*b9e67834SAndre Fischer const ::rtl::OUString& rsHighContrastImageURL, 43*b9e67834SAndre Fischer const Reference<frame::XFrame>& rxFrame) 44*b9e67834SAndre Fischer { 45*b9e67834SAndre Fischer if (Theme::IsHighContrastMode()) 46*b9e67834SAndre Fischer return GetImage(rsHighContrastImageURL, rxFrame); 47*b9e67834SAndre Fischer else 48*b9e67834SAndre Fischer return GetImage(rsImageURL, rxFrame); 49*b9e67834SAndre Fischer } 50*b9e67834SAndre Fischer 51*b9e67834SAndre Fischer 52*b9e67834SAndre Fischer 53*b9e67834SAndre Fischer 54*b9e67834SAndre Fischer Image Tools::GetImage ( 55*b9e67834SAndre Fischer const ::rtl::OUString& rsURL, 56*b9e67834SAndre Fischer const Reference<frame::XFrame>& rxFrame) 57*b9e67834SAndre Fischer { 58*b9e67834SAndre Fischer if (rsURL.getLength() > 0) 59*b9e67834SAndre Fischer { 60*b9e67834SAndre Fischer static const sal_Char* sUnoCommandPrefix = ".uno:"; 61*b9e67834SAndre Fischer static const sal_Int32 nUnoCommandPrefixLength = strlen(sUnoCommandPrefix); 62*b9e67834SAndre Fischer static const sal_Char* sCommandImagePrefix = "private:commandimage/"; 63*b9e67834SAndre Fischer static const sal_Int32 nCommandImagePrefixLength = strlen(sCommandImagePrefix); 64*b9e67834SAndre Fischer 65*b9e67834SAndre Fischer if (rsURL.compareToAscii(sUnoCommandPrefix, nUnoCommandPrefixLength) == 0) 66*b9e67834SAndre Fischer { 67*b9e67834SAndre Fischer const Image aPanelImage (::GetImage(rxFrame, rsURL, sal_False, Theme::IsHighContrastMode())); 68*b9e67834SAndre Fischer return aPanelImage; 69*b9e67834SAndre Fischer } 70*b9e67834SAndre Fischer else if (rsURL.compareToAscii(sCommandImagePrefix, nCommandImagePrefixLength) == 0) 71*b9e67834SAndre Fischer { 72*b9e67834SAndre Fischer ::rtl::OUStringBuffer aCommandName; 73*b9e67834SAndre Fischer aCommandName.appendAscii(sUnoCommandPrefix); 74*b9e67834SAndre Fischer aCommandName.append(rsURL.copy(nCommandImagePrefixLength)); 75*b9e67834SAndre Fischer const ::rtl::OUString sCommandName (aCommandName.makeStringAndClear()); 76*b9e67834SAndre Fischer 77*b9e67834SAndre Fischer const Image aPanelImage (::GetImage(rxFrame, sCommandName, sal_False, Theme::IsHighContrastMode())); 78*b9e67834SAndre Fischer return aPanelImage; 79*b9e67834SAndre Fischer } 80*b9e67834SAndre Fischer else 81*b9e67834SAndre Fischer { 82*b9e67834SAndre Fischer const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); 83*b9e67834SAndre Fischer const Reference<graphic::XGraphicProvider> xGraphicProvider ( 84*b9e67834SAndre Fischer aContext.createComponent("com.sun.star.graphic.GraphicProvider"), 85*b9e67834SAndre Fischer UNO_QUERY); 86*b9e67834SAndre Fischer if ( xGraphicProvider.is()) 87*b9e67834SAndre Fischer { 88*b9e67834SAndre Fischer ::comphelper::NamedValueCollection aMediaProperties; 89*b9e67834SAndre Fischer aMediaProperties.put("URL", rsURL); 90*b9e67834SAndre Fischer const Reference<graphic::XGraphic> xGraphic ( 91*b9e67834SAndre Fischer xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()), 92*b9e67834SAndre Fischer UNO_QUERY); 93*b9e67834SAndre Fischer if (xGraphic.is()) 94*b9e67834SAndre Fischer return Image(xGraphic); 95*b9e67834SAndre Fischer } 96*b9e67834SAndre Fischer } 97*b9e67834SAndre Fischer } 98*b9e67834SAndre Fischer return Image(); 99*b9e67834SAndre Fischer } 100*b9e67834SAndre Fischer 101*b9e67834SAndre Fischer 102*b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar 103