1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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 OAttributeDispatcher::OAttributeDispatcher( EditView
& _rView
, AttributeId _nAttributeId
, const URL
& _rURL
,
36 IMultiAttributeDispatcher
* _pMasterDispatcher
)
37 :ORichTextFeatureDispatcher( _rView
, _rURL
)
38 ,m_pMasterDispatcher( _pMasterDispatcher
)
39 ,m_nAttributeId( _nAttributeId
)
41 OSL_ENSURE( m_pMasterDispatcher
, "OAttributeDispatcher::OAttributeDispatcher: invalid master dispatcher!" );
45 OAttributeDispatcher::~OAttributeDispatcher( )
52 void OAttributeDispatcher::disposing( ::osl::ClearableMutexGuard
& _rClearBeforeNotify
)
54 m_pMasterDispatcher
= NULL
;
55 ORichTextFeatureDispatcher::disposing( _rClearBeforeNotify
);
59 void OAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent
& _rEvent
, const AttributeState
& _rState
) const
61 if ( _rState
.eSimpleState
== eChecked
)
62 _rEvent
.State
<<= true;
63 else if ( _rState
.eSimpleState
== eUnchecked
)
64 _rEvent
.State
<<= false;
68 FeatureStateEvent
OAttributeDispatcher::buildStatusEvent() const
70 FeatureStateEvent
aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
71 aEvent
.IsEnabled
= getEditView() ? !getEditView()->IsReadOnly() : sal_False
;
73 AttributeState aState
;
74 if ( m_pMasterDispatcher
)
75 aState
= m_pMasterDispatcher
->getState( m_nAttributeId
);
77 fillFeatureEventFromAttributeState( aEvent
, aState
);
83 void SAL_CALL
OAttributeDispatcher::dispatch( const URL
& _rURL
, const Sequence
< PropertyValue
>& _rArguments
) throw (RuntimeException
, std::exception
)
85 ::osl::MutexGuard
aGuard( m_aMutex
);
92 OSL_ENSURE( _rURL
.Complete
== getFeatureURL().Complete
, "OAttributeDispatcher::dispatch: invalid URL!" );
93 #if OSL_DEBUG_LEVEL > 0
94 if ( _rArguments
.getLength() )
96 OString
sMessage( "OAttributeDispatcher::dispatch: found arguments, but can't handle arguments at all" );
97 sMessage
+= "\n (URL: ";
98 sMessage
+= OString( _rURL
.Complete
.getStr(), _rURL
.Complete
.getLength(), RTL_TEXTENCODING_ASCII_US
);
100 OSL_FAIL( sMessage
.getStr() );
104 if ( m_pMasterDispatcher
)
105 m_pMasterDispatcher
->executeAttribute( m_nAttributeId
, NULL
);
109 void OAttributeDispatcher::onAttributeStateChanged( AttributeId _nAttributeId
, const AttributeState
& /*_rState*/ )
111 OSL_ENSURE( _nAttributeId
== m_nAttributeId
, "OAttributeDispatcher::onAttributeStateChanged: wrong attribute!" );
114 FeatureStateEvent
aEvent( buildStatusEvent() );
115 ::cppu::OInterfaceIteratorHelper
aIter( getStatusListeners() );
116 while ( aIter
.hasMoreElements() )
117 doNotify( static_cast< XStatusListener
* >( aIter
.next() ), aEvent
);
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */