1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <com/sun/star/lang/XServiceInfo.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/container/XEnumeration.hpp>
26 #include <com/sun/star/container/XIndexAccess.hpp>
27 #include <cppuhelper/implbase.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <osl/diagnose.h>
32 #define SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
33 OUString SAL_CALL ClassName::getImplementationName() \
35 return ClassNameAscii; \
37 sal_Bool SAL_CALL ClassName::supportsService( const OUString& ServiceName ) \
39 return cppu::supportsService(this, ServiceName); \
42 #define SC_SIMPLE_SERVICE_INFO_NAME( ClassName, ServiceAscii ) \
43 css::uno::Sequence< OUString > \
44 SAL_CALL ClassName::getSupportedServiceNames() \
46 css::uno::Sequence< OUString > aRet { ServiceAscii }; \
50 // Place the old mistyped variant as first element so existing code can
51 // continue to ask aRet[0] if it doesn't iterate; new code can iterate over the
52 // sequence. This mostly should be used by supportsService() iterating anyway.
53 #define SC_SIMPLE_SERVICE_INFO_TYPO( ClassName, ServiceAscii, ServiceAsciiMistyped ) \
54 css::uno::Sequence< OUString > \
55 SAL_CALL ClassName::getSupportedServiceNames() \
57 css::uno::Sequence< OUString > aRet { ServiceAsciiMistyped, ServiceAscii }; \
61 #define SC_SIMPLE_SERVICE_INFO( ClassName, ClassNameAscii, ServiceAscii ) \
62 SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
63 SC_SIMPLE_SERVICE_INFO_NAME( ClassName, ServiceAscii )
65 #define SC_SIMPLE_SERVICE_INFO_COMPAT( ClassName, ClassNameAscii, ServiceAscii, ServiceAsciiMistyped ) \
66 SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
67 SC_SIMPLE_SERVICE_INFO_TYPO( ClassName, ServiceAscii, ServiceAsciiMistyped )
70 #define SC_IMPL_DUMMY_PROPERTY_LISTENER( ClassName ) \
71 void SAL_CALL ClassName::addPropertyChangeListener( const OUString&, \
72 const uno::Reference<beans::XPropertyChangeListener>&) \
73 { OSL_FAIL("not implemented"); } \
74 void SAL_CALL ClassName::removePropertyChangeListener( const OUString&, \
75 const uno::Reference<beans::XPropertyChangeListener>&) \
76 { OSL_FAIL("not implemented"); } \
77 void SAL_CALL ClassName::addVetoableChangeListener( const OUString&, \
78 const uno::Reference<beans::XVetoableChangeListener>&) \
79 { OSL_FAIL("not implemented"); } \
80 void SAL_CALL ClassName::removeVetoableChangeListener( const OUString&, \
81 const uno::Reference<beans::XVetoableChangeListener>&) \
82 { OSL_FAIL("not implemented"); }
85 class ScIndexEnumeration final
: public cppu::WeakImplHelper
<
86 css::container::XEnumeration
,
87 css::lang::XServiceInfo
>
90 css::uno::Reference
<css::container::XIndexAccess
> xIndex
;
91 OUString sServiceName
;
95 ScIndexEnumeration(css::uno::Reference
<
96 css::container::XIndexAccess
> xInd
, OUString aServiceName
);
97 virtual ~ScIndexEnumeration() override
;
100 virtual sal_Bool SAL_CALL
hasMoreElements() override
;
101 virtual css::uno::Any SAL_CALL
nextElement() override
;
104 virtual OUString SAL_CALL
getImplementationName( ) override
;
105 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
106 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
109 // new (uno 3) variant
110 class ScNameToIndexAccess final
: public cppu::WeakImplHelper
<
111 css::container::XIndexAccess
,
112 css::lang::XServiceInfo
>
115 css::uno::Reference
<css::container::XNameAccess
> xNameAccess
;
116 css::uno::Sequence
<OUString
> aNames
;
120 css::uno::Reference
< css::container::XNameAccess
> xNameObj
);
121 virtual ~ScNameToIndexAccess() override
;
124 virtual sal_Int32 SAL_CALL
getCount( ) override
;
125 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
;
128 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
129 virtual sal_Bool SAL_CALL
hasElements( ) override
;
132 virtual OUString SAL_CALL
getImplementationName( ) override
;
133 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
134 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
137 class ScUnoHelpFunctions
140 static bool GetBoolProperty( const css::uno::Reference
< css::beans::XPropertySet
>& xProp
,
141 const OUString
& rName
, bool bDefault
= false );
142 static sal_Int16
GetShortProperty( const css::uno::Reference
< css::beans::XPropertySet
>& xProp
,
143 const OUString
& rName
, sal_Int16 nDefault
);
144 static sal_Int32
GetLongProperty( const css::uno::Reference
< css::beans::XPropertySet
>& xProp
,
145 const OUString
& rName
);
146 template<typename EnumT
>
147 static EnumT
GetEnumProperty( const css::uno::Reference
< css::beans::XPropertySet
>& xProp
,
148 const OUString
& rName
, EnumT nDefault
)
149 { return static_cast<EnumT
>(GetEnumPropertyImpl(xProp
, rName
, static_cast<sal_Int32
>(nDefault
))); }
151 static OUString
GetStringProperty(
152 const css::uno::Reference
<css::beans::XPropertySet
>& xProp
,
153 const OUString
& rName
, const OUString
& rDefault
);
155 SC_DLLPUBLIC
static bool GetBoolFromAny( const css::uno::Any
& aAny
);
156 SC_DLLPUBLIC
static sal_Int16
GetInt16FromAny( const css::uno::Any
& aAny
);
157 static sal_Int32
GetInt32FromAny( const css::uno::Any
& aAny
);
158 static sal_Int32
GetEnumFromAny( const css::uno::Any
& aAny
);
160 static void SetOptionalPropertyValue(
161 const css::uno::Reference
< css::beans::XPropertySet
>& rPropSet
,
162 const char* pPropName
, const css::uno::Any
& rVal
);
163 static void SetOptionalPropertyValue(
164 const css::uno::Reference
< css::beans::XPropertySet
>& rPropSet
,
165 const OUString
& rPropName
, const css::uno::Any
& rVal
);
167 template<typename ValueType
>
168 static void SetOptionalPropertyValue(
169 const css::uno::Reference
< css::beans::XPropertySet
>& rPropSet
,
170 const char* pPropName
, const ValueType
& rVal
)
174 SetOptionalPropertyValue(rPropSet
, pPropName
, any
);
176 template<typename ValueType
>
177 static void SetOptionalPropertyValue(
178 const css::uno::Reference
< css::beans::XPropertySet
>& rPropSet
,
179 const OUString
& rPropName
, const ValueType
& rVal
)
183 SetOptionalPropertyValue(rPropSet
, rPropName
, any
);
187 static sal_Int32
GetEnumPropertyImpl( const css::uno::Reference
< css::beans::XPropertySet
>& xProp
,
188 const OUString
& rName
, sal_Int32 nDefault
);
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */