Line data Source code
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 <cppuhelper/implbase2.hxx>
21 : #include <cppuhelper/supportsservice.hxx>
22 : #include <com/sun/star/graphic/XGraphicObject.hpp>
23 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
24 : #include <com/sun/star/lang/XServiceInfo.hpp>
25 : #include <com/sun/star/uno/XComponentContext.hpp>
26 : #include <svtools/grfmgr.hxx>
27 : #include <rtl/ref.hxx>
28 :
29 : using namespace com::sun::star;
30 :
31 : namespace {
32 :
33 : typedef ::cppu::WeakImplHelper2< graphic::XGraphicObject, css::lang::XServiceInfo > GObjectAccess_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 1968 : class GObjectImpl : public GObjectAccess_BASE
38 : {
39 : ::osl::Mutex m_aMutex;
40 : std::unique_ptr< GraphicObject > mpGObject;
41 : public:
42 : GObjectImpl(uno::Sequence< uno::Any > const & args) throw (uno::RuntimeException, std::exception);
43 :
44 : // XGraphicObject
45 : virtual uno::Reference< graphic::XGraphic > SAL_CALL getGraphic() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
46 : virtual void SAL_CALL setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
47 : OUString SAL_CALL getUniqueID() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
48 :
49 0 : virtual OUString SAL_CALL getImplementationName()
50 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
51 : {
52 0 : return OUString("com.sun.star.graphic.GraphicObject");
53 : }
54 :
55 0 : virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
56 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
57 : {
58 0 : return cppu::supportsService(this, ServiceName);
59 : }
60 :
61 0 : virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
62 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
63 : {
64 0 : uno::Sequence< OUString > aRet(1);
65 0 : OUString* pArray = aRet.getArray();
66 0 : pArray[0] = OUString("com.sun.star.graphic.GraphicObject");
67 0 : return aRet;
68 : }
69 : };
70 :
71 984 : GObjectImpl::GObjectImpl(const uno::Sequence< uno::Any >& args) throw (uno::RuntimeException, std::exception)
72 : {
73 984 : if ( args.getLength() == 1 )
74 : {
75 0 : OUString sId;
76 0 : if ( !( args[ 0 ] >>= sId ) || sId.isEmpty() )
77 0 : throw lang::IllegalArgumentException();
78 0 : OString bsId(OUStringToOString(sId, RTL_TEXTENCODING_UTF8));
79 0 : mpGObject.reset( new GraphicObject( bsId ) );
80 : }
81 : else
82 984 : mpGObject.reset( new GraphicObject() );
83 984 : }
84 :
85 0 : uno::Reference< graphic::XGraphic > SAL_CALL GObjectImpl::getGraphic() throw (uno::RuntimeException, std::exception)
86 : {
87 0 : ::osl::MutexGuard aGuard( m_aMutex );
88 0 : if ( !mpGObject.get() )
89 0 : throw uno::RuntimeException();
90 0 : return mpGObject->GetGraphic().GetXGraphic();
91 : }
92 :
93 982 : void SAL_CALL GObjectImpl::setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException, std::exception)
94 : {
95 982 : ::osl::MutexGuard aGuard( m_aMutex );
96 982 : if ( !mpGObject.get() )
97 0 : throw uno::RuntimeException();
98 1964 : Graphic aGraphic( _graphic );
99 1964 : mpGObject->SetGraphic( aGraphic );
100 982 : }
101 :
102 980 : OUString SAL_CALL GObjectImpl::getUniqueID() throw (uno::RuntimeException, std::exception)
103 : {
104 980 : ::osl::MutexGuard aGuard( m_aMutex );
105 980 : OUString sId;
106 980 : if ( mpGObject.get() )
107 980 : sId = OStringToOUString(mpGObject->GetUniqueID(), RTL_TEXTENCODING_ASCII_US);
108 980 : return sId;
109 : }
110 :
111 : }
112 :
113 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
114 984 : com_sun_star_graphic_GraphicObject_get_implementation(
115 : SAL_UNUSED_PARAMETER css::uno::XComponentContext *,
116 : css::uno::Sequence<css::uno::Any> const &arguments)
117 : {
118 984 : return cppu::acquire(new GObjectImpl(arguments));
119 1227 : }
120 :
121 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|