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 #include <ModelEventListener.hxx> 24 #include <com/sun/star/document/XEventBroadcaster.hpp> 25 #include <com/sun/star/text/XDocumentIndex.hpp> 26 #include <com/sun/star/text/XDocumentIndexesSupplier.hpp> 27 28 namespace writerfilter { 29 namespace dmapper { 30 31 using namespace ::com::sun::star; 32 33 34 /*-- 22.11.2007 08:40:22--------------------------------------------------- 35 36 -----------------------------------------------------------------------*/ ModelEventListener()37ModelEventListener::ModelEventListener() 38 { 39 } 40 /*-- 22.11.2007 08:40:22--------------------------------------------------- 41 42 -----------------------------------------------------------------------*/ ~ModelEventListener()43ModelEventListener::~ModelEventListener() 44 { 45 } 46 /*-- 22.11.2007 08:40:22--------------------------------------------------- 47 48 -----------------------------------------------------------------------*/ notifyEvent(const document::EventObject & rEvent)49void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) throw (uno::RuntimeException) 50 { 51 if( rEvent.EventName.equalsAscii("OnFocus")) 52 { 53 try 54 { 55 uno::Reference< text::XDocumentIndexesSupplier> xIndexesSupplier( rEvent.Source, uno::UNO_QUERY ); 56 //remove listener 57 uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener( 58 uno::Reference<document::XEventListener>(this)); 59 60 uno::Reference< container::XIndexAccess > xIndexes = xIndexesSupplier->getDocumentIndexes(); 61 62 sal_Int32 nIndexes = xIndexes->getCount(); 63 for( sal_Int32 nIndex = 0; nIndex < nIndexes; ++nIndex) 64 { 65 uno::Reference< text::XDocumentIndex> xIndex( xIndexes->getByIndex( nIndex ), uno::UNO_QUERY ); 66 xIndex->update(); 67 } 68 } 69 catch( const uno::Exception& rEx ) 70 { 71 (void)rEx; 72 OSL_ENSURE( false, "exception while updating indexes" ); 73 } 74 } 75 } 76 /*-- 22.11.2007 08:40:22--------------------------------------------------- 77 78 -----------------------------------------------------------------------*/ disposing(const lang::EventObject & rEvent)79void ModelEventListener::disposing( const lang::EventObject& rEvent ) throw (uno::RuntimeException) 80 { 81 try 82 { 83 uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener( 84 uno::Reference<document::XEventListener>(this)); 85 } 86 catch( const uno::Exception& ) 87 { 88 } 89 } 90 91 } //namespace dmapper 92 } //namespace writerfilter 93