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>
27 #include <tools/diagnose_ex.h>
28 
29 #include <com/sun/star/uno/Reference.h>
31 #include <vcl/svapp.hxx>
32 #include <dlelstnr.hxx>
33 #include <proofreadingiterator.hxx>
34 #include <swmodule.hxx>
35 #include <wrtsh.hxx>
36 #include <view.hxx>
37 
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;
44 
46 {
48  try
49  {
50  xDesktop = frame::Desktop::create(xContext);
51  xDesktop->addTerminateListener( this );
52 
53  xLngSvcMgr = LinguServiceManager::create(xContext);
54  xLngSvcMgr->addLinguServiceManagerListener( static_cast<XLinguServiceEventListener *>(this) );
55 
56  if (SvtLinguConfig().HasGrammarChecker())
57  {
59  Reference< XLinguServiceEventBroadcaster > xBC( 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 (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
109  xLngSvcMgr = nullptr;
110  if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator)
111  xGCIterator = nullptr;
112 }
113 
115  const EventObject& /*rEventObj*/ )
116 {
117 }
118 
120  const EventObject& rEventObj )
121 {
122  SolarMutexGuard aGuard;
123 
124  if (xDesktop.is() && rEventObj.Source == xDesktop)
125  {
126  if (xLngSvcMgr.is())
127  xLngSvcMgr = nullptr;
128  if (xGCIterator.is())
129  xGCIterator = nullptr;
130  xDesktop = nullptr;
131  }
132 }
133 
134 /* 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:74
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
static void CheckSpellChanges(bool bOnlineSpelling, bool bIsSpellWrongAgain, bool bIsSpellAllAgain, bool bSmartTags)
Definition: swmodul1.cxx:631
void ChgHyphenation()
Definition: viewsh.hxx:208
#define TOOLS_WARN_EXCEPTION(area, stream)
virtual ~SwLinguServiceEventListener() override
Definition: dlelstnr.cxx:70
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &rEventObj) override
Definition: dlelstnr.cxx:119
static SwView * GetFirstView()
Definition: swmodul1.cxx:122
virtual void SAL_CALL disposing(const css::lang::EventObject &rEventObj) override
XEventListener.
Definition: dlelstnr.cxx:103
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:114
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:414
css::uno::Reference< css::linguistic2::XProofreadingIterator > xGCIterator
Definition: dlelstnr.hxx:51
Reference< XComponentContext > getProcessComponentContext()
static SwView * GetNextView(SwView const *)
Definition: swmodul1.cxx:129
css::uno::Reference< css::frame::XDesktop2 > xDesktop
Definition: dlelstnr.hxx:49
Definition: view.hxx:144