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 .
21 #include <comphelper/servicedecl.hxx>
22 #include <cppuhelper/implbase1.hxx>
23 #include <com/sun/star/graphic/XGraphicObject.hpp>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <svtools/grfmgr.hxx>
27 using namespace com::sun::star
;
29 namespace unographic
{
31 typedef ::cppu::WeakImplHelper1
< graphic::XGraphicObject
> GObjectAccess_BASE
;
32 // Simple uno wrapper around the GraphicObject class to allow basic
33 // access. ( and solves a horrible cyclic link problem between
34 // goodies/toolkit/extensions )
35 class GObjectImpl
: public GObjectAccess_BASE
37 ::osl::Mutex m_aMutex
;
38 std::auto_ptr
< GraphicObject
> mpGObject
;
40 GObjectImpl( uno::Sequence
< uno::Any
> const & args
, uno::Reference
< uno::XComponentContext
> const & xComponentContext
) throw (uno::RuntimeException
);
43 virtual uno::Reference
< graphic::XGraphic
> SAL_CALL
getGraphic() throw (uno::RuntimeException
);
44 virtual void SAL_CALL
setGraphic( const uno::Reference
< graphic::XGraphic
>& _graphic
) throw (uno::RuntimeException
);
45 ::rtl::OUString SAL_CALL
getUniqueID() throw (uno::RuntimeException
);
48 GObjectImpl::GObjectImpl( uno::Sequence
< uno::Any
> const & args
, uno::Reference
< uno::XComponentContext
> const & /*xComponentContext*/ ) throw (uno::RuntimeException
)
50 if ( args
.getLength() == 1 )
53 if ( !( args
[ 0 ] >>= sId
) || sId
.isEmpty() )
54 throw lang::IllegalArgumentException();
55 rtl::OString
bsId(rtl::OUStringToOString(sId
, RTL_TEXTENCODING_UTF8
));
56 mpGObject
.reset( new GraphicObject( bsId
) );
59 mpGObject
.reset( new GraphicObject() );
62 uno::Reference
< graphic::XGraphic
> SAL_CALL
GObjectImpl::getGraphic() throw (uno::RuntimeException
)
64 ::osl::MutexGuard
aGuard( m_aMutex
);
65 if ( !mpGObject
.get() )
66 throw uno::RuntimeException();
67 return mpGObject
->GetGraphic().GetXGraphic();
70 void SAL_CALL
GObjectImpl::setGraphic( const uno::Reference
< graphic::XGraphic
>& _graphic
) throw (uno::RuntimeException
)
72 ::osl::MutexGuard
aGuard( m_aMutex
);
73 if ( !mpGObject
.get() )
74 throw uno::RuntimeException();
75 Graphic
aGraphic( _graphic
);
76 mpGObject
->SetGraphic( aGraphic
);
79 ::rtl::OUString SAL_CALL
GObjectImpl::getUniqueID() throw (uno::RuntimeException
)
81 ::osl::MutexGuard
aGuard( m_aMutex
);
83 if ( mpGObject
.get() )
84 sId
= rtl::OStringToOUString(mpGObject
->GetUniqueID(), RTL_TEXTENCODING_ASCII_US
);
89 namespace sdecl
= comphelper::service_decl
;
90 sdecl::class_
<GObjectImpl
, sdecl::with_args
<true> > serviceBI
;
91 extern sdecl::ServiceDecl
const serviceDecl( serviceBI
, "com.sun.star.graphic.GraphicObject", "com.sun.star.graphic.GraphicObject" );
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */