LCOV - code coverage report
Current view: top level - svx/source/unodraw - unoctabl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 13 62 21.0 %
Date: 2015-06-13 12:38:46 Functions: 6 15 40.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           2 : 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           1 : SvxUnoColorTable::SvxUnoColorTable()
      66             : {
      67           4 :     pList = XPropertyList::AsColorList(
      68             :         XPropertyList::CreatePropertyList(
      69           3 :             XCOLOR_LIST, SvtPathOptions().GetPalettePath(), ""));
      70           1 : }
      71             : 
      72           0 : sal_Bool SAL_CALL SvxUnoColorTable::supportsService( const  OUString& ServiceName ) throw(uno::RuntimeException, std::exception)
      73             : {
      74           0 :     return cppu::supportsService( this, ServiceName );
      75             : }
      76             : 
      77           1 : OUString SAL_CALL SvxUnoColorTable::getImplementationName() throw( uno::RuntimeException, std::exception )
      78             : {
      79           1 :     return OUString("com.sun.star.drawing.SvxUnoColorTable");
      80             : }
      81             : 
      82           1 : uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getSupportedServiceNames()
      83             :     throw( uno::RuntimeException, std::exception )
      84             : {
      85           1 :     uno::Sequence< OUString > aSNS( 1 );
      86           1 :     aSNS.getArray()[0] = "com.sun.star.drawing.ColorTable";
      87           1 :     return aSNS;
      88             : }
      89             : 
      90             : // XNameContainer
      91           0 : void SAL_CALL SvxUnoColorTable::insertByName( const OUString& aName, const uno::Any& aElement )
      92             :     throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
      93             : {
      94           0 :     if( hasByName( aName ) )
      95           0 :         throw container::ElementExistException();
      96             : 
      97           0 :     sal_Int32 nColor = 0;
      98           0 :     if( !(aElement >>= nColor) )
      99           0 :         throw lang::IllegalArgumentException();
     100             : 
     101           0 :     if( pList.is() )
     102             :     {
     103           0 :         XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName  );
     104           0 :         pList->Insert( pEntry, pList->Count() );
     105             :     }
     106           0 : }
     107             : 
     108           0 : void SAL_CALL SvxUnoColorTable::removeByName( const OUString& Name )
     109             :     throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     110             : {
     111           0 :     long nIndex = pList.is() ? pList->GetIndex( Name ) : -1;
     112           0 :     if( nIndex == -1 )
     113           0 :         throw container::NoSuchElementException();
     114             : 
     115           0 :     pList->Remove( nIndex );
     116           0 : }
     117             : 
     118             : // XNameReplace
     119           0 : void SAL_CALL SvxUnoColorTable::replaceByName( const OUString& aName, const uno::Any& aElement )
     120             :     throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
     121             : {
     122           0 :     sal_Int32 nColor = 0;
     123           0 :     if( !(aElement >>= nColor) )
     124           0 :         throw lang::IllegalArgumentException();
     125             : 
     126           0 :     long nIndex = pList.is() ? pList->GetIndex( aName ) : -1;
     127           0 :     if( nIndex == -1  )
     128           0 :         throw container::NoSuchElementException();
     129             : 
     130           0 :     XColorEntry* pEntry = new XColorEntry( Color( (ColorData)nColor ), aName );
     131           0 :     delete pList->Replace( nIndex, pEntry );
     132           0 : }
     133             : 
     134             : // XNameAccess
     135           0 : uno::Any SAL_CALL SvxUnoColorTable::getByName( const OUString& aName )
     136             :     throw( container::NoSuchElementException,  lang::WrappedTargetException, uno::RuntimeException, std::exception)
     137             : {
     138           0 :     long nIndex = pList.is() ? pList->GetIndex( aName ) : -1;
     139           0 :     if( nIndex == -1 )
     140           0 :         throw container::NoSuchElementException();
     141             : 
     142           0 :     XColorEntry* pEntry = pList->GetColor( nIndex );
     143           0 :     return uno::Any( (sal_Int32) pEntry->GetColor().GetRGBColor() );
     144             : }
     145             : 
     146           0 : uno::Sequence< OUString > SAL_CALL SvxUnoColorTable::getElementNames()
     147             :     throw( uno::RuntimeException, std::exception )
     148             : {
     149           0 :     const long nCount = pList.is() ? pList->Count() : 0;
     150             : 
     151           0 :     uno::Sequence< OUString > aSeq( nCount );
     152           0 :     OUString* pStrings = aSeq.getArray();
     153             : 
     154           0 :     for( long nIndex = 0; nIndex < nCount; nIndex++ )
     155             :     {
     156           0 :         XColorEntry* pEntry = pList->GetColor( (long)nIndex );
     157           0 :         pStrings[nIndex] = pEntry->GetName();
     158             :     }
     159             : 
     160           0 :     return aSeq;
     161             : }
     162             : 
     163           0 : sal_Bool SAL_CALL SvxUnoColorTable::hasByName( const OUString& aName )
     164             :     throw( uno::RuntimeException, std::exception )
     165             : {
     166           0 :     long nIndex = pList.is() ? pList->GetIndex( aName ) : -1;
     167           0 :     return nIndex != -1;
     168             : }
     169             : 
     170             : // XElementAccess
     171           0 : uno::Type SAL_CALL SvxUnoColorTable::getElementType()
     172             :     throw( uno::RuntimeException, std::exception )
     173             : {
     174           0 :     return ::cppu::UnoType<sal_Int32>::get();
     175             : }
     176             : 
     177           0 : sal_Bool SAL_CALL SvxUnoColorTable::hasElements()
     178             :     throw( uno::RuntimeException, std::exception )
     179             : {
     180           0 :     return pList.is() && pList->Count() != 0;
     181             : }
     182             : 
     183             : }
     184             : 
     185             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     186           1 : com_sun_star_drawing_SvxUnoColorTable_get_implementation(
     187             :     css::uno::XComponentContext *,
     188             :     css::uno::Sequence<css::uno::Any> const &)
     189             : {
     190           1 :     return cppu::acquire(new SvxUnoColorTable);
     191             : }
     192             : 
     193             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11