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 .
20 #ifndef INCLUDED_SC_INC_MISCUNO_HXX
21 #define INCLUDED_SC_INC_MISCUNO_HXX
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>
35 #define SC_SIMPLE_SERVICE_INFO( ClassName, ClassNameAscii, ServiceAscii ) \
36 OUString SAL_CALL ClassName::getImplementationName() \
38 return ClassNameAscii; \
40 sal_Bool SAL_CALL ClassName::supportsService( const OUString& ServiceName ) \
42 return cppu::supportsService(this, ServiceName); \
44 css::uno::Sequence< OUString > \
45 SAL_CALL ClassName::getSupportedServiceNames() \
47 css::uno::Sequence< OUString > aRet { ServiceAscii }; \
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
>
81 css::uno::Reference
<css::container::XIndexAccess
> xIndex
;
82 OUString
const sServiceName
;
86 ScIndexEnumeration(const css::uno::Reference
<
87 css::container::XIndexAccess
>& rInd
, const OUString
& rServiceName
);
88 virtual ~ScIndexEnumeration() override
;
91 virtual sal_Bool SAL_CALL
hasMoreElements() override
;
92 virtual css::uno::Any SAL_CALL
nextElement() override
;
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
>
106 css::uno::Reference
<css::container::XNameAccess
> xNameAccess
;
107 css::uno::Sequence
<OUString
> aNames
;
111 const css::uno::Reference
< css::container::XNameAccess
>& rNameObj
);
112 virtual ~ScNameToIndexAccess() override
;
115 virtual sal_Int32 SAL_CALL
getCount( ) override
;
116 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
;
119 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
120 virtual sal_Bool SAL_CALL
hasElements( ) override
;
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
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
)
162 SetOptionalPropertyValue(rPropSet
, pPropName
, any
);
165 template<typename ValueType
>
166 static css::uno::Sequence
<ValueType
> VectorToSequence( const std::vector
<ValueType
>& rVector
)
169 return css::uno::Sequence
<ValueType
>();
171 return css::uno::Sequence
<ValueType
>(&rVector
[0], static_cast<sal_Int32
>(rVector
.size()));
174 static sal_Int32
GetEnumPropertyImpl( const css::uno::Reference
< css::beans::XPropertySet
>& xProp
,
175 const OUString
& rName
, sal_Int32 nDefault
);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */