1*b0724fc6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b0724fc6SAndrew Rist * distributed with this work for additional information 6*b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance 9*b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b0724fc6SAndrew Rist * software distributed under the License is distributed on an 15*b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the 17*b0724fc6SAndrew Rist * specific language governing permissions and limitations 18*b0724fc6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b0724fc6SAndrew Rist *************************************************************/ 21*b0724fc6SAndrew Rist 22*b0724fc6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 26cdf0e10cSrcweir #include <toolkit/helper/tkresmgr.hxx> 27cdf0e10cSrcweir #include <tools/simplerm.hxx> 28cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 29cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 30cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 31cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicProvider.hpp> 32cdf0e10cSrcweir #ifndef _TOOLS_RESMGR_HXX_ 33cdf0e10cSrcweir #include <tools/resmgr.hxx> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #include <tools/diagnose_ex.h> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <vcl/svapp.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 40cdf0e10cSrcweir using ::com::sun::star::graphic::XGraphic; 41cdf0e10cSrcweir using ::com::sun::star::graphic::XGraphicProvider; 42cdf0e10cSrcweir using namespace ::com::sun::star; 43cdf0e10cSrcweir // ----------------------------------------------------------------------------- 44cdf0e10cSrcweir // TkResMgr 45cdf0e10cSrcweir // ----------------------------------------------------------------------------- 46cdf0e10cSrcweir 47cdf0e10cSrcweir SimpleResMgr* TkResMgr::m_pSimpleResMgr = NULL; 48cdf0e10cSrcweir ResMgr* TkResMgr::m_pResMgr = NULL; 49cdf0e10cSrcweir 50cdf0e10cSrcweir // ----------------------------------------------------------------------------- 51cdf0e10cSrcweir 52cdf0e10cSrcweir TkResMgr::EnsureDelete::~EnsureDelete() 53cdf0e10cSrcweir { 54cdf0e10cSrcweir delete TkResMgr::m_pSimpleResMgr; 55cdf0e10cSrcweir // delete TkResMgr::m_pResMgr; 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir // ----------------------------------------------------------------------------- 59cdf0e10cSrcweir 60cdf0e10cSrcweir void TkResMgr::ensureImplExists() 61cdf0e10cSrcweir { 62cdf0e10cSrcweir if (m_pSimpleResMgr) 63cdf0e10cSrcweir return; 64cdf0e10cSrcweir 65cdf0e10cSrcweir ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale(); 66cdf0e10cSrcweir 67cdf0e10cSrcweir ByteString sResMgrName( "tk" ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir m_pSimpleResMgr = SimpleResMgr::Create( sResMgrName.GetBuffer(), aLocale ); 70cdf0e10cSrcweir m_pResMgr = ResMgr::CreateResMgr( sResMgrName.GetBuffer() ); 71cdf0e10cSrcweir 72cdf0e10cSrcweir if (m_pSimpleResMgr) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir // now that we have a impl class, make sure it's deleted on unloading the library 75cdf0e10cSrcweir static TkResMgr::EnsureDelete s_aDeleteTheImplClass; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir // ----------------------------------------------------------------------------- 80cdf0e10cSrcweir ::rtl::OUString TkResMgr::loadString( sal_uInt16 nResId ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir ::rtl::OUString sReturn; 83cdf0e10cSrcweir 84cdf0e10cSrcweir ensureImplExists(); 85cdf0e10cSrcweir if ( m_pSimpleResMgr ) 86cdf0e10cSrcweir sReturn = m_pSimpleResMgr->ReadString( nResId ); 87cdf0e10cSrcweir 88cdf0e10cSrcweir return sReturn; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir // ----------------------------------------------------------------------------- 92cdf0e10cSrcweir Image TkResMgr::loadImage( sal_uInt16 nResId ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir Image aReturn; 95cdf0e10cSrcweir 96cdf0e10cSrcweir ensureImplExists(); 97cdf0e10cSrcweir if ( m_pResMgr ) 98cdf0e10cSrcweir aReturn = Image( ResId( nResId, *m_pResMgr ) ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir return aReturn; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir // ----------------------------------------------------------------------------- 104cdf0e10cSrcweir Image TkResMgr::getImageFromURL( const ::rtl::OUString& i_rImageURL ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir if ( !i_rImageURL.getLength() ) 107cdf0e10cSrcweir return Image(); 108cdf0e10cSrcweir 109cdf0e10cSrcweir try 110cdf0e10cSrcweir { 111cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 112cdf0e10cSrcweir Reference< XGraphicProvider > xProvider; 113cdf0e10cSrcweir if ( aContext.createComponent( "com.sun.star.graphic.GraphicProvider", xProvider ) ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir ::comphelper::NamedValueCollection aMediaProperties; 116cdf0e10cSrcweir aMediaProperties.put( "URL", i_rImageURL ); 117cdf0e10cSrcweir Reference< XGraphic > xGraphic = xProvider->queryGraphic( aMediaProperties.getPropertyValues() ); 118cdf0e10cSrcweir return Image( xGraphic ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir } 121cdf0e10cSrcweir catch( const uno::Exception& ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir return Image(); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128