bump product version to 4.1.6.2
[LibreOffice.git] / toolkit / source / helper / tkresmgr.cxx
blob1d788efe5c64437acce7703058d1b92e992c85d6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <toolkit/helper/tkresmgr.hxx>
21 #include <tools/simplerm.hxx>
22 #include <comphelper/processfactory.hxx>
23 #include <comphelper/componentcontext.hxx>
24 #include <comphelper/namedvaluecollection.hxx>
25 #include <com/sun/star/graphic/GraphicProvider.hpp>
26 #include <com/sun/star/graphic/XGraphicProvider.hpp>
27 #include <tools/resmgr.hxx>
28 #include <tools/diagnose_ex.h>
30 #include <vcl/svapp.hxx>
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::graphic::XGraphic;
34 using ::com::sun::star::graphic::XGraphicProvider;
35 using namespace ::com::sun::star;
36 // -----------------------------------------------------------------------------
37 // TkResMgr
38 // -----------------------------------------------------------------------------
40 SimpleResMgr* TkResMgr::m_pSimpleResMgr = NULL;
41 ResMgr* TkResMgr::m_pResMgr = NULL;
43 // -----------------------------------------------------------------------------
45 TkResMgr::EnsureDelete::~EnsureDelete()
47 delete TkResMgr::m_pSimpleResMgr;
48 // delete TkResMgr::m_pResMgr;
51 // -----------------------------------------------------------------------------
53 void TkResMgr::ensureImplExists()
55 if (m_pSimpleResMgr)
56 return;
58 m_pSimpleResMgr = SimpleResMgr::Create( "tk", Application::GetSettings().GetUILanguageTag() );
59 m_pResMgr = ResMgr::CreateResMgr( "tk" );
61 if (m_pSimpleResMgr)
63 // now that we have a impl class, make sure it's deleted on unloading the library
64 static TkResMgr::EnsureDelete s_aDeleteTheImplClass;
68 // -----------------------------------------------------------------------------
69 OUString TkResMgr::loadString( sal_uInt16 nResId )
71 OUString sReturn;
73 ensureImplExists();
74 if ( m_pSimpleResMgr )
75 sReturn = m_pSimpleResMgr->ReadString( nResId );
77 return sReturn;
80 // -----------------------------------------------------------------------------
81 Image TkResMgr::loadImage( sal_uInt16 nResId )
83 Image aReturn;
85 ensureImplExists();
86 if ( m_pResMgr )
87 aReturn = Image( ResId( nResId, *m_pResMgr ) );
89 return aReturn;
92 // -----------------------------------------------------------------------------
93 Image TkResMgr::getImageFromURL( const OUString& i_rImageURL )
95 if ( i_rImageURL.isEmpty() )
96 return Image();
98 try
100 Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
101 Reference< XGraphicProvider > xProvider( graphic::GraphicProvider::create(xContext) );
102 ::comphelper::NamedValueCollection aMediaProperties;
103 aMediaProperties.put( "URL", i_rImageURL );
104 Reference< XGraphic > xGraphic = xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
105 return Image( xGraphic );
107 catch( const uno::Exception& )
109 DBG_UNHANDLED_EXCEPTION();
111 return Image();
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */