xref: /aoo41x/main/linguistic/inc/iprcache.hxx (revision 63ce064a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _LINGUISTIC_IPRCACHE_HXX_
25 #define _LINGUISTIC_IPRCACHE_HXX_
26 
27 
28 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
29 #include <cppuhelper/implbase2.hxx>	// helper for implementations
30 
31 #include <com/sun/star/uno/Reference.h>
32 #include <com/sun/star/document/XEventListener.hpp>
33 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/linguistic2/XDictionaryListEventListener.hpp>
36 #include <com/sun/star/linguistic2/XDictionaryList.hpp>
37 
38 #include <rtl/string.hxx>
39 #include <i18npool/lang.h>
40 
41 #include <set>
42 #include <map>
43 
44 namespace linguistic
45 {
46 
47 ///////////////////////////////////////////////////////////////////////////
48 
49 class Flushable
50 {
51 public:
52 	virtual void	Flush() = 0;
53 };
54 
55 ///////////////////////////////////////////////////////////////////////////
56 
57 class FlushListener :
58 	public cppu::WeakImplHelper2
59 	<
60 		::com::sun::star::linguistic2::XDictionaryListEventListener,
61 		::com::sun::star::beans::XPropertyChangeListener
62 	>
63 {
64 	::com::sun::star::uno::Reference<
65 		::com::sun::star::linguistic2::XDictionaryList >	xDicList;
66 	::com::sun::star::uno::Reference<
67 		::com::sun::star::beans::XPropertySet >				xPropSet;
68 	Flushable				   							   *pFlushObj;
69 
70 	// don't allow to use copy-constructor and assignment-operator
71 	FlushListener(const FlushListener &);
72 	FlushListener & operator = (const FlushListener &);
73 
74 public:
75 	FlushListener( Flushable *pFO );
76 	virtual ~FlushListener();
77 
SetFlushObj(Flushable * pFO)78 	inline void	SetFlushObj( Flushable *pFO)	{ pFlushObj = pFO; }
79 
80     void        SetDicList( ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionaryList > &rDL );
81     void        SetPropSet( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > &rPS );
82 
83 	//XEventListener
84     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& rSource ) throw(::com::sun::star::uno::RuntimeException);
85 
86 	// XDictionaryListEventListener
87     virtual void SAL_CALL processDictionaryListEvent( const ::com::sun::star::linguistic2::DictionaryListEvent& rDicListEvent ) throw(::com::sun::star::uno::RuntimeException);
88 
89 	// XPropertyChangeListener
90     virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt ) throw(::com::sun::star::uno::RuntimeException);
91 };
92 
93 ///////////////////////////////////////////////////////////////////////////
94 
95 class SpellCache :
96 	public Flushable
97 {
98 	::com::sun::star::uno::Reference<
99 		::com::sun::star::linguistic2::XDictionaryListEventListener >
100 						xFlushLstnr;
101 	FlushListener	   *pFlushLstnr;
102 
103     typedef std::set< ::rtl::OUString >             WordList_t;
104     typedef std::map< LanguageType, WordList_t >    LangWordList_t;
105     LangWordList_t  aWordLists;
106 
107 	// don't allow to use copy-constructor and assignment-operator
108     SpellCache(const SpellCache &);
109     SpellCache & operator = (const SpellCache &);
110 
111 public:
112     SpellCache();
113     virtual ~SpellCache();
114 
115 	// Flushable
116 	virtual void	Flush();
117 
118     void    AddWord( const ::rtl::OUString& rWord, LanguageType nLang );
119     bool    CheckWord( const ::rtl::OUString& rWord, LanguageType nLang );
120 };
121 
122 ///////////////////////////////////////////////////////////////////////////
123 
124 }	// namespace linguistic
125 
126 #endif
127 
128