LibreOffice Module sc (master) 1
miscuno.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <vector>
23
24#include <com/sun/star/lang/XServiceInfo.hpp>
25#include <com/sun/star/beans/XPropertySet.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>
31#include <osl/diagnose.h>
32#include "scdllapi.h"
33
34#define SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
35OUString SAL_CALL ClassName::getImplementationName() \
36{ \
37 return ClassNameAscii; \
38} \
39sal_Bool SAL_CALL ClassName::supportsService( const OUString& ServiceName ) \
40{ \
41 return cppu::supportsService(this, ServiceName); \
42}
43
44#define SC_SIMPLE_SERVICE_INFO_NAME( ClassName, ServiceAscii ) \
45css::uno::Sequence< OUString > \
46 SAL_CALL ClassName::getSupportedServiceNames() \
47{ \
48 css::uno::Sequence< OUString > aRet { ServiceAscii }; \
49 return aRet; \
50}
51
52// Place the old mistyped variant as first element so existing code can
53// continue to ask aRet[0] if it doesn't iterate; new code can iterate over the
54// sequence. This mostly should be used by supportsService() iterating anyway.
55#define SC_SIMPLE_SERVICE_INFO_TYPO( ClassName, ServiceAscii, ServiceAsciiMistyped ) \
56css::uno::Sequence< OUString > \
57 SAL_CALL ClassName::getSupportedServiceNames() \
58{ \
59 css::uno::Sequence< OUString > aRet { ServiceAsciiMistyped, ServiceAscii }; \
60 return aRet; \
61}
62
63#define SC_SIMPLE_SERVICE_INFO( ClassName, ClassNameAscii, ServiceAscii ) \
64 SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
65 SC_SIMPLE_SERVICE_INFO_NAME( ClassName, ServiceAscii )
66
67#define SC_SIMPLE_SERVICE_INFO_COMPAT( ClassName, ClassNameAscii, ServiceAscii, ServiceAsciiMistyped ) \
68 SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
69 SC_SIMPLE_SERVICE_INFO_TYPO( ClassName, ServiceAscii, ServiceAsciiMistyped )
70
71
72#define SC_IMPL_DUMMY_PROPERTY_LISTENER( ClassName ) \
73 void SAL_CALL ClassName::addPropertyChangeListener( const OUString&, \
74 const uno::Reference<beans::XPropertyChangeListener>&) \
75 { OSL_FAIL("not implemented"); } \
76 void SAL_CALL ClassName::removePropertyChangeListener( const OUString&, \
77 const uno::Reference<beans::XPropertyChangeListener>&) \
78 { OSL_FAIL("not implemented"); } \
79 void SAL_CALL ClassName::addVetoableChangeListener( const OUString&, \
80 const uno::Reference<beans::XVetoableChangeListener>&) \
81 { OSL_FAIL("not implemented"); } \
82 void SAL_CALL ClassName::removeVetoableChangeListener( const OUString&, \
83 const uno::Reference<beans::XVetoableChangeListener>&) \
84 { OSL_FAIL("not implemented"); }
85
86#define SC_QUERYINTERFACE(x) \
87 if (rType == cppu::UnoType<x>::get()) \
88 { return uno::Any(uno::Reference<x>(this)); }
89
90// SC_QUERY_MULTIPLE( XElementAccess, XIndexAccess ):
91// use if interface is used several times in one class
92
93#define SC_QUERY_MULTIPLE(x,y) \
94 if (rType == cppu::UnoType<x>::get()) \
95 { uno::Any aR; aR <<= uno::Reference<x>(static_cast<y*>(this)); return aR; }
96
97class ScIndexEnumeration final : public cppu::WeakImplHelper<
98 css::container::XEnumeration,
99 css::lang::XServiceInfo >
100{
101private:
102 css::uno::Reference<css::container::XIndexAccess> xIndex;
103 OUString sServiceName;
104 sal_Int32 nPos;
105
106public:
107 ScIndexEnumeration(css::uno::Reference<
108 css::container::XIndexAccess> xInd, OUString aServiceName);
109 virtual ~ScIndexEnumeration() override;
110
111 // XEnumeration
112 virtual sal_Bool SAL_CALL hasMoreElements() override;
113 virtual css::uno::Any SAL_CALL nextElement() override;
114
115 // XServiceInfo
116 virtual OUString SAL_CALL getImplementationName( ) override;
117 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
118 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
119};
120
121// new (uno 3) variant
122class ScNameToIndexAccess final : public cppu::WeakImplHelper<
123 css::container::XIndexAccess,
124 css::lang::XServiceInfo >
125{
126private:
127 css::uno::Reference<css::container::XNameAccess> xNameAccess;
128 css::uno::Sequence<OUString> aNames;
129
130public:
132 css::uno::Reference< css::container::XNameAccess> xNameObj );
133 virtual ~ScNameToIndexAccess() override;
134
135 // XIndexAccess
136 virtual sal_Int32 SAL_CALL getCount( ) override;
137 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
138
139 // XElementAccess
140 virtual css::uno::Type SAL_CALL getElementType( ) override;
141 virtual sal_Bool SAL_CALL hasElements( ) override;
142
143 // XServiceInfo
144 virtual OUString SAL_CALL getImplementationName( ) override;
145 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
146 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
147};
148
150{
151public:
152 static bool GetBoolProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
153 const OUString& rName, bool bDefault = false );
154 static sal_Int16 GetShortProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
155 const OUString& rName, sal_Int16 nDefault );
156 static sal_Int32 GetLongProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
157 const OUString& rName );
158 template<typename EnumT>
159 static EnumT GetEnumProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
160 const OUString& rName, EnumT nDefault )
161 { return static_cast<EnumT>(GetEnumPropertyImpl(xProp, rName, static_cast<sal_Int32>(nDefault))); }
162
163 static OUString GetStringProperty(
164 const css::uno::Reference<css::beans::XPropertySet>& xProp,
165 const OUString& rName, const OUString& rDefault );
166
167 static bool GetBoolFromAny( const css::uno::Any& aAny );
168 static sal_Int16 GetInt16FromAny( const css::uno::Any& aAny );
169 static sal_Int32 GetInt32FromAny( const css::uno::Any& aAny );
170 static sal_Int32 GetEnumFromAny( const css::uno::Any& aAny );
171
173 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
174 const char* pPropName, const css::uno::Any& rVal );
176 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
177 const OUString& rPropName, const css::uno::Any& rVal );
178
179 template<typename ValueType>
181 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
182 const char* pPropName, const ValueType& rVal )
183 {
184 css::uno::Any any;
185 any <<= rVal;
186 SetOptionalPropertyValue(rPropSet, pPropName, any);
187 }
188 template<typename ValueType>
190 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
191 const OUString& rPropName, const ValueType& rVal )
192 {
193 css::uno::Any any;
194 any <<= rVal;
195 SetOptionalPropertyValue(rPropSet, rPropName, any);
196 }
197
198 template<typename ValueType>
199 static css::uno::Sequence<ValueType> VectorToSequence( const std::vector<ValueType>& rVector )
200 {
201 if (rVector.empty())
202 return css::uno::Sequence<ValueType>();
203
204 return css::uno::Sequence<ValueType>(&rVector[0], static_cast<sal_Int32>(rVector.size()));
205 }
206private:
207 static sal_Int32 GetEnumPropertyImpl( const css::uno::Reference< css::beans::XPropertySet>& xProp,
208 const OUString& rName, sal_Int32 nDefault );
209};
210
211/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
const Any & any
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: miscuno.cxx:236
virtual sal_Bool SAL_CALL hasMoreElements() override
Definition: miscuno.cxx:204
ScIndexEnumeration(css::uno::Reference< css::container::XIndexAccess > xInd, OUString aServiceName)
Definition: miscuno.cxx:190
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: miscuno.cxx:230
sal_Int32 nPos
Definition: miscuno.hxx:104
virtual css::uno::Any SAL_CALL nextElement() override
Definition: miscuno.cxx:210
virtual ~ScIndexEnumeration() override
Definition: miscuno.cxx:198
OUString sServiceName
Definition: miscuno.hxx:103
css::uno::Reference< css::container::XIndexAccess > xIndex
Definition: miscuno.hxx:102
virtual OUString SAL_CALL getImplementationName() override
Definition: miscuno.cxx:225
virtual sal_Int32 SAL_CALL getCount() override
Definition: miscuno.cxx:257
ScNameToIndexAccess(css::uno::Reference< css::container::XNameAccess > xNameObj)
Definition: miscuno.cxx:241
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Type SAL_CALL getElementType() override
Definition: miscuno.cxx:272
css::uno::Sequence< OUString > aNames
Definition: miscuno.hxx:128
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: miscuno.cxx:262
virtual ~ScNameToIndexAccess() override
Definition: miscuno.cxx:251
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL hasElements() override
Definition: miscuno.cxx:280
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::container::XNameAccess > xNameAccess
Definition: miscuno.hxx:127
static void SetOptionalPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, const char *pPropName, const ValueType &rVal)
Definition: miscuno.hxx:180
static void SetOptionalPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, const OUString &rPropName, const ValueType &rVal)
Definition: miscuno.hxx:189
static EnumT GetEnumProperty(const css::uno::Reference< css::beans::XPropertySet > &xProp, const OUString &rName, EnumT nDefault)
Definition: miscuno.hxx:159
static void SetOptionalPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, const OUString &rPropName, const css::uno::Any &rVal)
static void SetOptionalPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, const char *pPropName, const css::uno::Any &rVal)
static css::uno::Sequence< ValueType > VectorToSequence(const std::vector< ValueType > &rVector)
Definition: miscuno.hxx:199
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
unsigned char sal_Bool