Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / linguistic / lngprophelp.hxx
blob85b32b7cec3e0e4be83534975eaad9084f568a16
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 #ifndef INCLUDED_LINGUISTIC_LNGPROPHELP_HXX
21 #define INCLUDED_LINGUISTIC_LNGPROPHELP_HXX
23 #include <cppuhelper/implbase.hxx>
24 #include <comphelper/interfacecontainer3.hxx>
25 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
26 #include <com/sun/star/beans/PropertyValues.hpp>
27 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
28 #include <linguistic/lngdllapi.h>
29 #include <rtl/ref.hxx>
30 #include <config_options.h>
32 namespace com::sun::star::beans { class XPropertySet; }
33 namespace com::sun::star::linguistic2 { struct LinguServiceEvent; }
34 namespace com::sun::star::linguistic2 { class XLinguProperties; }
37 namespace linguistic
40 // PropertyChgHelper
41 // Base class for all XPropertyChangeListener members of the
42 // various lingu services.
45 // Flags for type of events allowed to be launched
46 #define AE_SPELLCHECKER 1
47 #define AE_HYPHENATOR 2
49 typedef cppu::WeakImplHelper
51 css::beans::XPropertyChangeListener,
52 css::linguistic2::XLinguServiceEventBroadcaster
53 > PropertyChgHelperBase;
55 class UNLESS_MERGELIBS(LNG_DLLPUBLIC) PropertyChgHelper :
56 public PropertyChgHelperBase
58 std::vector< OUString > aPropNames;
59 css::uno::Reference< css::uno::XInterface > xMyEvtObj;
60 ::comphelper::OInterfaceContainerHelper3<css::linguistic2::XLinguServiceEventListener> aLngSvcEvtListeners;
61 css::uno::Reference< css::beans::XPropertySet > xPropSet;
63 int nEvtFlags; // flags for event types allowed to be launched
65 // default values
66 bool bIsIgnoreControlCharacters;
67 bool bIsUseDictionaryList;
69 // return values, will be set to default value or current temporary value
70 bool bResIsIgnoreControlCharacters;
71 bool bResIsUseDictionaryList;
73 PropertyChgHelper( const PropertyChgHelper & ) = delete;
74 PropertyChgHelper & operator = ( const PropertyChgHelper & ) = delete;
76 protected:
77 virtual void SetDefaultValues();
78 virtual void GetCurrentValues();
80 std::vector< OUString > & GetPropNames() { return aPropNames; }
81 css::uno::Reference<
82 css::beans::XPropertySet > &
83 GetPropSet() { return xPropSet; }
85 virtual bool propertyChange_Impl( const css::beans::PropertyChangeEvent& rEvt );
87 public:
88 PropertyChgHelper(
89 const css::uno::Reference< css::uno::XInterface > &rxSource,
90 css::uno::Reference< css::linguistic2::XLinguProperties > const &rxPropSet,
91 int nAllowedEvents );
92 virtual ~PropertyChgHelper() override;
94 virtual void SetTmpPropVals( const css::beans::PropertyValues &rPropVals );
96 // XEventListener
97 virtual void SAL_CALL
98 disposing( const css::lang::EventObject& rSource ) override;
100 // XPropertyChangeListener
101 virtual void SAL_CALL
102 propertyChange( const css::beans::PropertyChangeEvent& rEvt ) override;
104 // XLinguServiceEventBroadcaster
105 virtual sal_Bool SAL_CALL
106 addLinguServiceEventListener(
107 const css::uno::Reference< css::linguistic2::XLinguServiceEventListener >& rxListener ) override;
108 virtual sal_Bool SAL_CALL
109 removeLinguServiceEventListener(
110 const css::uno::Reference< css::linguistic2::XLinguServiceEventListener >& rxListener ) override;
112 // non-UNO functions
113 void AddAsPropListener();
114 void RemoveAsPropListener();
115 void LaunchEvent( const css::linguistic2::LinguServiceEvent& rEvt );
117 const std::vector< OUString > &
118 GetPropNames() const { return aPropNames; }
119 const css::uno::Reference< css::beans::XPropertySet > &
120 GetPropSet() const { return xPropSet; }
121 const css::uno::Reference< css::uno::XInterface > &
122 GetEvtObj() const { return xMyEvtObj; }
126 class PropertyHelper_Thes final :
127 public PropertyChgHelper
129 PropertyHelper_Thes( const PropertyHelper_Thes & ) = delete;
130 PropertyHelper_Thes & operator = ( const PropertyHelper_Thes & ) = delete;
132 public:
133 PropertyHelper_Thes(
134 const css::uno::Reference< css::uno::XInterface > &rxSource,
135 css::uno::Reference< css::linguistic2::XLinguProperties > const &rxPropSet );
136 virtual ~PropertyHelper_Thes() override;
138 // XPropertyChangeListener
139 virtual void SAL_CALL
140 propertyChange( const css::beans::PropertyChangeEvent& rEvt ) override;
143 class UNLESS_MERGELIBS(LNG_DLLPUBLIC) PropertyHelper_Thesaurus
145 rtl::Reference< PropertyHelper_Thes > mxPropHelper;
147 // disallow use of copy-constructor and assignment-operator
148 PropertyHelper_Thesaurus( const PropertyHelper_Thes & ) = delete;
149 PropertyHelper_Thesaurus & operator = ( const PropertyHelper_Thes & ) = delete;
151 public:
152 PropertyHelper_Thesaurus(
153 const css::uno::Reference< css::uno::XInterface > &rxSource,
154 css::uno::Reference< css::linguistic2::XLinguProperties > const &rxPropSet );
155 ~PropertyHelper_Thesaurus();
156 void AddAsPropListener();
157 void RemoveAsPropListener();
158 void SetTmpPropVals( const css::beans::PropertyValues &rPropVals );
162 class UNLESS_MERGELIBS(LNG_DLLPUBLIC) PropertyHelper_Spell final :
163 public PropertyChgHelper
165 // default values
166 bool bIsSpellUpperCase;
167 bool bIsSpellWithDigits;
168 bool bIsSpellCapitalization;
169 bool bIsSpellClosedCompound;
170 bool bIsSpellHyphenatedCompound;
172 // return values, will be set to default value or current temporary value
173 bool bResIsSpellUpperCase;
174 bool bResIsSpellWithDigits;
175 bool bResIsSpellCapitalization;
176 bool bResIsSpellClosedCompound;
177 bool bResIsSpellHyphenatedCompound;
179 PropertyHelper_Spell( const PropertyHelper_Spell & ) = delete;
180 PropertyHelper_Spell & operator = ( const PropertyHelper_Spell & ) = delete;
182 // PropertyChgHelper
183 virtual void SetDefaultValues() override;
184 virtual void GetCurrentValues() override;
185 virtual bool propertyChange_Impl(
186 const css::beans::PropertyChangeEvent& rEvt ) override;
188 public:
189 PropertyHelper_Spell(
190 const css::uno::Reference< css::uno::XInterface > &rxSource,
191 css::uno::Reference< css::linguistic2::XLinguProperties > const &rxPropSet );
192 virtual ~PropertyHelper_Spell() override;
194 virtual void SetTmpPropVals( const css::beans::PropertyValues &rPropVals ) override;
196 // XPropertyChangeListener
197 virtual void SAL_CALL
198 propertyChange( const css::beans::PropertyChangeEvent& rEvt ) override;
200 bool IsSpellUpperCase() const { return bResIsSpellUpperCase; }
201 bool IsSpellWithDigits() const { return bResIsSpellWithDigits; }
202 bool IsSpellCapitalization() const { return bResIsSpellCapitalization; }
203 bool IsSpellClosedCompound() const { return bResIsSpellClosedCompound; }
204 bool IsSpellHyphenatedCompound() const { return bResIsSpellHyphenatedCompound; }
208 class UNLESS_MERGELIBS(LNG_DLLPUBLIC) PropertyHelper_Spelling
210 rtl::Reference< PropertyHelper_Spell > mxPropHelper;
212 // disallow use of copy-constructor and assignment-operator
213 PropertyHelper_Spelling( const PropertyHelper_Spell & ) = delete;
214 PropertyHelper_Spelling & operator = ( const PropertyHelper_Spell & ) = delete;
216 public:
217 PropertyHelper_Spelling(
218 const css::uno::Reference< css::uno::XInterface > &rxSource,
219 css::uno::Reference< css::linguistic2::XLinguProperties > const &rxPropSet );
220 ~PropertyHelper_Spelling();
222 void AddAsPropListener();
223 void RemoveAsPropListener();
224 void SetTmpPropVals( const css::beans::PropertyValues &rPropVals );
225 bool IsSpellUpperCase() const;
226 bool IsSpellWithDigits() const;
227 bool IsSpellCapitalization() const;
228 bool IsSpellClosedCompound() const;
229 bool IsSpellHyphenatedCompound() const;
230 /// @throws css::uno::RuntimeException
231 bool addLinguServiceEventListener(
232 const css::uno::Reference< css::linguistic2::XLinguServiceEventListener >& rxListener );
233 /// @throws css::uno::RuntimeException
234 bool removeLinguServiceEventListener(
235 const css::uno::Reference< css::linguistic2::XLinguServiceEventListener >& rxListener );
239 class PropertyHelper_Hyphen final :
240 public PropertyChgHelper
242 // default values
243 sal_Int16 nHyphMinLeading,
244 nHyphMinTrailing,
245 nHyphMinWordLength;
246 bool bNoHyphenateCaps;
248 // return values, will be set to default value or current temporary value
249 sal_Int16 nResHyphMinLeading,
250 nResHyphMinTrailing,
251 nResHyphMinWordLength;
252 bool bResNoHyphenateCaps;
254 PropertyHelper_Hyphen( const PropertyHelper_Hyphen & ) = delete;
255 PropertyHelper_Hyphen & operator = ( const PropertyHelper_Hyphen & ) = delete;
257 // PropertyChgHelper
258 virtual void SetDefaultValues() override;
259 virtual void GetCurrentValues() override;
260 virtual bool propertyChange_Impl(
261 const css::beans::PropertyChangeEvent& rEvt ) override;
263 public:
264 PropertyHelper_Hyphen(
265 const css::uno::Reference< css::uno::XInterface > &rxSource,
266 css::uno::Reference< css::linguistic2::XLinguProperties > const &rxPropSet);
267 virtual ~PropertyHelper_Hyphen() override;
269 virtual void SetTmpPropVals( const css::beans::PropertyValues &rPropVals ) override;
271 // XPropertyChangeListener
272 virtual void SAL_CALL
273 propertyChange( const css::beans::PropertyChangeEvent& rEvt ) override;
275 sal_Int16 GetMinLeading() const { return nResHyphMinLeading; }
276 sal_Int16 GetMinTrailing() const { return nResHyphMinTrailing; }
277 sal_Int16 GetMinWordLength() const { return nResHyphMinWordLength; }
278 bool IsNoHyphenateCaps() const { return bResNoHyphenateCaps; }
281 class UNLESS_MERGELIBS(LNG_DLLPUBLIC) PropertyHelper_Hyphenation
283 rtl::Reference< PropertyHelper_Hyphen > mxPropHelper;
285 // disallow use of copy-constructor and assignment-operator
286 PropertyHelper_Hyphenation( const PropertyHelper_Hyphen & ) = delete;
287 PropertyHelper_Hyphenation & operator = ( const PropertyHelper_Hyphen & ) = delete;
289 public:
290 PropertyHelper_Hyphenation(
291 const css::uno::Reference< css::uno::XInterface > &rxSource,
292 css::uno::Reference< css::linguistic2::XLinguProperties > const &rxPropSet);
293 ~PropertyHelper_Hyphenation();
295 void AddAsPropListener();
296 void RemoveAsPropListener();
297 void SetTmpPropVals( const css::beans::PropertyValues &rPropVals );
298 sal_Int16 GetMinLeading() const;
299 sal_Int16 GetMinTrailing() const;
300 sal_Int16 GetMinWordLength() const;
301 bool IsNoHyphenateCaps() const;
302 /// @throws css::uno::RuntimeException
303 bool addLinguServiceEventListener(
304 const css::uno::Reference< css::linguistic2::XLinguServiceEventListener >& rxListener );
305 /// @throws css::uno::RuntimeException
306 bool removeLinguServiceEventListener(
307 const css::uno::Reference< css::linguistic2::XLinguServiceEventListener >& rxListener );
310 } // namespace linguistic
312 #endif
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */