Bump version to 6.4-15
[LibreOffice.git] / sc / inc / miscuno.hxx
blob37250a6d21e26b643789e9644e57c99e17508d59
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( ClassName, ClassNameAscii, ServiceAscii ) \
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); \
43 } \
44 css::uno::Sequence< OUString > \
45 SAL_CALL ClassName::getSupportedServiceNames() \
46 { \
47 css::uno::Sequence< OUString > aRet { ServiceAscii }; \
48 return aRet; \
51 #define SC_IMPL_DUMMY_PROPERTY_LISTENER( ClassName ) \
52 void SAL_CALL ClassName::addPropertyChangeListener( const OUString&, \
53 const uno::Reference<beans::XPropertyChangeListener>&) \
54 { OSL_FAIL("not implemented"); } \
55 void SAL_CALL ClassName::removePropertyChangeListener( const OUString&, \
56 const uno::Reference<beans::XPropertyChangeListener>&) \
57 { OSL_FAIL("not implemented"); } \
58 void SAL_CALL ClassName::addVetoableChangeListener( const OUString&, \
59 const uno::Reference<beans::XVetoableChangeListener>&) \
60 { OSL_FAIL("not implemented"); } \
61 void SAL_CALL ClassName::removeVetoableChangeListener( const OUString&, \
62 const uno::Reference<beans::XVetoableChangeListener>&) \
63 { OSL_FAIL("not implemented"); }
65 #define SC_QUERYINTERFACE(x) \
66 if (rType == cppu::UnoType<x>::get()) \
67 { return uno::makeAny(uno::Reference<x>(this)); }
69 // SC_QUERY_MULTIPLE( XElementAccess, XIndexAccess ):
70 // use if interface is used several times in one class
72 #define SC_QUERY_MULTIPLE(x,y) \
73 if (rType == cppu::UnoType<x>::get()) \
74 { uno::Any aR; aR <<= uno::Reference<x>(static_cast<y*>(this)); return aR; }
76 class ScIndexEnumeration final : public cppu::WeakImplHelper<
77 css::container::XEnumeration,
78 css::lang::XServiceInfo >
80 private:
81 css::uno::Reference<css::container::XIndexAccess> xIndex;
82 OUString const sServiceName;
83 sal_Int32 nPos;
85 public:
86 ScIndexEnumeration(const css::uno::Reference<
87 css::container::XIndexAccess>& rInd, const OUString& rServiceName);
88 virtual ~ScIndexEnumeration() override;
90 // XEnumeration
91 virtual sal_Bool SAL_CALL hasMoreElements() override;
92 virtual css::uno::Any SAL_CALL nextElement() override;
94 // XServiceInfo
95 virtual OUString SAL_CALL getImplementationName( ) override;
96 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
97 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
100 // new (uno 3) variant
101 class ScNameToIndexAccess final : public cppu::WeakImplHelper<
102 css::container::XIndexAccess,
103 css::lang::XServiceInfo >
105 private:
106 css::uno::Reference<css::container::XNameAccess> xNameAccess;
107 css::uno::Sequence<OUString> aNames;
109 public:
110 ScNameToIndexAccess(
111 const css::uno::Reference< css::container::XNameAccess>& rNameObj );
112 virtual ~ScNameToIndexAccess() override;
114 // XIndexAccess
115 virtual sal_Int32 SAL_CALL getCount( ) override;
116 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
118 // XElementAccess
119 virtual css::uno::Type SAL_CALL getElementType( ) override;
120 virtual sal_Bool SAL_CALL hasElements( ) override;
122 // XServiceInfo
123 virtual OUString SAL_CALL getImplementationName( ) override;
124 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
125 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
128 class SC_DLLPUBLIC ScUnoHelpFunctions
130 public:
131 static bool GetBoolProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
132 const OUString& rName, bool bDefault = false );
133 static sal_Int16 GetShortProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
134 const OUString& rName, sal_Int16 nDefault );
135 static sal_Int32 GetLongProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
136 const OUString& rName );
137 template<typename EnumT>
138 static EnumT GetEnumProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
139 const OUString& rName, EnumT nDefault )
140 { return static_cast<EnumT>(GetEnumPropertyImpl(xProp, rName, static_cast<sal_Int32>(nDefault))); }
142 static OUString GetStringProperty(
143 const css::uno::Reference<css::beans::XPropertySet>& xProp,
144 const OUString& rName, const OUString& rDefault );
146 static bool GetBoolFromAny( const css::uno::Any& aAny );
147 static sal_Int16 GetInt16FromAny( const css::uno::Any& aAny );
148 static sal_Int32 GetInt32FromAny( const css::uno::Any& aAny );
149 static sal_Int32 GetEnumFromAny( const css::uno::Any& aAny );
151 static void SetOptionalPropertyValue(
152 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
153 const sal_Char* pPropName, const css::uno::Any& rVal );
155 template<typename ValueType>
156 static void SetOptionalPropertyValue(
157 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
158 const sal_Char* pPropName, const ValueType& rVal )
160 css::uno::Any any;
161 any <<= rVal;
162 SetOptionalPropertyValue(rPropSet, pPropName, any);
165 template<typename ValueType>
166 static css::uno::Sequence<ValueType> VectorToSequence( const std::vector<ValueType>& rVector )
168 if (rVector.empty())
169 return css::uno::Sequence<ValueType>();
171 return css::uno::Sequence<ValueType>(&rVector[0], static_cast<sal_Int32>(rVector.size()));
173 private:
174 static sal_Int32 GetEnumPropertyImpl( const css::uno::Reference< css::beans::XPropertySet>& xProp,
175 const OUString& rName, sal_Int32 nDefault );
178 #endif
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */