Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / inc / miscuno.hxx
blob23289affbdbad5da795cf109fb90d73af1f8a271
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 #pragma once
22 #include <vector>
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>
29 #include <cppuhelper/implbase.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <osl/diagnose.h>
32 #include "scdllapi.h"
34 #define SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
35 OUString SAL_CALL ClassName::getImplementationName() \
36 { \
37 return ClassNameAscii; \
38 } \
39 sal_Bool SAL_CALL ClassName::supportsService( const OUString& ServiceName ) \
40 { \
41 return cppu::supportsService(this, ServiceName); \
44 #define SC_SIMPLE_SERVICE_INFO_NAME( ClassName, ServiceAscii ) \
45 css::uno::Sequence< OUString > \
46 SAL_CALL ClassName::getSupportedServiceNames() \
47 { \
48 css::uno::Sequence< OUString > aRet { ServiceAscii }; \
49 return aRet; \
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 ) \
56 css::uno::Sequence< OUString > \
57 SAL_CALL ClassName::getSupportedServiceNames() \
58 { \
59 css::uno::Sequence< OUString > aRet { ServiceAsciiMistyped, ServiceAscii }; \
60 return aRet; \
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 )
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 )
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"); }
87 class ScIndexEnumeration final : public cppu::WeakImplHelper<
88 css::container::XEnumeration,
89 css::lang::XServiceInfo >
91 private:
92 css::uno::Reference<css::container::XIndexAccess> xIndex;
93 OUString sServiceName;
94 sal_Int32 nPos;
96 public:
97 ScIndexEnumeration(css::uno::Reference<
98 css::container::XIndexAccess> xInd, OUString aServiceName);
99 virtual ~ScIndexEnumeration() override;
101 // XEnumeration
102 virtual sal_Bool SAL_CALL hasMoreElements() override;
103 virtual css::uno::Any SAL_CALL nextElement() override;
105 // XServiceInfo
106 virtual OUString SAL_CALL getImplementationName( ) override;
107 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
108 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
111 // new (uno 3) variant
112 class ScNameToIndexAccess final : public cppu::WeakImplHelper<
113 css::container::XIndexAccess,
114 css::lang::XServiceInfo >
116 private:
117 css::uno::Reference<css::container::XNameAccess> xNameAccess;
118 css::uno::Sequence<OUString> aNames;
120 public:
121 ScNameToIndexAccess(
122 css::uno::Reference< css::container::XNameAccess> xNameObj );
123 virtual ~ScNameToIndexAccess() override;
125 // XIndexAccess
126 virtual sal_Int32 SAL_CALL getCount( ) override;
127 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
129 // XElementAccess
130 virtual css::uno::Type SAL_CALL getElementType( ) override;
131 virtual sal_Bool SAL_CALL hasElements( ) override;
133 // XServiceInfo
134 virtual OUString SAL_CALL getImplementationName( ) override;
135 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
136 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
139 class SC_DLLPUBLIC ScUnoHelpFunctions
141 public:
142 static bool GetBoolProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
143 const OUString& rName, bool bDefault = false );
144 static sal_Int16 GetShortProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
145 const OUString& rName, sal_Int16 nDefault );
146 static sal_Int32 GetLongProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
147 const OUString& rName );
148 template<typename EnumT>
149 static EnumT GetEnumProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
150 const OUString& rName, EnumT nDefault )
151 { return static_cast<EnumT>(GetEnumPropertyImpl(xProp, rName, static_cast<sal_Int32>(nDefault))); }
153 static OUString GetStringProperty(
154 const css::uno::Reference<css::beans::XPropertySet>& xProp,
155 const OUString& rName, const OUString& rDefault );
157 static bool GetBoolFromAny( const css::uno::Any& aAny );
158 static sal_Int16 GetInt16FromAny( const css::uno::Any& aAny );
159 static sal_Int32 GetInt32FromAny( const css::uno::Any& aAny );
160 static sal_Int32 GetEnumFromAny( const css::uno::Any& aAny );
162 static void SetOptionalPropertyValue(
163 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
164 const char* pPropName, const css::uno::Any& rVal );
165 static void SetOptionalPropertyValue(
166 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
167 const OUString& rPropName, const css::uno::Any& rVal );
169 template<typename ValueType>
170 static void SetOptionalPropertyValue(
171 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
172 const char* pPropName, const ValueType& rVal )
174 css::uno::Any any;
175 any <<= rVal;
176 SetOptionalPropertyValue(rPropSet, pPropName, any);
178 template<typename ValueType>
179 static void SetOptionalPropertyValue(
180 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
181 const OUString& rPropName, const ValueType& rVal )
183 css::uno::Any any;
184 any <<= rVal;
185 SetOptionalPropertyValue(rPropSet, rPropName, any);
188 private:
189 static sal_Int32 GetEnumPropertyImpl( const css::uno::Reference< css::beans::XPropertySet>& xProp,
190 const OUString& rName, sal_Int32 nDefault );
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */