update credits
[LibreOffice.git] / forms / source / richtext / attributedispatcher.cxx
blob5a2acfe146c010bf208e25c14fcf115d57aa1402
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "attributedispatcher.hxx"
22 #include <editeng/editview.hxx>
24 //........................................................................
25 namespace frm
27 //........................................................................
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::frame;
31 using namespace ::com::sun::star::lang;
32 using namespace ::com::sun::star::util;
33 using namespace ::com::sun::star::beans;
35 //====================================================================
36 //= OAttributeDispatcher
37 //====================================================================
38 //--------------------------------------------------------------------
39 OAttributeDispatcher::OAttributeDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL,
40 IMultiAttributeDispatcher* _pMasterDispatcher )
41 :ORichTextFeatureDispatcher( _rView, _rURL )
42 ,m_pMasterDispatcher( _pMasterDispatcher )
43 ,m_nAttributeId( _nAttributeId )
45 OSL_ENSURE( m_pMasterDispatcher, "OAttributeDispatcher::OAttributeDispatcher: invalid master dispatcher!" );
48 //--------------------------------------------------------------------
49 OAttributeDispatcher::~OAttributeDispatcher( )
51 acquire();
52 dispose();
55 //--------------------------------------------------------------------
56 void OAttributeDispatcher::disposing( ::osl::ClearableMutexGuard& _rClearBeforeNotify )
58 m_pMasterDispatcher = NULL;
59 ORichTextFeatureDispatcher::disposing( _rClearBeforeNotify );
62 //--------------------------------------------------------------------
63 void OAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent& _rEvent, const AttributeState& _rState ) const
65 if ( _rState.eSimpleState == eChecked )
66 _rEvent.State <<= (sal_Bool)sal_True;
67 else if ( _rState.eSimpleState == eUnchecked )
68 _rEvent.State <<= (sal_Bool)sal_False;
71 //--------------------------------------------------------------------
72 FeatureStateEvent OAttributeDispatcher::buildStatusEvent() const
74 FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
75 aEvent.IsEnabled = getEditView() ? !getEditView()->IsReadOnly() : sal_False;
77 AttributeState aState;
78 if ( m_pMasterDispatcher )
79 aState = m_pMasterDispatcher->getState( m_nAttributeId );
81 fillFeatureEventFromAttributeState( aEvent, aState );
83 return aEvent;
86 //--------------------------------------------------------------------
87 void SAL_CALL OAttributeDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException)
89 ::osl::MutexGuard aGuard( m_aMutex );
91 checkDisposed();
93 (void)_rURL;
94 (void)_rArguments;
96 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OAttributeDispatcher::dispatch: invalid URL!" );
97 #if OSL_DEBUG_LEVEL > 0
98 if ( _rArguments.getLength() )
100 OString sMessage( "OAttributeDispatcher::dispatch: found arguments, but can't handle arguments at all" );
101 sMessage += "\n (URL: ";
102 sMessage += OString( _rURL.Complete.getStr(), _rURL.Complete.getLength(), RTL_TEXTENCODING_ASCII_US );
103 sMessage += ")";
104 OSL_FAIL( sMessage.getStr() );
106 #endif
108 if ( m_pMasterDispatcher )
109 m_pMasterDispatcher->executeAttribute( m_nAttributeId, NULL );
112 //--------------------------------------------------------------------
113 void OAttributeDispatcher::onAttributeStateChanged( AttributeId _nAttributeId, const AttributeState& /*_rState*/ )
115 OSL_ENSURE( _nAttributeId == m_nAttributeId, "OAttributeDispatcher::onAttributeStateChanged: wrong attribute!" );
116 (void)_nAttributeId;
118 FeatureStateEvent aEvent( buildStatusEvent() );
119 ::cppu::OInterfaceIteratorHelper aIter( getStatusListeners() );
120 while ( aIter.hasMoreElements() )
121 doNotify( static_cast< XStatusListener* >( aIter.next() ), aEvent );
124 //........................................................................
125 } // namespace frm
126 //........................................................................
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */