Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <comphelper/servicedecl.hxx>
31 : : #include <cppuhelper/implbase1.hxx>
32 : : #include <com/sun/star/graphic/XGraphicObject.hpp>
33 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
34 : : #include <svtools/grfmgr.hxx>
35 : :
36 : : using namespace com::sun::star;
37 : :
38 : : namespace unographic {
39 : :
40 : : typedef ::cppu::WeakImplHelper1< graphic::XGraphicObject > GObjectAccess_BASE;
41 : : // Simple uno wrapper around the GraphicObject class to allow basic
42 : : // access. ( and solves a horrible cyclic link problem between
43 : : // goodies/toolkit/extensions )
44 [ + - ][ + - ]: 44 : class GObjectImpl : public GObjectAccess_BASE
[ - + ]
45 : : {
46 : : ::osl::Mutex m_aMutex;
47 : : std::auto_ptr< GraphicObject > mpGObject;
48 : : public:
49 : : GObjectImpl( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & xComponentContext ) throw (uno::RuntimeException);
50 : :
51 : : // XGraphicObject
52 : : virtual uno::Reference< graphic::XGraphic > SAL_CALL getGraphic() throw (uno::RuntimeException);
53 : : virtual void SAL_CALL setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException);
54 : : ::rtl::OUString SAL_CALL getUniqueID() throw (uno::RuntimeException);
55 : : };
56 : :
57 [ + - ]: 44 : GObjectImpl::GObjectImpl( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & /*xComponentContext*/ ) throw (uno::RuntimeException)
58 : : {
59 [ - + ]: 44 : if ( args.getLength() == 1 )
60 : : {
61 : 0 : rtl::OUString sId;
62 [ # # ][ # # ]: 0 : if ( !( args[ 0 ] >>= sId ) || sId.isEmpty() )
[ # # ]
63 [ # # ]: 0 : throw lang::IllegalArgumentException();
64 [ # # ]: 0 : rtl::OString bsId(rtl::OUStringToOString(sId, RTL_TEXTENCODING_UTF8));
65 [ # # ][ # # ]: 0 : mpGObject.reset( new GraphicObject( bsId ) );
66 : : }
67 : : else
68 [ + - ][ + - ]: 44 : mpGObject.reset( new GraphicObject() );
69 : 44 : }
70 : :
71 : 0 : uno::Reference< graphic::XGraphic > SAL_CALL GObjectImpl::getGraphic() throw (uno::RuntimeException)
72 : : {
73 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
74 [ # # ]: 0 : if ( !mpGObject.get() )
75 [ # # ]: 0 : throw uno::RuntimeException();
76 [ # # ][ # # ]: 0 : return mpGObject->GetGraphic().GetXGraphic();
[ # # ]
77 : : }
78 : :
79 : 44 : void SAL_CALL GObjectImpl::setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException)
80 : : {
81 [ + - ]: 44 : ::osl::MutexGuard aGuard( m_aMutex );
82 [ - + ]: 44 : if ( !mpGObject.get() )
83 [ # # ]: 0 : throw uno::RuntimeException();
84 [ + - ]: 44 : Graphic aGraphic( _graphic );
85 [ + - ][ + - ]: 44 : mpGObject->SetGraphic( aGraphic );
[ + - ]
86 : 44 : }
87 : :
88 : 42 : ::rtl::OUString SAL_CALL GObjectImpl::getUniqueID() throw (uno::RuntimeException)
89 : : {
90 [ + - ]: 42 : ::osl::MutexGuard aGuard( m_aMutex );
91 : 42 : rtl::OUString sId;
92 [ + - ]: 42 : if ( mpGObject.get() )
93 [ + - ][ + - ]: 42 : sId = rtl::OStringToOUString(mpGObject->GetUniqueID(), RTL_TEXTENCODING_ASCII_US);
94 [ + - ]: 42 : return sId;
95 : : }
96 : :
97 : :
98 : : namespace sdecl = comphelper::service_decl;
99 : 281 : sdecl::class_<GObjectImpl, sdecl::with_args<true> > serviceBI;
100 : 281 : extern sdecl::ServiceDecl const serviceDecl( serviceBI, "com.sun.star.graphic.GraphicObject", "com.sun.star.graphic.GraphicObject" );
101 : :
102 [ + - ][ + - ]: 843 : }
103 : :
104 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|