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

Generated by: LCOV version 1.10