xref: /AOO41X/main/sw/source/ui/uno/dlelstnr.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
31cdf0e10cSrcweir #include <com/sun/star/linguistic2/XDictionaryList.hpp>
32cdf0e10cSrcweir #include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
33cdf0e10cSrcweir #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
34cdf0e10cSrcweir #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
35cdf0e10cSrcweir #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir #include <vos/mutex.hxx>
42cdf0e10cSrcweir #include <vcl/svapp.hxx>
43cdf0e10cSrcweir #include <tools/shl.hxx>
44cdf0e10cSrcweir #include "dlelstnr.hxx"
45cdf0e10cSrcweir #include <swmodule.hxx>
46cdf0e10cSrcweir #include <wrtsh.hxx>
47cdf0e10cSrcweir #include <view.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using ::rtl::OUString;
51cdf0e10cSrcweir using namespace ::com::sun::star;
52cdf0e10cSrcweir using namespace ::com::sun::star::lang;
53cdf0e10cSrcweir using namespace ::com::sun::star::frame;
54cdf0e10cSrcweir using namespace ::com::sun::star::uno;
55cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2;
56cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #define A2OU(x)	OUString::createFromAscii(x)
59cdf0e10cSrcweir 
60cdf0e10cSrcweir /* -----------------------------17.03.00 09:07--------------------------------
61cdf0e10cSrcweir 
62cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SwLinguServiceEventListener()63cdf0e10cSrcweir SwLinguServiceEventListener::SwLinguServiceEventListener()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xMgr( comphelper::getProcessServiceFactory() );
66cdf0e10cSrcweir 	if (xMgr.is())
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir         try
69cdf0e10cSrcweir         {
70cdf0e10cSrcweir             OUString aSvcName( A2OU( "com.sun.star.frame.Desktop" ) );
71cdf0e10cSrcweir             xDesktop = Reference< frame::XDesktop >(
72cdf0e10cSrcweir                     xMgr->createInstance( aSvcName ), UNO_QUERY );
73cdf0e10cSrcweir             if (xDesktop.is())
74cdf0e10cSrcweir                 xDesktop->addTerminateListener( this );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir             aSvcName = A2OU( "com.sun.star.linguistic2.LinguServiceManager" );
77cdf0e10cSrcweir             xLngSvcMgr = Reference< XLinguServiceManager >( xMgr->createInstance( aSvcName ), UNO_QUERY );
78cdf0e10cSrcweir             if (xLngSvcMgr.is())
79cdf0e10cSrcweir                 xLngSvcMgr->addLinguServiceManagerListener( (XLinguServiceEventListener *) this );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir             if (SvtLinguConfig().HasGrammarChecker())
82cdf0e10cSrcweir             {
83cdf0e10cSrcweir                 aSvcName = A2OU( "com.sun.star.linguistic2.ProofreadingIterator" );
84cdf0e10cSrcweir                 xGCIterator = Reference< XProofreadingIterator >( xMgr->createInstance( aSvcName ), UNO_QUERY );
85cdf0e10cSrcweir                 Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY );
86cdf0e10cSrcweir                 if (xBC.is())
87cdf0e10cSrcweir                     xBC->addLinguServiceEventListener( (XLinguServiceEventListener *) this );
88cdf0e10cSrcweir             }
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir         catch (uno::Exception &)
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir             DBG_ASSERT(0, "exception caught in SwLinguServiceEventListener c-tor" );
93cdf0e10cSrcweir         }
94cdf0e10cSrcweir 	}
95cdf0e10cSrcweir }
96cdf0e10cSrcweir /* -----------------------------17.03.00 09:07--------------------------------
97cdf0e10cSrcweir 
98cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
~SwLinguServiceEventListener()99cdf0e10cSrcweir SwLinguServiceEventListener::~SwLinguServiceEventListener()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir /* -----------------------------17.03.00 09:06--------------------------------
104cdf0e10cSrcweir 
105cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
106cdf0e10cSrcweir 
processDictionaryListEvent(const DictionaryListEvent & rDicListEvent)107cdf0e10cSrcweir void SwLinguServiceEventListener::processDictionaryListEvent(
108cdf0e10cSrcweir 			const DictionaryListEvent& rDicListEvent)
109cdf0e10cSrcweir 		throw( RuntimeException )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	sal_Int16 nSpellWrongFlags =
116cdf0e10cSrcweir 			DictionaryListEventFlags::ADD_POS_ENTRY 	|
117cdf0e10cSrcweir 			DictionaryListEventFlags::DEL_NEG_ENTRY		|
118cdf0e10cSrcweir 			DictionaryListEventFlags::ACTIVATE_POS_DIC	|
119cdf0e10cSrcweir 			DictionaryListEventFlags::DEACTIVATE_NEG_DIC;
120cdf0e10cSrcweir 	sal_Bool bIsSpellWrong	=  0 != (nEvt & nSpellWrongFlags);
121cdf0e10cSrcweir 	sal_Int16 nSpellAllFlags =
122cdf0e10cSrcweir 			DictionaryListEventFlags::ADD_NEG_ENTRY		|
123cdf0e10cSrcweir 			DictionaryListEventFlags::DEL_POS_ENTRY		|
124cdf0e10cSrcweir 			DictionaryListEventFlags::ACTIVATE_NEG_DIC	|
125cdf0e10cSrcweir 			DictionaryListEventFlags::DEACTIVATE_POS_DIC;
126cdf0e10cSrcweir 	sal_Bool bIsSpellAll	=  0 != (nEvt & nSpellAllFlags);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	if (bIsSpellWrong || bIsSpellAll)
129cdf0e10cSrcweir 		SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 
processLinguServiceEvent(const LinguServiceEvent & rLngSvcEvent)133cdf0e10cSrcweir void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent(
134cdf0e10cSrcweir 			const LinguServiceEvent& rLngSvcEvent )
135cdf0e10cSrcweir 		throw(RuntimeException)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	sal_Bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
140cdf0e10cSrcweir 	sal_Bool bIsSpellAll   = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
141cdf0e10cSrcweir     if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN))
142cdf0e10cSrcweir         bIsSpellWrong = bIsSpellAll = sal_True;     // have all spelling and grammar checked...
143cdf0e10cSrcweir 	if (bIsSpellWrong || bIsSpellAll)
144cdf0e10cSrcweir 	{
145cdf0e10cSrcweir 		SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False );
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir 	if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
148cdf0e10cSrcweir 	{
149cdf0e10cSrcweir 		SwView *pSwView = SW_MOD()->GetFirstView();
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         //!! since this function may be called within the ctor of
152cdf0e10cSrcweir         //!! SwView (during formatting) where the WrtShell is not yet
153cdf0e10cSrcweir         //!! created, we have to check for the WrtShellPtr to see
154cdf0e10cSrcweir         //!! if it is already availbale
155cdf0e10cSrcweir         while (pSwView && pSwView->GetWrtShellPtr())
156cdf0e10cSrcweir 		{
157cdf0e10cSrcweir 			pSwView->GetWrtShell().ChgHyphenation();
158cdf0e10cSrcweir 			pSwView = SW_MOD()->GetNextView( pSwView );
159cdf0e10cSrcweir 		}
160cdf0e10cSrcweir 	}
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 
disposing(const EventObject & rEventObj)164cdf0e10cSrcweir void SAL_CALL SwLinguServiceEventListener::disposing(
165cdf0e10cSrcweir 			const EventObject& rEventObj )
166cdf0e10cSrcweir 		throw(RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	if (xLngSvcMgr.is()  &&  rEventObj.Source == xLngSvcMgr)
171cdf0e10cSrcweir 		xLngSvcMgr = 0;
172cdf0e10cSrcweir     if (xLngSvcMgr.is()  &&  rEventObj.Source == xGCIterator)
173cdf0e10cSrcweir         xGCIterator = 0;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 
queryTermination(const EventObject &)177cdf0e10cSrcweir void SAL_CALL SwLinguServiceEventListener::queryTermination(
178cdf0e10cSrcweir 			const EventObject& /*rEventObj*/ )
179cdf0e10cSrcweir 		throw(TerminationVetoException, RuntimeException)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	//vos::OGuard aGuard(Application::GetSolarMutex());
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 
notifyTermination(const EventObject & rEventObj)185cdf0e10cSrcweir void SAL_CALL SwLinguServiceEventListener::notifyTermination(
186cdf0e10cSrcweir 			const EventObject& rEventObj )
187cdf0e10cSrcweir 		throw(RuntimeException)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	if (xDesktop.is()  &&  rEventObj.Source == xDesktop)
192cdf0e10cSrcweir 	{
193cdf0e10cSrcweir 		if (xLngSvcMgr.is())
194cdf0e10cSrcweir 			xLngSvcMgr = 0;
195cdf0e10cSrcweir         if (xGCIterator.is())
196cdf0e10cSrcweir             xGCIterator = 0;
197cdf0e10cSrcweir 		xDesktop = NULL;
198cdf0e10cSrcweir 	}
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201