nss: upgrade to release 3.73
[LibreOffice.git] / sc / inc / miscuno.hxx
blob9e2963e08027a3aee52f5f9e1565fe26654b103a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_MISCUNO_HXX
21 #define INCLUDED_SC_INC_MISCUNO_HXX
23 #include <vector>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/container/XEnumeration.hpp>
29 #include <com/sun/star/container/XIndexAccess.hpp>
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <osl/diagnose.h>
33 #include "scdllapi.h"
35 #define SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
36 OUString SAL_CALL ClassName::getImplementationName() \
37 { \
38 return ClassNameAscii; \
39 } \
40 sal_Bool SAL_CALL ClassName::supportsService( const OUString& ServiceName ) \
41 { \
42 return cppu::supportsService(this, ServiceName); \
45 #define SC_SIMPLE_SERVICE_INFO_NAME( ClassName, ServiceAscii ) \
46 css::uno::Sequence< OUString > \
47 SAL_CALL ClassName::getSupportedServiceNames() \
48 { \
49 css::uno::Sequence< OUString > aRet { ServiceAscii }; \
50 return aRet; \
53 // Place the old mistyped variant as first element so existing code can
54 // continue to ask aRet[0] if it doesn't iterate; new code can iterate over the
55 // sequence. This mostly should be used by supportsService() iterating anyway.
56 #define SC_SIMPLE_SERVICE_INFO_TYPO( ClassName, ServiceAscii, ServiceAsciiMistyped ) \
57 css::uno::Sequence< OUString > \
58 SAL_CALL ClassName::getSupportedServiceNames() \
59 { \
60 css::uno::Sequence< OUString > aRet { ServiceAsciiMistyped, ServiceAscii }; \
61 return aRet; \
64 #define SC_SIMPLE_SERVICE_INFO( ClassName, ClassNameAscii, ServiceAscii ) \
65 SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
66 SC_SIMPLE_SERVICE_INFO_NAME( ClassName, ServiceAscii )
68 #define SC_SIMPLE_SERVICE_INFO_COMPAT( ClassName, ClassNameAscii, ServiceAscii, ServiceAsciiMistyped ) \
69 SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
70 SC_SIMPLE_SERVICE_INFO_TYPO( ClassName, ServiceAscii, ServiceAsciiMistyped )
73 #define SC_IMPL_DUMMY_PROPERTY_LISTENER( ClassName ) \
74 void SAL_CALL ClassName::addPropertyChangeListener( const OUString&, \
75 const uno::Reference<beans::XPropertyChangeListener>&) \
76 { OSL_FAIL("not implemented"); } \
77 void SAL_CALL ClassName::removePropertyChangeListener( const OUString&, \
78 const uno::Reference<beans::XPropertyChangeListener>&) \
79 { OSL_FAIL("not implemented"); } \
80 void SAL_CALL ClassName::addVetoableChangeListener( const OUString&, \
81 const uno::Reference<beans::XVetoableChangeListener>&) \
82 { OSL_FAIL("not implemented"); } \
83 void SAL_CALL ClassName::removeVetoableChangeListener( const OUString&, \
84 const uno::Reference<beans::XVetoableChangeListener>&) \
85 { OSL_FAIL("not implemented"); }
87 #define SC_QUERYINTERFACE(x) \
88 if (rType == cppu::UnoType<x>::get()) \
89 { return uno::makeAny(uno::Reference<x>(this)); }
91 // SC_QUERY_MULTIPLE( XElementAccess, XIndexAccess ):
92 // use if interface is used several times in one class
94 #define SC_QUERY_MULTIPLE(x,y) \
95 if (rType == cppu::UnoType<x>::get()) \
96 { uno::Any aR; aR <<= uno::Reference<x>(static_cast<y*>(this)); return aR; }
98 class ScIndexEnumeration final : public cppu::WeakImplHelper<
99 css::container::XEnumeration,
100 css::lang::XServiceInfo >
102 private:
103 css::uno::Reference<css::container::XIndexAccess> xIndex;
104 OUString sServiceName;
105 sal_Int32 nPos;
107 public:
108 ScIndexEnumeration(const css::uno::Reference<
109 css::container::XIndexAccess>& rInd, const OUString& rServiceName);
110 virtual ~ScIndexEnumeration() override;
112 // XEnumeration
113 virtual sal_Bool SAL_CALL hasMoreElements() override;
114 virtual css::uno::Any SAL_CALL nextElement() override;
116 // XServiceInfo
117 virtual OUString SAL_CALL getImplementationName( ) override;
118 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
119 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
122 // new (uno 3) variant
123 class ScNameToIndexAccess final : public cppu::WeakImplHelper<
124 css::container::XIndexAccess,
125 css::lang::XServiceInfo >
127 private:
128 css::uno::Reference<css::container::XNameAccess> xNameAccess;
129 css::uno::Sequence<OUString> aNames;
131 public:
132 ScNameToIndexAccess(
133 const css::uno::Reference< css::container::XNameAccess>& rNameObj );
134 virtual ~ScNameToIndexAccess() override;
136 // XIndexAccess
137 virtual sal_Int32 SAL_CALL getCount( ) override;
138 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
140 // XElementAccess
141 virtual css::uno::Type SAL_CALL getElementType( ) override;
142 virtual sal_Bool SAL_CALL hasElements( ) override;
144 // XServiceInfo
145 virtual OUString SAL_CALL getImplementationName( ) override;
146 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
147 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
150 class SC_DLLPUBLIC ScUnoHelpFunctions
152 public:
153 static bool GetBoolProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
154 const OUString& rName, bool bDefault = false );
155 static sal_Int16 GetShortProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
156 const OUString& rName, sal_Int16 nDefault );
157 static sal_Int32 GetLongProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
158 const OUString& rName );
159 template<typename EnumT>
160 static EnumT GetEnumProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
161 const OUString& rName, EnumT nDefault )
162 { return static_cast<EnumT>(GetEnumPropertyImpl(xProp, rName, static_cast<sal_Int32>(nDefault))); }
164 static OUString GetStringProperty(
165 const css::uno::Reference<css::beans::XPropertySet>& xProp,
166 const OUString& rName, const OUString& rDefault );
168 static bool GetBoolFromAny( const css::uno::Any& aAny );
169 static sal_Int16 GetInt16FromAny( const css::uno::Any& aAny );
170 static sal_Int32 GetInt32FromAny( const css::uno::Any& aAny );
171 static sal_Int32 GetEnumFromAny( const css::uno::Any& aAny );
173 static void SetOptionalPropertyValue(
174 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
175 const char* pPropName, const css::uno::Any& rVal );
177 template<typename ValueType>
178 static void SetOptionalPropertyValue(
179 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
180 const char* pPropName, const ValueType& rVal )
182 css::uno::Any any;
183 any <<= rVal;
184 SetOptionalPropertyValue(rPropSet, pPropName, any);
187 template<typename ValueType>
188 static css::uno::Sequence<ValueType> VectorToSequence( const std::vector<ValueType>& rVector )
190 if (rVector.empty())
191 return css::uno::Sequence<ValueType>();
193 return css::uno::Sequence<ValueType>(&rVector[0], static_cast<sal_Int32>(rVector.size()));
195 private:
196 static sal_Int32 GetEnumPropertyImpl( const css::uno::Reference< css::beans::XPropertySet>& xProp,
197 const OUString& rName, sal_Int32 nDefault );
200 #endif
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */