LibreOffice Module vcl (master) 1
UnoGraphicObject.cxx
Go to the documentation of this file.
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 <memory>
23#include <com/sun/star/graphic/XGraphicObject.hpp>
24#include <com/sun/star/lang/XServiceInfo.hpp>
25#include <com/sun/star/uno/XComponentContext.hpp>
26#include <vcl/GraphicObject.hxx>
27#include <mutex>
28
29using namespace css;
30
31namespace {
32
33typedef ::cppu::WeakImplHelper<graphic::XGraphicObject, css::lang::XServiceInfo> GraphicObject_BASE;
34
35 // Simple uno wrapper around the GraphicObject class to allow basic
36 // access. ( and solves a horrible cyclic link problem between
37 // goodies/toolkit/extensions )
38class GraphicObjectImpl : public GraphicObject_BASE
39{
40 std::mutex m_aMutex;
41 std::optional<GraphicObject> mpGraphicObject;
42
43public:
45 explicit GraphicObjectImpl(uno::Sequence<uno::Any> const & rArgs);
46
47 // XGraphicObject
48 virtual uno::Reference<graphic::XGraphic> SAL_CALL getGraphic() override;
49 virtual void SAL_CALL setGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic) override;
50
51 virtual OUString SAL_CALL getImplementationName() override
52 {
53 return "com.sun.star.graphic.GraphicObject";
54 }
55
56 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
57 {
58 return cppu::supportsService(this, ServiceName);
59 }
60
61 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
62 {
63 return { "com.sun.star.graphic.GraphicObject" };
64 }
65};
66
67GraphicObjectImpl::GraphicObjectImpl(const uno::Sequence<uno::Any>& /*rArgs*/)
68{
69 mpGraphicObject.emplace();
70}
71
72uno::Reference<graphic::XGraphic> SAL_CALL GraphicObjectImpl::getGraphic()
73{
74 std::scoped_lock aGuard(m_aMutex);
75
76 if (!mpGraphicObject)
77 throw uno::RuntimeException();
78 return mpGraphicObject->GetGraphic().GetXGraphic();
79}
80
81void SAL_CALL GraphicObjectImpl::setGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic)
82{
83 std::scoped_lock aGuard(m_aMutex);
84
85 if (!mpGraphicObject)
86 throw uno::RuntimeException();
87 Graphic aGraphic(rxGraphic);
88 mpGraphicObject->SetGraphic(aGraphic);
89}
90
91} // end anonymous namespace
92
93extern "C" SAL_DLLPUBLIC_EXPORT
95 SAL_UNUSED_PARAMETER uno::XComponentContext*,
96 uno::Sequence<uno::Any> const & rArguments)
97{
98 return cppu::acquire(new GraphicObjectImpl(rArguments));
99}
100
101/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_graphic_GraphicObject_get_implementation(SAL_UNUSED_PARAMETER uno::XComponentContext *, uno::Sequence< uno::Any > const &rArguments)
std::mutex m_aMutex
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool