LibreOffice Module lingucomponent (master)  1
sspellimp.hxx
Go to the documentation of this file.
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_LINGUCOMPONENT_SOURCE_SPELLCHECK_SPELL_SSPELLIMP_HXX
21 #define INCLUDED_LINGUCOMPONENT_SOURCE_SPELLCHECK_SPELL_SSPELLIMP_HXX
22 
23 #include <cppuhelper/implbase.hxx>
24 #include <com/sun/star/lang/XComponent.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/lang/XServiceDisplayName.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/beans/PropertyValues.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/linguistic2/XSpellChecker.hpp>
31 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
32 
33 #include <linguistic/misc.hxx>
35 
36 #include <lingutil.hxx>
37 #include <memory>
38 
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::linguistic2;
43 
44 class Hunspell;
45 
46 class SpellChecker :
47  public cppu::WeakImplHelper
48  <
49  XSpellChecker,
50  XLinguServiceEventBroadcaster,
51  XInitialization,
52  XComponent,
53  XServiceInfo,
54  XServiceDisplayName
55  >
56 {
57  struct DictItem
58  {
59  OUString m_aDName;
61  std::unique_ptr<Hunspell> m_pDict;
62  rtl_TextEncoding m_aDEnc;
63 
64  DictItem(OUString i_DName, Locale i_DLoc, rtl_TextEncoding i_DEnc);
65  };
66 
67  std::vector<DictItem> m_DictItems;
68 
69  Sequence< Locale > m_aSuppLocales;
70 
72  std::unique_ptr<linguistic::PropertyHelper_Spelling> m_pPropHelper;
74 
75  SpellChecker(const SpellChecker &) = delete;
76  SpellChecker & operator = (const SpellChecker &) = delete;
77 
80  {
81  return m_pPropHelper ? *m_pPropHelper : GetPropHelper_Impl();
82  }
83 
84  sal_Int16 GetSpellFailure( const OUString &rWord, const Locale &rLocale );
85  Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale );
86 
87 public:
88  SpellChecker();
89  virtual ~SpellChecker() override;
90 
91  // XSupportedLocales (for XSpellChecker)
92  virtual Sequence< Locale > SAL_CALL getLocales() override;
93  virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) override;
94 
95  // XSpellChecker
96  virtual sal_Bool SAL_CALL isValid( const OUString& rWord, const Locale& rLocale, const css::uno::Sequence< css::beans::PropertyValue >& rProperties ) override;
97  virtual Reference< XSpellAlternatives > SAL_CALL spell( const OUString& rWord, const Locale& rLocale, const css::uno::Sequence< css::beans::PropertyValue >& rProperties ) override;
98 
99  // XLinguServiceEventBroadcaster
100  virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) override;
101  virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) override;
102 
103  // XServiceDisplayName
104  virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) override;
105 
106  // XInitialization
107  virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) override;
108 
109  // XComponent
110  virtual void SAL_CALL dispose() override;
111  virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) override;
112  virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) override;
113 
114  // XServiceInfo
115  virtual OUString SAL_CALL getImplementationName() override;
116  virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override;
117  virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
118 
119  static inline OUString getImplementationName_Static() throw();
120  static Sequence< OUString > getSupportedServiceNames_Static() throw();
121 };
122 
123 inline OUString SpellChecker::getImplementationName_Static() throw()
124 {
125  return "org.openoffice.lingu.MySpellSpellChecker";
126 }
127 
128 #endif
129 
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
linguistic::PropertyHelper_Spelling & GetPropHelper()
Definition: sspellimp.hxx:79
DictItem(OUString i_DName, Locale i_DLoc, rtl_TextEncoding i_DEnc)
Definition: sspellimp.cxx:84
sal_Int16 GetSpellFailure(const OUString &rWord, const Locale &rLocale)
Definition: sspellimp.cxx:253
virtual void SAL_CALL initialize(const Sequence< Any > &rArguments) override
Definition: sspellimp.cxx:568
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: sspellimp.cxx:638
std::unique_ptr< linguistic::PropertyHelper_Spelling > m_pPropHelper
Definition: sspellimp.hxx:72
static OUString getImplementationName_Static()
Definition: sspellimp.hxx:123
Reference< XSpellAlternatives > GetProposals(const OUString &rWord, const Locale &rLocale)
Definition: sspellimp.cxx:423
virtual sal_Bool SAL_CALL addLinguServiceEventListener(const Reference< XLinguServiceEventListener > &rxLstnr) override
Definition: sspellimp.cxx:536
rtl_TextEncoding m_aDEnc
Definition: sspellimp.hxx:62
Sequence< Locale > m_aSuppLocales
Definition: sspellimp.hxx:69
virtual void SAL_CALL dispose() override
Definition: sspellimp.cxx:594
virtual sal_Bool SAL_CALL hasLocale(const Locale &rLocale) override
Definition: sspellimp.cxx:234
virtual ~SpellChecker() override
Definition: sspellimp.cxx:91
virtual sal_Bool SAL_CALL isValid(const OUString &rWord, const Locale &rLocale, const css::uno::Sequence< css::beans::PropertyValue > &rProperties) override
Definition: sspellimp.cxx:383
static Sequence< OUString > getSupportedServiceNames_Static()
Definition: sspellimp.cxx:643
virtual OUString SAL_CALL getServiceDisplayName(const Locale &rLocale) override
Definition: sspellimp.cxx:562
std::unique_ptr< Hunspell > m_pDict
Definition: sspellimp.hxx:61
virtual Reference< XSpellAlternatives > SAL_CALL spell(const OUString &rWord, const Locale &rLocale, const css::uno::Sequence< css::beans::PropertyValue > &rProperties) override
Definition: sspellimp.cxx:507
linguistic::PropertyHelper_Spelling & GetPropHelper_Impl()
Definition: sspellimp.cxx:99
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
Definition: sspellimp.cxx:633
unsigned char sal_Bool
::comphelper::OInterfaceContainerHelper2 m_aEvtListeners
Definition: sspellimp.hxx:71
std::vector< DictItem > m_DictItems
Definition: sspellimp.hxx:67
virtual sal_Bool SAL_CALL removeLinguServiceEventListener(const Reference< XLinguServiceEventListener > &rxLstnr) override
Definition: sspellimp.cxx:549
virtual Sequence< Locale > SAL_CALL getLocales() override
Definition: sspellimp.cxx:111
bool m_bDisposing
Definition: sspellimp.hxx:73
virtual void SAL_CALL removeEventListener(const Reference< XEventListener > &rxListener) override
Definition: sspellimp.cxx:619
virtual void SAL_CALL addEventListener(const Reference< XEventListener > &rxListener) override
Definition: sspellimp.cxx:611
SpellChecker & operator=(const SpellChecker &)=delete
virtual OUString SAL_CALL getImplementationName() override
Definition: sspellimp.cxx:628