LCOV - code coverage report
Current view: top level - svx/source/unodraw - unoctabl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 61 0.0 %
Date: 2014-04-14 Functions: 0 15 0.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             : #include <unotools/pathoptions.hxx>
      21             : #include <com/sun/star/lang/XServiceInfo.hpp>
      22             : #include <com/sun/star/container/XNameContainer.hpp>
      23             : #include <com/sun/star/uno/XComponentContext.hpp>
      24             : #include <cppuhelper/implbase2.hxx>
      25             : #include <cppuhelper/supportsservice.hxx>
      26             : #include <rtl/ref.hxx>
      27             : #include <svx/xtable.hxx>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : 
      31             : namespace {
      32             : 
      33           0 : class SvxUnoColorTable : public cppu::WeakImplHelper2< container::XNameContainer, lang::XServiceInfo >
      34             : {
      35             : private:
      36             :     XColorListRef pList;
      37             : 
      38             : public:
      39             :     SvxUnoColorTable();
      40             : 
      41             :     // XServiceInfo
      42             :     virtual OUString SAL_CALL getImplementationName() throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      43             :     virtual sal_Bool SAL_CALL supportsService( const  OUString& ServiceName ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
      44             :     virtual uno::Sequence<  OUString > SAL_CALL getSupportedServiceNames() throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
      45             : 
      46             :     // XNameContainer
      47             :     virtual void SAL_CALL insertByName( const  OUString& aName, const  uno::Any& aElement ) throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      48             :     virtual void SAL_CALL removeByName( const  OUString& Name ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      49             : 
      50             :     // XNameReplace
      51             :     virtual void SAL_CALL replaceByName( const  OUString& aName, const  uno::Any& aElement ) throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      52             : 
      53             :     // XNameAccess
      54             :     virtual uno::Any SAL_CALL getByName( const  OUString& aName ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      55             : 
      56             :     virtual uno::Sequence<  OUString > SAL_CALL getElementNames() throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
      57             : 
      58             :     virtual sal_Bool SAL_CALL hasByName( const  OUString& aName ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
      59             : 
      60             :     // XElementAccess
      61             :     virtual uno::Type SAL_CALL getElementType() throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
      62             :     virtual sal_Bool SAL_CALL hasElements() throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
      63             : };
      64             : 
      65           0 : SvxUnoColorTable::SvxUnoColorTable()
      66             : {
      67           0 :     pList = XPropertyList::CreatePropertyList( XCOLOR_LIST, SvtPathOptions().GetPalettePath(), "" )->AsColorList();
      68           0 : }
      69             : 
      70           0 : sal_Bool SAL_CALL SvxUnoColorTable::supportsService( const  OUString& ServiceName ) throw(uno::RuntimeException, std::exception)
      71             : {
      72           0 :     return cppu::supportsService( this, ServiceName );
      73             : }
      74             : 
      75           0 : OUString SAL_CALL SvxUnoColorTable::getImplementationName() throw( uno::RuntimeException, std::exception )
      76             : {
      77           0 :     return OUString("com.sun.star.drawing.SvxUnoColorTable");
      78             : }
      79             : 
      80           0 : uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getSupportedServiceNames()
      81             :     throw( uno::RuntimeException, std::exception )
      82             : {
      83           0 :     uno::Sequence< OUString > aSNS( 1 );
      84           0 :     aSNS.getArray()[0] = "com.sun.star.drawing.ColorTable";
      85           0 :     return aSNS;
      86             : }
      87             : 
      88             : // XNameContainer
      89           0 : void SAL_CALL SvxUnoColorTable::insertByName( const OUString& aName, const uno::Any& aElement )
      90             :     throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
      91             : {
      92           0 :     if( hasByName( aName ) )
      93           0 :         throw container::ElementExistException();
      94             : 
      95           0 :     sal_Int32 nColor = 0;
      96           0 :     if( !(aElement >>= nColor) )
      97           0 :         throw lang::IllegalArgumentException();
      98             : 
      99           0 :     if( pList.is() )
     100             :     {
     101           0 :         XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName  );
     102           0 :         pList->Insert( pEntry, pList->Count() );
     103             :     }
     104           0 : }
     105             : 
     106           0 : void SAL_CALL SvxUnoColorTable::removeByName( const OUString& Name )
     107             :     throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     108             : {
     109           0 :     long nIndex = pList.is() ? pList->GetIndex( Name ) : -1;
     110           0 :     if( nIndex == -1 )
     111           0 :         throw container::NoSuchElementException();
     112             : 
     113           0 :     pList->Remove( nIndex );
     114           0 : }
     115             : 
     116             : // XNameReplace
     117           0 : void SAL_CALL SvxUnoColorTable::replaceByName( const OUString& aName, const uno::Any& aElement )
     118             :     throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
     119             : {
     120           0 :     sal_Int32 nColor = 0;
     121           0 :     if( !(aElement >>= nColor) )
     122           0 :         throw lang::IllegalArgumentException();
     123             : 
     124           0 :     long nIndex = pList.is() ? pList->GetIndex( aName ) : -1;
     125           0 :     if( nIndex == -1  )
     126           0 :         throw container::NoSuchElementException();
     127             : 
     128           0 :     XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName );
     129           0 :     delete pList->Replace( nIndex, pEntry );
     130           0 : }
     131             : 
     132             : // XNameAccess
     133           0 : uno::Any SAL_CALL SvxUnoColorTable::getByName( const OUString& aName )
     134             :     throw( container::NoSuchElementException,  lang::WrappedTargetException, uno::RuntimeException, std::exception)
     135             : {
     136           0 :     long nIndex = pList.is() ? pList->GetIndex( aName ) : -1;
     137           0 :     if( nIndex == -1 )
     138           0 :         throw container::NoSuchElementException();
     139             : 
     140           0 :     XColorEntry* pEntry = pList->GetColor( nIndex );
     141           0 :     return uno::Any( (sal_Int32) pEntry->GetColor().GetRGBColor() );
     142             : }
     143             : 
     144           0 : uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getElementNames()
     145             :     throw( uno::RuntimeException, std::exception )
     146             : {
     147           0 :     const long nCount = pList.is() ? pList->Count() : 0;
     148             : 
     149           0 :     uno::Sequence< OUString > aSeq( nCount );
     150           0 :     OUString* pStrings = aSeq.getArray();
     151             : 
     152           0 :     for( long nIndex = 0; nIndex < nCount; nIndex++ )
     153             :     {
     154           0 :         XColorEntry* pEntry = pList->GetColor( (long)nIndex );
     155           0 :         pStrings[nIndex] = pEntry->GetName();
     156             :     }
     157             : 
     158           0 :     return aSeq;
     159             : }
     160             : 
     161           0 : sal_Bool SAL_CALL SvxUnoColorTable::hasByName( const OUString& aName )
     162             :     throw( uno::RuntimeException, std::exception )
     163             : {
     164           0 :     long nIndex = pList.is() ? pList->GetIndex( aName ) : -1;
     165           0 :     return nIndex != -1;
     166             : }
     167             : 
     168             : // XElementAccess
     169           0 : uno::Type SAL_CALL SvxUnoColorTable::getElementType()
     170             :     throw( uno::RuntimeException, std::exception )
     171             : {
     172           0 :     return ::getCppuType((const sal_Int32*)0);
     173             : }
     174             : 
     175           0 : sal_Bool SAL_CALL SvxUnoColorTable::hasElements()
     176             :     throw( uno::RuntimeException, std::exception )
     177             : {
     178           0 :     return pList.is() && pList->Count() != 0;
     179             : }
     180             : 
     181             : }
     182             : 
     183             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     184           0 : com_sun_star_drawing_SvxUnoColorTable_get_implementation(
     185             :     css::uno::XComponentContext *,
     186             :     css::uno::Sequence<css::uno::Any> const &)
     187             : {
     188           0 :     return cppu::acquire(new SvxUnoColorTable);
     189             : }
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10