/src/libreoffice/vcl/source/graphic/UnoGraphicMapper.cxx
Line | Count | Source |
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 | | |
10 | | #include <com/sun/star/uno/XComponentContext.hpp> |
11 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
12 | | #include <com/sun/star/graphic/XGraphicMapper.hpp> |
13 | | #include <com/sun/star/graphic/XGraphic.hpp> |
14 | | #include <cppuhelper/implbase.hxx> |
15 | | #include <cppuhelper/supportsservice.hxx> |
16 | | #include <comphelper/unique_disposing_ptr.hxx> |
17 | | |
18 | | #include <memory> |
19 | | #include <unordered_map> |
20 | | |
21 | | using namespace css; |
22 | | |
23 | | namespace |
24 | | { |
25 | | class GraphicMapper : public cppu::WeakImplHelper<graphic::XGraphicMapper, lang::XServiceInfo> |
26 | | { |
27 | | private: |
28 | | std::unordered_map<OUString, uno::Reference<graphic::XGraphic>> maGraphicMap; |
29 | | |
30 | | public: |
31 | 7.12k | GraphicMapper() = default; |
32 | | |
33 | | protected: |
34 | | // XServiceInfo |
35 | | OUString SAL_CALL getImplementationName() override |
36 | 0 | { |
37 | 0 | return u"com.sun.star.comp.graphic.GraphicMapper"_ustr; |
38 | 0 | } |
39 | | sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override |
40 | 0 | { |
41 | 0 | return cppu::supportsService(this, ServiceName); |
42 | 0 | } |
43 | | css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override |
44 | 0 | { |
45 | 0 | return { u"com.sun.star.graphic.GraphicMapper"_ustr }; |
46 | 0 | } |
47 | | |
48 | | // XTypeProvider |
49 | | css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override |
50 | 0 | { |
51 | 0 | static const uno::Sequence<uno::Type> aTypes{ |
52 | 0 | cppu::UnoType<lang::XServiceInfo>::get(), cppu::UnoType<lang::XTypeProvider>::get(), |
53 | 0 | cppu::UnoType<graphic::XGraphicMapper>::get() |
54 | 0 | }; |
55 | 0 | return aTypes; |
56 | 0 | } |
57 | | css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override |
58 | 0 | { |
59 | 0 | return css::uno::Sequence<sal_Int8>(); |
60 | 0 | } |
61 | | |
62 | | // XGraphicMapper |
63 | | css::uno::Reference<css::graphic::XGraphic> SAL_CALL findGraphic(const OUString& rId) override |
64 | 4.83k | { |
65 | 4.83k | auto aIterator = maGraphicMap.find(rId); |
66 | | |
67 | 4.83k | if (aIterator == maGraphicMap.end()) |
68 | 2.31k | return css::uno::Reference<css::graphic::XGraphic>(); |
69 | | |
70 | 2.52k | return aIterator->second; |
71 | 4.83k | } |
72 | | void SAL_CALL putGraphic(const OUString& rId, |
73 | | css::uno::Reference<css::graphic::XGraphic> const& rGraphic) override |
74 | 1.00k | { |
75 | 1.00k | maGraphicMap.emplace(rId, rGraphic); |
76 | 1.00k | } |
77 | | }; |
78 | | } |
79 | | |
80 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
81 | | com_sun_star_comp_graphic_GraphicMapper_get_implementation(css::uno::XComponentContext*, |
82 | | css::uno::Sequence<css::uno::Any> const&) |
83 | 7.12k | { |
84 | 7.12k | return cppu::acquire(new GraphicMapper); |
85 | 7.12k | } |
86 | | |
87 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |