LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - ModelEventListener.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 33 37 89.2 %
Date: 2014-04-11 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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/ustring.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             : #include <com/sun/star/frame/XModel.hpp>
      31             : #include <com/sun/star/view/XFormLayerAccess.hpp>
      32             : 
      33             : namespace writerfilter {
      34             : namespace dmapper {
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38             : 
      39             : 
      40             : 
      41         201 : ModelEventListener::ModelEventListener(bool bIndexes, bool bControls)
      42             :     : m_bIndexes(bIndexes),
      43         201 :     m_bControls(bControls)
      44             : {
      45         201 : }
      46             : 
      47             : 
      48         402 : ModelEventListener::~ModelEventListener()
      49             : {
      50         402 : }
      51             : 
      52             : 
      53         713 : void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) throw (uno::RuntimeException, std::exception)
      54             : {
      55         713 :     if ( rEvent.EventName == "OnFocus" && m_bIndexes)
      56             :     {
      57             :         try
      58             :         {
      59         189 :             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
      60             : 
      61             :             //remove listener
      62         378 :             uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener(
      63         189 :             uno::Reference<document::XEventListener>(this));
      64             : 
      65             :             // If we have PAGEREF fields, update fields as well.
      66         189 :             uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(rEvent.Source, uno::UNO_QUERY);
      67         378 :             uno::Reference<container::XEnumeration> xEnumeration(xTextFieldsSupplier->getTextFields()->createEnumeration(), uno::UNO_QUERY);
      68         189 :             sal_Int32 nIndex = 0;
      69         708 :             while(xEnumeration->hasMoreElements())
      70             :             {
      71             :                 try
      72             :                 {
      73         330 :                     uno::Reference<beans::XPropertySet> xPropertySet(xEnumeration->nextElement(), uno::UNO_QUERY);
      74         330 :                     sal_Int16 nSource = 0;
      75         642 :                     xPropertySet->getPropertyValue(rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_SOURCE)) >>= nSource;
      76          18 :                     sal_Int16 nPart = 0;
      77          18 :                     xPropertySet->getPropertyValue(rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_PART)) >>= nPart;
      78          18 :                     if (nSource == text::ReferenceFieldSource::BOOKMARK && nPart == text::ReferenceFieldPart::PAGE)
      79         312 :                         ++nIndex;
      80             :                 }
      81         312 :                 catch( const beans::UnknownPropertyException& )
      82             :                 {
      83             :                     // doesn't even have such a property? ignore
      84             :                 }
      85             :             }
      86         189 :             if (nIndex)
      87             :             {
      88           0 :                 uno::Reference<util::XRefreshable> xRefreshable(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY);
      89           0 :                 xRefreshable->refresh();
      90         189 :             }
      91             :         }
      92           0 :         catch( const uno::Exception& rEx )
      93             :         {
      94             :             SAL_WARN("writerfilter", "exception while updating indexes: " << rEx.Message);
      95             :         }
      96             :     }
      97             : 
      98         713 :     if ( rEvent.EventName == "OnFocus" && m_bControls)
      99             :     {
     100             : 
     101             :         // Form design mode is enabled by default in Writer, not in Word.
     102          12 :         uno::Reference<frame::XModel> xModel(rEvent.Source, uno::UNO_QUERY);
     103          24 :         uno::Reference<view::XFormLayerAccess> xFormLayerAccess(xModel->getCurrentController(), uno::UNO_QUERY);
     104          24 :         xFormLayerAccess->setFormDesignMode(false);
     105             :     }
     106         713 : }
     107             : 
     108             : 
     109          12 : void ModelEventListener::disposing( const lang::EventObject& rEvent ) throw (uno::RuntimeException, std::exception)
     110             : {
     111             :     try
     112             :     {
     113          24 :         uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener(
     114          12 :             uno::Reference<document::XEventListener>(this));
     115             :     }
     116           0 :     catch( const uno::Exception& )
     117             :     {
     118             :     }
     119          12 : }
     120             : 
     121             : } //namespace dmapper
     122             : } //namespace writerfilter
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10