xref: /aoo42x/main/linguistic/inc/iprcache.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _LINGUISTIC_IPRCACHE_HXX_
29 #define _LINGUISTIC_IPRCACHE_HXX_
30 
31 
32 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
33 #include <cppuhelper/implbase2.hxx>	// helper for implementations
34 
35 #include <com/sun/star/uno/Reference.h>
36 #include <com/sun/star/document/XEventListener.hpp>
37 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/linguistic2/XDictionaryListEventListener.hpp>
40 #include <com/sun/star/linguistic2/XDictionaryList.hpp>
41 
42 #include <rtl/string.hxx>
43 #include <i18npool/lang.h>
44 
45 #include <set>
46 #include <map>
47 
48 namespace linguistic
49 {
50 
51 ///////////////////////////////////////////////////////////////////////////
52 
53 class Flushable
54 {
55 public:
56 	virtual void	Flush() = 0;
57 };
58 
59 ///////////////////////////////////////////////////////////////////////////
60 
61 class FlushListener :
62 	public cppu::WeakImplHelper2
63 	<
64 		::com::sun::star::linguistic2::XDictionaryListEventListener,
65 		::com::sun::star::beans::XPropertyChangeListener
66 	>
67 {
68 	::com::sun::star::uno::Reference<
69 		::com::sun::star::linguistic2::XDictionaryList >	xDicList;
70 	::com::sun::star::uno::Reference<
71 		::com::sun::star::beans::XPropertySet >				xPropSet;
72 	Flushable				   							   *pFlushObj;
73 
74 	// don't allow to use copy-constructor and assignment-operator
75 	FlushListener(const FlushListener &);
76 	FlushListener & operator = (const FlushListener &);
77 
78 public:
79 	FlushListener( Flushable *pFO );
80 	virtual ~FlushListener();
81 
82 	inline void	SetFlushObj( Flushable *pFO)	{ pFlushObj = pFO; }
83 
84     void        SetDicList( ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionaryList > &rDL );
85     void        SetPropSet( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > &rPS );
86 
87 	//XEventListener
88     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& rSource ) throw(::com::sun::star::uno::RuntimeException);
89 
90 	// XDictionaryListEventListener
91     virtual void SAL_CALL processDictionaryListEvent( const ::com::sun::star::linguistic2::DictionaryListEvent& rDicListEvent ) throw(::com::sun::star::uno::RuntimeException);
92 
93 	// XPropertyChangeListener
94     virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt ) throw(::com::sun::star::uno::RuntimeException);
95 };
96 
97 ///////////////////////////////////////////////////////////////////////////
98 
99 class SpellCache :
100 	public Flushable
101 {
102 	::com::sun::star::uno::Reference<
103 		::com::sun::star::linguistic2::XDictionaryListEventListener >
104 						xFlushLstnr;
105 	FlushListener	   *pFlushLstnr;
106 
107     typedef std::set< ::rtl::OUString >             WordList_t;
108     typedef std::map< LanguageType, WordList_t >    LangWordList_t;
109     LangWordList_t  aWordLists;
110 
111 	// don't allow to use copy-constructor and assignment-operator
112     SpellCache(const SpellCache &);
113     SpellCache & operator = (const SpellCache &);
114 
115 public:
116     SpellCache();
117     virtual ~SpellCache();
118 
119 	// Flushable
120 	virtual void	Flush();
121 
122     void    AddWord( const ::rtl::OUString& rWord, LanguageType nLang );
123     bool    CheckWord( const ::rtl::OUString& rWord, LanguageType nLang );
124 };
125 
126 ///////////////////////////////////////////////////////////////////////////
127 
128 }	// namespace linguistic
129 
130 #endif
131 
132