LCOV - code coverage report
Current view: top level - sc/inc - miscuno.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 8 9 88.9 %
Date: 2014-11-03 Functions: 7 7 100.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             : #ifndef INCLUDED_SC_INC_MISCUNO_HXX
      21             : #define INCLUDED_SC_INC_MISCUNO_HXX
      22             : 
      23             : #include <com/sun/star/lang/XServiceInfo.hpp>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      26             : #include <com/sun/star/container/XNameAccess.hpp>
      27             : #include <com/sun/star/container/XEnumeration.hpp>
      28             : #include <com/sun/star/container/XIndexAccess.hpp>
      29             : #include <cppuhelper/implbase2.hxx>
      30             : #include <cppuhelper/supportsservice.hxx>
      31             : #include "scdllapi.h"
      32             : 
      33             : #define SC_SIMPLE_SERVICE_INFO( ClassName, ClassNameAscii, ServiceAscii )            \
      34             : OUString SAL_CALL ClassName::getImplementationName()                      \
      35             :     throw(::com::sun::star::uno::RuntimeException, std::exception)                                   \
      36             : {                                                                                    \
      37             :     return OUString::createFromAscii(ClassNameAscii);                         \
      38             : }                                                                                    \
      39             : sal_Bool SAL_CALL ClassName::supportsService( const OUString& ServiceName ) \
      40             :     throw(::com::sun::star::uno::RuntimeException, std::exception)                                   \
      41             : {                                                                                    \
      42             :     return cppu::supportsService(this, ServiceName);                                \
      43             : }                                                                                    \
      44             : ::com::sun::star::uno::Sequence< OUString >                                   \
      45             :     SAL_CALL ClassName::getSupportedServiceNames(void)                           \
      46             :     throw(::com::sun::star::uno::RuntimeException, std::exception)                                   \
      47             : {                                                                                    \
      48             :     ::com::sun::star::uno::Sequence< OUString > aRet(1);                      \
      49             :     OUString* pArray = aRet.getArray();                                       \
      50             :     pArray[0] = OUString::createFromAscii(ServiceAscii);                  \
      51             :     return aRet;                                                                     \
      52             : }
      53             : 
      54             : #define SC_IMPL_DUMMY_PROPERTY_LISTENER( ClassName )                                \
      55             :     void SAL_CALL ClassName::addPropertyChangeListener( const OUString&,       \
      56             :                             const uno::Reference<beans::XPropertyChangeListener>&)  \
      57             :                             throw(beans::UnknownPropertyException,                  \
      58             :                             lang::WrappedTargetException, uno::RuntimeException, std::exception)    \
      59             :     { OSL_FAIL("not implemented"); }                                                \
      60             :     void SAL_CALL ClassName::removePropertyChangeListener( const OUString&,    \
      61             :                             const uno::Reference<beans::XPropertyChangeListener>&)  \
      62             :                             throw(beans::UnknownPropertyException,                  \
      63             :                             lang::WrappedTargetException, uno::RuntimeException, std::exception)    \
      64             :     { OSL_FAIL("not implemented"); }                                                \
      65             :     void SAL_CALL ClassName::addVetoableChangeListener( const OUString&,       \
      66             :                             const uno::Reference<beans::XVetoableChangeListener>&)  \
      67             :                             throw(beans::UnknownPropertyException,                  \
      68             :                             lang::WrappedTargetException, uno::RuntimeException, std::exception)    \
      69             :     { OSL_FAIL("not implemented"); }                                                \
      70             :     void SAL_CALL ClassName::removeVetoableChangeListener( const OUString&,    \
      71             :                             const uno::Reference<beans::XVetoableChangeListener>&)  \
      72             :                             throw(beans::UnknownPropertyException,                  \
      73             :                             lang::WrappedTargetException, uno::RuntimeException, std::exception)    \
      74             :     { OSL_FAIL("not implemented"); }
      75             : 
      76             : #define SC_QUERYINTERFACE(x)    \
      77             :     if (rType == getCppuType((const uno::Reference<x>*)0))  \
      78             :     { return uno::makeAny(uno::Reference<x>(this)); }
      79             : 
      80             : // SC_QUERY_MULTIPLE( XElementAccess, XIndexAccess ):
      81             : //  use if interface is used several times in one class
      82             : 
      83             : #define SC_QUERY_MULTIPLE(x,y)  \
      84             :     if (rType == getCppuType((const uno::Reference<x>*)0))  \
      85             :     { uno::Any aR; aR <<= uno::Reference<x>(static_cast<y*>(this)); return aR; }
      86             : 
      87             : class ScIndexEnumeration : public cppu::WeakImplHelper2<
      88             :                                 com::sun::star::container::XEnumeration,
      89             :                                 com::sun::star::lang::XServiceInfo >
      90             : {
      91             : private:
      92             :     com::sun::star::uno::Reference<com::sun::star::container::XIndexAccess> xIndex;
      93             :     OUString           sServiceName;
      94             :     sal_Int32               nPos;
      95             : 
      96             : public:
      97             :                             ScIndexEnumeration(const com::sun::star::uno::Reference<
      98             :                                 com::sun::star::container::XIndexAccess>& rInd, const OUString& rServiceName);
      99             :     virtual                 ~ScIndexEnumeration();
     100             : 
     101             :                             // XEnumeration
     102             :     virtual sal_Bool SAL_CALL hasMoreElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     103             :     virtual ::com::sun::star::uno::Any SAL_CALL nextElement()
     104             :                                 throw(::com::sun::star::container::NoSuchElementException,
     105             :                                         ::com::sun::star::lang::WrappedTargetException,
     106             :                                         ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     107             : 
     108             :                             // XServiceInfo
     109             :     virtual OUString SAL_CALL getImplementationName(  )
     110             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     111             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
     112             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     113             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  )
     114             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     115             : };
     116             : 
     117             : //  new (uno 3) variant
     118             : class ScNameToIndexAccess : public cppu::WeakImplHelper2<
     119             :                                 com::sun::star::container::XIndexAccess,
     120             :                                 com::sun::star::lang::XServiceInfo >
     121             : {
     122             : private:
     123             :     com::sun::star::uno::Reference<com::sun::star::container::XNameAccess> xNameAccess;
     124             :     com::sun::star::uno::Sequence<OUString> aNames;
     125             : 
     126             : public:
     127             :                             ScNameToIndexAccess(
     128             :                                 const com::sun::star::uno::Reference<
     129             :                                     com::sun::star::container::XNameAccess>& rNameObj );
     130             :     virtual                 ~ScNameToIndexAccess();
     131             : 
     132             :                             // XIndexAccess
     133             :     virtual sal_Int32 SAL_CALL getCount(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     134             :     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
     135             :                                 throw(::com::sun::star::lang::IndexOutOfBoundsException,
     136             :                                         ::com::sun::star::lang::WrappedTargetException,
     137             :                                         ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     138             : 
     139             :                             // XElementAccess
     140             :     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  )
     141             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     142             :     virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     143             : 
     144             :                             // XServiceInfo
     145             :     virtual OUString SAL_CALL getImplementationName(  )
     146             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     147             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
     148             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     149             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  )
     150             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     151             : };
     152             : 
     153             : class SC_DLLPUBLIC ScUnoHelpFunctions
     154             : {
     155             : public:
     156             :     static com::sun::star::uno::Reference<com::sun::star::uno::XInterface>
     157             :                             AnyToInterface( const com::sun::star::uno::Any& rAny );
     158             :     static bool             GetBoolProperty( const com::sun::star::uno::Reference<
     159             :                                                 com::sun::star::beans::XPropertySet>& xProp,
     160             :                                             const OUString& rName, bool bDefault = false );
     161             :     static sal_Int32        GetLongProperty( const com::sun::star::uno::Reference<
     162             :                                                 com::sun::star::beans::XPropertySet>& xProp,
     163             :                                             const OUString& rName, long nDefault = 0 );
     164             :     static sal_Int32        GetEnumProperty( const com::sun::star::uno::Reference<
     165             :                                                 com::sun::star::beans::XPropertySet>& xProp,
     166             :                                             const OUString& rName, long nDefault );
     167             :     static OUString  GetStringProperty(
     168             :         const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xProp,
     169             :         const OUString& rName, const OUString& rDefault );
     170             : 
     171             :     static bool             GetBoolFromAny( const com::sun::star::uno::Any& aAny );
     172             :     static sal_Int16        GetInt16FromAny( const com::sun::star::uno::Any& aAny );
     173             :     static sal_Int32        GetInt32FromAny( const com::sun::star::uno::Any& aAny );
     174             :     static sal_Int32        GetEnumFromAny( const com::sun::star::uno::Any& aAny );
     175             :     static void             SetBoolInAny( com::sun::star::uno::Any& rAny, bool bValue );
     176             : 
     177             :     static void             SetOptionalPropertyValue(
     178             :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rPropSet,
     179             :         const sal_Char* pPropName, const ::com::sun::star::uno::Any& rVal );
     180             : 
     181             :     template<typename ValueType>
     182        1444 :     static void             SetOptionalPropertyValue(
     183             :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rPropSet,
     184             :         const sal_Char* pPropName, const ValueType& rVal )
     185             :     {
     186        1444 :         ::com::sun::star::uno::Any any;
     187        1444 :         any <<= rVal;
     188        1444 :         SetOptionalPropertyValue(rPropSet, pPropName, any);
     189        1444 :     }
     190             : 
     191             :     template<typename ValueType>
     192           8 :     static com::sun::star::uno::Sequence<ValueType> VectorToSequence( const std::vector<ValueType>& rVector )
     193             :     {
     194           8 :         if (rVector.empty())
     195           0 :             return com::sun::star::uno::Sequence<ValueType>();
     196             : 
     197           8 :         return com::sun::star::uno::Sequence<ValueType>(&rVector[0], static_cast<sal_Int32>(rVector.size()));
     198             :     }
     199             : };
     200             : 
     201             : #endif
     202             : 
     203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10