Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/graphic/UnoGraphicObject.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
 * 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>
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>
28
29
using namespace css;
30
31
namespace {
32
33
typedef ::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 )
38
class GraphicObjectImpl : public GraphicObject_BASE
39
{
40
     std::mutex m_aMutex;
41
     std::optional<GraphicObject> mpGraphicObject;
42
43
public:
44
    /// @throws uno::RuntimeException
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
0
    {
53
0
        return u"com.sun.star.graphic.GraphicObject"_ustr;
54
0
    }
55
56
    virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
57
0
    {
58
0
        return cppu::supportsService(this, ServiceName);
59
0
    }
60
61
    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
62
0
    {
63
0
        return { u"com.sun.star.graphic.GraphicObject"_ustr };
64
0
    }
65
};
66
67
GraphicObjectImpl::GraphicObjectImpl(const uno::Sequence<uno::Any>& /*rArgs*/)
68
0
{
69
0
    mpGraphicObject.emplace();
70
0
}
71
72
uno::Reference<graphic::XGraphic> SAL_CALL GraphicObjectImpl::getGraphic()
73
0
{
74
0
    std::scoped_lock aGuard(m_aMutex);
75
76
0
    if (!mpGraphicObject)
77
0
        throw uno::RuntimeException();
78
0
    return mpGraphicObject->GetGraphic().GetXGraphic();
79
0
}
80
81
void SAL_CALL GraphicObjectImpl::setGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic)
82
0
{
83
0
    std::scoped_lock aGuard(m_aMutex);
84
85
0
    if (!mpGraphicObject)
86
0
        throw uno::RuntimeException();
87
0
    Graphic aGraphic(rxGraphic);
88
0
    mpGraphicObject->SetGraphic(aGraphic);
89
0
}
90
91
} // end anonymous namespace
92
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)
97
0
{
98
0
    return cppu::acquire(new GraphicObjectImpl(rArguments));
99
0
}
100
101
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */