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 : #include <com/sun/star/frame/Desktop.hpp>
21 : #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
22 : #include <com/sun/star/linguistic2/XDictionaryList.hpp>
23 : #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
24 : #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
25 : #include <com/sun/star/linguistic2/ProofreadingIterator.hpp>
26 : #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
27 :
28 : #include <unotools/lingucfg.hxx>
29 :
30 : #include <com/sun/star/uno/Reference.h>
31 : #include <comphelper/processfactory.hxx>
32 : #include <osl/mutex.hxx>
33 : #include <vcl/svapp.hxx>
34 : #include <tools/shl.hxx>
35 : #include "dlelstnr.hxx"
36 : #include <swmodule.hxx>
37 : #include <wrtsh.hxx>
38 : #include <view.hxx>
39 :
40 : using namespace ::com::sun::star;
41 : using namespace ::com::sun::star::lang;
42 : using namespace ::com::sun::star::frame;
43 : using namespace ::com::sun::star::uno;
44 : using namespace ::com::sun::star::linguistic2;
45 : using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags;
46 :
47 0 : SwLinguServiceEventListener::SwLinguServiceEventListener()
48 : {
49 0 : Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
50 : try
51 : {
52 0 : xDesktop = frame::Desktop::create(xContext);
53 0 : xDesktop->addTerminateListener( this );
54 :
55 0 : xLngSvcMgr = LinguServiceManager::create(xContext);
56 0 : xLngSvcMgr->addLinguServiceManagerListener( (XLinguServiceEventListener *) this );
57 :
58 0 : if (SvtLinguConfig().HasGrammarChecker())
59 : {
60 0 : xGCIterator = ProofreadingIterator::create(xContext);
61 0 : Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY );
62 0 : if (xBC.is())
63 0 : xBC->addLinguServiceEventListener( (XLinguServiceEventListener *) this );
64 : }
65 : }
66 0 : catch (const uno::Exception&)
67 : {
68 : OSL_FAIL("exception caught in SwLinguServiceEventListener c-tor" );
69 0 : }
70 0 : }
71 :
72 0 : SwLinguServiceEventListener::~SwLinguServiceEventListener()
73 : {
74 0 : }
75 :
76 0 : void SwLinguServiceEventListener::processDictionaryListEvent(
77 : const DictionaryListEvent& rDicListEvent)
78 : throw( RuntimeException )
79 : {
80 0 : SolarMutexGuard aGuard;
81 :
82 0 : sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
83 :
84 : sal_Int16 nSpellWrongFlags =
85 : DictionaryListEventFlags::ADD_POS_ENTRY |
86 : DictionaryListEventFlags::DEL_NEG_ENTRY |
87 : DictionaryListEventFlags::ACTIVATE_POS_DIC |
88 0 : DictionaryListEventFlags::DEACTIVATE_NEG_DIC;
89 0 : bool bIsSpellWrong = 0 != (nEvt & nSpellWrongFlags);
90 : sal_Int16 nSpellAllFlags =
91 : DictionaryListEventFlags::ADD_NEG_ENTRY |
92 : DictionaryListEventFlags::DEL_POS_ENTRY |
93 : DictionaryListEventFlags::ACTIVATE_NEG_DIC |
94 0 : DictionaryListEventFlags::DEACTIVATE_POS_DIC;
95 0 : bool bIsSpellAll = 0 != (nEvt & nSpellAllFlags);
96 :
97 0 : if (bIsSpellWrong || bIsSpellAll)
98 0 : SW_MOD()->CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
99 0 : }
100 :
101 0 : void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent(
102 : const LinguServiceEvent& rLngSvcEvent )
103 : throw(RuntimeException, std::exception)
104 : {
105 0 : SolarMutexGuard aGuard;
106 :
107 0 : bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
108 0 : bool bIsSpellAll = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
109 0 : if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN))
110 0 : bIsSpellWrong = bIsSpellAll = true; // have all spelling and grammar checked...
111 0 : if (bIsSpellWrong || bIsSpellAll)
112 : {
113 0 : SW_MOD()->CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
114 : }
115 0 : if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
116 : {
117 0 : SwView *pSwView = SW_MOD()->GetFirstView();
118 :
119 : //!! since this function may be called within the ctor of
120 : //!! SwView (during formatting) where the WrtShell is not yet
121 : //!! created, we have to check for the WrtShellPtr to see
122 : //!! if it is already availbale
123 0 : while (pSwView && pSwView->GetWrtShellPtr())
124 : {
125 0 : pSwView->GetWrtShell().ChgHyphenation();
126 0 : pSwView = SW_MOD()->GetNextView( pSwView );
127 : }
128 0 : }
129 0 : }
130 :
131 0 : void SAL_CALL SwLinguServiceEventListener::disposing(
132 : const EventObject& rEventObj )
133 : throw(RuntimeException, std::exception)
134 : {
135 0 : SolarMutexGuard aGuard;
136 :
137 0 : if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
138 0 : xLngSvcMgr = 0;
139 0 : if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator)
140 0 : xGCIterator = 0;
141 0 : }
142 :
143 0 : void SAL_CALL SwLinguServiceEventListener::queryTermination(
144 : const EventObject& /*rEventObj*/ )
145 : throw(TerminationVetoException, RuntimeException, std::exception)
146 : {
147 0 : }
148 :
149 0 : void SAL_CALL SwLinguServiceEventListener::notifyTermination(
150 : const EventObject& rEventObj )
151 : throw(RuntimeException, std::exception)
152 : {
153 0 : SolarMutexGuard aGuard;
154 :
155 0 : if (xDesktop.is() && rEventObj.Source == xDesktop)
156 : {
157 0 : if (xLngSvcMgr.is())
158 0 : xLngSvcMgr = 0;
159 0 : if (xGCIterator.is())
160 0 : xGCIterator = 0;
161 0 : xDesktop = NULL;
162 0 : }
163 0 : }
164 :
165 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|