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/LinguServiceEventFlags.hpp>
24 
25 #include <unotools/lingucfg.hxx>
26 
27 #include <com/sun/star/uno/Reference.h>
29 #include <vcl/svapp.hxx>
30 #include <dlelstnr.hxx>
31 #include <proofreadingiterator.hxx>
32 #include <swmodule.hxx>
33 #include <wrtsh.hxx>
34 #include <view.hxx>
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::frame;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::linguistic2;
41 using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags;
42 
44 {
46  try
47  {
48  xDesktop = frame::Desktop::create(xContext);
49  xDesktop->addTerminateListener( this );
50 
51  xLngSvcMgr = LinguServiceManager::create(xContext);
52  xLngSvcMgr->addLinguServiceManagerListener( static_cast<XLinguServiceEventListener *>(this) );
53 
54  if (SvtLinguConfig().HasGrammarChecker())
55  {
57  Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY );
58  if (xBC.is())
59  xBC->addLinguServiceEventListener( static_cast<XLinguServiceEventListener *>(this) );
60  }
61  }
62  catch (const uno::Exception&)
63  {
64  OSL_FAIL("exception caught in SwLinguServiceEventListener c-tor" );
65  }
66 }
67 
69 {
70 }
71 
73  const LinguServiceEvent& rLngSvcEvent )
74 {
75  SolarMutexGuard aGuard;
76 
77  bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
78  bool bIsSpellAll = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
79  if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN))
80  bIsSpellWrong = bIsSpellAll = true; // have all spelling and grammar checked...
81  if (bIsSpellWrong || bIsSpellAll)
82  {
83  SwModule::CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
84  }
85  if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
86  {
87  SwView *pSwView = SwModule::GetFirstView();
88 
93  while (pSwView && pSwView->GetWrtShellPtr())
94  {
95  pSwView->GetWrtShell().ChgHyphenation();
96  pSwView = SwModule::GetNextView( pSwView );
97  }
98  }
99 }
100 
102  const EventObject& rEventObj )
103 {
104  SolarMutexGuard aGuard;
105 
106  if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
107  xLngSvcMgr = nullptr;
108  if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator)
109  xGCIterator = nullptr;
110 }
111 
113  const EventObject& /*rEventObj*/ )
114 {
115 }
116 
118  const EventObject& rEventObj )
119 {
120  SolarMutexGuard aGuard;
121 
122  if (xDesktop.is() && rEventObj.Source == xDesktop)
123  {
124  if (xLngSvcMgr.is())
125  xLngSvcMgr = nullptr;
126  if (xGCIterator.is())
127  xGCIterator = nullptr;
128  xDesktop = nullptr;
129  }
130 }
131 
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
virtual void SAL_CALL processLinguServiceEvent(const css::linguistic2::LinguServiceEvent &rLngSvcEvent) override
XLinguServiceEventListener.
Definition: dlelstnr.cxx:72
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
static void CheckSpellChanges(bool bOnlineSpelling, bool bIsSpellWrongAgain, bool bIsSpellAllAgain, bool bSmartTags)
Definition: swmodul1.cxx:650
void ChgHyphenation()
Definition: viewsh.hxx:211
virtual ~SwLinguServiceEventListener() override
Definition: dlelstnr.cxx:68
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &rEventObj) override
Definition: dlelstnr.cxx:117
static SwView * GetFirstView()
Definition: swmodul1.cxx:129
virtual void SAL_CALL disposing(const css::lang::EventObject &rEventObj) override
XEventListener.
Definition: dlelstnr.cxx:101
css::uno::Reference< css::linguistic2::XLinguServiceManager2 > xLngSvcMgr
Definition: dlelstnr.hxx:50
virtual void SAL_CALL queryTermination(const css::lang::EventObject &rEventObj) override
XTerminateListener.
Definition: dlelstnr.cxx:112
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:401
css::uno::Reference< css::linguistic2::XProofreadingIterator > xGCIterator
Definition: dlelstnr.hxx:51
Reference< XComponentContext > getProcessComponentContext()
static SwView * GetNextView(SwView const *)
Definition: swmodul1.cxx:136
css::uno::Reference< css::frame::XDesktop2 > xDesktop
Definition: dlelstnr.hxx:49
Definition: view.hxx:146