Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
29 :
30 : #include <vcl/svapp.hxx>
31 :
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 : // -----------------------------------------------------------------------------
39 :
40 : SimpleResMgr* TkResMgr::m_pSimpleResMgr = NULL;
41 : ResMgr* TkResMgr::m_pResMgr = NULL;
42 :
43 : // -----------------------------------------------------------------------------
44 :
45 0 : TkResMgr::EnsureDelete::~EnsureDelete()
46 : {
47 0 : delete TkResMgr::m_pSimpleResMgr;
48 : // delete TkResMgr::m_pResMgr;
49 0 : }
50 :
51 : // -----------------------------------------------------------------------------
52 :
53 0 : void TkResMgr::ensureImplExists()
54 : {
55 0 : if (m_pSimpleResMgr)
56 0 : return;
57 :
58 0 : ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
59 :
60 0 : m_pSimpleResMgr = SimpleResMgr::Create( "tk", aLocale );
61 0 : m_pResMgr = ResMgr::CreateResMgr( "tk" );
62 :
63 0 : if (m_pSimpleResMgr)
64 : {
65 : // now that we have a impl class, make sure it's deleted on unloading the library
66 0 : static TkResMgr::EnsureDelete s_aDeleteTheImplClass;
67 0 : }
68 : }
69 :
70 : // -----------------------------------------------------------------------------
71 0 : ::rtl::OUString TkResMgr::loadString( sal_uInt16 nResId )
72 : {
73 0 : ::rtl::OUString sReturn;
74 :
75 0 : ensureImplExists();
76 0 : if ( m_pSimpleResMgr )
77 0 : sReturn = m_pSimpleResMgr->ReadString( nResId );
78 :
79 0 : return sReturn;
80 : }
81 :
82 : // -----------------------------------------------------------------------------
83 0 : Image TkResMgr::loadImage( sal_uInt16 nResId )
84 : {
85 0 : Image aReturn;
86 :
87 0 : ensureImplExists();
88 0 : if ( m_pResMgr )
89 0 : aReturn = Image( ResId( nResId, *m_pResMgr ) );
90 :
91 0 : return aReturn;
92 : }
93 :
94 : // -----------------------------------------------------------------------------
95 0 : Image TkResMgr::getImageFromURL( const ::rtl::OUString& i_rImageURL )
96 : {
97 0 : if ( i_rImageURL.isEmpty() )
98 0 : return Image();
99 :
100 : try
101 : {
102 0 : Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
103 0 : Reference< XGraphicProvider > xProvider( graphic::GraphicProvider::create(xContext) );
104 0 : ::comphelper::NamedValueCollection aMediaProperties;
105 0 : aMediaProperties.put( "URL", i_rImageURL );
106 0 : Reference< XGraphic > xGraphic = xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
107 0 : return Image( xGraphic );
108 : }
109 0 : catch( const uno::Exception& )
110 : {
111 : DBG_UNHANDLED_EXCEPTION();
112 : }
113 0 : return Image();
114 : }
115 :
116 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|