Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / inc / afmtuno.hxx
blob6434a5073c0eec5cde8e3779bed7dca683127ebc
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 <rtl/ref.hxx>
23 #include <svl/itemprop.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/container/XIndexAccess.hpp>
26 #include <com/sun/star/container/XEnumerationAccess.hpp>
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #include <com/sun/star/container/XNamed.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <comphelper/servicehelper.hxx>
31 #include <cppuhelper/implbase.hxx>
33 #include <climits>
35 class ScAutoFormatFieldObj;
36 class ScAutoFormatObj;
38 #define SC_AFMTOBJ_INVALID USHRT_MAX
40 class ScAutoFormatsObj final : public ::cppu::WeakImplHelper<
41 css::container::XNameContainer,
42 css::container::XEnumerationAccess,
43 css::container::XIndexAccess,
44 css::lang::XServiceInfo >
46 private:
47 static rtl::Reference<ScAutoFormatObj> GetObjectByIndex_Impl(sal_uInt16 nIndex);
48 static rtl::Reference<ScAutoFormatObj> GetObjectByName_Impl(std::u16string_view aName);
50 public:
51 ScAutoFormatsObj();
52 virtual ~ScAutoFormatsObj() override;
54 // XNameContainer
55 virtual void SAL_CALL insertByName( const OUString& aName,
56 const css::uno::Any& aElement ) override;
57 virtual void SAL_CALL removeByName( const OUString& Name ) override;
59 // XNameReplace
60 virtual void SAL_CALL replaceByName( const OUString& aName,
61 const css::uno::Any& aElement ) override;
63 // XNameAccess
64 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
65 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
66 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
68 // XElementAccess
69 virtual css::uno::Type SAL_CALL getElementType() override;
70 virtual sal_Bool SAL_CALL hasElements() override;
72 // XEnumerationAccess
73 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
74 createEnumeration() override;
76 // XIndexAccess
77 virtual sal_Int32 SAL_CALL getCount() override;
78 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
80 // XServiceInfo
81 virtual OUString SAL_CALL getImplementationName() override;
82 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
83 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
86 class ScAutoFormatObj final : public ::cppu::WeakImplHelper<
87 css::container::XIndexAccess,
88 css::container::XEnumerationAccess,
89 css::container::XNamed,
90 css::beans::XPropertySet,
91 css::lang::XServiceInfo >
93 private:
94 SfxItemPropertySet aPropSet;
95 sal_uInt16 nFormatIndex;
97 rtl::Reference<ScAutoFormatFieldObj> GetObjectByIndex_Impl(sal_uInt16 nIndex);
99 public:
100 ScAutoFormatObj(sal_uInt16 nIndex);
101 virtual ~ScAutoFormatObj() override;
103 // called via getImplementation:
104 bool IsInserted() const { return nFormatIndex != SC_AFMTOBJ_INVALID; }
105 void InitFormat( sal_uInt16 nNewIndex );
107 // XIndexAccess
108 virtual sal_Int32 SAL_CALL getCount() override;
109 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
111 // XElementAccess
112 virtual css::uno::Type SAL_CALL getElementType() override;
113 virtual sal_Bool SAL_CALL hasElements() override;
115 // XEnumerationAccess
116 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
117 createEnumeration() override;
119 // XNamed
120 virtual OUString SAL_CALL getName() override;
121 virtual void SAL_CALL setName( const OUString& aName ) override;
123 // XPropertySet
124 virtual css::uno::Reference< css::beans::XPropertySetInfo >
125 SAL_CALL getPropertySetInfo() override;
126 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
127 const css::uno::Any& aValue ) override;
128 virtual css::uno::Any SAL_CALL getPropertyValue(
129 const OUString& PropertyName ) override;
130 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
131 const css::uno::Reference<
132 css::beans::XPropertyChangeListener >& xListener ) override;
133 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
134 const css::uno::Reference<
135 css::beans::XPropertyChangeListener >& aListener ) override;
136 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
137 const css::uno::Reference<
138 css::beans::XVetoableChangeListener >& aListener ) override;
139 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
140 const css::uno::Reference<
141 css::beans::XVetoableChangeListener >& aListener ) override;
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;
149 class ScAutoFormatFieldObj final : public ::cppu::WeakImplHelper<
150 css::beans::XPropertySet,
151 css::lang::XServiceInfo >
153 private:
154 SfxItemPropertySet aPropSet;
155 sal_uInt16 nFormatIndex;
156 sal_uInt16 nFieldIndex;
158 public:
159 ScAutoFormatFieldObj(sal_uInt16 nFormat, sal_uInt16 nField);
160 virtual ~ScAutoFormatFieldObj() override;
162 // XPropertySet
163 virtual css::uno::Reference< css::beans::XPropertySetInfo >
164 SAL_CALL getPropertySetInfo() override;
165 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
166 const css::uno::Any& aValue ) override;
167 virtual css::uno::Any SAL_CALL getPropertyValue(
168 const OUString& PropertyName ) override;
169 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
170 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
171 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
172 const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
173 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
174 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
175 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
176 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
178 // XServiceInfo
179 virtual OUString SAL_CALL getImplementationName() override;
180 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
181 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */