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