bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / uno / dlelstnr.cxx
blobac8c54cb87cf30b90bf0762051472e21232cf2a1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/frame/Desktop.hpp>
22 #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
23 #include <com/sun/star/linguistic2/XDictionaryList.hpp>
24 #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
25 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
26 #include <com/sun/star/linguistic2/ProofreadingIterator.hpp>
27 #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
29 #include <unotools/lingucfg.hxx>
31 #include <com/sun/star/uno/Reference.h>
32 #include <comphelper/processfactory.hxx>
33 #include <osl/mutex.hxx>
34 #include <vcl/svapp.hxx>
35 #include <tools/shl.hxx>
36 #include "dlelstnr.hxx"
37 #include <swmodule.hxx>
38 #include <wrtsh.hxx>
39 #include <view.hxx>
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::frame;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::linguistic2;
46 using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags;
48 SwLinguServiceEventListener::SwLinguServiceEventListener()
50 Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
51 try
53 xDesktop = frame::Desktop::create(xContext);
54 xDesktop->addTerminateListener( this );
56 xLngSvcMgr = LinguServiceManager::create(xContext);
57 xLngSvcMgr->addLinguServiceManagerListener( (XLinguServiceEventListener *) this );
59 if (SvtLinguConfig().HasGrammarChecker())
61 xGCIterator = ProofreadingIterator::create(xContext);
62 Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY );
63 if (xBC.is())
64 xBC->addLinguServiceEventListener( (XLinguServiceEventListener *) this );
67 catch (const uno::Exception&)
69 OSL_FAIL("exception caught in SwLinguServiceEventListener c-tor" );
73 SwLinguServiceEventListener::~SwLinguServiceEventListener()
77 void SwLinguServiceEventListener::processDictionaryListEvent(
78 const DictionaryListEvent& rDicListEvent)
79 throw( RuntimeException )
81 SolarMutexGuard aGuard;
83 sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
85 sal_Int16 nSpellWrongFlags =
86 DictionaryListEventFlags::ADD_POS_ENTRY |
87 DictionaryListEventFlags::DEL_NEG_ENTRY |
88 DictionaryListEventFlags::ACTIVATE_POS_DIC |
89 DictionaryListEventFlags::DEACTIVATE_NEG_DIC;
90 bool bIsSpellWrong = 0 != (nEvt & nSpellWrongFlags);
91 sal_Int16 nSpellAllFlags =
92 DictionaryListEventFlags::ADD_NEG_ENTRY |
93 DictionaryListEventFlags::DEL_POS_ENTRY |
94 DictionaryListEventFlags::ACTIVATE_NEG_DIC |
95 DictionaryListEventFlags::DEACTIVATE_POS_DIC;
96 bool bIsSpellAll = 0 != (nEvt & nSpellAllFlags);
98 if (bIsSpellWrong || bIsSpellAll)
99 SW_MOD()->CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
102 void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent(
103 const LinguServiceEvent& rLngSvcEvent )
104 throw(RuntimeException)
106 SolarMutexGuard aGuard;
108 bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
109 bool bIsSpellAll = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
110 if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN))
111 bIsSpellWrong = bIsSpellAll = true; // have all spelling and grammar checked...
112 if (bIsSpellWrong || bIsSpellAll)
114 SW_MOD()->CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
116 if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
118 SwView *pSwView = SW_MOD()->GetFirstView();
120 //!! since this function may be called within the ctor of
121 //!! SwView (during formatting) where the WrtShell is not yet
122 //!! created, we have to check for the WrtShellPtr to see
123 //!! if it is already availbale
124 while (pSwView && pSwView->GetWrtShellPtr())
126 pSwView->GetWrtShell().ChgHyphenation();
127 pSwView = SW_MOD()->GetNextView( pSwView );
132 void SAL_CALL SwLinguServiceEventListener::disposing(
133 const EventObject& rEventObj )
134 throw(RuntimeException)
136 SolarMutexGuard aGuard;
138 if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
139 xLngSvcMgr = 0;
140 if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator)
141 xGCIterator = 0;
144 void SAL_CALL SwLinguServiceEventListener::queryTermination(
145 const EventObject& /*rEventObj*/ )
146 throw(TerminationVetoException, RuntimeException)
150 void SAL_CALL SwLinguServiceEventListener::notifyTermination(
151 const EventObject& rEventObj )
152 throw(RuntimeException)
154 SolarMutexGuard aGuard;
156 if (xDesktop.is() && rEventObj.Source == xDesktop)
158 if (xLngSvcMgr.is())
159 xLngSvcMgr = 0;
160 if (xGCIterator.is())
161 xGCIterator = 0;
162 xDesktop = NULL;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */