Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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>
28 :
29 : #include <unotools/lingucfg.hxx>
30 :
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>
40 :
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;
47 :
48 19 : SwLinguServiceEventListener::SwLinguServiceEventListener()
49 : {
50 19 : Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
51 : try
52 : {
53 19 : xDesktop = frame::Desktop::create(xContext);
54 19 : xDesktop->addTerminateListener( this );
55 :
56 19 : xLngSvcMgr = LinguServiceManager::create(xContext);
57 19 : xLngSvcMgr->addLinguServiceManagerListener( (XLinguServiceEventListener *) this );
58 :
59 19 : if (SvtLinguConfig().HasGrammarChecker())
60 : {
61 0 : xGCIterator = ProofreadingIterator::create(xContext);
62 0 : Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY );
63 0 : if (xBC.is())
64 0 : xBC->addLinguServiceEventListener( (XLinguServiceEventListener *) this );
65 : }
66 : }
67 0 : catch (const uno::Exception&)
68 : {
69 : OSL_FAIL("exception caught in SwLinguServiceEventListener c-tor" );
70 19 : }
71 19 : }
72 :
73 24 : SwLinguServiceEventListener::~SwLinguServiceEventListener()
74 : {
75 24 : }
76 :
77 0 : void SwLinguServiceEventListener::processDictionaryListEvent(
78 : const DictionaryListEvent& rDicListEvent)
79 : throw( RuntimeException )
80 : {
81 0 : SolarMutexGuard aGuard;
82 :
83 0 : sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
84 :
85 : sal_Int16 nSpellWrongFlags =
86 : DictionaryListEventFlags::ADD_POS_ENTRY |
87 : DictionaryListEventFlags::DEL_NEG_ENTRY |
88 : DictionaryListEventFlags::ACTIVATE_POS_DIC |
89 0 : DictionaryListEventFlags::DEACTIVATE_NEG_DIC;
90 0 : 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 0 : DictionaryListEventFlags::DEACTIVATE_POS_DIC;
96 0 : bool bIsSpellAll = 0 != (nEvt & nSpellAllFlags);
97 :
98 0 : if (bIsSpellWrong || bIsSpellAll)
99 0 : SW_MOD()->CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
100 0 : }
101 :
102 0 : void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent(
103 : const LinguServiceEvent& rLngSvcEvent )
104 : throw(RuntimeException)
105 : {
106 0 : SolarMutexGuard aGuard;
107 :
108 0 : bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
109 0 : bool bIsSpellAll = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
110 0 : if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN))
111 0 : bIsSpellWrong = bIsSpellAll = true; // have all spelling and grammar checked...
112 0 : if (bIsSpellWrong || bIsSpellAll)
113 : {
114 0 : SW_MOD()->CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
115 : }
116 0 : if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
117 : {
118 0 : SwView *pSwView = SW_MOD()->GetFirstView();
119 :
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 0 : while (pSwView && pSwView->GetWrtShellPtr())
125 : {
126 0 : pSwView->GetWrtShell().ChgHyphenation();
127 0 : pSwView = SW_MOD()->GetNextView( pSwView );
128 : }
129 0 : }
130 0 : }
131 :
132 38 : void SAL_CALL SwLinguServiceEventListener::disposing(
133 : const EventObject& rEventObj )
134 : throw(RuntimeException)
135 : {
136 38 : SolarMutexGuard aGuard;
137 :
138 38 : if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
139 7 : xLngSvcMgr = 0;
140 38 : if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator)
141 0 : xGCIterator = 0;
142 38 : }
143 :
144 12 : void SAL_CALL SwLinguServiceEventListener::queryTermination(
145 : const EventObject& /*rEventObj*/ )
146 : throw(TerminationVetoException, RuntimeException)
147 : {
148 12 : }
149 :
150 12 : void SAL_CALL SwLinguServiceEventListener::notifyTermination(
151 : const EventObject& rEventObj )
152 : throw(RuntimeException)
153 : {
154 12 : SolarMutexGuard aGuard;
155 :
156 12 : if (xDesktop.is() && rEventObj.Source == xDesktop)
157 : {
158 12 : if (xLngSvcMgr.is())
159 12 : xLngSvcMgr = 0;
160 12 : if (xGCIterator.is())
161 0 : xGCIterator = 0;
162 12 : xDesktop = NULL;
163 12 : }
164 111 : }
165 :
166 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|