crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / vcl / source / graphic / UnoGraphicObject.cxx
blobb7700a391d4a2d429c95bb8ebcfcb6886158d277
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 <memory>
21 #include <cppuhelper/implbase.hxx>
22 #include <cppuhelper/supportsservice.hxx>
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>
29 using namespace css;
31 namespace {
33 typedef ::cppu::WeakImplHelper<graphic::XGraphicObject, css::lang::XServiceInfo> GraphicObject_BASE;
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 )
38 class GraphicObjectImpl : public GraphicObject_BASE
40 std::mutex m_aMutex;
41 std::optional<GraphicObject> mpGraphicObject;
43 public:
44 /// @throws uno::RuntimeException
45 explicit GraphicObjectImpl(uno::Sequence<uno::Any> const & rArgs);
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;
51 virtual OUString SAL_CALL getImplementationName() override
53 return u"com.sun.star.graphic.GraphicObject"_ustr;
56 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
58 return cppu::supportsService(this, ServiceName);
61 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
63 return { u"com.sun.star.graphic.GraphicObject"_ustr };
67 GraphicObjectImpl::GraphicObjectImpl(const uno::Sequence<uno::Any>& /*rArgs*/)
69 mpGraphicObject.emplace();
72 uno::Reference<graphic::XGraphic> SAL_CALL GraphicObjectImpl::getGraphic()
74 std::scoped_lock aGuard(m_aMutex);
76 if (!mpGraphicObject)
77 throw uno::RuntimeException();
78 return mpGraphicObject->GetGraphic().GetXGraphic();
81 void SAL_CALL GraphicObjectImpl::setGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic)
83 std::scoped_lock aGuard(m_aMutex);
85 if (!mpGraphicObject)
86 throw uno::RuntimeException();
87 Graphic aGraphic(rxGraphic);
88 mpGraphicObject->SetGraphic(aGraphic);
91 } // end anonymous namespace
93 extern "C" SAL_DLLPUBLIC_EXPORT
94 css::uno::XInterface* com_sun_star_graphic_GraphicObject_get_implementation(
95 SAL_UNUSED_PARAMETER uno::XComponentContext*,
96 uno::Sequence<uno::Any> const & rArguments)
98 return cppu::acquire(new GraphicObjectImpl(rArguments));
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */