merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / uno / dlelstnr.cxx
blob5453c721c0a7df2ccd1490d8d63e1b9662f310c4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlelstnr.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
37 #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
38 #include <com/sun/star/linguistic2/XDictionaryList.hpp>
39 #include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
40 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
41 #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
42 #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
44 #include <svtools/lingucfg.hxx>
46 #include <com/sun/star/uno/Reference.h>
47 #include <comphelper/processfactory.hxx>
48 #include <vos/mutex.hxx>
49 #include <vcl/svapp.hxx>
50 #include <tools/shl.hxx>
51 #include "dlelstnr.hxx"
52 #include <swmodule.hxx>
53 #include <wrtsh.hxx>
54 #include <view.hxx>
57 using ::rtl::OUString;
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::frame;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::linguistic2;
63 using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags;
65 #define A2OU(x) OUString::createFromAscii(x)
67 /* -----------------------------17.03.00 09:07--------------------------------
69 ---------------------------------------------------------------------------*/
70 SwLinguServiceEventListener::SwLinguServiceEventListener()
72 Reference< XMultiServiceFactory > xMgr( comphelper::getProcessServiceFactory() );
73 if (xMgr.is())
75 try
77 OUString aSvcName( A2OU( "com.sun.star.frame.Desktop" ) );
78 xDesktop = Reference< frame::XDesktop >(
79 xMgr->createInstance( aSvcName ), UNO_QUERY );
80 if (xDesktop.is())
81 xDesktop->addTerminateListener( this );
83 aSvcName = A2OU( "com.sun.star.linguistic2.LinguServiceManager" );
84 xLngSvcMgr = Reference< XLinguServiceManager >( xMgr->createInstance( aSvcName ), UNO_QUERY );
85 if (xLngSvcMgr.is())
86 xLngSvcMgr->addLinguServiceManagerListener( (XLinguServiceEventListener *) this );
88 if (SvtLinguConfig().HasGrammarChecker())
90 aSvcName = A2OU( "com.sun.star.linguistic2.ProofreadingIterator" );
91 xGCIterator = Reference< XProofreadingIterator >( xMgr->createInstance( aSvcName ), UNO_QUERY );
92 Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY );
93 if (xBC.is())
94 xBC->addLinguServiceEventListener( (XLinguServiceEventListener *) this );
97 catch (uno::Exception &)
99 DBG_ASSERT(0, "exception caught in SwLinguServiceEventListener c-tor" );
103 /* -----------------------------17.03.00 09:07--------------------------------
105 ---------------------------------------------------------------------------*/
106 SwLinguServiceEventListener::~SwLinguServiceEventListener()
110 /* -----------------------------17.03.00 09:06--------------------------------
112 ---------------------------------------------------------------------------*/
114 void SwLinguServiceEventListener::processDictionaryListEvent(
115 const DictionaryListEvent& rDicListEvent)
116 throw( RuntimeException )
118 vos::OGuard aGuard(Application::GetSolarMutex());
120 sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
122 sal_Int16 nSpellWrongFlags =
123 DictionaryListEventFlags::ADD_POS_ENTRY |
124 DictionaryListEventFlags::DEL_NEG_ENTRY |
125 DictionaryListEventFlags::ACTIVATE_POS_DIC |
126 DictionaryListEventFlags::DEACTIVATE_NEG_DIC;
127 sal_Bool bIsSpellWrong = 0 != (nEvt & nSpellWrongFlags);
128 sal_Int16 nSpellAllFlags =
129 DictionaryListEventFlags::ADD_NEG_ENTRY |
130 DictionaryListEventFlags::DEL_POS_ENTRY |
131 DictionaryListEventFlags::ACTIVATE_NEG_DIC |
132 DictionaryListEventFlags::DEACTIVATE_POS_DIC;
133 sal_Bool bIsSpellAll = 0 != (nEvt & nSpellAllFlags);
135 if (bIsSpellWrong || bIsSpellAll)
136 SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False );
140 void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent(
141 const LinguServiceEvent& rLngSvcEvent )
142 throw(RuntimeException)
144 vos::OGuard aGuard(Application::GetSolarMutex());
146 sal_Bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
147 sal_Bool bIsSpellAll = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
148 if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN))
149 bIsSpellWrong = bIsSpellAll = sal_True; // have all spelling and grammar checked...
150 if (bIsSpellWrong || bIsSpellAll)
152 SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False );
154 if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
156 SwView *pSwView = SW_MOD()->GetFirstView();
158 //!! since this function may be called within the ctor of
159 //!! SwView (during formatting) where the WrtShell is not yet
160 //!! created, we have to check for the WrtShellPtr to see
161 //!! if it is already availbale
162 while (pSwView && pSwView->GetWrtShellPtr())
164 pSwView->GetWrtShell().ChgHyphenation();
165 pSwView = SW_MOD()->GetNextView( pSwView );
171 void SAL_CALL SwLinguServiceEventListener::disposing(
172 const EventObject& rEventObj )
173 throw(RuntimeException)
175 vos::OGuard aGuard(Application::GetSolarMutex());
177 if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
178 xLngSvcMgr = 0;
179 if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator)
180 xGCIterator = 0;
184 void SAL_CALL SwLinguServiceEventListener::queryTermination(
185 const EventObject& /*rEventObj*/ )
186 throw(TerminationVetoException, RuntimeException)
188 //vos::OGuard aGuard(Application::GetSolarMutex());
192 void SAL_CALL SwLinguServiceEventListener::notifyTermination(
193 const EventObject& rEventObj )
194 throw(RuntimeException)
196 vos::OGuard aGuard(Application::GetSolarMutex());
198 if (xDesktop.is() && rEventObj.Source == xDesktop)
200 if (xLngSvcMgr.is())
201 xLngSvcMgr = 0;
202 if (xGCIterator.is())
203 xGCIterator = 0;
204 xDesktop = NULL;