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