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 1126 : class GObjectImpl : public GObjectAccess_BASE
38 : {
39 : ::osl::Mutex m_aMutex;
40 : std::unique_ptr< GraphicObject > mpGObject;
41 : public:
42 : explicit 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 1 : virtual OUString SAL_CALL getImplementationName()
50 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
51 : {
52 1 : 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 1 : virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
62 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
63 : {
64 1 : uno::Sequence< OUString > aRet(1);
65 1 : OUString* pArray = aRet.getArray();
66 1 : pArray[0] = "com.sun.star.graphic.GraphicObject";
67 1 : return aRet;
68 : }
69 : };
70 :
71 563 : GObjectImpl::GObjectImpl(const uno::Sequence< uno::Any >& args) throw (uno::RuntimeException, std::exception)
72 : {
73 563 : 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 563 : mpGObject.reset( new GraphicObject() );
83 563 : }
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 562 : void SAL_CALL GObjectImpl::setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException, std::exception)
94 : {
95 562 : ::osl::MutexGuard aGuard( m_aMutex );
96 562 : if ( !mpGObject.get() )
97 0 : throw uno::RuntimeException();
98 1124 : Graphic aGraphic( _graphic );
99 1124 : mpGObject->SetGraphic( aGraphic );
100 562 : }
101 :
102 561 : OUString SAL_CALL GObjectImpl::getUniqueID() throw (uno::RuntimeException, std::exception)
103 : {
104 561 : ::osl::MutexGuard aGuard( m_aMutex );
105 561 : OUString sId;
106 561 : if ( mpGObject.get() )
107 561 : sId = OStringToOUString(mpGObject->GetUniqueID(), RTL_TEXTENCODING_ASCII_US);
108 561 : return sId;
109 : }
110 :
111 : }
112 :
113 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
114 563 : 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 563 : return cppu::acquire(new GObjectImpl(arguments));
119 : }
120 :
121 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|