1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <comphelper/servicedecl.hxx>
28cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
29cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicObject.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
31cdf0e10cSrcweir #include <svtools/grfmgr.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace com::sun::star;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace unographic {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< graphic::XGraphicObject > GObjectAccess_BASE;
38cdf0e10cSrcweir  // Simple uno wrapper around the GraphicObject class to allow basic
39cdf0e10cSrcweir  // access. ( and solves a horrible cyclic link problem between
40cdf0e10cSrcweir  // goodies/toolkit/extensions )
41cdf0e10cSrcweir class GObjectImpl : public GObjectAccess_BASE
42cdf0e10cSrcweir {
43cdf0e10cSrcweir      ::osl::Mutex m_aMutex;
44cdf0e10cSrcweir      std::auto_ptr< GraphicObject > mpGObject;
45cdf0e10cSrcweir public:
46cdf0e10cSrcweir      GObjectImpl( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & xComponentContext ) throw (uno::RuntimeException);
47cdf0e10cSrcweir 
48cdf0e10cSrcweir      // XGraphicObject
49cdf0e10cSrcweir     virtual uno::Reference< graphic::XGraphic > SAL_CALL getGraphic() throw (uno::RuntimeException);
50cdf0e10cSrcweir     virtual void SAL_CALL setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException);
51cdf0e10cSrcweir     ::rtl::OUString SAL_CALL getUniqueID() throw (uno::RuntimeException);
52cdf0e10cSrcweir };
53cdf0e10cSrcweir 
GObjectImpl(uno::Sequence<uno::Any> const & args,uno::Reference<uno::XComponentContext> const &)54cdf0e10cSrcweir GObjectImpl::GObjectImpl( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & /*xComponentContext*/ ) throw (uno::RuntimeException)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir     if ( args.getLength() == 1 )
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir         rtl::OUString sId;
59cdf0e10cSrcweir         if ( !( args[ 0 ] >>= sId ) || sId.getLength() == 0 )
60cdf0e10cSrcweir             throw lang::IllegalArgumentException();
61cdf0e10cSrcweir         ByteString bsId( sId.getStr(), RTL_TEXTENCODING_UTF8 );
62cdf0e10cSrcweir         mpGObject.reset( new GraphicObject( bsId ) );
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir     else
65cdf0e10cSrcweir        mpGObject.reset( new GraphicObject() );
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
getGraphic()68cdf0e10cSrcweir uno::Reference< graphic::XGraphic > SAL_CALL GObjectImpl::getGraphic() throw (uno::RuntimeException)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
71cdf0e10cSrcweir     if ( !mpGObject.get() )
72cdf0e10cSrcweir         throw uno::RuntimeException();
73cdf0e10cSrcweir     return mpGObject->GetGraphic().GetXGraphic();
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
setGraphic(const uno::Reference<graphic::XGraphic> & _graphic)76cdf0e10cSrcweir void SAL_CALL GObjectImpl::setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
79cdf0e10cSrcweir     if ( !mpGObject.get() )
80cdf0e10cSrcweir         throw uno::RuntimeException();
81cdf0e10cSrcweir     Graphic aGraphic( _graphic );
82cdf0e10cSrcweir     mpGObject->SetGraphic( aGraphic );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
getUniqueID()85cdf0e10cSrcweir ::rtl::OUString SAL_CALL GObjectImpl::getUniqueID() throw (uno::RuntimeException)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
88cdf0e10cSrcweir     rtl::OUString sId;
89cdf0e10cSrcweir     if ( mpGObject.get() )
90cdf0e10cSrcweir         sId = String( mpGObject->GetUniqueID().GetBuffer(), RTL_TEXTENCODING_ASCII_US );
91cdf0e10cSrcweir     return sId;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir namespace sdecl = comphelper::service_decl;
96cdf0e10cSrcweir sdecl::class_<GObjectImpl, sdecl::with_args<true> > serviceBI;
97cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl( serviceBI, "com.sun.star.graphic.GraphicObject", "com.sun.star.graphic.GraphicObject" );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir }
100