1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <com/sun/star/frame/Desktop.hpp>
21 #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
22 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
23 #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
24 #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
26 #include <unotools/lingucfg.hxx>
27 #include <comphelper/diagnose_ex.hxx>
29 #include <com/sun/star/uno/Reference.h>
30 #include <comphelper/processfactory.hxx>
31 #include <vcl/svapp.hxx>
32 #include <dlelstnr.hxx>
33 #include <proofreadingiterator.hxx>
34 #include <swmodule.hxx>
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::frame
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::linguistic2
;
43 using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags
;
45 SwLinguServiceEventListener::SwLinguServiceEventListener()
47 Reference
< XComponentContext
> xContext( comphelper::getProcessComponentContext() );
50 m_xDesktop
= frame::Desktop::create(xContext
);
51 m_xDesktop
->addTerminateListener( this );
53 m_xLngSvcMgr
= LinguServiceManager::create(xContext
);
54 m_xLngSvcMgr
->addLinguServiceManagerListener( static_cast<XLinguServiceEventListener
*>(this) );
56 if (SvtLinguConfig().HasGrammarChecker())
58 m_xGCIterator
= sw::proofreadingiterator::get(xContext
);
59 Reference
< XLinguServiceEventBroadcaster
> xBC( m_xGCIterator
, UNO_QUERY
);
61 xBC
->addLinguServiceEventListener( static_cast<XLinguServiceEventListener
*>(this) );
64 catch (const uno::Exception
&)
66 TOOLS_WARN_EXCEPTION( "sw", "SwLinguServiceEventListener c-tor" );
70 SwLinguServiceEventListener::~SwLinguServiceEventListener()
74 void SAL_CALL
SwLinguServiceEventListener::processLinguServiceEvent(
75 const LinguServiceEvent
& rLngSvcEvent
)
77 SolarMutexGuard aGuard
;
79 bool bIsSpellWrong
= 0 != (rLngSvcEvent
.nEvent
& SPELL_WRONG_WORDS_AGAIN
);
80 bool bIsSpellAll
= 0 != (rLngSvcEvent
.nEvent
& SPELL_CORRECT_WORDS_AGAIN
);
81 if (0 != (rLngSvcEvent
.nEvent
& PROOFREAD_AGAIN
))
82 bIsSpellWrong
= bIsSpellAll
= true; // have all spelling and grammar checked...
83 if (bIsSpellWrong
|| bIsSpellAll
)
85 SwModule::CheckSpellChanges( false, bIsSpellWrong
, bIsSpellAll
, false );
87 if (!(rLngSvcEvent
.nEvent
& HYPHENATE_AGAIN
))
90 SwView
*pSwView
= SwModule::GetFirstView();
92 //!! since this function may be called within the ctor of
93 //!! SwView (during formatting) where the WrtShell is not yet
94 //!! created, we have to check for the WrtShellPtr to see
95 //!! if it is already available
96 while (pSwView
&& pSwView
->GetWrtShellPtr())
98 pSwView
->GetWrtShell().ChgHyphenation();
99 pSwView
= SwModule::GetNextView( pSwView
);
103 void SAL_CALL
SwLinguServiceEventListener::disposing(
104 const EventObject
& rEventObj
)
106 SolarMutexGuard aGuard
;
108 if (m_xLngSvcMgr
.is() && rEventObj
.Source
== m_xLngSvcMgr
)
109 m_xLngSvcMgr
= nullptr;
110 if (m_xLngSvcMgr
.is() && rEventObj
.Source
== m_xGCIterator
)
111 m_xGCIterator
= nullptr;
114 void SAL_CALL
SwLinguServiceEventListener::queryTermination(
115 const EventObject
& /*rEventObj*/ )
119 void SAL_CALL
SwLinguServiceEventListener::notifyTermination(
120 const EventObject
& rEventObj
)
122 SolarMutexGuard aGuard
;
124 if (m_xDesktop
.is() && rEventObj
.Source
== m_xDesktop
)
126 if (m_xLngSvcMgr
.is())
127 m_xLngSvcMgr
= nullptr;
128 if (m_xGCIterator
.is())
129 m_xGCIterator
= nullptr;
130 m_xDesktop
= nullptr;
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */