001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037 #include "precompiled_sw.hxx"
038
039
040
041
042 #ifndef _COM_SUN_STAR_LINGUISTIC2_DICTIONARYLISTEVENTFLAGS_HPP_
043 #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
044 #endif
045 #ifndef _COM_SUN_STAR_LINGUISTIC_XDICTIONARYLIST_HPP_
046 #include <com/sun/star/linguistic2/XDictionaryList.hpp>
047 #endif
048 #ifndef _COM_SUN_STAR_LINGUISTIC2_XLINGUSERVICEMANAGER_HPP_
049 #include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
050 #endif
051 #ifndef _COM_SUN_STAR_LINGUISTIC2_LINGUSERVICEEVENTFLAGS_HPP_
052 #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
053 #endif
054
055 #include <com/sun/star/uno/Reference.h>
056
057 #ifndef _COMPHELPER_PROCESSFACTORY_HXX_
058 #include <comphelper/processfactory.hxx>
059 #endif
060
061 #ifndef _VOS_MUTEX_HXX_
062 #include <vos/mutex.hxx>
063 #endif
064 #ifndef _SV_SVAPP_HXX
065 #include <vcl/svapp.hxx>
066 #endif
067 #ifndef _SHL_HXX
068 #include <tools/shl.hxx>
069 #endif
070
071 #ifndef _DLELSTNR_HXX_
072 #include "dlelstnr.hxx"
073 #endif
074 #ifndef _SWMODULE_HXX
075 #include <swmodule.hxx>
076 #endif
077 #ifndef _WRTSH_HXX
078 #include <wrtsh.hxx>
079 #endif
080 #ifndef _SWVIEW_HXX
081 #include <view.hxx>
082 #endif
083
084
085 using namespace ::rtl;
086 using namespace ::com::sun::star;
087 using namespace ::com::sun::star::lang;
088 using namespace ::com::sun::star::frame;
089 using namespace ::com::sun::star::uno;
090 using namespace ::com::sun::star::linguistic2;
091 using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags;
092
093 #define A2OU(x) OUString::createFromAscii(x)
094
095
096
097
098 SwLinguServiceEventListener::SwLinguServiceEventListener()
099 {
100 Reference< XMultiServiceFactory > xMgr( comphelper::getProcessServiceFactory() );
101 if (xMgr.is())
102 {
103 OUString aSvcName( A2OU( "com.sun.star.frame.Desktop" ) );
104 xDesktop = Reference< frame::XDesktop >(
105 xMgr->createInstance( aSvcName ), UNO_QUERY );
106 if (xDesktop.is())
107 xDesktop->addTerminateListener( this );
108
109 aSvcName = A2OU( "com.sun.star.linguistic2.LinguServiceManager" );
110 xLngSvcMgr = Reference< XLinguServiceManager >(
111 xMgr->createInstance( aSvcName ), UNO_QUERY );
112 if (xLngSvcMgr.is())
113 xLngSvcMgr->addLinguServiceManagerListener(
114 (XLinguServiceEventListener *) this );
115 }
116 }
117
118
119
120 SwLinguServiceEventListener::~SwLinguServiceEventListener()
121 {
122 }
123
124
125
126
127
128 void SwLinguServiceEventListener::processDictionaryListEvent(
129 const DictionaryListEvent& rDicListEvent)
130 throw( RuntimeException )
131 {
132 vos::OGuard aGuard(Application::GetSolarMutex());
133
134 sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
135
136 sal_Int16 nSpellWrongFlags =
137 DictionaryListEventFlags::ADD_POS_ENTRY |
138 DictionaryListEventFlags::DEL_NEG_ENTRY |
139 DictionaryListEventFlags::ACTIVATE_POS_DIC |
140 DictionaryListEventFlags::DEACTIVATE_NEG_DIC;
141 sal_Bool bIsSpellWrong = 0 != (nEvt & nSpellWrongFlags);
142 sal_Int16 nSpellAllFlags =
143 DictionaryListEventFlags::ADD_NEG_ENTRY |
144 DictionaryListEventFlags::DEL_POS_ENTRY |
145 DictionaryListEventFlags::ACTIVATE_NEG_DIC |
146 DictionaryListEventFlags::DEACTIVATE_POS_DIC;
147 sal_Bool bIsSpellAll = 0 != (nEvt & nSpellAllFlags);
148
149 if (bIsSpellWrong || bIsSpellAll)
150 SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False );
151 }
152
153
154 void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent(
155 const LinguServiceEvent& rLngSvcEvent )
156 throw(RuntimeException)
157 {
158 vos::OGuard aGuard(Application::GetSolarMutex());
159
160 if (rLngSvcEvent.Source == xLngSvcMgr)
161 {
162 sal_Bool bIsSpellWrong =
163 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
164 sal_Bool bIsSpellAll =
165 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
166 if (bIsSpellWrong || bIsSpellAll)
167 {
168 SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False );
169 }
170 if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
171 {
172 SwView *pSwView = SW_MOD()->GetFirstView();
173
174
175
176
177
178 while (pSwView && pSwView->GetWrtShellPtr())
179 {
180 pSwView->GetWrtShell().ChgHyphenation();
181 pSwView = SW_MOD()->GetNextView( pSwView );
182 }
183 }
184 }
185 }
186
187
188 void SAL_CALL SwLinguServiceEventListener::disposing(
189 const EventObject& rEventObj )
190 throw(RuntimeException)
191 {
192 vos::OGuard aGuard(Application::GetSolarMutex());
193
194 if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
195 {
196 xLngSvcMgr = 0;
197 }
198 }
199
200
201 void SAL_CALL SwLinguServiceEventListener::queryTermination(
202 const EventObject& )
203 throw(TerminationVetoException, RuntimeException)
204 {
205
206 }
207
208
209 void SAL_CALL SwLinguServiceEventListener::notifyTermination(
210 const EventObject& rEventObj )
211 throw(RuntimeException)
212 {
213 vos::OGuard aGuard(Application::GetSolarMutex());
214
215 if (xDesktop.is() && rEventObj.Source == xDesktop)
216 {
217 if (xLngSvcMgr.is())
218 {
219 xLngSvcMgr->removeLinguServiceManagerListener(
220 (XLinguServiceEventListener *) this );
221 xLngSvcMgr = 0;
222 }
223 xDesktop = NULL;
224 }
225 }
226