Branch data Line data Source code
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 : : #include <ModelEventListener.hxx>
20 : : #include <PropertyIds.hxx>
21 : : #include <rtl/oustringostreaminserter.hxx>
22 : : #include <com/sun/star/document/XEventBroadcaster.hpp>
23 : : #include <com/sun/star/text/XDocumentIndex.hpp>
24 : : #include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
25 : : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
26 : : #include <com/sun/star/util/XRefreshable.hpp>
27 : : #include <com/sun/star/beans/XPropertySet.hpp>
28 : : #include <com/sun/star/text/ReferenceFieldPart.hpp>
29 : : #include <com/sun/star/text/ReferenceFieldSource.hpp>
30 : :
31 : : namespace writerfilter {
32 : : namespace dmapper {
33 : :
34 : : using namespace ::com::sun::star;
35 : :
36 : :
37 : :
38 : :
39 : 30 : ModelEventListener::ModelEventListener()
40 : : {
41 : 30 : }
42 : :
43 : :
44 : 30 : ModelEventListener::~ModelEventListener()
45 : : {
46 [ - + ]: 60 : }
47 : :
48 : :
49 : 90 : void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) throw (uno::RuntimeException)
50 : : {
51 [ + + ]: 90 : if ( rEvent.EventName == "OnFocus" )
52 : : {
53 : : try
54 : : {
55 [ + - ]: 30 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
56 : :
57 [ + - ]: 30 : uno::Reference< text::XDocumentIndexesSupplier> xIndexesSupplier( rEvent.Source, uno::UNO_QUERY );
58 : : //remove listener
59 [ + - ][ + - ]: 60 : uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener(
60 [ + - ][ + - ]: 30 : uno::Reference<document::XEventListener>(this));
61 : :
62 [ + - ][ + - ]: 30 : uno::Reference< container::XIndexAccess > xIndexes = xIndexesSupplier->getDocumentIndexes();
63 : :
64 [ + - ][ + - ]: 30 : sal_Int32 nIndexes = xIndexes->getCount();
65 [ - + ]: 30 : for( sal_Int32 nIndex = 0; nIndex < nIndexes; ++nIndex)
66 : : {
67 [ # # ][ # # ]: 0 : uno::Reference< text::XDocumentIndex> xIndex( xIndexes->getByIndex( nIndex ), uno::UNO_QUERY );
[ # # ]
68 [ # # ][ # # ]: 0 : xIndex->update();
69 : 0 : }
70 : :
71 : : // If we have PAGEREF fields, update fields as well.
72 [ + - ]: 30 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(rEvent.Source, uno::UNO_QUERY);
73 [ + - ][ + - ]: 30 : uno::Reference<container::XEnumeration> xEnumeration(xTextFieldsSupplier->getTextFields()->createEnumeration(), uno::UNO_QUERY);
[ + - ][ + - ]
[ + - ]
74 : 30 : sal_Int32 nIndex = 0;
75 [ + - ][ + - ]: 63 : while(xEnumeration->hasMoreElements())
[ + + ]
76 : : {
77 : : try
78 : : {
79 [ + - ][ + - ]: 33 : uno::Reference<beans::XPropertySet> xPropertySet(xEnumeration->nextElement(), uno::UNO_QUERY);
[ + - ]
80 : 33 : sal_Int16 nSource = 0;
81 [ + - ][ - + ]: 33 : xPropertySet->getPropertyValue(rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_SOURCE)) >>= nSource;
[ + - ]
82 : 0 : sal_Int16 nPart = 0;
83 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue(rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_PART)) >>= nPart;
[ # # ]
84 [ # # ][ # # ]: 0 : if (nSource == text::ReferenceFieldSource::BOOKMARK && nPart == text::ReferenceFieldPart::PAGE)
85 [ - + ]: 33 : ++nIndex;
86 : : }
87 [ + - ]: 33 : catch( const beans::UnknownPropertyException& )
88 : : {
89 : : // doesn't even have such a property? ignore
90 : : }
91 : : }
92 [ - + ]: 30 : if (nIndex)
93 : : {
94 [ # # ][ # # ]: 0 : uno::Reference<util::XRefreshable> xRefreshable(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY);
[ # # ]
95 [ # # ][ # # ]: 0 : xRefreshable->refresh();
96 [ # # ]: 30 : }
97 : : }
98 : 0 : catch( const uno::Exception& rEx )
99 : : {
100 : : SAL_WARN("writerfilter", "exception while updating indexes: " << rEx.Message);
101 : : }
102 : : }
103 : 90 : }
104 : :
105 : :
106 : 0 : void ModelEventListener::disposing( const lang::EventObject& rEvent ) throw (uno::RuntimeException)
107 : : {
108 : : try
109 : : {
110 [ # # ]: 0 : uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener(
[ # # # # ]
111 [ # # ][ # # ]: 0 : uno::Reference<document::XEventListener>(this));
112 : : }
113 : 0 : catch( const uno::Exception& )
114 : : {
115 : : }
116 : 0 : }
117 : :
118 : : } //namespace dmapper
119 : : } //namespace writerfilter
120 : :
121 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|