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>
21 #include <cppuhelper/implbase.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 
28 using namespace css;
29 
30 namespace {
31 
32 typedef ::cppu::WeakImplHelper<graphic::XGraphicObject, css::lang::XServiceInfo> GraphicObject_BASE;
33 
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
38 {
39  osl::Mutex m_aMutex;
40  std::unique_ptr<GraphicObject> mpGraphicObject;
41 
42 public:
44  explicit GraphicObjectImpl(uno::Sequence<uno::Any> const & rArgs);
45 
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;
49 
50  virtual OUString SAL_CALL getImplementationName() override
51  {
52  return "com.sun.star.graphic.GraphicObject";
53  }
54 
55  virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
56  {
57  return cppu::supportsService(this, ServiceName);
58  }
59 
60  virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
61  {
62  return uno::Sequence<OUString> { "com.sun.star.graphic.GraphicObject" };
63  }
64 };
65 
66 GraphicObjectImpl::GraphicObjectImpl(const uno::Sequence<uno::Any>& /*rArgs*/)
67 {
68  mpGraphicObject.reset(new GraphicObject());
69 }
70 
71 uno::Reference<graphic::XGraphic> SAL_CALL GraphicObjectImpl::getGraphic()
72 {
73  osl::MutexGuard aGuard(m_aMutex);
74 
75  if (!mpGraphicObject)
76  throw uno::RuntimeException();
77  return mpGraphicObject->GetGraphic().GetXGraphic();
78 }
79 
80 void SAL_CALL GraphicObjectImpl::setGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic)
81 {
82  osl::MutexGuard aGuard(m_aMutex);
83 
84  if (!mpGraphicObject)
85  throw uno::RuntimeException();
86  Graphic aGraphic(rxGraphic);
87  mpGraphicObject->SetGraphic(aGraphic);
88 }
89 
90 } // end anonymous namespace
91 
92 extern "C" SAL_DLLPUBLIC_EXPORT
94  SAL_UNUSED_PARAMETER uno::XComponentContext*,
95  uno::Sequence<uno::Any> const & rArguments)
96 {
97  return cppu::acquire(new GraphicObjectImpl(rArguments));
98 }
99 
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex m_aMutex
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::uno::Sequence< OUString > getSupportedServiceNames()
unsigned char sal_Bool
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_graphic_GraphicObject_get_implementation(SAL_UNUSED_PARAMETER uno::XComponentContext *, uno::Sequence< uno::Any > const &rArguments)