1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 28 29 30 #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp> 31 #include <com/sun/star/linguistic2/XDictionaryList.hpp> 32 #include <com/sun/star/linguistic2/XLinguServiceManager.hpp> 33 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp> 34 #include <com/sun/star/linguistic2/XProofreadingIterator.hpp> 35 #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp> 36 37 #include <unotools/lingucfg.hxx> 38 39 #include <com/sun/star/uno/Reference.h> 40 #include <comphelper/processfactory.hxx> 41 #include <vos/mutex.hxx> 42 #include <vcl/svapp.hxx> 43 #include <tools/shl.hxx> 44 #include "dlelstnr.hxx" 45 #include <swmodule.hxx> 46 #include <wrtsh.hxx> 47 #include <view.hxx> 48 49 50 using ::rtl::OUString; 51 using namespace ::com::sun::star; 52 using namespace ::com::sun::star::lang; 53 using namespace ::com::sun::star::frame; 54 using namespace ::com::sun::star::uno; 55 using namespace ::com::sun::star::linguistic2; 56 using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags; 57 58 #define A2OU(x) OUString::createFromAscii(x) 59 60 /* -----------------------------17.03.00 09:07-------------------------------- 61 62 ---------------------------------------------------------------------------*/ 63 SwLinguServiceEventListener::SwLinguServiceEventListener() 64 { 65 Reference< XMultiServiceFactory > xMgr( comphelper::getProcessServiceFactory() ); 66 if (xMgr.is()) 67 { 68 try 69 { 70 OUString aSvcName( A2OU( "com.sun.star.frame.Desktop" ) ); 71 xDesktop = Reference< frame::XDesktop >( 72 xMgr->createInstance( aSvcName ), UNO_QUERY ); 73 if (xDesktop.is()) 74 xDesktop->addTerminateListener( this ); 75 76 aSvcName = A2OU( "com.sun.star.linguistic2.LinguServiceManager" ); 77 xLngSvcMgr = Reference< XLinguServiceManager >( xMgr->createInstance( aSvcName ), UNO_QUERY ); 78 if (xLngSvcMgr.is()) 79 xLngSvcMgr->addLinguServiceManagerListener( (XLinguServiceEventListener *) this ); 80 81 if (SvtLinguConfig().HasGrammarChecker()) 82 { 83 aSvcName = A2OU( "com.sun.star.linguistic2.ProofreadingIterator" ); 84 xGCIterator = Reference< XProofreadingIterator >( xMgr->createInstance( aSvcName ), UNO_QUERY ); 85 Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY ); 86 if (xBC.is()) 87 xBC->addLinguServiceEventListener( (XLinguServiceEventListener *) this ); 88 } 89 } 90 catch (uno::Exception &) 91 { 92 DBG_ASSERT(0, "exception caught in SwLinguServiceEventListener c-tor" ); 93 } 94 } 95 } 96 /* -----------------------------17.03.00 09:07-------------------------------- 97 98 ---------------------------------------------------------------------------*/ 99 SwLinguServiceEventListener::~SwLinguServiceEventListener() 100 { 101 } 102 103 /* -----------------------------17.03.00 09:06-------------------------------- 104 105 ---------------------------------------------------------------------------*/ 106 107 void SwLinguServiceEventListener::processDictionaryListEvent( 108 const DictionaryListEvent& rDicListEvent) 109 throw( RuntimeException ) 110 { 111 vos::OGuard aGuard(Application::GetSolarMutex()); 112 113 sal_Int16 nEvt = rDicListEvent.nCondensedEvent; 114 115 sal_Int16 nSpellWrongFlags = 116 DictionaryListEventFlags::ADD_POS_ENTRY | 117 DictionaryListEventFlags::DEL_NEG_ENTRY | 118 DictionaryListEventFlags::ACTIVATE_POS_DIC | 119 DictionaryListEventFlags::DEACTIVATE_NEG_DIC; 120 sal_Bool bIsSpellWrong = 0 != (nEvt & nSpellWrongFlags); 121 sal_Int16 nSpellAllFlags = 122 DictionaryListEventFlags::ADD_NEG_ENTRY | 123 DictionaryListEventFlags::DEL_POS_ENTRY | 124 DictionaryListEventFlags::ACTIVATE_NEG_DIC | 125 DictionaryListEventFlags::DEACTIVATE_POS_DIC; 126 sal_Bool bIsSpellAll = 0 != (nEvt & nSpellAllFlags); 127 128 if (bIsSpellWrong || bIsSpellAll) 129 SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False ); 130 } 131 132 133 void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent( 134 const LinguServiceEvent& rLngSvcEvent ) 135 throw(RuntimeException) 136 { 137 vos::OGuard aGuard(Application::GetSolarMutex()); 138 139 sal_Bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN); 140 sal_Bool bIsSpellAll = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN); 141 if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN)) 142 bIsSpellWrong = bIsSpellAll = sal_True; // have all spelling and grammar checked... 143 if (bIsSpellWrong || bIsSpellAll) 144 { 145 SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False ); 146 } 147 if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN) 148 { 149 SwView *pSwView = SW_MOD()->GetFirstView(); 150 151 //!! since this function may be called within the ctor of 152 //!! SwView (during formatting) where the WrtShell is not yet 153 //!! created, we have to check for the WrtShellPtr to see 154 //!! if it is already availbale 155 while (pSwView && pSwView->GetWrtShellPtr()) 156 { 157 pSwView->GetWrtShell().ChgHyphenation(); 158 pSwView = SW_MOD()->GetNextView( pSwView ); 159 } 160 } 161 } 162 163 164 void SAL_CALL SwLinguServiceEventListener::disposing( 165 const EventObject& rEventObj ) 166 throw(RuntimeException) 167 { 168 vos::OGuard aGuard(Application::GetSolarMutex()); 169 170 if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr) 171 xLngSvcMgr = 0; 172 if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator) 173 xGCIterator = 0; 174 } 175 176 177 void SAL_CALL SwLinguServiceEventListener::queryTermination( 178 const EventObject& /*rEventObj*/ ) 179 throw(TerminationVetoException, RuntimeException) 180 { 181 //vos::OGuard aGuard(Application::GetSolarMutex()); 182 } 183 184 185 void SAL_CALL SwLinguServiceEventListener::notifyTermination( 186 const EventObject& rEventObj ) 187 throw(RuntimeException) 188 { 189 vos::OGuard aGuard(Application::GetSolarMutex()); 190 191 if (xDesktop.is() && rEventObj.Source == xDesktop) 192 { 193 if (xLngSvcMgr.is()) 194 xLngSvcMgr = 0; 195 if (xGCIterator.is()) 196 xGCIterator = 0; 197 xDesktop = NULL; 198 } 199 } 200 201