Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / toolkit / source / helper / tkresmgr.cxx
blobae197370a3551a5da42c640a191118d14ff82ec7
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 ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
60 m_pSimpleResMgr = SimpleResMgr::Create( "tk", aLocale );
61 m_pResMgr = ResMgr::CreateResMgr( "tk" );
63 if (m_pSimpleResMgr)
65 // now that we have a impl class, make sure it's deleted on unloading the library
66 static TkResMgr::EnsureDelete s_aDeleteTheImplClass;
70 // -----------------------------------------------------------------------------
71 ::rtl::OUString TkResMgr::loadString( sal_uInt16 nResId )
73 ::rtl::OUString sReturn;
75 ensureImplExists();
76 if ( m_pSimpleResMgr )
77 sReturn = m_pSimpleResMgr->ReadString( nResId );
79 return sReturn;
82 // -----------------------------------------------------------------------------
83 Image TkResMgr::loadImage( sal_uInt16 nResId )
85 Image aReturn;
87 ensureImplExists();
88 if ( m_pResMgr )
89 aReturn = Image( ResId( nResId, *m_pResMgr ) );
91 return aReturn;
94 // -----------------------------------------------------------------------------
95 Image TkResMgr::getImageFromURL( const ::rtl::OUString& i_rImageURL )
97 if ( i_rImageURL.isEmpty() )
98 return Image();
102 Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
103 Reference< XGraphicProvider > xProvider( graphic::GraphicProvider::create(xContext) );
104 ::comphelper::NamedValueCollection aMediaProperties;
105 aMediaProperties.put( "URL", i_rImageURL );
106 Reference< XGraphic > xGraphic = xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
107 return Image( xGraphic );
109 catch( const uno::Exception& )
111 DBG_UNHANDLED_EXCEPTION();
113 return Image();
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */