1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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>
29 using namespace com::sun::star
;
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 class GObjectImpl
: public GObjectAccess_BASE
39 ::osl::Mutex m_aMutex
;
40 std::unique_ptr
< GraphicObject
> mpGObject
;
42 GObjectImpl(uno::Sequence
< uno::Any
> const & args
) throw (uno::RuntimeException
, std::exception
);
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
;
49 virtual OUString SAL_CALL
getImplementationName()
50 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
52 return OUString("com.sun.star.graphic.GraphicObject");
55 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
)
56 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
58 return cppu::supportsService(this, ServiceName
);
61 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames()
62 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
64 uno::Sequence
< OUString
> aRet(1);
65 OUString
* pArray
= aRet
.getArray();
66 pArray
[0] = "com.sun.star.graphic.GraphicObject";
71 GObjectImpl::GObjectImpl(const uno::Sequence
< uno::Any
>& args
) throw (uno::RuntimeException
, std::exception
)
73 if ( args
.getLength() == 1 )
76 if ( !( args
[ 0 ] >>= sId
) || sId
.isEmpty() )
77 throw lang::IllegalArgumentException();
78 OString
bsId(OUStringToOString(sId
, RTL_TEXTENCODING_UTF8
));
79 mpGObject
.reset( new GraphicObject( bsId
) );
82 mpGObject
.reset( new GraphicObject() );
85 uno::Reference
< graphic::XGraphic
> SAL_CALL
GObjectImpl::getGraphic() throw (uno::RuntimeException
, std::exception
)
87 ::osl::MutexGuard
aGuard( m_aMutex
);
88 if ( !mpGObject
.get() )
89 throw uno::RuntimeException();
90 return mpGObject
->GetGraphic().GetXGraphic();
93 void SAL_CALL
GObjectImpl::setGraphic( const uno::Reference
< graphic::XGraphic
>& _graphic
) throw (uno::RuntimeException
, std::exception
)
95 ::osl::MutexGuard
aGuard( m_aMutex
);
96 if ( !mpGObject
.get() )
97 throw uno::RuntimeException();
98 Graphic
aGraphic( _graphic
);
99 mpGObject
->SetGraphic( aGraphic
);
102 OUString SAL_CALL
GObjectImpl::getUniqueID() throw (uno::RuntimeException
, std::exception
)
104 ::osl::MutexGuard
aGuard( m_aMutex
);
106 if ( mpGObject
.get() )
107 sId
= OStringToOUString(mpGObject
->GetUniqueID(), RTL_TEXTENCODING_ASCII_US
);
113 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
114 com_sun_star_graphic_GraphicObject_get_implementation(
115 SAL_UNUSED_PARAMETER
css::uno::XComponentContext
*,
116 css::uno::Sequence
<css::uno::Any
> const &arguments
)
118 return cppu::acquire(new GObjectImpl(arguments
));
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */