Update ooo320-m1
[ooovba.git] / goodies / source / unographic / graphicunofactory.cxx
blob6998768240da255fc3f1287e3c0779ae593a43f8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: graphicunofactory.cxx,v $
10 * $Revision: 1.1.2.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_goodies.hxx"
34 #include <comphelper/servicedecl.hxx>
35 #include <cppuhelper/implbase1.hxx>
36 #include <com/sun/star/graphic/XGraphicObject.hpp>
37 #include <com/sun/star/lang/IllegalArgumentException.hpp>
38 #include "grfmgr.hxx"
40 using namespace com::sun::star;
42 namespace unographic {
44 typedef ::cppu::WeakImplHelper1< graphic::XGraphicObject > GObjectAccess_BASE;
45 // Simple uno wrapper around the GraphicObject class to allow basic
46 // access. ( and solves a horrible cyclic link problem between
47 // goodies/toolkit/extensions )
48 class GObjectImpl : public GObjectAccess_BASE
50 ::osl::Mutex m_aMutex;
51 std::auto_ptr< GraphicObject > mpGObject;
52 public:
53 GObjectImpl( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & xComponentContext ) throw (uno::RuntimeException);
55 // XGraphicObject
56 virtual uno::Reference< graphic::XGraphic > SAL_CALL getGraphic() throw (uno::RuntimeException);
57 virtual void SAL_CALL setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException);
58 ::rtl::OUString SAL_CALL getUniqueID() throw (uno::RuntimeException);
61 GObjectImpl::GObjectImpl( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & /*xComponentContext*/ ) throw (uno::RuntimeException)
63 if ( args.getLength() == 1 )
65 rtl::OUString sId;
66 if ( !( args[ 0 ] >>= sId ) || sId.getLength() == 0 )
67 throw lang::IllegalArgumentException();
68 ByteString bsId( sId.getStr(), RTL_TEXTENCODING_UTF8 );
69 mpGObject.reset( new GraphicObject( bsId ) );
71 else
72 mpGObject.reset( new GraphicObject() );
75 uno::Reference< graphic::XGraphic > SAL_CALL GObjectImpl::getGraphic() throw (uno::RuntimeException)
77 ::osl::MutexGuard aGuard( m_aMutex );
78 if ( !mpGObject.get() )
79 throw uno::RuntimeException();
80 return mpGObject->GetGraphic().GetXGraphic();
83 void SAL_CALL GObjectImpl::setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException)
85 ::osl::MutexGuard aGuard( m_aMutex );
86 if ( !mpGObject.get() )
87 throw uno::RuntimeException();
88 Graphic aGraphic( _graphic );
89 mpGObject->SetGraphic( aGraphic );
92 ::rtl::OUString SAL_CALL GObjectImpl::getUniqueID() throw (uno::RuntimeException)
94 ::osl::MutexGuard aGuard( m_aMutex );
95 rtl::OUString sId;
96 if ( mpGObject.get() )
97 sId = String( mpGObject->GetUniqueID().GetBuffer(), RTL_TEXTENCODING_ASCII_US );
98 return sId;
102 namespace sdecl = comphelper::service_decl;
103 sdecl::class_<GObjectImpl, sdecl::with_args<true> > serviceBI;
104 extern sdecl::ServiceDecl const serviceDecl( serviceBI, "com.sun.star.graphic.GraphicObject", "com.sun.star.graphic.GraphicObject" );