LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/graphic - graphicunofactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 31 64.5 %
Date: 2012-12-27 Functions: 6 8 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      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>
      26             : 
      27             : using namespace com::sun::star;
      28             : 
      29             : namespace unographic {
      30             : 
      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          30 : class GObjectImpl : public GObjectAccess_BASE
      36             : {
      37             :      ::osl::Mutex m_aMutex;
      38             :      std::auto_ptr< GraphicObject > mpGObject;
      39             : public:
      40             :      GObjectImpl( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & xComponentContext ) throw (uno::RuntimeException);
      41             : 
      42             :      // XGraphicObject
      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);
      46             : };
      47             : 
      48          30 : GObjectImpl::GObjectImpl( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & /*xComponentContext*/ ) throw (uno::RuntimeException)
      49             : {
      50          30 :     if ( args.getLength() == 1 )
      51             :     {
      52           0 :         rtl::OUString sId;
      53           0 :         if ( !( args[ 0 ] >>= sId ) || sId.isEmpty() )
      54           0 :             throw lang::IllegalArgumentException();
      55           0 :         rtl::OString bsId(rtl::OUStringToOString(sId, RTL_TEXTENCODING_UTF8));
      56           0 :         mpGObject.reset( new GraphicObject( bsId ) );
      57             :     }
      58             :     else
      59          30 :        mpGObject.reset( new GraphicObject() );
      60          30 : }
      61             : 
      62           0 : uno::Reference< graphic::XGraphic > SAL_CALL GObjectImpl::getGraphic() throw (uno::RuntimeException)
      63             : {
      64           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      65           0 :     if ( !mpGObject.get() )
      66           0 :         throw uno::RuntimeException();
      67           0 :     return mpGObject->GetGraphic().GetXGraphic();
      68             : }
      69             : 
      70          30 : void SAL_CALL GObjectImpl::setGraphic( const uno::Reference< graphic::XGraphic >& _graphic ) throw (uno::RuntimeException)
      71             : {
      72          30 :     ::osl::MutexGuard aGuard( m_aMutex );
      73          30 :     if ( !mpGObject.get() )
      74           0 :         throw uno::RuntimeException();
      75          30 :     Graphic aGraphic( _graphic );
      76          30 :     mpGObject->SetGraphic( aGraphic );
      77          30 : }
      78             : 
      79          30 : ::rtl::OUString SAL_CALL GObjectImpl::getUniqueID() throw (uno::RuntimeException)
      80             : {
      81          30 :     ::osl::MutexGuard aGuard( m_aMutex );
      82          30 :     rtl::OUString sId;
      83          30 :     if ( mpGObject.get() )
      84          30 :         sId = rtl::OStringToOUString(mpGObject->GetUniqueID(), RTL_TEXTENCODING_ASCII_US);
      85          30 :     return sId;
      86             : }
      87             : 
      88             : 
      89             : namespace sdecl = comphelper::service_decl;
      90          36 : sdecl::class_<GObjectImpl, sdecl::with_args<true> > serviceBI;
      91          36 : extern sdecl::ServiceDecl const serviceDecl( serviceBI, "com.sun.star.graphic.GraphicObject", "com.sun.star.graphic.GraphicObject" );
      92             : 
      93         108 : }
      94             : 
      95             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10