LibreOffice Module sw (master) 1
dlelstnr.cxx
Go to the documentation of this file.
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/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>
25
26#include <unotools/lingucfg.hxx>
28
29#include <com/sun/star/uno/Reference.h>
31#include <vcl/svapp.hxx>
32#include <dlelstnr.hxx>
34#include <swmodule.hxx>
35#include <wrtsh.hxx>
36#include <view.hxx>
37
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::lang;
40using namespace ::com::sun::star::frame;
41using namespace ::com::sun::star::uno;
42using namespace ::com::sun::star::linguistic2;
43using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags;
44
46{
47 Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
48 try
49 {
50 m_xDesktop = frame::Desktop::create(xContext);
51 m_xDesktop->addTerminateListener( this );
52
53 m_xLngSvcMgr = LinguServiceManager::create(xContext);
54 m_xLngSvcMgr->addLinguServiceManagerListener( static_cast<XLinguServiceEventListener *>(this) );
55
56 if (SvtLinguConfig().HasGrammarChecker())
57 {
59 Reference< XLinguServiceEventBroadcaster > xBC( m_xGCIterator, UNO_QUERY );
60 if (xBC.is())
61 xBC->addLinguServiceEventListener( static_cast<XLinguServiceEventListener *>(this) );
62 }
63 }
64 catch (const uno::Exception&)
65 {
66 TOOLS_WARN_EXCEPTION( "sw", "SwLinguServiceEventListener c-tor" );
67 }
68}
69
71{
72}
73
75 const LinguServiceEvent& rLngSvcEvent )
76{
77 SolarMutexGuard aGuard;
78
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)
84 {
85 SwModule::CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
86 }
87 if (!(rLngSvcEvent.nEvent & HYPHENATE_AGAIN))
88 return;
89
90 SwView *pSwView = SwModule::GetFirstView();
91
96 while (pSwView && pSwView->GetWrtShellPtr())
97 {
98 pSwView->GetWrtShell().ChgHyphenation();
99 pSwView = SwModule::GetNextView( pSwView );
100 }
101}
102
104 const EventObject& rEventObj )
105{
106 SolarMutexGuard aGuard;
107
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;
112}
113
115 const EventObject& /*rEventObj*/ )
116{
117}
118
120 const EventObject& rEventObj )
121{
122 SolarMutexGuard aGuard;
123
124 if (m_xDesktop.is() && rEventObj.Source == m_xDesktop)
125 {
126 if (m_xLngSvcMgr.is())
127 m_xLngSvcMgr = nullptr;
128 if (m_xGCIterator.is())
129 m_xGCIterator = nullptr;
130 m_xDesktop = nullptr;
131 }
132}
133
134/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XDesktop2 > m_xDesktop
Definition: dlelstnr.hxx:49
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &rEventObj) override
Definition: dlelstnr.cxx:119
virtual void SAL_CALL disposing(const css::lang::EventObject &rEventObj) override
XEventListener.
Definition: dlelstnr.cxx:103
css::uno::Reference< css::linguistic2::XProofreadingIterator > m_xGCIterator
Definition: dlelstnr.hxx:51
virtual ~SwLinguServiceEventListener() override
Definition: dlelstnr.cxx:70
css::uno::Reference< css::linguistic2::XLinguServiceManager2 > m_xLngSvcMgr
Definition: dlelstnr.hxx:50
virtual void SAL_CALL queryTermination(const css::lang::EventObject &rEventObj) override
XTerminateListener.
Definition: dlelstnr.cxx:114
virtual void SAL_CALL processLinguServiceEvent(const css::linguistic2::LinguServiceEvent &rLngSvcEvent) override
XLinguServiceEventListener.
Definition: dlelstnr.cxx:74
static void CheckSpellChanges(bool bOnlineSpelling, bool bIsSpellWrongAgain, bool bIsSpellAllAgain, bool bSmartTags)
Definition: swmodul1.cxx:643
static SwView * GetNextView(SwView const *)
Definition: swmodul1.cxx:129
static SwView * GetFirstView()
Definition: swmodul1.cxx:122
void ChgHyphenation()
Definition: viewsh.hxx:216
Definition: view.hxx:146
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:414
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)