Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / graphic / UnoGraphicObject.cxx
blobbab6bffe5beb9c87f2b001c834c3ec338c330661
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>
28 using namespace css;
30 namespace {
32 typedef ::cppu::WeakImplHelper<graphic::XGraphicObject, css::lang::XServiceInfo> GraphicObject_BASE;
34 // Simple uno wrapper around the GraphicObject class to allow basic
35 // access. ( and solves a horrible cyclic link problem between
36 // goodies/toolkit/extensions )
37 class GraphicObjectImpl : public GraphicObject_BASE
39 osl::Mutex m_aMutex;
40 std::unique_ptr<GraphicObject> mpGraphicObject;
42 public:
43 /// @throws uno::RuntimeException
44 explicit GraphicObjectImpl(uno::Sequence<uno::Any> const & rArgs);
46 // XGraphicObject
47 virtual uno::Reference<graphic::XGraphic> SAL_CALL getGraphic() override;
48 virtual void SAL_CALL setGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic) override;
50 virtual OUString SAL_CALL getImplementationName() override
52 return "com.sun.star.graphic.GraphicObject";
55 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
57 return cppu::supportsService(this, ServiceName);
60 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
62 return uno::Sequence<OUString> { "com.sun.star.graphic.GraphicObject" };
66 GraphicObjectImpl::GraphicObjectImpl(const uno::Sequence<uno::Any>& /*rArgs*/)
68 mpGraphicObject.reset(new GraphicObject());
71 uno::Reference<graphic::XGraphic> SAL_CALL GraphicObjectImpl::getGraphic()
73 osl::MutexGuard aGuard(m_aMutex);
75 if (!mpGraphicObject)
76 throw uno::RuntimeException();
77 return mpGraphicObject->GetGraphic().GetXGraphic();
80 void SAL_CALL GraphicObjectImpl::setGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic)
82 osl::MutexGuard aGuard(m_aMutex);
84 if (!mpGraphicObject)
85 throw uno::RuntimeException();
86 Graphic aGraphic(rxGraphic);
87 mpGraphicObject->SetGraphic(aGraphic);
90 } // end anonymous namespace
92 extern "C" SAL_DLLPUBLIC_EXPORT
93 css::uno::XInterface* com_sun_star_graphic_GraphicObject_get_implementation(
94 SAL_UNUSED_PARAMETER uno::XComponentContext*,
95 uno::Sequence<uno::Any> const & rArguments)
97 return cppu::acquire(new GraphicObjectImpl(rArguments));
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */