1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_LINGUISTIC_SOURCE_LNGOPT_HXX
21 #define INCLUDED_LINGUISTIC_SOURCE_LNGOPT_HXX
22 
23 #include <cppuhelper/implbase.hxx>
24 #include <cppuhelper/interfacecontainer.hxx>
25 #include <comphelper/interfacecontainer2.hxx>
26 #include <com/sun/star/beans/XFastPropertySet.hpp>
27 #include <com/sun/star/beans/XPropertyAccess.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/lang/XComponent.hpp>
30 #include <com/sun/star/linguistic2/XLinguProperties.hpp>
31 #include <unotools/lingucfg.hxx>
32 #include <svl/itemprop.hxx>
33 #include <unotools/linguprops.hxx>
34 #include <com/sun/star/uno/Any.h>
35 
36 namespace com { namespace sun { namespace star {
37     namespace beans {
38         struct PropertyChangeEvent;
39     }
40 }}}
41 
42 
43 // LinguOptions
44 // This class represents all Linguistik relevant options.
45 
46 class LinguOptions
47 {
48     static SvtLinguOptions     *pData;
49     static oslInterlockedCount  nRefCount;  // number of objects of this class
50 
51 public:
52     LinguOptions();
53     LinguOptions(const LinguOptions &rOpt);
54     ~LinguOptions();
55 
56     static OUString    GetName( sal_Int32 nWID );
57 
58     const css::uno::Sequence< OUString >&
GetActiveDics() const59             GetActiveDics() const   { return pData->aActiveDics; }
60 };
61 
62 typedef cppu::OMultiTypeInterfaceContainerHelperVar<sal_Int32>
63     OPropertyListenerContainerHelper;
64 
65 class LinguProps :
66     public cppu::WeakImplHelper
67     <
68         css::linguistic2::XLinguProperties,
69         css::beans::XFastPropertySet,
70         css::beans::XPropertyAccess,
71         css::lang::XComponent,
72         css::lang::XServiceInfo
73     >
74 {
75     ::comphelper::OInterfaceContainerHelper2           aEvtListeners;
76     OPropertyListenerContainerHelper            aPropListeners;
77 
78     SfxItemPropertyMap                          aPropertyMap;
79     SvtLinguConfig                              aConfig;
80 
81     bool                                        bDisposing;
82 
83     LinguProps(const LinguProps &) = delete;
84     LinguProps & operator = (const LinguProps &) = delete;
85 
86     void    launchEvent( const css::beans::PropertyChangeEvent &rEvt ) const;
87 
88     /// @throws css::uno::RuntimeException
89     bool getPropertyBool(const OUString& aPropertyName);
90     /// @throws css::uno::RuntimeException
91     sal_Int16 getPropertyInt16(const OUString& aPropertyName);
92     /// @throws css::uno::RuntimeException
93     css::lang::Locale getPropertyLocale(const OUString& aPropertyName);
94     /// @throws css::uno::RuntimeException
setProperty(const OUString & aPropertyName,bool p1)95     void setProperty(const OUString& aPropertyName, bool p1)
96         { setPropertyValue( aPropertyName, css::uno::Any(p1) ); }
97     /// @throws css::uno::RuntimeException
setProperty(const OUString & aPropertyName,sal_Int16 p1)98     void setProperty(const OUString& aPropertyName, sal_Int16 p1)
99         { setPropertyValue( aPropertyName, css::uno::Any(p1) ); }
100     /// @throws css::uno::RuntimeException
setProperty(const OUString & aPropertyName,css::lang::Locale p1)101     void setProperty(const OUString& aPropertyName, css::lang::Locale p1)
102         { setPropertyValue( aPropertyName, css::uno::Any(p1) ); }
103 
104 public:
105     LinguProps();
106 
getIsUseDictionaryList()107     virtual sal_Bool SAL_CALL getIsUseDictionaryList() override
108         { return getPropertyBool(UPN_IS_USE_DICTIONARY_LIST); }
setIsUseDictionaryList(sal_Bool p1)109     virtual void SAL_CALL setIsUseDictionaryList(sal_Bool p1) override
110         { setProperty(UPN_IS_USE_DICTIONARY_LIST, static_cast<bool>(p1)); }
getIsIgnoreControlCharacters()111     virtual sal_Bool SAL_CALL getIsIgnoreControlCharacters() override
112         { return getPropertyBool(UPN_IS_IGNORE_CONTROL_CHARACTERS); }
setIsIgnoreControlCharacters(sal_Bool p1)113     virtual void SAL_CALL setIsIgnoreControlCharacters(sal_Bool p1) override
114         { setProperty(UPN_IS_IGNORE_CONTROL_CHARACTERS, static_cast<bool>(p1)); }
getIsSpellUpperCase()115     virtual sal_Bool SAL_CALL getIsSpellUpperCase() override
116         { return getPropertyBool(UPN_IS_SPELL_UPPER_CASE); }
setIsSpellUpperCase(sal_Bool p1)117     virtual void SAL_CALL setIsSpellUpperCase(sal_Bool p1) override
118         { setProperty(UPN_IS_SPELL_UPPER_CASE, static_cast<bool>(p1)); }
getIsSpellWithDigits()119     virtual sal_Bool SAL_CALL getIsSpellWithDigits() override
120         { return getPropertyBool(UPN_IS_SPELL_WITH_DIGITS); }
setIsSpellWithDigits(sal_Bool p1)121     virtual void SAL_CALL setIsSpellWithDigits(sal_Bool p1) override
122         { setProperty(UPN_IS_SPELL_WITH_DIGITS, static_cast<bool>(p1)); }
getIsSpellCapitalization()123     virtual sal_Bool SAL_CALL getIsSpellCapitalization() override
124         { return getPropertyBool(UPN_IS_SPELL_CAPITALIZATION); }
setIsSpellCapitalization(sal_Bool p1)125     virtual void SAL_CALL setIsSpellCapitalization(sal_Bool p1) override
126         { setProperty(UPN_IS_SPELL_CAPITALIZATION, static_cast<bool>(p1)); }
getHyphMinLeading()127     virtual sal_Int16 SAL_CALL getHyphMinLeading() override
128         { return getPropertyInt16(UPN_HYPH_MIN_LEADING); }
setHyphMinLeading(sal_Int16 p1)129     virtual void SAL_CALL setHyphMinLeading(sal_Int16 p1) override
130         { setProperty(UPN_HYPH_MIN_LEADING, p1); }
getHyphMinTrailing()131     virtual sal_Int16 SAL_CALL getHyphMinTrailing() override
132         { return getPropertyInt16(UPN_HYPH_MIN_TRAILING); }
setHyphMinTrailing(sal_Int16 p1)133     virtual void SAL_CALL setHyphMinTrailing(sal_Int16 p1) override
134         { setProperty(UPN_HYPH_MIN_TRAILING, p1); }
getHyphMinWordLength()135     virtual sal_Int16 SAL_CALL getHyphMinWordLength() override
136         { return getPropertyInt16(UPN_HYPH_MIN_WORD_LENGTH); }
setHyphMinWordLength(sal_Int16 p1)137     virtual void SAL_CALL setHyphMinWordLength(sal_Int16 p1) override
138         { setProperty(UPN_HYPH_MIN_WORD_LENGTH, p1); }
getDefaultLocale()139     virtual css::lang::Locale SAL_CALL getDefaultLocale() override
140         { return getPropertyLocale(UPN_DEFAULT_LOCALE); }
setDefaultLocale(const css::lang::Locale & p1)141     virtual void SAL_CALL setDefaultLocale(const css::lang::Locale& p1) override
142         { setProperty(UPN_DEFAULT_LOCALE, p1); }
getIsHyphAuto()143     virtual sal_Bool SAL_CALL getIsHyphAuto() override
144         { return getPropertyBool(UPN_IS_HYPH_AUTO); }
setIsHyphAuto(sal_Bool p1)145     virtual void SAL_CALL setIsHyphAuto(sal_Bool p1) override
146         { setProperty(UPN_IS_HYPH_AUTO, static_cast<bool>(p1)); }
getIsHyphSpecial()147     virtual sal_Bool SAL_CALL getIsHyphSpecial() override
148         { return getPropertyBool(UPN_IS_HYPH_SPECIAL); }
setIsHyphSpecial(sal_Bool p1)149     virtual void SAL_CALL setIsHyphSpecial(sal_Bool p1) override
150         { setProperty(UPN_IS_HYPH_SPECIAL, static_cast<bool>(p1)); }
getIsSpellAuto()151     virtual sal_Bool SAL_CALL getIsSpellAuto() override
152         { return getPropertyBool(UPN_IS_SPELL_AUTO); }
setIsSpellAuto(sal_Bool p1)153     virtual void SAL_CALL setIsSpellAuto(sal_Bool p1) override
154         { setProperty(UPN_IS_SPELL_AUTO, static_cast<bool>(p1)); }
getIsSpellSpecial()155     virtual sal_Bool SAL_CALL getIsSpellSpecial() override
156         { return getPropertyBool(UPN_IS_SPELL_SPECIAL); }
setIsSpellSpecial(sal_Bool p1)157     virtual void SAL_CALL setIsSpellSpecial(sal_Bool p1) override
158         { setProperty(UPN_IS_SPELL_SPECIAL, static_cast<bool>(p1)); }
getIsWrapReverse()159     virtual sal_Bool SAL_CALL getIsWrapReverse() override
160         { return getPropertyBool(UPN_IS_WRAP_REVERSE); }
setIsWrapReverse(sal_Bool p1)161     virtual void SAL_CALL setIsWrapReverse(sal_Bool p1) override
162         { setProperty(UPN_IS_WRAP_REVERSE, static_cast<bool>(p1)); }
getDefaultLocale_CJK()163     virtual css::lang::Locale SAL_CALL getDefaultLocale_CJK() override
164         { return getPropertyLocale(UPN_DEFAULT_LOCALE_CJK); }
setDefaultLocale_CJK(const css::lang::Locale & p1)165     virtual void SAL_CALL setDefaultLocale_CJK(const css::lang::Locale& p1) override
166         { setProperty(UPN_DEFAULT_LOCALE_CJK, p1); }
getDefaultLocale_CTL()167     virtual css::lang::Locale SAL_CALL getDefaultLocale_CTL() override
168         { return getPropertyLocale(UPN_DEFAULT_LOCALE_CTL); }
setDefaultLocale_CTL(const css::lang::Locale & p1)169     virtual void SAL_CALL setDefaultLocale_CTL(const css::lang::Locale& p1) override
170         { setProperty(UPN_DEFAULT_LOCALE_CTL, p1); }
171 
172     // XPropertySet
173     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
174     virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
175     virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
176     virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& rxListener ) override;
177     virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& rxListener ) override;
178     virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& rxListener ) override;
179     virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& rxListener ) override;
180 
181     // XFastPropertySet
182     virtual void SAL_CALL setFastPropertyValue( sal_Int32 nHandle, const css::uno::Any& aValue ) override;
183     virtual css::uno::Any SAL_CALL getFastPropertyValue( sal_Int32 nHandle ) override;
184 
185     // XPropertyAccess
186     virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getPropertyValues() override;
187     virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& aProps ) override;
188 
189     // XComponent
190     virtual void SAL_CALL dispose() override;
191     virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) override;
192     virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) override;
193 
194     // XServiceInfo
195     virtual OUString SAL_CALL getImplementationName() override;
196     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
197     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
198 
199 
200     static inline OUString getImplementationName_Static() throw();
201     static css::uno::Sequence< OUString > getSupportedServiceNames_Static() throw();
202 };
203 
getImplementationName_Static()204 inline OUString LinguProps::getImplementationName_Static() throw()
205 {
206     return "com.sun.star.lingu2.LinguProps";
207 }
208 
209 
210 #endif
211 
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
213